feat(runtime): 启动时扫描并接管已有窗口
从 handle_map_request 中提取 populate_window_event 供复用, 新增 backend_scan_windows 扫描 X11 根窗口子树, runtime_scan 将扫描到的窗口走完整 policy 流程纳入管理。 route_map_request 增加 override_redirect 过滤。
This commit is contained in:
@@ -22,8 +22,10 @@
|
||||
#include "base/macros.h"
|
||||
#include "base/memory.h"
|
||||
#include "base/window_list.h"
|
||||
#include "core/event.h"
|
||||
#include "core/plan.h"
|
||||
#include "core/types.h"
|
||||
#include "core/window.h"
|
||||
#include "internal.h"
|
||||
|
||||
typedef struct atom_item_t {
|
||||
@@ -625,3 +627,54 @@ bool backend_apply_effect(
|
||||
xcb_flush(backend->conn);
|
||||
return true;
|
||||
}
|
||||
|
||||
backend_scan_result_t *backend_scan_windows(backend_t *backend) {
|
||||
auto conn = backend->conn;
|
||||
auto root = backend->screen->root;
|
||||
auto cookie = xcb_query_tree_unchecked(conn, root);
|
||||
auto reply = xcb_query_tree_reply(conn, cookie, nullptr);
|
||||
if (!reply) return nullptr;
|
||||
|
||||
auto length = xcb_query_tree_children_length(reply);
|
||||
if (!length) {
|
||||
p_delete(&reply);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto list = xcb_query_tree_children(reply);
|
||||
|
||||
backend_scan_result_t *result = p_new(backend_scan_result_t, 1);
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
auto slot = (window_map_request_event_t *)
|
||||
array_push(result->windows, result->count, result->capacity);
|
||||
if (!populate_window_event(backend, list[i], slot)) {
|
||||
window_layer_props_cleanup(&slot->props);
|
||||
window_metadata_cleanup(&slot->metadata);
|
||||
result->count--;
|
||||
}
|
||||
}
|
||||
|
||||
p_delete(&reply);
|
||||
|
||||
if (result->count == 0) {
|
||||
backend_scan_result_destroy(result);
|
||||
result = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void backend_scan_result_destroy(backend_scan_result_t *result) {
|
||||
if (!result) return;
|
||||
|
||||
for (size_t i = 0; i < result->count; i++) {
|
||||
window_map_request_event_t *ev = &result->windows[i];
|
||||
window_layer_props_cleanup(&ev->props);
|
||||
window_metadata_cleanup(&ev->metadata);
|
||||
}
|
||||
|
||||
p_delete(&result->windows);
|
||||
p_delete(&result);
|
||||
}
|
||||
|
||||
@@ -91,18 +91,13 @@ static bool urgent_from_states(
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool handle_map_request(
|
||||
bool populate_window_event(
|
||||
backend_t *backend,
|
||||
event_t *event,
|
||||
const xcb_map_request_event_t *xcb_event
|
||||
xcb_window_t window,
|
||||
window_map_request_event_t *ev
|
||||
) {
|
||||
xcb_window_t window = xcb_event->window;
|
||||
|
||||
event->type = ZDWM_EVENT_WINDOW_MAP_REQUEST;
|
||||
|
||||
window_map_request_event_t *ev = &event->as.window_map_request;
|
||||
ev->window = (window_id_t)window;
|
||||
ev->transient_for = window_get_transient_for(backend, window);
|
||||
ev->window = (window_id_t)window;
|
||||
ev->transient_for = window_get_transient_for(backend, window);
|
||||
|
||||
xcb_get_window_attributes_reply_t *wa =
|
||||
window_get_attributes(backend, window);
|
||||
@@ -167,6 +162,19 @@ static bool handle_map_request(
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool handle_map_request(
|
||||
backend_t *backend,
|
||||
event_t *event,
|
||||
const xcb_map_request_event_t *xcb_event
|
||||
) {
|
||||
event->type = ZDWM_EVENT_WINDOW_MAP_REQUEST;
|
||||
return populate_window_event(
|
||||
backend,
|
||||
xcb_event->window,
|
||||
&event->as.window_map_request
|
||||
);
|
||||
}
|
||||
|
||||
static bool handle_unmap_notify(
|
||||
backend_t *backend,
|
||||
event_t *event,
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <xcb/xproto.h>
|
||||
|
||||
#include "base/window_list.h"
|
||||
#include "core/event.h"
|
||||
|
||||
#define ATOM_LIST(X) \
|
||||
X(COMPOUND_TEXT) \
|
||||
@@ -94,3 +95,9 @@ struct backend_t {
|
||||
window_list_t map;
|
||||
window_list_t kill;
|
||||
};
|
||||
|
||||
bool populate_window_event(
|
||||
struct backend_t *backend,
|
||||
xcb_window_t window,
|
||||
window_map_request_event_t *ev
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user