Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FvwmRerrange: Add gap option when tiling. #1159

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/FvwmRearrange.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ override this behavior and make windows fit in their cells better.
-fill_end::
This will use any unused space in the grid by filling the last row (or
last column with _-swap_) left open in the grid.
-gap_x _N_, -gap_y _N_, -gap _N_::
This will set the gap between the cells the windows are placed in.
_-gap_x_ sets the size of the horizontal gap, _-gap_y_ sets the size
of the vertical gap, and _-gap_ sets both the size of the horizontal
and vertical gap to be the same. The value _N_ is the number of pixels
between cells, or the width of the line between cells. Default: 0.

=== CASCADING OPTIONS

Expand Down
36 changes: 23 additions & 13 deletions modules/FvwmRearrange/FvwmRearrange.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ int c_width = 0, c_height = 0; /* FvwmCascade window sizes. */
int max_n = 0; /* FvwmTile maximum rows or cols. */
int current_desk = 0;
int win_order = WIN_ORDER_DEFAULT;
int gap_x = 0, gap_y = 0;

/* Switches */
int FvwmTile = 1;
Expand Down Expand Up @@ -484,15 +485,15 @@ size_win_to_cell(window_item *wi, int x, int y, int cell_w, int cell_h,

if (x < extra_w) {
w++;
x = box_x + x * cell_w + x;
x = box_x + x * (cell_w + gap_x + 1);
} else {
x = box_x + x * cell_w + extra_w;
x = box_x + x * (cell_w + gap_x) + extra_w;
}
if (y < extra_h) {
h++;
y = box_y + y * cell_h + y;
y = box_y + y * (cell_h + gap_y + 1);
} else {
y = box_y + y * cell_h + extra_h;
y = box_y + y * (cell_h + gap_y) + extra_h;
}

if (nostretchx && w > wi->width)
Expand All @@ -512,12 +513,12 @@ window_item

if (horizontal) {
extra_wins = wins_count % rows;
cell_l = box_h / extra_wins;
extra_l = box_h % extra_wins;
cell_l = (box_h - (extra_wins - 1) * gap_y) / extra_wins;
extra_l = (box_h - (extra_wins - 1) * gap_y) % extra_wins;
} else {
extra_wins = wins_count % cols;
cell_l = box_w / extra_wins;
extra_l = box_w % extra_wins;
cell_l = (box_w - (extra_wins - 1) * gap_x) / extra_wins;
extra_l = (box_w - (extra_wins - 1) * gap_x) % extra_wins;
}

for (i = 0; i < extra_wins; i++) {
Expand Down Expand Up @@ -569,11 +570,11 @@ tile_windows(void)
}

/* Compute single cell size. */
cell_w = box_w / cols;
cell_h = box_h / rows;
cell_w = (box_w - (cols - 1) * gap_x) / cols;
cell_h = (box_h - (rows - 1) * gap_y) / rows;
/* Extra space to spread across initial cells. */
extra_w = box_w % cols;
extra_h = box_h % rows;
extra_w = (box_w - (cols - 1) * gap_x) % cols;
extra_h = (box_h - (rows - 1) * gap_y) % rows;

/* Do nothing if cells are too small. */
if (cell_w < MIN_CELL_SIZE || cell_h < MIN_CELL_SIZE) {
Expand Down Expand Up @@ -680,6 +681,15 @@ parse_args(int argc, char *argv[], int argi)
fill_start = 1;
} else if (StrEquals(argv[argi], "-fill_end")) {
fill_end = 1;
} else if (StrEquals(argv[argi], "-gap")
&& ((argi + 1) < argc)) {
gap_x = gap_y = atoi(argv[++argi]);
} else if (StrEquals(argv[argi], "-gap_x")
&& ((argi + 1) < argc)) {
gap_x = atoi(argv[++argi]);
} else if (StrEquals(argv[argi], "-gap_y")
&& ((argi + 1) < argc)) {
gap_y = atoi(argv[++argi]);

/* Cascading options */
} else if (StrEquals(argv[argi], "-cascade")) {
Expand Down Expand Up @@ -999,4 +1009,4 @@ void process_message(unsigned long type, unsigned long *body)
default:
break;
}
}
}