From 133f0e1cf7208df2bca6b925fccec7d19ce81fc4 Mon Sep 17 00:00:00 2001 From: Yazeed1s Date: Sat, 14 Dec 2024 08:47:18 -0500 Subject: [PATCH 1/8] update README.md --- README.md | 118 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 646bbbc..707ba72 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,18 @@ ### zwm ## Table of Contents -- [About ZWM](#about-zwm) -- [Motivation](#motivation) -- [Goals](#goals) -- [Features](#features) -- [The underlying data structure](#the-underlying-data-structure) -- [Screenshots](#screenshots) -- [Installation](#installation) -- [Configuration](#configuration) -- [Default Keybindings](#default-keybindings) -- [ewmh specific settings for polyabr](#ewmh-specific-settings-for-polyabr) -- [Contributing](#contributing) + +- [About ZWM](#about-zwm) +- [Motivation](#motivation) +- [Goals](#goals) +- [Features](#features) +- [The underlying data structure](#the-underlying-data-structure) +- [Screenshots](#screenshots) +- [Installation](#installation) +- [Configuration](#configuration) +- [Default Keybindings](#default-keybindings) +- [ewmh specific settings for polyabr](#ewmh-specific-settings-for-polyabr) +- [Contributing](#contributing) ## About ZWM @@ -144,6 +145,7 @@ ZWM uses **binary space partitioning tree** ([BSP-tree](https://en.wikipedia.org ## Installation #### Arch Linux (AUR) + ```bash yay -S zwm ``` @@ -151,6 +153,7 @@ yay -S zwm #### Void Linux (XBPS-SRC) Assuming you have [void-packages](https://github.com/void-linux/void-packages) + ```bash git clone https://github.com/elbachir-one/void-templates cp void-templates/zwm/ void-packages/srcpkgs/ # Copying the zwm/ directory that has the template @@ -160,15 +163,18 @@ sudo xbps-install -R hostdir/binpkgs zwm ``` #### Build from source + ##### Dependencies -- gcc -- libxcb -- xcb-util -- xcb-util-keysyms -- xcb-util-wm (ewmh,icccm) -- lxcb-randr -- lxcb-xinerama -- lxcb-cursor + +- gcc +- libxcb +- xcb-util +- xcb-util-keysyms +- xcb-util-wm (ewmh,icccm) +- lxcb-randr +- lxcb-xinerama +- lxcb-cursor + ```bash git clone https://github.com/Yazeed1s/zwm.git cd zwm && sudo make install @@ -283,6 +289,8 @@ rule = wm_class("firefox"), state(tiled), desktop(-1) - **shift_window**: Shift the floating window's position to the specified direction by 10px (up, down, left, right). - **gap_handler**: Increase or decrease window gaps (GROW, SHRINK). - **change_state**: Set window state (FLAOTING, TILED). + - **grow_floating_window**: Grow floating window (horizontally or vertically). + - **shrink_floating_window**: Shrink floating window (horizontally or vertically). - Default keys @@ -312,6 +320,10 @@ bind = shift + up -> func(shift_window:up) bind = shift + right -> func(shift_window:right) bind = shift + left -> func(shift_window:left) bind = shift + down -> func(shift_window:down) +bind = super|shift + t -> func(shrink_floating_window:horizontal) +bind = super|shift + g -> func(shrink_floating_window:vertical) +bind = super|shift + y -> func(grow_floating_window:horizontal) +bind = super|shift + h -> func(grow_floating_window:vertical) bind = shift + t -> func(change_state:tile) bind = shift + f -> func(change_state:float) bind = super|shift + left -> func(cycle_desktop:left) @@ -336,38 +348,42 @@ More options will be added in the future as development progresses. ## Default Keybindings -| Key | Description | -| ------------------------ | --------------------------------- | -| `super + w` | kill/close window | -| `super + return` | launch a terminal (alacritty) | -| `super + space` | launch dmenu | -| `super + p ` | launch rofi | -| `super + [1..N]` | switch to desktop | -| `super + l` | resize window (grow/expand) | -| `super + h` | resize window (shrink) | -| `super + f` | toggle fullscreen | -| `super + shift + [1..N]` | transfer window to a diff desktop | -| `super + shift + m` | toggle master layout | -| `super + shift + s` | toggle stack layout | -| `super + shift + d` | toggle default layout | -| `super + shift + j/k` | traverse the stack | -| `super + shift + f` | flip the window/partion | -| `super + shift + r` | hot-reload | -| `super + s` | swap window's orientation | -| `super + ←` | focus window on the left | -| `super + ↑` | focus window above | -| `super + →` | focus window on the right | -| `super + ↓` | focus window below | -| `super + shift + →` | cycle desktop right | -| `super + shift + ←` | cycle desktop left | -| `shift + ←` | shift window to the left by 10px | -| `shift + ↑` | shift window up by 10px | -| `shift + →` | shift window to the right by 10px | -| `shift + ↓` | shift window down by 10px | -| `super + i` | increase window gaps by 5px | -| `super + d` | decrease window gaps by 5px | -| `super + t` | tile window | -| `super + f` | float window | +| Key | Description | +| ------------------------ | ------------------------------------ | +| `super + w` | kill/close window | +| `super + return` | launch a terminal (alacritty) | +| `super + space` | launch dmenu | +| `super + p ` | launch rofi | +| `super + [1..N]` | switch to desktop | +| `super + l` | resize window (grow/expand) | +| `super + h` | resize window (shrink) | +| `super + f` | toggle fullscreen | +| `super + shift + [1..N]` | transfer window to a diff desktop | +| `super + shift + m` | toggle master layout | +| `super + shift + s` | toggle stack layout | +| `super + shift + d` | toggle default layout | +| `super + shift + j/k` | traverse the stack | +| `super + shift + f` | flip the window/partion | +| `super + shift + r` | hot-reload | +| `super + shift + y` | grow floating windows horizontally | +| `super + shift + h` | grow floating windows vertically | +| `super + shift + t` | shrink floating windows horizontally | +| `super + shift + g` | shrink floating windows vertically | +| `super + s` | swap window's orientation | +| `super + ←` | focus window on the left | +| `super + ↑` | focus window above | +| `super + →` | focus window on the right | +| `super + ↓` | focus window below | +| `super + shift + →` | cycle desktop right | +| `super + shift + ←` | cycle desktop left | +| `shift + ←` | shift window to the left by 10px | +| `shift + ↑` | shift window up by 10px | +| `shift + →` | shift window to the right by 10px | +| `shift + ↓` | shift window down by 10px | +| `super + i` | increase window gaps by 5px | +| `super + d` | decrease window gaps by 5px | +| `super + t` | tile window | +| `super + f` | float window | ## ewmh specific settings for polyabr From 2af0caa7396ff08b41f1ae07d9a941196f694b3c Mon Sep 17 00:00:00 2001 From: Yazeed1s Date: Sat, 14 Dec 2024 08:48:01 -0500 Subject: [PATCH 2/8] add grow/shrink floating window keys --- src/config_parser.c | 56 +++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/src/config_parser.c b/src/config_parser.c index cf56add..07ece76 100644 --- a/src/config_parser.c +++ b/src/config_parser.c @@ -69,22 +69,24 @@ free_tokens(char **, int); /* clang-format off */ static const conf_mapper_t _cmapper_[] = { - DEFINE_MAPPING("run", exec_process), - DEFINE_MAPPING("kill", close_or_kill_wrapper), - DEFINE_MAPPING("switch_desktop", switch_desktop_wrapper), - DEFINE_MAPPING("resize", horizontal_resize_wrapper), - DEFINE_MAPPING("fullscreen", set_fullscreen_wrapper), - DEFINE_MAPPING("swap", swap_node_wrapper), - DEFINE_MAPPING("transfer_node", transfer_node_wrapper), - DEFINE_MAPPING("layout", layout_handler), - DEFINE_MAPPING("traverse", traverse_stack_wrapper), - DEFINE_MAPPING("flip", flip_node_wrapper), - DEFINE_MAPPING("cycle_window", cycle_win_wrapper), - DEFINE_MAPPING("reload_config", reload_config_wrapper), - DEFINE_MAPPING("cycle_desktop", cycle_desktop_wrapper), - DEFINE_MAPPING("shift_window", shift_floating_window), - DEFINE_MAPPING("gap_handler", gap_handler), - DEFINE_MAPPING("change_state", change_state), + DEFINE_MAPPING("run", exec_process), + DEFINE_MAPPING("kill", close_or_kill_wrapper), + DEFINE_MAPPING("switch_desktop", switch_desktop_wrapper), + DEFINE_MAPPING("resize", horizontal_resize_wrapper), + DEFINE_MAPPING("fullscreen", set_fullscreen_wrapper), + DEFINE_MAPPING("swap", swap_node_wrapper), + DEFINE_MAPPING("transfer_node", transfer_node_wrapper), + DEFINE_MAPPING("layout", layout_handler), + DEFINE_MAPPING("traverse", traverse_stack_wrapper), + DEFINE_MAPPING("flip", flip_node_wrapper), + DEFINE_MAPPING("cycle_window", cycle_win_wrapper), + DEFINE_MAPPING("reload_config", reload_config_wrapper), + DEFINE_MAPPING("cycle_desktop", cycle_desktop_wrapper), + DEFINE_MAPPING("shift_window", shift_floating_window), + DEFINE_MAPPING("grow_floating_window", grow_floating_window), + DEFINE_MAPPING("shrink_floating_window", shrink_floating_window), + DEFINE_MAPPING("gap_handler", gap_handler), + DEFINE_MAPPING("change_state", change_state), }; static key_mapper_t _kmapper_[] = { @@ -349,7 +351,15 @@ write_default_config(const char *filename, config_t *c) "bind = shift + left -> func(shift_window:left)\n" "bind = shift + down -> func(shift_window:down)\n" "\n" - "; cycle through virtual desktops\n" + "; grow floating windows\n" + "bind = super|shift + y -> func(grow_floating_window:horizontal)\n" + "bind = super|shift + h -> func(grow_floating_window:vertical)\n" + "\n" + "; shrink floating windows\n" + "bind = super|shift + t -> func(shrink_floating_window:horizontal)\n" + "bind = super|shift + g -> func(shrink_floating_window:vertical)\n" + "\n" + "; cycle through virtual desktops\n" "bind = super|shift + left -> func(cycle_desktop:left)\n" "bind = super|shift + right -> func(cycle_desktop:right)\n" "\n" @@ -754,6 +764,18 @@ set_key_args(conf_key_t *key, char *func, char *arg) } else if (strcmp(arg, "tile") == 0) { key->arg->s = TILED; } + } else if (strcmp(func, "shrink_floating_window") == 0) { + if (strcmp(arg, "horizontal") == 0) { + key->arg->rd = HORIZONTAL_DIR; + } else if (strcmp(arg, "vertical") == 0) { + key->arg->rd = VERTICAL_DIR; + } + } else if (strcmp(func, "grow_floating_window") == 0) { + if (strcmp(arg, "horizontal") == 0) { + key->arg->rd = HORIZONTAL_DIR; + } else if (strcmp(arg, "vertical") == 0) { + key->arg->rd = VERTICAL_DIR; + } } } From cb3beb3d0e3fdf51fed8a69b144daeeb9f32429c Mon Sep 17 00:00:00 2001 From: Yazeed1s Date: Sat, 14 Dec 2024 08:48:12 -0500 Subject: [PATCH 3/8] add resize direction --- src/type.h | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/type.h b/src/type.h index 1e410ea..8e09753 100644 --- a/src/type.h +++ b/src/type.h @@ -72,10 +72,15 @@ typedef enum { } resize_t; typedef enum { - LEFT = 1, /* move/resize left */ - RIGHT, /* move/resize right */ - UP, /* move/resize up */ - DOWN, /* move/resize down */ + HORIZONTAL_DIR = 1, + VERTICAL_DIR, +} resize_dir_t; + +typedef enum { + LEFT = 1, /* move left */ + RIGHT, /* move right */ + UP, /* move up */ + DOWN, /* move down */ NONE /* no direction */ } direction_t; @@ -260,13 +265,14 @@ typedef struct { /* argument structure for key bindings */ typedef struct { - char **cmd; /* command arguments, used for execp family actions */ - uint8_t argc; /* argument count */ - uint8_t idx; /* target index, used for desktop switching */ - resize_t r; /* resize operation */ - layout_t t; /* layout type */ - direction_t d; /* movement direction */ - state_t s; /* window state, used to change window state */ + char **cmd; /* command arguments, used for execp family actions */ + uint8_t argc; /* argument count */ + uint8_t idx; /* target index, used for desktop switching */ + resize_t r; /* resize operation */ + resize_dir_t rd; /* resize direction */ + layout_t t; /* layout type */ + direction_t d; /* movement direction */ + state_t s; /* window state, used to change window state */ } arg_t; /* key binding structure. used for the global fallback array in zwm.c */ From 9cca5cc40d0fcbf437fbf51c7612a15e1ab70aba Mon Sep 17 00:00:00 2001 From: Yazeed1s Date: Sat, 14 Dec 2024 08:48:48 -0500 Subject: [PATCH 4/8] initial implementation for floating window resize --- src/zwm.c | 175 +++++++++++++++++++++++++++++++++++++++++++----------- src/zwm.h | 2 + 2 files changed, 141 insertions(+), 36 deletions(-) diff --git a/src/zwm.c b/src/zwm.c index fabc4fd..8e6ec1e 100644 --- a/src/zwm.c +++ b/src/zwm.c @@ -904,6 +904,117 @@ horizontal_resize_wrapper(arg_t *arg) return 0; } +int +grow_floating_window(arg_t *arg) +{ + node_t *root = get_foucsed_desktop_tree(); + if (root == NULL) + return -1; + + node_t *n = get_focused_node(root); + if (n == NULL) + return -1; + + if (n->client && n->client->state != FLOATING) + return 0; + + const uint16_t step = 10; + const resize_dir_t resize_dir = arg->rd; + uint16_t *dim_to_resize = (resize_dir == HORIZONTAL_DIR) + ? &n->floating_rectangle.width + : &n->floating_rectangle.height; + int16_t *pos = (resize_dir == HORIZONTAL_DIR) ? &n->floating_rectangle.x + : &n->floating_rectangle.y; + *dim_to_resize += step; + *pos -= step; + grab_pointer(wm->root_window, false); + if (resize_window(n->client->window, + n->floating_rectangle.width, + n->floating_rectangle.height) != 0 || + move_window(n->client->window, + n->floating_rectangle.x, + n->floating_rectangle.y) != 0) { + return -1; + } + ungrab_pointer(); + return 0; +} + +int +shrink_floating_window(arg_t *arg) +{ + node_t *root = get_foucsed_desktop_tree(); + if (root == NULL) + return -1; + + node_t *n = get_focused_node(root); + if (n == NULL) + return -1; + + if (n->client && n->client->state != FLOATING) + return 0; + const uint16_t step = 10; + const resize_dir_t resize_dir = arg->rd; + uint16_t *dim_to_resize = (resize_dir == HORIZONTAL_DIR) + ? &n->floating_rectangle.width + : &n->floating_rectangle.height; + int16_t *pos = (resize_dir == HORIZONTAL_DIR) ? &n->floating_rectangle.x + : &n->floating_rectangle.y; + *dim_to_resize -= step; + *pos += step; + grab_pointer(wm->root_window, false); + if (resize_window(n->client->window, + n->floating_rectangle.width, + n->floating_rectangle.height) != 0 || + move_window(n->client->window, + n->floating_rectangle.x, + n->floating_rectangle.y) != 0) { + return -1; + } + ungrab_pointer(); + return 0; +} + +int +resize_floating_window(arg_t *arg) +{ + node_t *root = get_foucsed_desktop_tree(); + if (root == NULL) + return -1; + + node_t *n = get_focused_node(root); + if (n == NULL) + return -1; + + if (n->client && n->client->state != FLOATING) + return 0; + + const uint16_t step = 10; + const resize_t resize_type = arg->r; + const resize_dir_t resize_dir = arg->rd; + int16_t delta = (resize_type == GROW ? step : -step); + uint16_t *dim_to_resize = (resize_dir == HORIZONTAL_DIR) + ? &n->floating_rectangle.width + : &n->floating_rectangle.height; + int16_t *pos_to_adjust = (resize_dir == HORIZONTAL_DIR) + ? &n->floating_rectangle.x + : &n->floating_rectangle.y; + *pos_to_adjust -= delta / 2; + *dim_to_resize += delta; + if (*dim_to_resize <= 0) { + *dim_to_resize = step; + *pos_to_adjust += delta / 2; + } + grab_pointer(wm->root_window, false); + if (resize_window(n->client->window, + n->floating_rectangle.width, + n->floating_rectangle.height) != 0) { + return -1; + } + ungrab_pointer(); + return 0; +} + int shift_floating_window(arg_t *arg) { @@ -918,49 +1029,41 @@ shift_floating_window(arg_t *arg) if (n->client && n->client->state != FLOATING) return 0; - const int16_t pxl = 10; - int16_t new_x = n->floating_rectangle.x; - int16_t new_y = n->floating_rectangle.y; - uint16_t monitor_width = curr_monitor->rectangle.width; - uint16_t monitor_height = curr_monitor->rectangle.height; - int16_t monitor_x = curr_monitor->rectangle.x; - int16_t monitor_y = curr_monitor->rectangle.y; - - switch (arg->d) { - case LEFT: - new_x -= pxl; - if (new_x < monitor_x) { - return 0; - } - break; - case RIGHT: - new_x += pxl; - if (new_x + n->floating_rectangle.width > monitor_x + monitor_width) { - return 0; - } - break; - case UP: - new_y -= pxl; - if (new_y < monitor_y) { - return 0; - } - break; - case DOWN: - new_y += pxl; - if (new_y + n->floating_rectangle.height > monitor_y + monitor_height) { - return 0; - } - break; + const int16_t step = 10; + rectangle_t *rect = &n->floating_rectangle; + const rectangle_t *monitor_rect = &curr_monitor->rectangle; + const direction_t dir = arg->d; + + switch (dir) { + case LEFT: rect->x -= step; break; + case RIGHT: rect->x += step; break; + case UP: rect->y -= step; break; + case DOWN: rect->y += step; break; case NONE: return 0; } + if (rect->x < monitor_rect->x) { + rect->x = monitor_rect->x; + return 0; + } + if (rect->x + rect->width > monitor_rect->x + monitor_rect->width) { + rect->x = monitor_rect->x + monitor_rect->width - rect->width; + return 0; + } + if (rect->y < monitor_rect->y) { + rect->y = monitor_rect->y; + return 0; + } + if (rect->y + rect->height > monitor_rect->y + monitor_rect->height) { + rect->y = monitor_rect->y + monitor_rect->height - rect->height; + return 0; + } + grab_pointer(wm->root_window, false); - if (move_window(n->client->window, new_x, new_y) != 0) { + if (move_window(n->client->window, rect->x, rect->y) != 0) { return -1; } - n->floating_rectangle.x = new_x; - n->floating_rectangle.y = new_y; ungrab_pointer(); return 0; } diff --git a/src/zwm.h b/src/zwm.h index 52b9afa..63992dd 100644 --- a/src/zwm.h +++ b/src/zwm.h @@ -69,6 +69,8 @@ int cycle_desktop_wrapper(arg_t *arg); int close_or_kill_wrapper(); int traverse_stack_wrapper(arg_t *arg); int shift_floating_window(arg_t *arg); +int shrink_floating_window(arg_t *arg); +int grow_floating_window(arg_t *arg); int tile(node_t *node); int set_focus(node_t *n, bool flag); int swap_node_wrapper(); From b290946ed3f20b9341613c8aad009e3943b5dae3 Mon Sep 17 00:00:00 2001 From: Yazeed1s Date: Sat, 14 Dec 2024 08:48:54 -0500 Subject: [PATCH 5/8] update --- zwm.conf | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/zwm.conf b/zwm.conf index 685d710..eb5b005 100644 --- a/zwm.conf +++ b/zwm.conf @@ -131,6 +131,14 @@ bind = shift + right -> func(shift_window:right) bind = shift + left -> func(shift_window:left) bind = shift + down -> func(shift_window:down) +; grow floating windows +bind = super|shift + y -> func(grow_floating_window:horizontal) +bind = super|shift + h -> func(grow_floating_window:vertical) + +; shrink floating windows +bind = super|shift + t -> func(shrink_floating_window:horizontal) +bind = super|shift + g -> func(shrink_floating_window:vertical) + ; cycle through virtual desktops bind = super|shift + left -> func(cycle_desktop:left) bind = super|shift + right -> func(cycle_desktop:right) From 5b9c12c54665de49775d6be005a895010843889f Mon Sep 17 00:00:00 2001 From: Yazeed1s Date: Sat, 14 Dec 2024 09:17:08 -0500 Subject: [PATCH 6/8] guard resize functions & keep relative position --- src/zwm.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/zwm.c b/src/zwm.c index 8e6ec1e..5ceb2a7 100644 --- a/src/zwm.c +++ b/src/zwm.c @@ -918,15 +918,23 @@ grow_floating_window(arg_t *arg) if (n->client && n->client->state != FLOATING) return 0; - const uint16_t step = 10; - const resize_dir_t resize_dir = arg->rd; - uint16_t *dim_to_resize = (resize_dir == HORIZONTAL_DIR) - ? &n->floating_rectangle.width - : &n->floating_rectangle.height; + const uint16_t step = 10; + const resize_dir_t resize_dir = arg->rd; + const uint16_t max_dim = (resize_dir == HORIZONTAL_DIR) + ? curr_monitor->rectangle.width + : curr_monitor->rectangle.height; + uint16_t *dim = (resize_dir == HORIZONTAL_DIR) + ? &n->floating_rectangle.width + : &n->floating_rectangle.height; int16_t *pos = (resize_dir == HORIZONTAL_DIR) ? &n->floating_rectangle.x : &n->floating_rectangle.y; - *dim_to_resize += step; + + if (*dim + (step * 2) > max_dim) + return 0; + + *dim += (step * 2); *pos -= step; + grab_pointer(wm->root_window, false); if (resize_window(n->client->window, n->floating_rectangle.width, @@ -953,14 +961,18 @@ shrink_floating_window(arg_t *arg) if (n->client && n->client->state != FLOATING) return 0; - const uint16_t step = 10; - const resize_dir_t resize_dir = arg->rd; - uint16_t *dim_to_resize = (resize_dir == HORIZONTAL_DIR) - ? &n->floating_rectangle.width - : &n->floating_rectangle.height; + const uint16_t step = 10; + const resize_dir_t resize_dir = arg->rd; + const uint16_t min_dim = step * 40; + uint16_t *dim = (resize_dir == HORIZONTAL_DIR) + ? &n->floating_rectangle.width + : &n->floating_rectangle.height; int16_t *pos = (resize_dir == HORIZONTAL_DIR) ? &n->floating_rectangle.x : &n->floating_rectangle.y; - *dim_to_resize -= step; + if (*dim - (step * 2) < min_dim) { + return 0; + } + *dim -= (step * 2); *pos += step; grab_pointer(wm->root_window, false); if (resize_window(n->client->window, From bf89c5fb3bd1fe948ae148eaf4405586854f3cdd Mon Sep 17 00:00:00 2001 From: Yazeed1s Date: Sun, 15 Dec 2024 15:46:18 -0500 Subject: [PATCH 7/8] use pointer rectangle --- src/tree.c | 78 ++++++++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/src/tree.c b/src/tree.c index 442174f..8302809 100644 --- a/src/tree.c +++ b/src/tree.c @@ -195,49 +195,47 @@ insert_floating_node(node_t *node, desktop_t *d) static void split_node(node_t *n, node_t *nd) { + rectangle_t *first_rect = &n->first_child->rectangle; + rectangle_t *second_rect = &n->second_child->rectangle; if (IS_FLOATING(nd->client)) { - n->first_child->rectangle = n->first_child->floating_rectangle = - n->rectangle; + *first_rect = n->floating_rectangle = n->rectangle; + return; + } + if (n->rectangle.width >= n->rectangle.height) { + /* horizontal split */ + const int16_t gap = conf.window_gap - conf.border_width; + const int16_t half_width = (n->rectangle.width - gap) / 2; + first_rect->x = n->rectangle.x; + first_rect->y = n->rectangle.y; + first_rect->width = half_width; + first_rect->height = n->rectangle.height; + if (!IS_FLOATING(n->first_child->client)) { + second_rect->x = n->rectangle.x + first_rect->width + + conf.window_gap + conf.border_width; + second_rect->y = n->rectangle.y; + second_rect->width = n->rectangle.width - first_rect->width - + conf.window_gap - conf.border_width; + second_rect->height = n->rectangle.height; + } else { + *second_rect = n->rectangle; + } } else { - if (n->rectangle.width >= n->rectangle.height) { - n->first_child->rectangle.x = n->rectangle.x; - n->first_child->rectangle.y = n->rectangle.y; - n->first_child->rectangle.width = - (n->rectangle.width - (conf.window_gap - conf.border_width)) / - 2; - n->first_child->rectangle.height = n->rectangle.height; - if (!IS_FLOATING(n->first_child->client)) { - n->second_child->rectangle.x = - (int16_t)(n->rectangle.x + n->first_child->rectangle.width + - conf.window_gap + conf.border_width); - n->second_child->rectangle.y = n->rectangle.y; - n->second_child->rectangle.width = - n->rectangle.width - n->first_child->rectangle.width - - conf.window_gap - conf.border_width; - n->second_child->rectangle.height = n->rectangle.height; - } else { - n->second_child->rectangle = n->rectangle; - } + /* verticall split */ + const int16_t gap = conf.window_gap - conf.border_width; + const int16_t half_height = (n->rectangle.height - gap) / 2; + first_rect->x = n->rectangle.x; + first_rect->y = n->rectangle.y; + first_rect->width = n->rectangle.width; + first_rect->height = half_height; + if (!IS_FLOATING(n->first_child->client)) { + second_rect->x = n->rectangle.x; + second_rect->y = n->rectangle.y + first_rect->height + + conf.window_gap + conf.border_width; + second_rect->width = n->rectangle.width; + second_rect->height = n->rectangle.height - first_rect->height - + conf.window_gap - conf.border_width; } else { - n->first_child->rectangle.x = n->rectangle.x; - n->first_child->rectangle.y = n->rectangle.y; - n->first_child->rectangle.width = n->rectangle.width; - n->first_child->rectangle.height = - (n->rectangle.height - (conf.window_gap - conf.border_width)) / - 2; - if (!IS_FLOATING(n->first_child->client)) { - n->second_child->rectangle.x = n->rectangle.x; - n->second_child->rectangle.y = - (int16_t)(n->rectangle.y + - n->first_child->rectangle.height + - conf.window_gap + conf.border_width); - n->second_child->rectangle.width = n->rectangle.width; - n->second_child->rectangle.height = - n->rectangle.height - n->first_child->rectangle.height - - conf.window_gap - conf.border_width; - } else { - n->second_child->rectangle = n->rectangle; - } + *second_rect = n->rectangle; } } } From 549c31655be7cea71fd10b84c62f01a45984f43f Mon Sep 17 00:00:00 2001 From: Yazeed1s Date: Sun, 15 Dec 2024 15:46:40 -0500 Subject: [PATCH 8/8] update keybinding array --- src/zwm.c | 98 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/src/zwm.c b/src/zwm.c index 5ceb2a7..892478e 100644 --- a/src/zwm.c +++ b/src/zwm.c @@ -72,10 +72,10 @@ #define BUTTON_RELEASE (XCB_EVENT_MASK_BUTTON_RELEASE) #define POINTER_MOTION (XCB_EVENT_MASK_POINTER_MOTION) -#define ALT_MASK (XCB_MOD_MASK_1) -#define SUPER_MASK (XCB_MOD_MASK_4) -#define SHIFT_MASK (XCB_MOD_MASK_SHIFT) -#define CTRL_MASK (XCB_MOD_MASK_CONTROL) +#define ALT (XCB_MOD_MASK_1) +#define SUPER (XCB_MOD_MASK_4) +#define SHIFT (XCB_MOD_MASK_SHIFT) +#define CTRL (XCB_MOD_MASK_CONTROL) #define CLICK_TO_FOCUS (XCB_BUTTON_INDEX_1) #define CLIENT_EVENT_MASK \ @@ -111,49 +111,53 @@ xcb_cursor_t cursors[CURSOR_MAX]; /* see X11/keysymdef.h */ static const _key__t _keys_[] = { - DEFINE_KEY(SUPER_MASK, XK_w, close_or_kill_wrapper, NULL), - DEFINE_KEY(SUPER_MASK, XK_Return, exec_process, &((arg_t){.argc = 1, .cmd = (char *[]){"alacritty"}})), - DEFINE_KEY(SUPER_MASK, XK_space, exec_process, &((arg_t){.argc = 1, .cmd = (char *[]){"dmenu_run"}})), - DEFINE_KEY(SUPER_MASK, XK_p, exec_process, &((arg_t){.argc = 3, .cmd = (char *[]){"rofi", "-show", "drun"}})), - DEFINE_KEY(SUPER_MASK, XK_1, switch_desktop_wrapper, &((arg_t){.idx = 0})), - DEFINE_KEY(SUPER_MASK, XK_2, switch_desktop_wrapper, &((arg_t){.idx = 1})), - DEFINE_KEY(SUPER_MASK, XK_3, switch_desktop_wrapper, &((arg_t){.idx = 2})), - DEFINE_KEY(SUPER_MASK, XK_4, switch_desktop_wrapper, &((arg_t){.idx = 3})), - DEFINE_KEY(SUPER_MASK, XK_5, switch_desktop_wrapper, &((arg_t){.idx = 4})), - DEFINE_KEY(SUPER_MASK, XK_6, switch_desktop_wrapper, &((arg_t){.idx = 5})), - DEFINE_KEY(SUPER_MASK, XK_7, switch_desktop_wrapper, &((arg_t){.idx = 6})), - DEFINE_KEY(SUPER_MASK, XK_Left, cycle_win_wrapper, &((arg_t){.d = LEFT})), - DEFINE_KEY(SUPER_MASK, XK_Right, cycle_win_wrapper, &((arg_t){.d = RIGHT})), - DEFINE_KEY(SUPER_MASK, XK_Up, cycle_win_wrapper, &((arg_t){.d = UP})), - DEFINE_KEY(SUPER_MASK, XK_Down, cycle_win_wrapper, &((arg_t){.d = DOWN})), - DEFINE_KEY(SUPER_MASK, XK_l, horizontal_resize_wrapper, &((arg_t){.r = GROW})), - DEFINE_KEY(SUPER_MASK, XK_h, horizontal_resize_wrapper, &((arg_t){.r = SHRINK})), - DEFINE_KEY(SUPER_MASK, XK_f, set_fullscreen_wrapper, NULL), - DEFINE_KEY(SUPER_MASK, XK_s, swap_node_wrapper, NULL), - DEFINE_KEY(SUPER_MASK | SHIFT_MASK, XK_1, transfer_node_wrapper, &((arg_t){.idx = 0})), - DEFINE_KEY(SUPER_MASK | SHIFT_MASK, XK_2, transfer_node_wrapper, &((arg_t){.idx = 1})), - DEFINE_KEY(SUPER_MASK | SHIFT_MASK, XK_3, transfer_node_wrapper, &((arg_t){.idx = 2})), - DEFINE_KEY(SUPER_MASK | SHIFT_MASK, XK_4, transfer_node_wrapper, &((arg_t){.idx = 3})), - DEFINE_KEY(SUPER_MASK | SHIFT_MASK, XK_5, transfer_node_wrapper, &((arg_t){.idx = 4})), - DEFINE_KEY(SUPER_MASK | SHIFT_MASK, XK_6, transfer_node_wrapper, &((arg_t){.idx = 5})), - DEFINE_KEY(SUPER_MASK | SHIFT_MASK, XK_7, transfer_node_wrapper, &((arg_t){.idx = 6})), - DEFINE_KEY(SUPER_MASK | SHIFT_MASK, XK_m, layout_handler, &((arg_t){.t = MASTER})), - DEFINE_KEY(SUPER_MASK | SHIFT_MASK, XK_d, layout_handler, &((arg_t){.t = DEFAULT})), - DEFINE_KEY(SUPER_MASK | SHIFT_MASK, XK_s, layout_handler, &((arg_t){.t = STACK})), - DEFINE_KEY(SUPER_MASK | SHIFT_MASK, XK_k, traverse_stack_wrapper, &((arg_t){.d = UP})), - DEFINE_KEY(SUPER_MASK | SHIFT_MASK, XK_j, traverse_stack_wrapper, &((arg_t){.d = DOWN})), - DEFINE_KEY(SUPER_MASK | SHIFT_MASK, XK_f, flip_node_wrapper, NULL), - DEFINE_KEY(SUPER_MASK | SHIFT_MASK, XK_r, reload_config_wrapper, NULL), - DEFINE_KEY(SUPER_MASK | SHIFT_MASK, XK_Left, cycle_desktop_wrapper, &((arg_t){.d = LEFT})), - DEFINE_KEY(SUPER_MASK | SHIFT_MASK, XK_Right,cycle_desktop_wrapper, &((arg_t){.d = RIGHT})), - DEFINE_KEY(SHIFT_MASK, XK_Left, shift_floating_window, &((arg_t){.d = LEFT})), - DEFINE_KEY(SHIFT_MASK, XK_Right, shift_floating_window, &((arg_t){.d = RIGHT})), - DEFINE_KEY(SHIFT_MASK, XK_Up, shift_floating_window, &((arg_t){.d = UP})), - DEFINE_KEY(SHIFT_MASK, XK_Down, shift_floating_window, &((arg_t){.d = DOWN})), - DEFINE_KEY(SUPER_MASK, XK_i, gap_handler, &((arg_t){.r = GROW})), - DEFINE_KEY(SUPER_MASK, XK_d, gap_handler, &((arg_t){.r = SHRINK})), - DEFINE_KEY(SHIFT_MASK, XK_f, change_state, &((arg_t){.s = FLOATING})), - DEFINE_KEY(SHIFT_MASK, XK_t, change_state, &((arg_t){.s = TILED})), + DEFINE_KEY(SUPER, XK_w, close_or_kill_wrapper, NULL), + DEFINE_KEY(SUPER, XK_Return, exec_process, &((arg_t){.argc = 1, .cmd = (char *[]){"alacritty"}})), + DEFINE_KEY(SUPER, XK_space, exec_process, &((arg_t){.argc = 1, .cmd = (char *[]){"dmenu_run"}})), + DEFINE_KEY(SUPER, XK_p, exec_process, &((arg_t){.argc = 3, .cmd = (char *[]){"rofi", "-show", "drun"}})), + DEFINE_KEY(SUPER, XK_1, switch_desktop_wrapper, &((arg_t){.idx = 0})), + DEFINE_KEY(SUPER, XK_2, switch_desktop_wrapper, &((arg_t){.idx = 1})), + DEFINE_KEY(SUPER, XK_3, switch_desktop_wrapper, &((arg_t){.idx = 2})), + DEFINE_KEY(SUPER, XK_4, switch_desktop_wrapper, &((arg_t){.idx = 3})), + DEFINE_KEY(SUPER, XK_5, switch_desktop_wrapper, &((arg_t){.idx = 4})), + DEFINE_KEY(SUPER, XK_6, switch_desktop_wrapper, &((arg_t){.idx = 5})), + DEFINE_KEY(SUPER, XK_7, switch_desktop_wrapper, &((arg_t){.idx = 6})), + DEFINE_KEY(SUPER, XK_Left, cycle_win_wrapper, &((arg_t){.d = LEFT})), + DEFINE_KEY(SUPER, XK_Right, cycle_win_wrapper, &((arg_t){.d = RIGHT})), + DEFINE_KEY(SUPER, XK_Up, cycle_win_wrapper, &((arg_t){.d = UP})), + DEFINE_KEY(SUPER, XK_Down, cycle_win_wrapper, &((arg_t){.d = DOWN})), + DEFINE_KEY(SUPER, XK_l, horizontal_resize_wrapper, &((arg_t){.r = GROW})), + DEFINE_KEY(SUPER, XK_h, horizontal_resize_wrapper, &((arg_t){.r = SHRINK})), + DEFINE_KEY(SUPER, XK_f, set_fullscreen_wrapper, NULL), + DEFINE_KEY(SUPER, XK_s, swap_node_wrapper, NULL), + DEFINE_KEY(SUPER, XK_i, gap_handler, &((arg_t){.r = GROW})), + DEFINE_KEY(SUPER, XK_d, gap_handler, &((arg_t){.r = SHRINK})), + DEFINE_KEY(SUPER | SHIFT, XK_Left, shift_floating_window, &((arg_t){.d = LEFT})), + DEFINE_KEY(SUPER | SHIFT, XK_Right, shift_floating_window, &((arg_t){.d = RIGHT})), + DEFINE_KEY(SUPER | SHIFT, XK_Up, shift_floating_window, &((arg_t){.d = UP})), + DEFINE_KEY(SUPER | SHIFT, XK_Down, shift_floating_window, &((arg_t){.d = DOWN})), + DEFINE_KEY(SUPER | ALT, XK_f, change_state, &((arg_t){.s = FLOATING})), + DEFINE_KEY(SUPER | ALT, XK_t, change_state, &((arg_t){.s = TILED})), + DEFINE_KEY(SUPER | SHIFT, XK_1, transfer_node_wrapper, &((arg_t){.idx = 0})), + DEFINE_KEY(SUPER | SHIFT, XK_2, transfer_node_wrapper, &((arg_t){.idx = 1})), + DEFINE_KEY(SUPER | SHIFT, XK_3, transfer_node_wrapper, &((arg_t){.idx = 2})), + DEFINE_KEY(SUPER | SHIFT, XK_4, transfer_node_wrapper, &((arg_t){.idx = 3})), + DEFINE_KEY(SUPER | SHIFT, XK_5, transfer_node_wrapper, &((arg_t){.idx = 4})), + DEFINE_KEY(SUPER | SHIFT, XK_6, transfer_node_wrapper, &((arg_t){.idx = 5})), + DEFINE_KEY(SUPER | SHIFT, XK_7, transfer_node_wrapper, &((arg_t){.idx = 6})), + DEFINE_KEY(SUPER | SHIFT, XK_m, layout_handler, &((arg_t){.t = MASTER})), + DEFINE_KEY(SUPER | SHIFT, XK_d, layout_handler, &((arg_t){.t = DEFAULT})), + DEFINE_KEY(SUPER | SHIFT, XK_s, layout_handler, &((arg_t){.t = STACK})), + DEFINE_KEY(SUPER | SHIFT, XK_k, traverse_stack_wrapper, &((arg_t){.d = UP})), + DEFINE_KEY(SUPER | SHIFT, XK_j, traverse_stack_wrapper, &((arg_t){.d = DOWN})), + DEFINE_KEY(SUPER | SHIFT, XK_f, flip_node_wrapper, NULL), + DEFINE_KEY(SUPER | SHIFT, XK_r, reload_config_wrapper, NULL), + DEFINE_KEY(SUPER | SHIFT, XK_Left, cycle_desktop_wrapper, &((arg_t){.d = LEFT})), + DEFINE_KEY(SUPER | SHIFT, XK_Right, cycle_desktop_wrapper, &((arg_t){.d = RIGHT})), + DEFINE_KEY(SUPER | SHIFT, XK_y, grow_floating_window, &((arg_t){.rd = HORIZONTAL_DIR})), + DEFINE_KEY(SUPER | SHIFT, XK_h, grow_floating_window, &((arg_t){.rd = VERTICAL_DIR})), + DEFINE_KEY(SUPER | SHIFT, XK_t, shrink_floating_window, &((arg_t){.rd = HORIZONTAL_DIR})), + DEFINE_KEY(SUPER | SHIFT, XK_g, shrink_floating_window, &((arg_t){.rd = VERTICAL_DIR})), }; static const uint32_t _buttons_[] = {