From b24b319bdfb3e94d16950d7fdeadba990bb91a2d Mon Sep 17 00:00:00 2001 From: Bruno Pinto Date: Sun, 8 Apr 2018 00:34:12 +0100 Subject: [PATCH 1/7] Improve dependency checks --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 5a37b0e2..bf266e5f 100644 --- a/meson.build +++ b/meson.build @@ -35,7 +35,7 @@ pangocairo = dependency('pangocairo') gdk_pixbuf = dependency('gdk-pixbuf-2.0', required: false) pixman = dependency('pixman-1') libcap = dependency('libcap') -libinput = dependency('libinput') +libinput = dependency('libinput', version: '>=1.6.0') libpam = cc.find_library('libpam') math = cc.find_library('m') rt = cc.find_library('rt') From 257a831c726e7dadb23eca224ef405f374961695 Mon Sep 17 00:00:00 2001 From: db Date: Sun, 8 Apr 2018 15:48:59 +0200 Subject: [PATCH 2/7] Use full ws->name in swaybar hotspot callback If strip_workspace_numbers option is enabled, we must preserve the right workspace name for hotspot. --- swaybar/render.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/swaybar/render.c b/swaybar/render.c index 53e578f0..1c24e01f 100644 --- a/swaybar/render.c +++ b/swaybar/render.c @@ -352,6 +352,7 @@ static uint32_t render_workspace_button(cairo_t *cairo, struct swaybar_output *output, struct swaybar_config *config, struct swaybar_workspace *ws, double *x, uint32_t surface_height) { const char *name = ws->name; + const char *whole_name = ws->name; if (config->strip_workspace_numbers) { name = strip_workspace_number(ws->name); } @@ -411,7 +412,7 @@ static uint32_t render_workspace_button(cairo_t *cairo, hotspot->height = height; hotspot->callback = workspace_hotspot_callback; hotspot->destroy = free; - hotspot->data = strdup(name); + hotspot->data = strdup(whole_name); wl_list_insert(&output->hotspots, &hotspot->link); *x += width; From 4ba6545c650712b1ec18854fa7f94995d0176637 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 8 Apr 2018 10:04:23 -0400 Subject: [PATCH 3/7] Fixup for #1773 --- swaybar/render.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/swaybar/render.c b/swaybar/render.c index 1c24e01f..d2175f0a 100644 --- a/swaybar/render.c +++ b/swaybar/render.c @@ -352,7 +352,6 @@ static uint32_t render_workspace_button(cairo_t *cairo, struct swaybar_output *output, struct swaybar_config *config, struct swaybar_workspace *ws, double *x, uint32_t surface_height) { const char *name = ws->name; - const char *whole_name = ws->name; if (config->strip_workspace_numbers) { name = strip_workspace_number(ws->name); } @@ -412,7 +411,7 @@ static uint32_t render_workspace_button(cairo_t *cairo, hotspot->height = height; hotspot->callback = workspace_hotspot_callback; hotspot->destroy = free; - hotspot->data = strdup(whole_name); + hotspot->data = strdup(ws->name); wl_list_insert(&output->hotspots, &hotspot->link); *x += width; From 042b80b9faef72c36451eecb5c803223fda3264a Mon Sep 17 00:00:00 2001 From: db Date: Sun, 8 Apr 2018 16:44:59 +0200 Subject: [PATCH 4/7] Add workspace_auto_back_and_forth command This is the only missing piece - other code regarding this functionality has already been ported from pre-wlroots source. --- sway/commands.c | 1 + sway/commands/ws_auto_back_and_forth.c | 12 ++++++++++++ sway/meson.build | 1 + 3 files changed, 14 insertions(+) create mode 100644 sway/commands/ws_auto_back_and_forth.c diff --git a/sway/commands.c b/sway/commands.c index 22decef3..20b8a2aa 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -106,6 +106,7 @@ static struct cmd_handler handlers[] = { { "output", cmd_output }, { "seat", cmd_seat }, { "workspace", cmd_workspace }, + { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth }, }; static struct cmd_handler bar_handlers[] = { diff --git a/sway/commands/ws_auto_back_and_forth.c b/sway/commands/ws_auto_back_and_forth.c new file mode 100644 index 00000000..2485db35 --- /dev/null +++ b/sway/commands/ws_auto_back_and_forth.c @@ -0,0 +1,12 @@ +#include +#include +#include "sway/commands.h" + +struct cmd_results *cmd_ws_auto_back_and_forth(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "workspace_auto_back_and_forth", EXPECTED_EQUAL_TO, 1))) { + return error; + } + config->auto_back_and_forth = !strcasecmp(argv[0], "yes"); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/meson.build b/sway/meson.build index 1fe0f29a..2521069f 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -52,6 +52,7 @@ sway_sources = files( 'commands/split.c', 'commands/swaybg_command.c', 'commands/workspace.c', + 'commands/ws_auto_back_and_forth.c', 'commands/bar/activate_button.c', 'commands/bar/binding_mode_indicator.c', From 9114d3b84cf4e5ba0513a8f4d4a018a6de3d6223 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 8 Apr 2018 10:48:13 -0400 Subject: [PATCH 5/7] Implement tablet tool support --- include/sway/input/cursor.h | 4 ++- sway/input/cursor.c | 67 ++++++++++++++++++++++++++++++++----- sway/input/seat.c | 12 +++++-- 3 files changed, 72 insertions(+), 11 deletions(-) diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 64917ce5..8f907dcd 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h @@ -1,6 +1,6 @@ #ifndef _SWAY_INPUT_CURSOR_H #define _SWAY_INPUT_CURSOR_H - +#include #include "sway/input/seat.h" struct sway_cursor { @@ -22,6 +22,8 @@ struct sway_cursor { struct wl_listener tool_axis; struct wl_listener tool_tip; + struct wl_listener tool_button; + uint32_t tool_buttons; struct wl_listener request_set_cursor; }; diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 6db615b1..cdded1c7 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -179,10 +179,8 @@ static void handle_cursor_motion_absolute( cursor_send_pointer_motion(cursor, event->time_msec); } -static void handle_cursor_button(struct wl_listener *listener, void *data) { - struct sway_cursor *cursor = wl_container_of(listener, cursor, button); - struct wlr_event_pointer_button *event = data; - +static void dispatch_cursor_button(struct sway_cursor *cursor, + uint32_t time_msec, uint32_t button, enum wlr_button_state state) { struct wlr_surface *surface = NULL; double sx, sy; struct sway_container *cont = @@ -215,8 +213,15 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) { seat_set_focus(cursor->seat, cont); } - wlr_seat_pointer_notify_button(cursor->seat->wlr_seat, event->time_msec, - event->button, event->state); + wlr_seat_pointer_notify_button(cursor->seat->wlr_seat, + time_msec, button, state); +} + +static void handle_cursor_button(struct wl_listener *listener, void *data) { + struct sway_cursor *cursor = wl_container_of(listener, cursor, button); + struct wlr_event_pointer_button *event = data; + dispatch_cursor_button(cursor, + event->time_msec, event->button, event->state); } static void handle_cursor_axis(struct wl_listener *listener, void *data) { @@ -248,13 +253,53 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { static void handle_tool_axis(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis); struct wlr_event_tablet_tool_axis *event = data; - wlr_log(L_DEBUG, "TODO: handle tool axis event: %p", event); + + if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) && + (event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { + wlr_cursor_warp_absolute(cursor->cursor, event->device, + event->x, event->y); + cursor_update_position(cursor); + cursor_send_pointer_motion(cursor, event->time_msec); + } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) { + wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, -1); + cursor_update_position(cursor); + cursor_send_pointer_motion(cursor, event->time_msec); + } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { + wlr_cursor_warp_absolute(cursor->cursor, event->device, -1, event->y); + cursor_update_position(cursor); + cursor_send_pointer_motion(cursor, event->time_msec); + } } static void handle_tool_tip(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_tip); struct wlr_event_tablet_tool_tip *event = data; - wlr_log(L_DEBUG, "TODO: handle tool tip event: %p", event); + dispatch_cursor_button(cursor, event->time_msec, + BTN_LEFT, event->state == WLR_TABLET_TOOL_TIP_DOWN ? + WLR_BUTTON_PRESSED : WLR_BUTTON_RELEASED); +} + +static void handle_tool_button(struct wl_listener *listener, void *data) { + struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_button); + struct wlr_event_tablet_tool_button *event = data; + // TODO: the user may want to configure which tool buttons are mapped to + // which simulated pointer buttons + switch (event->state) { + case WLR_BUTTON_PRESSED: + if (cursor->tool_buttons == 0) { + dispatch_cursor_button(cursor, + event->time_msec, BTN_RIGHT, event->state); + } + cursor->tool_buttons++; + break; + case WLR_BUTTON_RELEASED: + if (cursor->tool_buttons == 1) { + dispatch_cursor_button(cursor, + event->time_msec, BTN_RIGHT, event->state); + } + cursor->tool_buttons--; + break; + } } static void handle_request_set_cursor(struct wl_listener *listener, @@ -332,6 +377,9 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) { &cursor->touch_motion); cursor->touch_motion.notify = handle_touch_motion; + // TODO: tablet protocol support + // Note: We should emulate pointer events for clients that don't support the + // tablet protocol when the time comes wl_signal_add(&wlr_cursor->events.tablet_tool_axis, &cursor->tool_axis); cursor->tool_axis.notify = handle_tool_axis; @@ -339,6 +387,9 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) { wl_signal_add(&wlr_cursor->events.tablet_tool_tip, &cursor->tool_tip); cursor->tool_tip.notify = handle_tool_tip; + wl_signal_add(&wlr_cursor->events.tablet_tool_button, &cursor->tool_button); + cursor->tool_button.notify = handle_tool_button; + wl_signal_add(&seat->wlr_seat->events.request_set_cursor, &cursor->request_set_cursor); cursor->request_set_cursor.notify = handle_request_set_cursor; diff --git a/sway/input/seat.c b/sway/input/seat.c index b94e3291..c34da5e5 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -245,6 +245,12 @@ static void seat_configure_keyboard(struct sway_seat *seat, } } +static void seat_configure_tablet_tool(struct sway_seat *seat, + struct sway_seat_device *sway_device) { + wlr_cursor_attach_input_device(seat->cursor->cursor, + sway_device->input_device->wlr_device); +} + static struct sway_seat_device *seat_get_device(struct sway_seat *seat, struct sway_input_device *input_device) { struct sway_seat_device *seat_device = NULL; @@ -272,9 +278,11 @@ void seat_configure_device(struct sway_seat *seat, case WLR_INPUT_DEVICE_KEYBOARD: seat_configure_keyboard(seat, seat_device); break; - case WLR_INPUT_DEVICE_TOUCH: - case WLR_INPUT_DEVICE_TABLET_PAD: case WLR_INPUT_DEVICE_TABLET_TOOL: + seat_configure_tablet_tool(seat, seat_device); + break; + case WLR_INPUT_DEVICE_TABLET_PAD: + case WLR_INPUT_DEVICE_TOUCH: wlr_log(L_DEBUG, "TODO: configure other devices"); break; } From 9570e37016ff6d2d6fa9ac85b576b8cc17f04e8c Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 8 Apr 2018 11:19:14 -0400 Subject: [PATCH 6/7] Update for wlroots#850 --- sway/server.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sway/server.c b/sway/server.c index 0e98b5f9..c1125f14 100644 --- a/sway/server.c +++ b/sway/server.c @@ -111,8 +111,7 @@ bool server_init(struct sway_server *server) { wlr_server_decoration_manager_set_default_mode( deco_manager, WLR_SERVER_DECORATION_MANAGER_MODE_SERVER); - struct wlr_egl *egl = wlr_backend_get_egl(server->backend); - wlr_linux_dmabuf_create(server->wl_display, egl); + wlr_linux_dmabuf_create(server->wl_display, renderer); server->socket = wl_display_add_socket_auto(server->wl_display); if (!server->socket) { From 5ebc99253ae04ee31d31b3f01bc0ce35f6ea5979 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 8 Apr 2018 11:43:18 -0400 Subject: [PATCH 7/7] Use wlr_surface_point_accepts_input for unmanaged surfaces --- sway/input/cursor.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index cdded1c7..4bcf72fc 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -52,17 +52,13 @@ static struct sway_container *container_at_cursor(struct sway_cursor *cursor, wl_list_for_each_reverse(unmanaged_surface, unmanaged, link) { struct wlr_xwayland_surface *xsurface = unmanaged_surface->wlr_xwayland_surface; - struct wlr_box box = { - .x = unmanaged_surface->lx, - .y = unmanaged_surface->ly, - .width = xsurface->width, - .height = xsurface->height, - }; - - if (wlr_box_contains_point(&box, cursor->x, cursor->y)) { + + double _sx = cursor->x - unmanaged_surface->lx; + double _sy = cursor->y - unmanaged_surface->ly; + if (wlr_surface_point_accepts_input(xsurface->surface, _sx, _sy)) { *surface = xsurface->surface; - *sx = cursor->x - box.x; - *sy = cursor->y - box.y; + *sx = _sx; + *sy = _sy; return NULL; } }