Skip to content

Commit

Permalink
every desktop has its own gap size
Browse files Browse the repository at this point in the history
  • Loading branch information
adamtherookie committed Aug 29, 2023
1 parent 3c81f1c commit 468800c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
53 changes: 27 additions & 26 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,31 +131,31 @@ void TileWindows() {
if (!c->is_fullscreen && !c->is_floating) break;
}

x = gap_width;
y = (bar_position == top) ? (bar_size + gap_width + bar_padding_y) : (gap_width);
w = width - (2 * gap_width) - (2 * border_width);
h = win_height - (2 * gap_width) - (2 * border_width);
x = desktops[current_desktop].gap_width;
y = (bar_position == top) ? (bar_size + desktops[current_desktop].gap_width + bar_padding_y) : (desktops[current_desktop].gap_width);
w = width - (2 * desktops[current_desktop].gap_width) - (2 * border_width);
h = win_height - (2 * desktops[current_desktop].gap_width) - (2 * border_width);

XMoveResizeWindow(display, c->window, x, y, w, h);
} else {
unsigned int master_width = (width * desktops[current_desktop].master) - (gap_width * 2);
unsigned int stack_width = (width * (1 - desktops[current_desktop].master)) - (gap_width * 2);
unsigned int master_width = (width * desktops[current_desktop].master) - (desktops[current_desktop].gap_width * 2);
unsigned int stack_width = (width * (1 - desktops[current_desktop].master)) - (desktops[current_desktop].gap_width * 2);

unsigned int n = 0;
for (c = head; c; c = c->next) {
if (c->desktop == current_desktop && !c->is_fullscreen && !c->is_floating) {
unsigned int x, y, w, h;

if (n == 0) {
x = gap_width;
y = (bar_position == top) ? (bar_size + gap_width + bar_padding_y) : (gap_width);
x = desktops[current_desktop].gap_width;
y = (bar_position == top) ? (bar_size + desktops[current_desktop].gap_width + bar_padding_y) : (desktops[current_desktop].gap_width);
w = master_width - (border_width * 2);
h = win_height - (border_width * 2) - (gap_width * 2);
h = win_height - (border_width * 2) - (desktops[current_desktop].gap_width * 2);
} else {
x = width * desktops[current_desktop].master;
w = stack_width - (border_width * 2) + (gap_width);
h = (win_height - (2 * border_width * stack_windows) - gap_width * (stack_windows + 1)) / stack_windows;
y = ((bar_position == top) ? (bar_size + gap_width + bar_padding_y) : (gap_width)) + ((n - 1) * (h + gap_width + (2 * border_width)));
w = stack_width - (border_width * 2) + (desktops[current_desktop].gap_width);
h = (win_height - (2 * border_width * stack_windows) - desktops[current_desktop].gap_width * (stack_windows + 1)) / stack_windows;
y = ((bar_position == top) ? (bar_size + desktops[current_desktop].gap_width + bar_padding_y) : (desktops[current_desktop].gap_width)) + ((n - 1) * (h + desktops[current_desktop].gap_width + (2 * border_width)));
}

XMoveResizeWindow(display, c->window, x, y, w, h);
Expand All @@ -173,16 +173,16 @@ void TileWindows() {

if (windows == 0) return;

int window_width = (width - (windows + 1) * gap_width) / windows;
int window_height = height - bar_size - 3 * gap_width;
int window_width = (width - (windows + 1) * desktops[current_desktop].gap_width) / windows;
int window_height = height - bar_size - 3 * desktops[current_desktop].gap_width;

int offset = gap_width;
int offset = desktops[current_desktop].gap_width;

for (c = head; c; c = c->next) {
if (!c->is_tiled) continue;

XMoveResizeWindow(display, c->window, offset, gap_width, window_width, window_height);
offset += window_width + gap_width;
XMoveResizeWindow(display, c->window, offset, desktops[current_desktop].gap_width, window_width, window_height);
offset += window_width + desktops[current_desktop].gap_width;
}
} else if (desktops[current_desktop].layout = STRIPES_HORIZONTAL) {
int windows = 0;
Expand All @@ -194,16 +194,16 @@ void TileWindows() {

if (windows == 0) return;

int window_width = width - gap_width * 2;
int window_height = (height - bar_size - gap_width - (windows + 1) * gap_width) / windows;
int window_width = width - desktops[current_desktop].gap_width * 2;
int window_height = (height - bar_size - desktops[current_desktop].gap_width - (windows + 1) * gap_width) / windows;

int offset = gap_width;
int offset = desktops[current_desktop].gap_width;

for (c = head; c; c = c->next) {
if (!c->is_tiled) continue;

XMoveResizeWindow(display, c->window, gap_width, offset, window_width, window_height);
offset += window_height + gap_width;
XMoveResizeWindow(display, c->window, desktops[current_desktop].gap_width, offset, window_width, window_height);
offset += window_height + desktops[current_desktop].gap_width;
}
}

Expand Down Expand Up @@ -733,14 +733,14 @@ static inline void DecMaster() {
}

static inline void IncGapWidth() {
gap_width += 1;
gap_width = MIN(gap_width, max_gap_width);
desktops[current_desktop].gap_width += 1;
desktops[current_desktop].gap_width = MIN(desktops[current_desktop].gap_width, max_gap_width);
TileWindows();
}

static inline void DecGapWidth() {
gap_width -= 1;
gap_width = MAX(gap_width, min_gap_width);
desktops[current_desktop].gap_width -= 1;
desktops[current_desktop].gap_width = MAX(desktops[current_desktop].gap_width, min_gap_width);
TileWindows();
}

Expand Down Expand Up @@ -1122,6 +1122,7 @@ void init() {
desktops[i].head = head;
desktops[i].current = current;
desktops[i].master = master_size;
desktops[i].gap_width = gap_width;
desktops[i].layout = DEFAULT_LAYOUT;
}

Expand Down
1 change: 1 addition & 0 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ typedef struct Desktop {
Client *current;

float master;
int gap_width;
int layout;
} Desktop;

Expand Down

0 comments on commit 468800c

Please sign in to comment.