pointer-constraints: remove protocol
This implementation as it stands is incomplete/buggy and will make updating to wlr_scene more complex. It will be reimplemented after updating to wlr_scene is complete.
This commit is contained in:
		| @ -108,7 +108,6 @@ pub fn build(b: *zbs.Builder) !void { | ||||
|  | ||||
|     scanner.generate("xdg_wm_base", 2); | ||||
|     scanner.generate("zwp_pointer_gestures_v1", 3); | ||||
|     scanner.generate("zwp_pointer_constraints_v1", 1); | ||||
|     scanner.generate("ext_session_lock_manager_v1", 1); | ||||
|  | ||||
|     scanner.generate("zriver_control_v1", 1); | ||||
|  | ||||
| @ -102,8 +102,6 @@ xcursor_manager: *wlr.XcursorManager, | ||||
|  | ||||
| image: Image = .unknown, | ||||
|  | ||||
| constraint: ?*wlr.PointerConstraintV1 = null, | ||||
|  | ||||
| /// Number of distinct buttons currently pressed | ||||
| pressed_count: u32 = 0, | ||||
|  | ||||
| @ -959,26 +957,6 @@ fn processMotion(self: *Self, device: *wlr.InputDevice, time: u32, delta_x: f64, | ||||
|     ); | ||||
|     var dx: f64 = delta_x; | ||||
|     var dy: f64 = delta_y; | ||||
|     if (self.constraint) |constraint| { | ||||
|         if (self.mode == .passthrough or self.mode == .down) { | ||||
|             if (constraint.type == .locked) return; | ||||
|  | ||||
|             const result = self.surfaceAt() orelse return; | ||||
|  | ||||
|             if (result.surface != constraint.surface) return; | ||||
|  | ||||
|             const sx = result.sx; | ||||
|             const sy = result.sy; | ||||
|             var sx_con: f64 = undefined; | ||||
|             var sy_con: f64 = undefined; | ||||
|             if (!wlr.region.confine(&constraint.region, sx, sy, sx + dx, sy + dy, &sx_con, &sy_con)) { | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
|             dx = sx_con - sx; | ||||
|             dy = sy_con - sy; | ||||
|         } | ||||
|     } | ||||
|     switch (self.mode) { | ||||
|         .passthrough => { | ||||
|             self.wlr_cursor.move(device, dx, dy); | ||||
|  | ||||
| @ -29,7 +29,6 @@ const util = @import("util.zig"); | ||||
| const InputConfig = @import("InputConfig.zig"); | ||||
| const InputDevice = @import("InputDevice.zig"); | ||||
| const Keyboard = @import("Keyboard.zig"); | ||||
| const PointerConstraint = @import("PointerConstraint.zig"); | ||||
| const Seat = @import("Seat.zig"); | ||||
| const Switch = @import("Switch.zig"); | ||||
|  | ||||
| @ -40,7 +39,6 @@ const log = std.log.scoped(.input_manager); | ||||
| new_input: wl.Listener(*wlr.InputDevice) = wl.Listener(*wlr.InputDevice).init(handleNewInput), | ||||
|  | ||||
| idle_notifier: *wlr.IdleNotifierV1, | ||||
| pointer_constraints: *wlr.PointerConstraintsV1, | ||||
| relative_pointer_manager: *wlr.RelativePointerManagerV1, | ||||
| virtual_pointer_manager: *wlr.VirtualPointerManagerV1, | ||||
| virtual_keyboard_manager: *wlr.VirtualKeyboardManagerV1, | ||||
| @ -51,8 +49,6 @@ seats: std.TailQueue(Seat) = .{}, | ||||
|  | ||||
| exclusive_client: ?*wl.Client = null, | ||||
|  | ||||
| new_pointer_constraint: wl.Listener(*wlr.PointerConstraintV1) = | ||||
|     wl.Listener(*wlr.PointerConstraintV1).init(handleNewPointerConstraint), | ||||
| new_virtual_pointer: wl.Listener(*wlr.VirtualPointerManagerV1.event.NewPointer) = | ||||
|     wl.Listener(*wlr.VirtualPointerManagerV1.event.NewPointer).init(handleNewVirtualPointer), | ||||
| new_virtual_keyboard: wl.Listener(*wlr.VirtualKeyboardV1) = | ||||
| @ -65,7 +61,6 @@ pub fn init(self: *Self) !void { | ||||
|     self.* = .{ | ||||
|         // These are automatically freed when the display is destroyed | ||||
|         .idle_notifier = try wlr.IdleNotifierV1.create(server.wl_server), | ||||
|         .pointer_constraints = try wlr.PointerConstraintsV1.create(server.wl_server), | ||||
|         .relative_pointer_manager = try wlr.RelativePointerManagerV1.create(server.wl_server), | ||||
|         .virtual_pointer_manager = try wlr.VirtualPointerManagerV1.create(server.wl_server), | ||||
|         .virtual_keyboard_manager = try wlr.VirtualKeyboardManagerV1.create(server.wl_server), | ||||
| @ -81,7 +76,6 @@ pub fn init(self: *Self) !void { | ||||
|     if (build_options.xwayland) server.xwayland.setSeat(self.defaultSeat().wlr_seat); | ||||
|  | ||||
|     server.backend.events.new_input.add(&self.new_input); | ||||
|     self.pointer_constraints.events.new_constraint.add(&self.new_pointer_constraint); | ||||
|     self.virtual_pointer_manager.events.new_virtual_pointer.add(&self.new_virtual_pointer); | ||||
|     self.virtual_keyboard_manager.events.new_virtual_keyboard.add(&self.new_virtual_keyboard); | ||||
| } | ||||
| @ -124,19 +118,6 @@ fn handleNewInput(listener: *wl.Listener(*wlr.InputDevice), wlr_device: *wlr.Inp | ||||
|     self.defaultSeat().addDevice(wlr_device); | ||||
| } | ||||
|  | ||||
| fn handleNewPointerConstraint( | ||||
|     _: *wl.Listener(*wlr.PointerConstraintV1), | ||||
|     constraint: *wlr.PointerConstraintV1, | ||||
| ) void { | ||||
|     const pointer_constraint = util.gpa.create(PointerConstraint) catch { | ||||
|         constraint.resource.getClient().postNoMemory(); | ||||
|         log.err("out of memory", .{}); | ||||
|         return; | ||||
|     }; | ||||
|  | ||||
|     pointer_constraint.init(constraint); | ||||
| } | ||||
|  | ||||
| fn handleNewVirtualPointer( | ||||
|     listener: *wl.Listener(*wlr.VirtualPointerManagerV1.event.NewPointer), | ||||
|     event: *wlr.VirtualPointerManagerV1.event.NewPointer, | ||||
|  | ||||
| @ -1,144 +0,0 @@ | ||||
| // This file is part of river, a dynamic tiling wayland compositor. | ||||
| // | ||||
| // Copyright 2021 The River Developers | ||||
| // | ||||
| // This program is free software: you can redistribute it and/or modify | ||||
| // it under the terms of the GNU General Public License as published by | ||||
| // the Free Software Foundation, version 3. | ||||
| // | ||||
| // This program is distributed in the hope that it will be useful, | ||||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| // GNU General Public License for more details. | ||||
| // | ||||
| // You should have received a copy of the GNU General Public License | ||||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
|  | ||||
| const Self = @This(); | ||||
|  | ||||
| const build_options = @import("build_options"); | ||||
| const std = @import("std"); | ||||
| const wlr = @import("wlroots"); | ||||
| const wl = @import("wayland").server.wl; | ||||
| const pixman = @import("pixman"); | ||||
|  | ||||
| const server = &@import("main.zig").server; | ||||
| const util = @import("util.zig"); | ||||
|  | ||||
| const Cursor = @import("Cursor.zig"); | ||||
| const Seat = @import("Seat.zig"); | ||||
| const View = @import("View.zig"); | ||||
|  | ||||
| constraint: *wlr.PointerConstraintV1, | ||||
| cursor: *Cursor, | ||||
|  | ||||
| destroy: wl.Listener(*wlr.PointerConstraintV1) = wl.Listener(*wlr.PointerConstraintV1).init(handleDestroy), | ||||
| set_region: wl.Listener(void) = wl.Listener(void).init(handleSetRegion), | ||||
|  | ||||
| pub fn init(self: *Self, constraint: *wlr.PointerConstraintV1) void { | ||||
|     const seat = @intToPtr(*Seat, constraint.seat.data); | ||||
|     self.* = .{ | ||||
|         .constraint = constraint, | ||||
|         .cursor = &seat.cursor, | ||||
|     }; | ||||
|  | ||||
|     self.constraint.data = @ptrToInt(self); | ||||
|  | ||||
|     self.constraint.events.destroy.add(&self.destroy); | ||||
|     self.constraint.events.set_region.add(&self.set_region); | ||||
|  | ||||
|     if (seat.focused == .view and seat.focused.view.surface == self.constraint.surface) { | ||||
|         self.setAsActive(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| pub fn setAsActive(self: *Self) void { | ||||
|     if (self.cursor.constraint == self.constraint) return; | ||||
|  | ||||
|     if (self.cursor.constraint) |constraint| { | ||||
|         constraint.sendDeactivated(); | ||||
|     } | ||||
|  | ||||
|     self.cursor.constraint = self.constraint; | ||||
|  | ||||
|     // TODO: This is the same hack sway uses to deal with the fact that this | ||||
|     // function may be called in response to a surface commit but before the | ||||
|     // the wlroots pointer constraints implementation's commit handler has been called. | ||||
|     // This logic is duplicated from that commit handler. | ||||
|     if (self.constraint.current.region.notEmpty()) { | ||||
|         _ = self.constraint.region.intersect(&self.constraint.surface.input_region, &self.constraint.current.region); | ||||
|     } else { | ||||
|         _ = self.constraint.region.copy(&self.constraint.surface.input_region); | ||||
|     } | ||||
|  | ||||
|     self.constrainToRegion(); | ||||
|  | ||||
|     self.constraint.sendActivated(); | ||||
| } | ||||
|  | ||||
| fn constrainToRegion(self: *Self) void { | ||||
|     if (self.cursor.constraint != self.constraint) return; | ||||
|     if (View.fromWlrSurface(self.constraint.surface)) |view| { | ||||
|         const output = view.output; | ||||
|         var output_box: wlr.Box = undefined; | ||||
|         server.root.output_layout.getBox(output.wlr_output, &output_box); | ||||
|  | ||||
|         const surface_lx = @intToFloat(f64, output_box.x + view.current.box.x - view.surface_box.x); | ||||
|         const surface_ly = @intToFloat(f64, output_box.y + view.current.box.y - view.surface_box.y); | ||||
|  | ||||
|         const sx = @floatToInt(c_int, self.cursor.wlr_cursor.x - surface_lx); | ||||
|         const sy = @floatToInt(c_int, self.cursor.wlr_cursor.y - surface_ly); | ||||
|  | ||||
|         // If the cursor is not already inside the constraint region, warp | ||||
|         // it to an arbitrary point inside the constraint region. | ||||
|         if (!self.constraint.region.containsPoint(sx, sy, null)) { | ||||
|             const rects = self.constraint.region.rectangles(); | ||||
|             if (rects.len > 0) { | ||||
|                 const new_lx = surface_lx + @intToFloat(f64, rects[0].x1 + rects[0].x2) / 2; | ||||
|                 const new_ly = surface_ly + @intToFloat(f64, rects[0].y1 + rects[0].y2) / 2; | ||||
|                 self.cursor.wlr_cursor.warpClosest(null, new_lx, new_ly); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| fn handleDestroy(listener: *wl.Listener(*wlr.PointerConstraintV1), _: *wlr.PointerConstraintV1) void { | ||||
|     const self = @fieldParentPtr(Self, "destroy", listener); | ||||
|  | ||||
|     self.destroy.link.remove(); | ||||
|     self.set_region.link.remove(); | ||||
|  | ||||
|     if (self.cursor.constraint == self.constraint) { | ||||
|         warpToHint(self.cursor); | ||||
|  | ||||
|         self.cursor.constraint = null; | ||||
|     } | ||||
|  | ||||
|     util.gpa.destroy(self); | ||||
| } | ||||
|  | ||||
| fn handleSetRegion(listener: *wl.Listener(void)) void { | ||||
|     const self = @fieldParentPtr(Self, "set_region", listener); | ||||
|     self.constrainToRegion(); | ||||
| } | ||||
|  | ||||
| pub fn warpToHint(cursor: *Cursor) void { | ||||
|     if (cursor.constraint) |constraint| { | ||||
|         if (constraint.current.committed.cursor_hint) { | ||||
|             if (View.fromWlrSurface(constraint.surface)) |view| { | ||||
|                 const output = view.output; | ||||
|                 var output_box: wlr.Box = undefined; | ||||
|                 server.root.output_layout.getBox(output.wlr_output, &output_box); | ||||
|  | ||||
|                 const surface_lx = @intToFloat(f64, output_box.x + view.current.box.x - view.surface_box.x); | ||||
|                 const surface_ly = @intToFloat(f64, output_box.y + view.current.box.y - view.surface_box.y); | ||||
|  | ||||
|                 _ = cursor.wlr_cursor.warp( | ||||
|                     null, | ||||
|                     surface_lx + constraint.current.cursor_hint.x, | ||||
|                     surface_ly + constraint.current.cursor_hint.y, | ||||
|                 ); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -45,7 +45,6 @@ const ViewStack = @import("view_stack.zig").ViewStack; | ||||
| const XwaylandOverrideRedirect = @import("XwaylandOverrideRedirect.zig"); | ||||
|  | ||||
| const log = std.log.scoped(.seat); | ||||
| const PointerConstraint = @import("PointerConstraint.zig"); | ||||
|  | ||||
| pub const FocusTarget = union(enum) { | ||||
|     view: *View, | ||||
| @ -271,29 +270,15 @@ pub fn keyboardEnterOrLeave(self: *Self, target_surface: ?*wlr.Surface) void { | ||||
|     if (target_surface) |wlr_surface| { | ||||
|         self.keyboardNotifyEnter(wlr_surface); | ||||
|  | ||||
|         if (server.input_manager.pointer_constraints.constraintForSurface(wlr_surface, self.wlr_seat)) |constraint| { | ||||
|             @intToPtr(*PointerConstraint, constraint.data).setAsActive(); | ||||
|         } else if (self.cursor.constraint) |constraint| { | ||||
|             PointerConstraint.warpToHint(&self.cursor); | ||||
|             constraint.sendDeactivated(); | ||||
|             self.cursor.constraint = null; | ||||
|         } else { | ||||
|             // Depending on configuration and cursor position, changing keyboard focus | ||||
|             // may cause the cursor to be warped. | ||||
|             self.cursor.may_need_warp = true; | ||||
|         } | ||||
|         // Depending on configuration and cursor position, changing keyboard focus | ||||
|         // may cause the cursor to be warped. | ||||
|         self.cursor.may_need_warp = true; | ||||
|     } else { | ||||
|         self.wlr_seat.keyboardClearFocus(); | ||||
|  | ||||
|         if (self.cursor.constraint) |constraint| { | ||||
|             PointerConstraint.warpToHint(&self.cursor); | ||||
|             constraint.sendDeactivated(); | ||||
|             self.cursor.constraint = null; | ||||
|         } else { | ||||
|             // Depending on configuration and cursor position, changing keyboard focus | ||||
|             // may cause the cursor to be warped. | ||||
|             self.cursor.may_need_warp = true; | ||||
|         } | ||||
|         // Depending on configuration and cursor position, changing keyboard focus | ||||
|         // may cause the cursor to be warped. | ||||
|         self.cursor.may_need_warp = true; | ||||
|     } | ||||
| } | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user