diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/sway/commands.h | 10 | ||||
-rw-r--r-- | include/sway/config.h | 405 |
2 files changed, 415 insertions, 0 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h index df5c6859..b1f0423d 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h | |||
@@ -47,6 +47,16 @@ struct cmd_results *checkarg(int argc, const char *name, | |||
47 | */ | 47 | */ |
48 | struct cmd_results *handle_command(char *command); | 48 | struct cmd_results *handle_command(char *command); |
49 | /** | 49 | /** |
50 | * Parse and handles a command during config file loading. | ||
51 | * | ||
52 | * Do not use this under normal conditions. | ||
53 | */ | ||
54 | struct cmd_results *config_command(char *command, enum cmd_status block); | ||
55 | /* | ||
56 | * Parses a command policy rule. | ||
57 | */ | ||
58 | struct cmd_results *config_commands_command(char *exec); | ||
59 | /** | ||
50 | * Allocates a cmd_results object. | 60 | * Allocates a cmd_results object. |
51 | */ | 61 | */ |
52 | struct cmd_results *cmd_results_new(enum cmd_status status, const char* input, const char *error, ...); | 62 | struct cmd_results *cmd_results_new(enum cmd_status status, const char* input, const char *error, ...); |
diff --git a/include/sway/config.h b/include/sway/config.h new file mode 100644 index 00000000..56b4e637 --- /dev/null +++ b/include/sway/config.h | |||
@@ -0,0 +1,405 @@ | |||
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 "list.h" | ||
13 | #include "layout.h" | ||
14 | #include "container.h" | ||
15 | |||
16 | /** | ||
17 | * Describes a variable created via the `set` command. | ||
18 | */ | ||
19 | struct sway_variable { | ||
20 | char *name; | ||
21 | char *value; | ||
22 | }; | ||
23 | |||
24 | /** | ||
25 | * A key binding and an associated command. | ||
26 | */ | ||
27 | struct sway_binding { | ||
28 | int order; | ||
29 | bool release; | ||
30 | bool bindcode; | ||
31 | list_t *keys; | ||
32 | uint32_t modifiers; | ||
33 | char *command; | ||
34 | }; | ||
35 | |||
36 | /** | ||
37 | * A mouse binding and an associated command. | ||
38 | */ | ||
39 | struct sway_mouse_binding { | ||
40 | uint32_t button; | ||
41 | char *command; | ||
42 | }; | ||
43 | |||
44 | /** | ||
45 | * A "mode" of keybindings created via the `mode` command. | ||
46 | */ | ||
47 | struct sway_mode { | ||
48 | char *name; | ||
49 | list_t *bindings; | ||
50 | }; | ||
51 | |||
52 | /** | ||
53 | * libinput options for input devices | ||
54 | */ | ||
55 | struct input_config { | ||
56 | char *identifier; | ||
57 | |||
58 | int accel_profile; | ||
59 | int click_method; | ||
60 | int drag_lock; | ||
61 | int dwt; | ||
62 | int left_handed; | ||
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 | */ | ||
79 | struct 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 | */ | ||
94 | struct workspace_output { | ||
95 | char *output; | ||
96 | char *workspace; | ||
97 | }; | ||
98 | |||
99 | struct pid_workspace { | ||
100 | pid_t *pid; | ||
101 | char *workspace; | ||
102 | time_t *time_added; | ||
103 | }; | ||
104 | |||
105 | struct bar_config { | ||
106 | /** | ||
107 | * One of "dock", "hide", "invisible" | ||
108 | * | ||
109 | * Always visible in dock mode. Visible only when modifier key is held in hide mode. | ||
110 | * Never visible in invisible mode. | ||
111 | */ | ||
112 | char *mode; | ||
113 | /** | ||
114 | * One of "show" or "hide". | ||
115 | * | ||
116 | * In "show" mode, it will always be shown on top of the active workspace. | ||
117 | */ | ||
118 | char *hidden_state; | ||
119 | /** | ||
120 | * Id name used to identify the bar through IPC. | ||
121 | * | ||
122 | * Defaults to bar-x, where x corresponds to the position of the | ||
123 | * embedding bar block in the config file (bar-0, bar-1, ...). | ||
124 | */ | ||
125 | char *id; | ||
126 | uint32_t modifier; | ||
127 | list_t *outputs; | ||
128 | //enum desktop_shell_panel_position position; // TODO | ||
129 | list_t *bindings; | ||
130 | char *status_command; | ||
131 | bool pango_markup; | ||
132 | char *swaybar_command; | ||
133 | char *font; | ||
134 | int height; // -1 not defined | ||
135 | |||
136 | #ifdef ENABLE_TRAY | ||
137 | // Tray | ||
138 | char *tray_output; | ||
139 | char *icon_theme; | ||
140 | uint32_t tray_padding; | ||
141 | uint32_t activate_button; | ||
142 | uint32_t context_button; | ||
143 | uint32_t secondary_button; | ||
144 | #endif | ||
145 | |||
146 | bool workspace_buttons; | ||
147 | bool wrap_scroll; | ||
148 | char *separator_symbol; | ||
149 | bool strip_workspace_numbers; | ||
150 | bool binding_mode_indicator; | ||
151 | bool verbose; | ||
152 | pid_t pid; | ||
153 | struct { | ||
154 | char *background; | ||
155 | char *statusline; | ||
156 | char *separator; | ||
157 | char *focused_background; | ||
158 | char *focused_statusline; | ||
159 | char *focused_separator; | ||
160 | char *focused_workspace_border; | ||
161 | char *focused_workspace_bg; | ||
162 | char *focused_workspace_text; | ||
163 | char *active_workspace_border; | ||
164 | char *active_workspace_bg; | ||
165 | char *active_workspace_text; | ||
166 | char *inactive_workspace_border; | ||
167 | char *inactive_workspace_bg; | ||
168 | char *inactive_workspace_text; | ||
169 | char *urgent_workspace_border; | ||
170 | char *urgent_workspace_bg; | ||
171 | char *urgent_workspace_text; | ||
172 | char *binding_mode_border; | ||
173 | char *binding_mode_bg; | ||
174 | char *binding_mode_text; | ||
175 | } colors; | ||
176 | }; | ||
177 | |||
178 | struct border_colors { | ||
179 | uint32_t border; | ||
180 | uint32_t background; | ||
181 | uint32_t text; | ||
182 | uint32_t indicator; | ||
183 | uint32_t child_border; | ||
184 | }; | ||
185 | |||
186 | enum edge_border_types { | ||
187 | E_NONE, /**< Don't hide edge borders */ | ||
188 | E_VERTICAL, /**< hide vertical edge borders */ | ||
189 | E_HORIZONTAL, /**< hide horizontal edge borders */ | ||
190 | E_BOTH, /**< hide vertical and horizontal edge borders */ | ||
191 | E_SMART /**< hide both if precisely one window is present in workspace */ | ||
192 | }; | ||
193 | |||
194 | enum command_context { | ||
195 | CONTEXT_CONFIG = 1, | ||
196 | CONTEXT_BINDING = 2, | ||
197 | CONTEXT_IPC = 4, | ||
198 | CONTEXT_CRITERIA = 8, | ||
199 | CONTEXT_ALL = 0xFFFFFFFF, | ||
200 | }; | ||
201 | |||
202 | struct command_policy { | ||
203 | char *command; | ||
204 | uint32_t context; | ||
205 | }; | ||
206 | |||
207 | enum secure_feature { | ||
208 | FEATURE_LOCK = 1, | ||
209 | FEATURE_PANEL = 2, | ||
210 | FEATURE_BACKGROUND = 4, | ||
211 | FEATURE_SCREENSHOT = 8, | ||
212 | FEATURE_FULLSCREEN = 16, | ||
213 | FEATURE_KEYBOARD = 32, | ||
214 | FEATURE_MOUSE = 64, | ||
215 | }; | ||
216 | |||
217 | struct feature_policy { | ||
218 | char *program; | ||
219 | uint32_t features; | ||
220 | }; | ||
221 | |||
222 | enum ipc_feature { | ||
223 | IPC_FEATURE_COMMAND = 1, | ||
224 | IPC_FEATURE_GET_WORKSPACES = 2, | ||
225 | IPC_FEATURE_GET_OUTPUTS = 4, | ||
226 | IPC_FEATURE_GET_TREE = 8, | ||
227 | IPC_FEATURE_GET_MARKS = 16, | ||
228 | IPC_FEATURE_GET_BAR_CONFIG = 32, | ||
229 | IPC_FEATURE_GET_VERSION = 64, | ||
230 | IPC_FEATURE_GET_INPUTS = 128, | ||
231 | IPC_FEATURE_EVENT_WORKSPACE = 256, | ||
232 | IPC_FEATURE_EVENT_OUTPUT = 512, | ||
233 | IPC_FEATURE_EVENT_MODE = 1024, | ||
234 | IPC_FEATURE_EVENT_WINDOW = 2048, | ||
235 | IPC_FEATURE_EVENT_BINDING = 4096, | ||
236 | IPC_FEATURE_EVENT_INPUT = 8192, | ||
237 | IPC_FEATURE_GET_CLIPBOARD = 16384, | ||
238 | |||
239 | IPC_FEATURE_ALL_COMMANDS = 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128 | 16384, | ||
240 | IPC_FEATURE_ALL_EVENTS = 256 | 512 | 1024 | 2048 | 4096 | 8192, | ||
241 | |||
242 | IPC_FEATURE_ALL = IPC_FEATURE_ALL_COMMANDS | IPC_FEATURE_ALL_EVENTS, | ||
243 | }; | ||
244 | |||
245 | struct ipc_policy { | ||
246 | char *program; | ||
247 | uint32_t features; | ||
248 | }; | ||
249 | |||
250 | /** | ||
251 | * The configuration struct. The result of loading a config file. | ||
252 | */ | ||
253 | struct sway_config { | ||
254 | list_t *symbols; | ||
255 | list_t *modes; | ||
256 | list_t *bars; | ||
257 | list_t *cmd_queue; | ||
258 | list_t *workspace_outputs; | ||
259 | list_t *pid_workspaces; | ||
260 | list_t *output_configs; | ||
261 | list_t *input_configs; | ||
262 | list_t *criteria; | ||
263 | list_t *no_focus; | ||
264 | list_t *active_bar_modifiers; | ||
265 | struct sway_mode *current_mode; | ||
266 | struct bar_config *current_bar; | ||
267 | uint32_t floating_mod; | ||
268 | uint32_t dragging_key; | ||
269 | uint32_t resizing_key; | ||
270 | char *floating_scroll_up_cmd; | ||
271 | char *floating_scroll_down_cmd; | ||
272 | char *floating_scroll_left_cmd; | ||
273 | char *floating_scroll_right_cmd; | ||
274 | enum swayc_layouts default_orientation; | ||
275 | enum swayc_layouts default_layout; | ||
276 | char *font; | ||
277 | int font_height; | ||
278 | |||
279 | // Flags | ||
280 | bool focus_follows_mouse; | ||
281 | bool mouse_warping; | ||
282 | bool force_focus_wrapping; | ||
283 | bool active; | ||
284 | bool failed; | ||
285 | bool reloading; | ||
286 | bool reading; | ||
287 | bool auto_back_and_forth; | ||
288 | bool seamless_mouse; | ||
289 | bool show_marks; | ||
290 | |||
291 | bool edge_gaps; | ||
292 | bool smart_gaps; | ||
293 | int gaps_inner; | ||
294 | int gaps_outer; | ||
295 | |||
296 | list_t *config_chain; | ||
297 | const char *current_config; | ||
298 | |||
299 | enum swayc_border_types border; | ||
300 | enum swayc_border_types floating_border; | ||
301 | int border_thickness; | ||
302 | int floating_border_thickness; | ||
303 | enum edge_border_types hide_edge_borders; | ||
304 | |||
305 | // border colors | ||
306 | struct { | ||
307 | struct border_colors focused; | ||
308 | struct border_colors focused_inactive; | ||
309 | struct border_colors unfocused; | ||
310 | struct border_colors urgent; | ||
311 | struct border_colors placeholder; | ||
312 | uint32_t background; | ||
313 | } border_colors; | ||
314 | |||
315 | // floating view | ||
316 | int32_t floating_maximum_width; | ||
317 | int32_t floating_maximum_height; | ||
318 | int32_t floating_minimum_width; | ||
319 | int32_t floating_minimum_height; | ||
320 | |||
321 | // Security | ||
322 | list_t *command_policies; | ||
323 | list_t *feature_policies; | ||
324 | list_t *ipc_policies; | ||
325 | }; | ||
326 | |||
327 | void pid_workspace_add(struct pid_workspace *pw); | ||
328 | void free_pid_workspace(struct pid_workspace *pw); | ||
329 | |||
330 | /** | ||
331 | * Loads the main config from the given path. is_active should be true when | ||
332 | * reloading the config. | ||
333 | */ | ||
334 | bool load_main_config(const char *path, bool is_active); | ||
335 | |||
336 | /** | ||
337 | * Loads an included config. Can only be used after load_main_config. | ||
338 | */ | ||
339 | bool load_include_configs(const char *path, struct sway_config *config); | ||
340 | |||
341 | /** | ||
342 | * Reads the config from the given FILE. | ||
343 | */ | ||
344 | bool read_config(FILE *file, struct sway_config *config); | ||
345 | |||
346 | /** | ||
347 | * Free config struct | ||
348 | */ | ||
349 | void free_config(struct sway_config *config); | ||
350 | /** | ||
351 | * Does variable replacement for a string based on the config's currently loaded variables. | ||
352 | */ | ||
353 | char *do_var_replacement(char *str); | ||
354 | |||
355 | struct cmd_results *check_security_config(); | ||
356 | |||
357 | int input_identifier_cmp(const void *item, const void *data); | ||
358 | void merge_input_config(struct input_config *dst, struct input_config *src); | ||
359 | void apply_input_config(struct input_config *ic, struct libinput_device *dev); | ||
360 | void free_input_config(struct input_config *ic); | ||
361 | |||
362 | int output_name_cmp(const void *item, const void *data); | ||
363 | void merge_output_config(struct output_config *dst, struct output_config *src); | ||
364 | /** Sets up a WLC output handle based on a given output_config. | ||
365 | */ | ||
366 | void apply_output_config(struct output_config *oc, swayc_t *output); | ||
367 | void free_output_config(struct output_config *oc); | ||
368 | |||
369 | /** | ||
370 | * Updates the list of active bar modifiers | ||
371 | */ | ||
372 | void update_active_bar_modifiers(void); | ||
373 | |||
374 | int workspace_output_cmp_workspace(const void *a, const void *b); | ||
375 | |||
376 | int sway_binding_cmp(const void *a, const void *b); | ||
377 | int sway_binding_cmp_qsort(const void *a, const void *b); | ||
378 | int sway_binding_cmp_keys(const void *a, const void *b); | ||
379 | void free_sway_binding(struct sway_binding *sb); | ||
380 | struct sway_binding *sway_binding_dup(struct sway_binding *sb); | ||
381 | |||
382 | int sway_mouse_binding_cmp(const void *a, const void *b); | ||
383 | int sway_mouse_binding_cmp_qsort(const void *a, const void *b); | ||
384 | int sway_mouse_binding_cmp_buttons(const void *a, const void *b); | ||
385 | void free_sway_mouse_binding(struct sway_mouse_binding *smb); | ||
386 | |||
387 | void load_swaybars(); | ||
388 | void terminate_swaybg(pid_t pid); | ||
389 | |||
390 | /** | ||
391 | * Allocate and initialize default bar configuration. | ||
392 | */ | ||
393 | struct bar_config *default_bar_config(void); | ||
394 | |||
395 | /** | ||
396 | * Global config singleton. | ||
397 | */ | ||
398 | extern struct sway_config *config; | ||
399 | |||
400 | /** | ||
401 | * Config file currently being read. | ||
402 | */ | ||
403 | extern const char *current_config_path; | ||
404 | |||
405 | #endif | ||