feat(tray): 拦截托盘窗口的 map/configure/property 事件
This commit is contained in:
@@ -190,6 +190,8 @@ static bool handle_map_request(
|
||||
event_t *event,
|
||||
const xcb_map_request_event_t *xcb_event
|
||||
) {
|
||||
if (tray_handle_map_request(backend, xcb_event)) return false;
|
||||
|
||||
event->type = ZDWM_EVENT_WINDOW_MAP_REQUEST;
|
||||
return populate_window_event(
|
||||
backend,
|
||||
@@ -231,6 +233,8 @@ static bool handle_configure_request(
|
||||
event_t *event,
|
||||
const xcb_configure_request_event_t *xcb_event
|
||||
) {
|
||||
if (tray_handle_configure_request(backend, xcb_event)) return false;
|
||||
|
||||
event->type = ZDWM_EVENT_CONFIGURE_REQUEST;
|
||||
auto data = &event->as.configure_request;
|
||||
data->window = xcb_event->window;
|
||||
@@ -342,6 +346,8 @@ static bool handle_property_notify(
|
||||
event_t *event,
|
||||
const xcb_property_notify_event_t *xcb_event
|
||||
) {
|
||||
if (tray_handle_property_notify(backend, xcb_event)) return false;
|
||||
|
||||
auto window_id = xcb_event->window;
|
||||
if (
|
||||
xcb_event->atom == backend->atoms.WM_NAME ||
|
||||
|
||||
@@ -487,3 +487,64 @@ bool tray_handle_client_message(
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tray_handle_configure_request(
|
||||
backend_t *backend,
|
||||
const xcb_configure_request_event_t *ev
|
||||
) {
|
||||
auto tray = get_tray_host(backend);
|
||||
if (!tray || !tray->initialized) return false;
|
||||
|
||||
if (ev->window == tray->container) {
|
||||
tray_dispatch_callback(tray);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto icon = tray_get_icon(tray, ev->window);
|
||||
if (!icon) return false;
|
||||
|
||||
if ((ev->value_mask & XCB_CONFIG_WINDOW_WIDTH) && ev->width > 0) {
|
||||
icon->natural_width = (int32_t)ev->width;
|
||||
}
|
||||
if ((ev->value_mask & XCB_CONFIG_WINDOW_HEIGHT) && ev->height > 0) {
|
||||
icon->natural_height = (int32_t)ev->height;
|
||||
}
|
||||
|
||||
tray_dispatch_callback(tray);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tray_handle_map_request(
|
||||
backend_t *backend,
|
||||
const xcb_map_request_event_t *ev
|
||||
) {
|
||||
auto tray = get_tray_host(backend);
|
||||
if (!tray || !tray->initialized) return false;
|
||||
|
||||
auto conn = backend->conn;
|
||||
if (ev->window == tray->container) {
|
||||
tray_dispatch_callback(tray);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto icon = tray_get_icon(tray, ev->window);
|
||||
if (!icon && ev->parent != tray->container) return false;
|
||||
|
||||
xcb_map_window(conn, ev->window);
|
||||
xcb_flush(conn);
|
||||
|
||||
tray_dispatch_callback(tray);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tray_handle_property_notify(
|
||||
backend_t *backend,
|
||||
const xcb_property_notify_event_t *ev
|
||||
) {
|
||||
auto tray = get_tray_host(backend);
|
||||
if (!tray || !tray->initialized) return false;
|
||||
|
||||
if (ev->window == XCB_WINDOW_NONE) return false;
|
||||
if (ev->window == tray->container) return true;
|
||||
return tray_get_icon(tray, ev->window) != nullptr;
|
||||
}
|
||||
|
||||
@@ -22,3 +22,15 @@ bool tray_handle_client_message(
|
||||
backend_t *backend,
|
||||
const xcb_client_message_event_t *ev
|
||||
);
|
||||
bool tray_handle_configure_request(
|
||||
backend_t *backend,
|
||||
const xcb_configure_request_event_t *ev
|
||||
);
|
||||
bool tray_handle_map_request(
|
||||
backend_t *backend,
|
||||
const xcb_map_request_event_t *ev
|
||||
);
|
||||
bool tray_handle_property_notify(
|
||||
backend_t *backend,
|
||||
const xcb_property_notify_event_t *ev
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user