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:
parent
b243cd7fc3
commit
53dd3875b3
@ -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
|
/// 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,
|
/// the target view of a cursor operation potentially being moved to a non-visible tag,
|
||||||
/// becoming fullscreen, etc.
|
/// becoming fullscreen, etc.
|
||||||
pub fn maybeResetState(self: *Self) void {
|
pub fn updateState(self: *Self) void {
|
||||||
switch (self.mode) {
|
if (self.shouldExitMode()) {
|
||||||
.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;
|
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) {
|
|
||||||
var now: os.timespec = undefined;
|
var now: os.timespec = undefined;
|
||||||
os.clock_gettime(os.CLOCK_MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported");
|
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 +
|
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.
|
/// Pass an event on to the surface under the cursor, if any.
|
||||||
fn passthrough(self: *Self, time: u32) void {
|
fn passthrough(self: *Self, time: u32) void {
|
||||||
assert(self.mode == .passthrough);
|
assert(self.mode == .passthrough);
|
||||||
|
@ -178,9 +178,9 @@ pub fn inputAllowed(self: Self, wlr_surface: *wlr.Surface) bool {
|
|||||||
true;
|
true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn maybeResetCursorState(self: Self) void {
|
pub fn updateCursorState(self: Self) void {
|
||||||
var it = self.seats.first;
|
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(
|
fn handleInhibitActivate(
|
||||||
|
@ -405,7 +405,7 @@ fn commitTransaction(self: *Self) void {
|
|||||||
|
|
||||||
output.damage.addWhole();
|
output.damage.addWhole();
|
||||||
}
|
}
|
||||||
server.input_manager.maybeResetCursorState();
|
server.input_manager.updateCursorState();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send the new output configuration to all wlr-output-manager clients
|
/// Send the new output configuration to all wlr-output-manager clients
|
||||||
|
@ -273,7 +273,7 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), surface: *wlr.Surface) voi
|
|||||||
view.current = view.pending;
|
view.current = view.pending;
|
||||||
if (self_tags_changed) view.output.sendViewTags();
|
if (self_tags_changed) view.output.sendViewTags();
|
||||||
view.output.damage.addWhole();
|
view.output.damage.addWhole();
|
||||||
server.input_manager.maybeResetCursorState();
|
server.input_manager.updateCursorState();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If the client has not yet acked our configure, we need to send a
|
// If the client has not yet acked our configure, we need to send a
|
||||||
|
Loading…
Reference in New Issue
Block a user