commit 2f2483e29a1aa2e91556afc2c4f22af31d2d5e88
parent 765b9bd99fb181078e15c553e0cbd57d2c0908ea
Author: Drew DeVault <sir@cmpwn.com>
Date: Tue, 23 Apr 2019 21:31:24 -0400
Focus views on map
Diffstat:
2 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/include/view.h b/include/view.h
@@ -10,9 +10,12 @@ struct wio_view {
struct wlr_xdg_surface *xdg_surface;
struct wio_server *server;
struct wl_list link;
+ struct wl_listener map;
struct wl_listener destroy;
};
void server_new_xdg_surface(struct wl_listener *listener, void *data);
+void wio_view_focus(struct wio_view *view, struct wlr_surface *surface);
+
#endif
diff --git a/view.c b/view.c
@@ -4,6 +4,11 @@
#include "server.h"
#include "view.h"
+static void xdg_surface_map(struct wl_listener *listener, void *data) {
+ struct wio_view *view = wl_container_of(listener, view, map);
+ wio_view_focus(view, view->xdg_surface->surface);
+}
+
static void xdg_surface_destroy(struct wl_listener *listener, void *data) {
struct wio_view *view = wl_container_of(listener, view, destroy);
wl_list_remove(&view->link);
@@ -24,6 +29,32 @@ void server_new_xdg_surface(struct wl_listener *listener, void *data) {
view->destroy.notify = xdg_surface_destroy;
wl_signal_add(&xdg_surface->events.destroy, &view->destroy);
+ view->map.notify = xdg_surface_map;
+ wl_signal_add(&xdg_surface->events.map, &view->map);
wl_list_insert(&server->views, &view->link);
}
+
+void wio_view_focus(struct wio_view *view, struct wlr_surface *surface) {
+ if (view == NULL) {
+ return;
+ }
+ struct wio_server *server = view->server;
+ struct wlr_seat *seat = server->seat;
+ struct wlr_surface *prev_surface = seat->keyboard_state.focused_surface;
+ if (prev_surface == surface) {
+ return;
+ }
+ if (prev_surface) {
+ struct wlr_xdg_surface *previous = wlr_xdg_surface_from_wlr_surface(
+ seat->keyboard_state.focused_surface);
+ wlr_xdg_toplevel_set_activated(previous, false);
+ }
+ struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat);
+ wlr_xdg_toplevel_set_activated(view->xdg_surface, true);
+ wlr_seat_keyboard_notify_enter(seat, view->xdg_surface->surface,
+ keyboard->keycodes, keyboard->num_keycodes, &keyboard->modifiers);
+ /* bring to front */
+ wl_list_remove(&view->link);
+ wl_list_insert(&view->server->views, &view->link);
+}