Merge pull request #1078 from ernestoCruz05/ipc
Some checks failed
Sync website / sync-website (push) Has been cancelled
Sync wiki / sync-wiki (push) Has been cancelled

feat(ipc): add 'get cursorpos'
This commit is contained in:
DreamMaoMao 2026-06-22 10:01:41 +08:00
commit eb9b5ca8cc
4 changed files with 17 additions and 0 deletions

View file

@ -24,6 +24,7 @@ description: Control mangowm programmatically using mmsg.
| Command | Description | | Command | Description |
| :--- | :--- | | :--- | :--- |
| `get version` | Returns the current version of the compositor. | | `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 keymode` | Returns the current active keyboard mode (e.g., normal, insert). |
| `get keyboardlayout` | Returns the active XKB layout (abbreviated). | | `get keyboardlayout` | Returns the active XKB layout (abbreviated). |
| `get monitor <name>` | Returns full JSON details for a specific monitor. | | `get monitor <name>` | 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 monitor eDP-1
mmsg get all-clients mmsg get all-clients
mmsg get all-monitors mmsg get all-monitors
mmsg get cursorpos
``` ```
### WATCH (Event Subscription) ### WATCH (Event Subscription)

View file

@ -21,6 +21,10 @@ All \fBget\fR commands print a single JSON object and then close the connection.
\fBget version\fR \fBget version\fR
Return compositor version. Return compositor version.
.TP .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 \fBget keymode\fR
Return current keymode. Return current keymode.
.TP .TP

View file

@ -12,6 +12,8 @@ static void usage(void) {
printf("One-shot queries (get):\n"); printf("One-shot queries (get):\n");
printf( printf(
" get version Show compositor version\n"); " get version Show compositor version\n");
printf(" get cursorpos Show pointer position + "
"monitor\n");
printf(" get keymode Show current keymode\n"); printf(" get keymode Show current keymode\n");
printf(" get keyboardlayout Show current keyboard " printf(" get keyboardlayout Show current keyboard "
"layout\n"); "layout\n");

View file

@ -237,6 +237,15 @@ static void handle_command(int client_fd, const char *cmd_raw) {
if (strcmp(cmd, "get version") == 0) { if (strcmp(cmd, "get version") == 0) {
resp = cJSON_CreateObject(); resp = cJSON_CreateObject();
cJSON_AddStringToObject(resp, "version", VERSION); 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) { } else if (strcmp(cmd, "get keymode") == 0) {
resp = cJSON_CreateObject(); resp = cJSON_CreateObject();
cJSON_AddStringToObject(resp, "keymode", keymode.mode); cJSON_AddStringToObject(resp, "keymode", keymode.mode);