Debian Codegraph @

src/atom.h

raw symbols SCIP
1 // SPDX-License-Identifier: MPL-2.0
2 // Copyright (c) Yuxuan Shui <[email protected]>
3
4 #pragma once
5 #include <string.h>
6 #include <xcb/xcb.h>
7
8 #include "utils/meta.h"
9
10 // clang-format off
11 // Splitted into 2 lists because of the limitation of our macros
12 #define ATOM_LIST1 \
13 _NET_WM_WINDOW_OPACITY, \
14 _NET_FRAME_EXTENTS, \
15 WM_STATE, \
16 _NET_WM_NAME, \
17 _NET_WM_PID, \
18 WM_NAME, \
19 WM_CLASS, \
20 WM_HINTS, \
21 WM_ICON_NAME, \
22 WM_TRANSIENT_FOR, \
23 WM_WINDOW_ROLE, \
24 WM_CLIENT_LEADER, \
25 WM_CLIENT_MACHINE, \
26 _NET_ACTIVE_WINDOW, \
27 _COMPTON_SHADOW, \
28 COMPTON_VERSION, \
29 _NET_WM_WINDOW_TYPE, \
30 _XROOTPMAP_ID, \
31 ESETROOT_PMAP_ID, \
32 _XSETROOT_ID
33
34 #define ATOM_LIST2 \
35 _NET_WM_WINDOW_TYPE_DESKTOP, \
36 _NET_WM_WINDOW_TYPE_DOCK, \
37 _NET_WM_WINDOW_TYPE_TOOLBAR, \
38 _NET_WM_WINDOW_TYPE_MENU, \
39 _NET_WM_WINDOW_TYPE_UTILITY, \
40 _NET_WM_WINDOW_TYPE_SPLASH, \
41 _NET_WM_WINDOW_TYPE_DIALOG, \
42 _NET_WM_WINDOW_TYPE_NORMAL, \
43 _NET_WM_WINDOW_TYPE_DROPDOWN_MENU, \
44 _NET_WM_WINDOW_TYPE_POPUP_MENU, \
45 _NET_WM_WINDOW_TYPE_TOOLTIP, \
46 _NET_WM_WINDOW_TYPE_NOTIFICATION, \
47 _NET_WM_WINDOW_TYPE_COMBO, \
48 _NET_WM_WINDOW_TYPE_DND, \
49 _NET_WM_STATE, \
50 _NET_WM_STATE_FULLSCREEN, \
51 _NET_WM_BYPASS_COMPOSITOR, \
52 UTF8_STRING, \
53 C_STRING
54 // clang-format on
55
56 #define ATOM_DEF(x) xcb_atom_t a##x
57
58 struct atom_entry;
59 struct atom {
60 LIST_APPLY(ATOM_DEF, SEP_COLON, ATOM_LIST1);
61 LIST_APPLY(ATOM_DEF, SEP_COLON, ATOM_LIST2);
62 };
63
64 /// Create a new atom object with a xcb connection. `struct atom` does not hold
65 /// a reference to the connection.
66 struct atom *init_atoms(xcb_connection_t *c);
67
68 xcb_atom_t get_atom(struct atom *a, const char *key, size_t keylen, xcb_connection_t *c);
69 static inline xcb_atom_t
70 get_atom_with_nul(struct atom *a, const char *key, xcb_connection_t *c) {
71 return get_atom(a, key, strlen(key), c);
72 }
73 xcb_atom_t get_atom_cached(struct atom *a, const char *key, size_t keylen);
74 static inline xcb_atom_t get_atom_cached_with_nul(struct atom *a, const char *key) {
75 return get_atom_cached(a, key, strlen(key));
76 }
77 const char *get_atom_name(struct atom *a, xcb_atom_t, xcb_connection_t *c);
78 const char *get_atom_name_cached(struct atom *a, xcb_atom_t atom);
79
80 void destroy_atoms(struct atom *a);
81
82 /// A mock atom object for unit testing. Successive calls to get_atom will return
83 /// consecutive integers as atoms, starting from 1. Calling get_atom_name with atoms
84 /// previously seen will result in the string that was used to create the atom; if
85 /// the atom was never returned by get_atom, it will abort.
86 struct atom *init_mock_atoms(void);