annotate dep/animia/src/win/x11.cc @ 236:4d461ef7d424

HUGE UPDATE: convert build system to autotools why? because cmake sucks :)
author Paper <mrpapersonic@gmail.com>
date Fri, 19 Jan 2024 00:24:02 -0500
parents 593108b3d555
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
157
18c8eb5d1edc x11: make it work
Paper <mrpapersonic@gmail.com>
parents: 156
diff changeset
1 #include "animia/win/x11.h"
18c8eb5d1edc x11: make it work
Paper <mrpapersonic@gmail.com>
parents: 156
diff changeset
2 #include "animia/win.h"
18c8eb5d1edc x11: make it work
Paper <mrpapersonic@gmail.com>
parents: 156
diff changeset
3 #include "animia.h"
18c8eb5d1edc x11: make it work
Paper <mrpapersonic@gmail.com>
parents: 156
diff changeset
4
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
5 #include <xcb/xcb.h>
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
6 #include <xcb/res.h>
158
80d6b28eb29f dep/animia: fix most X11 stuff
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
7
157
18c8eb5d1edc x11: make it work
Paper <mrpapersonic@gmail.com>
parents: 156
diff changeset
8 #include <cstdint>
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
9 #include <climits>
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
10 #include <cstring>
157
18c8eb5d1edc x11: make it work
Paper <mrpapersonic@gmail.com>
parents: 156
diff changeset
11 #include <string>
158
80d6b28eb29f dep/animia: fix most X11 stuff
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
12 #include <set>
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
14 #include <chrono>
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
15
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
16 #include <iostream>
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
17
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
18 static size_t str_nlen(const char* s, size_t len) {
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
19 size_t i = 0;
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
20 for (; i < len && s[i]; i++);
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
21 return i;
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
22 }
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
23
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24 namespace animia::internal::x11 {
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
26 static void GetWindowPID(xcb_connection_t* connection, const std::vector<xcb_window_t>& windows, std::unordered_map<xcb_window_t, pid_t>& result) {
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
27 std::vector<xcb_res_query_client_ids_cookie_t> cookies;
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
28 cookies.reserve(windows.size());
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
29
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
30 for (const auto& window : windows) {
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
31 xcb_res_client_id_spec_t spec = {
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
32 .client = window,
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
33 .mask = XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
34 };
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
35
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
36 cookies.push_back(::xcb_res_query_client_ids(connection, 1, &spec));
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
37 }
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
38
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
39 for (size_t i = 0; i < cookies.size(); i++) {
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
40 xcb_res_query_client_ids_reply_t* reply = ::xcb_res_query_client_ids_reply(connection, cookies.at(i), NULL);
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
41
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
42 xcb_res_client_id_value_iterator_t it = xcb_res_query_client_ids_ids_iterator(reply);
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
43 for (; it.rem; xcb_res_client_id_value_next(&it)) {
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
44 if (it.data->spec.mask & XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID) {
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
45 result[windows.at(i)] = *::xcb_res_client_id_value_value(it.data);
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
46 continue;
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
47 }
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
48 }
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
49 }
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
50 }
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
51
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
52 static bool GetAllTopLevelWindowsEWMH(xcb_connection_t* connection, const std::vector<xcb_window_t>& roots, std::set<xcb_window_t>& result) {
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
53 const xcb_atom_t Atom__NET_CLIENT_LIST = [connection]{
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
54 static constexpr std::string_view name = "_NET_CLIENT_LIST";
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
55 xcb_intern_atom_cookie_t cookie = ::xcb_intern_atom(connection, true, name.size(), name.data());
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
56 xcb_intern_atom_reply_t* reply = ::xcb_intern_atom_reply(connection, cookie, NULL);
166
54c5d80a737e dep/animia: add libutil method
paper@DavesDouble.local
parents: 158
diff changeset
57
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
58 xcb_atom_t atom = reply->atom;
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
59 free(reply);
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
60 return atom;
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
61 }();
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
62 if (Atom__NET_CLIENT_LIST == XCB_ATOM_NONE)
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
63 return false; // BTFO
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
64
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
65 bool success = false;
213
58e81b42a0d6 dep/animia: win/x11: find toplevels WAY faster
Paper <mrpapersonic@gmail.com>
parents: 199
diff changeset
66
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
67 std::vector<xcb_get_property_cookie_t> cookies;
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
68 cookies.reserve(roots.size());
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
69
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
70 for (const auto& root : roots)
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
71 cookies.push_back(::xcb_get_property(connection, 0, root, Atom__NET_CLIENT_LIST, XCB_ATOM_ANY, 0L, UINT_MAX));
213
58e81b42a0d6 dep/animia: win/x11: find toplevels WAY faster
Paper <mrpapersonic@gmail.com>
parents: 199
diff changeset
72
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
73 for (const auto& cookie : cookies) {
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
74 xcb_get_property_reply_t* reply = ::xcb_get_property_reply(connection, cookie, NULL);
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
75 if (reply) {
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
76 xcb_window_t* value = reinterpret_cast<xcb_window_t*>(::xcb_get_property_value(reply));
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
77 int len = ::xcb_get_property_value_length(reply);
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
78
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
79 for (size_t i = 0; i < len; i++)
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
80 result.insert(value[i]);
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
81 success = true;
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
82 }
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
83 free(reply);
213
58e81b42a0d6 dep/animia: win/x11: find toplevels WAY faster
Paper <mrpapersonic@gmail.com>
parents: 199
diff changeset
84 }
58e81b42a0d6 dep/animia: win/x11: find toplevels WAY faster
Paper <mrpapersonic@gmail.com>
parents: 199
diff changeset
85
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
86 return success;
213
58e81b42a0d6 dep/animia: win/x11: find toplevels WAY faster
Paper <mrpapersonic@gmail.com>
parents: 199
diff changeset
87 }
58e81b42a0d6 dep/animia: win/x11: find toplevels WAY faster
Paper <mrpapersonic@gmail.com>
parents: 199
diff changeset
88
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
89 /* I have no idea why this works. */
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
90 static bool WalkWindows(xcb_connection_t* connection, const std::vector<xcb_window_t>& roots, std::set<xcb_window_t>& result) {
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
91 /* move this somewhere */
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
92 xcb_atom_t Atom_WM_STATE = [connection]{
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
93 static constexpr std::string_view name = "WM_STATE";
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
94 xcb_intern_atom_cookie_t cookie = ::xcb_intern_atom(connection, true, name.size(), name.data());
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
95 xcb_intern_atom_reply_t* reply = ::xcb_intern_atom_reply(connection, cookie, NULL);
213
58e81b42a0d6 dep/animia: win/x11: find toplevels WAY faster
Paper <mrpapersonic@gmail.com>
parents: 199
diff changeset
96
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
97 xcb_atom_t atom = reply->atom;
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
98 free(reply);
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
99 return atom;
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
100 }();
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
101 if (Atom_WM_STATE == XCB_ATOM_NONE)
213
58e81b42a0d6 dep/animia: win/x11: find toplevels WAY faster
Paper <mrpapersonic@gmail.com>
parents: 199
diff changeset
102 return false;
58e81b42a0d6 dep/animia: win/x11: find toplevels WAY faster
Paper <mrpapersonic@gmail.com>
parents: 199
diff changeset
103
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
104 std::vector<xcb_query_tree_cookie_t> cookies;
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
105 cookies.reserve(roots.size());
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
106
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
107 for (const auto& root : roots)
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
108 cookies.push_back(::xcb_query_tree(connection, root));
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
109
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
110 for (const auto& cookie : cookies) {
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
111 xcb_query_tree_reply_t* reply = ::xcb_query_tree_reply(connection, cookie, NULL);
213
58e81b42a0d6 dep/animia: win/x11: find toplevels WAY faster
Paper <mrpapersonic@gmail.com>
parents: 199
diff changeset
112
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
113 std::vector<xcb_window_t> windows = [reply]{
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
114 xcb_window_t* windows = ::xcb_query_tree_children(reply);
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
115 int len = ::xcb_query_tree_children_length(reply);
213
58e81b42a0d6 dep/animia: win/x11: find toplevels WAY faster
Paper <mrpapersonic@gmail.com>
parents: 199
diff changeset
116
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
117 std::vector<xcb_window_t> w;
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
118 w.reserve(len);
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
119
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
120 for (int i = 0; i < len; i++)
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
121 w.push_back(windows[i]);
213
58e81b42a0d6 dep/animia: win/x11: find toplevels WAY faster
Paper <mrpapersonic@gmail.com>
parents: 199
diff changeset
122
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
123 return w;
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
124 }();
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
125
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
126 std::vector<xcb_get_property_cookie_t> state_property_cookies;
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
127 state_property_cookies.reserve(windows.size());
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
128
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
129 for (int i = 0; i < windows.size(); i++)
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
130 state_property_cookies.push_back(::xcb_get_property(connection, 0, windows[i], Atom_WM_STATE, Atom_WM_STATE, 0, 0));
166
54c5d80a737e dep/animia: add libutil method
paper@DavesDouble.local
parents: 158
diff changeset
131
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
132 for (size_t i = 0; i < state_property_cookies.size(); i++) {
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
133 xcb_generic_error_t* err = NULL;
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
134 xcb_get_property_reply_t* reply = ::xcb_get_property_reply(connection, state_property_cookies.at(i), &err);
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
135
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
136 if (reply->format || reply->type || reply->length) {
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
137 result.insert(windows[i]);
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
138 free(reply);
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
139 continue;
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
140 }
166
54c5d80a737e dep/animia: add libutil method
paper@DavesDouble.local
parents: 158
diff changeset
141
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
142 free(reply);
213
58e81b42a0d6 dep/animia: win/x11: find toplevels WAY faster
Paper <mrpapersonic@gmail.com>
parents: 199
diff changeset
143 }
58e81b42a0d6 dep/animia: win/x11: find toplevels WAY faster
Paper <mrpapersonic@gmail.com>
parents: 199
diff changeset
144
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
145 if (WalkWindows(connection, windows, result))
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
146 continue;
166
54c5d80a737e dep/animia: add libutil method
paper@DavesDouble.local
parents: 158
diff changeset
147 }
54c5d80a737e dep/animia: add libutil method
paper@DavesDouble.local
parents: 158
diff changeset
148
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
149 return false;
166
54c5d80a737e dep/animia: add libutil method
paper@DavesDouble.local
parents: 158
diff changeset
150 }
54c5d80a737e dep/animia: add libutil method
paper@DavesDouble.local
parents: 158
diff changeset
151
198
bc1ae1810855 dep/animia: switch from using classes to global functions
Paper <mrpapersonic@gmail.com>
parents: 191
diff changeset
152 bool EnumerateWindows(window_proc_t window_proc) {
158
80d6b28eb29f dep/animia: fix most X11 stuff
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
153 if (!window_proc)
80d6b28eb29f dep/animia: fix most X11 stuff
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
154 return false;
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
155
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
156 xcb_connection_t* connection = ::xcb_connect(NULL, NULL);
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
157 if (!connection)
166
54c5d80a737e dep/animia: add libutil method
paper@DavesDouble.local
parents: 158
diff changeset
158 return false;
54c5d80a737e dep/animia: add libutil method
paper@DavesDouble.local
parents: 158
diff changeset
159
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
160 std::set<xcb_window_t> windows;
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
161 {
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
162 std::vector<xcb_window_t> roots;
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
163 {
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
164 xcb_screen_iterator_t iter = ::xcb_setup_roots_iterator(xcb_get_setup(connection));
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
165 for (; iter.rem; ::xcb_screen_next(&iter))
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
166 roots.push_back(iter.data->root);
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
167 }
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
168
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
169
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
170 if (!GetAllTopLevelWindowsEWMH(connection, roots, windows))
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
171 WalkWindows(connection, roots, windows);
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
172 }
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
173
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
174 std::vector<xcb_get_property_cookie_t> class_property_cookies;
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
175 std::vector<xcb_get_property_cookie_t> name_property_cookies;
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
176 std::vector<xcb_get_property_cookie_t> pid_property_cookies;
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
177 class_property_cookies.reserve(windows.size());
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
178 name_property_cookies.reserve(windows.size());
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
179 pid_property_cookies.reserve(windows.size());
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
180
166
54c5d80a737e dep/animia: add libutil method
paper@DavesDouble.local
parents: 158
diff changeset
181 for (const auto& window : windows) {
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
182 class_property_cookies.push_back(::xcb_get_property(connection, 0, window, XCB_ATOM_WM_CLASS, XCB_ATOM_STRING, 0L, 2048L));
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
183 name_property_cookies.push_back(::xcb_get_property(connection, 0, window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 0L, UINT_MAX));
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
184 pid_property_cookies.push_back(::xcb_get_property(connection, 0, window, XCB_ATOM_WM_NAME, XCB_ATOM_CARDINAL, 0L, 1L));
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
185 }
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
186
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
187 size_t i = 0;
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
188 for (const auto& window : windows) {
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
189 Window win = {0};
158
80d6b28eb29f dep/animia: fix most X11 stuff
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
190 win.id = window;
157
18c8eb5d1edc x11: make it work
Paper <mrpapersonic@gmail.com>
parents: 156
diff changeset
191 {
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
192 xcb_get_property_reply_t* reply = ::xcb_get_property_reply(connection, class_property_cookies.at(i), NULL);
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
193 if (reply && reply->format == 8) {
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
194 const char* data = reinterpret_cast<char*>(::xcb_get_property_value(reply));
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
195 const int data_len = ::xcb_get_property_value_length(reply);
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
196
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
197 int instance_len = str_nlen(data, data_len);
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
198 const char* class_name = data + instance_len + 1;
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
199
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
200 win.class_name = std::string(class_name, str_nlen(class_name, data_len - (instance_len + 1)));
157
18c8eb5d1edc x11: make it work
Paper <mrpapersonic@gmail.com>
parents: 156
diff changeset
201 }
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
202 free(reply);
157
18c8eb5d1edc x11: make it work
Paper <mrpapersonic@gmail.com>
parents: 156
diff changeset
203 }
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
204 {
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
205 xcb_get_property_reply_t* reply = ::xcb_get_property_reply(connection, name_property_cookies.at(i), NULL);
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
206 if (reply) {
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
207 const char* data = reinterpret_cast<char*>(::xcb_get_property_value(reply));
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
208 int len = ::xcb_get_property_value_length(reply);
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
209
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
210 win.text = std::string((char*)data, len);
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
211 }
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
212 free(reply);
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
213 }
235
593108b3d555 dep/animia: x11: finalize xcb conversion
Paper <paper@paper.us.eu.org>
parents: 234
diff changeset
214 Process proc = {0};
593108b3d555 dep/animia: x11: finalize xcb conversion
Paper <paper@paper.us.eu.org>
parents: 234
diff changeset
215 {
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
216 xcb_get_property_reply_t* reply = ::xcb_get_property_reply(connection, pid_property_cookies.at(i), NULL);
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
217 if (reply)
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 235
diff changeset
218 proc.pid = *reinterpret_cast<uint32_t*>(::xcb_get_property_value(reply));
235
593108b3d555 dep/animia: x11: finalize xcb conversion
Paper <paper@paper.us.eu.org>
parents: 234
diff changeset
219
593108b3d555 dep/animia: x11: finalize xcb conversion
Paper <paper@paper.us.eu.org>
parents: 234
diff changeset
220 free(reply);
593108b3d555 dep/animia: x11: finalize xcb conversion
Paper <paper@paper.us.eu.org>
parents: 234
diff changeset
221 }
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
222 if (!window_proc(proc, win)) {
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
223 ::xcb_disconnect(connection);
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
224 return false;
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
225 }
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
226 i++;
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
227 }
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
228
234
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
229 ::xcb_disconnect(connection);
8ccf0302afb1 dep/animia: convert xlib code to xcb
Paper <mrpapersonic@gmail.com>
parents: 214
diff changeset
230
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
231 return true;
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
232 }
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
233
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
234 }