diff --git a/resizor.c b/resizor.c index 12eaffe..4389d78 100644 --- a/resizor.c +++ b/resizor.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "client.h" static struct wleird_toplevel toplevel = {0}; @@ -9,7 +10,11 @@ static struct wleird_toplevel toplevel = {0}; struct { int x, y; int last_x, last_y; - bool resizing; + enum { + RESIZING_NONE = 0, + RESIZING_ANCHORED_TO_BOTTOM_RIGHT, + RESIZING_ANCHORED_TO_CENTER, + } resizing; } pointer_state; static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer, @@ -30,13 +35,19 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, pointer_state.y = wl_fixed_to_int(surface_y); if (pointer_state.resizing) { - int dx = pointer_state.x - pointer_state.last_x; - int dy = pointer_state.y - pointer_state.last_y; + int dwidth = pointer_state.x - pointer_state.last_x; + int dheight = pointer_state.y - pointer_state.last_y; + int dx = dwidth, dy = dheight; + + if (pointer_state.resizing == RESIZING_ANCHORED_TO_CENTER) { + dwidth *= 2; + dheight *= 2; + } toplevel.surface.attach_x = dx; toplevel.surface.attach_y = dy; - toplevel.surface.width -= dx; - toplevel.surface.height -= dy; + toplevel.surface.width -= dwidth; + toplevel.surface.height -= dheight; surface_render(&toplevel.surface); } @@ -47,7 +58,15 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t button_state) { - pointer_state.resizing = (button_state == WL_POINTER_BUTTON_STATE_PRESSED); + if (button_state == WL_POINTER_BUTTON_STATE_PRESSED) { + if (button == BTN_LEFT) { + pointer_state.resizing = RESIZING_ANCHORED_TO_BOTTOM_RIGHT; + } else if (button == BTN_RIGHT) { + pointer_state.resizing = RESIZING_ANCHORED_TO_CENTER; + } + } else { + pointer_state.resizing = RESIZING_NONE; + } pointer_state.last_x = pointer_state.x; pointer_state.last_y = pointer_state.y;