Fix the gridmode patch

This commit is contained in:
Abanoub 2023-06-21 18:04:49 +03:00
parent 68a17f962e
commit 4a3f56c8dd
No known key found for this signature in database
GPG Key ID: A4A10C91692482EC
2 changed files with 38 additions and 0 deletions

View File

@ -24,6 +24,7 @@ static const Layout layouts[] = {
{ "[]=", tile }, { "[]=", tile },
{ "><>", NULL }, /* no layout function means floating behavior */ { "><>", NULL }, /* no layout function means floating behavior */
{ "[M]", monocle }, { "[M]", monocle },
{ "HHH", grid },
}; };
/* monitors */ /* monitors */
@ -123,6 +124,7 @@ static const Key keys[] = {
{ MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[0]} }, { MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[0]} },
{ MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} }, { MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} },
{ MODKEY, XKB_KEY_m, setlayout, {.v = &layouts[2]} }, { MODKEY, XKB_KEY_m, setlayout, {.v = &layouts[2]} },
{ MODKEY, XKB_KEY_g, setlayout, {.v = &layouts[3]} },
{ MODKEY, XKB_KEY_space, setlayout, {0} }, { MODKEY, XKB_KEY_space, setlayout, {0} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, togglefloating, {0} }, { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, togglefloating, {0} },
{ MODKEY, XKB_KEY_e, togglefullscreen, {0} }, { MODKEY, XKB_KEY_e, togglefullscreen, {0} },

36
dwl.c
View File

@ -259,6 +259,7 @@ static void focusclient(Client *c, int lift);
static void focusmon(const Arg *arg); static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg); static void focusstack(const Arg *arg);
static Client *focustop(Monitor *m); static Client *focustop(Monitor *m);
static void grid(Monitor *m);
static void fullscreennotify(struct wl_listener *listener, void *data); static void fullscreennotify(struct wl_listener *listener, void *data);
static void incnmaster(const Arg *arg); static void incnmaster(const Arg *arg);
static void inputdevice(struct wl_listener *listener, void *data); static void inputdevice(struct wl_listener *listener, void *data);
@ -1333,6 +1334,41 @@ fullscreennotify(struct wl_listener *listener, void *data)
setfullscreen(c, client_wants_fullscreen(c)); setfullscreen(c, client_wants_fullscreen(c));
} }
void
grid(Monitor *m) {
unsigned int n = 0, i = 0, ch, cw, rows, cols;
Client *c;
wl_list_for_each(c, &clients, link)
if (VISIBLEON(c, m) && !c->isfloating)
n++;
if (n == 0)
return;
/* grid dimensions */
for (rows = 0; rows <= (n / 2); rows++)
if ((rows * rows) >= n)
break;
cols = (rows && ((rows - 1) * rows) >= n) ? rows - 1 : rows;
/* window geoms (cell height/width) */
ch = m->w.height / (rows ? rows : 1);
cw = m->w.width / (cols ? cols : 1);
wl_list_for_each(c, &clients, link) {
unsigned int cx, cy, ah, aw;
if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
continue;
cx = m->w.x + (i / rows) * cw;
cy = m->w.y + (i % rows) * ch;
/* adjust height/width of last row/column's windows */
ah = (((i + 1) % rows) == 0) ? m->w.height - ch * rows : 0;
aw = (i >= (rows * (cols - 1))) ? m->w.width - cw * cols : 0;
resize(c, (struct wlr_box) { .x = cx, .y = cy, .width = cw - aw, .height = ch - ah }, 0);
i++;
}
}
void void
incnmaster(const Arg *arg) incnmaster(const Arg *arg)
{ {