[PATCH 3/3 weston] Implement optional resize-from-center mode.
Scott Moreau
oreaus at gmail.com
Fri Nov 9 00:11:32 PST 2012
---
clients/window.c | 15 ++++++++++-----
src/shell.c | 40 +++++++++++++++++++++++++++++++---------
weston.ini | 1 +
3 files changed, 42 insertions(+), 14 deletions(-)
diff --git a/clients/window.c b/clients/window.c
index 9a11571..6468e85 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -342,9 +342,7 @@ enum window_location {
WINDOW_RESIZING_TOP_RIGHT = 9,
WINDOW_RESIZING_BOTTOM_RIGHT = 10,
WINDOW_RESIZING_MASK = 15,
- WINDOW_EXTERIOR = 16,
- WINDOW_TITLEBAR = 17,
- WINDOW_CLIENT_AREA = 18,
+ WINDOW_RESIZING_FROM_CENTER = 16,
};
static const cairo_user_data_key_t surface_data_key;
@@ -803,12 +801,19 @@ display_get_pointer_image(struct display *display, int pointer)
static void
window_get_resize_dx_dy(struct window *window, int *x, int *y)
{
- if (window->resize_edges & WINDOW_RESIZING_LEFT)
+ if (window->resize_edges & WINDOW_RESIZING_FROM_CENTER) {
+ *x = window->server_allocation.width - window->allocation.width;
+ *x /= 2;
+ } else if (window->resize_edges & WINDOW_RESIZING_LEFT)
*x = window->server_allocation.width - window->allocation.width;
else
*x = 0;
- if (window->resize_edges & WINDOW_RESIZING_TOP)
+ if (window->resize_edges & WINDOW_RESIZING_FROM_CENTER) {
+ *y = window->server_allocation.height -
+ window->allocation.height;
+ *y /= 2;
+ } else if (window->resize_edges & WINDOW_RESIZING_TOP)
*y = window->server_allocation.height -
window->allocation.height;
else
diff --git a/src/shell.c b/src/shell.c
index 26068cd..299fd25 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -102,6 +102,7 @@ struct desktop_shell {
bool locked;
bool showing_input_panels;
bool prepare_event_sent;
+ bool resize_from_center;
struct weston_surface *lock_surface;
struct wl_listener lock_surface_listener;
@@ -356,10 +357,12 @@ shell_configuration(struct desktop_shell *shell)
unsigned int num_workspaces = DEFAULT_NUM_WORKSPACES;
char *modifier = NULL;
char *win_animation = NULL;
+ bool resize_from_center;
struct config_key shell_keys[] = {
{ "binding-modifier", CONFIG_KEY_STRING, &modifier },
{ "animation", CONFIG_KEY_STRING, &win_animation},
+ { "resize-from-center", CONFIG_KEY_BOOLEAN, &resize_from_center},
{ "num-workspaces",
CONFIG_KEY_UNSIGNED_INTEGER, &num_workspaces },
};
@@ -383,6 +386,7 @@ shell_configuration(struct desktop_shell *shell)
shell->binding_modifier = get_modifier(modifier);
shell->win_animation_type = get_animation_type(win_animation);
shell->workspaces.num = num_workspaces > 0 ? num_workspaces : 1;
+ shell->resize_from_center = resize_from_center;
}
static void
@@ -1097,7 +1101,7 @@ resize_grab_motion(struct wl_pointer_grab *grab,
struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
struct wl_pointer *pointer = grab->pointer;
struct shell_surface *shsurf = resize->base.shsurf;
- int32_t width, height;
+ int32_t width, height, offset;
wl_fixed_t from_x, from_y;
wl_fixed_t to_x, to_y;
@@ -1112,17 +1116,29 @@ resize_grab_motion(struct wl_pointer_grab *grab,
width = resize->width;
if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
- width += wl_fixed_to_int(from_x - to_x);
+ offset = wl_fixed_to_int(from_x - to_x);
} else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
- width += wl_fixed_to_int(to_x - from_x);
- }
+ offset = wl_fixed_to_int(to_x - from_x);
+ } else
+ offset = 0;
+
+ if (resize->edges & WL_SHELL_SURFACE_RESIZE_FROM_CENTER)
+ offset *= 2;
+
+ width += offset;
height = resize->height;
if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
- height += wl_fixed_to_int(from_y - to_y);
+ offset = wl_fixed_to_int(from_y - to_y);
} else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
- height += wl_fixed_to_int(to_y - from_y);
- }
+ offset = wl_fixed_to_int(to_y - from_y);
+ } else
+ offset = 0;
+
+ if (resize->edges & WL_SHELL_SURFACE_RESIZE_FROM_CENTER)
+ offset *= 2;
+
+ height += offset;
shsurf->client->send_configure(shsurf->surface,
resize->edges, width, height);
@@ -1172,7 +1188,7 @@ surface_resize(struct shell_surface *shsurf,
if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
return 0;
- if (edges == 0 || edges > 15 ||
+ if (edges == 0 || (edges & 0x0f) > 15 ||
(edges & 3) == 3 || (edges & 12) == 12)
return 0;
@@ -1185,7 +1201,7 @@ surface_resize(struct shell_surface *shsurf,
resize->height = shsurf->surface->geometry.height;
shell_grab_start(&resize->base, &resize_grab_interface, shsurf,
- ws->seat.pointer, edges);
+ ws->seat.pointer, edges & 0x0f);
return 0;
}
@@ -1206,6 +1222,9 @@ shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
ws->seat.pointer->focus != &shsurf->surface->surface)
return;
+ if (shsurf->shell->resize_from_center)
+ edges |= WL_SHELL_SURFACE_RESIZE_FROM_CENTER;
+
if (surface_resize(shsurf, ws, edges) < 0)
wl_resource_post_no_memory(resource);
}
@@ -2763,6 +2782,9 @@ resize_binding(struct wl_seat *seat, uint32_t time, uint32_t button, void *data)
else
edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
+ if (shsurf->shell->resize_from_center)
+ edges |= WL_SHELL_SURFACE_RESIZE_FROM_CENTER;
+
surface_resize(shsurf, (struct weston_seat *) seat, edges);
}
diff --git a/weston.ini b/weston.ini
index cb88eba..6a74368 100644
--- a/weston.ini
+++ b/weston.ini
@@ -7,6 +7,7 @@ locking=true
animation=zoom
#binding-modifier=ctrl
#num-workspaces=6
+#resize-from-center=true
#type=tablet-shell.so
#lockscreen-icon=/usr/share/icons/gnome/256x256/actions/lock.png
--
1.7.11.7
More information about the wayland-devel
mailing list