aboutsummaryrefslogtreecommitdiffstats
path: root/include/sway
diff options
context:
space:
mode:
authorLibravatar Zandr Martin <zandrmartin@gmail.com>2016-09-02 13:46:19 -0500
committerLibravatar Zandr Martin <zandrmartin@gmail.com>2016-09-02 13:46:19 -0500
commit79ffea328c992c5109406771a59a9f016d85970d (patch)
tree5d965e72127f227ea0a38dc5c6e4fc14e08d9498 /include/sway
parentrefactor commands.c (diff)
parentMerge pull request #878 from lukaslihotzki/master (diff)
downloadsway-79ffea328c992c5109406771a59a9f016d85970d.tar.gz
sway-79ffea328c992c5109406771a59a9f016d85970d.tar.zst
sway-79ffea328c992c5109406771a59a9f016d85970d.zip
Merge branch 'master' of git://github.com/SirCmpwn/sway into commands-refactor
Diffstat (limited to 'include/sway')
-rw-r--r--include/sway/border.h28
-rw-r--r--include/sway/commands.h181
-rw-r--r--include/sway/config.h320
-rw-r--r--include/sway/container.h312
-rw-r--r--include/sway/criteria.h36
-rw-r--r--include/sway/extensions.h49
-rw-r--r--include/sway/focus.h43
-rw-r--r--include/sway/handlers.h11
-rw-r--r--include/sway/input.h23
-rw-r--r--include/sway/input_state.h102
-rw-r--r--include/sway/ipc-json.h14
-rw-r--r--include/sway/ipc-server.h41
-rw-r--r--include/sway/layout.h78
-rw-r--r--include/sway/output.h24
-rw-r--r--include/sway/resize.h14
-rw-r--r--include/sway/workspace.h22
16 files changed, 1298 insertions, 0 deletions
diff --git a/include/sway/border.h b/include/sway/border.h
new file mode 100644
index 00000000..c30c9da3
--- /dev/null
+++ b/include/sway/border.h
@@ -0,0 +1,28 @@
1#ifndef _SWAY_BORDER_H
2#define _SWAY_BORDER_H
3#include <wlc/wlc.h>
4#include "container.h"
5
6/**
7 * Border pixel buffer and corresponding geometry.
8 */
9struct border {
10 unsigned char *buffer;
11 struct wlc_geometry geometry;
12};
13
14/**
15 * Clear border buffer.
16 */
17void border_clear(struct border *border);
18
19/**
20 * Recursively update all of the borders within a container.
21 */
22void update_container_border(swayc_t *container);
23
24void render_view_borders(wlc_handle view);
25int get_font_text_height(const char *font);
26bool should_hide_top_border(swayc_t *con, double y);
27
28#endif
diff --git a/include/sway/commands.h b/include/sway/commands.h
new file mode 100644
index 00000000..f646c412
--- /dev/null
+++ b/include/sway/commands.h
@@ -0,0 +1,181 @@
1#ifndef _SWAY_COMMANDS_H
2#define _SWAY_COMMANDS_H
3#include <stdbool.h>
4#include <json-c/json.h>
5#include <wlc/wlc.h>
6#include "config.h"
7
8/**
9 * Indicates the result of a command's execution.
10 */
11enum cmd_status {
12 CMD_SUCCESS, /**< The command was successful */
13 CMD_FAILURE, /**< The command resulted in an error */
14 CMD_INVALID, /**< Unknown command or parser error */
15 CMD_DEFER, /**< Command execution deferred */
16 // Config Blocks
17 CMD_BLOCK_END,
18 CMD_BLOCK_MODE,
19 CMD_BLOCK_BAR,
20 CMD_BLOCK_BAR_COLORS,
21 CMD_BLOCK_INPUT
22};
23
24/**
25 * Stores the result of executing a command.
26 */
27struct cmd_results {
28 enum cmd_status status;
29 char *input;
30 /**
31 * Human friendly error message, or NULL on success
32 */
33 char *error;
34};
35
36enum expected_args {
37 EXPECTED_MORE_THAN,
38 EXPECTED_AT_LEAST,
39 EXPECTED_LESS_THAN,
40 EXPECTED_EQUAL_TO
41};
42
43struct cmd_results *checkarg(int argc, const char *name, enum expected_args type, int val);
44struct cmd_results *add_color(const char*, char*, const char*);
45void input_cmd_apply(struct input_config *input);
46void hide_view_in_scratchpad(swayc_t *sp_view);
47
48swayc_t *sp_view;
49int sp_index;
50
51/**
52 * Parse and handles a command.
53 */
54struct cmd_results *handle_command(char *command);
55/**
56 * Parse and handles a command during config file loading.
57 *
58 * Do not use this under normal conditions.
59 */
60struct cmd_results *config_command(char *command, enum cmd_status block);
61
62/**
63 * Allocates a cmd_results object.
64 */
65struct cmd_results *cmd_results_new(enum cmd_status status, const char* input, const char *error, ...);
66/**
67 * Frees a cmd_results object.
68 */
69void free_cmd_results(struct cmd_results *results);
70/**
71 * Serializes cmd_results to a JSON string.
72 *
73 * Free the JSON string later on.
74 */
75const char *cmd_results_to_json(struct cmd_results *results);
76
77void remove_view_from_scratchpad(swayc_t *);
78
79/**
80 * Actual command function signatures for individual .c files in commands/ directory.
81 */
82
83typedef struct cmd_results *sway_cmd(int argc, char **argv);
84
85sway_cmd cmd_assign;
86sway_cmd cmd_bar;
87sway_cmd cmd_bindcode;
88sway_cmd cmd_bindsym;
89sway_cmd cmd_border;
90sway_cmd cmd_client_focused;
91sway_cmd cmd_client_focused_inactive;
92sway_cmd cmd_client_unfocused;
93sway_cmd cmd_client_urgent;
94sway_cmd cmd_client_placeholder;
95sway_cmd cmd_client_background;
96sway_cmd cmd_debuglog;
97sway_cmd cmd_exec;
98sway_cmd cmd_exec_always;
99sway_cmd cmd_exit;
100sway_cmd cmd_floating;
101sway_cmd cmd_floating_maximum_size;
102sway_cmd cmd_floating_minimum_size;
103sway_cmd cmd_floating_mod;
104sway_cmd cmd_floating_scroll;
105sway_cmd cmd_focus;
106sway_cmd cmd_focus_follows_mouse;
107sway_cmd cmd_font;
108sway_cmd cmd_for_window;
109sway_cmd cmd_fullscreen;
110sway_cmd cmd_gaps;
111sway_cmd cmd_hide_edge_borders;
112sway_cmd cmd_include;
113sway_cmd cmd_input;
114sway_cmd cmd_kill;
115sway_cmd cmd_layout;
116sway_cmd cmd_log_colors;
117sway_cmd cmd_mode;
118sway_cmd cmd_mouse_warping;
119sway_cmd cmd_move;
120sway_cmd cmd_new_float;
121sway_cmd cmd_new_window;
122sway_cmd cmd_orientation;
123sway_cmd cmd_output;
124sway_cmd cmd_reload;
125sway_cmd cmd_resize;
126sway_cmd cmd_scratchpad;
127sway_cmd cmd_seamless_mouse;
128sway_cmd cmd_set;
129sway_cmd cmd_smart_gaps;
130sway_cmd cmd_split;
131sway_cmd cmd_splith;
132sway_cmd cmd_splitt;
133sway_cmd cmd_splitv;
134sway_cmd cmd_sticky;
135sway_cmd cmd_workspace;
136sway_cmd cmd_ws_auto_back_and_forth;
137sway_cmd cmd_workspace_layout;
138
139sway_cmd bar_cmd_binding_mode_indicator;
140sway_cmd bar_cmd_bindsym;
141sway_cmd bar_cmd_colors;
142sway_cmd bar_cmd_font;
143sway_cmd bar_cmd_mode;
144sway_cmd bar_cmd_modifier;
145sway_cmd bar_cmd_output;
146sway_cmd bar_cmd_height;
147sway_cmd bar_cmd_hidden_state;
148sway_cmd bar_cmd_id;
149sway_cmd bar_cmd_position;
150sway_cmd bar_cmd_separator_symbol;
151sway_cmd bar_cmd_status_command;
152sway_cmd bar_cmd_pango_markup;
153sway_cmd bar_cmd_strip_workspace_numbers;
154sway_cmd bar_cmd_swaybar_command;
155sway_cmd bar_cmd_tray_output;
156sway_cmd bar_cmd_tray_padding;
157sway_cmd bar_cmd_wrap_scroll;
158sway_cmd bar_cmd_workspace_buttons;
159
160sway_cmd bar_colors_cmd_active_workspace;
161sway_cmd bar_colors_cmd_background;
162sway_cmd bar_colors_cmd_background;
163sway_cmd bar_colors_cmd_binding_mode;
164sway_cmd bar_colors_cmd_focused_workspace;
165sway_cmd bar_colors_cmd_inactive_workspace;
166sway_cmd bar_colors_cmd_separator;
167sway_cmd bar_colors_cmd_statusline;
168sway_cmd bar_colors_cmd_urgent_workspace;
169
170sway_cmd input_cmd_accel_profile;
171sway_cmd input_cmd_click_method;
172sway_cmd input_cmd_drag_lock;
173sway_cmd input_cmd_dwt;
174sway_cmd input_cmd_events;
175sway_cmd input_cmd_middle_emulation;
176sway_cmd input_cmd_natural_scroll;
177sway_cmd input_cmd_pointer_accel;
178sway_cmd input_cmd_scroll_method;
179sway_cmd input_cmd_tap;
180
181#endif
diff --git a/include/sway/config.h b/include/sway/config.h
new file mode 100644
index 00000000..56deaf01
--- /dev/null
+++ b/include/sway/config.h
@@ -0,0 +1,320 @@
1#ifndef _SWAY_CONFIG_H
2#define _SWAY_CONFIG_H
3
4#define PID_WORKSPACE_TIMEOUT 60
5
6#include <libinput.h>
7#include <stdint.h>
8#include <wlc/geometry.h>
9#include <wlc/wlc.h>
10#include <xkbcommon/xkbcommon.h>
11#include <time.h>
12#include "wayland-desktop-shell-server-protocol.h"
13#include "list.h"
14#include "layout.h"
15#include "container.h"
16
17/**
18 * Describes a variable created via the `set` command.
19 */
20struct sway_variable {
21 char *name;
22 char *value;
23};
24
25/**
26 * A key binding and an associated command.
27 */
28struct sway_binding {
29 int order;
30 bool release;
31 bool bindcode;
32 list_t *keys;
33 uint32_t modifiers;
34 char *command;
35};
36
37/**
38 * A mouse binding and an associated command.
39 */
40struct sway_mouse_binding {
41 uint32_t button;
42 char *command;
43};
44
45/**
46 * A "mode" of keybindings created via the `mode` command.
47 */
48struct sway_mode {
49 char *name;
50 list_t *bindings;
51};
52
53/**
54 * libinput options for input devices
55 */
56struct input_config {
57 char *identifier;
58
59 int accel_profile;
60 int click_method;
61 int drag_lock;
62 int dwt;
63 int middle_emulation;
64 int natural_scroll;
65 float pointer_accel;
66 int scroll_method;
67 int send_events;
68 int tap;
69
70 bool capturable;
71 struct wlc_geometry region;
72};
73
74/**
75 * Size and position configuration for a particular output.
76 *
77 * This is set via the `output` command.
78 */
79struct output_config {
80 char *name;
81 int enabled;
82 int width, height;
83 int x, y;
84 int scale;
85 char *background;
86 char *background_option;
87};
88
89/**
90 * Maps a workspace name to an output name.
91 *
92 * Set via `workspace <x> output <y>`
93 */
94struct workspace_output {
95 char *output;
96 char *workspace;
97};
98
99struct pid_workspace {
100 pid_t *pid;
101 char *workspace;
102 time_t *time_added;
103};
104
105void pid_workspace_add(struct pid_workspace *pw);
106void free_pid_workspace(struct pid_workspace *pw);
107
108struct bar_config {
109 /**
110 * One of "dock", "hide", "invisible"
111 *
112 * Always visible in dock mode. Visible only when modifier key is held in hide mode.
113 * Never visible in invisible mode.
114 */
115 char *mode;
116 /**
117 * One of "show" or "hide".
118 *
119 * In "show" mode, it will always be shown on top of the active workspace.
120 */
121 char *hidden_state;
122 /**
123 * Id name used to identify the bar through IPC.
124 *
125 * Defaults to bar-x, where x corresponds to the position of the
126 * embedding bar block in the config file (bar-0, bar-1, ...).
127 */
128 char *id;
129 uint32_t modifier;
130 list_t *outputs;
131 enum desktop_shell_panel_position position;
132 list_t *bindings;
133 char *status_command;
134 bool pango_markup;
135 char *swaybar_command;
136 char *font;
137 int height; // -1 not defined
138 int tray_padding;
139 bool workspace_buttons;
140 bool wrap_scroll;
141 char *separator_symbol;
142 bool strip_workspace_numbers;
143 bool binding_mode_indicator;
144 bool verbose;
145 pid_t pid;
146 struct {
147 char background[10];
148 char statusline[10];
149 char separator[10];
150 char focused_workspace_border[10];
151 char focused_workspace_bg[10];
152 char focused_workspace_text[10];
153 char active_workspace_border[10];
154 char active_workspace_bg[10];
155 char active_workspace_text[10];
156 char inactive_workspace_border[10];
157 char inactive_workspace_bg[10];
158 char inactive_workspace_text[10];
159 char urgent_workspace_border[10];
160 char urgent_workspace_bg[10];
161 char urgent_workspace_text[10];
162 char binding_mode_border[10];
163 char binding_mode_bg[10];
164 char binding_mode_text[10];
165 } colors;
166};
167
168struct border_colors {
169 uint32_t border;
170 uint32_t background;
171 uint32_t text;
172 uint32_t indicator;
173 uint32_t child_border;
174};
175
176enum edge_border_types {
177 E_NONE, /**< Don't hide edge borders */
178 E_VERTICAL, /**< hide vertical edge borders */
179 E_HORIZONTAL, /**< hide horizontal edge borders */
180 E_BOTH /**< hide vertical and horizontal edge borders */
181};
182
183/**
184 * The configuration struct. The result of loading a config file.
185 */
186struct sway_config {
187 list_t *symbols;
188 list_t *modes;
189 list_t *bars;
190 list_t *cmd_queue;
191 list_t *workspace_outputs;
192 list_t *pid_workspaces;
193 list_t *output_configs;
194 list_t *input_configs;
195 list_t *criteria;
196 list_t *active_bar_modifiers;
197 struct sway_mode *current_mode;
198 struct bar_config *current_bar;
199 uint32_t floating_mod;
200 uint32_t dragging_key;
201 uint32_t resizing_key;
202 char *floating_scroll_up_cmd;
203 char *floating_scroll_down_cmd;
204 char *floating_scroll_left_cmd;
205 char *floating_scroll_right_cmd;
206 enum swayc_layouts default_orientation;
207 enum swayc_layouts default_layout;
208 char *font;
209 int font_height;
210
211 // Flags
212 bool focus_follows_mouse;
213 bool mouse_warping;
214 bool active;
215 bool failed;
216 bool reloading;
217 bool reading;
218 bool auto_back_and_forth;
219 bool seamless_mouse;
220
221 bool edge_gaps;
222 bool smart_gaps;
223 int gaps_inner;
224 int gaps_outer;
225
226 list_t *config_chain;
227 const char *current_config;
228
229 enum swayc_border_types border;
230 enum swayc_border_types floating_border;
231 int border_thickness;
232 int floating_border_thickness;
233 enum edge_border_types hide_edge_borders;
234
235 // border colors
236 struct {
237 struct border_colors focused;
238 struct border_colors focused_inactive;
239 struct border_colors unfocused;
240 struct border_colors urgent;
241 struct border_colors placeholder;
242 uint32_t background;
243 } border_colors;
244
245 // floating view
246 int32_t floating_maximum_width;
247 int32_t floating_maximum_height;
248 int32_t floating_minimum_width;
249 int32_t floating_minimum_height;
250};
251
252/**
253 * Loads the main config from the given path. is_active should be true when
254 * reloading the config.
255 */
256bool load_main_config(const char *path, bool is_active);
257
258/**
259 * Loads an included config. Can only be used after load_main_config.
260 */
261bool load_include_configs(const char *path, struct sway_config *config);
262
263/**
264 * Reads the config from the given FILE.
265 */
266bool read_config(FILE *file, struct sway_config *config);
267
268/**
269 * Free config struct
270 */
271void free_config(struct sway_config *config);
272/**
273 * Does variable replacement for a string based on the config's currently loaded variables.
274 */
275char *do_var_replacement(char *str);
276
277int input_identifier_cmp(const void *item, const void *data);
278void merge_input_config(struct input_config *dst, struct input_config *src);
279void apply_input_config(struct input_config *ic, struct libinput_device *dev);
280void free_input_config(struct input_config *ic);
281
282int output_name_cmp(const void *item, const void *data);
283void merge_output_config(struct output_config *dst, struct output_config *src);
284/** Sets up a WLC output handle based on a given output_config.
285 */
286void apply_output_config(struct output_config *oc, swayc_t *output);
287void free_output_config(struct output_config *oc);
288
289/**
290 * Updates the list of active bar modifiers
291 */
292void update_active_bar_modifiers(void);
293
294int workspace_output_cmp_workspace(const void *a, const void *b);
295
296int sway_binding_cmp(const void *a, const void *b);
297int sway_binding_cmp_qsort(const void *a, const void *b);
298int sway_binding_cmp_keys(const void *a, const void *b);
299void free_sway_binding(struct sway_binding *sb);
300struct sway_binding *sway_binding_dup(struct sway_binding *sb);
301
302int sway_mouse_binding_cmp(const void *a, const void *b);
303int sway_mouse_binding_cmp_qsort(const void *a, const void *b);
304int sway_mouse_binding_cmp_buttons(const void *a, const void *b);
305void free_sway_mouse_binding(struct sway_mouse_binding *smb);
306
307void load_swaybars();
308void terminate_swaybg(pid_t pid);
309
310/**
311 * Allocate and initialize default bar configuration.
312 */
313struct bar_config *default_bar_config(void);
314
315/**
316 * Global config singleton.
317 */
318extern struct sway_config *config;
319
320#endif
diff --git a/include/sway/container.h b/include/sway/container.h
new file mode 100644
index 00000000..4dd7f3a0
--- /dev/null
+++ b/include/sway/container.h
@@ -0,0 +1,312 @@
1#ifndef _SWAY_CONTAINER_H
2#define _SWAY_CONTAINER_H
3#include <sys/types.h>
4#include <wlc/wlc.h>
5
6#include "list.h"
7
8typedef struct sway_container swayc_t;
9
10extern swayc_t root_container;
11
12/**
13 * Different kinds of containers.
14 *
15 * This enum is in order. A container will never be inside of a container below
16 * it on this list.
17 */
18enum swayc_types {
19 C_ROOT, /**< The root container. Only one of these ever exists. */
20 C_OUTPUT, /**< An output (aka monitor, head, etc). */
21 C_WORKSPACE, /**< A workspace. */
22 C_CONTAINER, /**< A manually created container. */
23 C_VIEW, /**< A view (aka window). */
24 // Keep last
25 C_TYPES,
26};
27
28/**
29 * Different ways to arrange a container.
30 */
31enum swayc_layouts {
32 L_NONE, /**< Used for containers that have no layout (views, root) */
33 L_HORIZ,
34 L_VERT,
35 L_STACKED,
36 L_TABBED,
37 L_FLOATING, /**< A psuedo-container, removed from the tree, to hold floating windows */
38 // Keep last
39 L_LAYOUTS,
40};
41
42enum swayc_border_types {
43 B_NONE, /**< No border */
44 B_PIXEL, /**< 1px border */
45 B_NORMAL /**< Normal border with title bar */
46};
47
48/**
49 * Stores information about a container.
50 *
51 * The tree is made of these. Views are containers that cannot have children.
52 */
53struct sway_container {
54 /**
55 * If this container maps to a WLC object, this is set to that object's
56 * handle. Otherwise, NULL.
57 */
58 wlc_handle handle;
59
60 enum swayc_types type;
61 enum swayc_layouts layout;
62 enum swayc_layouts prev_layout;
63
64 /**
65 * Width and height of this container, without borders or gaps.
66 */
67 double width, height;
68
69 /**
70 * Views may request geometry, which is stored in this and ignored until
71 * the views are floated.
72 */
73 int desired_width, desired_height;
74
75 /**
76 * The coordinates that this view appear at, relative to the output they
77 * are located on (output containers have absolute coordinates).
78 */
79 double x, y;
80
81 /**
82 * Cached geometry used to store view/container geometry when switching
83 * between tabbed/stacked and horizontal/vertical layouts.
84 */
85 struct wlc_geometry cached_geometry;
86
87 /**
88 * False if this view is invisible. It could be in the scratchpad or on a
89 * workspace that is not shown.
90 */
91 bool visible;
92 bool is_floating;
93 bool is_focused;
94 bool sticky; // floating view always visible on its output
95
96 // Attributes that mostly views have.
97 char *name;
98 char *class;
99 char *app_id;
100
101 // Used by output containers to keep track of swaybg child processes.
102 pid_t bg_pid;
103
104 int gaps;
105
106 list_t *children;
107 /**
108 * Children of this container that are floated.
109 */
110 list_t *floating;
111 /**
112 * Unmanaged view handles in this container.
113 */
114 list_t *unmanaged;
115
116 /**
117 * The parent of this container. NULL for the root container.
118 */
119 struct sway_container *parent;
120 /**
121 * Which of this container's children has focus.
122 */
123 struct sway_container *focused;
124 /**
125 * If this container's children include a fullscreen view, this is that view.
126 */
127 struct sway_container *fullscreen;
128 /**
129 * If this container is a view, this may be set to the window's decoration
130 * buffer (or NULL).
131 */
132 struct border *border;
133 enum swayc_border_types border_type;
134 struct wlc_geometry border_geometry;
135 struct wlc_geometry title_bar_geometry;
136 struct wlc_geometry actual_geometry;
137 int border_thickness;
138};
139
140enum visibility_mask {
141 VISIBLE = true
142} visible;
143
144/**
145 * Allocates a new output container.
146 */
147swayc_t *new_output(wlc_handle handle);
148/**
149 * Allocates a new workspace container.
150 */
151swayc_t *new_workspace(swayc_t *output, const char *name);
152/**
153 * Allocates a new container and places a child into it.
154 *
155 * This is used from the split command, which creates a new container with the
156 * requested layout and replaces the focused container in the tree with the new
157 * one. Then the removed container is added as a child of the new container.
158 */
159swayc_t *new_container(swayc_t *child, enum swayc_layouts layout);
160/**
161 * Allocates a new view container.
162 *
163 * Pass in a sibling view, or a workspace to become this container's parent.
164 */
165swayc_t *new_view(swayc_t *sibling, wlc_handle handle);
166/**
167 * Allocates a new floating view in the active workspace.
168 */
169swayc_t *new_floating_view(wlc_handle handle);
170
171void floating_view_sane_size(swayc_t *view);
172
173/**
174 * Frees an output's container.
175 */
176swayc_t *destroy_output(swayc_t *output);
177/**
178 * Destroys a workspace container and returns the parent pointer, or NULL.
179 */
180swayc_t *destroy_workspace(swayc_t *workspace);
181/**
182 * Destroys a container and all empty parents. Returns the topmost non-empty
183 * parent container, or NULL.
184 */
185swayc_t *destroy_container(swayc_t *container);
186/**
187 * Destroys a view container and all empty parents. Returns the topmost
188 * non-empty parent container, or NULL.
189 */
190swayc_t *destroy_view(swayc_t *view);
191
192/**
193 * Finds a container based on test criteria. Returns the first container that
194 * passes the test.
195 */
196swayc_t *swayc_by_test(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data);
197/**
198 * Finds a parent container with the given swayc_type.
199 */
200swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types);
201/**
202 * Finds a parent with the given swayc_layout.
203 */
204swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts);
205/**
206 * Finds the bottom-most focused container of a type.
207 */
208swayc_t *swayc_focus_by_type(swayc_t *container, enum swayc_types);
209/**
210 * Finds the bottom-most focused container of a layout.
211 */
212swayc_t *swayc_focus_by_layout(swayc_t *container, enum swayc_layouts);
213
214/**
215 * Gets the swayc_t associated with a wlc_handle.
216 */
217swayc_t *swayc_by_handle(wlc_handle handle);
218/**
219 * Gets the named swayc_t.
220 */
221swayc_t *swayc_by_name(const char *name);
222/**
223 * Gets the active output's container.
224 */
225swayc_t *swayc_active_output(void);
226/**
227 * Gets the active workspace's container.
228 */
229swayc_t *swayc_active_workspace(void);
230/**
231 * Gets the workspace for the given view container.
232 */
233swayc_t *swayc_active_workspace_for(swayc_t *view);
234/**
235 * Finds the container currently underneath the pointer.
236 */
237swayc_t *container_under_pointer(void);
238
239/**
240 * Returns true if a container is fullscreen.
241 */
242bool swayc_is_fullscreen(swayc_t *view);
243/**
244 * Returns true if this view is focused.
245 */
246bool swayc_is_active(swayc_t *view);
247/**
248 * Returns true if the parent is an ancestor of the child.
249 */
250bool swayc_is_parent_of(swayc_t *parent, swayc_t *child);
251/**
252 * Returns true if the child is a desecendant of the parent.
253 */
254bool swayc_is_child_of(swayc_t *child, swayc_t *parent);
255
256/**
257 * Returns true if this container is an empty workspace.
258 */
259bool swayc_is_empty_workspace(swayc_t *container);
260
261/**
262 * Returns the top most tabbed or stacked parent container. Returns NULL if
263 * view is not in a tabbed/stacked layout.
264 */
265swayc_t *swayc_tabbed_stacked_ancestor(swayc_t *view);
266
267/**
268 * Returns the immediate tabbed or stacked parent container. Returns NULL if
269 * view is not directly in a tabbed/stacked layout.
270 */
271swayc_t *swayc_tabbed_stacked_parent(swayc_t *view);
272
273/**
274 * Returns the gap (padding) of the container.
275 *
276 * This returns the inner gaps for a view, the outer gaps for a workspace, and
277 * 0 otherwise.
278 */
279int swayc_gap(swayc_t *container);
280
281/**
282 * Maps a container's children over a function.
283 */
284void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *);
285
286/**
287 * Set a view as visible or invisible.
288 *
289 * This will perform the required wlc calls as well; it is not sufficient to
290 * simply toggle the boolean in swayc_t.
291 */
292void set_view_visibility(swayc_t *view, void *data);
293/**
294 * Set the gaps value for a view.
295 */
296void set_gaps(swayc_t *view, void *amount);
297/**
298 * Add to the gaps value for a view.
299 */
300void add_gaps(swayc_t *view, void *amount);
301
302/**
303 * Issue wlc calls to make the visibility of a container consistent.
304 */
305void update_visibility(swayc_t *container);
306
307/**
308 * Close all child views of container
309 */
310void close_views(swayc_t *container);
311
312#endif
diff --git a/include/sway/criteria.h b/include/sway/criteria.h
new file mode 100644
index 00000000..5c71d172
--- /dev/null
+++ b/include/sway/criteria.h
@@ -0,0 +1,36 @@
1#ifndef _SWAY_CRITERIA_H
2#define _SWAY_CRITERIA_H
3
4#include "container.h"
5#include "list.h"
6
7/**
8 * Maps criteria (as a list of criteria tokens) to a command list.
9 *
10 * A list of tokens together represent a single criteria string (e.g.
11 * '[class="abc" title="xyz"]' becomes two criteria tokens).
12 *
13 * for_window: Views matching all criteria will have the bound command list
14 * executed on them.
15 *
16 * Set via `for_window <criteria> <cmd list>`.
17 */
18struct criteria {
19 list_t *tokens; // struct crit_token, contains compiled regex.
20 char *crit_raw; // entire criteria string (for logging)
21
22 char *cmdlist;
23};
24
25int criteria_cmp(const void *item, const void *data);
26void free_criteria(struct criteria *crit);
27
28// Pouplate list with crit_tokens extracted from criteria string, returns error
29// string or NULL if successful.
30char *extract_crit_tokens(list_t *tokens, const char *criteria);
31
32// Returns list of criteria that match given container. These criteria have
33// been set with `for_window` commands and have an associated cmdlist.
34list_t *criteria_for(swayc_t *cont);
35
36#endif
diff --git a/include/sway/extensions.h b/include/sway/extensions.h
new file mode 100644
index 00000000..f6b0c00e
--- /dev/null
+++ b/include/sway/extensions.h
@@ -0,0 +1,49 @@
1#ifndef _SWAY_EXTENSIONS_H
2#define _SWAY_EXTENSIONS_H
3
4#include <wayland-server.h>
5#include <wlc/wlc-wayland.h>
6#include "wayland-desktop-shell-server-protocol.h"
7#include "list.h"
8
9struct background_config {
10 wlc_handle output;
11 wlc_resource surface;
12 // we need the wl_resource of the surface in the destructor
13 struct wl_resource *wl_surface_res;
14 struct wl_client *client;
15 wlc_handle handle;
16};
17
18struct panel_config {
19 // wayland resource used in callbacks, is used to track this panel
20 struct wl_resource *wl_resource;
21 wlc_handle output;
22 wlc_resource surface;
23 // we need the wl_resource of the surface in the destructor
24 struct wl_resource *wl_surface_res;
25 enum desktop_shell_panel_position panel_position;
26 // used to determine if client is a panel
27 struct wl_client *client;
28 // wlc handle for this panel's surface, not set until panel is created
29 wlc_handle handle;
30};
31
32struct desktop_shell_state {
33 list_t *backgrounds;
34 list_t *panels;
35 list_t *lock_surfaces;
36 bool is_locked;
37};
38
39struct swaylock_state {
40 bool active;
41 wlc_handle output;
42 wlc_resource surface;
43};
44
45extern struct desktop_shell_state desktop_shell;
46
47void register_extensions(void);
48
49#endif
diff --git a/include/sway/focus.h b/include/sway/focus.h
new file mode 100644
index 00000000..b532edc2
--- /dev/null
+++ b/include/sway/focus.h
@@ -0,0 +1,43 @@
1#ifndef _SWAY_FOCUS_H
2#define _SWAY_FOCUS_H
3enum movement_direction {
4 MOVE_LEFT,
5 MOVE_RIGHT,
6 MOVE_UP,
7 MOVE_DOWN,
8 MOVE_PARENT,
9 MOVE_CHILD
10};
11
12#include "container.h"
13
14// focused_container - the container found by following the `focused` pointer
15// from a given container to a container with `is_focused` boolean set
16// ---
17// focused_view - the container found by following the `focused` pointer from a
18// given container to a view.
19// ---
20
21swayc_t *get_focused_container(swayc_t *parent);
22swayc_t *get_focused_view(swayc_t *parent);
23swayc_t *get_focused_float(swayc_t *ws);
24
25// a special-case function to get the focused view, regardless
26// of whether it's tiled or floating
27swayc_t *get_focused_view_include_floating(swayc_t *parent);
28
29bool set_focused_container(swayc_t *container);
30bool set_focused_container_for(swayc_t *ancestor, swayc_t *container);
31
32// lock focused container/view. locked by windows with OVERRIDE attribute
33// and unlocked when they are destroyed
34
35extern bool locked_container_focus;
36
37// Prevents wss from being destroyed on focus switch
38extern bool suspend_workspace_cleanup;
39
40bool move_focus(enum movement_direction direction);
41
42#endif
43
diff --git a/include/sway/handlers.h b/include/sway/handlers.h
new file mode 100644
index 00000000..956b98f4
--- /dev/null
+++ b/include/sway/handlers.h
@@ -0,0 +1,11 @@
1#ifndef _SWAY_HANDLERS_H
2#define _SWAY_HANDLERS_H
3#include "container.h"
4#include <stdbool.h>
5#include <wlc/wlc.h>
6
7void register_wlc_handlers();
8
9extern uint32_t keys_pressed[32];
10
11#endif
diff --git a/include/sway/input.h b/include/sway/input.h
new file mode 100644
index 00000000..4ed9bffe
--- /dev/null
+++ b/include/sway/input.h
@@ -0,0 +1,23 @@
1#ifndef _SWAY_INPUT_H
2#define _SWAY_INPUT_H
3
4#include <libinput.h>
5#include "config.h"
6#include "list.h"
7
8struct input_config *new_input_config(const char* identifier);
9
10char* libinput_dev_unique_id(struct libinput_device *dev);
11
12/**
13 * Global input device list.
14 */
15extern list_t *input_devices;
16
17/**
18 * Pointer used when reading input blocked.
19 * Shared so that it can be cleared from commands.c when closing the block
20 */
21extern struct input_config *current_input_config;
22
23#endif
diff --git a/include/sway/input_state.h b/include/sway/input_state.h
new file mode 100644
index 00000000..903301fb
--- /dev/null
+++ b/include/sway/input_state.h
@@ -0,0 +1,102 @@
1#ifndef _SWAY_KEY_STATE_H
2#define _SWAY_KEY_STATE_H
3#include <stdbool.h>
4#include <stdint.h>
5#include "container.h"
6
7/* Keyboard state */
8
9// returns true if key has been pressed, otherwise false
10bool check_key(uint32_t key_sym, uint32_t key_code);
11
12// returns true if key_sym matches latest released key.
13bool check_released_key(uint32_t key_sym);
14
15// sets a key as pressed
16void press_key(uint32_t key_sym, uint32_t key_code);
17
18// unsets a key as pressed
19void release_key(uint32_t key_sym, uint32_t key_code);
20
21
22/* Pointer state */
23
24enum pointer_values {
25 M_LEFT_CLICK = 272,
26 M_RIGHT_CLICK = 273,
27 M_SCROLL_CLICK = 274,
28 M_SCROLL_UP = 275,
29 M_SCROLL_DOWN = 276,
30};
31
32enum pointer_mode {
33 // Target
34 M_FLOATING = 1,
35 M_TILING = 2,
36 // Action
37 M_DRAGGING = 4,
38 M_RESIZING = 8,
39};
40
41struct pointer_button_state {
42 bool held;
43 // state at the point it was pressed
44 int x, y;
45 swayc_t *view;
46};
47
48extern struct pointer_state {
49 // mouse clicks
50 struct pointer_button_state left;
51 struct pointer_button_state right;
52 struct pointer_button_state scroll;
53
54 // change in pointer position
55 struct {
56 int x, y;
57 } delta;
58
59 // view pointer is currently over
60 swayc_t *view;
61
62 // Pointer mode
63 int mode;
64} pointer_state;
65
66enum modifier_state {
67 MOD_STATE_UNCHANGED = 0,
68 MOD_STATE_PRESSED = 1,
69 MOD_STATE_RELEASED = 2
70};
71
72void pointer_position_set(struct wlc_origin *new_origin, bool force_focus);
73void center_pointer_on(swayc_t *view);
74
75// on button release unset mode depending on the button.
76// on button press set mode conditionally depending on the button
77void pointer_mode_set(uint32_t button, bool condition);
78
79// Update mode in mouse motion
80void pointer_mode_update(void);
81
82// Reset mode on any keypress;
83void pointer_mode_reset(void);
84
85void input_init(void);
86
87/**
88 * Check if state of mod changed from current state to new_state.
89 *
90 * Returns MOD_STATE_UNCHANGED if the state didn't change, MOD_STATE_PRESSED if
91 * the state changed to pressed and MOD_STATE_RELEASED if the state changed to
92 * released.
93 */
94uint32_t modifier_state_changed(uint32_t new_state, uint32_t mod);
95
96/**
97 * Update the current modifiers state to new_state.
98 */
99void modifiers_state_update(uint32_t new_state);
100
101#endif
102
diff --git a/include/sway/ipc-json.h b/include/sway/ipc-json.h
new file mode 100644
index 00000000..02b07a23
--- /dev/null
+++ b/include/sway/ipc-json.h
@@ -0,0 +1,14 @@
1#ifndef _SWAY_IPC_JSON_H
2#define _SWAY_IPC_JSON_H
3
4#include <json-c/json.h>
5#include "config.h"
6#include "container.h"
7
8json_object *ipc_json_get_version();
9json_object *ipc_json_describe_bar_config(struct bar_config *bar);
10json_object *ipc_json_describe_container(swayc_t *c);
11json_object *ipc_json_describe_container_recursive(swayc_t *c);
12json_object *ipc_json_describe_window(swayc_t *c);
13
14#endif
diff --git a/include/sway/ipc-server.h b/include/sway/ipc-server.h
new file mode 100644
index 00000000..1d199134
--- /dev/null
+++ b/include/sway/ipc-server.h
@@ -0,0 +1,41 @@
1#ifndef _SWAY_IPC_SERVER_H
2#define _SWAY_IPC_SERVER_H
3
4#include <wlc/wlc.h>
5
6#include "container.h"
7#include "config.h"
8#include "ipc.h"
9
10void ipc_init(void);
11void ipc_terminate(void);
12struct sockaddr_un *ipc_user_sockaddr(void);
13
14void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change);
15void ipc_event_barconfig_update(struct bar_config *bar);
16/**
17 * Send IPC mode event to all listening clients
18 */
19void ipc_event_mode(const char *mode);
20/**
21 * Send IPC window change event
22 */
23void ipc_event_window(swayc_t *window, const char *change);
24/**
25 * Sends an IPC modifier event to all listening clients. The modifier event
26 * includes a key 'change' with the value of state and a key 'modifier' with
27 * the name of that modifier.
28 */
29void ipc_event_modifier(uint32_t modifier, const char *state);
30/**
31 * Send IPC keyboard binding event.
32 */
33void ipc_event_binding_keyboard(struct sway_binding *sb);
34const char *swayc_type_string(enum swayc_types type);
35
36/**
37 * Send pixel data to registered clients.
38 */
39void ipc_get_pixels(wlc_handle output);
40
41#endif
diff --git a/include/sway/layout.h b/include/sway/layout.h
new file mode 100644
index 00000000..b982365c
--- /dev/null
+++ b/include/sway/layout.h
@@ -0,0 +1,78 @@
1#ifndef _SWAY_LAYOUT_H
2#define _SWAY_LAYOUT_H
3
4#include <wlc/wlc.h>
5#include "log.h"
6#include "list.h"
7#include "container.h"
8#include "focus.h"
9
10extern list_t *scratchpad;
11
12extern int min_sane_w;
13extern int min_sane_h;
14
15// Set initial values for root_container
16void init_layout(void);
17
18// Returns the index of child for its parent
19int index_child(const swayc_t *child);
20
21// Adds child to parent, if parent has no focus, it is set to child
22// parent must be of type C_WORKSPACE or C_CONTAINER
23void add_child(swayc_t *parent, swayc_t *child);
24
25// Adds child to parent at index, if parent has no focus, it is set to child
26// parent must be of type C_WORKSPACE or C_CONTAINER
27void insert_child(swayc_t *parent, swayc_t *child, int index);
28
29// Adds child as floating window to ws, if there is no focus it is set to child.
30// ws must be of type C_WORKSPACE
31void add_floating(swayc_t *ws, swayc_t *child);
32
33// insert child after sibling in parents children.
34swayc_t *add_sibling(swayc_t *sibling, swayc_t *child);
35
36// Replace child with new_child in parents children
37// new_child will inherit childs geometry, childs geometry will be reset
38// if parents focus is on child, it will be changed to new_child
39swayc_t *replace_child(swayc_t *child, swayc_t *new_child);
40
41// Remove child from its parent, if focus is on child, focus will be changed to
42// a sibling, or to a floating window, or NULL
43swayc_t *remove_child(swayc_t *child);
44
45// 2 containers are swapped, they inherit eachothers focus
46void swap_container(swayc_t *a, swayc_t *b);
47
48// 2 Containers geometry are swapped, used with `swap_container`
49void swap_geometry(swayc_t *a, swayc_t *b);
50
51void move_container(swayc_t* container, enum movement_direction direction);
52void move_container_to(swayc_t* container, swayc_t* destination);
53void move_workspace_to(swayc_t* workspace, swayc_t* destination);
54
55// Layout
56/**
57 * Update child container geometries when switching between layouts.
58 */
59void update_layout_geometry(swayc_t *parent, enum swayc_layouts prev_layout);
60void update_geometry(swayc_t *view);
61void arrange_windows(swayc_t *container, double width, double height);
62void arrange_backgrounds(void);
63
64swayc_t *get_focused_container(swayc_t *parent);
65swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir);
66swayc_t *get_swayc_in_direction_under(swayc_t *container, enum movement_direction dir, swayc_t *limit);
67
68void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge);
69
70void layout_log(const swayc_t *c, int depth);
71void swayc_log(log_importance_t verbosity, swayc_t *cont, const char* format, ...) __attribute__((format(printf,3,4)));
72
73/**
74 * Get default layout.
75 */
76enum swayc_layouts default_layout(swayc_t *output);
77
78#endif
diff --git a/include/sway/output.h b/include/sway/output.h
new file mode 100644
index 00000000..e8afd5ed
--- /dev/null
+++ b/include/sway/output.h
@@ -0,0 +1,24 @@
1#ifndef _SWAY_OUTPUT_H
2#define _SWAY_OUTPUT_H
3
4#include "container.h"
5#include "focus.h"
6
7// Position is absolute coordinates on the edge where the adjacent output
8// should be searched for.
9swayc_t *output_by_name(const char* name, const struct wlc_point *abs_pos);
10swayc_t *swayc_adjacent_output(swayc_t *output, enum movement_direction dir, const struct wlc_point *abs_pos, bool pick_closest);
11
12// Place absolute coordinates for given container into given wlc_point.
13void get_absolute_position(swayc_t *container, struct wlc_point *point);
14
15// Place absolute coordinates for the center point of given container into
16// given wlc_point.
17void get_absolute_center_position(swayc_t *container, struct wlc_point *point);
18
19// stable sort workspaces on this output
20void sort_workspaces(swayc_t *output);
21
22void output_get_scaled_size(wlc_handle handle, struct wlc_size *size);
23
24#endif
diff --git a/include/sway/resize.h b/include/sway/resize.h
new file mode 100644
index 00000000..0d382994
--- /dev/null
+++ b/include/sway/resize.h
@@ -0,0 +1,14 @@
1#ifndef _SWAY_RESIZE_H
2#define _SWAY_RESIZE_H
3#include <stdbool.h>
4
5enum resize_dim_types {
6 RESIZE_DIM_PX,
7 RESIZE_DIM_PPT,
8 RESIZE_DIM_DEFAULT,
9};
10
11bool set_size(int dimension, bool use_width);
12bool resize(int dimension, bool use_width, enum resize_dim_types dim_type);
13
14#endif
diff --git a/include/sway/workspace.h b/include/sway/workspace.h
new file mode 100644
index 00000000..c268fafa
--- /dev/null
+++ b/include/sway/workspace.h
@@ -0,0 +1,22 @@
1#ifndef _SWAY_WORKSPACE_H
2#define _SWAY_WORKSPACE_H
3
4#include <wlc/wlc.h>
5#include <unistd.h>
6#include "list.h"
7#include "layout.h"
8
9extern char *prev_workspace_name;
10
11char *workspace_next_name(const char *output_name);
12swayc_t *workspace_create(const char*);
13swayc_t *workspace_by_name(const char*);
14swayc_t *workspace_by_number(const char*);
15bool workspace_switch(swayc_t*);
16swayc_t *workspace_output_next();
17swayc_t *workspace_next();
18swayc_t *workspace_output_prev();
19swayc_t *workspace_prev();
20swayc_t *workspace_for_pid(pid_t pid);
21
22#endif