Mercurial > minori
comparison dep/animone/src/win/x11.cc @ 266:1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
apparently I broke these, and even now the x11 code *still* doesn't want
to work correctly (at least on FreeBSD). half of the PID response codes
are just 0 or the PID for the X server itself... wtf?
maybe dwm just doesn't support the XRes extension, or I'm just stupid.
i don't know.
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Thu, 11 Apr 2024 22:05:41 -0400 |
parents | 862d0d8619f6 |
children | a796e97cc86d |
comparison
equal
deleted
inserted
replaced
265:ff0b2052b234 | 266:1a6a5d3a94cd |
---|---|
51 | 51 |
52 for (const auto& cookie : cookies) { | 52 for (const auto& cookie : cookies) { |
53 std::unique_ptr<xcb_get_property_reply_t> reply(::xcb_get_property_reply(connection, cookie, NULL)); | 53 std::unique_ptr<xcb_get_property_reply_t> reply(::xcb_get_property_reply(connection, cookie, NULL)); |
54 | 54 |
55 if (reply) { | 55 if (reply) { |
56 xcb_window_t* value = reinterpret_cast<xcb_window_t*>(::xcb_get_property_value(reply)); | 56 xcb_window_t* value = reinterpret_cast<xcb_window_t*>(::xcb_get_property_value(reply.get())); |
57 int len = ::xcb_get_property_value_length(reply); | 57 int len = ::xcb_get_property_value_length(reply.get()); |
58 | 58 |
59 for (size_t i = 0; i < len; i++) | 59 for (size_t i = 0; i < len; i++) |
60 result.insert(value[i]); | 60 result.insert(value[i]); |
61 | 61 |
62 success |= true; | 62 success |= true; |
72 * 3. If that failed... return the original window | 72 * 3. If that failed... return the original window |
73 */ | 73 */ |
74 static bool WalkWindows(xcb_connection_t* connection, int depth, xcb_atom_t Atom_WM_STATE, const xcb_window_t* windows, | 74 static bool WalkWindows(xcb_connection_t* connection, int depth, xcb_atom_t Atom_WM_STATE, const xcb_window_t* windows, |
75 int windows_len, std::set<xcb_window_t>& result) { | 75 int windows_len, std::set<xcb_window_t>& result) { |
76 /* The depth we should start returning at. */ | 76 /* The depth we should start returning at. */ |
77 static constexpr int CUTOFF = 2; | 77 static constexpr int CUTOFF = 1; |
78 | 78 |
79 bool success = false; | 79 bool success = false; |
80 | 80 |
81 std::vector<xcb_query_tree_cookie_t> cookies; | 81 std::vector<xcb_query_tree_cookie_t> cookies; |
82 cookies.reserve(windows_len); | 82 cookies.reserve(windows_len); |
85 cookies.push_back(::xcb_query_tree(connection, windows[i])); | 85 cookies.push_back(::xcb_query_tree(connection, windows[i])); |
86 | 86 |
87 for (const auto& cookie : cookies) { | 87 for (const auto& cookie : cookies) { |
88 std::unique_ptr<xcb_query_tree_reply_t> query_tree_reply(::xcb_query_tree_reply(connection, cookie, NULL)); | 88 std::unique_ptr<xcb_query_tree_reply_t> query_tree_reply(::xcb_query_tree_reply(connection, cookie, NULL)); |
89 | 89 |
90 xcb_window_t* tree_children = ::xcb_query_tree_children(query_tree_reply); | 90 xcb_window_t* tree_children = ::xcb_query_tree_children(query_tree_reply.get()); |
91 int tree_children_len = ::xcb_query_tree_children_length(query_tree_reply); | 91 int tree_children_len = ::xcb_query_tree_children_length(query_tree_reply.get()); |
92 | 92 |
93 std::vector<xcb_get_property_cookie_t> state_property_cookies; | 93 std::vector<xcb_get_property_cookie_t> state_property_cookies; |
94 state_property_cookies.reserve(tree_children_len); | 94 state_property_cookies.reserve(tree_children_len); |
95 | 95 |
96 for (int i = 0; i < tree_children_len; i++) | 96 for (int i = 0; i < tree_children_len; i++) |
161 | 161 |
162 std::set<xcb_window_t> windows; | 162 std::set<xcb_window_t> windows; |
163 { | 163 { |
164 std::vector<xcb_window_t> roots; | 164 std::vector<xcb_window_t> roots; |
165 { | 165 { |
166 xcb_screen_iterator_t iter = ::xcb_setup_roots_iterator(xcb_get_setup(connection)); | 166 xcb_screen_iterator_t iter = ::xcb_setup_roots_iterator(::xcb_get_setup(connection)); |
167 for (; iter.rem; ::xcb_screen_next(&iter)) | 167 for (; iter.rem; ::xcb_screen_next(&iter)) |
168 roots.push_back(iter.data->root); | 168 roots.push_back(iter.data->root); |
169 } | 169 } |
170 | 170 |
171 if (!GetAllTopLevelWindowsEWMH(connection, roots, windows)) | 171 if (!GetAllTopLevelWindowsEWMH(connection, roots, windows)) |
200 /* Class name */ | 200 /* Class name */ |
201 std::unique_ptr<xcb_get_property_reply_t> reply( | 201 std::unique_ptr<xcb_get_property_reply_t> reply( |
202 ::xcb_get_property_reply(connection, window_cookie.class_property_cookie, NULL)); | 202 ::xcb_get_property_reply(connection, window_cookie.class_property_cookie, NULL)); |
203 | 203 |
204 if (reply && reply->format == 8) { | 204 if (reply && reply->format == 8) { |
205 const char* data = reinterpret_cast<char*>(::xcb_get_property_value(reply.get())); | 205 const char* data = reinterpret_cast<const char*>(::xcb_get_property_value(reply.get())); |
206 const int data_len = ::xcb_get_property_value_length(reply.get()); | 206 const int data_len = ::xcb_get_property_value_length(reply.get()); |
207 | 207 |
208 int instance_len = str_nlen(data, data_len); | 208 int instance_len = str_nlen(data, data_len); |
209 const char* class_name = data + instance_len + 1; | 209 const char* class_name = data + instance_len + 1; |
210 | 210 |
215 /* Title text */ | 215 /* Title text */ |
216 std::unique_ptr<xcb_get_property_reply_t> reply( | 216 std::unique_ptr<xcb_get_property_reply_t> reply( |
217 ::xcb_get_property_reply(connection, window_cookie.name_property_cookie, NULL)); | 217 ::xcb_get_property_reply(connection, window_cookie.name_property_cookie, NULL)); |
218 | 218 |
219 if (reply) { | 219 if (reply) { |
220 const char* data = reinterpret_cast<char*>(::xcb_get_property_value(reply.get())); | 220 const char* data = reinterpret_cast<const char*>(::xcb_get_property_value(reply.get())); |
221 int len = ::xcb_get_property_value_length(reply.get()); | 221 int len = ::xcb_get_property_value_length(reply.get()); |
222 | 222 |
223 win.text = std::string(data, len); | 223 win.text = std::string(data, len); |
224 } | 224 } |
225 } | 225 } |
228 /* PID */ | 228 /* PID */ |
229 std::unique_ptr<xcb_res_query_client_ids_reply_t> reply( | 229 std::unique_ptr<xcb_res_query_client_ids_reply_t> reply( |
230 ::xcb_res_query_client_ids_reply(connection, window_cookie.pid_property_cookie, NULL)); | 230 ::xcb_res_query_client_ids_reply(connection, window_cookie.pid_property_cookie, NULL)); |
231 | 231 |
232 if (reply) { | 232 if (reply) { |
233 xcb_res_client_id_value_iterator_t it = ::xcb_res_query_client_ids_ids_iterator(reply); | 233 xcb_res_client_id_value_iterator_t it = ::xcb_res_query_client_ids_ids_iterator(reply.get()); |
234 for (; it.rem; ::xcb_res_client_id_value_next(&it)) { | 234 for (; it.rem; ::xcb_res_client_id_value_next(&it)) { |
235 if (it.data->spec.mask & XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID) { | 235 if (it.data->spec.mask & XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID) { |
236 proc.pid = *reinterpret_cast<uint32_t*>(::xcb_res_client_id_value_value(it.data)); | 236 proc.pid = *::xcb_res_client_id_value_value(it.data); |
237 fd::GetProcessName(proc.pid, proc.name); /* fill this in if we can */ | 237 GetProcessName(proc.pid, proc.name); /* fill this in if we can */ |
238 break; | 238 break; |
239 } | 239 } |
240 } | 240 } |
241 } | 241 } |
242 } | 242 } |
243 | 243 |
244 std::cout << "got window: " << win.id << "\n" | |
245 << "class name: " << win.class_name << "\n" | |
246 << "title: " << win.text << "\n" | |
247 << "PID: " << proc.pid << "\n" | |
248 << "executable: " << proc.name << "\n" << std::endl; | |
249 | |
244 if (!window_proc(proc, win)) { | 250 if (!window_proc(proc, win)) { |
245 ::xcb_disconnect(connection); | 251 ::xcb_disconnect(connection); |
246 return false; | 252 return false; |
247 } | 253 } |
248 } | 254 } |