启动时扫描已有窗口并管理
This commit is contained in:
@@ -185,8 +185,9 @@ window_list_t *scan_window_list(void) {
|
||||
xcb_window_t *list = xcb_query_tree_children(tree_reply);
|
||||
int len = xcb_query_tree_children_length(tree_reply);
|
||||
|
||||
uint32_t count = 0;
|
||||
xcb_window_t temp_window_array[len];
|
||||
uint32_t normal_count = 0, transient_count = 0;
|
||||
xcb_window_t normal_window_array[len];
|
||||
xcb_window_t transient_window_array[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
xcb_window_t window = list[i];
|
||||
|
||||
@@ -199,34 +200,47 @@ window_list_t *scan_window_list(void) {
|
||||
uint8_t override_redirect = attribute_reply->override_redirect;
|
||||
uint8_t map_state = attribute_reply->map_state;
|
||||
free(attribute_reply);
|
||||
if (override_redirect || map_state != XCB_MAP_STATE_VIEWABLE) continue;
|
||||
if (!(map_state == XCB_MAP_STATE_VIEWABLE ||
|
||||
get_window_state(window) == wm_state_iconic)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
xcb_window_t transient_for = XCB_NONE;
|
||||
xcb_get_property_cookie_t p_cookie =
|
||||
xcb_icccm_get_wm_transient_for(conn, window);
|
||||
xcb_icccm_get_wm_transient_for_reply(conn, p_cookie, &transient_for, NULL);
|
||||
if (transient_for != XCB_NONE) continue;
|
||||
|
||||
temp_window_array[count] = window;
|
||||
count++;
|
||||
xcb_window_t transient_for = get_transient_window_for(window);
|
||||
if (transient_for) {
|
||||
transient_window_array[transient_count++] = window;
|
||||
} else if (!override_redirect) {
|
||||
normal_window_array[normal_count++] = window;
|
||||
}
|
||||
}
|
||||
free(tree_reply);
|
||||
|
||||
if (!count) return NULL;
|
||||
|
||||
xcb_window_t *window_list = ecalloc(count, sizeof(xcb_window_t));
|
||||
for (uint32_t i = 0; i < count; i++) window_list[i] = temp_window_array[i];
|
||||
if ((!normal_count) && (!transient_count)) return NULL;
|
||||
|
||||
window_list_t *r = ecalloc(1, sizeof(window_list_t));
|
||||
r->count = count;
|
||||
r->list = window_list;
|
||||
r->normal_count = normal_count;
|
||||
r->transient_count = transient_count;
|
||||
|
||||
if (normal_count) {
|
||||
r->normal_list = ecalloc(normal_count, sizeof(xcb_window_t));
|
||||
for (uint32_t i = 0; i < normal_count; i++) {
|
||||
r->normal_list[i] = normal_window_array[i];
|
||||
}
|
||||
}
|
||||
if (transient_count) {
|
||||
r->transient_list = ecalloc(transient_count, sizeof(xcb_window_t));
|
||||
for (uint32_t i = 0; i < transient_count; i++) {
|
||||
r->transient_list[i] = transient_window_array[i];
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void free_window_list(window_list_t *window_list) {
|
||||
if (window_list == NULL) return;
|
||||
free(window_list->list);
|
||||
|
||||
if (window_list->normal_list) free(window_list->normal_list);
|
||||
if (window_list->transient_list) free(window_list->transient_list);
|
||||
free(window_list);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user