aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-04-07 14:43:38 -0400
committerGitHub <noreply@github.com>2018-04-07 14:43:38 -0400
commit4b200869b2769a41d087c70e3e80124b2ed51064 (patch)
tree7a56e757655bf8e8943cb277c81a3e89f724f9ce
parenta5d06b6e2b52d535fca25adf143f27233a3609c5 (diff)
parent2b357af7eed9c7dd3a8f9b5bb589c352cabd6406 (diff)
downloadsway-4b200869b2769a41d087c70e3e80124b2ed51064.zip
sway-4b200869b2769a41d087c70e3e80124b2ed51064.tar.gz
sway-4b200869b2769a41d087c70e3e80124b2ed51064.tar.bz2
Merge pull request #1767 from emersion/fix-dmenu1.0-alpha.1
Give keyboard focus to unmanaged xwayland surfaces
-rw-r--r--include/sway/input/seat.h3
-rw-r--r--sway/desktop/xwayland.c7
-rw-r--r--sway/input/input-manager.c2
-rw-r--r--sway/input/seat.c82
4 files changed, 58 insertions, 36 deletions
diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h
index d1cfbe4..c7be58b 100644
--- a/include/sway/input/seat.h
+++ b/include/sway/input/seat.h
@@ -64,6 +64,9 @@ void seat_set_focus(struct sway_seat *seat, struct sway_container *container);
void seat_set_focus_warp(struct sway_seat *seat,
struct sway_container *container, bool warp);
+void seat_set_focus_surface(struct sway_seat *seat,
+ struct wlr_surface *surface);
+
void seat_set_focus_layer(struct sway_seat *seat,
struct wlr_layer_surface *layer);
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c
index 6de1365..413dbf8 100644
--- a/sway/desktop/xwayland.c
+++ b/sway/desktop/xwayland.c
@@ -59,6 +59,13 @@ static void unmanaged_handle_map(struct wl_listener *listener, void *data) {
surface->ly = xsurface->y;
desktop_damage_surface(xsurface->surface, surface->lx, surface->ly, true);
+ if (!wlr_xwayland_surface_is_unmanaged(xsurface)) {
+ struct sway_seat *seat = input_manager_current_seat(input_manager);
+ struct wlr_xwayland *xwayland = seat->input->server->xwayland;
+ wlr_xwayland_set_seat(xwayland, seat->wlr_seat);
+ seat_set_focus_surface(seat, xsurface->surface);
+ }
+
// TODO: we don't send surface enter/leave events to xwayland unmanaged
// surfaces, but xwayland doesn't support HiDPI anyway
}
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c
index f71a06e..ae55d2a 100644
--- a/sway/input/input-manager.c
+++ b/sway/input/input-manager.c
@@ -333,7 +333,7 @@ bool input_manager_has_focus(struct sway_input_manager *input,
void input_manager_set_focus(struct sway_input_manager *input,
struct sway_container *container) {
- struct sway_seat *seat ;
+ struct sway_seat *seat;
wl_list_for_each(seat, &input->seats, link) {
seat_set_focus(seat, container);
}
diff --git a/sway/input/seat.c b/sway/input/seat.c
index e8cf982..b94e329 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -84,7 +84,6 @@ static void seat_send_focus(struct sway_seat *seat,
wlr_seat_keyboard_notify_enter(
seat->wlr_seat, view->surface, NULL, 0, NULL);
}
-
}
static void handle_seat_container_destroy(struct wl_listener *listener,
@@ -405,23 +404,29 @@ void seat_set_focus_warp(struct sway_seat *seat,
container_destroy(last_ws);
}
}
- 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);
- }
- if (new_output && last_output && new_output != last_output
- && config->mouse_warping && warp) {
- struct wlr_output *output = new_output->sway_output->wlr_output;
- double x = container->x + output->lx + container->width / 2.0;
- double y = container->y + output->ly + container->height / 2.0;
- if (!wlr_output_layout_contains_point(
- root_container.sway_root->output_layout,
- output, seat->cursor->cursor->x, seat->cursor->cursor->y)) {
- wlr_cursor_warp(seat->cursor->cursor, NULL, x, y);
+
+ if (config->mouse_warping && warp) {
+ 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);
+ }
+ if (new_output && last_output && new_output != last_output) {
+ double x = new_output->x + container->x +
+ container->width / 2.0;
+ double y = new_output->y + container->y +
+ container->height / 2.0;
+ 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);
+ }
}
}
}
@@ -442,6 +447,29 @@ void seat_set_focus(struct sway_seat *seat,
seat_set_focus_warp(seat, container, true);
}
+void seat_set_focus_surface(struct sway_seat *seat,
+ struct wlr_surface *surface) {
+ if (seat->focused_layer != NULL) {
+ return;
+ }
+ if (seat->has_focus) {
+ struct sway_container *focus = seat_get_focus(seat);
+ if (focus->type == C_VIEW) {
+ wlr_seat_keyboard_clear_focus(seat->wlr_seat);
+ view_set_activated(focus->sway_view, false);
+ }
+ 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);
+ }
+}
+
void seat_set_focus_layer(struct sway_seat *seat,
struct wlr_layer_surface *layer) {
if (!layer && seat->focused_layer) {
@@ -458,26 +486,10 @@ void seat_set_focus_layer(struct sway_seat *seat,
} else if (!layer || seat->focused_layer == layer) {
return;
}
- if (seat->has_focus) {
- struct sway_container *focus = seat_get_focus(seat);
- if (focus->type == C_VIEW) {
- wlr_seat_keyboard_clear_focus(seat->wlr_seat);
- view_set_activated(focus->sway_view, false);
- }
- }
+ seat_set_focus_surface(seat, layer->surface);
if (layer->layer >= ZWLR_LAYER_SHELL_V1_LAYER_TOP) {
seat->focused_layer = layer;
}
- struct wlr_keyboard *keyboard =
- wlr_seat_get_keyboard(seat->wlr_seat);
- if (keyboard) {
- wlr_seat_keyboard_notify_enter(seat->wlr_seat,
- layer->surface, keyboard->keycodes,
- keyboard->num_keycodes, &keyboard->modifiers);
- } else {
- wlr_seat_keyboard_notify_enter(seat->wlr_seat,
- layer->surface, NULL, 0, NULL);
- }
}
void seat_set_exclusive_client(struct sway_seat *seat,