From 822690146d929a098a2d814cdf0d496bd98fb0be Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Fri, 19 Apr 2024 14:00:29 +0200 Subject: [PATCH 01/90] build: bump version to 0.3.1-dev --- build.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig b/build.zig index c0d8360..c12085b 100644 --- a/build.zig +++ b/build.zig @@ -10,7 +10,7 @@ const Scanner = @import("deps/zig-wayland/build.zig").Scanner; /// with the "-dev" suffix. /// When a release is tagged, the "-dev" suffix should be removed for the commit that gets tagged. /// Directly after the tagged commit, the version should be bumped and the "-dev" suffix added. -const version = "0.3.0"; +const version = "0.3.1-dev"; pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); From dbfaa05a679bce85c0c83f02176dbbd10e820a22 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 18 Apr 2024 10:48:59 +0200 Subject: [PATCH 02/90] XdgToplevel: don't update geometry if configure inflight (cherry picked from commit d1dc873408d2b45c53dfc174ad0eadfe15a2355e) --- river/XdgToplevel.zig | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/river/XdgToplevel.zig b/river/XdgToplevel.zig index 58e18c7..438794c 100644 --- a/river/XdgToplevel.zig +++ b/river/XdgToplevel.zig @@ -319,11 +319,11 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { }; } - const old_geometry = toplevel.geometry; - toplevel.wlr_toplevel.base.getGeometry(&toplevel.geometry); - switch (toplevel.configure_state) { .idle, .committed, .timed_out => { + const old_geometry = toplevel.geometry; + toplevel.wlr_toplevel.base.getGeometry(&toplevel.geometry); + const size_changed = toplevel.geometry.width != old_geometry.width or toplevel.geometry.height != old_geometry.height; const no_layout = view.current.output != null and view.current.output.?.layout == null; @@ -360,6 +360,8 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { // stashed buffer from when the transaction started. .inflight => view.sendFrameDone(), .acked, .timed_out_acked => { + toplevel.wlr_toplevel.base.getGeometry(&toplevel.geometry); + if (view.inflight.resizing) { view.resizeUpdatePosition(toplevel.geometry.width, toplevel.geometry.height); } From b2c4d38e09bbfdda24b3bc7a1612202e9affabf8 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Fri, 19 Apr 2024 13:42:16 +0200 Subject: [PATCH 03/90] XdgToplevel: update clip on geometry x/y change Currently if a client commits a geometry with a different x/y value but does not change the width/height we might not update the clip coordinates of the surface tree, potentially causing part of the surface to be unintentionally clipped off. To fix this, check for change in geometry x/y as well as width/height on commit if the client is not currently part of an ongoing transaction. Firefox for example it seems may respond to a configure non-atomically with multiple commits: 1. commit new buffer and new geometry of a new width/height. 2. commit again with the same width/height but a new geometry x/y. I don't think this is technically a bug but it doesn't seem like the most efficient way to do things. I think this may also cause imperfect frames. In any case, this should no longer cause river to crop off part of firefox's surface. (cherry picked from commit 9bbd34a0e31b6d429df2d39a59d8990a9585e186) --- river/XdgToplevel.zig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/river/XdgToplevel.zig b/river/XdgToplevel.zig index 438794c..909845a 100644 --- a/river/XdgToplevel.zig +++ b/river/XdgToplevel.zig @@ -352,6 +352,11 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { view.pending.box.height = toplevel.geometry.height; view.current = view.inflight; view.updateSceneState(); + } else if (old_geometry.x != toplevel.geometry.x or + old_geometry.y != toplevel.geometry.y) + { + // We need to update the surface clip box to reflect the geometry change. + view.updateSceneState(); } }, // If the client has not yet acked our configure, we need to send a From 33cc85d5ef12feeb63f5ba673b43515174e032f4 Mon Sep 17 00:00:00 2001 From: Alex Mirrlees-Black Date: Tue, 23 Apr 2024 22:38:18 +1000 Subject: [PATCH 04/90] input: prevent duplicate input configs (cherry picked from commit 5fbf174c3644a64ee217c732190b16ab9b65120a) --- river/command/input.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/river/command/input.zig b/river/command/input.zig index 09acae7..acc7927 100644 --- a/river/command/input.zig +++ b/river/command/input.zig @@ -91,6 +91,7 @@ pub fn input( for (server.input_manager.configs.items) |*input_config| { if (mem.eql(u8, input_config.glob, args[1])) { try input_config.parse(args[2], args[3]); + break; } } else { var input_config: InputConfig = .{ From b5964d7f1faf5954ac0760d9f29d9d4562da919f Mon Sep 17 00:00:00 2001 From: Alex Mirrlees-Black Date: Tue, 23 Apr 2024 23:28:42 +1000 Subject: [PATCH 05/90] input: fix scroll-factor resetting if unspecified (cherry picked from commit bd5da261eb584fd40e0b1e1609d7db5faa0ae517) --- river/InputConfig.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/river/InputConfig.zig b/river/InputConfig.zig index 09250d7..8c5e022 100644 --- a/river/InputConfig.zig +++ b/river/InputConfig.zig @@ -256,7 +256,9 @@ pub const ScrollFactor = struct { value: ?f32 = null, fn apply(scroll_factor: ScrollFactor, device: *InputDevice) void { - device.config.scroll_factor = scroll_factor.value orelse 1.0; + if (scroll_factor.value) |value| { + device.config.scroll_factor = value; + } } }; From 442913fa82f93c207e0931cde307417b8d3d2ea5 Mon Sep 17 00:00:00 2001 From: Alex Mirrlees-Black Date: Wed, 24 Apr 2024 23:59:54 +1000 Subject: [PATCH 06/90] input: change ScrollFactor and MapToOutput to align with other options (cherry picked from commit 5262a4c5a61f547acd29560f1af9cf342b9958ae) --- river/InputConfig.zig | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/river/InputConfig.zig b/river/InputConfig.zig index 8c5e022..5cbe27b 100644 --- a/river/InputConfig.zig +++ b/river/InputConfig.zig @@ -253,12 +253,10 @@ pub const MapToOutput = struct { }; pub const ScrollFactor = struct { - value: ?f32 = null, + value: f32, fn apply(scroll_factor: ScrollFactor, device: *InputDevice) void { - if (scroll_factor.value) |value| { - device.config.scroll_factor = value; - } + device.config.scroll_factor = scroll_factor.value; } }; @@ -274,19 +272,21 @@ drag: ?DragState = null, @"disable-while-trackpointing": ?DwtpState = null, @"middle-emulation": ?MiddleEmulation = null, @"natural-scroll": ?NaturalScroll = null, -@"scroll-factor": ScrollFactor = .{}, +@"scroll-factor": ?ScrollFactor = null, @"left-handed": ?LeftHanded = null, tap: ?TapState = null, @"tap-button-map": ?TapButtonMap = null, @"pointer-accel": ?PointerAccel = null, @"scroll-method": ?ScrollMethod = null, @"scroll-button": ?ScrollButton = null, -@"map-to-output": MapToOutput = .{ .output_name = null }, +@"map-to-output": ?MapToOutput = null, pub fn deinit(config: *InputConfig) void { util.gpa.free(config.glob); - if (config.@"map-to-output".output_name) |output_name| { - util.gpa.free(output_name); + if (config.@"map-to-output") |@"map-to-output"| { + if (@"map-to-output".output_name) |output_name| { + util.gpa.free(output_name); + } } } @@ -297,13 +297,15 @@ pub fn apply(config: *const InputConfig, device: *InputDevice) void { inline for (@typeInfo(InputConfig).Struct.fields) |field| { if (comptime mem.eql(u8, field.name, "glob")) continue; - if (comptime mem.eql(u8, field.name, "map-to-output")) { - @field(config, field.name).apply(device); - } else if (comptime mem.eql(u8, field.name, "scroll-factor")) { - @field(config, field.name).apply(device); - } else if (@field(config, field.name)) |setting| { + if (@field(config, field.name)) |setting| { log.debug("applying setting: {s}", .{field.name}); - setting.apply(libinput_device); + if (comptime mem.eql(u8, field.name, "scroll-factor")) { + setting.apply(device); + } else if (comptime mem.eql(u8, field.name, "map-to-output")) { + setting.apply(device); + } else { + setting.apply(libinput_device); + } } } } @@ -338,7 +340,9 @@ pub fn parse(config: *InputConfig, setting: []const u8, value: []const u8) !void } }; - if (config.@"map-to-output".output_name) |old| util.gpa.free(old); + if (config.@"map-to-output") |@"map-to-output"| { + if (@"map-to-output".output_name) |old| util.gpa.free(old); + } config.@"map-to-output" = .{ .output_name = output_name_owned }; } else { const T = @typeInfo(field.type).Optional.child; @@ -363,12 +367,12 @@ pub fn write(config: *InputConfig, writer: anytype) !void { if (comptime mem.eql(u8, field.name, "glob")) continue; if (comptime mem.eql(u8, field.name, "map-to-output")) { - if (@field(config, field.name).output_name) |output_name| { - try writer.print("\tmap-to-output: {s}\n", .{output_name}); + if (@field(config, field.name)) |@"map-to-output"| { + try writer.print("\tmap-to-output: {s}\n", .{@"map-to-output".output_name orelse "disabled"}); } } else if (comptime mem.eql(u8, field.name, "scroll-factor")) { - if (@field(config, field.name).value) |value| { - try writer.print("\tscroll-factor: {d}\n", .{value}); + if (@field(config, field.name)) |@"scroll-offset"| { + try writer.print("\tscroll-factor: {d}\n", .{@"scroll-offset".value}); } } else if (@field(config, field.name)) |setting| { // Special-case the settings which are not enums. From 717894b007d020399176c8e1afd51f0c2d048313 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sun, 12 May 2024 10:42:19 +0200 Subject: [PATCH 07/90] Cursor: don't hide while pointer constraint active Fixes: https://codeberg.org/river/river/issues/1053 (cherry picked from commit f66eec92482dabb782d5457caef4ca1dbfb82b59) --- river/Cursor.zig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/river/Cursor.zig b/river/Cursor.zig index 3b4e0a3..29e7ed9 100644 --- a/river/Cursor.zig +++ b/river/Cursor.zig @@ -769,6 +769,14 @@ fn handleRequestSetCursor( pub fn hide(cursor: *Cursor) void { if (cursor.pressed_count > 0) return; + + // Hiding the cursor and sending wl_pointer.leave whlie a pointer constraint + // is active does not make much sense. In particular, doing so seems to interact + // poorly with Xwayland's pointer constraints implementation. + if (cursor.constraint) |constraint| { + if (constraint.state == .active) return; + } + cursor.hidden = true; cursor.wlr_cursor.unsetImage(); cursor.xcursor_name = null; From cfb67b9e7a136517c8ae026fb1908855d56c3df9 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sun, 12 May 2024 09:58:14 +0200 Subject: [PATCH 08/90] Keyboard: fix redundant leave/enter on creation Currently if a second keyboard input device is created river will send a wl_keyboard.leave event immediately followed by a wl_keyboard.enter event. This serves no purpose and can confuse clients, in particular due to fctix creating/destroying virtual keyboards on focus change. Fixes: https://codeberg.org/river/river/issues/1062 References: https://github.com/fcitx/fcitx5/issues/1044 (cherry picked from commit 1e3ef88bd573e4940f7e9dcffdbf119161473e4d) --- river/Seat.zig | 1 - 1 file changed, 1 deletion(-) diff --git a/river/Seat.zig b/river/Seat.zig index 8751aa7..6fc7c65 100644 --- a/river/Seat.zig +++ b/river/Seat.zig @@ -489,7 +489,6 @@ fn tryAddDevice(seat: *Seat, wlr_device: *wlr.InputDevice) !void { seat.wlr_seat.setKeyboard(keyboard.device.wlr_device.toKeyboard()); if (seat.wlr_seat.keyboard_state.focused_surface) |wlr_surface| { - seat.wlr_seat.keyboardNotifyClearFocus(); seat.keyboardNotifyEnter(wlr_surface); } }, From 9b0e90cdb4fa1b0439fd63386e4b59c1149d9463 Mon Sep 17 00:00:00 2001 From: ymcx <89810988+ymcx@users.noreply.github.com> Date: Tue, 14 May 2024 20:23:18 +0300 Subject: [PATCH 09/90] command/swap: fix cursor warp on focus change (cherry picked from commit bed50f0dd2099e06c85f0fd0cc3bbdb10f3c9353) --- river/command/view_operations.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/river/command/view_operations.zig b/river/command/view_operations.zig index 285717d..4f1319b 100644 --- a/river/command/view_operations.zig +++ b/river/command/view_operations.zig @@ -67,6 +67,7 @@ pub fn swap( assert(!target.pending.float); assert(!target.pending.fullscreen); seat.focused.view.pending_wm_stack_link.swapWith(&target.pending_wm_stack_link); + seat.cursor.may_need_warp = true; server.root.applyPending(); } } From 9c56eb051f7fc6b261e8ee8ac27a3199869316a1 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Wed, 15 May 2024 09:48:55 +0200 Subject: [PATCH 10/90] Server: fix filtering of newly created globals Fixes: https://codeberg.org/river/river/issues/1068 (cherry picked from commit b5a80c7b9b34a42b2546d8724498b0b6d59f6cec) --- river/Server.zig | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/river/Server.zig b/river/Server.zig index e1fda5f..895f1cc 100644 --- a/river/Server.zig +++ b/river/Server.zig @@ -289,21 +289,17 @@ fn allowlist(server: *Server, global: *const wl.Global) bool { if (server.drm) |drm| if (global == drm.global) return true; if (server.linux_dmabuf) |linux_dmabuf| if (global == linux_dmabuf.global) return true; - { - var it = server.root.all_outputs.iterator(.forward); - while (it.next()) |output| { - if (global == output.wlr_output.global) return true; - } - } - - { - var it = server.input_manager.seats.first; - while (it) |node| : (it = node.next) { - if (global == node.data.wlr_seat.global) return true; - } - } - - return global == hackGlobal(server.shm) or + // We must use the getInterface() approach for dynamically created globals + // such as wl_output and wl_seat since the wl_global_create() function will + // advertise the global to clients and invoke this filter before returning + // the new global pointer. + // + // For other globals I like the current pointer comparison approach as it + // should catch river accidentally exposing multiple copies of e.g. wl_shm + // with an assertion failure. + return global.getInterface() == wl.Output.getInterface() or + global.getInterface() == wl.Seat.getInterface() or + global == hackGlobal(server.shm) or global == hackGlobal(server.single_pixel_buffer_manager) or global == server.viewporter.global or global == server.fractional_scale_manager.global or From 7db9ade574f63eda787221703191a7925b79a3b8 Mon Sep 17 00:00:00 2001 From: leviathan <1041281842@qq.com> Date: Mon, 1 Apr 2024 11:37:30 +0800 Subject: [PATCH 11/90] input-method-v2: Implement popups (cherry picked from commit 74baf7225ad95f8288f5dc1fe50345425cd62f71) --- 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 84ec97aff2b48c57ddc22e91f6af56579944850f Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Wed, 15 May 2024 11:50:58 +0200 Subject: [PATCH 12/90] InputPopup: fix naming (cherry picked from commit ba6023e38a965d80788a3de33d6c19968db03647) --- .../{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 cc5a249e9e26f66a915f56d5a9681b890dede13c Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Wed, 15 May 2024 12:21:22 +0200 Subject: [PATCH 13/90] TextInput: ignore enable requests without focus (cherry picked from commit b35a40b9dfa3e70dbdc11e8383c584164b475420) --- 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 fa077d31b4f74a746d717935ad022478e35f3d6d Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Wed, 15 May 2024 18:04:53 +0200 Subject: [PATCH 14/90] InputPopup: fix minor issues, simplify code (cherry picked from commit c75d32c88b2fda71b543b72e02117cdfb7693e2e) --- 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 7b42c3827603c0007d3764d7f3a5dc6235334f62 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sat, 18 May 2024 14:40:20 +0200 Subject: [PATCH 15/90] 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. (cherry picked from commit 5d1fc034bc6aedc340671d5de76add308effd2e8) --- 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 a019045a16c4e1a53a02b10b45acf3b6b2220330 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sat, 18 May 2024 16:28:28 +0200 Subject: [PATCH 16/90] 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. (cherry picked from commit 680cb8ef699f89cd7ce0b613221e073b534c22c5) --- 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 6a2eeba9eda8ae9d5cb030b232f5eda35d387343 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sat, 18 May 2024 17:09:03 +0200 Subject: [PATCH 17/90] bulid: bump version to 0.3.1 --- build.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig b/build.zig index c12085b..0f17621 100644 --- a/build.zig +++ b/build.zig @@ -10,7 +10,7 @@ const Scanner = @import("deps/zig-wayland/build.zig").Scanner; /// with the "-dev" suffix. /// When a release is tagged, the "-dev" suffix should be removed for the commit that gets tagged. /// Directly after the tagged commit, the version should be bumped and the "-dev" suffix added. -const version = "0.3.1-dev"; +const version = "0.3.1"; pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); From c757e1b33ea32e2c5fa436363fad62f88916cee1 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sat, 18 May 2024 17:43:46 +0200 Subject: [PATCH 18/90] build: bump version to 0.3.2-dev --- build.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig b/build.zig index 0f17621..91868db 100644 --- a/build.zig +++ b/build.zig @@ -10,7 +10,7 @@ const Scanner = @import("deps/zig-wayland/build.zig").Scanner; /// with the "-dev" suffix. /// When a release is tagged, the "-dev" suffix should be removed for the commit that gets tagged. /// Directly after the tagged commit, the version should be bumped and the "-dev" suffix added. -const version = "0.3.1"; +const version = "0.3.2-dev"; pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); From 312465e0cb9785112bff4d1e22c4849c7d0c536b Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 7 Mar 2024 16:19:22 +0100 Subject: [PATCH 19/90] build: update to Zig 0.12 (cherry picked from commit 033cad47bf63f2914865c19fc10b4dc991007515) --- .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 91868db..e611ff9 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 258129d..38e920d 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 9cbd66f543e621523e633382f34988b8501edd82 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sat, 20 Apr 2024 13:27:03 +0200 Subject: [PATCH 20/90] build: add -Dno-llvm build option (cherry picked from commit 045ee7bd25963d1a12635fd83af0629474c5575f) --- build.zig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/build.zig b/build.zig index e611ff9..8a44b43 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 b1bac967317a3a851e5cb7252abaf25987e02825 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 20 May 2024 11:33:04 +0200 Subject: [PATCH 21/90] build: switch to the Zig package manager No more git submodules! (cherry picked from commit 958f8798b6fdfab40aa29e1538827fa74e833a1c) --- .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 8a44b43..8106587 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..2df5e84 --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,23 @@ +.{ + .name = "river", + .version = "0.3.2-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 25675e4fcb434bfbd9b97f468da9a9fd27a73692 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 20 May 2024 11:45:09 +0200 Subject: [PATCH 22/90] 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. (cherry picked from commit 7fdba05b8249b10d10a2c64c1175429539c01af1) --- .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 3ff620fae389a66bbdf03a2c589fa737d31faf30 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 20 May 2024 12:14:13 +0200 Subject: [PATCH 23/90] build: bump version to 0.3.2 --- build.zig | 2 +- build.zig.zon | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index 8106587..808aff7 100644 --- a/build.zig +++ b/build.zig @@ -10,7 +10,7 @@ const Scanner = @import("zig-wayland").Scanner; /// with the "-dev" suffix. /// When a release is tagged, the "-dev" suffix should be removed for the commit that gets tagged. /// Directly after the tagged commit, the version should be bumped and the "-dev" suffix added. -const version = "0.3.2-dev"; +const version = "0.3.2"; pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); diff --git a/build.zig.zon b/build.zig.zon index 2df5e84..7958ce6 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,6 @@ .{ .name = "river", - .version = "0.3.2-dev", + .version = "0.3.2", .paths = .{""}, .dependencies = .{ .@"zig-pixman" = .{ From 5cd22edb582b952c9ba5c7ebd503fa164e06adec Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 20 May 2024 12:17:38 +0200 Subject: [PATCH 24/90] build: bump version to 0.3.3-dev --- build.zig | 2 +- build.zig.zon | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index 808aff7..7a7280c 100644 --- a/build.zig +++ b/build.zig @@ -10,7 +10,7 @@ const Scanner = @import("zig-wayland").Scanner; /// with the "-dev" suffix. /// When a release is tagged, the "-dev" suffix should be removed for the commit that gets tagged. /// Directly after the tagged commit, the version should be bumped and the "-dev" suffix added. -const version = "0.3.2"; +const version = "0.3.3-dev"; pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); diff --git a/build.zig.zon b/build.zig.zon index 7958ce6..3a7c58c 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,6 @@ .{ .name = "river", - .version = "0.3.2", + .version = "0.3.3-dev", .paths = .{""}, .dependencies = .{ .@"zig-pixman" = .{ From 914f5fae20ddbc60e8e52bf141542c83e589a4ac Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 23 May 2024 16:15:06 +0200 Subject: [PATCH 25/90] ci: cleanup messy tar invocations (cherry picked from commit c5b1d1de4e78fcd39d08d8b71486dd85edc60f3c) --- .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 e365c0f..7427a81 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 476e0ac..0f8fc32 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 a17270721eb92b0df0415d9659564d70552d939f Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Fri, 7 Jun 2024 14:01:11 +0200 Subject: [PATCH 26/90] build: update to Zig 0.13.0 (cherry picked from commit 8da69699e952ee6163bb626c637c34ad7754bab7) --- .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 7427a81..0c6d96f 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 0f8fc32..03e5763 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 7a7280c..1b47dd7 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 3a7c58c..d2935d4 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, From 1e65e652c2832128b11a2989a38f0c79a293a720 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Fri, 7 Jun 2024 14:11:31 +0200 Subject: [PATCH 27/90] build: bump version to 0.3.3 --- build.zig | 2 +- build.zig.zon | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index 1b47dd7..25a93b9 100644 --- a/build.zig +++ b/build.zig @@ -10,7 +10,7 @@ const Scanner = @import("zig-wayland").Scanner; /// with the "-dev" suffix. /// When a release is tagged, the "-dev" suffix should be removed for the commit that gets tagged. /// Directly after the tagged commit, the version should be bumped and the "-dev" suffix added. -const version = "0.3.3-dev"; +const version = "0.3.3"; pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); diff --git a/build.zig.zon b/build.zig.zon index d2935d4..f67696f 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,6 @@ .{ .name = "river", - .version = "0.3.3-dev", + .version = "0.3.3", .paths = .{""}, .dependencies = .{ .@"zig-pixman" = .{ From 64e2555505bbd01c5ce5031fa5085260abfaa19b Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Fri, 7 Jun 2024 14:16:32 +0200 Subject: [PATCH 28/90] build: bump version to 0.3.4-dev --- build.zig | 2 +- build.zig.zon | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index 25a93b9..c2c594b 100644 --- a/build.zig +++ b/build.zig @@ -10,7 +10,7 @@ const Scanner = @import("zig-wayland").Scanner; /// with the "-dev" suffix. /// When a release is tagged, the "-dev" suffix should be removed for the commit that gets tagged. /// Directly after the tagged commit, the version should be bumped and the "-dev" suffix added. -const version = "0.3.3"; +const version = "0.3.4-dev"; pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); diff --git a/build.zig.zon b/build.zig.zon index f67696f..01d58d8 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,6 @@ .{ .name = "river", - .version = "0.3.3", + .version = "0.3.4-dev", .paths = .{""}, .dependencies = .{ .@"zig-pixman" = .{ From 77699aa0ba0672e8bf0f0617bb9e8eeb8bdf7e84 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 13 Jun 2024 11:15:44 +0200 Subject: [PATCH 29/90] ci: use mirror for zig tarball downloads Eat Github's resources rather than the Zig Software Foundation's resources! (cherry picked from commit 16c938111da571765409947ee371017478633c4c) --- .builds/alpine.yml | 3 ++- .builds/archlinux.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.builds/alpine.yml b/.builds/alpine.yml index 0c6d96f..ae247d5 100644 --- a/.builds/alpine.yml +++ b/.builds/alpine.yml @@ -40,7 +40,8 @@ tasks: sudo ninja -C build/ install cd .. - wget -nv https://ziglang.org/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz + # Eat Github's resources rather than the Zig Software Foundation's resources! + wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/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 diff --git a/.builds/archlinux.yml b/.builds/archlinux.yml index 03e5763..9e23f15 100644 --- a/.builds/archlinux.yml +++ b/.builds/archlinux.yml @@ -38,7 +38,8 @@ tasks: sudo ninja -C build/ install cd .. - wget -nv https://ziglang.org/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz + # Eat Github's resources rather than the Zig Software Foundation's resources! + wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/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 From f577cb5f2ee508e1cc83b2c04c8f3b9183e1fd2b Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 13 Jun 2024 11:12:56 +0200 Subject: [PATCH 30/90] ci: re-enable FreeBSD builds Official FreeBSD zig tarballs have returned! This reverts commit 7fdba05b8249b10d10a2c64c1175429539c01af1. (cherry picked from commit f9201ae7cdc9cf7c36817c81df0134942bfbc3cb) --- .builds/freebsd.yml | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 .builds/freebsd.yml diff --git a/.builds/freebsd.yml b/.builds/freebsd.yml new file mode 100644 index 0000000..ce82620 --- /dev/null +++ b/.builds/freebsd.yml @@ -0,0 +1,62 @@ +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 + - security/ca_root_nss + - 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 .. + + # Eat Github's resources rather than the Zig Software Foundation's resources! + wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/download/0.13.0/zig-freebsd-x86_64-0.13.0.tar.xz + tar xf zig-freebsd-x86_64-0.13.0.tar.xz + sudo mv zig-freebsd-x86_64-0.13.0/zig /usr/bin/ + sudo mv zig-freebsd-x86_64-0.13.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 4653a7730ec6bf3b5b54ac08952565aba819e621 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 13 Jun 2024 11:37:13 +0200 Subject: [PATCH 31/90] ci: log build summaries (cherry picked from commit e2f3cd82521ba94bfb6907a05a3022fdc514a355) --- .builds/alpine.yml | 4 ++-- .builds/archlinux.yml | 4 ++-- .builds/freebsd.yml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.builds/alpine.yml b/.builds/alpine.yml index ae247d5..954b0d2 100644 --- a/.builds/alpine.yml +++ b/.builds/alpine.yml @@ -47,10 +47,10 @@ tasks: sudo mv zig-linux-x86_64-0.13.0/lib /usr/lib/zig - build: | cd river - zig build + zig build --summary all - build_xwayland: | cd river - zig build -Dxwayland + zig build --summary all -Dxwayland - fmt: | cd river zig fmt --check river/ diff --git a/.builds/archlinux.yml b/.builds/archlinux.yml index 9e23f15..c13941f 100644 --- a/.builds/archlinux.yml +++ b/.builds/archlinux.yml @@ -45,10 +45,10 @@ tasks: sudo mv zig-linux-x86_64-0.13.0/lib /usr/lib/zig - build: | cd river - zig build + zig build --summary all - build_xwayland: | cd river - zig build -Dxwayland + zig build --summary all -Dxwayland - fmt: | cd river zig fmt --check river/ diff --git a/.builds/freebsd.yml b/.builds/freebsd.yml index ce82620..eeb1d1b 100644 --- a/.builds/freebsd.yml +++ b/.builds/freebsd.yml @@ -50,10 +50,10 @@ tasks: sudo mv zig-freebsd-x86_64-0.13.0/lib /usr/lib/zig - build: | cd river - zig build + zig build --summary all - build_xwayland: | cd river - zig build -Dxwayland + zig build --summary all -Dxwayland - fmt: | cd river zig fmt --check river/ From 36cdbbc0876fbd10fa90af2f80709657e1c8fcd8 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 13 Jun 2024 12:36:00 +0200 Subject: [PATCH 32/90] SceneNodeData: fix fromSurface() use after free We must clean up the user data of the wlr_surface for layer surfaces and lock surfaces as fromSurface() may be called (e.g. by the idle inhibit implementation) after the scene node has been destroyed but before the wlr_surface is destroyed. (cherry picked from commit 28a14c6794ddc21a23d2e14d41761007d15569e8) --- river/LayerSurface.zig | 4 +++- river/LockSurface.zig | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/river/LayerSurface.zig b/river/LayerSurface.zig index 03d243d..81dfe57 100644 --- a/river/LayerSurface.zig +++ b/river/LayerSurface.zig @@ -55,7 +55,6 @@ pub fn create(wlr_layer_surface: *wlr.LayerSurfaceV1) error{OutOfMemory}!void { .scene_layer_surface = try layer_tree.createSceneLayerSurfaceV1(wlr_layer_surface), .popup_tree = try output.layers.popups.createSceneTree(), }; - wlr_layer_surface.data = @intFromPtr(layer_surface); try SceneNodeData.attach(&layer_surface.scene_layer_surface.tree.node, .{ .layer_surface = layer_surface }); try SceneNodeData.attach(&layer_surface.popup_tree.node, .{ .layer_surface = layer_surface }); @@ -93,6 +92,9 @@ fn handleDestroy(listener: *wl.Listener(*wlr.LayerSurfaceV1), _: *wlr.LayerSurfa layer_surface.popup_tree.node.destroy(); + // The wlr_surface may outlive the wlr_layer_surface so we must clean up the user data. + layer_surface.wlr_layer_surface.surface.data = 0; + util.gpa.destroy(layer_surface); } diff --git a/river/LockSurface.zig b/river/LockSurface.zig index c3cd384..60f0aa8 100644 --- a/river/LockSurface.zig +++ b/river/LockSurface.zig @@ -85,6 +85,9 @@ pub fn destroy(lock_surface: *LockSurface) void { lock_surface.map.link.remove(); lock_surface.surface_destroy.link.remove(); + // The wlr_surface may outlive the wlr_lock_surface so we must clean up the user data. + lock_surface.wlr_lock_surface.surface.data = 0; + util.gpa.destroy(lock_surface); } From 99b31c39f3ec6db99b46ab5a8232f7b444484b13 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Fri, 14 Jun 2024 15:32:37 +0200 Subject: [PATCH 33/90] input: apply map-to-output on output activation Currently a map-to-output input config setting loses effect when an output is disabled and re-enabled for example. (cherry picked from commit de3035563ccd5ea9f4fe0b843618e4265c880e30) --- river/Root.zig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/river/Root.zig b/river/Root.zig index 38e920d..94c0d86 100644 --- a/river/Root.zig +++ b/river/Root.zig @@ -416,6 +416,9 @@ pub fn activateOutput(root: *Root, output: *Output) void { } assert(root.fallback_pending.focus_stack.empty()); assert(root.fallback_pending.wm_stack.empty()); + + // Enforce map-to-output configuration for the newly active output. + server.input_manager.reconfigureDevices(); } /// Trigger asynchronous application of pending state for all outputs and views. From b85da678861e4e2852feadfc187d9ba471644b56 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 24 Jun 2024 19:29:19 +0200 Subject: [PATCH 34/90] Output: flag gamma as dirty on enable We can end up with stale gamma settings if we don't re-check the current gamma settings for the output on enable. (cherry picked from commit 2e09b66963805caccfe8534d69f2f35dd4a4c3f7) --- river/Output.zig | 1 + river/Root.zig | 1 + 2 files changed, 2 insertions(+) diff --git a/river/Output.zig b/river/Output.zig index b235c1e..518bfc6 100644 --- a/river/Output.zig +++ b/river/Output.zig @@ -474,6 +474,7 @@ pub fn applyState(output: *Output, state: *wlr.Output.State) error{CommitFailed} fn handleEnableDisable(output: *Output) void { output.updateLockRenderStateOnEnableDisable(); + output.gamma_dirty = true; if (output.wlr_output.enabled) { // Add the output to root.active_outputs and the output layout if it has not diff --git a/river/Root.zig b/river/Root.zig index 94c0d86..619200c 100644 --- a/river/Root.zig +++ b/river/Root.zig @@ -881,6 +881,7 @@ fn handlePowerManagerSetMode( } output.updateLockRenderStateOnEnableDisable(); + output.gamma_dirty = true; } fn handleSetGamma( From 6564db22df85bdd1922f246975a1e606b3d4d716 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Tue, 25 Jun 2024 12:24:25 +0200 Subject: [PATCH 35/90] Xwayland: fix unsound cast The X11 protocol uses 16 bit integers for width/height but we use 32 bit integers everywhere else in river. Make sure that values outside the range of a 16 bit integer don't cause river to crash with an assertion failure. I think that coordinates outside the range of a 16 bit integer could theoretically be reasonable with tiled high resolution displays in the future. I doubt they ever get used in practice today but at the same time we can't allow an errant layout generator to crash river. (cherry picked from commit ae7f4b8fcbb323e68b07eebf8dc8cca38b582940) --- river/XwaylandView.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/river/XwaylandView.zig b/river/XwaylandView.zig index 80cecc6..db91199 100644 --- a/river/XwaylandView.zig +++ b/river/XwaylandView.zig @@ -106,10 +106,10 @@ pub fn configure(xwayland_view: XwaylandView) bool { } xwayland_view.xwayland_surface.configure( - @intCast(inflight.box.x + output_box.x), - @intCast(inflight.box.y + output_box.y), - @intCast(inflight.box.width), - @intCast(inflight.box.height), + math.lossyCast(i16, inflight.box.x + output_box.x), + math.lossyCast(i16, inflight.box.y + output_box.y), + math.lossyCast(u16, inflight.box.width), + math.lossyCast(u16, inflight.box.height), ); xwayland_view.setActivated(inflight.focus != 0); From 5cfa1fc8f5a25234a7580740b395b648e0c09dbe Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sun, 30 Jun 2024 12:12:00 +0200 Subject: [PATCH 36/90] docs: tweak repology link wording in readme (cherry picked from commit 0997fde28e1aad90a983d28061deed9fdcb972f3) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c9ed713..a3f7577 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ River is a dynamic tiling Wayland compositor with flexible runtime configuration. -Install from your [package manager](https://repology.org/project/river/versions) — +Check [packaging status](https://repology.org/project/river/versions) — Join us at [#river](https://web.libera.chat/?channels=#river) on irc.libera.chat — Read our man pages, [wiki](https://codeberg.org/river/wiki), and [Code of Conduct](CODE_OF_CONDUCT.md) From 6e0c1037059e113b4173be094f3ad07fc0a81924 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 1 Jul 2024 12:27:16 +0200 Subject: [PATCH 37/90] Output: fix Wayland backend support The wlroots Wayland backend does not support gamma LUT application and will currently fail to render anything if river commits a gamma LUT. To fix this, test the state when applying a gamma LUT and fall back to a state with no gamma LUT set if that fails. This problem was revealed by 2e09b66 which flags gamma as dirty on all outputs when they are enabled. (cherry picked from commit a80e0f7322b1f9f8b091a327aaea366b615042c8) --- build.zig.zon | 4 ++-- river/Output.zig | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/build.zig.zon b/build.zig.zon index 01d58d8..fc5de55 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -12,8 +12,8 @@ .hash = "1220687c8c47a48ba285d26a05600f8700d37fc637e223ced3aa8324f3650bf52242", }, .@"zig-wlroots" = .{ - .url = "https://codeberg.org/ifreund/zig-wlroots/archive/v0.17.1.tar.gz", - .hash = "1220c65ab884c236cc950b564c70f6cd04046d86485ee76e0cde886cef7438021b4f", + .url = "https://codeberg.org/ifreund/zig-wlroots/archive/v0.17.2.tar.gz", + .hash = "1220bb5e5c802c517425bc1d8d8d43d7b7fe5eb81ce4c46b15ce829d67ddadc55418", }, .@"zig-xkbcommon" = .{ .url = "https://codeberg.org/ifreund/zig-xkbcommon/archive/v0.2.0.tar.gz", diff --git a/river/Output.zig b/river/Output.zig index 518bfc6..c9d8add 100644 --- a/river/Output.zig +++ b/river/Output.zig @@ -540,18 +540,23 @@ fn renderAndCommit(output: *Output, scene_output: *wlr.SceneOutput) !void { var state = wlr.Output.State.init(); defer state.finish(); - if (server.root.gamma_control_manager.getControl(output.wlr_output)) |control| { - log.info("applying gamma settings from client", .{}); - if (!control.apply(&state)) return error.OutOfMemory; - } else { - log.info("clearing gamma settings from client", .{}); + const control = server.root.gamma_control_manager.getControl(output.wlr_output); + if (!wlr.GammaControlV1.apply(control, &state)) return error.OutOfMemory; + + if (!output.wlr_output.testState(&state)) { + wlr.GammaControlV1.sendFailedAndDestroy(control); state.clearGammaLut(); + // If the backend does not support gamma LUTs it will reject any + // state with the gamma LUT committed bit set even if the state + // has a null LUT. The wayland backend for example has this behavior. + state.committed.gamma_lut = false; } if (!scene_output.buildState(&state, null)) return error.CommitFailed; if (!output.wlr_output.commitState(&state)) return error.CommitFailed; + // TODO(wlroots) remove this rotate() call when updating to wlroots 0.18 scene_output.damage_ring.rotate(); output.gamma_dirty = false; } else { From cf63d16846a3e98b84fc555b11df834a71e1477a Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 1 Jul 2024 12:52:31 +0200 Subject: [PATCH 38/90] XdgPopup: send configure after initial commit Currently we send the first configure for xdg popups before the popup has made its initial commit. This is incorrect according to the protocol and may confuse clients. (cherry picked from commit ec16f1c3753d51feb7dfc6d406dd508f4513a106) --- river/XdgPopup.zig | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/river/XdgPopup.zig b/river/XdgPopup.zig index 5198e9b..fd82fbe 100644 --- a/river/XdgPopup.zig +++ b/river/XdgPopup.zig @@ -35,6 +35,7 @@ root: *wlr.SceneTree, tree: *wlr.SceneTree, destroy: wl.Listener(void) = wl.Listener(void).init(handleDestroy), +commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit), new_popup: wl.Listener(*wlr.XdgPopup) = wl.Listener(*wlr.XdgPopup).init(handleNewPopup), reposition: wl.Listener(void) = wl.Listener(void).init(handleReposition), @@ -54,22 +55,30 @@ pub fn create( }; wlr_xdg_popup.base.events.destroy.add(&xdg_popup.destroy); + wlr_xdg_popup.base.surface.events.commit.add(&xdg_popup.commit); wlr_xdg_popup.base.events.new_popup.add(&xdg_popup.new_popup); wlr_xdg_popup.events.reposition.add(&xdg_popup.reposition); - - handleReposition(&xdg_popup.reposition); } fn handleDestroy(listener: *wl.Listener(void)) void { const xdg_popup: *XdgPopup = @fieldParentPtr("destroy", listener); xdg_popup.destroy.link.remove(); + xdg_popup.commit.link.remove(); xdg_popup.new_popup.link.remove(); xdg_popup.reposition.link.remove(); util.gpa.destroy(xdg_popup); } +fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { + const xdg_popup: *XdgPopup = @fieldParentPtr("commit", listener); + + if (xdg_popup.wlr_xdg_popup.base.initial_commit) { + handleReposition(&xdg_popup.reposition); + } +} + fn handleNewPopup(listener: *wl.Listener(*wlr.XdgPopup), wlr_xdg_popup: *wlr.XdgPopup) void { const xdg_popup: *XdgPopup = @fieldParentPtr("new_popup", listener); From eab893c4819daa39fed254672d44e8788cb2a5b6 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Tue, 2 Jul 2024 15:03:22 +0200 Subject: [PATCH 39/90] layer-shell: fix on_demand keyboard focus Currently keyboard focus is stolen from layer surfaces with on_demand keyboard interactivity any time Root.applyPending() is called. This commit fixes the behavior to only steal focus when explicitly focusing a different window/layer surface. (cherry picked from commit 4232d6b99f2eeede9f318aa6043128530597cc4e) --- river/Seat.zig | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/river/Seat.zig b/river/Seat.zig index ff77cce..4ac83f5 100644 --- a/river/Seat.zig +++ b/river/Seat.zig @@ -165,14 +165,21 @@ pub fn focus(seat: *Seat, _target: ?*View) void { // Views may not receive focus while locked. if (server.lock_manager.state != .unlocked) return; - // While a layer surface is exclusively focused, views may not receive focus + // A layer surface with exclusive focus will prevent any view from gaining + // focus if it is on the top or overlay layer. Otherwise, only steal focus + // from a focused layer surface if there is an explicit target view. if (seat.focused == .layer) { const wlr_layer_surface = seat.focused.layer.wlr_layer_surface; assert(wlr_layer_surface.surface.mapped); - if (wlr_layer_surface.current.keyboard_interactive == .exclusive and - (wlr_layer_surface.current.layer == .top or wlr_layer_surface.current.layer == .overlay)) - { - return; + switch (wlr_layer_surface.current.keyboard_interactive) { + .none => {}, + .exclusive => switch (wlr_layer_surface.current.layer) { + .top, .overlay => return, + .bottom, .background => if (target == null) return, + _ => {}, + }, + .on_demand => if (target == null) return, + _ => {}, } } From 667b047cdfb1619164b93ac2eac9c219a51f7e91 Mon Sep 17 00:00:00 2001 From: Palanix Date: Sun, 7 Jul 2024 18:44:07 +0200 Subject: [PATCH 40/90] docs: mention zig build -h in readme (cherry picked from commit 1f5bf1d972816a4c61f28e4b3601582355a98931) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a3f7577..1a11941 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ Then run, for example: zig build -Doptimize=ReleaseSafe --prefix ~/.local install ``` To enable Xwayland support pass the `-Dxwayland` option as well. +Run `zig build -h` to see a list of all options. ## Usage From 6849176e25333429c8b9abcfd5a43fb5d7f0acb3 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Wed, 10 Jul 2024 12:16:42 +0200 Subject: [PATCH 41/90] PointerConstraint: fix assertion failure The assertion in PointerConstraint.confine() can currently still be triggered if the input region of a surface is changed and the pointer is moved outside of the new intersection of input region and constraint region before PointerConstraint.updateState() is called. This can happen, for example, when a client is made non-fullscreen at the same time as the pointer is moved across the boundary of the new, post-fullscreen, input region. If the pointer crosses the boundary before the transaction completes and updateState() is called, the assertion in PointerConstraint.confine() will fail. To fix this, listen for the surface commit event rather than the set_region event to handle possible deactivation on region changes. (cherry picked from commit a7411ef2a6e0ec38fc4931a142bd33bc8b618d01) --- river/PointerConstraint.zig | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/river/PointerConstraint.zig b/river/PointerConstraint.zig index b35b29f..deadc2d 100644 --- a/river/PointerConstraint.zig +++ b/river/PointerConstraint.zig @@ -42,7 +42,7 @@ state: union(enum) { } = .inactive, destroy: wl.Listener(*wlr.PointerConstraintV1) = wl.Listener(*wlr.PointerConstraintV1).init(handleDestroy), -set_region: wl.Listener(void) = wl.Listener(void).init(handleSetRegion), +commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit), node_destroy: wl.Listener(void) = wl.Listener(void).init(handleNodeDestroy), @@ -58,7 +58,7 @@ pub fn create(wlr_constraint: *wlr.PointerConstraintV1) error{OutOfMemory}!void wlr_constraint.data = @intFromPtr(constraint); wlr_constraint.events.destroy.add(&constraint.destroy); - wlr_constraint.events.set_region.add(&constraint.set_region); + wlr_constraint.surface.events.commit.add(&constraint.commit); if (seat.wlr_seat.keyboard_state.focused_surface) |surface| { if (surface == wlr_constraint.surface) { @@ -201,7 +201,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.PointerConstraintV1), _: *wlr.Point } constraint.destroy.link.remove(); - constraint.set_region.link.remove(); + constraint.commit.link.remove(); if (seat.cursor.constraint == constraint) { seat.cursor.constraint = null; @@ -210,8 +210,11 @@ fn handleDestroy(listener: *wl.Listener(*wlr.PointerConstraintV1), _: *wlr.Point util.gpa.destroy(constraint); } -fn handleSetRegion(listener: *wl.Listener(void)) void { - const constraint: *PointerConstraint = @fieldParentPtr("set_region", listener); +// It is necessary to listen for the commit event rather than the set_region +// event as the latter is not triggered by wlroots when the input region of +// the surface changes. +fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { + const constraint: *PointerConstraint = @fieldParentPtr("commit", listener); const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data); switch (constraint.state) { @@ -219,7 +222,7 @@ fn handleSetRegion(listener: *wl.Listener(void)) void { const sx: i32 = @intFromFloat(state.sx); const sy: i32 = @intFromFloat(state.sy); if (!constraint.wlr_constraint.region.containsPoint(sx, sy, null)) { - log.info("deactivating pointer constraint, region change left pointer outside constraint", .{}); + log.info("deactivating pointer constraint, (input) region change left pointer outside constraint", .{}); constraint.deactivate(); } }, From 4f39ce79e91c89f4424e75ef13772b8ef9cd8c4f Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Wed, 10 Jul 2024 12:55:32 +0200 Subject: [PATCH 42/90] build: bump version to 0.3.4 --- build.zig | 2 +- build.zig.zon | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index c2c594b..425dc62 100644 --- a/build.zig +++ b/build.zig @@ -10,7 +10,7 @@ const Scanner = @import("zig-wayland").Scanner; /// with the "-dev" suffix. /// When a release is tagged, the "-dev" suffix should be removed for the commit that gets tagged. /// Directly after the tagged commit, the version should be bumped and the "-dev" suffix added. -const version = "0.3.4-dev"; +const version = "0.3.4"; pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); diff --git a/build.zig.zon b/build.zig.zon index fc5de55..3616985 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,6 @@ .{ .name = "river", - .version = "0.3.4-dev", + .version = "0.3.4", .paths = .{""}, .dependencies = .{ .@"zig-pixman" = .{ From dc0d8112a6d504ada58433d1c86900652a714329 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Wed, 10 Jul 2024 12:58:47 +0200 Subject: [PATCH 43/90] build: bump version to 0.3.5-dev --- build.zig | 2 +- build.zig.zon | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index 425dc62..53b39e4 100644 --- a/build.zig +++ b/build.zig @@ -10,7 +10,7 @@ const Scanner = @import("zig-wayland").Scanner; /// with the "-dev" suffix. /// When a release is tagged, the "-dev" suffix should be removed for the commit that gets tagged. /// Directly after the tagged commit, the version should be bumped and the "-dev" suffix added. -const version = "0.3.4"; +const version = "0.3.5-dev"; pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); diff --git a/build.zig.zon b/build.zig.zon index 3616985..1001377 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,6 @@ .{ .name = "river", - .version = "0.3.4", + .version = "0.3.5-dev", .paths = .{""}, .dependencies = .{ .@"zig-pixman" = .{ From 4e2a1a12f8c4c2577db37b02c23c8e140f4919f5 Mon Sep 17 00:00:00 2001 From: Felix Bowman Date: Fri, 12 Jul 2024 09:10:40 +0100 Subject: [PATCH 44/90] completions: zsh click-method option fix "button-areas" seems to be the argument this command expects instead of "button-area" -- other shells also have the option as "button-areas". (cherry picked from commit ccd676e5a939aabafd297fcec1db3058c651a91b) --- completions/zsh/_riverctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completions/zsh/_riverctl b/completions/zsh/_riverctl index ade30e5..73df6b1 100644 --- a/completions/zsh/_riverctl +++ b/completions/zsh/_riverctl @@ -135,7 +135,7 @@ _riverctl() case "$line[2]" in events) _alternative 'input-cmds:args:(enabled disabled disabled-on-external-mouse)' ;; accel-profile) _alternative 'input-cmds:args:(none flat adaptive)' ;; - click-method) _alternative 'input-cmds:args:(none button-area clickfinger)' ;; + click-method) _alternative 'input-cmds:args:(none button-areas clickfinger)' ;; drag) _alternative 'input-cmds:args:(enabled disabled)' ;; drag-lock) _alternative 'input-cmds:args:(enabled disabled)' ;; disable-while-typing) _alternative 'input-cmds:args:(enabled disabled)' ;; From eb32deaf76281a3e552438ab9d1a2d88a216c1f8 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Tue, 16 Jul 2024 14:24:22 +0200 Subject: [PATCH 45/90] build: update to wlroots 0.18.0 (cherry picked from commit 99ef96a389eb3e350a7fd3294d1033263751b1a1) --- .builds/alpine.yml | 10 +++--- .builds/archlinux.yml | 10 +++--- .builds/freebsd.yml | 10 +++--- README.md | 2 +- build.zig | 4 +-- build.zig.zon | 4 +-- river/Cursor.zig | 32 +++-------------- river/InputConfig.zig | 6 ++-- river/InputDevice.zig | 23 ++++++------ river/LayerSurface.zig | 5 --- river/Output.zig | 2 -- river/PointerConstraint.zig | 2 +- river/Root.zig | 7 ++-- river/Seat.zig | 6 ++-- river/Server.zig | 70 ++++++++++++++++++------------------- river/Tablet.zig | 2 +- river/TabletTool.zig | 27 ++++++++------ river/XdgDecoration.zig | 11 ++---- river/XdgPopup.zig | 2 +- river/XdgToplevel.zig | 30 ++++++++++++---- river/main.zig | 6 ---- 21 files changed, 128 insertions(+), 143 deletions(-) diff --git a/.builds/alpine.yml b/.builds/alpine.yml index 954b0d2..1014c77 100644 --- a/.builds/alpine.yml +++ b/.builds/alpine.yml @@ -28,15 +28,17 @@ sources: tasks: - install_deps: | cd wayland - git checkout 1.22.0 + git checkout 1.23.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 -Dxcb-errors=disabled --prefix /usr + git checkout 0.18.0 + meson setup build --auto-features=enabled -Drenderers=gles2 \ + -Dcolor-management=disabled -Dlibliftoff=disabled \ + -Dexamples=false -Dwerror=false -Db_ndebug=false \ + -Dxcb-errors=disabled --prefix /usr sudo ninja -C build/ install cd .. diff --git a/.builds/archlinux.yml b/.builds/archlinux.yml index c13941f..44bf5e0 100644 --- a/.builds/archlinux.yml +++ b/.builds/archlinux.yml @@ -26,15 +26,17 @@ sources: tasks: - install_deps: | cd wayland - git checkout 1.22.0 + git checkout 1.23.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 + git checkout 0.18.0 + meson setup build --auto-features=enabled -Drenderers=gles2 \ + -Dcolor-management=disabled -Dlibliftoff=disabled \ + -Dexamples=false -Dwerror=false -Db_ndebug=false \ + -Dxcb-errors=disabled --prefix /usr sudo ninja -C build/ install cd .. diff --git a/.builds/freebsd.yml b/.builds/freebsd.yml index eeb1d1b..2928661 100644 --- a/.builds/freebsd.yml +++ b/.builds/freebsd.yml @@ -31,15 +31,17 @@ sources: tasks: - install_deps: | cd wayland - git checkout 1.22.0 + git checkout 1.23.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 + git checkout 0.18.0 + meson setup build --auto-features=enabled -Drenderers=gles2 \ + -Dcolor-management=disabled -Dlibliftoff=disabled \ + -Dexamples=false -Dwerror=false -Db_ndebug=false \ + -Dxcb-errors=disabled --prefix /usr sudo ninja -C build/ install cd .. diff --git a/README.md b/README.md index 1a11941..f8eb56e 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ distribution. - [zig](https://ziglang.org/download/) 0.13 - wayland - wayland-protocols -- [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 0.17.2 +- [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 0.18 - xkbcommon - libevdev - pixman diff --git a/build.zig b/build.zig index 53b39e4..2b1ce1b 100644 --- a/build.zig +++ b/build.zig @@ -146,7 +146,7 @@ pub fn build(b: *Build) !void { // 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", .{}); + wlroots.linkSystemLibrary("wlroots-0.18", .{}); const flags = b.createModule(.{ .root_source_file = b.path("common/flags.zig") }); const globber = b.createModule(.{ .root_source_file = b.path("common/globber.zig") }); @@ -167,7 +167,7 @@ pub fn build(b: *Build) !void { river.linkSystemLibrary("libevdev"); river.linkSystemLibrary("libinput"); river.linkSystemLibrary("wayland-server"); - river.linkSystemLibrary("wlroots"); + river.linkSystemLibrary("wlroots-0.18"); river.linkSystemLibrary("xkbcommon"); river.linkSystemLibrary("pixman-1"); diff --git a/build.zig.zon b/build.zig.zon index 1001377..f9558bf 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -12,8 +12,8 @@ .hash = "1220687c8c47a48ba285d26a05600f8700d37fc637e223ced3aa8324f3650bf52242", }, .@"zig-wlroots" = .{ - .url = "https://codeberg.org/ifreund/zig-wlroots/archive/v0.17.2.tar.gz", - .hash = "1220bb5e5c802c517425bc1d8d8d43d7b7fe5eb81ce4c46b15ce829d67ddadc55418", + .url = "https://codeberg.org/ifreund/zig-wlroots/archive/v0.18.0.tar.gz", + .hash = "12204d789e17c158971f69c7b900e8d8f288e7b9e42b2242f3adfbca57e8266d848f", }, .@"zig-xkbcommon" = .{ .url = "https://codeberg.org/ifreund/zig-xkbcommon/archive/v0.2.0.tar.gz", diff --git a/river/Cursor.zig b/river/Cursor.zig index aa031fc..235f29c 100644 --- a/river/Cursor.zig +++ b/river/Cursor.zig @@ -324,6 +324,7 @@ fn handleAxis(listener: *wl.Listener(*wlr.Pointer.event.Axis), event: *wlr.Point math.maxInt(i32) / 2, )), event.source, + event.relative_direction, ); } @@ -568,7 +569,7 @@ fn handleTouchUp( cursor.seat.handleActivity(); if (cursor.touch_points.remove(event.touch_id)) { - cursor.seat.wlr_seat.touchNotifyUp(event.time_msec, event.touch_id); + _ = cursor.seat.wlr_seat.touchNotifyUp(event.time_msec, event.touch_id); } } @@ -582,32 +583,9 @@ fn handleTouchCancel( cursor.touch_points.clearRetainingCapacity(); - // We can't call touchNotifyCancel() from inside the loop over touch points as it also loops - // over touch points and may destroy multiple touch points in a single call. - // - // What we should do here is `while (touch_points.first()) |point| cancel()` but since the - // surface may be null we can't rely on the fact tha all touch points will be destroyed - // and risk an infinite loop if the surface of any wlr_touch_point is null. - // - // This is all really silly and totally unnecessary since all touchNotifyCancel() does with - // the surface argument is obtain a seat client and touch_point.seat_client is never null. - // TODO(wlroots) clean this up after the wlroots MR fixing this is merged: - // https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4613 - - // The upper bound of 32 comes from an implementation detail of libinput which uses - // a 32-bit integer as a map to keep track of touch points. - var surfaces: std.BoundedArray(*wlr.Surface, 32) = .{}; - { - var it = cursor.seat.wlr_seat.touch_state.touch_points.iterator(.forward); - while (it.next()) |touch_point| { - if (touch_point.surface) |surface| { - surfaces.append(surface) catch break; - } - } - } - - for (surfaces.slice()) |surface| { - cursor.seat.wlr_seat.touchNotifyCancel(surface); + const wlr_seat = cursor.seat.wlr_seat; + while (wlr_seat.touch_state.touch_points.first()) |touch_point| { + wlr_seat.touchNotifyCancel(touch_point.client); } } diff --git a/river/InputConfig.zig b/river/InputConfig.zig index 6922081..39fc47d 100644 --- a/river/InputConfig.zig +++ b/river/InputConfig.zig @@ -232,7 +232,7 @@ pub const MapToOutput = struct { }; switch (device.wlr_device.type) { - .pointer, .touch, .tablet_tool => { + .pointer, .touch, .tablet => { log.debug("mapping input '{s}' -> '{s}'", .{ device.identifier, if (wlr_output) |o| o.name else "", @@ -240,14 +240,14 @@ pub const MapToOutput = struct { device.seat.cursor.wlr_cursor.mapInputToOutput(device.wlr_device, wlr_output); - if (device.wlr_device.type == .tablet_tool) { + if (device.wlr_device.type == .tablet) { const tablet: *Tablet = @fieldParentPtr("device", device); tablet.output_mapping = wlr_output; } }, // These devices do not support being mapped to outputs. - .keyboard, .tablet_pad, .switch_device => {}, + .keyboard, .tablet_pad, .@"switch" => {}, } } }; diff --git a/river/InputDevice.zig b/river/InputDevice.zig index f3d9924..a35eefd 100644 --- a/river/InputDevice.zig +++ b/river/InputDevice.zig @@ -24,6 +24,7 @@ const wl = @import("wayland").server.wl; const globber = @import("globber"); +const c = @import("c.zig"); const server = &@import("main.zig").server; const util = @import("util.zig"); @@ -52,19 +53,21 @@ config: struct { link: wl.list.Link, pub fn init(device: *InputDevice, seat: *Seat, wlr_device: *wlr.InputDevice) !void { - const device_type: []const u8 = switch (wlr_device.type) { - .switch_device => "switch", - .tablet_tool => "tablet", - else => @tagName(wlr_device.type), - }; + var vendor: c_uint = 0; + var product: c_uint = 0; + + if (wlr_device.getLibinputDevice()) |d| { + vendor = c.libinput_device_get_id_vendor(@ptrCast(d)); + product = c.libinput_device_get_id_product(@ptrCast(d)); + } const identifier = try std.fmt.allocPrint( util.gpa, "{s}-{}-{}-{s}", .{ - device_type, - wlr_device.vendor, - wlr_device.product, + @tagName(wlr_device.type), + vendor, + product, mem.trim(u8, mem.sliceTo(wlr_device.name orelse "unknown", 0), &ascii.whitespace), }, ); @@ -139,11 +142,11 @@ fn handleDestroy(listener: *wl.Listener(*wlr.InputDevice), _: *wlr.InputDevice) device.deinit(); util.gpa.destroy(device); }, - .tablet_tool => { + .tablet => { const tablet: *Tablet = @fieldParentPtr("device", device); tablet.destroy(); }, - .switch_device => { + .@"switch" => { const switch_device: *Switch = @fieldParentPtr("device", device); switch_device.deinit(); util.gpa.destroy(switch_device); diff --git a/river/LayerSurface.zig b/river/LayerSurface.zig index 81dfe57..004a6c2 100644 --- a/river/LayerSurface.zig +++ b/river/LayerSurface.zig @@ -66,11 +66,6 @@ pub fn create(wlr_layer_surface: *wlr.LayerSurfaceV1) error{OutOfMemory}!void { wlr_layer_surface.surface.events.unmap.add(&layer_surface.unmap); wlr_layer_surface.surface.events.commit.add(&layer_surface.commit); wlr_layer_surface.events.new_popup.add(&layer_surface.new_popup); - - // wlroots only informs us of the new surface after the first commit, - // so our listener does not get called for this first commit. However, - // we do want our listener called in order to send the initial configure. - handleCommit(&layer_surface.commit, wlr_layer_surface.surface); } pub fn destroyPopups(layer_surface: *LayerSurface) void { diff --git a/river/Output.zig b/river/Output.zig index c9d8add..e449f3f 100644 --- a/river/Output.zig +++ b/river/Output.zig @@ -556,8 +556,6 @@ fn renderAndCommit(output: *Output, scene_output: *wlr.SceneOutput) !void { if (!output.wlr_output.commitState(&state)) return error.CommitFailed; - // TODO(wlroots) remove this rotate() call when updating to wlroots 0.18 - scene_output.damage_ring.rotate(); output.gamma_dirty = false; } else { if (!scene_output.commit(null)) return error.CommitFailed; diff --git a/river/PointerConstraint.zig b/river/PointerConstraint.zig index deadc2d..a2c4d74 100644 --- a/river/PointerConstraint.zig +++ b/river/PointerConstraint.zig @@ -169,7 +169,7 @@ pub fn deactivate(constraint: *PointerConstraint) void { fn warpToHintIfSet(constraint: *PointerConstraint) void { const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data); - if (constraint.wlr_constraint.current.committed.cursor_hint) { + if (constraint.wlr_constraint.current.cursor_hint.enabled) { var lx: i32 = undefined; var ly: i32 = undefined; _ = constraint.state.active.node.coords(&lx, &ly); diff --git a/river/Root.zig b/river/Root.zig index 619200c..829a304 100644 --- a/river/Root.zig +++ b/river/Root.zig @@ -117,7 +117,7 @@ transaction_timeout: *wl.EventSource, pending_state_dirty: bool = false, pub fn init(root: *Root) !void { - const output_layout = try wlr.OutputLayout.create(); + const output_layout = try wlr.OutputLayout.create(server.wl_server); errdefer output_layout.destroy(); const scene = try wlr.Scene.create(); @@ -131,9 +131,6 @@ pub fn init(root: *Root) !void { const outputs = try interactive_content.createSceneTree(); const override_redirect = if (build_options.xwayland) try interactive_content.createSceneTree(); - const presentation = try wlr.Presentation.create(server.wl_server, server.backend); - scene.setPresentation(presentation); - const event_loop = server.wl_server.getEventLoop(); const transaction_timeout = try event_loop.addTimer(*Root, handleTransactionTimeout, root); errdefer transaction_timeout.remove(); @@ -166,7 +163,7 @@ pub fn init(root: *Root) !void { .all_outputs = undefined, .active_outputs = undefined, - .presentation = presentation, + .presentation = try wlr.Presentation.create(server.wl_server, server.backend), .xdg_output_manager = try wlr.XdgOutputManagerV1.create(server.wl_server, output_layout), .output_manager = try wlr.OutputManagerV1.create(server.wl_server), .power_manager = try wlr.OutputPowerManagerV1.create(server.wl_server), diff --git a/river/Seat.zig b/river/Seat.zig index 4ac83f5..bb8e827 100644 --- a/river/Seat.zig +++ b/river/Seat.zig @@ -507,11 +507,11 @@ fn tryAddDevice(seat: *Seat, wlr_device: *wlr.InputDevice) !void { seat.cursor.wlr_cursor.attachInputDevice(wlr_device); }, - .tablet_tool => { + .tablet => { try Tablet.create(seat, wlr_device); seat.cursor.wlr_cursor.attachInputDevice(wlr_device); }, - .switch_device => { + .@"switch" => { const switch_device = try util.gpa.create(Switch); errdefer util.gpa.destroy(switch_device); @@ -534,7 +534,7 @@ pub fn updateCapabilities(seat: *Seat) void { switch (device.wlr_device.type) { .keyboard => capabilities.keyboard = true, .touch => capabilities.touch = true, - .pointer, .switch_device, .tablet_tool => {}, + .pointer, .@"switch", .tablet => {}, .tablet_pad => unreachable, } } diff --git a/river/Server.zig b/river/Server.zig index 7b46f3f..bb50dab 100644 --- a/river/Server.zig +++ b/river/Server.zig @@ -38,6 +38,7 @@ const Root = @import("Root.zig"); const Seat = @import("Seat.zig"); const SceneNodeData = @import("SceneNodeData.zig"); const StatusManager = @import("StatusManager.zig"); +const TabletTool = @import("TabletTool.zig"); const XdgDecoration = @import("XdgDecoration.zig"); const XdgToplevel = @import("XdgToplevel.zig"); const XwaylandOverrideRedirect = @import("XwaylandOverrideRedirect.zig"); @@ -96,8 +97,8 @@ xwayland: if (build_options.xwayland) ?*wlr.Xwayland else void = if (build_optio new_xwayland_surface: if (build_options.xwayland) wl.Listener(*wlr.XwaylandSurface) else void = if (build_options.xwayland) wl.Listener(*wlr.XwaylandSurface).init(handleNewXwaylandSurface), -new_xdg_surface: wl.Listener(*wlr.XdgSurface) = - wl.Listener(*wlr.XdgSurface).init(handleNewXdgSurface), +new_xdg_toplevel: wl.Listener(*wlr.XdgToplevel) = + wl.Listener(*wlr.XdgToplevel).init(handleNewXdgToplevel), new_toplevel_decoration: wl.Listener(*wlr.XdgToplevelDecorationV1) = wl.Listener(*wlr.XdgToplevelDecorationV1).init(handleNewToplevelDecoration), new_layer_surface: wl.Listener(*wlr.LayerSurfaceV1) = @@ -113,14 +114,14 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void { // This keeps the code simpler and more readable. const wl_server = try wl.Server.create(); + const loop = wl_server.getEventLoop(); var session: ?*wlr.Session = undefined; - const backend = try wlr.Backend.autocreate(wl_server, &session); + const backend = try wlr.Backend.autocreate(loop, &session); const renderer = try wlr.Renderer.autocreate(backend); const compositor = try wlr.Compositor.create(wl_server, 6, renderer); - const loop = wl_server.getEventLoop(); server.* = .{ .wl_server = wl_server, .sigint_source = try loop.addSignal(*wl.Server, posix.SIG.INT, terminate, wl_server), @@ -167,7 +168,7 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void { .lock_manager = undefined, }; - if (renderer.getDmabufFormats() != null and renderer.getDrmFd() >= 0) { + if (renderer.getTextureFormats(@intFromEnum(wlr.BufferCap.dmabuf)) != null) { // wl_drm is a legacy interface and all clients should switch to linux_dmabuf. // However, enough widely used clients still rely on wl_drm that the pragmatic option // is to keep it around for the near future. @@ -190,7 +191,7 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void { try server.idle_inhibit_manager.init(); try server.lock_manager.init(); - server.xdg_shell.events.new_surface.add(&server.new_xdg_surface); + server.xdg_shell.events.new_toplevel.add(&server.new_xdg_toplevel); server.xdg_decoration_manager.events.new_toplevel_decoration.add(&server.new_toplevel_decoration); server.layer_shell.events.new_surface.add(&server.new_layer_surface); server.xdg_activation.events.request_activate.add(&server.request_activate); @@ -204,7 +205,7 @@ pub fn deinit(server: *Server) void { server.sigint_source.remove(); server.sigterm_source.remove(); - server.new_xdg_surface.link.remove(); + server.new_xdg_toplevel.link.remove(); server.new_toplevel_decoration.link.remove(); server.new_layer_surface.link.remove(); server.request_activate.link.remove(); @@ -277,14 +278,6 @@ fn globalFilter(client: *const wl.Client, global: *const wl.Global, server: *Ser } } -fn hackGlobal(ptr: *anyopaque) *wl.Global { - // TODO(wlroots) MR that eliminates the need for this hack: - // https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4612 - if (wlr.version.major != 0 or wlr.version.minor != 17) @compileError("FIXME"); - - return @as(*extern struct { global: *wl.Global }, @alignCast(@ptrCast(ptr))).global; -} - /// Returns true if the global is allowlisted for security contexts fn allowlist(server: *Server, global: *const wl.Global) bool { if (server.drm) |drm| if (global == drm.global) return true; @@ -300,8 +293,8 @@ fn allowlist(server: *Server, global: *const wl.Global) bool { // with an assertion failure. return global.getInterface() == wl.Output.getInterface() or global.getInterface() == wl.Seat.getInterface() or - global == hackGlobal(server.shm) or - global == hackGlobal(server.single_pixel_buffer_manager) or + global == server.shm.global or + global == server.single_pixel_buffer_manager.global or global == server.viewporter.global or global == server.fractional_scale_manager.global or global == server.compositor.global or @@ -336,7 +329,7 @@ fn blocklist(server: *Server, global: *const wl.Global) bool { global == server.root.output_manager.global or global == server.root.power_manager.global or global == server.root.gamma_control_manager.global or - global == hackGlobal(server.input_manager.idle_notifier) or + global == server.input_manager.idle_notifier.global or global == server.input_manager.virtual_pointer_manager.global or global == server.input_manager.virtual_keyboard_manager.global or global == server.input_manager.input_method_manager.global or @@ -349,17 +342,12 @@ fn terminate(_: c_int, wl_server: *wl.Server) c_int { return 0; } -fn handleNewXdgSurface(_: *wl.Listener(*wlr.XdgSurface), xdg_surface: *wlr.XdgSurface) void { - if (xdg_surface.role == .popup) { - log.debug("new xdg_popup", .{}); - return; - } - +fn handleNewXdgToplevel(_: *wl.Listener(*wlr.XdgToplevel), xdg_toplevel: *wlr.XdgToplevel) void { log.debug("new xdg_toplevel", .{}); - XdgToplevel.create(xdg_surface.role_data.toplevel.?) catch { + XdgToplevel.create(xdg_toplevel) catch { log.err("out of memory", .{}); - xdg_surface.resource.postNoMemory(); + xdg_toplevel.resource.postNoMemory(); return; }; } @@ -450,17 +438,27 @@ fn handleRequestSetCursorShape( _: *wl.Listener(*wlr.CursorShapeManagerV1.event.RequestSetShape), event: *wlr.CursorShapeManagerV1.event.RequestSetShape, ) void { - // Ignore requests to set a tablet tool's cursor shape for now - // TODO(wlroots): https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3821 - if (event.device_type == .tablet_tool) return; + const seat: *Seat = @ptrFromInt(event.seat_client.seat.data); - const focused_client = event.seat_client.seat.pointer_state.focused_client; + if (event.tablet_tool) |wp_tool| { + assert(event.device_type == .tablet_tool); - // This can be sent by any client, so we check to make sure this one is - // actually has pointer focus first. - if (focused_client == event.seat_client) { - const seat: *Seat = @ptrFromInt(event.seat_client.seat.data); - const name = wlr.CursorShapeManagerV1.shapeName(event.shape); - seat.cursor.setXcursor(name); + const tool = TabletTool.get(event.seat_client.seat, wp_tool.wlr_tool) catch return; + + if (tool.allowSetCursor(event.seat_client, event.serial)) { + const name = wlr.CursorShapeManagerV1.shapeName(event.shape); + tool.wlr_cursor.setXcursor(seat.cursor.xcursor_manager, name); + } + } else { + assert(event.device_type == .pointer); + + const focused_client = event.seat_client.seat.pointer_state.focused_client; + + // This can be sent by any client, so we check to make sure this one is + // actually has pointer focus first. + if (focused_client == event.seat_client) { + const name = wlr.CursorShapeManagerV1.shapeName(event.shape); + seat.cursor.setXcursor(name); + } } } diff --git a/river/Tablet.zig b/river/Tablet.zig index d5773de..8d3f0da 100644 --- a/river/Tablet.zig +++ b/river/Tablet.zig @@ -33,7 +33,7 @@ wp_tablet: *wlr.TabletV2Tablet, output_mapping: ?*wlr.Output = null, pub fn create(seat: *Seat, wlr_device: *wlr.InputDevice) !void { - assert(wlr_device.type == .tablet_tool); + assert(wlr_device.type == .tablet); const tablet = try util.gpa.create(Tablet); errdefer util.gpa.destroy(tablet); diff --git a/river/TabletTool.zig b/river/TabletTool.zig index 1642469..af558a3 100644 --- a/river/TabletTool.zig +++ b/river/TabletTool.zig @@ -102,24 +102,29 @@ fn handleDestroy(listener: *wl.Listener(*wlr.TabletTool), _: *wlr.TabletTool) vo util.gpa.destroy(tool); } +pub fn allowSetCursor(tool: *TabletTool, seat_client: *wlr.Seat.Client, serial: u32) bool { + if (tool.wp_tool.focused_surface == null or + tool.wp_tool.focused_surface.?.resource.getClient() != seat_client.client) + { + log.debug("client tried to set cursor without focus", .{}); + return false; + } + if (serial != tool.wp_tool.proximity_serial) { + log.debug("focused client tried to set cursor with incorrect serial", .{}); + return false; + } + return true; +} + fn handleSetCursor( listener: *wl.Listener(*wlr.TabletV2TabletTool.event.SetCursor), event: *wlr.TabletV2TabletTool.event.SetCursor, ) void { 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) - { - log.debug("client tried to set cursor without focus", .{}); - return; + if (tool.allowSetCursor(event.seat_client, event.serial)) { + tool.wlr_cursor.setSurface(event.surface, event.hotspot_x, event.hotspot_y); } - if (event.serial != tool.wp_tool.proximity_serial) { - log.debug("focused client tried to set cursor with incorrect serial", .{}); - return; - } - - tool.wlr_cursor.setSurface(event.surface, event.hotspot_x, event.hotspot_y); } pub fn axis(tool: *TabletTool, tablet: *Tablet, event: *wlr.Tablet.event.Axis) void { diff --git a/river/XdgDecoration.zig b/river/XdgDecoration.zig index 8ea55de..eee0c1d 100644 --- a/river/XdgDecoration.zig +++ b/river/XdgDecoration.zig @@ -42,14 +42,9 @@ pub fn init(wlr_decoration: *wlr.XdgToplevelDecorationV1) void { wlr_decoration.events.destroy.add(&decoration.destroy); wlr_decoration.events.request_mode.add(&decoration.request_mode); - const ssd = server.config.rules.ssd.match(toplevel.view) orelse - (decoration.wlr_decoration.requested_mode != .client_side); - - // TODO(wlroots): make sure this is properly batched in a single configure - // with all other initial state when wlroots makes this possible. - _ = wlr_decoration.setMode(if (ssd) .server_side else .client_side); - - toplevel.view.pending.ssd = ssd; + if (toplevel.wlr_toplevel.base.initialized) { + handleRequestMode(&decoration.request_mode, wlr_decoration); + } } pub fn deinit(decoration: *XdgDecoration) void { diff --git a/river/XdgPopup.zig b/river/XdgPopup.zig index fd82fbe..3467210 100644 --- a/river/XdgPopup.zig +++ b/river/XdgPopup.zig @@ -54,7 +54,7 @@ pub fn create( .tree = try parent.createSceneXdgSurface(wlr_xdg_popup.base), }; - wlr_xdg_popup.base.events.destroy.add(&xdg_popup.destroy); + wlr_xdg_popup.events.destroy.add(&xdg_popup.destroy); wlr_xdg_popup.base.surface.events.commit.add(&xdg_popup.commit); wlr_xdg_popup.base.events.new_popup.add(&xdg_popup.new_popup); wlr_xdg_popup.events.reposition.add(&xdg_popup.reposition); diff --git a/river/XdgToplevel.zig b/river/XdgToplevel.zig index da3bf92..deca0b0 100644 --- a/river/XdgToplevel.zig +++ b/river/XdgToplevel.zig @@ -62,12 +62,12 @@ configure_state: union(enum) { 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), new_popup: wl.Listener(*wlr.XdgPopup) = wl.Listener(*wlr.XdgPopup).init(handleNewPopup), // Listeners that are only active while the view is mapped ack_configure: wl.Listener(*wlr.XdgSurface.Configure) = wl.Listener(*wlr.XdgSurface.Configure).init(handleAckConfigure), -commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit), request_fullscreen: wl.Listener(void) = wl.Listener(void).init(handleRequestFullscreen), request_move: wl.Listener(*wlr.XdgToplevel.event.Move) = wl.Listener(*wlr.XdgToplevel.event.Move).init(handleRequestMove), @@ -104,11 +104,10 @@ pub fn create(wlr_toplevel: *wlr.XdgToplevel) error{OutOfMemory}!void { wlr_toplevel.base.surface.data = @intFromPtr(&view.tree.node); // Add listeners that are active over the toplevel's entire lifetime - wlr_toplevel.base.events.destroy.add(&toplevel.destroy); + wlr_toplevel.events.destroy.add(&toplevel.destroy); wlr_toplevel.base.surface.events.map.add(&toplevel.map); + wlr_toplevel.base.surface.events.commit.add(&toplevel.commit); wlr_toplevel.base.events.new_popup.add(&toplevel.new_popup); - - _ = wlr_toplevel.setWmCapabilities(.{ .fullscreen = true }); } /// Send a configure event, applying the inflight state of the view. @@ -213,8 +212,10 @@ fn handleDestroy(listener: *wl.Listener(void)) void { toplevel.destroy.link.remove(); toplevel.map.link.remove(); toplevel.unmap.link.remove(); + toplevel.commit.link.remove(); + toplevel.new_popup.link.remove(); - // The wlr_surface may outlive the wlr_xdg_surface so we must clean up the user data. + // The wlr_surface may outlive the wlr_xdg_toplevel so we must clean up the user data. toplevel.wlr_toplevel.base.surface.data = 0; const view = toplevel.view; @@ -228,7 +229,6 @@ fn handleMap(listener: *wl.Listener(void)) void { // Add listeners that are only active while mapped toplevel.wlr_toplevel.base.events.ack_configure.add(&toplevel.ack_configure); - toplevel.wlr_toplevel.base.surface.events.commit.add(&toplevel.commit); toplevel.wlr_toplevel.events.request_fullscreen.add(&toplevel.request_fullscreen); toplevel.wlr_toplevel.events.request_move.add(&toplevel.request_move); toplevel.wlr_toplevel.events.request_resize.add(&toplevel.request_resize); @@ -270,7 +270,6 @@ fn handleUnmap(listener: *wl.Listener(void)) void { // Remove listeners that are only active while mapped toplevel.ack_configure.link.remove(); - toplevel.commit.link.remove(); toplevel.request_fullscreen.link.remove(); toplevel.request_move.link.remove(); toplevel.request_resize.link.remove(); @@ -309,6 +308,23 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { const toplevel: *XdgToplevel = @fieldParentPtr("commit", listener); const view = toplevel.view; + if (toplevel.wlr_toplevel.base.initial_commit) { + _ = toplevel.wlr_toplevel.setWmCapabilities(.{ .fullscreen = true }); + + if (toplevel.decoration) |decoration| { + const ssd = server.config.rules.ssd.match(toplevel.view) orelse + (decoration.wlr_decoration.requested_mode != .client_side); + _ = decoration.wlr_decoration.setMode(if (ssd) .server_side else .client_side); + toplevel.view.pending.ssd = ssd; + } + + return; + } + + if (!view.mapped) { + return; + } + { const state = &toplevel.wlr_toplevel.current; view.constraints = .{ diff --git a/river/main.zig b/river/main.zig index 19d23b5..4226e6a 100644 --- a/river/main.zig +++ b/river/main.zig @@ -31,12 +31,6 @@ const process = @import("process.zig"); const Server = @import("Server.zig"); -comptime { - if (wlr.version.major != 0 or wlr.version.minor != 17 or wlr.version.micro < 2) { - @compileError("river requires at least wlroots version 0.17.2 due to bugs in wlroots 0.17.0/0.17.1"); - } -} - const usage: []const u8 = \\usage: river [options] \\ From 2a75d51eec94014966a319c44bc9525119ae6476 Mon Sep 17 00:00:00 2001 From: tiosgz Date: Tue, 16 Jul 2024 21:11:55 +0000 Subject: [PATCH 46/90] LayerSurface: focus on_demand-interactive surfaces on map This is done specifically for lxqt-runner and qterminal to work as expected, consistently among (almost) all compositors with layer-shell. The most prominent drawback of this is that top- and overlay-layer status bars with on_demand interactivity also get focus on map. See https://codeberg.org/river/river/issues/1111 for more details. (cherry picked from commit f27bbf03f1173c9f148c5343dc0fc168c4fcb982) --- river/LayerSurface.zig | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/river/LayerSurface.zig b/river/LayerSurface.zig index 004a6c2..156ef1b 100644 --- a/river/LayerSurface.zig +++ b/river/LayerSurface.zig @@ -95,11 +95,17 @@ fn handleDestroy(listener: *wl.Listener(*wlr.LayerSurfaceV1), _: *wlr.LayerSurfa fn handleMap(listener: *wl.Listener(void)) void { const layer_surface: *LayerSurface = @fieldParentPtr("map", listener); + const wlr_surface = layer_surface.wlr_layer_surface; - log.debug("layer surface '{s}' mapped", .{layer_surface.wlr_layer_surface.namespace}); + log.debug("layer surface '{s}' mapped", .{wlr_surface.namespace}); layer_surface.output.arrangeLayers(); - handleKeyboardInteractiveExclusive(layer_surface.output); + const consider = (wlr_surface.current.keyboard_interactive != .none and + (wlr_surface.current.layer == .top or wlr_surface.current.layer == .overlay)); + handleKeyboardInteractiveExclusive( + layer_surface.output, + if (consider) layer_surface else null, + ); server.root.applyPending(); } @@ -109,7 +115,7 @@ fn handleUnmap(listener: *wl.Listener(void)) void { log.debug("layer surface '{s}' unmapped", .{layer_surface.wlr_layer_surface.namespace}); layer_surface.output.arrangeLayers(); - handleKeyboardInteractiveExclusive(layer_surface.output); + handleKeyboardInteractiveExclusive(layer_surface.output, null); server.root.applyPending(); } @@ -129,17 +135,19 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { @as(u32, @bitCast(wlr_layer_surface.current.committed)) != 0) { layer_surface.output.arrangeLayers(); - handleKeyboardInteractiveExclusive(layer_surface.output); + handleKeyboardInteractiveExclusive(layer_surface.output, null); server.root.applyPending(); } } +/// Focus topmost keyboard-interactivity-exclusive layer surface above normal +/// content, or if none found, focus that given as `consider`. /// Requires a call to Root.applyPending() -fn handleKeyboardInteractiveExclusive(output: *Output) void { +fn handleKeyboardInteractiveExclusive(output: *Output, consider: ?*LayerSurface) void { if (server.lock_manager.state != .unlocked) return; - // Find the topmost layer surface in the top or overlay layers which - // requests keyboard interactivity if any. + // Find the topmost layer surface (if any) in the top or overlay layers which + // requests exclusive keyboard interactivity. const topmost_surface = outer: for ([_]zwlr.LayerShellV1.Layer{ .overlay, .top }) |layer| { const tree = output.layerSurfaceTree(layer); // Iterate in reverse to match rendering order. @@ -156,7 +164,11 @@ fn handleKeyboardInteractiveExclusive(output: *Output) void { } } } - } else null; + } else consider; + + if (topmost_surface) |surface| { + assert(surface.wlr_layer_surface.current.keyboard_interactive != .none); + } var it = server.input_manager.seats.first; while (it) |node| : (it = node.next) { From 62576d792c62222326affc7dab845ffd1b512232 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Wed, 17 Jul 2024 11:10:02 +0200 Subject: [PATCH 47/90] LayerSurface: minor style/naming tweaks No functional changes (cherry picked from commit 2cc1d1cef3aa5adf621f82475b30b19ae9aecff5) --- river/LayerSurface.zig | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/river/LayerSurface.zig b/river/LayerSurface.zig index 156ef1b..d20d159 100644 --- a/river/LayerSurface.zig +++ b/river/LayerSurface.zig @@ -100,12 +100,14 @@ fn handleMap(listener: *wl.Listener(void)) void { log.debug("layer surface '{s}' mapped", .{wlr_surface.namespace}); layer_surface.output.arrangeLayers(); - const consider = (wlr_surface.current.keyboard_interactive != .none and - (wlr_surface.current.layer == .top or wlr_surface.current.layer == .overlay)); + + const consider = wlr_surface.current.keyboard_interactive == .on_demand and + (wlr_surface.current.layer == .top or wlr_surface.current.layer == .overlay); handleKeyboardInteractiveExclusive( layer_surface.output, if (consider) layer_surface else null, ); + server.root.applyPending(); } @@ -141,14 +143,14 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { } /// Focus topmost keyboard-interactivity-exclusive layer surface above normal -/// content, or if none found, focus that given as `consider`. +/// content, or if none found, focus the surface given as `consider`. /// Requires a call to Root.applyPending() fn handleKeyboardInteractiveExclusive(output: *Output, consider: ?*LayerSurface) void { if (server.lock_manager.state != .unlocked) return; // Find the topmost layer surface (if any) in the top or overlay layers which // requests exclusive keyboard interactivity. - const topmost_surface = outer: for ([_]zwlr.LayerShellV1.Layer{ .overlay, .top }) |layer| { + const to_focus = outer: for ([_]zwlr.LayerShellV1.Layer{ .overlay, .top }) |layer| { const tree = output.layerSurfaceTree(layer); // Iterate in reverse to match rendering order. var it = tree.children.iterator(.reverse); @@ -166,8 +168,8 @@ fn handleKeyboardInteractiveExclusive(output: *Output, consider: ?*LayerSurface) } } else consider; - if (topmost_surface) |surface| { - assert(surface.wlr_layer_surface.current.keyboard_interactive != .none); + if (to_focus) |s| { + assert(s.wlr_layer_surface.current.keyboard_interactive != .none); } var it = server.input_manager.seats.first; @@ -175,10 +177,10 @@ fn handleKeyboardInteractiveExclusive(output: *Output, consider: ?*LayerSurface) const seat = &node.data; if (seat.focused_output == output) { - if (topmost_surface) |to_focus| { + if (to_focus) |s| { // If we found a surface on the output that requires focus, grab the focus of all // seats that are focusing that output. - seat.setFocusRaw(.{ .layer = to_focus }); + seat.setFocusRaw(.{ .layer = s }); continue; } } From 510268d83a248eeb8921acb8d94c6e83f5593821 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 22 Jul 2024 16:17:07 +0200 Subject: [PATCH 48/90] river: attempt to recover from GPU resets (cherry picked from commit 85a1673a9e8bece59467a0107b79f9a5330c0f15) --- river/Server.zig | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/river/Server.zig b/river/Server.zig index bb50dab..6b5d12f 100644 --- a/river/Server.zig +++ b/river/Server.zig @@ -97,6 +97,8 @@ xwayland: if (build_options.xwayland) ?*wlr.Xwayland else void = if (build_optio new_xwayland_surface: if (build_options.xwayland) wl.Listener(*wlr.XwaylandSurface) else void = if (build_options.xwayland) wl.Listener(*wlr.XwaylandSurface).init(handleNewXwaylandSurface), +renderer_lost: wl.Listener(void) = wl.Listener(void).init(handleRendererLost), + new_xdg_toplevel: wl.Listener(*wlr.XdgToplevel) = wl.Listener(*wlr.XdgToplevel).init(handleNewXdgToplevel), new_toplevel_decoration: wl.Listener(*wlr.XdgToplevelDecorationV1) = @@ -191,6 +193,7 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void { try server.idle_inhibit_manager.init(); try server.lock_manager.init(); + server.renderer.events.lost.add(&server.renderer_lost); server.xdg_shell.events.new_toplevel.add(&server.new_xdg_toplevel); server.xdg_decoration_manager.events.new_toplevel_decoration.add(&server.new_toplevel_decoration); server.layer_shell.events.new_surface.add(&server.new_layer_surface); @@ -205,6 +208,7 @@ pub fn deinit(server: *Server) void { server.sigint_source.remove(); server.sigterm_source.remove(); + server.renderer_lost.link.remove(); server.new_xdg_toplevel.link.remove(); server.new_toplevel_decoration.link.remove(); server.new_layer_surface.link.remove(); @@ -342,6 +346,49 @@ fn terminate(_: c_int, wl_server: *wl.Server) c_int { return 0; } +fn handleRendererLost(listener: *wl.Listener(void)) void { + const server: *Server = @fieldParentPtr("renderer_lost", listener); + + log.info("recovering from GPU reset", .{}); + + // There's not much that can be done if creating a new renderer or allocator fails. + // With luck there might be another GPU reset after which we try again and succeed. + + server.recoverFromGpuReset() catch |err| switch (err) { + error.RendererCreateFailed => log.err("failed to create new renderer after GPU reset", .{}), + error.AllocatorCreateFailed => log.err("failed to create new allocator after GPU reset", .{}), + }; +} + +fn recoverFromGpuReset(server: *Server) !void { + const new_renderer = try wlr.Renderer.autocreate(server.backend); + errdefer new_renderer.destroy(); + + const new_allocator = try wlr.Allocator.autocreate(server.backend, new_renderer); + errdefer comptime unreachable; // no failure allowed after this point + + server.renderer_lost.link.remove(); + new_renderer.events.lost.add(&server.renderer_lost); + + server.compositor.setRenderer(new_renderer); + + { + var it = server.root.all_outputs.iterator(.forward); + while (it.next()) |output| { + // This should never fail here as failure with this combination of + // renderer, allocator, and backend should have prevented creating + // the output in the first place. + _ = output.wlr_output.initRender(new_allocator, new_renderer); + } + } + + server.renderer.destroy(); + server.renderer = new_renderer; + + server.allocator.destroy(); + server.allocator = new_allocator; +} + fn handleNewXdgToplevel(_: *wl.Listener(*wlr.XdgToplevel), xdg_toplevel: *wlr.XdgToplevel) void { log.debug("new xdg_toplevel", .{}); From 0e1b1862caaf4de438c81a3a3edd95e67e4275c2 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 22 Jul 2024 17:21:01 +0200 Subject: [PATCH 49/90] build: bump version to 0.3.5 --- build.zig | 2 +- build.zig.zon | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index 2b1ce1b..a085664 100644 --- a/build.zig +++ b/build.zig @@ -10,7 +10,7 @@ const Scanner = @import("zig-wayland").Scanner; /// with the "-dev" suffix. /// When a release is tagged, the "-dev" suffix should be removed for the commit that gets tagged. /// Directly after the tagged commit, the version should be bumped and the "-dev" suffix added. -const version = "0.3.5-dev"; +const version = "0.3.5"; pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); diff --git a/build.zig.zon b/build.zig.zon index f9558bf..a2bc090 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,6 @@ .{ .name = "river", - .version = "0.3.5-dev", + .version = "0.3.5", .paths = .{""}, .dependencies = .{ .@"zig-pixman" = .{ From dcc8e5cb9d532efa3117e8b1b69eefb002eafe44 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 22 Jul 2024 17:25:15 +0200 Subject: [PATCH 50/90] build: bump version to 0.3.6-dev --- build.zig | 2 +- build.zig.zon | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index a085664..8605632 100644 --- a/build.zig +++ b/build.zig @@ -10,7 +10,7 @@ const Scanner = @import("zig-wayland").Scanner; /// with the "-dev" suffix. /// When a release is tagged, the "-dev" suffix should be removed for the commit that gets tagged. /// Directly after the tagged commit, the version should be bumped and the "-dev" suffix added. -const version = "0.3.5"; +const version = "0.3.6-dev"; pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); diff --git a/build.zig.zon b/build.zig.zon index a2bc090..29fab87 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,6 @@ .{ .name = "river", - .version = "0.3.5", + .version = "0.3.6-dev", .paths = .{""}, .dependencies = .{ .@"zig-pixman" = .{ From 379f25fb3b6a4463ec9279f8929669130344ee0d Mon Sep 17 00:00:00 2001 From: tiosgz Date: Fri, 26 Jul 2024 07:53:42 +0000 Subject: [PATCH 51/90] Output: don't configure uninitialized layer surfaces It is possible for a layer surface to notably delay its initial commit; for example shotman[1] creates two layer surfaces and uses one of them to get enough information for a screenshot and initializing the other. River could also have sent a configure before initial commit if two clients raced against each other. Fixes https://codeberg.org/river/river/issues/1123 [1]:https://sr.ht/~whynothugo/shotman/ (cherry picked from commit 93863b132eb7a32e296d5f224181b04e161b1c58) --- river/Output.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/river/Output.zig b/river/Output.zig index e449f3f..77f0eb8 100644 --- a/river/Output.zig +++ b/river/Output.zig @@ -367,6 +367,8 @@ fn sendLayerConfigures( if (@as(?*SceneNodeData, @ptrFromInt(node.data))) |node_data| { const layer_surface = node_data.data.layer_surface; + if (!layer_surface.wlr_layer_surface.initialized) continue; + const exclusive = layer_surface.wlr_layer_surface.current.exclusive_zone > 0; if (exclusive != (mode == .exclusive)) { continue; From 4d11cd97e01ca3533774d2bb8fbbaa8fb9768c6a Mon Sep 17 00:00:00 2001 From: akawama Date: Sat, 27 Jul 2024 14:04:44 +0000 Subject: [PATCH 52/90] docs: clarify input device name description The word "numerical" suggests both decimal and hexadecimal, so changed it to decimal. (cherry picked from commit f5d37f9b4d70a20adb1825fb9d8e6d3f743b270c) --- doc/riverctl.1.scd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/riverctl.1.scd b/doc/riverctl.1.scd index 01b05a1..a40eb90 100644 --- a/doc/riverctl.1.scd +++ b/doc/riverctl.1.scd @@ -465,8 +465,8 @@ matches everything while _\*\*_ and the empty string are invalid. The _input_ command can be used to create a configuration rule for an input device identified by its _name_. -The _name_ of an input device consists of its type, its numerical vendor id, -its numerical product id and finally its self-advertised name, separated by -. +The _name_ of an input device consists of its type, its decimal vendor id, +its decimal product id and finally its self-advertised name, separated by -. Simple globbing patterns are supported, see the rules section for further information on globs. From 993bdf96d1cd20cae6c6afe22faf423a55df4ebb Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Wed, 7 Aug 2024 11:05:46 +0200 Subject: [PATCH 53/90] Root: simplify scene tree reparenting Making these reparent() calls unconditional avoids inconsistent state. It's also simpler and less error-prone and the wlroots function returns immediately if the parent doesn't change anyways. (cherry picked from commit db7de8151cf1491bc6e3b664d8ab1df0c23a93a7) --- river/Root.zig | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/river/Root.zig b/river/Root.zig index 829a304..5516280 100644 --- a/river/Root.zig +++ b/river/Root.zig @@ -673,24 +673,12 @@ fn commitTransaction(root: *Root) void { while (focus_stack_it.next()) |view| { assert(view.inflight.output == output); - if (view.current.output != view.inflight.output or - (output.current.fullscreen == view and output.inflight.fullscreen != view)) - { - if (view.inflight.float) { - view.tree.node.reparent(output.layers.float); - } else { - view.tree.node.reparent(output.layers.layout); - } - view.popup_tree.node.reparent(output.layers.popups); - } - - if (view.current.float != view.inflight.float) { - if (view.inflight.float) { - view.tree.node.reparent(output.layers.float); - } else { - view.tree.node.reparent(output.layers.layout); - } + if (view.inflight.float) { + view.tree.node.reparent(output.layers.float); + } else { + view.tree.node.reparent(output.layers.layout); } + view.popup_tree.node.reparent(output.layers.popups); view.commitTransaction(); @@ -703,15 +691,13 @@ fn commitTransaction(root: *Root) void { } } - if (output.inflight.fullscreen != output.current.fullscreen) { - if (output.inflight.fullscreen) |view| { - assert(view.inflight.output == output); - assert(view.current.output == output); - view.tree.node.reparent(output.layers.fullscreen); - } - output.current.fullscreen = output.inflight.fullscreen; - output.layers.fullscreen.node.setEnabled(output.current.fullscreen != null); + if (output.inflight.fullscreen) |view| { + assert(view.inflight.output == output); + assert(view.current.output == output); + view.tree.node.reparent(output.layers.fullscreen); } + output.current.fullscreen = output.inflight.fullscreen; + output.layers.fullscreen.node.setEnabled(output.current.fullscreen != null); output.status.handleTransactionCommit(output); } From aa1ef644488b10163f0b6e80694f48efb1999320 Mon Sep 17 00:00:00 2001 From: Violet Purcell Date: Wed, 7 Aug 2024 22:21:23 -0400 Subject: [PATCH 54/90] tearing-control-v1: implement Implement the wp-tearing-control-v1 protocol allowing window to hint the compositor that they prefer async "tearing" page flips. Add tearing/no-tearing rules to allow the user to manually enabled/disable tearing for a window. Use async "tearing" page flips when a window that should be allowed to tear is fullscreen. This still requires several kernel patches to work with the wlroots atomic DRM backend. For now, either set WLR_DRM_NO_ATOMIC=1 or use a custom kernel that includes the unmerged patches (such as CachyOS). Closes: https://codeberg.org/river/river/issues/1094 (cherry picked from commit 066baa575340a1926bc300cbeebba8ee735839a0) --- build.zig | 2 ++ build.zig.zon | 4 ++-- doc/riverctl.1.scd | 11 ++++++++++- river/Config.zig | 9 +++++++++ river/Output.zig | 37 ++++++++++++++++++++++++++----------- river/Server.zig | 4 ++++ river/View.zig | 25 +++++++++++++++++++++++++ river/command.zig | 1 + river/command/config.zig | 11 +++++++++++ river/command/rule.zig | 32 ++++++++++++++++++++++++++++++-- 10 files changed, 120 insertions(+), 16 deletions(-) diff --git a/build.zig b/build.zig index 8605632..068220d 100644 --- a/build.zig +++ b/build.zig @@ -94,6 +94,7 @@ pub fn build(b: *Build) !void { scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml"); scanner.addSystemProtocol("staging/cursor-shape/cursor-shape-v1.xml"); scanner.addSystemProtocol("staging/ext-session-lock/ext-session-lock-v1.xml"); + scanner.addSystemProtocol("staging/tearing-control/tearing-control-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"); @@ -124,6 +125,7 @@ pub fn build(b: *Build) !void { scanner.generate("zxdg_decoration_manager_v1", 1); scanner.generate("ext_session_lock_manager_v1", 1); scanner.generate("wp_cursor_shape_manager_v1", 1); + scanner.generate("wp_tearing_control_manager_v1", 1); scanner.generate("zriver_control_v1", 1); scanner.generate("zriver_status_manager_v1", 4); diff --git a/build.zig.zon b/build.zig.zon index 29fab87..8f92f44 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -12,8 +12,8 @@ .hash = "1220687c8c47a48ba285d26a05600f8700d37fc637e223ced3aa8324f3650bf52242", }, .@"zig-wlroots" = .{ - .url = "https://codeberg.org/ifreund/zig-wlroots/archive/v0.18.0.tar.gz", - .hash = "12204d789e17c158971f69c7b900e8d8f288e7b9e42b2242f3adfbca57e8266d848f", + .url = "https://codeberg.org/ifreund/zig-wlroots/archive/v0.18.1.tar.gz", + .hash = "122083317b028705b5d27be12976feebf17066a4e51802b3b5e9f970bec580e433e1", }, .@"zig-xkbcommon" = .{ .url = "https://codeberg.org/ifreund/zig-xkbcommon/archive/v0.2.0.tar.gz", diff --git a/doc/riverctl.1.scd b/doc/riverctl.1.scd index a40eb90..68008fa 100644 --- a/doc/riverctl.1.scd +++ b/doc/riverctl.1.scd @@ -307,11 +307,17 @@ matches everything while _\*\*_ and the empty string are invalid. - *fullscreen*: Make the view fullscreen. Applies only to new views. - *no-fullscreen*: Don't make the view fullscreen. Applies only to new views. + - *tearing*: Enable tearing for view when fullscreen regardless of the + supplied tearing hint. Note that tearing additionally requires setting the + *allow-tearing* server option. Applies to new and existing views. + - *no-tearing*: Disable tearing for view regardless of the supplied + tearing hint. Applies to new and existing views. Both *float* and *no-float* rules are added to the same list, which means that adding a *no-float* rule with the same arguments as a *float* rule will overwrite it. The same holds for *ssd* and - *csd*, *fullscreen* and *no-fullscreen* rules. + *csd*, *fullscreen* and *no-fullscreen*, *tearing* and + *no-tearing* rules. If multiple rules in a list match a given view the most specific rule will be applied. For example with the following rules @@ -364,6 +370,9 @@ matches everything while _\*\*_ and the empty string are invalid. Set the attach mode of the currently focused output, overriding the value of default-attach-mode if any. +*allow-tearing* *enabled*|*disabled* + Allow windows to tear if requested by either the program or the user. + *background-color* _0xRRGGBB_|_0xRRGGBBAA_ Set the background color. diff --git a/river/Config.zig b/river/Config.zig index 0b54f77..ed34617 100644 --- a/river/Config.zig +++ b/river/Config.zig @@ -31,6 +31,11 @@ const Mode = @import("Mode.zig"); const RuleList = @import("rule_list.zig").RuleList; const View = @import("View.zig"); +pub const AllowTearing = enum { + disabled, + enabled, +}; + pub const AttachMode = union(enum) { top, bottom, @@ -68,6 +73,9 @@ pub const Dimensions = struct { height: u31, }; +/// Whether to allow tearing page flips if a view requests it. +allow_tearing: AllowTearing = .disabled, + /// Color of background in RGBA with premultiplied alpha (alpha should only affect nested sessions) background_color: [4]f32 = [_]f32{ 0.0, 0.16862745, 0.21176471, 1.0 }, // Solarized base03 @@ -98,6 +106,7 @@ rules: struct { position: RuleList(Position) = .{}, dimensions: RuleList(Dimensions) = .{}, fullscreen: RuleList(bool) = .{}, + tearing: RuleList(bool) = .{}, } = .{}, /// The selected focus_follows_cursor mode diff --git a/river/Output.zig b/river/Output.zig index 77f0eb8..d7f087f 100644 --- a/river/Output.zig +++ b/river/Output.zig @@ -538,10 +538,12 @@ fn handleFrame(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void { } fn renderAndCommit(output: *Output, scene_output: *wlr.SceneOutput) !void { - if (output.gamma_dirty) { - var state = wlr.Output.State.init(); - defer state.finish(); + var state = wlr.Output.State.init(); + defer state.finish(); + if (!scene_output.buildState(&state, null)) return error.CommitFailed; + + if (output.gamma_dirty) { const control = server.root.gamma_control_manager.getControl(output.wlr_output); if (!wlr.GammaControlV1.apply(control, &state)) return error.OutOfMemory; @@ -553,16 +555,21 @@ fn renderAndCommit(output: *Output, scene_output: *wlr.SceneOutput) !void { // has a null LUT. The wayland backend for example has this behavior. state.committed.gamma_lut = false; } - - if (!scene_output.buildState(&state, null)) return error.CommitFailed; - - if (!output.wlr_output.commitState(&state)) return error.CommitFailed; - - output.gamma_dirty = false; - } else { - if (!scene_output.commit(null)) return error.CommitFailed; } + if (output.allowTearing() and server.config.allow_tearing == .enabled) { + state.tearing_page_flip = true; + + if (!output.wlr_output.testState(&state)) { + log.debug("tearing page flip test failed for {s}, retrying without tearing", .{output.wlr_output.name}); + state.tearing_page_flip = false; + } + } + + if (!output.wlr_output.commitState(&state)) return error.CommitFailed; + + if (output.gamma_dirty) output.gamma_dirty = false; + if (server.lock_manager.state == .locked or (server.lock_manager.state == .waiting_for_lock_surfaces and output.locked_content.node.enabled) or server.lock_manager.state == .waiting_for_blank) @@ -635,6 +642,14 @@ fn setTitle(output: Output) void { } } +fn allowTearing(output: *Output) bool { + if (output.current.fullscreen) |fullscreen_view| { + return fullscreen_view.allowTearing(); + } + + return false; +} + pub fn handleLayoutNamespaceChange(output: *Output) void { // The user changed the layout namespace of this output. Try to find a // matching layout. diff --git a/river/Server.zig b/river/Server.zig index 6b5d12f..2fbc97c 100644 --- a/river/Server.zig +++ b/river/Server.zig @@ -84,6 +84,8 @@ screencopy_manager: *wlr.ScreencopyManagerV1, foreign_toplevel_manager: *wlr.ForeignToplevelManagerV1, +tearing_control_manager: *wlr.TearingControlManagerV1, + input_manager: InputManager, root: Root, config: Config, @@ -159,6 +161,8 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void { .foreign_toplevel_manager = try wlr.ForeignToplevelManagerV1.create(wl_server), + .tearing_control_manager = try wlr.TearingControlManagerV1.create(wl_server, 1), + .config = try Config.init(), .root = undefined, diff --git a/river/View.zig b/river/View.zig index bb02da0..7ecceb4 100644 --- a/river/View.zig +++ b/river/View.zig @@ -23,6 +23,7 @@ const math = std.math; const posix = std.posix; const wlr = @import("wlroots"); const wl = @import("wayland").server.wl; +const wp = @import("wayland").server.wp; const server = &@import("main.zig").server; const util = @import("util.zig"); @@ -59,6 +60,12 @@ const AttachRelativeMode = enum { below, }; +const TearingMode = enum { + override_false, + override_true, + window_hint, +}; + pub const State = struct { /// The output the view is currently assigned to. /// May be null if there are no outputs or for newly created views. @@ -177,6 +184,9 @@ foreign_toplevel_handle: ForeignToplevelHandle = .{}, /// Connector name of the output this view occupied before an evacuation. output_before_evac: ?[]const u8 = null, +// Current tearing mode of the view. Defaults to using the window tearing hint. +tearing_mode: TearingMode = .window_hint, + pub fn create(impl: Impl) error{OutOfMemory}!*View { assert(impl != .none); @@ -572,6 +582,17 @@ pub fn getAppId(view: View) ?[*:0]const u8 { }; } +/// Return true if the view can currently tear. +pub fn allowTearing(view: *View) bool { + switch (view.tearing_mode) { + TearingMode.override_false => return false, + TearingMode.override_true => return true, + TearingMode.window_hint => if (view.rootSurface()) |root_surface| { + return server.tearing_control_manager.hintFromSurface(root_surface) == .@"async"; + } else return false, + } +} + /// Clamp the width/height of the box to the constraints of the view pub fn applyConstraints(view: *View, box: *wlr.Box) void { box.width = math.clamp(box.width, view.constraints.min_width, view.constraints.max_width); @@ -640,6 +661,10 @@ pub fn map(view: *View) !void { view.pending.ssd = ssd; } + if (server.config.rules.tearing.match(view)) |tearing| { + view.tearing_mode = if (tearing) .override_true else .override_false; + } + if (server.config.rules.dimensions.match(view)) |dimensions| { view.pending.box.width = dimensions.width; view.pending.box.height = dimensions.height; diff --git a/river/command.zig b/river/command.zig index 6ea5b96..85a5247 100644 --- a/river/command.zig +++ b/river/command.zig @@ -41,6 +41,7 @@ const command_impls = std.StaticStringMap( ).initComptime( .{ // zig fmt: off + .{ "allow-tearing", @import("command/config.zig").allowTearing }, .{ "attach-mode", @import("command/attach_mode.zig").defaultAttachMode }, .{ "background-color", @import("command/config.zig").backgroundColor }, .{ "border-color-focused", @import("command/config.zig").borderColorFocused }, diff --git a/river/command/config.zig b/river/command/config.zig index a97e233..3db604c 100644 --- a/river/command/config.zig +++ b/river/command/config.zig @@ -24,6 +24,17 @@ const Error = @import("../command.zig").Error; const Seat = @import("../Seat.zig"); const Config = @import("../Config.zig"); +pub fn allowTearing( + _: *Seat, + args: []const [:0]const u8, + _: *?[]const u8, +) Error!void { + if (args.len < 2) return Error.NotEnoughArguments; + if (args.len > 2) return Error.TooManyArguments; + server.config.allow_tearing = std.meta.stringToEnum(Config.AllowTearing, args[1]) orelse + return Error.UnknownOption; +} + pub fn borderWidth( _: *Seat, args: []const [:0]const u8, diff --git a/river/command/rule.zig b/river/command/rule.zig index 7703955..a8076fa 100644 --- a/river/command/rule.zig +++ b/river/command/rule.zig @@ -38,6 +38,8 @@ const Action = enum { dimensions, fullscreen, @"no-fullscreen", + tearing, + @"no-tearing", }; pub fn ruleAdd(_: *Seat, args: []const [:0]const u8, _: *?[]const u8) Error!void { @@ -53,7 +55,7 @@ pub fn ruleAdd(_: *Seat, args: []const [:0]const u8, _: *?[]const u8) Error!void const action = std.meta.stringToEnum(Action, result.args[0]) orelse return Error.UnknownOption; const positional_arguments_count: u8 = switch (action) { - .float, .@"no-float", .ssd, .csd, .fullscreen, .@"no-fullscreen" => 1, + .float, .@"no-float", .ssd, .csd, .fullscreen, .@"no-fullscreen", .tearing, .@"no-tearing" => 1, .tags, .output => 2, .position, .dimensions => 3, }; @@ -83,6 +85,14 @@ pub fn ruleAdd(_: *Seat, args: []const [:0]const u8, _: *?[]const u8) Error!void apply_ssd_rules(); server.root.applyPending(); }, + .tearing, .@"no-tearing" => { + try server.config.rules.tearing.add(.{ + .app_id_glob = app_id_glob, + .title_glob = title_glob, + .value = (action == .tearing), + }); + apply_tearing_rules(); + }, .tags => { const tags = try fmt.parseInt(u32, result.args[1], 10); try server.config.rules.tags.add(.{ @@ -177,6 +187,10 @@ pub fn ruleDel(_: *Seat, args: []const [:0]const u8, _: *?[]const u8) Error!void .fullscreen, .@"no-fullscreen" => { _ = server.config.rules.fullscreen.del(rule); }, + .tearing, .@"no-tearing" => { + _ = server.config.rules.tearing.del(rule); + apply_tearing_rules(); + }, } } @@ -191,6 +205,17 @@ fn apply_ssd_rules() void { } } +fn apply_tearing_rules() void { + var it = server.root.views.iterator(.forward); + while (it.next()) |view| { + if (view.destroying) continue; + + if (server.config.rules.tearing.match(view)) |tearing| { + view.tearing_mode = if (tearing) .override_true else .override_false; + } + } +} + pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error!void { if (args.len < 2) return error.NotEnoughArguments; if (args.len > 2) return error.TooManyArguments; @@ -203,6 +228,7 @@ pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error! position, dimensions, fullscreen, + tearing, }, args[1]) orelse return Error.UnknownOption; const max_glob_len = switch (rule_list) { inline else => |list| @field(server.config.rules, @tagName(list)).getMaxGlobLen(), @@ -218,12 +244,13 @@ pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error! try writer.writeAll("action\n"); switch (rule_list) { - inline .float, .ssd, .output, .fullscreen => |list| { + inline .float, .ssd, .output, .fullscreen, .tearing => |list| { const rules = switch (list) { .float => server.config.rules.float.rules.items, .ssd => server.config.rules.ssd.rules.items, .output => server.config.rules.output.rules.items, .fullscreen => server.config.rules.fullscreen.rules.items, + .tearing => server.config.rules.tearing.rules.items, else => unreachable, }; for (rules) |rule| { @@ -234,6 +261,7 @@ pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error! .ssd => if (rule.value) "ssd" else "csd", .output => rule.value, .fullscreen => if (rule.value) "fullscreen" else "no-fullscreen", + .tearing => if (rule.value) "tearing" else "no-tearing", else => unreachable, }}); } From c69139644820c691283ac11fe893fc7df534dfca Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 15 Aug 2024 11:42:38 +0200 Subject: [PATCH 55/90] tearing-control: minor cleanups/style improvements This commit also tweaks the riverctl interface to make the global allow-tearing option apply only to tearing-control-v1 hints from clients. The global option no longer affects tearing/no-tearing rules explicitly created by the user. (cherry picked from commit f82b2f58163eb092941d7d2e05e1d0eeaa9f50fe) --- doc/riverctl.1.scd | 12 ++++++------ river/Config.zig | 9 ++------- river/Output.zig | 25 ++++++++++--------------- river/View.zig | 24 ++++++++++++++---------- river/command/config.zig | 5 ++++- river/command/rule.zig | 2 +- 6 files changed, 37 insertions(+), 40 deletions(-) diff --git a/doc/riverctl.1.scd b/doc/riverctl.1.scd index 68008fa..b729f22 100644 --- a/doc/riverctl.1.scd +++ b/doc/riverctl.1.scd @@ -307,11 +307,10 @@ matches everything while _\*\*_ and the empty string are invalid. - *fullscreen*: Make the view fullscreen. Applies only to new views. - *no-fullscreen*: Don't make the view fullscreen. Applies only to new views. - - *tearing*: Enable tearing for view when fullscreen regardless of the - supplied tearing hint. Note that tearing additionally requires setting the - *allow-tearing* server option. Applies to new and existing views. - - *no-tearing*: Disable tearing for view regardless of the supplied - tearing hint. Applies to new and existing views. + - *tearing*: Allow the view to tear when fullscreen regardless of the + view's preference. Applies to new and existing views. + - *no-tearing*: Disable tearing for the view regardless of the view's + preference. Applies to new and existing views. Both *float* and *no-float* rules are added to the same list, which means that adding a *no-float* rule with the same arguments @@ -371,7 +370,8 @@ matches everything while _\*\*_ and the empty string are invalid. default-attach-mode if any. *allow-tearing* *enabled*|*disabled* - Allow windows to tear if requested by either the program or the user. + Allow fullscreen views to tear if requested by the view. See also the + *tearing* rule to force enable tearing for specific views. *background-color* _0xRRGGBB_|_0xRRGGBBAA_ Set the background color. diff --git a/river/Config.zig b/river/Config.zig index ed34617..f61c82c 100644 --- a/river/Config.zig +++ b/river/Config.zig @@ -31,11 +31,6 @@ const Mode = @import("Mode.zig"); const RuleList = @import("rule_list.zig").RuleList; const View = @import("View.zig"); -pub const AllowTearing = enum { - disabled, - enabled, -}; - pub const AttachMode = union(enum) { top, bottom, @@ -73,8 +68,8 @@ pub const Dimensions = struct { height: u31, }; -/// Whether to allow tearing page flips if a view requests it. -allow_tearing: AllowTearing = .disabled, +/// Whether to allow tearing page flips when fullscreen if a view requests it. +allow_tearing: bool = false, /// Color of background in RGBA with premultiplied alpha (alpha should only affect nested sessions) background_color: [4]f32 = [_]f32{ 0.0, 0.16862745, 0.21176471, 1.0 }, // Solarized base03 diff --git a/river/Output.zig b/river/Output.zig index d7f087f..be6a5bb 100644 --- a/river/Output.zig +++ b/river/Output.zig @@ -557,18 +557,21 @@ fn renderAndCommit(output: *Output, scene_output: *wlr.SceneOutput) !void { } } - if (output.allowTearing() and server.config.allow_tearing == .enabled) { - state.tearing_page_flip = true; - - if (!output.wlr_output.testState(&state)) { - log.debug("tearing page flip test failed for {s}, retrying without tearing", .{output.wlr_output.name}); - state.tearing_page_flip = false; + if (output.current.fullscreen) |fullscreen| { + if (fullscreen.allowTearing()) { + state.tearing_page_flip = true; + if (!output.wlr_output.testState(&state)) { + log.debug("tearing page flip test failed for {s}, retrying without tearing", .{ + output.wlr_output.name, + }); + state.tearing_page_flip = false; + } } } if (!output.wlr_output.commitState(&state)) return error.CommitFailed; - if (output.gamma_dirty) output.gamma_dirty = false; + output.gamma_dirty = false; if (server.lock_manager.state == .locked or (server.lock_manager.state == .waiting_for_lock_surfaces and output.locked_content.node.enabled) or @@ -642,14 +645,6 @@ fn setTitle(output: Output) void { } } -fn allowTearing(output: *Output) bool { - if (output.current.fullscreen) |fullscreen_view| { - return fullscreen_view.allowTearing(); - } - - return false; -} - pub fn handleLayoutNamespaceChange(output: *Output) void { // The user changed the layout namespace of this output. Try to find a // matching layout. diff --git a/river/View.zig b/river/View.zig index 7ecceb4..2199f85 100644 --- a/river/View.zig +++ b/river/View.zig @@ -61,8 +61,8 @@ const AttachRelativeMode = enum { }; const TearingMode = enum { - override_false, - override_true, + no_tearing, + tearing, window_hint, }; @@ -184,7 +184,6 @@ foreign_toplevel_handle: ForeignToplevelHandle = .{}, /// Connector name of the output this view occupied before an evacuation. output_before_evac: ?[]const u8 = null, -// Current tearing mode of the view. Defaults to using the window tearing hint. tearing_mode: TearingMode = .window_hint, pub fn create(impl: Impl) error{OutOfMemory}!*View { @@ -582,14 +581,19 @@ pub fn getAppId(view: View) ?[*:0]const u8 { }; } -/// Return true if the view can currently tear. +/// Return true if tearing should be allowed for the view. pub fn allowTearing(view: *View) bool { switch (view.tearing_mode) { - TearingMode.override_false => return false, - TearingMode.override_true => return true, - TearingMode.window_hint => if (view.rootSurface()) |root_surface| { - return server.tearing_control_manager.hintFromSurface(root_surface) == .@"async"; - } else return false, + .no_tearing => return false, + .tearing => return true, + .window_hint => { + if (server.config.allow_tearing) { + if (view.rootSurface()) |root_surface| { + return server.tearing_control_manager.hintFromSurface(root_surface) == .@"async"; + } + } + return false; + }, } } @@ -662,7 +666,7 @@ pub fn map(view: *View) !void { } if (server.config.rules.tearing.match(view)) |tearing| { - view.tearing_mode = if (tearing) .override_true else .override_false; + view.tearing_mode = if (tearing) .tearing else .no_tearing; } if (server.config.rules.dimensions.match(view)) |dimensions| { diff --git a/river/command/config.zig b/river/command/config.zig index 3db604c..531ae92 100644 --- a/river/command/config.zig +++ b/river/command/config.zig @@ -31,8 +31,11 @@ pub fn allowTearing( ) Error!void { if (args.len < 2) return Error.NotEnoughArguments; if (args.len > 2) return Error.TooManyArguments; - server.config.allow_tearing = std.meta.stringToEnum(Config.AllowTearing, args[1]) orelse + + const arg = std.meta.stringToEnum(enum { enabled, disabled }, args[1]) orelse return Error.UnknownOption; + + server.config.allow_tearing = arg == .enabled; } pub fn borderWidth( diff --git a/river/command/rule.zig b/river/command/rule.zig index a8076fa..5b64400 100644 --- a/river/command/rule.zig +++ b/river/command/rule.zig @@ -211,7 +211,7 @@ fn apply_tearing_rules() void { if (view.destroying) continue; if (server.config.rules.tearing.match(view)) |tearing| { - view.tearing_mode = if (tearing) .override_true else .override_false; + view.tearing_mode = if (tearing) .tearing else .no_tearing; } } } From a50573082b5565f9cb44fcda3150ace00d2e0d92 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Wed, 28 Aug 2024 11:26:35 +0200 Subject: [PATCH 56/90] tearing-control: fix security-context related assert (cherry picked from commit 55974987b6a09d4208af09a07ecccd4656b660b6) --- river/Server.zig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/river/Server.zig b/river/Server.zig index 2fbc97c..8fc7422 100644 --- a/river/Server.zig +++ b/river/Server.zig @@ -320,7 +320,8 @@ fn allowlist(server: *Server, global: *const wl.Global) bool { global == server.input_manager.text_input_manager.global or global == server.input_manager.tablet_manager.global or global == server.input_manager.pointer_gestures.global or - global == server.idle_inhibit_manager.wlr_manager.global; + global == server.idle_inhibit_manager.wlr_manager.global or + global == server.tearing_control_manager.global; } /// Returns true if the global is blocked for security contexts From b281d196e45fc92ea36492618757f7a8daebf477 Mon Sep 17 00:00:00 2001 From: tiosgz Date: Wed, 4 Sep 2024 10:57:16 +0000 Subject: [PATCH 57/90] build: load tablet-v2 protocol from its new location (cherry picked from commit fbb9cc0f76da5e19f25ef2bc32f4e89febc95435) --- build.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig b/build.zig index 068220d..b638d86 100644 --- a/build.zig +++ b/build.zig @@ -92,12 +92,12 @@ pub fn build(b: *Build) !void { const scanner = Scanner.create(b, .{}); scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml"); + scanner.addSystemProtocol("stable/tablet/tablet-v2.xml"); scanner.addSystemProtocol("staging/cursor-shape/cursor-shape-v1.xml"); scanner.addSystemProtocol("staging/ext-session-lock/ext-session-lock-v1.xml"); scanner.addSystemProtocol("staging/tearing-control/tearing-control-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"); From fd58a84f18bd2763de232635800f634b26bf2a62 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Wed, 18 Sep 2024 16:12:18 +0200 Subject: [PATCH 58/90] docs: fix broken repology link (cherry picked from commit 26f599b56b8f73dc13be055f6730edafd6c30401) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f8eb56e..f156566 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ River is a dynamic tiling Wayland compositor with flexible runtime configuration. -Check [packaging status](https://repology.org/project/river/versions) — +Check [packaging status](https://repology.org/project/river-compositor/versions) — Join us at [#river](https://web.libera.chat/?channels=#river) on irc.libera.chat — Read our man pages, [wiki](https://codeberg.org/river/wiki), and [Code of Conduct](CODE_OF_CONDUCT.md) From 42b339fbb8ef699b555ac83cf3c76239f8f94192 Mon Sep 17 00:00:00 2001 From: Aviva Ruben Date: Tue, 1 Oct 2024 14:48:27 -0500 Subject: [PATCH 59/90] input: support scroll button lock config (cherry picked from commit fd55f51ba1b53af95fe3a24611490d42a895ef98) --- completions/bash/riverctl | 3 ++- completions/fish/riverctl.fish | 3 ++- completions/zsh/_riverctl | 2 ++ doc/riverctl.1.scd | 5 +++++ river/InputConfig.zig | 13 +++++++++++++ 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/completions/bash/riverctl b/completions/bash/riverctl index 68684d5..a889d4c 100644 --- a/completions/bash/riverctl +++ b/completions/bash/riverctl @@ -99,6 +99,7 @@ function __riverctl_completion () tap-button-map \ scroll-method \ scroll-button \ + scroll-button-lock \ map-to-output" COMPREPLY=($(compgen -W "${OPTS}" -- "${COMP_WORDS[3]}")) elif [ "${COMP_WORDS[1]}" == "hide-cursor" ] @@ -117,7 +118,7 @@ function __riverctl_completion () "events") OPTS="enabled disabled disabled-on-external-mouse" ;; "accel-profile") OPTS="none flat adaptive" ;; "click-method") OPTS="none button-areas clickfinger" ;; - "drag"|"drag-lock"|"disable-while-typing"|"middle-emulation"|"left-handed"|"tap") OPTS="enabled disabled" ;; + "drag"|"drag-lock"|"disable-while-typing"|"middle-emulation"|"left-handed"|"tap"|"scroll-button-lock") OPTS="enabled disabled" ;; "tap-button-map") OPTS="left-right-middle left-middle-right" ;; "scroll-method") OPTS="none two-finger edge button" ;; *) return ;; diff --git a/completions/fish/riverctl.fish b/completions/fish/riverctl.fish index 65fad0a..50458b4 100644 --- a/completions/fish/riverctl.fish +++ b/completions/fish/riverctl.fish @@ -119,10 +119,11 @@ complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_ complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 3' -a 'tap-button-map' -d 'Configure the button mapping for tapping' complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 3' -a 'scroll-method' -d 'Set the scroll method' complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 3' -a 'scroll-button' -d 'Set the scroll button' +complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 3' -a 'scroll-button-lock' -d 'Enable or disable the scroll button lock functionality' complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 3' -a 'map-to-output' -d 'Map to a given output' # Subcommands for the subcommands of 'input' -complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 4; and __fish_seen_subcommand_from drag drag-lock disable-while-typing disable-while-trackpointing middle-emulation natural-scroll left-handed tap' -a 'enabled disabled' +complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 4; and __fish_seen_subcommand_from drag drag-lock disable-while-typing disable-while-trackpointing middle-emulation natural-scroll left-handed tap scroll-button-lock' -a 'enabled disabled' complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 4; and __fish_seen_subcommand_from events' -a 'enabled disabled disabled-on-external-mouse' complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 4; and __fish_seen_subcommand_from accel-profile' -a 'none flat adaptive' complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 4; and __fish_seen_subcommand_from click-method' -a 'none button-areas clickfinger' diff --git a/completions/zsh/_riverctl b/completions/zsh/_riverctl index 73df6b1..ad372d3 100644 --- a/completions/zsh/_riverctl +++ b/completions/zsh/_riverctl @@ -126,6 +126,7 @@ _riverctl() 'tap-button-map:Configure the button mapping for tapping' 'scroll-method:Set the scroll method' 'scroll-button:Set the scroll button' + 'scroll-button-lock:Enable or disable the scroll button lock functionality' 'map-to-output:Map to a given output' ) @@ -144,6 +145,7 @@ _riverctl() natural-scroll) _alternative 'input-cmds:args:(enabled disabled)' ;; left-handed) _alternative 'input-cmds:args:(enabled disabled)' ;; tap) _alternative 'input-cmds:args:(enabled disabled)' ;; + scroll-button-lock) _alternative 'input-cmds:args:(enabled disabled)' ;; tap-button-map) _alternative 'input-cmds:args:(left-right-middle left-middle-right)' ;; scroll-method) _alternative 'input-cmds:args:(none two-finger edge button)' ;; *) return 0 ;; diff --git a/doc/riverctl.1.scd b/doc/riverctl.1.scd index b729f22..3a3ac1b 100644 --- a/doc/riverctl.1.scd +++ b/doc/riverctl.1.scd @@ -545,6 +545,11 @@ However note that not every input device supports every property. Set the scroll button of an input device. _button_ is the name of a Linux input event code. +*input* _name_ *scroll-button-lock* *enabled*|*disabled* + Enable or disable the scroll button lock functionality of the input device. If + active, the button does not need to be held down. One press makes the button + considered to be held down, and a second press releases the button. + *input* _name_ *map-to-output* _output_|*disabled* Maps the input to a given output. This is valid even if the output isn't currently active and will lead to the device being mapped once it is diff --git a/river/InputConfig.zig b/river/InputConfig.zig index 39fc47d..40abf3c 100644 --- a/river/InputConfig.zig +++ b/river/InputConfig.zig @@ -215,6 +215,18 @@ pub const ScrollButton = struct { } }; +pub const ScrollButtonLock = enum { + enabled, + disabled, + + fn apply(scroll_button_lock: ScrollButtonLock, device: *c.libinput_device) void { + _ = c.libinput_device_config_scroll_set_button_lock(device, switch (scroll_button_lock) { + .enabled => c.LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED, + .disabled => c.LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED, + }); + } +}; + pub const MapToOutput = struct { output_name: ?[]const u8, @@ -279,6 +291,7 @@ tap: ?TapState = null, @"pointer-accel": ?PointerAccel = null, @"scroll-method": ?ScrollMethod = null, @"scroll-button": ?ScrollButton = null, +@"scroll-button-lock": ?ScrollButtonLock = null, @"map-to-output": ?MapToOutput = null, pub fn deinit(config: *InputConfig) void { From 08cc135ebd5fc3b9fd36bb9d554b2df677e33882 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 24 Oct 2024 10:55:44 +0200 Subject: [PATCH 60/90] Output: workaround wlroots headless output bug (cherry picked from commit 3529463569d4e7f8f9a7510ab11292e91b1c9a4a) --- river/Output.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/river/Output.zig b/river/Output.zig index be6a5bb..9a5b94e 100644 --- a/river/Output.zig +++ b/river/Output.zig @@ -547,7 +547,9 @@ fn renderAndCommit(output: *Output, scene_output: *wlr.SceneOutput) !void { const control = server.root.gamma_control_manager.getControl(output.wlr_output); if (!wlr.GammaControlV1.apply(control, &state)) return error.OutOfMemory; - if (!output.wlr_output.testState(&state)) { + // TODO(wlroots): remove this isHeadless() workaround after upstream fix is available + // in a release: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4868 + if (!output.wlr_output.testState(&state) or output.wlr_output.isHeadless()) { wlr.GammaControlV1.sendFailedAndDestroy(control); state.clearGammaLut(); // If the backend does not support gamma LUTs it will reject any From f0798f7536d8aba1486e50cfa7518861e20a001c Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 24 Oct 2024 12:05:48 +0200 Subject: [PATCH 61/90] layer-surface: fix clip box coordinates The clip box must be relative to the layer surface, not the output. (cherry picked from commit 1b5dd21ee610b30d13c9165dfde23989c5e97e8d) --- river/Output.zig | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/river/Output.zig b/river/Output.zig index 9a5b94e..d4490c3 100644 --- a/river/Output.zig +++ b/river/Output.zig @@ -393,11 +393,15 @@ fn sendLayerConfigures( usable_box.* = new_usable_box; } - layer_surface.popup_tree.node.setPosition( - layer_surface.scene_layer_surface.tree.node.x, - layer_surface.scene_layer_surface.tree.node.y, - ); - layer_surface.scene_layer_surface.tree.node.subsurfaceTreeSetClip(&full_box); + const x = layer_surface.scene_layer_surface.tree.node.x; + const y = layer_surface.scene_layer_surface.tree.node.y; + layer_surface.popup_tree.node.setPosition(x, y); + layer_surface.scene_layer_surface.tree.node.subsurfaceTreeSetClip(&.{ + .x = -x, + .y = -y, + .width = full_box.width, + .height = full_box.height, + }); } } } From be0e372fbc76e088f4e2a8f1412665308083abae Mon Sep 17 00:00:00 2001 From: tesselslate Date: Mon, 4 Nov 2024 21:03:34 -0500 Subject: [PATCH 62/90] alpha-modifier-v1: implement protocol Implement the alpha-modifier-v1 protocol, which allows clients to offload alpha blending operations to the compositor. wlroots' scene graph code takes care of updating the opacity of wlr_scene_buffers with an associated wp_alpha_modifier_surface_v1. (cherry picked from commit a2a5e8f4632374b4b322c0520b7e30e35e0d753a) --- river/Server.zig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/river/Server.zig b/river/Server.zig index 8fc7422..027e777 100644 --- a/river/Server.zig +++ b/river/Server.zig @@ -86,6 +86,8 @@ foreign_toplevel_manager: *wlr.ForeignToplevelManagerV1, tearing_control_manager: *wlr.TearingControlManagerV1, +alpha_modifier: *wlr.AlphaModifierV1, + input_manager: InputManager, root: Root, config: Config, @@ -163,6 +165,8 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void { .tearing_control_manager = try wlr.TearingControlManagerV1.create(wl_server, 1), + .alpha_modifier = try wlr.AlphaModifierV1.create(wl_server), + .config = try Config.init(), .root = undefined, @@ -321,7 +325,8 @@ fn allowlist(server: *Server, global: *const wl.Global) bool { global == server.input_manager.tablet_manager.global or global == server.input_manager.pointer_gestures.global or global == server.idle_inhibit_manager.wlr_manager.global or - global == server.tearing_control_manager.global; + global == server.tearing_control_manager.global or + global == server.alpha_modifier.global; } /// Returns true if the global is blocked for security contexts From 59f0fb2882c66120d9b383d03fbc744348895950 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sun, 24 Nov 2024 15:11:42 +0100 Subject: [PATCH 63/90] docs: mention key repeat defaults (cherry picked from commit 5ca829bd5acea4c68abcf16332ccfe6202da4aeb) --- doc/riverctl.1.scd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/riverctl.1.scd b/doc/riverctl.1.scd index 3a3ac1b..d0476ea 100644 --- a/doc/riverctl.1.scd +++ b/doc/riverctl.1.scd @@ -422,7 +422,8 @@ matches everything while _\*\*_ and the empty string are invalid. *set-repeat* _rate_ _delay_ Set the keyboard repeat rate to _rate_ key repeats per second and - repeat delay to _delay_ milliseconds. + repeat delay to _delay_ milliseconds. The default is a rate of 25 + repeats per second and a delay of 600ms. *xcursor-theme* _theme_name_ [_size_] Set the xcursor theme to _theme_name_ and optionally set the _size_. From 4b24287da73684dcb8879a96804f79dbfd0fb490 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 9 Dec 2024 15:01:53 +0100 Subject: [PATCH 64/90] build: bump version to 0.3.6 --- build.zig | 2 +- build.zig.zon | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index b638d86..55f7ced 100644 --- a/build.zig +++ b/build.zig @@ -10,7 +10,7 @@ const Scanner = @import("zig-wayland").Scanner; /// with the "-dev" suffix. /// When a release is tagged, the "-dev" suffix should be removed for the commit that gets tagged. /// Directly after the tagged commit, the version should be bumped and the "-dev" suffix added. -const version = "0.3.6-dev"; +const version = "0.3.6"; pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); diff --git a/build.zig.zon b/build.zig.zon index 8f92f44..11890df 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,6 @@ .{ .name = "river", - .version = "0.3.6-dev", + .version = "0.3.6", .paths = .{""}, .dependencies = .{ .@"zig-pixman" = .{ From 6254211a26db623379886c073c17f93bbd156a61 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 9 Dec 2024 15:07:58 +0100 Subject: [PATCH 65/90] build: bump version to 0.3.7-dev --- build.zig | 2 +- build.zig.zon | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index 55f7ced..ca9e837 100644 --- a/build.zig +++ b/build.zig @@ -10,7 +10,7 @@ const Scanner = @import("zig-wayland").Scanner; /// with the "-dev" suffix. /// When a release is tagged, the "-dev" suffix should be removed for the commit that gets tagged. /// Directly after the tagged commit, the version should be bumped and the "-dev" suffix added. -const version = "0.3.6"; +const version = "0.3.7-dev"; pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); diff --git a/build.zig.zon b/build.zig.zon index 11890df..924e369 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,6 @@ .{ .name = "river", - .version = "0.3.6", + .version = "0.3.7-dev", .paths = .{""}, .dependencies = .{ .@"zig-pixman" = .{ From a5f94268e653b2bb7c27cd38aac721c96f29f37e Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sun, 29 Dec 2024 16:09:44 -0600 Subject: [PATCH 66/90] Output: check scene damage before rendering This should fix adaptive sync/VRR, which was regressed by db7de8151. (cherry picked from commit ab879e245cbc317e3a2f5ec0379143d4b25b3cfe) --- river/Output.zig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/river/Output.zig b/river/Output.zig index d4490c3..34e49dd 100644 --- a/river/Output.zig +++ b/river/Output.zig @@ -542,6 +542,13 @@ fn handleFrame(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void { } fn renderAndCommit(output: *Output, scene_output: *wlr.SceneOutput) !void { + // TODO(wlroots): replace this with wlr_scene_output_needs_frame() + if (!output.wlr_output.needs_frame and !output.gamma_dirty and + !scene_output.pending_commit_damage.notEmpty()) + { + return; + } + var state = wlr.Output.State.init(); defer state.finish(); From 840eacae62adeee1eed50556a8bb26bec39c45f1 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 30 Dec 2024 09:21:24 -0600 Subject: [PATCH 67/90] river: wrap monotonic time > 2^32-1 milliseconds Fixes: https://codeberg.org/river/river/issues/1176 (cherry picked from commit 6abcc68a198d0246077aaaed8af08db224f16775) --- river/Cursor.zig | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/river/Cursor.zig b/river/Cursor.zig index 235f29c..bb6334f 100644 --- a/river/Cursor.zig +++ b/river/Cursor.zig @@ -1091,8 +1091,13 @@ pub fn updateState(cursor: *Cursor) void { if (!cursor.hidden) { 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)); + // 2^32-1 milliseconds is ~50 days, which is a realistic uptime. + // This means that we must wrap if the monotonic time is greater than + // 2^32-1 milliseconds and hope that clients don't get too confused. + const msec: u32 = @intCast(@rem( + now.tv_sec *% std.time.ms_per_s +% @divTrunc(now.tv_nsec, std.time.ns_per_ms), + math.maxInt(u32), + )); cursor.passthrough(msec); } }, From 189cf6e68b37b30a90a301b059c2f469bdc1900b Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sat, 4 Jan 2025 11:35:17 -0600 Subject: [PATCH 68/90] build: bump version to 0.3.7 --- build.zig | 2 +- build.zig.zon | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index ca9e837..d93b660 100644 --- a/build.zig +++ b/build.zig @@ -10,7 +10,7 @@ const Scanner = @import("zig-wayland").Scanner; /// with the "-dev" suffix. /// When a release is tagged, the "-dev" suffix should be removed for the commit that gets tagged. /// Directly after the tagged commit, the version should be bumped and the "-dev" suffix added. -const version = "0.3.7-dev"; +const version = "0.3.7"; pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); diff --git a/build.zig.zon b/build.zig.zon index 924e369..1d6cd68 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,6 @@ .{ .name = "river", - .version = "0.3.7-dev", + .version = "0.3.7", .paths = .{""}, .dependencies = .{ .@"zig-pixman" = .{ From 295bbb241a48de5a073d47f6dbbff9634fcb8565 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sat, 4 Jan 2025 11:39:28 -0600 Subject: [PATCH 69/90] build: bump version to 0.3.8-dev --- build.zig | 2 +- build.zig.zon | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index d93b660..f7468bb 100644 --- a/build.zig +++ b/build.zig @@ -10,7 +10,7 @@ const Scanner = @import("zig-wayland").Scanner; /// with the "-dev" suffix. /// When a release is tagged, the "-dev" suffix should be removed for the commit that gets tagged. /// Directly after the tagged commit, the version should be bumped and the "-dev" suffix added. -const version = "0.3.7"; +const version = "0.3.8-dev"; pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); diff --git a/build.zig.zon b/build.zig.zon index 1d6cd68..b0f01ed 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,6 @@ .{ .name = "river", - .version = "0.3.7", + .version = "0.3.8-dev", .paths = .{""}, .dependencies = .{ .@"zig-pixman" = .{ From 0eb478b06a719a84cf37150284eabb7383726559 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Tue, 7 Jan 2025 11:00:44 -0600 Subject: [PATCH 70/90] Xwayland: don't inherit rlimit changes from river (cherry picked from commit 543697847f2167152ae25f775f39541591b8d020) --- river/main.zig | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/river/main.zig b/river/main.zig index 4226e6a..2bb0ed5 100644 --- a/river/main.zig +++ b/river/main.zig @@ -84,7 +84,7 @@ pub fn main() anyerror!void { posix.exit(1); } } - const enable_xwayland = !result.flags.@"no-xwayland"; + const runtime_xwayland = !result.flags.@"no-xwayland"; const startup_command = blk: { if (result.flags.c) |command| { break :blk try util.gpa.dupeZ(u8, command); @@ -95,17 +95,25 @@ pub fn main() anyerror!void { log.info("river version {s}, initializing server", .{build_options.version}); - process.setup(); - river_init_wlroots_log(switch (runtime_log_level) { .debug => .debug, .info => .info, .warn, .err => .err, }); - try server.init(enable_xwayland); + try server.init(runtime_xwayland); defer server.deinit(); + // wlroots starts the Xwayland process from an idle event source, the reasoning being that + // this gives the compositor time to set up event listeners before Xwayland is actually + // started. We want Xwayland to be started by wlroots before we modify our rlimits in + // process.setup() since wlroots does not offer a way for us to reset the rlimit post-fork. + if (build_options.xwayland and runtime_xwayland) { + server.wl_server.getEventLoop().dispatchIdle(); + } + + process.setup(); + try server.start(); // Run the child in a new process group so that we can send SIGTERM to all From 933701d7f9cee4711368bd3cc8e65426bdc85b89 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Fri, 7 Mar 2025 12:37:11 +0100 Subject: [PATCH 71/90] build: update to zig 0.14.0 --- .builds/alpine.yml | 8 ++++---- .builds/archlinux.yml | 8 ++++---- .builds/freebsd.yml | 8 ++++---- README.md | 2 +- build.zig | 27 ++++++++++----------------- build.zig.zon | 27 ++++++++++++++------------- common/flags.zig | 6 +++--- river/Cursor.zig | 7 +++---- river/IdleInhibitManager.zig | 4 ++-- river/IdleInhibitor.zig | 2 +- river/InputConfig.zig | 14 +++++++------- river/InputManager.zig | 4 ++-- river/Keyboard.zig | 2 +- river/KeyboardGroup.zig | 4 ++-- river/Layout.zig | 4 ++-- river/Output.zig | 5 ++--- river/Seat.zig | 2 +- river/Server.zig | 4 ++-- river/View.zig | 3 +-- river/XwaylandView.zig | 2 +- river/command/map.zig | 2 +- river/command/rule.zig | 3 ++- river/process.zig | 4 ++-- river/rule_list.zig | 7 ++++++- riverctl/main.zig | 4 ++-- rivertile/main.zig | 10 +++++----- 26 files changed, 85 insertions(+), 88 deletions(-) diff --git a/.builds/alpine.yml b/.builds/alpine.yml index 1014c77..1b60fc3 100644 --- a/.builds/alpine.yml +++ b/.builds/alpine.yml @@ -43,10 +43,10 @@ tasks: cd .. # Eat Github's resources rather than the Zig Software Foundation's resources! - wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/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 + wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/download/0.14.0/zig-linux-x86_64-0.14.0.tar.xz + tar xf zig-linux-x86_64-0.14.0.tar.xz + sudo mv zig-linux-x86_64-0.14.0/zig /usr/bin/ + sudo mv zig-linux-x86_64-0.14.0/lib /usr/lib/zig - build: | cd river zig build --summary all diff --git a/.builds/archlinux.yml b/.builds/archlinux.yml index 44bf5e0..dcae5d2 100644 --- a/.builds/archlinux.yml +++ b/.builds/archlinux.yml @@ -41,10 +41,10 @@ tasks: cd .. # Eat Github's resources rather than the Zig Software Foundation's resources! - wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/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 + wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/download/0.14.0/zig-linux-x86_64-0.14.0.tar.xz + tar xf zig-linux-x86_64-0.14.0.tar.xz + sudo mv zig-linux-x86_64-0.14.0/zig /usr/bin/ + sudo mv zig-linux-x86_64-0.14.0/lib /usr/lib/zig - build: | cd river zig build --summary all diff --git a/.builds/freebsd.yml b/.builds/freebsd.yml index 2928661..0f080d4 100644 --- a/.builds/freebsd.yml +++ b/.builds/freebsd.yml @@ -46,10 +46,10 @@ tasks: cd .. # Eat Github's resources rather than the Zig Software Foundation's resources! - wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/download/0.13.0/zig-freebsd-x86_64-0.13.0.tar.xz - tar xf zig-freebsd-x86_64-0.13.0.tar.xz - sudo mv zig-freebsd-x86_64-0.13.0/zig /usr/bin/ - sudo mv zig-freebsd-x86_64-0.13.0/lib /usr/lib/zig + wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/download/0.14.0/zig-freebsd-x86_64-0.14.0-unofficial.tar.xz + tar xf zig-freebsd-x86_64-0.14.0-unofficial.tar.xz + sudo mv zig-freebsd-x86_64-0.14.0-unofficial/zig /usr/bin/ + sudo mv zig-freebsd-x86_64-0.14.0-unofficial/lib /usr/lib/zig - build: | cd river zig build --summary all diff --git a/README.md b/README.md index f156566..f4681e3 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.13 +- [zig](https://ziglang.org/download/) 0.14 - wayland - wayland-protocols - [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 0.18 diff --git a/build.zig b/build.zig index f7468bb..585d7f5 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("zig-wayland").Scanner; +const Scanner = @import("wayland").Scanner; /// While a river release is in development, this string should contain the version in development /// with the "-dev" suffix. @@ -71,7 +71,7 @@ pub fn build(b: *Build) !void { .Inherit, ) catch break :blk version; - var it = mem.split(u8, mem.trim(u8, git_describe_long, &std.ascii.whitespace), "-"); + var it = mem.splitScalar(u8, mem.trim(u8, git_describe_long, &std.ascii.whitespace), '-'); _ = it.next().?; // previous tag const commit_count = it.next().?; const commit_hash = it.next().?; @@ -100,11 +100,11 @@ pub fn build(b: *Build) !void { scanner.addSystemProtocol("unstable/pointer-gestures/pointer-gestures-unstable-v1.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"); - scanner.addCustomProtocol("protocol/river-layout-v3.xml"); - scanner.addCustomProtocol("protocol/wlr-layer-shell-unstable-v1.xml"); - scanner.addCustomProtocol("protocol/wlr-output-power-management-unstable-v1.xml"); + scanner.addCustomProtocol(b.path("protocol/river-control-unstable-v1.xml")); + scanner.addCustomProtocol(b.path("protocol/river-status-unstable-v1.xml")); + scanner.addCustomProtocol(b.path("protocol/river-layout-v3.xml")); + scanner.addCustomProtocol(b.path("protocol/wlr-layer-shell-unstable-v1.xml")); + scanner.addCustomProtocol(b.path("protocol/wlr-output-power-management-unstable-v1.xml")); // Some of these versions may be out of date with what wlroots implements. // This is not a problem in practice though as long as river successfully compiles. @@ -136,10 +136,10 @@ pub fn build(b: *Build) !void { const wayland = b.createModule(.{ .root_source_file = scanner.result }); - const xkbcommon = b.dependency("zig-xkbcommon", .{}).module("xkbcommon"); - const pixman = b.dependency("zig-pixman", .{}).module("pixman"); + const xkbcommon = b.dependency("xkbcommon", .{}).module("xkbcommon"); + const pixman = b.dependency("pixman", .{}).module("pixman"); - const wlroots = b.dependency("zig-wlroots", .{}).module("wlroots"); + const wlroots = b.dependency("wlroots", .{}).module("wlroots"); wlroots.addImport("wayland", wayland); wlroots.addImport("xkbcommon", xkbcommon); wlroots.addImport("pixman", pixman); @@ -185,9 +185,6 @@ pub fn build(b: *Build) !void { .flags = &.{ "-std=c99", "-O2" }, }); - // TODO: remove when zig issue #131 is implemented - scanner.addCSource(river); - river.pie = pie; river.root_module.omit_frame_pointer = omit_frame_pointer; @@ -211,8 +208,6 @@ pub fn build(b: *Build) !void { riverctl.linkLibC(); riverctl.linkSystemLibrary("wayland-client"); - scanner.addCSource(riverctl); - riverctl.pie = pie; riverctl.root_module.omit_frame_pointer = omit_frame_pointer; @@ -236,8 +231,6 @@ pub fn build(b: *Build) !void { rivertile.linkLibC(); rivertile.linkSystemLibrary("wayland-client"); - scanner.addCSource(rivertile); - rivertile.pie = pie; rivertile.root_module.omit_frame_pointer = omit_frame_pointer; diff --git a/build.zig.zon b/build.zig.zon index b0f01ed..fb084dc 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,23 +1,24 @@ .{ - .name = "river", + .name = .river, .version = "0.3.8-dev", .paths = .{""}, .dependencies = .{ - .@"zig-pixman" = .{ - .url = "https://codeberg.org/ifreund/zig-pixman/archive/v0.2.0.tar.gz", - .hash = "12209db20ce873af176138b76632931def33a10539387cba745db72933c43d274d56", + .pixman = .{ + .url = "https://codeberg.org/ifreund/zig-pixman/archive/v0.3.0.tar.gz", + .hash = "pixman-0.3.0-LClMnz2VAAAs7QSCGwLimV5VUYx0JFnX5xWU6HwtMuDX", }, - .@"zig-wayland" = .{ - .url = "https://codeberg.org/ifreund/zig-wayland/archive/v0.2.0.tar.gz", - .hash = "1220687c8c47a48ba285d26a05600f8700d37fc637e223ced3aa8324f3650bf52242", + .wayland = .{ + .url = "https://codeberg.org/ifreund/zig-wayland/archive/v0.3.0.tar.gz", + .hash = "wayland-0.3.0-lQa1kjPIAQDmhGYpY-zxiRzQJFHQ2VqhJkQLbKKdt5wl", }, - .@"zig-wlroots" = .{ - .url = "https://codeberg.org/ifreund/zig-wlroots/archive/v0.18.1.tar.gz", - .hash = "122083317b028705b5d27be12976feebf17066a4e51802b3b5e9f970bec580e433e1", + .wlroots = .{ + .url = "https://codeberg.org/ifreund/zig-wlroots/archive/v0.18.2.tar.gz", + .hash = "wlroots-0.18.2-jmOlchnIAwBq45_cxU1V3OWErxxJjQZlc9PyJfR-l3uk", }, - .@"zig-xkbcommon" = .{ - .url = "https://codeberg.org/ifreund/zig-xkbcommon/archive/v0.2.0.tar.gz", - .hash = "1220c90b2228d65fd8427a837d31b0add83e9fade1dcfa539bb56fd06f1f8461605f", + .xkbcommon = .{ + .url = "https://codeberg.org/ifreund/zig-xkbcommon/archive/v0.3.0.tar.gz", + .hash = "xkbcommon-0.3.0-VDqIe3K9AQB2fG5ZeRcMC9i7kfrp5m2rWgLrmdNn9azr", }, }, + .fingerprint = 0xf5e3672b8e8d6efc, } diff --git a/common/flags.zig b/common/flags.zig index 5b7b552..79adde9 100644 --- a/common/flags.zig +++ b/common/flags.zig @@ -42,21 +42,21 @@ pub fn parser(comptime Arg: type, comptime flags: []const Flag) type { .boolean => .{ .name = flag.name, .type = bool, - .default_value = &false, + .default_value_ptr = &false, .is_comptime = false, .alignment = @alignOf(bool), }, .arg => .{ .name = flag.name, .type = ?[:0]const u8, - .default_value = &@as(?[:0]const u8, null), + .default_value_ptr = &@as(?[:0]const u8, null), .is_comptime = false, .alignment = @alignOf(?[:0]const u8), }, }; fields = fields ++ [_]std.builtin.Type.StructField{field}; } - break :flags_type @Type(.{ .Struct = .{ + break :flags_type @Type(.{ .@"struct" = .{ .layout = .auto, .fields = fields, .decls = &.{}, diff --git a/river/Cursor.zig b/river/Cursor.zig index bb6334f..b2ad694 100644 --- a/river/Cursor.zig +++ b/river/Cursor.zig @@ -1089,13 +1089,12 @@ pub fn updateState(cursor: *Cursor) void { .passthrough => { cursor.updateFocusFollowsCursorTarget(); if (!cursor.hidden) { - var now: posix.timespec = undefined; - posix.clock_gettime(posix.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported"); + const now = posix.clock_gettime(.MONOTONIC) catch @panic("CLOCK_MONOTONIC not supported"); // 2^32-1 milliseconds is ~50 days, which is a realistic uptime. // This means that we must wrap if the monotonic time is greater than // 2^32-1 milliseconds and hope that clients don't get too confused. const msec: u32 = @intCast(@rem( - now.tv_sec *% std.time.ms_per_s +% @divTrunc(now.tv_nsec, std.time.ns_per_ms), + now.sec *% std.time.ms_per_s +% @divTrunc(now.nsec, std.time.ns_per_ms), math.maxInt(u32), )); cursor.passthrough(msec); @@ -1216,7 +1215,7 @@ fn warp(cursor: *Cursor) void { }; if (!output_layout_box.containsPoint(cursor.wlr_cursor.x, cursor.wlr_cursor.y) or (usable_layout_box.containsPoint(cursor.wlr_cursor.x, cursor.wlr_cursor.y) and - !target_box.containsPoint(cursor.wlr_cursor.x, cursor.wlr_cursor.y))) + !target_box.containsPoint(cursor.wlr_cursor.x, cursor.wlr_cursor.y))) { const lx: f64 = @floatFromInt(target_box.x + @divTrunc(target_box.width, 2)); const ly: f64 = @floatFromInt(target_box.y + @divTrunc(target_box.height, 2)); diff --git a/river/IdleInhibitManager.zig b/river/IdleInhibitManager.zig index 475d833..46b3bc6 100644 --- a/river/IdleInhibitManager.zig +++ b/river/IdleInhibitManager.zig @@ -30,7 +30,7 @@ const View = @import("View.zig"); wlr_manager: *wlr.IdleInhibitManagerV1, new_idle_inhibitor: wl.Listener(*wlr.IdleInhibitorV1) = wl.Listener(*wlr.IdleInhibitorV1).init(handleNewIdleInhibitor), -inhibitors: std.TailQueue(IdleInhibitor) = .{}, +inhibitors: std.DoublyLinkedList(IdleInhibitor) = .{}, pub fn init(inhibit_manager: *IdleInhibitManager) !void { inhibit_manager.* = .{ @@ -79,7 +79,7 @@ pub fn checkActive(inhibit_manager: *IdleInhibitManager) void { fn handleNewIdleInhibitor(listener: *wl.Listener(*wlr.IdleInhibitorV1), inhibitor: *wlr.IdleInhibitorV1) void { const inhibit_manager: *IdleInhibitManager = @fieldParentPtr("new_idle_inhibitor", listener); - const inhibitor_node = util.gpa.create(std.TailQueue(IdleInhibitor).Node) catch return; + const inhibitor_node = util.gpa.create(std.DoublyLinkedList(IdleInhibitor).Node) catch return; inhibitor_node.data.init(inhibitor, inhibit_manager) catch { util.gpa.destroy(inhibitor_node); return; diff --git a/river/IdleInhibitor.zig b/river/IdleInhibitor.zig index 4babaa3..2b45786 100644 --- a/river/IdleInhibitor.zig +++ b/river/IdleInhibitor.zig @@ -49,7 +49,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { inhibitor.destroy.link.remove(); - const node: *std.TailQueue(IdleInhibitor).Node = @fieldParentPtr("data", inhibitor); + const node: *std.DoublyLinkedList(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 40abf3c..c8a94bb 100644 --- a/river/InputConfig.zig +++ b/river/InputConfig.zig @@ -307,7 +307,7 @@ pub fn apply(config: *const InputConfig, device: *InputDevice) void { const libinput_device: *c.libinput_device = @ptrCast(device.wlr_device.getLibinputDevice() orelse return); log.debug("applying input configuration '{s}' to device '{s}'.", .{ config.glob, device.identifier }); - inline for (@typeInfo(InputConfig).Struct.fields) |field| { + inline for (@typeInfo(InputConfig).@"struct".fields) |field| { if (comptime mem.eql(u8, field.name, "glob")) continue; if (@field(config, field.name)) |setting| { @@ -324,7 +324,7 @@ pub fn apply(config: *const InputConfig, device: *InputDevice) void { } pub fn parse(config: *InputConfig, setting: []const u8, value: []const u8) !void { - inline for (@typeInfo(InputConfig).Struct.fields) |field| { + inline for (@typeInfo(InputConfig).@"struct".fields) |field| { if (comptime mem.eql(u8, field.name, "glob")) continue; if (mem.eql(u8, setting, field.name)) { @@ -358,8 +358,8 @@ pub fn parse(config: *InputConfig, setting: []const u8, value: []const u8) !void } config.@"map-to-output" = .{ .output_name = output_name_owned }; } else { - const T = @typeInfo(field.type).Optional.child; - if (@typeInfo(T) != .Enum) { + const T = @typeInfo(field.type).optional.child; + if (@typeInfo(T) != .@"enum") { @compileError("You forgot to implement parsing for an input configuration setting."); } @field(config, field.name) = meta.stringToEnum(T, value) orelse @@ -376,7 +376,7 @@ pub fn parse(config: *InputConfig, setting: []const u8, value: []const u8) !void pub fn write(config: *InputConfig, writer: anytype) !void { try writer.print("{s}\n", .{config.glob}); - inline for (@typeInfo(InputConfig).Struct.fields) |field| { + inline for (@typeInfo(InputConfig).@"struct".fields) |field| { if (comptime mem.eql(u8, field.name, "glob")) continue; if (comptime mem.eql(u8, field.name, "map-to-output")) { @@ -396,8 +396,8 @@ pub fn write(config: *InputConfig, writer: anytype) !void { mem.sliceTo(c.libevdev_event_code_get_name(c.EV_KEY, setting.button), 0), }); } else { - const T = @typeInfo(field.type).Optional.child; - if (@typeInfo(T) != .Enum) { + const T = @typeInfo(field.type).optional.child; + if (@typeInfo(T) != .@"enum") { @compileError("You forgot to implement listing for an input configuration setting."); } try writer.print("\t{s}: {s}\n", .{ field.name, @tagName(setting) }); diff --git a/river/InputManager.zig b/river/InputManager.zig index 6368c63..b851360 100644 --- a/river/InputManager.zig +++ b/river/InputManager.zig @@ -58,7 +58,7 @@ tablet_manager: *wlr.TabletManagerV2, configs: std.ArrayList(InputConfig), devices: wl.list.Head(InputDevice, .link), -seats: std.TailQueue(Seat) = .{}, +seats: std.DoublyLinkedList(Seat) = .{}, exclusive_client: ?*wl.Client = null, @@ -74,7 +74,7 @@ new_text_input: wl.Listener(*wlr.TextInputV3) = wl.Listener(*wlr.TextInputV3).init(handleNewTextInput), pub fn init(input_manager: *InputManager) !void { - const seat_node = try util.gpa.create(std.TailQueue(Seat).Node); + const seat_node = try util.gpa.create(std.DoublyLinkedList(Seat).Node); errdefer util.gpa.destroy(seat_node); input_manager.* = .{ diff --git a/river/Keyboard.zig b/river/Keyboard.zig index 3c659d8..1bb0b68 100644 --- a/river/Keyboard.zig +++ b/river/Keyboard.zig @@ -54,7 +54,7 @@ pub const Pressed = struct { // Furthermore, wlroots will continue to forward key press/release events to river if more // than 32 keys are pressed. Therefore river chooses to ignore keypresses that would take // the keyboard beyond 32 simultaneously pressed keys. - assert(capacity == @typeInfo(std.meta.fieldInfo(wlr.Keyboard, .keycodes).type).Array.len); + assert(capacity == @typeInfo(std.meta.fieldInfo(wlr.Keyboard, .keycodes).type).array.len); } keys: std.BoundedArray(Key, capacity) = .{}, diff --git a/river/KeyboardGroup.zig b/river/KeyboardGroup.zig index 5f79608..c53063e 100644 --- a/river/KeyboardGroup.zig +++ b/river/KeyboardGroup.zig @@ -41,7 +41,7 @@ globs: std.ArrayListUnmanaged([]const u8) = .{}, pub fn create(seat: *Seat, name: []const u8) !void { log.debug("new keyboard group: '{s}'", .{name}); - const node = try util.gpa.create(std.TailQueue(KeyboardGroup).Node); + const node = try util.gpa.create(std.DoublyLinkedList(KeyboardGroup).Node); errdefer util.gpa.destroy(node); const wlr_group = try wlr.KeyboardGroup.create(); @@ -72,7 +72,7 @@ pub fn destroy(group: *KeyboardGroup) void { group.wlr_group.destroy(); - const node: *std.TailQueue(KeyboardGroup).Node = @fieldParentPtr("data", group); + const node: *std.DoublyLinkedList(KeyboardGroup).Node = @fieldParentPtr("data", group); group.seat.keyboard_groups.remove(node); util.gpa.destroy(node); } diff --git a/river/Layout.zig b/river/Layout.zig index 858cd08..54a0de9 100644 --- a/river/Layout.zig +++ b/river/Layout.zig @@ -47,7 +47,7 @@ pub fn create(client: *wl.Client, version: u32, id: u32, output: *Output, namesp return; } - const node = try util.gpa.create(std.TailQueue(Layout).Node); + const node = try util.gpa.create(std.DoublyLinkedList(Layout).Node); errdefer util.gpa.destroy(node); node.data = .{ .layout_v3 = layout_v3, @@ -186,7 +186,7 @@ pub fn destroy(layout: *Layout) void { ); // Remove layout from the list - const node: *std.TailQueue(Layout).Node = @fieldParentPtr("data", layout); + const node: *std.DoublyLinkedList(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/Output.zig b/river/Output.zig index 34e49dd..769bb4c 100644 --- a/river/Output.zig +++ b/river/Output.zig @@ -171,7 +171,7 @@ previous_tags: u32 = 1 << 0, attach_mode: ?Config.AttachMode = null, /// List of all layouts -layouts: std.TailQueue(Layout) = .{}, +layouts: std.DoublyLinkedList(Layout) = .{}, /// The current layout namespace of the output. If null, /// config.default_layout_namespace should be used instead. @@ -536,8 +536,7 @@ 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: posix.timespec = undefined; - posix.clock_gettime(posix.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported"); + var now = posix.clock_gettime(.MONOTONIC) catch @panic("CLOCK_MONOTONIC not supported"); scene_output.sendFrameDone(&now); } diff --git a/river/Seat.zig b/river/Seat.zig index bb8e827..b9b76d0 100644 --- a/river/Seat.zig +++ b/river/Seat.zig @@ -84,7 +84,7 @@ mapping_repeat_timer: *wl.EventSource, /// Currently repeating mapping, if any repeating_mapping: ?*const Mapping = null, -keyboard_groups: std.TailQueue(KeyboardGroup) = .{}, +keyboard_groups: std.DoublyLinkedList(KeyboardGroup) = .{}, /// Currently focused output. Null only when there are no outputs at all. focused_output: ?*Output = null, diff --git a/river/Server.zig b/river/Server.zig index 027e777..401689a 100644 --- a/river/Server.zig +++ b/river/Server.zig @@ -303,8 +303,8 @@ fn allowlist(server: *Server, global: *const wl.Global) bool { // For other globals I like the current pointer comparison approach as it // should catch river accidentally exposing multiple copies of e.g. wl_shm // with an assertion failure. - return global.getInterface() == wl.Output.getInterface() or - global.getInterface() == wl.Seat.getInterface() or + return global.getInterface() == wl.Output.interface or + global.getInterface() == wl.Seat.interface or global == server.shm.global or global == server.single_pixel_buffer_manager.global or global == server.viewporter.global or diff --git a/river/View.zig b/river/View.zig index 2199f85..3d57ca4 100644 --- a/river/View.zig +++ b/river/View.zig @@ -482,8 +482,7 @@ pub fn rootSurface(view: View) ?*wlr.Surface { pub fn sendFrameDone(view: View) void { assert(view.mapped and !view.destroying); - var now: posix.timespec = undefined; - posix.clock_gettime(posix.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported"); + const now = posix.clock_gettime(.MONOTONIC) catch @panic("CLOCK_MONOTONIC not supported"); view.rootSurface().?.sendFrameDone(&now); } diff --git a/river/XwaylandView.zig b/river/XwaylandView.zig index db91199..f7c7578 100644 --- a/river/XwaylandView.zig +++ b/river/XwaylandView.zig @@ -100,7 +100,7 @@ pub fn configure(xwayland_view: XwaylandView) bool { xwayland_view.xwayland_surface.height == inflight.box.height and (inflight.focus != 0) == (current.focus != 0) and (output.inflight.fullscreen == xwayland_view.view) == - (current.output != null and current.output.?.current.fullscreen == xwayland_view.view)) + (current.output != null and current.output.?.current.fullscreen == xwayland_view.view)) { return false; } diff --git a/river/command/map.zig b/river/command/map.zig index e8ded57..1ecc124 100644 --- a/river/command/map.zig +++ b/river/command/map.zig @@ -285,7 +285,7 @@ fn parseKeysym(name: [:0]const u8, out: *?[]const u8) !xkb.Keysym { } fn parseModifiers(modifiers_str: []const u8, out: *?[]const u8) !wlr.Keyboard.ModifierMask { - var it = mem.split(u8, modifiers_str, "+"); + var it = mem.splitScalar(u8, modifiers_str, '+'); var modifiers = wlr.Keyboard.ModifierMask{}; outer: while (it.next()) |mod_name| { if (mem.eql(u8, mod_name, "None")) continue; diff --git a/river/command/rule.zig b/river/command/rule.zig index 5b64400..dfbdb73 100644 --- a/river/command/rule.zig +++ b/river/command/rule.zig @@ -26,6 +26,7 @@ const util = @import("../util.zig"); const Error = @import("../command.zig").Error; const Seat = @import("../Seat.zig"); const View = @import("../View.zig"); +const RuleGlobs = @import("../rule_list.zig").RuleGlobs; const Action = enum { float, @@ -157,7 +158,7 @@ pub fn ruleDel(_: *Seat, args: []const [:0]const u8, _: *?[]const u8) Error!void const action = std.meta.stringToEnum(Action, result.args[0]) orelse return Error.UnknownOption; - const rule = .{ + const rule: RuleGlobs = .{ .app_id_glob = result.flags.@"app-id" orelse "*", .title_glob = result.flags.title orelse "*", }; diff --git a/river/process.zig b/river/process.zig index c83f61f..fb160e9 100644 --- a/river/process.zig +++ b/river/process.zig @@ -29,7 +29,7 @@ pub fn setup() void { .mask = posix.empty_sigset, .flags = 0, }; - posix.sigaction(posix.SIG.PIPE, &sig_ign, null) catch unreachable; + posix.sigaction(posix.SIG.PIPE, &sig_ign, null); // 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 @@ -68,7 +68,7 @@ pub fn cleanupChild() void { .mask = posix.empty_sigset, .flags = 0, }; - posix.sigaction(posix.SIG.PIPE, &sig_dfl, null) catch unreachable; + posix.sigaction(posix.SIG.PIPE, &sig_dfl, null); if (original_rlimit) |original| { posix.setrlimit(.NOFILE, original) catch { diff --git a/river/rule_list.zig b/river/rule_list.zig index 1d0a6fb..8c5edd3 100644 --- a/river/rule_list.zig +++ b/river/rule_list.zig @@ -23,6 +23,11 @@ const util = @import("util.zig"); const View = @import("View.zig"); +pub const RuleGlobs = struct { + app_id_glob: []const u8, + title_glob: []const u8, +}; + pub const MaxGlobLen = struct { app_id: usize, title: usize, @@ -83,7 +88,7 @@ pub fn RuleList(comptime T: type) type { }); } - pub fn del(list: *List, rule: struct { app_id_glob: []const u8, title_glob: []const u8 }) ?T { + pub fn del(list: *List, rule: RuleGlobs) ?T { for (list.rules.items, 0..) |existing, i| { if (mem.eql(u8, rule.app_id_glob, existing.app_id_glob) and mem.eql(u8, rule.title_glob, existing.title_glob)) diff --git a/riverctl/main.zig b/riverctl/main.zig index 13a36ae..06d083b 100644 --- a/riverctl/main.zig +++ b/riverctl/main.zig @@ -110,10 +110,10 @@ fn _main() !void { fn registryListener(registry: *wl.Registry, event: wl.Registry.Event, globals: *Globals) void { switch (event) { .global => |global| { - if (mem.orderZ(u8, global.interface, wl.Seat.getInterface().name) == .eq) { + if (mem.orderZ(u8, global.interface, wl.Seat.interface.name) == .eq) { assert(globals.seat == null); // TODO: support multiple seats globals.seat = registry.bind(global.name, wl.Seat, 1) catch @panic("out of memory"); - } else if (mem.orderZ(u8, global.interface, zriver.ControlV1.getInterface().name) == .eq) { + } else if (mem.orderZ(u8, global.interface, zriver.ControlV1.interface.name) == .eq) { globals.control = registry.bind(global.name, zriver.ControlV1, 1) catch @panic("out of memory"); } }, diff --git a/rivertile/main.zig b/rivertile/main.zig index 2590e7e..e4e11ee 100644 --- a/rivertile/main.zig +++ b/rivertile/main.zig @@ -91,12 +91,12 @@ const gpa = std.heap.c_allocator; const Context = struct { initialized: bool = false, layout_manager: ?*river.LayoutManagerV3 = null, - outputs: std.TailQueue(Output) = .{}, + outputs: std.DoublyLinkedList(Output) = .{}, fn addOutput(context: *Context, registry: *wl.Registry, name: u32) !void { const wl_output = try registry.bind(name, wl.Output, 3); errdefer wl_output.release(); - const node = try gpa.create(std.TailQueue(Output).Node); + const node = try gpa.create(std.DoublyLinkedList(Output).Node); errdefer gpa.destroy(node); try node.data.init(context, wl_output, name); context.outputs.append(node); @@ -140,7 +140,7 @@ const Output = struct { .namespace_in_use => fatal("namespace 'rivertile' already in use.", .{}), .user_command => |ev| { - var it = mem.tokenize(u8, mem.span(ev.command), " "); + var it = mem.tokenizeScalar(u8, mem.span(ev.command), ' '); const raw_cmd = it.next() orelse { std.log.err("not enough arguments", .{}); return; @@ -382,9 +382,9 @@ pub fn main() !void { fn registryListener(registry: *wl.Registry, event: wl.Registry.Event, context: *Context) void { switch (event) { .global => |global| { - if (mem.orderZ(u8, global.interface, river.LayoutManagerV3.getInterface().name) == .eq) { + if (mem.orderZ(u8, global.interface, river.LayoutManagerV3.interface.name) == .eq) { context.layout_manager = registry.bind(global.name, river.LayoutManagerV3, 1) catch return; - } else if (mem.orderZ(u8, global.interface, wl.Output.getInterface().name) == .eq) { + } else if (mem.orderZ(u8, global.interface, wl.Output.interface.name) == .eq) { context.addOutput(registry, global.name) catch |err| fatal("failed to bind output: {}", .{err}); } }, From 23ad9aa4126ff27ace6dc321ff01f77c953f15d0 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Fri, 7 Mar 2025 12:50:31 +0100 Subject: [PATCH 72/90] build: bump version to 0.3.8 --- build.zig.zon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig.zon b/build.zig.zon index fb084dc..b75c1da 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,6 @@ .{ .name = .river, - .version = "0.3.8-dev", + .version = "0.3.8", .paths = .{""}, .dependencies = .{ .pixman = .{ From 00ab4910e01c5d92104826ff4e01e5a9486500a0 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Fri, 7 Mar 2025 12:52:50 +0100 Subject: [PATCH 73/90] build: bump version to 0.3.9-dev --- build.zig.zon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig.zon b/build.zig.zon index b75c1da..e2ccaf0 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,6 @@ .{ .name = .river, - .version = "0.3.8", + .version = "0.3.9-dev", .paths = .{""}, .dependencies = .{ .pixman = .{ From 8f4a746da0317d557b2b5e530bf73da969649e18 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 10 Mar 2025 07:53:19 +0100 Subject: [PATCH 74/90] security-context: fix assertion failure This regression was caused by turning my brain off a bit too much during the zig 0.14 upgrade. --- river/Server.zig | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/river/Server.zig b/river/Server.zig index 401689a..ea06842 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 mem = std.mem; const posix = std.posix; const wlr = @import("wlroots"); const wl = @import("wayland").server.wl; @@ -299,13 +300,16 @@ fn allowlist(server: *Server, global: *const wl.Global) bool { // such as wl_output and wl_seat since the wl_global_create() function will // advertise the global to clients and invoke this filter before returning // the new global pointer. - // + if ((mem.orderZ(u8, global.getInterface().name, "wl_output") == .eq) or + (mem.orderZ(u8, global.getInterface().name, "wl_seat") == .eq)) + { + return true; + } + // For other globals I like the current pointer comparison approach as it // should catch river accidentally exposing multiple copies of e.g. wl_shm // with an assertion failure. - return global.getInterface() == wl.Output.interface or - global.getInterface() == wl.Seat.interface or - global == server.shm.global or + return global == server.shm.global or global == server.single_pixel_buffer_manager.global or global == server.viewporter.global or global == server.fractional_scale_manager.global or From 60f954c2b076a4670432167c51f43d2cdd361e7d Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 10 Mar 2025 08:17:17 +0100 Subject: [PATCH 75/90] build: eliminate duplicate version string There is now a single source of truth for river's version. It is no longer possible for the versions in build.zig and build.zig.zon to get out of sync as build.zig now parses the version from build.zig.zon. --- build.zig | 34 ++++++++++++++++++++++++++++------ build.zig.zon | 5 +++++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/build.zig b/build.zig index 585d7f5..8bdd5ce 100644 --- a/build.zig +++ b/build.zig @@ -6,12 +6,6 @@ const mem = std.mem; const Scanner = @import("wayland").Scanner; -/// While a river release is in development, this string should contain the version in development -/// with the "-dev" suffix. -/// When a release is tagged, the "-dev" suffix should be removed for the commit that gets tagged. -/// Directly after the tagged commit, the version should be bumped and the "-dev" suffix added. -const version = "0.3.8-dev"; - pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); @@ -291,3 +285,31 @@ pub fn build(b: *Build) !void { test_step.dependOn(&run_globber_test.step); } } + +const version = manifest.version; +/// Getting rid of this wart requires upstream zig improvements. +/// See: https://github.com/ziglang/zig/issues/22775 +const manifest: struct { + name: @Type(.enum_literal), + version: []const u8, + paths: []const []const u8, + dependencies: struct { + pixman: struct { + url: []const u8, + hash: []const u8, + }, + wayland: struct { + url: []const u8, + hash: []const u8, + }, + wlroots: struct { + url: []const u8, + hash: []const u8, + }, + xkbcommon: struct { + url: []const u8, + hash: []const u8, + }, + }, + fingerprint: u64, +} = @import("build.zig.zon"); diff --git a/build.zig.zon b/build.zig.zon index e2ccaf0..6d5cf21 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,5 +1,10 @@ .{ .name = .river, + // While a river release is in development, this string should contain + // the version in development with the "-dev" suffix. + // When a release is tagged, the "-dev" suffix should be removed for the + // commit that gets tagged. Directly after the tagged commit, the version + // should be bumped and the "-dev" suffix added. .version = "0.3.9-dev", .paths = .{""}, .dependencies = .{ From bdc3c0ccf9a411de24d0bce7dc591517f75521fc Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 10 Mar 2025 08:20:10 +0100 Subject: [PATCH 76/90] build: bump version to 0.3.9 --- build.zig.zon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig.zon b/build.zig.zon index 6d5cf21..7ba4bbf 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -5,7 +5,7 @@ // When a release is tagged, the "-dev" suffix should be removed for the // commit that gets tagged. Directly after the tagged commit, the version // should be bumped and the "-dev" suffix added. - .version = "0.3.9-dev", + .version = "0.3.9", .paths = .{""}, .dependencies = .{ .pixman = .{ From f1904d4e6fa55f4381fc1e4379de0bc3e4e8b6d9 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sun, 16 Mar 2025 12:14:07 +0100 Subject: [PATCH 77/90] build: bump version to 0.3.10-dev --- build.zig.zon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig.zon b/build.zig.zon index 7ba4bbf..93d5d22 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -5,7 +5,7 @@ // When a release is tagged, the "-dev" suffix should be removed for the // commit that gets tagged. Directly after the tagged commit, the version // should be bumped and the "-dev" suffix added. - .version = "0.3.9", + .version = "0.3.10-dev", .paths = .{""}, .dependencies = .{ .pixman = .{ From f482b9ddaa203b395a6a52a3437c02a10b0198ca Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sun, 16 Mar 2025 13:37:57 +0100 Subject: [PATCH 78/90] Cursor: restore previous image on unhide If client A has an xdg_popup open and the user moves the cursor over a surface of client B and waits for the cursor to be hidden after a timeout, the cursor will not be shown on movement until the (invisible) cursor is moved back into a surface of client A or somewhere the compositor is responsible for rendering the cursor. This is due to the (flawed) xdg popup grab interface of wlroots which prevents wlr_seat_pointer_notify_enter() from sending events to clients other than the one with the active xdg popup. Closes: https://codeberg.org/river/river/issues/1192 --- river/Cursor.zig | 70 +++++++++++++++++++++++++++++++++++++----------- river/Server.zig | 2 +- 2 files changed, 56 insertions(+), 16 deletions(-) diff --git a/river/Cursor.zig b/river/Cursor.zig index b2ad694..4f2d148 100644 --- a/river/Cursor.zig +++ b/river/Cursor.zig @@ -108,6 +108,19 @@ const LayoutPoint = struct { ly: f64, }; +const Image = union(enum) { + /// No cursor image + none, + /// Name of the current Xcursor shape + xcursor: [*:0]const u8, + /// Cursor surface configured by a client + client: struct { + surface: *wlr.Surface, + hotspot_x: i32, + hotspot_y: i32, + }, +}; + const log = std.log.scoped(.cursor); /// Current cursor mode as well as any state needed to implement that mode @@ -124,9 +137,8 @@ wlr_cursor: *wlr.Cursor, /// Xcursor manager for the currently configured Xcursor theme. xcursor_manager: *wlr.XcursorManager, -/// Name of the current Xcursor shape, or null if a client has configured a -/// surface to be used as the cursor shape instead. -xcursor_name: ?[*:0]const u8 = null, +image: Image = .none, +image_surface_destroy: wl.Listener(*wlr.Surface) = .init(handleImageSurfaceDestroy), /// Number of distinct buttons currently pressed pressed_count: u32 = 0, @@ -286,18 +298,40 @@ pub fn setTheme(cursor: *Cursor, theme: ?[*:0]const u8, _size: ?u32) !void { cursor.xcursor_manager.destroy(); cursor.xcursor_manager = xcursor_manager; - if (cursor.xcursor_name) |name| { - cursor.setXcursor(name); + switch (cursor.image) { + .none, .client => {}, + .xcursor => |name| cursor.wlr_cursor.setXcursor(xcursor_manager, name), } } -pub fn setXcursor(cursor: *Cursor, name: [*:0]const u8) void { - cursor.wlr_cursor.setXcursor(cursor.xcursor_manager, name); - cursor.xcursor_name = name; +pub fn setImage(cursor: *Cursor, image: Image) void { + switch (cursor.image) { + .none, .xcursor => {}, + .client => { + cursor.image_surface_destroy.link.remove(); + }, + } + cursor.image = image; + switch (cursor.image) { + .none => cursor.wlr_cursor.unsetImage(), + .xcursor => |name| cursor.wlr_cursor.setXcursor(cursor.xcursor_manager, name), + .client => |client| { + cursor.wlr_cursor.setSurface(client.surface, client.hotspot_x, client.hotspot_y); + client.surface.events.destroy.add(&cursor.image_surface_destroy); + }, + } +} + +fn handleImageSurfaceDestroy(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { + const cursor: *Cursor = @fieldParentPtr("image_surface_destroy", listener); + // wlroots calls wlr_cursor_unset_image() automatically + // when the cursor surface is destroyed. + cursor.image = .none; + cursor.image_surface_destroy.link.remove(); } fn clearFocus(cursor: *Cursor) void { - cursor.setXcursor("default"); + cursor.setImage(.{ .xcursor = "default" }); cursor.seat.wlr_seat.pointerNotifyClearFocus(); } @@ -740,8 +774,15 @@ fn handleRequestSetCursor( // on the output that it's currently on and continue to do so as the // cursor moves between outputs. log.debug("focused client set cursor", .{}); - cursor.wlr_cursor.setSurface(event.surface, event.hotspot_x, event.hotspot_y); - cursor.xcursor_name = null; + if (event.surface) |surface| { + cursor.setImage(.{ .client = .{ + .surface = surface, + .hotspot_x = event.hotspot_x, + .hotspot_y = event.hotspot_y, + } }); + } else { + cursor.setImage(.none); + } } } @@ -757,8 +798,6 @@ pub fn hide(cursor: *Cursor) void { cursor.hidden = true; cursor.wlr_cursor.unsetImage(); - cursor.xcursor_name = null; - cursor.seat.wlr_seat.pointerNotifyClearFocus(); cursor.hide_cursor_timer.timerUpdate(0) catch { log.err("failed to update cursor hide timeout", .{}); }; @@ -770,6 +809,7 @@ pub fn unhide(cursor: *Cursor) void { }; if (!cursor.hidden) return; cursor.hidden = false; + cursor.setImage(cursor.image); cursor.updateState(); } @@ -868,7 +908,7 @@ fn computeEdges(cursor: *const Cursor, view: *const View) wlr.Edges { } } -fn enterMode(cursor: *Cursor, mode: Mode, view: *View, xcursor_name: [*:0]const u8) void { +fn enterMode(cursor: *Cursor, mode: Mode, view: *View, xcursor: [*:0]const u8) void { assert(cursor.mode == .passthrough or cursor.mode == .down); assert(mode == .move or mode == .resize); @@ -884,7 +924,7 @@ fn enterMode(cursor: *Cursor, mode: Mode, view: *View, xcursor_name: [*:0]const } cursor.seat.wlr_seat.pointerNotifyClearFocus(); - cursor.setXcursor(xcursor_name); + cursor.setImage(.{ .xcursor = xcursor }); server.root.applyPending(); } diff --git a/river/Server.zig b/river/Server.zig index ea06842..05bc96b 100644 --- a/river/Server.zig +++ b/river/Server.zig @@ -519,7 +519,7 @@ fn handleRequestSetCursorShape( // actually has pointer focus first. if (focused_client == event.seat_client) { const name = wlr.CursorShapeManagerV1.shapeName(event.shape); - seat.cursor.setXcursor(name); + seat.cursor.setImage(.{ .xcursor = name }); } } } From ecd2a396d36a7f0b7e11723c09b92402c34a02a7 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sat, 29 Mar 2025 10:54:29 +0100 Subject: [PATCH 79/90] Seat: put all keyboards in a single group Deprecate and ignore the riverctl commands for creating explicit keyboard groups. In my mind, the only reason to have more than one keyboard group is if different keyboard devices are assigned different keymaps or repeat rates. River does not currently allow such things to be configured however. When river eventually makes it possible to configure different keymaps and repeat rates per keyboard device, there is no reason we can't 100% automatically group keyboards based on the keymap/repeat rate. Exposing this keyboard group abstraction to the user is just bad UX. Failing to group keyboards automatically also creates confusing/buggy behavior for the user if the hardware, for example, exposes some of the the XF86 buttons on a laptop as a separate keyboard device from the main keyboard. Creating keybindings for these XF86 buttons that use modifiers doesn't work by default, but there's no reason it shouldn't just work. Closes: https://codeberg.org/river/river/issues/1138 (cherry picked from commit 46f77f30dcce06b7af0ec8dff5ae3e4fbc73176f) --- completions/bash/riverctl | 4 - completions/fish/riverctl.fish | 5 -- completions/zsh/_riverctl | 5 -- doc/riverctl.1.scd | 19 ----- river/Keyboard.zig | 13 +-- river/KeyboardGroup.zig | 141 ------------------------------- river/Seat.zig | 10 +-- river/command/keyboard_group.zig | 78 ++--------------- 8 files changed, 15 insertions(+), 260 deletions(-) delete mode 100644 river/KeyboardGroup.zig diff --git a/completions/bash/riverctl b/completions/bash/riverctl index a889d4c..891f13c 100644 --- a/completions/bash/riverctl +++ b/completions/bash/riverctl @@ -4,10 +4,6 @@ function __riverctl_completion () if [ "${COMP_CWORD}" -eq 1 ] then OPTS=" \ - keyboard-group-create \ - keyboard-group-destroy \ - keyboard-group-add \ - keyboard-group-remove \ keyboard-layout \ keyboard-layout-file \ close \ diff --git a/completions/fish/riverctl.fish b/completions/fish/riverctl.fish index 50458b4..70aceb7 100644 --- a/completions/fish/riverctl.fish +++ b/completions/fish/riverctl.fish @@ -72,11 +72,6 @@ complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'hide-cursor' complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'set-repeat' -d 'Set the keyboard repeat rate and repeat delay' complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'set-cursor-warp' -d 'Set the cursor warp mode' complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'xcursor-theme' -d 'Set the xcursor theme' -# Keyboardgroups -complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'keyboard-group-create' -d 'Create a keyboard group' -complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'keyboard-group-destroy' -d 'Destroy a keyboard group' -complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'keyboard-group-add' -d 'Add a keyboard to a keyboard group' -complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'keyboard-group-remove' -d 'Remove a keyboard from a keyboard group' complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'keyboard-layout' -d 'Set the keyboard layout' complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'keyboard-layout-file' -d 'Set the keyboard layout from a file.' diff --git a/completions/zsh/_riverctl b/completions/zsh/_riverctl index ad372d3..8bfd8f0 100644 --- a/completions/zsh/_riverctl +++ b/completions/zsh/_riverctl @@ -62,11 +62,6 @@ _riverctl_commands() 'set-repeat:Set the keyboard repeat rate and repeat delay' 'set-cursor-warp:Set the cursor warp mode.' 'xcursor-theme:Set the xcursor theme' - # Keyboard groups - 'keyboard-group-create:Create a keyboard group' - 'keyboard-group-destroy:Destroy a keyboard group' - 'keyboard-group-add:Add a keyboard to a keyboard group' - 'keyboard-group-remove:Remove a keyboard from a keyboard group' 'keyboard-layout:Set the keyboard layout' 'keyboard-layout-file:Set the keyboard layout from a file' # Input diff --git a/doc/riverctl.1.scd b/doc/riverctl.1.scd index d0476ea..9c1f223 100644 --- a/doc/riverctl.1.scd +++ b/doc/riverctl.1.scd @@ -454,25 +454,6 @@ matches everything while _\*\*_ and the empty string are invalid. following URL: https://xkbcommon.org/doc/current/keymap-text-format-v1.html -*keyboard-group-create* _group_name_ - Create a keyboard group. A keyboard group collects multiple keyboards in - a single logical keyboard. This means that all state, like the active - modifiers, is shared between the keyboards in a group. - -*keyboard-group-destroy* _group_name_ - Destroy the keyboard group with the given name. All attached keyboards - will be released, making them act as separate devices again. - -*keyboard-group-add* _group_name_ _input_device_name_ - Add a keyboard to a keyboard group, identified by the keyboard's - input device name. Any currently connected and future keyboards with - the given name will be added to the group. Simple globbing patterns are - supported, see the rules section for further information on globs. - -*keyboard-group-remove* _group_name_ _input_device_name_ - Remove a keyboard from a keyboard group, identified by the keyboard's - input device name. - The _input_ command can be used to create a configuration rule for an input device identified by its _name_. The _name_ of an input device consists of its type, its decimal vendor id, diff --git a/river/Keyboard.zig b/river/Keyboard.zig index 1bb0b68..a739f03 100644 --- a/river/Keyboard.zig +++ b/river/Keyboard.zig @@ -101,16 +101,9 @@ pub fn init(keyboard: *Keyboard, seat: *Seat, wlr_device: *wlr.InputDevice) !voi // wlroots will log a more detailed error if this fails. if (!wlr_keyboard.setKeymap(server.config.keymap)) return error.OutOfMemory; - // Add to keyboard-group, if applicable. - var group_it = seat.keyboard_groups.first; - outer: while (group_it) |group_node| : (group_it = group_node.next) { - for (group_node.data.globs.items) |glob| { - if (globber.match(glob, keyboard.device.identifier)) { - // wlroots will log an error if this fails explaining the reason. - _ = group_node.data.wlr_group.addKeyboard(wlr_keyboard); - break :outer; - } - } + if (wlr.KeyboardGroup.fromKeyboard(wlr_keyboard) == null) { + // wlroots will log an error on failure + _ = seat.keyboard_group.addKeyboard(wlr_keyboard); } wlr_keyboard.setRepeatInfo(server.config.repeat_rate, server.config.repeat_delay); diff --git a/river/KeyboardGroup.zig b/river/KeyboardGroup.zig deleted file mode 100644 index c53063e..0000000 --- a/river/KeyboardGroup.zig +++ /dev/null @@ -1,141 +0,0 @@ -// This file is part of river, a dynamic tiling wayland compositor. -// -// Copyright 2022 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, version 3. -// -// 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 KeyboardGroup = @This(); - -const std = @import("std"); -const assert = std.debug.assert; -const mem = std.mem; - -const globber = @import("globber"); -const wlr = @import("wlroots"); -const wl = @import("wayland").server.wl; -const xkb = @import("xkbcommon"); - -const log = std.log.scoped(.keyboard_group); - -const server = &@import("main.zig").server; -const util = @import("util.zig"); - -const Seat = @import("Seat.zig"); -const Keyboard = @import("Keyboard.zig"); - -seat: *Seat, -wlr_group: *wlr.KeyboardGroup, -name: []const u8, -globs: std.ArrayListUnmanaged([]const u8) = .{}, - -pub fn create(seat: *Seat, name: []const u8) !void { - log.debug("new keyboard group: '{s}'", .{name}); - - const node = try util.gpa.create(std.DoublyLinkedList(KeyboardGroup).Node); - errdefer util.gpa.destroy(node); - - const wlr_group = try wlr.KeyboardGroup.create(); - errdefer wlr_group.destroy(); - - const owned_name = try util.gpa.dupe(u8, name); - errdefer util.gpa.free(owned_name); - - node.data = .{ - .wlr_group = wlr_group, - .name = owned_name, - .seat = seat, - }; - - seat.addDevice(&wlr_group.keyboard.base); - seat.keyboard_groups.append(node); -} - -pub fn destroy(group: *KeyboardGroup) void { - log.debug("destroying keyboard group: '{s}'", .{group.name}); - - util.gpa.free(group.name); - - for (group.globs.items) |glob| { - util.gpa.free(glob); - } - group.globs.deinit(util.gpa); - - group.wlr_group.destroy(); - - const node: *std.DoublyLinkedList(KeyboardGroup).Node = @fieldParentPtr("data", group); - group.seat.keyboard_groups.remove(node); - util.gpa.destroy(node); -} - -pub fn addIdentifier(group: *KeyboardGroup, new_id: []const u8) !void { - for (group.globs.items) |glob| { - if (mem.eql(u8, glob, new_id)) return; - } - - log.debug("keyboard group '{s}' adding identifier: '{s}'", .{ group.name, new_id }); - - const owned_id = try util.gpa.dupe(u8, new_id); - errdefer util.gpa.free(owned_id); - - // Glob is validated in the command handler. - try group.globs.append(util.gpa, owned_id); - errdefer { - // Not used now, but if at any point this function is modified to that - // it may return an error after the glob pattern is added to the list, - // the list will have a pointer to freed memory in its last position. - _ = group.globs.pop(); - } - - // Add any existing matching keyboards to the group. - var it = server.input_manager.devices.iterator(.forward); - while (it.next()) |device| { - if (device.seat != group.seat) continue; - if (device.wlr_device.type != .keyboard) continue; - - if (globber.match(device.identifier, new_id)) { - log.debug("found existing matching keyboard; adding to group", .{}); - - if (!group.wlr_group.addKeyboard(device.wlr_device.toKeyboard())) { - // wlroots logs an error message to explain why this failed. - continue; - } - } - - // Continue, because we may have more than one device with the exact - // same identifier. That is in fact one reason for the keyboard group - // feature to exist in the first place. - } -} - -pub fn removeIdentifier(group: *KeyboardGroup, id: []const u8) !void { - for (group.globs.items, 0..) |glob, index| { - if (mem.eql(u8, glob, id)) { - _ = group.globs.orderedRemove(index); - break; - } - } else { - return; - } - - var it = server.input_manager.devices.iterator(.forward); - while (it.next()) |device| { - if (device.seat != group.seat) continue; - if (device.wlr_device.type != .keyboard) continue; - - if (globber.match(device.identifier, id)) { - const wlr_keyboard = device.wlr_device.toKeyboard(); - assert(wlr_keyboard.group == group.wlr_group); - group.wlr_group.removeKeyboard(wlr_keyboard); - } - } -} diff --git a/river/Seat.zig b/river/Seat.zig index b9b76d0..0dc0376 100644 --- a/river/Seat.zig +++ b/river/Seat.zig @@ -33,7 +33,6 @@ const InputDevice = @import("InputDevice.zig"); const InputManager = @import("InputManager.zig"); const InputRelay = @import("InputRelay.zig"); const Keyboard = @import("Keyboard.zig"); -const KeyboardGroup = @import("KeyboardGroup.zig"); const LayerSurface = @import("LayerSurface.zig"); const LockSurface = @import("LockSurface.zig"); const Mapping = @import("Mapping.zig"); @@ -84,7 +83,7 @@ mapping_repeat_timer: *wl.EventSource, /// Currently repeating mapping, if any repeating_mapping: ?*const Mapping = null, -keyboard_groups: std.DoublyLinkedList(KeyboardGroup) = .{}, +keyboard_group: *wlr.KeyboardGroup, /// Currently focused output. Null only when there are no outputs at all. focused_output: ?*Output = null, @@ -121,12 +120,15 @@ pub fn init(seat: *Seat, name: [*:0]const u8) !void { .cursor = undefined, .relay = undefined, .mapping_repeat_timer = mapping_repeat_timer, + .keyboard_group = try wlr.KeyboardGroup.create(), }; seat.wlr_seat.data = @intFromPtr(seat); try seat.cursor.init(seat); seat.relay.init(); + try seat.tryAddDevice(&seat.keyboard_group.keyboard.base); + seat.wlr_seat.events.request_set_selection.add(&seat.request_set_selection); seat.wlr_seat.events.request_start_drag.add(&seat.request_start_drag); seat.wlr_seat.events.start_drag.add(&seat.start_drag); @@ -142,9 +144,7 @@ pub fn deinit(seat: *Seat) void { seat.cursor.deinit(); seat.mapping_repeat_timer.remove(); - while (seat.keyboard_groups.first) |node| { - node.data.destroy(); - } + seat.keyboard_group.destroy(); seat.request_set_selection.link.remove(); seat.request_start_drag.link.remove(); diff --git a/river/command/keyboard_group.zig b/river/command/keyboard_group.zig index 442fbdc..95a8153 100644 --- a/river/command/keyboard_group.zig +++ b/river/command/keyboard_group.zig @@ -24,77 +24,13 @@ const util = @import("../util.zig"); const Error = @import("../command.zig").Error; const Seat = @import("../Seat.zig"); -const KeyboardGroup = @import("../KeyboardGroup.zig"); -pub fn keyboardGroupCreate( - seat: *Seat, - args: []const [:0]const u8, - out: *?[]const u8, -) Error!void { - if (args.len < 2) return Error.NotEnoughArguments; - if (args.len > 2) return Error.TooManyArguments; +pub const keyboardGroupCreate = keyboardGroupDeprecated; +pub const keyboardGroupDestroy = keyboardGroupDeprecated; +pub const keyboardGroupAdd = keyboardGroupDeprecated; +pub const keyboardGroupRemove = keyboardGroupDeprecated; - if (keyboardGroupFromName(seat, args[1]) != null) { - const msg = try util.gpa.dupe(u8, "error: failed to create keybaord group: group of same name already exists\n"); - out.* = msg; - return; - } - - try KeyboardGroup.create(seat, args[1]); -} - -pub fn keyboardGroupDestroy( - seat: *Seat, - args: []const [:0]const u8, - out: *?[]const u8, -) Error!void { - if (args.len < 2) return Error.NotEnoughArguments; - if (args.len > 2) return Error.TooManyArguments; - const group = keyboardGroupFromName(seat, args[1]) orelse { - const msg = try util.gpa.dupe(u8, "error: no keyboard group with that name exists\n"); - out.* = msg; - return; - }; - group.destroy(); -} - -pub fn keyboardGroupAdd( - seat: *Seat, - args: []const [:0]const u8, - out: *?[]const u8, -) Error!void { - if (args.len < 3) return Error.NotEnoughArguments; - if (args.len > 3) return Error.TooManyArguments; - - const group = keyboardGroupFromName(seat, args[1]) orelse { - const msg = try util.gpa.dupe(u8, "error: no keyboard group with that name exists\n"); - out.* = msg; - return; - }; - try globber.validate(args[2]); - try group.addIdentifier(args[2]); -} - -pub fn keyboardGroupRemove( - seat: *Seat, - args: []const [:0]const u8, - out: *?[]const u8, -) Error!void { - if (args.len < 3) return Error.NotEnoughArguments; - if (args.len > 3) return Error.TooManyArguments; - - const group = keyboardGroupFromName(seat, args[1]) orelse { - const msg = try util.gpa.dupe(u8, "error: no keyboard group with that name exists\n"); - out.* = msg; - return; - }; - try group.removeIdentifier(args[2]); -} - -fn keyboardGroupFromName(seat: *Seat, name: []const u8) ?*KeyboardGroup { - var it = seat.keyboard_groups.first; - while (it) |node| : (it = node.next) { - if (mem.eql(u8, node.data.name, name)) return &node.data; - } - return null; +fn keyboardGroupDeprecated(_: *Seat, _: []const [:0]const u8, out: *?[]const u8) Error!void { + out.* = try util.gpa.dupe(u8, "warning: explicit keyboard groups are deprecated, " ++ + "all keyboards are now automatically added to a single group\n"); } From 037314823e1d6d9877d8d6071e405125481eb7e9 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sat, 26 Apr 2025 13:50:28 +0200 Subject: [PATCH 80/90] build: update to wlroots 0.19 --- .builds/alpine.yml | 10 ++------ .builds/archlinux.yml | 9 +------ .builds/freebsd.yml | 11 +++----- README.md | 2 +- build.zig | 4 +-- build.zig.zon | 4 +-- river/Control.zig | 2 +- river/Cursor.zig | 40 ++++++++++++++++++++++++------ river/DragIcon.zig | 2 +- river/ForeignToplevelHandle.zig | 2 +- river/InputDevice.zig | 4 +-- river/InputManager.zig | 4 +-- river/Keyboard.zig | 2 +- river/LayerSurface.zig | 8 +++--- river/LayoutManager.zig | 2 +- river/LockManager.zig | 2 +- river/LockSurface.zig | 10 ++++---- river/Output.zig | 37 +++------------------------ river/PointerConstraint.zig | 16 ++++++------ river/Root.zig | 35 ++++++++++---------------- river/SceneNodeData.zig | 8 +++--- river/Seat.zig | 6 ++--- river/Server.zig | 4 ++- river/StatusManager.zig | 4 +-- river/TabletTool.zig | 6 ++--- river/TextInput.zig | 10 ++++---- river/XdgDecoration.zig | 6 ++--- river/XdgToplevel.zig | 16 ++++++------ river/XwaylandOverrideRedirect.zig | 4 +-- river/XwaylandView.zig | 4 +-- river/command/output.zig | 4 +-- 31 files changed, 124 insertions(+), 154 deletions(-) diff --git a/.builds/alpine.yml b/.builds/alpine.yml index 1b60fc3..e2cff37 100644 --- a/.builds/alpine.yml +++ b/.builds/alpine.yml @@ -14,6 +14,7 @@ packages: - xcb-util-wm-dev - pixman-dev - libevdev-dev + - wayland-dev - wayland-protocols - xwayland-dev - meson @@ -23,18 +24,11 @@ packages: - xz 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.23.0 - meson setup build -Ddocumentation=false -Dtests=false --prefix /usr - sudo ninja -C build install - cd .. - cd wlroots - git checkout 0.18.0 + git checkout 0.19.0 meson setup build --auto-features=enabled -Drenderers=gles2 \ -Dcolor-management=disabled -Dlibliftoff=disabled \ -Dexamples=false -Dwerror=false -Db_ndebug=false \ diff --git a/.builds/archlinux.yml b/.builds/archlinux.yml index dcae5d2..b1c0eaf 100644 --- a/.builds/archlinux.yml +++ b/.builds/archlinux.yml @@ -21,18 +21,11 @@ packages: - xz 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.23.0 - meson setup build -Ddocumentation=false -Dtests=false --prefix /usr - sudo ninja -C build install - cd .. - cd wlroots - git checkout 0.18.0 + git checkout 0.19.0 meson setup build --auto-features=enabled -Drenderers=gles2 \ -Dcolor-management=disabled -Dlibliftoff=disabled \ -Dexamples=false -Dwerror=false -Db_ndebug=false \ diff --git a/.builds/freebsd.yml b/.builds/freebsd.yml index 0f080d4..d160aca 100644 --- a/.builds/freebsd.yml +++ b/.builds/freebsd.yml @@ -7,6 +7,7 @@ packages: - devel/meson - devel/pkgconf - graphics/mesa-libs + - graphics/wayland - graphics/wayland-protocols - misc/hwdata - x11/libX11 @@ -26,19 +27,13 @@ packages: - 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.23.0 - meson setup build -Ddocumentation=false -Dtests=false --prefix /usr - sudo ninja -C build install - cd .. - cd wlroots - git checkout 0.18.0 + git checkout 0.19.0 meson setup build --auto-features=enabled -Drenderers=gles2 \ + -Dallocators=gbm \ -Dcolor-management=disabled -Dlibliftoff=disabled \ -Dexamples=false -Dwerror=false -Db_ndebug=false \ -Dxcb-errors=disabled --prefix /usr diff --git a/README.md b/README.md index f4681e3..4c5b12a 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ distribution. - [zig](https://ziglang.org/download/) 0.14 - wayland - wayland-protocols -- [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 0.18 +- [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 0.19 - xkbcommon - libevdev - pixman diff --git a/build.zig b/build.zig index 8bdd5ce..6280f65 100644 --- a/build.zig +++ b/build.zig @@ -142,7 +142,7 @@ pub fn build(b: *Build) !void { // 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-0.18", .{}); + wlroots.linkSystemLibrary("wlroots-0.19", .{}); const flags = b.createModule(.{ .root_source_file = b.path("common/flags.zig") }); const globber = b.createModule(.{ .root_source_file = b.path("common/globber.zig") }); @@ -163,7 +163,7 @@ pub fn build(b: *Build) !void { river.linkSystemLibrary("libevdev"); river.linkSystemLibrary("libinput"); river.linkSystemLibrary("wayland-server"); - river.linkSystemLibrary("wlroots-0.18"); + river.linkSystemLibrary("wlroots-0.19"); river.linkSystemLibrary("xkbcommon"); river.linkSystemLibrary("pixman-1"); diff --git a/build.zig.zon b/build.zig.zon index 93d5d22..9de42f7 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -17,8 +17,8 @@ .hash = "wayland-0.3.0-lQa1kjPIAQDmhGYpY-zxiRzQJFHQ2VqhJkQLbKKdt5wl", }, .wlroots = .{ - .url = "https://codeberg.org/ifreund/zig-wlroots/archive/v0.18.2.tar.gz", - .hash = "wlroots-0.18.2-jmOlchnIAwBq45_cxU1V3OWErxxJjQZlc9PyJfR-l3uk", + .url = "https://codeberg.org/ifreund/zig-wlroots/archive/v0.19.1.tar.gz", + .hash = "wlroots-0.19.1-jmOlcs7dAwCajnVWlQZIc-ySYjRlbLxy0F5FvTQqYA3P", }, .xkbcommon = .{ .url = "https://codeberg.org/ifreund/zig-xkbcommon/archive/v0.3.0.tar.gz", diff --git a/river/Control.zig b/river/Control.zig index 2b0d21f..1c472b8 100644 --- a/river/Control.zig +++ b/river/Control.zig @@ -84,7 +84,7 @@ fn handleRequest(control_v1: *zriver.ControlV1, request: zriver.ControlV1.Reques }; }, .run_command => |run_command| { - const seat: *Seat = @ptrFromInt(wlr.Seat.Client.fromWlSeat(run_command.seat).?.seat.data); + const seat: *Seat = @alignCast(@ptrCast(wlr.Seat.Client.fromWlSeat(run_command.seat).?.seat.data)); const callback = zriver.CommandCallbackV1.create( control_v1.getClient(), diff --git a/river/Cursor.zig b/river/Cursor.zig index 4f2d148..cda18ad 100644 --- a/river/Cursor.zig +++ b/river/Cursor.zig @@ -255,6 +255,30 @@ pub fn init(cursor: *Cursor, seat: *Seat) !void { } pub fn deinit(cursor: *Cursor) void { + cursor.axis.link.remove(); + cursor.button.link.remove(); + cursor.frame.link.remove(); + cursor.motion_absolute.link.remove(); + cursor.motion.link.remove(); + cursor.swipe_begin.link.remove(); + cursor.swipe_update.link.remove(); + cursor.swipe_end.link.remove(); + cursor.pinch_begin.link.remove(); + cursor.pinch_update.link.remove(); + cursor.pinch_end.link.remove(); + cursor.request_set_cursor.link.remove(); + + cursor.touch_down.link.remove(); + cursor.touch_motion.link.remove(); + cursor.touch_up.link.remove(); + cursor.touch_cancel.link.remove(); + cursor.touch_frame.link.remove(); + + cursor.tablet_tool_axis.link.remove(); + cursor.tablet_tool_proximity.link.remove(); + cursor.tablet_tool_tip.link.remove(); + cursor.tablet_tool_button.link.remove(); + cursor.hide_cursor_timer.remove(); cursor.xcursor_manager.destroy(); cursor.wlr_cursor.destroy(); @@ -338,7 +362,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: *Cursor = @fieldParentPtr("axis", listener); - const device: *InputDevice = @ptrFromInt(event.device.data); + const device: *InputDevice = @alignCast(@ptrCast(event.device.data)); cursor.seat.handleActivity(); cursor.unhide(); @@ -458,7 +482,7 @@ fn updateKeyboardFocus(cursor: Cursor, result: Root.AtResult) void { /// Requires a call to Root.applyPending() fn updateOutputFocus(cursor: Cursor, lx: f64, ly: f64) void { if (server.root.output_layout.outputAt(lx, ly)) |wlr_output| { - const output: *Output = @ptrFromInt(wlr_output.data); + const output: *Output = @alignCast(@ptrCast(wlr_output.data)); cursor.seat.focusOutput(output); } } @@ -635,7 +659,7 @@ fn handleTabletToolAxis( _: *wl.Listener(*wlr.Tablet.event.Axis), event: *wlr.Tablet.event.Axis, ) void { - const device: *InputDevice = @ptrFromInt(event.device.data); + const device: *InputDevice = @alignCast(@ptrCast(event.device.data)); const tablet: *Tablet = @fieldParentPtr("device", device); device.seat.handleActivity(); @@ -649,7 +673,7 @@ fn handleTabletToolProximity( _: *wl.Listener(*wlr.Tablet.event.Proximity), event: *wlr.Tablet.event.Proximity, ) void { - const device: *InputDevice = @ptrFromInt(event.device.data); + const device: *InputDevice = @alignCast(@ptrCast(event.device.data)); const tablet: *Tablet = @fieldParentPtr("device", device); device.seat.handleActivity(); @@ -663,7 +687,7 @@ fn handleTabletToolTip( _: *wl.Listener(*wlr.Tablet.event.Tip), event: *wlr.Tablet.event.Tip, ) void { - const device: *InputDevice = @ptrFromInt(event.device.data); + const device: *InputDevice = @alignCast(@ptrCast(event.device.data)); const tablet: *Tablet = @fieldParentPtr("device", device); device.seat.handleActivity(); @@ -677,7 +701,7 @@ fn handleTabletToolButton( _: *wl.Listener(*wlr.Tablet.event.Button), event: *wlr.Tablet.event.Button, ) void { - const device: *InputDevice = @ptrFromInt(event.device.data); + const device: *InputDevice = @alignCast(@ptrCast(event.device.data)); const tablet: *Tablet = @fieldParentPtr("device", device); device.seat.handleActivity(); @@ -1255,7 +1279,7 @@ fn warp(cursor: *Cursor) void { }; if (!output_layout_box.containsPoint(cursor.wlr_cursor.x, cursor.wlr_cursor.y) or (usable_layout_box.containsPoint(cursor.wlr_cursor.x, cursor.wlr_cursor.y) and - !target_box.containsPoint(cursor.wlr_cursor.x, cursor.wlr_cursor.y))) + !target_box.containsPoint(cursor.wlr_cursor.x, cursor.wlr_cursor.y))) { const lx: f64 = @floatFromInt(target_box.x + @divTrunc(target_box.width, 2)); const ly: f64 = @floatFromInt(target_box.y + @divTrunc(target_box.height, 2)); @@ -1268,7 +1292,7 @@ fn warp(cursor: *Cursor) void { fn updateDragIcons(cursor: *Cursor) void { var it = server.root.drag_icons.children.iterator(.forward); while (it.next()) |node| { - const icon = @as(*DragIcon, @ptrFromInt(node.data)); + const icon: *DragIcon = @alignCast(@ptrCast(node.data)); if (icon.wlr_drag_icon.drag.seat == cursor.seat.wlr_seat) { icon.updatePosition(cursor); diff --git a/river/DragIcon.zig b/river/DragIcon.zig index eae4059..6b7c135 100644 --- a/river/DragIcon.zig +++ b/river/DragIcon.zig @@ -42,7 +42,7 @@ pub fn create(wlr_drag_icon: *wlr.Drag.Icon, cursor: *Cursor) error{OutOfMemory} .wlr_drag_icon = wlr_drag_icon, .scene_drag_icon = scene_drag_icon, }; - scene_drag_icon.node.data = @intFromPtr(drag_icon); + scene_drag_icon.node.data = drag_icon; drag_icon.updatePosition(cursor); diff --git a/river/ForeignToplevelHandle.zig b/river/ForeignToplevelHandle.zig index a49c8a1..3434c89 100644 --- a/river/ForeignToplevelHandle.zig +++ b/river/ForeignToplevelHandle.zig @@ -89,7 +89,7 @@ fn handleForeignActivate( ) void { const handle: *ForeignToplevelHandle = @fieldParentPtr("foreign_activate", listener); const view: *View = @fieldParentPtr("foreign_toplevel_handle", handle); - const seat: *Seat = @ptrFromInt(event.seat.data); + const seat: *Seat = @alignCast(@ptrCast(event.seat.data)); seat.focus(view); server.root.applyPending(); diff --git a/river/InputDevice.zig b/river/InputDevice.zig index a35eefd..48c5a44 100644 --- a/river/InputDevice.zig +++ b/river/InputDevice.zig @@ -86,7 +86,7 @@ pub fn init(device: *InputDevice, seat: *Seat, wlr_device: *wlr.InputDevice) !vo .link = undefined, }; - wlr_device.data = @intFromPtr(device); + wlr_device.data = device; wlr_device.events.destroy.add(&device.destroy); @@ -117,7 +117,7 @@ pub fn deinit(device: *InputDevice) void { device.seat.updateCapabilities(); } - device.wlr_device.data = 0; + device.wlr_device.data = null; device.* = undefined; } diff --git a/river/InputManager.zig b/river/InputManager.zig index b851360..d0ab7c6 100644 --- a/river/InputManager.zig +++ b/river/InputManager.zig @@ -185,7 +185,7 @@ fn handleNewVirtualKeyboard( _: *wl.Listener(*wlr.VirtualKeyboardV1), virtual_keyboard: *wlr.VirtualKeyboardV1, ) void { - const seat: *Seat = @ptrFromInt(virtual_keyboard.seat.data); + const seat: *Seat = @alignCast(@ptrCast(virtual_keyboard.seat.data)); seat.addDevice(&virtual_keyboard.keyboard.base); } @@ -200,7 +200,7 @@ fn handleNewConstraint( } fn handleNewInputMethod(_: *wl.Listener(*wlr.InputMethodV2), input_method: *wlr.InputMethodV2) void { - const seat: *Seat = @ptrFromInt(input_method.seat.data); + const seat: *Seat = @alignCast(@ptrCast(input_method.seat.data)); log.debug("new input method on seat {s}", .{seat.wlr_seat.name}); diff --git a/river/Keyboard.zig b/river/Keyboard.zig index a739f03..0fffefa 100644 --- a/river/Keyboard.zig +++ b/river/Keyboard.zig @@ -96,7 +96,7 @@ pub fn init(keyboard: *Keyboard, seat: *Seat, wlr_device: *wlr.InputDevice) !voi errdefer keyboard.device.deinit(); const wlr_keyboard = keyboard.device.wlr_device.toKeyboard(); - wlr_keyboard.data = @intFromPtr(keyboard); + wlr_keyboard.data = keyboard; // wlroots will log a more detailed error if this fails. if (!wlr_keyboard.setKeymap(server.config.keymap)) return error.OutOfMemory; diff --git a/river/LayerSurface.zig b/river/LayerSurface.zig index d20d159..f63b934 100644 --- a/river/LayerSurface.zig +++ b/river/LayerSurface.zig @@ -43,7 +43,7 @@ commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit) new_popup: wl.Listener(*wlr.XdgPopup) = wl.Listener(*wlr.XdgPopup).init(handleNewPopup), pub fn create(wlr_layer_surface: *wlr.LayerSurfaceV1) error{OutOfMemory}!void { - const output: *Output = @ptrFromInt(wlr_layer_surface.output.?.data); + const output: *Output = @alignCast(@ptrCast(wlr_layer_surface.output.?.data)); const layer_surface = try util.gpa.create(LayerSurface); errdefer util.gpa.destroy(layer_surface); @@ -59,7 +59,7 @@ pub fn create(wlr_layer_surface: *wlr.LayerSurfaceV1) error{OutOfMemory}!void { try SceneNodeData.attach(&layer_surface.scene_layer_surface.tree.node, .{ .layer_surface = layer_surface }); try SceneNodeData.attach(&layer_surface.popup_tree.node, .{ .layer_surface = layer_surface }); - wlr_layer_surface.surface.data = @intFromPtr(&layer_surface.scene_layer_surface.tree.node); + wlr_layer_surface.surface.data = &layer_surface.scene_layer_surface.tree.node; wlr_layer_surface.events.destroy.add(&layer_surface.destroy); wlr_layer_surface.surface.events.map.add(&layer_surface.map); @@ -88,7 +88,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.LayerSurfaceV1), _: *wlr.LayerSurfa layer_surface.popup_tree.node.destroy(); // The wlr_surface may outlive the wlr_layer_surface so we must clean up the user data. - layer_surface.wlr_layer_surface.surface.data = 0; + layer_surface.wlr_layer_surface.surface.data = null; util.gpa.destroy(layer_surface); } @@ -156,7 +156,7 @@ fn handleKeyboardInteractiveExclusive(output: *Output, consider: ?*LayerSurface) var it = tree.children.iterator(.reverse); while (it.next()) |node| { assert(node.type == .tree); - if (@as(?*SceneNodeData, @ptrFromInt(node.data))) |node_data| { + if (@as(?*SceneNodeData, @alignCast(@ptrCast(node.data)))) |node_data| { const layer_surface = node_data.data.layer_surface; const wlr_layer_surface = layer_surface.wlr_layer_surface; if (wlr_layer_surface.surface.mapped and diff --git a/river/LayoutManager.zig b/river/LayoutManager.zig index d994d28..847c714 100644 --- a/river/LayoutManager.zig +++ b/river/LayoutManager.zig @@ -68,7 +68,7 @@ fn handleRequest( .get_layout => |req| { // Ignore if the output is inert const wlr_output = wlr.Output.fromWlOutput(req.output) orelse return; - const output: *Output = @ptrFromInt(wlr_output.data); + const output: *Output = @alignCast(@ptrCast(wlr_output.data)); log.debug("bind layout '{s}' on output '{s}'", .{ req.namespace, output.wlr_output.name }); diff --git a/river/LockManager.zig b/river/LockManager.zig index efd1efb..5b86c8c 100644 --- a/river/LockManager.zig +++ b/river/LockManager.zig @@ -266,7 +266,7 @@ pub fn updateLockSurfaceSize(manager: *LockManager, output: *Output) void { var it = lock.surfaces.iterator(.forward); while (it.next()) |wlr_lock_surface| { - const lock_surface: *LockSurface = @ptrFromInt(wlr_lock_surface.data); + const lock_surface: *LockSurface = @alignCast(@ptrCast(wlr_lock_surface.data)); if (output == lock_surface.getOutput()) { lock_surface.configure(); } diff --git a/river/LockSurface.zig b/river/LockSurface.zig index 60f0aa8..285c8ec 100644 --- a/river/LockSurface.zig +++ b/river/LockSurface.zig @@ -44,7 +44,7 @@ pub fn create(wlr_lock_surface: *wlr.SessionLockSurfaceV1, lock: *wlr.SessionLoc .wlr_lock_surface = wlr_lock_surface, .lock = lock, }; - wlr_lock_surface.data = @intFromPtr(lock_surface); + wlr_lock_surface.data = lock_surface; const output = lock_surface.getOutput(); const tree = try output.locked_content.createSceneSubsurfaceTree(wlr_lock_surface.surface); @@ -52,7 +52,7 @@ pub fn create(wlr_lock_surface: *wlr.SessionLockSurfaceV1, lock: *wlr.SessionLoc try SceneNodeData.attach(&tree.node, .{ .lock_surface = lock_surface }); - wlr_lock_surface.surface.data = @intFromPtr(&tree.node); + wlr_lock_surface.surface.data = &tree.node; wlr_lock_surface.surface.events.map.add(&lock_surface.map); wlr_lock_surface.events.destroy.add(&lock_surface.surface_destroy); @@ -65,7 +65,7 @@ pub fn destroy(lock_surface: *LockSurface) void { var surface_it = lock_surface.lock.surfaces.iterator(.forward); const new_focus: Seat.FocusTarget = while (surface_it.next()) |surface| { if (surface != lock_surface.wlr_lock_surface) - break .{ .lock_surface = @ptrFromInt(surface.data) }; + break .{ .lock_surface = @alignCast(@ptrCast(surface.data)) }; } else .none; var seat_it = server.input_manager.seats.first; @@ -86,13 +86,13 @@ pub fn destroy(lock_surface: *LockSurface) void { lock_surface.surface_destroy.link.remove(); // The wlr_surface may outlive the wlr_lock_surface so we must clean up the user data. - lock_surface.wlr_lock_surface.surface.data = 0; + lock_surface.wlr_lock_surface.surface.data = null; util.gpa.destroy(lock_surface); } pub fn getOutput(lock_surface: *LockSurface) *Output { - return @ptrFromInt(lock_surface.wlr_lock_surface.output.data); + return @alignCast(@ptrCast(lock_surface.wlr_lock_surface.output.data)); } pub fn configure(lock_surface: *LockSurface) void { diff --git a/river/Output.zig b/river/Output.zig index 769bb4c..daf6b7a 100644 --- a/river/Output.zig +++ b/river/Output.zig @@ -125,10 +125,6 @@ lock_render_state: enum { lock_surface, } = .blanked, -/// Set to true if a gamma control client makes a set gamma request. -/// This request is handled while rendering the next frame in handleFrame(). -gamma_dirty: bool = false, - /// The state of the output that is directly acted upon/modified through user input. /// /// Pending state will be copied to the inflight state and communicated to clients @@ -295,7 +291,7 @@ pub fn create(wlr_output: *wlr.Output) !void { }, .status = undefined, }; - wlr_output.data = @intFromPtr(output); + wlr_output.data = output; output.pending.focus_stack.init(); output.pending.wm_stack.init(); @@ -364,7 +360,7 @@ fn sendLayerConfigures( var it = tree.children.safeIterator(.forward); while (it.next()) |node| { assert(node.type == .tree); - if (@as(?*SceneNodeData, @ptrFromInt(node.data))) |node_data| { + if (@as(?*SceneNodeData, @alignCast(@ptrCast(node.data)))) |node_data| { const layer_surface = node_data.data.layer_surface; if (!layer_surface.wlr_layer_surface.initialized) continue; @@ -433,7 +429,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void { if (output.layout_namespace) |namespace| util.gpa.free(namespace); - output.wlr_output.data = 0; + output.wlr_output.data = null; util.gpa.destroy(output); @@ -480,7 +476,6 @@ pub fn applyState(output: *Output, state: *wlr.Output.State) error{CommitFailed} fn handleEnableDisable(output: *Output) void { output.updateLockRenderStateOnEnableDisable(); - output.gamma_dirty = true; if (output.wlr_output.enabled) { // Add the output to root.active_outputs and the output layout if it has not @@ -532,7 +527,6 @@ fn handleFrame(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void { // TODO this should probably be retried on failure output.renderAndCommit(scene_output) catch |err| switch (err) { - error.OutOfMemory => log.err("out of memory", .{}), error.CommitFailed => log.err("output commit failed for {s}", .{output.wlr_output.name}), }; @@ -541,34 +535,13 @@ fn handleFrame(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void { } fn renderAndCommit(output: *Output, scene_output: *wlr.SceneOutput) !void { - // TODO(wlroots): replace this with wlr_scene_output_needs_frame() - if (!output.wlr_output.needs_frame and !output.gamma_dirty and - !scene_output.pending_commit_damage.notEmpty()) - { - return; - } + if (!scene_output.needsFrame()) return; var state = wlr.Output.State.init(); defer state.finish(); if (!scene_output.buildState(&state, null)) return error.CommitFailed; - if (output.gamma_dirty) { - const control = server.root.gamma_control_manager.getControl(output.wlr_output); - if (!wlr.GammaControlV1.apply(control, &state)) return error.OutOfMemory; - - // TODO(wlroots): remove this isHeadless() workaround after upstream fix is available - // in a release: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4868 - if (!output.wlr_output.testState(&state) or output.wlr_output.isHeadless()) { - wlr.GammaControlV1.sendFailedAndDestroy(control); - state.clearGammaLut(); - // If the backend does not support gamma LUTs it will reject any - // state with the gamma LUT committed bit set even if the state - // has a null LUT. The wayland backend for example has this behavior. - state.committed.gamma_lut = false; - } - } - if (output.current.fullscreen) |fullscreen| { if (fullscreen.allowTearing()) { state.tearing_page_flip = true; @@ -583,8 +556,6 @@ fn renderAndCommit(output: *Output, scene_output: *wlr.SceneOutput) !void { if (!output.wlr_output.commitState(&state)) return error.CommitFailed; - output.gamma_dirty = false; - if (server.lock_manager.state == .locked or (server.lock_manager.state == .waiting_for_lock_surfaces and output.locked_content.node.enabled) or server.lock_manager.state == .waiting_for_blank) diff --git a/river/PointerConstraint.zig b/river/PointerConstraint.zig index a2c4d74..12708aa 100644 --- a/river/PointerConstraint.zig +++ b/river/PointerConstraint.zig @@ -47,7 +47,7 @@ commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit) node_destroy: wl.Listener(void) = wl.Listener(void).init(handleNodeDestroy), pub fn create(wlr_constraint: *wlr.PointerConstraintV1) error{OutOfMemory}!void { - const seat: *Seat = @ptrFromInt(wlr_constraint.seat.data); + const seat: *Seat = @alignCast(@ptrCast(wlr_constraint.seat.data)); const constraint = try util.gpa.create(PointerConstraint); errdefer util.gpa.destroy(constraint); @@ -55,7 +55,7 @@ pub fn create(wlr_constraint: *wlr.PointerConstraintV1) error{OutOfMemory}!void constraint.* = .{ .wlr_constraint = wlr_constraint, }; - wlr_constraint.data = @intFromPtr(constraint); + wlr_constraint.data = constraint; wlr_constraint.events.destroy.add(&constraint.destroy); wlr_constraint.surface.events.commit.add(&constraint.commit); @@ -70,7 +70,7 @@ pub fn create(wlr_constraint: *wlr.PointerConstraintV1) error{OutOfMemory}!void } pub fn maybeActivate(constraint: *PointerConstraint) void { - const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data); + const seat: *Seat = @alignCast(@ptrCast(constraint.wlr_constraint.seat.data)); assert(seat.cursor.constraint == constraint); @@ -102,7 +102,7 @@ pub fn maybeActivate(constraint: *PointerConstraint) void { /// Called when the cursor position or content in the scene graph changes pub fn updateState(constraint: *PointerConstraint) void { - const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data); + const seat: *Seat = @alignCast(@ptrCast(constraint.wlr_constraint.seat.data)); constraint.maybeActivate(); @@ -154,7 +154,7 @@ pub fn confine(constraint: *PointerConstraint, dx: *f64, dy: *f64) void { } pub fn deactivate(constraint: *PointerConstraint) void { - const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data); + const seat: *Seat = @alignCast(@ptrCast(constraint.wlr_constraint.seat.data)); assert(seat.cursor.constraint == constraint); assert(constraint.state == .active); @@ -167,7 +167,7 @@ pub fn deactivate(constraint: *PointerConstraint) void { } fn warpToHintIfSet(constraint: *PointerConstraint) void { - const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data); + const seat: *Seat = @alignCast(@ptrCast(constraint.wlr_constraint.seat.data)); if (constraint.wlr_constraint.current.cursor_hint.enabled) { var lx: i32 = undefined; @@ -190,7 +190,7 @@ fn handleNodeDestroy(listener: *wl.Listener(void)) void { fn handleDestroy(listener: *wl.Listener(*wlr.PointerConstraintV1), _: *wlr.PointerConstraintV1) void { const constraint: *PointerConstraint = @fieldParentPtr("destroy", listener); - const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data); + const seat: *Seat = @alignCast(@ptrCast(constraint.wlr_constraint.seat.data)); if (constraint.state == .active) { // We can't simply call deactivate() here as it calls sendDeactivated(), @@ -215,7 +215,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.PointerConstraintV1), _: *wlr.Point // the surface changes. fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { const constraint: *PointerConstraint = @fieldParentPtr("commit", listener); - const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data); + const seat: *Seat = @alignCast(@ptrCast(constraint.wlr_constraint.seat.data)); switch (constraint.state) { .active => |state| { diff --git a/river/Root.zig b/river/Root.zig index 5516280..ccdf2e1 100644 --- a/river/Root.zig +++ b/river/Root.zig @@ -97,8 +97,6 @@ power_manager_set_mode: wl.Listener(*wlr.OutputPowerManagerV1.event.SetMode) = wl.Listener(*wlr.OutputPowerManagerV1.event.SetMode).init(handlePowerManagerSetMode), gamma_control_manager: *wlr.GammaControlManagerV1, -gamma_control_set_gamma: wl.Listener(*wlr.GammaControlManagerV1.event.SetGamma) = - wl.Listener(*wlr.GammaControlManagerV1.event.SetGamma).init(handleSetGamma), /// A list of all outputs all_outputs: wl.list.Head(Output, .all_link), @@ -123,6 +121,9 @@ pub fn init(root: *Root) !void { const scene = try wlr.Scene.create(); errdefer scene.tree.node.destroy(); + const gamma_control_manager = try wlr.GammaControlManagerV1.create(server.wl_server); + scene.setGammaControlManagerV1(gamma_control_manager); + const interactive_content = try scene.tree.createSceneTree(); const drag_icons = try scene.tree.createSceneTree(); const hidden_tree = try scene.tree.createSceneTree(); @@ -163,11 +164,11 @@ pub fn init(root: *Root) !void { .all_outputs = undefined, .active_outputs = undefined, - .presentation = try wlr.Presentation.create(server.wl_server, server.backend), + .presentation = try wlr.Presentation.create(server.wl_server, server.backend, 2), .xdg_output_manager = try wlr.XdgOutputManagerV1.create(server.wl_server, output_layout), .output_manager = try wlr.OutputManagerV1.create(server.wl_server), .power_manager = try wlr.OutputPowerManagerV1.create(server.wl_server), - .gamma_control_manager = try wlr.GammaControlManagerV1.create(server.wl_server), + .gamma_control_manager = gamma_control_manager, .transaction_timeout = transaction_timeout, }; root.hidden.pending.focus_stack.init(); @@ -187,10 +188,14 @@ pub fn init(root: *Root) !void { root.output_manager.events.@"test".add(&root.manager_test); root.output_layout.events.change.add(&root.layout_change); root.power_manager.events.set_mode.add(&root.power_manager_set_mode); - root.gamma_control_manager.events.set_gamma.add(&root.gamma_control_set_gamma); } pub fn deinit(root: *Root) void { + root.manager_apply.link.remove(); + root.manager_test.link.remove(); + root.layout_change.link.remove(); + root.power_manager_set_mode.link.remove(); + root.output_layout.destroy(); root.transaction_timeout.remove(); } @@ -323,7 +328,7 @@ pub fn deactivateOutput(root: *Root, output: *Output) void { var it = tree.children.safeIterator(.forward); while (it.next()) |scene_node| { assert(scene_node.type == .tree); - if (@as(?*SceneNodeData, @ptrFromInt(scene_node.data))) |node_data| { + if (@as(?*SceneNodeData, @alignCast(@ptrCast(scene_node.data)))) |node_data| { node_data.data.layer_surface.wlr_layer_surface.destroy(); } } @@ -795,7 +800,7 @@ fn processOutputConfig( var it = config.heads.iterator(.forward); while (it.next()) |head| { const wlr_output = head.state.output; - const output: *Output = @ptrFromInt(wlr_output.data); + const output: *Output = @alignCast(@ptrCast(wlr_output.data)); var proposed_state = wlr.Output.State.init(); head.state.apply(&proposed_state); @@ -834,7 +839,7 @@ fn handlePowerManagerSetMode( event: *wlr.OutputPowerManagerV1.event.SetMode, ) void { // The output may have been destroyed, in which case there is nothing to do - const output = @as(?*Output, @ptrFromInt(event.output.data)) orelse return; + const output: *Output = @alignCast(@ptrCast(event.output.data orelse return)); std.log.debug("client requested dpms {s} for output {s}", .{ @tagName(event.mode), @@ -864,18 +869,4 @@ fn handlePowerManagerSetMode( } output.updateLockRenderStateOnEnableDisable(); - output.gamma_dirty = true; -} - -fn handleSetGamma( - _: *wl.Listener(*wlr.GammaControlManagerV1.event.SetGamma), - event: *wlr.GammaControlManagerV1.event.SetGamma, -) void { - // The output may have been destroyed, in which case there is nothing to do - const output = @as(?*Output, @ptrFromInt(event.output.data)) orelse return; - - std.log.debug("client requested to set gamma", .{}); - - output.gamma_dirty = true; - output.wlr_output.scheduleFrame(); } diff --git a/river/SceneNodeData.zig b/river/SceneNodeData.zig index 68d5923..1e9116f 100644 --- a/river/SceneNodeData.zig +++ b/river/SceneNodeData.zig @@ -46,7 +46,7 @@ pub fn attach(node: *wlr.SceneNode, data: Data) error{OutOfMemory}!void { .node = node, .data = data, }; - node.data = @intFromPtr(scene_node_data); + node.data = scene_node_data; node.events.destroy.add(&scene_node_data.destroy); } @@ -54,7 +54,7 @@ pub fn attach(node: *wlr.SceneNode, data: Data) error{OutOfMemory}!void { pub fn fromNode(node: *wlr.SceneNode) ?*SceneNodeData { var n = node; while (true) { - if (@as(?*SceneNodeData, @ptrFromInt(n.data))) |scene_node_data| { + if (@as(?*SceneNodeData, @alignCast(@ptrCast(n.data)))) |scene_node_data| { return scene_node_data; } if (n.parent) |parent_tree| { @@ -66,7 +66,7 @@ pub fn fromNode(node: *wlr.SceneNode) ?*SceneNodeData { } pub fn fromSurface(surface: *wlr.Surface) ?*SceneNodeData { - if (@as(?*wlr.SceneNode, @ptrFromInt(surface.getRootSurface().data))) |node| { + if (@as(?*wlr.SceneNode, @alignCast(@ptrCast(surface.getRootSurface().data)))) |node| { return fromNode(node); } return null; @@ -76,7 +76,7 @@ fn handleDestroy(listener: *wl.Listener(void)) void { const scene_node_data: *SceneNodeData = @fieldParentPtr("destroy", listener); scene_node_data.destroy.link.remove(); - scene_node_data.node.data = 0; + scene_node_data.node.data = null; util.gpa.destroy(scene_node_data); } diff --git a/river/Seat.zig b/river/Seat.zig index 0dc0376..626eb6b 100644 --- a/river/Seat.zig +++ b/river/Seat.zig @@ -122,7 +122,7 @@ pub fn init(seat: *Seat, name: [*:0]const u8) !void { .mapping_repeat_timer = mapping_repeat_timer, .keyboard_group = try wlr.KeyboardGroup.create(), }; - seat.wlr_seat.data = @intFromPtr(seat); + seat.wlr_seat.data = seat; try seat.cursor.init(seat); seat.relay.init(); @@ -284,7 +284,7 @@ pub fn setFocusRaw(seat: *Seat, new_focus: FocusTarget) void { if (seat.cursor.constraint) |constraint| { assert(constraint.wlr_constraint == wlr_constraint); } else { - seat.cursor.constraint = @ptrFromInt(wlr_constraint.data); + seat.cursor.constraint = @alignCast(@ptrCast(wlr_constraint.data)); assert(seat.cursor.constraint != null); } } @@ -312,7 +312,7 @@ pub fn keyboardEnterOrLeave(seat: *Seat, target_surface: ?*wlr.Surface) void { fn keyboardNotifyEnter(seat: *Seat, wlr_surface: *wlr.Surface) void { if (seat.wlr_seat.getKeyboard()) |wlr_keyboard| { - const keyboard: *Keyboard = @ptrFromInt(wlr_keyboard.data); + const keyboard: *Keyboard = @alignCast(@ptrCast(wlr_keyboard.data)); var keycodes: std.BoundedArray(u32, Keyboard.Pressed.capacity) = .{}; for (keyboard.pressed.keys.constSlice()) |item| { diff --git a/river/Server.zig b/river/Server.zig index 05bc96b..cda3a04 100644 --- a/river/Server.zig +++ b/river/Server.zig @@ -233,6 +233,8 @@ pub fn deinit(server: *Server) void { server.wl_server.destroyClients(); + server.input_manager.new_input.link.remove(); + server.root.new_output.link.remove(); server.backend.destroy(); // The scene graph needs to be destroyed after the backend but before the renderer @@ -499,7 +501,7 @@ fn handleRequestSetCursorShape( _: *wl.Listener(*wlr.CursorShapeManagerV1.event.RequestSetShape), event: *wlr.CursorShapeManagerV1.event.RequestSetShape, ) void { - const seat: *Seat = @ptrFromInt(event.seat_client.seat.data); + const seat: *Seat = @alignCast(@ptrCast(event.seat_client.seat.data)); if (event.tablet_tool) |wp_tool| { assert(event.device_type == .tablet_tool); diff --git a/river/StatusManager.zig b/river/StatusManager.zig index 4464431..b18dd17 100644 --- a/river/StatusManager.zig +++ b/river/StatusManager.zig @@ -69,7 +69,7 @@ fn handleRequest( .get_river_output_status => |req| { // ignore if the output is inert const wlr_output = wlr.Output.fromWlOutput(req.output) orelse return; - const output: *Output = @ptrFromInt(wlr_output.data); + const output: *Output = @alignCast(@ptrCast(wlr_output.data)); const resource = zriver.OutputStatusV1.create( status_manager_v1.getClient(), @@ -86,7 +86,7 @@ fn handleRequest( .get_river_seat_status => |req| { // ignore if the seat is inert const wlr_seat = wlr.Seat.Client.fromWlSeat(req.seat) orelse return; - const seat: *Seat = @ptrFromInt(wlr_seat.seat.data); + const seat: *Seat = @alignCast(@ptrCast(wlr_seat.seat.data)); const node = util.gpa.create(std.SinglyLinkedList(SeatStatus).Node) catch { status_manager_v1.getClient().postNoMemory(); diff --git a/river/TabletTool.zig b/river/TabletTool.zig index af558a3..c1db876 100644 --- a/river/TabletTool.zig +++ b/river/TabletTool.zig @@ -59,7 +59,7 @@ set_cursor: wl.Listener(*wlr.TabletV2TabletTool.event.SetCursor) = wl.Listener(*wlr.TabletV2TabletTool.event.SetCursor).init(handleSetCursor), pub fn get(wlr_seat: *wlr.Seat, wlr_tool: *wlr.TabletTool) error{OutOfMemory}!*TabletTool { - if (@as(?*TabletTool, @ptrFromInt(wlr_tool.data))) |tool| { + if (@as(?*TabletTool, @alignCast(@ptrCast(wlr_tool.data)))) |tool| { return tool; } else { return TabletTool.create(wlr_seat, wlr_tool); @@ -81,7 +81,7 @@ fn create(wlr_seat: *wlr.Seat, wlr_tool: *wlr.TabletTool) error{OutOfMemory}!*Ta .wlr_cursor = wlr_cursor, }; - wlr_tool.data = @intFromPtr(tool); + wlr_tool.data = tool; wlr_tool.events.destroy.add(&tool.destroy); tool.wp_tool.events.set_cursor.add(&tool.set_cursor); @@ -92,7 +92,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: *TabletTool = @fieldParentPtr("destroy", listener); - tool.wp_tool.wlr_tool.data = 0; + tool.wp_tool.wlr_tool.data = null; tool.wlr_cursor.destroy(); diff --git a/river/TextInput.zig b/river/TextInput.zig index 1364454..1df7d5f 100644 --- a/river/TextInput.zig +++ b/river/TextInput.zig @@ -43,7 +43,7 @@ destroy: wl.Listener(*wlr.TextInputV3) = wl.Listener(*wlr.TextInputV3).init(handleDestroy), pub fn create(wlr_text_input: *wlr.TextInputV3) !void { - const seat: *Seat = @ptrFromInt(wlr_text_input.seat.data); + const seat: *Seat = @alignCast(@ptrCast(wlr_text_input.seat.data)); const text_input = try util.gpa.create(TextInput); @@ -64,7 +64,7 @@ pub fn create(wlr_text_input: *wlr.TextInputV3) !void { fn handleEnable(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) void { const text_input: *TextInput = @fieldParentPtr("enable", listener); - const seat: *Seat = @ptrFromInt(text_input.wlr_text_input.seat.data); + const seat: *Seat = @alignCast(@ptrCast(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", .{}); @@ -91,7 +91,7 @@ fn handleEnable(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) v fn handleCommit(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) void { const text_input: *TextInput = @fieldParentPtr("commit", listener); - const seat: *Seat = @ptrFromInt(text_input.wlr_text_input.seat.data); + const seat: *Seat = @alignCast(@ptrCast(text_input.wlr_text_input.seat.data)); if (seat.relay.text_input != text_input) { log.err("inactive text input tried to commit an update, client bug?", .{}); @@ -105,7 +105,7 @@ fn handleCommit(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) v fn handleDisable(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) void { const text_input: *TextInput = @fieldParentPtr("disable", listener); - const seat: *Seat = @ptrFromInt(text_input.wlr_text_input.seat.data); + const seat: *Seat = @alignCast(@ptrCast(text_input.wlr_text_input.seat.data)); if (seat.relay.text_input == text_input) { seat.relay.disableTextInput(); @@ -114,7 +114,7 @@ fn handleDisable(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) fn handleDestroy(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) void { const text_input: *TextInput = @fieldParentPtr("destroy", listener); - const seat: *Seat = @ptrFromInt(text_input.wlr_text_input.seat.data); + const seat: *Seat = @alignCast(@ptrCast(text_input.wlr_text_input.seat.data)); if (seat.relay.text_input == text_input) { seat.relay.disableTextInput(); diff --git a/river/XdgDecoration.zig b/river/XdgDecoration.zig index eee0c1d..7c72d6b 100644 --- a/river/XdgDecoration.zig +++ b/river/XdgDecoration.zig @@ -34,7 +34,7 @@ request_mode: wl.Listener(*wlr.XdgToplevelDecorationV1) = wl.Listener(*wlr.XdgToplevelDecorationV1).init(handleRequestMode), pub fn init(wlr_decoration: *wlr.XdgToplevelDecorationV1) void { - const toplevel: *XdgToplevel = @ptrFromInt(wlr_decoration.toplevel.base.data); + const toplevel: *XdgToplevel = @alignCast(@ptrCast(wlr_decoration.toplevel.base.data)); toplevel.decoration = .{ .wlr_decoration = wlr_decoration }; const decoration = &toplevel.decoration.?; @@ -48,7 +48,7 @@ pub fn init(wlr_decoration: *wlr.XdgToplevelDecorationV1) void { } pub fn deinit(decoration: *XdgDecoration) void { - const toplevel: *XdgToplevel = @ptrFromInt(decoration.wlr_decoration.toplevel.base.data); + const toplevel: *XdgToplevel = @alignCast(@ptrCast(decoration.wlr_decoration.toplevel.base.data)); decoration.destroy.link.remove(); decoration.request_mode.link.remove(); @@ -72,7 +72,7 @@ fn handleRequestMode( ) void { const decoration: *XdgDecoration = @fieldParentPtr("request_mode", listener); - const toplevel: *XdgToplevel = @ptrFromInt(decoration.wlr_decoration.toplevel.base.data); + const toplevel: *XdgToplevel = @alignCast(@ptrCast(decoration.wlr_decoration.toplevel.base.data)); const view = toplevel.view; const ssd = server.config.rules.ssd.match(toplevel.view) orelse diff --git a/river/XdgToplevel.zig b/river/XdgToplevel.zig index deca0b0..f021986 100644 --- a/river/XdgToplevel.zig +++ b/river/XdgToplevel.zig @@ -100,8 +100,8 @@ pub fn create(wlr_toplevel: *wlr.XdgToplevel) error{OutOfMemory}!void { toplevel.view = view; - wlr_toplevel.base.data = @intFromPtr(toplevel); - wlr_toplevel.base.surface.data = @intFromPtr(&view.tree.node); + wlr_toplevel.base.data = toplevel; + wlr_toplevel.base.surface.data = &view.tree.node; // Add listeners that are active over the toplevel's entire lifetime wlr_toplevel.events.destroy.add(&toplevel.destroy); @@ -216,7 +216,7 @@ fn handleDestroy(listener: *wl.Listener(void)) void { toplevel.new_popup.link.remove(); // The wlr_surface may outlive the wlr_xdg_toplevel so we must clean up the user data. - toplevel.wlr_toplevel.base.surface.data = 0; + toplevel.wlr_toplevel.base.surface.data = null; const view = toplevel.view; view.impl = .none; @@ -235,7 +235,7 @@ fn handleMap(listener: *wl.Listener(void)) void { toplevel.wlr_toplevel.events.set_title.add(&toplevel.set_title); toplevel.wlr_toplevel.events.set_app_id.add(&toplevel.set_app_id); - toplevel.wlr_toplevel.base.getGeometry(&toplevel.geometry); + toplevel.geometry = toplevel.wlr_toplevel.base.geometry; view.pending.box = .{ .x = 0, @@ -338,7 +338,7 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { switch (toplevel.configure_state) { .idle, .committed, .timed_out => { const old_geometry = toplevel.geometry; - toplevel.wlr_toplevel.base.getGeometry(&toplevel.geometry); + toplevel.geometry = toplevel.wlr_toplevel.base.geometry; const size_changed = toplevel.geometry.width != old_geometry.width or toplevel.geometry.height != old_geometry.height; @@ -381,7 +381,7 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { // stashed buffer from when the transaction started. .inflight => view.sendFrameDone(), .acked, .timed_out_acked => { - toplevel.wlr_toplevel.base.getGeometry(&toplevel.geometry); + toplevel.geometry = toplevel.wlr_toplevel.base.geometry; if (view.inflight.resizing) { view.resizeUpdatePosition(toplevel.geometry.width, toplevel.geometry.height); @@ -423,7 +423,7 @@ fn handleRequestMove( event: *wlr.XdgToplevel.event.Move, ) void { const toplevel: *XdgToplevel = @fieldParentPtr("request_move", listener); - const seat: *Seat = @ptrFromInt(event.seat.seat.data); + const seat: *Seat = @alignCast(@ptrCast(event.seat.seat.data)); const view = toplevel.view; if (view.pending.fullscreen) return; @@ -446,7 +446,7 @@ fn handleRequestMove( fn handleRequestResize(listener: *wl.Listener(*wlr.XdgToplevel.event.Resize), event: *wlr.XdgToplevel.event.Resize) void { const toplevel: *XdgToplevel = @fieldParentPtr("request_resize", listener); - const seat: *Seat = @ptrFromInt(event.seat.seat.data); + const seat: *Seat = @alignCast(@ptrCast(event.seat.seat.data)); const view = toplevel.view; if (view.pending.fullscreen) return; diff --git a/river/XwaylandOverrideRedirect.zig b/river/XwaylandOverrideRedirect.zig index ff638a3..2834acd 100644 --- a/river/XwaylandOverrideRedirect.zig +++ b/river/XwaylandOverrideRedirect.zig @@ -120,7 +120,7 @@ fn mapImpl(override_redirect: *XwaylandOverrideRedirect) error{OutOfMemory}!void .override_redirect = override_redirect, }); - surface.data = @intFromPtr(&override_redirect.surface_tree.?.node); + surface.data = &override_redirect.surface_tree.?.node; override_redirect.surface_tree.?.node.setPosition( override_redirect.xwayland_surface.x, @@ -159,7 +159,7 @@ fn handleUnmap(listener: *wl.Listener(void)) void { override_redirect.set_geometry.link.remove(); - override_redirect.xwayland_surface.surface.?.data = 0; + override_redirect.xwayland_surface.surface.?.data = null; override_redirect.surface_tree.?.node.destroy(); override_redirect.surface_tree = null; diff --git a/river/XwaylandView.zig b/river/XwaylandView.zig index f7c7578..68918ed 100644 --- a/river/XwaylandView.zig +++ b/river/XwaylandView.zig @@ -164,7 +164,7 @@ pub fn handleMap(listener: *wl.Listener(void)) void { const xwayland_surface = xwayland_view.xwayland_surface; const surface = xwayland_surface.surface.?; - surface.data = @intFromPtr(&view.tree.node); + surface.data = &view.tree.node; // Add listeners that are only active while mapped xwayland_surface.events.set_title.add(&xwayland_view.set_title); @@ -215,7 +215,7 @@ pub fn handleMap(listener: *wl.Listener(void)) void { fn handleUnmap(listener: *wl.Listener(void)) void { const xwayland_view: *XwaylandView = @fieldParentPtr("unmap", listener); - xwayland_view.xwayland_surface.surface.?.data = 0; + xwayland_view.xwayland_surface.surface.?.data = null; // Remove listeners that are only active while mapped xwayland_view.set_title.link.remove(); diff --git a/river/command/output.zig b/river/command/output.zig index 8f7cd0e..a9ac836 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 @as(*Output, @fieldParentPtr("active_link", link)); + return @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); @@ -121,7 +121,7 @@ fn getOutput(seat: *Seat, str: []const u8) !?*Output { @floatFromInt(focus_box.x + @divTrunc(focus_box.width, 2)), @floatFromInt(focus_box.y + @divTrunc(focus_box.height, 2)), ) orelse return null; - return @as(*Output, @ptrFromInt(wlr_output.data)); + return @alignCast(@ptrCast(wlr_output.data)); } else { // Check if an output matches by name var it = server.root.active_outputs.iterator(.forward); From 15736c57d733fe71043a2cdbf2c2196b9740e6db Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sun, 27 Apr 2025 12:39:21 +0200 Subject: [PATCH 81/90] linux-dmabuf: re-enable per-surface feedback This was disabled due to being too spammy in the past. Since wlr_scene now debounces per-surface feedback it should be fine to re-enable this. --- river/Root.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/river/Root.zig b/river/Root.zig index ccdf2e1..1de9434 100644 --- a/river/Root.zig +++ b/river/Root.zig @@ -124,6 +124,8 @@ pub fn init(root: *Root) !void { const gamma_control_manager = try wlr.GammaControlManagerV1.create(server.wl_server); scene.setGammaControlManagerV1(gamma_control_manager); + if (server.linux_dmabuf) |linux_dmabuf| scene.setLinuxDmabufV1(linux_dmabuf); + const interactive_content = try scene.tree.createSceneTree(); const drag_icons = try scene.tree.createSceneTree(); const hidden_tree = try scene.tree.createSceneTree(); From bbb62ac8d8288b19f63d28799157f887c6bf817a Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sun, 27 Apr 2025 12:53:43 +0200 Subject: [PATCH 82/90] linux-drm-syncobj: implement protocol --- river/Server.zig | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/river/Server.zig b/river/Server.zig index cda3a04..2c065d5 100644 --- a/river/Server.zig +++ b/river/Server.zig @@ -63,6 +63,7 @@ security_context_manager: *wlr.SecurityContextManagerV1, shm: *wlr.Shm, drm: ?*wlr.Drm = null, linux_dmabuf: ?*wlr.LinuxDmabufV1 = null, +linux_drm_syncobj_manager: ?*wlr.LinuxDrmSyncobjManagerV1 = null, single_pixel_buffer_manager: *wlr.SinglePixelBufferManagerV1, viewporter: *wlr.Viewporter, @@ -188,6 +189,12 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void { server.linux_dmabuf = try wlr.LinuxDmabufV1.createWithRenderer(wl_server, 4, renderer); } + if (renderer.features.timeline and backend.features.timeline) { + const drm_fd = renderer.getDrmFd(); + if (drm_fd >= 0) { + server.linux_drm_syncobj_manager = wlr.LinuxDrmSyncobjManagerV1.create(wl_server, 1, drm_fd); + } + } if (build_options.xwayland and runtime_xwayland) { server.xwayland = try wlr.Xwayland.create(wl_server, compositor, false); @@ -296,7 +303,12 @@ fn globalFilter(client: *const wl.Client, global: *const wl.Global, server: *Ser /// Returns true if the global is allowlisted for security contexts fn allowlist(server: *Server, global: *const wl.Global) bool { if (server.drm) |drm| if (global == drm.global) return true; - if (server.linux_dmabuf) |linux_dmabuf| if (global == linux_dmabuf.global) return true; + if (server.linux_dmabuf) |linux_dmabuf| { + if (global == linux_dmabuf.global) return true; + } + if (server.linux_drm_syncobj_manager) |linux_drm_syncobj_manager| { + if (global == linux_drm_syncobj_manager.global) return true; + } // We must use the getInterface() approach for dynamically created globals // such as wl_output and wl_seat since the wl_global_create() function will From c111fc9905f0e97ddbc512cda1dd185f2b53e23a Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sun, 27 Apr 2025 12:55:14 +0200 Subject: [PATCH 83/90] river: drop wl_drm support Looks like other compositors have completely dropped this by now. --- river/Server.zig | 8 -------- 1 file changed, 8 deletions(-) diff --git a/river/Server.zig b/river/Server.zig index 2c065d5..58c7eb6 100644 --- a/river/Server.zig +++ b/river/Server.zig @@ -61,7 +61,6 @@ allocator: *wlr.Allocator, security_context_manager: *wlr.SecurityContextManagerV1, shm: *wlr.Shm, -drm: ?*wlr.Drm = null, linux_dmabuf: ?*wlr.LinuxDmabufV1 = null, linux_drm_syncobj_manager: ?*wlr.LinuxDrmSyncobjManagerV1 = null, single_pixel_buffer_manager: *wlr.SinglePixelBufferManagerV1, @@ -181,12 +180,6 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void { }; if (renderer.getTextureFormats(@intFromEnum(wlr.BufferCap.dmabuf)) != null) { - // wl_drm is a legacy interface and all clients should switch to linux_dmabuf. - // However, enough widely used clients still rely on wl_drm that the pragmatic option - // is to keep it around for the near future. - // TODO remove wl_drm support - server.drm = try wlr.Drm.create(wl_server, renderer); - server.linux_dmabuf = try wlr.LinuxDmabufV1.createWithRenderer(wl_server, 4, renderer); } if (renderer.features.timeline and backend.features.timeline) { @@ -302,7 +295,6 @@ fn globalFilter(client: *const wl.Client, global: *const wl.Global, server: *Ser /// Returns true if the global is allowlisted for security contexts fn allowlist(server: *Server, global: *const wl.Global) bool { - if (server.drm) |drm| if (global == drm.global) return true; if (server.linux_dmabuf) |linux_dmabuf| { if (global == linux_dmabuf.global) return true; } From 40294223d40df441b7d60a89f6e0d46a60ad7ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 11 Jun 2025 07:15:58 +0200 Subject: [PATCH 84/90] LayerSurface: drop new_popup link in handleDestroy() This fixes an assertion in wlroots: river: types/wlr_layer_shell_v1.c:55: layer_surface_destroy: Assertion `wl_list_empty(&surface->events.new_popup.listener_list)' failed. --- river/LayerSurface.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/river/LayerSurface.zig b/river/LayerSurface.zig index f63b934..b89c472 100644 --- a/river/LayerSurface.zig +++ b/river/LayerSurface.zig @@ -82,6 +82,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.LayerSurfaceV1), _: *wlr.LayerSurfa layer_surface.map.link.remove(); layer_surface.unmap.link.remove(); layer_surface.commit.link.remove(); + layer_surface.new_popup.link.remove(); layer_surface.destroyPopups(); From c8fb3952f8830b94230e7eb2b0ca44d7a899cb9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 13 Jun 2025 12:23:59 +0200 Subject: [PATCH 85/90] XwaylandView: drop set_decorations link in handleDestroy() Fixes yet another assertion in wlroots: river: xwayland/xwm.c:601: xwayland_surface_destroy: Assertion `wl_list_empty(&xsurface->events.set_decorations.listener_list)' failed. --- river/XwaylandView.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/river/XwaylandView.zig b/river/XwaylandView.zig index 68918ed..f27d040 100644 --- a/river/XwaylandView.zig +++ b/river/XwaylandView.zig @@ -139,6 +139,7 @@ fn handleDestroy(listener: *wl.Listener(void)) void { xwayland_view.dissociate.link.remove(); xwayland_view.request_configure.link.remove(); xwayland_view.set_override_redirect.link.remove(); + xwayland_view.set_decorations.link.remove(); const view = xwayland_view.view; view.impl = .none; From 6385d71c37264adef3258b10cb830b42ee60958a Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Wed, 18 Jun 2025 12:26:46 +0200 Subject: [PATCH 86/90] XwaylandView: remove set_decorations listener on unmap --- river/XwaylandView.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/river/XwaylandView.zig b/river/XwaylandView.zig index f27d040..836de81 100644 --- a/river/XwaylandView.zig +++ b/river/XwaylandView.zig @@ -139,7 +139,6 @@ fn handleDestroy(listener: *wl.Listener(void)) void { xwayland_view.dissociate.link.remove(); xwayland_view.request_configure.link.remove(); xwayland_view.set_override_redirect.link.remove(); - xwayland_view.set_decorations.link.remove(); const view = xwayland_view.view; view.impl = .none; @@ -221,6 +220,7 @@ fn handleUnmap(listener: *wl.Listener(void)) void { // Remove listeners that are only active while mapped xwayland_view.set_title.link.remove(); xwayland_view.set_class.link.remove(); + xwayland_view.set_decorations.link.remove(); xwayland_view.request_fullscreen.link.remove(); xwayland_view.request_minimize.link.remove(); From 7fc7b570f0e5d4432699af2df7f269e51b6f2a01 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Wed, 18 Jun 2025 13:46:17 +0200 Subject: [PATCH 87/90] View: workaround wlr_box_intersect() quirk --- river/View.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/river/View.zig b/river/View.zig index 3d57ca4..3ba48f5 100644 --- a/river/View.zig +++ b/river/View.zig @@ -446,7 +446,11 @@ pub fn updateSceneState(view: *View) void { for (&view.borders, &border_boxes) |border, *border_box| { border_box.x += box.x; border_box.y += box.y; - _ = border_box.intersection(border_box, &output_box); + if (!border_box.intersection(border_box, &output_box)) { + // TODO(wlroots): remove this redundant code after fixed upstream + // https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/5084 + border_box.* = .{ .x = 0, .y = 0, .width = 0, .height = 0 }; + } border_box.x -= box.x; border_box.y -= box.y; From 6af8369624262533988a0c41edf4b51b7bb51c51 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Wed, 18 Jun 2025 14:06:52 +0200 Subject: [PATCH 88/90] build: bump version to 0.3.10 --- build.zig.zon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig.zon b/build.zig.zon index 9de42f7..99942b6 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -5,7 +5,7 @@ // When a release is tagged, the "-dev" suffix should be removed for the // commit that gets tagged. Directly after the tagged commit, the version // should be bumped and the "-dev" suffix added. - .version = "0.3.10-dev", + .version = "0.3.10", .paths = .{""}, .dependencies = .{ .pixman = .{ From ed85b4401e246458699452803b2479830439ae99 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Wed, 18 Jun 2025 14:14:46 +0200 Subject: [PATCH 89/90] build: bump version to 0.3.11-dev --- build.zig.zon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig.zon b/build.zig.zon index 99942b6..cc8d63e 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -5,7 +5,7 @@ // When a release is tagged, the "-dev" suffix should be removed for the // commit that gets tagged. Directly after the tagged commit, the version // should be bumped and the "-dev" suffix added. - .version = "0.3.10", + .version = "0.3.11-dev", .paths = .{""}, .dependencies = .{ .pixman = .{ From fcf8b1e44293875627e1b3b3223809ed01ebfcab Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 26 Jun 2025 11:01:19 +0200 Subject: [PATCH 90/90] Cursor: fix formatting This is a behavior change in zig 0.14 --- river/Cursor.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/river/Cursor.zig b/river/Cursor.zig index cda18ad..241cbc1 100644 --- a/river/Cursor.zig +++ b/river/Cursor.zig @@ -1279,7 +1279,7 @@ fn warp(cursor: *Cursor) void { }; if (!output_layout_box.containsPoint(cursor.wlr_cursor.x, cursor.wlr_cursor.y) or (usable_layout_box.containsPoint(cursor.wlr_cursor.x, cursor.wlr_cursor.y) and - !target_box.containsPoint(cursor.wlr_cursor.x, cursor.wlr_cursor.y))) + !target_box.containsPoint(cursor.wlr_cursor.x, cursor.wlr_cursor.y))) { const lx: f64 = @floatFromInt(target_box.x + @divTrunc(target_box.width, 2)); const ly: f64 = @floatFromInt(target_box.y + @divTrunc(target_box.height, 2));