mirror of
https://github.com/swaywm/sway.git
synced 2025-10-08 21:25:58 +00:00
swaymsg: get_cursor support
This commit is contained in:
parent
495ba1e96e
commit
945abfc49a
4 changed files with 50 additions and 1 deletions
|
@ -21,5 +21,6 @@ complete -c swaymsg -s t -l type -fra 'get_binding_modes' --description "Gets a
|
|||
complete -c swaymsg -s t -l type -fra 'get_binding_state' --description "Get JSON-encoded info about the current binding state."
|
||||
complete -c swaymsg -s t -l type -fra 'get_config' --description "Gets a JSON-encoded copy of the current configuration."
|
||||
complete -c swaymsg -s t -l type -fra 'get_seats' --description "Gets a JSON-encoded list of all seats, its properties and all assigned devices."
|
||||
complete -c swaymsg -s t -l type -fra 'get_cursor' --description "Get JSON-encoded information about the current cursor position and the node under it."
|
||||
complete -c swaymsg -s t -l type -fra 'send_tick' --description "Sends a tick event to all subscribed clients."
|
||||
complete -c swaymsg -s t -l type -fra 'subscribe' --description "Subscribe to a list of event types."
|
||||
|
|
|
@ -25,6 +25,7 @@ types=(
|
|||
'get_binding_modes'
|
||||
'get_binding_state'
|
||||
'get_config'
|
||||
'get_cursor'
|
||||
'send_tick'
|
||||
'subscribe'
|
||||
)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -377,6 +376,46 @@ static void pretty_print_tree(json_object *obj, int indent) {
|
|||
}
|
||||
}
|
||||
|
||||
static void pretty_print_cursor(json_object *c) {
|
||||
json_object *x, *y, *surface_x, *surface_y, *node_type, *window_title, *app_id, *workspace_name, *pid;
|
||||
json_object_object_get_ex(c, "x", &x);
|
||||
json_object_object_get_ex(c, "y", &y);
|
||||
json_object_object_get_ex(c, "surface_x", &surface_x);
|
||||
json_object_object_get_ex(c, "surface_y", &surface_y);
|
||||
json_object_object_get_ex(c, "node_type", &node_type);
|
||||
json_object_object_get_ex(c, "window_title", &window_title);
|
||||
json_object_object_get_ex(c, "app_id", &app_id);
|
||||
json_object_object_get_ex(c, "workspace_name", &workspace_name);
|
||||
json_object_object_get_ex(c, "pid", &pid);
|
||||
|
||||
printf("Cursor position: %d, %d",
|
||||
json_object_get_int(x), json_object_get_int(y));
|
||||
|
||||
if (surface_x && surface_y) {
|
||||
printf(" (relative: %d, %d)",
|
||||
json_object_get_int(surface_x), json_object_get_int(surface_y));
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
if (node_type) {
|
||||
printf("Under cursor: %s", json_object_get_string(node_type));
|
||||
|
||||
if (workspace_name) {
|
||||
printf(" \"%s\"", json_object_get_string(workspace_name));
|
||||
}
|
||||
if (window_title) {
|
||||
printf(" - %s", json_object_get_string(window_title));
|
||||
}
|
||||
if (app_id) {
|
||||
printf(" (%s)", json_object_get_string(app_id));
|
||||
}
|
||||
if (pid) {
|
||||
printf(" [PID: %d]", json_object_get_int(pid));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void pretty_print(int type, json_object *resp) {
|
||||
switch (type) {
|
||||
case IPC_SEND_TICK:
|
||||
|
@ -390,6 +429,9 @@ static void pretty_print(int type, json_object *resp) {
|
|||
case IPC_GET_TREE:
|
||||
pretty_print_tree(resp, 0);
|
||||
return;
|
||||
case IPC_GET_CURSOR:
|
||||
pretty_print_cursor(resp);
|
||||
return;
|
||||
case IPC_COMMAND:
|
||||
case IPC_GET_WORKSPACES:
|
||||
case IPC_GET_INPUTS:
|
||||
|
@ -518,6 +560,8 @@ int main(int argc, char **argv) {
|
|||
type = IPC_GET_WORKSPACES;
|
||||
} else if (strcasecmp(cmdtype, "get_seats") == 0) {
|
||||
type = IPC_GET_SEATS;
|
||||
} else if (strcasecmp(cmdtype, "get_cursor") == 0) {
|
||||
type = IPC_GET_CURSOR;
|
||||
} else if (strcasecmp(cmdtype, "get_inputs") == 0) {
|
||||
type = IPC_GET_INPUTS;
|
||||
} else if (strcasecmp(cmdtype, "get_outputs") == 0) {
|
||||
|
|
|
@ -82,6 +82,9 @@ _swaymsg_ [options...] [message]
|
|||
Gets a list of all seats,
|
||||
its properties and all assigned devices.
|
||||
|
||||
*get\_cursor*
|
||||
Gets the current cursor position and information about the element under it.
|
||||
|
||||
*get\_marks*
|
||||
Get a JSON-encoded list of marks.
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue