From 064f8f20dc123c5bbff2106c2c45e2b7dcc3fef1 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Wed, 3 May 2023 09:29:22 +0200 Subject: [PATCH] Allow centering the terminal Adds a keybinding that toggles centering Alacritty horizontally when it's the only window, while still tiling multiple windows. This limits the width of long text making it easier to read, and avoids covering the wallpaper more than necessary. Replace the Alacritty app id if you use a different terminal. --- config.def.h | 1 + dwl.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/config.def.h b/config.def.h index 1677f6f..970f079 100644 --- a/config.def.h +++ b/config.def.h @@ -127,6 +127,7 @@ static const Key keys[] = { { MODKEY, XKB_KEY_space, setlayout, {0} }, { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, togglefloating, {0} }, { MODKEY, XKB_KEY_e, togglefullscreen, {0} }, + { MODKEY, XKB_KEY_z, togglecenter, {0} }, { MODKEY, XKB_KEY_0, view, {.ui = ~0} }, { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_parenright, tag, {.ui = ~0} }, { MODKEY, XKB_KEY_comma, focusmon, {.i = WLR_DIRECTION_LEFT} }, diff --git a/dwl.c b/dwl.c index 4118fd8..d16c0b8 100644 --- a/dwl.c +++ b/dwl.c @@ -125,6 +125,7 @@ typedef struct { unsigned int bw; uint32_t tags; int isfloating, isurgent, isfullscreen; + bool centered; uint32_t resize; /* configure serial of a pending resize */ } Client; @@ -302,6 +303,7 @@ static void startdrag(struct wl_listener *listener, void *data); static void tag(const Arg *arg); static void tagmon(const Arg *arg); static void tile(Monitor *m); +static void togglecenter(const Arg *arg); static void togglefloating(const Arg *arg); static void togglefullscreen(const Arg *arg); static void toggletag(const Arg *arg); @@ -367,6 +369,8 @@ static struct wlr_box sgeom; static struct wl_list mons; static Monitor *selmon; +static bool center; + /* global event handlers */ static struct wl_listener cursor_axis = {.notify = axisnotify}; static struct wl_listener cursor_button = {.notify = buttonpress}; @@ -468,6 +472,8 @@ applyrules(Client *c) } } wlr_scene_node_reparent(&c->scene->node, layers[c->isfloating ? LyrFloat : LyrTile]); + if (!strcmp(appid, "Alacritty")) + c->centered = true; setmon(c, mon, newtags); } @@ -2376,6 +2382,11 @@ tile(Monitor *m) if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen) continue; if (i < m->nmaster) { + if (n == 1 && center && c->centered) { + resize(c, (struct wlr_box){.x = m->w.width / 4, .y = m->w.y, + .width = m->w.width / 2, .height = m->w.height - 2 * c->bw}, 0); + return; + } resize(c, (struct wlr_box){.x = m->w.x, .y = m->w.y + my, .width = mw, .height = (m->w.height - my) / (MIN(n, m->nmaster) - i)}, 0); my += c->geom.height; @@ -2388,6 +2399,13 @@ tile(Monitor *m) } } +void +togglecenter(const Arg *arg) +{ + center = !center; + tile(selmon); +} + void togglefloating(const Arg *arg) {