build: update to Zig 0.11.0

This commit is contained in:
Isaac Freund
2023-10-16 16:18:36 +02:00
parent 7f30c655c7
commit 2e586c7061
54 changed files with 333 additions and 363 deletions

View File

@ -71,7 +71,7 @@ fn handleRequest(control: *zriver.ControlV1, request: zriver.ControlV1.Request,
switch (request) {
.destroy => control.destroy(),
.add_argument => |add_argument| {
const owned_slice = util.gpa.dupeZ(u8, mem.span(add_argument.argument)) catch {
const owned_slice = util.gpa.dupeZ(u8, mem.sliceTo(add_argument.argument, 0)) catch {
control.getClient().postNoMemory();
return;
};
@ -84,7 +84,7 @@ fn handleRequest(control: *zriver.ControlV1, request: zriver.ControlV1.Request,
};
},
.run_command => |run_command| {
const seat = @intToPtr(*Seat, wlr.Seat.Client.fromWlSeat(run_command.seat).?.seat.data);
const seat: *Seat = @ptrFromInt(wlr.Seat.Client.fromWlSeat(run_command.seat).?.seat.data);
const callback = zriver.CommandCallbackV1.create(
control.getClient(),
@ -109,7 +109,7 @@ fn handleRequest(control: *zriver.ControlV1, request: zriver.ControlV1.Request,
callback.getClient().postNoMemory();
return;
},
command.Error.Other => std.cstr.addNullByte(util.gpa, out.?) catch {
command.Error.Other => util.gpa.dupeZ(u8, out.?) catch {
callback.getClient().postNoMemory();
return;
},

View File

@ -287,8 +287,8 @@ pub fn setTheme(self: *Self, theme: ?[*:0]const u8, _size: ?u32) !void {
image.width * 4,
image.width,
image.height,
@intCast(i32, image.hotspot_x),
@intCast(i32, image.hotspot_y),
@intCast(image.hotspot_x),
@intCast(image.hotspot_y),
);
}
@ -427,7 +427,7 @@ fn updateKeyboardFocus(self: Self, result: Root.AtResult) void {
/// Requires a call to Root.applyPending()
fn updateOutputFocus(self: Self, lx: f64, ly: f64) void {
if (server.root.output_layout.outputAt(lx, ly)) |wlr_output| {
const output = @intToPtr(*Output, wlr_output.data);
const output: *Output = @ptrFromInt(wlr_output.data);
self.seat.focusOutput(output);
}
}
@ -712,8 +712,8 @@ pub fn startMove(cursor: *Self, view: *View) void {
const new_mode: Mode = .{ .move = .{
.view = view,
.offset_x = @floatToInt(i32, cursor.wlr_cursor.x) - view.current.box.x,
.offset_y = @floatToInt(i32, cursor.wlr_cursor.y) - view.current.box.y,
.offset_x = @as(i32, @intFromFloat(cursor.wlr_cursor.x)) - view.current.box.x,
.offset_y = @as(i32, @intFromFloat(cursor.wlr_cursor.y)) - view.current.box.y,
} };
cursor.enterMode(new_mode, view, .move);
}
@ -733,8 +733,8 @@ pub fn startResize(cursor: *Self, view: *View, proposed_edges: ?wlr.Edges) void
};
const box = &view.current.box;
const lx = @floatToInt(i32, cursor.wlr_cursor.x);
const ly = @floatToInt(i32, cursor.wlr_cursor.y);
const lx: i32 = @intFromFloat(cursor.wlr_cursor.x);
const ly: i32 = @intFromFloat(cursor.wlr_cursor.y);
const offset_x = if (edges.left) lx - box.x else box.x + box.width - lx;
const offset_y = if (edges.top) ly - box.y else box.y + box.height - ly;
@ -756,13 +756,13 @@ fn computeEdges(cursor: *const Self, view: *const View) wlr.Edges {
var output_box: wlr.Box = undefined;
server.root.output_layout.getBox(view.current.output.?.wlr_output, &output_box);
const sx = @floatToInt(i32, cursor.wlr_cursor.x) - output_box.x - box.x;
const sy = @floatToInt(i32, cursor.wlr_cursor.y) - output_box.y - box.y;
const sx = @as(i32, @intFromFloat(cursor.wlr_cursor.x)) - output_box.x - box.x;
const sy = @as(i32, @intFromFloat(cursor.wlr_cursor.y)) - output_box.y - box.y;
var edges: wlr.Edges = .{};
if (box.width > min_handle_size * 2) {
const handle = math.max(min_handle_size, @divFloor(box.width, 5));
const handle = @max(min_handle_size, @divFloor(box.width, 5));
if (sx < handle) {
edges.left = true;
} else if (sx > box.width - handle) {
@ -771,7 +771,7 @@ fn computeEdges(cursor: *const Self, view: *const View) wlr.Edges {
}
if (box.height > min_handle_size * 2) {
const handle = math.max(min_handle_size, @divFloor(box.height, 5));
const handle = @max(min_handle_size, @divFloor(box.height, 5));
if (sy < handle) {
edges.top = true;
} else if (sy > box.height - handle) {
@ -863,7 +863,7 @@ fn processMotion(self: *Self, device: *wlr.InputDevice, time: u32, delta_x: f64,
data.delta_y = dy - @trunc(dy);
if (tag == .move) {
data.view.pending.move(@floatToInt(i32, dx), @floatToInt(i32, dy));
data.view.pending.move(@intFromFloat(dx), @intFromFloat(dy));
} else {
// Modify width/height of the pending box, taking constraints into account
// The x/y coordinates of the view will be adjusted as needed in View.resizeCommit()
@ -880,31 +880,31 @@ fn processMotion(self: *Self, device: *wlr.InputDevice, time: u32, delta_x: f64,
if (data.edges.left) {
var x1 = box.x;
const x2 = box.x + box.width;
x1 += @floatToInt(i32, dx);
x1 = math.max(x1, border_width);
x1 = math.max(x1, x2 - constraints.max_width);
x1 = math.min(x1, x2 - constraints.min_width);
x1 += @intFromFloat(dx);
x1 = @max(x1, border_width);
x1 = @max(x1, x2 - constraints.max_width);
x1 = @min(x1, x2 - constraints.min_width);
box.width = x2 - x1;
} else if (data.edges.right) {
box.width += @floatToInt(i32, dx);
box.width = math.max(box.width, constraints.min_width);
box.width = math.min(box.width, constraints.max_width);
box.width = math.min(box.width, output_width - border_width - box.x);
box.width += @intFromFloat(dx);
box.width = @max(box.width, constraints.min_width);
box.width = @min(box.width, constraints.max_width);
box.width = @min(box.width, output_width - border_width - box.x);
}
if (data.edges.top) {
var y1 = box.y;
const y2 = box.y + box.height;
y1 += @floatToInt(i32, dy);
y1 = math.max(y1, border_width);
y1 = math.max(y1, y2 - constraints.max_height);
y1 = math.min(y1, y2 - constraints.min_height);
y1 += @intFromFloat(dy);
y1 = @max(y1, border_width);
y1 = @max(y1, y2 - constraints.max_height);
y1 = @min(y1, y2 - constraints.min_height);
box.height = y2 - y1;
} else if (data.edges.bottom) {
box.height += @floatToInt(i32, dy);
box.height = math.max(box.height, constraints.min_height);
box.height = math.min(box.height, constraints.max_height);
box.height = math.min(box.height, output_height - border_width - box.y);
box.height += @intFromFloat(dy);
box.height = @max(box.height, constraints.min_height);
box.height = @min(box.height, constraints.max_height);
box.height = @min(box.height, output_height - border_width - box.y);
}
}
@ -943,8 +943,9 @@ fn updateFocusFollowsCursorTarget(self: *Self) void {
// in order to avoid clashes with cursor warping on focus change.
var output_layout_box: wlr.Box = undefined;
server.root.output_layout.getBox(view.current.output.?.wlr_output, &output_layout_box);
const cursor_ox = self.wlr_cursor.x - @intToFloat(f64, output_layout_box.x);
const cursor_oy = self.wlr_cursor.y - @intToFloat(f64, output_layout_box.y);
const cursor_ox = self.wlr_cursor.x - @as(f64, @floatFromInt(output_layout_box.x));
const cursor_oy = self.wlr_cursor.y - @as(f64, @floatFromInt(output_layout_box.y));
if (view.current.box.containsPoint(cursor_ox, cursor_oy)) {
self.focus_follows_cursor_target = view;
}
@ -981,7 +982,7 @@ pub fn updateState(self: *Self) void {
if (!self.hidden) {
var now: os.timespec = undefined;
os.clock_gettime(os.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported");
const msec = @intCast(u32, now.tv_sec * std.time.ms_per_s +
const msec: u32 = @intCast(now.tv_sec * std.time.ms_per_s +
@divTrunc(now.tv_nsec, std.time.ns_per_ms));
self.passthrough(msec);
}
@ -998,20 +999,20 @@ pub fn updateState(self: *Self) void {
// Keep the cursor locked to the original offset from the edges of the view.
const box = &data.view.current.box;
const new_x = blk: {
const new_x: f64 = blk: {
if (mode == .move or data.edges.left) {
break :blk @intToFloat(f64, data.offset_x + box.x);
break :blk @floatFromInt(data.offset_x + box.x);
} else if (data.edges.right) {
break :blk @intToFloat(f64, box.x + box.width - data.offset_x);
break :blk @floatFromInt(box.x + box.width - data.offset_x);
} else {
break :blk self.wlr_cursor.x;
}
};
const new_y = blk: {
const new_y: f64 = blk: {
if (mode == .move or data.edges.top) {
break :blk @intToFloat(f64, data.offset_y + box.y);
break :blk @floatFromInt(data.offset_y + box.y);
} else if (data.edges.bottom) {
break :blk @intToFloat(f64, box.y + box.height - data.offset_y);
break :blk @floatFromInt(box.y + box.height - data.offset_y);
} else {
break :blk self.wlr_cursor.y;
}
@ -1083,8 +1084,8 @@ fn warp(self: *Self) void {
(usable_layout_box.containsPoint(self.wlr_cursor.x, self.wlr_cursor.y) and
!target_box.containsPoint(self.wlr_cursor.x, self.wlr_cursor.y)))
{
const lx = @intToFloat(f64, target_box.x + @divTrunc(target_box.width, 2));
const ly = @intToFloat(f64, target_box.y + @divTrunc(target_box.height, 2));
const lx: f64 = @floatFromInt(target_box.x + @divTrunc(target_box.width, 2));
const ly: f64 = @floatFromInt(target_box.y + @divTrunc(target_box.height, 2));
if (!self.wlr_cursor.warp(null, lx, ly)) {
log.err("failed to warp cursor on focus change", .{});
}
@ -1094,7 +1095,7 @@ fn warp(self: *Self) void {
fn updateDragIcons(self: *Self) void {
var it = server.root.drag_icons.children.iterator(.forward);
while (it.next()) |node| {
const icon = @intToPtr(*DragIcon, node.data);
const icon = @as(*DragIcon, @ptrFromInt(node.data));
if (icon.wlr_drag_icon.drag.seat != self.seat.wlr_seat) continue;
@ -1102,16 +1103,16 @@ fn updateDragIcons(self: *Self) void {
.keyboard => unreachable,
.keyboard_pointer => {
icon.tree.node.setPosition(
@floatToInt(c_int, self.wlr_cursor.x),
@floatToInt(c_int, self.wlr_cursor.y),
@intFromFloat(self.wlr_cursor.x),
@intFromFloat(self.wlr_cursor.y),
);
},
.keyboard_touch => {
const touch_id = icon.wlr_drag_icon.drag.touch_id;
const point = self.touch_points.get(touch_id) orelse continue;
icon.tree.node.setPosition(
@floatToInt(c_int, point.lx),
@floatToInt(c_int, point.ly),
@intFromFloat(point.lx),
@intFromFloat(point.ly),
);
},
}

View File

@ -47,7 +47,7 @@ pub fn create(wlr_drag_icon: *wlr.Drag.Icon) error{OutOfMemory}!void {
.tree = tree,
.surface = try tree.createSceneSubsurfaceTree(wlr_drag_icon.surface),
};
tree.node.data = @ptrToInt(drag_icon);
tree.node.data = @intFromPtr(drag_icon);
tree.node.setEnabled(wlr_drag_icon.mapped);

View File

@ -89,7 +89,7 @@ fn handleForeignActivate(
) void {
const handle = @fieldParentPtr(ForeignToplevelHandle, "foreign_activate", listener);
const view = @fieldParentPtr(View, "foreign_toplevel_handle", handle);
const seat = @intToPtr(*Seat, event.seat.data);
const seat: *Seat = @ptrFromInt(event.seat.data);
seat.focus(view);
server.root.applyPending();

View File

@ -281,10 +281,7 @@ pub fn deinit(self: *Self) void {
}
pub fn apply(self: *Self, device: *InputDevice) void {
const libinput_device = @ptrCast(
*c.libinput_device,
device.wlr_device.getLibinputDevice() orelse return,
);
const libinput_device: *c.libinput_device = @ptrCast(device.wlr_device.getLibinputDevice() orelse return);
log.debug("applying input configuration to device: {s}", .{device.identifier});
if (self.event_state) |setting| setting.apply(libinput_device);
if (self.accel_profile) |setting| setting.apply(libinput_device);

View File

@ -57,13 +57,13 @@ pub fn init(device: *InputDevice, seat: *Seat, wlr_device: *wlr.InputDevice) !vo
device_type,
wlr_device.vendor,
wlr_device.product,
mem.trim(u8, mem.span(wlr_device.name), &ascii.spaces),
mem.trim(u8, mem.sliceTo(wlr_device.name, 0), &ascii.whitespace),
},
);
errdefer util.gpa.free(identifier);
for (identifier) |*char| {
if (!ascii.isGraph(char.*)) {
if (!ascii.isPrint(char.*) or ascii.isWhitespace(char.*)) {
char.* = '_';
}
}

View File

@ -145,7 +145,7 @@ fn handleNewVirtualKeyboard(
_: *wl.Listener(*wlr.VirtualKeyboardV1),
virtual_keyboard: *wlr.VirtualKeyboardV1,
) void {
const seat = @intToPtr(*Seat, virtual_keyboard.seat.data);
const seat: *Seat = @ptrFromInt(virtual_keyboard.seat.data);
seat.addDevice(&virtual_keyboard.keyboard.base);
}

View File

@ -47,7 +47,7 @@ pub fn init(self: *Self, seat: *Seat, wlr_device: *wlr.InputDevice) !void {
errdefer self.device.deinit();
const wlr_keyboard = self.device.wlr_device.toKeyboard();
wlr_keyboard.data = @ptrToInt(self);
wlr_keyboard.data = @intFromPtr(self);
// wlroots will log a more detailed error if this fails.
if (!wlr_keyboard.setKeymap(server.config.keymap)) return error.OutOfMemory;
@ -127,7 +127,7 @@ fn handleKey(listener: *wl.Listener(*wlr.Keyboard.event.Key), event: *wlr.Keyboa
}
fn isModifier(keysym: xkb.Keysym) bool {
return @enumToInt(keysym) >= xkb.Keysym.Shift_L and @enumToInt(keysym) <= xkb.Keysym.Hyper_R;
return @intFromEnum(keysym) >= xkb.Keysym.Shift_L and @intFromEnum(keysym) <= xkb.Keysym.Hyper_R;
}
fn handleModifiers(listener: *wl.Listener(*wlr.Keyboard), _: *wlr.Keyboard) void {
@ -144,12 +144,12 @@ fn handleModifiers(listener: *wl.Listener(*wlr.Keyboard), _: *wlr.Keyboard) void
/// Handle any builtin, harcoded compsitor mappings such as VT switching.
/// Returns true if the keysym was handled.
fn handleBuiltinMapping(keysym: xkb.Keysym) bool {
switch (@enumToInt(keysym)) {
switch (@intFromEnum(keysym)) {
xkb.Keysym.XF86Switch_VT_1...xkb.Keysym.XF86Switch_VT_12 => {
log.debug("switch VT keysym received", .{});
if (server.backend.isMulti()) {
if (server.backend.getSession()) |session| {
const vt = @enumToInt(keysym) - xkb.Keysym.XF86Switch_VT_1 + 1;
const vt = @intFromEnum(keysym) - xkb.Keysym.XF86Switch_VT_1 + 1;
const log_server = std.log.scoped(.server);
log_server.info("switching to VT {}", .{vt});
session.changeVt(vt) catch log_server.err("changing VT failed", .{});

View File

@ -28,8 +28,8 @@ len: usize = 0,
pub fn add(self: *Self, new: u32) void {
for (self.items[0..self.len]) |item| if (new == item) return;
comptime assert(@typeInfo(std.meta.fieldInfo(Self, .items).field_type).Array.len ==
@typeInfo(std.meta.fieldInfo(wlr.Keyboard, .keycodes).field_type).Array.len);
comptime assert(@typeInfo(std.meta.fieldInfo(Self, .items).type).Array.len ==
@typeInfo(std.meta.fieldInfo(wlr.Keyboard, .keycodes).type).Array.len);
if (self.len == self.items.len) {
log.err("KeycodeSet limit reached, code {d} omitted", .{new});
@ -41,7 +41,7 @@ pub fn add(self: *Self, new: u32) void {
}
pub fn remove(self: *Self, old: u32) bool {
for (self.items[0..self.len]) |item, idx| if (old == item) {
for (self.items[0..self.len], 0..) |item, idx| if (old == item) {
self.len -= 1;
if (self.len > 0) self.items[idx] = self.items[self.len];

View File

@ -43,7 +43,7 @@ commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit)
new_popup: wl.Listener(*wlr.XdgPopup) = wl.Listener(*wlr.XdgPopup).init(handleNewPopup),
pub fn create(wlr_layer_surface: *wlr.LayerSurfaceV1) error{OutOfMemory}!void {
const output = @intToPtr(*Output, wlr_layer_surface.output.?.data);
const output: *Output = @ptrFromInt(wlr_layer_surface.output.?.data);
const layer_surface = try util.gpa.create(LayerSurface);
errdefer util.gpa.destroy(layer_surface);
@ -55,12 +55,12 @@ pub fn create(wlr_layer_surface: *wlr.LayerSurfaceV1) error{OutOfMemory}!void {
.scene_layer_surface = try layer_tree.createSceneLayerSurfaceV1(wlr_layer_surface),
.popup_tree = try output.layers.popups.createSceneTree(),
};
wlr_layer_surface.data = @ptrToInt(layer_surface);
wlr_layer_surface.data = @intFromPtr(layer_surface);
try SceneNodeData.attach(&layer_surface.scene_layer_surface.tree.node, .{ .layer_surface = layer_surface });
try SceneNodeData.attach(&layer_surface.popup_tree.node, .{ .layer_surface = layer_surface });
wlr_layer_surface.surface.data = @ptrToInt(&layer_surface.scene_layer_surface.tree.node);
wlr_layer_surface.surface.data = @intFromPtr(&layer_surface.scene_layer_surface.tree.node);
wlr_layer_surface.events.destroy.add(&layer_surface.destroy);
wlr_layer_surface.events.map.add(&layer_surface.map);
@ -131,7 +131,7 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
// If a surface is committed while it is not mapped, we must send a configure.
// TODO: this mapped check is not correct as it will be true in the commit
// that triggers the unmap as well.
if (!wlr_layer_surface.mapped or @bitCast(u32, wlr_layer_surface.current.committed) != 0) {
if (!wlr_layer_surface.mapped or @as(u32, @bitCast(wlr_layer_surface.current.committed)) != 0) {
layer_surface.output.arrangeLayers();
handleKeyboardInteractiveExclusive(layer_surface.output);
server.root.applyPending();
@ -150,7 +150,7 @@ fn handleKeyboardInteractiveExclusive(output: *Output) void {
var it = tree.children.iterator(.reverse);
while (it.next()) |node| {
assert(node.type == .tree);
if (@intToPtr(?*SceneNodeData, node.data)) |node_data| {
if (@as(?*SceneNodeData, @ptrFromInt(node.data))) |node_data| {
const layer_surface = node_data.data.layer_surface;
const wlr_layer_surface = layer_surface.wlr_layer_surface;
if (wlr_layer_surface.mapped and

View File

@ -109,8 +109,8 @@ pub fn startLayoutDemand(self: *Self, views: u32) void {
self.layout.sendLayoutDemand(
views,
@intCast(u32, self.output.usable_box.width),
@intCast(u32, self.output.usable_box.height),
@intCast(self.output.usable_box.width),
@intCast(self.output.usable_box.height),
self.output.pending.tags,
self.output.inflight.layout_demand.?.serial,
);
@ -138,8 +138,8 @@ fn handleRequest(layout: *river.LayoutV3, request: river.LayoutV3.Request, self:
layout_demand.pushViewDimensions(
req.x,
req.y,
@intCast(u31, math.min(math.maxInt(u31), req.width)),
@intCast(u31, math.min(math.maxInt(u31), req.height)),
@min(math.maxInt(u31), req.width),
@min(math.maxInt(u31), req.height),
);
}
},

View File

@ -52,7 +52,7 @@ pub fn init(layout: *Layout, views: u32) !Self {
return Self{
.serial = server.wl_server.nextSerial(),
.views = @intCast(i32, views),
.views = @intCast(views),
.view_boxen = try util.gpa.alloc(wlr.Box, views),
.timeout_timer = timeout_timer,
};
@ -86,7 +86,7 @@ pub fn pushViewDimensions(self: *Self, x: i32, y: i32, width: u31, height: u31)
return;
}
self.view_boxen[self.view_boxen.len - @intCast(usize, self.views)] = .{
self.view_boxen[self.view_boxen.len - @as(usize, @intCast(self.views))] = .{
.x = x,
.y = y,
.width = width,
@ -114,7 +114,7 @@ pub fn apply(self: *Self, layout: *Layout) void {
if (self.views != 0) {
log.err(
"proposed dimension count ({}) does not match view count ({}), aborting layout demand",
.{ -self.views + @intCast(i32, self.view_boxen.len), self.view_boxen.len },
.{ -self.views + @as(i32, @intCast(self.view_boxen.len)), self.view_boxen.len },
);
layout.layout.postError(
.count_mismatch,

View File

@ -68,7 +68,7 @@ fn handleRequest(
.get_layout => |req| {
// Ignore if the output is inert
const wlr_output = wlr.Output.fromWlOutput(req.output) orelse return;
const output = @intToPtr(*Output, wlr_output.data);
const output: *Output = @ptrFromInt(wlr_output.data);
log.debug("bind layout '{s}' on output '{s}'", .{ req.namespace, output.wlr_output.name });
@ -77,7 +77,7 @@ fn handleRequest(
layout_manager.getVersion(),
req.id,
output,
mem.span(req.namespace),
mem.sliceTo(req.namespace, 0),
) catch {
layout_manager.getClient().postNoMemory();
log.err("out of memory", .{});

View File

@ -43,7 +43,7 @@ pub fn create(wlr_lock_surface: *wlr.SessionLockSurfaceV1, lock: *wlr.SessionLoc
.wlr_lock_surface = wlr_lock_surface,
.lock = lock,
};
wlr_lock_surface.data = @ptrToInt(lock_surface);
wlr_lock_surface.data = @intFromPtr(lock_surface);
const output = lock_surface.getOutput();
const tree = try output.locked_content.createSceneSubsurfaceTree(wlr_lock_surface.surface);
@ -51,7 +51,7 @@ pub fn create(wlr_lock_surface: *wlr.SessionLockSurfaceV1, lock: *wlr.SessionLoc
try SceneNodeData.attach(&tree.node, .{ .lock_surface = lock_surface });
wlr_lock_surface.surface.data = @ptrToInt(&tree.node);
wlr_lock_surface.surface.data = @intFromPtr(&tree.node);
wlr_lock_surface.output.events.mode.add(&lock_surface.output_mode);
wlr_lock_surface.events.map.add(&lock_surface.map);
@ -65,7 +65,7 @@ pub fn destroy(lock_surface: *LockSurface) void {
var surface_it = lock_surface.lock.surfaces.iterator(.forward);
const new_focus: Seat.FocusTarget = while (surface_it.next()) |surface| {
if (surface != lock_surface.wlr_lock_surface)
break .{ .lock_surface = @intToPtr(*LockSurface, surface.data) };
break .{ .lock_surface = @ptrFromInt(surface.data) };
} else .none;
var seat_it = server.input_manager.seats.first;
@ -86,7 +86,7 @@ pub fn destroy(lock_surface: *LockSurface) void {
}
fn getOutput(lock_surface: *LockSurface) *Output {
return @intToPtr(*Output, lock_surface.wlr_lock_surface.output.data);
return @ptrFromInt(lock_surface.wlr_lock_surface.output.data);
}
fn handleOutputMode(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
@ -95,7 +95,7 @@ fn handleOutputMode(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
var output_width: i32 = undefined;
var output_height: i32 = undefined;
lock_surface.getOutput().wlr_output.effectiveResolution(&output_width, &output_height);
_ = lock_surface.wlr_lock_surface.configure(@intCast(u32, output_width), @intCast(u32, output_height));
_ = lock_surface.wlr_lock_surface.configure(@intCast(output_width), @intCast(output_height));
}
fn handleMap(listener: *wl.Listener(void)) void {

View File

@ -45,7 +45,7 @@ pub fn init(
) !Self {
const owned_args = try util.gpa.alloc([:0]u8, command_args.len);
errdefer util.gpa.free(owned_args);
for (command_args) |arg, i| {
for (command_args, 0..) |arg, i| {
errdefer for (owned_args[0..i]) |a| util.gpa.free(a);
owned_args[i] = try util.gpa.dupeZ(u8, arg);
}

View File

@ -257,7 +257,7 @@ pub fn create(wlr_output: *wlr.Output) !void {
},
.status = undefined,
};
wlr_output.data = @ptrToInt(output);
wlr_output.data = @intFromPtr(output);
output.pending.focus_stack.init();
output.pending.wm_stack.init();
@ -299,7 +299,7 @@ pub fn layerSurfaceTree(self: Self, layer: zwlr.LayerShellV1.Layer) *wlr.SceneTr
self.layers.top,
self.layers.overlay,
};
return trees[@intCast(usize, @enumToInt(layer))];
return trees[@intCast(@intFromEnum(layer))];
}
/// Arrange all layer surfaces of this output and adjust the usable area.
@ -336,7 +336,7 @@ fn sendLayerConfigures(
var it = tree.children.iterator(.forward);
while (it.next()) |node| {
assert(node.type == .tree);
if (@intToPtr(?*SceneNodeData, node.data)) |node_data| {
if (@as(?*SceneNodeData, @ptrFromInt(node.data))) |node_data| {
const layer_surface = node_data.data.layer_surface;
const exclusive = layer_surface.wlr_layer_surface.current.exclusive_zone > 0;

View File

@ -47,7 +47,7 @@ set_region: wl.Listener(void) = wl.Listener(void).init(handleSetRegion),
node_destroy: wl.Listener(void) = wl.Listener(void).init(handleNodeDestroy),
pub fn create(wlr_constraint: *wlr.PointerConstraintV1) error{OutOfMemory}!void {
const seat = @intToPtr(*Seat, wlr_constraint.seat.data);
const seat: *Seat = @ptrFromInt(wlr_constraint.seat.data);
const constraint = try util.gpa.create(PointerConstraint);
errdefer util.gpa.destroy(constraint);
@ -55,7 +55,7 @@ pub fn create(wlr_constraint: *wlr.PointerConstraintV1) error{OutOfMemory}!void
constraint.* = .{
.wlr_constraint = wlr_constraint,
};
wlr_constraint.data = @ptrToInt(constraint);
wlr_constraint.data = @intFromPtr(constraint);
wlr_constraint.events.destroy.add(&constraint.destroy);
wlr_constraint.events.set_region.add(&constraint.set_region);
@ -70,7 +70,7 @@ pub fn create(wlr_constraint: *wlr.PointerConstraintV1) error{OutOfMemory}!void
}
pub fn maybeActivate(constraint: *PointerConstraint) void {
const seat = @intToPtr(*Seat, constraint.wlr_constraint.seat.data);
const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
assert(seat.cursor.constraint == constraint);
assert(seat.wlr_seat.keyboard_state.focused_surface == constraint.wlr_constraint.surface);
@ -82,8 +82,8 @@ pub fn maybeActivate(constraint: *PointerConstraint) void {
const result = server.root.at(seat.cursor.wlr_cursor.x, seat.cursor.wlr_cursor.y) orelse return;
if (result.surface != constraint.wlr_constraint.surface) return;
const sx = @floatToInt(i32, result.sx);
const sy = @floatToInt(i32, result.sy);
const sx: i32 = @intFromFloat(result.sx);
const sy: i32 = @intFromFloat(result.sy);
if (!constraint.wlr_constraint.region.containsPoint(sx, sy, null)) return;
assert(constraint.state == .inactive);
@ -103,7 +103,7 @@ pub fn maybeActivate(constraint: *PointerConstraint) void {
/// Called when the cursor position or content in the scene graph changes
pub fn updateState(constraint: *PointerConstraint) void {
const seat = @intToPtr(*Seat, constraint.wlr_constraint.seat.data);
const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
assert(seat.wlr_seat.keyboard_state.focused_surface == constraint.wlr_constraint.surface);
@ -119,8 +119,8 @@ pub fn updateState(constraint: *PointerConstraint) void {
return;
}
const warp_lx = @intToFloat(f64, lx) + constraint.state.active.sx;
const warp_ly = @intToFloat(f64, ly) + constraint.state.active.sy;
const warp_lx = @as(f64, @floatFromInt(lx)) + constraint.state.active.sx;
const warp_ly = @as(f64, @floatFromInt(ly)) + constraint.state.active.sy;
if (!seat.cursor.wlr_cursor.warp(null, warp_lx, warp_ly)) {
log.info("deactivating pointer constraint, could not warp cursor", .{});
constraint.deactivate();
@ -147,7 +147,7 @@ pub fn confine(constraint: *PointerConstraint, dx: *f64, dy: *f64) void {
}
pub fn deactivate(constraint: *PointerConstraint) void {
const seat = @intToPtr(*Seat, constraint.wlr_constraint.seat.data);
const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
assert(seat.cursor.constraint == constraint);
assert(constraint.state == .active);
@ -160,7 +160,7 @@ pub fn deactivate(constraint: *PointerConstraint) void {
}
fn warpToHintIfSet(constraint: *PointerConstraint) void {
const seat = @intToPtr(*Seat, constraint.wlr_constraint.seat.data);
const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
if (constraint.wlr_constraint.current.committed.cursor_hint) {
var lx: i32 = undefined;
@ -169,7 +169,7 @@ fn warpToHintIfSet(constraint: *PointerConstraint) void {
const sx = constraint.wlr_constraint.current.cursor_hint.x;
const sy = constraint.wlr_constraint.current.cursor_hint.y;
_ = seat.cursor.wlr_cursor.warp(null, @intToFloat(f64, lx) + sx, @intToFloat(f64, ly) + sy);
_ = seat.cursor.wlr_cursor.warp(null, @as(f64, @floatFromInt(lx)) + sx, @as(f64, @floatFromInt(ly)) + sy);
_ = seat.wlr_seat.pointerWarp(sx, sy);
}
}
@ -183,7 +183,7 @@ fn handleNodeDestroy(listener: *wl.Listener(void)) void {
fn handleDestroy(listener: *wl.Listener(*wlr.PointerConstraintV1), _: *wlr.PointerConstraintV1) void {
const constraint = @fieldParentPtr(PointerConstraint, "destroy", listener);
const seat = @intToPtr(*Seat, constraint.wlr_constraint.seat.data);
const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
if (constraint.state == .active) {
// We can't simply call deactivate() here as it calls sendDeactivated(),
@ -205,12 +205,12 @@ fn handleDestroy(listener: *wl.Listener(*wlr.PointerConstraintV1), _: *wlr.Point
fn handleSetRegion(listener: *wl.Listener(void)) void {
const constraint = @fieldParentPtr(PointerConstraint, "set_region", listener);
const seat = @intToPtr(*Seat, constraint.wlr_constraint.seat.data);
const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
switch (constraint.state) {
.active => |state| {
const sx = @floatToInt(i32, state.sx);
const sy = @floatToInt(i32, state.sy);
const sx: i32 = @intFromFloat(state.sx);
const sy: i32 = @intFromFloat(state.sy);
if (!constraint.wlr_constraint.region.containsPoint(sx, sy, null)) {
log.info("deactivating pointer constraint, region change left pointer outside constraint", .{});
constraint.deactivate();

View File

@ -52,7 +52,7 @@ pub fn init(
const arena_allocator = arena.allocator();
const owned_args = try arena_allocator.alloc([:0]const u8, command_args.len);
for (command_args) |arg, i| {
for (command_args, 0..) |arg, i| {
owned_args[i] = try arena_allocator.dupeZ(u8, arg);
}

View File

@ -312,7 +312,7 @@ pub fn deactivateOutput(root: *Self, output: *Output) void {
var it = tree.children.safeIterator(.forward);
while (it.next()) |scene_node| {
assert(scene_node.type == .tree);
if (@intToPtr(?*SceneNodeData, scene_node.data)) |node_data| {
if (@as(?*SceneNodeData, @ptrFromInt(scene_node.data))) |node_data| {
node_data.data.layer_surface.wlr_layer_surface.destroy();
}
}
@ -751,7 +751,7 @@ fn processOutputConfig(
var it = config.heads.iterator(.forward);
while (it.next()) |head| {
const wlr_output = head.state.output;
const output = @intToPtr(*Output, wlr_output.data);
const output: *Output = @ptrFromInt(wlr_output.data);
var proposed_state = wlr.Output.State.init();
head.state.apply(&proposed_state);

View File

@ -45,7 +45,7 @@ pub fn attach(node: *wlr.SceneNode, data: Data) error{OutOfMemory}!void {
.node = node,
.data = data,
};
node.data = @ptrToInt(scene_node_data);
node.data = @intFromPtr(scene_node_data);
node.events.destroy.add(&scene_node_data.destroy);
}
@ -53,7 +53,7 @@ pub fn attach(node: *wlr.SceneNode, data: Data) error{OutOfMemory}!void {
pub fn fromNode(node: *wlr.SceneNode) ?*SceneNodeData {
var it: ?*wlr.SceneNode = node;
while (it) |n| : (it = n.parent) {
if (@intToPtr(?*SceneNodeData, n.data)) |scene_node_data| {
if (@as(?*SceneNodeData, @ptrFromInt(n.data))) |scene_node_data| {
return scene_node_data;
}
}
@ -62,7 +62,7 @@ pub fn fromNode(node: *wlr.SceneNode) ?*SceneNodeData {
pub fn fromSurface(surface: *wlr.Surface) ?*SceneNodeData {
if (surface.getRootSurface()) |root_surface| {
if (@intToPtr(?*wlr.SceneNode, root_surface.data)) |node| {
if (@as(?*wlr.SceneNode, @ptrFromInt(root_surface.data))) |node| {
return fromNode(node);
}
}

View File

@ -107,7 +107,7 @@ pub fn init(self: *Self, name: [*:0]const u8) !void {
.wlr_seat = try wlr.Seat.create(server.wl_server, name),
.mapping_repeat_timer = mapping_repeat_timer,
};
self.wlr_seat.data = @ptrToInt(self);
self.wlr_seat.data = @intFromPtr(self);
try self.cursor.init(self);
@ -267,7 +267,8 @@ pub fn setFocusRaw(self: *Self, new_focus: FocusTarget) void {
if (self.cursor.constraint) |constraint| {
assert(constraint.wlr_constraint == wlr_constraint);
} else {
self.cursor.constraint = @intToPtr(*PointerConstraint, wlr_constraint.data);
self.cursor.constraint = @ptrFromInt(wlr_constraint.data);
assert(self.cursor.constraint != null);
}
}
}
@ -299,7 +300,7 @@ fn keyboardNotifyEnter(self: *Self, wlr_surface: *wlr.Surface) void {
.len = wlr_keyboard.num_keycodes,
};
const keyboard = @intToPtr(*Keyboard, wlr_keyboard.data);
const keyboard: *Keyboard = @ptrFromInt(wlr_keyboard.data);
keycodes.subtract(keyboard.eaten_keycodes);
self.wlr_seat.keyboardNotifyEnter(

View File

@ -214,7 +214,7 @@ fn handleNewToplevelDecoration(
_: *wl.Listener(*wlr.XdgToplevelDecorationV1),
wlr_decoration: *wlr.XdgToplevelDecorationV1,
) void {
const xdg_toplevel = @intToPtr(*XdgToplevel, wlr_decoration.surface.data);
const xdg_toplevel: *XdgToplevel = @ptrFromInt(wlr_decoration.surface.data);
// TODO(wlroots): The next wlroots version will handle this for us
if (xdg_toplevel.decoration != null) {
@ -236,7 +236,7 @@ fn handleNewLayerSurface(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_
.{
wlr_layer_surface.namespace,
@tagName(wlr_layer_surface.current.layer),
@bitCast(u32, wlr_layer_surface.current.anchor),
@as(u32, @bitCast(wlr_layer_surface.current.anchor)),
wlr_layer_surface.current.desired_width,
wlr_layer_surface.current.desired_height,
wlr_layer_surface.current.margin.top,

View File

@ -69,7 +69,7 @@ fn handleRequest(
.get_river_output_status => |req| {
// ignore if the output is inert
const wlr_output = wlr.Output.fromWlOutput(req.output) orelse return;
const output = @intToPtr(*Output, wlr_output.data);
const output: *Output = @ptrFromInt(wlr_output.data);
const resource = zriver.OutputStatusV1.create(
status_manager.getClient(),
@ -86,7 +86,7 @@ fn handleRequest(
.get_river_seat_status => |req| {
// ignore if the seat is inert
const wlr_seat = wlr.Seat.Client.fromWlSeat(req.seat) orelse return;
const seat = @intToPtr(*Seat, wlr_seat.seat.data);
const seat: *Seat = @ptrFromInt(wlr_seat.seat.data);
const node = util.gpa.create(std.SinglyLinkedList(SeatStatus).Node) catch {
status_manager.getClient().postNoMemory();

View File

@ -30,7 +30,7 @@ pub fn init(
) !Self {
const owned_args = try util.gpa.alloc([:0]u8, command_args.len);
errdefer util.gpa.free(owned_args);
for (command_args) |arg, i| {
for (command_args, 0..) |arg, i| {
errdefer for (owned_args[0..i]) |a| util.gpa.free(a);
owned_args[i] = try util.gpa.dupeZ(u8, arg);
}

View File

@ -54,5 +54,5 @@ pub fn direction(self: Vector) ?wlr.OutputLayout.Direction {
/// Returns the length of the vector.
pub fn length(self: Vector) u31 {
return math.sqrt(@intCast(u31, (self.x *| self.x) +| (self.y *| self.y)));
return math.sqrt(@as(u31, @intCast((self.x *| self.x) +| (self.y *| self.y))));
}

View File

@ -88,15 +88,15 @@ pub const State = struct {
const max_x = output_width - state.box.width - border_width;
state.box.x += delta_x;
state.box.x = math.max(state.box.x, border_width);
state.box.x = math.min(state.box.x, max_x);
state.box.x = math.max(state.box.x, 0);
state.box.x = @max(state.box.x, border_width);
state.box.x = @min(state.box.x, max_x);
state.box.x = @max(state.box.x, 0);
const max_y = output_height - state.box.height - border_width;
state.box.y += delta_y;
state.box.y = math.max(state.box.y, border_width);
state.box.y = math.min(state.box.y, max_y);
state.box.y = math.max(state.box.y, 0);
state.box.y = @max(state.box.y, border_width);
state.box.y = @min(state.box.y, max_y);
state.box.y = @max(state.box.y, 0);
}
pub fn clampToOutput(state: *State) void {
@ -107,8 +107,8 @@ pub const State = struct {
output.wlr_output.effectiveResolution(&output_width, &output_height);
const border_width = if (state.ssd) server.config.border_width else 0;
state.box.width = math.min(state.box.width, output_width - (2 * border_width));
state.box.height = math.min(state.box.height, output_height - (2 * border_width));
state.box.width = @min(state.box.width, output_width - (2 * border_width));
state.box.height = @min(state.box.height, output_height - (2 * border_width));
state.move(0, 0);
}
@ -504,8 +504,8 @@ pub fn map(view: *Self) !void {
if (server.input_manager.defaultSeat().focused_output) |output| {
// Center the initial pending box on the output
view.pending.box.x = @divTrunc(math.max(0, output.usable_box.width - view.pending.box.width), 2);
view.pending.box.y = @divTrunc(math.max(0, output.usable_box.height - view.pending.box.height), 2);
view.pending.box.x = @divTrunc(@max(0, output.usable_box.width - view.pending.box.width), 2);
view.pending.box.y = @divTrunc(@max(0, output.usable_box.height - view.pending.box.height), 2);
view.pending.tags = blk: {
if (server.config.tag_rules.match(view)) |tags| break :blk tags;

View File

@ -34,7 +34,7 @@ request_mode: wl.Listener(*wlr.XdgToplevelDecorationV1) =
wl.Listener(*wlr.XdgToplevelDecorationV1).init(handleRequestMode),
pub fn init(wlr_decoration: *wlr.XdgToplevelDecorationV1) void {
const xdg_toplevel = @intToPtr(*XdgToplevel, wlr_decoration.surface.data);
const xdg_toplevel: *XdgToplevel = @ptrFromInt(wlr_decoration.surface.data);
xdg_toplevel.decoration = .{ .wlr_decoration = wlr_decoration };
const decoration = &xdg_toplevel.decoration.?;
@ -64,7 +64,7 @@ fn handleDestroy(
_: *wlr.XdgToplevelDecorationV1,
) void {
const decoration = @fieldParentPtr(XdgDecoration, "destroy", listener);
const xdg_toplevel = @intToPtr(*XdgToplevel, decoration.wlr_decoration.surface.data);
const xdg_toplevel: *XdgToplevel = @ptrFromInt(decoration.wlr_decoration.surface.data);
decoration.deinit();
@ -78,7 +78,7 @@ fn handleRequestMode(
) void {
const decoration = @fieldParentPtr(XdgDecoration, "request_mode", listener);
const xdg_toplevel = @intToPtr(*XdgToplevel, decoration.wlr_decoration.surface.data);
const xdg_toplevel: *XdgToplevel = @ptrFromInt(decoration.wlr_decoration.surface.data);
const view = xdg_toplevel.view;
const ssd = server.config.ssd_rules.match(xdg_toplevel.view) orelse

View File

@ -85,8 +85,8 @@ pub fn create(xdg_toplevel: *wlr.XdgToplevel) error{OutOfMemory}!void {
self.view = view;
xdg_toplevel.base.data = @ptrToInt(self);
xdg_toplevel.base.surface.data = @ptrToInt(&view.tree.node);
xdg_toplevel.base.data = @intFromPtr(self);
xdg_toplevel.base.surface.data = @intFromPtr(&view.tree.node);
// Add listeners that are active over the toplevel's entire lifetime
xdg_toplevel.base.events.destroy.add(&self.destroy);
@ -307,10 +307,10 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
{
const state = &self.xdg_toplevel.current;
view.constraints = .{
.min_width = @intCast(u31, math.max(state.min_width, 1)),
.max_width = if (state.max_width > 0) @intCast(u31, state.max_width) else math.maxInt(u31),
.min_height = @intCast(u31, math.max(state.min_height, 1)),
.max_height = if (state.max_height > 0) @intCast(u31, state.max_height) else math.maxInt(u31),
.min_width = @max(state.min_width, 1),
.max_width = if (state.max_width > 0) @intCast(state.max_width) else math.maxInt(u31),
.min_height = @max(state.min_height, 1),
.max_height = if (state.max_height > 0) @intCast(state.max_height) else math.maxInt(u31),
};
}
@ -376,7 +376,7 @@ fn handleRequestMove(
event: *wlr.XdgToplevel.event.Move,
) void {
const self = @fieldParentPtr(Self, "request_move", listener);
const seat = @intToPtr(*Seat, event.seat.seat.data);
const seat: *Seat = @ptrFromInt(event.seat.seat.data);
const view = self.view;
if (view.current.output == null or view.pending.output == null) return;
@ -389,7 +389,7 @@ fn handleRequestMove(
fn handleRequestResize(listener: *wl.Listener(*wlr.XdgToplevel.event.Resize), event: *wlr.XdgToplevel.event.Resize) void {
const self = @fieldParentPtr(Self, "request_resize", listener);
const seat = @intToPtr(*Seat, event.seat.seat.data);
const seat: *Seat = @ptrFromInt(event.seat.seat.data);
const view = self.view;
{

View File

@ -93,7 +93,7 @@ fn mapImpl(self: *Self) error{OutOfMemory}!void {
self.surface_tree = try server.root.layers.xwayland_override_redirect.createSceneSubsurfaceTree(surface);
try SceneNodeData.attach(&self.surface_tree.?.node, .{ .xwayland_override_redirect = self });
surface.data = @ptrToInt(&self.surface_tree.?.node);
surface.data = @intFromPtr(&self.surface_tree.?.node);
self.surface_tree.?.node.setPosition(self.xwayland_surface.x, self.xwayland_surface.y);

View File

@ -102,10 +102,10 @@ pub fn configure(self: Self) bool {
}
self.xwayland_surface.configure(
@intCast(i16, inflight.box.x + output_box.x),
@intCast(i16, inflight.box.y + output_box.y),
@intCast(u16, inflight.box.width),
@intCast(u16, inflight.box.height),
@intCast(inflight.box.x + output_box.x),
@intCast(inflight.box.y + output_box.y),
@intCast(inflight.box.width),
@intCast(inflight.box.height),
);
self.setActivated(inflight.focus != 0);
@ -165,7 +165,7 @@ pub fn handleMap(listener: *wl.Listener(*wlr.XwaylandSurface), xwayland_surface:
const view = self.view;
const surface = xwayland_surface.surface.?;
surface.data = @ptrToInt(&view.tree.node);
surface.data = @intFromPtr(&view.tree.node);
// Add listeners that are only active while mapped
xwayland_surface.events.set_title.add(&self.set_title);

View File

@ -108,12 +108,12 @@ fn parseRgba(string: []const u8) ![4]f32 {
const b = try fmt.parseInt(u8, string[6..8], 16);
const a = if (string.len == 10) try fmt.parseInt(u8, string[8..10], 16) else 255;
const alpha = @intToFloat(f32, a) / 255.0;
const alpha = @as(f32, @floatFromInt(a)) / 255.0;
return [4]f32{
@intToFloat(f32, r) / 255.0 * alpha,
@intToFloat(f32, g) / 255.0 * alpha,
@intToFloat(f32, b) / 255.0 * alpha,
@as(f32, @floatFromInt(r)) / 255.0 * alpha,
@as(f32, @floatFromInt(g)) / 255.0 * alpha,
@as(f32, @floatFromInt(b)) / 255.0 * alpha,
alpha,
};
}

View File

@ -43,7 +43,7 @@ pub fn declareMode(
const owned_name = try util.gpa.dupeZ(u8, new_mode_name);
const id = @intCast(u32, config.modes.items.len);
const id: u32 = @intCast(config.modes.items.len);
config.mode_to_id.putAssumeCapacityNoClobber(owned_name, id);
config.modes.appendAssumeCapacity(.{ .name = owned_name });
}

View File

@ -55,7 +55,7 @@ pub fn listInputs(
});
}
out.* = input_list.toOwnedSlice();
out.* = try input_list.toOwnedSlice();
}
pub fn listInputConfigs(
@ -68,7 +68,7 @@ pub fn listInputConfigs(
var input_list = std.ArrayList(u8).init(util.gpa);
const writer = input_list.writer();
for (server.input_manager.configs.items) |*input_config, i| {
for (server.input_manager.configs.items, 0..) |*input_config, i| {
if (i > 0) try input_list.appendSlice("\n");
try writer.print("{s}\n", .{input_config.identifier});
@ -119,7 +119,7 @@ pub fn listInputConfigs(
}
}
out.* = input_list.toOwnedSlice();
out.* = try input_list.toOwnedSlice();
}
pub fn input(
@ -197,7 +197,7 @@ pub fn input(
} else if (mem.eql(u8, "scroll-button", args[2])) {
const ret = c.libevdev_event_code_from_name(c.EV_KEY, args[3].ptr);
if (ret < 1) return Error.InvalidButton;
input_config.scroll_button = InputConfig.ScrollButton{ .button = @intCast(u32, ret) };
input_config.scroll_button = InputConfig.ScrollButton{ .button = @intCast(ret) };
} else {
return Error.UnknownCommand;
}

View File

@ -200,7 +200,7 @@ fn mappingExists(
keysym: xkb.Keysym,
release: bool,
) ?usize {
for (mappings.items) |mapping, i| {
for (mappings.items, 0..) |mapping, i| {
if (meta.eql(mapping.modifiers, modifiers) and
mapping.keysym == keysym and mapping.options.release == release)
{
@ -217,7 +217,7 @@ fn switchMappingExists(
switch_type: Switch.Type,
switch_state: Switch.State,
) ?usize {
for (switch_mappings.items) |mapping, i| {
for (switch_mappings.items, 0..) |mapping, i| {
if (mapping.switch_type == switch_type and meta.eql(mapping.switch_state, switch_state)) {
return i;
}
@ -232,7 +232,7 @@ fn pointerMappingExists(
modifiers: wlr.Keyboard.ModifierMask,
event_code: u32,
) ?usize {
for (pointer_mappings.items) |mapping, i| {
for (pointer_mappings.items, 0..) |mapping, i| {
if (meta.eql(mapping.modifiers, modifiers) and mapping.event_code == event_code) {
return i;
}
@ -248,7 +248,7 @@ fn parseEventCode(name: [:0]const u8, out: *?[]const u8) !u32 {
return Error.Other;
}
return @intCast(u32, event_code);
return @intCast(event_code);
}
fn parseKeysym(name: [:0]const u8, out: *?[]const u8) !xkb.Keysym {

View File

@ -104,7 +104,7 @@ pub fn resize(
// up against an output edge.
const diff_width = prev_width - view.pending.box.width;
// Do not grow bigger than the output
view.pending.box.width = math.min(
view.pending.box.width = @min(
view.pending.box.width,
output_width - 2 * server.config.border_width,
);
@ -116,7 +116,7 @@ pub fn resize(
view.applyConstraints(&view.pending.box);
const diff_height = prev_height - view.pending.box.height;
// Do not grow bigger than the output
view.pending.box.height = math.min(
view.pending.box.height = @min(
view.pending.box.height,
output_height - 2 * server.config.border_width,
);

View File

@ -109,15 +109,15 @@ fn getOutput(seat: *Seat, str: []const u8) !?*Output {
const wlr_output = server.root.output_layout.adjacentOutput(
direction,
seat.focused_output.?.wlr_output,
@intToFloat(f64, focus_box.x + @divTrunc(focus_box.width, 2)),
@intToFloat(f64, focus_box.y + @divTrunc(focus_box.height, 2)),
@floatFromInt(focus_box.x + @divTrunc(focus_box.width, 2)),
@floatFromInt(focus_box.y + @divTrunc(focus_box.height, 2)),
) orelse return null;
return @intToPtr(*Output, wlr_output.data);
return @as(*Output, @ptrFromInt(wlr_output.data));
} else {
// Check if an output matches by name
var it = server.root.active_outputs.iterator(.forward);
while (it.next()) |output| {
if (mem.eql(u8, mem.span(output.wlr_output.name), str)) {
if (mem.eql(u8, mem.sliceTo(output.wlr_output.name, 0), str)) {
return output;
}
}

View File

@ -157,8 +157,8 @@ pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error!
var buffer = std.ArrayList(u8).init(util.gpa);
const writer = buffer.writer();
try fmt.formatBuf("title", .{ .width = title_column_max, .alignment = .Left }, writer);
try fmt.formatBuf("app-id", .{ .width = app_id_column_max, .alignment = .Left }, writer);
try fmt.formatBuf("title", .{ .width = title_column_max, .alignment = .left }, writer);
try fmt.formatBuf("app-id", .{ .width = app_id_column_max, .alignment = .left }, writer);
try writer.writeAll("action\n");
switch (list) {
@ -169,8 +169,8 @@ pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error!
else => unreachable,
};
for (rules) |rule| {
try fmt.formatBuf(rule.title_glob, .{ .width = title_column_max, .alignment = .Left }, writer);
try fmt.formatBuf(rule.app_id_glob, .{ .width = app_id_column_max, .alignment = .Left }, writer);
try fmt.formatBuf(rule.title_glob, .{ .width = title_column_max, .alignment = .left }, writer);
try fmt.formatBuf(rule.app_id_glob, .{ .width = app_id_column_max, .alignment = .left }, writer);
try writer.print("{s}\n", .{switch (list) {
.float => if (rule.value) "float" else "no-float",
.ssd => if (rule.value) "ssd" else "csd",
@ -181,12 +181,12 @@ pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error!
.tag => {
const rules = server.config.tag_rules.rules.items;
for (rules) |rule| {
try fmt.formatBuf(rule.title_glob, .{ .width = title_column_max, .alignment = .Left }, writer);
try fmt.formatBuf(rule.app_id_glob, .{ .width = app_id_column_max, .alignment = .Left }, writer);
try fmt.formatBuf(rule.title_glob, .{ .width = title_column_max, .alignment = .left }, writer);
try fmt.formatBuf(rule.app_id_glob, .{ .width = app_id_column_max, .alignment = .left }, writer);
try writer.print("{b}\n", .{rule.value});
}
},
}
out.* = buffer.toOwnedSlice();
out.* = try buffer.toOwnedSlice();
}

View File

@ -175,7 +175,7 @@ pub fn log(
comptime format: []const u8,
args: anytype,
) void {
if (@enumToInt(level) > @enumToInt(runtime_log_level)) return;
if (@intFromEnum(level) > @intFromEnum(runtime_log_level)) return;
const scope_prefix = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";

View File

@ -50,7 +50,7 @@ pub fn RuleList(comptime T: type) type {
}
pub fn add(list: *Self, rule: Rule) error{OutOfMemory}!void {
const index = for (list.rules.items) |*existing, i| {
const index = for (list.rules.items, 0..) |*existing, i| {
if (mem.eql(u8, rule.app_id_glob, existing.app_id_glob) and
mem.eql(u8, rule.title_glob, existing.title_glob))
{
@ -83,7 +83,7 @@ pub fn RuleList(comptime T: type) type {
}
pub fn del(list: *Self, rule: struct { app_id_glob: []const u8, title_glob: []const u8 }) void {
for (list.rules.items) |existing, i| {
for (list.rules.items, 0..) |existing, i| {
if (mem.eql(u8, rule.app_id_glob, existing.app_id_glob) and
mem.eql(u8, rule.title_glob, existing.title_glob))
{

View File

@ -1,6 +1,7 @@
#include <assert.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <wlr/util/log.h>