Skip to content

Commit

Permalink
Merge pull request #35 from yazeed1s/resize-floating-windows
Browse files Browse the repository at this point in the history
Resize floating windows
  • Loading branch information
yazeed1s authored Dec 15, 2024
2 parents d4976b1 + 549c316 commit 932d03f
Show file tree
Hide file tree
Showing 7 changed files with 373 additions and 202 deletions.
118 changes: 67 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -144,13 +145,15 @@ ZWM uses **binary space partitioning tree** ([BSP-tree](https://en.wikipedia.org
## Installation

#### Arch Linux (AUR)

```bash
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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down
56 changes: 39 additions & 17 deletions src/config_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_[] = {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
}
}

Expand Down
78 changes: 38 additions & 40 deletions src/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
28 changes: 17 additions & 11 deletions src/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 */
Expand Down
Loading

0 comments on commit 932d03f

Please sign in to comment.