diff --git a/completions/fish/swaymsg.fish b/completions/fish/swaymsg.fish index 5ee7dcc0b..47e298c92 100644 --- a/completions/fish/swaymsg.fish +++ b/completions/fish/swaymsg.fish @@ -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." diff --git a/completions/zsh/_swaymsg b/completions/zsh/_swaymsg index 106f3d9dc..f22ca84f7 100644 --- a/completions/zsh/_swaymsg +++ b/completions/zsh/_swaymsg @@ -25,6 +25,7 @@ types=( 'get_binding_modes' 'get_binding_state' 'get_config' +'get_cursor' 'send_tick' 'subscribe' ) diff --git a/swaymsg/main.c b/swaymsg/main.c index 6a9eb1987..7f2efbdb3 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c @@ -1,4 +1,3 @@ - #include #include #include @@ -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) { diff --git a/swaymsg/swaymsg.1.scd b/swaymsg/swaymsg.1.scd index abee1bb9e..7be5df74a 100644 --- a/swaymsg/swaymsg.1.scd +++ b/swaymsg/swaymsg.1.scd @@ -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.