Only update _NET_WM_STATE and _NET_WM_ALLOWED_ACTIONS when changed

Avoids some hint noise.
This commit is contained in:
Kim Woelders 2021-08-19 14:21:16 +02:00
parent 206839b33b
commit 2c01d2e1a4
2 changed files with 60 additions and 87 deletions

View File

@ -232,6 +232,8 @@ struct _ewin {
unsigned normal:1; unsigned normal:1;
} b; } b;
} type; } type;
unsigned int current_state;
unsigned int current_actions;
} ewmh; } ewmh;
struct { struct {
signed char gravity; signed char gravity;

View File

@ -34,6 +34,15 @@
#include "hints.h" #include "hints.h"
#include "xprop.h" #include "xprop.h"
#define ATOM_ADD_IF(atom, cond) \
do { \
if (cond) { \
atom_list[atom_count++] = atom; \
atom_mask |= 1U << atom_bit; \
} \
atom_bit++; \
} while(0)
/* /*
* _NET_WM_MOVERESIZE client message actions * _NET_WM_MOVERESIZE client message actions
*/ */
@ -62,37 +71,6 @@
#define OPSRC(src) (((src) == _NET_WM_SOURCE_USER) ? _NET_WM_SOURCE_USER : _NET_WM_SOURCE_APP) #define OPSRC(src) (((src) == _NET_WM_SOURCE_USER) ? _NET_WM_SOURCE_USER : _NET_WM_SOURCE_APP)
/*
* Set/clear Atom in list
*/
static void
atom_list_set(EX_Atom * atoms, int size, int *count, EX_Atom atom, int set)
{
int i, n, in_list;
n = *count;
/* Check if atom is in list or not (+get index) */
for (i = 0; i < n; i++)
if (atoms[i] == atom)
break;
in_list = i < n;
if (set && !in_list)
{
/* Add it (if space left) */
if (n < size)
atoms[n++] = atom;
*count = n;
}
else if (!set && in_list)
{
/* Remove it */
atoms[i] = atoms[--n];
*count = n;
}
}
/* /*
* Initialize EWMH stuff * Initialize EWMH stuff
*/ */
@ -385,37 +363,30 @@ EWMH_SetWindowDesktop(const EWin * ewin)
void void
EWMH_SetWindowState(const EWin * ewin) EWMH_SetWindowState(const EWin * ewin)
{ {
EX_Atom atom_list[64]; EX_Atom atom_list[16];
int len = E_ARRAY_SIZE(atom_list);
int atom_count; int atom_count;
unsigned int atom_mask, atom_bit;
atom_count = 0; atom_count = 0;
atom_list_set(atom_list, len, &atom_count, EX_ATOM_NET_WM_STATE_MODAL, atom_mask = atom_bit = 0;
ewin->state.modal);
atom_list_set(atom_list, len, &atom_count, EX_ATOM_NET_WM_STATE_STICKY, ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_MODAL, ewin->state.modal);
EoIsSticky(ewin)); ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_STICKY, EoIsSticky(ewin));
atom_list_set(atom_list, len, &atom_count, EX_ATOM_NET_WM_STATE_SHADED, ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_SHADED, ewin->state.shaded);
ewin->state.shaded); ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_SKIP_TASKBAR, ewin->props.skip_ext_task);
atom_list_set(atom_list, len, &atom_count, ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_HIDDEN,
EX_ATOM_NET_WM_STATE_SKIP_TASKBAR, ewin->props.skip_ext_task); ewin->state.iconified || ewin->state.shaded);
atom_list_set(atom_list, len, &atom_count, EX_ATOM_NET_WM_STATE_HIDDEN, ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_MAXIMIZED_VERT, ewin->state.maximized_vert);
ewin->state.iconified || ewin->state.shaded); ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_MAXIMIZED_HORZ, ewin->state.maximized_horz);
atom_list_set(atom_list, len, &atom_count, ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_FULLSCREEN, ewin->state.fullscreen);
EX_ATOM_NET_WM_STATE_MAXIMIZED_VERT, ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_SKIP_PAGER, ewin->props.skip_ext_pager);
ewin->state.maximized_vert); ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_ABOVE, EoGetLayer(ewin) >= 6);
atom_list_set(atom_list, len, &atom_count, ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_BELOW, EoGetLayer(ewin) <= 2);
EX_ATOM_NET_WM_STATE_MAXIMIZED_HORZ, ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_DEMANDS_ATTENTION, ewin->state.attention);
ewin->state.maximized_horz);
atom_list_set(atom_list, len, &atom_count, if (ewin->ewmh.current_state == atom_mask)
EX_ATOM_NET_WM_STATE_FULLSCREEN, ewin->state.fullscreen); return;
atom_list_set(atom_list, len, &atom_count, ((EWin *) ewin)->ewmh.current_state = atom_mask;
EX_ATOM_NET_WM_STATE_SKIP_PAGER, ewin->props.skip_ext_pager);
atom_list_set(atom_list, len, &atom_count, EX_ATOM_NET_WM_STATE_ABOVE,
EoGetLayer(ewin) >= 6);
atom_list_set(atom_list, len, &atom_count, EX_ATOM_NET_WM_STATE_BELOW,
EoGetLayer(ewin) <= 2);
atom_list_set(atom_list, len, &atom_count,
EX_ATOM_NET_WM_STATE_DEMANDS_ATTENTION, ewin->state.attention);
ex_window_prop_atom_set(EwinGetClientXwin(ewin), EX_ATOM_NET_WM_STATE, ex_window_prop_atom_set(EwinGetClientXwin(ewin), EX_ATOM_NET_WM_STATE,
atom_list, atom_count); atom_list, atom_count);
@ -757,37 +728,37 @@ EWMH_GetWindowStrut(EWin * ewin)
void void
EWMH_SetWindowActions(const EWin * ewin) EWMH_SetWindowActions(const EWin * ewin)
{ {
EX_Atom aa[12]; EX_Atom atom_list[16];
int num; int atom_count;
unsigned int atom_mask, atom_bit;
num = 0; atom_count = 0;
if (!ewin->state.inhibit_move) atom_mask = atom_bit = 0;
aa[num++] = EX_ATOM_NET_WM_ACTION_MOVE;
if (!ewin->state.inhibit_resize) ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_MOVE, !ewin->state.inhibit_move);
aa[num++] = EX_ATOM_NET_WM_ACTION_RESIZE; ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_RESIZE, !ewin->state.inhibit_resize);
if (!ewin->state.inhibit_iconify) ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_MINIMIZE, !ewin->state.inhibit_iconify);
aa[num++] = EX_ATOM_NET_WM_ACTION_MINIMIZE; ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_SHADE, !ewin->state.inhibit_shade);
if (!ewin->state.inhibit_shade) ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_STICK, !ewin->state.inhibit_stick);
aa[num++] = EX_ATOM_NET_WM_ACTION_SHADE; ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_MAXIMIZE_HORZ,
if (!ewin->state.inhibit_stick) !ewin->state.inhibit_max_hor);
aa[num++] = EX_ATOM_NET_WM_ACTION_STICK; ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_MAXIMIZE_VERT,
if (!ewin->state.inhibit_max_hor) !ewin->state.inhibit_max_ver);
aa[num++] = EX_ATOM_NET_WM_ACTION_MAXIMIZE_HORZ; ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_FULLSCREEN,
if (!ewin->state.inhibit_max_ver) !ewin->state.inhibit_fullscreeen);
aa[num++] = EX_ATOM_NET_WM_ACTION_MAXIMIZE_VERT; ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_CHANGE_DESKTOP,
if (!ewin->state.inhibit_fullscreeen) !ewin->state.inhibit_change_desk);
aa[num++] = EX_ATOM_NET_WM_ACTION_FULLSCREEN; ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_CLOSE, !ewin->state.inhibit_close);
if (!ewin->state.inhibit_change_desk) ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_ABOVE, !ewin->state.inhibit_stacking);
aa[num++] = EX_ATOM_NET_WM_ACTION_CHANGE_DESKTOP; ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_BELOW, !ewin->state.inhibit_stacking);
if (!ewin->state.inhibit_close)
aa[num++] = EX_ATOM_NET_WM_ACTION_CLOSE; if (ewin->ewmh.current_actions == atom_mask)
if (!ewin->state.inhibit_stacking) return;
aa[num++] = EX_ATOM_NET_WM_ACTION_ABOVE; ((EWin *) ewin)->ewmh.current_actions = atom_mask;
if (!ewin->state.inhibit_stacking)
aa[num++] = EX_ATOM_NET_WM_ACTION_BELOW;
ex_window_prop_atom_set(EwinGetClientXwin(ewin), ex_window_prop_atom_set(EwinGetClientXwin(ewin),
EX_ATOM_NET_WM_ALLOWED_ACTIONS, aa, num); EX_ATOM_NET_WM_ALLOWED_ACTIONS, atom_list,
atom_count);
} }
void void