git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commit02101249de199d69d97eb9a2bdd5bd9d689379f2
parent9d16e0ae79
authorIsaac Freund <[email protected]>
date2021-07-23 16:52
cursor: remove surfaceAt() parameters

We always pass the current cursor position, so this is a nice
simplification.

 river/Cursor.zig | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/river/Cursor.zig b/river/Cursor.zig
index 6d0c733..803d8c0 100644
--- a/river/Cursor.zig
+++ b/river/Cursor.zig
@@ -232,7 +232,7 @@ fn handleButton(listener: *wl.Listener(*wlr.Pointer.event.Button), event: *wlr.P
         }
     }
 
-    if (self.surfaceAt(self.wlr_cursor.x, self.wlr_cursor.y)) |result| {
+    if (self.surfaceAt()) |result| {
         switch (result.parent) {
             .view => |view| {
                 // If a view has been clicked on, give that view keyboard focus and
@@ -427,11 +427,12 @@ const SurfaceAtResult = struct {
     },
 };
 
-/// Find the topmost surface under the output layout coordinates lx/ly
-/// returns the surface if found and sets the sx/sy parameters to the
-/// surface coordinates.
+/// Find the surface under the cursor if any, and return information about that
+/// surface and the cursor's position in surface local coords.
 /// This function must be kept in sync with the rendering order in render.zig.
-fn surfaceAt(self: Self, lx: f64, ly: f64) ?SurfaceAtResult {
+pub fn surfaceAt(self: Self) ?SurfaceAtResult {
+    const lx = self.wlr_cursor.x;
+    const ly = self.wlr_cursor.y;
     const wlr_output = server.root.output_layout.outputAt(lx, ly) orelse return null;
     const output = @intToPtr(*Output, wlr_output.data);
 
@@ -708,7 +709,7 @@ fn processMotion(self: *Self, device: *wlr.InputDevice, time: u32, delta_x: f64,
         if (self.mode == .passthrough or self.mode == .down) {
             if (constraint.type == .locked) return;
 
-            const result = self.surfaceAt(self.wlr_cursor.x, self.wlr_cursor.y) orelse return;
+            const result = self.surfaceAt() orelse return;
 
             if (result.surface != constraint.surface) return;
 
@@ -812,7 +813,7 @@ pub fn maybeResetState(self: *Self) void {
 fn passthrough(self: *Self, time: u32) void {
     assert(self.mode == .passthrough);
 
-    if (self.surfaceAt(self.wlr_cursor.x, self.wlr_cursor.y)) |result| {
+    if (self.surfaceAt()) |result| {
         // If input is allowed on the surface, send pointer enter and motion
         // events. Note that wlroots won't actually send an enter event if
         // the surface has already been entered.