Skip to content

Commit

Permalink
[dwm] applied focus on net active patch
Browse files Browse the repository at this point in the history
  • Loading branch information
abbsi committed Jan 8, 2021
1 parent bf18873 commit d0c58a7
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Some note, issues to keep in mind:
| [Static Status](https://dwm.suckless.org/patches/staticstatus/) | allows the status text to be fixed to the bar on a specific monitor rather than being drawn on the focused monitor. Update `staticmonval` to select monitor |
| [Restart Signal](https://dwm.suckless.org/patches/restartsig/) | adds a keyboard shortcut to restart dwm or alternatively by using `kill -HUP dwmpid` and additionally dwm can quit cleanly by using `kill -TERM dwmpid` |
| [EWMH Tags](https://dwm.suckless.org/patches/ewmhtags/) | adds EWMH support for _NET_NUMBER_OF_DESKTOPS, _NET_CURRENT_DESKTOP, _NET_DESKTOP_NAMES, and _NET_DESKTOP_VIEWPORT, which allows for compatibility with other bars and programs that request workspace information. for example, polybar's xworkspaces module |
| [Focus on Active](https://dwm.suckless.org/patches/focusonnetactive/) | By default, dwm response to client requests to _NET_ACTIVE_WINDOW client messages by setting the urgency bit on the named window. This patch activates the window instead. |
## Appearance
Expand Down
2 changes: 1 addition & 1 deletion dwm/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} ${YAJLLIBS} -lXrender
# flags
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=2 -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
#CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os -Wno-unused-function ${INCS} ${CPPFLAGS}
CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Wno-incompatible-pointer-types -Os ${INCS} ${CPPFLAGS}
LDFLAGS = ${LIBS}

# Solaris
Expand Down
15 changes: 12 additions & 3 deletions dwm/dwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ static void setfullscreen(Client *c, int fullscreen);
static void setlayout(const Arg *arg);
static void setlayoutsafe(const Arg *arg);
static void setmfact(const Arg *arg);
static void setnumbdesktops(void);
static void setnumdesktops(void);
static void setup(void);
static void setviewport(void);
static void setupepoll(void);
Expand Down Expand Up @@ -721,6 +721,7 @@ clientmessage(XEvent *e)
{
XClientMessageEvent *cme = &e->xclient;
Client *c = wintoclient(cme->window);
unsigned int i;

if (!c)
return;
Expand All @@ -730,8 +731,16 @@ clientmessage(XEvent *e)
setfullscreen(c, (cme->data.l[0] == 1 /* _NET_WM_STATE_ADD */
|| (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen)));
} else if (cme->message_type == netatom[NetActiveWindow]) {
if (c != selmon->sel && !c->isurgent)
seturgent(c, 1);
//if (c != selmon->sel && !c->isurgent)
// seturgent(c, 1);
for (i = 0; i < LENGTH(tags) && !((1 << i) & c->tags); i++);
if (i < LENGTH(tags)) {
const Arg a = {.ui = 1 << i};
selmon = c->mon;
view(&a);
focus(c);
restack(selmon);
}
}
}

Expand Down
57 changes: 57 additions & 0 deletions dwm/patches/general/dwm-focusonnetactive-6.2.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
From 286ca3bb1af08b452bf8140abcc23d4ef61baaa2 Mon Sep 17 00:00:00 2001
From: bakkeby <bakkeby@gmail.com>
Date: Tue, 7 Apr 2020 12:33:04 +0200
Subject: [PATCH] Activate a window in response to _NET_ACTIVE_WINDOW

By default, dwm response to client requests to _NET_ACTIVE_WINDOW client
messages by setting the urgency bit on the named window.

This patch activates the window instead.

Both behaviours are legitimate according to
https://specifications.freedesktop.org/wm-spec/wm-spec-latest.html#idm140200472702304

One should decide which of these one should perform based on the message
senders' untestable claims that it represents the end-user. Setting the
urgency bit is the conservative decision. This patch implements the more
trusting alternative.

It also allows dwm to work with `wmctrl -a` and other external window
management utilities

---
dwm.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/dwm.c b/dwm.c
index 4465af1..3919d47 100644
--- a/dwm.c
+++ b/dwm.c
@@ -514,6 +514,7 @@ clientmessage(XEvent *e)
{
XClientMessageEvent *cme = &e->xclient;
Client *c = wintoclient(cme->window);
+ unsigned int i;

if (!c)
return;
@@ -523,8 +524,14 @@ clientmessage(XEvent *e)
setfullscreen(c, (cme->data.l[0] == 1 /* _NET_WM_STATE_ADD */
|| (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen)));
} else if (cme->message_type == netatom[NetActiveWindow]) {
- if (c != selmon->sel && !c->isurgent)
- seturgent(c, 1);
+ for (i = 0; i < LENGTH(tags) && !((1 << i) & c->tags); i++);
+ if (i < LENGTH(tags)) {
+ const Arg a = {.ui = 1 << i};
+ selmon = c->mon;
+ view(&a);
+ focus(c);
+ restack(selmon);
+ }
}
}

--
2.17.1

0 comments on commit d0c58a7

Please sign in to comment.