mirror of
				https://gitlab.freedesktop.org/wlroots/wlroots.git
				synced 2025-11-03 09:01:40 -05:00 
			
		
		
		
	DRY up focus and implement z ordering
This commit is contained in:
		
							parent
							
								
									033036712a
								
							
						
					
					
						commit
						ada7fde6fb
					
				
					 9 changed files with 56 additions and 43 deletions
				
			
		| 
						 | 
				
			
			@ -8,6 +8,7 @@
 | 
			
		|||
#include <wlr/types/wlr_wl_shell.h>
 | 
			
		||||
#include <wlr/types/wlr_xdg_shell_v6.h>
 | 
			
		||||
#include <wlr/types/wlr_gamma_control.h>
 | 
			
		||||
#include <wlr/util/list.h>
 | 
			
		||||
#include "rootston/view.h"
 | 
			
		||||
#include "rootston/config.h"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -21,7 +22,7 @@ struct roots_output {
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
struct roots_desktop {
 | 
			
		||||
	struct wl_list views;
 | 
			
		||||
	list_t *views;
 | 
			
		||||
 | 
			
		||||
	struct wl_list outputs;
 | 
			
		||||
	struct timespec last_frame;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -106,5 +106,9 @@ void cursor_load_config(struct roots_config *config,
 | 
			
		|||
		struct wlr_cursor *cursor,
 | 
			
		||||
		struct roots_input *input,
 | 
			
		||||
		struct roots_desktop *desktop);
 | 
			
		||||
const struct roots_input_event *get_input_event(struct roots_input *input,
 | 
			
		||||
		uint32_t serial);
 | 
			
		||||
void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor,
 | 
			
		||||
		struct roots_view *view);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -56,7 +56,6 @@ struct roots_view {
 | 
			
		|||
		struct roots_xwayland_surface *roots_xwayland_surface;
 | 
			
		||||
	};
 | 
			
		||||
	struct wlr_surface *wlr_surface;
 | 
			
		||||
	struct wl_list link;
 | 
			
		||||
	// TODO: This would probably be better as a field that's updated on a
 | 
			
		||||
	// configure event from the xdg_shell
 | 
			
		||||
	// If not then this should follow the typical type/impl pattern we use
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,6 +9,26 @@
 | 
			
		|||
#include "rootston/input.h"
 | 
			
		||||
#include "rootston/desktop.h"
 | 
			
		||||
 | 
			
		||||
const struct roots_input_event *get_input_event(struct roots_input *input,
 | 
			
		||||
		uint32_t serial) {
 | 
			
		||||
	size_t len = sizeof(input->input_events) / sizeof(*input->input_events);
 | 
			
		||||
	for (size_t i = 0; i < len; ++i) {
 | 
			
		||||
		if (input->input_events[i].cursor
 | 
			
		||||
				&& input->input_events[i].serial == serial) {
 | 
			
		||||
			return &input->input_events[i];
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor,
 | 
			
		||||
		struct roots_view *view) {
 | 
			
		||||
	input->mode = ROOTS_CURSOR_MOVE;
 | 
			
		||||
	input->offs_x = cursor->x - view->x;
 | 
			
		||||
	input->offs_y = cursor->y - view->y;
 | 
			
		||||
	wlr_seat_pointer_clear_focus(input->wl_seat);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void cursor_update_position(struct roots_input *input, uint32_t time) {
 | 
			
		||||
	struct roots_desktop *desktop = input->server->desktop;
 | 
			
		||||
	struct roots_view *view;
 | 
			
		||||
| 
						 | 
				
			
			@ -44,12 +64,19 @@ static void set_view_focus(struct roots_input *input,
 | 
			
		|||
	if (input->active_view == view) {
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	struct roots_view *_view;
 | 
			
		||||
	wl_list_for_each(_view, &desktop->views, link) {
 | 
			
		||||
	size_t index = 0;
 | 
			
		||||
	for (size_t i = 0; i < desktop->views->length; ++i) {
 | 
			
		||||
		struct roots_view *_view = desktop->views->items[i];
 | 
			
		||||
		view_activate(_view, _view == view);
 | 
			
		||||
		if (view == _view) {
 | 
			
		||||
			index = i;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	input->active_view = view;
 | 
			
		||||
	input->mode = ROOTS_CURSOR_PASSTHROUGH;
 | 
			
		||||
	// TODO: list_swap
 | 
			
		||||
	list_del(desktop->views, index);
 | 
			
		||||
	list_add(desktop->views, view);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void handle_cursor_motion(struct wl_listener *listener, void *data) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
#define _POSIX_C_SOURCE 199309L
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
#include <time.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <wlr/types/wlr_box.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -13,7 +14,14 @@
 | 
			
		|||
#include "rootston/server.h"
 | 
			
		||||
 | 
			
		||||
void view_destroy(struct roots_view *view) {
 | 
			
		||||
	wl_list_remove(&view->link);
 | 
			
		||||
	struct roots_desktop *desktop = view->desktop;
 | 
			
		||||
	for (size_t i = 0; i < desktop->views->length; ++i) {
 | 
			
		||||
		struct roots_view *_view = desktop->views->items[i];
 | 
			
		||||
		if (view == _view) {
 | 
			
		||||
			list_del(desktop->views, i);
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	free(view);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -34,8 +42,8 @@ void view_activate(struct roots_view *view, bool activate) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
struct roots_view *view_at(struct roots_desktop *desktop, int x, int y) {
 | 
			
		||||
	struct roots_view *view;
 | 
			
		||||
	wl_list_for_each(view, &desktop->views, link) {
 | 
			
		||||
	for (size_t i = 0; i < desktop->views->length; ++i) {
 | 
			
		||||
		struct roots_view *view = desktop->views->items[i];
 | 
			
		||||
		struct wlr_box box;
 | 
			
		||||
		view_get_input_bounds(view, &box);
 | 
			
		||||
		box.x += view->x;
 | 
			
		||||
| 
						 | 
				
			
			@ -52,7 +60,7 @@ struct roots_desktop *desktop_create(struct roots_server *server,
 | 
			
		|||
	struct roots_desktop *desktop = calloc(1, sizeof(struct roots_desktop));
 | 
			
		||||
	wlr_log(L_DEBUG, "Initializing roots desktop");
 | 
			
		||||
 | 
			
		||||
	wl_list_init(&desktop->views);
 | 
			
		||||
	assert(desktop->views = list_create());
 | 
			
		||||
	wl_list_init(&desktop->outputs);
 | 
			
		||||
	wl_list_init(&desktop->output_add.link);
 | 
			
		||||
	desktop->output_add.notify = output_add_notify;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -50,8 +50,8 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
 | 
			
		|||
	wlr_output_make_current(wlr_output);
 | 
			
		||||
	wlr_renderer_begin(server->renderer, wlr_output);
 | 
			
		||||
 | 
			
		||||
	struct roots_view *view;
 | 
			
		||||
	wl_list_for_each(view, &desktop->views, link) {
 | 
			
		||||
	for (size_t i = 0; i < desktop->views->length; ++i) {
 | 
			
		||||
		struct roots_view *view = desktop->views->items[i];
 | 
			
		||||
		int width = view->wlr_surface->current.buffer_width;
 | 
			
		||||
		int height = view->wlr_surface->current.buffer_height;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,24 +16,11 @@ static void handle_move(struct wl_listener *listener, void *data) {
 | 
			
		|||
	struct roots_view *view = roots_surface->view;
 | 
			
		||||
	struct roots_input *input = view->desktop->server->input;
 | 
			
		||||
	struct wlr_wl_shell_surface_move_event *e = data;
 | 
			
		||||
 | 
			
		||||
	// TODO: Some of this might want to live in cursor.c I guess
 | 
			
		||||
	struct roots_input_event *event = NULL;
 | 
			
		||||
	size_t len = sizeof(input->input_events) / sizeof(*input->input_events);
 | 
			
		||||
	for (size_t i = 0; i < len; ++i) {
 | 
			
		||||
		if (input->input_events[i].cursor
 | 
			
		||||
				&& input->input_events[i].serial == e->serial) {
 | 
			
		||||
			event = &input->input_events[i];
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	const struct roots_input_event *event = get_input_event(input, e->serial);
 | 
			
		||||
	if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) {
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	input->mode = ROOTS_CURSOR_MOVE;
 | 
			
		||||
	input->offs_x = input->cursor->x - view->x;
 | 
			
		||||
	input->offs_y = input->cursor->y - view->y;
 | 
			
		||||
	wlr_seat_pointer_clear_focus(input->wl_seat);
 | 
			
		||||
	view_begin_move(input, event->cursor, view);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void handle_destroy(struct wl_listener *listener, void *data) {
 | 
			
		||||
| 
						 | 
				
			
			@ -80,5 +67,5 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
 | 
			
		|||
	view->wlr_surface = surface->surface;
 | 
			
		||||
	view->desktop = desktop;
 | 
			
		||||
	roots_surface->view = view;
 | 
			
		||||
	wl_list_insert(&desktop->views, &view->link);
 | 
			
		||||
	list_add(desktop->views, view);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -30,24 +30,11 @@ static void handle_request_move(struct wl_listener *listener, void *data) {
 | 
			
		|||
	struct roots_view *view = roots_xdg_surface->view;
 | 
			
		||||
	struct roots_input *input = view->desktop->server->input;
 | 
			
		||||
	struct wlr_xdg_toplevel_v6_move_event *e = data;
 | 
			
		||||
 | 
			
		||||
	// TODO: Some of this might want to live in cursor.c I guess
 | 
			
		||||
	struct roots_input_event *event = NULL;
 | 
			
		||||
	size_t len = sizeof(input->input_events) / sizeof(*input->input_events);
 | 
			
		||||
	for (size_t i = 0; i < len; ++i) {
 | 
			
		||||
		if (input->input_events[i].cursor
 | 
			
		||||
				&& input->input_events[i].serial == e->serial) {
 | 
			
		||||
			event = &input->input_events[i];
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	const struct roots_input_event *event = get_input_event(input, e->serial);
 | 
			
		||||
	if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) {
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	input->mode = ROOTS_CURSOR_MOVE;
 | 
			
		||||
	input->offs_x = input->cursor->x - view->x;
 | 
			
		||||
	input->offs_y = input->cursor->y - view->y;
 | 
			
		||||
	wlr_seat_pointer_clear_focus(input->wl_seat);
 | 
			
		||||
	view_begin_move(input, event->cursor, view);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void handle_destroy(struct wl_listener *listener, void *data) {
 | 
			
		||||
| 
						 | 
				
			
			@ -96,5 +83,5 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
 | 
			
		|||
	view->activate = activate;
 | 
			
		||||
	view->desktop = desktop;
 | 
			
		||||
	roots_surface->view = view;
 | 
			
		||||
	wl_list_insert(&desktop->views, &view->link);
 | 
			
		||||
	list_add(desktop->views, view);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -45,5 +45,5 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
 | 
			
		|||
	view->desktop = desktop;
 | 
			
		||||
	view->activate = x11_activate;
 | 
			
		||||
	roots_surface->view = view;
 | 
			
		||||
	wl_list_insert(&desktop->views, &view->link);
 | 
			
		||||
	list_add(desktop->views, view);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue