diff --git a/config.conf b/config.conf index 338c6387..3604eb3a 100644 --- a/config.conf +++ b/config.conf @@ -277,6 +277,12 @@ bind=ALT+SHIFT,X,incgaps,1 bind=ALT+SHIFT,Z,incgaps,-1 bind=ALT+SHIFT,R,togglegaps +# movewin +bind=SUPER+CTRL,Up,movewin,up +bind=SUPER+CTRL,Down,movewin,down +bind=SUPER+CTRL,Left,movewin,left +bind=SUPER+CTRL,Right,movewin,right + #custom app bind example # spawn_on_empty (if tag 4 is empty , open app in this,otherwise view to tag 4) # bind=SUPER,Return,spawn_on_empty,google-chrome,4 diff --git a/dispatch.h b/dispatch.h index 5711d89a..8cba8fae 100644 --- a/dispatch.h +++ b/dispatch.h @@ -35,4 +35,6 @@ void incgaps(const Arg *arg); void focusmon(const Arg *arg); void focusstack(const Arg *arg); void chvt(const Arg *arg); -void reload_config(const Arg *arg); \ No newline at end of file +void reload_config(const Arg *arg); +void movewin(const Arg *arg); +void resizewin(const Arg *arg); diff --git a/maomao.c b/maomao.c index d28dd418..d96cf81d 100644 --- a/maomao.c +++ b/maomao.c @@ -6941,6 +6941,110 @@ void zoom(const Arg *arg) { arrange(selmon, false); } +void movewin(const Arg *arg) { + /* top, bottom, left, right */ + Client *c, *tc; + int nx, ny; + int buttom, top, left, right, tar; + c = selmon->sel; + if (!c || c->isfullscreen) + return; + if (!c->isfloating) + togglefloating(NULL); + nx = c->geom.x; + ny = c->geom.y; + + switch (arg->i) { + case UP: + tar = -99999; + top = c->geom.y; + ny -= c->mon->w.height / 4; + + wl_list_for_each(tc, &clients, link) { + if (!VISIBLEON(tc, selmon) || !tc->isfloating || tc == c) + continue; + if (c->geom.x + c->geom.width < tc->geom.x || + c->geom.x > tc->geom.x + tc->geom.width) + continue; + buttom = tc->geom.y + tc->geom.height + gappiv; + if (top > buttom && ny < buttom) { + tar = MAX(tar, buttom); + }; + } + + ny = tar == -99999 ? ny : tar; + ny = MAX(ny, c->mon->w.y + gappov); + break; + case DOWN: + tar = 99999; + buttom = c->geom.y + c->geom.height; + ny += c->mon->w.height / 4; + + wl_list_for_each(tc, &clients, link) { + if (!VISIBLEON(tc, selmon) || !tc->isfloating || tc == c) + continue; + if (c->geom.x + c->geom.width < tc->geom.x || + c->geom.x > tc->geom.x + tc->geom.width) + continue; + top = tc->geom.y - gappiv; + if (buttom < top && (ny + c->geom.height) > top) { + tar = MIN(tar, top - c->geom.height); + }; + } + ny = tar == 99999 ? ny : tar; + ny = MIN(ny, c->mon->w.y + c->mon->w.height - gappov - c->geom.height); + break; + case LEFT: + tar = -99999; + left = c->geom.x; + nx -= c->mon->w.width / 6; + + wl_list_for_each(tc, &clients, link) { + if (!VISIBLEON(tc, selmon) || !tc->isfloating || tc == c) + continue; + if (c->geom.y + c->geom.height < tc->geom.y || + c->geom.y > tc->geom.y + tc->geom.height) + continue; + right = tc->geom.x + tc->geom.width + gappih; + if (left > right && nx < right) { + tar = MAX(tar, right); + }; + } + + nx = tar == -99999 ? nx : tar; + nx = MAX(nx, c->mon->w.x + gappoh); + break; + case RIGHT: + tar = 99999; + right = c->geom.x + c->geom.width; + nx += c->mon->w.width / 6; + wl_list_for_each(tc, &clients, link) { + if (!VISIBLEON(tc, selmon) || !tc->isfloating || tc == c) + continue; + if (c->geom.y + c->geom.height < tc->geom.y || + c->geom.y > tc->geom.y + tc->geom.height) + continue; + left = tc->geom.x - gappih; + if (right < left && (nx + c->geom.width) > left) { + tar = MIN(tar, left - c->geom.width); + }; + } + nx = tar == 99999 ? nx : tar; + nx = MIN(nx, c->mon->w.x + c->mon->w.width - gappoh - c->geom.width); + break; + } + + resize( + c, + (struct wlr_box){ + .x = nx, .y = ny, .width = c->geom.width, .height = c->geom.height}, + 1); +} + +void resizewin(const Arg *arg) { + +} + #ifdef XWAYLAND void activatex11(struct wl_listener *listener, void *data) { Client *c = wl_container_of(listener, c, activate); diff --git a/parse_config.h b/parse_config.h index 91fa3524..a0459732 100644 --- a/parse_config.h +++ b/parse_config.h @@ -477,6 +477,12 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value) { } else if (strcmp(func_name, "toggleview") == 0) { func = toggleview; (*arg).ui = 1 << (atoi(arg_value) - 1); + } else if (strcmp(func_name, "movewin") == 0) { + func = movewin; + (*arg).i = parse_direction(arg_value); + } else if (strcmp(func_name, "resizewin") == 0) { + func = resizewin; + (*arg).i = parse_direction(arg_value); } else { return NULL; } @@ -1378,4 +1384,4 @@ void reload_config(const Arg *arg) { } } arrange(selmon, false); -} \ No newline at end of file +}