diff options
-rw-r--r-- | include/sway/server.h | 1 | ||||
-rw-r--r-- | include/swaybar/bar.h | 23 | ||||
-rw-r--r-- | include/swaybar/ipc.h | 1 | ||||
-rw-r--r-- | meson.build | 1 | ||||
-rw-r--r-- | sway/config.c | 17 | ||||
-rw-r--r-- | sway/config/bar.c | 2 | ||||
-rw-r--r-- | sway/input/cursor.c | 25 | ||||
-rw-r--r-- | sway/input/seat.c | 12 | ||||
-rw-r--r-- | sway/server.c | 28 | ||||
-rw-r--r-- | swaybar/bar.c | 167 | ||||
-rw-r--r-- | swaybar/ipc.c | 8 | ||||
-rw-r--r-- | swaybar/meson.build | 4 | ||||
-rw-r--r-- | swaybar/render.c | 39 |
13 files changed, 294 insertions, 34 deletions
diff --git a/include/sway/server.h b/include/sway/server.h index 61f21cdb..296fbf22 100644 --- a/include/sway/server.h +++ b/include/sway/server.h | |||
@@ -33,6 +33,7 @@ struct sway_server { | |||
33 | struct wl_listener xdg_shell_v6_surface; | 33 | struct wl_listener xdg_shell_v6_surface; |
34 | 34 | ||
35 | struct wlr_xwayland *xwayland; | 35 | struct wlr_xwayland *xwayland; |
36 | struct wlr_xcursor_manager *xcursor_manager; | ||
36 | struct wl_listener xwayland_surface; | 37 | struct wl_listener xwayland_surface; |
37 | struct wl_listener xwayland_ready; | 38 | struct wl_listener xwayland_ready; |
38 | 39 | ||
diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h index 1bf2ea2d..74292519 100644 --- a/include/swaybar/bar.h +++ b/include/swaybar/bar.h | |||
@@ -2,20 +2,39 @@ | |||
2 | #define _SWAYBAR_BAR_H | 2 | #define _SWAYBAR_BAR_H |
3 | #include <wayland-client.h> | 3 | #include <wayland-client.h> |
4 | #include "pool-buffer.h" | 4 | #include "pool-buffer.h" |
5 | #include "list.h" | ||
6 | 5 | ||
7 | struct swaybar_config; | 6 | struct swaybar_config; |
8 | struct swaybar_output; | 7 | struct swaybar_output; |
9 | struct swaybar_workspace; | 8 | struct swaybar_workspace; |
10 | 9 | ||
10 | struct swaybar_pointer { | ||
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 | |||
19 | struct 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 | |||
11 | struct swaybar { | 28 | struct swaybar { |
12 | struct wl_display *display; | 29 | struct wl_display *display; |
13 | struct wl_compositor *compositor; | 30 | struct wl_compositor *compositor; |
14 | struct zwlr_layer_shell_v1 *layer_shell; | 31 | struct zwlr_layer_shell_v1 *layer_shell; |
15 | struct wl_shm *shm; | 32 | struct wl_shm *shm; |
33 | struct wl_seat *seat; | ||
16 | 34 | ||
17 | struct swaybar_config *config; | 35 | struct swaybar_config *config; |
18 | struct swaybar_output *focused_output; | 36 | struct swaybar_output *focused_output; |
37 | struct swaybar_pointer pointer; | ||
19 | struct status_line *status; | 38 | struct status_line *status; |
20 | 39 | ||
21 | int ipc_event_socketfd; | 40 | int ipc_event_socketfd; |
@@ -32,6 +51,7 @@ struct swaybar_output { | |||
32 | struct zwlr_layer_surface_v1 *layer_surface; | 51 | struct zwlr_layer_surface_v1 *layer_surface; |
33 | 52 | ||
34 | struct wl_list workspaces; | 53 | struct wl_list workspaces; |
54 | struct wl_list hotspots; | ||
35 | 55 | ||
36 | char *name; | 56 | char *name; |
37 | size_t index; | 57 | size_t index; |
@@ -51,7 +71,6 @@ struct swaybar_workspace { | |||
51 | bool urgent; | 71 | bool urgent; |
52 | }; | 72 | }; |
53 | 73 | ||
54 | // TODO: Rename stuff to match wlroots conventions (init/create/etc) | ||
55 | void bar_setup(struct swaybar *bar, | 74 | void bar_setup(struct swaybar *bar, |
56 | const char *socket_path, | 75 | const char *socket_path, |
57 | const char *bar_id); | 76 | const char *bar_id); |
diff --git a/include/swaybar/ipc.h b/include/swaybar/ipc.h index 278baef0..6ea7c4d6 100644 --- a/include/swaybar/ipc.h +++ b/include/swaybar/ipc.h | |||
@@ -6,5 +6,6 @@ | |||
6 | void ipc_initialize(struct swaybar *bar, const char *bar_id); | 6 | void ipc_initialize(struct swaybar *bar, const char *bar_id); |
7 | bool handle_ipc_event(struct swaybar *bar); | 7 | bool handle_ipc_event(struct swaybar *bar); |
8 | void ipc_get_workspaces(struct swaybar *bar); | 8 | void ipc_get_workspaces(struct swaybar *bar); |
9 | void ipc_send_workspace_command(struct swaybar *bar, const char *ws); | ||
9 | 10 | ||
10 | #endif | 11 | #endif |
diff --git a/meson.build b/meson.build index 49824b30..01788fd9 100644 --- a/meson.build +++ b/meson.build | |||
@@ -24,6 +24,7 @@ pcre = dependency('libpcre') | |||
24 | wlroots = dependency('wlroots', fallback: ['wlroots', 'wlroots']) | 24 | wlroots = dependency('wlroots', fallback: ['wlroots', 'wlroots']) |
25 | wayland_server = dependency('wayland-server') | 25 | wayland_server = dependency('wayland-server') |
26 | wayland_client = dependency('wayland-client') | 26 | wayland_client = dependency('wayland-client') |
27 | wayland_cursor = dependency('wayland-cursor') | ||
27 | wayland_egl = dependency('wayland-egl') | 28 | wayland_egl = dependency('wayland-egl') |
28 | wayland_protos = dependency('wayland-protocols') | 29 | wayland_protos = dependency('wayland-protocols') |
29 | xkbcommon = dependency('xkbcommon') | 30 | xkbcommon = dependency('xkbcommon') |
diff --git a/sway/config.c b/sway/config.c index 347d9e73..e9e7057d 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -57,38 +57,41 @@ static void free_mode(struct sway_mode *mode) { | |||
57 | void free_config(struct sway_config *config) { | 57 | void free_config(struct sway_config *config) { |
58 | config_clear_handler_context(config); | 58 | config_clear_handler_context(config); |
59 | 59 | ||
60 | int i; | ||
61 | |||
62 | if (!config) { | 60 | if (!config) { |
63 | return; | 61 | return; |
64 | } | 62 | } |
65 | 63 | ||
66 | // TODO: handle all currently unhandled lists as we add implementations | 64 | // TODO: handle all currently unhandled lists as we add implementations |
67 | if (config->symbols) { | 65 | if (config->symbols) { |
68 | for (i = 0; i < config->symbols->length; i++) { | 66 | for (int i = 0; i < config->symbols->length; ++i) { |
69 | free_sway_variable(config->symbols->items[i]); | 67 | free_sway_variable(config->symbols->items[i]); |
70 | } | 68 | } |
71 | list_free(config->symbols); | 69 | list_free(config->symbols); |
72 | } | 70 | } |
73 | if (config->modes) { | 71 | if (config->modes) { |
74 | for (i = 0; i < config->modes->length; i++) { | 72 | for (int i = 0; i < config->modes->length; ++i) { |
75 | free_mode(config->modes->items[i]); | 73 | free_mode(config->modes->items[i]); |
76 | } | 74 | } |
77 | list_free(config->modes); | 75 | list_free(config->modes); |
78 | } | 76 | } |
79 | list_free(config->bars); | 77 | if (config->bars) { |
78 | for (int i = 0; i < config->bars->length; ++i) { | ||
79 | free_bar_config(config->bars->items[i]); | ||
80 | } | ||
81 | list_free(config->bars); | ||
82 | } | ||
80 | list_free(config->cmd_queue); | 83 | list_free(config->cmd_queue); |
81 | list_free(config->workspace_outputs); | 84 | list_free(config->workspace_outputs); |
82 | list_free(config->pid_workspaces); | 85 | list_free(config->pid_workspaces); |
83 | list_free(config->output_configs); | 86 | list_free(config->output_configs); |
84 | if (config->input_configs) { | 87 | if (config->input_configs) { |
85 | for (i = 0; i < config->input_configs->length; i++) { | 88 | for (int i = 0; i < config->input_configs->length; i++) { |
86 | free_input_config(config->input_configs->items[i]); | 89 | free_input_config(config->input_configs->items[i]); |
87 | } | 90 | } |
88 | list_free(config->input_configs); | 91 | list_free(config->input_configs); |
89 | } | 92 | } |
90 | if (config->seat_configs) { | 93 | if (config->seat_configs) { |
91 | for (i = 0; i < config->seat_configs->length; i++) { | 94 | for (int i = 0; i < config->seat_configs->length; i++) { |
92 | free_seat_config(config->seat_configs->items[i]); | 95 | free_seat_config(config->seat_configs->items[i]); |
93 | } | 96 | } |
94 | list_free(config->seat_configs); | 97 | list_free(config->seat_configs); |
diff --git a/sway/config/bar.c b/sway/config/bar.c index 48b2fc7c..2913f059 100644 --- a/sway/config/bar.c +++ b/sway/config/bar.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include "log.h" | 16 | #include "log.h" |
17 | 17 | ||
18 | static void terminate_swaybar(pid_t pid) { | 18 | static void terminate_swaybar(pid_t pid) { |
19 | wlr_log(L_DEBUG, "Terminating swaybar %d", pid); | ||
19 | int ret = kill(pid, SIGTERM); | 20 | int ret = kill(pid, SIGTERM); |
20 | if (ret != 0) { | 21 | if (ret != 0) { |
21 | wlr_log_errno(L_ERROR, "Unable to terminate swaybar %d", pid); | 22 | wlr_log_errno(L_ERROR, "Unable to terminate swaybar %d", pid); |
@@ -185,6 +186,7 @@ void invoke_swaybar(struct bar_config *bar) { | |||
185 | execvp(cmd[0], cmd); | 186 | execvp(cmd[0], cmd); |
186 | exit(1); | 187 | exit(1); |
187 | } | 188 | } |
189 | wlr_log(L_DEBUG, "Spawned swaybar %d", bar->pid); | ||
188 | close(filedes[0]); | 190 | close(filedes[0]); |
189 | ssize_t len; | 191 | ssize_t len; |
190 | if (read(filedes[1], &len, sizeof(int)) == sizeof(int)) { | 192 | if (read(filedes[1], &len, sizeof(int)) == sizeof(int)) { |
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 7390816f..74af6426 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -63,7 +63,7 @@ static struct sway_container *container_at_cursor(struct sway_cursor *cursor, | |||
63 | *surface = xsurface->surface; | 63 | *surface = xsurface->surface; |
64 | *sx = cursor->x - box.x; | 64 | *sx = cursor->x - box.x; |
65 | *sy = cursor->y - box.y; | 65 | *sy = cursor->y - box.y; |
66 | return view->swayc; | 66 | return NULL; |
67 | } | 67 | } |
68 | } | 68 | } |
69 | } | 69 | } |
@@ -175,7 +175,28 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) { | |||
175 | double sx, sy; | 175 | double sx, sy; |
176 | struct sway_container *cont = | 176 | struct sway_container *cont = |
177 | container_at_cursor(cursor, &surface, &sx, &sy); | 177 | container_at_cursor(cursor, &surface, &sx, &sy); |
178 | sway_seat_set_focus(cursor->seat, cont); | 178 | // Avoid moving keyboard focus from a surface that accepts it to one |
179 | // that does not unless the change would move us to a new workspace. | ||
180 | // | ||
181 | // This prevents, for example, losing focus when clicking on swaybar. | ||
182 | // | ||
183 | // TODO: Replace this condition with something like | ||
184 | // !surface_accepts_keyboard_input | ||
185 | if (surface && cont && cont->type != C_VIEW) { | ||
186 | struct sway_container *new_ws = cont; | ||
187 | if (new_ws && new_ws->type != C_WORKSPACE) { | ||
188 | new_ws = container_parent(new_ws, C_WORKSPACE); | ||
189 | } | ||
190 | struct sway_container *old_ws = sway_seat_get_focus(cursor->seat); | ||
191 | if (old_ws && old_ws->type != C_WORKSPACE) { | ||
192 | old_ws = container_parent(old_ws, C_WORKSPACE); | ||
193 | } | ||
194 | if (new_ws != old_ws) { | ||
195 | sway_seat_set_focus(cursor->seat, cont); | ||
196 | } | ||
197 | } else { | ||
198 | sway_seat_set_focus(cursor->seat, cont); | ||
199 | } | ||
179 | } | 200 | } |
180 | 201 | ||
181 | wlr_seat_pointer_notify_button(cursor->seat->wlr_seat, event->time_msec, | 202 | wlr_seat_pointer_notify_button(cursor->seat->wlr_seat, event->time_msec, |
diff --git a/sway/input/seat.c b/sway/input/seat.c index ae536264..8d592872 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c | |||
@@ -259,11 +259,11 @@ void sway_seat_remove_device(struct sway_seat *seat, | |||
259 | 259 | ||
260 | void sway_seat_configure_xcursor(struct sway_seat *seat) { | 260 | void sway_seat_configure_xcursor(struct sway_seat *seat) { |
261 | // TODO configure theme and size | 261 | // TODO configure theme and size |
262 | const char *cursor_theme = "default"; | 262 | const char *cursor_theme = NULL; |
263 | 263 | ||
264 | if (!seat->cursor->xcursor_manager) { | 264 | if (!seat->cursor->xcursor_manager) { |
265 | seat->cursor->xcursor_manager = | 265 | seat->cursor->xcursor_manager = |
266 | wlr_xcursor_manager_create("default", 24); | 266 | wlr_xcursor_manager_create(cursor_theme, 24); |
267 | if (sway_assert(seat->cursor->xcursor_manager, | 267 | if (sway_assert(seat->cursor->xcursor_manager, |
268 | "Cannot create XCursor manager for theme %s", | 268 | "Cannot create XCursor manager for theme %s", |
269 | cursor_theme)) { | 269 | cursor_theme)) { |
@@ -291,7 +291,8 @@ void sway_seat_configure_xcursor(struct sway_seat *seat) { | |||
291 | seat->cursor->cursor->y); | 291 | seat->cursor->cursor->y); |
292 | } | 292 | } |
293 | 293 | ||
294 | void sway_seat_set_focus(struct sway_seat *seat, struct sway_container *container) { | 294 | void sway_seat_set_focus(struct sway_seat *seat, |
295 | struct sway_container *container) { | ||
295 | struct sway_container *last_focus = sway_seat_get_focus(seat); | 296 | struct sway_container *last_focus = sway_seat_get_focus(seat); |
296 | 297 | ||
297 | if (container && last_focus == container) { | 298 | if (container && last_focus == container) { |
@@ -311,6 +312,11 @@ void sway_seat_set_focus(struct sway_seat *seat, struct sway_container *containe | |||
311 | if (container->type == C_VIEW) { | 312 | if (container->type == C_VIEW) { |
312 | struct sway_view *view = container->sway_view; | 313 | struct sway_view *view = container->sway_view; |
313 | view_set_activated(view, true); | 314 | view_set_activated(view, true); |
315 | if (view->type == SWAY_XWAYLAND_VIEW) { | ||
316 | struct wlr_xwayland *xwayland = | ||
317 | seat->input->server->xwayland; | ||
318 | wlr_xwayland_set_seat(xwayland, seat->wlr_seat); | ||
319 | } | ||
314 | struct wlr_keyboard *keyboard = | 320 | struct wlr_keyboard *keyboard = |
315 | wlr_seat_get_keyboard(seat->wlr_seat); | 321 | wlr_seat_get_keyboard(seat->wlr_seat); |
316 | if (keyboard) { | 322 | if (keyboard) { |
diff --git a/sway/server.c b/sway/server.c index 728e624e..f5cc199c 100644 --- a/sway/server.c +++ b/sway/server.c | |||
@@ -8,9 +8,12 @@ | |||
8 | #include <wlr/render/wlr_renderer.h> | 8 | #include <wlr/render/wlr_renderer.h> |
9 | #include <wlr/types/wlr_compositor.h> | 9 | #include <wlr/types/wlr_compositor.h> |
10 | #include <wlr/types/wlr_gamma_control.h> | 10 | #include <wlr/types/wlr_gamma_control.h> |
11 | #include <wlr/types/wlr_linux_dmabuf.h> | ||
11 | #include <wlr/types/wlr_layer_shell.h> | 12 | #include <wlr/types/wlr_layer_shell.h> |
13 | #include <wlr/types/wlr_primary_selection.h> | ||
12 | #include <wlr/types/wlr_screenshooter.h> | 14 | #include <wlr/types/wlr_screenshooter.h> |
13 | #include <wlr/types/wlr_wl_shell.h> | 15 | #include <wlr/types/wlr_wl_shell.h> |
16 | #include <wlr/types/wlr_xcursor_manager.h> | ||
14 | #include <wlr/util/log.h> | 17 | #include <wlr/util/log.h> |
15 | // TODO WLR: make Xwayland optional | 18 | // TODO WLR: make Xwayland optional |
16 | #include <wlr/xwayland.h> | 19 | #include <wlr/xwayland.h> |
@@ -53,6 +56,7 @@ bool server_init(struct sway_server *server) { | |||
53 | 56 | ||
54 | wlr_screenshooter_create(server->wl_display); | 57 | wlr_screenshooter_create(server->wl_display); |
55 | wlr_gamma_control_manager_create(server->wl_display); | 58 | wlr_gamma_control_manager_create(server->wl_display); |
59 | wlr_primary_selection_device_manager_create(server->wl_display); | ||
56 | 60 | ||
57 | server->new_output.notify = handle_new_output; | 61 | server->new_output.notify = handle_new_output; |
58 | wl_signal_add(&server->backend->events.new_output, &server->new_output); | 62 | wl_signal_add(&server->backend->events.new_output, &server->new_output); |
@@ -67,6 +71,11 @@ bool server_init(struct sway_server *server) { | |||
67 | &server->xdg_shell_v6_surface); | 71 | &server->xdg_shell_v6_surface); |
68 | server->xdg_shell_v6_surface.notify = handle_xdg_shell_v6_surface; | 72 | server->xdg_shell_v6_surface.notify = handle_xdg_shell_v6_surface; |
69 | 73 | ||
74 | server->wl_shell = wlr_wl_shell_create(server->wl_display); | ||
75 | wl_signal_add(&server->wl_shell->events.new_surface, | ||
76 | &server->wl_shell_surface); | ||
77 | server->wl_shell_surface.notify = handle_wl_shell_surface; | ||
78 | |||
70 | // TODO make xwayland optional | 79 | // TODO make xwayland optional |
71 | server->xwayland = | 80 | server->xwayland = |
72 | wlr_xwayland_create(server->wl_display, server->compositor); | 81 | wlr_xwayland_create(server->wl_display, server->compositor); |
@@ -78,10 +87,20 @@ bool server_init(struct sway_server *server) { | |||
78 | // TODO: call server_ready now if xwayland is not enabled | 87 | // TODO: call server_ready now if xwayland is not enabled |
79 | server->xwayland_ready.notify = server_ready; | 88 | server->xwayland_ready.notify = server_ready; |
80 | 89 | ||
81 | server->wl_shell = wlr_wl_shell_create(server->wl_display); | 90 | // TODO: configurable cursor theme and size |
82 | wl_signal_add(&server->wl_shell->events.new_surface, | 91 | server->xcursor_manager = wlr_xcursor_manager_create(NULL, 24); |
83 | &server->wl_shell_surface); | 92 | wlr_xcursor_manager_load(server->xcursor_manager, 1); |
84 | server->wl_shell_surface.notify = handle_wl_shell_surface; | 93 | struct wlr_xcursor *xcursor = wlr_xcursor_manager_get_xcursor( |
94 | server->xcursor_manager, "left_ptr", 1); | ||
95 | if (xcursor != NULL) { | ||
96 | struct wlr_xcursor_image *image = xcursor->images[0]; | ||
97 | wlr_xwayland_set_cursor(server->xwayland, image->buffer, | ||
98 | image->width * 4, image->width, image->height, image->hotspot_x, | ||
99 | image->hotspot_y); | ||
100 | } | ||
101 | |||
102 | struct wlr_egl *egl = wlr_backend_get_egl(server->backend); | ||
103 | wlr_linux_dmabuf_create(server->wl_display, egl); | ||
85 | 104 | ||
86 | server->socket = wl_display_add_socket_auto(server->wl_display); | 105 | server->socket = wl_display_add_socket_auto(server->wl_display); |
87 | if (!server->socket) { | 106 | if (!server->socket) { |
@@ -91,7 +110,6 @@ bool server_init(struct sway_server *server) { | |||
91 | } | 110 | } |
92 | 111 | ||
93 | input_manager = sway_input_manager_create(server); | 112 | input_manager = sway_input_manager_create(server); |
94 | |||
95 | return true; | 113 | return true; |
96 | } | 114 | } |
97 | 115 | ||
diff --git a/swaybar/bar.c b/swaybar/bar.c index 0fc41517..f743236c 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c | |||
@@ -9,7 +9,13 @@ | |||
9 | #include <sys/wait.h> | 9 | #include <sys/wait.h> |
10 | #include <unistd.h> | 10 | #include <unistd.h> |
11 | #include <wayland-client.h> | 11 | #include <wayland-client.h> |
12 | #include <wayland-cursor.h> | ||
12 | #include <wlr/util/log.h> | 13 | #include <wlr/util/log.h> |
14 | #ifdef __FreeBSD__ | ||
15 | #include <dev/evdev/input-event-codes.h> | ||
16 | #else | ||
17 | #include <linux/input-event-codes.h> | ||
18 | #endif | ||
13 | #include "swaybar/render.h" | 19 | #include "swaybar/render.h" |
14 | #include "swaybar/config.h" | 20 | #include "swaybar/config.h" |
15 | #include "swaybar/event_loop.h" | 21 | #include "swaybar/event_loop.h" |
@@ -18,6 +24,7 @@ | |||
18 | #include "swaybar/ipc.h" | 24 | #include "swaybar/ipc.h" |
19 | #include "ipc-client.h" | 25 | #include "ipc-client.h" |
20 | #include "list.h" | 26 | #include "list.h" |
27 | #include "log.h" | ||
21 | #include "pango.h" | 28 | #include "pango.h" |
22 | #include "pool-buffer.h" | 29 | #include "pool-buffer.h" |
23 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" | 30 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" |
@@ -27,12 +34,6 @@ static void bar_init(struct swaybar *bar) { | |||
27 | wl_list_init(&bar->outputs); | 34 | wl_list_init(&bar->outputs); |
28 | } | 35 | } |
29 | 36 | ||
30 | struct swaybar_output *new_output(const char *name) { | ||
31 | struct swaybar_output *output = malloc(sizeof(struct swaybar_output)); | ||
32 | output->name = strdup(name); | ||
33 | return output; | ||
34 | } | ||
35 | |||
36 | static void layer_surface_configure(void *data, | 37 | static void layer_surface_configure(void *data, |
37 | struct zwlr_layer_surface_v1 *surface, | 38 | struct zwlr_layer_surface_v1 *surface, |
38 | uint32_t serial, uint32_t width, uint32_t height) { | 39 | uint32_t serial, uint32_t width, uint32_t height) { |
@@ -56,12 +57,156 @@ struct zwlr_layer_surface_v1_listener layer_surface_listener = { | |||
56 | .closed = layer_surface_closed, | 57 | .closed = layer_surface_closed, |
57 | }; | 58 | }; |
58 | 59 | ||
60 | static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, | ||
61 | uint32_t serial, struct wl_surface *surface, | ||
62 | wl_fixed_t surface_x, wl_fixed_t surface_y) { | ||
63 | struct swaybar *bar = data; | ||
64 | struct swaybar_pointer *pointer = &bar->pointer; | ||
65 | struct swaybar_output *output; | ||
66 | wl_list_for_each(output, &bar->outputs, link) { | ||
67 | if (output->surface == surface) { | ||
68 | pointer->current = output; | ||
69 | break; | ||
70 | } | ||
71 | } | ||
72 | wl_surface_attach(pointer->cursor_surface, | ||
73 | wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0); | ||
74 | wl_pointer_set_cursor(wl_pointer, serial, pointer->cursor_surface, | ||
75 | pointer->cursor_image->hotspot_x, | ||
76 | pointer->cursor_image->hotspot_y); | ||
77 | wl_surface_commit(pointer->cursor_surface); | ||
78 | } | ||
79 | |||
80 | static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, | ||
81 | uint32_t serial, struct wl_surface *surface) { | ||
82 | struct swaybar *bar = data; | ||
83 | bar->pointer.current = NULL; | ||
84 | } | ||
85 | |||
86 | static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, | ||
87 | uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { | ||
88 | struct swaybar *bar = data; | ||
89 | bar->pointer.x = wl_fixed_to_int(surface_x); | ||
90 | bar->pointer.y = wl_fixed_to_int(surface_y); | ||
91 | } | ||
92 | |||
93 | static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, | ||
94 | uint32_t serial, uint32_t time, uint32_t button, uint32_t state) { | ||
95 | struct swaybar *bar = data; | ||
96 | struct swaybar_pointer *pointer = &bar->pointer; | ||
97 | struct swaybar_output *output = pointer->current; | ||
98 | if (!sway_assert(output, "button with no active output")) { | ||
99 | return; | ||
100 | } | ||
101 | if (state != WL_POINTER_BUTTON_STATE_PRESSED) { | ||
102 | return; | ||
103 | } | ||
104 | struct swaybar_hotspot *hotspot; | ||
105 | wl_list_for_each(hotspot, &output->hotspots, link) { | ||
106 | if (pointer->x >= hotspot->x | ||
107 | && pointer->y >= hotspot->y | ||
108 | && pointer->x < hotspot->x + hotspot->width | ||
109 | && pointer->y < hotspot->y + hotspot->height) { | ||
110 | hotspot->callback(output, pointer->x, pointer->y, | ||
111 | button, hotspot->data); | ||
112 | } | ||
113 | } | ||
114 | } | ||
115 | |||
116 | static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, | ||
117 | uint32_t time, uint32_t axis, wl_fixed_t value) { | ||
118 | struct swaybar *bar = data; | ||
119 | struct swaybar_output *output = bar->pointer.current; | ||
120 | if (!sway_assert(output, "axis with no active output")) { | ||
121 | return; | ||
122 | } | ||
123 | double amt = wl_fixed_to_double(value); | ||
124 | if (!bar->config->wrap_scroll) { | ||
125 | int i = 0; | ||
126 | struct swaybar_workspace *ws = NULL; | ||
127 | wl_list_for_each(ws, &output->workspaces, link) { | ||
128 | if (ws->focused) { | ||
129 | break; | ||
130 | } | ||
131 | ++i; | ||
132 | } | ||
133 | int len = wl_list_length(&output->workspaces); | ||
134 | if (!sway_assert(i != len, "axis with null workspace")) { | ||
135 | return; | ||
136 | } | ||
137 | if (i == 0 && amt > 0) { | ||
138 | return; // Do not wrap | ||
139 | } | ||
140 | if (i == len - 1 && amt < 0) { | ||
141 | return; // Do not wrap | ||
142 | } | ||
143 | } | ||
144 | |||
145 | const char *workspace_name = | ||
146 | amt < 0 ? "prev_on_output" : "next_on_output"; | ||
147 | ipc_send_workspace_command(bar, workspace_name); | ||
148 | } | ||
149 | |||
150 | static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) { | ||
151 | // Who cares | ||
152 | } | ||
153 | |||
154 | static void wl_pointer_axis_source(void *data, struct wl_pointer *wl_pointer, | ||
155 | uint32_t axis_source) { | ||
156 | // Who cares | ||
157 | } | ||
158 | |||
159 | static void wl_pointer_axis_stop(void *data, struct wl_pointer *wl_pointer, | ||
160 | uint32_t time, uint32_t axis) { | ||
161 | // Who cares | ||
162 | } | ||
163 | |||
164 | static void wl_pointer_axis_discrete(void *data, struct wl_pointer *wl_pointer, | ||
165 | uint32_t axis, int32_t discrete) { | ||
166 | // Who cares | ||
167 | } | ||
168 | |||
169 | struct wl_pointer_listener pointer_listener = { | ||
170 | .enter = wl_pointer_enter, | ||
171 | .leave = wl_pointer_leave, | ||
172 | .motion = wl_pointer_motion, | ||
173 | .button = wl_pointer_button, | ||
174 | .axis = wl_pointer_axis, | ||
175 | .frame = wl_pointer_frame, | ||
176 | .axis_source = wl_pointer_axis_source, | ||
177 | .axis_stop = wl_pointer_axis_stop, | ||
178 | .axis_discrete = wl_pointer_axis_discrete, | ||
179 | }; | ||
180 | |||
181 | static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, | ||
182 | enum wl_seat_capability caps) { | ||
183 | struct swaybar *bar = data; | ||
184 | if ((caps & WL_SEAT_CAPABILITY_POINTER)) { | ||
185 | bar->pointer.pointer = wl_seat_get_pointer(wl_seat); | ||
186 | wl_pointer_add_listener(bar->pointer.pointer, &pointer_listener, bar); | ||
187 | } | ||
188 | } | ||
189 | |||
190 | static void seat_handle_name(void *data, struct wl_seat *wl_seat, | ||
191 | const char *name) { | ||
192 | // Who cares | ||
193 | } | ||
194 | |||
195 | const struct wl_seat_listener seat_listener = { | ||
196 | .capabilities = seat_handle_capabilities, | ||
197 | .name = seat_handle_name, | ||
198 | }; | ||
199 | |||
59 | static void handle_global(void *data, struct wl_registry *registry, | 200 | static void handle_global(void *data, struct wl_registry *registry, |
60 | uint32_t name, const char *interface, uint32_t version) { | 201 | uint32_t name, const char *interface, uint32_t version) { |
61 | struct swaybar *bar = data; | 202 | struct swaybar *bar = data; |
62 | if (strcmp(interface, wl_compositor_interface.name) == 0) { | 203 | if (strcmp(interface, wl_compositor_interface.name) == 0) { |
63 | bar->compositor = wl_registry_bind(registry, name, | 204 | bar->compositor = wl_registry_bind(registry, name, |
64 | &wl_compositor_interface, 1); | 205 | &wl_compositor_interface, 1); |
206 | } else if (strcmp(interface, wl_seat_interface.name) == 0) { | ||
207 | bar->seat = wl_registry_bind(registry, name, | ||
208 | &wl_seat_interface, 1); | ||
209 | wl_seat_add_listener(bar->seat, &seat_listener, bar); | ||
65 | } else if (strcmp(interface, wl_shm_interface.name) == 0) { | 210 | } else if (strcmp(interface, wl_shm_interface.name) == 0) { |
66 | bar->shm = wl_registry_bind(registry, name, | 211 | bar->shm = wl_registry_bind(registry, name, |
67 | &wl_shm_interface, 1); | 212 | &wl_shm_interface, 1); |
@@ -74,6 +219,7 @@ static void handle_global(void *data, struct wl_registry *registry, | |||
74 | &wl_output_interface, 1); | 219 | &wl_output_interface, 1); |
75 | output->index = index++; | 220 | output->index = index++; |
76 | wl_list_init(&output->workspaces); | 221 | wl_list_init(&output->workspaces); |
222 | wl_list_init(&output->hotspots); | ||
77 | wl_list_insert(&bar->outputs, &output->link); | 223 | wl_list_insert(&bar->outputs, &output->link); |
78 | } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { | 224 | } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { |
79 | bar->layer_shell = wl_registry_bind( | 225 | bar->layer_shell = wl_registry_bind( |
@@ -116,6 +262,15 @@ void bar_setup(struct swaybar *bar, | |||
116 | wl_registry_add_listener(registry, ®istry_listener, bar); | 262 | wl_registry_add_listener(registry, ®istry_listener, bar); |
117 | wl_display_roundtrip(bar->display); | 263 | wl_display_roundtrip(bar->display); |
118 | assert(bar->compositor && bar->layer_shell && bar->shm); | 264 | assert(bar->compositor && bar->layer_shell && bar->shm); |
265 | struct swaybar_pointer *pointer = &bar->pointer; | ||
266 | |||
267 | assert(pointer->cursor_theme = wl_cursor_theme_load(NULL, 16, bar->shm)); | ||
268 | struct wl_cursor *cursor; | ||
269 | assert(cursor = wl_cursor_theme_get_cursor( | ||
270 | pointer->cursor_theme, "left_ptr")); | ||
271 | pointer->cursor_image = cursor->images[0]; | ||
272 | assert(pointer->cursor_surface = | ||
273 | wl_compositor_create_surface(bar->compositor)); | ||
119 | 274 | ||
120 | // TODO: we might not necessarily be meant to do all of the outputs | 275 | // TODO: we might not necessarily be meant to do all of the outputs |
121 | struct swaybar_output *output; | 276 | struct swaybar_output *output; |
diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 326f25cc..64583df0 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c | |||
@@ -8,6 +8,14 @@ | |||
8 | #include "swaybar/ipc.h" | 8 | #include "swaybar/ipc.h" |
9 | #include "ipc-client.h" | 9 | #include "ipc-client.h" |
10 | 10 | ||
11 | void ipc_send_workspace_command(struct swaybar *bar, const char *ws) { | ||
12 | const char *fmt = "workspace \"%s\""; | ||
13 | uint32_t size = snprintf(NULL, 0, fmt, ws); | ||
14 | char command[size]; | ||
15 | snprintf(command, size, fmt, ws); | ||
16 | ipc_single_command(bar->ipc_socketfd, IPC_COMMAND, command, &size); | ||
17 | } | ||
18 | |||
11 | char *parse_font(const char *font) { | 19 | char *parse_font(const char *font) { |
12 | char *new_font = NULL; | 20 | char *new_font = NULL; |
13 | if (strncmp("pango:", font, 6) == 0) { | 21 | if (strncmp("pango:", font, 6) == 0) { |
diff --git a/swaybar/meson.build b/swaybar/meson.build index d15e8b5c..bf6f6d7a 100644 --- a/swaybar/meson.build +++ b/swaybar/meson.build | |||
@@ -1,6 +1,5 @@ | |||
1 | executable( | 1 | executable( |
2 | 'swaybar', | 2 | 'swaybar', [ |
3 | [ | ||
4 | 'bar.c', | 3 | 'bar.c', |
5 | 'config.c', | 4 | 'config.c', |
6 | 'event_loop.c', | 5 | 'event_loop.c', |
@@ -20,6 +19,7 @@ executable( | |||
20 | pangocairo, | 19 | pangocairo, |
21 | rt, | 20 | rt, |
22 | wayland_client, | 21 | wayland_client, |
22 | wayland_cursor, | ||
23 | wlroots, | 23 | wlroots, |
24 | ], | 24 | ], |
25 | link_with: [lib_sway_common, lib_sway_client], | 25 | link_with: [lib_sway_common, lib_sway_client], |
diff --git a/swaybar/render.c b/swaybar/render.c index 3d9ef66b..c2358724 100644 --- a/swaybar/render.c +++ b/swaybar/render.c | |||
@@ -1,3 +1,4 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
1 | #include <limits.h> | 2 | #include <limits.h> |
2 | #include <stdlib.h> | 3 | #include <stdlib.h> |
3 | #include <stdint.h> | 4 | #include <stdint.h> |
@@ -8,6 +9,7 @@ | |||
8 | #include "pool-buffer.h" | 9 | #include "pool-buffer.h" |
9 | #include "swaybar/bar.h" | 10 | #include "swaybar/bar.h" |
10 | #include "swaybar/config.h" | 11 | #include "swaybar/config.h" |
12 | #include "swaybar/ipc.h" | ||
11 | #include "swaybar/render.h" | 13 | #include "swaybar/render.h" |
12 | #include "swaybar/status_line.h" | 14 | #include "swaybar/status_line.h" |
13 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" | 15 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" |
@@ -108,9 +110,14 @@ static const char *strip_workspace_number(const char *ws_name) { | |||
108 | return ws_name; | 110 | return ws_name; |
109 | } | 111 | } |
110 | 112 | ||
113 | static void workspace_hotspot_callback(struct swaybar_output *output, | ||
114 | int x, int y, uint32_t button, void *data) { | ||
115 | ipc_send_workspace_command(output->bar, (const char *)data); | ||
116 | } | ||
117 | |||
111 | static uint32_t render_workspace_button(cairo_t *cairo, | 118 | static uint32_t render_workspace_button(cairo_t *cairo, |
112 | struct swaybar_config *config, struct swaybar_workspace *ws, | 119 | struct swaybar_output *output, struct swaybar_config *config, |
113 | double *x, uint32_t height) { | 120 | struct swaybar_workspace *ws, double *x, uint32_t height) { |
114 | const char *name = ws->name; | 121 | const char *name = ws->name; |
115 | if (config->strip_workspace_numbers) { | 122 | if (config->strip_workspace_numbers) { |
116 | name = strip_workspace_number(ws->name); | 123 | name = strip_workspace_number(ws->name); |
@@ -156,8 +163,18 @@ static uint32_t render_workspace_button(cairo_t *cairo, | |||
156 | cairo_move_to(cairo, *x + width / 2 - text_width / 2, (int)floor(text_y)); | 163 | cairo_move_to(cairo, *x + width / 2 - text_width / 2, (int)floor(text_y)); |
157 | pango_printf(cairo, config->font, 1, true, "%s", name); | 164 | pango_printf(cairo, config->font, 1, true, "%s", name); |
158 | 165 | ||
166 | struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot)); | ||
167 | hotspot->x = *x; | ||
168 | hotspot->y = 0; | ||
169 | hotspot->height = height; | ||
170 | hotspot->width = width; | ||
171 | hotspot->callback = workspace_hotspot_callback; | ||
172 | hotspot->destroy = free; | ||
173 | hotspot->data = strdup(name); | ||
174 | wl_list_insert(&output->hotspots, &hotspot->link); | ||
175 | |||
159 | *x += width; | 176 | *x += width; |
160 | return ideal_height; | 177 | return height; |
161 | } | 178 | } |
162 | 179 | ||
163 | static uint32_t render_to_cairo(cairo_t *cairo, | 180 | static uint32_t render_to_cairo(cairo_t *cairo, |
@@ -184,8 +201,8 @@ static uint32_t render_to_cairo(cairo_t *cairo, | |||
184 | if (config->workspace_buttons) { | 201 | if (config->workspace_buttons) { |
185 | struct swaybar_workspace *ws; | 202 | struct swaybar_workspace *ws; |
186 | wl_list_for_each_reverse(ws, &output->workspaces, link) { | 203 | wl_list_for_each_reverse(ws, &output->workspaces, link) { |
187 | uint32_t h = render_workspace_button( | 204 | uint32_t h = render_workspace_button(cairo, |
188 | cairo, config, ws, &x, output->height); | 205 | output, config, ws, &x, output->height); |
189 | max_height = h > max_height ? h : max_height; | 206 | max_height = h > max_height ? h : max_height; |
190 | } | 207 | } |
191 | } | 208 | } |
@@ -203,8 +220,16 @@ static uint32_t render_to_cairo(cairo_t *cairo, | |||
203 | return max_height > output->height ? max_height : output->height; | 220 | return max_height > output->height ? max_height : output->height; |
204 | } | 221 | } |
205 | 222 | ||
206 | void render_frame(struct swaybar *bar, | 223 | void render_frame(struct swaybar *bar, struct swaybar_output *output) { |
207 | struct swaybar_output *output) { | 224 | struct swaybar_hotspot *hotspot, *tmp; |
225 | wl_list_for_each_safe(hotspot, tmp, &output->hotspots, link) { | ||
226 | if (hotspot->destroy) { | ||
227 | hotspot->destroy(hotspot->data); | ||
228 | } | ||
229 | wl_list_remove(&hotspot->link); | ||
230 | free(hotspot); | ||
231 | } | ||
232 | |||
208 | cairo_surface_t *recorder = cairo_recording_surface_create( | 233 | cairo_surface_t *recorder = cairo_recording_surface_create( |
209 | CAIRO_CONTENT_COLOR_ALPHA, NULL); | 234 | CAIRO_CONTENT_COLOR_ALPHA, NULL); |
210 | cairo_t *cairo = cairo_create(recorder); | 235 | cairo_t *cairo = cairo_create(recorder); |