aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/bar.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-03-30 21:38:28 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-03-30 22:44:08 -0400
commit8d1425bde9e7f17a5a9e6bce73dffcf296dad6a1 (patch)
tree803cc6a902f5d595e2dbcb3897e0633ccf5aa2fa /swaybar/bar.c
parentMerge pull request #1674 from swaywm/layer-input (diff)
downloadsway-8d1425bde9e7f17a5a9e6bce73dffcf296dad6a1.tar.gz
sway-8d1425bde9e7f17a5a9e6bce73dffcf296dad6a1.tar.zst
sway-8d1425bde9e7f17a5a9e6bce73dffcf296dad6a1.zip
Initialize seat pointer in swaybar
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r--swaybar/bar.c105
1 files changed, 105 insertions, 0 deletions
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
65static 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
78static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer,
79 uint32_t serial, struct wl_surface *surface) {
80 // Who cares
81}
82
83static 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
89static 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
95static 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
101static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) {
102 // Who cares
103}
104
105static void wl_pointer_axis_source(void *data, struct wl_pointer *wl_pointer,
106 uint32_t axis_source) {
107 // Who cares
108}
109
110static void wl_pointer_axis_stop(void *data, struct wl_pointer *wl_pointer,
111 uint32_t time, uint32_t axis) {
112 // Who cares
113}
114
115static void wl_pointer_axis_discrete(void *data, struct wl_pointer *wl_pointer,
116 uint32_t axis, int32_t discrete) {
117 // Who cares
118}
119
120struct 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
132static 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
141static void seat_handle_name(void *data, struct wl_seat *wl_seat,
142 const char *name) {
143 // Who cares
144}
145
146const struct wl_seat_listener seat_listener = {
147 .capabilities = seat_handle_capabilities,
148 .name = seat_handle_name,
149};
150
59static void handle_global(void *data, struct wl_registry *registry, 151static 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, &registry_listener, bar); 212 wl_registry_add_listener(registry, &registry_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;