Commit 26ef9fc0 authored by Sebastian Krzyszkowiak's avatar Sebastian Krzyszkowiak Committed by Guido Gunther
Browse files

Take view geometry into account when dealing with saved state

We're interested in restoring the actual window into the same
position, regardless of whether the shadows around it happened
to change their size meanwhile.
parent d9835ac2
......@@ -255,6 +255,8 @@ void roots_cursor_update_position(struct roots_cursor *cursor,
case ROOTS_CURSOR_MOVE:
view = roots_seat_get_focus(seat);
if (view != NULL) {
struct wlr_box geom;
view_get_geometry(view, &geom);
double dx = cursor->cursor->x - cursor->offs_x;
double dy = cursor->cursor->y - cursor->offs_y;
......@@ -271,13 +273,16 @@ void roots_cursor_update_position(struct roots_cursor *cursor,
view_tile(view, PHOC_VIEW_TILE_RIGHT, wlr_output);
} else {
view_restore(view);
view_move(view, cursor->view_x + dx, cursor->view_y + dy);
view_move(view, cursor->view_x + dx - geom.x * view->scale,
cursor->view_y + dy - geom.y * view->scale);
}
}
break;
case ROOTS_CURSOR_RESIZE:
view = roots_seat_get_focus(seat);
if (view != NULL) {
struct wlr_box geom;
view_get_geometry(view, &geom);
double dx = cursor->cursor->x - cursor->offs_x;
double dy = cursor->cursor->y - cursor->offs_y;
double x = view->box.x;
......@@ -285,7 +290,7 @@ void roots_cursor_update_position(struct roots_cursor *cursor,
int width = cursor->view_width;
int height = cursor->view_height;
if (cursor->resize_edges & WLR_EDGE_TOP) {
y = cursor->view_y + dy;
y = cursor->view_y + dy - geom.y * view->scale;
height -= dy;
if (height < 1) {
y += height;
......@@ -294,7 +299,7 @@ void roots_cursor_update_position(struct roots_cursor *cursor,
height += dy;
}
if (cursor->resize_edges & WLR_EDGE_LEFT) {
x = cursor->view_x + dx;
x = cursor->view_x + dx - geom.x * view->scale;
width -= dx;
if (width < 1) {
x += width;
......
......@@ -1619,6 +1619,8 @@ void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view) {
cursor->mode = ROOTS_CURSOR_MOVE;
cursor->offs_x = cursor->cursor->x;
cursor->offs_y = cursor->cursor->y;
struct wlr_box geom;
view_get_geometry(view, &geom);
if (view_is_maximized(view) || view_is_tiled(view)) {
// calculate normalized (0..1) position of cursor in maximized window
// and make it stay the same after restoring saved size
......@@ -1630,8 +1632,8 @@ void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view) {
view->saved.y = cursor->view_y;
view_restore(view);
} else {
cursor->view_x = view->box.x;
cursor->view_y = view->box.y;
cursor->view_x = view->box.x + geom.x * view->scale;
cursor->view_y = view->box.y + geom.y * view->scale;
}
wlr_seat_pointer_clear_focus(seat->seat);
......@@ -1647,16 +1649,18 @@ void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view,
cursor->mode = ROOTS_CURSOR_RESIZE;
cursor->offs_x = cursor->cursor->x;
cursor->offs_y = cursor->cursor->y;
struct wlr_box geom;
view_get_geometry(view, &geom);
if (view_is_maximized(view) || view_is_tiled(view)) {
view->saved.x = view->box.x;
view->saved.y = view->box.y;
view->saved.x = view->box.x + geom.x * view->scale;
view->saved.y = view->box.y + geom.y * view->scale;
view->saved.width = view->box.width;
view->saved.height = view->box.height;
view_restore(view);
}
cursor->view_x = view->box.x;
cursor->view_y = view->box.y;
cursor->view_x = view->box.x + geom.x * view->scale;
cursor->view_y = view->box.y + geom.y * view->scale;
struct wlr_box box;
view_get_box(view, &box);
cursor->view_width = box.width;
......
......@@ -199,8 +199,10 @@ view_save(struct roots_view *view)
return;
/* backup window state */
view->saved.x = view->box.x;
view->saved.y = view->box.y;
struct wlr_box geom;
view_get_geometry(view, &geom);
view->saved.x = view->box.x + geom.x * view->scale;
view->saved.y = view->box.y + geom.y * view->scale;
view->saved.width = view->box.width;
view->saved.height = view->box.height;
}
......@@ -403,8 +405,11 @@ view_restore(struct roots_view *view)
if (want_auto_maximize (view))
return;
struct wlr_box geom;
view_get_geometry(view, &geom);
view->state = PHOC_VIEW_STATE_NORMAL;
view_move_resize (view, view->saved.x, view->saved.y,
view_move_resize (view, view->saved.x - geom.x * view->scale, view->saved.y - geom.y * view->scale,
view->saved.width, view->saved.height);
if (view->toplevel_handle)
......@@ -431,6 +436,9 @@ void view_set_fullscreen(struct roots_view *view, bool fullscreen,
}
}
struct wlr_box view_geom;
view_get_geometry(view, &view_geom);
if (fullscreen) {
if (output == NULL) {
output = view_get_output(view);
......@@ -472,7 +480,7 @@ void view_set_fullscreen(struct roots_view *view, bool fullscreen,
} else if (view->state == PHOC_VIEW_STATE_TILED) {
view_arrange_tiled (view, phoc_output->wlr_output);
} else {
view_move_resize(view, view->saved.x, view->saved.y,
view_move_resize(view, view->saved.x - view_geom.x * view->scale, view->saved.y - view_geom.y * view->scale,
view->saved.width, view->saved.height);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment