From c64dd51b69071b500b70f453936723dab06b84f7 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Sat, 3 May 2025 15:18:33 +0800 Subject: [PATCH] feat: add mvoewin resizewin dispatch --- config.conf | 29 ++++++++++----- src/config/parse_config.h | 25 +++++++++++++ src/dispatch/dispatch.h | 2 ++ src/maomao.c | 74 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+), 8 deletions(-) diff --git a/config.conf b/config.conf index 76a72de..582a602 100644 --- a/config.conf +++ b/config.conf @@ -286,16 +286,29 @@ bind=ALT+SHIFT,Z,incgaps,-1 bind=ALT+SHIFT,R,togglegaps # smartmovewin -bind=SUPER+SHIFT,Up,smartmovewin,up -bind=SUPER+SHIFT,Down,smartmovewin,down -bind=SUPER+SHIFT,Left,smartmovewin,left -bind=SUPER+SHIFT,Right,smartmovewin,right +bind=CTRL+SHIFT,Up,smartmovewin,up +bind=CTRL+SHIFT,Down,smartmovewin,down +bind=CTRL+SHIFT,Left,smartmovewin,left +bind=CTRL+SHIFT,Right,smartmovewin,right + +# movewin +# bind=CTRL+SHIFT,Up,movewin,+0,-50 +# bind=CTRL+SHIFT,Down,movewin,+0,+50 +# bind=CTRL+SHIFT,Left,movewin,-50,+0 +# bind=CTRL+SHIFT,Right,movewin,+50,+0 + # smartresizewin -bind=SUPER+ALT,Up,smartresizewin,up -bind=SUPER+ALT,Down,smartresizewin,down -bind=SUPER+ALT,Left,smartresizewin,left -bind=SUPER+ALT,Right,smartresizewin,right +bind=CTRL+ALT,Up,smartresizewin,up +bind=CTRL+ALT,Down,smartresizewin,down +bind=CTRL+ALT,Left,smartresizewin,left +bind=CTRL+ALT,Right,smartresizewin,right + +# resizewin +# bind=CTRL+ALT,Up,resizewin,+0,-50 +# bind=CTRL+ALT,Down,resizewin,+0,+50 +# bind=CTRL+ALT,Left,resizewin,-50,+0 +# bind=CTRL+ALT,Right,resizewin,+50,+0 #custom app bind example # spawn_on_empty (if tag 4 is empty , open app in this,otherwise view to tag 4) diff --git a/src/config/parse_config.h b/src/config/parse_config.h index 382e208..65ce0bf 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -7,6 +7,8 @@ #define SYSCONFDIR "/etc" #endif +enum { NUM_TYPE_MINUS, NUM_TYPE_PLUS, NUM_TYPE_DEFAULT }; + typedef struct { uint32_t mod; xkb_keysym_t keysym; @@ -400,6 +402,17 @@ void convert_hex_to_rgba(float *color, unsigned long int hex) { color[3] = (hex & 0xFF) / 255.0f; } +unsigned int parse_num_type(char *str) { + switch (str[0]) { + case '-': + return NUM_TYPE_MINUS; + case '+': + return NUM_TYPE_PLUS; + default: + return NUM_TYPE_DEFAULT; + } +} + FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value, char *arg_value2) { FuncType func = NULL; @@ -526,6 +539,18 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value, char *arg_v } else if (strcmp(func_name, "smartresizewin") == 0) { func = smartresizewin; (*arg).i = parse_direction(arg_value); + } else if (strcmp(func_name, "resizewin") == 0) { + func = resizewin; + (*arg).ui = parse_num_type(arg_value); + (*arg).ui2 = parse_num_type(arg_value2); + (*arg).i = (*arg).ui == NUM_TYPE_DEFAULT ? atoi(arg_value) : atoi(arg_value+1); + (*arg).i2 = (*arg).ui2 == NUM_TYPE_DEFAULT ? atoi(arg_value2) : atoi(arg_value2+1); + } else if (strcmp(func_name, "movewin") == 0) { + func = movewin; + (*arg).ui = parse_num_type(arg_value); + (*arg).ui2 = parse_num_type(arg_value2); + (*arg).i = (*arg).ui == NUM_TYPE_DEFAULT ? atoi(arg_value) : atoi(arg_value+1); + (*arg).i2 = (*arg).ui2 == NUM_TYPE_DEFAULT ? atoi(arg_value2) : atoi(arg_value2+1); } else { return NULL; } diff --git a/src/dispatch/dispatch.h b/src/dispatch/dispatch.h index 191301e..8125422 100644 --- a/src/dispatch/dispatch.h +++ b/src/dispatch/dispatch.h @@ -51,3 +51,5 @@ void incigaps(const Arg *arg); void defaultgaps(const Arg *arg); void togglefakefullscreen(const Arg *arg); void toggleoverlay(const Arg *arg); +void movewin(const Arg *arg); +void resizewin(const Arg *arg); diff --git a/src/maomao.c b/src/maomao.c index 15a6f7b..08893c8 100644 --- a/src/maomao.c +++ b/src/maomao.c @@ -1923,6 +1923,7 @@ void apply_window_snap(Client *c) { c->geom.y = c->geom.y + snap_down; } + c->oldgeom = c->geom; resize(c, c->geom, 1); } @@ -7174,6 +7175,79 @@ void zoom(const Arg *arg) { arrange(selmon, false); } +void resizewin(const Arg *arg) { + Client *c; + c = selmon->sel; + if (!c || c->isfullscreen) + return; + if (!c->isfloating) + togglefloating(NULL); + + switch(arg->ui) { + case NUM_TYPE_MINUS: + c->geom.width -= arg->i; + break; + case NUM_TYPE_PLUS: + c->geom.width += arg->i; + break; + default: + c->geom.width = arg->i; + break; + } + + switch(arg->ui2) { + case NUM_TYPE_MINUS: + c->geom.height -= arg->i2; + break; + case NUM_TYPE_PLUS: + c->geom.height += arg->i2; + break; + default: + c->geom.height = arg->i2; + break; + } + + c->oldgeom = c->geom; + resize(c, c->geom, 0); +} + +void movewin(const Arg *arg) { + Client *c; + c = selmon->sel; + if (!c || c->isfullscreen) + return; + if (!c->isfloating) + togglefloating(NULL); + + switch(arg->ui) { + case NUM_TYPE_MINUS: + c->geom.x -= arg->i; + break; + case NUM_TYPE_PLUS: + c->geom.x += arg->i; + break; + default: + c->geom.x = arg->i; + break; + } + + switch(arg->ui2) { + case NUM_TYPE_MINUS: + c->geom.y -= arg->i2; + break; + case NUM_TYPE_PLUS: + c->geom.y += arg->i2; + break; + default: + c->geom.y = arg->i2; + break; + } + + c->oldgeom = c->geom; + resize(c, c->geom, 0); +} + + void smartmovewin(const Arg *arg) { Client *c, *tc; int nx, ny;