2017-12-08 13:22:26 +01:00
|
|
|
#define _XOPEN_SOURCE 700
|
2018-04-27 18:30:45 +02:00
|
|
|
#include <math.h>
|
2017-12-10 17:11:47 +01:00
|
|
|
#ifdef __linux__
|
|
|
|
#include <linux/input-event-codes.h>
|
|
|
|
#elif __FreeBSD__
|
|
|
|
#include <dev/evdev/input-event-codes.h>
|
|
|
|
#endif
|
2018-07-18 08:13:28 +02:00
|
|
|
#include <limits.h>
|
2017-12-08 13:22:26 +01:00
|
|
|
#include <wlr/types/wlr_cursor.h>
|
2017-12-09 20:06:00 +01:00
|
|
|
#include <wlr/types/wlr_xcursor_manager.h>
|
2018-04-17 09:54:02 +02:00
|
|
|
#include <wlr/types/wlr_idle.h>
|
2017-12-10 14:48:44 +01:00
|
|
|
#include "list.h"
|
2017-12-08 13:22:26 +01:00
|
|
|
#include "log.h"
|
2018-07-18 08:13:28 +02:00
|
|
|
#include "sway/desktop.h"
|
2018-07-15 07:20:21 +02:00
|
|
|
#include "sway/desktop/transaction.h"
|
2018-03-30 21:33:16 +02:00
|
|
|
#include "sway/input/cursor.h"
|
2018-07-18 08:13:28 +02:00
|
|
|
#include "sway/input/keyboard.h"
|
2018-03-31 03:03:35 +02:00
|
|
|
#include "sway/layers.h"
|
2018-03-30 21:33:16 +02:00
|
|
|
#include "sway/output.h"
|
2018-07-18 08:13:28 +02:00
|
|
|
#include "sway/tree/arrange.h"
|
2018-03-30 21:33:16 +02:00
|
|
|
#include "sway/tree/view.h"
|
2018-04-18 00:35:28 +02:00
|
|
|
#include "sway/tree/workspace.h"
|
2018-03-31 03:03:35 +02:00
|
|
|
#include "wlr-layer-shell-unstable-v1-protocol.h"
|
2017-12-08 13:22:26 +01:00
|
|
|
|
2018-04-21 15:07:22 +02:00
|
|
|
static uint32_t get_current_time_msec() {
|
|
|
|
struct timespec now;
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
|
|
return now.tv_nsec / 1000;
|
|
|
|
}
|
|
|
|
|
2018-03-31 03:03:35 +02:00
|
|
|
static struct wlr_surface *layer_surface_at(struct sway_output *output,
|
|
|
|
struct wl_list *layer, double ox, double oy, double *sx, double *sy) {
|
|
|
|
struct sway_layer_surface *sway_layer;
|
|
|
|
wl_list_for_each_reverse(sway_layer, layer, link) {
|
|
|
|
struct wlr_surface *wlr_surface =
|
|
|
|
sway_layer->layer_surface->surface;
|
|
|
|
double _sx = ox - sway_layer->geo.x;
|
|
|
|
double _sy = oy - sway_layer->geo.y;
|
|
|
|
// TODO: Test popups/subsurfaces
|
2018-03-31 05:08:24 +02:00
|
|
|
if (wlr_surface_point_accepts_input(wlr_surface, _sx, _sy)) {
|
2018-03-31 03:03:35 +02:00
|
|
|
*sx = _sx;
|
|
|
|
*sy = _sy;
|
|
|
|
return wlr_surface;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-03-30 22:12:02 +02:00
|
|
|
/**
|
2018-03-31 03:03:35 +02:00
|
|
|
* Returns the container at the cursor's position. If there is a surface at that
|
|
|
|
* location, it is stored in **surface (it may not be a view).
|
2018-03-30 22:12:02 +02:00
|
|
|
*/
|
2018-05-02 15:00:26 +02:00
|
|
|
static struct sway_container *container_at_coords(
|
2018-05-26 08:26:10 +02:00
|
|
|
struct sway_seat *seat, double lx, double ly,
|
2018-03-30 21:33:16 +02:00
|
|
|
struct wlr_surface **surface, double *sx, double *sy) {
|
2018-01-14 19:19:21 +01:00
|
|
|
// check for unmanaged views first
|
2018-04-02 20:35:43 +02:00
|
|
|
struct wl_list *unmanaged = &root_container.sway_root->xwayland_unmanaged;
|
2018-04-06 00:48:35 +02:00
|
|
|
struct sway_xwayland_unmanaged *unmanaged_surface;
|
|
|
|
wl_list_for_each_reverse(unmanaged_surface, unmanaged, link) {
|
2018-04-02 20:35:43 +02:00
|
|
|
struct wlr_xwayland_surface *xsurface =
|
2018-04-06 00:48:35 +02:00
|
|
|
unmanaged_surface->wlr_xwayland_surface;
|
2018-01-14 19:19:21 +01:00
|
|
|
|
2018-05-26 08:26:10 +02:00
|
|
|
double _sx = lx - unmanaged_surface->lx;
|
|
|
|
double _sy = ly - unmanaged_surface->ly;
|
2018-04-08 17:43:18 +02:00
|
|
|
if (wlr_surface_point_accepts_input(xsurface->surface, _sx, _sy)) {
|
2018-03-31 17:30:15 +02:00
|
|
|
*surface = xsurface->surface;
|
2018-04-08 17:43:18 +02:00
|
|
|
*sx = _sx;
|
|
|
|
*sy = _sy;
|
2018-03-31 17:30:15 +02:00
|
|
|
return NULL;
|
2018-01-14 19:19:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-30 21:33:16 +02:00
|
|
|
// find the output the cursor is on
|
|
|
|
struct wlr_output_layout *output_layout =
|
|
|
|
root_container.sway_root->output_layout;
|
2018-05-02 15:00:26 +02:00
|
|
|
struct wlr_output *wlr_output = wlr_output_layout_output_at(
|
2018-05-26 08:26:10 +02:00
|
|
|
output_layout, lx, ly);
|
2018-03-30 21:33:16 +02:00
|
|
|
if (wlr_output == NULL) {
|
|
|
|
return NULL;
|
2018-03-30 16:53:18 +02:00
|
|
|
}
|
2018-03-30 21:33:16 +02:00
|
|
|
struct sway_output *output = wlr_output->data;
|
2018-05-26 08:26:10 +02:00
|
|
|
double ox = lx, oy = ly;
|
2018-03-31 03:03:35 +02:00
|
|
|
wlr_output_layout_output_coords(output_layout, wlr_output, &ox, &oy);
|
2018-03-30 21:33:16 +02:00
|
|
|
|
|
|
|
// find the focused workspace on the output for this seat
|
2018-05-02 15:00:26 +02:00
|
|
|
struct sway_container *ws = seat_get_focus_inactive(seat, output->swayc);
|
2018-03-31 03:03:35 +02:00
|
|
|
if (ws && ws->type != C_WORKSPACE) {
|
|
|
|
ws = container_parent(ws, C_WORKSPACE);
|
2018-03-30 22:12:02 +02:00
|
|
|
}
|
2018-03-31 03:03:35 +02:00
|
|
|
if (!ws) {
|
2018-03-30 22:12:02 +02:00
|
|
|
return output->swayc;
|
2018-03-30 21:33:16 +02:00
|
|
|
}
|
|
|
|
|
2018-03-31 03:03:35 +02:00
|
|
|
if ((*surface = layer_surface_at(output,
|
|
|
|
&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY],
|
|
|
|
ox, oy, sx, sy))) {
|
|
|
|
return ws;
|
|
|
|
}
|
2018-04-18 05:06:10 +02:00
|
|
|
if (ws->sway_workspace->fullscreen) {
|
|
|
|
struct wlr_surface *wlr_surface = ws->sway_workspace->fullscreen->surface;
|
|
|
|
if (wlr_surface_point_accepts_input(wlr_surface, ox, oy)) {
|
|
|
|
*sx = ox;
|
|
|
|
*sy = oy;
|
|
|
|
*surface = wlr_surface;
|
|
|
|
return ws->sway_workspace->fullscreen->swayc;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-03-31 03:03:35 +02:00
|
|
|
if ((*surface = layer_surface_at(output,
|
|
|
|
&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP],
|
|
|
|
ox, oy, sx, sy))) {
|
|
|
|
return ws;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sway_container *c;
|
2018-05-26 08:26:10 +02:00
|
|
|
if ((c = floating_container_at(lx, ly, surface, sx, sy))) {
|
2018-05-24 14:30:44 +02:00
|
|
|
return c;
|
|
|
|
}
|
2018-05-26 08:26:10 +02:00
|
|
|
if ((c = container_at(ws, lx, ly, surface, sx, sy))) {
|
2018-03-31 03:03:35 +02:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*surface = layer_surface_at(output,
|
|
|
|
&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM],
|
|
|
|
ox, oy, sx, sy))) {
|
|
|
|
return ws;
|
|
|
|
}
|
|
|
|
if ((*surface = layer_surface_at(output,
|
|
|
|
&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND],
|
|
|
|
ox, oy, sx, sy))) {
|
|
|
|
return ws;
|
|
|
|
}
|
|
|
|
|
2018-07-18 08:13:28 +02:00
|
|
|
c = seat_get_active_child(seat, output->swayc);
|
2018-04-06 15:32:38 +02:00
|
|
|
if (c) {
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
if (!c && output->swayc->children->length) {
|
|
|
|
c = output->swayc->children->items[0];
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
return output->swayc;
|
2018-03-30 21:33:16 +02:00
|
|
|
}
|
|
|
|
|
2018-07-20 01:28:22 +02:00
|
|
|
static enum wlr_edges find_resize_edge(struct sway_container *cont,
|
2018-07-18 08:13:28 +02:00
|
|
|
struct sway_cursor *cursor) {
|
|
|
|
if (cont->type != C_VIEW) {
|
2018-07-20 01:28:22 +02:00
|
|
|
return WLR_EDGE_NONE;
|
2018-07-18 08:13:28 +02:00
|
|
|
}
|
|
|
|
struct sway_view *view = cont->sway_view;
|
|
|
|
if (view->border == B_NONE || !view->border_thickness || view->using_csd) {
|
2018-07-20 01:28:22 +02:00
|
|
|
return WLR_EDGE_NONE;
|
2018-07-18 08:13:28 +02:00
|
|
|
}
|
|
|
|
|
2018-07-20 01:28:22 +02:00
|
|
|
enum wlr_edges edge = 0;
|
2018-07-18 08:13:28 +02:00
|
|
|
if (cursor->cursor->x < cont->x + view->border_thickness) {
|
2018-07-20 01:28:22 +02:00
|
|
|
edge |= WLR_EDGE_LEFT;
|
2018-07-18 08:13:28 +02:00
|
|
|
}
|
|
|
|
if (cursor->cursor->y < cont->y + view->border_thickness) {
|
2018-07-20 01:28:22 +02:00
|
|
|
edge |= WLR_EDGE_TOP;
|
2018-07-18 08:13:28 +02:00
|
|
|
}
|
|
|
|
if (cursor->cursor->x >= cont->x + cont->width - view->border_thickness) {
|
2018-07-20 01:28:22 +02:00
|
|
|
edge |= WLR_EDGE_RIGHT;
|
2018-07-18 08:13:28 +02:00
|
|
|
}
|
|
|
|
if (cursor->cursor->y >= cont->y + cont->height - view->border_thickness) {
|
2018-07-20 01:28:22 +02:00
|
|
|
edge |= WLR_EDGE_BOTTOM;
|
2018-07-18 08:13:28 +02:00
|
|
|
}
|
|
|
|
return edge;
|
|
|
|
}
|
|
|
|
|
2018-07-20 01:28:22 +02:00
|
|
|
static void handle_move_motion(struct sway_seat *seat,
|
2018-07-18 08:13:28 +02:00
|
|
|
struct sway_cursor *cursor) {
|
|
|
|
struct sway_container *con = seat->op_container;
|
|
|
|
desktop_damage_whole_container(con);
|
|
|
|
container_floating_translate(con,
|
|
|
|
cursor->cursor->x - cursor->previous.x,
|
|
|
|
cursor->cursor->y - cursor->previous.y);
|
|
|
|
desktop_damage_whole_container(con);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void calculate_floating_constraints(struct sway_container *con,
|
|
|
|
int *min_width, int *max_width, int *min_height, int *max_height) {
|
|
|
|
if (config->floating_minimum_width == -1) { // no minimum
|
|
|
|
*min_width = 0;
|
|
|
|
} else if (config->floating_minimum_width == 0) { // automatic
|
|
|
|
*min_width = 75;
|
|
|
|
} else {
|
|
|
|
*min_width = config->floating_minimum_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config->floating_minimum_height == -1) { // no minimum
|
|
|
|
*min_height = 0;
|
|
|
|
} else if (config->floating_minimum_height == 0) { // automatic
|
|
|
|
*min_height = 50;
|
|
|
|
} else {
|
|
|
|
*min_height = config->floating_minimum_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config->floating_maximum_width == -1) { // no maximum
|
|
|
|
*max_width = INT_MAX;
|
|
|
|
} else if (config->floating_maximum_width == 0) { // automatic
|
|
|
|
struct sway_container *ws = container_parent(con, C_WORKSPACE);
|
|
|
|
*max_width = ws->width;
|
|
|
|
} else {
|
|
|
|
*max_width = config->floating_maximum_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config->floating_maximum_height == -1) { // no maximum
|
|
|
|
*max_height = INT_MAX;
|
|
|
|
} else if (config->floating_maximum_height == 0) { // automatic
|
|
|
|
struct sway_container *ws = container_parent(con, C_WORKSPACE);
|
|
|
|
*max_height = ws->height;
|
|
|
|
} else {
|
|
|
|
*max_height = config->floating_maximum_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static void handle_resize_motion(struct sway_seat *seat,
|
|
|
|
struct sway_cursor *cursor) {
|
|
|
|
struct sway_container *con = seat->op_container;
|
2018-07-20 01:28:22 +02:00
|
|
|
enum wlr_edges edge = seat->op_resize_edge;
|
2018-07-18 08:13:28 +02:00
|
|
|
|
|
|
|
// The amount the mouse has moved since the start of the resize operation
|
|
|
|
// Positive is down/right
|
|
|
|
double mouse_move_x = cursor->cursor->x - seat->op_ref_lx;
|
|
|
|
double mouse_move_y = cursor->cursor->y - seat->op_ref_ly;
|
|
|
|
|
2018-07-20 01:28:22 +02:00
|
|
|
if (edge == WLR_EDGE_TOP || edge == WLR_EDGE_BOTTOM) {
|
2018-07-18 08:13:28 +02:00
|
|
|
mouse_move_x = 0;
|
|
|
|
}
|
2018-07-20 01:28:22 +02:00
|
|
|
if (edge == WLR_EDGE_LEFT || edge == WLR_EDGE_RIGHT) {
|
2018-07-18 08:13:28 +02:00
|
|
|
mouse_move_y = 0;
|
|
|
|
}
|
|
|
|
|
2018-07-20 01:28:22 +02:00
|
|
|
double grow_width = edge & WLR_EDGE_LEFT ? -mouse_move_x : mouse_move_x;
|
|
|
|
double grow_height = edge & WLR_EDGE_TOP ? -mouse_move_y : mouse_move_y;
|
2018-07-18 08:13:28 +02:00
|
|
|
|
|
|
|
if (seat->op_resize_preserve_ratio) {
|
|
|
|
double x_multiplier = grow_width / seat->op_ref_width;
|
|
|
|
double y_multiplier = grow_height / seat->op_ref_height;
|
2018-07-19 05:42:43 +02:00
|
|
|
double max_multiplier = fmax(x_multiplier, y_multiplier);
|
|
|
|
grow_width = seat->op_ref_width * max_multiplier;
|
|
|
|
grow_height = seat->op_ref_height * max_multiplier;
|
2018-07-18 08:13:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Determine new width/height, and accommodate for min/max values
|
|
|
|
double width = seat->op_ref_width + grow_width;
|
|
|
|
double height = seat->op_ref_height + grow_height;
|
|
|
|
int min_width, max_width, min_height, max_height;
|
|
|
|
calculate_floating_constraints(con, &min_width, &max_width,
|
|
|
|
&min_height, &max_height);
|
|
|
|
width = fmax(min_width, fmin(width, max_width));
|
|
|
|
height = fmax(min_height, fmin(height, max_height));
|
|
|
|
|
|
|
|
// Recalculate these, in case we hit a min/max limit
|
|
|
|
grow_width = width - seat->op_ref_width;
|
|
|
|
grow_height = height - seat->op_ref_height;
|
|
|
|
|
|
|
|
// Determine grow x/y values - these are relative to the container's x/y at
|
|
|
|
// the start of the resize operation.
|
|
|
|
double grow_x = 0, grow_y = 0;
|
2018-07-20 01:28:22 +02:00
|
|
|
if (edge & WLR_EDGE_LEFT) {
|
2018-07-18 08:13:28 +02:00
|
|
|
grow_x = -grow_width;
|
2018-07-20 01:28:22 +02:00
|
|
|
} else if (edge & WLR_EDGE_RIGHT) {
|
2018-07-18 08:13:28 +02:00
|
|
|
grow_x = 0;
|
|
|
|
} else {
|
|
|
|
grow_x = -grow_width / 2;
|
|
|
|
}
|
2018-07-20 01:28:22 +02:00
|
|
|
if (edge & WLR_EDGE_TOP) {
|
2018-07-18 08:13:28 +02:00
|
|
|
grow_y = -grow_height;
|
2018-07-20 01:28:22 +02:00
|
|
|
} else if (edge & WLR_EDGE_BOTTOM) {
|
2018-07-18 08:13:28 +02:00
|
|
|
grow_y = 0;
|
|
|
|
} else {
|
|
|
|
grow_y = -grow_height / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine the amounts we need to bump everything relative to the current
|
|
|
|
// size.
|
|
|
|
int relative_grow_width = width - con->width;
|
|
|
|
int relative_grow_height = height - con->height;
|
|
|
|
int relative_grow_x = (seat->op_ref_con_lx + grow_x) - con->x;
|
|
|
|
int relative_grow_y = (seat->op_ref_con_ly + grow_y) - con->y;
|
|
|
|
|
|
|
|
// Actually resize stuff
|
|
|
|
con->x += relative_grow_x;
|
|
|
|
con->y += relative_grow_y;
|
|
|
|
con->width += relative_grow_width;
|
|
|
|
con->height += relative_grow_height;
|
|
|
|
|
|
|
|
if (con->type == C_VIEW) {
|
|
|
|
struct sway_view *view = con->sway_view;
|
|
|
|
view->x += relative_grow_x;
|
|
|
|
view->y += relative_grow_y;
|
|
|
|
view->width += relative_grow_width;
|
|
|
|
view->height += relative_grow_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
arrange_windows(con);
|
|
|
|
transaction_commit_dirty();
|
|
|
|
}
|
|
|
|
|
2018-05-27 14:45:14 +02:00
|
|
|
void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
|
|
|
|
bool allow_refocusing) {
|
2018-04-21 15:07:22 +02:00
|
|
|
if (time_msec == 0) {
|
|
|
|
time_msec = get_current_time_msec();
|
|
|
|
}
|
|
|
|
|
2018-06-09 14:26:03 +02:00
|
|
|
struct sway_seat *seat = cursor->seat;
|
2018-07-18 08:13:28 +02:00
|
|
|
|
|
|
|
if (seat->operation != OP_NONE) {
|
2018-07-20 01:28:22 +02:00
|
|
|
if (seat->operation == OP_MOVE) {
|
|
|
|
handle_move_motion(seat, cursor);
|
2018-07-18 08:13:28 +02:00
|
|
|
} else {
|
|
|
|
handle_resize_motion(seat, cursor);
|
|
|
|
}
|
|
|
|
cursor->previous.x = cursor->cursor->x;
|
|
|
|
cursor->previous.y = cursor->cursor->y;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-09 14:26:03 +02:00
|
|
|
struct wlr_seat *wlr_seat = seat->wlr_seat;
|
2018-05-27 14:45:14 +02:00
|
|
|
struct wlr_surface *surface = NULL;
|
|
|
|
double sx, sy;
|
|
|
|
|
2018-05-27 18:35:24 +02:00
|
|
|
// Find the container beneath the pointer's previous position
|
2018-06-09 14:26:03 +02:00
|
|
|
struct sway_container *prev_c = container_at_coords(seat,
|
2018-05-27 18:14:19 +02:00
|
|
|
cursor->previous.x, cursor->previous.y, &surface, &sx, &sy);
|
2018-05-27 14:45:14 +02:00
|
|
|
// Update the stored previous position
|
2018-05-27 18:14:19 +02:00
|
|
|
cursor->previous.x = cursor->cursor->x;
|
|
|
|
cursor->previous.y = cursor->cursor->y;
|
2018-05-27 14:45:14 +02:00
|
|
|
|
2018-06-09 14:26:03 +02:00
|
|
|
struct sway_container *c = container_at_coords(seat,
|
2018-05-02 15:00:26 +02:00
|
|
|
cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy);
|
2018-05-21 05:12:33 +02:00
|
|
|
if (c && config->focus_follows_mouse && allow_refocusing) {
|
2018-06-09 14:26:03 +02:00
|
|
|
struct sway_container *focus = seat_get_focus(seat);
|
2018-05-21 23:21:01 +02:00
|
|
|
if (focus && c->type == C_WORKSPACE) {
|
2018-05-20 01:57:10 +02:00
|
|
|
// Only follow the mouse if it would move to a new output
|
|
|
|
// Otherwise we'll focus the workspace, which is probably wrong
|
|
|
|
if (focus->type != C_OUTPUT) {
|
|
|
|
focus = container_parent(focus, C_OUTPUT);
|
|
|
|
}
|
|
|
|
struct sway_container *output = c;
|
|
|
|
if (output->type != C_OUTPUT) {
|
|
|
|
output = container_parent(c, C_OUTPUT);
|
|
|
|
}
|
|
|
|
if (output != focus) {
|
2018-06-09 14:26:03 +02:00
|
|
|
seat_set_focus_warp(seat, c, false);
|
2018-05-20 01:57:10 +02:00
|
|
|
}
|
2018-05-26 16:35:15 +02:00
|
|
|
} else if (c->type == C_VIEW) {
|
2018-06-25 02:30:43 +02:00
|
|
|
// Focus c if the following are true:
|
2018-05-27 17:30:19 +02:00
|
|
|
// - cursor is over a new view, i.e. entered a new window; and
|
2018-06-25 02:30:43 +02:00
|
|
|
// - the new view is visible, i.e. not hidden in a stack or tab; and
|
|
|
|
// - the seat does not have a keyboard grab
|
|
|
|
if (!wlr_seat_keyboard_has_grab(cursor->seat->wlr_seat) &&
|
|
|
|
c != prev_c &&
|
|
|
|
view_is_visible(c->sway_view)) {
|
2018-06-09 14:26:03 +02:00
|
|
|
seat_set_focus_warp(seat, c, false);
|
2018-05-27 14:45:14 +02:00
|
|
|
} else {
|
|
|
|
struct sway_container *next_focus =
|
2018-06-09 14:26:03 +02:00
|
|
|
seat_get_focus_inactive(seat, &root_container);
|
2018-05-27 18:25:42 +02:00
|
|
|
if (next_focus && next_focus->type == C_VIEW &&
|
|
|
|
view_is_visible(next_focus->sway_view)) {
|
2018-06-09 14:26:03 +02:00
|
|
|
seat_set_focus_warp(seat, next_focus, false);
|
2018-05-27 14:45:14 +02:00
|
|
|
}
|
2018-05-24 20:02:38 +02:00
|
|
|
}
|
2018-05-20 01:57:10 +02:00
|
|
|
}
|
2018-03-31 16:11:15 +02:00
|
|
|
}
|
2018-03-30 16:53:18 +02:00
|
|
|
|
2018-07-18 08:13:28 +02:00
|
|
|
// Handle cursor image
|
|
|
|
if (surface) {
|
|
|
|
// Reset cursor if switching between clients
|
|
|
|
struct wl_client *client = wl_resource_get_client(surface->resource);
|
|
|
|
if (client != cursor->image_client) {
|
|
|
|
wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager,
|
|
|
|
"left_ptr", cursor->cursor);
|
|
|
|
cursor->image_client = client;
|
|
|
|
}
|
|
|
|
} else if (c && container_is_floating(c)) {
|
|
|
|
// Try a floating container's resize edge
|
2018-07-20 01:28:22 +02:00
|
|
|
enum wlr_edges edge = find_resize_edge(c, cursor);
|
|
|
|
const char *image = edge == WLR_EDGE_NONE ?
|
|
|
|
"left_ptr" : wlr_xcursor_get_resize_name(edge);
|
2018-07-19 13:29:21 +02:00
|
|
|
wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, image,
|
|
|
|
cursor->cursor);
|
2018-07-18 08:13:28 +02:00
|
|
|
cursor->image_client = NULL;
|
|
|
|
} else {
|
2018-03-30 16:53:18 +02:00
|
|
|
wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager,
|
2018-07-18 08:13:28 +02:00
|
|
|
"left_ptr", cursor->cursor);
|
|
|
|
cursor->image_client = NULL;
|
2018-03-30 16:53:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// send pointer enter/leave
|
2018-03-31 03:03:35 +02:00
|
|
|
if (surface != NULL) {
|
2018-06-09 14:26:03 +02:00
|
|
|
if (seat_is_input_allowed(seat, surface)) {
|
|
|
|
wlr_seat_pointer_notify_enter(wlr_seat, surface, sx, sy);
|
|
|
|
wlr_seat_pointer_notify_motion(wlr_seat, time_msec, sx, sy);
|
2018-04-03 23:03:29 +02:00
|
|
|
}
|
2017-12-10 14:48:44 +01:00
|
|
|
} else {
|
2018-06-09 14:26:03 +02:00
|
|
|
wlr_seat_pointer_clear_focus(wlr_seat);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_drag_icon *wlr_drag_icon;
|
|
|
|
wl_list_for_each(wlr_drag_icon, &wlr_seat->drag_icons, link) {
|
|
|
|
struct sway_drag_icon *drag_icon = wlr_drag_icon->data;
|
|
|
|
drag_icon_update_position(drag_icon);
|
2017-12-10 14:48:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-08 13:22:26 +01:00
|
|
|
static void handle_cursor_motion(struct wl_listener *listener, void *data) {
|
2018-03-30 21:33:16 +02:00
|
|
|
struct sway_cursor *cursor = wl_container_of(listener, cursor, motion);
|
2018-04-17 09:54:02 +02:00
|
|
|
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
2017-12-08 13:22:26 +01:00
|
|
|
struct wlr_event_pointer_motion *event = data;
|
2017-12-10 14:48:44 +01:00
|
|
|
wlr_cursor_move(cursor->cursor, event->device,
|
|
|
|
event->delta_x, event->delta_y);
|
2018-05-27 14:45:14 +02:00
|
|
|
cursor_send_pointer_motion(cursor, event->time_msec, true);
|
2018-07-19 11:49:50 +02:00
|
|
|
transaction_commit_dirty();
|
2017-12-08 13:22:26 +01:00
|
|
|
}
|
|
|
|
|
2018-03-31 16:49:52 +02:00
|
|
|
static void handle_cursor_motion_absolute(
|
|
|
|
struct wl_listener *listener, void *data) {
|
2017-12-08 13:22:26 +01:00
|
|
|
struct sway_cursor *cursor =
|
|
|
|
wl_container_of(listener, cursor, motion_absolute);
|
2018-04-17 09:54:02 +02:00
|
|
|
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
2017-12-08 13:22:26 +01:00
|
|
|
struct wlr_event_pointer_motion_absolute *event = data;
|
2018-03-28 18:22:45 +02:00
|
|
|
wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y);
|
2018-05-27 14:45:14 +02:00
|
|
|
cursor_send_pointer_motion(cursor, event->time_msec, true);
|
2018-07-19 11:49:50 +02:00
|
|
|
transaction_commit_dirty();
|
2017-12-08 13:22:26 +01:00
|
|
|
}
|
|
|
|
|
2018-07-18 08:13:28 +02:00
|
|
|
static void dispatch_cursor_button_floating(struct sway_cursor *cursor,
|
|
|
|
uint32_t time_msec, uint32_t button, enum wlr_button_state state,
|
|
|
|
struct wlr_surface *surface, double sx, double sy,
|
|
|
|
struct sway_container *cont) {
|
|
|
|
struct sway_seat *seat = cursor->seat;
|
|
|
|
|
2018-07-20 01:28:22 +02:00
|
|
|
// Deny moving or resizing a fullscreen view
|
2018-07-18 08:13:28 +02:00
|
|
|
if (cont->type == C_VIEW && cont->sway_view->is_fullscreen) {
|
|
|
|
wlr_seat_pointer_notify_button(seat->wlr_seat, time_msec, button, state);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat);
|
|
|
|
bool mod_pressed = keyboard &&
|
2018-07-19 13:31:10 +02:00
|
|
|
(wlr_keyboard_get_modifiers(keyboard) & config->floating_mod);
|
2018-07-20 01:28:22 +02:00
|
|
|
enum wlr_edges edge = find_resize_edge(cont, cursor);
|
|
|
|
bool over_title = edge == WLR_EDGE_NONE && !surface;
|
2018-07-18 08:13:28 +02:00
|
|
|
|
2018-07-20 01:28:22 +02:00
|
|
|
// Check for beginning move
|
2018-07-18 08:13:28 +02:00
|
|
|
if (button == BTN_LEFT && state == WLR_BUTTON_PRESSED &&
|
|
|
|
(mod_pressed || over_title)) {
|
2018-07-20 01:28:22 +02:00
|
|
|
seat_begin_move(seat, cont);
|
2018-07-18 08:13:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for beginning resize
|
2018-07-20 01:28:22 +02:00
|
|
|
bool resizing_via_border = button == BTN_LEFT && edge != WLR_EDGE_NONE;
|
2018-07-18 08:13:28 +02:00
|
|
|
bool resizing_via_mod = button == BTN_RIGHT && mod_pressed;
|
|
|
|
if ((resizing_via_border || resizing_via_mod) &&
|
|
|
|
state == WLR_BUTTON_PRESSED) {
|
2018-07-20 01:28:22 +02:00
|
|
|
seat_begin_resize(seat, cont, button, edge);
|
2018-07-18 08:13:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send event to surface
|
|
|
|
wlr_seat_pointer_notify_button(seat->wlr_seat, time_msec, button, state);
|
|
|
|
}
|
|
|
|
|
2018-04-10 17:32:37 +02:00
|
|
|
void dispatch_cursor_button(struct sway_cursor *cursor,
|
2018-04-08 16:48:13 +02:00
|
|
|
uint32_t time_msec, uint32_t button, enum wlr_button_state state) {
|
2018-07-18 08:13:28 +02:00
|
|
|
if (cursor->seat->operation != OP_NONE &&
|
|
|
|
button == cursor->seat->op_button && state == WLR_BUTTON_RELEASED) {
|
2018-07-21 02:40:12 +02:00
|
|
|
seat_end_mouse_operation(cursor->seat);
|
2018-07-18 08:13:28 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-04-21 15:07:22 +02:00
|
|
|
if (time_msec == 0) {
|
|
|
|
time_msec = get_current_time_msec();
|
|
|
|
}
|
|
|
|
|
2018-03-31 16:11:15 +02:00
|
|
|
struct wlr_surface *surface = NULL;
|
|
|
|
double sx, sy;
|
2018-05-02 15:00:26 +02:00
|
|
|
struct sway_container *cont = container_at_coords(cursor->seat,
|
|
|
|
cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy);
|
2018-04-03 03:17:16 +02:00
|
|
|
if (surface && wlr_surface_is_layer_surface(surface)) {
|
|
|
|
struct wlr_layer_surface *layer =
|
|
|
|
wlr_layer_surface_from_wlr_surface(surface);
|
|
|
|
if (layer->current.keyboard_interactive) {
|
|
|
|
seat_set_focus_layer(cursor->seat, layer);
|
|
|
|
}
|
2018-07-18 08:13:28 +02:00
|
|
|
wlr_seat_pointer_notify_button(cursor->seat->wlr_seat,
|
|
|
|
time_msec, button, state);
|
|
|
|
} else if (cont && container_is_floating(cont)) {
|
|
|
|
dispatch_cursor_button_floating(cursor, time_msec, button, state,
|
|
|
|
surface, sx, sy, cont);
|
2018-07-06 05:01:35 +02:00
|
|
|
} else if (surface && cont && cont->type != C_VIEW) {
|
|
|
|
// Avoid moving keyboard focus from a surface that accepts it to one
|
|
|
|
// that does not unless the change would move us to a new workspace.
|
|
|
|
//
|
|
|
|
// This prevents, for example, losing focus when clicking on swaybar.
|
2018-03-31 16:11:15 +02:00
|
|
|
struct sway_container *new_ws = cont;
|
|
|
|
if (new_ws && new_ws->type != C_WORKSPACE) {
|
|
|
|
new_ws = container_parent(new_ws, C_WORKSPACE);
|
|
|
|
}
|
2018-04-02 14:45:37 +02:00
|
|
|
struct sway_container *old_ws = seat_get_focus(cursor->seat);
|
2018-03-31 16:11:15 +02:00
|
|
|
if (old_ws && old_ws->type != C_WORKSPACE) {
|
|
|
|
old_ws = container_parent(old_ws, C_WORKSPACE);
|
|
|
|
}
|
|
|
|
if (new_ws != old_ws) {
|
2018-04-02 14:45:37 +02:00
|
|
|
seat_set_focus(cursor->seat, cont);
|
2018-03-31 15:45:11 +02:00
|
|
|
}
|
2018-07-18 08:13:28 +02:00
|
|
|
wlr_seat_pointer_notify_button(cursor->seat->wlr_seat,
|
|
|
|
time_msec, button, state);
|
2018-06-04 03:31:25 +02:00
|
|
|
} else if (cont) {
|
2018-04-02 14:45:37 +02:00
|
|
|
seat_set_focus(cursor->seat, cont);
|
2018-07-18 08:13:28 +02:00
|
|
|
wlr_seat_pointer_notify_button(cursor->seat->wlr_seat,
|
|
|
|
time_msec, button, state);
|
2018-07-19 07:20:43 +02:00
|
|
|
} else {
|
|
|
|
wlr_seat_pointer_notify_button(cursor->seat->wlr_seat,
|
|
|
|
time_msec, button, state);
|
2017-12-10 17:11:47 +01:00
|
|
|
}
|
|
|
|
|
2018-07-15 07:20:21 +02:00
|
|
|
transaction_commit_dirty();
|
2018-04-08 16:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_cursor_button(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_cursor *cursor = wl_container_of(listener, cursor, button);
|
2018-04-17 09:54:02 +02:00
|
|
|
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
2018-04-08 16:48:13 +02:00
|
|
|
struct wlr_event_pointer_button *event = data;
|
|
|
|
dispatch_cursor_button(cursor,
|
|
|
|
event->time_msec, event->button, event->state);
|
2017-12-08 13:22:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_cursor_axis(struct wl_listener *listener, void *data) {
|
2018-03-30 21:33:16 +02:00
|
|
|
struct sway_cursor *cursor = wl_container_of(listener, cursor, axis);
|
2018-04-17 09:54:02 +02:00
|
|
|
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
2017-12-08 13:22:26 +01:00
|
|
|
struct wlr_event_pointer_axis *event = data;
|
2017-12-14 17:11:56 +01:00
|
|
|
wlr_seat_pointer_notify_axis(cursor->seat->wlr_seat, event->time_msec,
|
2018-05-12 14:13:38 +02:00
|
|
|
event->orientation, event->delta, event->delta_discrete, event->source);
|
2017-12-08 13:22:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_touch_down(struct wl_listener *listener, void *data) {
|
2018-03-30 21:33:16 +02:00
|
|
|
struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_down);
|
2018-04-17 09:54:02 +02:00
|
|
|
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
2017-12-08 13:22:26 +01:00
|
|
|
struct wlr_event_touch_down *event = data;
|
2018-05-02 15:00:26 +02:00
|
|
|
|
2018-06-09 14:26:03 +02:00
|
|
|
struct sway_seat *seat = cursor->seat;
|
|
|
|
struct wlr_seat *wlr_seat = seat->wlr_seat;
|
2018-05-02 15:00:26 +02:00
|
|
|
struct wlr_surface *surface = NULL;
|
|
|
|
|
|
|
|
double lx, ly;
|
|
|
|
wlr_cursor_absolute_to_layout_coords(cursor->cursor, event->device,
|
|
|
|
event->x, event->y, &lx, &ly);
|
|
|
|
double sx, sy;
|
2018-06-09 14:26:03 +02:00
|
|
|
container_at_coords(seat, lx, ly, &surface, &sx, &sy);
|
|
|
|
|
|
|
|
seat->touch_id = event->touch_id;
|
|
|
|
seat->touch_x = lx;
|
|
|
|
seat->touch_y = ly;
|
2018-05-02 15:00:26 +02:00
|
|
|
|
|
|
|
if (!surface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: fall back to cursor simulation if client has not bound to touch
|
2018-06-09 14:26:03 +02:00
|
|
|
if (seat_is_input_allowed(seat, surface)) {
|
|
|
|
wlr_seat_touch_notify_down(wlr_seat, surface, event->time_msec,
|
2018-05-02 15:00:26 +02:00
|
|
|
event->touch_id, sx, sy);
|
2018-05-03 14:21:29 +02:00
|
|
|
cursor->image_client = NULL;
|
|
|
|
wlr_cursor_set_image(cursor->cursor, NULL, 0, 0, 0, 0, 0, 0);
|
2018-05-02 15:00:26 +02:00
|
|
|
}
|
2017-12-08 13:22:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_touch_up(struct wl_listener *listener, void *data) {
|
2018-03-30 21:33:16 +02:00
|
|
|
struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_up);
|
2018-04-17 09:54:02 +02:00
|
|
|
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
2017-12-08 13:22:26 +01:00
|
|
|
struct wlr_event_touch_up *event = data;
|
2018-05-02 15:00:26 +02:00
|
|
|
struct wlr_seat *seat = cursor->seat->wlr_seat;
|
|
|
|
// TODO: fall back to cursor simulation if client has not bound to touch
|
|
|
|
wlr_seat_touch_notify_up(seat, event->time_msec, event->touch_id);
|
2017-12-08 13:22:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_touch_motion(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_cursor *cursor =
|
|
|
|
wl_container_of(listener, cursor, touch_motion);
|
2018-04-17 09:54:02 +02:00
|
|
|
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
2017-12-08 13:22:26 +01:00
|
|
|
struct wlr_event_touch_motion *event = data;
|
2018-05-02 15:00:26 +02:00
|
|
|
|
2018-06-09 14:26:03 +02:00
|
|
|
struct sway_seat *seat = cursor->seat;
|
|
|
|
struct wlr_seat *wlr_seat = seat->wlr_seat;
|
2018-05-02 15:00:26 +02:00
|
|
|
struct wlr_surface *surface = NULL;
|
|
|
|
|
|
|
|
double lx, ly;
|
|
|
|
wlr_cursor_absolute_to_layout_coords(cursor->cursor, event->device,
|
|
|
|
event->x, event->y, &lx, &ly);
|
|
|
|
double sx, sy;
|
|
|
|
container_at_coords(cursor->seat, lx, ly, &surface, &sx, &sy);
|
|
|
|
|
2018-06-09 14:26:03 +02:00
|
|
|
if (seat->touch_id == event->touch_id) {
|
|
|
|
seat->touch_x = lx;
|
|
|
|
seat->touch_y = ly;
|
|
|
|
|
|
|
|
struct wlr_drag_icon *wlr_drag_icon;
|
|
|
|
wl_list_for_each(wlr_drag_icon, &wlr_seat->drag_icons, link) {
|
|
|
|
struct sway_drag_icon *drag_icon = wlr_drag_icon->data;
|
|
|
|
drag_icon_update_position(drag_icon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-02 15:00:26 +02:00
|
|
|
if (!surface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: fall back to cursor simulation if client has not bound to touch
|
|
|
|
if (seat_is_input_allowed(cursor->seat, surface)) {
|
2018-06-09 14:26:03 +02:00
|
|
|
wlr_seat_touch_notify_motion(wlr_seat, event->time_msec,
|
|
|
|
event->touch_id, sx, sy);
|
2018-05-02 15:00:26 +02:00
|
|
|
}
|
2017-12-08 13:22:26 +01:00
|
|
|
}
|
|
|
|
|
2018-04-24 20:39:29 +02:00
|
|
|
static double apply_mapping_from_coord(double low, double high, double value) {
|
2018-04-27 18:30:45 +02:00
|
|
|
if (isnan(value)) {
|
2018-04-24 20:39:29 +02:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2018-04-27 18:30:45 +02:00
|
|
|
return (value - low) / (high - low);
|
2018-04-24 20:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void apply_mapping_from_region(struct wlr_input_device *device,
|
|
|
|
struct input_config_mapped_from_region *region, double *x, double *y) {
|
|
|
|
double x1 = region->x1, x2 = region->x2;
|
|
|
|
double y1 = region->y1, y2 = region->y2;
|
|
|
|
|
|
|
|
if (region->mm) {
|
|
|
|
if (device->width_mm == 0 || device->height_mm == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
x1 /= device->width_mm;
|
|
|
|
x2 /= device->width_mm;
|
|
|
|
y1 /= device->height_mm;
|
|
|
|
y2 /= device->height_mm;
|
|
|
|
}
|
|
|
|
|
|
|
|
*x = apply_mapping_from_coord(x1, x2, *x);
|
|
|
|
*y = apply_mapping_from_coord(y1, y2, *y);
|
|
|
|
}
|
|
|
|
|
2017-12-08 13:22:26 +01:00
|
|
|
static void handle_tool_axis(struct wl_listener *listener, void *data) {
|
2018-03-30 21:33:16 +02:00
|
|
|
struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis);
|
2018-04-17 09:54:02 +02:00
|
|
|
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
2017-12-08 13:22:26 +01:00
|
|
|
struct wlr_event_tablet_tool_axis *event = data;
|
2018-04-24 20:39:29 +02:00
|
|
|
struct sway_input_device *input_device = event->device->data;
|
2018-04-08 16:48:13 +02:00
|
|
|
|
2018-04-27 18:30:45 +02:00
|
|
|
double x = NAN, y = NAN;
|
2018-04-24 20:39:29 +02:00
|
|
|
if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) {
|
|
|
|
x = event->x;
|
|
|
|
}
|
|
|
|
if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
|
|
|
|
y = event->y;
|
2018-04-08 16:48:13 +02:00
|
|
|
}
|
2018-04-24 20:39:29 +02:00
|
|
|
|
|
|
|
struct input_config *ic = input_device_get_config(input_device);
|
|
|
|
if (ic != NULL && ic->mapped_from_region != NULL) {
|
|
|
|
apply_mapping_from_region(event->device, ic->mapped_from_region, &x, &y);
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_cursor_warp_absolute(cursor->cursor, event->device, x, y);
|
2018-05-27 14:45:14 +02:00
|
|
|
cursor_send_pointer_motion(cursor, event->time_msec, true);
|
2018-07-19 11:49:50 +02:00
|
|
|
transaction_commit_dirty();
|
2017-12-08 13:22:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_tool_tip(struct wl_listener *listener, void *data) {
|
2018-03-30 21:33:16 +02:00
|
|
|
struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_tip);
|
2018-04-17 09:54:02 +02:00
|
|
|
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
2017-12-08 13:22:26 +01:00
|
|
|
struct wlr_event_tablet_tool_tip *event = data;
|
2018-04-08 16:48:13 +02:00
|
|
|
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);
|
2018-04-17 09:54:02 +02:00
|
|
|
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
2018-04-08 16:48:13 +02:00
|
|
|
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;
|
|
|
|
}
|
2017-12-08 13:22:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_request_set_cursor(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
struct sway_cursor *cursor =
|
|
|
|
wl_container_of(listener, cursor, request_set_cursor);
|
|
|
|
struct wlr_seat_pointer_request_set_cursor_event *event = data;
|
2018-03-30 16:53:18 +02:00
|
|
|
|
|
|
|
struct wl_client *focused_client = NULL;
|
|
|
|
struct wlr_surface *focused_surface =
|
|
|
|
cursor->seat->wlr_seat->pointer_state.focused_surface;
|
|
|
|
if (focused_surface != NULL) {
|
|
|
|
focused_client = wl_resource_get_client(focused_surface->resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: check cursor mode
|
|
|
|
if (focused_client == NULL ||
|
|
|
|
event->seat_client->client != focused_client) {
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_DEBUG, "denying request to set cursor from unfocused client");
|
2018-03-30 16:53:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_cursor_set_surface(cursor->cursor, event->surface, event->hotspot_x,
|
|
|
|
event->hotspot_y);
|
|
|
|
cursor->image_client = focused_client;
|
2017-12-08 13:22:26 +01:00
|
|
|
}
|
|
|
|
|
2018-01-16 21:16:04 +01:00
|
|
|
void sway_cursor_destroy(struct sway_cursor *cursor) {
|
|
|
|
if (!cursor) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_xcursor_manager_destroy(cursor->xcursor_manager);
|
|
|
|
wlr_cursor_destroy(cursor->cursor);
|
|
|
|
free(cursor);
|
|
|
|
}
|
|
|
|
|
2017-12-08 13:22:26 +01:00
|
|
|
struct sway_cursor *sway_cursor_create(struct sway_seat *seat) {
|
|
|
|
struct sway_cursor *cursor = calloc(1, sizeof(struct sway_cursor));
|
|
|
|
if (!sway_assert(cursor, "could not allocate sway cursor")) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_cursor *wlr_cursor = wlr_cursor_create();
|
|
|
|
if (!sway_assert(wlr_cursor, "could not allocate wlr cursor")) {
|
|
|
|
free(cursor);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-06-06 12:45:02 +02:00
|
|
|
cursor->previous.x = wlr_cursor->x;
|
|
|
|
cursor->previous.y = wlr_cursor->y;
|
|
|
|
|
2017-12-10 14:48:44 +01:00
|
|
|
cursor->seat = seat;
|
2017-12-16 13:33:23 +01:00
|
|
|
wlr_cursor_attach_output_layout(wlr_cursor,
|
|
|
|
root_container.sway_root->output_layout);
|
2017-12-09 20:06:00 +01:00
|
|
|
|
2017-12-08 13:22:26 +01:00
|
|
|
// input events
|
|
|
|
wl_signal_add(&wlr_cursor->events.motion, &cursor->motion);
|
|
|
|
cursor->motion.notify = handle_cursor_motion;
|
|
|
|
|
|
|
|
wl_signal_add(&wlr_cursor->events.motion_absolute,
|
|
|
|
&cursor->motion_absolute);
|
|
|
|
cursor->motion_absolute.notify = handle_cursor_motion_absolute;
|
|
|
|
|
|
|
|
wl_signal_add(&wlr_cursor->events.button, &cursor->button);
|
|
|
|
cursor->button.notify = handle_cursor_button;
|
|
|
|
|
|
|
|
wl_signal_add(&wlr_cursor->events.axis, &cursor->axis);
|
|
|
|
cursor->axis.notify = handle_cursor_axis;
|
|
|
|
|
|
|
|
wl_signal_add(&wlr_cursor->events.touch_down, &cursor->touch_down);
|
|
|
|
cursor->touch_down.notify = handle_touch_down;
|
|
|
|
|
|
|
|
wl_signal_add(&wlr_cursor->events.touch_up, &cursor->touch_up);
|
|
|
|
cursor->touch_up.notify = handle_touch_up;
|
|
|
|
|
|
|
|
wl_signal_add(&wlr_cursor->events.touch_motion,
|
|
|
|
&cursor->touch_motion);
|
|
|
|
cursor->touch_motion.notify = handle_touch_motion;
|
|
|
|
|
2018-04-08 16:48:13 +02:00
|
|
|
// TODO: tablet protocol support
|
|
|
|
// Note: We should emulate pointer events for clients that don't support the
|
|
|
|
// tablet protocol when the time comes
|
2017-12-08 13:22:26 +01:00
|
|
|
wl_signal_add(&wlr_cursor->events.tablet_tool_axis,
|
|
|
|
&cursor->tool_axis);
|
|
|
|
cursor->tool_axis.notify = handle_tool_axis;
|
|
|
|
|
|
|
|
wl_signal_add(&wlr_cursor->events.tablet_tool_tip, &cursor->tool_tip);
|
|
|
|
cursor->tool_tip.notify = handle_tool_tip;
|
|
|
|
|
2018-04-08 16:48:13 +02:00
|
|
|
wl_signal_add(&wlr_cursor->events.tablet_tool_button, &cursor->tool_button);
|
|
|
|
cursor->tool_button.notify = handle_tool_button;
|
|
|
|
|
2017-12-14 17:11:56 +01:00
|
|
|
wl_signal_add(&seat->wlr_seat->events.request_set_cursor,
|
2017-12-08 13:22:26 +01:00
|
|
|
&cursor->request_set_cursor);
|
|
|
|
cursor->request_set_cursor.notify = handle_request_set_cursor;
|
|
|
|
|
|
|
|
cursor->cursor = wlr_cursor;
|
|
|
|
|
|
|
|
return cursor;
|
|
|
|
}
|