aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsaac Freund <ifreund@ifreund.xyz>2021-07-14 15:32:24 +0200
committerIsaac Freund <ifreund@ifreund.xyz>2021-07-14 15:32:24 +0200
commitd413db92270eef22c7de19c13fd555cc12e6db19 (patch)
tree445e0dbda78bf985d39a4efcd8348d7574dd37ba
parent7b18b4944e8534733a5d65c343976064532333b4 (diff)
downloadriver-d413db92270eef22c7de19c13fd555cc12e6db19.tar.gz
river-d413db92270eef22c7de19c13fd555cc12e6db19.tar.xz
xdg-shell: set resizing state during interactive resize
-rw-r--r--river/Cursor.zig38
-rw-r--r--river/View.zig7
-rw-r--r--river/XdgToplevel.zig4
3 files changed, 36 insertions, 13 deletions
diff --git a/river/Cursor.zig b/river/Cursor.zig
index 888ab08..5a09a88 100644
--- a/river/Cursor.zig
+++ b/river/Cursor.zig
@@ -19,6 +19,7 @@ const Self = @This();
const build_options = @import("build_options");
const std = @import("std");
+const assert = std.debug.assert;
const math = std.math;
const wlr = @import("wlroots");
const wayland = @import("wayland");
@@ -524,7 +525,7 @@ fn surfaceAtFilter(view: *View, filter_tags: u32) bool {
/// Enter move or resize mode
pub fn enterMode(self: *Self, mode: std.meta.Tag((Mode)), view: *View) void {
- log.debug("enter {s} mode", .{@tagName(mode)});
+ log.debug("enter {s} cursor mode", .{@tagName(mode)});
self.seat.focus(view);
@@ -535,18 +536,19 @@ pub fn enterMode(self: *Self, mode: std.meta.Tag((Mode)), view: *View) void {
server.root.startTransaction();
},
.move, .resize => {
- const cur_box = &view.current.box;
- self.mode = switch (mode) {
+ switch (mode) {
.passthrough, .down => unreachable,
- .move => .{ .move = view },
- .resize => .{
- .resize = .{
+ .move => self.mode = .{ .move = 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);
},
- };
+ }
// Automatically float all views being moved by the pointer, if
// their dimensions are set by a layout client. If however the views
@@ -556,6 +558,10 @@ pub fn enterMode(self: *Self, mode: std.meta.Tag((Mode)), view: *View) void {
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();
}
// Clear cursor focus, so that the surface does not receive events
@@ -571,13 +577,17 @@ pub fn enterMode(self: *Self, mode: std.meta.Tag((Mode)), view: *View) void {
/// Return from down/move/resize to passthrough
fn leaveMode(self: *Self, event: *wlr.Pointer.event.Button) void {
- std.debug.assert(self.mode != .passthrough);
-
log.debug("leave {s} mode", .{@tagName(self.mode)});
- // If we were in down mode, we need pass along the release event
- if (self.mode == .down)
- _ = self.seat.wlr_seat.pointerNotifyButton(event.time_msec, event.button, event.state);
+ 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),
+ }
self.mode = .passthrough;
self.passthrough(event.time_msec);
@@ -666,6 +676,8 @@ fn processMotion(self: *Self, device: *wlr.InputDevice, time: u32, delta_x: f64,
/// Pass an event on to the surface under the cursor, if any.
fn passthrough(self: *Self, time: u32) void {
+ assert(self.mode == .passthrough);
+
var sx: f64 = undefined;
var sy: f64 = undefined;
if (self.surfaceAt(self.wlr_cursor.x, self.wlr_cursor.y, &sx, &sy)) |surface| {
diff --git a/river/View.zig b/river/View.zig
index 5b57774..567a910 100644
--- a/river/View.zig
+++ b/river/View.zig
@@ -338,6 +338,13 @@ pub fn setFullscreen(self: Self, fullscreen: bool) void {
}
}
+pub fn setResizing(self: Self, resizing: bool) void {
+ switch (self.impl) {
+ .xdg_toplevel => |xdg_toplevel| xdg_toplevel.setResizing(resizing),
+ .xwayland_view => unreachable,
+ }
+}
+
pub inline fn forEachPopupSurface(
self: Self,
comptime T: type,
diff --git a/river/XdgToplevel.zig b/river/XdgToplevel.zig
index 4bd8cc3..b56ed08 100644
--- a/river/XdgToplevel.zig
+++ b/river/XdgToplevel.zig
@@ -120,6 +120,10 @@ pub fn setFullscreen(self: Self, fullscreen: bool) void {
_ = self.xdg_surface.role_data.toplevel.setFullscreen(fullscreen);
}
+pub fn setResizing(self: Self, resizing: bool) void {
+ _ = self.xdg_surface.role_data.toplevel.setResizing(resizing);
+}
+
pub inline fn forEachPopupSurface(
self: Self,
comptime T: type,