Skip to content

Instantly share code, notes, and snippets.

@bendem
Last active April 8, 2016 19:11
Show Gist options
  • Save bendem/60cd81c4a3aa1961fc94fd8c7557d702 to your computer and use it in GitHub Desktop.
Save bendem/60cd81c4a3aa1961fc94fd8c7557d702 to your computer and use it in GitHub Desktop.
~ $ curl -s https://gist.githubusercontent.com/bendem/60cd81c4a3aa1961fc94fd8c7557d702/raw/fe3a9bbceb9408fb86b6150553948100cc3ce197/i3ipc-glib-test.c | gcc $(pkg-config --libs --cflags i3ipc-glib-1.0) -x c -
~ $ ./a.out
id: 2577442560
$ i3-msg -t get_tree | jq . | grep 'id"' | sed -E 's/\s+//' | sort
"id": 94341533615152,
"id": 94341533617280,
"id": 94341533617712,
"id": 94341533703184,
"id": 94341534014560,
"id": 94341534026752,
"id": 94341534037296,
"id": 94341534037952,
"id": 94341534038512,
"id": 94341534052576,
"id": 94341534054000,
"id": 94341534054432,
"id": 94341534055136,
"id": 94341534055840,
"id": 94341534056544,
"id": 94341534058176,
"id": 94341534059040,
"id": 94341534092576,
"id": 94341534099200,
#include <glib/gprintf.h>
#include <i3ipc-glib/i3ipc-glib.h>
#include <inttypes.h>
gint main() {
i3ipcConnection *conn;
gchar *reply;
conn = i3ipc_connection_new(NULL, NULL);
i3ipcCon *root = i3ipc_connection_get_tree(conn, NULL);
i3ipcCon *focused = i3ipc_con_find_focused(root);
uintptr_t id;
g_object_get(focused, "id", &id, NULL);
printf("id: %" PRIuPTR "\n", id);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment