From 7de2edb623bc5f4f13a591da7bbff7a47e1c6e58 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 13 Aug 2020 12:22:32 +0200 Subject: [PATCH] seat: implement kde idle protocol --- river/Cursor.zig | 12 ++++++++++-- river/InputManager.zig | 8 +++++--- river/Keyboard.zig | 3 ++- river/Seat.zig | 4 ++++ river/c.zig | 1 + 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/river/Cursor.zig b/river/Cursor.zig index d2a2e17..ab78137 100644 --- a/river/Cursor.zig +++ b/river/Cursor.zig @@ -324,12 +324,14 @@ pub fn setTheme(self: *Self, theme: ?[*:0]const u8, _size: ?u32) !void { fn handleAxis(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { // This event is forwarded by the cursor when a pointer emits an axis event, // for example when you move the scroll wheel. - const cursor = @fieldParentPtr(Self, "listen_axis", listener.?); + const self = @fieldParentPtr(Self, "listen_axis", listener.?); const event = util.voidCast(c.wlr_event_pointer_axis, data.?); + self.seat.handleActivity(); + // Notify the client with pointer focus of the axis event. c.wlr_seat_pointer_notify_axis( - cursor.seat.wlr_seat, + self.seat.wlr_seat, event.time_msec, event.orientation, event.delta, @@ -344,6 +346,8 @@ fn handleButton(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { const self = @fieldParentPtr(Self, "listen_button", listener.?); const event = util.voidCast(c.wlr_event_pointer_button, data.?); + self.seat.handleActivity(); + if (event.state == .WLR_BUTTON_PRESSED) { self.pressed_count += 1; } else { @@ -421,6 +425,8 @@ fn handleMotionAbsolute(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) const self = @fieldParentPtr(Self, "listen_motion_absolute", listener.?); const event = util.voidCast(c.wlr_event_pointer_motion_absolute, data.?); + self.seat.handleActivity(); + var lx: f64 = undefined; var ly: f64 = undefined; c.wlr_cursor_absolute_to_layout_coords(self.wlr_cursor, event.device, event.x, event.y, &lx, &ly); @@ -434,6 +440,8 @@ fn handleMotion(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { const self = @fieldParentPtr(Self, "listen_motion", listener.?); const event = util.voidCast(c.wlr_event_pointer_motion, data.?); + self.seat.handleActivity(); + Mode.processMotion(self, event.device, event.time_msec, event.delta_x, event.delta_y); } diff --git a/river/InputManager.zig b/river/InputManager.zig index ea79db8..feb1ef2 100644 --- a/river/InputManager.zig +++ b/river/InputManager.zig @@ -32,6 +32,7 @@ const default_seat_name = "default"; server: *Server, +wlr_idle: *c.wlr_idle, wlr_input_inhibit_manager: *c.wlr_input_inhibit_manager, seats: std.TailQueue(Seat), @@ -46,9 +47,10 @@ listen_new_input: c.wl_listener, pub fn init(self: *Self, server: *Server) !void { self.server = server; - // This is automatically freed when the display is destroyed - self.wlr_input_inhibit_manager = - c.wlr_input_inhibit_manager_create(server.wl_display) orelse return error.OutOfMemory; + // These are automatically freed when the display is destroyed + self.wlr_idle = c.wlr_idle_create(server.wl_display) orelse return error.OutOfMemory; + self.wlr_input_inhibit_manager = c.wlr_input_inhibit_manager_create(server.wl_display) orelse + return error.OutOfMemory; self.seats = std.TailQueue(Seat).init(); diff --git a/river/Keyboard.zig b/river/Keyboard.zig index 24e4022..0054e4f 100644 --- a/river/Keyboard.zig +++ b/river/Keyboard.zig @@ -71,9 +71,10 @@ fn handleKey(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { // This event is raised when a key is pressed or released. const self = @fieldParentPtr(Self, "listen_key", listener.?); const event = util.voidCast(c.wlr_event_keyboard_key, data.?); - const wlr_keyboard = self.wlr_keyboard; + self.seat.handleActivity(); + // Translate libinput keycode -> xkbcommon const keycode = event.keycode + 8; diff --git a/river/Seat.zig b/river/Seat.zig index d988610..96d320b 100644 --- a/river/Seat.zig +++ b/river/Seat.zig @@ -238,6 +238,10 @@ pub fn focusOutput(self: *Self, output: *Output) void { while (it) |node| : (it = node.next) node.data.sendOutput(.focused); } +pub fn handleActivity(self: Self) void { + c.wlr_idle_notify_activity(self.input_manager.wlr_idle, self.wlr_seat); +} + /// Handle the unmapping of a view, removing it from the focus stack and /// setting the focus if needed. pub fn handleViewUnmap(self: *Self, view: *View) void { diff --git a/river/c.zig b/river/c.zig index dacb06e..5a09aaa 100644 --- a/river/c.zig +++ b/river/c.zig @@ -33,6 +33,7 @@ pub usingnamespace @cImport({ @cInclude("wlr/types/wlr_cursor.h"); @cInclude("wlr/types/wlr_data_control_v1.h"); @cInclude("wlr/types/wlr_data_device.h"); + @cInclude("wlr/types/wlr_idle.h"); @cInclude("wlr/types/wlr_input_device.h"); @cInclude("wlr/types/wlr_input_inhibitor.h"); @cInclude("wlr/types/wlr_keyboard.h");