From 0c361a6593f0a76323e033266b90a8d038acf9d4 Mon Sep 17 00:00:00 2001 From: Zedhugh Chen Date: Mon, 1 Sep 2025 17:55:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=20EWMH=20=E6=89=A9=E5=B1=95?= =?UTF-8?q?=E7=9A=84=20=5FNET=5FACTIVE=5FWINDOW=20=E5=8D=8F=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/include/xcb.h | 1 + src/main.c | 18 ++++++++++++++++++ src/xcb/wm-extension.c | 1 + 3 files changed, 20 insertions(+) diff --git a/src/include/xcb.h b/src/include/xcb.h index 2f33b3f..124a1be 100644 --- a/src/include/xcb.h +++ b/src/include/xcb.h @@ -126,6 +126,7 @@ typedef enum atom_t { atom_wm_protocols, atom_wm_delete, atom_wm_take_focus, + atom_net_active_window, atom_net_wm_name, atom_net_wm_state, atom_net_wm_fullscreen, diff --git a/src/main.c b/src/main.c index bf0a755..c4a06a3 100644 --- a/src/main.c +++ b/src/main.c @@ -909,6 +909,24 @@ void client_message(client_message_event_t *event) { bool toggle_to_fullscreen = event->data.data32[0] == 2 && !c->fullscreen; set_client_fullscreen(c, set_fullscreen || toggle_to_fullscreen); } + } else if (event->message_type == get_xcb_atom(atom_net_active_window)) { + client_t *client = get_client_of_window(event->window); + if (client) { + logger("==== _NET_ACTIVE_WINDOW\n"); + print_client(client); + + uint32_t tag_mask = 0; + for (uint32_t i = 0; i < g_strv_length(client->monitor->tags); i++) { + tag_mask |= 1 << i; + } + uint32_t target_tag = tag_mask & client->tags; + const user_action_arg_t arg = {.ui = target_tag}; + + current_monitor = client->monitor; + select_tag(&arg); + focus(client); + restack(current_monitor); + } } } diff --git a/src/xcb/wm-extension.c b/src/xcb/wm-extension.c index b0f0adf..f2c1808 100644 --- a/src/xcb/wm-extension.c +++ b/src/xcb/wm-extension.c @@ -26,6 +26,7 @@ static atom_map_t atom_map[] = { {.atom = atom_wm_protocols, .name = "WM_PROTOCOLS"}, {.atom = atom_wm_delete, .name = "WM_DELETE_WINDOW"}, {.atom = atom_wm_take_focus, .name = "WM_TAKE_FOCUS"}, + {.atom = atom_net_active_window, .name = "_NET_ACTIVE_WINDOW"}, {.atom = atom_net_wm_name, .name = "_NET_WM_NAME"}, {.atom = atom_net_wm_state, .name = "_NET_WM_STATE"}, {.atom = atom_net_wm_fullscreen, .name = "_NET_WM_STATE_FULLSCREEN"},