From 447bc67691d9ff80cabd23b5b679f1c1617f547a Mon Sep 17 00:00:00 2001 From: Ernesto Cruz Date: Sat, 20 Jun 2026 00:23:54 +0100 Subject: [PATCH] feat(ipc): add 'get cursorpos' to mmsg --- docs/ipc.md | 2 ++ mmsg/mmsg.1 | 4 ++++ mmsg/mmsg.c | 2 ++ src/ipc/ipc.h | 9 +++++++++ 4 files changed, 17 insertions(+) diff --git a/docs/ipc.md b/docs/ipc.md index 489293fa..0bdcc0b1 100644 --- a/docs/ipc.md +++ b/docs/ipc.md @@ -24,6 +24,7 @@ description: Control mangowm programmatically using mmsg. | Command | Description | | :--- | :--- | | `get version` | Returns the current version of the compositor. | +| `get cursorpos` | Returns the global pointer position (`x`, `y`) and the monitor under it. | | `get keymode` | Returns the current active keyboard mode (e.g., normal, insert). | | `get keyboardlayout` | Returns the active XKB layout (abbreviated). | | `get monitor ` | Returns full JSON details for a specific monitor. | @@ -41,6 +42,7 @@ description: Control mangowm programmatically using mmsg. mmsg get monitor eDP-1 mmsg get all-clients mmsg get all-monitors +mmsg get cursorpos ``` ### WATCH (Event Subscription) diff --git a/mmsg/mmsg.1 b/mmsg/mmsg.1 index 8a935f50..2449e6e0 100644 --- a/mmsg/mmsg.1 +++ b/mmsg/mmsg.1 @@ -21,6 +21,10 @@ All \fBget\fR commands print a single JSON object and then close the connection. \fBget version\fR Return compositor version. .TP +\fBget cursorpos\fR +Return the global pointer position (\fBx\fR, \fBy\fR) and the monitor under it +(\fBnull\fR if over no output). +.TP \fBget keymode\fR Return current keymode. .TP diff --git a/mmsg/mmsg.c b/mmsg/mmsg.c index adb0b539..1fccf3ed 100644 --- a/mmsg/mmsg.c +++ b/mmsg/mmsg.c @@ -12,6 +12,8 @@ static void usage(void) { printf("One-shot queries (get):\n"); printf( " get version Show compositor version\n"); + printf(" get cursorpos Show pointer position + " + "monitor\n"); printf(" get keymode Show current keymode\n"); printf(" get keyboardlayout Show current keyboard " "layout\n"); diff --git a/src/ipc/ipc.h b/src/ipc/ipc.h index 9ac1a7b2..03e0746e 100644 --- a/src/ipc/ipc.h +++ b/src/ipc/ipc.h @@ -237,6 +237,15 @@ static void handle_command(int client_fd, const char *cmd_raw) { if (strcmp(cmd, "get version") == 0) { resp = cJSON_CreateObject(); cJSON_AddStringToObject(resp, "version", VERSION); + } else if (strcmp(cmd, "get cursorpos") == 0) { + resp = cJSON_CreateObject(); + cJSON_AddNumberToObject(resp, "x", cursor->x); + cJSON_AddNumberToObject(resp, "y", cursor->y); + Monitor *m = xytomon(cursor->x, cursor->y); + if (m) + cJSON_AddStringToObject(resp, "monitor", m->wlr_output->name); + else + cJSON_AddNullToObject(resp, "monitor"); } else if (strcmp(cmd, "get keymode") == 0) { resp = cJSON_CreateObject(); cJSON_AddStringToObject(resp, "keymode", keymode.mode);