diff options
| author | emersion <contact@emersion.fr> | 2018-02-16 23:36:17 +0100 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-16 23:36:17 +0100 | 
| commit | 088028c570dd5b52f81069654166f0117667fac0 (patch) | |
| tree | 54630cfe4990d868a928a55a3bc5563ff3bef11d /rootston | |
| parent | 8c1cc45c7db9be4b49ffb27541e908f492fd59ba (diff) | |
| parent | 4941befeb0fb268e5c60fb6001dc381320407072 (diff) | |
| download | wlroots-088028c570dd5b52f81069654166f0117667fac0.tar.xz | |
Merge pull request #630 from martinetd/xdg_shell
xdg-shell stable implementation
Diffstat (limited to 'rootston')
| -rw-r--r-- | rootston/desktop.c | 6 | ||||
| -rw-r--r-- | rootston/meson.build | 1 | ||||
| -rw-r--r-- | rootston/output.c | 37 | ||||
| -rw-r--r-- | rootston/xdg_shell.c | 363 | 
4 files changed, 407 insertions, 0 deletions
| diff --git a/rootston/desktop.c b/rootston/desktop.c index 80ccbc25..6b28a41c 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -15,6 +15,7 @@  #include <wlr/types/wlr_wl_shell.h>  #include <wlr/types/wlr_xcursor_manager.h>  #include <wlr/types/wlr_xdg_shell_v6.h> +#include <wlr/types/wlr_xdg_shell.h>  #include <wlr/util/log.h>  #include "rootston/seat.h"  #include "rootston/server.h" @@ -639,6 +640,11 @@ struct roots_desktop *desktop_create(struct roots_server *server,  		&desktop->xdg_shell_v6_surface);  	desktop->xdg_shell_v6_surface.notify = handle_xdg_shell_v6_surface; +	desktop->xdg_shell = wlr_xdg_shell_create(server->wl_display); +	wl_signal_add(&desktop->xdg_shell->events.new_surface, +		&desktop->xdg_shell_surface); +	desktop->xdg_shell_surface.notify = handle_xdg_shell_surface; +  	desktop->wl_shell = wlr_wl_shell_create(server->wl_display);  	wl_signal_add(&desktop->wl_shell->events.new_surface,  		&desktop->wl_shell_surface); diff --git a/rootston/meson.build b/rootston/meson.build index a53812e3..9dbe37c2 100644 --- a/rootston/meson.build +++ b/rootston/meson.build @@ -10,6 +10,7 @@ sources = [  	'seat.c',  	'wl_shell.c',  	'xdg_shell_v6.c', +	'xdg_shell.c',  ]  if get_option('enable_xwayland')  	sources += ['xwayland.c'] diff --git a/rootston/output.c b/rootston/output.c index 1ea4412e..8ef383c3 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -8,6 +8,7 @@  #include <wlr/types/wlr_output_layout.h>  #include <wlr/types/wlr_wl_shell.h>  #include <wlr/types/wlr_xdg_shell_v6.h> +#include <wlr/types/wlr_xdg_shell.h>  #include <wlr/util/log.h>  #include <wlr/util/region.h>  #include "rootston/config.h" @@ -81,6 +82,34 @@ static void xdg_surface_v6_for_each_surface(struct wlr_xdg_surface_v6 *surface,  	}  } +static void xdg_surface_for_each_surface(struct wlr_xdg_surface *surface, +		double base_x, double base_y, float rotation, +		surface_iterator_func_t iterator, void *user_data) { +	double width = surface->surface->current->width; +	double height = surface->surface->current->height; + +	struct wlr_xdg_popup *popup_state; +	wl_list_for_each(popup_state, &surface->popups, link) { +		struct wlr_xdg_surface *popup = popup_state->base; +		if (!popup->configured) { +			continue; +		} + +		double popup_width = popup->surface->current->width; +		double popup_height = popup->surface->current->height; + +		double popup_sx, popup_sy; +		wlr_xdg_surface_popup_get_position(popup, &popup_sx, &popup_sy); +		rotate_child_position(&popup_sx, &popup_sy, popup_width, popup_height, +			width, height, rotation); + +		surface_for_each_surface(popup->surface, base_x + popup_sx, +			base_y + popup_sy, rotation, iterator, user_data); +		xdg_surface_for_each_surface(popup, base_x + popup_sx, +			base_y + popup_sy, rotation, iterator, user_data); +	} +} +  static void wl_shell_surface_for_each_surface(  		struct wlr_wl_shell_surface *surface, double lx, double ly,  		float rotation, bool is_child, surface_iterator_func_t iterator, @@ -117,6 +146,12 @@ static void view_for_each_surface(struct roots_view *view,  		xdg_surface_v6_for_each_surface(view->xdg_surface_v6, view->x, view->y,  			view->rotation, iterator, user_data);  		break; +	case ROOTS_XDG_SHELL_VIEW: +		surface_for_each_surface(view->wlr_surface, view->x, view->y, +			view->rotation, iterator, user_data); +		xdg_surface_for_each_surface(view->xdg_surface, view->x, view->y, +			view->rotation, iterator, user_data); +		break;  	case ROOTS_WL_SHELL_VIEW:  		wl_shell_surface_for_each_surface(view->wl_shell_surface, view->x,  			view->y, view->rotation, false, iterator, user_data); @@ -337,6 +372,8 @@ static bool has_standalone_surface(struct roots_view *view) {  	switch (view->type) {  	case ROOTS_XDG_SHELL_V6_VIEW:  		return wl_list_empty(&view->xdg_surface_v6->popups); +	case ROOTS_XDG_SHELL_VIEW: +		return wl_list_empty(&view->xdg_surface->popups);  	case ROOTS_WL_SHELL_VIEW:  		return wl_list_empty(&view->wl_shell_surface->popups);  #ifdef WLR_HAS_XWAYLAND diff --git a/rootston/xdg_shell.c b/rootston/xdg_shell.c new file mode 100644 index 00000000..8340de46 --- /dev/null +++ b/rootston/xdg_shell.c @@ -0,0 +1,363 @@ +#include <assert.h> +#include <stdbool.h> +#include <stdlib.h> +#include <wayland-server.h> +#include <wlr/types/wlr_box.h> +#include <wlr/types/wlr_surface.h> +#include <wlr/types/wlr_xdg_shell.h> +#include <wlr/util/log.h> +#include "rootston/desktop.h" +#include "rootston/input.h" +#include "rootston/server.h" + +static void popup_destroy(struct roots_view_child *child) { +	assert(child->destroy == popup_destroy); +	struct roots_xdg_popup *popup = (struct roots_xdg_popup *)child; +	if (popup == NULL) { +		return; +	} +	wl_list_remove(&popup->destroy.link); +	wl_list_remove(&popup->new_popup.link); +	view_child_finish(&popup->view_child); +	free(popup); +} + +static void popup_handle_destroy(struct wl_listener *listener, void *data) { +	struct roots_xdg_popup *popup = +		wl_container_of(listener, popup, destroy); +	popup_destroy((struct roots_view_child *)popup); +} + +static struct roots_xdg_popup *popup_create(struct roots_view *view, +	struct wlr_xdg_popup *wlr_popup); + +static void popup_handle_new_popup(struct wl_listener *listener, void *data) { +	struct roots_xdg_popup *popup = +		wl_container_of(listener, popup, new_popup); +	struct wlr_xdg_popup *wlr_popup = data; +	popup_create(popup->view_child.view, wlr_popup); +} + +static struct roots_xdg_popup *popup_create(struct roots_view *view, +		struct wlr_xdg_popup *wlr_popup) { +	struct roots_xdg_popup *popup = +		calloc(1, sizeof(struct roots_xdg_popup)); +	if (popup == NULL) { +		return NULL; +	} +	popup->wlr_popup = wlr_popup; +	popup->view_child.destroy = popup_destroy; +	view_child_init(&popup->view_child, view, wlr_popup->base->surface); +	popup->destroy.notify = popup_handle_destroy; +	wl_signal_add(&wlr_popup->base->events.destroy, &popup->destroy); +	popup->new_popup.notify = popup_handle_new_popup; +	wl_signal_add(&wlr_popup->base->events.new_popup, &popup->new_popup); +	return popup; +} + + +static void get_size(const struct roots_view *view, struct wlr_box *box) { +	assert(view->type == ROOTS_XDG_SHELL_VIEW); +	struct wlr_xdg_surface *surface = view->xdg_surface; + +	if (surface->geometry->width > 0 && surface->geometry->height > 0) { +		box->width = surface->geometry->width; +		box->height = surface->geometry->height; +	} else { +		box->width = view->wlr_surface->current->width; +		box->height = view->wlr_surface->current->height; +	} +} + +static void activate(struct roots_view *view, bool active) { +	assert(view->type == ROOTS_XDG_SHELL_VIEW); +	struct wlr_xdg_surface *surface = view->xdg_surface; +	if (surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) { +		wlr_xdg_toplevel_set_activated(surface, active); +	} +} + +static void apply_size_constraints(struct wlr_xdg_surface *surface, +		uint32_t width, uint32_t height, uint32_t *dest_width, +		uint32_t *dest_height) { +	*dest_width = width; +	*dest_height = height; + +	struct wlr_xdg_toplevel_state *state = &surface->toplevel_state->current; +	if (width < state->min_width) { +		*dest_width = state->min_width; +	} else if (state->max_width > 0 && +			width > state->max_width) { +		*dest_width = state->max_width; +	} +	if (height < state->min_height) { +		*dest_height = state->min_height; +	} else if (state->max_height > 0 && +			height > state->max_height) { +		*dest_height = state->max_height; +	} +} + +static void resize(struct roots_view *view, uint32_t width, uint32_t height) { +	assert(view->type == ROOTS_XDG_SHELL_VIEW); +	struct wlr_xdg_surface *surface = view->xdg_surface; +	if (surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) { +		return; +	} + +	uint32_t constrained_width, constrained_height; +	apply_size_constraints(surface, width, height, &constrained_width, +		&constrained_height); + +	wlr_xdg_toplevel_set_size(surface, constrained_width, +		constrained_height); +} + +static void move_resize(struct roots_view *view, double x, double y, +		uint32_t width, uint32_t height) { +	assert(view->type == ROOTS_XDG_SHELL_VIEW); +	struct roots_xdg_surface *roots_surface = view->roots_xdg_surface; +	struct wlr_xdg_surface *surface = view->xdg_surface; +	if (surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) { +		return; +	} + +	bool update_x = x != view->x; +	bool update_y = y != view->y; + +	uint32_t constrained_width, constrained_height; +	apply_size_constraints(surface, width, height, &constrained_width, +		&constrained_height); + +	if (update_x) { +		x = x + width - constrained_width; +	} +	if (update_y) { +		y = y + height - constrained_height; +	} + +	view->pending_move_resize.update_x = update_x; +	view->pending_move_resize.update_y = update_y; +	view->pending_move_resize.x = x; +	view->pending_move_resize.y = y; +	view->pending_move_resize.width = constrained_width; +	view->pending_move_resize.height = constrained_height; + +	uint32_t serial = wlr_xdg_toplevel_set_size(surface, constrained_width, +		constrained_height); +	if (serial > 0) { +		roots_surface->pending_move_resize_configure_serial = serial; +	} else if (roots_surface->pending_move_resize_configure_serial == 0) { +		view_update_position(view, x, y); +	} +} + +static void maximize(struct roots_view *view, bool maximized) { +	assert(view->type == ROOTS_XDG_SHELL_VIEW); +	struct wlr_xdg_surface *surface = view->xdg_surface; +	if (surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) { +		return; +	} + +	wlr_xdg_toplevel_set_maximized(surface, maximized); +} + +static void set_fullscreen(struct roots_view *view, bool fullscreen) { +	assert(view->type == ROOTS_XDG_SHELL_VIEW); +	struct wlr_xdg_surface *surface = view->xdg_surface; +	if (surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) { +		return; +	} + +	wlr_xdg_toplevel_set_fullscreen(surface, fullscreen); +} + +static void close(struct roots_view *view) { +	assert(view->type == ROOTS_XDG_SHELL_VIEW); +	struct wlr_xdg_surface *surface = view->xdg_surface; +	if (surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) { +		wlr_xdg_toplevel_send_close(surface); +	} +} + +static void handle_request_move(struct wl_listener *listener, void *data) { +	struct roots_xdg_surface *roots_xdg_surface = +		wl_container_of(listener, roots_xdg_surface, request_move); +	struct roots_view *view = roots_xdg_surface->view; +	struct roots_input *input = view->desktop->server->input; +	struct wlr_xdg_toplevel_move_event *e = data; +	struct roots_seat *seat = input_seat_from_wlr_seat(input, e->seat->seat); +	// TODO verify event serial +	if (!seat || seat->cursor->mode != ROOTS_CURSOR_PASSTHROUGH) { +		return; +	} +	roots_seat_begin_move(seat, view); +} + +static void handle_request_resize(struct wl_listener *listener, void *data) { +	struct roots_xdg_surface *roots_xdg_surface = +		wl_container_of(listener, roots_xdg_surface, request_resize); +	struct roots_view *view = roots_xdg_surface->view; +	struct roots_input *input = view->desktop->server->input; +	struct wlr_xdg_toplevel_resize_event *e = data; +	// TODO verify event serial +	struct roots_seat *seat = input_seat_from_wlr_seat(input, e->seat->seat); +	assert(seat); +	if (!seat || seat->cursor->mode != ROOTS_CURSOR_PASSTHROUGH) { +		return; +	} +	roots_seat_begin_resize(seat, view, e->edges); +} + +static void handle_request_maximize(struct wl_listener *listener, void *data) { +	struct roots_xdg_surface *roots_xdg_surface = +		wl_container_of(listener, roots_xdg_surface, request_maximize); +	struct roots_view *view = roots_xdg_surface->view; +	struct wlr_xdg_surface *surface = view->xdg_surface; + +	if (surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) { +		return; +	} + +	view_maximize(view, surface->toplevel_state->next.maximized); +} + +static void handle_request_fullscreen(struct wl_listener *listener, +		void *data) { +	struct roots_xdg_surface *roots_xdg_surface = +		wl_container_of(listener, roots_xdg_surface, request_fullscreen); +	struct roots_view *view = roots_xdg_surface->view; +	struct wlr_xdg_surface *surface = view->xdg_surface; +	struct wlr_xdg_toplevel_set_fullscreen_event *e = data; + +	if (surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) { +		return; +	} + +	view_set_fullscreen(view, e->fullscreen, e->output); +} + +static void handle_surface_commit(struct wl_listener *listener, void *data) { +	struct roots_xdg_surface *roots_surface = +		wl_container_of(listener, roots_surface, surface_commit); +	struct roots_view *view = roots_surface->view; +	struct wlr_xdg_surface *surface = view->xdg_surface; + +	view_apply_damage(view); + +	struct wlr_box size; +	get_size(view, &size); +	view_update_size(view, size.width, size.height); + +	uint32_t pending_serial = +		roots_surface->pending_move_resize_configure_serial; +	if (pending_serial > 0 && pending_serial >= surface->configure_serial) { +		double x = view->x; +		double y = view->y; +		if (view->pending_move_resize.update_x) { +			x = view->pending_move_resize.x + view->pending_move_resize.width - +				size.width; +		} +		if (view->pending_move_resize.update_y) { +			y = view->pending_move_resize.y + view->pending_move_resize.height - +				size.height; +		} +		view_update_position(view, x, y); + +		if (pending_serial == surface->configure_serial) { +			roots_surface->pending_move_resize_configure_serial = 0; +		} +	} +} + +static void handle_new_popup(struct wl_listener *listener, void *data) { +	struct roots_xdg_surface *roots_xdg_surface = +		wl_container_of(listener, roots_xdg_surface, new_popup); +	struct wlr_xdg_popup *wlr_popup = data; +	popup_create(roots_xdg_surface->view, wlr_popup); +} + +static void handle_destroy(struct wl_listener *listener, void *data) { +	struct roots_xdg_surface *roots_xdg_surface = +		wl_container_of(listener, roots_xdg_surface, destroy); +	wl_list_remove(&roots_xdg_surface->surface_commit.link); +	wl_list_remove(&roots_xdg_surface->destroy.link); +	wl_list_remove(&roots_xdg_surface->new_popup.link); +	wl_list_remove(&roots_xdg_surface->request_move.link); +	wl_list_remove(&roots_xdg_surface->request_resize.link); +	wl_list_remove(&roots_xdg_surface->request_maximize.link); +	wl_list_remove(&roots_xdg_surface->request_fullscreen.link); +	wl_list_remove(&roots_xdg_surface->view->link); +	view_finish(roots_xdg_surface->view); +	free(roots_xdg_surface->view); +	free(roots_xdg_surface); +} + +void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { +	struct wlr_xdg_surface *surface = data; +	assert(surface->role != WLR_XDG_SURFACE_ROLE_NONE); + +	if (surface->role == WLR_XDG_SURFACE_ROLE_POPUP) { +		wlr_log(L_DEBUG, "new xdg popup"); +		return; +	} + +	struct roots_desktop *desktop = +		wl_container_of(listener, desktop, xdg_shell_surface); + +	wlr_log(L_DEBUG, "new xdg toplevel: title=%s, app_id=%s", +		surface->title, surface->app_id); +	wlr_xdg_surface_ping(surface); + +	struct roots_xdg_surface *roots_surface = +		calloc(1, sizeof(struct roots_xdg_surface)); +	if (!roots_surface) { +		return; +	} +	roots_surface->surface_commit.notify = handle_surface_commit; +	wl_signal_add(&surface->surface->events.commit, +		&roots_surface->surface_commit); +	roots_surface->destroy.notify = handle_destroy; +	wl_signal_add(&surface->events.destroy, &roots_surface->destroy); +	roots_surface->request_move.notify = handle_request_move; +	wl_signal_add(&surface->events.request_move, &roots_surface->request_move); +	roots_surface->request_resize.notify = handle_request_resize; +	wl_signal_add(&surface->events.request_resize, +		&roots_surface->request_resize); +	roots_surface->request_maximize.notify = handle_request_maximize; +	wl_signal_add(&surface->events.request_maximize, +		&roots_surface->request_maximize); +	roots_surface->request_fullscreen.notify = handle_request_fullscreen; +	wl_signal_add(&surface->events.request_fullscreen, +		&roots_surface->request_fullscreen); +	roots_surface->new_popup.notify = handle_new_popup; +	wl_signal_add(&surface->events.new_popup, &roots_surface->new_popup); + +	struct roots_view *view = calloc(1, sizeof(struct roots_view)); +	if (!view) { +		free(roots_surface); +		return; +	} +	view->type = ROOTS_XDG_SHELL_VIEW; + +	view->xdg_surface = surface; +	view->roots_xdg_surface = roots_surface; +	view->wlr_surface = surface->surface; +	view->activate = activate; +	view->resize = resize; +	view->move_resize = move_resize; +	view->maximize = maximize; +	view->set_fullscreen = set_fullscreen; +	view->close = close; +	roots_surface->view = view; + +	struct wlr_box box; +	get_size(view, &box); +	view->width = box.width; +	view->height = box.height; + +	view_init(view, desktop); +	wl_list_insert(&desktop->views, &view->link); + +	view_setup(view); +} | 
