mirror of
https://gitlab.freedesktop.org/wayland/weston
synced 2024-10-15 15:31:41 +00:00
shell: Reorganise set/unset methods for fullscreen/maximize/popup/transient
Move them to be next to each other, and standardise the naming scheme so they’re more greppable. This should make maintenance easier.
This commit is contained in:
parent
becf5a342f
commit
becb77e211
420
src/shell.c
420
src/shell.c
|
@ -366,6 +366,9 @@ surface_rotate(struct shell_surface *surface, struct weston_seat *seat);
|
|||
static void
|
||||
shell_fade_startup(struct desktop_shell *shell);
|
||||
|
||||
static struct shell_seat *
|
||||
get_shell_seat(struct weston_seat *seat);
|
||||
|
||||
static bool
|
||||
shell_surface_is_top_fullscreen(struct shell_surface *shsurf)
|
||||
{
|
||||
|
@ -2010,124 +2013,26 @@ restore_all_output_modes(struct weston_compositor *compositor)
|
|||
restore_output_mode(output);
|
||||
}
|
||||
|
||||
static void
|
||||
shell_unset_fullscreen(struct shell_surface *shsurf)
|
||||
{
|
||||
struct workspace *ws;
|
||||
/* undo all fullscreen things here */
|
||||
if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
|
||||
shell_surface_is_top_fullscreen(shsurf)) {
|
||||
restore_output_mode(shsurf->fullscreen_output);
|
||||
}
|
||||
shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
|
||||
shsurf->fullscreen.framerate = 0;
|
||||
wl_list_remove(&shsurf->fullscreen.transform.link);
|
||||
wl_list_init(&shsurf->fullscreen.transform.link);
|
||||
if (shsurf->fullscreen.black_view)
|
||||
weston_surface_destroy(shsurf->fullscreen.black_view->surface);
|
||||
shsurf->fullscreen.black_view = NULL;
|
||||
shsurf->fullscreen_output = NULL;
|
||||
weston_view_set_position(shsurf->view,
|
||||
shsurf->saved_x, shsurf->saved_y);
|
||||
if (shsurf->saved_rotation_valid) {
|
||||
wl_list_insert(&shsurf->view->geometry.transformation_list,
|
||||
&shsurf->rotation.transform.link);
|
||||
shsurf->saved_rotation_valid = false;
|
||||
}
|
||||
|
||||
ws = get_current_workspace(shsurf->shell);
|
||||
wl_list_remove(&shsurf->view->layer_link);
|
||||
wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link);
|
||||
}
|
||||
|
||||
static void
|
||||
shell_unset_maximized(struct shell_surface *shsurf)
|
||||
{
|
||||
struct workspace *ws;
|
||||
/* undo all maximized things here */
|
||||
shsurf->output = get_default_output(shsurf->surface->compositor);
|
||||
weston_view_set_position(shsurf->view,
|
||||
shsurf->saved_x,
|
||||
shsurf->saved_y);
|
||||
|
||||
if (shsurf->saved_rotation_valid) {
|
||||
wl_list_insert(&shsurf->view->geometry.transformation_list,
|
||||
&shsurf->rotation.transform.link);
|
||||
shsurf->saved_rotation_valid = false;
|
||||
}
|
||||
|
||||
ws = get_current_workspace(shsurf->shell);
|
||||
wl_list_remove(&shsurf->view->layer_link);
|
||||
wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link);
|
||||
}
|
||||
|
||||
static int
|
||||
reset_shell_surface_type(struct shell_surface *surface)
|
||||
get_output_panel_height(struct desktop_shell *shell,
|
||||
struct weston_output *output)
|
||||
{
|
||||
switch (surface->type) {
|
||||
case SHELL_SURFACE_FULLSCREEN:
|
||||
shell_unset_fullscreen(surface);
|
||||
break;
|
||||
case SHELL_SURFACE_MAXIMIZED:
|
||||
shell_unset_maximized(surface);
|
||||
break;
|
||||
case SHELL_SURFACE_NONE:
|
||||
case SHELL_SURFACE_TOPLEVEL:
|
||||
case SHELL_SURFACE_TRANSIENT:
|
||||
case SHELL_SURFACE_POPUP:
|
||||
case SHELL_SURFACE_XWAYLAND:
|
||||
break;
|
||||
}
|
||||
struct weston_view *view;
|
||||
int panel_height = 0;
|
||||
|
||||
surface->type = SHELL_SURFACE_NONE;
|
||||
if (!output)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
set_surface_type(struct shell_surface *shsurf)
|
||||
{
|
||||
struct weston_surface *pes = shsurf->parent;
|
||||
struct weston_view *pev = get_default_view(pes);
|
||||
|
||||
reset_shell_surface_type(shsurf);
|
||||
|
||||
shsurf->type = shsurf->next_type;
|
||||
shsurf->next_type = SHELL_SURFACE_NONE;
|
||||
|
||||
switch (shsurf->type) {
|
||||
case SHELL_SURFACE_TOPLEVEL:
|
||||
break;
|
||||
case SHELL_SURFACE_TRANSIENT:
|
||||
if (pev)
|
||||
weston_view_set_position(shsurf->view,
|
||||
pev->geometry.x + shsurf->transient.x,
|
||||
pev->geometry.y + shsurf->transient.y);
|
||||
break;
|
||||
|
||||
case SHELL_SURFACE_MAXIMIZED:
|
||||
case SHELL_SURFACE_FULLSCREEN:
|
||||
shsurf->saved_x = shsurf->view->geometry.x;
|
||||
shsurf->saved_y = shsurf->view->geometry.y;
|
||||
shsurf->saved_position_valid = true;
|
||||
|
||||
if (!wl_list_empty(&shsurf->rotation.transform.link)) {
|
||||
wl_list_remove(&shsurf->rotation.transform.link);
|
||||
wl_list_init(&shsurf->rotation.transform.link);
|
||||
weston_view_geometry_dirty(shsurf->view);
|
||||
shsurf->saved_rotation_valid = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case SHELL_SURFACE_XWAYLAND:
|
||||
weston_view_set_position(shsurf->view, shsurf->transient.x,
|
||||
shsurf->transient.y);
|
||||
break;
|
||||
|
||||
default:
|
||||
wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) {
|
||||
if (view->surface->output == output) {
|
||||
panel_height = view->geometry.height;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return panel_height;
|
||||
}
|
||||
|
||||
static void
|
||||
set_toplevel(struct shell_surface *shsurf)
|
||||
{
|
||||
|
@ -2168,46 +2073,123 @@ shell_surface_set_transient(struct wl_client *client,
|
|||
set_transient(shsurf, parent, x, y, flags);
|
||||
}
|
||||
|
||||
static struct desktop_shell *
|
||||
shell_surface_get_shell(struct shell_surface *shsurf)
|
||||
{
|
||||
return shsurf->shell;
|
||||
}
|
||||
|
||||
static int
|
||||
get_output_panel_height(struct desktop_shell *shell,
|
||||
static void
|
||||
set_fullscreen(struct shell_surface *shsurf,
|
||||
uint32_t method,
|
||||
uint32_t framerate,
|
||||
struct weston_output *output)
|
||||
{
|
||||
struct weston_view *view;
|
||||
int panel_height = 0;
|
||||
struct weston_surface *es = shsurf->surface;
|
||||
|
||||
if (!output)
|
||||
return 0;
|
||||
if (output)
|
||||
shsurf->output = output;
|
||||
else if (es->output)
|
||||
shsurf->output = es->output;
|
||||
else
|
||||
shsurf->output = get_default_output(es->compositor);
|
||||
|
||||
wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) {
|
||||
if (view->surface->output == output) {
|
||||
panel_height = view->geometry.height;
|
||||
break;
|
||||
}
|
||||
}
|
||||
shsurf->fullscreen_output = shsurf->output;
|
||||
shsurf->fullscreen.type = method;
|
||||
shsurf->fullscreen.framerate = framerate;
|
||||
shsurf->next_type = SHELL_SURFACE_FULLSCREEN;
|
||||
|
||||
return panel_height;
|
||||
shsurf->client->send_configure(shsurf->surface, 0,
|
||||
shsurf->output->width,
|
||||
shsurf->output->height);
|
||||
}
|
||||
|
||||
static void
|
||||
shell_surface_set_maximized(struct wl_client *client,
|
||||
unset_fullscreen(struct shell_surface *shsurf)
|
||||
{
|
||||
struct workspace *ws;
|
||||
/* undo all fullscreen things here */
|
||||
if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
|
||||
shell_surface_is_top_fullscreen(shsurf)) {
|
||||
restore_output_mode(shsurf->fullscreen_output);
|
||||
}
|
||||
shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
|
||||
shsurf->fullscreen.framerate = 0;
|
||||
wl_list_remove(&shsurf->fullscreen.transform.link);
|
||||
wl_list_init(&shsurf->fullscreen.transform.link);
|
||||
if (shsurf->fullscreen.black_view)
|
||||
weston_surface_destroy(shsurf->fullscreen.black_view->surface);
|
||||
shsurf->fullscreen.black_view = NULL;
|
||||
shsurf->fullscreen_output = NULL;
|
||||
weston_view_set_position(shsurf->view,
|
||||
shsurf->saved_x, shsurf->saved_y);
|
||||
if (shsurf->saved_rotation_valid) {
|
||||
wl_list_insert(&shsurf->view->geometry.transformation_list,
|
||||
&shsurf->rotation.transform.link);
|
||||
shsurf->saved_rotation_valid = false;
|
||||
}
|
||||
|
||||
ws = get_current_workspace(shsurf->shell);
|
||||
wl_list_remove(&shsurf->view->layer_link);
|
||||
wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link);
|
||||
}
|
||||
|
||||
static void
|
||||
shell_surface_set_fullscreen(struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
uint32_t method,
|
||||
uint32_t framerate,
|
||||
struct wl_resource *output_resource)
|
||||
{
|
||||
struct shell_surface *shsurf = wl_resource_get_user_data(resource);
|
||||
struct weston_surface *es = shsurf->surface;
|
||||
struct desktop_shell *shell = NULL;
|
||||
struct weston_output *output;
|
||||
|
||||
if (output_resource)
|
||||
output = wl_resource_get_user_data(output_resource);
|
||||
else
|
||||
output = NULL;
|
||||
|
||||
set_fullscreen(shsurf, method, framerate, output);
|
||||
}
|
||||
|
||||
static void
|
||||
set_popup(struct shell_surface *shsurf,
|
||||
struct weston_surface *parent,
|
||||
struct weston_seat *seat,
|
||||
uint32_t serial,
|
||||
int32_t x,
|
||||
int32_t y)
|
||||
{
|
||||
shsurf->type = SHELL_SURFACE_POPUP;
|
||||
shsurf->parent = parent;
|
||||
shsurf->popup.shseat = get_shell_seat(seat);
|
||||
shsurf->popup.serial = serial;
|
||||
shsurf->popup.x = x;
|
||||
shsurf->popup.y = y;
|
||||
}
|
||||
|
||||
static void
|
||||
shell_surface_set_popup(struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
struct wl_resource *seat_resource,
|
||||
uint32_t serial,
|
||||
struct wl_resource *parent_resource,
|
||||
int32_t x, int32_t y, uint32_t flags)
|
||||
{
|
||||
struct shell_surface *shsurf = wl_resource_get_user_data(resource);
|
||||
|
||||
set_popup(shsurf,
|
||||
wl_resource_get_user_data(parent_resource),
|
||||
wl_resource_get_user_data(seat_resource),
|
||||
serial, x, y);
|
||||
}
|
||||
|
||||
static void
|
||||
set_maximized(struct shell_surface *shsurf,
|
||||
struct weston_output *output)
|
||||
{
|
||||
struct desktop_shell *shell;
|
||||
uint32_t edges = 0, panel_height = 0;
|
||||
struct weston_surface *es = shsurf->surface;
|
||||
|
||||
/* get the default output, if the client set it as NULL
|
||||
check whether the ouput is available */
|
||||
if (output_resource)
|
||||
shsurf->output = wl_resource_get_user_data(output_resource);
|
||||
if (output)
|
||||
shsurf->output = output;
|
||||
else if (es->output)
|
||||
shsurf->output = es->output;
|
||||
else
|
||||
|
@ -2224,6 +2206,117 @@ shell_surface_set_maximized(struct wl_client *client,
|
|||
shsurf->next_type = SHELL_SURFACE_MAXIMIZED;
|
||||
}
|
||||
|
||||
static void
|
||||
unset_maximized(struct shell_surface *shsurf)
|
||||
{
|
||||
struct workspace *ws;
|
||||
|
||||
/* undo all maximized things here */
|
||||
shsurf->output = get_default_output(shsurf->surface->compositor);
|
||||
weston_view_set_position(shsurf->view,
|
||||
shsurf->saved_x,
|
||||
shsurf->saved_y);
|
||||
|
||||
if (shsurf->saved_rotation_valid) {
|
||||
wl_list_insert(&shsurf->view->geometry.transformation_list,
|
||||
&shsurf->rotation.transform.link);
|
||||
shsurf->saved_rotation_valid = false;
|
||||
}
|
||||
|
||||
ws = get_current_workspace(shsurf->shell);
|
||||
wl_list_remove(&shsurf->view->layer_link);
|
||||
wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link);
|
||||
}
|
||||
|
||||
static void
|
||||
shell_surface_set_maximized(struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
struct wl_resource *output_resource)
|
||||
{
|
||||
struct shell_surface *shsurf = wl_resource_get_user_data(resource);
|
||||
struct weston_output *output;
|
||||
|
||||
if (output_resource)
|
||||
output = wl_resource_get_user_data(output_resource);
|
||||
else
|
||||
output = NULL;
|
||||
|
||||
set_maximized(shsurf, output);
|
||||
}
|
||||
|
||||
static int
|
||||
reset_surface_type(struct shell_surface *surface)
|
||||
{
|
||||
switch (surface->type) {
|
||||
case SHELL_SURFACE_FULLSCREEN:
|
||||
unset_fullscreen(surface);
|
||||
break;
|
||||
case SHELL_SURFACE_MAXIMIZED:
|
||||
unset_maximized(surface);
|
||||
break;
|
||||
case SHELL_SURFACE_NONE:
|
||||
case SHELL_SURFACE_TOPLEVEL:
|
||||
case SHELL_SURFACE_TRANSIENT:
|
||||
case SHELL_SURFACE_POPUP:
|
||||
case SHELL_SURFACE_XWAYLAND:
|
||||
break;
|
||||
}
|
||||
|
||||
surface->type = SHELL_SURFACE_NONE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
set_surface_type(struct shell_surface *shsurf)
|
||||
{
|
||||
struct weston_surface *pes = shsurf->parent;
|
||||
struct weston_view *pev = get_default_view(pes);
|
||||
|
||||
reset_surface_type(shsurf);
|
||||
|
||||
shsurf->type = shsurf->next_type;
|
||||
shsurf->next_type = SHELL_SURFACE_NONE;
|
||||
|
||||
switch (shsurf->type) {
|
||||
case SHELL_SURFACE_TOPLEVEL:
|
||||
break;
|
||||
case SHELL_SURFACE_TRANSIENT:
|
||||
if (pev)
|
||||
weston_view_set_position(shsurf->view,
|
||||
pev->geometry.x + shsurf->transient.x,
|
||||
pev->geometry.y + shsurf->transient.y);
|
||||
break;
|
||||
|
||||
case SHELL_SURFACE_MAXIMIZED:
|
||||
case SHELL_SURFACE_FULLSCREEN:
|
||||
shsurf->saved_x = shsurf->view->geometry.x;
|
||||
shsurf->saved_y = shsurf->view->geometry.y;
|
||||
shsurf->saved_position_valid = true;
|
||||
|
||||
if (!wl_list_empty(&shsurf->rotation.transform.link)) {
|
||||
wl_list_remove(&shsurf->rotation.transform.link);
|
||||
wl_list_init(&shsurf->rotation.transform.link);
|
||||
weston_view_geometry_dirty(shsurf->view);
|
||||
shsurf->saved_rotation_valid = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case SHELL_SURFACE_XWAYLAND:
|
||||
weston_view_set_position(shsurf->view, shsurf->transient.x,
|
||||
shsurf->transient.y);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static struct desktop_shell *
|
||||
shell_surface_get_shell(struct shell_surface *shsurf)
|
||||
{
|
||||
return shsurf->shell;
|
||||
}
|
||||
|
||||
static void
|
||||
black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height);
|
||||
|
||||
|
@ -2397,49 +2490,6 @@ shell_map_fullscreen(struct shell_surface *shsurf)
|
|||
shell_configure_fullscreen(shsurf);
|
||||
}
|
||||
|
||||
static void
|
||||
set_fullscreen(struct shell_surface *shsurf,
|
||||
uint32_t method,
|
||||
uint32_t framerate,
|
||||
struct weston_output *output)
|
||||
{
|
||||
struct weston_surface *es = shsurf->surface;
|
||||
|
||||
if (output)
|
||||
shsurf->output = output;
|
||||
else if (es->output)
|
||||
shsurf->output = es->output;
|
||||
else
|
||||
shsurf->output = get_default_output(es->compositor);
|
||||
|
||||
shsurf->fullscreen_output = shsurf->output;
|
||||
shsurf->fullscreen.type = method;
|
||||
shsurf->fullscreen.framerate = framerate;
|
||||
shsurf->next_type = SHELL_SURFACE_FULLSCREEN;
|
||||
|
||||
shsurf->client->send_configure(shsurf->surface, 0,
|
||||
shsurf->output->width,
|
||||
shsurf->output->height);
|
||||
}
|
||||
|
||||
static void
|
||||
shell_surface_set_fullscreen(struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
uint32_t method,
|
||||
uint32_t framerate,
|
||||
struct wl_resource *output_resource)
|
||||
{
|
||||
struct shell_surface *shsurf = wl_resource_get_user_data(resource);
|
||||
struct weston_output *output;
|
||||
|
||||
if (output_resource)
|
||||
output = wl_resource_get_user_data(output_resource);
|
||||
else
|
||||
output = NULL;
|
||||
|
||||
set_fullscreen(shsurf, method, framerate, output);
|
||||
}
|
||||
|
||||
static void
|
||||
set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags)
|
||||
{
|
||||
|
@ -2679,24 +2729,6 @@ shell_map_popup(struct shell_surface *shsurf)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
shell_surface_set_popup(struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
struct wl_resource *seat_resource,
|
||||
uint32_t serial,
|
||||
struct wl_resource *parent_resource,
|
||||
int32_t x, int32_t y, uint32_t flags)
|
||||
{
|
||||
struct shell_surface *shsurf = wl_resource_get_user_data(resource);
|
||||
|
||||
shsurf->type = SHELL_SURFACE_POPUP;
|
||||
shsurf->parent = wl_resource_get_user_data(parent_resource);
|
||||
shsurf->popup.shseat = get_shell_seat(wl_resource_get_user_data(seat_resource));
|
||||
shsurf->popup.serial = serial;
|
||||
shsurf->popup.x = x;
|
||||
shsurf->popup.y = y;
|
||||
}
|
||||
|
||||
static const struct wl_shell_surface_interface shell_surface_implementation = {
|
||||
shell_surface_pong,
|
||||
shell_surface_move,
|
||||
|
|
Loading…
Reference in a new issue