Fix rules for focus and unfocus

This commit is contained in:
Hans von Hohenstaufen 2026-04-27 04:25:20 +00:00
parent e55349448e
commit 86fc4bd35d
No known key found for this signature in database
GPG Key ID: A59E421E6853855D
2 changed files with 24 additions and 22 deletions

View File

@ -14,7 +14,7 @@ The opacity levels can be change by short cuts.
### Download ### Download
- [git branch](https://codeberg.org/Hansvon/dwl/src/branch/client-opacity-focus) - [git branch](https://codeberg.org/Hansvon/dwl/src/branch/client-opacity-focus)
- [2025-12-11](https://codeberg.org/dwl/dwl-patches/raw/branch/main/patches/client-opacity-focus/client-opacity-focus.patch) - [2026-04-27](https://codeberg.org/dwl/dwl-patches/raw/branch/main/patches/client-opacity-focus/client-opacity-focus.patch)
### Authors ### Authors
- [Hansvon](https://codeberg.org/Hansvon) - [Hansvon](https://codeberg.org/Hansvon)

View File

@ -1,15 +1,15 @@
From 694751a31a437bbb28c3a75c917ed922231ab366 Mon Sep 17 00:00:00 2001 From 57c5475d7f715b77ec05d69a2bda808b224cf0b4 Mon Sep 17 00:00:00 2001
From: Hans von Hohenstaufen <Hans.von.Hohenstaufen@protonmail.com> From: Hans von Hohenstaufen <Hans.von.Hohenstaufen@protonmail.com>
Date: Mon, 22 Dec 2025 01:43:50 +0000 Date: Mon, 22 Dec 2025 01:43:50 +0000
Subject: [PATCH] Add client opacity focus Subject: [PATCH] Add client opacity focus
--- ---
config.def.h | 12 +++++++--- config.def.h | 12 +++++++---
dwl.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ dwl.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 3 deletions(-) 2 files changed, 74 insertions(+), 3 deletions(-)
diff --git a/config.def.h b/config.def.h diff --git a/config.def.h b/config.def.h
index 95c2afa..b7002f5 100644 index 95c2afa..55abf84 100644
--- a/config.def.h --- a/config.def.h
+++ b/config.def.h +++ b/config.def.h
@@ -13,6 +13,8 @@ static const float focuscolor[] = COLOR(0x005577ff); @@ -13,6 +13,8 @@ static const float focuscolor[] = COLOR(0x005577ff);
@ -26,12 +26,12 @@ index 95c2afa..b7002f5 100644
/* NOTE: ALWAYS keep a rule declared even if you don't use rules (e.g leave at least one example) */ /* NOTE: ALWAYS keep a rule declared even if you don't use rules (e.g leave at least one example) */
static const Rule rules[] = { static const Rule rules[] = {
- /* app_id title tags mask isfloating monitor */ - /* app_id title tags mask isfloating monitor */
+ /* app_id title tags mask isfloating alpha unfocus monitor */ + /* app_id title tags mask isfloating alpha focus alpha unfocus monitor */
/* examples: */ /* examples: */
- { "Gimp_EXAMPLE", NULL, 0, 1, -1 }, /* Start on currently visible tags floating, not tiled */ - { "Gimp_EXAMPLE", NULL, 0, 1, -1 }, /* Start on currently visible tags floating, not tiled */
- { "firefox_EXAMPLE", NULL, 1 << 8, 0, -1 }, /* Start on ONLY tag "9" */ - { "firefox_EXAMPLE", NULL, 1 << 8, 0, -1 }, /* Start on ONLY tag "9" */
+ { "Gimp_EXAMPLE", NULL, 0, 1, default_opacity_unfocus, -1 }, /* Start on currently visible tags floating, not tiled */ + { "Gimp_EXAMPLE", NULL, 0, 1, 1.00, 0.20, -1 }, /* Start on currently visible tags floating, not tiled */
+ { "firefox_EXAMPLE", NULL, 1 << 8, 0, 1.00, -1 }, /* Start on ONLY tag "9" */ + { "firefox_EXAMPLE", NULL, 1 << 8, 0, 1.00, 1.00, -1 }, /* Start on ONLY tag "9" */
}; };
/* layout(s) */ /* layout(s) */
@ -47,7 +47,7 @@ index 95c2afa..b7002f5 100644
{ 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} },
diff --git a/dwl.c b/dwl.c diff --git a/dwl.c b/dwl.c
index 12f441e..7539738 100644 index 12f441e..e45e420 100644
--- a/dwl.c --- a/dwl.c
+++ b/dwl.c +++ b/dwl.c
@@ -138,6 +138,9 @@ typedef struct { @@ -138,6 +138,9 @@ typedef struct {
@ -60,15 +60,16 @@ index 12f441e..7539738 100644
uint32_t resize; /* configure serial of a pending resize */ uint32_t resize; /* configure serial of a pending resize */
} Client; } Client;
@@ -227,6 +230,7 @@ typedef struct { @@ -227,6 +230,8 @@ typedef struct {
const char *title; const char *title;
uint32_t tags; uint32_t tags;
int isfloating; int isfloating;
+ float opacity_focus;
+ float opacity_unfocus; + float opacity_unfocus;
int monitor; int monitor;
} Rule; } Rule;
@@ -319,6 +323,7 @@ static void requeststartdrag(struct wl_listener *listener, void *data); @@ -319,6 +324,7 @@ static void requeststartdrag(struct wl_listener *listener, void *data);
static void requestmonstate(struct wl_listener *listener, void *data); static void requestmonstate(struct wl_listener *listener, void *data);
static void resize(Client *c, struct wlr_box geo, int interact); static void resize(Client *c, struct wlr_box geo, int interact);
static void run(char *startup_cmd); static void run(char *startup_cmd);
@ -76,7 +77,7 @@ index 12f441e..7539738 100644
static void setcursor(struct wl_listener *listener, void *data); static void setcursor(struct wl_listener *listener, void *data);
static void setcursorshape(struct wl_listener *listener, void *data); static void setcursorshape(struct wl_listener *listener, void *data);
static void setfloating(Client *c, int floating); static void setfloating(Client *c, int floating);
@@ -326,6 +331,8 @@ static void setfullscreen(Client *c, int fullscreen); @@ -326,6 +332,8 @@ static void setfullscreen(Client *c, int fullscreen);
static void setlayout(const Arg *arg); static void setlayout(const Arg *arg);
static void setmfact(const Arg *arg); static void setmfact(const Arg *arg);
static void setmon(Client *c, Monitor *m, uint32_t newtags); static void setmon(Client *c, Monitor *m, uint32_t newtags);
@ -85,15 +86,16 @@ index 12f441e..7539738 100644
static void setpsel(struct wl_listener *listener, void *data); static void setpsel(struct wl_listener *listener, void *data);
static void setsel(struct wl_listener *listener, void *data); static void setsel(struct wl_listener *listener, void *data);
static void setup(void); static void setup(void);
@@ -490,6 +497,7 @@ applyrules(Client *c) @@ -490,6 +498,8 @@ applyrules(Client *c)
if ((!r->title || strstr(title, r->title)) if ((!r->title || strstr(title, r->title))
&& (!r->id || strstr(appid, r->id))) { && (!r->id || strstr(appid, r->id))) {
c->isfloating = r->isfloating; c->isfloating = r->isfloating;
+ c->opacity = r->opacity_unfocus; + c->opacity_unfocus = r->opacity_unfocus;
+ c->opacity_focus = r->opacity_focus;
newtags |= r->tags; newtags |= r->tags;
i = 0; i = 0;
wl_list_for_each(m, &mons, link) { wl_list_for_each(m, &mons, link) {
@@ -1127,6 +1135,10 @@ createnotify(struct wl_listener *listener, void *data) @@ -1127,6 +1137,10 @@ createnotify(struct wl_listener *listener, void *data)
c = toplevel->base->data = ecalloc(1, sizeof(*c)); c = toplevel->base->data = ecalloc(1, sizeof(*c));
c->surface.xdg = toplevel->base; c->surface.xdg = toplevel->base;
c->bw = borderpx; c->bw = borderpx;
@ -104,7 +106,7 @@ index 12f441e..7539738 100644
LISTEN(&toplevel->base->surface->events.commit, &c->commit, commitnotify); LISTEN(&toplevel->base->surface->events.commit, &c->commit, commitnotify);
LISTEN(&toplevel->base->surface->events.map, &c->map, mapnotify); LISTEN(&toplevel->base->surface->events.map, &c->map, mapnotify);
@@ -1429,6 +1441,7 @@ focusclient(Client *c, int lift) @@ -1429,6 +1443,7 @@ focusclient(Client *c, int lift)
wl_list_insert(&fstack, &c->flink); wl_list_insert(&fstack, &c->flink);
selmon = c->mon; selmon = c->mon;
c->isurgent = 0; c->isurgent = 0;
@ -112,7 +114,7 @@ index 12f441e..7539738 100644
/* Don't change border color if there is an exclusive focus or we are /* Don't change border color if there is an exclusive focus or we are
* handling a drag operation */ * handling a drag operation */
@@ -1453,6 +1466,7 @@ focusclient(Client *c, int lift) @@ -1453,6 +1468,7 @@ focusclient(Client *c, int lift)
client_set_border_color(old_c, bordercolor); client_set_border_color(old_c, bordercolor);
client_activate_surface(old, 0); client_activate_surface(old, 0);
@ -120,7 +122,7 @@ index 12f441e..7539738 100644
} }
} }
printstatus(); printstatus();
@@ -2159,6 +2173,7 @@ rendermon(struct wl_listener *listener, void *data) @@ -2159,6 +2175,7 @@ rendermon(struct wl_listener *listener, void *data)
/* Render if no XDG clients have an outstanding resize and are visible on /* Render if no XDG clients have an outstanding resize and are visible on
* this monitor. */ * this monitor. */
wl_list_for_each(c, &clients, link) { wl_list_for_each(c, &clients, link) {
@ -128,7 +130,7 @@ index 12f441e..7539738 100644
if (c->resize && !c->isfloating && client_is_rendered_on_mon(c, m) && !client_is_stopped(c)) if (c->resize && !c->isfloating && client_is_rendered_on_mon(c, m) && !client_is_stopped(c))
goto skip; goto skip;
} }
@@ -2295,6 +2310,15 @@ run(char *startup_cmd) @@ -2295,6 +2312,15 @@ run(char *startup_cmd)
wl_display_run(dpy); wl_display_run(dpy);
} }
@ -144,7 +146,7 @@ index 12f441e..7539738 100644
void void
setcursor(struct wl_listener *listener, void *data) setcursor(struct wl_listener *listener, void *data)
{ {
@@ -2363,6 +2387,7 @@ setfullscreen(Client *c, int fullscreen) @@ -2363,6 +2389,7 @@ setfullscreen(Client *c, int fullscreen)
* client positions are set by the user and cannot be recalculated */ * client positions are set by the user and cannot be recalculated */
resize(c, c->prev, 0); resize(c, c->prev, 0);
} }
@ -152,7 +154,7 @@ index 12f441e..7539738 100644
arrange(c->mon); arrange(c->mon);
printstatus(); printstatus();
} }
@@ -2419,6 +2444,44 @@ setmon(Client *c, Monitor *m, uint32_t newtags) @@ -2419,6 +2446,44 @@ setmon(Client *c, Monitor *m, uint32_t newtags)
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), 1);
} }
@ -198,5 +200,5 @@ index 12f441e..7539738 100644
setpsel(struct wl_listener *listener, void *data) setpsel(struct wl_listener *listener, void *data)
{ {
-- --
2.51.2 2.53.0