diff options
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r-- | swaybar/bar.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c index 5679a892..f743236c 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c | |||
@@ -34,12 +34,6 @@ static void bar_init(struct swaybar *bar) { | |||
34 | wl_list_init(&bar->outputs); | 34 | wl_list_init(&bar->outputs); |
35 | } | 35 | } |
36 | 36 | ||
37 | struct swaybar_output *new_output(const char *name) { | ||
38 | struct swaybar_output *output = malloc(sizeof(struct swaybar_output)); | ||
39 | output->name = strdup(name); | ||
40 | return output; | ||
41 | } | ||
42 | |||
43 | static void layer_surface_configure(void *data, | 37 | static void layer_surface_configure(void *data, |
44 | struct zwlr_layer_surface_v1 *surface, | 38 | struct zwlr_layer_surface_v1 *surface, |
45 | uint32_t serial, uint32_t width, uint32_t height) { | 39 | uint32_t serial, uint32_t width, uint32_t height) { |
@@ -91,20 +85,39 @@ static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, | |||
91 | 85 | ||
92 | static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, | 86 | static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, |
93 | uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { | 87 | uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { |
94 | // TODO | 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); | ||
95 | } | 91 | } |
96 | 92 | ||
97 | static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, | 93 | static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, |
98 | uint32_t serial, uint32_t time, uint32_t button, uint32_t state) { | 94 | uint32_t serial, uint32_t time, uint32_t button, uint32_t state) { |
99 | wlr_log(L_DEBUG, "button"); | 95 | struct swaybar *bar = data; |
100 | // TODO | 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 | } | ||
101 | } | 114 | } |
102 | 115 | ||
103 | static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, | 116 | static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, |
104 | uint32_t time, uint32_t axis, wl_fixed_t value) { | 117 | uint32_t time, uint32_t axis, wl_fixed_t value) { |
105 | struct swaybar *bar = data; | 118 | struct swaybar *bar = data; |
106 | struct swaybar_output *output = bar->pointer.current; | 119 | struct swaybar_output *output = bar->pointer.current; |
107 | if (!output) { | 120 | if (!sway_assert(output, "axis with no active output")) { |
108 | return; | 121 | return; |
109 | } | 122 | } |
110 | double amt = wl_fixed_to_double(value); | 123 | double amt = wl_fixed_to_double(value); |
@@ -206,6 +219,7 @@ static void handle_global(void *data, struct wl_registry *registry, | |||
206 | &wl_output_interface, 1); | 219 | &wl_output_interface, 1); |
207 | output->index = index++; | 220 | output->index = index++; |
208 | wl_list_init(&output->workspaces); | 221 | wl_list_init(&output->workspaces); |
222 | wl_list_init(&output->hotspots); | ||
209 | wl_list_insert(&bar->outputs, &output->link); | 223 | wl_list_insert(&bar->outputs, &output->link); |
210 | } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { | 224 | } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { |
211 | bar->layer_shell = wl_registry_bind( | 225 | bar->layer_shell = wl_registry_bind( |