From 74baf7225ad95f8288f5dc1fe50345425cd62f71 Mon Sep 17 00:00:00 2001 From: leviathan <1041281842@qq.com> Date: Mon, 1 Apr 2024 11:37:30 +0800 Subject: [PATCH 01/13] input-method-v2: Implement popups --- river/InputMethodPopup.zig | 232 +++++++++++++++++++++++++++++++++++++ river/InputRelay.zig | 27 ++++- river/XwaylandView.zig | 1 + 3 files changed, 258 insertions(+), 2 deletions(-) create mode 100644 river/InputMethodPopup.zig diff --git a/river/InputMethodPopup.zig b/river/InputMethodPopup.zig new file mode 100644 index 0000000..8719b1c --- /dev/null +++ b/river/InputMethodPopup.zig @@ -0,0 +1,232 @@ +// This file is part of river, a dynamic tiling wayland compositor. +// +// Copyright 2024 The River Developers +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +const InputMethodPopup = @This(); + +const build_options = @import("build_options"); +const std = @import("std"); +const assert = std.debug.assert; +const mem = std.mem; +const wlr = @import("wlroots"); +const wl = @import("wayland").server.wl; +const server = &@import("main.zig").server; + +const util = @import("util.zig"); +const InputRelay = @import("InputRelay.zig"); +const TextInput = @import("TextInput.zig"); +const Root = @import("Root.zig"); +const View = @import("View.zig"); +const LayerSurface = @import("LayerSurface.zig"); +const XdgToplevel = @import("XdgToplevel.zig"); +const XwaylandView = @import("XwaylandView.zig"); + +const log = std.log.scoped(.input_method_popup); + +link: wl.list.Link, +scene_tree: ?*wlr.SceneTree = null, +parent_scene_tree: ?*wlr.SceneTree = null, +scene_surface: ?*wlr.SceneTree = null, +view: ?*View = null, + +input_relay: *InputRelay, +wlr_input_popup_surface: *wlr.InputPopupSurfaceV2, + +popup_surface_commit: wl.Listener(*wlr.Surface) = + wl.Listener(*wlr.Surface).init(handlePopupSurfaceCommit), + +popup_surface_map: wl.Listener(void) = + wl.Listener(void).init(handlePopupSurfaceMap), + +popup_surface_unmap: wl.Listener(void) = + wl.Listener(void).init(handlePopupSurfaceUnmap), +popup_destroy: wl.Listener(void) = + wl.Listener(void).init(handlePopupDestroy), + +pub fn create(wlr_input_popup_surface: *wlr.InputPopupSurfaceV2, input_relay: *InputRelay) !void { + const input_method_popup = try util.gpa.create(InputMethodPopup); + errdefer util.gpa.destroy(input_method_popup); + log.debug("new input_method_pupup", .{}); + input_method_popup.* = .{ + .link = undefined, + .input_relay = input_relay, + .wlr_input_popup_surface = wlr_input_popup_surface, + }; + + input_method_popup.wlr_input_popup_surface.events.destroy.add(&input_method_popup.popup_destroy); + input_method_popup.wlr_input_popup_surface.surface.events.map.add(&input_method_popup.popup_surface_map); + input_method_popup.wlr_input_popup_surface.surface.events.unmap.add(&input_method_popup.popup_surface_unmap); + input_method_popup.wlr_input_popup_surface.surface.events.commit.add(&input_method_popup.popup_surface_commit); + input_relay.input_method_popups.append(input_method_popup); + input_method_popup.updatePopup(); +} + +fn handlePopupDestroy(listener: *wl.Listener(void)) void { + log.debug("destroy ime_popup", .{}); + const input_method_popup = @fieldParentPtr(InputMethodPopup, "popup_destroy", listener); + input_method_popup.popup_surface_map.link.remove(); + input_method_popup.popup_surface_unmap.link.remove(); + input_method_popup.popup_surface_commit.link.remove(); + input_method_popup.popup_destroy.link.remove(); + input_method_popup.link.remove(); + util.gpa.destroy(input_method_popup); +} + +fn handlePopupSurfaceCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { + log.debug("popup surface commit", .{}); + const input_method_popup = @fieldParentPtr(InputMethodPopup, "popup_surface_commit", listener); + input_method_popup.updatePopup(); +} + +fn handlePopupSurfaceMap(listener: *wl.Listener(void)) void { + log.debug("popup surface map", .{}); + const input_method_popup = @fieldParentPtr(InputMethodPopup, "popup_surface_map", listener); + input_method_popup.updatePopup(); +} + +fn handlePopupSurfaceUnmap(listener: *wl.Listener(void)) void { + log.debug("popup surface unmap", .{}); + const input_method_popup = @fieldParentPtr(InputMethodPopup, "popup_surface_unmap", listener); + input_method_popup.scene_tree.?.node.destroy(); + input_method_popup.scene_tree = null; +} + +pub fn updatePopup(input_method_popup: *InputMethodPopup) void { + log.debug("update ime_popup", .{}); + var text_input = input_method_popup.getTextInputFocused() orelse return; + const focused_surface = text_input.wlr_text_input.focused_surface orelse return; + + if (!input_method_popup.wlr_input_popup_surface.surface.mapped) { + return; + } + + var output_box: wlr.Box = undefined; + var parent: wlr.Box = undefined; + + input_method_popup.getParentAndOutputBox(focused_surface, &parent, &output_box); + + var cursor_rect = if (text_input.wlr_text_input.current.features.cursor_rectangle) + text_input.wlr_text_input.current.cursor_rectangle + else + wlr.Box{ + .x = 0, + .y = 0, + .width = parent.width, + .height = parent.height, + }; + + const popup_width = input_method_popup.wlr_input_popup_surface.surface.current.width; + const popup_height = input_method_popup.wlr_input_popup_surface.surface.current.height; + + const cursor_rect_left = parent.x + cursor_rect.x; + const popup_anchor_left = blk: { + const cursor_rect_right = cursor_rect_left + cursor_rect.width; + const available_right_of_cursor = output_box.x + output_box.width - cursor_rect_left; + const available_left_of_cursor = cursor_rect_right - output_box.x; + if (available_right_of_cursor < popup_width and available_left_of_cursor > popup_width) { + break :blk cursor_rect_right - popup_width; + } else { + break :blk cursor_rect_left; + } + }; + + const cursor_rect_up = parent.y + cursor_rect.y; + const popup_anchor_up = blk: { + const cursor_rect_down = cursor_rect_up + cursor_rect.height; + const available_down_of_cursor = output_box.y + output_box.height - cursor_rect_down; + const available_up_of_cursor = cursor_rect_up - output_box.y; + if (available_down_of_cursor < popup_height and available_up_of_cursor > popup_height) { + break :blk cursor_rect_up - popup_height; + } else { + break :blk cursor_rect_down; + } + }; + + if (text_input.wlr_text_input.current.features.cursor_rectangle) { + var box = wlr.Box{ + .x = cursor_rect_left - popup_anchor_left, + .y = cursor_rect_up - popup_anchor_up, + .width = cursor_rect.width, + .height = cursor_rect.height, + }; + input_method_popup.wlr_input_popup_surface.sendTextInputRectangle(&box); + } + + if (input_method_popup.scene_tree == null) { + input_method_popup.scene_tree = input_method_popup.parent_scene_tree.?.createSceneTree() catch { + log.err("out of memory", .{}); + return; + }; + + input_method_popup.scene_surface = input_method_popup.scene_tree.? + .createSceneSubsurfaceTree( + input_method_popup.wlr_input_popup_surface.surface, + ) catch { + log.err("failed to create subsurface tree", .{}); + input_method_popup.wlr_input_popup_surface.surface.resource.getClient().postNoMemory(); + return; + }; + } + input_method_popup.scene_tree.?.node.setPosition(popup_anchor_left - parent.x, popup_anchor_up - parent.y); +} + +pub fn getTextInputFocused(input_method_popup: *InputMethodPopup) ?*TextInput { + var it = input_method_popup.input_relay.text_inputs.iterator(.forward); + while (it.next()) |text_input| { + if (text_input.wlr_text_input.focused_surface != null) return text_input; + } + return null; +} + +pub fn getParentAndOutputBox( + input_method_popup: *InputMethodPopup, + focused_surface: *wlr.Surface, + parent: *wlr.Box, + output_box: *wlr.Box, +) void { + if (wlr.LayerSurfaceV1.tryFromWlrSurface(focused_surface)) |wlr_layer_surface| { + const layer_surface: *LayerSurface = @ptrFromInt(wlr_layer_surface.data); + input_method_popup.parent_scene_tree = layer_surface.popup_tree; + const output = layer_surface.output.wlr_output; + server.root.output_layout.getBox(output, output_box); + _ = layer_surface.popup_tree.node.coords(&parent.x, &parent.y); + } else { + const view = getViewFromWlrSurface(focused_surface) orelse return; + input_method_popup.parent_scene_tree = view.tree; + _ = view.tree.node.coords(&parent.x, &parent.y); + const output = view.current.output orelse return; + server.root.output_layout.getBox(output.wlr_output, output_box); + parent.width = view.current.box.width; + parent.height = view.current.box.height; + } +} + +fn getViewFromWlrSurface(wlr_surface: *wlr.Surface) ?*View { + if (wlr.XdgSurface.tryFromWlrSurface(wlr_surface)) |xdg_surface| { + const xdg_toplevel: *XdgToplevel = @ptrFromInt(xdg_surface.data); + return xdg_toplevel.view; + } + if (build_options.xwayland) { + if (wlr.XwaylandSurface.tryFromWlrSurface(wlr_surface)) |xwayland_surface| { + const xwayland_view: *XwaylandView = @ptrFromInt(xwayland_surface.data); + return xwayland_view.view; + } + } + if (wlr.Subsurface.tryFromWlrSurface(wlr_surface)) |wlr_subsurface| { + if (wlr_subsurface.parent) |parent| return getViewFromWlrSurface(parent); + } + return null; +} diff --git a/river/InputRelay.zig b/river/InputRelay.zig index d70d447..6bfcf27 100644 --- a/river/InputRelay.zig +++ b/river/InputRelay.zig @@ -26,6 +26,7 @@ const wl = @import("wayland").server.wl; const util = @import("util.zig"); const TextInput = @import("TextInput.zig"); +const InputMethodPopup = @import("InputMethodPopup.zig"); const Seat = @import("Seat.zig"); const log = std.log.scoped(.input_relay); @@ -40,6 +41,7 @@ text_inputs: wl.list.Head(TextInput, .link), /// already in use new input methods are ignored. /// If this is null, no text input enter events will be sent. input_method: ?*wlr.InputMethodV2 = null, +input_method_popups: wl.list.Head(InputMethodPopup, .link), /// The currently enabled text input for the currently focused surface. /// Always null if there is no input method. text_input: ?*TextInput = null, @@ -50,14 +52,17 @@ grab_keyboard: wl.Listener(*wlr.InputMethodV2.KeyboardGrab) = wl.Listener(*wlr.InputMethodV2.KeyboardGrab).init(handleInputMethodGrabKeyboard), input_method_destroy: wl.Listener(*wlr.InputMethodV2) = wl.Listener(*wlr.InputMethodV2).init(handleInputMethodDestroy), +input_method_new_popup_surface: wl.Listener(*wlr.InputPopupSurfaceV2) = + wl.Listener(*wlr.InputPopupSurfaceV2).init(handleInputMethodNewPopupSurface), grab_keyboard_destroy: wl.Listener(*wlr.InputMethodV2.KeyboardGrab) = wl.Listener(*wlr.InputMethodV2.KeyboardGrab).init(handleInputMethodGrabKeyboardDestroy), pub fn init(relay: *InputRelay) void { - relay.* = .{ .text_inputs = undefined }; + relay.* = .{ .text_inputs = undefined, .input_method_popups = undefined }; relay.text_inputs.init(); + relay.input_method_popups.init(); } pub fn newInputMethod(relay: *InputRelay, input_method: *wlr.InputMethodV2) void { @@ -77,6 +82,7 @@ pub fn newInputMethod(relay: *InputRelay, input_method: *wlr.InputMethodV2) void input_method.events.commit.add(&relay.input_method_commit); input_method.events.grab_keyboard.add(&relay.grab_keyboard); input_method.events.destroy.add(&relay.input_method_destroy); + input_method.events.new_popup_surface.add(&relay.input_method_new_popup_surface); if (seat.focused.surface()) |surface| { relay.focus(surface); @@ -127,7 +133,7 @@ fn handleInputMethodDestroy( relay.input_method_commit.link.remove(); relay.grab_keyboard.link.remove(); relay.input_method_destroy.link.remove(); - + relay.input_method_new_popup_surface.link.remove(); relay.input_method = null; relay.focus(null); @@ -148,6 +154,18 @@ fn handleInputMethodGrabKeyboard( keyboard_grab.events.destroy.add(&relay.grab_keyboard_destroy); } +fn handleInputMethodNewPopupSurface( + listener: *wl.Listener(*wlr.InputPopupSurfaceV2), + input_method_new_popup_surface: *wlr.InputPopupSurfaceV2, +) void { + log.debug("new input_method_popup_surface", .{}); + const relay = @fieldParentPtr(InputRelay, "input_method_new_popup_surface", listener); + InputMethodPopup.create(input_method_new_popup_surface, relay) catch { + log.err("out of memory", .{}); + return; + }; +} + fn handleInputMethodGrabKeyboardDestroy( listener: *wl.Listener(*wlr.InputMethodV2.KeyboardGrab), keyboard_grab: *wlr.InputMethodV2.KeyboardGrab, @@ -197,6 +215,11 @@ pub fn sendInputMethodState(relay: *InputRelay) void { ); } + // Update input popups + var it = relay.input_method_popups.iterator(.forward); + while (it.next()) |popup| { + popup.updatePopup(); + } input_method.sendDone(); } diff --git a/river/XwaylandView.zig b/river/XwaylandView.zig index 7155868..d85e45a 100644 --- a/river/XwaylandView.zig +++ b/river/XwaylandView.zig @@ -163,6 +163,7 @@ pub fn handleMap(listener: *wl.Listener(void)) void { const view = xwayland_view.view; const xwayland_surface = xwayland_view.xwayland_surface; + xwayland_surface.data = @intFromPtr(xwayland_view); const surface = xwayland_surface.surface.?; surface.data = @intFromPtr(&view.tree.node); From ba6023e38a965d80788a3de33d6c19968db03647 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Wed, 15 May 2024 11:50:58 +0200 Subject: [PATCH 02/13] InputPopup: fix naming --- .../{InputMethodPopup.zig => InputPopup.zig} | 133 +++++++++--------- river/InputRelay.zig | 14 +- 2 files changed, 72 insertions(+), 75 deletions(-) rename river/{InputMethodPopup.zig => InputPopup.zig} (55%) diff --git a/river/InputMethodPopup.zig b/river/InputPopup.zig similarity index 55% rename from river/InputMethodPopup.zig rename to river/InputPopup.zig index 8719b1c..57ea2d9 100644 --- a/river/InputMethodPopup.zig +++ b/river/InputPopup.zig @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -const InputMethodPopup = @This(); +const InputPopup = @This(); const build_options = @import("build_options"); const std = @import("std"); @@ -34,8 +34,6 @@ const LayerSurface = @import("LayerSurface.zig"); const XdgToplevel = @import("XdgToplevel.zig"); const XwaylandView = @import("XwaylandView.zig"); -const log = std.log.scoped(.input_method_popup); - link: wl.list.Link, scene_tree: ?*wlr.SceneTree = null, parent_scene_tree: ?*wlr.SceneTree = null, @@ -43,80 +41,79 @@ scene_surface: ?*wlr.SceneTree = null, view: ?*View = null, input_relay: *InputRelay, -wlr_input_popup_surface: *wlr.InputPopupSurfaceV2, +wlr_popup: *wlr.InputPopupSurfaceV2, -popup_surface_commit: wl.Listener(*wlr.Surface) = - wl.Listener(*wlr.Surface).init(handlePopupSurfaceCommit), +destroy: wl.Listener(void) = + wl.Listener(void).init(handleDestroy), +map: wl.Listener(void) = + wl.Listener(void).init(handleMap), +unmap: wl.Listener(void) = + wl.Listener(void).init(handleUnmap), +commit: wl.Listener(*wlr.Surface) = + wl.Listener(*wlr.Surface).init(handleCommit), -popup_surface_map: wl.Listener(void) = - wl.Listener(void).init(handlePopupSurfaceMap), +pub fn create(wlr_popup: *wlr.InputPopupSurfaceV2, input_relay: *InputRelay) !void { + const input_popup = try util.gpa.create(InputPopup); + errdefer util.gpa.destroy(input_popup); -popup_surface_unmap: wl.Listener(void) = - wl.Listener(void).init(handlePopupSurfaceUnmap), -popup_destroy: wl.Listener(void) = - wl.Listener(void).init(handlePopupDestroy), - -pub fn create(wlr_input_popup_surface: *wlr.InputPopupSurfaceV2, input_relay: *InputRelay) !void { - const input_method_popup = try util.gpa.create(InputMethodPopup); - errdefer util.gpa.destroy(input_method_popup); - log.debug("new input_method_pupup", .{}); - input_method_popup.* = .{ + input_popup.* = .{ .link = undefined, .input_relay = input_relay, - .wlr_input_popup_surface = wlr_input_popup_surface, + .wlr_popup = wlr_popup, }; - input_method_popup.wlr_input_popup_surface.events.destroy.add(&input_method_popup.popup_destroy); - input_method_popup.wlr_input_popup_surface.surface.events.map.add(&input_method_popup.popup_surface_map); - input_method_popup.wlr_input_popup_surface.surface.events.unmap.add(&input_method_popup.popup_surface_unmap); - input_method_popup.wlr_input_popup_surface.surface.events.commit.add(&input_method_popup.popup_surface_commit); - input_relay.input_method_popups.append(input_method_popup); - input_method_popup.updatePopup(); + input_popup.wlr_popup.events.destroy.add(&input_popup.destroy); + input_popup.wlr_popup.surface.events.map.add(&input_popup.map); + input_popup.wlr_popup.surface.events.unmap.add(&input_popup.unmap); + input_popup.wlr_popup.surface.events.commit.add(&input_popup.commit); + + input_relay.input_popups.append(input_popup); + input_popup.update(); } -fn handlePopupDestroy(listener: *wl.Listener(void)) void { - log.debug("destroy ime_popup", .{}); - const input_method_popup = @fieldParentPtr(InputMethodPopup, "popup_destroy", listener); - input_method_popup.popup_surface_map.link.remove(); - input_method_popup.popup_surface_unmap.link.remove(); - input_method_popup.popup_surface_commit.link.remove(); - input_method_popup.popup_destroy.link.remove(); - input_method_popup.link.remove(); - util.gpa.destroy(input_method_popup); +fn handleDestroy(listener: *wl.Listener(void)) void { + const input_popup = @fieldParentPtr(InputPopup, "destroy", listener); + + input_popup.map.link.remove(); + input_popup.unmap.link.remove(); + input_popup.commit.link.remove(); + input_popup.destroy.link.remove(); + input_popup.link.remove(); + + util.gpa.destroy(input_popup); } -fn handlePopupSurfaceCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { - log.debug("popup surface commit", .{}); - const input_method_popup = @fieldParentPtr(InputMethodPopup, "popup_surface_commit", listener); - input_method_popup.updatePopup(); +fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { + const input_popup = @fieldParentPtr(InputPopup, "commit", listener); + + input_popup.update(); } -fn handlePopupSurfaceMap(listener: *wl.Listener(void)) void { - log.debug("popup surface map", .{}); - const input_method_popup = @fieldParentPtr(InputMethodPopup, "popup_surface_map", listener); - input_method_popup.updatePopup(); +fn handleMap(listener: *wl.Listener(void)) void { + const input_popup = @fieldParentPtr(InputPopup, "map", listener); + + input_popup.update(); } -fn handlePopupSurfaceUnmap(listener: *wl.Listener(void)) void { - log.debug("popup surface unmap", .{}); - const input_method_popup = @fieldParentPtr(InputMethodPopup, "popup_surface_unmap", listener); - input_method_popup.scene_tree.?.node.destroy(); - input_method_popup.scene_tree = null; +fn handleUnmap(listener: *wl.Listener(void)) void { + const input_popup = @fieldParentPtr(InputPopup, "unmap", listener); + + input_popup.scene_tree.?.node.destroy(); + input_popup.scene_tree = null; } -pub fn updatePopup(input_method_popup: *InputMethodPopup) void { - log.debug("update ime_popup", .{}); - var text_input = input_method_popup.getTextInputFocused() orelse return; +pub fn update(input_popup: *InputPopup) void { + var text_input = input_popup.getTextInputFocused() orelse return; const focused_surface = text_input.wlr_text_input.focused_surface orelse return; - if (!input_method_popup.wlr_input_popup_surface.surface.mapped) { + if (!input_popup.wlr_popup.surface.mapped) { return; } var output_box: wlr.Box = undefined; var parent: wlr.Box = undefined; - input_method_popup.getParentAndOutputBox(focused_surface, &parent, &output_box); + input_popup.getParentAndOutputBox(focused_surface, &parent, &output_box); var cursor_rect = if (text_input.wlr_text_input.current.features.cursor_rectangle) text_input.wlr_text_input.current.cursor_rectangle @@ -128,8 +125,8 @@ pub fn updatePopup(input_method_popup: *InputMethodPopup) void { .height = parent.height, }; - const popup_width = input_method_popup.wlr_input_popup_surface.surface.current.width; - const popup_height = input_method_popup.wlr_input_popup_surface.surface.current.height; + const popup_width = input_popup.wlr_popup.surface.current.width; + const popup_height = input_popup.wlr_popup.surface.current.height; const cursor_rect_left = parent.x + cursor_rect.x; const popup_anchor_left = blk: { @@ -162,29 +159,29 @@ pub fn updatePopup(input_method_popup: *InputMethodPopup) void { .width = cursor_rect.width, .height = cursor_rect.height, }; - input_method_popup.wlr_input_popup_surface.sendTextInputRectangle(&box); + input_popup.wlr_popup.sendTextInputRectangle(&box); } - if (input_method_popup.scene_tree == null) { - input_method_popup.scene_tree = input_method_popup.parent_scene_tree.?.createSceneTree() catch { - log.err("out of memory", .{}); + if (input_popup.scene_tree == null) { + input_popup.scene_tree = input_popup.parent_scene_tree.?.createSceneTree() catch { + std.log.err("out of memory", .{}); return; }; - input_method_popup.scene_surface = input_method_popup.scene_tree.? + input_popup.scene_surface = input_popup.scene_tree.? .createSceneSubsurfaceTree( - input_method_popup.wlr_input_popup_surface.surface, + input_popup.wlr_popup.surface, ) catch { - log.err("failed to create subsurface tree", .{}); - input_method_popup.wlr_input_popup_surface.surface.resource.getClient().postNoMemory(); + std.log.err("out of memory", .{}); + input_popup.wlr_popup.surface.resource.getClient().postNoMemory(); return; }; } - input_method_popup.scene_tree.?.node.setPosition(popup_anchor_left - parent.x, popup_anchor_up - parent.y); + input_popup.scene_tree.?.node.setPosition(popup_anchor_left - parent.x, popup_anchor_up - parent.y); } -pub fn getTextInputFocused(input_method_popup: *InputMethodPopup) ?*TextInput { - var it = input_method_popup.input_relay.text_inputs.iterator(.forward); +pub fn getTextInputFocused(input_popup: *InputPopup) ?*TextInput { + var it = input_popup.input_relay.text_inputs.iterator(.forward); while (it.next()) |text_input| { if (text_input.wlr_text_input.focused_surface != null) return text_input; } @@ -192,20 +189,20 @@ pub fn getTextInputFocused(input_method_popup: *InputMethodPopup) ?*TextInput { } pub fn getParentAndOutputBox( - input_method_popup: *InputMethodPopup, + input_popup: *InputPopup, focused_surface: *wlr.Surface, parent: *wlr.Box, output_box: *wlr.Box, ) void { if (wlr.LayerSurfaceV1.tryFromWlrSurface(focused_surface)) |wlr_layer_surface| { const layer_surface: *LayerSurface = @ptrFromInt(wlr_layer_surface.data); - input_method_popup.parent_scene_tree = layer_surface.popup_tree; + input_popup.parent_scene_tree = layer_surface.popup_tree; const output = layer_surface.output.wlr_output; server.root.output_layout.getBox(output, output_box); _ = layer_surface.popup_tree.node.coords(&parent.x, &parent.y); } else { const view = getViewFromWlrSurface(focused_surface) orelse return; - input_method_popup.parent_scene_tree = view.tree; + input_popup.parent_scene_tree = view.tree; _ = view.tree.node.coords(&parent.x, &parent.y); const output = view.current.output orelse return; server.root.output_layout.getBox(output.wlr_output, output_box); diff --git a/river/InputRelay.zig b/river/InputRelay.zig index 6bfcf27..ae84582 100644 --- a/river/InputRelay.zig +++ b/river/InputRelay.zig @@ -26,7 +26,7 @@ const wl = @import("wayland").server.wl; const util = @import("util.zig"); const TextInput = @import("TextInput.zig"); -const InputMethodPopup = @import("InputMethodPopup.zig"); +const InputPopup = @import("InputPopup.zig"); const Seat = @import("Seat.zig"); const log = std.log.scoped(.input_relay); @@ -41,7 +41,7 @@ text_inputs: wl.list.Head(TextInput, .link), /// already in use new input methods are ignored. /// If this is null, no text input enter events will be sent. input_method: ?*wlr.InputMethodV2 = null, -input_method_popups: wl.list.Head(InputMethodPopup, .link), +input_popups: wl.list.Head(InputPopup, .link), /// The currently enabled text input for the currently focused surface. /// Always null if there is no input method. text_input: ?*TextInput = null, @@ -59,10 +59,10 @@ grab_keyboard_destroy: wl.Listener(*wlr.InputMethodV2.KeyboardGrab) = wl.Listener(*wlr.InputMethodV2.KeyboardGrab).init(handleInputMethodGrabKeyboardDestroy), pub fn init(relay: *InputRelay) void { - relay.* = .{ .text_inputs = undefined, .input_method_popups = undefined }; + relay.* = .{ .text_inputs = undefined, .input_popups = undefined }; relay.text_inputs.init(); - relay.input_method_popups.init(); + relay.input_popups.init(); } pub fn newInputMethod(relay: *InputRelay, input_method: *wlr.InputMethodV2) void { @@ -160,7 +160,7 @@ fn handleInputMethodNewPopupSurface( ) void { log.debug("new input_method_popup_surface", .{}); const relay = @fieldParentPtr(InputRelay, "input_method_new_popup_surface", listener); - InputMethodPopup.create(input_method_new_popup_surface, relay) catch { + InputPopup.create(input_method_new_popup_surface, relay) catch { log.err("out of memory", .{}); return; }; @@ -216,9 +216,9 @@ pub fn sendInputMethodState(relay: *InputRelay) void { } // Update input popups - var it = relay.input_method_popups.iterator(.forward); + var it = relay.input_popups.iterator(.forward); while (it.next()) |popup| { - popup.updatePopup(); + popup.update(); } input_method.sendDone(); } From b35a40b9dfa3e70dbdc11e8383c584164b475420 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Wed, 15 May 2024 12:21:22 +0200 Subject: [PATCH 03/13] TextInput: ignore enable requests without focus --- river/TextInput.zig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/river/TextInput.zig b/river/TextInput.zig index 2b6af49..d513758 100644 --- a/river/TextInput.zig +++ b/river/TextInput.zig @@ -66,6 +66,11 @@ fn handleEnable(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) v const text_input = @fieldParentPtr(TextInput, "enable", listener); const seat: *Seat = @ptrFromInt(text_input.wlr_text_input.seat.data); + if (text_input.wlr_text_input.focused_surface == null) { + log.err("client requested to enable text input without focus, ignoring request", .{}); + return; + } + // The same text_input object may be enabled multiple times consecutively // without first disabling it. Enabling a different text input object without // first disabling the current one is disallowed by the protocol however. From c75d32c88b2fda71b543b72e02117cdfb7693e2e Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Wed, 15 May 2024 18:04:53 +0200 Subject: [PATCH 04/13] InputPopup: fix minor issues, simplify code --- deps/zig-wlroots | 2 +- river/InputPopup.zig | 233 +++++++++++++++++----------------------- river/InputRelay.zig | 33 +++--- river/Output.zig | 2 +- river/SceneNodeData.zig | 7 +- river/XwaylandView.zig | 1 - 6 files changed, 119 insertions(+), 159 deletions(-) diff --git a/deps/zig-wlroots b/deps/zig-wlroots index a579f9f..5bc01a9 160000 --- a/deps/zig-wlroots +++ b/deps/zig-wlroots @@ -1 +1 @@ -Subproject commit a579f9f7dae72c960e8804737109815c78e471f4 +Subproject commit 5bc01a9f597e051c0dfab6dd9991f08697794e3d diff --git a/river/InputPopup.zig b/river/InputPopup.zig index 57ea2d9..79a517d 100644 --- a/river/InputPopup.zig +++ b/river/InputPopup.zig @@ -17,40 +17,27 @@ const InputPopup = @This(); -const build_options = @import("build_options"); const std = @import("std"); const assert = std.debug.assert; -const mem = std.mem; const wlr = @import("wlroots"); const wl = @import("wayland").server.wl; -const server = &@import("main.zig").server; +const server = &@import("main.zig").server; const util = @import("util.zig"); + const InputRelay = @import("InputRelay.zig"); -const TextInput = @import("TextInput.zig"); -const Root = @import("Root.zig"); -const View = @import("View.zig"); -const LayerSurface = @import("LayerSurface.zig"); -const XdgToplevel = @import("XdgToplevel.zig"); -const XwaylandView = @import("XwaylandView.zig"); +const SceneNodeData = @import("SceneNodeData.zig"); link: wl.list.Link, -scene_tree: ?*wlr.SceneTree = null, -parent_scene_tree: ?*wlr.SceneTree = null, -scene_surface: ?*wlr.SceneTree = null, -view: ?*View = null, - input_relay: *InputRelay, -wlr_popup: *wlr.InputPopupSurfaceV2, -destroy: wl.Listener(void) = - wl.Listener(void).init(handleDestroy), -map: wl.Listener(void) = - wl.Listener(void).init(handleMap), -unmap: wl.Listener(void) = - wl.Listener(void).init(handleUnmap), -commit: wl.Listener(*wlr.Surface) = - wl.Listener(*wlr.Surface).init(handleCommit), +wlr_popup: *wlr.InputPopupSurfaceV2, +surface_tree: *wlr.SceneTree, + +destroy: wl.Listener(void) = wl.Listener(void).init(handleDestroy), +map: wl.Listener(void) = wl.Listener(void).init(handleMap), +unmap: wl.Listener(void) = wl.Listener(void).init(handleUnmap), +commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit), pub fn create(wlr_popup: *wlr.InputPopupSurfaceV2, input_relay: *InputRelay) !void { const input_popup = try util.gpa.create(InputPopup); @@ -60,35 +47,32 @@ pub fn create(wlr_popup: *wlr.InputPopupSurfaceV2, input_relay: *InputRelay) !vo .link = undefined, .input_relay = input_relay, .wlr_popup = wlr_popup, + .surface_tree = try server.root.hidden.tree.createSceneSubsurfaceTree(wlr_popup.surface), }; + input_relay.input_popups.append(input_popup); + input_popup.wlr_popup.events.destroy.add(&input_popup.destroy); input_popup.wlr_popup.surface.events.map.add(&input_popup.map); input_popup.wlr_popup.surface.events.unmap.add(&input_popup.unmap); input_popup.wlr_popup.surface.events.commit.add(&input_popup.commit); - input_relay.input_popups.append(input_popup); input_popup.update(); } fn handleDestroy(listener: *wl.Listener(void)) void { const input_popup = @fieldParentPtr(InputPopup, "destroy", listener); + input_popup.destroy.link.remove(); input_popup.map.link.remove(); input_popup.unmap.link.remove(); input_popup.commit.link.remove(); - input_popup.destroy.link.remove(); + input_popup.link.remove(); util.gpa.destroy(input_popup); } -fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { - const input_popup = @fieldParentPtr(InputPopup, "commit", listener); - - input_popup.update(); -} - fn handleMap(listener: *wl.Listener(void)) void { const input_popup = @fieldParentPtr(InputPopup, "map", listener); @@ -98,132 +82,107 @@ fn handleMap(listener: *wl.Listener(void)) void { fn handleUnmap(listener: *wl.Listener(void)) void { const input_popup = @fieldParentPtr(InputPopup, "unmap", listener); - input_popup.scene_tree.?.node.destroy(); - input_popup.scene_tree = null; + input_popup.surface_tree.node.reparent(server.root.hidden.tree); +} + +fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { + const input_popup = @fieldParentPtr(InputPopup, "commit", listener); + + input_popup.update(); } pub fn update(input_popup: *InputPopup) void { - var text_input = input_popup.getTextInputFocused() orelse return; + const text_input = input_popup.input_relay.text_input orelse { + input_popup.surface_tree.node.reparent(server.root.hidden.tree); + return; + }; + + if (!input_popup.wlr_popup.surface.mapped) return; + + // This seems like it could be null if the focused surface is destroyed const focused_surface = text_input.wlr_text_input.focused_surface orelse return; - if (!input_popup.wlr_popup.surface.mapped) { + // Focus should never be sent to subsurfaces + assert(focused_surface.getRootSurface() == focused_surface); + + const focused = SceneNodeData.fromSurface(focused_surface) orelse return; + + const output = switch (focused.data) { + .view => |view| view.current.output orelse return, + .layer_surface => |layer_surface| layer_surface.output, + .lock_surface => |lock_surface| lock_surface.getOutput(), + // Xwayland doesn't use the text-input protocol + .override_redirect => unreachable, + }; + + const popup_tree = switch (focused.data) { + .view => |view| view.popup_tree, + .layer_surface => |layer_surface| layer_surface.popup_tree, + .lock_surface => |lock_surface| lock_surface.getOutput().layers.popups, + // Xwayland doesn't use the text-input protocol + .override_redirect => unreachable, + }; + + input_popup.surface_tree.node.reparent(popup_tree); + + if (!text_input.wlr_text_input.current.features.cursor_rectangle) { + // If the text-input client does not inform us where in the surface + // the active text input is there's not much we can do. Placing the + // popup at the top left corner of the window is nice and simple + // while not looking terrible. + input_popup.surface_tree.node.setPosition(0, 0); return; } + var focused_x: c_int = undefined; + var focused_y: c_int = undefined; + _ = focused.node.coords(&focused_x, &focused_y); + var output_box: wlr.Box = undefined; - var parent: wlr.Box = undefined; + server.root.output_layout.getBox(output.wlr_output, &output_box); - input_popup.getParentAndOutputBox(focused_surface, &parent, &output_box); + // Relative to the surface with the active text input + var cursor_box = text_input.wlr_text_input.current.cursor_rectangle; - var cursor_rect = if (text_input.wlr_text_input.current.features.cursor_rectangle) - text_input.wlr_text_input.current.cursor_rectangle - else - wlr.Box{ - .x = 0, - .y = 0, - .width = parent.width, - .height = parent.height, - }; + // Adjust to be relative to the output + cursor_box.x += focused_x - output_box.x; + cursor_box.y += focused_y - output_box.y; - const popup_width = input_popup.wlr_popup.surface.current.width; - const popup_height = input_popup.wlr_popup.surface.current.height; + // Choose popup x/y relative to the output: - const cursor_rect_left = parent.x + cursor_rect.x; - const popup_anchor_left = blk: { - const cursor_rect_right = cursor_rect_left + cursor_rect.width; - const available_right_of_cursor = output_box.x + output_box.width - cursor_rect_left; - const available_left_of_cursor = cursor_rect_right - output_box.x; - if (available_right_of_cursor < popup_width and available_left_of_cursor > popup_width) { - break :blk cursor_rect_right - popup_width; + // Align the left edge of the popup with the left edge of the cursor. + // If the popup wouldn't fit on the output instead align the right edge + // of the popup with the right edge of the cursor. + const popup_x = blk: { + const popup_width = input_popup.wlr_popup.surface.current.width; + if (output_box.width - cursor_box.x >= popup_width) { + break :blk cursor_box.x; } else { - break :blk cursor_rect_left; + break :blk cursor_box.x + cursor_box.width - popup_width; } }; - const cursor_rect_up = parent.y + cursor_rect.y; - const popup_anchor_up = blk: { - const cursor_rect_down = cursor_rect_up + cursor_rect.height; - const available_down_of_cursor = output_box.y + output_box.height - cursor_rect_down; - const available_up_of_cursor = cursor_rect_up - output_box.y; - if (available_down_of_cursor < popup_height and available_up_of_cursor > popup_height) { - break :blk cursor_rect_up - popup_height; + // Align the top edge of the popup with the bottom edge of the cursor. + // If the popup wouldn't fit on the output instead align the bottom edge + // of the popup with the top edge of the cursor. + const popup_y = blk: { + const popup_height = input_popup.wlr_popup.surface.current.height; + if (output_box.height - (cursor_box.y + cursor_box.height) >= popup_height) { + break :blk cursor_box.y + cursor_box.height; } else { - break :blk cursor_rect_down; + break :blk cursor_box.y - popup_height; } }; - if (text_input.wlr_text_input.current.features.cursor_rectangle) { - var box = wlr.Box{ - .x = cursor_rect_left - popup_anchor_left, - .y = cursor_rect_up - popup_anchor_up, - .width = cursor_rect.width, - .height = cursor_rect.height, - }; - input_popup.wlr_popup.sendTextInputRectangle(&box); - } + // Scene node position is relative to the parent so adjust popup x/y to + // be relative to the focused surface. + input_popup.surface_tree.node.setPosition( + popup_x - focused_x + output_box.x, + popup_y - focused_y + output_box.y, + ); - if (input_popup.scene_tree == null) { - input_popup.scene_tree = input_popup.parent_scene_tree.?.createSceneTree() catch { - std.log.err("out of memory", .{}); - return; - }; - - input_popup.scene_surface = input_popup.scene_tree.? - .createSceneSubsurfaceTree( - input_popup.wlr_popup.surface, - ) catch { - std.log.err("out of memory", .{}); - input_popup.wlr_popup.surface.resource.getClient().postNoMemory(); - return; - }; - } - input_popup.scene_tree.?.node.setPosition(popup_anchor_left - parent.x, popup_anchor_up - parent.y); -} - -pub fn getTextInputFocused(input_popup: *InputPopup) ?*TextInput { - var it = input_popup.input_relay.text_inputs.iterator(.forward); - while (it.next()) |text_input| { - if (text_input.wlr_text_input.focused_surface != null) return text_input; - } - return null; -} - -pub fn getParentAndOutputBox( - input_popup: *InputPopup, - focused_surface: *wlr.Surface, - parent: *wlr.Box, - output_box: *wlr.Box, -) void { - if (wlr.LayerSurfaceV1.tryFromWlrSurface(focused_surface)) |wlr_layer_surface| { - const layer_surface: *LayerSurface = @ptrFromInt(wlr_layer_surface.data); - input_popup.parent_scene_tree = layer_surface.popup_tree; - const output = layer_surface.output.wlr_output; - server.root.output_layout.getBox(output, output_box); - _ = layer_surface.popup_tree.node.coords(&parent.x, &parent.y); - } else { - const view = getViewFromWlrSurface(focused_surface) orelse return; - input_popup.parent_scene_tree = view.tree; - _ = view.tree.node.coords(&parent.x, &parent.y); - const output = view.current.output orelse return; - server.root.output_layout.getBox(output.wlr_output, output_box); - parent.width = view.current.box.width; - parent.height = view.current.box.height; - } -} - -fn getViewFromWlrSurface(wlr_surface: *wlr.Surface) ?*View { - if (wlr.XdgSurface.tryFromWlrSurface(wlr_surface)) |xdg_surface| { - const xdg_toplevel: *XdgToplevel = @ptrFromInt(xdg_surface.data); - return xdg_toplevel.view; - } - if (build_options.xwayland) { - if (wlr.XwaylandSurface.tryFromWlrSurface(wlr_surface)) |xwayland_surface| { - const xwayland_view: *XwaylandView = @ptrFromInt(xwayland_surface.data); - return xwayland_view.view; - } - } - if (wlr.Subsurface.tryFromWlrSurface(wlr_surface)) |wlr_subsurface| { - if (wlr_subsurface.parent) |parent| return getViewFromWlrSurface(parent); - } - return null; + // The text input rectangle sent to the input method is relative to the popup. + cursor_box.x -= popup_x; + cursor_box.y -= popup_y; + input_popup.wlr_popup.sendTextInputRectangle(&cursor_box); } diff --git a/river/InputRelay.zig b/river/InputRelay.zig index ae84582..cebb46c 100644 --- a/river/InputRelay.zig +++ b/river/InputRelay.zig @@ -52,8 +52,8 @@ grab_keyboard: wl.Listener(*wlr.InputMethodV2.KeyboardGrab) = wl.Listener(*wlr.InputMethodV2.KeyboardGrab).init(handleInputMethodGrabKeyboard), input_method_destroy: wl.Listener(*wlr.InputMethodV2) = wl.Listener(*wlr.InputMethodV2).init(handleInputMethodDestroy), -input_method_new_popup_surface: wl.Listener(*wlr.InputPopupSurfaceV2) = - wl.Listener(*wlr.InputPopupSurfaceV2).init(handleInputMethodNewPopupSurface), +input_method_new_popup: wl.Listener(*wlr.InputPopupSurfaceV2) = + wl.Listener(*wlr.InputPopupSurfaceV2).init(handleInputMethodNewPopup), grab_keyboard_destroy: wl.Listener(*wlr.InputMethodV2.KeyboardGrab) = wl.Listener(*wlr.InputMethodV2.KeyboardGrab).init(handleInputMethodGrabKeyboardDestroy), @@ -82,7 +82,7 @@ pub fn newInputMethod(relay: *InputRelay, input_method: *wlr.InputMethodV2) void input_method.events.commit.add(&relay.input_method_commit); input_method.events.grab_keyboard.add(&relay.grab_keyboard); input_method.events.destroy.add(&relay.input_method_destroy); - input_method.events.new_popup_surface.add(&relay.input_method_new_popup_surface); + input_method.events.new_popup_surface.add(&relay.input_method_new_popup); if (seat.focused.surface()) |surface| { relay.focus(surface); @@ -133,7 +133,7 @@ fn handleInputMethodDestroy( relay.input_method_commit.link.remove(); relay.grab_keyboard.link.remove(); relay.input_method_destroy.link.remove(); - relay.input_method_new_popup_surface.link.remove(); + relay.input_method_new_popup.link.remove(); relay.input_method = null; relay.focus(null); @@ -154,13 +154,13 @@ fn handleInputMethodGrabKeyboard( keyboard_grab.events.destroy.add(&relay.grab_keyboard_destroy); } -fn handleInputMethodNewPopupSurface( +fn handleInputMethodNewPopup( listener: *wl.Listener(*wlr.InputPopupSurfaceV2), - input_method_new_popup_surface: *wlr.InputPopupSurfaceV2, + wlr_popup: *wlr.InputPopupSurfaceV2, ) void { - log.debug("new input_method_popup_surface", .{}); - const relay = @fieldParentPtr(InputRelay, "input_method_new_popup_surface", listener); - InputPopup.create(input_method_new_popup_surface, relay) catch { + const relay = @fieldParentPtr(InputRelay, "input_method_new_popup", listener); + + InputPopup.create(wlr_popup, relay) catch { log.err("out of memory", .{}); return; }; @@ -180,13 +180,16 @@ fn handleInputMethodGrabKeyboardDestroy( pub fn disableTextInput(relay: *InputRelay) void { assert(relay.text_input != null); + relay.text_input = null; if (relay.input_method) |input_method| { + { + var it = relay.input_popups.iterator(.forward); + while (it.next()) |popup| popup.update(); + } input_method.sendDeactivate(); input_method.sendDone(); } - - relay.text_input = null; } pub fn sendInputMethodState(relay: *InputRelay) void { @@ -215,11 +218,11 @@ pub fn sendInputMethodState(relay: *InputRelay) void { ); } - // Update input popups - var it = relay.input_popups.iterator(.forward); - while (it.next()) |popup| { - popup.update(); + { + var it = relay.input_popups.iterator(.forward); + while (it.next()) |popup| popup.update(); } + input_method.sendDone(); } diff --git a/river/Output.zig b/river/Output.zig index 3230fa3..1403e61 100644 --- a/river/Output.zig +++ b/river/Output.zig @@ -99,7 +99,7 @@ layers: struct { fullscreen: *wlr.SceneTree, /// Overlay layer shell layer overlay: *wlr.SceneTree, - /// xdg-popups of views and layer-shell surfaces + /// Popups from xdg-shell and input-method-v2 clients. popups: *wlr.SceneTree, }, diff --git a/river/SceneNodeData.zig b/river/SceneNodeData.zig index 45568c9..c90ff65 100644 --- a/river/SceneNodeData.zig +++ b/river/SceneNodeData.zig @@ -24,6 +24,7 @@ const util = @import("util.zig"); const LayerSurface = @import("LayerSurface.zig"); const LockSurface = @import("LockSurface.zig"); +const InputPopup = @import("InputPopup.zig"); const View = @import("View.zig"); const XwaylandOverrideRedirect = @import("XwaylandOverrideRedirect.zig"); @@ -65,10 +66,8 @@ pub fn fromNode(node: *wlr.SceneNode) ?*SceneNodeData { } pub fn fromSurface(surface: *wlr.Surface) ?*SceneNodeData { - if (surface.getRootSurface()) |root_surface| { - if (@as(?*wlr.SceneNode, @ptrFromInt(root_surface.data))) |node| { - return fromNode(node); - } + if (@as(?*wlr.SceneNode, @ptrFromInt(surface.getRootSurface().data))) |node| { + return fromNode(node); } return null; } diff --git a/river/XwaylandView.zig b/river/XwaylandView.zig index d85e45a..7155868 100644 --- a/river/XwaylandView.zig +++ b/river/XwaylandView.zig @@ -163,7 +163,6 @@ pub fn handleMap(listener: *wl.Listener(void)) void { const view = xwayland_view.view; const xwayland_surface = xwayland_view.xwayland_surface; - xwayland_surface.data = @intFromPtr(xwayland_view); const surface = xwayland_surface.surface.?; surface.data = @intFromPtr(&view.tree.node); From 5d1fc034bc6aedc340671d5de76add308effd2e8 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sat, 18 May 2024 14:40:20 +0200 Subject: [PATCH 05/13] PointerConstraint: remove overly tight assert This assert is incorrect if Xwayland is enabled and an Override Redirect window steals the keyboard focus from the parent surface. It also seems likely to be hit if a Wayland client attempts to use a pointer constraint on a subsurface. I don't think a pointer constraint on a subsurface is likely to work entirely correctly and I don't know of any Wayland clients that try such a thing. We can't let them crash river by trying though. --- river/PointerConstraint.zig | 2 -- 1 file changed, 2 deletions(-) diff --git a/river/PointerConstraint.zig b/river/PointerConstraint.zig index e833ee8..654debe 100644 --- a/river/PointerConstraint.zig +++ b/river/PointerConstraint.zig @@ -105,8 +105,6 @@ pub fn maybeActivate(constraint: *PointerConstraint) void { pub fn updateState(constraint: *PointerConstraint) void { const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data); - assert(seat.wlr_seat.keyboard_state.focused_surface == constraint.wlr_constraint.surface); - constraint.maybeActivate(); if (constraint.state != .active) return; From 680cb8ef699f89cd7ce0b613221e073b534c22c5 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sat, 18 May 2024 16:28:28 +0200 Subject: [PATCH 06/13] PointerConstraint: remove overly tight assert 2 This is a second copy of the same assert that was removed in the last commit. It should have been removed by that commit as well but was overlooked. --- river/PointerConstraint.zig | 1 - 1 file changed, 1 deletion(-) diff --git a/river/PointerConstraint.zig b/river/PointerConstraint.zig index 654debe..4f640e7 100644 --- a/river/PointerConstraint.zig +++ b/river/PointerConstraint.zig @@ -73,7 +73,6 @@ pub fn maybeActivate(constraint: *PointerConstraint) void { 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); if (constraint.state == .active) return; From 033cad47bf63f2914865c19fc10b4dc991007515 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 7 Mar 2024 16:19:22 +0100 Subject: [PATCH 07/13] build: update to Zig 0.12 --- .builds/alpine.yml | 8 +-- .builds/archlinux.yml | 8 +-- .builds/freebsd.yml | 8 +-- README.md | 2 +- build.zig | 83 ++++++++++++++++-------------- common/flags.zig | 6 +-- deps/zig-wayland | 2 +- deps/zig-wlroots | 2 +- deps/zig-xkbcommon | 2 +- river/Control.zig | 2 +- river/Cursor.zig | 48 ++++++++--------- river/DragIcon.zig | 2 +- river/ForeignToplevelHandle.zig | 16 +++--- river/IdleInhibitManager.zig | 2 +- river/IdleInhibitor.zig | 4 +- river/InputConfig.zig | 2 +- river/InputDevice.zig | 8 +-- river/InputManager.zig | 4 +- river/InputPopup.zig | 8 +-- river/InputRelay.zig | 14 ++--- river/Keyboard.zig | 4 +- river/KeyboardGroup.zig | 2 +- river/LayerSurface.zig | 10 ++-- river/Layout.zig | 2 +- river/LayoutManager.zig | 2 +- river/LockManager.zig | 8 +-- river/LockSurface.zig | 4 +- river/Output.zig | 15 +++--- river/PointerConstraint.zig | 6 +-- river/Root.zig | 6 +-- river/SceneNodeData.zig | 2 +- river/Seat.zig | 10 ++-- river/SeatStatus.zig | 2 +- river/Server.zig | 9 ++-- river/StatusManager.zig | 2 +- river/Switch.zig | 2 +- river/TabletTool.zig | 4 +- river/TextInput.zig | 8 +-- river/Vector.zig | 2 +- river/View.zig | 7 +-- river/XdgDecoration.zig | 4 +- river/XdgPopup.zig | 6 +-- river/XdgToplevel.zig | 22 ++++---- river/XwaylandOverrideRedirect.zig | 14 ++--- river/XwaylandView.zig | 24 ++++----- river/command/output.zig | 2 +- river/command/spawn.zig | 17 +++--- river/main.zig | 65 +++++++++++------------ river/process.zig | 30 +++++------ riverctl/main.zig | 18 +++---- rivertile/main.zig | 16 +++--- 51 files changed, 285 insertions(+), 271 deletions(-) diff --git a/.builds/alpine.yml b/.builds/alpine.yml index f59a12d..e365c0f 100644 --- a/.builds/alpine.yml +++ b/.builds/alpine.yml @@ -40,11 +40,11 @@ tasks: sudo ninja -C build/ install cd .. - wget -nv https://ziglang.org/download/0.11.0/zig-linux-x86_64-0.11.0.tar.xz + wget -nv https://ziglang.org/download/0.12.0/zig-linux-x86_64-0.12.0.tar.xz # Remove a lot of useless lines from tar output. - tar -xvf zig-linux-x86_64-0.11.0.tar.xz 1>/dev/null - sudo mv zig-linux-x86_64-0.11.0/zig /usr/bin/ - sudo mv zig-linux-x86_64-0.11.0/lib /usr/lib/zig + tar -xvf zig-linux-x86_64-0.12.0.tar.xz 1>/dev/null + sudo mv zig-linux-x86_64-0.12.0/zig /usr/bin/ + sudo mv zig-linux-x86_64-0.12.0/lib /usr/lib/zig - build: | cd river zig build diff --git a/.builds/archlinux.yml b/.builds/archlinux.yml index caf4795..476e0ac 100644 --- a/.builds/archlinux.yml +++ b/.builds/archlinux.yml @@ -38,11 +38,11 @@ tasks: sudo ninja -C build/ install cd .. - wget -nv https://ziglang.org/download/0.11.0/zig-linux-x86_64-0.11.0.tar.xz + wget -nv https://ziglang.org/download/0.12.0/zig-linux-x86_64-0.12.0.tar.xz # Remove a lot of useless lines from tar output. - tar -xvf zig-linux-x86_64-0.11.0.tar.xz 1>/dev/null - sudo mv zig-linux-x86_64-0.11.0/zig /usr/bin/ - sudo mv zig-linux-x86_64-0.11.0/lib /usr/lib/zig + tar -xvf zig-linux-x86_64-0.12.0.tar.xz 1>/dev/null + sudo mv zig-linux-x86_64-0.12.0/zig /usr/bin/ + sudo mv zig-linux-x86_64-0.12.0/lib /usr/lib/zig - build: | cd river zig build diff --git a/.builds/freebsd.yml b/.builds/freebsd.yml index 4ca6414..e05be88 100644 --- a/.builds/freebsd.yml +++ b/.builds/freebsd.yml @@ -42,11 +42,11 @@ tasks: sudo ninja -C build/ install cd .. - wget -nv https://ziglang.org/download/0.11.0/zig-freebsd-x86_64-0.11.0.tar.xz + wget -nv https://ziglang.org/download/0.12.0/zig-freebsd-x86_64-0.12.0.tar.xz # Remove a lot of useless lines from tar output. - tar -xvf zig-freebsd-x86_64-0.11.0.tar.xz 1>/dev/null - sudo mv zig-freebsd-x86_64-0.11.0/zig /usr/bin/ - sudo mv zig-freebsd-x86_64-0.11.0/lib /usr/lib/zig + tar -xvf zig-freebsd-x86_64-0.12.0.tar.xz 1>/dev/null + sudo mv zig-freebsd-x86_64-0.12.0/zig /usr/bin/ + sudo mv zig-freebsd-x86_64-0.12.0/lib /usr/lib/zig - build: | cd river zig build diff --git a/README.md b/README.md index d25d19f..8b8c5b9 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ To compile river first ensure that you have the following dependencies installed. The "development" versions are required if applicable to your distribution. -- [zig](https://ziglang.org/download/) 0.11 +- [zig](https://ziglang.org/download/) 0.12 - wayland - wayland-protocols - [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 0.17.2 diff --git a/build.zig b/build.zig index 5dbe3c2..1b9fba9 100644 --- a/build.zig +++ b/build.zig @@ -64,7 +64,7 @@ pub fn build(b: *Build) !void { if (mem.endsWith(u8, version, "-dev")) { var ret: u8 = undefined; - const git_describe_long = b.execAllowFail( + const git_describe_long = b.runAllowFail( &.{ "git", "-C", b.build_root.path orelse ".", "describe", "--long" }, &ret, .Inherit, @@ -91,12 +91,12 @@ pub fn build(b: *Build) !void { const scanner = Scanner.create(b, .{}); scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml"); - scanner.addSystemProtocol("staging/ext-session-lock/ext-session-lock-v1.xml"); - scanner.addSystemProtocol("unstable/pointer-gestures/pointer-gestures-unstable-v1.xml"); - scanner.addSystemProtocol("unstable/pointer-constraints/pointer-constraints-unstable-v1.xml"); - scanner.addSystemProtocol("unstable/xdg-decoration/xdg-decoration-unstable-v1.xml"); - scanner.addSystemProtocol("unstable/tablet/tablet-unstable-v2.xml"); scanner.addSystemProtocol("staging/cursor-shape/cursor-shape-v1.xml"); + scanner.addSystemProtocol("staging/ext-session-lock/ext-session-lock-v1.xml"); + scanner.addSystemProtocol("unstable/pointer-constraints/pointer-constraints-unstable-v1.xml"); + scanner.addSystemProtocol("unstable/pointer-gestures/pointer-gestures-unstable-v1.xml"); + scanner.addSystemProtocol("unstable/tablet/tablet-unstable-v2.xml"); + scanner.addSystemProtocol("unstable/xdg-decoration/xdg-decoration-unstable-v1.xml"); scanner.addCustomProtocol("protocol/river-control-unstable-v1.xml"); scanner.addCustomProtocol("protocol/river-status-unstable-v1.xml"); @@ -131,24 +131,36 @@ pub fn build(b: *Build) !void { scanner.generate("zwlr_layer_shell_v1", 4); scanner.generate("zwlr_output_power_manager_v1", 1); - const wayland = b.createModule(.{ .source_file = scanner.result }); + const wayland = b.createModule(.{ + .root_source_file = scanner.result, + .target = target, + }); + const xkbcommon = b.createModule(.{ - .source_file = .{ .path = "deps/zig-xkbcommon/src/xkbcommon.zig" }, + .root_source_file = .{ .path = "deps/zig-xkbcommon/src/xkbcommon.zig" }, + .target = target, }); + xkbcommon.linkSystemLibrary("xkbcommon", .{}); + const pixman = b.createModule(.{ - .source_file = .{ .path = "deps/zig-pixman/pixman.zig" }, + .root_source_file = .{ .path = "deps/zig-pixman/pixman.zig" }, + .target = target, }); + pixman.linkSystemLibrary("pixman-1", .{}); + const wlroots = b.createModule(.{ - .source_file = .{ .path = "deps/zig-wlroots/src/wlroots.zig" }, - .dependencies = &.{ + .root_source_file = .{ .path = "deps/zig-wlroots/src/wlroots.zig" }, + .imports = &.{ .{ .name = "wayland", .module = wayland }, .{ .name = "xkbcommon", .module = xkbcommon }, .{ .name = "pixman", .module = pixman }, }, + .target = target, }); + wlroots.linkSystemLibrary("wlroots", .{}); - const flags = b.createModule(.{ .source_file = .{ .path = "common/flags.zig" } }); - const globber = b.createModule(.{ .source_file = .{ .path = "common/globber.zig" } }); + const flags = b.createModule(.{ .root_source_file = .{ .path = "common/flags.zig" } }); + const globber = b.createModule(.{ .root_source_file = .{ .path = "common/globber.zig" } }); { const river = b.addExecutable(.{ @@ -156,38 +168,33 @@ pub fn build(b: *Build) !void { .root_source_file = .{ .path = "river/main.zig" }, .target = target, .optimize = optimize, + .strip = strip, }); - river.addOptions("build_options", options); + river.root_module.addOptions("build_options", options); river.linkLibC(); river.linkSystemLibrary("libevdev"); river.linkSystemLibrary("libinput"); - - river.addModule("wayland", wayland); river.linkSystemLibrary("wayland-server"); - river.addModule("xkbcommon", xkbcommon); - river.linkSystemLibrary("xkbcommon"); + river.root_module.addImport("wayland", wayland); + river.root_module.addImport("xkbcommon", xkbcommon); + river.root_module.addImport("pixman", pixman); + river.root_module.addImport("wlroots", wlroots); + river.root_module.addImport("flags", flags); + river.root_module.addImport("globber", globber); - river.addModule("pixman", pixman); - river.linkSystemLibrary("pixman-1"); - - river.addModule("wlroots", wlroots); - river.linkSystemLibrary("wlroots"); - - river.addModule("flags", flags); - river.addModule("globber", globber); river.addCSourceFile(.{ .file = .{ .path = "river/wlroots_log_wrapper.c" }, .flags = &.{ "-std=c99", "-O2" }, }); + river.linkSystemLibrary("wlroots"); // TODO: remove when zig issue #131 is implemented scanner.addCSource(river); - river.strip = strip; river.pie = pie; - river.omit_frame_pointer = omit_frame_pointer; + river.root_module.omit_frame_pointer = omit_frame_pointer; b.installArtifact(river); } @@ -198,19 +205,19 @@ pub fn build(b: *Build) !void { .root_source_file = .{ .path = "riverctl/main.zig" }, .target = target, .optimize = optimize, + .strip = strip, }); - riverctl.addOptions("build_options", options); + riverctl.root_module.addOptions("build_options", options); - riverctl.addModule("flags", flags); - riverctl.addModule("wayland", wayland); + riverctl.root_module.addImport("flags", flags); + riverctl.root_module.addImport("wayland", wayland); riverctl.linkLibC(); riverctl.linkSystemLibrary("wayland-client"); scanner.addCSource(riverctl); - riverctl.strip = strip; riverctl.pie = pie; - riverctl.omit_frame_pointer = omit_frame_pointer; + riverctl.root_module.omit_frame_pointer = omit_frame_pointer; b.installArtifact(riverctl); } @@ -221,19 +228,19 @@ pub fn build(b: *Build) !void { .root_source_file = .{ .path = "rivertile/main.zig" }, .target = target, .optimize = optimize, + .strip = strip, }); - rivertile.addOptions("build_options", options); + rivertile.root_module.addOptions("build_options", options); - rivertile.addModule("flags", flags); - rivertile.addModule("wayland", wayland); + rivertile.root_module.addImport("flags", flags); + rivertile.root_module.addImport("wayland", wayland); rivertile.linkLibC(); rivertile.linkSystemLibrary("wayland-client"); scanner.addCSource(rivertile); - rivertile.strip = strip; rivertile.pie = pie; - rivertile.omit_frame_pointer = omit_frame_pointer; + rivertile.root_module.omit_frame_pointer = omit_frame_pointer; b.installArtifact(rivertile); } diff --git a/common/flags.zig b/common/flags.zig index 3f75e13..5b7b552 100644 --- a/common/flags.zig +++ b/common/flags.zig @@ -18,7 +18,7 @@ const std = @import("std"); const mem = std.mem; pub const Flag = struct { - name: []const u8, + name: [:0]const u8, kind: enum { boolean, arg }, }; @@ -37,7 +37,7 @@ pub fn parser(comptime Arg: type, comptime flags: []const Flag) type { pub const Flags = flags_type: { var fields: []const std.builtin.Type.StructField = &.{}; - inline for (flags) |flag| { + for (flags) |flag| { const field: std.builtin.Type.StructField = switch (flag.kind) { .boolean => .{ .name = flag.name, @@ -57,7 +57,7 @@ pub fn parser(comptime Arg: type, comptime flags: []const Flag) type { fields = fields ++ [_]std.builtin.Type.StructField{field}; } break :flags_type @Type(.{ .Struct = .{ - .layout = .Auto, + .layout = .auto, .fields = fields, .decls = &.{}, .is_tuple = false, diff --git a/deps/zig-wayland b/deps/zig-wayland index 73fed09..6be3eb9 160000 --- a/deps/zig-wayland +++ b/deps/zig-wayland @@ -1 +1 @@ -Subproject commit 73fed093301b2e5f58998aa4797ce952bd148676 +Subproject commit 6be3eb9bff878bbf3f83a7c6862f1e14233606f5 diff --git a/deps/zig-wlroots b/deps/zig-wlroots index 5bc01a9..941859c 160000 --- a/deps/zig-wlroots +++ b/deps/zig-wlroots @@ -1 +1 @@ -Subproject commit 5bc01a9f597e051c0dfab6dd9991f08697794e3d +Subproject commit 941859cd842b68cc5d20757e8708eb70295e9344 diff --git a/deps/zig-xkbcommon b/deps/zig-xkbcommon index 7e09b38..3a2eefd 160000 --- a/deps/zig-xkbcommon +++ b/deps/zig-xkbcommon @@ -1 +1 @@ -Subproject commit 7e09b389373b060148c0ca050e0b525e118d91e7 +Subproject commit 3a2eefdad6b4d48757274061dd2b5df3b89a2bfd diff --git a/river/Control.zig b/river/Control.zig index c59a4a3..2b0d21f 100644 --- a/river/Control.zig +++ b/river/Control.zig @@ -48,7 +48,7 @@ pub fn init(control: *Control) !void { } fn handleServerDestroy(listener: *wl.Listener(*wl.Server), _: *wl.Server) void { - const control = @fieldParentPtr(Control, "server_destroy", listener); + const control: *Control = @fieldParentPtr("server_destroy", listener); control.global.destroy(); control.args_map.deinit(); } diff --git a/river/Cursor.zig b/river/Cursor.zig index 29e7ed9..aa031fc 100644 --- a/river/Cursor.zig +++ b/river/Cursor.zig @@ -19,7 +19,7 @@ const Cursor = @This(); const build_options = @import("build_options"); const std = @import("std"); const assert = std.debug.assert; -const os = std.os; +const posix = std.posix; const math = std.math; const wlr = @import("wlroots"); const wayland = @import("wayland"); @@ -303,7 +303,7 @@ fn clearFocus(cursor: *Cursor) void { /// Axis event is a scroll wheel or similiar fn handleAxis(listener: *wl.Listener(*wlr.Pointer.event.Axis), event: *wlr.Pointer.event.Axis) void { - const cursor = @fieldParentPtr(Cursor, "axis", listener); + const cursor: *Cursor = @fieldParentPtr("axis", listener); const device: *InputDevice = @ptrFromInt(event.device.data); cursor.seat.handleActivity(); @@ -328,7 +328,7 @@ fn handleAxis(listener: *wl.Listener(*wlr.Pointer.event.Axis), event: *wlr.Point } fn handleButton(listener: *wl.Listener(*wlr.Pointer.event.Button), event: *wlr.Pointer.event.Button) void { - const cursor = @fieldParentPtr(Cursor, "button", listener); + const cursor: *Cursor = @fieldParentPtr("button", listener); cursor.seat.handleActivity(); cursor.unhide(); @@ -432,7 +432,7 @@ fn handlePinchBegin( listener: *wl.Listener(*wlr.Pointer.event.PinchBegin), event: *wlr.Pointer.event.PinchBegin, ) void { - const cursor = @fieldParentPtr(Cursor, "pinch_begin", listener); + const cursor: *Cursor = @fieldParentPtr("pinch_begin", listener); server.input_manager.pointer_gestures.sendPinchBegin( cursor.seat.wlr_seat, event.time_msec, @@ -444,7 +444,7 @@ fn handlePinchUpdate( listener: *wl.Listener(*wlr.Pointer.event.PinchUpdate), event: *wlr.Pointer.event.PinchUpdate, ) void { - const cursor = @fieldParentPtr(Cursor, "pinch_update", listener); + const cursor: *Cursor = @fieldParentPtr("pinch_update", listener); server.input_manager.pointer_gestures.sendPinchUpdate( cursor.seat.wlr_seat, event.time_msec, @@ -459,7 +459,7 @@ fn handlePinchEnd( listener: *wl.Listener(*wlr.Pointer.event.PinchEnd), event: *wlr.Pointer.event.PinchEnd, ) void { - const cursor = @fieldParentPtr(Cursor, "pinch_end", listener); + const cursor: *Cursor = @fieldParentPtr("pinch_end", listener); server.input_manager.pointer_gestures.sendPinchEnd( cursor.seat.wlr_seat, event.time_msec, @@ -471,7 +471,7 @@ fn handleSwipeBegin( listener: *wl.Listener(*wlr.Pointer.event.SwipeBegin), event: *wlr.Pointer.event.SwipeBegin, ) void { - const cursor = @fieldParentPtr(Cursor, "swipe_begin", listener); + const cursor: *Cursor = @fieldParentPtr("swipe_begin", listener); server.input_manager.pointer_gestures.sendSwipeBegin( cursor.seat.wlr_seat, event.time_msec, @@ -483,7 +483,7 @@ fn handleSwipeUpdate( listener: *wl.Listener(*wlr.Pointer.event.SwipeUpdate), event: *wlr.Pointer.event.SwipeUpdate, ) void { - const cursor = @fieldParentPtr(Cursor, "swipe_update", listener); + const cursor: *Cursor = @fieldParentPtr("swipe_update", listener); server.input_manager.pointer_gestures.sendSwipeUpdate( cursor.seat.wlr_seat, event.time_msec, @@ -496,7 +496,7 @@ fn handleSwipeEnd( listener: *wl.Listener(*wlr.Pointer.event.SwipeEnd), event: *wlr.Pointer.event.SwipeEnd, ) void { - const cursor = @fieldParentPtr(Cursor, "swipe_end", listener); + const cursor: *Cursor = @fieldParentPtr("swipe_end", listener); server.input_manager.pointer_gestures.sendSwipeEnd( cursor.seat.wlr_seat, event.time_msec, @@ -508,7 +508,7 @@ fn handleTouchDown( listener: *wl.Listener(*wlr.Touch.event.Down), event: *wlr.Touch.event.Down, ) void { - const cursor = @fieldParentPtr(Cursor, "touch_down", listener); + const cursor: *Cursor = @fieldParentPtr("touch_down", listener); cursor.seat.handleActivity(); @@ -544,7 +544,7 @@ fn handleTouchMotion( listener: *wl.Listener(*wlr.Touch.event.Motion), event: *wlr.Touch.event.Motion, ) void { - const cursor = @fieldParentPtr(Cursor, "touch_motion", listener); + const cursor: *Cursor = @fieldParentPtr("touch_motion", listener); cursor.seat.handleActivity(); @@ -563,7 +563,7 @@ fn handleTouchUp( listener: *wl.Listener(*wlr.Touch.event.Up), event: *wlr.Touch.event.Up, ) void { - const cursor = @fieldParentPtr(Cursor, "touch_up", listener); + const cursor: *Cursor = @fieldParentPtr("touch_up", listener); cursor.seat.handleActivity(); @@ -576,7 +576,7 @@ fn handleTouchCancel( listener: *wl.Listener(*wlr.Touch.event.Cancel), _: *wlr.Touch.event.Cancel, ) void { - const cursor = @fieldParentPtr(Cursor, "touch_cancel", listener); + const cursor: *Cursor = @fieldParentPtr("touch_cancel", listener); cursor.seat.handleActivity(); @@ -612,7 +612,7 @@ fn handleTouchCancel( } fn handleTouchFrame(listener: *wl.Listener(void)) void { - const cursor = @fieldParentPtr(Cursor, "touch_frame", listener); + const cursor: *Cursor = @fieldParentPtr("touch_frame", listener); cursor.seat.handleActivity(); @@ -624,7 +624,7 @@ fn handleTabletToolAxis( event: *wlr.Tablet.event.Axis, ) void { const device: *InputDevice = @ptrFromInt(event.device.data); - const tablet = @fieldParentPtr(Tablet, "device", device); + const tablet: *Tablet = @fieldParentPtr("device", device); device.seat.handleActivity(); @@ -638,7 +638,7 @@ fn handleTabletToolProximity( event: *wlr.Tablet.event.Proximity, ) void { const device: *InputDevice = @ptrFromInt(event.device.data); - const tablet = @fieldParentPtr(Tablet, "device", device); + const tablet: *Tablet = @fieldParentPtr("device", device); device.seat.handleActivity(); @@ -652,7 +652,7 @@ fn handleTabletToolTip( event: *wlr.Tablet.event.Tip, ) void { const device: *InputDevice = @ptrFromInt(event.device.data); - const tablet = @fieldParentPtr(Tablet, "device", device); + const tablet: *Tablet = @fieldParentPtr("device", device); device.seat.handleActivity(); @@ -666,7 +666,7 @@ fn handleTabletToolButton( event: *wlr.Tablet.event.Button, ) void { const device: *InputDevice = @ptrFromInt(event.device.data); - const tablet = @fieldParentPtr(Tablet, "device", device); + const tablet: *Tablet = @fieldParentPtr("device", device); device.seat.handleActivity(); @@ -706,7 +706,7 @@ fn handlePointerMapping(cursor: *Cursor, event: *wlr.Pointer.event.Button, view: /// events together. For instance, two axis events may happen at the same /// time, in which case a frame event won't be sent in between. fn handleFrame(listener: *wl.Listener(*wlr.Cursor), _: *wlr.Cursor) void { - const cursor = @fieldParentPtr(Cursor, "frame", listener); + const cursor: *Cursor = @fieldParentPtr("frame", listener); cursor.seat.wlr_seat.pointerNotifyFrame(); } @@ -720,7 +720,7 @@ fn handleMotionAbsolute( listener: *wl.Listener(*wlr.Pointer.event.MotionAbsolute), event: *wlr.Pointer.event.MotionAbsolute, ) void { - const cursor = @fieldParentPtr(Cursor, "motion_absolute", listener); + const cursor: *Cursor = @fieldParentPtr("motion_absolute", listener); cursor.seat.handleActivity(); @@ -739,7 +739,7 @@ fn handleMotion( listener: *wl.Listener(*wlr.Pointer.event.Motion), event: *wlr.Pointer.event.Motion, ) void { - const cursor = @fieldParentPtr(Cursor, "motion", listener); + const cursor: *Cursor = @fieldParentPtr("motion", listener); cursor.seat.handleActivity(); @@ -751,7 +751,7 @@ fn handleRequestSetCursor( event: *wlr.Seat.event.RequestSetCursor, ) void { // This event is rasied by the seat when a client provides a cursor image - const cursor = @fieldParentPtr(Cursor, "request_set_cursor", listener); + const cursor: *Cursor = @fieldParentPtr("request_set_cursor", listener); const focused_client = cursor.seat.wlr_seat.pointer_state.focused_client; // This can be sent by any client, so we check to make sure this one is @@ -1111,8 +1111,8 @@ pub fn updateState(cursor: *Cursor) void { .passthrough => { cursor.updateFocusFollowsCursorTarget(); if (!cursor.hidden) { - var now: os.timespec = undefined; - os.clock_gettime(os.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported"); + var now: posix.timespec = undefined; + posix.clock_gettime(posix.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported"); const msec: u32 = @intCast(now.tv_sec * std.time.ms_per_s + @divTrunc(now.tv_nsec, std.time.ns_per_ms)); cursor.passthrough(msec); diff --git a/river/DragIcon.zig b/river/DragIcon.zig index 2505e4b..eae4059 100644 --- a/river/DragIcon.zig +++ b/river/DragIcon.zig @@ -71,7 +71,7 @@ pub fn updatePosition(drag_icon: *DragIcon, cursor: *Cursor) void { } fn handleDestroy(listener: *wl.Listener(*wlr.Drag.Icon), _: *wlr.Drag.Icon) void { - const drag_icon = @fieldParentPtr(DragIcon, "destroy", listener); + const drag_icon: *DragIcon = @fieldParentPtr("destroy", listener); drag_icon.destroy.link.remove(); diff --git a/river/ForeignToplevelHandle.zig b/river/ForeignToplevelHandle.zig index dcf88cb..a49c8a1 100644 --- a/river/ForeignToplevelHandle.zig +++ b/river/ForeignToplevelHandle.zig @@ -36,7 +36,7 @@ foreign_close: wl.Listener(*wlr.ForeignToplevelHandleV1) = wl.Listener(*wlr.ForeignToplevelHandleV1).init(handleForeignClose), pub fn map(handle: *ForeignToplevelHandle) void { - const view = @fieldParentPtr(View, "foreign_toplevel_handle", handle); + const view: *View = @fieldParentPtr("foreign_toplevel_handle", handle); assert(handle.wlr_handle == null); @@ -67,7 +67,7 @@ pub fn unmap(handle: *ForeignToplevelHandle) void { /// Must be called just before the view's inflight state is made current. pub fn update(handle: *ForeignToplevelHandle) void { - const view = @fieldParentPtr(View, "foreign_toplevel_handle", handle); + const view: *View = @fieldParentPtr("foreign_toplevel_handle", handle); const wlr_handle = handle.wlr_handle orelse return; @@ -87,8 +87,8 @@ fn handleForeignActivate( listener: *wl.Listener(*wlr.ForeignToplevelHandleV1.event.Activated), event: *wlr.ForeignToplevelHandleV1.event.Activated, ) void { - const handle = @fieldParentPtr(ForeignToplevelHandle, "foreign_activate", listener); - const view = @fieldParentPtr(View, "foreign_toplevel_handle", handle); + const handle: *ForeignToplevelHandle = @fieldParentPtr("foreign_activate", listener); + const view: *View = @fieldParentPtr("foreign_toplevel_handle", handle); const seat: *Seat = @ptrFromInt(event.seat.data); seat.focus(view); @@ -99,8 +99,8 @@ fn handleForeignFullscreen( listener: *wl.Listener(*wlr.ForeignToplevelHandleV1.event.Fullscreen), event: *wlr.ForeignToplevelHandleV1.event.Fullscreen, ) void { - const handle = @fieldParentPtr(ForeignToplevelHandle, "foreign_fullscreen", listener); - const view = @fieldParentPtr(View, "foreign_toplevel_handle", handle); + const handle: *ForeignToplevelHandle = @fieldParentPtr("foreign_fullscreen", listener); + const view: *View = @fieldParentPtr("foreign_toplevel_handle", handle); view.pending.fullscreen = event.fullscreen; server.root.applyPending(); @@ -110,8 +110,8 @@ fn handleForeignClose( listener: *wl.Listener(*wlr.ForeignToplevelHandleV1), _: *wlr.ForeignToplevelHandleV1, ) void { - const handle = @fieldParentPtr(ForeignToplevelHandle, "foreign_close", listener); - const view = @fieldParentPtr(View, "foreign_toplevel_handle", handle); + const handle: *ForeignToplevelHandle = @fieldParentPtr("foreign_close", listener); + const view: *View = @fieldParentPtr("foreign_toplevel_handle", handle); view.close(); } diff --git a/river/IdleInhibitManager.zig b/river/IdleInhibitManager.zig index 5a3c4ba..475d833 100644 --- a/river/IdleInhibitManager.zig +++ b/river/IdleInhibitManager.zig @@ -78,7 +78,7 @@ pub fn checkActive(inhibit_manager: *IdleInhibitManager) void { } fn handleNewIdleInhibitor(listener: *wl.Listener(*wlr.IdleInhibitorV1), inhibitor: *wlr.IdleInhibitorV1) void { - const inhibit_manager = @fieldParentPtr(IdleInhibitManager, "new_idle_inhibitor", listener); + const inhibit_manager: *IdleInhibitManager = @fieldParentPtr("new_idle_inhibitor", listener); const inhibitor_node = util.gpa.create(std.TailQueue(IdleInhibitor).Node) catch return; inhibitor_node.data.init(inhibitor, inhibit_manager) catch { util.gpa.destroy(inhibitor_node); diff --git a/river/IdleInhibitor.zig b/river/IdleInhibitor.zig index e59d728..4babaa3 100644 --- a/river/IdleInhibitor.zig +++ b/river/IdleInhibitor.zig @@ -45,11 +45,11 @@ pub fn init( } fn handleDestroy(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { - const inhibitor = @fieldParentPtr(IdleInhibitor, "destroy", listener); + const inhibitor: *IdleInhibitor = @fieldParentPtr("destroy", listener); inhibitor.destroy.link.remove(); - const node = @fieldParentPtr(std.TailQueue(IdleInhibitor).Node, "data", inhibitor); + const node: *std.TailQueue(IdleInhibitor).Node = @fieldParentPtr("data", inhibitor); server.idle_inhibit_manager.inhibitors.remove(node); inhibitor.inhibit_manager.checkActive(); diff --git a/river/InputConfig.zig b/river/InputConfig.zig index 5cbe27b..6922081 100644 --- a/river/InputConfig.zig +++ b/river/InputConfig.zig @@ -241,7 +241,7 @@ pub const MapToOutput = struct { device.seat.cursor.wlr_cursor.mapInputToOutput(device.wlr_device, wlr_output); if (device.wlr_device.type == .tablet_tool) { - const tablet = @fieldParentPtr(Tablet, "device", device); + const tablet: *Tablet = @fieldParentPtr("device", device); tablet.output_mapping = wlr_output; } }, diff --git a/river/InputDevice.zig b/river/InputDevice.zig index 685a671..f3d9924 100644 --- a/river/InputDevice.zig +++ b/river/InputDevice.zig @@ -125,13 +125,13 @@ fn isKeyboardGroup(wlr_device: *wlr.InputDevice) bool { } fn handleDestroy(listener: *wl.Listener(*wlr.InputDevice), _: *wlr.InputDevice) void { - const device = @fieldParentPtr(InputDevice, "destroy", listener); + const device: *InputDevice = @fieldParentPtr("destroy", listener); log.debug("removed input device: {s}", .{device.identifier}); switch (device.wlr_device.type) { .keyboard => { - const keyboard = @fieldParentPtr(Keyboard, "device", device); + const keyboard: *Keyboard = @fieldParentPtr("device", device); keyboard.deinit(); util.gpa.destroy(keyboard); }, @@ -140,11 +140,11 @@ fn handleDestroy(listener: *wl.Listener(*wlr.InputDevice), _: *wlr.InputDevice) util.gpa.destroy(device); }, .tablet_tool => { - const tablet = @fieldParentPtr(Tablet, "device", device); + const tablet: *Tablet = @fieldParentPtr("device", device); tablet.destroy(); }, .switch_device => { - const switch_device = @fieldParentPtr(Switch, "device", device); + const switch_device: *Switch = @fieldParentPtr("device", device); switch_device.deinit(); util.gpa.destroy(switch_device); }, diff --git a/river/InputManager.zig b/river/InputManager.zig index ff7bb05..6368c63 100644 --- a/river/InputManager.zig +++ b/river/InputManager.zig @@ -158,7 +158,7 @@ pub fn reconfigureDevices(input_manager: *InputManager) void { } fn handleNewInput(listener: *wl.Listener(*wlr.InputDevice), wlr_device: *wlr.InputDevice) void { - const input_manager = @fieldParentPtr(InputManager, "new_input", listener); + const input_manager: *InputManager = @fieldParentPtr("new_input", listener); input_manager.defaultSeat().addDevice(wlr_device); } @@ -167,7 +167,7 @@ fn handleNewVirtualPointer( listener: *wl.Listener(*wlr.VirtualPointerManagerV1.event.NewPointer), event: *wlr.VirtualPointerManagerV1.event.NewPointer, ) void { - const input_manager = @fieldParentPtr(InputManager, "new_virtual_pointer", listener); + const input_manager: *InputManager = @fieldParentPtr("new_virtual_pointer", listener); // TODO Support multiple seats and don't ignore if (event.suggested_seat != null) { diff --git a/river/InputPopup.zig b/river/InputPopup.zig index 79a517d..0e35753 100644 --- a/river/InputPopup.zig +++ b/river/InputPopup.zig @@ -61,7 +61,7 @@ pub fn create(wlr_popup: *wlr.InputPopupSurfaceV2, input_relay: *InputRelay) !vo } fn handleDestroy(listener: *wl.Listener(void)) void { - const input_popup = @fieldParentPtr(InputPopup, "destroy", listener); + const input_popup: *InputPopup = @fieldParentPtr("destroy", listener); input_popup.destroy.link.remove(); input_popup.map.link.remove(); @@ -74,19 +74,19 @@ fn handleDestroy(listener: *wl.Listener(void)) void { } fn handleMap(listener: *wl.Listener(void)) void { - const input_popup = @fieldParentPtr(InputPopup, "map", listener); + const input_popup: *InputPopup = @fieldParentPtr("map", listener); input_popup.update(); } fn handleUnmap(listener: *wl.Listener(void)) void { - const input_popup = @fieldParentPtr(InputPopup, "unmap", listener); + const input_popup: *InputPopup = @fieldParentPtr("unmap", listener); input_popup.surface_tree.node.reparent(server.root.hidden.tree); } fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { - const input_popup = @fieldParentPtr(InputPopup, "commit", listener); + const input_popup: *InputPopup = @fieldParentPtr("commit", listener); input_popup.update(); } diff --git a/river/InputRelay.zig b/river/InputRelay.zig index cebb46c..69d655d 100644 --- a/river/InputRelay.zig +++ b/river/InputRelay.zig @@ -66,7 +66,7 @@ pub fn init(relay: *InputRelay) void { } pub fn newInputMethod(relay: *InputRelay, input_method: *wlr.InputMethodV2) void { - const seat = @fieldParentPtr(Seat, "relay", relay); + const seat: *Seat = @fieldParentPtr("relay", relay); log.debug("new input method on seat {s}", .{seat.wlr_seat.name}); @@ -93,7 +93,7 @@ fn handleInputMethodCommit( listener: *wl.Listener(*wlr.InputMethodV2), input_method: *wlr.InputMethodV2, ) void { - const relay = @fieldParentPtr(InputRelay, "input_method_commit", listener); + const relay: *InputRelay = @fieldParentPtr("input_method_commit", listener); assert(input_method == relay.input_method); if (!input_method.client_active) return; @@ -127,7 +127,7 @@ fn handleInputMethodDestroy( listener: *wl.Listener(*wlr.InputMethodV2), input_method: *wlr.InputMethodV2, ) void { - const relay = @fieldParentPtr(InputRelay, "input_method_destroy", listener); + const relay: *InputRelay = @fieldParentPtr("input_method_destroy", listener); assert(input_method == relay.input_method); relay.input_method_commit.link.remove(); @@ -145,8 +145,8 @@ fn handleInputMethodGrabKeyboard( listener: *wl.Listener(*wlr.InputMethodV2.KeyboardGrab), keyboard_grab: *wlr.InputMethodV2.KeyboardGrab, ) void { - const relay = @fieldParentPtr(InputRelay, "grab_keyboard", listener); - const seat = @fieldParentPtr(Seat, "relay", relay); + const relay: *InputRelay = @fieldParentPtr("grab_keyboard", listener); + const seat: *Seat = @fieldParentPtr("relay", relay); const active_keyboard = seat.wlr_seat.getKeyboard(); keyboard_grab.setKeyboard(active_keyboard); @@ -158,7 +158,7 @@ fn handleInputMethodNewPopup( listener: *wl.Listener(*wlr.InputPopupSurfaceV2), wlr_popup: *wlr.InputPopupSurfaceV2, ) void { - const relay = @fieldParentPtr(InputRelay, "input_method_new_popup", listener); + const relay: *InputRelay = @fieldParentPtr("input_method_new_popup", listener); InputPopup.create(wlr_popup, relay) catch { log.err("out of memory", .{}); @@ -170,7 +170,7 @@ fn handleInputMethodGrabKeyboardDestroy( listener: *wl.Listener(*wlr.InputMethodV2.KeyboardGrab), keyboard_grab: *wlr.InputMethodV2.KeyboardGrab, ) void { - const relay = @fieldParentPtr(InputRelay, "grab_keyboard_destroy", listener); + const relay: *InputRelay = @fieldParentPtr("grab_keyboard_destroy", listener); relay.grab_keyboard_destroy.link.remove(); if (keyboard_grab.keyboard) |keyboard| { diff --git a/river/Keyboard.zig b/river/Keyboard.zig index 4bc3a10..3c659d8 100644 --- a/river/Keyboard.zig +++ b/river/Keyboard.zig @@ -146,7 +146,7 @@ pub fn deinit(keyboard: *Keyboard) void { fn handleKey(listener: *wl.Listener(*wlr.Keyboard.event.Key), event: *wlr.Keyboard.event.Key) void { // This event is raised when a key is pressed or released. - const keyboard = @fieldParentPtr(Keyboard, "key", listener); + const keyboard: *Keyboard = @fieldParentPtr("key", listener); const wlr_keyboard = keyboard.device.wlr_device.toKeyboard(); // If the keyboard is in a group, this event will be handled by the group's Keyboard instance. @@ -247,7 +247,7 @@ fn isModifier(keysym: xkb.Keysym) bool { } fn handleModifiers(listener: *wl.Listener(*wlr.Keyboard), _: *wlr.Keyboard) void { - const keyboard = @fieldParentPtr(Keyboard, "modifiers", listener); + const keyboard: *Keyboard = @fieldParentPtr("modifiers", listener); const wlr_keyboard = keyboard.device.wlr_device.toKeyboard(); // If the keyboard is in a group, this event will be handled by the group's Keyboard instance. diff --git a/river/KeyboardGroup.zig b/river/KeyboardGroup.zig index cf68bde..5f79608 100644 --- a/river/KeyboardGroup.zig +++ b/river/KeyboardGroup.zig @@ -72,7 +72,7 @@ pub fn destroy(group: *KeyboardGroup) void { group.wlr_group.destroy(); - const node = @fieldParentPtr(std.TailQueue(KeyboardGroup).Node, "data", group); + const node: *std.TailQueue(KeyboardGroup).Node = @fieldParentPtr("data", group); group.seat.keyboard_groups.remove(node); util.gpa.destroy(node); } diff --git a/river/LayerSurface.zig b/river/LayerSurface.zig index 3ab20dc..03d243d 100644 --- a/river/LayerSurface.zig +++ b/river/LayerSurface.zig @@ -80,7 +80,7 @@ pub fn destroyPopups(layer_surface: *LayerSurface) void { } fn handleDestroy(listener: *wl.Listener(*wlr.LayerSurfaceV1), _: *wlr.LayerSurfaceV1) void { - const layer_surface = @fieldParentPtr(LayerSurface, "destroy", listener); + const layer_surface: *LayerSurface = @fieldParentPtr("destroy", listener); log.debug("layer surface '{s}' destroyed", .{layer_surface.wlr_layer_surface.namespace}); @@ -97,7 +97,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.LayerSurfaceV1), _: *wlr.LayerSurfa } fn handleMap(listener: *wl.Listener(void)) void { - const layer_surface = @fieldParentPtr(LayerSurface, "map", listener); + const layer_surface: *LayerSurface = @fieldParentPtr("map", listener); log.debug("layer surface '{s}' mapped", .{layer_surface.wlr_layer_surface.namespace}); @@ -107,7 +107,7 @@ fn handleMap(listener: *wl.Listener(void)) void { } fn handleUnmap(listener: *wl.Listener(void)) void { - const layer_surface = @fieldParentPtr(LayerSurface, "unmap", listener); + const layer_surface: *LayerSurface = @fieldParentPtr("unmap", listener); log.debug("layer surface '{s}' unmapped", .{layer_surface.wlr_layer_surface.namespace}); @@ -117,7 +117,7 @@ fn handleUnmap(listener: *wl.Listener(void)) void { } fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { - const layer_surface = @fieldParentPtr(LayerSurface, "commit", listener); + const layer_surface: *LayerSurface = @fieldParentPtr("commit", listener); const wlr_layer_surface = layer_surface.wlr_layer_surface; assert(wlr_layer_surface.output != null); @@ -186,7 +186,7 @@ fn handleKeyboardInteractiveExclusive(output: *Output) void { } fn handleNewPopup(listener: *wl.Listener(*wlr.XdgPopup), wlr_xdg_popup: *wlr.XdgPopup) void { - const layer_surface = @fieldParentPtr(LayerSurface, "new_popup", listener); + const layer_surface: *LayerSurface = @fieldParentPtr("new_popup", listener); XdgPopup.create( wlr_xdg_popup, diff --git a/river/Layout.zig b/river/Layout.zig index 11626c6..858cd08 100644 --- a/river/Layout.zig +++ b/river/Layout.zig @@ -186,7 +186,7 @@ pub fn destroy(layout: *Layout) void { ); // Remove layout from the list - const node = @fieldParentPtr(std.TailQueue(Layout).Node, "data", layout); + const node: *std.TailQueue(Layout).Node = @fieldParentPtr("data", layout); layout.output.layouts.remove(node); // If we are the currently active layout of an output, clean up. diff --git a/river/LayoutManager.zig b/river/LayoutManager.zig index 0073752..d994d28 100644 --- a/river/LayoutManager.zig +++ b/river/LayoutManager.zig @@ -44,7 +44,7 @@ pub fn init(layout_manager: *LayoutManager) !void { } fn handleServerDestroy(listener: *wl.Listener(*wl.Server), _: *wl.Server) void { - const layout_manager = @fieldParentPtr(LayoutManager, "server_destroy", listener); + const layout_manager: *LayoutManager = @fieldParentPtr("server_destroy", listener); layout_manager.global.destroy(); } diff --git a/river/LockManager.zig b/river/LockManager.zig index 6d60e67..efd1efb 100644 --- a/river/LockManager.zig +++ b/river/LockManager.zig @@ -85,7 +85,7 @@ pub fn deinit(manager: *LockManager) void { } fn handleLock(listener: *wl.Listener(*wlr.SessionLockV1), lock: *wlr.SessionLockV1) void { - const manager = @fieldParentPtr(LockManager, "new_lock", listener); + const manager: *LockManager = @fieldParentPtr("new_lock", listener); if (manager.lock != null) { log.info("denying new session lock client, an active one already exists", .{}); @@ -191,7 +191,7 @@ pub fn maybeLock(manager: *LockManager) void { } fn handleUnlock(listener: *wl.Listener(void)) void { - const manager = @fieldParentPtr(LockManager, "unlock", listener); + const manager: *LockManager = @fieldParentPtr("unlock", listener); manager.state = .unlocked; @@ -229,7 +229,7 @@ fn handleUnlock(listener: *wl.Listener(void)) void { } fn handleDestroy(listener: *wl.Listener(void)) void { - const manager = @fieldParentPtr(LockManager, "destroy", listener); + const manager: *LockManager = @fieldParentPtr("destroy", listener); log.debug("ext_session_lock_v1 destroyed", .{}); @@ -248,7 +248,7 @@ fn handleSurface( listener: *wl.Listener(*wlr.SessionLockSurfaceV1), wlr_lock_surface: *wlr.SessionLockSurfaceV1, ) void { - const manager = @fieldParentPtr(LockManager, "new_surface", listener); + const manager: *LockManager = @fieldParentPtr("new_surface", listener); log.debug("new ext_session_lock_surface_v1 created", .{}); diff --git a/river/LockSurface.zig b/river/LockSurface.zig index 9c8ec94..c3cd384 100644 --- a/river/LockSurface.zig +++ b/river/LockSurface.zig @@ -100,7 +100,7 @@ pub fn configure(lock_surface: *LockSurface) void { } fn handleMap(listener: *wl.Listener(void)) void { - const lock_surface = @fieldParentPtr(LockSurface, "map", listener); + const lock_surface: *LockSurface = @fieldParentPtr("map", listener); const output = lock_surface.getOutput(); output.normal_content.node.setEnabled(false); @@ -132,7 +132,7 @@ fn updateFocus(lock_surface: *LockSurface) void { } fn handleDestroy(listener: *wl.Listener(void)) void { - const lock_surface = @fieldParentPtr(LockSurface, "surface_destroy", listener); + const lock_surface: *LockSurface = @fieldParentPtr("surface_destroy", listener); lock_surface.destroy(); } diff --git a/river/Output.zig b/river/Output.zig index 1403e61..b235c1e 100644 --- a/river/Output.zig +++ b/river/Output.zig @@ -20,6 +20,7 @@ const std = @import("std"); const assert = std.debug.assert; const math = std.math; const mem = std.mem; +const posix = std.posix; const fmt = std.fmt; const wlr = @import("wlroots"); const wayland = @import("wayland"); @@ -401,7 +402,7 @@ fn sendLayerConfigures( } fn handleDestroy(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void { - const output = @fieldParentPtr(Output, "destroy", listener); + const output: *Output = @fieldParentPtr("destroy", listener); log.debug("output '{s}' destroyed", .{output.wlr_output.name}); @@ -436,7 +437,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void { } fn handleRequestState(listener: *wl.Listener(*wlr.Output.event.RequestState), event: *wlr.Output.event.RequestState) void { - const output = @fieldParentPtr(Output, "request_state", listener); + const output: *Output = @fieldParentPtr("request_state", listener); output.applyState(event.state) catch { log.err("failed to commit requested state", .{}); @@ -514,12 +515,12 @@ pub fn updateBackgroundRect(output: *Output) void { output.layers.background_color_rect.setSize(width, height); var it = output.layers.fullscreen.children.iterator(.forward); - const fullscreen_background = @fieldParentPtr(wlr.SceneRect, "node", it.next().?); + const fullscreen_background: *wlr.SceneRect = @fieldParentPtr("node", it.next().?); fullscreen_background.setSize(width, height); } fn handleFrame(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void { - const output = @fieldParentPtr(Output, "frame", listener); + const output: *Output = @fieldParentPtr("frame", listener); const scene_output = server.root.scene.getSceneOutput(output.wlr_output).?; // TODO this should probably be retried on failure @@ -528,8 +529,8 @@ fn handleFrame(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void { error.CommitFailed => log.err("output commit failed for {s}", .{output.wlr_output.name}), }; - var now: std.os.timespec = undefined; - std.os.clock_gettime(std.os.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported"); + var now: posix.timespec = undefined; + posix.clock_gettime(posix.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported"); scene_output.sendFrameDone(&now); } @@ -591,7 +592,7 @@ fn handlePresent( listener: *wl.Listener(*wlr.Output.event.Present), event: *wlr.Output.event.Present, ) void { - const output = @fieldParentPtr(Output, "present", listener); + const output: *Output = @fieldParentPtr("present", listener); if (!event.presented) { return; diff --git a/river/PointerConstraint.zig b/river/PointerConstraint.zig index 4f640e7..b35b29f 100644 --- a/river/PointerConstraint.zig +++ b/river/PointerConstraint.zig @@ -182,14 +182,14 @@ fn warpToHintIfSet(constraint: *PointerConstraint) void { } fn handleNodeDestroy(listener: *wl.Listener(void)) void { - const constraint = @fieldParentPtr(PointerConstraint, "node_destroy", listener); + const constraint: *PointerConstraint = @fieldParentPtr("node_destroy", listener); log.info("deactivating pointer constraint, scene node destroyed", .{}); constraint.deactivate(); } fn handleDestroy(listener: *wl.Listener(*wlr.PointerConstraintV1), _: *wlr.PointerConstraintV1) void { - const constraint = @fieldParentPtr(PointerConstraint, "destroy", listener); + const constraint: *PointerConstraint = @fieldParentPtr("destroy", listener); const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data); if (constraint.state == .active) { @@ -211,7 +211,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.PointerConstraintV1), _: *wlr.Point } fn handleSetRegion(listener: *wl.Listener(void)) void { - const constraint = @fieldParentPtr(PointerConstraint, "set_region", listener); + const constraint: *PointerConstraint = @fieldParentPtr("set_region", listener); const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data); switch (constraint.state) { diff --git a/river/Root.zig b/river/Root.zig index 6d2dd8f..7b87741 100644 --- a/river/Root.zig +++ b/river/Root.zig @@ -740,7 +740,7 @@ fn commitTransaction(root: *Root) void { // We need this listener to deal with outputs that have their position auto-configured // by the wlr_output_layout. fn handleLayoutChange(listener: *wl.Listener(*wlr.OutputLayout), _: *wlr.OutputLayout) void { - const root = @fieldParentPtr(Root, "layout_change", listener); + const root: *Root = @fieldParentPtr("layout_change", listener); root.handleOutputConfigChange() catch std.log.err("out of memory", .{}); } @@ -775,7 +775,7 @@ fn handleManagerApply( listener: *wl.Listener(*wlr.OutputConfigurationV1), config: *wlr.OutputConfigurationV1, ) void { - const root = @fieldParentPtr(Root, "manager_apply", listener); + const root: *Root = @fieldParentPtr("manager_apply", listener); defer config.destroy(); std.log.scoped(.output_manager).info("applying output configuration", .{}); @@ -789,7 +789,7 @@ fn handleManagerTest( listener: *wl.Listener(*wlr.OutputConfigurationV1), config: *wlr.OutputConfigurationV1, ) void { - const root = @fieldParentPtr(Root, "manager_test", listener); + const root: *Root = @fieldParentPtr("manager_test", listener); defer config.destroy(); root.processOutputConfig(config, .test_only); diff --git a/river/SceneNodeData.zig b/river/SceneNodeData.zig index c90ff65..68d5923 100644 --- a/river/SceneNodeData.zig +++ b/river/SceneNodeData.zig @@ -73,7 +73,7 @@ pub fn fromSurface(surface: *wlr.Surface) ?*SceneNodeData { } fn handleDestroy(listener: *wl.Listener(void)) void { - const scene_node_data = @fieldParentPtr(SceneNodeData, "destroy", listener); + const scene_node_data: *SceneNodeData = @fieldParentPtr("destroy", listener); scene_node_data.destroy.link.remove(); scene_node_data.node.data = 0; diff --git a/river/Seat.zig b/river/Seat.zig index 6fc7c65..ff77cce 100644 --- a/river/Seat.zig +++ b/river/Seat.zig @@ -540,7 +540,7 @@ fn handleRequestSetSelection( listener: *wl.Listener(*wlr.Seat.event.RequestSetSelection), event: *wlr.Seat.event.RequestSetSelection, ) void { - const seat = @fieldParentPtr(Seat, "request_set_selection", listener); + const seat: *Seat = @fieldParentPtr("request_set_selection", listener); seat.wlr_seat.setSelection(event.source, event.serial); } @@ -548,7 +548,7 @@ fn handleRequestStartDrag( listener: *wl.Listener(*wlr.Seat.event.RequestStartDrag), event: *wlr.Seat.event.RequestStartDrag, ) void { - const seat = @fieldParentPtr(Seat, "request_start_drag", listener); + const seat: *Seat = @fieldParentPtr("request_start_drag", listener); // The start_drag request is ignored by wlroots if a drag is currently in progress. assert(seat.drag == .none); @@ -572,7 +572,7 @@ fn handleRequestStartDrag( } fn handleStartDrag(listener: *wl.Listener(*wlr.Drag), wlr_drag: *wlr.Drag) void { - const seat = @fieldParentPtr(Seat, "start_drag", listener); + const seat: *Seat = @fieldParentPtr("start_drag", listener); assert(seat.drag == .none); switch (wlr_drag.grab_type) { @@ -595,7 +595,7 @@ fn handleStartDrag(listener: *wl.Listener(*wlr.Drag), wlr_drag: *wlr.Drag) void } fn handleDragDestroy(listener: *wl.Listener(*wlr.Drag), _: *wlr.Drag) void { - const seat = @fieldParentPtr(Seat, "drag_destroy", listener); + const seat: *Seat = @fieldParentPtr("drag_destroy", listener); seat.drag_destroy.link.remove(); switch (seat.drag) { @@ -613,6 +613,6 @@ fn handleRequestSetPrimarySelection( listener: *wl.Listener(*wlr.Seat.event.RequestSetPrimarySelection), event: *wlr.Seat.event.RequestSetPrimarySelection, ) void { - const seat = @fieldParentPtr(Seat, "request_set_primary_selection", listener); + const seat: *Seat = @fieldParentPtr("request_set_primary_selection", listener); seat.wlr_seat.setPrimarySelection(event.source, event.serial); } diff --git a/river/SeatStatus.zig b/river/SeatStatus.zig index 1941774..0c8b3eb 100644 --- a/river/SeatStatus.zig +++ b/river/SeatStatus.zig @@ -49,7 +49,7 @@ fn handleRequest(seat_status_v1: *zriver.SeatStatusV1, request: zriver.SeatStatu } fn handleDestroy(_: *zriver.SeatStatusV1, seat_status: *SeatStatus) void { - const node = @fieldParentPtr(std.SinglyLinkedList(SeatStatus).Node, "data", seat_status); + const node: *std.SinglyLinkedList(SeatStatus).Node = @fieldParentPtr("data", seat_status); seat_status.seat.status_trackers.remove(node); util.gpa.destroy(node); } diff --git a/river/Server.zig b/river/Server.zig index 895f1cc..7b46f3f 100644 --- a/river/Server.zig +++ b/river/Server.zig @@ -19,6 +19,7 @@ const Server = @This(); const build_options = @import("build_options"); const std = @import("std"); const assert = std.debug.assert; +const posix = std.posix; const wlr = @import("wlroots"); const wl = @import("wayland").server.wl; @@ -122,8 +123,8 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void { const loop = wl_server.getEventLoop(); server.* = .{ .wl_server = wl_server, - .sigint_source = try loop.addSignal(*wl.Server, std.os.SIG.INT, terminate, wl_server), - .sigterm_source = try loop.addSignal(*wl.Server, std.os.SIG.TERM, terminate, wl_server), + .sigint_source = try loop.addSignal(*wl.Server, posix.SIG.INT, terminate, wl_server), + .sigterm_source = try loop.addSignal(*wl.Server, posix.SIG.TERM, terminate, wl_server), .backend = backend, .session = session, @@ -371,7 +372,7 @@ fn handleNewToplevelDecoration( } fn handleNewLayerSurface(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_surface: *wlr.LayerSurfaceV1) void { - const server = @fieldParentPtr(Server, "new_layer_surface", listener); + const server: *Server = @fieldParentPtr("new_layer_surface", listener); log.debug( "new layer surface: namespace {s}, layer {s}, anchor {b:0>4}, size {},{}, margin {},{},{},{}, exclusive_zone {}", @@ -431,7 +432,7 @@ fn handleRequestActivate( listener: *wl.Listener(*wlr.XdgActivationV1.event.RequestActivate), event: *wlr.XdgActivationV1.event.RequestActivate, ) void { - const server = @fieldParentPtr(Server, "request_activate", listener); + const server: *Server = @fieldParentPtr("request_activate", listener); const node_data = SceneNodeData.fromSurface(event.surface) orelse return; switch (node_data.data) { diff --git a/river/StatusManager.zig b/river/StatusManager.zig index 43d5367..4464431 100644 --- a/river/StatusManager.zig +++ b/river/StatusManager.zig @@ -46,7 +46,7 @@ pub fn init(status_manager: *StatusManager) !void { } fn handleServerDestroy(listener: *wl.Listener(*wl.Server), _: *wl.Server) void { - const status_manager = @fieldParentPtr(StatusManager, "server_destroy", listener); + const status_manager: *StatusManager = @fieldParentPtr("server_destroy", listener); status_manager.global.destroy(); } diff --git a/river/Switch.zig b/river/Switch.zig index 17e1b8c..470511c 100644 --- a/river/Switch.zig +++ b/river/Switch.zig @@ -71,7 +71,7 @@ pub fn deinit(switch_device: *Switch) void { } fn handleToggle(listener: *wl.Listener(*wlr.Switch.event.Toggle), event: *wlr.Switch.event.Toggle) void { - const switch_device = @fieldParentPtr(Switch, "toggle", listener); + const switch_device: *Switch = @fieldParentPtr("toggle", listener); switch_device.device.seat.handleActivity(); diff --git a/river/TabletTool.zig b/river/TabletTool.zig index 7693875..1642469 100644 --- a/river/TabletTool.zig +++ b/river/TabletTool.zig @@ -90,7 +90,7 @@ fn create(wlr_seat: *wlr.Seat, wlr_tool: *wlr.TabletTool) error{OutOfMemory}!*Ta } fn handleDestroy(listener: *wl.Listener(*wlr.TabletTool), _: *wlr.TabletTool) void { - const tool = @fieldParentPtr(TabletTool, "destroy", listener); + const tool: *TabletTool = @fieldParentPtr("destroy", listener); tool.wp_tool.wlr_tool.data = 0; @@ -106,7 +106,7 @@ fn handleSetCursor( listener: *wl.Listener(*wlr.TabletV2TabletTool.event.SetCursor), event: *wlr.TabletV2TabletTool.event.SetCursor, ) void { - const tool = @fieldParentPtr(TabletTool, "set_cursor", listener); + const tool: *TabletTool = @fieldParentPtr("set_cursor", listener); if (tool.wp_tool.focused_surface == null or tool.wp_tool.focused_surface.?.resource.getClient() != event.seat_client.client) diff --git a/river/TextInput.zig b/river/TextInput.zig index d513758..1364454 100644 --- a/river/TextInput.zig +++ b/river/TextInput.zig @@ -63,7 +63,7 @@ pub fn create(wlr_text_input: *wlr.TextInputV3) !void { } fn handleEnable(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) void { - const text_input = @fieldParentPtr(TextInput, "enable", listener); + const text_input: *TextInput = @fieldParentPtr("enable", listener); const seat: *Seat = @ptrFromInt(text_input.wlr_text_input.seat.data); if (text_input.wlr_text_input.focused_surface == null) { @@ -90,7 +90,7 @@ fn handleEnable(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) v } fn handleCommit(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) void { - const text_input = @fieldParentPtr(TextInput, "commit", listener); + const text_input: *TextInput = @fieldParentPtr("commit", listener); const seat: *Seat = @ptrFromInt(text_input.wlr_text_input.seat.data); if (seat.relay.text_input != text_input) { @@ -104,7 +104,7 @@ fn handleCommit(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) v } fn handleDisable(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) void { - const text_input = @fieldParentPtr(TextInput, "disable", listener); + const text_input: *TextInput = @fieldParentPtr("disable", listener); const seat: *Seat = @ptrFromInt(text_input.wlr_text_input.seat.data); if (seat.relay.text_input == text_input) { @@ -113,7 +113,7 @@ fn handleDisable(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) } fn handleDestroy(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) void { - const text_input = @fieldParentPtr(TextInput, "destroy", listener); + const text_input: *TextInput = @fieldParentPtr("destroy", listener); const seat: *Seat = @ptrFromInt(text_input.wlr_text_input.seat.data); if (seat.relay.text_input == text_input) { diff --git a/river/Vector.zig b/river/Vector.zig index 17fe011..932cba9 100644 --- a/river/Vector.zig +++ b/river/Vector.zig @@ -44,7 +44,7 @@ pub fn direction(v: Vector) ?wlr.OutputLayout.Direction { // A zero length vector has no direction if (v.x == 0 and v.y == 0) return null; - if ((math.absInt(v.y) catch return null) > (math.absInt(v.x) catch return null)) { + if (@abs(v.y) > @abs(v.x)) { // Careful: We are operating in a Y-inverted coordinate system. return if (v.y > 0) .down else .up; } else { diff --git a/river/View.zig b/river/View.zig index b0542ad..bb02da0 100644 --- a/river/View.zig +++ b/river/View.zig @@ -20,7 +20,7 @@ const build_options = @import("build_options"); const std = @import("std"); const assert = std.debug.assert; const math = std.math; -const os = std.os; +const posix = std.posix; const wlr = @import("wlroots"); const wl = @import("wayland").server.wl; @@ -472,8 +472,9 @@ pub fn rootSurface(view: View) ?*wlr.Surface { pub fn sendFrameDone(view: View) void { assert(view.mapped and !view.destroying); - var now: os.timespec = undefined; - os.clock_gettime(os.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported"); + + var now: posix.timespec = undefined; + posix.clock_gettime(posix.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported"); view.rootSurface().?.sendFrameDone(&now); } diff --git a/river/XdgDecoration.zig b/river/XdgDecoration.zig index eb434cf..8ea55de 100644 --- a/river/XdgDecoration.zig +++ b/river/XdgDecoration.zig @@ -66,7 +66,7 @@ fn handleDestroy( listener: *wl.Listener(*wlr.XdgToplevelDecorationV1), _: *wlr.XdgToplevelDecorationV1, ) void { - const decoration = @fieldParentPtr(XdgDecoration, "destroy", listener); + const decoration: *XdgDecoration = @fieldParentPtr("destroy", listener); decoration.deinit(); } @@ -75,7 +75,7 @@ fn handleRequestMode( listener: *wl.Listener(*wlr.XdgToplevelDecorationV1), _: *wlr.XdgToplevelDecorationV1, ) void { - const decoration = @fieldParentPtr(XdgDecoration, "request_mode", listener); + const decoration: *XdgDecoration = @fieldParentPtr("request_mode", listener); const toplevel: *XdgToplevel = @ptrFromInt(decoration.wlr_decoration.toplevel.base.data); const view = toplevel.view; diff --git a/river/XdgPopup.zig b/river/XdgPopup.zig index c539cc9..5198e9b 100644 --- a/river/XdgPopup.zig +++ b/river/XdgPopup.zig @@ -61,7 +61,7 @@ pub fn create( } fn handleDestroy(listener: *wl.Listener(void)) void { - const xdg_popup = @fieldParentPtr(XdgPopup, "destroy", listener); + const xdg_popup: *XdgPopup = @fieldParentPtr("destroy", listener); xdg_popup.destroy.link.remove(); xdg_popup.new_popup.link.remove(); @@ -71,7 +71,7 @@ fn handleDestroy(listener: *wl.Listener(void)) void { } fn handleNewPopup(listener: *wl.Listener(*wlr.XdgPopup), wlr_xdg_popup: *wlr.XdgPopup) void { - const xdg_popup = @fieldParentPtr(XdgPopup, "new_popup", listener); + const xdg_popup: *XdgPopup = @fieldParentPtr("new_popup", listener); XdgPopup.create( wlr_xdg_popup, @@ -84,7 +84,7 @@ fn handleNewPopup(listener: *wl.Listener(*wlr.XdgPopup), wlr_xdg_popup: *wlr.Xdg } fn handleReposition(listener: *wl.Listener(void)) void { - const xdg_popup = @fieldParentPtr(XdgPopup, "reposition", listener); + const xdg_popup: *XdgPopup = @fieldParentPtr("reposition", listener); const output = switch (SceneNodeData.fromNode(&xdg_popup.root.node).?.data) { .view => |view| view.current.output orelse return, diff --git a/river/XdgToplevel.zig b/river/XdgToplevel.zig index 909845a..da3bf92 100644 --- a/river/XdgToplevel.zig +++ b/river/XdgToplevel.zig @@ -200,7 +200,7 @@ pub fn destroyPopups(toplevel: XdgToplevel) void { } fn handleDestroy(listener: *wl.Listener(void)) void { - const toplevel = @fieldParentPtr(XdgToplevel, "destroy", listener); + const toplevel: *XdgToplevel = @fieldParentPtr("destroy", listener); // This can be be non-null here if the client commits a protocol error or // if it exits without destroying its wayland objects. @@ -223,7 +223,7 @@ fn handleDestroy(listener: *wl.Listener(void)) void { } fn handleMap(listener: *wl.Listener(void)) void { - const toplevel = @fieldParentPtr(XdgToplevel, "map", listener); + const toplevel: *XdgToplevel = @fieldParentPtr("map", listener); const view = toplevel.view; // Add listeners that are only active while mapped @@ -266,7 +266,7 @@ fn handleMap(listener: *wl.Listener(void)) void { /// Called when the surface is unmapped and will no longer be displayed. fn handleUnmap(listener: *wl.Listener(void)) void { - const toplevel = @fieldParentPtr(XdgToplevel, "unmap", listener); + const toplevel: *XdgToplevel = @fieldParentPtr("unmap", listener); // Remove listeners that are only active while mapped toplevel.ack_configure.link.remove(); @@ -281,7 +281,7 @@ fn handleUnmap(listener: *wl.Listener(void)) void { } fn handleNewPopup(listener: *wl.Listener(*wlr.XdgPopup), wlr_xdg_popup: *wlr.XdgPopup) void { - const toplevel = @fieldParentPtr(XdgToplevel, "new_popup", listener); + const toplevel: *XdgToplevel = @fieldParentPtr("new_popup", listener); XdgPopup.create(wlr_xdg_popup, toplevel.view.popup_tree, toplevel.view.popup_tree) catch { wlr_xdg_popup.resource.postNoMemory(); @@ -293,7 +293,7 @@ fn handleAckConfigure( listener: *wl.Listener(*wlr.XdgSurface.Configure), acked_configure: *wlr.XdgSurface.Configure, ) void { - const toplevel = @fieldParentPtr(XdgToplevel, "ack_configure", listener); + const toplevel: *XdgToplevel = @fieldParentPtr("ack_configure", listener); switch (toplevel.configure_state) { .inflight => |serial| if (acked_configure.serial == serial) { toplevel.configure_state = .acked; @@ -306,7 +306,7 @@ fn handleAckConfigure( } fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { - const toplevel = @fieldParentPtr(XdgToplevel, "commit", listener); + const toplevel: *XdgToplevel = @fieldParentPtr("commit", listener); const view = toplevel.view; { @@ -395,7 +395,7 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { /// Called when the client asks to be fullscreened. We always honor the request /// for now, perhaps it should be denied in some cases in the future. fn handleRequestFullscreen(listener: *wl.Listener(void)) void { - const toplevel = @fieldParentPtr(XdgToplevel, "request_fullscreen", listener); + const toplevel: *XdgToplevel = @fieldParentPtr("request_fullscreen", listener); if (toplevel.view.pending.fullscreen != toplevel.wlr_toplevel.requested.fullscreen) { toplevel.view.pending.fullscreen = toplevel.wlr_toplevel.requested.fullscreen; server.root.applyPending(); @@ -406,7 +406,7 @@ fn handleRequestMove( listener: *wl.Listener(*wlr.XdgToplevel.event.Move), event: *wlr.XdgToplevel.event.Move, ) void { - const toplevel = @fieldParentPtr(XdgToplevel, "request_move", listener); + const toplevel: *XdgToplevel = @fieldParentPtr("request_move", listener); const seat: *Seat = @ptrFromInt(event.seat.seat.data); const view = toplevel.view; @@ -429,7 +429,7 @@ fn handleRequestMove( } fn handleRequestResize(listener: *wl.Listener(*wlr.XdgToplevel.event.Resize), event: *wlr.XdgToplevel.event.Resize) void { - const toplevel = @fieldParentPtr(XdgToplevel, "request_resize", listener); + const toplevel: *XdgToplevel = @fieldParentPtr("request_resize", listener); const seat: *Seat = @ptrFromInt(event.seat.seat.data); const view = toplevel.view; @@ -453,12 +453,12 @@ fn handleRequestResize(listener: *wl.Listener(*wlr.XdgToplevel.event.Resize), ev /// Called when the client sets / updates its title fn handleSetTitle(listener: *wl.Listener(void)) void { - const toplevel = @fieldParentPtr(XdgToplevel, "set_title", listener); + const toplevel: *XdgToplevel = @fieldParentPtr("set_title", listener); toplevel.view.notifyTitle(); } /// Called when the client sets / updates its app_id fn handleSetAppId(listener: *wl.Listener(void)) void { - const toplevel = @fieldParentPtr(XdgToplevel, "set_app_id", listener); + const toplevel: *XdgToplevel = @fieldParentPtr("set_app_id", listener); toplevel.view.notifyAppId(); } diff --git a/river/XwaylandOverrideRedirect.zig b/river/XwaylandOverrideRedirect.zig index 8a05548..ff638a3 100644 --- a/river/XwaylandOverrideRedirect.zig +++ b/river/XwaylandOverrideRedirect.zig @@ -78,7 +78,7 @@ fn handleRequestConfigure( } fn handleDestroy(listener: *wl.Listener(void)) void { - const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "destroy", listener); + const override_redirect: *XwaylandOverrideRedirect = @fieldParentPtr("destroy", listener); override_redirect.request_configure.link.remove(); override_redirect.destroy.link.remove(); @@ -90,21 +90,21 @@ fn handleDestroy(listener: *wl.Listener(void)) void { } fn handleAssociate(listener: *wl.Listener(void)) void { - const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "associate", listener); + const override_redirect: *XwaylandOverrideRedirect = @fieldParentPtr("associate", listener); override_redirect.xwayland_surface.surface.?.events.map.add(&override_redirect.map); override_redirect.xwayland_surface.surface.?.events.unmap.add(&override_redirect.unmap); } fn handleDissociate(listener: *wl.Listener(void)) void { - const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "dissociate", listener); + const override_redirect: *XwaylandOverrideRedirect = @fieldParentPtr("dissociate", listener); override_redirect.map.link.remove(); override_redirect.unmap.link.remove(); } pub fn handleMap(listener: *wl.Listener(void)) void { - const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "map", listener); + const override_redirect: *XwaylandOverrideRedirect = @fieldParentPtr("map", listener); override_redirect.mapImpl() catch { log.err("out of memory", .{}); @@ -155,7 +155,7 @@ pub fn focusIfDesired(override_redirect: *XwaylandOverrideRedirect) void { } fn handleUnmap(listener: *wl.Listener(void)) void { - const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "unmap", listener); + const override_redirect: *XwaylandOverrideRedirect = @fieldParentPtr("unmap", listener); override_redirect.set_geometry.link.remove(); @@ -180,7 +180,7 @@ fn handleUnmap(listener: *wl.Listener(void)) void { } fn handleSetGeometry(listener: *wl.Listener(void)) void { - const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "set_geometry", listener); + const override_redirect: *XwaylandOverrideRedirect = @fieldParentPtr("set_geometry", listener); override_redirect.surface_tree.?.node.setPosition( override_redirect.xwayland_surface.x, @@ -189,7 +189,7 @@ fn handleSetGeometry(listener: *wl.Listener(void)) void { } fn handleSetOverrideRedirect(listener: *wl.Listener(void)) void { - const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "set_override_redirect", listener); + const override_redirect: *XwaylandOverrideRedirect = @fieldParentPtr("set_override_redirect", listener); const xwayland_surface = override_redirect.xwayland_surface; log.debug("xwayland surface unset override redirect", .{}); diff --git a/river/XwaylandView.zig b/river/XwaylandView.zig index 7155868..80cecc6 100644 --- a/river/XwaylandView.zig +++ b/river/XwaylandView.zig @@ -131,7 +131,7 @@ fn setActivated(xwayland_view: XwaylandView, activated: bool) void { } fn handleDestroy(listener: *wl.Listener(void)) void { - const xwayland_view = @fieldParentPtr(XwaylandView, "destroy", listener); + const xwayland_view: *XwaylandView = @fieldParentPtr("destroy", listener); // Remove listeners that are active for the entire lifetime of the view xwayland_view.destroy.link.remove(); @@ -146,20 +146,20 @@ fn handleDestroy(listener: *wl.Listener(void)) void { } fn handleAssociate(listener: *wl.Listener(void)) void { - const xwayland_view = @fieldParentPtr(XwaylandView, "associate", listener); + const xwayland_view: *XwaylandView = @fieldParentPtr("associate", listener); xwayland_view.xwayland_surface.surface.?.events.map.add(&xwayland_view.map); xwayland_view.xwayland_surface.surface.?.events.unmap.add(&xwayland_view.unmap); } fn handleDissociate(listener: *wl.Listener(void)) void { - const xwayland_view = @fieldParentPtr(XwaylandView, "dissociate", listener); + const xwayland_view: *XwaylandView = @fieldParentPtr("dissociate", listener); xwayland_view.map.link.remove(); xwayland_view.unmap.link.remove(); } pub fn handleMap(listener: *wl.Listener(void)) void { - const xwayland_view = @fieldParentPtr(XwaylandView, "map", listener); + const xwayland_view: *XwaylandView = @fieldParentPtr("map", listener); const view = xwayland_view.view; const xwayland_surface = xwayland_view.xwayland_surface; @@ -213,7 +213,7 @@ pub fn handleMap(listener: *wl.Listener(void)) void { } fn handleUnmap(listener: *wl.Listener(void)) void { - const xwayland_view = @fieldParentPtr(XwaylandView, "unmap", listener); + const xwayland_view: *XwaylandView = @fieldParentPtr("unmap", listener); xwayland_view.xwayland_surface.surface.?.data = 0; @@ -235,7 +235,7 @@ fn handleRequestConfigure( listener: *wl.Listener(*wlr.XwaylandSurface.event.Configure), event: *wlr.XwaylandSurface.event.Configure, ) void { - const xwayland_view = @fieldParentPtr(XwaylandView, "request_configure", listener); + const xwayland_view: *XwaylandView = @fieldParentPtr("request_configure", listener); // If unmapped, let the client do whatever it wants if (xwayland_view.xwayland_surface.surface == null or @@ -254,7 +254,7 @@ fn handleRequestConfigure( } fn handleSetOverrideRedirect(listener: *wl.Listener(void)) void { - const xwayland_view = @fieldParentPtr(XwaylandView, "set_override_redirect", listener); + const xwayland_view: *XwaylandView = @fieldParentPtr("set_override_redirect", listener); const xwayland_surface = xwayland_view.xwayland_surface; log.debug("xwayland surface set override redirect", .{}); @@ -276,17 +276,17 @@ fn handleSetOverrideRedirect(listener: *wl.Listener(void)) void { } fn handleSetTitle(listener: *wl.Listener(void)) void { - const xwayland_view = @fieldParentPtr(XwaylandView, "set_title", listener); + const xwayland_view: *XwaylandView = @fieldParentPtr("set_title", listener); xwayland_view.view.notifyTitle(); } fn handleSetClass(listener: *wl.Listener(void)) void { - const xwayland_view = @fieldParentPtr(XwaylandView, "set_class", listener); + const xwayland_view: *XwaylandView = @fieldParentPtr("set_class", listener); xwayland_view.view.notifyAppId(); } fn handleSetDecorations(listener: *wl.Listener(void)) void { - const xwayland_view = @fieldParentPtr(XwaylandView, "set_decorations", listener); + const xwayland_view: *XwaylandView = @fieldParentPtr("set_decorations", listener); const view = xwayland_view.view; const ssd = server.config.rules.ssd.match(view) orelse @@ -299,7 +299,7 @@ fn handleSetDecorations(listener: *wl.Listener(void)) void { } fn handleRequestFullscreen(listener: *wl.Listener(void)) void { - const xwayland_view = @fieldParentPtr(XwaylandView, "request_fullscreen", listener); + const xwayland_view: *XwaylandView = @fieldParentPtr("request_fullscreen", listener); if (xwayland_view.view.pending.fullscreen != xwayland_view.xwayland_surface.fullscreen) { xwayland_view.view.pending.fullscreen = xwayland_view.xwayland_surface.fullscreen; server.root.applyPending(); @@ -314,6 +314,6 @@ fn handleRequestMinimize( listener: *wl.Listener(*wlr.XwaylandSurface.event.Minimize), event: *wlr.XwaylandSurface.event.Minimize, ) void { - const xwayland_view = @fieldParentPtr(XwaylandView, "request_minimize", listener); + const xwayland_view: *XwaylandView = @fieldParentPtr("request_minimize", listener); xwayland_view.xwayland_surface.setMinimized(event.minimize); } diff --git a/river/command/output.zig b/river/command/output.zig index 3e10635..8f7cd0e 100644 --- a/river/command/output.zig +++ b/river/command/output.zig @@ -109,7 +109,7 @@ fn getOutput(seat: *Seat, str: []const u8) !?*Output { .previous => link.prev.?, }; } - return @fieldParentPtr(Output, "active_link", link); + return @as(*Output, @fieldParentPtr("active_link", link)); } else if (std.meta.stringToEnum(wlr.OutputLayout.Direction, str)) |direction| { // Spacial direction var focus_box: wlr.Box = undefined; server.root.output_layout.getBox(seat.focused_output.?.wlr_output, &focus_box); diff --git a/river/command/spawn.zig b/river/command/spawn.zig index e62bf2f..030535a 100644 --- a/river/command/spawn.zig +++ b/river/command/spawn.zig @@ -15,7 +15,7 @@ // along with this program. If not, see . const std = @import("std"); -const os = std.os; +const posix = std.posix; const c = @import("../c.zig"); const util = @import("../util.zig"); @@ -35,23 +35,26 @@ pub fn spawn( const child_args = [_:null]?[*:0]const u8{ "/bin/sh", "-c", args[1], null }; - const pid = os.fork() catch { + const pid = posix.fork() catch { out.* = try std.fmt.allocPrint(util.gpa, "fork/execve failed", .{}); return Error.Other; }; if (pid == 0) { process.cleanupChild(); - const pid2 = os.fork() catch c._exit(1); - if (pid2 == 0) os.execveZ("/bin/sh", &child_args, std.c.environ) catch c._exit(1); + + const pid2 = posix.fork() catch c._exit(1); + if (pid2 == 0) { + posix.execveZ("/bin/sh", &child_args, std.c.environ) catch c._exit(1); + } c._exit(0); } // Wait the intermediate child. - const ret = os.waitpid(pid, 0); - if (!os.W.IFEXITED(ret.status) or - (os.W.IFEXITED(ret.status) and os.W.EXITSTATUS(ret.status) != 0)) + const ret = posix.waitpid(pid, 0); + if (!posix.W.IFEXITED(ret.status) or + (posix.W.IFEXITED(ret.status) and posix.W.EXITSTATUS(ret.status) != 0)) { out.* = try std.fmt.allocPrint(util.gpa, "fork/execve failed", .{}); return Error.Other; diff --git a/river/main.zig b/river/main.zig index 74579bf..19d23b5 100644 --- a/river/main.zig +++ b/river/main.zig @@ -20,7 +20,7 @@ const mem = std.mem; const fs = std.fs; const io = std.io; const log = std.log; -const os = std.os; +const posix = std.posix; const builtin = @import("builtin"); const wlr = @import("wlroots"); const flags = @import("flags"); @@ -57,23 +57,23 @@ pub fn main() anyerror!void { .{ .name = "c", .kind = .arg }, .{ .name = "log-level", .kind = .arg }, .{ .name = "no-xwayland", .kind = .boolean }, - }).parse(os.argv[1..]) catch { + }).parse(std.os.argv[1..]) catch { try io.getStdErr().writeAll(usage); - os.exit(1); + posix.exit(1); }; if (result.flags.h) { try io.getStdOut().writeAll(usage); - os.exit(0); + posix.exit(0); } if (result.args.len != 0) { log.err("unknown option '{s}'", .{result.args[0]}); try io.getStdErr().writeAll(usage); - os.exit(1); + posix.exit(1); } if (result.flags.version) { try io.getStdOut().writeAll(build_options.version ++ "\n"); - os.exit(0); + posix.exit(0); } if (result.flags.@"log-level") |level| { if (mem.eql(u8, level, "error")) { @@ -87,7 +87,7 @@ pub fn main() anyerror!void { } else { log.err("invalid log level '{s}'", .{level}); try io.getStdErr().writeAll(usage); - os.exit(1); + posix.exit(1); } } const enable_xwayland = !result.flags.@"no-xwayland"; @@ -119,16 +119,16 @@ pub fn main() anyerror!void { const child_pgid = if (startup_command) |cmd| blk: { log.info("running init executable '{s}'", .{cmd}); const child_args = [_:null]?[*:0]const u8{ "/bin/sh", "-c", cmd, null }; - const pid = try os.fork(); + const pid = try posix.fork(); if (pid == 0) { process.cleanupChild(); - os.execveZ("/bin/sh", &child_args, std.c.environ) catch c._exit(1); + posix.execveZ("/bin/sh", &child_args, std.c.environ) catch c._exit(1); } util.gpa.free(cmd); // Since the child has called setsid, the pid is the pgid break :blk pid; } else null; - defer if (child_pgid) |pgid| os.kill(-pgid, os.SIG.TERM) catch |err| { + defer if (child_pgid) |pgid| posix.kill(-pgid, posix.SIG.TERM) catch |err| { log.err("failed to kill init process group: {s}", .{@errorName(err)}); }; @@ -141,20 +141,20 @@ pub fn main() anyerror!void { fn defaultInitPath() !?[:0]const u8 { const path = blk: { - if (os.getenv("XDG_CONFIG_HOME")) |xdg_config_home| { + if (posix.getenv("XDG_CONFIG_HOME")) |xdg_config_home| { break :blk try fs.path.joinZ(util.gpa, &[_][]const u8{ xdg_config_home, "river/init" }); - } else if (os.getenv("HOME")) |home| { + } else if (posix.getenv("HOME")) |home| { break :blk try fs.path.joinZ(util.gpa, &[_][]const u8{ home, ".config/river/init" }); } else { return null; } }; - os.accessZ(path, os.X_OK) catch |err| { + posix.accessZ(path, posix.X_OK) catch |err| { if (err == error.PermissionDenied) { - if (os.accessZ(path, os.R_OK)) { + if (posix.accessZ(path, posix.R_OK)) { log.err("failed to run init executable {s}: the file is not executable", .{path}); - os.exit(1); + posix.exit(1); } else |_| {} } log.err("failed to run init executable {s}: {s}", .{ path, @errorName(err) }); @@ -171,25 +171,26 @@ var runtime_log_level: log.Level = switch (builtin.mode) { .ReleaseSafe, .ReleaseFast, .ReleaseSmall => .info, }; -pub const std_options = struct { - /// Tell std.log to leave all log level filtering to us. - pub const log_level: log.Level = .debug; - - pub fn logFn( - comptime level: log.Level, - comptime scope: @TypeOf(.EnumLiteral), - comptime format: []const u8, - args: anytype, - ) void { - if (@intFromEnum(level) > @intFromEnum(runtime_log_level)) return; - - const scope_prefix = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): "; - - const stderr = io.getStdErr().writer(); - stderr.print(level.asText() ++ scope_prefix ++ format ++ "\n", args) catch {}; - } +pub const std_options: std.Options = .{ + // Tell std.log to leave all log level filtering to us. + .log_level = .debug, + .logFn = logFn, }; +pub fn logFn( + comptime level: log.Level, + comptime scope: @TypeOf(.EnumLiteral), + comptime format: []const u8, + args: anytype, +) void { + if (@intFromEnum(level) > @intFromEnum(runtime_log_level)) return; + + const scope_prefix = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): "; + + const stderr = io.getStdErr().writer(); + stderr.print(level.asText() ++ scope_prefix ++ format ++ "\n", args) catch {}; +} + /// See wlroots_log_wrapper.c extern fn river_init_wlroots_log(importance: wlr.log.Importance) void; export fn river_wlroots_log_callback(importance: wlr.log.Importance, ptr: [*:0]const u8, len: usize) void { diff --git a/river/process.zig b/river/process.zig index 27316c1..c83f61f 100644 --- a/river/process.zig +++ b/river/process.zig @@ -15,21 +15,21 @@ // along with this program. If not, see . const std = @import("std"); -const os = std.os; +const posix = std.posix; const c = @import("c.zig"); -var original_rlimit: ?os.rlimit = null; +var original_rlimit: ?posix.rlimit = null; pub fn setup() void { // Ignore SIGPIPE so we don't get killed when writing to a socket that // has had its read end closed by another process. - const sig_ign = os.Sigaction{ - .handler = .{ .handler = os.SIG.IGN }, - .mask = os.empty_sigset, + const sig_ign = posix.Sigaction{ + .handler = .{ .handler = posix.SIG.IGN }, + .mask = posix.empty_sigset, .flags = 0, }; - os.sigaction(os.SIG.PIPE, &sig_ign, null) catch unreachable; + posix.sigaction(posix.SIG.PIPE, &sig_ign, null) catch unreachable; // Most unix systems have a default limit of 1024 file descriptors and it // seems unlikely for this default to be universally raised due to the @@ -41,13 +41,13 @@ pub fn setup() void { // to catch any fd leaks. Therefore, don't use some crazy high limit that // can never be reached before the system runs out of memory. This can be // raised further if anyone reaches it in practice. - if (os.getrlimit(.NOFILE)) |original| { + if (posix.getrlimit(.NOFILE)) |original| { original_rlimit = original; - const new: os.rlimit = .{ + const new: posix.rlimit = .{ .cur = @min(4096, original.max), .max = original.max, }; - if (os.setrlimit(.NOFILE, new)) { + if (posix.setrlimit(.NOFILE, new)) { std.log.info("raised file descriptor limit of the river process to {d}", .{new.cur}); } else |_| { std.log.err("setrlimit failed, using system default file descriptor limit of {d}", .{ @@ -61,17 +61,17 @@ pub fn setup() void { pub fn cleanupChild() void { if (c.setsid() < 0) unreachable; - if (os.system.sigprocmask(os.SIG.SETMASK, &os.empty_sigset, null) < 0) unreachable; + if (posix.system.sigprocmask(posix.SIG.SETMASK, &posix.empty_sigset, null) < 0) unreachable; - const sig_dfl = os.Sigaction{ - .handler = .{ .handler = os.SIG.DFL }, - .mask = os.empty_sigset, + const sig_dfl = posix.Sigaction{ + .handler = .{ .handler = posix.SIG.DFL }, + .mask = posix.empty_sigset, .flags = 0, }; - os.sigaction(os.SIG.PIPE, &sig_dfl, null) catch unreachable; + posix.sigaction(posix.SIG.PIPE, &sig_dfl, null) catch unreachable; if (original_rlimit) |original| { - os.setrlimit(.NOFILE, original) catch { + posix.setrlimit(.NOFILE, original) catch { std.log.err("failed to restore original file descriptor limit for " ++ "child process, setrlimit failed", .{}); }; diff --git a/riverctl/main.zig b/riverctl/main.zig index b0511b4..13a36ae 100644 --- a/riverctl/main.zig +++ b/riverctl/main.zig @@ -17,7 +17,7 @@ const std = @import("std"); const mem = std.mem; const io = std.io; -const os = std.os; +const posix = std.posix; const assert = std.debug.assert; const builtin = @import("builtin"); @@ -57,7 +57,7 @@ pub fn main() !void { , .{}), error.ConnectFailed => { std.log.err("Unable to connect to the Wayland server.", .{}); - if (os.getenvZ("WAYLAND_DISPLAY") == null) { + if (posix.getenvZ("WAYLAND_DISPLAY") == null) { fatal("WAYLAND_DISPLAY is not set.", .{}); } else { fatal("Does WAYLAND_DISPLAY contain the socket name of a running server?", .{}); @@ -72,17 +72,17 @@ fn _main() !void { const result = flags.parser([*:0]const u8, &.{ .{ .name = "h", .kind = .boolean }, .{ .name = "version", .kind = .boolean }, - }).parse(os.argv[1..]) catch { + }).parse(std.os.argv[1..]) catch { try io.getStdErr().writeAll(usage); - os.exit(1); + posix.exit(1); }; if (result.flags.h) { try io.getStdOut().writeAll(usage); - os.exit(0); + posix.exit(0); } if (result.flags.version) { try io.getStdOut().writeAll(@import("build_options").version ++ "\n"); - os.exit(0); + posix.exit(0); } const display = try wl.Display.connect(null); @@ -128,14 +128,14 @@ fn callbackListener(_: *zriver.CommandCallbackV1, event: zriver.CommandCallbackV const stdout = io.getStdOut().writer(); stdout.print("{s}\n", .{success.output}) catch @panic("failed to write to stdout"); } - os.exit(0); + posix.exit(0); }, .failure => |failure| { // A small hack to provide usage text when river reports an unknown command. if (mem.orderZ(u8, failure.failure_message, "unknown command") == .eq) { std.log.err("unknown command", .{}); io.getStdErr().writeAll(usage) catch {}; - os.exit(1); + posix.exit(1); } fatal("{s}", .{failure.failure_message}); }, @@ -144,5 +144,5 @@ fn callbackListener(_: *zriver.CommandCallbackV1, event: zriver.CommandCallbackV fn fatal(comptime format: []const u8, args: anytype) noreturn { std.log.err(format, args); - os.exit(1); + posix.exit(1); } diff --git a/rivertile/main.zig b/rivertile/main.zig index a2caf8e..2590e7e 100644 --- a/rivertile/main.zig +++ b/rivertile/main.zig @@ -39,7 +39,7 @@ const std = @import("std"); const fmt = std.fmt; const mem = std.mem; const math = std.math; -const os = std.os; +const posix = std.posix; const assert = std.debug.assert; const wayland = @import("wayland"); @@ -311,19 +311,19 @@ pub fn main() !void { .{ .name = "main-location", .kind = .arg }, .{ .name = "main-count", .kind = .arg }, .{ .name = "main-ratio", .kind = .arg }, - }).parse(os.argv[1..]) catch { + }).parse(std.os.argv[1..]) catch { try std.io.getStdErr().writeAll(usage); - os.exit(1); + posix.exit(1); }; if (result.flags.h) { try std.io.getStdOut().writeAll(usage); - os.exit(0); + posix.exit(0); } if (result.args.len != 0) fatalPrintUsage("unknown option '{s}'", .{result.args[0]}); if (result.flags.version) { try std.io.getStdOut().writeAll(@import("build_options").version ++ "\n"); - os.exit(0); + posix.exit(0); } if (result.flags.@"view-padding") |raw| { view_padding = fmt.parseUnsigned(u31, raw, 10) catch @@ -352,7 +352,7 @@ pub fn main() !void { const display = wl.Display.connect(null) catch { std.debug.print("Unable to connect to Wayland server.\n", .{}); - os.exit(1); + posix.exit(1); }; defer display.disconnect(); @@ -405,13 +405,13 @@ fn registryListener(registry: *wl.Registry, event: wl.Registry.Event, context: * fn fatal(comptime format: []const u8, args: anytype) noreturn { std.log.err(format, args); - os.exit(1); + posix.exit(1); } fn fatalPrintUsage(comptime format: []const u8, args: anytype) noreturn { std.log.err(format, args); std.io.getStdErr().writeAll(usage) catch {}; - os.exit(1); + posix.exit(1); } fn saturatingCast(comptime T: type, x: anytype) T { From 045ee7bd25963d1a12635fd83af0629474c5575f Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sat, 20 Apr 2024 13:27:03 +0200 Subject: [PATCH 08/13] build: add -Dno-llvm build option --- build.zig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/build.zig b/build.zig index 1b9fba9..286145e 100644 --- a/build.zig +++ b/build.zig @@ -18,6 +18,7 @@ pub fn build(b: *Build) !void { const strip = b.option(bool, "strip", "Omit debug information") orelse false; const pie = b.option(bool, "pie", "Build a Position Independent Executable") orelse false; + const llvm = !(b.option(bool, "no-llvm", "(expirimental) Use non-LLVM x86 Zig backend") orelse false); const omit_frame_pointer = switch (optimize) { .Debug, .ReleaseSafe => false, @@ -169,6 +170,8 @@ pub fn build(b: *Build) !void { .target = target, .optimize = optimize, .strip = strip, + .use_llvm = llvm, + .use_lld = llvm, }); river.root_module.addOptions("build_options", options); @@ -206,6 +209,8 @@ pub fn build(b: *Build) !void { .target = target, .optimize = optimize, .strip = strip, + .use_llvm = llvm, + .use_lld = llvm, }); riverctl.root_module.addOptions("build_options", options); @@ -229,6 +234,8 @@ pub fn build(b: *Build) !void { .target = target, .optimize = optimize, .strip = strip, + .use_llvm = llvm, + .use_lld = llvm, }); rivertile.root_module.addOptions("build_options", options); From 958f8798b6fdfab40aa29e1538827fa74e833a1c Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 20 May 2024 11:33:04 +0200 Subject: [PATCH 09/13] build: switch to the Zig package manager No more git submodules! --- .gitmodules | 12 ------------ PACKAGING.md | 39 +++++++++++++++++++++++++++++++++++++++ README.md | 12 ++---------- build.zig | 40 +++++++++++++++------------------------- build.zig.zon | 23 +++++++++++++++++++++++ deps/zig-pixman | 1 - deps/zig-wayland | 1 - deps/zig-wlroots | 1 - deps/zig-xkbcommon | 1 - 9 files changed, 79 insertions(+), 51 deletions(-) delete mode 100644 .gitmodules create mode 100644 build.zig.zon delete mode 160000 deps/zig-pixman delete mode 160000 deps/zig-wayland delete mode 160000 deps/zig-wlroots delete mode 160000 deps/zig-xkbcommon diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 0729afd..0000000 --- a/.gitmodules +++ /dev/null @@ -1,12 +0,0 @@ -[submodule "deps/zig-wayland"] - path = deps/zig-wayland - url = https://codeberg.org/ifreund/zig-wayland -[submodule "deps/zig-pixman"] - path = deps/zig-pixman - url = https://codeberg.org/ifreund/zig-pixman -[submodule "deps/zig-xkbcommon"] - path = deps/zig-xkbcommon - url = https://codeberg.org/ifreund/zig-xkbcommon -[submodule "deps/zig-wlroots"] - path = deps/zig-wlroots - url = https://codeberg.org/ifreund/zig-wlroots diff --git a/PACKAGING.md b/PACKAGING.md index 0e465bd..315fe14 100644 --- a/PACKAGING.md +++ b/PACKAGING.md @@ -26,6 +26,45 @@ and is only compatible with that release and any patch releases. At the time of writing for example river is compatible with Zig 0.9.0 and 0.9.1 but not Zig 0.8.0 or 0.10.0. +## Zig Package Manager + +River uses the built-in Zig package manager for its (few) Zig dependencies. +By default, running `zig build` will fetch river's Zig dependencies from the +internet and store them in the global zig cache before building river. Since +accessing the internet is forbidden or at least frowned upon by most distro +packaging infrastructure, there are ways to fetch the Zig dependencies in a +separate step before building river: + +1. Fetch step with internet access: + + For each package in the `build.zig.zon` manifest file run the following command + with the tarball URL in the `build.zig.zon`: + + ``` + zig fetch --global-cache-dir /tmp/foobar $URL + ``` + + This command will download and unpack the tarball, hash the contents of the + tarball, and store the contents in the `/tmp/foobar/p/$HASH` directory. This + hash should match the corresponding hash field in the `build.zig.zon`. + +2. Build step with no internet access: + + The `--system` flag for `zig build` takes a path to an arbitrary directory in + which zig packages stored in subdirectories matching their hash can be found. + + ``` + zig build --system /tmp/foobar/p/ ... + ``` + + This flag will disable all internet access and error if a package is not found + in the provided directory. + +It is also possible for distros to distribute Zig package manager packages as +distro packages, although there are still some rough edges as the support for +this is not yet mature. See this patchset for Chimera Linux for an example of +how this can work: https://github.com/chimera-linux/cports/pull/1395 + ## Build options River is built using the Zig build system. To see all available build diff --git a/README.md b/README.md index 8b8c5b9..e3cd756 100644 --- a/README.md +++ b/README.md @@ -51,12 +51,7 @@ commands to set up the user's configuration. ## Building -On cloning the repository, you must init and update the submodules as well -with e.g. - -``` -git submodule update --init -``` +Note: If you are packaging river for distribution, see [PACKAGING.md](PACKAGING.md). To compile river first ensure that you have the following dependencies installed. The "development" versions are required if applicable to your @@ -76,10 +71,7 @@ Then run, for example: ``` zig build -Doptimize=ReleaseSafe --prefix ~/.local install ``` -To enable experimental Xwayland support pass the `-Dxwayland` option as well. - -If you are packaging river for distribution, see also -[PACKAGING.md](PACKAGING.md). +To enable Xwayland support pass the `-Dxwayland` option as well. ## Usage diff --git a/build.zig b/build.zig index 286145e..b4eacc1 100644 --- a/build.zig +++ b/build.zig @@ -4,7 +4,7 @@ const Build = std.Build; const fs = std.fs; const mem = std.mem; -const Scanner = @import("deps/zig-wayland/build.zig").Scanner; +const Scanner = @import("zig-wayland").Scanner; /// While a river release is in development, this string should contain the version in development /// with the "-dev" suffix. @@ -132,32 +132,20 @@ pub fn build(b: *Build) !void { scanner.generate("zwlr_layer_shell_v1", 4); scanner.generate("zwlr_output_power_manager_v1", 1); - const wayland = b.createModule(.{ - .root_source_file = scanner.result, - .target = target, - }); + const wayland = b.createModule(.{ .root_source_file = scanner.result }); - const xkbcommon = b.createModule(.{ - .root_source_file = .{ .path = "deps/zig-xkbcommon/src/xkbcommon.zig" }, - .target = target, - }); - xkbcommon.linkSystemLibrary("xkbcommon", .{}); + const xkbcommon = b.dependency("zig-xkbcommon", .{}).module("xkbcommon"); + const pixman = b.dependency("zig-pixman", .{}).module("pixman"); - const pixman = b.createModule(.{ - .root_source_file = .{ .path = "deps/zig-pixman/pixman.zig" }, - .target = target, - }); - pixman.linkSystemLibrary("pixman-1", .{}); + const wlroots = b.dependency("zig-wlroots", .{}).module("wlroots"); + wlroots.addImport("wayland", wayland); + wlroots.addImport("xkbcommon", xkbcommon); + wlroots.addImport("pixman", pixman); - const wlroots = b.createModule(.{ - .root_source_file = .{ .path = "deps/zig-wlroots/src/wlroots.zig" }, - .imports = &.{ - .{ .name = "wayland", .module = wayland }, - .{ .name = "xkbcommon", .module = xkbcommon }, - .{ .name = "pixman", .module = pixman }, - }, - .target = target, - }); + // We need to ensure the wlroots include path obtained from pkg-config is + // exposed to the wlroots module for @cImport() to work. This seems to be + // the best way to do so with the current std.Build API. + wlroots.resolved_target = target; wlroots.linkSystemLibrary("wlroots", .{}); const flags = b.createModule(.{ .root_source_file = .{ .path = "common/flags.zig" } }); @@ -179,6 +167,9 @@ pub fn build(b: *Build) !void { river.linkSystemLibrary("libevdev"); river.linkSystemLibrary("libinput"); river.linkSystemLibrary("wayland-server"); + river.linkSystemLibrary("wlroots"); + river.linkSystemLibrary("xkbcommon"); + river.linkSystemLibrary("pixman-1"); river.root_module.addImport("wayland", wayland); river.root_module.addImport("xkbcommon", xkbcommon); @@ -191,7 +182,6 @@ pub fn build(b: *Build) !void { .file = .{ .path = "river/wlroots_log_wrapper.c" }, .flags = &.{ "-std=c99", "-O2" }, }); - river.linkSystemLibrary("wlroots"); // TODO: remove when zig issue #131 is implemented scanner.addCSource(river); diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..057490a --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,23 @@ +.{ + .name = "river", + .version = "0.4.0-dev", + .paths = .{""}, + .dependencies = .{ + .@"zig-pixman" = .{ + .url = "https://codeberg.org/ifreund/zig-pixman/archive/v0.1.0.tar.gz", + .hash = "122014eeb4600a059bdcfe1c864862f17e6d5e4237e3bb7d6818f2a5583f6f4eb843", + }, + .@"zig-wayland" = .{ + .url = "https://codeberg.org/ifreund/zig-wayland/archive/v0.1.0.tar.gz", + .hash = "1220b0f8f822c1625af7aae4cb3ab2c4ec1a4c0e99ef32867b2a8d88bb070b3e7f6d", + }, + .@"zig-wlroots" = .{ + .url = "https://codeberg.org/ifreund/zig-wlroots/archive/v0.17.0.tar.gz", + .hash = "1220714d1cc39c3abb1d9c22a0b838d847ead099cb7d9931821490483f30c022e827", + }, + .@"zig-xkbcommon" = .{ + .url = "https://codeberg.org/ifreund/zig-xkbcommon/archive/v0.1.0.tar.gz", + .hash = "1220840390382c88caf9b0887f6cebbba3a7d05960b8b2ee6d80567b2950b71e5017", + }, + }, +} diff --git a/deps/zig-pixman b/deps/zig-pixman deleted file mode 160000 index 70bff91..0000000 --- a/deps/zig-pixman +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 70bff91beec4ad4c026dfc4465613e360dc85527 diff --git a/deps/zig-wayland b/deps/zig-wayland deleted file mode 160000 index 6be3eb9..0000000 --- a/deps/zig-wayland +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6be3eb9bff878bbf3f83a7c6862f1e14233606f5 diff --git a/deps/zig-wlroots b/deps/zig-wlroots deleted file mode 160000 index 941859c..0000000 --- a/deps/zig-wlroots +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 941859cd842b68cc5d20757e8708eb70295e9344 diff --git a/deps/zig-xkbcommon b/deps/zig-xkbcommon deleted file mode 160000 index 3a2eefd..0000000 --- a/deps/zig-xkbcommon +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3a2eefdad6b4d48757274061dd2b5df3b89a2bfd From 7fdba05b8249b10d10a2c64c1175429539c01af1 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 20 May 2024 11:45:09 +0200 Subject: [PATCH 10/13] ci: drop FreeBSD CI for now There is no FreeBSD tarball from ziglang.org and FreeBSD itself has not yet updated their Zig package to 0.12.0. This commit should be reverted when a good way is found to obtain Zig 0.12.0 for the FreeBSD CI. --- .builds/freebsd.yml | 61 --------------------------------------------- 1 file changed, 61 deletions(-) delete mode 100644 .builds/freebsd.yml diff --git a/.builds/freebsd.yml b/.builds/freebsd.yml deleted file mode 100644 index e05be88..0000000 --- a/.builds/freebsd.yml +++ /dev/null @@ -1,61 +0,0 @@ -image: freebsd/latest -packages: - - devel/evdev-proto - - devel/libevdev - - devel/libepoll-shim - - devel/libudev-devd - - devel/meson - - devel/pkgconf - - graphics/mesa-libs - - graphics/wayland-protocols - - misc/hwdata - - x11/libX11 - - x11/libinput - - x11/libxcb - - x11/libxkbcommon - - x11/pixman - - x11/xcb-util-errors - - x11/xcb-util-renderutil - - x11/xcb-util-wm - - x11-servers/xwayland - - sysutils/seatd - - sysutils/libdisplay-info - - gmake - - scdoc - - wget -sources: - - https://codeberg.org/river/river - - https://gitlab.freedesktop.org/wayland/wayland.git - - https://gitlab.freedesktop.org/wlroots/wlroots.git -tasks: - - install_deps: | - cd wayland - git checkout 1.22.0 - meson setup build -Ddocumentation=false -Dtests=false --prefix /usr - sudo ninja -C build install - cd .. - - cd wlroots - git checkout 0.17.2 - meson setup build --auto-features=enabled -Drenderers=gles2 -Dexamples=false \ - -Dwerror=false -Db_ndebug=false --prefix /usr - sudo ninja -C build/ install - cd .. - - wget -nv https://ziglang.org/download/0.12.0/zig-freebsd-x86_64-0.12.0.tar.xz - # Remove a lot of useless lines from tar output. - tar -xvf zig-freebsd-x86_64-0.12.0.tar.xz 1>/dev/null - sudo mv zig-freebsd-x86_64-0.12.0/zig /usr/bin/ - sudo mv zig-freebsd-x86_64-0.12.0/lib /usr/lib/zig - - build: | - cd river - zig build - - build_xwayland: | - cd river - zig build -Dxwayland - - fmt: | - cd river - zig fmt --check river/ - zig fmt --check riverctl/ - zig fmt --check rivertile/ - zig fmt --check build.zig From 4d44ca6d5dd3cb9614175968e091e6c144d4563b Mon Sep 17 00:00:00 2001 From: Hugo Machet Date: Mon, 20 May 2024 13:13:05 +0200 Subject: [PATCH 11/13] ci: Check the formatting of build.zig.zon --- .builds/alpine.yml | 1 + .builds/archlinux.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.builds/alpine.yml b/.builds/alpine.yml index e365c0f..5e0a554 100644 --- a/.builds/alpine.yml +++ b/.builds/alpine.yml @@ -57,3 +57,4 @@ tasks: zig fmt --check riverctl/ zig fmt --check rivertile/ zig fmt --check build.zig + zig fmt --check build.zig.zon diff --git a/.builds/archlinux.yml b/.builds/archlinux.yml index 476e0ac..d37fb66 100644 --- a/.builds/archlinux.yml +++ b/.builds/archlinux.yml @@ -55,3 +55,4 @@ tasks: zig fmt --check riverctl/ zig fmt --check rivertile/ zig fmt --check build.zig + zig fmt --check build.zig.zon From c5b1d1de4e78fcd39d08d8b71486dd85edc60f3c Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 23 May 2024 16:15:06 +0200 Subject: [PATCH 12/13] ci: cleanup messy tar invocations --- .builds/alpine.yml | 3 +-- .builds/archlinux.yml | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.builds/alpine.yml b/.builds/alpine.yml index 5e0a554..ef40998 100644 --- a/.builds/alpine.yml +++ b/.builds/alpine.yml @@ -41,8 +41,7 @@ tasks: cd .. wget -nv https://ziglang.org/download/0.12.0/zig-linux-x86_64-0.12.0.tar.xz - # Remove a lot of useless lines from tar output. - tar -xvf zig-linux-x86_64-0.12.0.tar.xz 1>/dev/null + tar xf zig-linux-x86_64-0.12.0.tar.xz sudo mv zig-linux-x86_64-0.12.0/zig /usr/bin/ sudo mv zig-linux-x86_64-0.12.0/lib /usr/lib/zig - build: | diff --git a/.builds/archlinux.yml b/.builds/archlinux.yml index d37fb66..ef1a5de 100644 --- a/.builds/archlinux.yml +++ b/.builds/archlinux.yml @@ -39,8 +39,7 @@ tasks: cd .. wget -nv https://ziglang.org/download/0.12.0/zig-linux-x86_64-0.12.0.tar.xz - # Remove a lot of useless lines from tar output. - tar -xvf zig-linux-x86_64-0.12.0.tar.xz 1>/dev/null + tar xf zig-linux-x86_64-0.12.0.tar.xz sudo mv zig-linux-x86_64-0.12.0/zig /usr/bin/ sudo mv zig-linux-x86_64-0.12.0/lib /usr/lib/zig - build: | From 8da69699e952ee6163bb626c637c34ad7754bab7 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Fri, 7 Jun 2024 14:01:11 +0200 Subject: [PATCH 13/13] build: update to Zig 0.13.0 --- .builds/alpine.yml | 8 ++++---- .builds/archlinux.yml | 8 ++++---- .gitignore | 2 +- README.md | 2 +- build.zig | 16 ++++++++-------- build.zig.zon | 16 ++++++++-------- river/command.zig | 7 ++++--- 7 files changed, 30 insertions(+), 29 deletions(-) diff --git a/.builds/alpine.yml b/.builds/alpine.yml index ef40998..29be9f6 100644 --- a/.builds/alpine.yml +++ b/.builds/alpine.yml @@ -40,10 +40,10 @@ tasks: sudo ninja -C build/ install cd .. - wget -nv https://ziglang.org/download/0.12.0/zig-linux-x86_64-0.12.0.tar.xz - tar xf zig-linux-x86_64-0.12.0.tar.xz - sudo mv zig-linux-x86_64-0.12.0/zig /usr/bin/ - sudo mv zig-linux-x86_64-0.12.0/lib /usr/lib/zig + wget -nv https://ziglang.org/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz + tar xf zig-linux-x86_64-0.13.0.tar.xz + sudo mv zig-linux-x86_64-0.13.0/zig /usr/bin/ + sudo mv zig-linux-x86_64-0.13.0/lib /usr/lib/zig - build: | cd river zig build diff --git a/.builds/archlinux.yml b/.builds/archlinux.yml index ef1a5de..5025899 100644 --- a/.builds/archlinux.yml +++ b/.builds/archlinux.yml @@ -38,10 +38,10 @@ tasks: sudo ninja -C build/ install cd .. - wget -nv https://ziglang.org/download/0.12.0/zig-linux-x86_64-0.12.0.tar.xz - tar xf zig-linux-x86_64-0.12.0.tar.xz - sudo mv zig-linux-x86_64-0.12.0/zig /usr/bin/ - sudo mv zig-linux-x86_64-0.12.0/lib /usr/lib/zig + wget -nv https://ziglang.org/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz + tar xf zig-linux-x86_64-0.13.0.tar.xz + sudo mv zig-linux-x86_64-0.13.0/zig /usr/bin/ + sudo mv zig-linux-x86_64-0.13.0/lib /usr/lib/zig - build: | cd river zig build diff --git a/.gitignore b/.gitignore index e73c965..3389c86 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -zig-cache/ +.zig-cache/ zig-out/ diff --git a/README.md b/README.md index e3cd756..c9ed713 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ To compile river first ensure that you have the following dependencies installed. The "development" versions are required if applicable to your distribution. -- [zig](https://ziglang.org/download/) 0.12 +- [zig](https://ziglang.org/download/) 0.13 - wayland - wayland-protocols - [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 0.17.2 diff --git a/build.zig b/build.zig index b4eacc1..1addf36 100644 --- a/build.zig +++ b/build.zig @@ -148,13 +148,13 @@ pub fn build(b: *Build) !void { wlroots.resolved_target = target; wlroots.linkSystemLibrary("wlroots", .{}); - const flags = b.createModule(.{ .root_source_file = .{ .path = "common/flags.zig" } }); - const globber = b.createModule(.{ .root_source_file = .{ .path = "common/globber.zig" } }); + const flags = b.createModule(.{ .root_source_file = b.path("common/flags.zig") }); + const globber = b.createModule(.{ .root_source_file = b.path("common/globber.zig") }); { const river = b.addExecutable(.{ .name = "river", - .root_source_file = .{ .path = "river/main.zig" }, + .root_source_file = b.path("river/main.zig"), .target = target, .optimize = optimize, .strip = strip, @@ -179,7 +179,7 @@ pub fn build(b: *Build) !void { river.root_module.addImport("globber", globber); river.addCSourceFile(.{ - .file = .{ .path = "river/wlroots_log_wrapper.c" }, + .file = b.path("river/wlroots_log_wrapper.c"), .flags = &.{ "-std=c99", "-O2" }, }); @@ -195,7 +195,7 @@ pub fn build(b: *Build) !void { { const riverctl = b.addExecutable(.{ .name = "riverctl", - .root_source_file = .{ .path = "riverctl/main.zig" }, + .root_source_file = b.path("riverctl/main.zig"), .target = target, .optimize = optimize, .strip = strip, @@ -220,7 +220,7 @@ pub fn build(b: *Build) !void { { const rivertile = b.addExecutable(.{ .name = "rivertile", - .root_source_file = .{ .path = "rivertile/main.zig" }, + .root_source_file = b.path("rivertile/main.zig"), .target = target, .optimize = optimize, .strip = strip, @@ -265,7 +265,7 @@ pub fn build(b: *Build) !void { // Even passing a buffer to std.Build.Step.Run appears to be racy and occasionally deadlocks. const scdoc = b.addSystemCommand(&.{ "/bin/sh", "-c", "scdoc < doc/" ++ page ++ ".1.scd" }); // This makes the caching work for the Workaround, and the extra argument is ignored by /bin/sh. - scdoc.addFileArg(.{ .path = "doc/" ++ page ++ ".1.scd" }); + scdoc.addFileArg(b.path("doc/" ++ page ++ ".1.scd")); const stdout = scdoc.captureStdOut(); b.getInstallStep().dependOn(&b.addInstallFile(stdout, "share/man/man1/" ++ page ++ ".1").step); @@ -286,7 +286,7 @@ pub fn build(b: *Build) !void { { const globber_test = b.addTest(.{ - .root_source_file = .{ .path = "common/globber.zig" }, + .root_source_file = b.path("common/globber.zig"), .target = target, .optimize = optimize, }); diff --git a/build.zig.zon b/build.zig.zon index 057490a..a1c2a92 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -4,20 +4,20 @@ .paths = .{""}, .dependencies = .{ .@"zig-pixman" = .{ - .url = "https://codeberg.org/ifreund/zig-pixman/archive/v0.1.0.tar.gz", - .hash = "122014eeb4600a059bdcfe1c864862f17e6d5e4237e3bb7d6818f2a5583f6f4eb843", + .url = "https://codeberg.org/ifreund/zig-pixman/archive/v0.2.0.tar.gz", + .hash = "12209db20ce873af176138b76632931def33a10539387cba745db72933c43d274d56", }, .@"zig-wayland" = .{ - .url = "https://codeberg.org/ifreund/zig-wayland/archive/v0.1.0.tar.gz", - .hash = "1220b0f8f822c1625af7aae4cb3ab2c4ec1a4c0e99ef32867b2a8d88bb070b3e7f6d", + .url = "https://codeberg.org/ifreund/zig-wayland/archive/v0.2.0.tar.gz", + .hash = "1220687c8c47a48ba285d26a05600f8700d37fc637e223ced3aa8324f3650bf52242", }, .@"zig-wlroots" = .{ - .url = "https://codeberg.org/ifreund/zig-wlroots/archive/v0.17.0.tar.gz", - .hash = "1220714d1cc39c3abb1d9c22a0b838d847ead099cb7d9931821490483f30c022e827", + .url = "https://codeberg.org/ifreund/zig-wlroots/archive/v0.17.1.tar.gz", + .hash = "1220c65ab884c236cc950b564c70f6cd04046d86485ee76e0cde886cef7438021b4f", }, .@"zig-xkbcommon" = .{ - .url = "https://codeberg.org/ifreund/zig-xkbcommon/archive/v0.1.0.tar.gz", - .hash = "1220840390382c88caf9b0887f6cebbba3a7d05960b8b2ee6d80567b2950b71e5017", + .url = "https://codeberg.org/ifreund/zig-xkbcommon/archive/v0.2.0.tar.gz", + .hash = "1220c90b2228d65fd8427a837d31b0add83e9fade1dcfa539bb56fd06f1f8461605f", }, }, } diff --git a/river/command.zig b/river/command.zig index d32efce..6ea5b96 100644 --- a/river/command.zig +++ b/river/command.zig @@ -36,10 +36,11 @@ pub const Orientation = enum { vertical, }; -// zig fmt: off -const command_impls = std.ComptimeStringMap( +const command_impls = std.StaticStringMap( *const fn (*Seat, []const [:0]const u8, *?[]const u8) Error!void, +).initComptime( .{ + // zig fmt: off .{ "attach-mode", @import("command/attach_mode.zig").defaultAttachMode }, .{ "background-color", @import("command/config.zig").backgroundColor }, .{ "border-color-focused", @import("command/config.zig").borderColorFocused }, @@ -96,9 +97,9 @@ const command_impls = std.ComptimeStringMap( .{ "unmap-switch", @import("command/map.zig").unmapSwitch }, .{ "xcursor-theme", @import("command/xcursor_theme.zig").xcursorTheme }, .{ "zoom", @import("command/zoom.zig").zoom }, + // zig fmt: on }, ); -// zig fmt: on pub const Error = error{ NoCommand,