aboutsummaryrefslogtreecommitdiff
path: root/swaybar
diff options
context:
space:
mode:
Diffstat (limited to 'swaybar')
-rw-r--r--swaybar/bar.c44
-rw-r--r--swaybar/ipc.c8
2 files changed, 48 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 @@
#include "swaybar/ipc.h"
#include "ipc-client.h"
#include "list.h"
+#include "log.h"
#include "pango.h"
#include "pool-buffer.h"
#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,
wl_fixed_t surface_x, wl_fixed_t surface_y) {
struct swaybar *bar = data;
struct swaybar_pointer *pointer = &bar->pointer;
+ struct swaybar_output *output;
+ wl_list_for_each(output, &bar->outputs, link) {
+ if (output->surface == surface) {
+ pointer->current = output;
+ break;
+ }
+ }
wl_surface_attach(pointer->cursor_surface,
wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0);
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,
static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer,
uint32_t serial, struct wl_surface *surface) {
- // Who cares
+ struct swaybar *bar = data;
+ bar->pointer.current = NULL;
}
static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
- wlr_log(L_DEBUG, "motion");
// TODO
}
@@ -94,8 +102,36 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
uint32_t time, uint32_t axis, wl_fixed_t value) {
- wlr_log(L_DEBUG, "axis");
- // TODO
+ struct swaybar *bar = data;
+ struct swaybar_output *output = bar->pointer.current;
+ if (!output) {
+ return;
+ }
+ double amt = wl_fixed_to_double(value);
+ if (!bar->config->wrap_scroll) {
+ int i = 0;
+ struct swaybar_workspace *ws = NULL;
+ wl_list_for_each(ws, &output->workspaces, link) {
+ if (ws->focused) {
+ break;
+ }
+ ++i;
+ }
+ int len = wl_list_length(&output->workspaces);
+ if (!sway_assert(i != len, "axis with null workspace")) {
+ return;
+ }
+ if (i == 0 && amt > 0) {
+ return; // Do not wrap
+ }
+ if (i == len - 1 && amt < 0) {
+ return; // Do not wrap
+ }
+ }
+
+ const char *workspace_name =
+ amt < 0 ? "prev_on_output" : "next_on_output";
+ ipc_send_workspace_command(bar, workspace_name);
}
static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) {
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 @@
#include "swaybar/ipc.h"
#include "ipc-client.h"
+void ipc_send_workspace_command(struct swaybar *bar, const char *ws) {
+ const char *fmt = "workspace \"%s\"";
+ uint32_t size = snprintf(NULL, 0, fmt, ws);
+ char command[size];
+ snprintf(command, size, fmt, ws);
+ ipc_single_command(bar->ipc_socketfd, IPC_COMMAND, command, &size);
+}
+
char *parse_font(const char *font) {
char *new_font = NULL;
if (strncmp("pango:", font, 6) == 0) {