Discussion:
[writing a compositor] Window does not return to previous position on unmaximize
adlo
2018-09-24 03:32:18 UTC
Permalink
I am writing a compositor using libweston. When unmaximizing a window,
the window doesn't return to the position it was at before it was
maximized. How can I resolve this?

Here is my code:

static void
set_maximized_position (struct ShellSurface *shsurf)
{
pixman_rectangle32_t area;
struct weston_geometry geometry;

area.x = shsurf->surface->output->x;
area.y = shsurf->surface->output->y;

geometry = weston_desktop_surface_get_geometry(shsurf-
desktop_surface);
weston_view_set_position(shsurf->view,
area.x - geometry.x,
area.y - geometry.y);
}

static void
map(struct TestServer *shell, struct ShellSurface *shsurf,
int32_t sx, int32_t sy)
{
if (shsurf->maximized)
set_maximized_position (shsurf);
weston_view_update_transform(shsurf->view);

}

static void
desktop_surface_committed(struct weston_desktop_surface
*desktop_surface,
int32_t sx, int32_t sy, void *data)
{
struct ShellSurface *shsurf =
weston_desktop_surface_get_user_data(desktop_surface);
struct weston_surface *surface =
weston_desktop_surface_get_surface(desktop_surface);
struct weston_view *view = shsurf->view;
struct TestServer *shell = data;
bool was_fullscreen;
bool was_maximized;

if (surface->width == 0)
return;

was_maximized = shsurf->maximized;

shsurf->maximized =
weston_desktop_surface_get_maximized (desktop_surface);

if (!weston_surface_is_mapped(surface))
map(shell, shsurf, sx, sy);

if (was_maximized == shsurf->maximized)
return;

if (was_maximized)
unset_maximized (shsurf);

if (shsurf->maximized && !shsurf->saved_position_valid)
{

shsurf->saved_x = shsurf->view->geometry.x;
shsurf->saved_y = shsurf->view->geometry.y;
shsurf->saved_position_valid = true;
}

weston_view_set_position (shsurf->view,
shsurf->saved_x, shsurf->saved_y);

if (shsurf->maximized)
set_maximized_position (shsurf);

}

An earlier version of the rest of my code can be found at:

https://github.com/adlocode/test-libweston-desktop/blob/master/shell.c

Regards

adlo
adlo
2018-09-25 03:41:35 UTC
Permalink
Here is some more code that I forgot to include:

static void
unset_maximized(struct ShellSurface *shsurf)
{
struct weston_surface *surface =
weston_desktop_surface_get_surface(shsurf-
desktop_surface);
if (shsurf->saved_position_valid)
weston_view_set_position(shsurf->view,
shsurf->saved_x, shsurf-
saved_y);
shsurf->saved_position_valid = false;
}

Regards

adlo
I am writing a compositor using libweston. When unmaximizing a
window,
the window doesn't return to the position it was at before it was
maximized. How can I resolve this?
static void
set_maximized_position (struct ShellSurface *shsurf)
{
pixman_rectangle32_t area;
struct weston_geometry geometry;
area.x = shsurf->surface->output->x;
area.y = shsurf->surface->output->y;
geometry = weston_desktop_surface_get_geometry(shsurf-
desktop_surface);
weston_view_set_position(shsurf->view,
area.x - geometry.x,
area.y - geometry.y);
}
static void
map(struct TestServer *shell, struct ShellSurface *shsurf,
int32_t sx, int32_t sy)
{
if (shsurf->maximized)
set_maximized_position (shsurf);
weston_view_update_transform(shsurf->view);
}
static void
desktop_surface_committed(struct weston_desktop_surface
*desktop_surface,
int32_t sx, int32_t sy, void *data)
{
struct ShellSurface *shsurf =
weston_desktop_surface_get_user_data(desktop_surface);
struct weston_surface *surface =
weston_desktop_surface_get_surface(desktop_surface);
struct weston_view *view = shsurf->view;
struct TestServer *shell = data;
bool was_fullscreen;
bool was_maximized;
if (surface->width == 0)
return;
was_maximized = shsurf->maximized;
shsurf->maximized =
weston_desktop_surface_get_maximized (desktop_surface);
if (!weston_surface_is_mapped(surface))
map(shell, shsurf, sx, sy);
if (was_maximized == shsurf->maximized)
return;
if (was_maximized)
unset_maximized (shsurf);
if (shsurf->maximized && !shsurf->saved_position_valid)
{
shsurf->saved_x = shsurf->view->geometry.x;
shsurf->saved_y = shsurf->view->geometry.y;
shsurf->saved_position_valid = true;
}
weston_view_set_position (shsurf->view,
shsurf->saved_x, shsurf->saved_y);
if (shsurf->maximized)
set_maximized_position (shsurf);
}
https://github.com/adlocode/test-libweston-desktop/blob/master/shell.c
Regards
adlo
adlo
2018-10-11 06:31:33 UTC
Permalink
As far as I can tell my code looks the same as Weston's code. What might I be doing differently that results in the windows not returning to their original position?

Regards

adlo
Post by adlo
static void
unset_maximized(struct ShellSurface *shsurf)
{
struct weston_surface *surface =
weston_desktop_surface_get_surface(shsurf-
desktop_surface);
if (shsurf->saved_position_valid)
weston_view_set_position(shsurf->view,
shsurf->saved_x, shsurf-
saved_y);
shsurf->saved_position_valid = false;
}
Regards
adlo
I am writing a compositor using libweston. When unmaximizing a window,
the window doesn't return to the position it was at before it was
maximized. How can I resolve this?
static void
set_maximized_position (struct ShellSurface *shsurf)
{
pixman_rectangle32_t area;
struct weston_geometry geometry;
area.x = shsurf->surface->output->x;
area.y = shsurf->surface->output->y;
geometry = weston_desktop_surface_get_geometry(shsurf-
desktop_surface);
weston_view_set_position(shsurf->view,
area.x - geometry.x,
area.y - geometry.y);
}
static void
map(struct TestServer *shell, struct ShellSurface *shsurf,
int32_t sx, int32_t sy)
{
if (shsurf->maximized)
set_maximized_position (shsurf);
weston_view_update_transform(shsurf->view);
}
static void
desktop_surface_committed(struct weston_desktop_surface
*desktop_surface,
int32_t sx, int32_t sy, void *data)
{
struct ShellSurface *shsurf =
weston_desktop_surface_get_user_data(desktop_surface);
struct weston_surface *surface =
weston_desktop_surface_get_surface(desktop_surface);
struct weston_view *view = shsurf->view;
struct TestServer *shell = data;
bool was_fullscreen;
bool was_maximized;
if (surface->width == 0)
return;
was_maximized = shsurf->maximized;
shsurf->maximized =
weston_desktop_surface_get_maximized (desktop_surface);
if (!weston_surface_is_mapped(surface))
map(shell, shsurf, sx, sy);
if (was_maximized == shsurf->maximized)
return;
if (was_maximized)
unset_maximized (shsurf);
if (shsurf->maximized && !shsurf->saved_position_valid)
{
shsurf->saved_x = shsurf->view->geometry.x;
shsurf->saved_y = shsurf->view->geometry.y;
shsurf->saved_position_valid = true;
}
weston_view_set_position (shsurf->view,
shsurf->saved_x, shsurf->saved_y);
if (shsurf->maximized)
set_maximized_position (shsurf);
}
https://github.com/adlocode/test-libweston-desktop/blob/master/shell.c
Regards
adlo
Loading...