summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/background-image.h20
-rw-r--r--include/cairo.h (renamed from include/client/cairo.h)10
-rw-r--r--include/client/buffer.h8
-rw-r--r--include/client/pango.h16
-rw-r--r--include/client/registry.h75
-rw-r--r--include/client/window.h67
-rw-r--r--include/ipc.h1
-rw-r--r--include/log.h33
-rw-r--r--include/meson.build1
-rw-r--r--include/pango.h16
-rw-r--r--include/pool-buffer.h22
-rw-r--r--include/sway.h6
-rw-r--r--include/sway/border.h28
-rw-r--r--include/sway/commands.h45
-rw-r--r--include/sway/config.h159
-rw-r--r--include/sway/container.h357
-rw-r--r--include/sway/criteria.h8
-rw-r--r--include/sway/debug.h7
-rw-r--r--include/sway/desktop.h4
-rw-r--r--include/sway/extensions.h56
-rw-r--r--include/sway/focus.h45
-rw-r--r--include/sway/handlers.h11
-rw-r--r--include/sway/input.h23
-rw-r--r--include/sway/input/cursor.h36
-rw-r--r--include/sway/input/input-manager.h64
-rw-r--r--include/sway/input/keyboard.h30
-rw-r--r--include/sway/input/seat.h111
-rw-r--r--include/sway/input_state.h102
-rw-r--r--include/sway/ipc-json.h13
-rw-r--r--include/sway/ipc-server.h38
-rw-r--r--include/sway/layers.h25
-rw-r--r--include/sway/layout.h85
-rw-r--r--include/sway/output.h53
-rw-r--r--include/sway/server.h57
-rw-r--r--include/sway/tree/container.h192
-rw-r--r--include/sway/tree/layout.h78
-rw-r--r--include/sway/tree/output.h0
-rw-r--r--include/sway/tree/view.h186
-rw-r--r--include/sway/tree/workspace.h26
-rw-r--r--include/sway/workspace.h22
-rw-r--r--include/swaybar/bar.h110
-rw-r--r--include/swaybar/config.h59
-rw-r--r--include/swaybar/event_loop.h4
-rw-r--r--include/swaybar/ipc.h26
-rw-r--r--include/swaybar/render.h22
-rw-r--r--include/swaybar/status_line.h78
-rw-r--r--include/swaylock/seat.h38
-rw-r--r--include/swaylock/swaylock.h98
-rw-r--r--include/unicode.h33
49 files changed, 1328 insertions, 1276 deletions
diff --git a/include/background-image.h b/include/background-image.h
new file mode 100644
index 00000000..15935ffd
--- /dev/null
+++ b/include/background-image.h
@@ -0,0 +1,20 @@
1#ifndef _SWAY_BACKGROUND_IMAGE_H
2#define _SWAY_BACKGROUND_IMAGE_H
3#include "cairo.h"
4
5enum background_mode {
6 BACKGROUND_MODE_STRETCH,
7 BACKGROUND_MODE_FILL,
8 BACKGROUND_MODE_FIT,
9 BACKGROUND_MODE_CENTER,
10 BACKGROUND_MODE_TILE,
11 BACKGROUND_MODE_SOLID_COLOR,
12 BACKGROUND_MODE_INVALID,
13};
14
15enum background_mode parse_background_mode(const char *mode);
16cairo_surface_t *load_background_image(const char *path);
17void render_background_image(cairo_t *cairo, cairo_surface_t *image,
18 enum background_mode mode, int buffer_width, int buffer_height);
19
20#endif
diff --git a/include/client/cairo.h b/include/cairo.h
index e7ef7c7e..31672705 100644
--- a/include/client/cairo.h
+++ b/include/cairo.h
@@ -1,17 +1,19 @@
1#ifndef _SWAY_CAIRO_H 1#ifndef _SWAY_CAIRO_H
2#define _SWAY_CAIRO_H 2#define _SWAY_CAIRO_H
3
4#include <stdint.h> 3#include <stdint.h>
5#include <cairo/cairo.h> 4#include <cairo/cairo.h>
6 5
7void cairo_set_source_u32(cairo_t *cairo, uint32_t color); 6void cairo_set_source_u32(cairo_t *cairo, uint32_t color);
8 7
9cairo_surface_t *cairo_image_surface_scale(cairo_surface_t *image, int width, int height); 8cairo_surface_t *cairo_image_surface_scale(cairo_surface_t *image,
9 int width, int height);
10 10
11#ifdef WITH_GDK_PIXBUF 11#include "config.h"
12#ifdef HAVE_GDK_PIXBUF
12#include <gdk-pixbuf/gdk-pixbuf.h> 13#include <gdk-pixbuf/gdk-pixbuf.h>
13 14
14cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(const GdkPixbuf *gdkbuf); 15cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(
16 const GdkPixbuf *gdkbuf);
15#endif //WITH_GDK_PIXBUF 17#endif //WITH_GDK_PIXBUF
16 18
17#endif 19#endif
diff --git a/include/client/buffer.h b/include/client/buffer.h
deleted file mode 100644
index eb9973ed..00000000
--- a/include/client/buffer.h
+++ /dev/null
@@ -1,8 +0,0 @@
1#ifndef _BUFFER_H
2#define _BUFFER_H
3
4#include "client/window.h"
5
6struct buffer *get_next_buffer(struct window *state);
7
8#endif
diff --git a/include/client/pango.h b/include/client/pango.h
deleted file mode 100644
index dd2f53c3..00000000
--- a/include/client/pango.h
+++ /dev/null
@@ -1,16 +0,0 @@
1#ifndef _SWAY_CLIENT_PANGO_H
2#define _SWAY_CLIENT_PANGO_H
3
4#include <cairo/cairo.h>
5#include <pango/pangocairo.h>
6#include <stdarg.h>
7#include <stdbool.h>
8#include <stdint.h>
9
10PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text,
11 int32_t scale, bool markup);
12void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
13 int32_t scale, bool markup, const char *fmt, ...);
14void pango_printf(cairo_t *cairo, const char *font, int32_t scale, bool markup, const char *fmt, ...);
15
16#endif
diff --git a/include/client/registry.h b/include/client/registry.h
deleted file mode 100644
index 9dfbd835..00000000
--- a/include/client/registry.h
+++ /dev/null
@@ -1,75 +0,0 @@
1#ifndef _SWAY_CLIENT_REGISTRY_H
2#define _SWAY_CLIENT_REGISTRY_H
3
4#include <wayland-client.h>
5#include <xkbcommon/xkbcommon.h>
6#include "wayland-desktop-shell-client-protocol.h"
7#include "wayland-swaylock-client-protocol.h"
8#include "list.h"
9
10enum mod_bit {
11 MOD_SHIFT = 1<<0,
12 MOD_CAPS = 1<<1,
13 MOD_CTRL = 1<<2,
14 MOD_ALT = 1<<3,
15 MOD_MOD2 = 1<<4,
16 MOD_MOD3 = 1<<5,
17 MOD_LOGO = 1<<6,
18 MOD_MOD5 = 1<<7,
19};
20
21enum mask {
22 MASK_SHIFT,
23 MASK_CAPS,
24 MASK_CTRL,
25 MASK_ALT,
26 MASK_MOD2,
27 MASK_MOD3,
28 MASK_LOGO,
29 MASK_MOD5,
30 MASK_LAST
31};
32
33struct output_state {
34 struct wl_output *output;
35 uint32_t flags;
36 uint32_t width, height;
37 uint32_t scale;
38};
39
40struct xkb {
41 struct xkb_state *state;
42 struct xkb_context *context;
43 struct xkb_keymap *keymap;
44 xkb_mod_mask_t masks[MASK_LAST];
45};
46
47struct input {
48 struct xkb xkb;
49
50 xkb_keysym_t sym;
51 uint32_t code;
52 uint32_t last_code;
53 uint32_t modifiers;
54
55 void (*notify)(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t code, uint32_t codepoint);
56};
57
58struct registry {
59 struct wl_compositor *compositor;
60 struct wl_display *display;
61 struct wl_pointer *pointer;
62 struct wl_keyboard *keyboard;
63 struct wl_seat *seat;
64 struct wl_shell *shell;
65 struct wl_shm *shm;
66 struct desktop_shell *desktop_shell;
67 struct lock *swaylock;
68 struct input *input;
69 list_t *outputs;
70};
71
72struct registry *registry_poll(void);
73void registry_teardown(struct registry *registry);
74
75#endif
diff --git a/include/client/window.h b/include/client/window.h
deleted file mode 100644
index 8af8225c..00000000
--- a/include/client/window.h
+++ /dev/null
@@ -1,67 +0,0 @@
1#ifndef _CLIENT_H
2#define _CLIENT_H
3
4#include <wayland-client.h>
5#include "wayland-desktop-shell-client-protocol.h"
6#include <cairo/cairo.h>
7#include <pango/pangocairo.h>
8#include <stdbool.h>
9#include "list.h"
10#include "client/registry.h"
11
12struct window;
13
14struct buffer {
15 struct wl_buffer *buffer;
16 cairo_surface_t *surface;
17 cairo_t *cairo;
18 PangoContext *pango;
19 uint32_t width, height;
20 bool busy;
21};
22
23struct cursor {
24 struct wl_surface *surface;
25 struct wl_cursor_theme *cursor_theme;
26 struct wl_cursor *cursor;
27 struct wl_pointer *pointer;
28};
29
30enum scroll_direction {
31 SCROLL_UP,
32 SCROLL_DOWN,
33 SCROLL_LEFT,
34 SCROLL_RIGHT,
35};
36
37struct pointer_input {
38 int last_x;
39 int last_y;
40
41 void (*notify_button)(struct window *window, int x, int y, uint32_t button, uint32_t state_w);
42 void (*notify_scroll)(struct window *window, enum scroll_direction direction);
43};
44
45struct window {
46 struct registry *registry;
47 struct buffer buffers[2];
48 struct buffer *buffer;
49 struct wl_surface *surface;
50 struct wl_shell_surface *shell_surface;
51 struct wl_callback *frame_cb;
52 struct cursor cursor;
53 uint32_t width, height;
54 int32_t scale;
55 char *font;
56 cairo_t *cairo;
57 struct pointer_input pointer_input;
58};
59
60struct window *window_setup(struct registry *registry, uint32_t width, uint32_t height,
61 int32_t scale, bool shell_surface);
62void window_teardown(struct window *state);
63int window_prerender(struct window *state);
64int window_render(struct window *state);
65void window_make_shell(struct window *window);
66
67#endif
diff --git a/include/ipc.h b/include/ipc.h
index 2b16dc50..9665a88d 100644
--- a/include/ipc.h
+++ b/include/ipc.h
@@ -23,7 +23,6 @@ enum ipc_command_type {
23 IPC_EVENT_BINDING = ((1<<31) | 5), 23 IPC_EVENT_BINDING = ((1<<31) | 5),
24 IPC_EVENT_MODIFIER = ((1<<31) | 6), 24 IPC_EVENT_MODIFIER = ((1<<31) | 6),
25 IPC_EVENT_INPUT = ((1<<31) | 7), 25 IPC_EVENT_INPUT = ((1<<31) | 7),
26 IPC_SWAY_GET_PIXELS = 0x81
27}; 26};
28 27
29#endif 28#endif
diff --git a/include/log.h b/include/log.h
index a1e33fa2..a9748127 100644
--- a/include/log.h
+++ b/include/log.h
@@ -1,38 +1,15 @@
1#ifndef _SWAY_LOG_H 1#ifndef _SWAY_LOG_H
2#define _SWAY_LOG_H 2#define _SWAY_LOG_H
3#include <stdbool.h> 3#include <stdbool.h>
4#include <wlr/util/log.h>
4 5
5typedef enum { 6void _sway_abort(const char *filename, ...) ATTRIB_PRINTF(1, 2);
6 L_SILENT = 0,
7 L_ERROR = 1,
8 L_INFO = 2,
9 L_DEBUG = 3,
10} log_importance_t;
11
12void init_log(log_importance_t verbosity);
13void set_log_level(log_importance_t verbosity);
14log_importance_t get_log_level(void);
15void reset_log_level(void);
16// returns whether debug logging is on after switching.
17bool toggle_debug_logging(void);
18void sway_log_colors(int mode);
19void sway_log_errno(log_importance_t verbosity, char* format, ...) __attribute__((format(printf,2,3)));
20
21void _sway_abort(const char *filename, int line, const char* format, ...) __attribute__((format(printf,3,4)));
22#define sway_abort(FMT, ...) \ 7#define sway_abort(FMT, ...) \
23 _sway_abort(__FILE__, __LINE__, FMT, ##__VA_ARGS__) 8 _sway_abort("[%s:%d] " FMT, wlr_strip_path(__FILE__), __LINE__, ##__VA_ARGS__)
24 9
25bool _sway_assert(bool condition, const char *filename, int line, const char* format, ...) __attribute__((format(printf,4,5))); 10bool _sway_assert(bool condition, const char* format, ...) ATTRIB_PRINTF(2, 3);
26#define sway_assert(COND, FMT, ...) \ 11#define sway_assert(COND, FMT, ...) \
27 _sway_assert(COND, __FILE__, __LINE__, "%s:" FMT, __PRETTY_FUNCTION__, ##__VA_ARGS__) 12 _sway_assert(COND, "[%s:%d] %s:" FMT, wlr_strip_path(__FILE__), __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__)
28
29void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,4,5)));
30
31#define sway_log(VERBOSITY, FMT, ...) \
32 _sway_log(__FILE__, __LINE__, VERBOSITY, FMT, ##__VA_ARGS__)
33
34#define sway_vlog(VERBOSITY, FMT, VA_ARGS) \
35 _sway_vlog(__FILE__, __LINE__, VERBOSITY, FMT, VA_ARGS)
36 13
37void error_handler(int sig); 14void error_handler(int sig);
38 15
diff --git a/include/meson.build b/include/meson.build
new file mode 100644
index 00000000..65ed027a
--- /dev/null
+++ b/include/meson.build
@@ -0,0 +1 @@
configure_file(output: 'config.h', configuration: conf_data)
diff --git a/include/pango.h b/include/pango.h
new file mode 100644
index 00000000..f6325f28
--- /dev/null
+++ b/include/pango.h
@@ -0,0 +1,16 @@
1#ifndef _SWAY_PANGO_H
2#define _SWAY_PANGO_H
3#include <stdarg.h>
4#include <stdbool.h>
5#include <stdint.h>
6#include <cairo/cairo.h>
7#include <pango/pangocairo.h>
8
9PangoLayout *get_pango_layout(cairo_t *cairo, const char *font,
10 const char *text, int32_t scale, bool markup);
11void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
12 int32_t scale, bool markup, const char *fmt, ...);
13void pango_printf(cairo_t *cairo, const char *font,
14 int32_t scale, bool markup, const char *fmt, ...);
15
16#endif
diff --git a/include/pool-buffer.h b/include/pool-buffer.h
new file mode 100644
index 00000000..856f7c8c
--- /dev/null
+++ b/include/pool-buffer.h
@@ -0,0 +1,22 @@
1#ifndef _SWAY_BUFFERS_H
2#define _SWAY_BUFFERS_H
3#include <cairo/cairo.h>
4#include <pango/pangocairo.h>
5#include <stdbool.h>
6#include <stdint.h>
7#include <wayland-client.h>
8
9struct pool_buffer {
10 struct wl_buffer *buffer;
11 cairo_surface_t *surface;
12 cairo_t *cairo;
13 PangoContext *pango;
14 uint32_t width, height;
15 bool busy;
16};
17
18struct pool_buffer *get_next_buffer(struct wl_shm *shm,
19 struct pool_buffer pool[static 2], uint32_t width, uint32_t height);
20void destroy_buffer(struct pool_buffer *buffer);
21
22#endif
diff --git a/include/sway.h b/include/sway.h
deleted file mode 100644
index b5cfb668..00000000
--- a/include/sway.h
+++ /dev/null
@@ -1,6 +0,0 @@
1#ifndef _SWAY_SWAY_H
2#define _SWAY_SWAY_H
3
4void sway_terminate(int exit_code);
5
6#endif
diff --git a/include/sway/border.h b/include/sway/border.h
deleted file mode 100644
index c30c9da3..00000000
--- a/include/sway/border.h
+++ /dev/null
@@ -1,28 +0,0 @@
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
index 660da2c2..dbebaa49 100644
--- a/include/sway/commands.h
+++ b/include/sway/commands.h
@@ -1,12 +1,7 @@
1#ifndef _SWAY_COMMANDS_H 1#ifndef _SWAY_COMMANDS_H
2#define _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 3
8// Container that a called command should act upon. Only valid in command functions. 4#include "config.h"
9extern swayc_t *current_container;
10 5
11/** 6/**
12 * Indicates the result of a command's execution. 7 * Indicates the result of a command's execution.
@@ -22,6 +17,7 @@ enum cmd_status {
22 CMD_BLOCK_BAR, 17 CMD_BLOCK_BAR,
23 CMD_BLOCK_BAR_COLORS, 18 CMD_BLOCK_BAR_COLORS,
24 CMD_BLOCK_INPUT, 19 CMD_BLOCK_INPUT,
20 CMD_BLOCK_SEAT,
25 CMD_BLOCK_COMMANDS, 21 CMD_BLOCK_COMMANDS,
26 CMD_BLOCK_IPC, 22 CMD_BLOCK_IPC,
27 CMD_BLOCK_IPC_EVENTS, 23 CMD_BLOCK_IPC_EVENTS,
@@ -46,18 +42,13 @@ enum expected_args {
46 EXPECTED_EQUAL_TO 42 EXPECTED_EQUAL_TO
47}; 43};
48 44
49struct cmd_results *checkarg(int argc, const char *name, enum expected_args type, int val); 45struct cmd_results *checkarg(int argc, const char *name,
50struct cmd_results *add_color(const char*, char*, const char*); 46 enum expected_args type, int val);
51void input_cmd_apply(struct input_config *input);
52void hide_view_in_scratchpad(swayc_t *sp_view);
53
54swayc_t *sp_view;
55int sp_index;
56 47
57/** 48/**
58 * Parse and handles a command. 49 * Parse and executes a command.
59 */ 50 */
60struct cmd_results *handle_command(char *command, enum command_context context); 51struct cmd_results *execute_command(char *command, struct sway_seat *seat);
61/** 52/**
62 * Parse and handles a command during config file loading. 53 * Parse and handles a command during config file loading.
63 * 54 *
@@ -68,7 +59,6 @@ struct cmd_results *config_command(char *command, enum cmd_status block);
68 * Parses a command policy rule. 59 * Parses a command policy rule.
69 */ 60 */
70struct cmd_results *config_commands_command(char *exec); 61struct cmd_results *config_commands_command(char *exec);
71
72/** 62/**
73 * Allocates a cmd_results object. 63 * Allocates a cmd_results object.
74 */ 64 */
@@ -84,11 +74,8 @@ void free_cmd_results(struct cmd_results *results);
84 */ 74 */
85const char *cmd_results_to_json(struct cmd_results *results); 75const char *cmd_results_to_json(struct cmd_results *results);
86 76
87void remove_view_from_scratchpad(swayc_t *); 77struct cmd_results *add_color(const char *name,
88 78 char *buffer, const char *color);
89/**
90 * Actual command function signatures for individual .c files in commands/ directory.
91 */
92 79
93typedef struct cmd_results *sway_cmd(int argc, char **argv); 80typedef struct cmd_results *sway_cmd(int argc, char **argv);
94 81
@@ -108,6 +95,7 @@ sway_cmd cmd_commands;
108sway_cmd cmd_debuglog; 95sway_cmd cmd_debuglog;
109sway_cmd cmd_default_border; 96sway_cmd cmd_default_border;
110sway_cmd cmd_default_floating_border; 97sway_cmd cmd_default_floating_border;
98sway_cmd cmd_default_orientation;
111sway_cmd cmd_exec; 99sway_cmd cmd_exec;
112sway_cmd cmd_exec_always; 100sway_cmd cmd_exec_always;
113sway_cmd cmd_exit; 101sway_cmd cmd_exit;
@@ -126,6 +114,7 @@ sway_cmd cmd_gaps;
126sway_cmd cmd_hide_edge_borders; 114sway_cmd cmd_hide_edge_borders;
127sway_cmd cmd_include; 115sway_cmd cmd_include;
128sway_cmd cmd_input; 116sway_cmd cmd_input;
117sway_cmd cmd_seat;
129sway_cmd cmd_ipc; 118sway_cmd cmd_ipc;
130sway_cmd cmd_kill; 119sway_cmd cmd_kill;
131sway_cmd cmd_layout; 120sway_cmd cmd_layout;
@@ -134,10 +123,10 @@ sway_cmd cmd_mark;
134sway_cmd cmd_mode; 123sway_cmd cmd_mode;
135sway_cmd cmd_mouse_warping; 124sway_cmd cmd_mouse_warping;
136sway_cmd cmd_move; 125sway_cmd cmd_move;
126sway_cmd cmd_opacity;
137sway_cmd cmd_new_float; 127sway_cmd cmd_new_float;
138sway_cmd cmd_new_window; 128sway_cmd cmd_new_window;
139sway_cmd cmd_no_focus; 129sway_cmd cmd_no_focus;
140sway_cmd cmd_orientation;
141sway_cmd cmd_output; 130sway_cmd cmd_output;
142sway_cmd cmd_permit; 131sway_cmd cmd_permit;
143sway_cmd cmd_reject; 132sway_cmd cmd_reject;
@@ -153,6 +142,7 @@ sway_cmd cmd_splith;
153sway_cmd cmd_splitt; 142sway_cmd cmd_splitt;
154sway_cmd cmd_splitv; 143sway_cmd cmd_splitv;
155sway_cmd cmd_sticky; 144sway_cmd cmd_sticky;
145sway_cmd cmd_swaybg_command;
156sway_cmd cmd_unmark; 146sway_cmd cmd_unmark;
157sway_cmd cmd_workspace; 147sway_cmd cmd_workspace;
158sway_cmd cmd_ws_auto_back_and_forth; 148sway_cmd cmd_ws_auto_back_and_forth;
@@ -195,17 +185,28 @@ sway_cmd bar_colors_cmd_statusline;
195sway_cmd bar_colors_cmd_focused_statusline; 185sway_cmd bar_colors_cmd_focused_statusline;
196sway_cmd bar_colors_cmd_urgent_workspace; 186sway_cmd bar_colors_cmd_urgent_workspace;
197 187
188sway_cmd input_cmd_seat;
198sway_cmd input_cmd_accel_profile; 189sway_cmd input_cmd_accel_profile;
199sway_cmd input_cmd_click_method; 190sway_cmd input_cmd_click_method;
200sway_cmd input_cmd_drag_lock; 191sway_cmd input_cmd_drag_lock;
201sway_cmd input_cmd_dwt; 192sway_cmd input_cmd_dwt;
202sway_cmd input_cmd_events; 193sway_cmd input_cmd_events;
203sway_cmd input_cmd_left_handed; 194sway_cmd input_cmd_left_handed;
195sway_cmd input_cmd_map_to_output;
204sway_cmd input_cmd_middle_emulation; 196sway_cmd input_cmd_middle_emulation;
205sway_cmd input_cmd_natural_scroll; 197sway_cmd input_cmd_natural_scroll;
206sway_cmd input_cmd_pointer_accel; 198sway_cmd input_cmd_pointer_accel;
207sway_cmd input_cmd_scroll_method; 199sway_cmd input_cmd_scroll_method;
208sway_cmd input_cmd_tap; 200sway_cmd input_cmd_tap;
201sway_cmd input_cmd_xkb_layout;
202sway_cmd input_cmd_xkb_model;
203sway_cmd input_cmd_xkb_options;
204sway_cmd input_cmd_xkb_rules;
205sway_cmd input_cmd_xkb_variant;
206
207sway_cmd seat_cmd_attach;
208sway_cmd seat_cmd_fallback;
209sway_cmd seat_cmd_cursor;
209 210
210sway_cmd cmd_ipc_cmd; 211sway_cmd cmd_ipc_cmd;
211sway_cmd cmd_ipc_events; 212sway_cmd cmd_ipc_events;
diff --git a/include/sway/config.h b/include/sway/config.h
index a05d5ede..ed49fbbd 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -1,18 +1,18 @@
1#ifndef _SWAY_CONFIG_H 1#ifndef _SWAY_CONFIG_H
2#define _SWAY_CONFIG_H 2#define _SWAY_CONFIG_H
3
4#define PID_WORKSPACE_TIMEOUT 60 3#define PID_WORKSPACE_TIMEOUT 60
5
6#include <libinput.h> 4#include <libinput.h>
7#include <stdint.h> 5#include <stdint.h>
8#include <wlc/geometry.h> 6#include <string.h>
9#include <wlc/wlc.h>
10#include <xkbcommon/xkbcommon.h>
11#include <time.h> 7#include <time.h>
12#include "wayland-desktop-shell-server-protocol.h" 8#include <wlr/types/wlr_box.h>
9#include <xkbcommon/xkbcommon.h>
13#include "list.h" 10#include "list.h"
14#include "layout.h" 11#include "tree/layout.h"
15#include "container.h" 12#include "tree/container.h"
13#include "wlr-layer-shell-unstable-v1-protocol.h"
14
15// TODO: Refactor this shit
16 16
17/** 17/**
18 * Describes a variable created via the `set` command. 18 * Describes a variable created via the `set` command.
@@ -47,11 +47,12 @@ struct sway_mouse_binding {
47 */ 47 */
48struct sway_mode { 48struct sway_mode {
49 char *name; 49 char *name;
50 list_t *bindings; 50 list_t *keysym_bindings;
51 list_t *keycode_bindings;
51}; 52};
52 53
53/** 54/**
54 * libinput options for input devices 55 * options for input devices
55 */ 56 */
56struct input_config { 57struct input_config {
57 char *identifier; 58 char *identifier;
@@ -68,8 +69,33 @@ struct input_config {
68 int send_events; 69 int send_events;
69 int tap; 70 int tap;
70 71
72 char *xkb_layout;
73 char *xkb_model;
74 char *xkb_options;
75 char *xkb_rules;
76 char *xkb_variant;
77
78 char *mapped_output;
79
71 bool capturable; 80 bool capturable;
72 struct wlc_geometry region; 81 struct wlr_box region;
82};
83
84/**
85 * Options for misc device configurations that happen in the seat block
86 */
87struct seat_attachment_config {
88 char *identifier;
89 // TODO other things are configured here for some reason
90};
91
92/**
93 * Options for multiseat and other misc device configurations
94 */
95struct seat_config {
96 char *name;
97 int fallback; // -1 means not set
98 list_t *attachments; // list of seat_attachment configs
73}; 99};
74 100
75/** 101/**
@@ -81,8 +107,11 @@ struct output_config {
81 char *name; 107 char *name;
82 int enabled; 108 int enabled;
83 int width, height; 109 int width, height;
110 float refresh_rate;
84 int x, y; 111 int x, y;
85 int scale; 112 float scale;
113 int32_t transform;
114
86 char *background; 115 char *background;
87 char *background_option; 116 char *background_option;
88}; 117};
@@ -126,24 +155,13 @@ struct bar_config {
126 char *id; 155 char *id;
127 uint32_t modifier; 156 uint32_t modifier;
128 list_t *outputs; 157 list_t *outputs;
129 enum desktop_shell_panel_position position; 158 char *position;
130 list_t *bindings; 159 list_t *bindings;
131 char *status_command; 160 char *status_command;
132 bool pango_markup; 161 bool pango_markup;
133 char *swaybar_command; 162 char *swaybar_command;
134 char *font; 163 char *font;
135 int height; // -1 not defined 164 int height; // -1 not defined
136
137#ifdef ENABLE_TRAY
138 // Tray
139 char *tray_output;
140 char *icon_theme;
141 uint32_t tray_padding;
142 uint32_t activate_button;
143 uint32_t context_button;
144 uint32_t secondary_button;
145#endif
146
147 bool workspace_buttons; 165 bool workspace_buttons;
148 bool wrap_scroll; 166 bool wrap_scroll;
149 char *separator_symbol; 167 char *separator_symbol;
@@ -260,11 +278,13 @@ struct sway_config {
260 list_t *pid_workspaces; 278 list_t *pid_workspaces;
261 list_t *output_configs; 279 list_t *output_configs;
262 list_t *input_configs; 280 list_t *input_configs;
281 list_t *seat_configs;
263 list_t *criteria; 282 list_t *criteria;
264 list_t *no_focus; 283 list_t *no_focus;
265 list_t *active_bar_modifiers; 284 list_t *active_bar_modifiers;
266 struct sway_mode *current_mode; 285 struct sway_mode *current_mode;
267 struct bar_config *current_bar; 286 struct bar_config *current_bar;
287 char *swaybg_command;
268 uint32_t floating_mod; 288 uint32_t floating_mod;
269 uint32_t dragging_key; 289 uint32_t dragging_key;
270 uint32_t resizing_key; 290 uint32_t resizing_key;
@@ -272,8 +292,8 @@ struct sway_config {
272 char *floating_scroll_down_cmd; 292 char *floating_scroll_down_cmd;
273 char *floating_scroll_left_cmd; 293 char *floating_scroll_left_cmd;
274 char *floating_scroll_right_cmd; 294 char *floating_scroll_right_cmd;
275 enum swayc_layouts default_orientation; 295 enum sway_container_layout default_orientation;
276 enum swayc_layouts default_layout; 296 enum sway_container_layout default_layout;
277 char *font; 297 char *font;
278 int font_height; 298 int font_height;
279 299
@@ -286,7 +306,6 @@ struct sway_config {
286 bool reloading; 306 bool reloading;
287 bool reading; 307 bool reading;
288 bool auto_back_and_forth; 308 bool auto_back_and_forth;
289 bool seamless_mouse;
290 bool show_marks; 309 bool show_marks;
291 310
292 bool edge_gaps; 311 bool edge_gaps;
@@ -297,8 +316,8 @@ struct sway_config {
297 list_t *config_chain; 316 list_t *config_chain;
298 const char *current_config; 317 const char *current_config;
299 318
300 enum swayc_border_types border; 319 enum sway_container_border border;
301 enum swayc_border_types floating_border; 320 enum sway_container_border floating_border;
302 int border_thickness; 321 int border_thickness;
303 int floating_border_thickness; 322 int floating_border_thickness;
304 enum edge_border_types hide_edge_borders; 323 enum edge_border_types hide_edge_borders;
@@ -323,6 +342,14 @@ struct sway_config {
323 list_t *command_policies; 342 list_t *command_policies;
324 list_t *feature_policies; 343 list_t *feature_policies;
325 list_t *ipc_policies; 344 list_t *ipc_policies;
345
346 // Context for command handlers
347 struct {
348 struct input_config *input_config;
349 struct seat_config *seat_config;
350 struct sway_seat *seat;
351 struct sway_container *current_container;
352 } handler_context;
326}; 353};
327 354
328void pid_workspace_add(struct pid_workspace *pw); 355void pid_workspace_add(struct pid_workspace *pw);
@@ -348,6 +375,11 @@ bool read_config(FILE *file, struct sway_config *config);
348 * Free config struct 375 * Free config struct
349 */ 376 */
350void free_config(struct sway_config *config); 377void free_config(struct sway_config *config);
378
379void config_clear_handler_context(struct sway_config *config);
380
381void free_sway_variable(struct sway_variable *var);
382
351/** 383/**
352 * Does variable replacement for a string based on the config's currently loaded variables. 384 * Does variable replacement for a string based on the config's currently loaded variables.
353 */ 385 */
@@ -356,51 +388,74 @@ char *do_var_replacement(char *str);
356struct cmd_results *check_security_config(); 388struct cmd_results *check_security_config();
357 389
358int input_identifier_cmp(const void *item, const void *data); 390int input_identifier_cmp(const void *item, const void *data);
391
392struct input_config *new_input_config(const char* identifier);
393
359void merge_input_config(struct input_config *dst, struct input_config *src); 394void merge_input_config(struct input_config *dst, struct input_config *src);
360void apply_input_config(struct input_config *ic, struct libinput_device *dev); 395
396struct input_config *copy_input_config(struct input_config *ic);
397
361void free_input_config(struct input_config *ic); 398void free_input_config(struct input_config *ic);
362 399
400void apply_input_config(struct input_config *input);
401
402int seat_name_cmp(const void *item, const void *data);
403
404struct seat_config *new_seat_config(const char* name);
405
406void merge_seat_config(struct seat_config *dst, struct seat_config *src);
407
408struct seat_config *copy_seat_config(struct seat_config *seat);
409
410void free_seat_config(struct seat_config *ic);
411
412struct seat_attachment_config *seat_attachment_config_new();
413
414struct seat_attachment_config *seat_config_get_attachment(
415 struct seat_config *seat_config, char *identifier);
416
417void apply_seat_config(struct seat_config *seat);
418
363int output_name_cmp(const void *item, const void *data); 419int output_name_cmp(const void *item, const void *data);
420
421void output_get_identifier(char *identifier, size_t len,
422 struct sway_output *output);
423
424struct output_config *new_output_config(const char *name);
425
364void merge_output_config(struct output_config *dst, struct output_config *src); 426void merge_output_config(struct output_config *dst, struct output_config *src);
365/** Sets up a WLC output handle based on a given output_config.
366 */
367void apply_output_config(struct output_config *oc, swayc_t *output);
368void free_output_config(struct output_config *oc);
369 427
370/** 428void apply_output_config(struct output_config *oc,
371 * Updates the list of active bar modifiers 429 struct sway_container *output);
372 */ 430
373void update_active_bar_modifiers(void); 431void free_output_config(struct output_config *oc);
374 432
375int workspace_output_cmp_workspace(const void *a, const void *b); 433int workspace_output_cmp_workspace(const void *a, const void *b);
376 434
377int sway_binding_cmp(const void *a, const void *b); 435int sway_binding_cmp(const void *a, const void *b);
436
378int sway_binding_cmp_qsort(const void *a, const void *b); 437int sway_binding_cmp_qsort(const void *a, const void *b);
438
379int sway_binding_cmp_keys(const void *a, const void *b); 439int sway_binding_cmp_keys(const void *a, const void *b);
440
380void free_sway_binding(struct sway_binding *sb); 441void free_sway_binding(struct sway_binding *sb);
381struct sway_binding *sway_binding_dup(struct sway_binding *sb);
382 442
383int sway_mouse_binding_cmp(const void *a, const void *b); 443struct sway_binding *sway_binding_dup(struct sway_binding *sb);
384int sway_mouse_binding_cmp_qsort(const void *a, const void *b);
385int sway_mouse_binding_cmp_buttons(const void *a, const void *b);
386void free_sway_mouse_binding(struct sway_mouse_binding *smb);
387 444
388void load_swaybars(); 445void load_swaybars();
446
447void invoke_swaybar(struct bar_config *bar);
448
389void terminate_swaybg(pid_t pid); 449void terminate_swaybg(pid_t pid);
390 450
391/**
392 * Allocate and initialize default bar configuration.
393 */
394struct bar_config *default_bar_config(void); 451struct bar_config *default_bar_config(void);
395 452
396/** 453void free_bar_config(struct bar_config *bar);
397 * Global config singleton. 454
398 */ 455/* Global config singleton. */
399extern struct sway_config *config; 456extern struct sway_config *config;
400 457
401/** 458/* Config file currently being read */
402 * Config file currently being read.
403 */
404extern const char *current_config_path; 459extern const char *current_config_path;
405 460
406#endif 461#endif
diff --git a/include/sway/container.h b/include/sway/container.h
deleted file mode 100644
index 37192ce3..00000000
--- a/include/sway/container.h
+++ /dev/null
@@ -1,357 +0,0 @@
1#ifndef _SWAY_CONTAINER_H
2#define _SWAY_CONTAINER_H
3#include <sys/types.h>
4#include <wlc/wlc.h>
5#include <stdint.h>
6
7#include "list.h"
8
9typedef struct sway_container swayc_t;
10
11extern swayc_t root_container;
12extern swayc_t *current_focus;
13
14/**
15 * Different kinds of containers.
16 *
17 * This enum is in order. A container will never be inside of a container below
18 * it on this list.
19 */
20enum swayc_types {
21 C_ROOT, /**< The root container. Only one of these ever exists. */
22 C_OUTPUT, /**< An output (aka monitor, head, etc). */
23 C_WORKSPACE, /**< A workspace. */
24 C_CONTAINER, /**< A manually created container. */
25 C_VIEW, /**< A view (aka window). */
26 // Keep last
27 C_TYPES,
28};
29
30/**
31 * Different ways to arrange a container.
32 */
33enum swayc_layouts {
34 L_NONE, /**< Used for containers that have no layout (views, root) */
35 L_HORIZ,
36 L_VERT,
37 L_STACKED,
38 L_TABBED,
39 L_FLOATING, /**< A psuedo-container, removed from the tree, to hold floating windows */
40
41 /* Awesome/Monad style auto layouts */
42 L_AUTO_LEFT,
43 L_AUTO_RIGHT,
44 L_AUTO_TOP,
45 L_AUTO_BOTTOM,
46
47 L_AUTO_FIRST = L_AUTO_LEFT,
48 L_AUTO_LAST = L_AUTO_BOTTOM,
49
50 // Keep last
51 L_LAYOUTS,
52};
53
54enum swayc_border_types {
55 B_NONE, /**< No border */
56 B_PIXEL, /**< 1px border */
57 B_NORMAL /**< Normal border with title bar */
58};
59
60/**
61 * Stores information about a container.
62 *
63 * The tree is made of these. Views are containers that cannot have children.
64 */
65struct sway_container {
66 /**
67 * If this container maps to a WLC object, this is set to that object's
68 * handle. Otherwise, NULL.
69 */
70 wlc_handle handle;
71
72 /**
73 * A unique ID to identify this container. Primarily used in the
74 * get_tree JSON output.
75 */
76 size_t id;
77
78 enum swayc_types type;
79 enum swayc_layouts layout;
80 enum swayc_layouts prev_layout;
81 enum swayc_layouts workspace_layout;
82
83 /**
84 * Width and height of this container, without borders or gaps.
85 */
86 double width, height;
87
88 /**
89 * Views may request geometry, which is stored in this and ignored until
90 * the views are floated.
91 */
92 int desired_width, desired_height;
93
94 /**
95 * The coordinates that this view appear at, relative to the output they
96 * are located on (output containers have absolute coordinates).
97 */
98 double x, y;
99
100 /**
101 * Cached geometry used to store view/container geometry when switching
102 * between tabbed/stacked and horizontal/vertical layouts.
103 */
104 struct wlc_geometry cached_geometry;
105
106 /**
107 * False if this view is invisible. It could be in the scratchpad or on a
108 * workspace that is not shown.
109 */
110 bool visible;
111 bool is_floating;
112 bool is_focused;
113 bool sticky; // floating view always visible on its output
114
115 // Attributes that mostly views have.
116 char *name;
117 char *class;
118 char *instance;
119 char *app_id;
120
121 // Used by output containers to keep track of swaybg child processes.
122 pid_t bg_pid;
123
124 int gaps;
125
126 list_t *children;
127 /**
128 * Children of this container that are floated.
129 */
130 list_t *floating;
131 /**
132 * Unmanaged view handles in this container.
133 */
134 list_t *unmanaged;
135
136 /**
137 * The parent of this container. NULL for the root container.
138 */
139 struct sway_container *parent;
140 /**
141 * Which of this container's children has focus.
142 */
143 struct sway_container *focused;
144 /**
145 * If this container's children include a fullscreen view, this is that view.
146 */
147 struct sway_container *fullscreen;
148 /**
149 * If this container is a view, this may be set to the window's decoration
150 * buffer (or NULL).
151 */
152 struct border *border;
153 enum swayc_border_types border_type;
154 struct wlc_geometry border_geometry;
155 struct wlc_geometry title_bar_geometry;
156 struct wlc_geometry actual_geometry;
157 int border_thickness;
158
159 /**
160 * Number of master views in auto layouts.
161 */
162 size_t nb_master;
163
164 /**
165 * Number of slave groups (e.g. columns) in auto layouts.
166 */
167 size_t nb_slave_groups;
168
169 /**
170 * Marks applied to the container, list_t of char*.
171 */
172 list_t *marks;
173};
174
175enum visibility_mask {
176 VISIBLE = true
177} visible;
178
179/**
180 * Allocates a new output container.
181 */
182swayc_t *new_output(wlc_handle handle);
183/**
184 * Allocates a new workspace container.
185 */
186swayc_t *new_workspace(swayc_t *output, const char *name);
187/**
188 * Allocates a new container and places a child into it.
189 *
190 * This is used from the split command, which creates a new container with the
191 * requested layout and replaces the focused container in the tree with the new
192 * one. Then the removed container is added as a child of the new container.
193 */
194swayc_t *new_container(swayc_t *child, enum swayc_layouts layout);
195/**
196 * Allocates a new view container.
197 *
198 * Pass in a sibling view, or a workspace to become this container's parent.
199 */
200swayc_t *new_view(swayc_t *sibling, wlc_handle handle);
201/**
202 * Allocates a new floating view in the active workspace.
203 */
204swayc_t *new_floating_view(wlc_handle handle);
205
206void floating_view_sane_size(swayc_t *view);
207
208/**
209 * Frees an output's container.
210 */
211swayc_t *destroy_output(swayc_t *output);
212/**
213 * Destroys a workspace container and returns the parent pointer, or NULL.
214 */
215swayc_t *destroy_workspace(swayc_t *workspace);
216/**
217 * Destroys a container and all empty parents. Returns the topmost non-empty
218 * parent container, or NULL.
219 */
220swayc_t *destroy_container(swayc_t *container);
221/**
222 * Destroys a view container and all empty parents. Returns the topmost
223 * non-empty parent container, or NULL.
224 */
225swayc_t *destroy_view(swayc_t *view);
226
227/**
228 * Finds a container based on test criteria. Returns the first container that
229 * passes the test.
230 */
231swayc_t *swayc_by_test(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data);
232/**
233 * Finds a parent container with the given swayc_type.
234 */
235swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types);
236/**
237 * Finds a parent with the given swayc_layout.
238 */
239swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts);
240/**
241 * Finds the bottom-most focused container of a type.
242 */
243swayc_t *swayc_focus_by_type(swayc_t *container, enum swayc_types);
244/**
245 * Finds the bottom-most focused container of a layout.
246 */
247swayc_t *swayc_focus_by_layout(swayc_t *container, enum swayc_layouts);
248
249/**
250 * Gets the swayc_t associated with a wlc_handle.
251 */
252swayc_t *swayc_by_handle(wlc_handle handle);
253/**
254 * Gets the named swayc_t.
255 */
256swayc_t *swayc_by_name(const char *name);
257/**
258 * Gets the active output's container.
259 */
260swayc_t *swayc_active_output(void);
261/**
262 * Gets the active workspace's container.
263 */
264swayc_t *swayc_active_workspace(void);
265/**
266 * Gets the workspace for the given view container.
267 */
268swayc_t *swayc_active_workspace_for(swayc_t *view);
269/**
270 * Finds the container currently underneath the pointer.
271 */
272swayc_t *container_under_pointer(void);
273/**
274 * Finds the first container following a callback.
275 */
276swayc_t *container_find(swayc_t *container, bool (*f)(swayc_t *, const void *), const void *data);
277
278/**
279 * Returns true if a container is fullscreen.
280 */
281bool swayc_is_fullscreen(swayc_t *view);
282/**
283 * Returns true if this view is focused.
284 */
285bool swayc_is_active(swayc_t *view);
286/**
287 * Returns true if the parent is an ancestor of the child.
288 */
289bool swayc_is_parent_of(swayc_t *parent, swayc_t *child);
290/**
291 * Returns true if the child is a desecendant of the parent.
292 */
293bool swayc_is_child_of(swayc_t *child, swayc_t *parent);
294
295/**
296 * Returns true if this container is an empty workspace.
297 */
298bool swayc_is_empty_workspace(swayc_t *container);
299
300/**
301 * Returns the top most tabbed or stacked parent container. Returns NULL if
302 * view is not in a tabbed/stacked layout.
303 */
304swayc_t *swayc_tabbed_stacked_ancestor(swayc_t *view);
305
306/**
307 * Returns the immediate tabbed or stacked parent container. Returns NULL if
308 * view is not directly in a tabbed/stacked layout.
309 */
310swayc_t *swayc_tabbed_stacked_parent(swayc_t *view);
311
312/**
313 * Returns the gap (padding) of the container.
314 *
315 * This returns the inner gaps for a view, the outer gaps for a workspace, and
316 * 0 otherwise.
317 */
318int swayc_gap(swayc_t *container);
319
320/**
321 * Maps a container's children over a function.
322 */
323void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *);
324
325/**
326 * Set a view as visible or invisible.
327 *
328 * This will perform the required wlc calls as well; it is not sufficient to
329 * simply toggle the boolean in swayc_t.
330 */
331void set_view_visibility(swayc_t *view, void *data);
332/**
333 * Set the gaps value for a view.
334 */
335void set_gaps(swayc_t *view, void *amount);
336/**
337 * Add to the gaps value for a view.
338 */
339void add_gaps(swayc_t *view, void *amount);
340
341/**
342 * Issue wlc calls to make the visibility of a container consistent.
343 */
344void update_visibility(swayc_t *container);
345
346/**
347 * Close all child views of container
348 */
349void close_views(swayc_t *container);
350
351/**
352 * Assign layout to a container. Needed due to workspace container specifics.
353 * Workspace should always have either L_VERT or L_HORIZ layout.
354 */
355swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout);
356
357#endif
diff --git a/include/sway/criteria.h b/include/sway/criteria.h
index c5ed9857..ec256ddb 100644
--- a/include/sway/criteria.h
+++ b/include/sway/criteria.h
@@ -1,7 +1,7 @@
1#ifndef _SWAY_CRITERIA_H 1#ifndef _SWAY_CRITERIA_H
2#define _SWAY_CRITERIA_H 2#define _SWAY_CRITERIA_H
3 3
4#include "container.h" 4#include "tree/container.h"
5#include "list.h" 5#include "list.h"
6 6
7/** 7/**
@@ -31,12 +31,12 @@ char *extract_crit_tokens(list_t *tokens, const char *criteria);
31 31
32// Returns list of criteria that match given container. These criteria have 32// Returns list of criteria that match given container. These criteria have
33// been set with `for_window` commands and have an associated cmdlist. 33// been set with `for_window` commands and have an associated cmdlist.
34list_t *criteria_for(swayc_t *cont); 34list_t *criteria_for(struct sway_container *cont);
35 35
36// Returns a list of all containers that match the given list of tokens. 36// Returns a list of all containers that match the given list of tokens.
37list_t *container_for(list_t *tokens); 37list_t *container_for_crit_tokens(list_t *tokens);
38 38
39// Returns true if any criteria in the given list matches this container 39// Returns true if any criteria in the given list matches this container
40bool criteria_any(swayc_t *cont, list_t *criteria); 40bool criteria_any(struct sway_container *cont, list_t *criteria);
41 41
42#endif 42#endif
diff --git a/include/sway/debug.h b/include/sway/debug.h
new file mode 100644
index 00000000..2430d319
--- /dev/null
+++ b/include/sway/debug.h
@@ -0,0 +1,7 @@
1#ifndef SWAY_DEBUG_H
2#define SWAY_DEBUG_H
3
4extern bool enable_debug_tree;
5void update_debug_tree();
6
7#endif
diff --git a/include/sway/desktop.h b/include/sway/desktop.h
new file mode 100644
index 00000000..f1ad759a
--- /dev/null
+++ b/include/sway/desktop.h
@@ -0,0 +1,4 @@
1#include <wlr/types/wlr_surface.h>
2
3void desktop_damage_surface(struct wlr_surface *surface, double lx, double ly,
4 bool whole);
diff --git a/include/sway/extensions.h b/include/sway/extensions.h
deleted file mode 100644
index 5212eb3a..00000000
--- a/include/sway/extensions.h
+++ /dev/null
@@ -1,56 +0,0 @@
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
45struct decoration_state {
46 list_t *csd_resources;
47};
48
49extern struct desktop_shell_state desktop_shell;
50extern struct decoration_state decoration_state;
51
52void register_extensions(void);
53
54void server_decoration_enable_csd(wlc_handle handle);
55
56#endif
diff --git a/include/sway/focus.h b/include/sway/focus.h
deleted file mode 100644
index 652cdccc..00000000
--- a/include/sway/focus.h
+++ /dev/null
@@ -1,45 +0,0 @@
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 MOVE_NEXT,
11 MOVE_PREV,
12 MOVE_FIRST
13};
14
15#include "container.h"
16
17// focused_container - the container found by following the `focused` pointer
18// from a given container to a container with `is_focused` boolean set
19// ---
20// focused_view - the container found by following the `focused` pointer from a
21// given container to a view.
22// ---
23
24swayc_t *get_focused_container(swayc_t *parent);
25swayc_t *get_focused_view(swayc_t *parent);
26swayc_t *get_focused_float(swayc_t *ws);
27
28// a special-case function to get the focused view, regardless
29// of whether it's tiled or floating
30swayc_t *get_focused_view_include_floating(swayc_t *parent);
31
32bool set_focused_container(swayc_t *container);
33bool set_focused_container_for(swayc_t *ancestor, swayc_t *container);
34
35// lock focused container/view. locked by windows with OVERRIDE attribute
36// and unlocked when they are destroyed
37
38extern bool locked_container_focus;
39
40// Prevents wss from being destroyed on focus switch
41extern bool suspend_workspace_cleanup;
42
43bool move_focus(enum movement_direction direction);
44
45#endif
diff --git a/include/sway/handlers.h b/include/sway/handlers.h
deleted file mode 100644
index 956b98f4..00000000
--- a/include/sway/handlers.h
+++ /dev/null
@@ -1,11 +0,0 @@
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
deleted file mode 100644
index 4ed9bffe..00000000
--- a/include/sway/input.h
+++ /dev/null
@@ -1,23 +0,0 @@
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/cursor.h b/include/sway/input/cursor.h
new file mode 100644
index 00000000..fcd94437
--- /dev/null
+++ b/include/sway/input/cursor.h
@@ -0,0 +1,36 @@
1#ifndef _SWAY_INPUT_CURSOR_H
2#define _SWAY_INPUT_CURSOR_H
3#include <stdint.h>
4#include "sway/input/seat.h"
5
6struct sway_cursor {
7 struct sway_seat *seat;
8 struct wlr_cursor *cursor;
9 struct wlr_xcursor_manager *xcursor_manager;
10
11 struct wl_client *image_client;
12
13 struct wl_listener motion;
14 struct wl_listener motion_absolute;
15 struct wl_listener button;
16 struct wl_listener axis;
17
18 struct wl_listener touch_down;
19 struct wl_listener touch_up;
20 struct wl_listener touch_motion;
21
22 struct wl_listener tool_axis;
23 struct wl_listener tool_tip;
24 struct wl_listener tool_button;
25 uint32_t tool_buttons;
26
27 struct wl_listener request_set_cursor;
28};
29
30void sway_cursor_destroy(struct sway_cursor *cursor);
31struct sway_cursor *sway_cursor_create(struct sway_seat *seat);
32void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time);
33void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t time_msec,
34 uint32_t button, enum wlr_button_state state);
35
36#endif
diff --git a/include/sway/input/input-manager.h b/include/sway/input/input-manager.h
new file mode 100644
index 00000000..89a3ac71
--- /dev/null
+++ b/include/sway/input/input-manager.h
@@ -0,0 +1,64 @@
1#ifndef _SWAY_INPUT_INPUT_MANAGER_H
2#define _SWAY_INPUT_INPUT_MANAGER_H
3#include <libinput.h>
4#include <wlr/types/wlr_input_inhibitor.h>
5#include "sway/server.h"
6#include "sway/config.h"
7#include "list.h"
8
9/**
10 * The global singleton input manager
11 * TODO: make me not a global
12 */
13extern struct sway_input_manager *input_manager;
14
15struct sway_input_device {
16 char *identifier;
17 struct wlr_input_device *wlr_device;
18 struct wl_list link;
19 struct wl_listener device_destroy;
20};
21
22struct sway_input_manager {
23 struct sway_server *server;
24 struct wl_list devices;
25 struct wl_list seats;
26
27 struct wlr_input_inhibit_manager *inhibit;
28
29 struct wl_listener new_input;
30 struct wl_listener inhibit_activate;
31 struct wl_listener inhibit_deactivate;
32};
33
34struct sway_input_manager *input_manager_create(struct sway_server *server);
35
36bool input_manager_has_focus(struct sway_input_manager *input,
37 struct sway_container *container);
38
39void input_manager_set_focus(struct sway_input_manager *input,
40 struct sway_container *container);
41
42void input_manager_configure_xcursor(struct sway_input_manager *input);
43
44void input_manager_apply_input_config(struct sway_input_manager *input,
45 struct input_config *input_config);
46
47void input_manager_apply_seat_config(struct sway_input_manager *input,
48 struct seat_config *seat_config);
49
50struct sway_seat *input_manager_get_default_seat(
51 struct sway_input_manager *input);
52
53struct sway_seat *input_manager_get_seat(struct sway_input_manager *input,
54 const char *seat_name);
55
56/**
57 * Gets the last seat the user interacted with
58 */
59struct sway_seat *input_manager_current_seat(struct sway_input_manager *input);
60
61struct input_config *input_device_get_config(struct sway_input_device *device);
62
63
64#endif
diff --git a/include/sway/input/keyboard.h b/include/sway/input/keyboard.h
new file mode 100644
index 00000000..8ec3eb35
--- /dev/null
+++ b/include/sway/input/keyboard.h
@@ -0,0 +1,30 @@
1#ifndef _SWAY_INPUT_KEYBOARD_H
2#define _SWAY_INPUT_KEYBOARD_H
3
4#include "sway/input/seat.h"
5
6#define SWAY_KEYBOARD_PRESSED_KEYSYMS_CAP 32
7
8struct sway_keyboard {
9 struct sway_seat_device *seat_device;
10
11 struct xkb_keymap *keymap;
12
13 struct wl_listener keyboard_key;
14 struct wl_listener keyboard_modifiers;
15
16 xkb_keysym_t pressed_keysyms_translated[SWAY_KEYBOARD_PRESSED_KEYSYMS_CAP];
17 uint32_t modifiers_translated;
18
19 xkb_keysym_t pressed_keysyms_raw[SWAY_KEYBOARD_PRESSED_KEYSYMS_CAP];
20 uint32_t modifiers_raw;
21};
22
23struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat,
24 struct sway_seat_device *device);
25
26void sway_keyboard_configure(struct sway_keyboard *keyboard);
27
28void sway_keyboard_destroy(struct sway_keyboard *keyboard);
29
30#endif
diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h
new file mode 100644
index 00000000..ff76841e
--- /dev/null
+++ b/include/sway/input/seat.h
@@ -0,0 +1,111 @@
1#ifndef _SWAY_INPUT_SEAT_H
2#define _SWAY_INPUT_SEAT_H
3
4#include <wlr/types/wlr_layer_shell.h>
5#include <wlr/types/wlr_seat.h>
6#include "sway/input/input-manager.h"
7
8struct sway_seat_device {
9 struct sway_seat *sway_seat;
10 struct sway_input_device *input_device;
11 struct sway_keyboard *keyboard;
12 struct wl_list link; // sway_seat::devices
13};
14
15struct sway_seat_container {
16 struct sway_seat *seat;
17 struct sway_container *container;
18
19 struct wl_list link; // sway_seat::focus_stack
20
21 struct wl_listener destroy;
22};
23
24struct sway_seat {
25 struct wlr_seat *wlr_seat;
26 struct sway_cursor *cursor;
27 struct sway_input_manager *input;
28
29 bool has_focus;
30 struct wl_list focus_stack; // list of containers in focus order
31
32 // If the focused layer is set, views cannot receive keyboard focus
33 struct wlr_layer_surface *focused_layer;
34
35 // If exclusive_client is set, no other clients will receive input events
36 struct wl_client *exclusive_client;
37
38 struct wl_listener focus_destroy;
39 struct wl_listener new_container;
40
41 struct wl_list devices; // sway_seat_device::link
42
43 struct wl_list link; // input_manager::seats
44};
45
46struct sway_seat *seat_create(struct sway_input_manager *input,
47 const char *seat_name);
48
49void seat_destroy(struct sway_seat *seat);
50
51void seat_add_device(struct sway_seat *seat,
52 struct sway_input_device *device);
53
54void seat_configure_device(struct sway_seat *seat,
55 struct sway_input_device *device);
56
57void seat_remove_device(struct sway_seat *seat,
58 struct sway_input_device *device);
59
60void seat_configure_xcursor(struct sway_seat *seat);
61
62void seat_set_focus(struct sway_seat *seat, struct sway_container *container);
63
64void seat_set_focus_warp(struct sway_seat *seat,
65 struct sway_container *container, bool warp);
66
67void seat_set_focus_surface(struct sway_seat *seat,
68 struct wlr_surface *surface);
69
70void seat_set_focus_layer(struct sway_seat *seat,
71 struct wlr_layer_surface *layer);
72
73void seat_set_exclusive_client(struct sway_seat *seat,
74 struct wl_client *client);
75
76struct sway_container *seat_get_focus(struct sway_seat *seat);
77
78/**
79 * Return the last container to be focused for the seat (or the most recently
80 * opened if no container has received focused) that is a child of the given
81 * container. The focus-inactive container of the root window is the focused
82 * container for the seat (if the seat does have focus). This function can be
83 * used to determine what container gets focused next if the focused container
84 * is destroyed, or focus moves to a container with children and we need to
85 * descend into the next leaf in focus order.
86 */
87struct sway_container *seat_get_focus_inactive(struct sway_seat *seat,
88 struct sway_container *container);
89
90/**
91 * Descend into the focus stack to find the focus-inactive view. Useful for
92 * container placement when they change position in the tree.
93 */
94struct sway_container *seat_get_focus_inactive_view(struct sway_seat *seat,
95 struct sway_container *container);
96
97/**
98 * Iterate over the focus-inactive children of the container calling the
99 * function on each.
100 */
101void seat_focus_inactive_children_for_each(struct sway_seat *seat,
102 struct sway_container *container,
103 void (*f)(struct sway_container *container, void *data), void *data);
104
105void seat_apply_config(struct sway_seat *seat, struct seat_config *seat_config);
106
107struct seat_config *seat_get_config(struct sway_seat *seat);
108
109bool seat_is_input_allowed(struct sway_seat *seat, struct wlr_surface *surface);
110
111#endif
diff --git a/include/sway/input_state.h b/include/sway/input_state.h
deleted file mode 100644
index fd5a3a25..00000000
--- a/include/sway/input_state.h
+++ /dev/null
@@ -1,102 +0,0 @@
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(double new_x, double new_y, 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
index 3a5af0f5..7d87d377 100644
--- a/include/sway/ipc-json.h
+++ b/include/sway/ipc-json.h
@@ -1,15 +1,14 @@
1#ifndef _SWAY_IPC_JSON_H 1#ifndef _SWAY_IPC_JSON_H
2#define _SWAY_IPC_JSON_H 2#define _SWAY_IPC_JSON_H
3
4#include <json-c/json.h> 3#include <json-c/json.h>
5#include "config.h" 4#include "sway/tree/container.h"
6#include "container.h" 5#include "sway/input/input-manager.h"
7 6
8json_object *ipc_json_get_version(); 7json_object *ipc_json_get_version();
8
9json_object *ipc_json_describe_container(struct sway_container *c);
10json_object *ipc_json_describe_container_recursive(struct sway_container *c);
11json_object *ipc_json_describe_input(struct sway_input_device *device);
9json_object *ipc_json_describe_bar_config(struct bar_config *bar); 12json_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);
13json_object *ipc_json_describe_input(struct libinput_device *device);
14 13
15#endif 14#endif
diff --git a/include/sway/ipc-server.h b/include/sway/ipc-server.h
index 1d199134..c3389fe8 100644
--- a/include/sway/ipc-server.h
+++ b/include/sway/ipc-server.h
@@ -1,41 +1,21 @@
1#ifndef _SWAY_IPC_SERVER_H 1#ifndef _SWAY_IPC_SERVER_H
2#define _SWAY_IPC_SERVER_H 2#define _SWAY_IPC_SERVER_H
3#include <sys/socket.h>
4#include "sway/tree/container.h"
5#include "ipc.h"
3 6
4#include <wlc/wlc.h> 7struct sway_server;
5 8
6#include "container.h" 9void ipc_init(struct sway_server *server);
7#include "config.h"
8#include "ipc.h"
9 10
10void ipc_init(void);
11void ipc_terminate(void); 11void ipc_terminate(void);
12
12struct sockaddr_un *ipc_user_sockaddr(void); 13struct sockaddr_un *ipc_user_sockaddr(void);
13 14
14void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change); 15void ipc_event_workspace(struct sway_container *old,
16 struct sway_container *new, const char *change);
17void ipc_event_window(struct sway_container *window, const char *change);
15void ipc_event_barconfig_update(struct bar_config *bar); 18void 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); 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 20
41#endif 21#endif
diff --git a/include/sway/layers.h b/include/sway/layers.h
new file mode 100644
index 00000000..ee47c5ad
--- /dev/null
+++ b/include/sway/layers.h
@@ -0,0 +1,25 @@
1#ifndef _SWAY_LAYERS_H
2#define _SWAY_LAYERS_H
3#include <stdbool.h>
4#include <wlr/types/wlr_box.h>
5#include <wlr/types/wlr_surface.h>
6#include <wlr/types/wlr_layer_shell.h>
7
8struct sway_layer_surface {
9 struct wlr_layer_surface *layer_surface;
10 struct wl_list link;
11
12 struct wl_listener destroy;
13 struct wl_listener map;
14 struct wl_listener unmap;
15 struct wl_listener surface_commit;
16 struct wl_listener output_destroy;
17
18 bool configured;
19 struct wlr_box geo;
20};
21
22struct sway_output;
23void arrange_layers(struct sway_output *output);
24
25#endif
diff --git a/include/sway/layout.h b/include/sway/layout.h
deleted file mode 100644
index f0791588..00000000
--- a/include/sway/layout.h
+++ /dev/null
@@ -1,85 +0,0 @@
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, int move_amt);
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
78bool is_auto_layout(enum swayc_layouts layout);
79int auto_group_start_index(const swayc_t *container, int index);
80int auto_group_end_index(const swayc_t *container, int index);
81size_t auto_group_count(const swayc_t *container);
82size_t auto_group_index(const swayc_t *container, int index);
83bool auto_group_bounds(const swayc_t *container, size_t group_index, int *start, int *end);
84
85#endif
diff --git a/include/sway/output.h b/include/sway/output.h
index e1bdd3f0..56571548 100644
--- a/include/sway/output.h
+++ b/include/sway/output.h
@@ -1,25 +1,48 @@
1#ifndef _SWAY_OUTPUT_H 1#ifndef _SWAY_OUTPUT_H
2#define _SWAY_OUTPUT_H 2#define _SWAY_OUTPUT_H
3#include <time.h>
4#include <unistd.h>
5#include <wayland-server.h>
6#include <wlr/types/wlr_box.h>
7#include <wlr/types/wlr_output.h>
8#include "sway/tree/view.h"
3 9
4#include "container.h" 10struct sway_server;
5#include "focus.h" 11struct sway_container;
6 12
7// Position is absolute coordinates on the edge where the adjacent output 13struct sway_output {
8// should be searched for. 14 struct wlr_output *wlr_output;
9swayc_t *output_by_name(const char* name, const struct wlc_point *abs_pos); 15 struct sway_container *swayc;
10swayc_t *swayc_opposite_output(enum movement_direction dir, const struct wlc_point *abs_pos); 16 struct sway_server *server;
11swayc_t *swayc_adjacent_output(swayc_t *output, enum movement_direction dir, const struct wlc_point *abs_pos, bool pick_closest);
12 17
13// Place absolute coordinates for given container into given wlc_point. 18 struct wl_list layers[4]; // sway_layer_surface::link
14void get_absolute_position(swayc_t *container, struct wlc_point *point); 19 struct wlr_box usable_area;
15 20
16// Place absolute coordinates for the center point of given container into 21 struct timespec last_frame;
17// given wlc_point. 22 struct wlr_output_damage *damage;
18void get_absolute_center_position(swayc_t *container, struct wlc_point *point);
19 23
20// stable sort workspaces on this output 24 struct wl_listener destroy;
21void sort_workspaces(swayc_t *output); 25 struct wl_listener mode;
26 struct wl_listener transform;
27 struct wl_listener scale;
22 28
23void output_get_scaled_size(wlc_handle handle, struct wlc_size *size); 29 struct wl_listener damage_destroy;
30 struct wl_listener damage_frame;
31
32 pid_t bg_pid;
33};
34
35void output_damage_whole(struct sway_output *output);
36
37void output_damage_surface(struct sway_output *output, double ox, double oy,
38 struct wlr_surface *surface, bool whole);
39
40void output_damage_view(struct sway_output *output, struct sway_view *view,
41 bool whole);
42
43void output_damage_whole_container(struct sway_output *output,
44 struct sway_container *con);
45
46struct sway_container *output_by_name(const char *name);
24 47
25#endif 48#endif
diff --git a/include/sway/server.h b/include/sway/server.h
new file mode 100644
index 00000000..296fbf22
--- /dev/null
+++ b/include/sway/server.h
@@ -0,0 +1,57 @@
1#ifndef _SWAY_SERVER_H
2#define _SWAY_SERVER_H
3#include <stdbool.h>
4#include <wayland-server.h>
5#include <wlr/backend.h>
6#include <wlr/backend/session.h>
7#include <wlr/types/wlr_compositor.h>
8#include <wlr/types/wlr_data_device.h>
9#include <wlr/types/wlr_layer_shell.h>
10#include <wlr/types/wlr_xdg_shell_v6.h>
11#include <wlr/render/wlr_renderer.h>
12// TODO WLR: make Xwayland optional
13#include <wlr/xwayland.h>
14
15struct sway_server {
16 struct wl_display *wl_display;
17 struct wl_event_loop *wl_event_loop;
18 const char *socket;
19
20 struct wlr_backend *backend;
21
22 struct wlr_compositor *compositor;
23 struct wlr_data_device_manager *data_device_manager;
24
25 struct sway_input_manager *input;
26
27 struct wl_listener new_output;
28
29 struct wlr_layer_shell *layer_shell;
30 struct wl_listener layer_shell_surface;
31
32 struct wlr_xdg_shell_v6 *xdg_shell_v6;
33 struct wl_listener xdg_shell_v6_surface;
34
35 struct wlr_xwayland *xwayland;
36 struct wlr_xcursor_manager *xcursor_manager;
37 struct wl_listener xwayland_surface;
38 struct wl_listener xwayland_ready;
39
40 struct wlr_wl_shell *wl_shell;
41 struct wl_listener wl_shell_surface;
42};
43
44struct sway_server server;
45
46bool server_init(struct sway_server *server);
47void server_fini(struct sway_server *server);
48void server_run(struct sway_server *server);
49
50void handle_new_output(struct wl_listener *listener, void *data);
51
52void handle_layer_shell_surface(struct wl_listener *listener, void *data);
53void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data);
54void handle_xwayland_surface(struct wl_listener *listener, void *data);
55void handle_wl_shell_surface(struct wl_listener *listener, void *data);
56
57#endif
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
new file mode 100644
index 00000000..2a8b8aba
--- /dev/null
+++ b/include/sway/tree/container.h
@@ -0,0 +1,192 @@
1#ifndef _SWAY_CONTAINER_H
2#define _SWAY_CONTAINER_H
3#include <stdint.h>
4#include <sys/types.h>
5#include <wlr/types/wlr_box.h>
6#include <wlr/types/wlr_surface.h>
7#include "list.h"
8
9extern struct sway_container root_container;
10
11struct sway_view;
12struct sway_seat;
13
14/**
15 * Different kinds of containers.
16 *
17 * This enum is in order. A container will never be inside of a container below
18 * it on this list.
19 */
20enum sway_container_type {
21 C_ROOT,
22 C_OUTPUT,
23 C_WORKSPACE,
24 C_CONTAINER,
25 C_VIEW,
26
27 // Keep last
28 C_TYPES,
29};
30
31enum sway_container_layout {
32 L_NONE,
33 L_HORIZ,
34 L_VERT,
35 L_STACKED,
36 L_TABBED,
37 L_FLOATING,
38};
39
40enum sway_container_border {
41 B_NONE,
42 B_PIXEL,
43 B_NORMAL,
44};
45
46struct sway_root;
47struct sway_output;
48struct sway_view;
49
50struct sway_container {
51 union {
52 // TODO: Encapsulate state for other node types as well like C_CONTAINER
53 struct sway_root *sway_root;
54 struct sway_output *sway_output;
55 struct sway_view *sway_view;
56 };
57
58 /**
59 * A unique ID to identify this container. Primarily used in the
60 * get_tree JSON output.
61 */
62 size_t id;
63
64 char *name;
65
66 enum sway_container_type type;
67 enum sway_container_layout layout;
68 enum sway_container_layout prev_layout;
69 enum sway_container_layout workspace_layout;
70
71 // For C_ROOT, this has no meaning
72 // For C_OUTPUT, this is the output position in layout coordinates
73 // For other types, this is the position in output-local coordinates
74 double x, y;
75 // does not include borders or gaps.
76 double width, height;
77
78 list_t *children;
79
80 struct sway_container *parent;
81
82 list_t *marks; // list of char*
83
84 float alpha;
85
86 struct {
87 struct wl_signal destroy;
88 // Raised after the tree updates, but before arrange_windows
89 // Passed the previous parent
90 struct wl_signal reparent;
91 } events;
92};
93
94struct sway_container *container_create(enum sway_container_type type);
95
96const char *container_type_to_str(enum sway_container_type type);
97
98struct sway_container *output_create(struct sway_output *sway_output);
99
100/**
101 * Create a new container container. A container container can be a a child of
102 * a workspace container or another container container.
103 */
104struct sway_container *container_container_create();
105
106/**
107 * Create a new output. Outputs are children of the root container and have no
108 * order in the tree structure.
109 */
110struct sway_container *output_create(struct sway_output *sway_output);
111
112/**
113 * Create a new workspace container. Workspaces are children of an output
114 * container and are ordered alphabetically by name.
115 */
116struct sway_container *workspace_create(struct sway_container *output,
117 const char *name);
118
119/*
120 * Create a new view container. A view can be a child of a workspace container
121 * or a container container and are rendered in the order and structure of
122 * how they are attached to the tree.
123 */
124struct sway_container *container_view_create(
125 struct sway_container *sibling, struct sway_view *sway_view);
126
127struct sway_container *container_destroy(struct sway_container *container);
128
129struct sway_container *container_close(struct sway_container *container);
130
131void container_descendants(struct sway_container *root,
132 enum sway_container_type type,
133 void (*func)(struct sway_container *item, void *data), void *data);
134
135/**
136 * Search a container's descendants a container based on test criteria. Returns
137 * the first container that passes the test.
138 */
139struct sway_container *container_find(struct sway_container *container,
140 bool (*test)(struct sway_container *view, void *data), void *data);
141
142/**
143 * Finds a parent container with the given struct sway_containerype.
144 */
145struct sway_container *container_parent(struct sway_container *container,
146 enum sway_container_type type);
147
148/**
149 * Find a container at the given coordinates. Returns the the surface and
150 * surface-local coordinates of the given layout coordinates if the container
151 * is a view and the view contains a surface at those coordinates.
152 */
153struct sway_container *container_at(struct sway_container *container,
154 double lx, double ly, struct wlr_surface **surface,
155 double *sx, double *sy);
156
157/**
158 * Apply the function for each descendant of the container breadth first.
159 */
160void container_for_each_descendant_bfs(struct sway_container *container,
161 void (*f)(struct sway_container *container, void *data), void *data);
162
163/**
164 * Apply the function for each child of the container depth first.
165 */
166void container_for_each_descendant_dfs(struct sway_container *container,
167 void (*f)(struct sway_container *container, void *data), void *data);
168
169/**
170 * Returns true if the given container is an ancestor of this container.
171 */
172bool container_has_anscestor(struct sway_container *container,
173 struct sway_container *anscestor);
174
175/**
176 * Returns true if the given container is a child descendant of this container.
177 */
178bool container_has_child(struct sway_container *con,
179 struct sway_container *child);
180
181void container_create_notify(struct sway_container *container);
182
183void container_damage_whole(struct sway_container *container);
184
185bool container_reap_empty(struct sway_container *con);
186
187struct sway_container *container_reap_empty_recursive(
188 struct sway_container *con);
189
190struct sway_container *container_flatten(struct sway_container *container);
191
192#endif
diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h
new file mode 100644
index 00000000..49ae00e4
--- /dev/null
+++ b/include/sway/tree/layout.h
@@ -0,0 +1,78 @@
1#ifndef _SWAY_LAYOUT_H
2#define _SWAY_LAYOUT_H
3#include <wlr/types/wlr_output_layout.h>
4#include <wlr/render/wlr_texture.h>
5#include "sway/tree/container.h"
6
7enum movement_direction {
8 MOVE_LEFT,
9 MOVE_RIGHT,
10 MOVE_UP,
11 MOVE_DOWN,
12 MOVE_PARENT,
13 MOVE_CHILD,
14};
15
16enum resize_edge {
17 RESIZE_EDGE_LEFT,
18 RESIZE_EDGE_RIGHT,
19 RESIZE_EDGE_TOP,
20 RESIZE_EDGE_BOTTOM,
21};
22
23struct sway_container;
24
25struct sway_root {
26 struct wlr_output_layout *output_layout;
27
28 struct wl_listener output_layout_change;
29
30 struct wl_list xwayland_unmanaged; // sway_xwayland_unmanaged::link
31
32 struct wlr_texture *debug_tree;
33
34 struct {
35 struct wl_signal new_container;
36 } events;
37};
38
39void layout_init(void);
40
41void container_add_child(struct sway_container *parent,
42 struct sway_container *child);
43
44struct sway_container *container_add_sibling(struct sway_container *parent,
45 struct sway_container *child);
46
47struct sway_container *container_remove_child(struct sway_container *child);
48
49struct sway_container *container_replace_child(struct sway_container *child,
50 struct sway_container *new_child);
51
52struct sway_container *container_set_layout(struct sway_container *container,
53 enum sway_container_layout layout);
54
55void container_move_to(struct sway_container* container,
56 struct sway_container* destination);
57
58void container_move(struct sway_container *container,
59 enum movement_direction dir, int move_amt);
60
61enum sway_container_layout container_get_default_layout(
62 struct sway_container *con);
63
64void container_sort_workspaces(struct sway_container *output);
65
66void arrange_windows(struct sway_container *container,
67 double width, double height);
68
69struct sway_container *container_get_in_direction(struct sway_container
70 *container, struct sway_seat *seat, enum movement_direction dir);
71
72struct sway_container *container_split(struct sway_container *child,
73 enum sway_container_layout layout);
74
75void container_recursive_resize(struct sway_container *container,
76 double amount, enum resize_edge edge);
77
78#endif
diff --git a/include/sway/tree/output.h b/include/sway/tree/output.h
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/include/sway/tree/output.h
diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h
new file mode 100644
index 00000000..b51c54b5
--- /dev/null
+++ b/include/sway/tree/view.h
@@ -0,0 +1,186 @@
1#ifndef _SWAY_VIEW_H
2#define _SWAY_VIEW_H
3#include <wayland-server.h>
4#include <wlr/types/wlr_surface.h>
5#include <wlr/types/wlr_xdg_shell_v6.h>
6#include <wlr/xwayland.h>
7#include "sway/input/input-manager.h"
8#include "sway/input/seat.h"
9
10struct sway_container;
11
12enum sway_view_type {
13 SWAY_VIEW_WL_SHELL,
14 SWAY_VIEW_XDG_SHELL_V6,
15 SWAY_VIEW_XWAYLAND,
16};
17
18enum sway_view_prop {
19 VIEW_PROP_TITLE,
20 VIEW_PROP_APP_ID,
21 VIEW_PROP_CLASS,
22 VIEW_PROP_INSTANCE,
23};
24
25struct sway_view_impl {
26 const char *(*get_prop)(struct sway_view *view,
27 enum sway_view_prop prop);
28 void (*configure)(struct sway_view *view, double ox, double oy, int width,
29 int height);
30 void (*set_activated)(struct sway_view *view, bool activated);
31 void (*for_each_surface)(struct sway_view *view,
32 wlr_surface_iterator_func_t iterator, void *user_data);
33 void (*close)(struct sway_view *view);
34 void (*destroy)(struct sway_view *view);
35};
36
37struct sway_view {
38 enum sway_view_type type;
39 const struct sway_view_impl *impl;
40
41 struct sway_container *swayc; // NULL for unmanaged views
42 struct wlr_surface *surface; // NULL for unmapped views
43 int width, height;
44
45 union {
46 struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6;
47 struct wlr_xwayland_surface *wlr_xwayland_surface;
48 struct wlr_wl_shell_surface *wlr_wl_shell_surface;
49 };
50
51 struct {
52 struct wl_signal unmap;
53 } events;
54
55 struct wl_listener surface_new_subsurface;
56 struct wl_listener container_reparent;
57};
58
59struct sway_xdg_shell_v6_view {
60 struct sway_view view;
61
62 struct wl_listener commit;
63 struct wl_listener request_move;
64 struct wl_listener request_resize;
65 struct wl_listener request_maximize;
66 struct wl_listener new_popup;
67 struct wl_listener map;
68 struct wl_listener unmap;
69 struct wl_listener destroy;
70
71 int pending_width, pending_height;
72};
73
74struct sway_xwayland_view {
75 struct sway_view view;
76
77 struct wl_listener commit;
78 struct wl_listener request_move;
79 struct wl_listener request_resize;
80 struct wl_listener request_maximize;
81 struct wl_listener request_configure;
82 struct wl_listener map;
83 struct wl_listener unmap;
84 struct wl_listener destroy;
85
86 int pending_width, pending_height;
87};
88
89struct sway_xwayland_unmanaged {
90 struct wlr_xwayland_surface *wlr_xwayland_surface;
91 struct wl_list link;
92
93 int lx, ly;
94
95 struct wl_listener request_configure;
96 struct wl_listener commit;
97 struct wl_listener map;
98 struct wl_listener unmap;
99 struct wl_listener destroy;
100};
101
102struct sway_wl_shell_view {
103 struct sway_view view;
104
105 struct wl_listener commit;
106 struct wl_listener request_move;
107 struct wl_listener request_resize;
108 struct wl_listener request_maximize;
109 struct wl_listener destroy;
110
111 int pending_width, pending_height;
112};
113
114struct sway_view_child;
115
116struct sway_view_child_impl {
117 void (*destroy)(struct sway_view_child *child);
118};
119
120/**
121 * A view child is a surface in the view tree, such as a subsurface or a popup.
122 */
123struct sway_view_child {
124 const struct sway_view_child_impl *impl;
125
126 struct sway_view *view;
127 struct wlr_surface *surface;
128
129 struct wl_listener surface_commit;
130 struct wl_listener surface_new_subsurface;
131 struct wl_listener surface_destroy;
132 struct wl_listener view_unmap;
133};
134
135struct sway_xdg_popup_v6 {
136 struct sway_view_child child;
137
138 struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6;
139
140 struct wl_listener new_popup;
141 struct wl_listener unmap;
142 struct wl_listener destroy;
143};
144
145const char *view_get_title(struct sway_view *view);
146
147const char *view_get_app_id(struct sway_view *view);
148
149const char *view_get_class(struct sway_view *view);
150
151const char *view_get_instance(struct sway_view *view);
152
153void view_configure(struct sway_view *view, double ox, double oy, int width,
154 int height);
155
156void view_set_activated(struct sway_view *view, bool activated);
157
158void view_close(struct sway_view *view);
159
160void view_damage(struct sway_view *view, bool whole);
161
162void view_for_each_surface(struct sway_view *view,
163 wlr_surface_iterator_func_t iterator, void *user_data);
164
165// view implementation
166
167void view_init(struct sway_view *view, enum sway_view_type type,
168 const struct sway_view_impl *impl);
169
170void view_destroy(struct sway_view *view);
171
172void view_map(struct sway_view *view, struct wlr_surface *wlr_surface);
173
174void view_unmap(struct sway_view *view);
175
176void view_update_position(struct sway_view *view, double ox, double oy);
177
178void view_update_size(struct sway_view *view, int width, int height);
179
180void view_child_init(struct sway_view_child *child,
181 const struct sway_view_child_impl *impl, struct sway_view *view,
182 struct wlr_surface *surface);
183
184void view_child_destroy(struct sway_view_child *child);
185
186#endif
diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h
new file mode 100644
index 00000000..8d49fefb
--- /dev/null
+++ b/include/sway/tree/workspace.h
@@ -0,0 +1,26 @@
1#ifndef _SWAY_WORKSPACE_H
2#define _SWAY_WORKSPACE_H
3
4#include "sway/tree/container.h"
5
6extern char *prev_workspace_name;
7
8char *workspace_next_name(const char *output_name);
9
10bool workspace_switch(struct sway_container *workspace);
11
12struct sway_container *workspace_by_number(const char* name);
13
14struct sway_container *workspace_by_name(const char*);
15
16struct sway_container *workspace_output_next(struct sway_container *current);
17
18struct sway_container *workspace_next(struct sway_container *current);
19
20struct sway_container *workspace_output_prev(struct sway_container *current);
21
22struct sway_container *workspace_prev(struct sway_container *current);
23
24bool workspace_is_visible(struct sway_container *ws);
25
26#endif
diff --git a/include/sway/workspace.h b/include/sway/workspace.h
deleted file mode 100644
index c268fafa..00000000
--- a/include/sway/workspace.h
+++ /dev/null
@@ -1,22 +0,0 @@
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
diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h
index 50d36e76..0037190b 100644
--- a/include/swaybar/bar.h
+++ b/include/swaybar/bar.h
@@ -1,36 +1,71 @@
1#ifndef _SWAYBAR_BAR_H 1#ifndef _SWAYBAR_BAR_H
2#define _SWAYBAR_BAR_H 2#define _SWAYBAR_BAR_H
3#include <wayland-client.h>
4#include "pool-buffer.h"
3 5
4#include "client/registry.h" 6struct swaybar_config;
5#include "client/window.h" 7struct swaybar_output;
6#include "list.h" 8struct swaybar_workspace;
7 9
8struct bar { 10struct swaybar_pointer {
9 struct config *config; 11 struct wl_pointer *pointer;
12 struct wl_cursor_theme *cursor_theme;
13 struct wl_cursor_image *cursor_image;
14 struct wl_surface *cursor_surface;
15 struct swaybar_output *current;
16 int x, y;
17};
18
19struct swaybar_hotspot {
20 struct wl_list link;
21 int x, y, width, height;
22 void (*callback)(struct swaybar_output *output,
23 int x, int y, uint32_t button, void *data);
24 void (*destroy)(void *data);
25 void *data;
26};
27
28struct swaybar {
29 struct wl_display *display;
30 struct wl_compositor *compositor;
31 struct zwlr_layer_shell_v1 *layer_shell;
32 struct wl_shm *shm;
33 struct wl_seat *seat;
34
35 struct swaybar_config *config;
36 struct swaybar_output *focused_output;
37 struct swaybar_pointer pointer;
10 struct status_line *status; 38 struct status_line *status;
11 list_t *outputs;
12 struct output *focused_output;
13 39
14 int ipc_event_socketfd; 40 int ipc_event_socketfd;
15 int ipc_socketfd; 41 int ipc_socketfd;
16 int status_read_fd; 42
17 int status_write_fd; 43 struct wl_list outputs;
18 pid_t status_command_pid;
19}; 44};
20 45
21struct output { 46struct swaybar_output {
22 struct window *window; 47 struct wl_list link;
23 struct registry *registry; 48 struct swaybar *bar;
24 list_t *workspaces; 49 struct wl_output *output;
25#ifdef ENABLE_TRAY 50 struct wl_surface *surface;
26 list_t *items; 51 struct zwlr_layer_surface_v1 *layer_surface;
27#endif 52 uint32_t wl_name;
53
54 struct wl_list workspaces;
55 struct wl_list hotspots;
56
28 char *name; 57 char *name;
29 int idx; 58 size_t index;
30 bool focused; 59 bool focused;
60
61 uint32_t width, height;
62 int32_t scale;
63 struct pool_buffer buffers[2];
64 struct pool_buffer *current_buffer;
31}; 65};
32 66
33struct workspace { 67struct swaybar_workspace {
68 struct wl_list link;
34 int num; 69 int num;
35 char *name; 70 char *name;
36 bool focused; 71 bool focused;
@@ -38,35 +73,10 @@ struct workspace {
38 bool urgent; 73 bool urgent;
39}; 74};
40 75
41/** Global bar state */ 76void bar_setup(struct swaybar *bar,
42extern struct bar swaybar; 77 const char *socket_path,
43 78 const char *bar_id);
44/** True if sway needs to render */ 79void bar_run(struct swaybar *bar);
45extern bool dirty; 80void bar_teardown(struct swaybar *bar);
46
47/**
48 * Setup bar.
49 */
50void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id);
51
52/**
53 * Create new output struct from name.
54 */
55struct output *new_output(const char *name);
56 81
57/** 82#endif
58 * Bar mainloop.
59 */
60void bar_run(struct bar *bar);
61
62/**
63 * free workspace list.
64 */
65void free_workspaces(list_t *workspaces);
66
67/**
68 * Teardown bar.
69 */
70void bar_teardown(struct bar *bar);
71
72#endif /* _SWAYBAR_BAR_H */
diff --git a/include/swaybar/config.h b/include/swaybar/config.h
index 651f0ee3..7f321df8 100644
--- a/include/swaybar/config.h
+++ b/include/swaybar/config.h
@@ -1,49 +1,36 @@
1#ifndef _SWAYBAR_CONFIG_H 1#ifndef _SWAYBAR_CONFIG_H
2#define _SWAYBAR_CONFIG_H 2#define _SWAYBAR_CONFIG_H
3
4#include <stdint.h>
5#include <stdbool.h> 3#include <stdbool.h>
6 4#include <stdint.h>
7#include "list.h" 5#include <wayland-client.h>
8#include "util.h" 6#include "util.h"
9 7
10/**
11 * Colors for a box with background, border and text colors.
12 */
13struct box_colors { 8struct box_colors {
14 uint32_t border; 9 uint32_t border;
15 uint32_t background; 10 uint32_t background;
16 uint32_t text; 11 uint32_t text;
17}; 12};
18 13
19/** 14struct config_output {
20 * Swaybar config. 15 struct wl_list link;
21 */ 16 char *name;
22struct config { 17 size_t index;
18};
19
20struct swaybar_config {
23 char *status_command; 21 char *status_command;
24 bool pango_markup; 22 bool pango_markup;
25 uint32_t position; 23 uint32_t position; // zwlr_layer_surface_v1_anchor
26 char *font; 24 char *font;
27 char *sep_symbol; 25 char *sep_symbol;
28 char *mode; 26 char *mode;
27 bool mode_pango_markup;
29 bool strip_workspace_numbers; 28 bool strip_workspace_numbers;
30 bool binding_mode_indicator; 29 bool binding_mode_indicator;
31 bool wrap_scroll; 30 bool wrap_scroll;
32 bool workspace_buttons; 31 bool workspace_buttons;
32 struct wl_list outputs;
33 bool all_outputs; 33 bool all_outputs;
34 list_t *outputs;
35
36#ifdef ENABLE_TRAY
37 // Tray
38 char *tray_output;
39 char *icon_theme;
40
41 uint32_t tray_padding;
42 uint32_t activate_button;
43 uint32_t context_button;
44 uint32_t secondary_button;
45#endif
46
47 int height; 34 int height;
48 35
49 struct { 36 struct {
@@ -63,24 +50,8 @@ struct config {
63 } colors; 50 } colors;
64}; 51};
65 52
66/** 53struct swaybar_config *init_config();
67 * Parse position top|bottom|left|right. 54void free_config(struct swaybar_config *config);
68 */
69uint32_t parse_position(const char *position); 55uint32_t parse_position(const char *position);
70 56
71/** 57#endif
72 * Parse font.
73 */
74char *parse_font(const char *font);
75
76/**
77 * Initialize default sway config.
78 */
79struct config *init_config();
80
81/**
82 * Free config struct.
83 */
84void free_config(struct config *config);
85
86#endif /* _SWAYBAR_CONFIG_H */
diff --git a/include/swaybar/event_loop.h b/include/swaybar/event_loop.h
index a0cde07f..99f6ed36 100644
--- a/include/swaybar/event_loop.h
+++ b/include/swaybar/event_loop.h
@@ -1,6 +1,5 @@
1#ifndef _SWAYBAR_EVENT_LOOP_H 1#ifndef _SWAYBAR_EVENT_LOOP_H
2#define _SWAYBAR_EVENT_LOOP_H 2#define _SWAYBAR_EVENT_LOOP_H
3
4#include <stdbool.h> 3#include <stdbool.h>
5#include <time.h> 4#include <time.h>
6 5
@@ -23,4 +22,5 @@ bool remove_timer(timer_t timer);
23void event_loop_poll(); 22void event_loop_poll();
24 23
25void init_event_loop(); 24void init_event_loop();
26#endif /*_SWAYBAR_EVENT_LOOP_H */ 25
26#endif
diff --git a/include/swaybar/ipc.h b/include/swaybar/ipc.h
index c11931d0..a1696bcf 100644
--- a/include/swaybar/ipc.h
+++ b/include/swaybar/ipc.h
@@ -1,23 +1,11 @@
1#ifndef _SWAYBAR_IPC_H 1#ifndef _SWAYBAR_IPC_H
2#define _SWAYBAR_IPC_H 2#define _SWAYBAR_IPC_H
3#include <stdbool.h>
4#include "swaybar/bar.h"
3 5
4#include "bar.h" 6void ipc_initialize(struct swaybar *bar, const char *bar_id);
5 7bool handle_ipc_readable(struct swaybar *bar);
6/** 8void ipc_get_workspaces(struct swaybar *bar);
7 * Initialize ipc connection to sway and get sway state, outputs, bar_config. 9void ipc_send_workspace_command(struct swaybar *bar, const char *ws);
8 */
9void ipc_bar_init(struct bar *bar, const char *bar_id);
10
11/**
12 * Handle ipc event from sway.
13 */
14bool handle_ipc_event(struct bar *bar);
15
16
17/**
18 * Send workspace command to sway
19 */
20void ipc_send_workspace_command(const char *workspace_name);
21
22#endif /* _SWAYBAR_IPC_H */
23 10
11#endif
diff --git a/include/swaybar/render.h b/include/swaybar/render.h
index 114f43f4..071e2298 100644
--- a/include/swaybar/render.h
+++ b/include/swaybar/render.h
@@ -1,22 +1,10 @@
1#ifndef _SWAYBAR_RENDER_H 1#ifndef _SWAYBAR_RENDER_H
2#define _SWAYBAR_RENDER_H 2#define _SWAYBAR_RENDER_H
3 3
4#include "config.h" 4struct swaybar;
5#include "bar.h" 5struct swaybar_output;
6struct swaybar_config;
6 7
7/** 8void render_frame(struct swaybar *bar, struct swaybar_output *output);
8 * Render swaybar.
9 */
10void render(struct output *output, struct config *config, struct status_line *line);
11 9
12/** 10#endif
13 * Set window height and modify internal spacing accordingly.
14 */
15void set_window_height(struct window *window, int height);
16
17/**
18 * Compute the size of a workspace name
19 */
20void workspace_button_size(struct window *window, const char *workspace_name, int *width, int *height);
21
22#endif /* _SWAYBAR_RENDER_H */
diff --git a/include/swaybar/status_line.h b/include/swaybar/status_line.h
index 0664ddee..3538f49c 100644
--- a/include/swaybar/status_line.h
+++ b/include/swaybar/status_line.h
@@ -1,25 +1,44 @@
1#ifndef _SWAYBAR_STATUS_LINE_H 1#ifndef _SWAYBAR_STATUS_LINE_H
2#define _SWAYBAR_STATUS_LINE_H 2#define _SWAYBAR_STATUS_LINE_H
3
4#include <stdint.h> 3#include <stdint.h>
4#include <stdio.h>
5#include <stdbool.h> 5#include <stdbool.h>
6
7#include "list.h"
8#include "bar.h" 6#include "bar.h"
9 7
10typedef enum {UNDEF, TEXT, I3BAR} command_protocol; 8enum status_protocol {
9 PROTOCOL_UNDEF,
10 PROTOCOL_ERROR,
11 PROTOCOL_TEXT,
12 PROTOCOL_I3BAR,
13};
14
15struct text_protocol_state {
16 char *buffer;
17 size_t buffer_size;
18};
11 19
12struct status_line { 20enum json_node_type {
13 list_t *block_line; 21 JSON_NODE_UNKNOWN,
14 const char *text_line; 22 JSON_NODE_ARRAY,
15 command_protocol protocol; 23 JSON_NODE_STRING,
24};
25
26struct i3bar_protocol_state {
16 bool click_events; 27 bool click_events;
28 char *buffer;
29 size_t buffer_size;
30 size_t buffer_index;
31 const char *current_node;
32 bool escape;
33 size_t depth;
34 enum json_node_type nodes[16];
17}; 35};
18 36
19struct status_block { 37struct i3bar_block {
38 struct wl_list link;
20 char *full_text, *short_text, *align; 39 char *full_text, *short_text, *align;
21 bool urgent; 40 bool urgent;
22 uint32_t color; 41 uint32_t *color;
23 int min_width; 42 int min_width;
24 char *name, *instance; 43 char *name, *instance;
25 bool separator; 44 bool separator;
@@ -32,30 +51,27 @@ struct status_block {
32 int border_bottom; 51 int border_bottom;
33 int border_left; 52 int border_left;
34 int border_right; 53 int border_right;
35
36 // Set during rendering
37 int x;
38 int width;
39}; 54};
40 55
41/** 56struct status_line {
42 * Initialize status line struct. 57 pid_t pid;
43 */ 58 int read_fd, write_fd;
44struct status_line *init_status_line(); 59 FILE *read, *write;
45 60
46/** 61 enum status_protocol protocol;
47 * handle status line activity. 62 const char *text;
48 */ 63 struct wl_list blocks; // i3bar_block::link
49bool handle_status_line(struct bar *bar);
50 64
51/** 65 struct text_protocol_state text_state;
52 * Handle mouse clicks. 66 struct i3bar_protocol_state i3bar_state;
53 */ 67};
54bool status_line_mouse_event(struct bar *bar, int x, int y, uint32_t button);
55 68
56/** 69struct status_line *status_line_init(char *cmd);
57 * Free status line struct. 70void status_error(struct status_line *status, const char *text);
58 */ 71bool status_handle_readable(struct status_line *status);
59void free_status_line(struct status_line *line); 72void status_line_free(struct status_line *status);
73bool i3bar_handle_readable(struct status_line *status);
74void i3bar_block_send_click(struct status_line *status,
75 struct i3bar_block *block, int x, int y, uint32_t button);
60 76
61#endif /* _SWAYBAR_STATUS_LINE_H */ 77#endif
diff --git a/include/swaylock/seat.h b/include/swaylock/seat.h
new file mode 100644
index 00000000..44bc37d5
--- /dev/null
+++ b/include/swaylock/seat.h
@@ -0,0 +1,38 @@
1#ifndef _SWAYLOCK_SEAT_H
2#define _SWAYLOCK_SEAT_H
3#include <xkbcommon/xkbcommon.h>
4
5enum mod_bit {
6 MOD_SHIFT = 1<<0,
7 MOD_CAPS = 1<<1,
8 MOD_CTRL = 1<<2,
9 MOD_ALT = 1<<3,
10 MOD_MOD2 = 1<<4,
11 MOD_MOD3 = 1<<5,
12 MOD_LOGO = 1<<6,
13 MOD_MOD5 = 1<<7,
14};
15
16enum mask {
17 MASK_SHIFT,
18 MASK_CAPS,
19 MASK_CTRL,
20 MASK_ALT,
21 MASK_MOD2,
22 MASK_MOD3,
23 MASK_LOGO,
24 MASK_MOD5,
25 MASK_LAST
26};
27
28struct swaylock_xkb {
29 uint32_t modifiers;
30 struct xkb_state *state;
31 struct xkb_context *context;
32 struct xkb_keymap *keymap;
33 xkb_mod_mask_t masks[MASK_LAST];
34};
35
36extern const struct wl_seat_listener seat_listener;
37
38#endif
diff --git a/include/swaylock/swaylock.h b/include/swaylock/swaylock.h
index eeed094e..173e8b12 100644
--- a/include/swaylock/swaylock.h
+++ b/include/swaylock/swaylock.h
@@ -1,66 +1,64 @@
1#ifndef _SWAYLOCK_H 1#ifndef _SWAYLOCK_H
2#define _SWAYLOCK_H 2#define _SWAYLOCK_H
3 3#include <stdbool.h>
4#include "client/cairo.h" 4#include <stdint.h>
5 5#include <wayland-client.h>
6enum scaling_mode { 6#include "background-image.h"
7 SCALING_MODE_STRETCH, 7#include "cairo.h"
8 SCALING_MODE_FILL, 8#include "pool-buffer.h"
9 SCALING_MODE_FIT, 9#include "swaylock/seat.h"
10 SCALING_MODE_CENTER, 10#include "wlr-layer-shell-unstable-v1-client-protocol.h"
11 SCALING_MODE_TILE,
12};
13 11
14enum auth_state { 12enum auth_state {
15 AUTH_STATE_IDLE, 13 AUTH_STATE_IDLE,
16 AUTH_STATE_INPUT, 14 AUTH_STATE_INPUT,
17 AUTH_STATE_BACKSPACE, 15 AUTH_STATE_BACKSPACE,
18 AUTH_STATE_VALIDATING, 16 AUTH_STATE_VALIDATING,
19 AUTH_STATE_INVALID, 17 AUTH_STATE_INVALID,
20}; 18};
21 19
22enum line_source { 20struct swaylock_args {
23 LINE_SOURCE_DEFAULT,
24 LINE_SOURCE_RING,
25 LINE_SOURCE_INSIDE,
26};
27
28struct render_data {
29 list_t *surfaces;
30 // Output specific images
31 cairo_surface_t **images;
32 // OR one image for all outputs:
33 cairo_surface_t *image;
34 int num_images;
35 int color_set;
36 uint32_t color; 21 uint32_t color;
37 enum scaling_mode scaling_mode; 22 enum background_mode mode;
38 enum auth_state auth_state; 23 bool show_indicator;
39}; 24};
40 25
41struct lock_colors { 26struct swaylock_password {
42 uint32_t inner_ring; 27 size_t size;
43 uint32_t outer_ring; 28 size_t len;
29 char *buffer;
44}; 30};
45 31
46struct lock_config { 32struct swaylock_state {
47 char *font; 33 struct wl_display *display;
48 34 struct wl_compositor *compositor;
49 struct { 35 struct zwlr_layer_shell_v1 *layer_shell;
50 uint32_t text; 36 struct zwlr_input_inhibit_manager_v1 *input_inhibit_manager;
51 uint32_t line; 37 struct wl_shm *shm;
52 uint32_t separator; 38 struct wl_list surfaces;
53 uint32_t input_cursor; 39 struct swaylock_args args;
54 uint32_t backspace_cursor; 40 struct swaylock_password password;
55 struct lock_colors normal; 41 struct swaylock_xkb xkb;
56 struct lock_colors validating; 42 enum auth_state auth_state;
57 struct lock_colors invalid; 43 bool run_display;
58 } colors; 44};
59 45
60 int radius; 46struct swaylock_surface {
61 int thickness; 47 cairo_surface_t *image;
48 struct swaylock_state *state;
49 struct wl_output *output;
50 struct wl_surface *surface;
51 struct zwlr_layer_surface_v1 *layer_surface;
52 struct pool_buffer buffers[2];
53 struct pool_buffer *current_buffer;
54 uint32_t width, height;
55 int32_t scale;
56 struct wl_list link;
62}; 57};
63 58
64void render(struct render_data* render_data, struct lock_config *config); 59void swaylock_handle_key(struct swaylock_state *state,
60 xkb_keysym_t keysym, uint32_t codepoint);
61void render_frame(struct swaylock_surface *surface);
62void render_frames(struct swaylock_state *state);
65 63
66#endif 64#endif
diff --git a/include/unicode.h b/include/unicode.h
new file mode 100644
index 00000000..e2ee9588
--- /dev/null
+++ b/include/unicode.h
@@ -0,0 +1,33 @@
1#ifndef _SWAY_UNICODE_H
2#define _SWAY_UNICODE_H
3#include <stddef.h>
4#include <stdint.h>
5
6// Technically UTF-8 supports up to 6 byte codepoints, but Unicode itself
7// doesn't really bother with more than 4.
8#define UTF8_MAX_SIZE 4
9
10#define UTF8_INVALID 0x80
11
12/**
13 * Grabs the next UTF-8 character and advances the string pointer
14 */
15uint32_t utf8_decode(const char **str);
16
17/**
18 * Encodes a character as UTF-8 and returns the length of that character.
19 */
20size_t utf8_encode(char *str, uint32_t ch);
21
22/**
23 * Returns the size of the next UTF-8 character
24 */
25int utf8_size(const char *str);
26
27/**
28 * Returns the size of a UTF-8 character
29 */
30size_t utf8_chsize(uint32_t ch);
31
32#endif
33