Skip to content

Commit 78ea08a

Browse files
LordRegmarcopeereboom
authored andcommitted
Add support for EWMH _NET_WM_STATE_FOCUSED
Windows with a focused border will have this property set in _NET_WM_STATE.
1 parent 2f1aa51 commit 78ea08a

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

spectrwm.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,9 @@ uint32_t swm_debug = 0
224224
#define EWMH_F_ABOVE (1 << 6)
225225
#define EWMH_F_BELOW (1 << 7)
226226
#define EWMH_F_DEMANDS_ATTENTION (1 << 8)
227-
#define SWM_F_MANUAL (1 << 9)
228-
#define SWM_EWMH_ACTION_COUNT_MAX (10)
227+
#define EWMH_F_FOCUSED (1 << 9)
228+
#define SWM_F_MANUAL (1 << 10)
229+
#define SWM_EWMH_ACTION_COUNT_MAX (11)
229230

230231
#define EWMH_F_MAXIMIZED (EWMH_F_MAXIMIZED_VERT | EWMH_F_MAXIMIZED_HORZ)
231232
#define EWMH_F_UNTILED (EWMH_F_ABOVE | EWMH_F_FULLSCREEN | \
@@ -315,6 +316,7 @@ uint32_t swm_debug = 0
315316
#define ABOVE(w) ((w)->ewmh_flags & EWMH_F_ABOVE)
316317
#define BELOW(w) ((w)->ewmh_flags & EWMH_F_BELOW)
317318
#define DEMANDS_ATTENTION(w) ((w)->ewmh_flags & EWMH_F_DEMANDS_ATTENTION)
319+
#define FOCUSED(w) ((w)->ewmh_flags & EWMH_F_FOCUSED)
318320
#define MANUAL(w) ((w)->ewmh_flags & SWM_F_MANUAL)
319321
#define MAXIMIZED(w) ((w)->ewmh_flags & EWMH_F_MAXIMIZED)
320322

@@ -1047,6 +1049,7 @@ enum {
10471049
_NET_WM_STATE_ABOVE,
10481050
_NET_WM_STATE_BELOW,
10491051
_NET_WM_STATE_DEMANDS_ATTENTION,
1052+
_NET_WM_STATE_FOCUSED,
10501053
_NET_WM_STRUT,
10511054
_NET_WM_STRUT_PARTIAL,
10521055
_NET_WM_WINDOW_TYPE,
@@ -1110,6 +1113,7 @@ struct ewmh_hint {
11101113
{"_NET_WM_STATE_ABOVE", XCB_ATOM_NONE},
11111114
{"_NET_WM_STATE_BELOW", XCB_ATOM_NONE},
11121115
{"_NET_WM_STATE_DEMANDS_ATTENTION", XCB_ATOM_NONE},
1116+
{"_NET_WM_STATE_FOCUSED", XCB_ATOM_NONE},
11131117
{"_NET_WM_STRUT", XCB_ATOM_NONE},
11141118
{"_NET_WM_STRUT_PARTIAL", XCB_ATOM_NONE},
11151119
{"_NET_WM_WINDOW_TYPE", XCB_ATOM_NONE},
@@ -2661,6 +2665,8 @@ ewmh_change_wm_state(struct ws_win *win, xcb_atom_t state, long action)
26612665
flag = EWMH_F_BELOW;
26622666
else if (state == ewmh[_NET_WM_STATE_DEMANDS_ATTENTION].atom)
26632667
flag = EWMH_F_DEMANDS_ATTENTION;
2668+
else if (state == ewmh[_NET_WM_STATE_FOCUSED].atom)
2669+
flag = EWMH_F_FOCUSED;
26642670
else if (state == ewmh[_SWM_WM_STATE_MANUAL].atom)
26652671
flag = SWM_F_MANUAL;
26662672

@@ -2770,6 +2776,8 @@ ewmh_update_wm_state(struct ws_win *win) {
27702776
vals[n++] = ewmh[_NET_WM_STATE_BELOW].atom;
27712777
if (DEMANDS_ATTENTION(win))
27722778
vals[n++] = ewmh[_NET_WM_STATE_DEMANDS_ATTENTION].atom;
2779+
if (FOCUSED(win))
2780+
vals[n++] = ewmh[_NET_WM_STATE_FOCUSED].atom;
27732781
if (MANUAL(win))
27742782
vals[n++] = ewmh[_SWM_WM_STATE_MANUAL].atom;
27752783

@@ -6787,6 +6795,8 @@ unfocus_win(struct ws_win *win)
67876795
update_window(win);
67886796
}
67896797

6798+
if (ewmh_apply_flags(win, win->ewmh_flags & ~EWMH_F_FOCUSED))
6799+
ewmh_update_wm_state(win);
67906800
draw_frame(win);
67916801
DNPRINTF(SWM_D_FOCUS, "done\n");
67926802
}
@@ -7095,7 +7105,12 @@ update_focus(struct swm_screen *s)
70957105
} else
70967106
set_input_focus((s->r_focus ? s->r_focus->id : s->swmwin), true);
70977107

7098-
draw_frame(win);
7108+
if (win) {
7109+
ewmh_apply_flags(win, win->ewmh_flags | EWMH_F_FOCUSED);
7110+
ewmh_update_wm_state(win);
7111+
draw_frame(win);
7112+
}
7113+
70997114
update_bars(s);
71007115
ewmh_update_active_window(s);
71017116
}
@@ -7490,8 +7505,11 @@ unmap_workspace(struct workspace *ws)
74907505
if (ws == NULL)
74917506
return;
74927507

7493-
TAILQ_FOREACH(w, &ws->winlist, entry)
7508+
TAILQ_FOREACH(w, &ws->winlist, entry) {
74947509
unmap_window(w);
7510+
if (ewmh_apply_flags(w, w->ewmh_flags & ~EWMH_F_FOCUSED))
7511+
ewmh_update_wm_state(w);
7512+
}
74957513
}
74967514

74977515
static void
@@ -10667,7 +10685,7 @@ draw_frame(struct ws_win *win)
1066710685
DNPRINTF(SWM_D_EVENT, "win %#x frame disabled\n", win->id);
1066810686
}
1066910687

10670-
if (win_focused(win)) {
10688+
if (FOCUSED(win)) {
1067110689
if (win_free(win))
1067210690
gcv[0] = getcolorpixel(win->s, (MAXIMIZED(win) ?
1067310691
SWM_S_COLOR_FOCUS_MAXIMIZED_FREE :
@@ -15538,7 +15556,7 @@ manage_window(xcb_window_t id, int spawn_pos, bool mapping)
1553815556
ewmh_get_wm_state(win);
1553915557

1554015558
/* Apply quirks. */
15541-
new_flags = win->ewmh_flags;
15559+
new_flags = win->ewmh_flags & ~EWMH_F_FOCUSED;
1554215560

1554315561
if (win->quirks & SWM_Q_FLOAT)
1554415562
new_flags |= EWMH_F_ABOVE;

0 commit comments

Comments
 (0)