mirror of
https://codeberg.org/dwl/dwl-patches.git
synced 2025-09-08 12:14:50 +00:00

Eliminated wiki. Individual patches have a README.md explanation in their own subdirectory. Simplified submission of new patches and maintenance of existing patches. Instructions page (README.md autodisplayed) is now at https://codeberg.org/dwl/dwl-patches/
103 lines
3.1 KiB
Diff
103 lines
3.1 KiB
Diff
From 5646d7e7d933a2e7a667767c3fde89c91697c4ea Mon Sep 17 00:00:00 2001
|
|
From: Guido Cella <guido@guidocella.xyz>
|
|
Date: Tue, 6 Feb 2024 09:20:48 +0100
|
|
Subject: [PATCH] add a keybinding to center the terminal
|
|
|
|
Add a keybinding that toggles centering the terminally 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.
|
|
---
|
|
config.def.h | 1 +
|
|
dwl.c | 19 +++++++++++++++++++
|
|
2 files changed, 20 insertions(+)
|
|
|
|
diff --git a/config.def.h b/config.def.h
|
|
index a85ca27..2055df9 100644
|
|
--- a/config.def.h
|
|
+++ b/config.def.h
|
|
@@ -139,6 +139,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_v, 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 002349a..4582413 100644
|
|
--- a/dwl.c
|
|
+++ b/dwl.c
|
|
@@ -7,6 +7,7 @@
|
|
#include <signal.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
+#include <strings.h>
|
|
#include <sys/wait.h>
|
|
#include <time.h>
|
|
#include <unistd.h>
|
|
@@ -135,6 +136,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;
|
|
|
|
@@ -319,6 +321,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);
|
|
@@ -392,6 +395,8 @@ static struct wlr_box sgeom;
|
|
static struct wl_list mons;
|
|
static Monitor *selmon;
|
|
|
|
+static bool center;
|
|
+
|
|
#ifdef XWAYLAND
|
|
static void activatex11(struct wl_listener *listener, void *data);
|
|
static void associatex11(struct wl_listener *listener, void *data);
|
|
@@ -457,6 +462,8 @@ applyrules(Client *c)
|
|
}
|
|
}
|
|
}
|
|
+ if (!strcasecmp(appid, termcmd[0]))
|
|
+ c->centered = true;
|
|
setmon(c, mon, newtags);
|
|
}
|
|
|
|
@@ -2519,6 +2526,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;
|
|
@@ -2531,6 +2543,13 @@ tile(Monitor *m)
|
|
}
|
|
}
|
|
|
|
+void
|
|
+togglecenter(const Arg *arg)
|
|
+{
|
|
+ center = !center;
|
|
+ tile(selmon);
|
|
+}
|
|
+
|
|
void
|
|
togglefloating(const Arg *arg)
|
|
{
|
|
--
|
|
2.43.0
|
|
|