2020-05-02 10:21:10 -07:00
|
|
|
// This file is part of river, a dynamic tiling wayland compositor.
|
|
|
|
//
|
2020-11-11 11:30:21 -08:00
|
|
|
// Copyright 2020 The River Developers
|
2020-05-02 10:21:10 -07:00
|
|
|
//
|
|
|
|
// 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
|
2022-01-31 10:33:22 -08:00
|
|
|
// the Free Software Foundation, version 3.
|
2020-05-02 10:21:10 -07:00
|
|
|
//
|
|
|
|
// 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/>.
|
|
|
|
|
2020-05-02 07:47:10 -07:00
|
|
|
const Self = @This();
|
|
|
|
|
2020-05-14 10:01:17 -07:00
|
|
|
const build_options = @import("build_options");
|
2020-03-22 14:42:55 -07:00
|
|
|
const std = @import("std");
|
2021-07-14 06:32:24 -07:00
|
|
|
const assert = std.debug.assert;
|
2021-06-23 06:56:38 -07:00
|
|
|
const os = std.os;
|
2020-12-26 16:06:18 -08:00
|
|
|
const math = std.math;
|
2020-11-03 15:23:21 -08:00
|
|
|
const wlr = @import("wlroots");
|
|
|
|
const wayland = @import("wayland");
|
|
|
|
const wl = wayland.server.wl;
|
|
|
|
const zwlr = wayland.server.zwlr;
|
2020-05-02 07:47:10 -07:00
|
|
|
|
2020-03-29 10:36:15 -07:00
|
|
|
const c = @import("c.zig");
|
2021-05-13 05:35:36 -07:00
|
|
|
const server = &@import("main.zig").server;
|
2020-06-16 11:54:05 -07:00
|
|
|
const util = @import("util.zig");
|
2020-03-22 14:42:55 -07:00
|
|
|
|
2020-07-07 07:39:08 -07:00
|
|
|
const Box = @import("Box.zig");
|
|
|
|
const Config = @import("Config.zig");
|
2020-05-02 14:11:56 -07:00
|
|
|
const LayerSurface = @import("LayerSurface.zig");
|
|
|
|
const Output = @import("Output.zig");
|
|
|
|
const Seat = @import("Seat.zig");
|
|
|
|
const View = @import("View.zig");
|
2020-04-24 05:51:10 -07:00
|
|
|
const ViewStack = @import("view_stack.zig").ViewStack;
|
2021-09-27 09:34:59 -07:00
|
|
|
const XwaylandUnmanaged = @import("XwaylandUnmanaged.zig");
|
2020-03-23 08:50:20 -07:00
|
|
|
|
2020-10-17 13:40:15 -07:00
|
|
|
const Mode = union(enum) {
|
2020-08-07 02:51:53 -07:00
|
|
|
passthrough: void,
|
2021-12-28 22:19:37 -08:00
|
|
|
down: struct {
|
|
|
|
// TODO: To handle the surface with pointer focus being moved during
|
|
|
|
// down mode we need to store the starting location of the surface as
|
|
|
|
// well and take that into account. This is currently not at all easy
|
|
|
|
// to do, but moing to the wlroots scene graph will allow us to fix this.
|
|
|
|
|
|
|
|
// Initial cursor position in layout coordinates
|
|
|
|
lx: f64,
|
|
|
|
ly: f64,
|
|
|
|
// Initial cursor position in surface-local coordinates
|
|
|
|
sx: f64,
|
|
|
|
sy: f64,
|
|
|
|
},
|
2021-10-30 10:16:31 -07:00
|
|
|
move: struct {
|
|
|
|
view: *View,
|
|
|
|
/// View coordinates are stored as i32s as they are in logical pixels.
|
|
|
|
/// However, it is possible to move the cursor by a fraction of a
|
|
|
|
/// logical pixel and this happens in practice with low dpi, high
|
|
|
|
/// polling rate mice. Therefore we must accumulate the current
|
|
|
|
/// fractional offset of the mouse to avoid rounding down tiny
|
|
|
|
/// motions to 0.
|
|
|
|
delta_x: f64 = 0,
|
|
|
|
delta_y: f64 = 0,
|
|
|
|
},
|
2020-08-07 12:34:38 -07:00
|
|
|
resize: struct {
|
|
|
|
view: *View,
|
2021-10-30 10:16:31 -07:00
|
|
|
delta_x: f64 = 0,
|
|
|
|
delta_y: f64 = 0,
|
2020-08-07 12:34:38 -07:00
|
|
|
/// Offset from the lower right corner of the view
|
|
|
|
offset_x: i32,
|
|
|
|
offset_y: i32,
|
|
|
|
},
|
2020-08-07 02:51:53 -07:00
|
|
|
};
|
|
|
|
|
2021-12-20 19:50:12 -08:00
|
|
|
const Image = enum {
|
2021-12-21 20:32:23 -08:00
|
|
|
/// The current image of the cursor is unknown, perhaps because it was set by a client.
|
|
|
|
unknown,
|
2021-12-20 19:50:12 -08:00
|
|
|
left_ptr,
|
|
|
|
move,
|
|
|
|
@"se-resize",
|
|
|
|
};
|
|
|
|
|
2020-07-14 08:34:29 -07:00
|
|
|
const default_size = 24;
|
|
|
|
|
2021-02-05 00:46:18 -08:00
|
|
|
const log = std.log.scoped(.cursor);
|
|
|
|
|
2020-10-17 13:40:15 -07:00
|
|
|
/// Current cursor mode as well as any state needed to implement that mode
|
|
|
|
mode: Mode = .passthrough,
|
|
|
|
|
2020-05-02 07:47:10 -07:00
|
|
|
seat: *Seat,
|
2020-11-03 15:23:21 -08:00
|
|
|
wlr_cursor: *wlr.Cursor,
|
2021-02-14 10:32:04 -08:00
|
|
|
pointer_gestures: *wlr.PointerGesturesV1,
|
2020-11-03 15:23:21 -08:00
|
|
|
xcursor_manager: *wlr.XcursorManager,
|
2020-05-02 07:47:10 -07:00
|
|
|
|
2021-12-21 20:32:23 -08:00
|
|
|
image: Image = .unknown,
|
2021-12-20 19:50:12 -08:00
|
|
|
|
2021-02-15 12:07:29 -08:00
|
|
|
constraint: ?*wlr.PointerConstraintV1 = null,
|
|
|
|
|
2020-07-29 07:36:46 -07:00
|
|
|
/// Number of distinct buttons currently pressed
|
2020-08-21 10:08:52 -07:00
|
|
|
pressed_count: u32 = 0,
|
2020-07-07 07:39:08 -07:00
|
|
|
|
2020-12-31 06:35:35 -08:00
|
|
|
axis: wl.Listener(*wlr.Pointer.event.Axis) = wl.Listener(*wlr.Pointer.event.Axis).init(handleAxis),
|
|
|
|
frame: wl.Listener(*wlr.Cursor) = wl.Listener(*wlr.Cursor).init(handleFrame),
|
|
|
|
button: wl.Listener(*wlr.Pointer.event.Button) =
|
|
|
|
wl.Listener(*wlr.Pointer.event.Button).init(handleButton),
|
|
|
|
motion_absolute: wl.Listener(*wlr.Pointer.event.MotionAbsolute) =
|
|
|
|
wl.Listener(*wlr.Pointer.event.MotionAbsolute).init(handleMotionAbsolute),
|
|
|
|
motion: wl.Listener(*wlr.Pointer.event.Motion) =
|
|
|
|
wl.Listener(*wlr.Pointer.event.Motion).init(handleMotion),
|
2021-02-14 10:32:04 -08:00
|
|
|
pinch_begin: wl.Listener(*wlr.Pointer.event.PinchBegin) =
|
|
|
|
wl.Listener(*wlr.Pointer.event.PinchBegin).init(handlePinchBegin),
|
|
|
|
pinch_update: wl.Listener(*wlr.Pointer.event.PinchUpdate) =
|
|
|
|
wl.Listener(*wlr.Pointer.event.PinchUpdate).init(handlePinchUpdate),
|
|
|
|
pinch_end: wl.Listener(*wlr.Pointer.event.PinchEnd) =
|
|
|
|
wl.Listener(*wlr.Pointer.event.PinchEnd).init(handlePinchEnd),
|
2020-12-31 06:35:35 -08:00
|
|
|
request_set_cursor: wl.Listener(*wlr.Seat.event.RequestSetCursor) =
|
|
|
|
wl.Listener(*wlr.Seat.event.RequestSetCursor).init(handleRequestSetCursor),
|
2021-02-14 10:32:04 -08:00
|
|
|
swipe_begin: wl.Listener(*wlr.Pointer.event.SwipeBegin) =
|
|
|
|
wl.Listener(*wlr.Pointer.event.SwipeBegin).init(handleSwipeBegin),
|
|
|
|
swipe_update: wl.Listener(*wlr.Pointer.event.SwipeUpdate) =
|
|
|
|
wl.Listener(*wlr.Pointer.event.SwipeUpdate).init(handleSwipeUpdate),
|
|
|
|
swipe_end: wl.Listener(*wlr.Pointer.event.SwipeEnd) =
|
|
|
|
wl.Listener(*wlr.Pointer.event.SwipeEnd).init(handleSwipeEnd),
|
2020-05-02 07:47:10 -07:00
|
|
|
|
|
|
|
pub fn init(self: *Self, seat: *Seat) !void {
|
2020-11-03 15:23:21 -08:00
|
|
|
const wlr_cursor = try wlr.Cursor.create();
|
|
|
|
errdefer wlr_cursor.destroy();
|
2021-05-13 05:53:08 -07:00
|
|
|
wlr_cursor.attachOutputLayout(server.root.output_layout);
|
2020-07-14 08:34:29 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
// This is here so that self.xcursor_manager doesn't need to be an
|
2020-07-14 08:34:29 -07:00
|
|
|
// optional pointer. This isn't optimal as it does a needless allocation,
|
|
|
|
// but this is not a hot path.
|
2020-11-03 15:23:21 -08:00
|
|
|
const xcursor_manager = try wlr.XcursorManager.create(null, default_size);
|
|
|
|
errdefer xcursor_manager.destroy();
|
2020-08-21 10:08:52 -07:00
|
|
|
|
|
|
|
self.* = .{
|
|
|
|
.seat = seat,
|
|
|
|
.wlr_cursor = wlr_cursor,
|
2021-05-13 05:53:08 -07:00
|
|
|
.pointer_gestures = try wlr.PointerGesturesV1.create(server.wl_server),
|
2020-11-03 15:23:21 -08:00
|
|
|
.xcursor_manager = xcursor_manager,
|
2020-08-21 10:08:52 -07:00
|
|
|
};
|
2020-07-14 08:34:29 -07:00
|
|
|
try self.setTheme(null, null);
|
2020-05-02 07:47:10 -07:00
|
|
|
|
|
|
|
// wlr_cursor *only* displays an image on screen. It does not move around
|
|
|
|
// when the pointer moves. However, we can attach input devices to it, and
|
|
|
|
// it will generate aggregate events for all of them. In these events, we
|
|
|
|
// can choose how we want to process them, forwarding them to clients and
|
|
|
|
// moving the cursor around. See following post for more detail:
|
|
|
|
// https://drewdevault.com/2018/07/17/Input-handling-in-wlroots.html
|
2020-12-31 06:35:35 -08:00
|
|
|
wlr_cursor.events.axis.add(&self.axis);
|
|
|
|
wlr_cursor.events.button.add(&self.button);
|
|
|
|
wlr_cursor.events.frame.add(&self.frame);
|
|
|
|
wlr_cursor.events.motion_absolute.add(&self.motion_absolute);
|
|
|
|
wlr_cursor.events.motion.add(&self.motion);
|
2021-02-14 10:32:04 -08:00
|
|
|
wlr_cursor.events.swipe_begin.add(&self.swipe_begin);
|
|
|
|
wlr_cursor.events.swipe_update.add(&self.swipe_update);
|
|
|
|
wlr_cursor.events.swipe_end.add(&self.swipe_end);
|
|
|
|
wlr_cursor.events.pinch_begin.add(&self.pinch_begin);
|
|
|
|
wlr_cursor.events.pinch_update.add(&self.pinch_update);
|
|
|
|
wlr_cursor.events.pinch_end.add(&self.pinch_end);
|
2020-12-31 06:35:35 -08:00
|
|
|
seat.wlr_seat.events.request_set_cursor.add(&self.request_set_cursor);
|
2020-05-02 07:47:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn deinit(self: *Self) void {
|
2020-11-03 15:23:21 -08:00
|
|
|
self.xcursor_manager.destroy();
|
|
|
|
self.wlr_cursor.destroy();
|
2020-05-02 07:47:10 -07:00
|
|
|
}
|
|
|
|
|
2020-07-14 08:34:29 -07:00
|
|
|
/// Set the cursor theme for the given seat, as well as the xwayland theme if
|
2020-07-17 11:40:33 -07:00
|
|
|
/// this is the default seat. Either argument may be null, in which case a
|
|
|
|
/// default will be used.
|
2020-07-17 03:56:15 -07:00
|
|
|
pub fn setTheme(self: *Self, theme: ?[*:0]const u8, _size: ?u32) !void {
|
|
|
|
const size = _size orelse default_size;
|
2020-07-14 08:34:29 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
self.xcursor_manager.destroy();
|
|
|
|
self.xcursor_manager = try wlr.XcursorManager.create(theme, size);
|
2020-07-14 08:34:29 -07:00
|
|
|
|
|
|
|
// For each output, ensure a theme of the proper scale is loaded
|
|
|
|
var it = server.root.outputs.first;
|
|
|
|
while (it) |node| : (it = node.next) {
|
|
|
|
const wlr_output = node.data.wlr_output;
|
2020-11-03 15:23:21 -08:00
|
|
|
self.xcursor_manager.load(wlr_output.scale) catch
|
2021-05-23 04:35:37 -07:00
|
|
|
log.err("failed to load xcursor theme '{s}' at scale {}", .{ theme, wlr_output.scale });
|
2020-07-14 08:34:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// If this cursor belongs to the default seat, set the xcursor environment
|
2022-01-29 06:40:29 -08:00
|
|
|
// variables as well as the xwayland cursor theme and update the cursor
|
|
|
|
// image if necessary.
|
2021-05-13 06:13:17 -07:00
|
|
|
if (self.seat == server.input_manager.defaultSeat()) {
|
2021-10-11 03:44:46 -07:00
|
|
|
const size_str = try std.fmt.allocPrintZ(util.gpa, "{}", .{size});
|
2020-07-14 08:34:29 -07:00
|
|
|
defer util.gpa.free(size_str);
|
|
|
|
if (c.setenv("XCURSOR_SIZE", size_str, 1) < 0) return error.OutOfMemory;
|
|
|
|
if (theme) |t| if (c.setenv("XCURSOR_THEME", t, 1) < 0) return error.OutOfMemory;
|
|
|
|
|
|
|
|
if (build_options.xwayland) {
|
2020-11-03 15:23:21 -08:00
|
|
|
self.xcursor_manager.load(1) catch {
|
2021-05-23 04:35:37 -07:00
|
|
|
log.err("failed to load xcursor theme '{s}' at scale 1", .{theme});
|
2020-11-03 15:23:21 -08:00
|
|
|
return;
|
|
|
|
};
|
|
|
|
const wlr_xcursor = self.xcursor_manager.getXcursor("left_ptr", 1).?;
|
|
|
|
const image = wlr_xcursor.images[0];
|
|
|
|
server.xwayland.setCursor(
|
|
|
|
image.buffer,
|
|
|
|
image.width * 4,
|
|
|
|
image.width,
|
|
|
|
image.height,
|
|
|
|
@intCast(i32, image.hotspot_x),
|
|
|
|
@intCast(i32, image.hotspot_y),
|
|
|
|
);
|
2020-07-14 08:34:29 -07:00
|
|
|
}
|
2022-01-29 06:40:29 -08:00
|
|
|
|
|
|
|
if (self.image != .unknown) {
|
|
|
|
self.xcursor_manager.setCursorImage(@tagName(self.image), self.wlr_cursor);
|
|
|
|
}
|
2020-07-14 08:34:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-23 02:44:10 -07:00
|
|
|
pub fn handleViewUnmap(self: *Self, view: *View) void {
|
|
|
|
if (switch (self.mode) {
|
2021-12-28 22:19:37 -08:00
|
|
|
.passthrough, .down => false,
|
2021-10-30 10:16:31 -07:00
|
|
|
.move => |data| data.view == view,
|
2020-08-21 07:23:23 -07:00
|
|
|
.resize => |data| data.view == view,
|
2021-07-23 02:44:10 -07:00
|
|
|
}) {
|
2020-08-21 07:23:23 -07:00
|
|
|
self.mode = .passthrough;
|
|
|
|
self.clearFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-20 19:50:12 -08:00
|
|
|
/// It seems that setCursorImage is actually fairly expensive to call repeatedly
|
|
|
|
/// as it does no checks to see if the the given image is already set. Therefore,
|
|
|
|
/// do that check here.
|
|
|
|
fn setImage(self: *Self, image: Image) void {
|
2021-12-21 20:32:23 -08:00
|
|
|
assert(image != .unknown);
|
|
|
|
|
2021-12-20 19:50:12 -08:00
|
|
|
if (image == self.image) return;
|
|
|
|
self.image = image;
|
2022-01-05 09:13:08 -08:00
|
|
|
self.xcursor_manager.setCursorImage(@tagName(image), self.wlr_cursor);
|
2021-12-20 19:50:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn clearFocus(self: *Self) void {
|
|
|
|
self.setImage(.left_ptr);
|
2020-11-03 15:23:21 -08:00
|
|
|
self.seat.wlr_seat.pointerNotifyClearFocus();
|
2020-08-21 07:23:23 -07:00
|
|
|
}
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
/// Axis event is a scroll wheel or similiar
|
|
|
|
fn handleAxis(listener: *wl.Listener(*wlr.Pointer.event.Axis), event: *wlr.Pointer.event.Axis) void {
|
|
|
|
const self = @fieldParentPtr(Self, "axis", listener);
|
2020-05-02 07:47:10 -07:00
|
|
|
|
2020-08-13 03:22:32 -07:00
|
|
|
self.seat.handleActivity();
|
|
|
|
|
2020-05-02 07:47:10 -07:00
|
|
|
// Notify the client with pointer focus of the axis event.
|
2020-11-03 15:23:21 -08:00
|
|
|
self.seat.wlr_seat.pointerNotifyAxis(
|
2020-05-02 07:47:10 -07:00
|
|
|
event.time_msec,
|
|
|
|
event.orientation,
|
|
|
|
event.delta,
|
|
|
|
event.delta_discrete,
|
|
|
|
event.source,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
fn handleButton(listener: *wl.Listener(*wlr.Pointer.event.Button), event: *wlr.Pointer.event.Button) void {
|
|
|
|
const self = @fieldParentPtr(Self, "button", listener);
|
2020-07-29 07:36:46 -07:00
|
|
|
|
2020-08-13 03:22:32 -07:00
|
|
|
self.seat.handleActivity();
|
|
|
|
|
2021-12-28 22:19:37 -08:00
|
|
|
if (event.state == .released) {
|
2020-07-29 07:36:46 -07:00
|
|
|
std.debug.assert(self.pressed_count > 0);
|
|
|
|
self.pressed_count -= 1;
|
|
|
|
if (self.pressed_count == 0 and self.mode != .passthrough) {
|
2020-10-17 13:40:15 -07:00
|
|
|
self.leaveMode(event);
|
2021-12-28 22:19:37 -08:00
|
|
|
} else {
|
|
|
|
_ = self.seat.wlr_seat.pointerNotifyButton(event.time_msec, event.button, event.state);
|
2020-07-29 07:36:46 -07:00
|
|
|
}
|
2021-12-28 22:19:37 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(event.state == .pressed);
|
|
|
|
self.pressed_count += 1;
|
|
|
|
|
|
|
|
if (self.pressed_count > 1) {
|
|
|
|
_ = self.seat.wlr_seat.pointerNotifyButton(event.time_msec, event.button, event.state);
|
|
|
|
return;
|
2020-07-29 07:36:46 -07:00
|
|
|
}
|
|
|
|
|
2021-07-23 07:52:48 -07:00
|
|
|
if (self.surfaceAt()) |result| {
|
2021-07-23 07:33:25 -07:00
|
|
|
switch (result.parent) {
|
|
|
|
.view => |view| {
|
2021-12-28 22:19:37 -08:00
|
|
|
// If there is an active mapping for this button which is
|
|
|
|
// handled we are done here
|
|
|
|
if (self.handlePointerMapping(event, view)) return;
|
|
|
|
// Otherwise focus the view
|
|
|
|
self.seat.focus(view);
|
2021-07-23 07:33:25 -07:00
|
|
|
},
|
|
|
|
.layer_surface => |layer_surface| {
|
2021-12-10 14:40:48 -08:00
|
|
|
self.seat.focusOutput(layer_surface.output);
|
2021-07-23 07:33:25 -07:00
|
|
|
// If a keyboard inteactive layer surface has been clicked on,
|
|
|
|
// give it keyboard focus.
|
|
|
|
if (layer_surface.wlr_layer_surface.current.keyboard_interactive == .exclusive) {
|
|
|
|
self.seat.setFocusRaw(.{ .layer = layer_surface });
|
2021-12-10 14:40:48 -08:00
|
|
|
} else {
|
|
|
|
self.seat.focus(null);
|
2021-07-23 07:33:25 -07:00
|
|
|
}
|
|
|
|
},
|
2021-09-27 09:34:59 -07:00
|
|
|
.xwayland_unmanaged => assert(build_options.xwayland),
|
2020-04-18 03:21:43 -07:00
|
|
|
}
|
2020-11-03 15:23:21 -08:00
|
|
|
_ = self.seat.wlr_seat.pointerNotifyButton(event.time_msec, event.button, event.state);
|
2021-12-28 22:19:37 -08:00
|
|
|
|
|
|
|
self.mode = .{
|
|
|
|
.down = .{
|
|
|
|
.lx = self.wlr_cursor.x,
|
|
|
|
.ly = self.wlr_cursor.y,
|
|
|
|
.sx = result.sx,
|
|
|
|
.sy = result.sy,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
server.root.startTransaction();
|
2021-12-10 14:40:48 -08:00
|
|
|
} else if (server.root.output_layout.outputAt(self.wlr_cursor.x, self.wlr_cursor.y)) |wlr_output| {
|
|
|
|
// If the user clicked on empty space of an output, focus it.
|
|
|
|
const output = @intToPtr(*Output, wlr_output.data);
|
|
|
|
self.seat.focusOutput(output);
|
|
|
|
self.seat.focus(null);
|
|
|
|
server.root.startTransaction();
|
2020-04-18 03:21:43 -07:00
|
|
|
}
|
2020-05-02 07:47:10 -07:00
|
|
|
}
|
|
|
|
|
2021-02-14 10:32:04 -08:00
|
|
|
fn handlePinchBegin(
|
|
|
|
listener: *wl.Listener(*wlr.Pointer.event.PinchBegin),
|
|
|
|
event: *wlr.Pointer.event.PinchBegin,
|
|
|
|
) void {
|
|
|
|
const self = @fieldParentPtr(Self, "pinch_begin", listener);
|
|
|
|
self.pointer_gestures.sendPinchBegin(
|
|
|
|
self.seat.wlr_seat,
|
|
|
|
event.time_msec,
|
|
|
|
event.fingers,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn handlePinchUpdate(
|
|
|
|
listener: *wl.Listener(*wlr.Pointer.event.PinchUpdate),
|
|
|
|
event: *wlr.Pointer.event.PinchUpdate,
|
|
|
|
) void {
|
|
|
|
const self = @fieldParentPtr(Self, "pinch_update", listener);
|
|
|
|
self.pointer_gestures.sendPinchUpdate(
|
|
|
|
self.seat.wlr_seat,
|
|
|
|
event.time_msec,
|
|
|
|
event.dx,
|
|
|
|
event.dy,
|
|
|
|
event.scale,
|
|
|
|
event.rotation,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn handlePinchEnd(
|
|
|
|
listener: *wl.Listener(*wlr.Pointer.event.PinchEnd),
|
|
|
|
event: *wlr.Pointer.event.PinchEnd,
|
|
|
|
) void {
|
|
|
|
const self = @fieldParentPtr(Self, "pinch_end", listener);
|
|
|
|
self.pointer_gestures.sendPinchEnd(
|
|
|
|
self.seat.wlr_seat,
|
|
|
|
event.time_msec,
|
|
|
|
event.cancelled,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn handleSwipeBegin(
|
|
|
|
listener: *wl.Listener(*wlr.Pointer.event.SwipeBegin),
|
|
|
|
event: *wlr.Pointer.event.SwipeBegin,
|
|
|
|
) void {
|
|
|
|
const self = @fieldParentPtr(Self, "swipe_begin", listener);
|
|
|
|
self.pointer_gestures.sendSwipeBegin(
|
|
|
|
self.seat.wlr_seat,
|
|
|
|
event.time_msec,
|
|
|
|
event.fingers,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn handleSwipeUpdate(
|
|
|
|
listener: *wl.Listener(*wlr.Pointer.event.SwipeUpdate),
|
|
|
|
event: *wlr.Pointer.event.SwipeUpdate,
|
|
|
|
) void {
|
|
|
|
const self = @fieldParentPtr(Self, "swipe_update", listener);
|
|
|
|
self.pointer_gestures.sendSwipeUpdate(
|
|
|
|
self.seat.wlr_seat,
|
|
|
|
event.time_msec,
|
|
|
|
event.dx,
|
|
|
|
event.dy,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn handleSwipeEnd(
|
|
|
|
listener: *wl.Listener(*wlr.Pointer.event.SwipeEnd),
|
|
|
|
event: *wlr.Pointer.event.SwipeEnd,
|
|
|
|
) void {
|
|
|
|
const self = @fieldParentPtr(Self, "swipe_end", listener);
|
|
|
|
self.pointer_gestures.sendSwipeEnd(
|
|
|
|
self.seat.wlr_seat,
|
|
|
|
event.time_msec,
|
|
|
|
event.cancelled,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-24 05:52:47 -07:00
|
|
|
/// Handle the mapping for the passed button if any. Returns true if there
|
|
|
|
/// was a mapping and the button was handled.
|
2020-11-03 15:23:21 -08:00
|
|
|
fn handlePointerMapping(self: *Self, event: *wlr.Pointer.event.Button, view: *View) bool {
|
|
|
|
const wlr_keyboard = self.seat.wlr_seat.getKeyboard() orelse return false;
|
|
|
|
const modifiers = wlr_keyboard.getModifiers();
|
2020-08-24 05:52:47 -07:00
|
|
|
|
|
|
|
const fullscreen = view.current.fullscreen or view.pending.fullscreen;
|
|
|
|
|
2021-05-13 05:53:08 -07:00
|
|
|
return for (server.config.modes.items[self.seat.mode_id].pointer_mappings.items) |mapping| {
|
2020-11-03 15:23:21 -08:00
|
|
|
if (event.button == mapping.event_code and std.meta.eql(modifiers, mapping.modifiers)) {
|
2020-08-24 05:52:47 -07:00
|
|
|
switch (mapping.action) {
|
2020-10-17 13:40:15 -07:00
|
|
|
.move => if (!fullscreen) self.enterMode(.move, view),
|
|
|
|
.resize => if (!fullscreen) self.enterMode(.resize, view),
|
2020-08-24 05:52:47 -07:00
|
|
|
}
|
|
|
|
break true;
|
|
|
|
}
|
|
|
|
} else false;
|
|
|
|
}
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
/// Frame events are sent after regular pointer events to group multiple
|
|
|
|
/// events together. For instance, two axis events may happen at the same
|
|
|
|
/// time, in which case a frame event won't be sent in between.
|
2021-10-11 03:44:46 -07:00
|
|
|
fn handleFrame(listener: *wl.Listener(*wlr.Cursor), _: *wlr.Cursor) void {
|
2020-11-03 15:23:21 -08:00
|
|
|
const self = @fieldParentPtr(Self, "frame", listener);
|
|
|
|
self.seat.wlr_seat.pointerNotifyFrame();
|
2020-05-02 07:47:10 -07:00
|
|
|
}
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
/// This event is forwarded by the cursor when a pointer emits an _absolute_
|
|
|
|
/// motion event, from 0..1 on each axis. This happens, for example, when
|
|
|
|
/// wlroots is running under a Wayland window rather than KMS+DRM, and you
|
|
|
|
/// move the mouse over the window. You could enter the window from any edge,
|
|
|
|
/// so we have to warp the mouse there. There is also some hardware which
|
|
|
|
/// emits these events.
|
|
|
|
fn handleMotionAbsolute(
|
|
|
|
listener: *wl.Listener(*wlr.Pointer.event.MotionAbsolute),
|
|
|
|
event: *wlr.Pointer.event.MotionAbsolute,
|
|
|
|
) void {
|
|
|
|
const self = @fieldParentPtr(Self, "motion_absolute", listener);
|
2020-08-07 02:51:53 -07:00
|
|
|
|
2020-08-13 03:22:32 -07:00
|
|
|
self.seat.handleActivity();
|
|
|
|
|
2020-08-07 02:51:53 -07:00
|
|
|
var lx: f64 = undefined;
|
|
|
|
var ly: f64 = undefined;
|
2020-11-03 15:23:21 -08:00
|
|
|
self.wlr_cursor.absoluteToLayoutCoords(event.device, event.x, event.y, &lx, &ly);
|
2020-08-07 02:51:53 -07:00
|
|
|
|
2021-02-15 12:07:29 -08:00
|
|
|
const dx = lx - self.wlr_cursor.x;
|
|
|
|
const dy = ly - self.wlr_cursor.y;
|
|
|
|
self.processMotion(event.device, event.time_msec, dx, dy, dx, dy);
|
2020-05-02 07:47:10 -07:00
|
|
|
}
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
/// This event is forwarded by the cursor when a pointer emits a _relative_
|
|
|
|
/// pointer motion event (i.e. a delta)
|
|
|
|
fn handleMotion(
|
|
|
|
listener: *wl.Listener(*wlr.Pointer.event.Motion),
|
|
|
|
event: *wlr.Pointer.event.Motion,
|
|
|
|
) void {
|
|
|
|
const self = @fieldParentPtr(Self, "motion", listener);
|
2020-08-07 02:51:53 -07:00
|
|
|
|
2020-08-13 03:22:32 -07:00
|
|
|
self.seat.handleActivity();
|
|
|
|
|
2021-02-15 12:07:29 -08:00
|
|
|
self.processMotion(event.device, event.time_msec, event.delta_x, event.delta_y, event.unaccel_dx, event.unaccel_dy);
|
2020-05-02 07:47:10 -07:00
|
|
|
}
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
fn handleRequestSetCursor(
|
|
|
|
listener: *wl.Listener(*wlr.Seat.event.RequestSetCursor),
|
|
|
|
event: *wlr.Seat.event.RequestSetCursor,
|
|
|
|
) void {
|
2020-05-02 07:47:10 -07:00
|
|
|
// This event is rasied by the seat when a client provides a cursor image
|
2020-11-03 15:23:21 -08:00
|
|
|
const self = @fieldParentPtr(Self, "request_set_cursor", listener);
|
2020-05-02 07:47:10 -07:00
|
|
|
const focused_client = self.seat.wlr_seat.pointer_state.focused_client;
|
|
|
|
|
|
|
|
// This can be sent by any client, so we check to make sure this one is
|
|
|
|
// actually has pointer focus first.
|
|
|
|
if (focused_client == event.seat_client) {
|
|
|
|
// Once we've vetted the client, we can tell the cursor to use the
|
|
|
|
// provided surface as the cursor image. It will set the hardware cursor
|
|
|
|
// on the output that it's currently on and continue to do so as the
|
|
|
|
// cursor moves between outputs.
|
2021-02-05 00:46:18 -08:00
|
|
|
log.debug("focused client set cursor", .{});
|
2020-11-03 15:23:21 -08:00
|
|
|
self.wlr_cursor.setSurface(event.surface, event.hotspot_x, event.hotspot_y);
|
2021-12-21 20:32:23 -08:00
|
|
|
self.image = .unknown;
|
2020-04-18 03:21:43 -07:00
|
|
|
}
|
2020-05-02 07:47:10 -07:00
|
|
|
}
|
|
|
|
|
2021-07-23 07:33:25 -07:00
|
|
|
const SurfaceAtResult = struct {
|
|
|
|
surface: *wlr.Surface,
|
|
|
|
sx: f64,
|
|
|
|
sy: f64,
|
|
|
|
parent: union(enum) {
|
|
|
|
view: *View,
|
|
|
|
layer_surface: *LayerSurface,
|
2021-09-27 09:34:59 -07:00
|
|
|
xwayland_unmanaged: if (build_options.xwayland) *XwaylandUnmanaged else void,
|
2021-07-23 07:33:25 -07:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-07-23 07:52:48 -07:00
|
|
|
/// Find the surface under the cursor if any, and return information about that
|
|
|
|
/// surface and the cursor's position in surface local coords.
|
2021-04-27 09:28:28 -07:00
|
|
|
/// This function must be kept in sync with the rendering order in render.zig.
|
2021-07-23 07:52:48 -07:00
|
|
|
pub fn surfaceAt(self: Self) ?SurfaceAtResult {
|
|
|
|
const lx = self.wlr_cursor.x;
|
|
|
|
const ly = self.wlr_cursor.y;
|
2021-05-13 05:53:08 -07:00
|
|
|
const wlr_output = server.root.output_layout.outputAt(lx, ly) orelse return null;
|
2020-11-03 15:23:21 -08:00
|
|
|
const output = @intToPtr(*Output, wlr_output.data);
|
2020-05-02 07:47:10 -07:00
|
|
|
|
|
|
|
// Get output-local coords from the layout coords
|
|
|
|
var ox = lx;
|
|
|
|
var oy = ly;
|
2021-05-13 05:53:08 -07:00
|
|
|
server.root.output_layout.outputCoords(wlr_output, &ox, &oy);
|
2020-05-02 07:47:10 -07:00
|
|
|
|
2021-07-23 04:40:54 -07:00
|
|
|
// Find the first visible fullscreen view in the stack if there is one
|
|
|
|
var it = ViewStack(View).iter(output.views.first, .forward, output.current.tags, surfaceAtFilter);
|
|
|
|
const fullscreen_view = while (it.next()) |view| {
|
|
|
|
if (view.current.fullscreen) break view;
|
|
|
|
} else null;
|
|
|
|
|
2021-04-27 09:56:06 -07:00
|
|
|
// Check surfaces in the reverse order they are rendered in:
|
2021-07-23 04:40:54 -07:00
|
|
|
//
|
|
|
|
// fullscreen:
|
|
|
|
// 1. overlay layer toplevels and popups
|
|
|
|
// 2. xwayland unmanaged stuff
|
|
|
|
// 3. fullscreen view toplevels and popups
|
|
|
|
//
|
|
|
|
// non-fullscreen:
|
|
|
|
// 1. overlay layer toplevels and popups
|
|
|
|
// 2. top, bottom, background layer popups
|
|
|
|
// 3. top layer toplevels
|
|
|
|
// 4. xwayland unmanaged stuff
|
|
|
|
// 5. view toplevels and popups
|
|
|
|
// 6. bottom, background layer toplevels
|
|
|
|
|
2021-07-23 07:33:25 -07:00
|
|
|
if (layerSurfaceAt(output.getLayer(.overlay).*, ox, oy)) |s| return s;
|
2020-04-24 05:51:10 -07:00
|
|
|
|
2021-07-23 04:40:54 -07:00
|
|
|
if (fullscreen_view) |view| {
|
2021-09-27 09:34:59 -07:00
|
|
|
if (build_options.xwayland) if (xwaylandUnmanagedSurfaceAt(ly, lx)) |s| return s;
|
2021-07-23 07:33:25 -07:00
|
|
|
var sx: f64 = undefined;
|
|
|
|
var sy: f64 = undefined;
|
|
|
|
if (view.surfaceAt(ox, oy, &sx, &sy)) |found| {
|
|
|
|
return SurfaceAtResult{
|
|
|
|
.surface = found,
|
|
|
|
.sx = sx,
|
|
|
|
.sy = sy,
|
|
|
|
.parent = .{ .view = view },
|
|
|
|
};
|
|
|
|
}
|
2021-07-23 04:40:54 -07:00
|
|
|
} else {
|
|
|
|
for ([_]zwlr.LayerShellV1.Layer{ .top, .bottom, .background }) |layer| {
|
2021-07-23 07:33:25 -07:00
|
|
|
if (layerPopupSurfaceAt(output.getLayer(layer).*, ox, oy)) |s| return s;
|
2021-07-23 04:40:54 -07:00
|
|
|
}
|
2020-03-24 12:35:45 -07:00
|
|
|
|
2021-07-23 07:33:25 -07:00
|
|
|
if (layerSurfaceAt(output.getLayer(.top).*, ox, oy)) |s| return s;
|
2020-04-24 05:51:10 -07:00
|
|
|
|
2021-09-27 09:34:59 -07:00
|
|
|
if (build_options.xwayland) if (xwaylandUnmanagedSurfaceAt(lx, ly)) |s| return s;
|
2020-03-22 14:42:55 -07:00
|
|
|
|
2021-07-23 07:33:25 -07:00
|
|
|
if (viewSurfaceAt(output, ox, oy)) |s| return s;
|
2021-07-23 04:40:54 -07:00
|
|
|
|
|
|
|
for ([_]zwlr.LayerShellV1.Layer{ .bottom, .background }) |layer| {
|
2021-07-23 07:33:25 -07:00
|
|
|
if (layerSurfaceAt(output.getLayer(layer).*, ox, oy)) |s| return s;
|
2021-07-23 04:40:54 -07:00
|
|
|
}
|
2021-04-27 09:56:06 -07:00
|
|
|
}
|
2020-04-24 05:51:10 -07:00
|
|
|
|
2020-05-02 07:47:10 -07:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-04-27 09:56:06 -07:00
|
|
|
/// Find the topmost popup surface on the given layer at ox,oy.
|
2021-07-23 07:33:25 -07:00
|
|
|
fn layerPopupSurfaceAt(layer: std.TailQueue(LayerSurface), ox: f64, oy: f64) ?SurfaceAtResult {
|
2021-04-27 09:56:06 -07:00
|
|
|
var it = layer.first;
|
|
|
|
while (it) |node| : (it = node.next) {
|
|
|
|
const layer_surface = &node.data;
|
2021-07-23 07:33:25 -07:00
|
|
|
var sx: f64 = undefined;
|
|
|
|
var sy: f64 = undefined;
|
2021-04-27 09:56:06 -07:00
|
|
|
if (layer_surface.wlr_layer_surface.popupSurfaceAt(
|
|
|
|
ox - @intToFloat(f64, layer_surface.box.x),
|
|
|
|
oy - @intToFloat(f64, layer_surface.box.y),
|
2021-07-23 07:33:25 -07:00
|
|
|
&sx,
|
|
|
|
&sy,
|
|
|
|
)) |found| {
|
|
|
|
return SurfaceAtResult{
|
|
|
|
.surface = found,
|
|
|
|
.sx = sx,
|
|
|
|
.sy = sy,
|
|
|
|
.parent = .{ .layer_surface = layer_surface },
|
|
|
|
};
|
|
|
|
}
|
2021-04-27 09:56:06 -07:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Find the topmost surface (or popup surface) on the given layer at ox,oy.
|
2021-07-23 07:33:25 -07:00
|
|
|
fn layerSurfaceAt(layer: std.TailQueue(LayerSurface), ox: f64, oy: f64) ?SurfaceAtResult {
|
2020-05-02 07:47:10 -07:00
|
|
|
var it = layer.first;
|
|
|
|
while (it) |node| : (it = node.next) {
|
|
|
|
const layer_surface = &node.data;
|
2021-07-23 07:33:25 -07:00
|
|
|
var sx: f64 = undefined;
|
|
|
|
var sy: f64 = undefined;
|
2020-11-03 15:23:21 -08:00
|
|
|
if (layer_surface.wlr_layer_surface.surfaceAt(
|
2020-05-02 07:47:10 -07:00
|
|
|
ox - @intToFloat(f64, layer_surface.box.x),
|
|
|
|
oy - @intToFloat(f64, layer_surface.box.y),
|
2021-07-23 07:33:25 -07:00
|
|
|
&sx,
|
|
|
|
&sy,
|
|
|
|
)) |found| {
|
|
|
|
return SurfaceAtResult{
|
|
|
|
.surface = found,
|
|
|
|
.sx = sx,
|
|
|
|
.sy = sy,
|
|
|
|
.parent = .{ .layer_surface = layer_surface },
|
|
|
|
};
|
|
|
|
}
|
2020-04-24 05:51:10 -07:00
|
|
|
}
|
2020-05-02 07:47:10 -07:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-06-27 08:33:09 -07:00
|
|
|
/// Find the topmost visible view surface (incl. popups) at ox,oy.
|
2021-07-23 07:33:25 -07:00
|
|
|
fn viewSurfaceAt(output: *const Output, ox: f64, oy: f64) ?SurfaceAtResult {
|
|
|
|
var sx: f64 = undefined;
|
|
|
|
var sy: f64 = undefined;
|
|
|
|
|
2021-04-27 09:28:28 -07:00
|
|
|
// focused, floating views
|
2020-08-21 06:08:28 -07:00
|
|
|
var it = ViewStack(View).iter(output.views.first, .forward, output.current.tags, surfaceAtFilter);
|
|
|
|
while (it.next()) |view| {
|
2021-04-27 09:28:28 -07:00
|
|
|
if (view.current.focus == 0 or !view.current.float) continue;
|
2021-07-23 07:33:25 -07:00
|
|
|
if (view.surfaceAt(ox, oy, &sx, &sy)) |found| {
|
|
|
|
return SurfaceAtResult{
|
|
|
|
.surface = found,
|
|
|
|
.sx = sx,
|
|
|
|
.sy = sy,
|
|
|
|
.parent = .{ .view = view },
|
|
|
|
};
|
|
|
|
}
|
2020-06-27 15:29:44 -07:00
|
|
|
}
|
|
|
|
|
2021-04-27 09:28:28 -07:00
|
|
|
// non-focused, floating views
|
2020-08-21 06:08:28 -07:00
|
|
|
it = ViewStack(View).iter(output.views.first, .forward, output.current.tags, surfaceAtFilter);
|
|
|
|
while (it.next()) |view| {
|
2021-04-27 09:28:28 -07:00
|
|
|
if (view.current.focus != 0 or !view.current.float) continue;
|
2021-07-23 07:33:25 -07:00
|
|
|
if (view.surfaceAt(ox, oy, &sx, &sy)) |found| {
|
|
|
|
return SurfaceAtResult{
|
|
|
|
.surface = found,
|
|
|
|
.sx = sx,
|
|
|
|
.sy = sy,
|
|
|
|
.parent = .{ .view = view },
|
|
|
|
};
|
|
|
|
}
|
2021-04-27 09:28:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// focused, non-floating views
|
|
|
|
it = ViewStack(View).iter(output.views.first, .forward, output.current.tags, surfaceAtFilter);
|
|
|
|
while (it.next()) |view| {
|
|
|
|
if (view.current.focus == 0 or view.current.float) continue;
|
2021-07-23 07:33:25 -07:00
|
|
|
if (view.surfaceAt(ox, oy, &sx, &sy)) |found| {
|
|
|
|
return SurfaceAtResult{
|
|
|
|
.surface = found,
|
|
|
|
.sx = sx,
|
|
|
|
.sy = sy,
|
|
|
|
.parent = .{ .view = view },
|
|
|
|
};
|
|
|
|
}
|
2021-04-27 09:28:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// non-focused, non-floating views
|
|
|
|
it = ViewStack(View).iter(output.views.first, .forward, output.current.tags, surfaceAtFilter);
|
|
|
|
while (it.next()) |view| {
|
|
|
|
if (view.current.focus != 0 or view.current.float) continue;
|
2021-07-23 07:33:25 -07:00
|
|
|
if (view.surfaceAt(ox, oy, &sx, &sy)) |found| {
|
|
|
|
return SurfaceAtResult{
|
|
|
|
.surface = found,
|
|
|
|
.sx = sx,
|
|
|
|
.sy = sy,
|
|
|
|
.parent = .{ .view = view },
|
|
|
|
};
|
|
|
|
}
|
2020-06-27 15:29:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2020-05-02 07:47:10 -07:00
|
|
|
}
|
2020-08-21 06:08:28 -07:00
|
|
|
|
2021-09-27 09:34:59 -07:00
|
|
|
fn xwaylandUnmanagedSurfaceAt(lx: f64, ly: f64) ?SurfaceAtResult {
|
2021-07-23 04:40:54 -07:00
|
|
|
var it = server.root.xwayland_unmanaged_views.first;
|
|
|
|
while (it) |node| : (it = node.next) {
|
|
|
|
const xwayland_surface = node.data.xwayland_surface;
|
2021-09-27 09:34:59 -07:00
|
|
|
var sx: f64 = undefined;
|
|
|
|
var sy: f64 = undefined;
|
2021-07-23 04:40:54 -07:00
|
|
|
if (xwayland_surface.surface.?.surfaceAt(
|
|
|
|
lx - @intToFloat(f64, xwayland_surface.x),
|
|
|
|
ly - @intToFloat(f64, xwayland_surface.y),
|
2021-09-27 09:34:59 -07:00
|
|
|
&sx,
|
|
|
|
&sy,
|
|
|
|
)) |found| {
|
|
|
|
return SurfaceAtResult{
|
|
|
|
.surface = found,
|
|
|
|
.sx = sx,
|
|
|
|
.sy = sy,
|
|
|
|
.parent = .{ .xwayland_unmanaged = &node.data },
|
|
|
|
};
|
|
|
|
}
|
2021-07-23 04:40:54 -07:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-08-21 06:08:28 -07:00
|
|
|
fn surfaceAtFilter(view: *View, filter_tags: u32) bool {
|
2021-10-02 05:29:39 -07:00
|
|
|
return view.surface != null and view.current.tags & filter_tags != 0;
|
2020-08-21 06:08:28 -07:00
|
|
|
}
|
2020-10-17 13:40:15 -07:00
|
|
|
|
2021-12-28 22:19:37 -08:00
|
|
|
pub fn enterMode(self: *Self, mode: enum { move, resize }, view: *View) void {
|
2021-07-14 06:32:24 -07:00
|
|
|
log.debug("enter {s} cursor mode", .{@tagName(mode)});
|
2020-10-17 13:40:15 -07:00
|
|
|
|
|
|
|
self.seat.focus(view);
|
|
|
|
|
|
|
|
switch (mode) {
|
2021-12-28 22:19:37 -08:00
|
|
|
.move => self.mode = .{ .move = .{ .view = view } },
|
|
|
|
.resize => {
|
|
|
|
const cur_box = &view.current.box;
|
|
|
|
self.mode = .{ .resize = .{
|
|
|
|
.view = view,
|
|
|
|
.offset_x = cur_box.x + @intCast(i32, cur_box.width) - @floatToInt(i32, self.wlr_cursor.x),
|
|
|
|
.offset_y = cur_box.y + @intCast(i32, cur_box.height) - @floatToInt(i32, self.wlr_cursor.y),
|
|
|
|
} };
|
|
|
|
view.setResizing(true);
|
2020-10-17 13:40:15 -07:00
|
|
|
},
|
2021-12-28 22:19:37 -08:00
|
|
|
}
|
2020-10-17 13:40:15 -07:00
|
|
|
|
2021-12-28 22:19:37 -08:00
|
|
|
// Automatically float all views being moved by the pointer, if
|
|
|
|
// their dimensions are set by a layout generator. If however the views
|
|
|
|
// are unarranged, leave them as non-floating so the next active
|
|
|
|
// layout can affect them.
|
|
|
|
if (!view.current.float and view.output.current.layout != null) {
|
|
|
|
view.pending.float = true;
|
|
|
|
view.float_box = view.current.box;
|
|
|
|
view.applyPending();
|
|
|
|
} else {
|
|
|
|
// The View.applyPending() call in the other branch starts
|
|
|
|
// the transaction needed after the seat.focus() call above.
|
|
|
|
server.root.startTransaction();
|
|
|
|
}
|
2020-10-17 13:40:15 -07:00
|
|
|
|
2021-12-28 22:19:37 -08:00
|
|
|
// Clear cursor focus, so that the surface does not receive events
|
|
|
|
self.seat.wlr_seat.pointerNotifyClearFocus();
|
2020-10-17 13:40:15 -07:00
|
|
|
|
2021-12-28 22:19:37 -08:00
|
|
|
self.setImage(if (mode == .move) .move else .@"se-resize");
|
2020-10-17 13:40:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Return from down/move/resize to passthrough
|
2020-11-03 15:23:21 -08:00
|
|
|
fn leaveMode(self: *Self, event: *wlr.Pointer.event.Button) void {
|
2021-05-23 04:35:37 -07:00
|
|
|
log.debug("leave {s} mode", .{@tagName(self.mode)});
|
2020-10-17 13:40:15 -07:00
|
|
|
|
2021-07-14 06:32:24 -07:00
|
|
|
switch (self.mode) {
|
|
|
|
.passthrough => unreachable,
|
|
|
|
.down => {
|
|
|
|
// If we were in down mode, we need pass along the release event
|
|
|
|
_ = self.seat.wlr_seat.pointerNotifyButton(event.time_msec, event.button, event.state);
|
|
|
|
},
|
|
|
|
.move => {},
|
|
|
|
.resize => |resize| resize.view.setResizing(false),
|
|
|
|
}
|
2020-10-17 13:40:15 -07:00
|
|
|
|
|
|
|
self.mode = .passthrough;
|
|
|
|
self.passthrough(event.time_msec);
|
|
|
|
}
|
|
|
|
|
2021-02-15 12:07:29 -08:00
|
|
|
fn processMotion(self: *Self, device: *wlr.InputDevice, time: u32, delta_x: f64, delta_y: f64, unaccel_dx: f64, unaccel_dy: f64) void {
|
2021-05-13 06:13:17 -07:00
|
|
|
server.input_manager.relative_pointer_manager.sendRelativeMotion(
|
2021-02-15 12:07:29 -08:00
|
|
|
self.seat.wlr_seat,
|
|
|
|
@as(u64, time) * 1000,
|
|
|
|
delta_x,
|
|
|
|
delta_y,
|
|
|
|
unaccel_dx,
|
|
|
|
unaccel_dy,
|
|
|
|
);
|
|
|
|
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;
|
|
|
|
|
2021-07-23 07:52:48 -07:00
|
|
|
const result = self.surfaceAt() orelse return;
|
2021-02-15 12:07:29 -08:00
|
|
|
|
2021-07-23 07:33:25 -07:00
|
|
|
if (result.surface != constraint.surface) return;
|
2021-02-15 12:07:29 -08:00
|
|
|
|
2021-07-23 07:33:25 -07:00
|
|
|
const sx = result.sx;
|
|
|
|
const sy = result.sy;
|
2021-02-15 12:07:29 -08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2020-10-17 13:40:15 -07:00
|
|
|
switch (self.mode) {
|
|
|
|
.passthrough => {
|
2021-02-15 12:07:29 -08:00
|
|
|
self.wlr_cursor.move(device, dx, dy);
|
2021-11-19 02:33:27 -08:00
|
|
|
self.checkFocusFollowsCursor();
|
2020-10-17 13:40:15 -07:00
|
|
|
self.passthrough(time);
|
|
|
|
},
|
2021-12-28 22:19:37 -08:00
|
|
|
.down => |down| {
|
2021-02-15 12:07:29 -08:00
|
|
|
self.wlr_cursor.move(device, dx, dy);
|
2020-11-03 15:23:21 -08:00
|
|
|
self.seat.wlr_seat.pointerNotifyMotion(
|
2020-10-17 13:40:15 -07:00
|
|
|
time,
|
2021-12-28 22:19:37 -08:00
|
|
|
down.sx + (self.wlr_cursor.x - down.lx),
|
|
|
|
down.sy + (self.wlr_cursor.y - down.ly),
|
2020-10-17 13:40:15 -07:00
|
|
|
);
|
|
|
|
},
|
2021-10-30 10:16:31 -07:00
|
|
|
.move => |*data| {
|
|
|
|
dx += data.delta_x;
|
|
|
|
dy += data.delta_y;
|
|
|
|
data.delta_x = dx - @trunc(dx);
|
|
|
|
data.delta_y = dy - @trunc(dy);
|
|
|
|
|
|
|
|
const view = data.view;
|
|
|
|
view.move(@floatToInt(i32, dx), @floatToInt(i32, dy));
|
2020-11-03 15:23:21 -08:00
|
|
|
self.wlr_cursor.move(
|
2020-10-17 13:40:15 -07:00
|
|
|
device,
|
|
|
|
@intToFloat(f64, view.pending.box.x - view.current.box.x),
|
|
|
|
@intToFloat(f64, view.pending.box.y - view.current.box.y),
|
|
|
|
);
|
|
|
|
view.applyPending();
|
|
|
|
},
|
2021-10-30 10:16:31 -07:00
|
|
|
.resize => |*data| {
|
|
|
|
dx += data.delta_x;
|
|
|
|
dy += data.delta_y;
|
|
|
|
data.delta_x = dx - @trunc(dx);
|
|
|
|
data.delta_y = dy - @trunc(dy);
|
|
|
|
|
2021-05-13 05:53:08 -07:00
|
|
|
const border_width = if (data.view.draw_borders) server.config.border_width else 0;
|
2020-10-17 13:40:15 -07:00
|
|
|
|
|
|
|
// Set width/height of view, clamp to view size constraints and output dimensions
|
|
|
|
const box = &data.view.pending.box;
|
2021-10-30 10:16:31 -07:00
|
|
|
box.width = @intCast(u32, math.max(0, @intCast(i32, box.width) + @floatToInt(i32, dx)));
|
|
|
|
box.height = @intCast(u32, math.max(0, @intCast(i32, box.height) + @floatToInt(i32, dy)));
|
2020-10-17 13:40:15 -07:00
|
|
|
|
|
|
|
data.view.applyConstraints();
|
|
|
|
|
|
|
|
const output_resolution = data.view.output.getEffectiveResolution();
|
2020-12-26 16:06:18 -08:00
|
|
|
box.width = math.min(box.width, output_resolution.width - border_width - @intCast(u32, box.x));
|
|
|
|
box.height = math.min(box.height, output_resolution.height - border_width - @intCast(u32, box.y));
|
2020-10-17 13:40:15 -07:00
|
|
|
|
|
|
|
data.view.applyPending();
|
|
|
|
|
|
|
|
// Keep cursor locked to the original offset from the bottom right corner
|
2020-11-03 15:23:21 -08:00
|
|
|
self.wlr_cursor.warpClosest(
|
2020-10-17 13:40:15 -07:00
|
|
|
device,
|
|
|
|
@intToFloat(f64, box.x + @intCast(i32, box.width) - data.offset_x),
|
|
|
|
@intToFloat(f64, box.y + @intCast(i32, box.height) - data.offset_y),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-19 02:33:27 -08:00
|
|
|
pub fn checkFocusFollowsCursor(self: *Self) void {
|
|
|
|
// Don't do focus-follows-cursor if a drag is in progress as focus change can't occur
|
|
|
|
if (self.seat.pointer_drag) return;
|
|
|
|
if (server.config.focus_follows_cursor == .disabled) return;
|
|
|
|
if (self.surfaceAt()) |result| {
|
|
|
|
if (self.seat.wlr_seat.pointer_state.focused_surface != result.surface) {
|
|
|
|
switch (result.parent) {
|
|
|
|
.view => |view| {
|
|
|
|
if (self.seat.focused != .view or self.seat.focused.view != view) {
|
|
|
|
self.seat.focusOutput(view.output);
|
|
|
|
self.seat.focus(view);
|
|
|
|
server.root.startTransaction();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
.layer_surface => {},
|
|
|
|
.xwayland_unmanaged => assert(build_options.xwayland),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-23 06:56:38 -07:00
|
|
|
/// 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.
|
2021-07-23 10:18:49 -07:00
|
|
|
pub fn updateState(self: *Self) void {
|
2021-07-23 17:30:15 -07:00
|
|
|
if (self.shouldPassthrough()) {
|
2021-07-23 10:18:49 -07:00
|
|
|
self.mode = .passthrough;
|
|
|
|
var now: os.timespec = undefined;
|
2021-10-11 03:44:46 -07:00
|
|
|
os.clock_gettime(os.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported");
|
2021-07-23 10:18:49 -07:00
|
|
|
const msec = @intCast(u32, now.tv_sec * std.time.ms_per_s +
|
|
|
|
@divFloor(now.tv_nsec, std.time.ns_per_ms));
|
|
|
|
self.passthrough(msec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-23 17:30:15 -07:00
|
|
|
fn shouldPassthrough(self: Self) bool {
|
2021-06-23 06:56:38 -07:00
|
|
|
switch (self.mode) {
|
2021-07-23 17:30:15 -07:00
|
|
|
.passthrough => {
|
|
|
|
// If we are not currently in down/resize/move mode, we *always* need to passthrough()
|
|
|
|
// as what is under the cursor may have changed and we are not locked to a single
|
|
|
|
// target view.
|
|
|
|
return true;
|
|
|
|
},
|
2021-12-28 22:19:37 -08:00
|
|
|
.down => {
|
|
|
|
// TODO: It's hard to determine from the target surface alone whether
|
|
|
|
// the surface is visible or not currently. Switching to the wlroots
|
|
|
|
// scene graph will fix this, but for now just don't bother.
|
|
|
|
return false;
|
2021-06-23 06:56:38 -07:00
|
|
|
},
|
|
|
|
.resize, .move => {
|
2021-10-30 10:16:31 -07:00
|
|
|
const target = if (self.mode == .resize) self.mode.resize.view else self.mode.move.view;
|
2021-07-23 10:18:49 -07:00
|
|
|
// 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
|
2021-06-23 06:56:38 -07:00
|
|
|
(!target.current.float and target.output.current.layout != null) or
|
2021-07-23 10:18:49 -07:00
|
|
|
target.current.fullscreen;
|
2021-06-23 06:56:38 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-17 13:40:15 -07:00
|
|
|
/// Pass an event on to the surface under the cursor, if any.
|
|
|
|
fn passthrough(self: *Self, time: u32) void {
|
2021-07-14 06:32:24 -07:00
|
|
|
assert(self.mode == .passthrough);
|
|
|
|
|
2021-07-23 07:52:48 -07:00
|
|
|
if (self.surfaceAt()) |result| {
|
2020-10-17 13:40:15 -07:00
|
|
|
// 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.
|
2021-07-23 07:33:25 -07:00
|
|
|
if (server.input_manager.inputAllowed(result.surface)) {
|
|
|
|
self.seat.wlr_seat.pointerNotifyEnter(result.surface, result.sx, result.sy);
|
|
|
|
self.seat.wlr_seat.pointerNotifyMotion(time, result.sx, result.sy);
|
2020-10-17 13:40:15 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// There is either no surface under the cursor or input is disallowed
|
|
|
|
// Reset the cursor image to the default and clear focus.
|
|
|
|
self.clearFocus();
|
|
|
|
}
|
|
|
|
}
|