diff --git a/deps/zig-wayland b/deps/zig-wayland index d693b37..0dd1bee 160000 --- a/deps/zig-wayland +++ b/deps/zig-wayland @@ -1 +1 @@ -Subproject commit d693b3704ee73762c71a68d634ef1a538c3307bd +Subproject commit 0dd1bee2dea065d45ce674c5b3ece2fda38f775d diff --git a/river/Control.zig b/river/Control.zig index eca712a..3278b82 100644 --- a/river/Control.zig +++ b/river/Control.zig @@ -37,7 +37,7 @@ global: *wl.Global, args_map: std.AutoHashMap(u32, std.ArrayList([]const u8)), -server_destroy: wl.Listener(*wl.Server) = undefined, +server_destroy: wl.Listener(*wl.Server) = wl.Listener(*wl.Server).init(handleServerDestroy), pub fn init(self: *Self, server: *Server) !void { self.* = .{ @@ -45,7 +45,6 @@ pub fn init(self: *Self, server: *Server) !void { .args_map = std.AutoHashMap(u32, std.ArrayList([]const u8)).init(util.gpa), }; - self.server_destroy.setNotify(handleServerDestroy); server.wl_server.addDestroyListener(&self.server_destroy); } diff --git a/river/Cursor.zig b/river/Cursor.zig index f1dff59..7e8d427 100644 --- a/river/Cursor.zig +++ b/river/Cursor.zig @@ -61,12 +61,18 @@ xcursor_manager: *wlr.XcursorManager, /// Number of distinct buttons currently pressed pressed_count: u32 = 0, -axis: wl.Listener(*wlr.Pointer.event.Axis) = undefined, -button: wl.Listener(*wlr.Pointer.event.Button) = undefined, -frame: wl.Listener(*wlr.Cursor) = undefined, -motion_absolute: wl.Listener(*wlr.Pointer.event.MotionAbsolute) = undefined, -motion: wl.Listener(*wlr.Pointer.event.Motion) = undefined, -request_set_cursor: wl.Listener(*wlr.Seat.event.RequestSetCursor) = undefined, +axis: wl.Listener(*wlr.Pointer.event.Axis) = wl.Listener(*wlr.Pointer.event.Axis).init(handleAxis), +frame: wl.Listener(*wlr.Cursor) = wl.Listener(*wlr.Cursor).init(handleFrame), +// zig fmt: off +button: wl.Listener(*wlr.Pointer.event.Button) = + wl.Listener(*wlr.Pointer.event.Button).init(handleButton), +motion_absolute: wl.Listener(*wlr.Pointer.event.MotionAbsolute) = + wl.Listener(*wlr.Pointer.event.MotionAbsolute).init(handleMotionAbsolute), +motion: wl.Listener(*wlr.Pointer.event.Motion) = + wl.Listener(*wlr.Pointer.event.Motion).init(handleMotion), +request_set_cursor: wl.Listener(*wlr.Seat.event.RequestSetCursor) = + wl.Listener(*wlr.Seat.event.RequestSetCursor).init(handleRequestSetCursor), +// zig fmt: on pub fn init(self: *Self, seat: *Seat) !void { const wlr_cursor = try wlr.Cursor.create(); @@ -92,23 +98,12 @@ pub fn init(self: *Self, seat: *Seat) !void { // can choose how we want to process them, forwarding them to clients and // moving the cursor around. See following post for more detail: // https://drewdevault.com/2018/07/17/Input-handling-in-wlroots.html - self.axis.setNotify(handleAxis); - self.wlr_cursor.events.axis.add(&self.axis); - - self.button.setNotify(handleButton); - self.wlr_cursor.events.button.add(&self.button); - - self.frame.setNotify(handleFrame); - self.wlr_cursor.events.frame.add(&self.frame); - - self.motion_absolute.setNotify(handleMotionAbsolute); - self.wlr_cursor.events.motion_absolute.add(&self.motion_absolute); - - self.motion.setNotify(handleMotion); - self.wlr_cursor.events.motion.add(&self.motion); - - self.request_set_cursor.setNotify(handleRequestSetCursor); - self.seat.wlr_seat.events.request_set_cursor.add(&self.request_set_cursor); + wlr_cursor.events.axis.add(&self.axis); + wlr_cursor.events.button.add(&self.button); + wlr_cursor.events.frame.add(&self.frame); + wlr_cursor.events.motion_absolute.add(&self.motion_absolute); + wlr_cursor.events.motion.add(&self.motion); + seat.wlr_seat.events.request_set_cursor.add(&self.request_set_cursor); } pub fn deinit(self: *Self) void { diff --git a/river/Decoration.zig b/river/Decoration.zig index 70cd138..2ad773d 100644 --- a/river/Decoration.zig +++ b/river/Decoration.zig @@ -29,8 +29,12 @@ server: *Server, xdg_toplevel_decoration: *wlr.XdgToplevelDecorationV1, -destroy: wl.Listener(*wlr.XdgToplevelDecorationV1) = undefined, -request_mode: wl.Listener(*wlr.XdgToplevelDecorationV1) = undefined, +// zig fmt: off +destroy: wl.Listener(*wlr.XdgToplevelDecorationV1) = + wl.Listener(*wlr.XdgToplevelDecorationV1).init(handleDestroy), +request_mode: wl.Listener(*wlr.XdgToplevelDecorationV1) = + wl.Listener(*wlr.XdgToplevelDecorationV1).init(handleRequestMode), +// zig fmt: on pub fn init( self: *Self, @@ -39,11 +43,8 @@ pub fn init( ) void { self.* = .{ .server = server, .xdg_toplevel_decoration = xdg_toplevel_decoration }; - self.destroy.setNotify(handleDestroy); - self.xdg_toplevel_decoration.events.destroy.add(&self.destroy); - - self.request_mode.setNotify(handleRequestMode); - self.xdg_toplevel_decoration.events.request_mode.add(&self.request_mode); + xdg_toplevel_decoration.events.destroy.add(&self.destroy); + xdg_toplevel_decoration.events.request_mode.add(&self.request_mode); handleRequestMode(&self.request_mode, self.xdg_toplevel_decoration); } diff --git a/river/DecorationManager.zig b/river/DecorationManager.zig index b4d6383..f2b9809 100644 --- a/river/DecorationManager.zig +++ b/river/DecorationManager.zig @@ -30,7 +30,10 @@ server: *Server, xdg_decoration_manager: *wlr.XdgDecorationManagerV1, -new_toplevel_decoration: wl.Listener(*wlr.XdgToplevelDecorationV1) = undefined, +// zig fmt: off +new_toplevel_decoration: wl.Listener(*wlr.XdgToplevelDecorationV1) = + wl.Listener(*wlr.XdgToplevelDecorationV1).init(handleNewToplevelDecoration), +// zig fmt: on pub fn init(self: *Self, server: *Server) !void { self.* = .{ @@ -38,7 +41,6 @@ pub fn init(self: *Self, server: *Server) !void { .xdg_decoration_manager = try wlr.XdgDecorationManagerV1.create(server.wl_server), }; - self.new_toplevel_decoration.setNotify(handleNewToplevelDecoration); self.xdg_decoration_manager.events.new_toplevel_decoration.add(&self.new_toplevel_decoration); } diff --git a/river/DragIcon.zig b/river/DragIcon.zig index 7c77ff2..ee9cc91 100644 --- a/river/DragIcon.zig +++ b/river/DragIcon.zig @@ -28,12 +28,10 @@ const Seat = @import("Seat.zig"); seat: *Seat, wlr_drag_icon: *wlr.Drag.Icon, -destroy: wl.Listener(*wlr.Drag.Icon) = undefined, +destroy: wl.Listener(*wlr.Drag.Icon) = wl.Listener(*wlr.Drag.Icon).init(handleDestroy), pub fn init(self: *Self, seat: *Seat, wlr_drag_icon: *wlr.Drag.Icon) void { self.* = .{ .seat = seat, .wlr_drag_icon = wlr_drag_icon }; - - self.destroy.setNotify(handleDestroy); wlr_drag_icon.events.destroy.add(&self.destroy); } diff --git a/river/InputManager.zig b/river/InputManager.zig index a67f07d..f085f82 100644 --- a/river/InputManager.zig +++ b/river/InputManager.zig @@ -32,6 +32,7 @@ const View = @import("View.zig"); const default_seat_name = "default"; server: *Server, +new_input: wl.Listener(*wlr.InputDevice) = wl.Listener(*wlr.InputDevice).init(handleNewInput), idle: *wlr.Idle, input_inhibit_manager: *wlr.InputInhibitManager, @@ -42,11 +43,16 @@ seats: std.TailQueue(Seat) = .{}, exclusive_client: ?*wl.Client = null, -inhibit_activate: wl.Listener(*wlr.InputInhibitManager) = undefined, -inhibit_deactivate: wl.Listener(*wlr.InputInhibitManager) = undefined, -new_input: wl.Listener(*wlr.InputDevice) = undefined, -new_virtual_pointer: wl.Listener(*wlr.VirtualPointerManagerV1.event.NewPointer) = undefined, -new_virtual_keyboard: wl.Listener(*wlr.VirtualKeyboardV1) = undefined, +// zig fmt: off +inhibit_activate: wl.Listener(*wlr.InputInhibitManager) = + wl.Listener(*wlr.InputInhibitManager).init(handleInhibitActivate), +inhibit_deactivate: wl.Listener(*wlr.InputInhibitManager) = + wl.Listener(*wlr.InputInhibitManager).init(handleInhibitDeactivate), +new_virtual_pointer: wl.Listener(*wlr.VirtualPointerManagerV1.event.NewPointer) = + wl.Listener(*wlr.VirtualPointerManagerV1.event.NewPointer).init(handleNewVirtualPointer), +new_virtual_keyboard: wl.Listener(*wlr.VirtualKeyboardV1) = + wl.Listener(*wlr.VirtualKeyboardV1).init(handleNewVirtualKeyboard), +// zig fmt: on pub fn init(self: *Self, server: *Server) !void { const seat_node = try util.gpa.create(std.TailQueue(Seat).Node); @@ -66,19 +72,10 @@ pub fn init(self: *Self, server: *Server) !void { if (build_options.xwayland) server.xwayland.setSeat(self.defaultSeat().wlr_seat); - self.inhibit_activate.setNotify(handleInhibitActivate); + server.backend.events.new_input.add(&self.new_input); self.input_inhibit_manager.events.activate.add(&self.inhibit_activate); - - self.inhibit_deactivate.setNotify(handleInhibitDeactivate); self.input_inhibit_manager.events.deactivate.add(&self.inhibit_deactivate); - - self.new_input.setNotify(handleNewInput); - self.server.backend.events.new_input.add(&self.new_input); - - self.new_virtual_pointer.setNotify(handleNewVirtualPointer); self.virtual_pointer_manager.events.new_virtual_pointer.add(&self.new_virtual_pointer); - - self.new_virtual_keyboard.setNotify(handleNewVirtualKeyboard); self.virtual_keyboard_manager.events.new_virtual_keyboard.add(&self.new_virtual_keyboard); } diff --git a/river/Keyboard.zig b/river/Keyboard.zig index 42a59c4..19c3a6e 100644 --- a/river/Keyboard.zig +++ b/river/Keyboard.zig @@ -30,9 +30,9 @@ const Seat = @import("Seat.zig"); seat: *Seat, input_device: *wlr.InputDevice, -key: wl.Listener(*wlr.Keyboard.event.Key) = undefined, -modifiers: wl.Listener(*wlr.Keyboard) = undefined, -destroy: wl.Listener(*wlr.Keyboard) = undefined, +key: wl.Listener(*wlr.Keyboard.event.Key) = wl.Listener(*wlr.Keyboard.event.Key).init(handleKey), +modifiers: wl.Listener(*wlr.Keyboard) = wl.Listener(*wlr.Keyboard).init(handleModifiers), +destroy: wl.Listener(*wlr.Keyboard) = wl.Listener(*wlr.Keyboard).init(handleDestroy), pub fn init(self: *Self, seat: *Seat, input_device: *wlr.InputDevice) !void { self.* = .{ @@ -62,13 +62,8 @@ pub fn init(self: *Self, seat: *Seat, input_device: *wlr.InputDevice) !void { const config = &seat.input_manager.server.config; wlr_keyboard.setRepeatInfo(config.repeat_rate, config.repeat_delay); - self.key.setNotify(handleKey); wlr_keyboard.events.key.add(&self.key); - - self.modifiers.setNotify(handleModifiers); wlr_keyboard.events.modifiers.add(&self.modifiers); - - self.destroy.setNotify(handleDestroy); wlr_keyboard.events.destroy.add(&self.destroy); } diff --git a/river/LayerSurface.zig b/river/LayerSurface.zig index 341a060..54de498 100644 --- a/river/LayerSurface.zig +++ b/river/LayerSurface.zig @@ -35,13 +35,13 @@ box: Box = undefined, state: wlr.LayerSurfaceV1.State, // Listeners active the entire lifetime of the layser surface -destroy: wl.Listener(*wlr.LayerSurfaceV1) = undefined, -map: wl.Listener(*wlr.LayerSurfaceV1) = undefined, -unmap: wl.Listener(*wlr.LayerSurfaceV1) = undefined, +destroy: wl.Listener(*wlr.LayerSurfaceV1) = wl.Listener(*wlr.LayerSurfaceV1).init(handleDestroy), +map: wl.Listener(*wlr.LayerSurfaceV1) = wl.Listener(*wlr.LayerSurfaceV1).init(handleMap), +unmap: wl.Listener(*wlr.LayerSurfaceV1) = wl.Listener(*wlr.LayerSurfaceV1).init(handleUnmap), // Listeners only active while the layer surface is mapped -commit: wl.Listener(*wlr.Surface) = undefined, -new_popup: wl.Listener(*wlr.XdgPopup) = undefined, +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 init(self: *Self, output: *Output, wlr_layer_surface: *wlr.LayerSurfaceV1) void { self.* = .{ @@ -60,13 +60,8 @@ pub fn init(self: *Self, output: *Output, wlr_layer_surface: *wlr.LayerSurfaceV1 list.remove(node); // Set up listeners that are active for the entire lifetime of the layer surface - self.destroy.setNotify(handleDestroy); self.wlr_layer_surface.events.destroy.add(&self.destroy); - - self.map.setNotify(handleMap); self.wlr_layer_surface.events.map.add(&self.map); - - self.unmap.setNotify(handleUnmap); self.wlr_layer_surface.events.unmap.add(&self.unmap); } @@ -90,10 +85,7 @@ fn handleMap(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_surface: *wl log.debug(.layer_shell, "layer surface '{}' mapped", .{wlr_layer_surface.namespace}); // Add listeners that are only active while mapped - self.commit.setNotify(handleCommit); wlr_layer_surface.surface.events.commit.add(&self.commit); - - self.new_popup.setNotify(handleNewPopup); wlr_layer_surface.events.new_popup.add(&self.new_popup); wlr_layer_surface.surface.sendEnter(wlr_layer_surface.output.?); diff --git a/river/Output.zig b/river/Output.zig index c614b6e..2a70c25 100644 --- a/river/Output.zig +++ b/river/Output.zig @@ -76,10 +76,10 @@ attach_mode: AttachMode = .top, /// List of status tracking objects relaying changes to this output to clients. status_trackers: std.SinglyLinkedList(OutputStatus) = .{}, -destroy: wl.Listener(*wlr.Output) = undefined, -enable: wl.Listener(*wlr.Output) = undefined, -frame: wl.Listener(*wlr.Output) = undefined, -mode: wl.Listener(*wlr.Output) = undefined, +destroy: wl.Listener(*wlr.Output) = wl.Listener(*wlr.Output).init(handleDestroy), +enable: wl.Listener(*wlr.Output) = wl.Listener(*wlr.Output).init(handleEnable), +frame: wl.Listener(*wlr.Output) = wl.Listener(*wlr.Output).init(handleFrame), +mode: wl.Listener(*wlr.Output) = wl.Listener(*wlr.Output).init(handleMode), pub fn init(self: *Self, root: *Root, wlr_output: *wlr.Output) !void { // Some backends don't have modes. DRM+KMS does, and we need to set a mode @@ -104,16 +104,9 @@ pub fn init(self: *Self, root: *Root, wlr_output: *wlr.Output) !void { }; wlr_output.data = @ptrToInt(self); - self.destroy.setNotify(handleDestroy); wlr_output.events.destroy.add(&self.destroy); - - self.enable.setNotify(handleEnable); wlr_output.events.enable.add(&self.enable); - - self.frame.setNotify(handleFrame); wlr_output.events.frame.add(&self.frame); - - self.mode.setNotify(handleMode); wlr_output.events.mode.add(&self.mode); if (wlr_output.isNoop()) { diff --git a/river/Root.zig b/river/Root.zig index 36493ba..e05d025 100644 --- a/river/Root.zig +++ b/river/Root.zig @@ -41,17 +41,22 @@ const DragIcon = @import("DragIcon.zig"); const min_size = 50; server: *Server, -new_output: wl.Listener(*wlr.Output) = undefined, +new_output: wl.Listener(*wlr.Output) = wl.Listener(*wlr.Output).init(handleNewOutput), output_layout: *wlr.OutputLayout, -layout_change: wl.Listener(*wlr.OutputLayout) = undefined, +layout_change: wl.Listener(*wlr.OutputLayout) = wl.Listener(*wlr.OutputLayout).init(handleLayoutChange), +// zig fmt: off output_manager: *wlr.OutputManagerV1, -manager_apply: wl.Listener(*wlr.OutputConfigurationV1) = undefined, -manager_test: wl.Listener(*wlr.OutputConfigurationV1) = undefined, +manager_apply: wl.Listener(*wlr.OutputConfigurationV1) = + wl.Listener(*wlr.OutputConfigurationV1).init(handleManagerApply), +manager_test: wl.Listener(*wlr.OutputConfigurationV1) = + wl.Listener(*wlr.OutputConfigurationV1).init(handleManagerTest), power_manager: *wlr.OutputPowerManagerV1, -power_manager_set_mode: wl.Listener(*wlr.OutputPowerManagerV1.event.SetMode) = undefined, +power_manager_set_mode: wl.Listener(*wlr.OutputPowerManagerV1.event.SetMode) = + wl.Listener(*wlr.OutputPowerManagerV1.event.SetMode).init(handlePowerManagerSetMode), +// zig fmt: on /// A list of all outputs all_outputs: std.TailQueue(*Output) = .{}, @@ -97,19 +102,10 @@ pub fn init(self: *Self, server: *Server) !void { const noop_wlr_output = try server.noop_backend.noopAddOutput(); try self.noop_output.init(self, noop_wlr_output); - self.new_output.setNotify(handleNewOutput); server.backend.events.new_output.add(&self.new_output); - - self.manager_apply.setNotify(handleOutputManagerApply); self.output_manager.events.apply.add(&self.manager_apply); - - self.manager_test.setNotify(handleOutputManagerTest); self.output_manager.events.@"test".add(&self.manager_test); - - self.layout_change.setNotify(handleOutputLayoutChange); self.output_layout.events.change.add(&self.layout_change); - - self.power_manager_set_mode.setNotify(handleOutputPowerManagementSetMode); self.power_manager.events.set_mode.add(&self.power_manager_set_mode); } @@ -389,7 +385,7 @@ fn commitTransaction(self: *Self) void { } /// Send the new output configuration to all wlr-output-manager clients -fn handleOutputLayoutChange( +fn handleLayoutChange( listener: *wl.Listener(*wlr.OutputLayout), output_layout: *wlr.OutputLayout, ) void { @@ -402,7 +398,7 @@ fn handleOutputLayoutChange( self.output_manager.setConfiguration(config); } -fn handleOutputManagerApply( +fn handleManagerApply( listener: *wl.Listener(*wlr.OutputConfigurationV1), config: *wlr.OutputConfigurationV1, ) void { @@ -423,7 +419,7 @@ fn handleOutputManagerApply( self.output_manager.setConfiguration(applied_config); } -fn handleOutputManagerTest( +fn handleManagerTest( listener: *wl.Listener(*wlr.OutputConfigurationV1), config: *wlr.OutputConfigurationV1, ) void { @@ -560,7 +556,7 @@ fn createHead(self: *Self, output: *Output, config: *wlr.OutputConfigurationV1) } } -fn handleOutputPowerManagementSetMode( +fn handlePowerManagerSetMode( listener: *wl.Listener(*wlr.OutputPowerManagerV1.event.SetMode), event: *wlr.OutputPowerManagerV1.event.SetMode, ) void { diff --git a/river/Seat.zig b/river/Seat.zig index 4a00d1a..c725053 100644 --- a/river/Seat.zig +++ b/river/Seat.zig @@ -72,10 +72,15 @@ focus_stack: ViewStack(*View) = .{}, /// List of status tracking objects relaying changes to this seat to clients. status_trackers: std.SinglyLinkedList(SeatStatus) = .{}, -request_set_selection: wl.Listener(*wlr.Seat.event.RequestSetSelection) = undefined, -request_start_drag: wl.Listener(*wlr.Seat.event.RequestStartDrag) = undefined, -start_drag: wl.Listener(*wlr.Drag) = undefined, -request_set_primary_selection: wl.Listener(*wlr.Seat.event.RequestSetPrimarySelection) = undefined, +// zig fmt: off +request_set_selection: wl.Listener(*wlr.Seat.event.RequestSetSelection) = + wl.Listener(*wlr.Seat.event.RequestSetSelection).init(handleRequestSetSelection), +request_start_drag: wl.Listener(*wlr.Seat.event.RequestStartDrag) = + wl.Listener(*wlr.Seat.event.RequestStartDrag).init(handleRequestStartDrag), +start_drag: wl.Listener(*wlr.Drag) = wl.Listener(*wlr.Drag).init(handleStartDrag), +request_set_primary_selection: wl.Listener(*wlr.Seat.event.RequestSetPrimarySelection) = + wl.Listener(*wlr.Seat.event.RequestSetPrimarySelection).init(handleRequestSetPrimarySelection), +// zig fmt: on pub fn init(self: *Self, input_manager: *InputManager, name: [*:0]const u8) !void { self.* = .{ @@ -88,16 +93,9 @@ pub fn init(self: *Self, input_manager: *InputManager, name: [*:0]const u8) !voi try self.cursor.init(self); - self.request_set_selection.setNotify(handleRequestSetSelection); self.wlr_seat.events.request_set_selection.add(&self.request_set_selection); - - self.request_start_drag.setNotify(handleRequestStartDrag); self.wlr_seat.events.request_start_drag.add(&self.request_start_drag); - - self.start_drag.setNotify(handleStartDrag); self.wlr_seat.events.start_drag.add(&self.start_drag); - - self.request_set_primary_selection.setNotify(handleRequestPrimarySelection); self.wlr_seat.events.request_set_primary_selection.add(&self.request_set_primary_selection); } @@ -399,7 +397,7 @@ fn handleStartDrag( self.cursor.mode = .passthrough; } -fn handleRequestPrimarySelection( +fn handleRequestSetPrimarySelection( listener: *wl.Listener(*wlr.Seat.event.RequestSetPrimarySelection), event: *wlr.Seat.event.RequestSetPrimarySelection, ) void { diff --git a/river/StatusManager.zig b/river/StatusManager.zig index f630dde..0cfdec0 100644 --- a/river/StatusManager.zig +++ b/river/StatusManager.zig @@ -34,14 +34,13 @@ const Server = @import("Server.zig"); global: *wl.Global, -server_destroy: wl.Listener(*wl.Server) = undefined, +server_destroy: wl.Listener(*wl.Server) = wl.Listener(*wl.Server).init(handleServerDestroy), pub fn init(self: *Self, server: *Server) !void { self.* = .{ .global = try wl.Global.create(server.wl_server, zriver.StatusManagerV1, 1, *Self, self, bind), }; - self.server_destroy.setNotify(handleServerDestroy); server.wl_server.addDestroyListener(&self.server_destroy); } diff --git a/river/View.zig b/river/View.zig index af913f0..b0c99dc 100644 --- a/river/View.zig +++ b/river/View.zig @@ -126,9 +126,14 @@ draw_borders: bool = true, /// This is created when the view is mapped and destroyed with the view foreign_toplevel_handle: ?*wlr.ForeignToplevelHandleV1 = null, -foreign_activate: wl.Listener(*wlr.ForeignToplevelHandleV1.event.Activated) = undefined, -foreign_fullscreen: wl.Listener(*wlr.ForeignToplevelHandleV1.event.Fullscreen) = undefined, -foreign_close: wl.Listener(*wlr.ForeignToplevelHandleV1) = undefined, +// zig fmt: off +foreign_activate: wl.Listener(*wlr.ForeignToplevelHandleV1.event.Activated) = + wl.Listener(*wlr.ForeignToplevelHandleV1.event.Activated).init(handleForeignActivate), +foreign_fullscreen: wl.Listener(*wlr.ForeignToplevelHandleV1.event.Fullscreen) = + wl.Listener(*wlr.ForeignToplevelHandleV1.event.Fullscreen).init(handleForeignFullscreen), +foreign_close: wl.Listener(*wlr.ForeignToplevelHandleV1) = + wl.Listener(*wlr.ForeignToplevelHandleV1).init(handleForeignClose), +// zig fmt: on pub fn init(self: *Self, output: *Output, tags: u32, surface: anytype) void { self.* = .{ @@ -369,8 +374,8 @@ pub fn getAppId(self: Self) ?[*:0]const u8 { pub fn applyConstraints(self: *Self) void { const constraints = self.getConstraints(); const box = &self.pending.box; - box.width = std.math.clamp(box.width, constraints.min_width, constraints.max_width); - box.height = std.math.clamp(box.height, constraints.min_height, constraints.max_height); + box.width = math.clamp(box.width, constraints.min_width, constraints.max_width); + box.height = math.clamp(box.height, constraints.min_height, constraints.max_height); } /// Return bounds on the dimensions of the view @@ -448,13 +453,8 @@ pub fn map(self: *Self) void { return; }; - self.foreign_activate.setNotify(handleForeignActivate); self.foreign_toplevel_handle.?.events.request_activate.add(&self.foreign_activate); - - self.foreign_fullscreen.setNotify(handleForeignFullscreen); self.foreign_toplevel_handle.?.events.request_fullscreen.add(&self.foreign_fullscreen); - - self.foreign_close.setNotify(handleForeignClose); self.foreign_toplevel_handle.?.events.request_close.add(&self.foreign_close); if (self.getTitle()) |s| self.foreign_toplevel_handle.?.setTitle(s); diff --git a/river/XdgPopup.zig b/river/XdgPopup.zig index abdced9..fa7eba1 100644 --- a/river/XdgPopup.zig +++ b/river/XdgPopup.zig @@ -36,8 +36,8 @@ parent_box: *const Box, /// The corresponding wlroots object wlr_xdg_popup: *wlr.XdgPopup, -destroy: wl.Listener(*wlr.XdgSurface) = undefined, -new_popup: wl.Listener(*wlr.XdgPopup) = undefined, +destroy: wl.Listener(*wlr.XdgSurface) = wl.Listener(*wlr.XdgSurface).init(handleDestroy), +new_popup: wl.Listener(*wlr.XdgPopup) = wl.Listener(*wlr.XdgPopup).init(handleNewPopup), pub fn init(self: *Self, output: *Output, parent_box: *const Box, wlr_xdg_popup: *wlr.XdgPopup) void { self.* = .{ @@ -52,10 +52,7 @@ pub fn init(self: *Self, output: *Output, parent_box: *const Box, wlr_xdg_popup: box.y -= parent_box.y; wlr_xdg_popup.unconstrainFromBox(&box); - self.destroy.setNotify(handleDestroy); wlr_xdg_popup.base.events.destroy.add(&self.destroy); - - self.new_popup.setNotify(handleNewPopup); wlr_xdg_popup.base.events.new_popup.add(&self.new_popup); } diff --git a/river/XdgToplevel.zig b/river/XdgToplevel.zig index 689a4aa..a517769 100644 --- a/river/XdgToplevel.zig +++ b/river/XdgToplevel.zig @@ -37,30 +37,30 @@ view: *View, xdg_surface: *wlr.XdgSurface, // Listeners that are always active over the view's lifetime -destroy: wl.Listener(*wlr.XdgSurface) = undefined, -map: wl.Listener(*wlr.XdgSurface) = undefined, -unmap: wl.Listener(*wlr.XdgSurface) = undefined, +destroy: wl.Listener(*wlr.XdgSurface) = wl.Listener(*wlr.XdgSurface).init(handleDestroy), +map: wl.Listener(*wlr.XdgSurface) = wl.Listener(*wlr.XdgSurface).init(handleMap), +unmap: wl.Listener(*wlr.XdgSurface) = wl.Listener(*wlr.XdgSurface).init(handleUnmap), // Listeners that are only active while the view is mapped -commit: wl.Listener(*wlr.Surface) = undefined, -new_popup: wl.Listener(*wlr.XdgPopup) = undefined, -request_fullscreen: wl.Listener(*wlr.XdgToplevel.event.SetFullscreen) = undefined, -request_move: wl.Listener(*wlr.XdgToplevel.event.Move) = undefined, -request_resize: wl.Listener(*wlr.XdgToplevel.event.Resize) = undefined, -set_title: wl.Listener(*wlr.XdgSurface) = undefined, +commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit), +new_popup: wl.Listener(*wlr.XdgPopup) = wl.Listener(*wlr.XdgPopup).init(handleNewPopup), +// zig fmt: off +request_fullscreen: wl.Listener(*wlr.XdgToplevel.event.SetFullscreen) = + wl.Listener(*wlr.XdgToplevel.event.SetFullscreen).init(handleRequestFullscreen), +request_move: wl.Listener(*wlr.XdgToplevel.event.Move) = + wl.Listener(*wlr.XdgToplevel.event.Move).init(handleRequestMove), +request_resize: wl.Listener(*wlr.XdgToplevel.event.Resize) = + wl.Listener(*wlr.XdgToplevel.event.Resize).init(handleRequestResize), +// zig fmt: on +set_title: wl.Listener(*wlr.XdgSurface) = wl.Listener(*wlr.XdgSurface).init(handleSetTitle), pub fn init(self: *Self, view: *View, xdg_surface: *wlr.XdgSurface) void { self.* = .{ .view = view, .xdg_surface = xdg_surface }; xdg_surface.data = @ptrToInt(self); // Add listeners that are active over the view's entire lifetime - self.destroy.setNotify(handleDestroy); self.xdg_surface.events.destroy.add(&self.destroy); - - self.map.setNotify(handleMap); self.xdg_surface.events.map.add(&self.map); - - self.unmap.setNotify(handleUnmap); self.xdg_surface.events.unmap.add(&self.unmap); } @@ -159,22 +159,11 @@ fn handleMap(listener: *wl.Listener(*wlr.XdgSurface), xdg_surface: *wlr.XdgSurfa const toplevel = self.xdg_surface.role_data.toplevel; // Add listeners that are only active while mapped - self.commit.setNotify(handleCommit); self.xdg_surface.surface.events.commit.add(&self.commit); - - self.new_popup.setNotify(handleNewPopup); self.xdg_surface.events.new_popup.add(&self.new_popup); - - self.request_fullscreen.setNotify(handleRequestFullscreen); toplevel.events.request_fullscreen.add(&self.request_fullscreen); - - self.request_move.setNotify(handleRequestMove); toplevel.events.request_move.add(&self.request_move); - - self.request_resize.setNotify(handleRequestResize); toplevel.events.request_resize.add(&self.request_resize); - - self.set_title.setNotify(handleSetTitle); toplevel.events.set_title.add(&self.set_title); view.surface = self.xdg_surface.surface; diff --git a/river/XwaylandUnmanaged.zig b/river/XwaylandUnmanaged.zig index 003693d..026c4f9 100644 --- a/river/XwaylandUnmanaged.zig +++ b/river/XwaylandUnmanaged.zig @@ -32,28 +32,24 @@ root: *Root, xwayland_surface: *wlr.XwaylandSurface, // Listeners that are always active over the view's lifetime -request_configure: wl.Listener(*wlr.XwaylandSurface.event.Configure) = undefined, -destroy: wl.Listener(*wlr.XwaylandSurface) = undefined, -map: wl.Listener(*wlr.XwaylandSurface) = undefined, -unmap: wl.Listener(*wlr.XwaylandSurface) = undefined, +// zig fmt: off +request_configure: wl.Listener(*wlr.XwaylandSurface.event.Configure) = + wl.Listener(*wlr.XwaylandSurface.event.Configure).init(handleRequestConfigure), +// zig fmt: on +destroy: wl.Listener(*wlr.XwaylandSurface) = wl.Listener(*wlr.XwaylandSurface).init(handleDestroy), +map: wl.Listener(*wlr.XwaylandSurface) = wl.Listener(*wlr.XwaylandSurface).init(handleMap), +unmap: wl.Listener(*wlr.XwaylandSurface) = wl.Listener(*wlr.XwaylandSurface).init(handleUnmap), // Listeners that are only active while the view is mapped -commit: wl.Listener(*wlr.Surface) = undefined, +commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit), pub fn init(self: *Self, root: *Root, xwayland_surface: *wlr.XwaylandSurface) void { self.* = .{ .root = root, .xwayland_surface = xwayland_surface }; // Add listeners that are active over the view's entire lifetime - self.request_configure.setNotify(handleRequestConfigure); xwayland_surface.events.request_configure.add(&self.request_configure); - - self.destroy.setNotify(handleDestroy); xwayland_surface.events.destroy.add(&self.destroy); - - self.map.setNotify(handleMap); xwayland_surface.events.map.add(&self.map); - - self.unmap.setNotify(handleUnmap); xwayland_surface.events.unmap.add(&self.unmap); } @@ -100,7 +96,6 @@ fn handleMap(listener: *wl.Listener(*wlr.XwaylandSurface), xwayland_surface: *wl root.xwayland_unmanaged_views.prepend(node); // Add listeners that are only active while mapped - self.commit.setNotify(handleCommit); xwayland_surface.surface.?.events.commit.add(&self.commit); // TODO: handle keyboard focus diff --git a/river/XwaylandView.zig b/river/XwaylandView.zig index 09da843..07e54a9 100644 --- a/river/XwaylandView.zig +++ b/river/XwaylandView.zig @@ -34,30 +34,23 @@ view: *View, xwayland_surface: *wlr.XwaylandSurface, // Listeners that are always active over the view's lifetime -destroy: wl.Listener(*wlr.XwaylandSurface) = undefined, -map: wl.Listener(*wlr.XwaylandSurface) = undefined, -unmap: wl.Listener(*wlr.XwaylandSurface) = undefined, -title: wl.Listener(*wlr.XwaylandSurface) = undefined, +destroy: wl.Listener(*wlr.XwaylandSurface) = wl.Listener(*wlr.XwaylandSurface).init(handleDestroy), +map: wl.Listener(*wlr.XwaylandSurface) = wl.Listener(*wlr.XwaylandSurface).init(handleMap), +unmap: wl.Listener(*wlr.XwaylandSurface) = wl.Listener(*wlr.XwaylandSurface).init(handleUnmap), +title: wl.Listener(*wlr.XwaylandSurface) = wl.Listener(*wlr.XwaylandSurface).init(handleTitle), // Listeners that are only active while the view is mapped -commit: wl.Listener(*wlr.Surface) = undefined, +commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit), pub fn init(self: *Self, view: *View, xwayland_surface: *wlr.XwaylandSurface) void { self.* = .{ .view = view, .xwayland_surface = xwayland_surface }; xwayland_surface.data = @ptrToInt(self); // Add listeners that are active over the view's entire lifetime - self.destroy.setNotify(handleDestroy); - self.xwayland_surface.events.destroy.add(&self.destroy); - - self.map.setNotify(handleMap); - self.xwayland_surface.events.map.add(&self.map); - - self.unmap.setNotify(handleUnmap); - self.xwayland_surface.events.unmap.add(&self.unmap); - - self.title.setNotify(handleTitle); - self.xwayland_surface.events.set_title.add(&self.title); + xwayland_surface.events.destroy.add(&self.destroy); + xwayland_surface.events.map.add(&self.map); + xwayland_surface.events.unmap.add(&self.unmap); + xwayland_surface.events.set_title.add(&self.title); } pub fn deinit(self: *Self) void { @@ -164,8 +157,7 @@ fn handleMap(listener: *wl.Listener(*wlr.XwaylandSurface), xwayland_surface: *wl const root = view.output.root; // Add listeners that are only active while mapped - self.commit.setNotify(handleCommit); - self.xwayland_surface.surface.?.events.commit.add(&self.commit); + xwayland_surface.surface.?.events.commit.add(&self.commit); view.surface = self.xwayland_surface.surface;