summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2021-08-19 14:21:16 +0200
committerKim Woelders <kim@woelders.dk>2021-08-21 20:47:34 +0200
commit2c01d2e1a4ed0b5739c45fde7d96bd5681dbc59b (patch)
treece96d653e397a4bad8034434a397e114a5ec744d
parent206839b33b4c9760c4336adf62ce9924be042de5 (diff)
Only update _NET_WM_STATE and _NET_WM_ALLOWED_ACTIONS when changed
Avoids some hint noise.
-rw-r--r--src/ewins.h2
-rw-r--r--src/ewmh.c145
2 files changed, 60 insertions, 87 deletions
diff --git a/src/ewins.h b/src/ewins.h
index e96258a4..8ec49d61 100644
--- a/src/ewins.h
+++ b/src/ewins.h
@@ -232,6 +232,8 @@ struct _ewin {
232 unsigned normal:1; 232 unsigned normal:1;
233 } b; 233 } b;
234 } type; 234 } type;
235 unsigned int current_state;
236 unsigned int current_actions;
235 } ewmh; 237 } ewmh;
236 struct { 238 struct {
237 signed char gravity; 239 signed char gravity;
diff --git a/src/ewmh.c b/src/ewmh.c
index f407d283..37aeb335 100644
--- a/src/ewmh.c
+++ b/src/ewmh.c
@@ -34,6 +34,15 @@
34#include "hints.h" 34#include "hints.h"
35#include "xprop.h" 35#include "xprop.h"
36 36
37#define ATOM_ADD_IF(atom, cond) \
38 do { \
39 if (cond) { \
40 atom_list[atom_count++] = atom; \
41 atom_mask |= 1U << atom_bit; \
42 } \
43 atom_bit++; \
44 } while(0)
45
37/* 46/*
38 * _NET_WM_MOVERESIZE client message actions 47 * _NET_WM_MOVERESIZE client message actions
39 */ 48 */
@@ -63,37 +72,6 @@
63#define OPSRC(src) (((src) == _NET_WM_SOURCE_USER) ? _NET_WM_SOURCE_USER : _NET_WM_SOURCE_APP) 72#define OPSRC(src) (((src) == _NET_WM_SOURCE_USER) ? _NET_WM_SOURCE_USER : _NET_WM_SOURCE_APP)
64 73
65/* 74/*
66 * Set/clear Atom in list
67 */
68static void
69atom_list_set(EX_Atom * atoms, int size, int *count, EX_Atom atom, int set)
70{
71 int i, n, in_list;
72
73 n = *count;
74
75 /* Check if atom is in list or not (+get index) */
76 for (i = 0; i < n; i++)
77 if (atoms[i] == atom)
78 break;
79 in_list = i < n;
80
81 if (set && !in_list)
82 {
83 /* Add it (if space left) */
84 if (n < size)
85 atoms[n++] = atom;
86 *count = n;
87 }
88 else if (!set && in_list)
89 {
90 /* Remove it */
91 atoms[i] = atoms[--n];
92 *count = n;
93 }
94}
95
96/*
97 * Initialize EWMH stuff 75 * Initialize EWMH stuff
98 */ 76 */
99void 77void
@@ -385,37 +363,30 @@ EWMH_SetWindowDesktop(const EWin * ewin)
385void 363void
386EWMH_SetWindowState(const EWin * ewin) 364EWMH_SetWindowState(const EWin * ewin)
387{ 365{
388 EX_Atom atom_list[64]; 366 EX_Atom atom_list[16];
389 int len = E_ARRAY_SIZE(atom_list);
390 int atom_count; 367 int atom_count;
368 unsigned int atom_mask, atom_bit;
391 369
392 atom_count = 0; 370 atom_count = 0;
393 atom_list_set(atom_list, len, &atom_count, EX_ATOM_NET_WM_STATE_MODAL, 371 atom_mask = atom_bit = 0;
394 ewin->state.modal); 372
395 atom_list_set(atom_list, len, &atom_count, EX_ATOM_NET_WM_STATE_STICKY, 373 ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_MODAL, ewin->state.modal);
396 EoIsSticky(ewin)); 374 ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_STICKY, EoIsSticky(ewin));
397 atom_list_set(atom_list, len, &atom_count, EX_ATOM_NET_WM_STATE_SHADED, 375 ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_SHADED, ewin->state.shaded);
398 ewin->state.shaded); 376 ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_SKIP_TASKBAR, ewin->props.skip_ext_task);
399 atom_list_set(atom_list, len, &atom_count, 377 ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_HIDDEN,
400 EX_ATOM_NET_WM_STATE_SKIP_TASKBAR, ewin->props.skip_ext_task); 378 ewin->state.iconified || ewin->state.shaded);
401 atom_list_set(atom_list, len, &atom_count, EX_ATOM_NET_WM_STATE_HIDDEN, 379 ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_MAXIMIZED_VERT, ewin->state.maximized_vert);
402 ewin->state.iconified || ewin->state.shaded); 380 ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_MAXIMIZED_HORZ, ewin->state.maximized_horz);
403 atom_list_set(atom_list, len, &atom_count, 381 ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_FULLSCREEN, ewin->state.fullscreen);
404 EX_ATOM_NET_WM_STATE_MAXIMIZED_VERT, 382 ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_SKIP_PAGER, ewin->props.skip_ext_pager);
405 ewin->state.maximized_vert); 383 ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_ABOVE, EoGetLayer(ewin) >= 6);
406 atom_list_set(atom_list, len, &atom_count, 384 ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_BELOW, EoGetLayer(ewin) <= 2);
407 EX_ATOM_NET_WM_STATE_MAXIMIZED_HORZ, 385 ATOM_ADD_IF(EX_ATOM_NET_WM_STATE_DEMANDS_ATTENTION, ewin->state.attention);
408 ewin->state.maximized_horz); 386
409 atom_list_set(atom_list, len, &atom_count, 387 if (ewin->ewmh.current_state == atom_mask)
410 EX_ATOM_NET_WM_STATE_FULLSCREEN, ewin->state.fullscreen); 388 return;
411 atom_list_set(atom_list, len, &atom_count, 389 ((EWin *) ewin)->ewmh.current_state = atom_mask;
412 EX_ATOM_NET_WM_STATE_SKIP_PAGER, ewin->props.skip_ext_pager);
413 atom_list_set(atom_list, len, &atom_count, EX_ATOM_NET_WM_STATE_ABOVE,
414 EoGetLayer(ewin) >= 6);
415 atom_list_set(atom_list, len, &atom_count, EX_ATOM_NET_WM_STATE_BELOW,
416 EoGetLayer(ewin) <= 2);
417 atom_list_set(atom_list, len, &atom_count,
418 EX_ATOM_NET_WM_STATE_DEMANDS_ATTENTION, ewin->state.attention);
419 390
420 ex_window_prop_atom_set(EwinGetClientXwin(ewin), EX_ATOM_NET_WM_STATE, 391 ex_window_prop_atom_set(EwinGetClientXwin(ewin), EX_ATOM_NET_WM_STATE,
421 atom_list, atom_count); 392 atom_list, atom_count);
@@ -757,37 +728,37 @@ EWMH_GetWindowStrut(EWin * ewin)
757void 728void
758EWMH_SetWindowActions(const EWin * ewin) 729EWMH_SetWindowActions(const EWin * ewin)
759{ 730{
760 EX_Atom aa[12]; 731 EX_Atom atom_list[16];
761 int num; 732 int atom_count;
733 unsigned int atom_mask, atom_bit;
762 734
763 num = 0; 735 atom_count = 0;
764 if (!ewin->state.inhibit_move) 736 atom_mask = atom_bit = 0;
765 aa[num++] = EX_ATOM_NET_WM_ACTION_MOVE; 737
766 if (!ewin->state.inhibit_resize) 738 ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_MOVE, !ewin->state.inhibit_move);
767 aa[num++] = EX_ATOM_NET_WM_ACTION_RESIZE; 739 ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_RESIZE, !ewin->state.inhibit_resize);
768 if (!ewin->state.inhibit_iconify) 740 ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_MINIMIZE, !ewin->state.inhibit_iconify);
769 aa[num++] = EX_ATOM_NET_WM_ACTION_MINIMIZE; 741 ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_SHADE, !ewin->state.inhibit_shade);
770 if (!ewin->state.inhibit_shade) 742 ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_STICK, !ewin->state.inhibit_stick);
771 aa[num++] = EX_ATOM_NET_WM_ACTION_SHADE; 743 ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_MAXIMIZE_HORZ,
772 if (!ewin->state.inhibit_stick) 744 !ewin->state.inhibit_max_hor);
773 aa[num++] = EX_ATOM_NET_WM_ACTION_STICK; 745 ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_MAXIMIZE_VERT,
774 if (!ewin->state.inhibit_max_hor) 746 !ewin->state.inhibit_max_ver);
775 aa[num++] = EX_ATOM_NET_WM_ACTION_MAXIMIZE_HORZ; 747 ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_FULLSCREEN,
776 if (!ewin->state.inhibit_max_ver) 748 !ewin->state.inhibit_fullscreeen);
777 aa[num++] = EX_ATOM_NET_WM_ACTION_MAXIMIZE_VERT; 749 ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_CHANGE_DESKTOP,
778 if (!ewin->state.inhibit_fullscreeen) 750 !ewin->state.inhibit_change_desk);
779 aa[num++] = EX_ATOM_NET_WM_ACTION_FULLSCREEN; 751 ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_CLOSE, !ewin->state.inhibit_close);
780 if (!ewin->state.inhibit_change_desk) 752 ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_ABOVE, !ewin->state.inhibit_stacking);
781 aa[num++] = EX_ATOM_NET_WM_ACTION_CHANGE_DESKTOP; 753 ATOM_ADD_IF(EX_ATOM_NET_WM_ACTION_BELOW, !ewin->state.inhibit_stacking);
782 if (!ewin->state.inhibit_close) 754
783 aa[num++] = EX_ATOM_NET_WM_ACTION_CLOSE; 755 if (ewin->ewmh.current_actions == atom_mask)
784 if (!ewin->state.inhibit_stacking) 756 return;
785 aa[num++] = EX_ATOM_NET_WM_ACTION_ABOVE; 757 ((EWin *) ewin)->ewmh.current_actions = atom_mask;
786 if (!ewin->state.inhibit_stacking)
787 aa[num++] = EX_ATOM_NET_WM_ACTION_BELOW;
788 758
789 ex_window_prop_atom_set(EwinGetClientXwin(ewin), 759 ex_window_prop_atom_set(EwinGetClientXwin(ewin),
790 EX_ATOM_NET_WM_ALLOWED_ACTIONS, aa, num); 760 EX_ATOM_NET_WM_ALLOWED_ACTIONS, atom_list,
761 atom_count);
791} 762}
792 763
793void 764void