Mercurial > minori
comparison dep/animone/src/win/x11.cc @ 277:a796e97cc86d
dep/animone: x11: correctly check for connection failure
if there's no X server running then the previous code segfaults(!)
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Mon, 22 Apr 2024 19:11:06 -0400 |
| parents | 1a6a5d3a94cd |
| children | c41c14ff8c67 |
comparison
equal
deleted
inserted
replaced
| 276:ec0a2b5493f8 | 277:a796e97cc86d |
|---|---|
| 9 #include <climits> | 9 #include <climits> |
| 10 #include <cstdint> | 10 #include <cstdint> |
| 11 #include <cstring> | 11 #include <cstring> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <memory> | |
| 14 | 15 |
| 15 #include <chrono> | 16 #include <chrono> |
| 16 | 17 |
| 17 #include <iostream> | 18 #include <iostream> |
| 18 | 19 |
| 154 bool EnumerateWindows(window_proc_t window_proc) { | 155 bool EnumerateWindows(window_proc_t window_proc) { |
| 155 if (!window_proc) | 156 if (!window_proc) |
| 156 return false; | 157 return false; |
| 157 | 158 |
| 158 xcb_connection_t* connection = ::xcb_connect(NULL, NULL); | 159 xcb_connection_t* connection = ::xcb_connect(NULL, NULL); |
| 159 if (!connection) | 160 if (xcb_connection_has_error(connection)) |
| 160 return false; | 161 return false; |
| 161 | 162 |
| 162 std::set<xcb_window_t> windows; | 163 std::set<xcb_window_t> windows; |
| 163 { | 164 { |
| 164 std::vector<xcb_window_t> roots; | 165 std::vector<xcb_window_t> roots; |
| 166 xcb_screen_iterator_t iter = ::xcb_setup_roots_iterator(::xcb_get_setup(connection)); | 167 xcb_screen_iterator_t iter = ::xcb_setup_roots_iterator(::xcb_get_setup(connection)); |
| 167 for (; iter.rem; ::xcb_screen_next(&iter)) | 168 for (; iter.rem; ::xcb_screen_next(&iter)) |
| 168 roots.push_back(iter.data->root); | 169 roots.push_back(iter.data->root); |
| 169 } | 170 } |
| 170 | 171 |
| 171 if (!GetAllTopLevelWindowsEWMH(connection, roots, windows)) | 172 //if (!GetAllTopLevelWindowsEWMH(connection, roots, windows)) |
| 172 GetAllTopLevelWindowsICCCM(connection, roots, windows); | 173 GetAllTopLevelWindowsICCCM(connection, roots, windows); |
| 173 } | 174 } |
| 174 | 175 |
| 175 struct WindowCookies { | 176 struct WindowCookies { |
| 176 xcb_window_t window; | 177 xcb_window_t window; |
