Always give keyboard focus to the topmost layer
This commit is contained in:
		
							parent
							
								
									883d8d306c
								
							
						
					
					
						commit
						a94f4d0edc
					
				|  | @ -17,7 +17,7 @@ static struct wl_compositor *compositor = NULL; | ||||||
| static struct wl_seat *seat = NULL; | static struct wl_seat *seat = NULL; | ||||||
| static struct wl_shm *shm = NULL; | static struct wl_shm *shm = NULL; | ||||||
| static struct wl_pointer *pointer = NULL; | static struct wl_pointer *pointer = NULL; | ||||||
| //static struct wl_keyboard *keyboard = NULL;
 | static struct wl_keyboard *keyboard = NULL; | ||||||
| static struct zwlr_layer_shell_v1 *layer_shell = NULL; | static struct zwlr_layer_shell_v1 *layer_shell = NULL; | ||||||
| struct zwlr_layer_surface_v1 *layer_surface; | struct zwlr_layer_surface_v1 *layer_surface; | ||||||
| static struct wl_output *wl_output = NULL; | static struct wl_output *wl_output = NULL; | ||||||
|  | @ -212,6 +212,46 @@ struct wl_pointer_listener pointer_listener = { | ||||||
| 	.axis_discrete = wl_pointer_axis_discrete, | 	.axis_discrete = wl_pointer_axis_discrete, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | static void wl_keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, | ||||||
|  | 		uint32_t format, int32_t fd, uint32_t size) { | ||||||
|  | 	// Who cares
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void wl_keyboard_enter(void *data, struct wl_keyboard *wl_keyboard, | ||||||
|  | 		uint32_t serial, struct wl_surface *surface, struct wl_array *keys) { | ||||||
|  | 	wlr_log(L_DEBUG, "Keyboard enter"); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void wl_keyboard_leave(void *data, struct wl_keyboard *wl_keyboard, | ||||||
|  | 		uint32_t serial, struct wl_surface *surface) { | ||||||
|  | 	wlr_log(L_DEBUG, "Keyboard leave"); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void wl_keyboard_key(void *data, struct wl_keyboard *wl_keyboard, | ||||||
|  | 		uint32_t serial, uint32_t time, uint32_t key, uint32_t state) { | ||||||
|  | 	wlr_log(L_DEBUG, "Key event: %d %d", key, state); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void wl_keyboard_modifiers(void *data, struct wl_keyboard *wl_keyboard, | ||||||
|  | 		uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, | ||||||
|  | 		uint32_t mods_locked, uint32_t group) { | ||||||
|  | 	// Who cares
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void wl_keyboard_repeat_info(void *data, struct wl_keyboard *wl_keyboard, | ||||||
|  | 		int32_t rate, int32_t delay) { | ||||||
|  | 	// Who cares
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static struct wl_keyboard_listener keyboard_listener = { | ||||||
|  | 	.keymap = wl_keyboard_keymap, | ||||||
|  | 	.enter = wl_keyboard_enter, | ||||||
|  | 	.leave = wl_keyboard_leave, | ||||||
|  | 	.key = wl_keyboard_key, | ||||||
|  | 	.modifiers = wl_keyboard_modifiers, | ||||||
|  | 	.repeat_info = wl_keyboard_repeat_info, | ||||||
|  | }; | ||||||
|  | 
 | ||||||
| static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, | static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, | ||||||
| 		enum wl_seat_capability caps) { | 		enum wl_seat_capability caps) { | ||||||
| 	if ((caps & WL_SEAT_CAPABILITY_POINTER)) { | 	if ((caps & WL_SEAT_CAPABILITY_POINTER)) { | ||||||
|  | @ -219,7 +259,8 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, | ||||||
| 		wl_pointer_add_listener(pointer, &pointer_listener, NULL); | 		wl_pointer_add_listener(pointer, &pointer_listener, NULL); | ||||||
| 	} | 	} | ||||||
| 	if ((caps & WL_SEAT_CAPABILITY_KEYBOARD)) { | 	if ((caps & WL_SEAT_CAPABILITY_KEYBOARD)) { | ||||||
| 		// TODO
 | 		keyboard = wl_seat_get_keyboard(wl_seat); | ||||||
|  | 		wl_keyboard_add_listener(keyboard, &keyboard_listener, NULL); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -4,6 +4,7 @@ | ||||||
| #include <wayland-server.h> | #include <wayland-server.h> | ||||||
| #include "rootston/input.h" | #include "rootston/input.h" | ||||||
| #include "rootston/keyboard.h" | #include "rootston/keyboard.h" | ||||||
|  | #include "rootston/layers.h" | ||||||
| 
 | 
 | ||||||
| struct roots_seat { | struct roots_seat { | ||||||
| 	struct roots_input *input; | 	struct roots_input *input; | ||||||
|  | @ -15,6 +16,9 @@ struct roots_seat { | ||||||
| 	int32_t touch_id; | 	int32_t touch_id; | ||||||
| 	double touch_x, touch_y; | 	double touch_x, touch_y; | ||||||
| 
 | 
 | ||||||
|  | 	// If the focused layer is set, views cannot receive keyboard focus
 | ||||||
|  | 	struct roots_layer_surface *focused_layer; | ||||||
|  | 
 | ||||||
| 	struct wl_list views; // roots_seat_view::link
 | 	struct wl_list views; // roots_seat_view::link
 | ||||||
| 	bool has_focus; | 	bool has_focus; | ||||||
| 
 | 
 | ||||||
|  | @ -100,6 +104,9 @@ struct roots_view *roots_seat_get_focus(struct roots_seat *seat); | ||||||
| 
 | 
 | ||||||
| void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view); | void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view); | ||||||
| 
 | 
 | ||||||
|  | void roots_seat_set_focus_layer(struct roots_seat *seat, | ||||||
|  | 		struct roots_layer_surface *layer); | ||||||
|  | 
 | ||||||
| void roots_seat_cycle_focus(struct roots_seat *seat); | void roots_seat_cycle_focus(struct roots_seat *seat); | ||||||
| 
 | 
 | ||||||
| void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view); | void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view); | ||||||
|  |  | ||||||
|  | @ -214,7 +214,12 @@ void arrange_layers(struct roots_output *output) { | ||||||
| 			break; | 			break; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	wlr_log(L_DEBUG, "topmost interactive layer: %p", topmost); | 
 | ||||||
|  | 	struct roots_input *input = output->desktop->server->input; | ||||||
|  | 	struct roots_seat *seat; | ||||||
|  | 	wl_list_for_each(seat, &input->seats, link) { | ||||||
|  | 		roots_seat_set_focus_layer(seat, topmost); | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void handle_output_destroy(struct wl_listener *listener, void *data) { | static void handle_output_destroy(struct wl_listener *listener, void *data) { | ||||||
|  |  | ||||||
|  | @ -4,6 +4,7 @@ | ||||||
| #include <wayland-server.h> | #include <wayland-server.h> | ||||||
| #include <wlr/config.h> | #include <wlr/config.h> | ||||||
| #include <wlr/types/wlr_idle.h> | #include <wlr/types/wlr_idle.h> | ||||||
|  | #include <wlr/types/wlr_layer_shell.h> | ||||||
| #include <wlr/types/wlr_xcursor_manager.h> | #include <wlr/types/wlr_xcursor_manager.h> | ||||||
| #include <wlr/util/log.h> | #include <wlr/util/log.h> | ||||||
| #include "rootston/cursor.h" | #include "rootston/cursor.h" | ||||||
|  | @ -723,7 +724,6 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) { | ||||||
| 		wl_list_insert(&seat->input->server->desktop->views, &view->link); | 		wl_list_insert(&seat->input->server->desktop->views, &view->link); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 	bool unfullscreen = true; | 	bool unfullscreen = true; | ||||||
| 
 | 
 | ||||||
| #ifdef WLR_HAS_XWAYLAND | #ifdef WLR_HAS_XWAYLAND | ||||||
|  | @ -781,14 +781,18 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) { | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	view_activate(view, true); |  | ||||||
| 
 |  | ||||||
| 	seat->has_focus = true; |  | ||||||
| 	wl_list_remove(&seat_view->link); | 	wl_list_remove(&seat_view->link); | ||||||
| 	wl_list_insert(&seat->views, &seat_view->link); | 	wl_list_insert(&seat->views, &seat_view->link); | ||||||
| 
 | 
 | ||||||
| 	view_damage_whole(view); | 	view_damage_whole(view); | ||||||
| 
 | 
 | ||||||
|  | 	if (seat->focused_layer) { | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	view_activate(view, true); | ||||||
|  | 	seat->has_focus = true; | ||||||
|  | 
 | ||||||
| 	struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->seat); | 	struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->seat); | ||||||
| 	if (keyboard != NULL) { | 	if (keyboard != NULL) { | ||||||
| 		wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface, | 		wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface, | ||||||
|  | @ -800,6 +804,30 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) { | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void roots_seat_set_focus_layer(struct roots_seat *seat, | ||||||
|  | 		struct roots_layer_surface *layer) { | ||||||
|  | 	struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->seat); | ||||||
|  | 	seat->focused_layer = layer; | ||||||
|  | 	if (!layer) { | ||||||
|  | 		wlr_seat_keyboard_clear_focus(seat->seat); | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 	if (seat->has_focus) { | ||||||
|  | 		struct roots_view *prev_focus = roots_seat_get_focus(seat); | ||||||
|  | 		view_activate(prev_focus, false); | ||||||
|  | 	} | ||||||
|  | 	seat->has_focus = false; | ||||||
|  | 	struct wlr_layer_surface *layer_surface = layer->layer_surface; | ||||||
|  | 	if (keyboard != NULL) { | ||||||
|  | 		wlr_seat_keyboard_notify_enter(seat->seat, layer_surface->surface, | ||||||
|  | 			keyboard->keycodes, keyboard->num_keycodes, | ||||||
|  | 			&keyboard->modifiers); | ||||||
|  | 	} else { | ||||||
|  | 		wlr_seat_keyboard_notify_enter(seat->seat, layer_surface->surface, | ||||||
|  | 			NULL, 0, NULL); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void roots_seat_cycle_focus(struct roots_seat *seat) { | void roots_seat_cycle_focus(struct roots_seat *seat) { | ||||||
| 	if (wl_list_empty(&seat->views)) { | 	if (wl_list_empty(&seat->views)) { | ||||||
| 		return; | 		return; | ||||||
|  | @ -826,6 +854,7 @@ void roots_seat_cycle_focus(struct roots_seat *seat) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view) { | void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view) { | ||||||
|  | 	wlr_log(L_DEBUG, "begin move"); | ||||||
| 	struct roots_cursor *cursor = seat->cursor; | 	struct roots_cursor *cursor = seat->cursor; | ||||||
| 	cursor->mode = ROOTS_CURSOR_MOVE; | 	cursor->mode = ROOTS_CURSOR_MOVE; | ||||||
| 	cursor->offs_x = cursor->cursor->x; | 	cursor->offs_x = cursor->cursor->x; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue