1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
From 5c75c67fe49e5ab89e4a61dfb2fe74c768477b90 Mon Sep 17 00:00:00 2001
From: wochap <gean.marroquin@gmail.com>
Date: Fri, 5 Jul 2024 11:13:53 -0500
Subject: [PATCH] implement relative-muse-resize
---
dwl.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 59 insertions(+), 7 deletions(-)
diff --git a/dwl.c b/dwl.c
index dc0437e..ebf9ef1 100644
--- a/dwl.c
+++ b/dwl.c
@@ -401,7 +401,8 @@ static struct wlr_seat *seat;
static KeyboardGroup *kb_group;
static unsigned int cursor_mode;
static Client *grabc;
-static int grabcx, grabcy; /* client-relative */
+static Client initial_grabc;
+static int grabcx, grabcy, grabx, graby, grabcenterx, grabcentery; /* client-relative */
static struct wlr_output_layout *output_layout;
static struct wlr_box sgeom;
@@ -1821,8 +1822,27 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double d
.width = grabc->geom.width, .height = grabc->geom.height}, 1);
return;
} else if (cursor_mode == CurResize) {
- resize(grabc, (struct wlr_box){.x = grabc->geom.x, .y = grabc->geom.y,
- .width = (int)round(cursor->x) - grabc->geom.x, .height = (int)round(cursor->y) - grabc->geom.y}, 1);
+ if (grabcenterx < grabx) {
+ if (grabcentery < graby) {
+ /* bottom-right */
+ resize(grabc, (struct wlr_box){.x = initial_grabc.geom.x, .y = initial_grabc.geom.y,
+ .width = (int)round(cursor->x) - initial_grabc.geom.x, .height = (int)round(cursor->y) - initial_grabc.geom.y}, 1);
+ } else {
+ /* top-right */
+ resize(grabc, (struct wlr_box){.x = initial_grabc.geom.x, .y = (int)round(cursor->y),
+ .width = (int)round(cursor->x) - initial_grabc.geom.x, .height = initial_grabc.geom.y + initial_grabc.geom.height - (int)round(cursor->y)}, 1);
+ }
+ } else {
+ if (grabcentery < graby) {
+ /* bottom-left */
+ resize(grabc, (struct wlr_box){.x = (int)round(cursor->x), .y = initial_grabc.geom.y,
+ .width = initial_grabc.geom.x + initial_grabc.geom.width - (int)round(cursor->x), .height = (int)round(cursor->y) - initial_grabc.geom.y}, 1);
+ } else {
+ /* top-left */
+ resize(grabc, (struct wlr_box){.x = (int)round(cursor->x), .y = (int)round(cursor->y),
+ .width = initial_grabc.geom.x + initial_grabc.geom.width - (int)round(cursor->x), .height = initial_grabc.geom.y + initial_grabc.geom.height - (int)round(cursor->y)}, 1);
+ }
+ }
return;
}
@@ -1870,10 +1890,42 @@ moveresize(const Arg *arg)
case CurResize:
/* Doesn't work for X11 output - the next absolute motion event
* returns the cursor to where it started */
- wlr_cursor_warp_closest(cursor, NULL,
- grabc->geom.x + grabc->geom.width,
- grabc->geom.y + grabc->geom.height);
- wlr_cursor_set_xcursor(cursor, cursor_mgr, "se-resize");
+ initial_grabc = *grabc;
+ grabx = (int)round(cursor->x);
+ graby = (int)round(cursor->y);
+ grabcx = (int)round(cursor->x) - grabc->geom.x;
+ grabcy = (int)round(cursor->y) - grabc->geom.y;
+ grabcenterx = grabc->geom.width / 2 + grabc->geom.x;
+ grabcentery = grabc->geom.height / 2 + grabc->geom.y;
+ if (grabcenterx < grabx) {
+ if (grabcentery < graby) {
+ /* bottom-right */
+ wlr_cursor_warp_closest(cursor, NULL,
+ grabc->geom.x + grabc->geom.width,
+ grabc->geom.y + grabc->geom.height);
+ wlr_cursor_set_xcursor(cursor, cursor_mgr, "se-resize");
+ } else {
+ /* top-right */
+ wlr_cursor_warp_closest(cursor, NULL,
+ grabc->geom.x + grabc->geom.width,
+ grabc->geom.y);
+ wlr_cursor_set_xcursor(cursor, cursor_mgr, "ne-resize");
+ }
+ } else {
+ if (grabcentery < graby) {
+ /* bottom-left */
+ wlr_cursor_warp_closest(cursor, NULL,
+ grabc->geom.x,
+ grabc->geom.y + grabc->geom.height);
+ wlr_cursor_set_xcursor(cursor, cursor_mgr, "sw-resize");
+ } else {
+ /* top-left */
+ wlr_cursor_warp_closest(cursor, NULL,
+ grabc->geom.x,
+ grabc->geom.y);
+ wlr_cursor_set_xcursor(cursor, cursor_mgr, "nw-resize");
+ }
+ }
break;
}
}
--
2.45.1
|