seat: implement kde idle protocol

This commit is contained in:
Isaac Freund 2020-08-13 12:22:32 +02:00
parent aabd85b028
commit 7de2edb623
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11
5 changed files with 22 additions and 6 deletions

View File

@ -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 { 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, // This event is forwarded by the cursor when a pointer emits an axis event,
// for example when you move the scroll wheel. // 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.?); const event = util.voidCast(c.wlr_event_pointer_axis, data.?);
self.seat.handleActivity();
// Notify the client with pointer focus of the axis event. // Notify the client with pointer focus of the axis event.
c.wlr_seat_pointer_notify_axis( c.wlr_seat_pointer_notify_axis(
cursor.seat.wlr_seat, self.seat.wlr_seat,
event.time_msec, event.time_msec,
event.orientation, event.orientation,
event.delta, 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 self = @fieldParentPtr(Self, "listen_button", listener.?);
const event = util.voidCast(c.wlr_event_pointer_button, data.?); const event = util.voidCast(c.wlr_event_pointer_button, data.?);
self.seat.handleActivity();
if (event.state == .WLR_BUTTON_PRESSED) { if (event.state == .WLR_BUTTON_PRESSED) {
self.pressed_count += 1; self.pressed_count += 1;
} else { } 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 self = @fieldParentPtr(Self, "listen_motion_absolute", listener.?);
const event = util.voidCast(c.wlr_event_pointer_motion_absolute, data.?); const event = util.voidCast(c.wlr_event_pointer_motion_absolute, data.?);
self.seat.handleActivity();
var lx: f64 = undefined; var lx: f64 = undefined;
var ly: f64 = undefined; var ly: f64 = undefined;
c.wlr_cursor_absolute_to_layout_coords(self.wlr_cursor, event.device, event.x, event.y, &lx, &ly); 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 self = @fieldParentPtr(Self, "listen_motion", listener.?);
const event = util.voidCast(c.wlr_event_pointer_motion, data.?); 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); Mode.processMotion(self, event.device, event.time_msec, event.delta_x, event.delta_y);
} }

View File

@ -32,6 +32,7 @@ const default_seat_name = "default";
server: *Server, server: *Server,
wlr_idle: *c.wlr_idle,
wlr_input_inhibit_manager: *c.wlr_input_inhibit_manager, wlr_input_inhibit_manager: *c.wlr_input_inhibit_manager,
seats: std.TailQueue(Seat), seats: std.TailQueue(Seat),
@ -46,9 +47,10 @@ listen_new_input: c.wl_listener,
pub fn init(self: *Self, server: *Server) !void { pub fn init(self: *Self, server: *Server) !void {
self.server = server; self.server = server;
// This is automatically freed when the display is destroyed // These are automatically freed when the display is destroyed
self.wlr_input_inhibit_manager = self.wlr_idle = c.wlr_idle_create(server.wl_display) orelse return error.OutOfMemory;
c.wlr_input_inhibit_manager_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(); self.seats = std.TailQueue(Seat).init();

View File

@ -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. // This event is raised when a key is pressed or released.
const self = @fieldParentPtr(Self, "listen_key", listener.?); const self = @fieldParentPtr(Self, "listen_key", listener.?);
const event = util.voidCast(c.wlr_event_keyboard_key, data.?); const event = util.voidCast(c.wlr_event_keyboard_key, data.?);
const wlr_keyboard = self.wlr_keyboard; const wlr_keyboard = self.wlr_keyboard;
self.seat.handleActivity();
// Translate libinput keycode -> xkbcommon // Translate libinput keycode -> xkbcommon
const keycode = event.keycode + 8; const keycode = event.keycode + 8;

View File

@ -238,6 +238,10 @@ pub fn focusOutput(self: *Self, output: *Output) void {
while (it) |node| : (it = node.next) node.data.sendOutput(.focused); 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 /// Handle the unmapping of a view, removing it from the focus stack and
/// setting the focus if needed. /// setting the focus if needed.
pub fn handleViewUnmap(self: *Self, view: *View) void { pub fn handleViewUnmap(self: *Self, view: *View) void {

View File

@ -33,6 +33,7 @@ pub usingnamespace @cImport({
@cInclude("wlr/types/wlr_cursor.h"); @cInclude("wlr/types/wlr_cursor.h");
@cInclude("wlr/types/wlr_data_control_v1.h"); @cInclude("wlr/types/wlr_data_control_v1.h");
@cInclude("wlr/types/wlr_data_device.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_device.h");
@cInclude("wlr/types/wlr_input_inhibitor.h"); @cInclude("wlr/types/wlr_input_inhibitor.h");
@cInclude("wlr/types/wlr_keyboard.h"); @cInclude("wlr/types/wlr_keyboard.h");