cursor: avoid sending unnecessary pointer motion events

If the current Cursor.maybeResetState() function is called while in
passthrough mode, it will send a pointer motion event. This is
unnecessary as we have already sent the same pointer motion event at
least once.

Also refactor the code slightly and improve naming.
This commit is contained in:
Isaac Freund 2021-07-23 19:18:49 +02:00
parent b243cd7fc3
commit 53dd3875b3
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
4 changed files with 24 additions and 27 deletions

View file

@ -774,29 +774,9 @@ fn processMotion(self: *Self, device: *wlr.InputDevice, time: u32, delta_x: f64,
/// Handle potential change in location of views on the output, as well as
/// the target view of a cursor operation potentially being moved to a non-visible tag,
/// becoming fullscreen, etc.
pub fn maybeResetState(self: *Self) void {
switch (self.mode) {
.passthrough => {},
.down => |target| {
// If the target view is no longer visible, abort the operation.
if (target.current.tags & target.output.current.tags == 0) {
self.mode = .passthrough;
}
},
.resize, .move => {
// If the target view is no longer visible, or now fullscreen or no
// longer floating, abort the operation.
const target = if (self.mode == .resize) self.mode.resize.view else self.mode.move;
if (target.current.tags & target.output.current.tags == 0 or
(!target.current.float and target.output.current.layout != null) or
target.current.fullscreen)
{
self.mode = .passthrough;
}
},
}
if (self.mode == .passthrough) {
pub fn updateState(self: *Self) void {
if (self.shouldExitMode()) {
self.mode = .passthrough;
var now: os.timespec = undefined;
os.clock_gettime(os.CLOCK_MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported");
const msec = @intCast(u32, now.tv_sec * std.time.ms_per_s +
@ -805,6 +785,23 @@ pub fn maybeResetState(self: *Self) void {
}
}
fn shouldExitMode(self: Self) bool {
switch (self.mode) {
.passthrough => return false,
.down => |target| {
// The target view is no longer visible
return target.current.tags & target.output.current.tags == 0;
},
.resize, .move => {
const target = if (self.mode == .resize) self.mode.resize.view else self.mode.move;
// The target view is no longer visible, is part of the layout, or is fullscreen.
return target.current.tags & target.output.current.tags == 0 or
(!target.current.float and target.output.current.layout != null) or
target.current.fullscreen;
},
}
}
/// Pass an event on to the surface under the cursor, if any.
fn passthrough(self: *Self, time: u32) void {
assert(self.mode == .passthrough);

View file

@ -178,9 +178,9 @@ pub fn inputAllowed(self: Self, wlr_surface: *wlr.Surface) bool {
true;
}
pub fn maybeResetCursorState(self: Self) void {
pub fn updateCursorState(self: Self) void {
var it = self.seats.first;
while (it) |node| : (it = node.next) node.data.cursor.maybeResetState();
while (it) |node| : (it = node.next) node.data.cursor.updateState();
}
fn handleInhibitActivate(

View file

@ -405,7 +405,7 @@ fn commitTransaction(self: *Self) void {
output.damage.addWhole();
}
server.input_manager.maybeResetCursorState();
server.input_manager.updateCursorState();
}
/// Send the new output configuration to all wlr-output-manager clients

View file

@ -273,7 +273,7 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), surface: *wlr.Surface) voi
view.current = view.pending;
if (self_tags_changed) view.output.sendViewTags();
view.output.damage.addWhole();
server.input_manager.maybeResetCursorState();
server.input_manager.updateCursorState();
}
} else {
// If the client has not yet acked our configure, we need to send a