From 8a1f3597e11e7e4e0740123899e25ee417d8ab4e Mon Sep 17 00:00:00 2001
From: DreamMaoMao <2523610504@qq.com>
Date: Wed, 11 Feb 2026 10:43:18 +0800
Subject: [PATCH] get kb meesage by ipc
---
mmsg/mmsg.c | 12 ++++++++++++
protocols/dwl-ipc-unstable-v2.xml | 7 +++++++
src/ext-protocol/dwl-ipc.h | 17 ++++++++++++++++-
src/mango.c | 10 +++++-----
4 files changed, 40 insertions(+), 6 deletions(-)
diff --git a/mmsg/mmsg.c b/mmsg/mmsg.c
index fb1d04fd..e4d68c44 100644
--- a/mmsg/mmsg.c
+++ b/mmsg/mmsg.c
@@ -265,6 +265,17 @@ static void dwl_ipc_output_kb_layout(void *data,
printf("kb_layout %s\n", kb_layout);
}
+static void dwl_ipc_output_active_kb(void *data,
+ struct zdwl_ipc_output_v2 *dwl_ipc_output,
+ const char *active_kb) {
+ if (!kflag)
+ return;
+ char *output_name = data;
+ if (output_name)
+ printf("%s ", output_name);
+ printf("active_kb %s\n", active_kb);
+}
+
static void
dwl_ipc_output_scalefactor(void *data,
struct zdwl_ipc_output_v2 *dwl_ipc_output,
@@ -425,6 +436,7 @@ static const struct zdwl_ipc_output_v2_listener dwl_ipc_output_listener = {
.height = dwl_ipc_output_height,
.last_layer = dwl_ipc_output_last_layer,
.kb_layout = dwl_ipc_output_kb_layout,
+ .active_kb = dwl_ipc_output_active_kb,
.keymode = dwl_ipc_output_keymode,
.scalefactor = dwl_ipc_output_scalefactor,
.frame = dwl_ipc_output_frame,
diff --git a/protocols/dwl-ipc-unstable-v2.xml b/protocols/dwl-ipc-unstable-v2.xml
index 5852107e..d6395caa 100644
--- a/protocols/dwl-ipc-unstable-v2.xml
+++ b/protocols/dwl-ipc-unstable-v2.xml
@@ -234,6 +234,13 @@ I would probably just submit raphi's patchset but I don't think that would be po
+
+
+ current active keyboard.
+
+
+
+
current keybind mode.
diff --git a/src/ext-protocol/dwl-ipc.h b/src/ext-protocol/dwl-ipc.h
index ab0bdb8d..90e6dd6b 100644
--- a/src/ext-protocol/dwl-ipc.h
+++ b/src/ext-protocol/dwl-ipc.h
@@ -114,7 +114,9 @@ void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) {
xkb_layout_index_t current;
int32_t tagmask, state, numclients, focused_client, tag;
const char *title, *appid, *symbol;
+ InputDevice *active_kb;
char kb_layout[32];
+ char active_kb_name[256];
focused = focustop(monitor);
zdwl_ipc_output_v2_send_active(ipc_output->resource, monitor == selmon);
@@ -147,12 +149,21 @@ void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) {
symbol = monitor->pertag->ltidxs[monitor->pertag->curtag]->symbol;
}
- keyboard = &kb_group->wlr_group->keyboard;
+ active_kb = get_active_keyboard_device();
+ if(active_kb) {
+ sprintf(active_kb_name, "vendor:%d,product:%d,name:%s", active_kb->vendor, active_kb->product, active_kb->name);
+ } else {
+ sprintf(active_kb_name, "-1 -1 unknown");
+ }
+
+
+ keyboard = active_kb ? (struct wlr_keyboard*)active_kb->device_data: &kb_group->wlr_group->keyboard;
current = xkb_state_serialize_layout(keyboard->xkb_state,
XKB_STATE_LAYOUT_EFFECTIVE);
get_layout_abbr(kb_layout,
xkb_keymap_layout_get_name(keyboard->keymap, current));
+
zdwl_ipc_output_v2_send_layout(
ipc_output->resource,
monitor->pertag->ltidxs[monitor->pertag->curtag] - layouts);
@@ -210,6 +221,10 @@ void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) {
zdwl_ipc_output_v2_send_scalefactor(ipc_output->resource,
monitor->wlr_output->scale * 100);
}
+ if (wl_resource_get_version(ipc_output->resource) >=
+ ZDWL_IPC_OUTPUT_V2_ACTIVE_KB_SINCE_VERSION) {
+ zdwl_ipc_output_v2_send_active_kb(ipc_output->resource, active_kb_name);
+ }
zdwl_ipc_output_v2_send_frame(ipc_output->resource);
}
diff --git a/src/mango.c b/src/mango.c
index fc7c1101..9361a74d 100644
--- a/src/mango.c
+++ b/src/mango.c
@@ -786,6 +786,7 @@ static Client *get_scroll_stack_head(Client *c);
static bool client_only_in_one_tag(Client *c);
static Client *get_focused_stack_client(Client *sc);
static bool client_is_in_same_stack(Client *sc, Client *tc, Client *fc);
+static InputDevice * get_active_keyboard_device(void);
#include "data/static_keymap.h"
#include "dispatch/bind_declare.h"
@@ -2577,12 +2578,11 @@ void createkeyboard(struct wlr_keyboard *keyboard) {
int32_t vendor = libinput_device_get_id_vendor(device);
int32_t product = libinput_device_get_id_product(device);
const char *name = libinput_device_get_name(device);
+ name = name ? name : "unknown";
- if (name) {
- input_dev->vendor = vendor;
- input_dev->product = product;
- input_dev->name = strdup(name);
- }
+ input_dev->vendor = vendor;
+ input_dev->product = product;
+ input_dev->name = strdup(name);
input_dev->destroy_listener.notify = destroyinputdevice;
wl_signal_add(&keyboard->base.events.destroy,