From 5835bbc3855c99252e2a94e9ae69df189279e20c Mon Sep 17 00:00:00 2001 From: Iskustvo Date: Tue, 7 Jan 2020 02:32:18 +0100 Subject: [PATCH] Added workspace ID in GET_WORKSPACES response. --- docs/ipc | 4 ++++ i3bar/include/workspaces.h | 1 + i3bar/src/workspaces.c | 6 ++++++ src/ipc.c | 3 +++ 4 files changed, 14 insertions(+) diff --git a/docs/ipc b/docs/ipc index 96e8988a..af362f98 100644 --- a/docs/ipc +++ b/docs/ipc @@ -164,6 +164,10 @@ sending a reply. Expect the socket to be shut down. The reply consists of a serialized list of workspaces. Each workspace has the following properties: +id (integer):: + The internal ID (actually a C pointer value) of this container. Do not + make any assumptions about it. You can use it to (re-)identify and + address containers when talking to i3. num (integer):: The logical number of the workspace. Corresponds to the command to switch to this workspace. For named workspaces, this will be -1. diff --git a/i3bar/include/workspaces.h b/i3bar/include/workspaces.h index e1f9e887..0ef5c0a9 100644 --- a/i3bar/include/workspaces.h +++ b/i3bar/include/workspaces.h @@ -30,6 +30,7 @@ void parse_workspaces_json(char *json); void free_workspaces(void); struct i3_ws { + uintptr_t id; /* Workspace ID - C pointer to a workspace container */ int num; /* The internal number of the ws */ char *canonical_name; /* The true name of the ws according to the ipc */ i3String *name; /* The name of the ws that is displayed on the bar */ diff --git a/i3bar/src/workspaces.c b/i3bar/src/workspaces.c index 7285d150..9a0b950e 100644 --- a/i3bar/src/workspaces.c +++ b/i3bar/src/workspaces.c @@ -61,6 +61,12 @@ static int workspaces_boolean_cb(void *params_, int val) { static int workspaces_integer_cb(void *params_, long long val) { struct workspaces_json_params *params = (struct workspaces_json_params *)params_; + if (!strcmp(params->cur_key, "id")) { + params->workspaces_walk->id = val; + FREE(params->cur_key); + return 1; + } + if (!strcmp(params->cur_key, "num")) { params->workspaces_walk->num = (int)val; FREE(params->cur_key); diff --git a/src/ipc.c b/src/ipc.c index ea382395..c844409c 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -906,6 +906,9 @@ IPC_HANDLER(get_workspaces) { assert(ws->type == CT_WORKSPACE); y(map_open); + ystr("id"); + y(integer, (uintptr_t)ws); + ystr("num"); y(integer, ws->num);