Skip to content

Commit

Permalink
resizor: add centered resize
Browse files Browse the repository at this point in the history
Use LMB for bottom-right anchored resize, RMB for centered resize.

Implements emersion#19
  • Loading branch information
Vyivel committed Jul 6, 2021
1 parent c53d068 commit 3c9bcec
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions resizor.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wayland-client-protocol.h>
#include "client.h"

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,
Expand All @@ -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);
}

Expand All @@ -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;
Expand Down

0 comments on commit 3c9bcec

Please sign in to comment.