diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-03-30 22:02:55 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2018-03-30 22:44:08 -0400 |
commit | ae14dfc7ae70f16a31a10f4ff2395d4ac432308d (patch) | |
tree | 024e8fc68d3356712cb9c114d09fe2cc56cc0483 /swaybar/bar.c | |
parent | Initialize seat pointer in swaybar (diff) | |
download | sway-ae14dfc7ae70f16a31a10f4ff2395d4ac432308d.tar.gz sway-ae14dfc7ae70f16a31a10f4ff2395d4ac432308d.tar.zst sway-ae14dfc7ae70f16a31a10f4ff2395d4ac432308d.zip |
Implement scroll wheel workspace switching
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r-- | swaybar/bar.c | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c index e7b8b2ca..5679a892 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include "swaybar/ipc.h" | 24 | #include "swaybar/ipc.h" |
25 | #include "ipc-client.h" | 25 | #include "ipc-client.h" |
26 | #include "list.h" | 26 | #include "list.h" |
27 | #include "log.h" | ||
27 | #include "pango.h" | 28 | #include "pango.h" |
28 | #include "pool-buffer.h" | 29 | #include "pool-buffer.h" |
29 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" | 30 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" |
@@ -67,6 +68,13 @@ static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, | |||
67 | wl_fixed_t surface_x, wl_fixed_t surface_y) { | 68 | wl_fixed_t surface_x, wl_fixed_t surface_y) { |
68 | struct swaybar *bar = data; | 69 | struct swaybar *bar = data; |
69 | struct swaybar_pointer *pointer = &bar->pointer; | 70 | struct swaybar_pointer *pointer = &bar->pointer; |
71 | struct swaybar_output *output; | ||
72 | wl_list_for_each(output, &bar->outputs, link) { | ||
73 | if (output->surface == surface) { | ||
74 | pointer->current = output; | ||
75 | break; | ||
76 | } | ||
77 | } | ||
70 | wl_surface_attach(pointer->cursor_surface, | 78 | wl_surface_attach(pointer->cursor_surface, |
71 | wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0); | 79 | wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0); |
72 | wl_pointer_set_cursor(wl_pointer, serial, pointer->cursor_surface, | 80 | wl_pointer_set_cursor(wl_pointer, serial, pointer->cursor_surface, |
@@ -77,12 +85,12 @@ static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, | |||
77 | 85 | ||
78 | static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, | 86 | static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, |
79 | uint32_t serial, struct wl_surface *surface) { | 87 | uint32_t serial, struct wl_surface *surface) { |
80 | // Who cares | 88 | struct swaybar *bar = data; |
89 | bar->pointer.current = NULL; | ||
81 | } | 90 | } |
82 | 91 | ||
83 | static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, | 92 | 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) { | 93 | uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { |
85 | wlr_log(L_DEBUG, "motion"); | ||
86 | // TODO | 94 | // TODO |
87 | } | 95 | } |
88 | 96 | ||
@@ -94,8 +102,36 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, | |||
94 | 102 | ||
95 | static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, | 103 | static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, |
96 | uint32_t time, uint32_t axis, wl_fixed_t value) { | 104 | uint32_t time, uint32_t axis, wl_fixed_t value) { |
97 | wlr_log(L_DEBUG, "axis"); | 105 | struct swaybar *bar = data; |
98 | // TODO | 106 | struct swaybar_output *output = bar->pointer.current; |
107 | if (!output) { | ||
108 | return; | ||
109 | } | ||
110 | double amt = wl_fixed_to_double(value); | ||
111 | if (!bar->config->wrap_scroll) { | ||
112 | int i = 0; | ||
113 | struct swaybar_workspace *ws = NULL; | ||
114 | wl_list_for_each(ws, &output->workspaces, link) { | ||
115 | if (ws->focused) { | ||
116 | break; | ||
117 | } | ||
118 | ++i; | ||
119 | } | ||
120 | int len = wl_list_length(&output->workspaces); | ||
121 | if (!sway_assert(i != len, "axis with null workspace")) { | ||
122 | return; | ||
123 | } | ||
124 | if (i == 0 && amt > 0) { | ||
125 | return; // Do not wrap | ||
126 | } | ||
127 | if (i == len - 1 && amt < 0) { | ||
128 | return; // Do not wrap | ||
129 | } | ||
130 | } | ||
131 | |||
132 | const char *workspace_name = | ||
133 | amt < 0 ? "prev_on_output" : "next_on_output"; | ||
134 | ipc_send_workspace_command(bar, workspace_name); | ||
99 | } | 135 | } |
100 | 136 | ||
101 | static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) { | 137 | static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) { |