2017-12-07 15:58:32 +01:00
|
|
|
#define _XOPEN_SOURCE 700
|
2018-04-03 23:03:29 +02:00
|
|
|
#define _POSIX_C_SOURCE 199309L
|
2018-03-31 06:44:17 +02:00
|
|
|
#include <assert.h>
|
2018-07-20 01:28:22 +02:00
|
|
|
#ifdef __linux__
|
|
|
|
#include <linux/input-event-codes.h>
|
|
|
|
#elif __FreeBSD__
|
|
|
|
#include <dev/evdev/input-event-codes.h>
|
|
|
|
#endif
|
2018-04-08 20:15:13 +02:00
|
|
|
#include <strings.h>
|
2018-04-03 23:03:29 +02:00
|
|
|
#include <time.h>
|
2017-12-08 13:22:26 +01:00
|
|
|
#include <wlr/types/wlr_cursor.h>
|
2018-03-31 21:13:27 +02:00
|
|
|
#include <wlr/types/wlr_output_layout.h>
|
2017-12-09 17:51:28 +01:00
|
|
|
#include <wlr/types/wlr_xcursor_manager.h>
|
2018-06-09 14:26:03 +02:00
|
|
|
#include "log.h"
|
2018-04-06 17:49:27 +02:00
|
|
|
#include "sway/debug.h"
|
2018-06-09 14:26:03 +02:00
|
|
|
#include "sway/desktop.h"
|
2017-12-08 14:07:47 +01:00
|
|
|
#include "sway/input/cursor.h"
|
|
|
|
#include "sway/input/input-manager.h"
|
2017-12-10 19:59:04 +01:00
|
|
|
#include "sway/input/keyboard.h"
|
2018-06-09 14:26:03 +02:00
|
|
|
#include "sway/input/seat.h"
|
2018-03-29 22:51:36 +02:00
|
|
|
#include "sway/ipc-server.h"
|
2018-04-03 23:03:29 +02:00
|
|
|
#include "sway/layers.h"
|
2017-12-09 17:51:28 +01:00
|
|
|
#include "sway/output.h"
|
2018-04-28 03:26:14 +02:00
|
|
|
#include "sway/tree/arrange.h"
|
2018-03-30 16:31:21 +02:00
|
|
|
#include "sway/tree/container.h"
|
2018-06-09 14:26:03 +02:00
|
|
|
#include "sway/tree/container.h"
|
2018-03-30 05:41:33 +02:00
|
|
|
#include "sway/tree/view.h"
|
2018-04-17 01:31:34 +02:00
|
|
|
#include "sway/tree/workspace.h"
|
2018-06-09 14:26:03 +02:00
|
|
|
#include "sway/tree/workspace.h"
|
2017-12-07 15:58:32 +01:00
|
|
|
|
2017-12-14 17:11:56 +01:00
|
|
|
static void seat_device_destroy(struct sway_seat_device *seat_device) {
|
|
|
|
if (!seat_device) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sway_keyboard_destroy(seat_device->keyboard);
|
|
|
|
wlr_cursor_detach_input_device(seat_device->sway_seat->cursor->cursor,
|
|
|
|
seat_device->input_device->wlr_device);
|
|
|
|
wl_list_remove(&seat_device->link);
|
|
|
|
free(seat_device);
|
|
|
|
}
|
|
|
|
|
2018-04-02 14:45:37 +02:00
|
|
|
void seat_destroy(struct sway_seat *seat) {
|
2018-01-16 21:16:04 +01:00
|
|
|
struct sway_seat_device *seat_device, *next;
|
|
|
|
wl_list_for_each_safe(seat_device, next, &seat->devices, link) {
|
|
|
|
seat_device_destroy(seat_device);
|
|
|
|
}
|
|
|
|
sway_cursor_destroy(seat->cursor);
|
2018-06-09 14:26:03 +02:00
|
|
|
wl_list_remove(&seat->new_container.link);
|
|
|
|
wl_list_remove(&seat->new_drag_icon.link);
|
2018-01-16 21:16:04 +01:00
|
|
|
wl_list_remove(&seat->link);
|
|
|
|
wlr_seat_destroy(seat->wlr_seat);
|
|
|
|
}
|
|
|
|
|
2018-03-31 21:22:10 +02:00
|
|
|
static struct sway_seat_container *seat_container_from_container(
|
|
|
|
struct sway_seat *seat, struct sway_container *con);
|
|
|
|
|
|
|
|
static void seat_container_destroy(struct sway_seat_container *seat_con) {
|
|
|
|
struct sway_container *con = seat_con->container;
|
|
|
|
struct sway_container *child = NULL;
|
|
|
|
|
|
|
|
if (con->children != NULL) {
|
|
|
|
for (int i = 0; i < con->children->length; ++i) {
|
|
|
|
child = con->children->items[i];
|
|
|
|
struct sway_seat_container *seat_child =
|
|
|
|
seat_container_from_container(seat_con->seat, child);
|
|
|
|
seat_container_destroy(seat_child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_list_remove(&seat_con->destroy.link);
|
|
|
|
wl_list_remove(&seat_con->link);
|
|
|
|
free(seat_con);
|
|
|
|
}
|
|
|
|
|
2018-05-11 01:13:40 +02:00
|
|
|
/**
|
|
|
|
* Activate all views within this container recursively.
|
|
|
|
*/
|
|
|
|
static void seat_send_activate(struct sway_container *con,
|
|
|
|
struct sway_seat *seat) {
|
|
|
|
if (con->type == C_VIEW) {
|
|
|
|
if (!seat_is_input_allowed(seat, con->sway_view->surface)) {
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_DEBUG, "Refusing to set focus, input is inhibited");
|
2018-05-11 01:13:40 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
view_set_activated(con->sway_view, true);
|
2018-03-31 23:07:37 +02:00
|
|
|
} else {
|
2018-05-11 01:13:40 +02:00
|
|
|
for (int i = 0; i < con->children->length; ++i) {
|
|
|
|
struct sway_container *child = con->children->items[i];
|
|
|
|
seat_send_activate(child, seat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If con is a view, set it as active and enable keyboard input.
|
|
|
|
* If con is a container, set all child views as active and don't enable
|
|
|
|
* keyboard input on any.
|
|
|
|
*/
|
|
|
|
static void seat_send_focus(struct sway_container *con,
|
|
|
|
struct sway_seat *seat) {
|
|
|
|
seat_send_activate(con, seat);
|
|
|
|
|
|
|
|
if (con->type == C_VIEW
|
|
|
|
&& seat_is_input_allowed(seat, con->sway_view->surface)) {
|
|
|
|
if (con->sway_view->type == SWAY_VIEW_XWAYLAND) {
|
2018-06-18 23:49:28 +02:00
|
|
|
struct wlr_xwayland *xwayland =
|
|
|
|
seat->input->server->xwayland.wlr_xwayland;
|
2018-05-11 01:13:40 +02:00
|
|
|
wlr_xwayland_set_seat(xwayland, seat->wlr_seat);
|
|
|
|
}
|
|
|
|
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat);
|
|
|
|
if (keyboard) {
|
|
|
|
wlr_seat_keyboard_notify_enter(seat->wlr_seat,
|
|
|
|
con->sway_view->surface, keyboard->keycodes,
|
|
|
|
keyboard->num_keycodes, &keyboard->modifiers);
|
|
|
|
} else {
|
|
|
|
wlr_seat_keyboard_notify_enter(
|
|
|
|
seat->wlr_seat, con->sway_view->surface, NULL, 0, NULL);
|
|
|
|
}
|
2018-03-31 23:07:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-07 22:06:36 +02:00
|
|
|
static struct sway_container *seat_get_focus_by_type(struct sway_seat *seat,
|
|
|
|
struct sway_container *container, enum sway_container_type type) {
|
2018-05-24 14:30:44 +02:00
|
|
|
if (container->type == C_VIEW) {
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sway_container *floating = container->type == C_WORKSPACE ?
|
|
|
|
container->sway_workspace->floating : NULL;
|
|
|
|
if (container->children->length == 0 &&
|
|
|
|
(!floating || floating->children->length == 0)) {
|
2018-04-07 22:06:36 +02:00
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sway_seat_container *current = NULL;
|
|
|
|
wl_list_for_each(current, &seat->focus_stack, link) {
|
|
|
|
if (current->container->type != type && type != C_TYPES) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (container_has_child(container, current->container)) {
|
|
|
|
return current->container;
|
|
|
|
}
|
2018-05-24 14:30:44 +02:00
|
|
|
if (floating && container_has_child(floating, current->container)) {
|
|
|
|
return current->container;
|
|
|
|
}
|
2018-04-07 22:06:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-04-07 22:14:12 +02:00
|
|
|
void seat_focus_inactive_children_for_each(struct sway_seat *seat,
|
|
|
|
struct sway_container *container,
|
|
|
|
void (*f)(struct sway_container *container, void *data), void *data) {
|
|
|
|
struct sway_seat_container *current = NULL;
|
|
|
|
wl_list_for_each(current, &seat->focus_stack, link) {
|
|
|
|
if (current->container->parent == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (current->container->parent == container) {
|
|
|
|
f(current->container, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-07 22:06:36 +02:00
|
|
|
struct sway_container *seat_get_focus_inactive_view(struct sway_seat *seat,
|
|
|
|
struct sway_container *container) {
|
|
|
|
return seat_get_focus_by_type(seat, container, C_VIEW);
|
|
|
|
}
|
|
|
|
|
2018-02-04 19:39:10 +01:00
|
|
|
static void handle_seat_container_destroy(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
struct sway_seat_container *seat_con =
|
|
|
|
wl_container_of(listener, seat_con, destroy);
|
2018-02-11 00:10:29 +01:00
|
|
|
struct sway_seat *seat = seat_con->seat;
|
2018-03-30 05:41:33 +02:00
|
|
|
struct sway_container *con = seat_con->container;
|
2018-03-31 21:22:10 +02:00
|
|
|
struct sway_container *parent = con->parent;
|
2018-04-02 22:09:27 +02:00
|
|
|
struct sway_container *focus = seat_get_focus(seat);
|
2018-02-11 00:10:29 +01:00
|
|
|
|
2018-03-31 21:22:10 +02:00
|
|
|
bool set_focus =
|
2018-04-01 00:52:02 +02:00
|
|
|
focus != NULL &&
|
2018-03-31 21:22:10 +02:00
|
|
|
(focus == con || container_has_child(con, focus)) &&
|
|
|
|
con->type != C_WORKSPACE;
|
2018-02-11 00:10:29 +01:00
|
|
|
|
2018-03-31 21:22:10 +02:00
|
|
|
seat_container_destroy(seat_con);
|
2018-02-11 00:10:29 +01:00
|
|
|
|
2018-03-31 23:07:37 +02:00
|
|
|
if (set_focus) {
|
2018-03-31 21:22:10 +02:00
|
|
|
struct sway_container *next_focus = NULL;
|
|
|
|
while (next_focus == NULL) {
|
2018-04-02 22:09:27 +02:00
|
|
|
next_focus = seat_get_focus_by_type(seat, parent, C_VIEW);
|
2018-02-11 00:10:29 +01:00
|
|
|
|
2018-03-31 21:22:10 +02:00
|
|
|
if (next_focus == NULL && parent->type == C_WORKSPACE) {
|
|
|
|
next_focus = parent;
|
|
|
|
break;
|
|
|
|
}
|
2018-04-01 00:52:02 +02:00
|
|
|
|
|
|
|
parent = parent->parent;
|
2018-03-31 21:22:10 +02:00
|
|
|
}
|
2018-02-11 00:10:29 +01:00
|
|
|
|
2018-03-31 23:07:37 +02:00
|
|
|
// the structure change might have caused it to move up to the top of
|
|
|
|
// the focus stack without sending focus notifications to the view
|
2018-04-02 22:09:27 +02:00
|
|
|
if (seat_get_focus(seat) == next_focus) {
|
2018-05-11 01:13:40 +02:00
|
|
|
seat_send_focus(next_focus, seat);
|
2018-03-31 23:07:37 +02:00
|
|
|
} else {
|
2018-04-02 22:09:27 +02:00
|
|
|
seat_set_focus(seat, next_focus);
|
2018-03-31 23:07:37 +02:00
|
|
|
}
|
2018-03-31 21:22:10 +02:00
|
|
|
}
|
2018-02-04 19:39:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct sway_seat_container *seat_container_from_container(
|
2018-03-30 05:41:33 +02:00
|
|
|
struct sway_seat *seat, struct sway_container *con) {
|
2018-04-05 04:31:10 +02:00
|
|
|
if (con->type == C_ROOT || con->type == C_OUTPUT) {
|
2018-02-11 00:10:29 +01:00
|
|
|
// these don't get seat containers ever
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-02-04 19:39:10 +01:00
|
|
|
struct sway_seat_container *seat_con = NULL;
|
|
|
|
wl_list_for_each(seat_con, &seat->focus_stack, link) {
|
|
|
|
if (seat_con->container == con) {
|
|
|
|
return seat_con;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
seat_con = calloc(1, sizeof(struct sway_seat_container));
|
|
|
|
if (seat_con == NULL) {
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_ERROR, "could not allocate seat container");
|
2018-02-04 19:39:10 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
seat_con->container = con;
|
2018-02-11 00:10:29 +01:00
|
|
|
seat_con->seat = seat;
|
2018-02-04 19:39:10 +01:00
|
|
|
wl_list_insert(seat->focus_stack.prev, &seat_con->link);
|
|
|
|
wl_signal_add(&con->events.destroy, &seat_con->destroy);
|
|
|
|
seat_con->destroy.notify = handle_seat_container_destroy;
|
|
|
|
|
|
|
|
return seat_con;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_new_container(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_seat *seat = wl_container_of(listener, seat, new_container);
|
2018-03-30 05:41:33 +02:00
|
|
|
struct sway_container *con = data;
|
2018-02-04 19:39:10 +01:00
|
|
|
seat_container_from_container(seat, con);
|
|
|
|
}
|
|
|
|
|
2018-06-09 14:26:03 +02:00
|
|
|
static void drag_icon_damage_whole(struct sway_drag_icon *icon) {
|
|
|
|
if (!icon->wlr_drag_icon->mapped) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
desktop_damage_surface(icon->wlr_drag_icon->surface, icon->x, icon->y, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void drag_icon_update_position(struct sway_drag_icon *icon) {
|
|
|
|
drag_icon_damage_whole(icon);
|
|
|
|
|
|
|
|
struct wlr_drag_icon *wlr_icon = icon->wlr_drag_icon;
|
|
|
|
struct sway_seat *seat = icon->seat;
|
|
|
|
struct wlr_cursor *cursor = seat->cursor->cursor;
|
|
|
|
if (wlr_icon->is_pointer) {
|
|
|
|
icon->x = cursor->x + wlr_icon->sx;
|
|
|
|
icon->y = cursor->y + wlr_icon->sy;
|
|
|
|
} else {
|
|
|
|
struct wlr_touch_point *point =
|
|
|
|
wlr_seat_touch_get_point(seat->wlr_seat, wlr_icon->touch_id);
|
|
|
|
if (point == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
icon->x = seat->touch_x + wlr_icon->sx;
|
|
|
|
icon->y = seat->touch_y + wlr_icon->sy;
|
|
|
|
}
|
|
|
|
|
|
|
|
drag_icon_damage_whole(icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void drag_icon_handle_surface_commit(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
struct sway_drag_icon *icon =
|
|
|
|
wl_container_of(listener, icon, surface_commit);
|
|
|
|
drag_icon_update_position(icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void drag_icon_handle_map(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_drag_icon *icon = wl_container_of(listener, icon, map);
|
|
|
|
drag_icon_damage_whole(icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void drag_icon_handle_unmap(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_drag_icon *icon = wl_container_of(listener, icon, unmap);
|
|
|
|
drag_icon_damage_whole(icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void drag_icon_handle_destroy(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
struct sway_drag_icon *icon = wl_container_of(listener, icon, destroy);
|
|
|
|
icon->wlr_drag_icon->data = NULL;
|
|
|
|
wl_list_remove(&icon->link);
|
|
|
|
wl_list_remove(&icon->surface_commit.link);
|
|
|
|
wl_list_remove(&icon->unmap.link);
|
|
|
|
wl_list_remove(&icon->destroy.link);
|
|
|
|
free(icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_new_drag_icon(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_seat *seat = wl_container_of(listener, seat, new_drag_icon);
|
|
|
|
struct wlr_drag_icon *wlr_drag_icon = data;
|
|
|
|
|
|
|
|
struct sway_drag_icon *icon = calloc(1, sizeof(struct sway_drag_icon));
|
|
|
|
if (icon == NULL) {
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_ERROR, "Allocation failed");
|
2018-06-09 14:26:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
icon->seat = seat;
|
|
|
|
icon->wlr_drag_icon = wlr_drag_icon;
|
|
|
|
wlr_drag_icon->data = icon;
|
|
|
|
|
|
|
|
icon->surface_commit.notify = drag_icon_handle_surface_commit;
|
|
|
|
wl_signal_add(&wlr_drag_icon->surface->events.commit, &icon->surface_commit);
|
|
|
|
icon->unmap.notify = drag_icon_handle_unmap;
|
|
|
|
wl_signal_add(&wlr_drag_icon->events.unmap, &icon->unmap);
|
|
|
|
icon->map.notify = drag_icon_handle_map;
|
|
|
|
wl_signal_add(&wlr_drag_icon->events.map, &icon->map);
|
|
|
|
icon->destroy.notify = drag_icon_handle_destroy;
|
|
|
|
wl_signal_add(&wlr_drag_icon->events.destroy, &icon->destroy);
|
|
|
|
|
|
|
|
wl_list_insert(&root_container.sway_root->drag_icons, &icon->link);
|
|
|
|
|
|
|
|
drag_icon_update_position(icon);
|
|
|
|
}
|
|
|
|
|
2018-03-30 05:41:33 +02:00
|
|
|
static void collect_focus_iter(struct sway_container *con, void *data) {
|
2018-02-10 22:52:45 +01:00
|
|
|
struct sway_seat *seat = data;
|
|
|
|
if (con->type > C_WORKSPACE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
struct sway_seat_container *seat_con =
|
|
|
|
seat_container_from_container(seat, con);
|
|
|
|
if (!seat_con) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wl_list_remove(&seat_con->link);
|
|
|
|
wl_list_insert(&seat->focus_stack, &seat_con->link);
|
|
|
|
}
|
|
|
|
|
2018-04-02 14:45:37 +02:00
|
|
|
struct sway_seat *seat_create(struct sway_input_manager *input,
|
2017-12-07 15:58:32 +01:00
|
|
|
const char *seat_name) {
|
|
|
|
struct sway_seat *seat = calloc(1, sizeof(struct sway_seat));
|
|
|
|
if (!seat) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-12-08 13:22:26 +01:00
|
|
|
|
2017-12-14 17:11:56 +01:00
|
|
|
seat->wlr_seat = wlr_seat_create(input->server->wl_display, seat_name);
|
|
|
|
if (!sway_assert(seat->wlr_seat, "could not allocate seat")) {
|
2017-12-20 12:12:08 +01:00
|
|
|
free(seat);
|
2017-12-08 13:22:26 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2018-07-20 01:28:22 +02:00
|
|
|
seat->wlr_seat->data = seat;
|
2017-12-08 13:22:26 +01:00
|
|
|
|
|
|
|
seat->cursor = sway_cursor_create(seat);
|
|
|
|
if (!seat->cursor) {
|
2017-12-14 17:11:56 +01:00
|
|
|
wlr_seat_destroy(seat->wlr_seat);
|
2017-12-08 13:22:26 +01:00
|
|
|
free(seat);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-02-04 19:39:10 +01:00
|
|
|
// init the focus stack
|
|
|
|
wl_list_init(&seat->focus_stack);
|
2018-02-10 22:52:45 +01:00
|
|
|
|
2018-04-02 17:44:42 +02:00
|
|
|
container_for_each_descendant_dfs(&root_container,
|
|
|
|
collect_focus_iter, seat);
|
2018-02-04 19:39:10 +01:00
|
|
|
|
|
|
|
wl_signal_add(&root_container.sway_root->events.new_container,
|
|
|
|
&seat->new_container);
|
|
|
|
seat->new_container.notify = handle_new_container;
|
|
|
|
|
2018-06-09 14:26:03 +02:00
|
|
|
wl_signal_add(&seat->wlr_seat->events.new_drag_icon, &seat->new_drag_icon);
|
|
|
|
seat->new_drag_icon.notify = handle_new_drag_icon;
|
|
|
|
|
2017-12-10 17:11:47 +01:00
|
|
|
seat->input = input;
|
2017-12-14 17:11:56 +01:00
|
|
|
wl_list_init(&seat->devices);
|
2017-12-10 17:11:47 +01:00
|
|
|
|
2017-12-14 17:11:56 +01:00
|
|
|
wlr_seat_set_capabilities(seat->wlr_seat,
|
2017-12-08 13:22:26 +01:00
|
|
|
WL_SEAT_CAPABILITY_KEYBOARD |
|
|
|
|
WL_SEAT_CAPABILITY_POINTER |
|
|
|
|
WL_SEAT_CAPABILITY_TOUCH);
|
|
|
|
|
2018-04-02 14:45:37 +02:00
|
|
|
seat_configure_xcursor(seat);
|
2017-12-09 17:51:28 +01:00
|
|
|
|
2017-12-12 14:29:37 +01:00
|
|
|
wl_list_insert(&input->seats, &seat->link);
|
2017-12-10 19:59:04 +01:00
|
|
|
|
2017-12-07 15:58:32 +01:00
|
|
|
return seat;
|
|
|
|
}
|
|
|
|
|
2018-04-08 20:15:13 +02:00
|
|
|
static void seat_apply_input_config(struct sway_seat *seat,
|
|
|
|
struct sway_seat_device *sway_device) {
|
2018-05-03 15:16:17 +02:00
|
|
|
const char *mapped_to_output = NULL;
|
|
|
|
|
2018-04-08 20:15:13 +02:00
|
|
|
struct input_config *ic = input_device_get_config(
|
|
|
|
sway_device->input_device);
|
2018-05-03 15:16:17 +02:00
|
|
|
if (ic != NULL) {
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_DEBUG, "Applying input config to %s",
|
2018-04-08 20:15:13 +02:00
|
|
|
sway_device->input_device->identifier);
|
2018-05-03 15:16:17 +02:00
|
|
|
|
|
|
|
mapped_to_output = ic->mapped_to_output;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mapped_to_output == NULL) {
|
|
|
|
mapped_to_output = sway_device->input_device->wlr_device->output_name;
|
|
|
|
}
|
|
|
|
if (mapped_to_output != NULL) {
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_DEBUG, "Mapping input device %s to output %s",
|
2018-05-03 15:16:17 +02:00
|
|
|
sway_device->input_device->identifier, mapped_to_output);
|
2018-04-08 20:15:13 +02:00
|
|
|
struct sway_container *output = NULL;
|
|
|
|
for (int i = 0; i < root_container.children->length; ++i) {
|
|
|
|
struct sway_container *_output = root_container.children->items[i];
|
2018-05-03 15:16:17 +02:00
|
|
|
if (strcasecmp(_output->name, mapped_to_output) == 0) {
|
2018-04-08 20:15:13 +02:00
|
|
|
output = _output;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (output) {
|
|
|
|
wlr_cursor_map_input_to_output(seat->cursor->cursor,
|
|
|
|
sway_device->input_device->wlr_device,
|
|
|
|
output->sway_output->wlr_output);
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_DEBUG, "Mapped to output %s", output->name);
|
2018-04-08 20:15:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 17:11:56 +01:00
|
|
|
static void seat_configure_pointer(struct sway_seat *seat,
|
|
|
|
struct sway_seat_device *sway_device) {
|
2017-12-12 14:29:37 +01:00
|
|
|
wlr_cursor_attach_input_device(seat->cursor->cursor,
|
2017-12-14 17:11:56 +01:00
|
|
|
sway_device->input_device->wlr_device);
|
2018-04-08 20:15:13 +02:00
|
|
|
seat_apply_input_config(seat, sway_device);
|
2017-12-08 13:22:26 +01:00
|
|
|
}
|
|
|
|
|
2017-12-14 17:11:56 +01:00
|
|
|
static void seat_configure_keyboard(struct sway_seat *seat,
|
|
|
|
struct sway_seat_device *seat_device) {
|
|
|
|
if (!seat_device->keyboard) {
|
|
|
|
sway_keyboard_create(seat, seat_device);
|
|
|
|
}
|
2018-04-02 17:44:42 +02:00
|
|
|
struct wlr_keyboard *wlr_keyboard =
|
|
|
|
seat_device->input_device->wlr_device->keyboard;
|
2017-12-14 17:11:56 +01:00
|
|
|
sway_keyboard_configure(seat_device->keyboard);
|
2017-12-17 14:30:20 +01:00
|
|
|
wlr_seat_set_keyboard(seat->wlr_seat,
|
2018-02-08 00:17:57 +01:00
|
|
|
seat_device->input_device->wlr_device);
|
2018-04-02 14:45:37 +02:00
|
|
|
struct sway_container *focus = seat_get_focus(seat);
|
2018-02-08 00:17:57 +01:00
|
|
|
if (focus && focus->type == C_VIEW) {
|
|
|
|
// force notify reenter to pick up the new configuration
|
|
|
|
wlr_seat_keyboard_clear_focus(seat->wlr_seat);
|
|
|
|
wlr_seat_keyboard_notify_enter(seat->wlr_seat,
|
|
|
|
focus->sway_view->surface, wlr_keyboard->keycodes,
|
|
|
|
wlr_keyboard->num_keycodes, &wlr_keyboard->modifiers);
|
2017-12-17 14:30:20 +01:00
|
|
|
}
|
2017-12-12 14:29:37 +01:00
|
|
|
}
|
|
|
|
|
2018-05-02 15:00:26 +02:00
|
|
|
static void seat_configure_touch(struct sway_seat *seat,
|
|
|
|
struct sway_seat_device *sway_device) {
|
|
|
|
wlr_cursor_attach_input_device(seat->cursor->cursor,
|
|
|
|
sway_device->input_device->wlr_device);
|
|
|
|
seat_apply_input_config(seat, sway_device);
|
|
|
|
}
|
|
|
|
|
2018-04-08 16:48:13 +02:00
|
|
|
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);
|
2018-04-08 20:15:13 +02:00
|
|
|
seat_apply_input_config(seat, sway_device);
|
2018-04-08 16:48:13 +02:00
|
|
|
}
|
|
|
|
|
2018-04-02 14:45:37 +02:00
|
|
|
static struct sway_seat_device *seat_get_device(struct sway_seat *seat,
|
2017-12-14 17:11:56 +01:00
|
|
|
struct sway_input_device *input_device) {
|
|
|
|
struct sway_seat_device *seat_device = NULL;
|
|
|
|
wl_list_for_each(seat_device, &seat->devices, link) {
|
|
|
|
if (seat_device->input_device == input_device) {
|
|
|
|
return seat_device;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2017-12-10 19:59:04 +01:00
|
|
|
}
|
|
|
|
|
2018-04-02 14:45:37 +02:00
|
|
|
void seat_configure_device(struct sway_seat *seat,
|
2017-12-14 17:11:56 +01:00
|
|
|
struct sway_input_device *input_device) {
|
|
|
|
struct sway_seat_device *seat_device =
|
2018-04-02 14:45:37 +02:00
|
|
|
seat_get_device(seat, input_device);
|
2017-12-14 17:11:56 +01:00
|
|
|
if (!seat_device) {
|
2017-12-12 14:29:37 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-14 17:11:56 +01:00
|
|
|
switch (input_device->wlr_device->type) {
|
2017-12-08 13:22:26 +01:00
|
|
|
case WLR_INPUT_DEVICE_POINTER:
|
2017-12-14 17:11:56 +01:00
|
|
|
seat_configure_pointer(seat, seat_device);
|
2017-12-08 13:22:26 +01:00
|
|
|
break;
|
|
|
|
case WLR_INPUT_DEVICE_KEYBOARD:
|
2017-12-14 17:11:56 +01:00
|
|
|
seat_configure_keyboard(seat, seat_device);
|
2017-12-10 19:59:04 +01:00
|
|
|
break;
|
2018-05-02 15:00:26 +02:00
|
|
|
case WLR_INPUT_DEVICE_TOUCH:
|
|
|
|
seat_configure_touch(seat, seat_device);
|
|
|
|
break;
|
2017-12-08 13:22:26 +01:00
|
|
|
case WLR_INPUT_DEVICE_TABLET_TOOL:
|
2018-04-08 16:48:13 +02:00
|
|
|
seat_configure_tablet_tool(seat, seat_device);
|
|
|
|
break;
|
|
|
|
case WLR_INPUT_DEVICE_TABLET_PAD:
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_DEBUG, "TODO: configure tablet pad");
|
2017-12-08 13:22:26 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 14:45:37 +02:00
|
|
|
void seat_add_device(struct sway_seat *seat,
|
2017-12-14 17:11:56 +01:00
|
|
|
struct sway_input_device *input_device) {
|
2018-04-02 14:45:37 +02:00
|
|
|
if (seat_get_device(seat, input_device)) {
|
|
|
|
seat_configure_device(seat, input_device);
|
2017-12-14 17:11:56 +01:00
|
|
|
return;
|
2017-12-10 21:37:17 +01:00
|
|
|
}
|
|
|
|
|
2017-12-14 17:11:56 +01:00
|
|
|
struct sway_seat_device *seat_device =
|
|
|
|
calloc(1, sizeof(struct sway_seat_device));
|
|
|
|
if (!seat_device) {
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_DEBUG, "could not allocate seat device");
|
2017-12-14 17:11:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_DEBUG, "adding device %s to seat %s",
|
2017-12-16 19:16:58 +01:00
|
|
|
input_device->identifier, seat->wlr_seat->name);
|
|
|
|
|
2017-12-14 17:11:56 +01:00
|
|
|
seat_device->sway_seat = seat;
|
|
|
|
seat_device->input_device = input_device;
|
|
|
|
wl_list_insert(&seat->devices, &seat_device->link);
|
|
|
|
|
2018-04-02 14:45:37 +02:00
|
|
|
seat_configure_device(seat, input_device);
|
2017-12-07 15:58:32 +01:00
|
|
|
}
|
|
|
|
|
2018-04-02 14:45:37 +02:00
|
|
|
void seat_remove_device(struct sway_seat *seat,
|
2017-12-14 17:11:56 +01:00
|
|
|
struct sway_input_device *input_device) {
|
|
|
|
struct sway_seat_device *seat_device =
|
2018-04-02 14:45:37 +02:00
|
|
|
seat_get_device(seat, input_device);
|
2017-12-12 14:29:37 +01:00
|
|
|
|
2017-12-14 17:11:56 +01:00
|
|
|
if (!seat_device) {
|
|
|
|
return;
|
2017-12-08 13:22:26 +01:00
|
|
|
}
|
2017-12-12 14:29:37 +01:00
|
|
|
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_DEBUG, "removing device %s from seat %s",
|
2017-12-16 19:16:58 +01:00
|
|
|
input_device->identifier, seat->wlr_seat->name);
|
|
|
|
|
2017-12-14 17:11:56 +01:00
|
|
|
seat_device_destroy(seat_device);
|
2017-12-07 15:58:32 +01:00
|
|
|
}
|
2017-12-09 17:51:28 +01:00
|
|
|
|
2018-04-02 14:45:37 +02:00
|
|
|
void seat_configure_xcursor(struct sway_seat *seat) {
|
2017-12-09 17:51:28 +01:00
|
|
|
// TODO configure theme and size
|
2018-03-31 06:13:26 +02:00
|
|
|
const char *cursor_theme = NULL;
|
2017-12-09 17:51:28 +01:00
|
|
|
|
2017-12-09 20:06:00 +01:00
|
|
|
if (!seat->cursor->xcursor_manager) {
|
|
|
|
seat->cursor->xcursor_manager =
|
2018-03-31 06:13:26 +02:00
|
|
|
wlr_xcursor_manager_create(cursor_theme, 24);
|
2017-12-09 20:06:00 +01:00
|
|
|
if (sway_assert(seat->cursor->xcursor_manager,
|
2017-12-14 17:11:56 +01:00
|
|
|
"Cannot create XCursor manager for theme %s",
|
|
|
|
cursor_theme)) {
|
2017-12-09 20:06:00 +01:00
|
|
|
return;
|
|
|
|
}
|
2017-12-09 17:51:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < root_container.children->length; ++i) {
|
2018-04-02 17:44:42 +02:00
|
|
|
struct sway_container *output_container =
|
|
|
|
root_container.children->items[i];
|
2017-12-09 17:51:28 +01:00
|
|
|
struct wlr_output *output =
|
|
|
|
output_container->sway_output->wlr_output;
|
|
|
|
bool result =
|
|
|
|
wlr_xcursor_manager_load(seat->cursor->xcursor_manager,
|
|
|
|
output->scale);
|
|
|
|
|
2017-12-09 20:06:00 +01:00
|
|
|
sway_assert(!result,
|
2017-12-16 13:39:22 +01:00
|
|
|
"Cannot load xcursor theme for output '%s' with scale %f",
|
2017-12-18 03:00:17 +01:00
|
|
|
// TODO: Fractional scaling
|
|
|
|
output->name, (double)output->scale);
|
2017-12-09 17:51:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
|
|
|
|
"left_ptr", seat->cursor->cursor);
|
|
|
|
wlr_cursor_warp(seat->cursor->cursor, NULL, seat->cursor->cursor->x,
|
|
|
|
seat->cursor->cursor->y);
|
|
|
|
}
|
2017-12-10 17:11:47 +01:00
|
|
|
|
2018-04-04 03:25:42 +02:00
|
|
|
bool seat_is_input_allowed(struct sway_seat *seat,
|
|
|
|
struct wlr_surface *surface) {
|
2018-04-03 23:03:29 +02:00
|
|
|
struct wl_client *client = wl_resource_get_client(surface->resource);
|
|
|
|
return !seat->exclusive_client || seat->exclusive_client == client;
|
|
|
|
}
|
|
|
|
|
2018-05-11 01:13:40 +02:00
|
|
|
// Unfocus the container and any children (eg. when leaving `focus parent`)
|
|
|
|
static void seat_send_unfocus(struct sway_container *container,
|
|
|
|
struct sway_seat *seat) {
|
|
|
|
if (container->type == C_VIEW) {
|
|
|
|
wlr_seat_keyboard_clear_focus(seat->wlr_seat);
|
|
|
|
view_set_activated(container->sway_view, false);
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < container->children->length; ++i) {
|
|
|
|
struct sway_container *child = container->children->items[i];
|
|
|
|
seat_send_unfocus(child, seat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-15 14:43:33 +02:00
|
|
|
static int handle_urgent_timeout(void *data) {
|
|
|
|
struct sway_view *view = data;
|
|
|
|
view_set_urgent(view, false);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-02 14:45:37 +02:00
|
|
|
void seat_set_focus_warp(struct sway_seat *seat,
|
2018-03-31 17:18:29 +02:00
|
|
|
struct sway_container *container, bool warp) {
|
2018-04-03 03:07:46 +02:00
|
|
|
if (seat->focused_layer) {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-10 17:11:47 +01:00
|
|
|
|
2018-04-03 03:07:46 +02:00
|
|
|
struct sway_container *last_focus = seat_get_focus(seat);
|
2018-02-04 19:39:10 +01:00
|
|
|
if (container && last_focus == container) {
|
2017-12-10 17:11:47 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-16 12:36:40 +02:00
|
|
|
struct sway_container *last_workspace = last_focus;
|
|
|
|
if (last_workspace && last_workspace->type != C_WORKSPACE) {
|
|
|
|
last_workspace = container_parent(last_workspace, C_WORKSPACE);
|
|
|
|
}
|
|
|
|
struct sway_container *new_workspace = container;
|
|
|
|
if (new_workspace && new_workspace->type != C_WORKSPACE) {
|
|
|
|
new_workspace = container_parent(new_workspace, C_WORKSPACE);
|
|
|
|
}
|
|
|
|
|
2018-04-19 15:15:21 +02:00
|
|
|
if (last_workspace && last_workspace == new_workspace
|
2018-04-17 01:31:34 +02:00
|
|
|
&& last_workspace->sway_workspace->fullscreen
|
2018-04-16 12:36:40 +02:00
|
|
|
&& !container->sway_view->is_fullscreen) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-15 08:24:04 +02:00
|
|
|
struct sway_container *last_output = last_focus;
|
|
|
|
if (last_output && last_output->type != C_OUTPUT) {
|
|
|
|
last_output = container_parent(last_output, C_OUTPUT);
|
|
|
|
}
|
|
|
|
struct sway_container *new_output = container;
|
|
|
|
if (new_output && new_output->type != C_OUTPUT) {
|
|
|
|
new_output = container_parent(new_output, C_OUTPUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
// find new output's old workspace, which might have to be removed if empty
|
|
|
|
struct sway_container *new_output_last_ws = NULL;
|
|
|
|
if (last_output && new_output && last_output != new_output) {
|
2018-04-24 19:18:49 +02:00
|
|
|
new_output_last_ws =
|
|
|
|
seat_get_focus_by_type(seat, new_output, C_WORKSPACE);
|
2018-04-15 08:24:04 +02:00
|
|
|
}
|
|
|
|
|
2018-04-24 19:18:49 +02:00
|
|
|
if (container && container->parent) {
|
2018-02-04 19:39:10 +01:00
|
|
|
struct sway_seat_container *seat_con =
|
|
|
|
seat_container_from_container(seat, container);
|
2018-04-08 17:34:38 +02:00
|
|
|
if (seat_con == NULL) {
|
2018-02-11 00:10:29 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-02-04 19:39:10 +01:00
|
|
|
|
2018-05-28 04:45:42 +02:00
|
|
|
// put all the ancestors of this container on top of the focus stack
|
2018-04-08 17:34:38 +02:00
|
|
|
struct sway_seat_container *parent =
|
2018-04-24 19:18:49 +02:00
|
|
|
seat_container_from_container(seat, container->parent);
|
2018-04-08 17:34:38 +02:00
|
|
|
while (parent) {
|
|
|
|
wl_list_remove(&parent->link);
|
|
|
|
wl_list_insert(&seat->focus_stack, &parent->link);
|
2018-07-16 10:09:35 +02:00
|
|
|
container_set_dirty(parent->container);
|
2018-04-08 17:34:38 +02:00
|
|
|
|
|
|
|
parent =
|
|
|
|
seat_container_from_container(seat,
|
|
|
|
parent->container->parent);
|
|
|
|
}
|
|
|
|
|
2018-02-04 19:39:10 +01:00
|
|
|
wl_list_remove(&seat_con->link);
|
|
|
|
wl_list_insert(&seat->focus_stack, &seat_con->link);
|
|
|
|
|
2018-05-11 01:13:40 +02:00
|
|
|
if (last_focus) {
|
|
|
|
seat_send_unfocus(last_focus, seat);
|
2018-04-03 23:03:29 +02:00
|
|
|
}
|
2018-05-11 01:13:40 +02:00
|
|
|
seat_send_focus(container, seat);
|
2018-07-15 07:20:21 +02:00
|
|
|
|
|
|
|
container_set_dirty(container);
|
|
|
|
container_set_dirty(container->parent); // for focused_inactive_child
|
|
|
|
if (last_focus) {
|
|
|
|
container_set_dirty(last_focus);
|
|
|
|
}
|
2017-12-10 17:11:47 +01:00
|
|
|
}
|
|
|
|
|
2018-07-21 02:27:40 +02:00
|
|
|
// If urgent, either unset the urgency or start a timer to unset it
|
2018-07-15 14:43:33 +02:00
|
|
|
if (container && container->type == C_VIEW &&
|
|
|
|
view_is_urgent(container->sway_view) &&
|
|
|
|
!container->sway_view->urgent_timer) {
|
|
|
|
struct sway_view *view = container->sway_view;
|
2018-07-21 02:27:40 +02:00
|
|
|
if (last_workspace && last_workspace != new_workspace &&
|
|
|
|
config->urgent_timeout > 0) {
|
|
|
|
view->urgent_timer = wl_event_loop_add_timer(server.wl_event_loop,
|
|
|
|
handle_urgent_timeout, view);
|
|
|
|
wl_event_source_timer_update(view->urgent_timer,
|
|
|
|
config->urgent_timeout);
|
|
|
|
} else {
|
|
|
|
view_set_urgent(view, false);
|
|
|
|
}
|
2018-07-15 14:43:33 +02:00
|
|
|
}
|
|
|
|
|
2018-07-11 11:50:02 +02:00
|
|
|
// If we've focused a floating container, bring it to the front.
|
|
|
|
// We do this by putting it at the end of the floating list.
|
|
|
|
// This must happen for both the pending and current children lists.
|
2018-07-12 06:43:08 +02:00
|
|
|
if (container && container_is_floating(container)) {
|
2018-07-11 11:50:02 +02:00
|
|
|
list_move_to_end(container->parent->children, container);
|
2018-07-11 17:08:33 +02:00
|
|
|
if (container_has_ancestor(container, container->current.parent)) {
|
|
|
|
list_move_to_end(container->parent->current.children, container);
|
|
|
|
}
|
2018-07-11 11:50:02 +02:00
|
|
|
}
|
|
|
|
|
2018-04-15 08:24:04 +02:00
|
|
|
// clean up unfocused empty workspace on new output
|
|
|
|
if (new_output_last_ws) {
|
|
|
|
if (!workspace_is_visible(new_output_last_ws)
|
2018-05-24 14:30:44 +02:00
|
|
|
&& workspace_is_empty(new_output_last_ws)) {
|
2018-04-24 19:18:49 +02:00
|
|
|
if (last_workspace == new_output_last_ws) {
|
|
|
|
last_focus = NULL;
|
|
|
|
last_workspace = NULL;
|
|
|
|
}
|
2018-04-15 08:24:04 +02:00
|
|
|
container_destroy(new_output_last_ws);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-29 22:51:36 +02:00
|
|
|
if (last_focus) {
|
2018-04-24 19:18:49 +02:00
|
|
|
if (last_workspace) {
|
|
|
|
ipc_event_workspace(last_workspace, container, "focus");
|
|
|
|
if (!workspace_is_visible(last_workspace)
|
2018-05-24 14:30:44 +02:00
|
|
|
&& workspace_is_empty(last_workspace)) {
|
2018-04-24 19:18:49 +02:00
|
|
|
if (last_workspace == last_focus) {
|
2018-04-13 07:56:58 +02:00
|
|
|
last_focus = NULL;
|
|
|
|
}
|
2018-04-24 19:18:49 +02:00
|
|
|
container_destroy(last_workspace);
|
2018-03-30 16:31:21 +02:00
|
|
|
}
|
2018-03-29 22:51:36 +02:00
|
|
|
}
|
2018-04-07 20:03:30 +02:00
|
|
|
|
|
|
|
if (config->mouse_warping && warp) {
|
|
|
|
if (new_output && last_output && new_output != last_output) {
|
2018-05-30 02:50:02 +02:00
|
|
|
double x = container->x + container->width / 2.0;
|
|
|
|
double y = container->y + container->height / 2.0;
|
2018-04-07 20:03:30 +02:00
|
|
|
struct wlr_output *wlr_output =
|
|
|
|
new_output->sway_output->wlr_output;
|
|
|
|
if (!wlr_output_layout_contains_point(
|
|
|
|
root_container.sway_root->output_layout,
|
|
|
|
wlr_output, seat->cursor->cursor->x,
|
|
|
|
seat->cursor->cursor->y)) {
|
|
|
|
wlr_cursor_warp(seat->cursor->cursor, NULL, x, y);
|
2018-05-27 14:45:14 +02:00
|
|
|
cursor_send_pointer_motion(seat->cursor, 0, true);
|
2018-04-07 20:03:30 +02:00
|
|
|
}
|
2018-03-31 21:13:27 +02:00
|
|
|
}
|
2018-03-31 16:49:52 +02:00
|
|
|
}
|
2018-03-29 22:51:36 +02:00
|
|
|
}
|
|
|
|
|
2018-07-18 00:04:55 +02:00
|
|
|
if (last_focus != NULL) {
|
2018-05-27 14:45:14 +02:00
|
|
|
cursor_send_pointer_motion(seat->cursor, 0, true);
|
2018-04-21 13:46:48 +02:00
|
|
|
}
|
|
|
|
|
2018-02-11 00:10:29 +01:00
|
|
|
seat->has_focus = (container != NULL);
|
2018-04-06 17:49:27 +02:00
|
|
|
|
|
|
|
update_debug_tree();
|
2017-12-10 17:11:47 +01:00
|
|
|
}
|
2017-12-14 17:11:56 +01:00
|
|
|
|
2018-04-02 14:45:37 +02:00
|
|
|
void seat_set_focus(struct sway_seat *seat,
|
2018-03-31 17:18:29 +02:00
|
|
|
struct sway_container *container) {
|
2018-04-02 14:45:37 +02:00
|
|
|
seat_set_focus_warp(seat, container, true);
|
2018-03-31 17:18:29 +02:00
|
|
|
}
|
|
|
|
|
2018-04-07 20:03:30 +02:00
|
|
|
void seat_set_focus_surface(struct sway_seat *seat,
|
2018-07-18 21:00:48 +02:00
|
|
|
struct wlr_surface *surface, bool unfocus) {
|
2018-04-07 20:03:30 +02:00
|
|
|
if (seat->focused_layer != NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-18 21:00:48 +02:00
|
|
|
if (seat->has_focus && unfocus) {
|
2018-04-07 20:03:30 +02:00
|
|
|
struct sway_container *focus = seat_get_focus(seat);
|
2018-05-11 01:13:40 +02:00
|
|
|
seat_send_unfocus(focus, seat);
|
2018-04-07 20:03:30 +02:00
|
|
|
seat->has_focus = false;
|
|
|
|
}
|
|
|
|
struct wlr_keyboard *keyboard =
|
|
|
|
wlr_seat_get_keyboard(seat->wlr_seat);
|
|
|
|
if (keyboard) {
|
|
|
|
wlr_seat_keyboard_notify_enter(seat->wlr_seat, surface,
|
|
|
|
keyboard->keycodes, keyboard->num_keycodes, &keyboard->modifiers);
|
|
|
|
} else {
|
|
|
|
wlr_seat_keyboard_notify_enter(seat->wlr_seat, surface, NULL, 0, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-03 03:07:46 +02:00
|
|
|
void seat_set_focus_layer(struct sway_seat *seat,
|
|
|
|
struct wlr_layer_surface *layer) {
|
2018-04-03 21:42:32 +02:00
|
|
|
if (!layer && seat->focused_layer) {
|
2018-04-03 03:07:46 +02:00
|
|
|
seat->focused_layer = NULL;
|
2018-06-04 03:31:07 +02:00
|
|
|
struct sway_container *previous =
|
|
|
|
seat_get_focus_inactive(seat, &root_container);
|
2018-04-03 23:03:29 +02:00
|
|
|
if (previous) {
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_DEBUG, "Returning focus to %p %s '%s'", previous,
|
2018-04-03 23:03:29 +02:00
|
|
|
container_type_to_str(previous->type), previous->name);
|
2018-04-03 21:42:32 +02:00
|
|
|
// Hack to get seat to re-focus the return value of get_focus
|
2018-04-03 23:03:29 +02:00
|
|
|
seat_set_focus(seat, previous->parent);
|
|
|
|
seat_set_focus(seat, previous);
|
2018-04-03 21:42:32 +02:00
|
|
|
}
|
2018-04-03 03:07:46 +02:00
|
|
|
return;
|
2018-04-03 21:42:32 +02:00
|
|
|
} else if (!layer || seat->focused_layer == layer) {
|
2018-04-03 03:07:46 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-07-18 21:00:48 +02:00
|
|
|
seat_set_focus_surface(seat, layer->surface, true);
|
2018-04-03 03:07:46 +02:00
|
|
|
if (layer->layer >= ZWLR_LAYER_SHELL_V1_LAYER_TOP) {
|
|
|
|
seat->focused_layer = layer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-03 22:16:42 +02:00
|
|
|
void seat_set_exclusive_client(struct sway_seat *seat,
|
|
|
|
struct wl_client *client) {
|
2018-04-03 23:03:29 +02:00
|
|
|
if (!client) {
|
|
|
|
seat->exclusive_client = client;
|
|
|
|
// Triggers a refocus of the topmost surface layer if necessary
|
|
|
|
// TODO: Make layer surface focus per-output based on cursor position
|
|
|
|
for (int i = 0; i < root_container.children->length; ++i) {
|
|
|
|
struct sway_container *output = root_container.children->items[i];
|
|
|
|
if (!sway_assert(output->type == C_OUTPUT,
|
|
|
|
"root container has non-output child")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
arrange_layers(output->sway_output);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (seat->focused_layer) {
|
|
|
|
if (wl_resource_get_client(seat->focused_layer->resource) != client) {
|
|
|
|
seat_set_focus_layer(seat, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (seat->has_focus) {
|
|
|
|
struct sway_container *focus = seat_get_focus(seat);
|
|
|
|
if (focus->type == C_VIEW && wl_resource_get_client(
|
|
|
|
focus->sway_view->surface->resource) != client) {
|
|
|
|
seat_set_focus(seat, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (seat->wlr_seat->pointer_state.focused_client) {
|
|
|
|
if (seat->wlr_seat->pointer_state.focused_client->client != client) {
|
|
|
|
wlr_seat_pointer_clear_focus(seat->wlr_seat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
struct timespec now;
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
|
|
struct wlr_touch_point *point;
|
|
|
|
wl_list_for_each(point, &seat->wlr_seat->touch_state.touch_points, link) {
|
|
|
|
if (point->client->client != client) {
|
|
|
|
wlr_seat_touch_point_clear_focus(seat->wlr_seat,
|
|
|
|
now.tv_nsec / 1000, point->touch_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
seat->exclusive_client = client;
|
2018-04-03 22:16:42 +02:00
|
|
|
}
|
|
|
|
|
2018-04-02 17:44:42 +02:00
|
|
|
struct sway_container *seat_get_focus_inactive(struct sway_seat *seat,
|
2018-03-31 21:22:10 +02:00
|
|
|
struct sway_container *container) {
|
2018-04-02 22:09:27 +02:00
|
|
|
return seat_get_focus_by_type(seat, container, C_TYPES);
|
2018-03-31 06:44:17 +02:00
|
|
|
}
|
|
|
|
|
2018-05-20 01:11:55 +02:00
|
|
|
struct sway_container *seat_get_active_child(struct sway_seat *seat,
|
|
|
|
struct sway_container *container) {
|
2018-06-03 14:31:54 +02:00
|
|
|
struct sway_seat_container *current = NULL;
|
|
|
|
wl_list_for_each(current, &seat->focus_stack, link) {
|
|
|
|
if (current->container->parent == container &&
|
|
|
|
current->container->layout != L_FLOATING) {
|
|
|
|
return current->container;
|
|
|
|
}
|
2018-05-20 01:11:55 +02:00
|
|
|
}
|
2018-06-03 14:31:54 +02:00
|
|
|
return NULL;
|
2018-05-20 01:11:55 +02:00
|
|
|
}
|
|
|
|
|
2018-04-02 14:45:37 +02:00
|
|
|
struct sway_container *seat_get_focus(struct sway_seat *seat) {
|
2018-02-08 00:17:57 +01:00
|
|
|
if (!seat->has_focus) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-04-02 14:45:37 +02:00
|
|
|
return seat_get_focus_inactive(seat, &root_container);
|
2018-02-08 00:17:57 +01:00
|
|
|
}
|
2017-12-14 17:11:56 +01:00
|
|
|
|
2018-04-02 16:37:31 +02:00
|
|
|
void seat_apply_config(struct sway_seat *seat,
|
2017-12-14 17:11:56 +01:00
|
|
|
struct seat_config *seat_config) {
|
|
|
|
struct sway_seat_device *seat_device = NULL;
|
|
|
|
|
|
|
|
if (!seat_config) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_list_for_each(seat_device, &seat->devices, link) {
|
2018-04-02 14:45:37 +02:00
|
|
|
seat_configure_device(seat, seat_device->input_device);
|
2017-12-14 17:11:56 +01:00
|
|
|
}
|
|
|
|
}
|
2018-04-02 16:37:31 +02:00
|
|
|
|
|
|
|
struct seat_config *seat_get_config(struct sway_seat *seat) {
|
|
|
|
struct seat_config *seat_config = NULL;
|
|
|
|
for (int i = 0; i < config->seat_configs->length; ++i ) {
|
|
|
|
seat_config = config->seat_configs->items[i];
|
|
|
|
if (strcmp(seat->wlr_seat->name, seat_config->name) == 0) {
|
|
|
|
return seat_config;
|
|
|
|
}
|
2017-12-14 17:11:56 +01:00
|
|
|
}
|
2018-04-02 16:37:31 +02:00
|
|
|
|
|
|
|
return NULL;
|
2017-12-14 17:11:56 +01:00
|
|
|
}
|
2018-07-20 01:28:22 +02:00
|
|
|
|
2018-07-21 03:23:48 +02:00
|
|
|
void seat_begin_move(struct sway_seat *seat, struct sway_container *con,
|
|
|
|
uint32_t button) {
|
2018-07-20 01:28:22 +02:00
|
|
|
if (!seat->cursor) {
|
|
|
|
wlr_log(WLR_DEBUG, "Ignoring move request due to no cursor device");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
seat->operation = OP_MOVE;
|
|
|
|
seat->op_container = con;
|
2018-07-21 03:23:48 +02:00
|
|
|
seat->op_button = button;
|
2018-07-20 01:28:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void seat_begin_resize(struct sway_seat *seat, struct sway_container *con,
|
|
|
|
uint32_t button, enum wlr_edges edge) {
|
|
|
|
if (!seat->cursor) {
|
|
|
|
wlr_log(WLR_DEBUG, "Ignoring resize request due to no cursor device");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat);
|
|
|
|
seat->operation = OP_RESIZE;
|
|
|
|
seat->op_container = con;
|
|
|
|
seat->op_resize_preserve_ratio = keyboard &&
|
|
|
|
(wlr_keyboard_get_modifiers(keyboard) & WLR_MODIFIER_SHIFT);
|
|
|
|
seat->op_resize_edge = edge == WLR_EDGE_NONE ?
|
|
|
|
RESIZE_EDGE_BOTTOM | RESIZE_EDGE_RIGHT : edge;
|
|
|
|
seat->op_button = button;
|
|
|
|
seat->op_ref_lx = seat->cursor->cursor->x;
|
|
|
|
seat->op_ref_ly = seat->cursor->cursor->y;
|
|
|
|
seat->op_ref_con_lx = con->x;
|
|
|
|
seat->op_ref_con_ly = con->y;
|
|
|
|
seat->op_ref_width = con->width;
|
|
|
|
seat->op_ref_height = con->height;
|
|
|
|
}
|
2018-07-21 02:40:12 +02:00
|
|
|
|
|
|
|
void seat_end_mouse_operation(struct sway_seat *seat) {
|
|
|
|
switch (seat->operation) {
|
|
|
|
case OP_MOVE:
|
|
|
|
{
|
|
|
|
// We "move" the container to its own location so it discovers its
|
|
|
|
// output again.
|
|
|
|
struct sway_container *con = seat->op_container;
|
|
|
|
container_floating_move_to(con, con->x, con->y);
|
|
|
|
}
|
|
|
|
case OP_RESIZE:
|
|
|
|
// Don't need to do anything here.
|
|
|
|
break;
|
|
|
|
case OP_NONE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
seat->operation = OP_NONE;
|
|
|
|
seat->op_container = NULL;
|
|
|
|
}
|
2018-07-21 03:23:48 +02:00
|
|
|
|
|
|
|
void seat_pointer_notify_button(struct sway_seat *seat, uint32_t time_msec,
|
|
|
|
uint32_t button, enum wlr_button_state state) {
|
|
|
|
seat->last_button = button;
|
|
|
|
seat->last_button_serial = wlr_seat_pointer_notify_button(seat->wlr_seat,
|
|
|
|
time_msec, button, state);
|
|
|
|
}
|