From 7dc569496559f213197da0c5de53b812806d77ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 31 Mar 2019 12:08:44 +0200 Subject: [PATCH] module/i3: use our own copy of i3/ipc.h The main advantage is when targeting sway/wayland instead of i3/x11; sway doesn't package ipc.h. There *is* an ipc.h in the sway sources, but it doesn't define e.g the header format, and has different names for the constants. --- modules/CMakeLists.txt | 4 -- modules/i3-common.c | 3 +- modules/i3-common.h | 1 - modules/i3-ipc.h | 114 +++++++++++++++++++++++++++++++++++++++++ modules/i3.c | 3 +- 5 files changed, 117 insertions(+), 8 deletions(-) create mode 100644 modules/i3-ipc.h diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 24a907d..c3aa40d 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -33,10 +33,6 @@ target_link_libraries(clock module-sdk) list(APPEND enabled clock) pkg_check_modules(json REQUIRED IMPORTED_TARGET json-c) -find_file(I3_IPC_H i3/ipc.h) -if (NOT I3_IPC_H) - message(FATAL_ERROR "cannot find header file: i3/ipc.h") -endif () add_library(i3-common STATIC EXCLUDE_FROM_ALL i3-common.c i3-common.h) target_link_libraries(i3-common PkgConfig::json) if (ENABLE_X11) diff --git a/modules/i3-common.c b/modules/i3-common.c index 8d1e26f..2f3e413 100644 --- a/modules/i3-common.c +++ b/modules/i3-common.c @@ -12,7 +12,6 @@ #include #endif -#include #include #define LOG_MODULE "i3:common" @@ -23,6 +22,8 @@ #include "../xcb.h" #endif +#include "i3-ipc.h" + #if defined(ENABLE_X11) static bool get_socket_address_x11(struct sockaddr_un *addr) diff --git a/modules/i3-common.h b/modules/i3-common.h index 0d48037..40948cb 100644 --- a/modules/i3-common.h +++ b/modules/i3-common.h @@ -6,7 +6,6 @@ #include #include -//#include #include bool i3_get_socket_address(struct sockaddr_un *addr); diff --git a/modules/i3-ipc.h b/modules/i3-ipc.h new file mode 100644 index 0000000..884a0cf --- /dev/null +++ b/modules/i3-ipc.h @@ -0,0 +1,114 @@ +/* + * vim:ts=4:sw=4:expandtab + * + * i3 - an improved dynamic tiling window manager + * © 2009 Michael Stapelberg and contributors (see also: LICENSE) + * + * This public header defines the different constants and message types to use + * for the IPC interface to i3 (see docs/ipc for more information). + * + */ +#pragma once + +#include + +typedef struct i3_ipc_header { + /* 6 = strlen(I3_IPC_MAGIC) */ + char magic[6]; + uint32_t size; + uint32_t type; +} __attribute__((packed)) i3_ipc_header_t; + +/* + * Messages from clients to i3 + * + */ + +/** Never change this, only on major IPC breakage (don’t do that) */ +#define I3_IPC_MAGIC "i3-ipc" + +/** Deprecated: use I3_IPC_MESSAGE_TYPE_RUN_COMMAND */ +#define I3_IPC_MESSAGE_TYPE_COMMAND 0 + +/** The payload of the message will be interpreted as a command */ +#define I3_IPC_MESSAGE_TYPE_RUN_COMMAND 0 + +/** Requests the current workspaces from i3 */ +#define I3_IPC_MESSAGE_TYPE_GET_WORKSPACES 1 + +/** Subscribe to the specified events */ +#define I3_IPC_MESSAGE_TYPE_SUBSCRIBE 2 + +/** Requests the current outputs from i3 */ +#define I3_IPC_MESSAGE_TYPE_GET_OUTPUTS 3 + +/** Requests the tree layout from i3 */ +#define I3_IPC_MESSAGE_TYPE_GET_TREE 4 + +/** Request the current defined marks from i3 */ +#define I3_IPC_MESSAGE_TYPE_GET_MARKS 5 + +/** Request the configuration for a specific 'bar' */ +#define I3_IPC_MESSAGE_TYPE_GET_BAR_CONFIG 6 + +/** Request the i3 version */ +#define I3_IPC_MESSAGE_TYPE_GET_VERSION 7 + +/** Request a list of configured binding modes. */ +#define I3_IPC_MESSAGE_TYPE_GET_BINDING_MODES 8 + +/** Request the raw last loaded i3 config. */ +#define I3_IPC_MESSAGE_TYPE_GET_CONFIG 9 + +/** Send a tick event to all subscribers. */ +#define I3_IPC_MESSAGE_TYPE_SEND_TICK 10 + +/** Trigger an i3 sync protocol message via IPC. */ +#define I3_IPC_MESSAGE_TYPE_SYNC 11 + +/* + * Messages from i3 to clients + * + */ +#define I3_IPC_REPLY_TYPE_COMMAND 0 +#define I3_IPC_REPLY_TYPE_WORKSPACES 1 +#define I3_IPC_REPLY_TYPE_SUBSCRIBE 2 +#define I3_IPC_REPLY_TYPE_OUTPUTS 3 +#define I3_IPC_REPLY_TYPE_TREE 4 +#define I3_IPC_REPLY_TYPE_MARKS 5 +#define I3_IPC_REPLY_TYPE_BAR_CONFIG 6 +#define I3_IPC_REPLY_TYPE_VERSION 7 +#define I3_IPC_REPLY_TYPE_BINDING_MODES 8 +#define I3_IPC_REPLY_TYPE_CONFIG 9 +#define I3_IPC_REPLY_TYPE_TICK 10 +#define I3_IPC_REPLY_TYPE_SYNC 11 + +/* + * Events from i3 to clients. Events have the first bit set high. + * + */ +#define I3_IPC_EVENT_MASK (1UL << 31) + +/* The workspace event will be triggered upon changes in the workspace list */ +#define I3_IPC_EVENT_WORKSPACE (I3_IPC_EVENT_MASK | 0) + +/* The output event will be triggered upon changes in the output list */ +#define I3_IPC_EVENT_OUTPUT (I3_IPC_EVENT_MASK | 1) + +/* The output event will be triggered upon mode changes */ +#define I3_IPC_EVENT_MODE (I3_IPC_EVENT_MASK | 2) + +/* The window event will be triggered upon window changes */ +#define I3_IPC_EVENT_WINDOW (I3_IPC_EVENT_MASK | 3) + +/** Bar config update will be triggered to update the bar config */ +#define I3_IPC_EVENT_BARCONFIG_UPDATE (I3_IPC_EVENT_MASK | 4) + +/** The binding event will be triggered when bindings run */ +#define I3_IPC_EVENT_BINDING (I3_IPC_EVENT_MASK | 5) + +/** The shutdown event will be triggered when the ipc shuts down */ +#define I3_IPC_EVENT_SHUTDOWN (I3_IPC_EVENT_MASK | 6) + +/** The tick event will be sent upon a tick IPC message */ +#define I3_IPC_EVENT_TICK (I3_IPC_EVENT_MASK | 7) diff --git a/modules/i3.c b/modules/i3.c index b451783..8f2420b 100644 --- a/modules/i3.c +++ b/modules/i3.c @@ -7,8 +7,6 @@ #include #include -#include - #define LOG_MODULE "i3" #define LOG_ENABLE_DBG 0 #include "../log.h" @@ -18,6 +16,7 @@ #include "../particles/dynlist.h" #include "../plugin.h" +#include "i3-ipc.h" #include "i3-common.h" struct ws_content {