Merge pull request #752 from deklov/bar-scroll-02

Change workspace with mouse wheel
This commit is contained in:
Drew DeVault 2016-07-16 09:09:37 -04:00 committed by GitHub
commit e66f813d49
3 changed files with 42 additions and 6 deletions

View file

@ -27,11 +27,20 @@ struct cursor {
struct wl_poitner *pointer; struct wl_poitner *pointer;
}; };
enum scroll_direction {
SCROLL_UP,
SCROLL_DOWN,
SCROLL_LEFT,
SCROLL_RIGHT,
};
struct pointer_input { struct pointer_input {
int last_x; int last_x;
int last_y; int last_y;
void (*notify)(struct window *window, int x, int y, uint32_t button); void (*notify_button)(struct window *window, int x, int y, uint32_t button);
void (*notify_scroll)(struct window *window, enum scroll_direction direction);
}; };
struct window { struct window {

View file

@ -89,6 +89,13 @@ static void mouse_button_notify(struct window *window, int x, int y, uint32_t bu
} }
} }
static void mouse_scroll_notify(struct window *window, enum scroll_direction direction) {
sway_log(L_DEBUG, "Mouse wheel scrolled %s", direction == SCROLL_UP ? "up" : "down");
const char *workspace_name = direction == SCROLL_UP ? "prev_on_output" : "next_on_output";
ipc_send_workspace_command(workspace_name);
}
void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) { void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) {
/* initialize bar with default values */ /* initialize bar with default values */
bar_init(bar); bar_init(bar);
@ -123,8 +130,9 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) {
/* set font */ /* set font */
bar_output->window->font = bar->config->font; bar_output->window->font = bar->config->font;
/* set font */ /* set mouse event callbacks */
bar_output->window->pointer_input.notify = mouse_button_notify; bar_output->window->pointer_input.notify_button = mouse_button_notify;
bar_output->window->pointer_input.notify_scroll = mouse_scroll_notify;
/* set window height */ /* set window height */
set_window_height(bar_output->window, bar->config->height); set_window_height(bar_output->window, bar->config->height);

View file

@ -41,13 +41,32 @@ static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32
struct window *window = data; struct window *window = data;
struct pointer_input *input = &window->pointer_input; struct pointer_input *input = &window->pointer_input;
if (window->pointer_input.notify) { if (window->pointer_input.notify_button) {
window->pointer_input.notify(window, input->last_x, input->last_y, button); window->pointer_input.notify_button(window, input->last_x, input->last_y, button);
} }
} }
static void pointer_handle_axis(void *data, struct wl_pointer *pointer, static void pointer_handle_axis(void *data, struct wl_pointer *pointer,
uint32_t time, uint32_t axis, wl_fixed_t value) { uint32_t time, uint32_t axis, wl_fixed_t value) {
struct window *window = data;
enum scroll_direction direction;
switch (axis) {
case 0:
direction = wl_fixed_to_double(value) < 0 ? SCROLL_UP : SCROLL_DOWN;
break;
case 1:
direction = wl_fixed_to_double(value) < 0 ? SCROLL_LEFT : SCROLL_RIGHT;
break;
default:
if (!sway_assert(false, "Unexpected axis value")) {
return;
}
}
if (window->pointer_input.notify_scroll) {
window->pointer_input.notify_scroll(window, direction);
}
} }
static const struct wl_pointer_listener pointer_listener = { static const struct wl_pointer_listener pointer_listener = {