mirror of
https://github.com/swaywm/sway.git
synced 2024-11-22 07:51:28 +00:00
Implement scroll wheel workspace switching
This commit is contained in:
parent
8d1425bde9
commit
ae14dfc7ae
|
@ -6,5 +6,6 @@
|
|||
void ipc_initialize(struct swaybar *bar, const char *bar_id);
|
||||
bool handle_ipc_event(struct swaybar *bar);
|
||||
void ipc_get_workspaces(struct swaybar *bar);
|
||||
void ipc_send_workspace_command(struct swaybar *bar, const char *ws);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue