modes: update for 0.8 and abandoned patch adopted by unixchad

This commit is contained in:
nate zhou 2026-03-08 11:46:46 +08:00 committed by unixchad
parent 9481ea7ea3
commit 99c3aeb1ed
3 changed files with 205 additions and 38 deletions

View File

@ -28,8 +28,10 @@ static const Modekey modekeys[] = {
``` ```
### Download ### Download
- [v0.8](https://codeberg.org/dwl/dwl-patches/raw/branch/main/patches/modes/modes.patch)
- [git branch](https://codeberg.org/wochap/dwl/src/branch/v0.5/modes) - [git branch](https://codeberg.org/wochap/dwl/src/branch/v0.5/modes)
- [v0.5](https://codeberg.org/dwl/dwl-patches/raw/branch/main/patches/modes/modes.patch) - [v0.5](https://codeberg.org/dwl/dwl-patches/raw/branch/main/patches/modes/modes-0.5.patch)
### Authors ### Authors
- [unixchad](https://codeberg.org/unixchad)
- [wochap](https://codeberg.org/wochap) - [wochap](https://codeberg.org/wochap)

View File

@ -0,0 +1,165 @@
From a32b85018ff2cea0fc9f9137789860a4aadc3b3a Mon Sep 17 00:00:00 2001
From: wochap <gean.marroquin@gmail.com>
Date: Wed, 6 Mar 2024 07:31:17 -0500
Subject: [PATCH] implement modes
like sway/river modes
---
config.def.h | 20 ++++++++++++++++++++
dwl.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+)
diff --git a/config.def.h b/config.def.h
index db0babc..1616136 100644
--- a/config.def.h
+++ b/config.def.h
@@ -13,6 +13,13 @@ static const float urgentcolor[] = COLOR(0xff0000ff);
/* To conform the xdg-protocol, set the alpha to zero to restore the old behavior */
static const float fullscreen_bg[] = {0.1, 0.1, 0.1, 1.0}; /* You can also use glsl colors */
+enum {
+ BROWSER,
+};
+const char *modes_labels[] = {
+ "browser",
+};
+
/* tagging - TAGCOUNT must be no greater than 31 */
#define TAGCOUNT (9)
@@ -152,6 +159,8 @@ static const Key keys[] = {
TAGKEYS( XKB_KEY_9, XKB_KEY_parenleft, 8),
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Q, quit, {0} },
+ { MODKEY, XKB_KEY_b, entermode, {.i = BROWSER} },
+
/* Ctrl-Alt-Backspace and Ctrl-Alt-Fx used to be handled by X server */
{ WLR_MODIFIER_CTRL|WLR_MODIFIER_ALT,XKB_KEY_Terminate_Server, quit, {0} },
/* Ctrl-Alt-Fx is used to switch to another VT, if you don't know what a VT is
@@ -162,6 +171,17 @@ static const Key keys[] = {
CHVT(7), CHVT(8), CHVT(9), CHVT(10), CHVT(11), CHVT(12),
};
+static const Modekey modekeys[] = {
+ /* mode modifier key function argument */
+ { BROWSER, { 0, XKB_KEY_f, spawn, SHCMD("firefox") } },
+ { BROWSER, { 0, XKB_KEY_f, entermode, {.i = NORMAL} } },
+ { BROWSER, { 0, XKB_KEY_b, spawn, SHCMD("brave") } },
+ { BROWSER, { 0, XKB_KEY_b, entermode, {.i = NORMAL} } },
+ { BROWSER, { 0, XKB_KEY_g, spawn, SHCMD("google-chrome-stable") } },
+ { BROWSER, { 0, XKB_KEY_g, entermode, {.i = NORMAL} } },
+ { BROWSER, { 0, XKB_KEY_Escape, entermode, {.i = NORMAL} } },
+};
+
static const Button buttons[] = {
{ MODKEY, BTN_LEFT, moveresize, {.ui = CurMove} },
{ MODKEY, BTN_MIDDLE, togglefloating, {0} },
diff --git a/dwl.c b/dwl.c
index ef27a1d..1ada006 100644
--- a/dwl.c
+++ b/dwl.c
@@ -139,6 +139,11 @@ typedef struct {
const Arg arg;
} Key;
+typedef struct {
+ int mode_index;
+ Key key;
+} Modekey;
+
typedef struct {
struct wl_list link;
struct wlr_keyboard *wlr_keyboard;
@@ -270,6 +275,7 @@ static void handlesig(int signo);
static void incnmaster(const Arg *arg);
static void inputdevice(struct wl_listener *listener, void *data);
static int keybinding(uint32_t mods, xkb_keysym_t sym);
+static int modekeybinding(uint32_t mods, xkb_keysym_t sym);
static void keypress(struct wl_listener *listener, void *data);
static void keypressmod(struct wl_listener *listener, void *data);
static int keyrepeat(void *data);
@@ -327,6 +333,7 @@ static Monitor *xytomon(double x, double y);
static void xytonode(double x, double y, struct wlr_surface **psurface,
Client **pc, LayerSurface **pl, double *nx, double *ny);
static void zoom(const Arg *arg);
+static void entermode(const Arg *arg);
/* variables */
static const char broken[] = "broken";
@@ -377,6 +384,9 @@ static struct wlr_box sgeom;
static struct wl_list mons;
static Monitor *selmon;
+static const int NORMAL = -1;
+static int active_mode_index = NORMAL;
+
#ifdef XWAYLAND
static void activatex11(struct wl_listener *listener, void *data);
static void associatex11(struct wl_listener *listener, void *data);
@@ -1372,6 +1382,11 @@ keybinding(uint32_t mods, xkb_keysym_t sym)
*/
int handled = 0;
const Key *k;
+
+ if (active_mode_index >= 0) {
+ return modekeybinding(mods, sym);
+ }
+
for (k = keys; k < END(keys); k++) {
if (CLEANMASK(mods) == CLEANMASK(k->mod) &&
sym == k->keysym && k->func) {
@@ -1382,6 +1397,29 @@ keybinding(uint32_t mods, xkb_keysym_t sym)
return handled;
}
+int
+modekeybinding(uint32_t mods, xkb_keysym_t sym)
+{
+ int handled = 0;
+ const Modekey *mk;
+ const Key *k;
+
+ for (mk = modekeys; mk < END(modekeys); mk++) {
+ if (active_mode_index != mk->mode_index) {
+ continue;
+ }
+
+ k = &mk->key;
+ if (CLEANMASK(mods) == CLEANMASK(k->mod) &&
+ sym == k->keysym && k->func) {
+ k->func(&k->arg);
+ handled = 1;
+ }
+ }
+
+ return handled;
+}
+
void
keypress(struct wl_listener *listener, void *data)
{
@@ -1851,6 +1889,7 @@ printstatus(void)
printf("%s tags %u %u %u %u\n", m->wlr_output->name, occ, m->tagset[m->seltags],
sel, urg);
printf("%s layout %s\n", m->wlr_output->name, m->ltsymbol);
+ printf("%s mode %s\n", m->wlr_output->name, modes_labels[active_mode_index] ? modes_labels[active_mode_index] : "");
}
fflush(stdout);
}
@@ -2746,6 +2785,13 @@ zoom(const Arg *arg)
arrange(selmon);
}
+void
+entermode(const Arg *arg)
+{
+ active_mode_index = arg->i;
+ printstatus();
+}
+
#ifdef XWAYLAND
void
activatex11(struct wl_listener *listener, void *data)
--
2.42.0

View File

@ -1,21 +1,20 @@
From a32b85018ff2cea0fc9f9137789860a4aadc3b3a Mon Sep 17 00:00:00 2001 From 915115151a4429bab38dd8cff2268f34ee23984f Mon Sep 17 00:00:00 2001
From: wochap <gean.marroquin@gmail.com> From: nate zhou <gnuunixchad@outlook.com>
Date: Wed, 6 Mar 2024 07:31:17 -0500 Date: Mon, 2 Mar 2026 19:23:59 +0800
Subject: [PATCH] implement modes Subject: [PATCH] Patch: modes-0.8.patch
like sway/river modes
--- ---
config.def.h | 20 ++++++++++++++++++++ config.def.h | 20 ++++++++++++++++++++
dwl.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ dwl.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+) 2 files changed, 67 insertions(+)
diff --git a/config.def.h b/config.def.h diff --git a/config.def.h b/config.def.h
index db0babc..1616136 100644 index 8a6eda0..bc88ea5 100644
--- a/config.def.h --- a/config.def.h
+++ b/config.def.h +++ b/config.def.h
@@ -13,6 +13,13 @@ static const float urgentcolor[] = COLOR(0xff0000ff); @@ -14,6 +14,13 @@ static const float urgentcolor[] = COLOR(0xff0000ff);
/* To conform the xdg-protocol, set the alpha to zero to restore the old behavior */ /* This conforms to the xdg-protocol. Set the alpha to zero to restore the old behavior */
static const float fullscreen_bg[] = {0.1, 0.1, 0.1, 1.0}; /* You can also use glsl colors */ static const float fullscreen_bg[] = {0.0f, 0.0f, 0.0f, 1.0f}; /* You can also use glsl colors */
+enum { +enum {
+ BROWSER, + BROWSER,
@ -27,16 +26,16 @@ index db0babc..1616136 100644
/* tagging - TAGCOUNT must be no greater than 31 */ /* tagging - TAGCOUNT must be no greater than 31 */
#define TAGCOUNT (9) #define TAGCOUNT (9)
@@ -152,6 +159,8 @@ static const Key keys[] = { @@ -155,6 +162,8 @@ static const Key keys[] = {
TAGKEYS( XKB_KEY_9, XKB_KEY_parenleft, 8), TAGKEYS( XKB_KEY_9, XKB_KEY_parenleft, 8),
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Q, quit, {0} }, { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_q, quit, {0} },
+ { MODKEY, XKB_KEY_b, entermode, {.i = BROWSER} }, + { MODKEY, XKB_KEY_b, entermode, {.i = BROWSER} },
+ +
/* Ctrl-Alt-Backspace and Ctrl-Alt-Fx used to be handled by X server */ /* Ctrl-Alt-Backspace and Ctrl-Alt-Fx used to be handled by X server */
{ WLR_MODIFIER_CTRL|WLR_MODIFIER_ALT,XKB_KEY_Terminate_Server, quit, {0} }, { WLR_MODIFIER_CTRL|WLR_MODIFIER_ALT,XKB_KEY_Terminate_Server, quit, {0} },
/* Ctrl-Alt-Fx is used to switch to another VT, if you don't know what a VT is /* Ctrl-Alt-Fx is used to switch to another VT, if you don't know what a VT is
@@ -162,6 +171,17 @@ static const Key keys[] = { @@ -165,6 +174,17 @@ static const Key keys[] = {
CHVT(7), CHVT(8), CHVT(9), CHVT(10), CHVT(11), CHVT(12), CHVT(7), CHVT(8), CHVT(9), CHVT(10), CHVT(11), CHVT(12),
}; };
@ -55,10 +54,10 @@ index db0babc..1616136 100644
{ MODKEY, BTN_LEFT, moveresize, {.ui = CurMove} }, { MODKEY, BTN_LEFT, moveresize, {.ui = CurMove} },
{ MODKEY, BTN_MIDDLE, togglefloating, {0} }, { MODKEY, BTN_MIDDLE, togglefloating, {0} },
diff --git a/dwl.c b/dwl.c diff --git a/dwl.c b/dwl.c
index ef27a1d..1ada006 100644 index 44f3ad9..9247541 100644
--- a/dwl.c --- a/dwl.c
+++ b/dwl.c +++ b/dwl.c
@@ -139,6 +139,11 @@ typedef struct { @@ -148,6 +148,11 @@ typedef struct {
const Arg arg; const Arg arg;
} Key; } Key;
@ -68,9 +67,9 @@ index ef27a1d..1ada006 100644
+} Modekey; +} Modekey;
+ +
typedef struct { typedef struct {
struct wl_list link; struct wlr_keyboard_group *wlr_group;
struct wlr_keyboard *wlr_keyboard;
@@ -270,6 +275,7 @@ static void handlesig(int signo); @@ -292,6 +297,7 @@ static void handlesig(int signo);
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);
static int keybinding(uint32_t mods, xkb_keysym_t sym); static int keybinding(uint32_t mods, xkb_keysym_t sym);
@ -78,27 +77,27 @@ index ef27a1d..1ada006 100644
static void keypress(struct wl_listener *listener, void *data); static void keypress(struct wl_listener *listener, void *data);
static void keypressmod(struct wl_listener *listener, void *data); static void keypressmod(struct wl_listener *listener, void *data);
static int keyrepeat(void *data); static int keyrepeat(void *data);
@@ -327,6 +333,7 @@ static Monitor *xytomon(double x, double y); @@ -351,6 +357,7 @@ static Monitor *xytomon(double x, double y);
static void xytonode(double x, double y, struct wlr_surface **psurface, static void xytonode(double x, double y, struct wlr_surface **psurface,
Client **pc, LayerSurface **pl, double *nx, double *ny); Client **pc, LayerSurface **pl, double *nx, double *ny);
static void zoom(const Arg *arg); static void zoom(const Arg *arg);
+static void entermode(const Arg *arg); +static void entermode(const Arg *arg);
/* variables */ /* variables */
static const char broken[] = "broken"; static pid_t child_pid = -1;
@@ -377,6 +384,9 @@ static struct wlr_box sgeom; @@ -406,6 +413,9 @@ static struct wlr_box sgeom;
static struct wl_list mons; static struct wl_list mons;
static Monitor *selmon; static Monitor *selmon;
+static const int NORMAL = -1; +static const int NORMAL = -1;
+static int active_mode_index = NORMAL; +static int active_mode_index = NORMAL;
+ +
#ifdef XWAYLAND /* global event handlers */
static void activatex11(struct wl_listener *listener, void *data); static struct wl_listener cursor_axis = {.notify = axisnotify};
static void associatex11(struct wl_listener *listener, void *data); static struct wl_listener cursor_button = {.notify = buttonpress};
@@ -1372,6 +1382,11 @@ keybinding(uint32_t mods, xkb_keysym_t sym) @@ -1614,6 +1624,11 @@ keybinding(uint32_t mods, xkb_keysym_t sym)
* processing.
*/ */
int handled = 0;
const Key *k; const Key *k;
+ +
+ if (active_mode_index >= 0) { + if (active_mode_index >= 0) {
@ -106,10 +105,10 @@ index ef27a1d..1ada006 100644
+ } + }
+ +
for (k = keys; k < END(keys); k++) { for (k = keys; k < END(keys); k++) {
if (CLEANMASK(mods) == CLEANMASK(k->mod) && if (CLEANMASK(mods) == CLEANMASK(k->mod)
sym == k->keysym && k->func) { && xkb_keysym_to_lower(sym) == xkb_keysym_to_lower(k->keysym)
@@ -1382,6 +1397,29 @@ keybinding(uint32_t mods, xkb_keysym_t sym) @@ -1625,6 +1640,30 @@ keybinding(uint32_t mods, xkb_keysym_t sym)
return handled; return 0;
} }
+int +int
@ -134,19 +133,20 @@ index ef27a1d..1ada006 100644
+ +
+ return handled; + return handled;
+} +}
+
+ +
void void
keypress(struct wl_listener *listener, void *data) keypress(struct wl_listener *listener, void *data)
{ {
@@ -1851,6 +1889,7 @@ printstatus(void) @@ -2119,6 +2158,7 @@ printstatus(void)
printf("%s tags %u %u %u %u\n", m->wlr_output->name, occ, m->tagset[m->seltags], printf("%s tags %"PRIu32" %"PRIu32" %"PRIu32" %"PRIu32"\n",
sel, urg); m->wlr_output->name, occ, m->tagset[m->seltags], sel, urg);
printf("%s layout %s\n", m->wlr_output->name, m->ltsymbol); printf("%s layout %s\n", m->wlr_output->name, m->ltsymbol);
+ printf("%s mode %s\n", m->wlr_output->name, modes_labels[active_mode_index] ? modes_labels[active_mode_index] : ""); + printf("%s mode %s\n", m->wlr_output->name, modes_labels[active_mode_index] ? modes_labels[active_mode_index] : "");
} }
fflush(stdout); fflush(stdout);
} }
@@ -2746,6 +2785,13 @@ zoom(const Arg *arg) @@ -3075,6 +3115,13 @@ zoom(const Arg *arg)
arrange(selmon); arrange(selmon);
} }
@ -161,5 +161,5 @@ index ef27a1d..1ada006 100644
void void
activatex11(struct wl_listener *listener, void *data) activatex11(struct wl_listener *listener, void *data)
-- --
2.42.0 2.53.0