summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.def.h2
-rw-r--r--dwl.c101
2 files changed, 96 insertions, 7 deletions
diff --git a/config.def.h b/config.def.h
index d31b59e..66c2e01 100644
--- a/config.def.h
+++ b/config.def.h
@@ -148,6 +148,8 @@ static const Key keys[] = {
{ MODKEY, XKB_KEY_b, togglebar, {0} },
{ MODKEY, XKB_KEY_j, focusstack, {.i = +1} },
{ MODKEY, XKB_KEY_k, focusstack, {.i = -1} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_J, movestack, {.i = +1} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_K, movestack, {.i = -1} },
{ MODKEY, XKB_KEY_i, incnmaster, {.i = +1} },
{ MODKEY, XKB_KEY_d, incnmaster, {.i = -1} },
{ MODKEY, XKB_KEY_h, setmfact, {.f = -0.05f} },
diff --git a/dwl.c b/dwl.c
index ecc6dfb..1feed65 100644
--- a/dwl.c
+++ b/dwl.c
@@ -343,6 +343,7 @@ static void locksession(struct wl_listener *listener, void *data);
static void mapnotify(struct wl_listener *listener, void *data);
static void maximizenotify(struct wl_listener *listener, void *data);
static void monocle(Monitor *m);
+static void movestack(const Arg *arg);
static void motionabsolute(struct wl_listener *listener, void *data);
static void motionnotify(uint32_t time, struct wlr_input_device *device, double sx,
double sy, double sx_unaccel, double sy_unaccel);
@@ -452,7 +453,8 @@ static KeyboardGroup *kb_group;
static unsigned int kblayout = 0;
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;
@@ -2112,6 +2114,40 @@ monocle(Monitor *m)
}
void
+movestack(const Arg *arg)
+{
+ Client *c, *sel = focustop(selmon);
+
+ if (!sel) {
+ return;
+ }
+
+ if (wl_list_length(&clients) <= 1) {
+ return;
+ }
+
+ if (arg->i > 0) {
+ wl_list_for_each(c, &sel->link, link) {
+ if (VISIBLEON(c, selmon) || &c->link == &clients) {
+ break; /* found it */
+ }
+ }
+ } else {
+ wl_list_for_each_reverse(c, &sel->link, link) {
+ if (VISIBLEON(c, selmon) || &c->link == &clients) {
+ break; /* found it */
+ }
+ }
+ /* backup one client */
+ c = wl_container_of(c->link.prev, c, link);
+ }
+
+ wl_list_remove(&sel->link);
+ wl_list_insert(&c->link, &sel->link);
+ arrange(selmon);
+}
+
+void
motionabsolute(struct wl_listener *listener, void *data)
{
/* This event is forwarded by the cursor when a pointer emits an _absolute_
@@ -2197,8 +2233,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;
}
@@ -2246,10 +2301,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;
}
}