i3ipc++
An C++ implementaiton of the i3 IPC
 All Classes Functions Variables Enumerations Enumerator Modules
ipc.hpp
1 #pragma once
2 
3 #include <cstdint>
4 #include <string>
5 #include <memory>
6 #include <vector>
7 #include <map>
8 
9 #include <sigc++/sigc++.h>
10 
11 extern "C" {
12 #include <i3/ipc.h>
13 }
14 
19 namespace i3ipc {
20 
25 std::string get_socketpath();
26 
30 struct rect_t {
31  int x;
32  int y;
33  int width;
34  int height;
35 };
36 
40 struct workspace_t {
41  int num;
42  std::string name;
43  bool visible;
44  bool focused;
45  bool urgent;
47  std::string output;
48 };
49 
53 struct output_t {
54  std::string name;
55  bool active;
56  std::string current_workspace;
58 };
59 
63 struct version_t {
64  std::string human_readable;
66  uint32_t major;
67  uint32_t minor;
68  uint32_t patch;
69 };
70 
71 
75 enum EventType {
76  ET_WORKSPACE = (1 << 0),
77  ET_OUTPUT = (1 << 1),
78  ET_MODE = (1 << 2),
79  ET_WINDOW = (1 << 3),
80  ET_BARCONFIG_UPDATE = (1 << 4),
81  ET_BINDING = (1 << 5),
82 };
83 
87 enum class WorkspaceEventType : char {
88  FOCUS = 'f',
89  INIT = 'i',
90  EMPTY = 'e',
91  URGENT = 'u',
92 };
93 
97 enum class WindowEventType : char {
98  NEW = 'n',
99  CLOSE = 'c',
100  FOCUS = 'f',
101  TITLE = 't',
102  FULLSCREEN_MODE = 'F',
103  MOVE = 'M',
104  FLOATING = '_',
105  URGENT = 'u',
106 };
107 
108 
112 enum class BorderStyle : char {
113  UNKNOWN = '?', //< If got an unknown border style in reply
114  NONE = 'N',
115  NORMAL = 'n',
116  PIXEL = 'P',
117  ONE_PIXEL = '1',
118 };
119 
120 
124 enum class ContainerLayout : char {
125  UNKNOWN = '?', //< If got an unknown border style in reply
126  SPLIT_H = 'h',
127  SPLIT_V = 'v',
128  STACKED = 's',
129  TABBED = 't',
130  DOCKAREA = 'd',
131  OUTPUT = 'o',
132 };
133 
134 
138 enum class InputType : char {
139  UNKNOWN = '?', //< If got an unknown input_type in binding_event
140  KEYBOARD = 'k',
141  MOUSE = 'm',
142 };
143 
144 
148 enum class BarMode : char {
149  UNKNOWN = '?',
150  DOCK = 'd',
151  HIDE = 'h',
152 };
153 
154 
158 enum class Position : char {
159  UNKNOWN = '?',
160  TOP = 't',
161  BOTTOM = 'b',
162 };
163 
164 
168 struct container_t {
169  uint64_t id;
170  uint64_t xwindow_id;
171  std::string name;
172  std::string type;
174  std::string border_raw;
177  std::string layout_raw;
178  float percent;
183  bool urgent;
184  bool focused;
185 
186  std::list< std::shared_ptr<container_t> > nodes;
187 };
188 
189 
194  WorkspaceEventType type;
195  std::shared_ptr<workspace_t> current;
196  std::shared_ptr<workspace_t> old;
197 };
198 
199 
204  WindowEventType type;
205  std::shared_ptr<container_t> container;
206 };
207 
208 
212 struct binding_t {
213  std::string command;
214  std::vector<std::string> event_state_mask;
215  int32_t input_code;
216  std::string symbol;
217  InputType input_type;
218 };
219 
220 
224 struct bar_config_t {
225  std::string id;
226  BarMode mode;
227  Position position;
228  std::string status_command;
229  std::string font;
232  bool verbose;
233  std::map<std::string, uint32_t> colors;
234 };
235 
236 
237 struct buf_t;
241 class connection {
242 public:
247  connection(const std::string& socket_path = get_socketpath());
248  ~connection();
249 
255  bool send_command(const std::string& command) const;
256 
261  std::vector< std::shared_ptr<workspace_t> > get_workspaces() const;
262 
267  std::vector< std::shared_ptr<output_t> > get_outputs() const;
268 
273  version_t get_version() const;
274 
279  std::shared_ptr<container_t> get_tree() const;
280 
285  std::vector<std::string> get_bar_configs_list() const;
286 
292  std::shared_ptr<bar_config_t> get_bar_config(const std::string& name) const;
293 
309  bool subscribe(const int32_t events);
310 
315  void handle_event();
316 
321  int32_t get_main_socket_fd();
322 
327  int32_t get_event_socket_fd();
328 
329  sigc::signal<void, const workspace_event_t&> signal_workspace_event;
330  sigc::signal<void> signal_output_event;
331  sigc::signal<void> signal_mode_event;
332  sigc::signal<void, const window_event_t&> signal_window_event;
333  sigc::signal<void, const bar_config_t&> signal_barconfig_update_event;
334  sigc::signal<void, const binding_t&> signal_binding_event;
335  sigc::signal<void, EventType, const std::shared_ptr<const buf_t>&> signal_event;
336 protected:
337  void prepare_to_event_handling();
338 private:
339  const int32_t m_main_socket;
340  int32_t m_event_socket;
341  int32_t m_subscriptions;
342  const std::string m_socket_path;
343 };
344 
349 const version_t& get_version();
350 
351 }
352 
std::vector< std::shared_ptr< output_t > > get_outputs() const
Request a list of outputs.
bool binding_mode_indicator
Display the mode indicator or not? Defaults to true.
Definition: ipc.hpp:231
bool urgent
Is the workspace is urgent.
Definition: ipc.hpp:45
i3's workspace
Definition: ipc.hpp:40
Output mode event.
Definition: ipc.hpp:78
std::string current_workspace
Name of current workspace.
Definition: ipc.hpp:56
BorderStyle
A style of a container's border.
Definition: ipc.hpp:112
A binding.
Definition: ipc.hpp:212
std::vector< std::string > event_state_mask
The group and modifier keys that were configured with this binding.
Definition: ipc.hpp:214
Output event.
Definition: ipc.hpp:77
int32_t get_event_socket_fd()
Get the fd of the event socket.
rect_t rect
The absolute display coordinates for this container.
Definition: ipc.hpp:179
InputType
A type of the input of bindings.
Definition: ipc.hpp:138
bool send_command(const std::string &command) const
Send a command to i3.
uint64_t id
The internal ID (actually a C pointer value) of this container. Do not make any assumptions about it...
Definition: ipc.hpp:169
Title of window has been changed.
std::string type
Type of this container.
Definition: ipc.hpp:172
WindowEventType
Types of window events.
Definition: ipc.hpp:97
int x
Position on X axis.
Definition: ipc.hpp:31
Definition: ipc-util.hpp:12
std::string font
The font to use for text on the bar.
Definition: ipc.hpp:229
WorkspaceEventType
Types of workspace events.
Definition: ipc.hpp:87
std::string output
An output of the workspace.
Definition: ipc.hpp:47
uint32_t patch
Patch number of i3.
Definition: ipc.hpp:68
A workspace event.
Definition: ipc.hpp:193
bool verbose
Should the bar enable verbose output for debugging? Defaults to false.
Definition: ipc.hpp:232
std::string id
The ID for this bar. Included in case you request multiple configurations and want to differentiate t...
Definition: ipc.hpp:225
bool workspace_buttons
Display workspace buttons or not? Defaults to true.
Definition: ipc.hpp:230
BorderStyle border
A style of the container's border.
Definition: ipc.hpp:173
Primitive of rectangle.
Definition: ipc.hpp:30
float percent
The percentage which this container takes in its parent. A value of < 0 means that the percent proper...
Definition: ipc.hpp:178
std::string name
Name of the workspace.
Definition: ipc.hpp:42
A node of tree of windows.
Definition: ipc.hpp:168
sigc::signal< void > signal_mode_event
Output mode event signal.
Definition: ipc.hpp:331
uint32_t minor
Minor version of i3.
Definition: ipc.hpp:67
void handle_event()
Handle an event from i3.
connection(const std::string &socket_path=get_socketpath())
Connect to the i3.
Version of i3.
Definition: ipc.hpp:63
ContainerLayout
A type of a container's layout.
Definition: ipc.hpp:124
sigc::signal< void, const window_event_t & > signal_window_event
Window event signal.
Definition: ipc.hpp:332
bool subscribe(const int32_t events)
Subscribe on an events of i3.
rect_t rect
Size of the output.
Definition: ipc.hpp:57
i3's output
Definition: ipc.hpp:53
std::string command
The i3 command that is configured to run for this binding.
Definition: ipc.hpp:213
sigc::signal< void > signal_output_event
Output event signal.
Definition: ipc.hpp:330
int y
Position on Y axis.
Definition: ipc.hpp:32
uint32_t current_border_width
Number of pixels of the border width.
Definition: ipc.hpp:175
std::shared_ptr< container_t > container
A container event associated with.
Definition: ipc.hpp:205
std::shared_ptr< workspace_t > current
Current focused workspace.
Definition: ipc.hpp:195
std::string status_command
Command which will be run to generate a statusline. Each line on stdout of this command will be displ...
Definition: ipc.hpp:228
std::shared_ptr< bar_config_t > get_bar_config(const std::string &name) const
Request a barconfig.
std::vector< std::string > get_bar_configs_list() const
Request a list of names of available barconfigs.
std::string border_raw
A "border" field of TREE reply. NOT empty only if border equals BorderStyle::UNKNOWN.
Definition: ipc.hpp:174
The bar does not show unless a specific key is pressed.
Connection to the i3.
Definition: ipc.hpp:241
std::shared_ptr< workspace_t > old
Old (previous) workspace.
Definition: ipc.hpp:196
std::string name
Name of the output.
Definition: ipc.hpp:54
int num
Index of the worksapce.
Definition: ipc.hpp:41
Binding event.
Definition: ipc.hpp:81
std::string loaded_config_file_name
Path to current config of i3.
Definition: ipc.hpp:65
Position
A position (of a bar?)
Definition: ipc.hpp:158
int32_t input_code
If the binding was configured with bindcode, this will be the key code that was given for the binding...
Definition: ipc.hpp:215
A window event.
Definition: ipc.hpp:203
EventType
Types of the events of i3.
Definition: ipc.hpp:75
uint32_t major
Major version of i3.
Definition: ipc.hpp:66
uint64_t xwindow_id
The X11 window ID of the actual client window inside this container. This field is set to null for sp...
Definition: ipc.hpp:170
Window toggled floating mode.
bool active
Is the output currently active.
Definition: ipc.hpp:55
sigc::signal< void, const binding_t & > signal_binding_event
Binding event signal.
Definition: ipc.hpp:334
Window toggled to fullscreen mode.
version_t get_version() const
Request a version of i3.
std::shared_ptr< container_t > get_tree() const
Request a tree of windows.
The bar sets the dock window type.
Window event.
Definition: ipc.hpp:79
std::map< std::string, uint32_t > colors
Contains key/value pairs of colors. Each value is a color code in format 0xRRGGBB.
Definition: ipc.hpp:233
rect_t deco_rect
The coordinates of the window decoration inside its container. These coordinates are relative to the ...
Definition: ipc.hpp:181
BarMode
A mode of a bar.
Definition: ipc.hpp:148
int height
Height of rectangle.
Definition: ipc.hpp:34
ContainerLayout layout
A type of the container's layout.
Definition: ipc.hpp:176
Bar config update event.
Definition: ipc.hpp:80
bool focused
Is the workspace is currently focused.
Definition: ipc.hpp:44
sigc::signal< void, const workspace_event_t & > signal_workspace_event
Workspace event signal.
Definition: ipc.hpp:329
rect_t rect
A size of the workspace.
Definition: ipc.hpp:46
sigc::signal< void, const bar_config_t & > signal_barconfig_update_event
Barconfig update event signal.
Definition: ipc.hpp:333
Workspace event.
Definition: ipc.hpp:76
std::string name
The internal name of this container. For all containers which are part of the tree structure down to ...
Definition: ipc.hpp:171
std::vector< std::shared_ptr< workspace_t > > get_workspaces() const
Request a list of workspaces.
int width
Width of rectangle.
Definition: ipc.hpp:33
A bar configuration.
Definition: ipc.hpp:224
std::string symbol
If this is a keyboard binding that was configured with bindsym, this field will contain the given sym...
Definition: ipc.hpp:216
int32_t get_main_socket_fd()
Get the fd of the main socket.
i3 IPC message buffer
Definition: ipc-util.hpp:95
std::string human_readable
Human redable version string.
Definition: ipc.hpp:64
rect_t geometry
The original geometry the window specified when i3 mapped it. Used when switching a window to floatin...
Definition: ipc.hpp:182
sigc::signal< void, EventType, const std::shared_ptr< const buf_t > & > signal_event
i3 event signal
Definition: ipc.hpp:335
bool visible
Is the workspace visible.
Definition: ipc.hpp:43
rect_t window_rect
The coordinates of the actual client window inside its container. These coordinates are relative to t...
Definition: ipc.hpp:180
std::string layout_raw
A "layout" field of TREE reply. NOT empty only if layout equals ContainerLayout::UNKNOWN.
Definition: ipc.hpp:177