diff options
-rw-r--r-- | include/swaybar/bar.h | 10 | ||||
-rw-r--r-- | meson.build | 1 | ||||
-rw-r--r-- | swaybar/bar.c | 105 | ||||
-rw-r--r-- | swaybar/meson.build | 4 |
4 files changed, 118 insertions, 2 deletions
diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h index 1bf2ea2d..0768a683 100644 --- a/include/swaybar/bar.h +++ b/include/swaybar/bar.h | |||
@@ -8,14 +8,24 @@ struct swaybar_config; | |||
8 | struct swaybar_output; | 8 | struct swaybar_output; |
9 | struct swaybar_workspace; | 9 | struct swaybar_workspace; |
10 | 10 | ||
11 | struct swaybar_pointer { | ||
12 | struct wl_pointer *pointer; | ||
13 | struct wl_cursor_theme *cursor_theme; | ||
14 | struct wl_cursor_image *cursor_image; | ||
15 | struct wl_surface *cursor_surface; | ||
16 | struct swaybar_output *current; | ||
17 | }; | ||
18 | |||
11 | struct swaybar { | 19 | struct swaybar { |
12 | struct wl_display *display; | 20 | struct wl_display *display; |
13 | struct wl_compositor *compositor; | 21 | struct wl_compositor *compositor; |
14 | struct zwlr_layer_shell_v1 *layer_shell; | 22 | struct zwlr_layer_shell_v1 *layer_shell; |
15 | struct wl_shm *shm; | 23 | struct wl_shm *shm; |
24 | struct wl_seat *seat; | ||
16 | 25 | ||
17 | struct swaybar_config *config; | 26 | struct swaybar_config *config; |
18 | struct swaybar_output *focused_output; | 27 | struct swaybar_output *focused_output; |
28 | struct swaybar_pointer pointer; | ||
19 | struct status_line *status; | 29 | struct status_line *status; |
20 | 30 | ||
21 | int ipc_event_socketfd; | 31 | int ipc_event_socketfd; |
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/swaybar/bar.c b/swaybar/bar.c index 0fc41517..e7b8b2ca 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" |
@@ -56,12 +62,102 @@ struct zwlr_layer_surface_v1_listener layer_surface_listener = { | |||
56 | .closed = layer_surface_closed, | 62 | .closed = layer_surface_closed, |
57 | }; | 63 | }; |
58 | 64 | ||
65 | static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, | ||
66 | uint32_t serial, struct wl_surface *surface, | ||
67 | wl_fixed_t surface_x, wl_fixed_t surface_y) { | ||
68 | struct swaybar *bar = data; | ||
69 | struct swaybar_pointer *pointer = &bar->pointer; | ||
70 | wl_surface_attach(pointer->cursor_surface, | ||
71 | wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0); | ||
72 | wl_pointer_set_cursor(wl_pointer, serial, pointer->cursor_surface, | ||
73 | pointer->cursor_image->hotspot_x, | ||
74 | pointer->cursor_image->hotspot_y); | ||
75 | wl_surface_commit(pointer->cursor_surface); | ||
76 | } | ||
77 | |||
78 | static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, | ||
79 | uint32_t serial, struct wl_surface *surface) { | ||
80 | // Who cares | ||
81 | } | ||
82 | |||
83 | static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, | ||
84 | uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { | ||
85 | wlr_log(L_DEBUG, "motion"); | ||
86 | // TODO | ||
87 | } | ||
88 | |||
89 | static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, | ||
90 | uint32_t serial, uint32_t time, uint32_t button, uint32_t state) { | ||
91 | wlr_log(L_DEBUG, "button"); | ||
92 | // TODO | ||
93 | } | ||
94 | |||
95 | static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, | ||
96 | uint32_t time, uint32_t axis, wl_fixed_t value) { | ||
97 | wlr_log(L_DEBUG, "axis"); | ||
98 | // TODO | ||
99 | } | ||
100 | |||
101 | static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) { | ||
102 | // Who cares | ||
103 | } | ||
104 | |||
105 | static void wl_pointer_axis_source(void *data, struct wl_pointer *wl_pointer, | ||
106 | uint32_t axis_source) { | ||
107 | // Who cares | ||
108 | } | ||
109 | |||
110 | static void wl_pointer_axis_stop(void *data, struct wl_pointer *wl_pointer, | ||
111 | uint32_t time, uint32_t axis) { | ||
112 | // Who cares | ||
113 | } | ||
114 | |||
115 | static void wl_pointer_axis_discrete(void *data, struct wl_pointer *wl_pointer, | ||
116 | uint32_t axis, int32_t discrete) { | ||
117 | // Who cares | ||
118 | } | ||
119 | |||
120 | struct wl_pointer_listener pointer_listener = { | ||
121 | .enter = wl_pointer_enter, | ||
122 | .leave = wl_pointer_leave, | ||
123 | .motion = wl_pointer_motion, | ||
124 | .button = wl_pointer_button, | ||
125 | .axis = wl_pointer_axis, | ||
126 | .frame = wl_pointer_frame, | ||
127 | .axis_source = wl_pointer_axis_source, | ||
128 | .axis_stop = wl_pointer_axis_stop, | ||
129 | .axis_discrete = wl_pointer_axis_discrete, | ||
130 | }; | ||
131 | |||
132 | static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, | ||
133 | enum wl_seat_capability caps) { | ||
134 | struct swaybar *bar = data; | ||
135 | if ((caps & WL_SEAT_CAPABILITY_POINTER)) { | ||
136 | bar->pointer.pointer = wl_seat_get_pointer(wl_seat); | ||
137 | wl_pointer_add_listener(bar->pointer.pointer, &pointer_listener, bar); | ||
138 | } | ||
139 | } | ||
140 | |||
141 | static void seat_handle_name(void *data, struct wl_seat *wl_seat, | ||
142 | const char *name) { | ||
143 | // Who cares | ||
144 | } | ||
145 | |||
146 | const struct wl_seat_listener seat_listener = { | ||
147 | .capabilities = seat_handle_capabilities, | ||
148 | .name = seat_handle_name, | ||
149 | }; | ||
150 | |||
59 | static void handle_global(void *data, struct wl_registry *registry, | 151 | static void handle_global(void *data, struct wl_registry *registry, |
60 | uint32_t name, const char *interface, uint32_t version) { | 152 | uint32_t name, const char *interface, uint32_t version) { |
61 | struct swaybar *bar = data; | 153 | struct swaybar *bar = data; |
62 | if (strcmp(interface, wl_compositor_interface.name) == 0) { | 154 | if (strcmp(interface, wl_compositor_interface.name) == 0) { |
63 | bar->compositor = wl_registry_bind(registry, name, | 155 | bar->compositor = wl_registry_bind(registry, name, |
64 | &wl_compositor_interface, 1); | 156 | &wl_compositor_interface, 1); |
157 | } else if (strcmp(interface, wl_seat_interface.name) == 0) { | ||
158 | bar->seat = wl_registry_bind(registry, name, | ||
159 | &wl_seat_interface, 1); | ||
160 | wl_seat_add_listener(bar->seat, &seat_listener, bar); | ||
65 | } else if (strcmp(interface, wl_shm_interface.name) == 0) { | 161 | } else if (strcmp(interface, wl_shm_interface.name) == 0) { |
66 | bar->shm = wl_registry_bind(registry, name, | 162 | bar->shm = wl_registry_bind(registry, name, |
67 | &wl_shm_interface, 1); | 163 | &wl_shm_interface, 1); |
@@ -116,6 +212,15 @@ void bar_setup(struct swaybar *bar, | |||
116 | wl_registry_add_listener(registry, ®istry_listener, bar); | 212 | wl_registry_add_listener(registry, ®istry_listener, bar); |
117 | wl_display_roundtrip(bar->display); | 213 | wl_display_roundtrip(bar->display); |
118 | assert(bar->compositor && bar->layer_shell && bar->shm); | 214 | assert(bar->compositor && bar->layer_shell && bar->shm); |
215 | struct swaybar_pointer *pointer = &bar->pointer; | ||
216 | |||
217 | assert(pointer->cursor_theme = wl_cursor_theme_load(NULL, 16, bar->shm)); | ||
218 | struct wl_cursor *cursor; | ||
219 | assert(cursor = wl_cursor_theme_get_cursor( | ||
220 | pointer->cursor_theme, "left_ptr")); | ||
221 | pointer->cursor_image = cursor->images[0]; | ||
222 | assert(pointer->cursor_surface = | ||
223 | wl_compositor_create_surface(bar->compositor)); | ||
119 | 224 | ||
120 | // TODO: we might not necessarily be meant to do all of the outputs | 225 | // TODO: we might not necessarily be meant to do all of the outputs |
121 | struct swaybar_output *output; | 226 | struct swaybar_output *output; |
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], |