~goleo/wio

c48c8a7995776a8f9d989be4ba89bbe8cf033140 — Leonid Bobrov 1 year, 1 month ago 7635da6
Scale while resizing
4 files changed, 24 insertions(+), 21 deletions(-)

M include/view.h
M input.c
M output.c
M view.c
M include/view.h => include/view.h +3 -2
@@ 36,7 36,8 @@ void wio_view_focus(struct wio_view *view, struct wlr_surface *surface);
struct wio_view *wio_view_at(struct wio_server *server, double lx, double ly,
		struct wlr_surface **surface, double *sx, double *sy);
void wio_view_move(struct wio_view *view, int x, int y);
struct wlr_box wio_which_box(struct wio_server *server);
struct wlr_box wio_canon_box(struct wio_server *server, struct wlr_box box);
struct wlr_box wio_which_box(struct wio_server *server, int scale);
void wio_save_box(struct wlr_box box);
struct wlr_box wio_restore_box(void);

#endif

M input.c => input.c +2 -6
@@ 224,7 224,7 @@ static void view_end_interactive(struct wio_server *server) {
}

static void new_view(struct wio_server *server) {
	struct wlr_box box = wio_which_box(server);
	struct wlr_box box = wio_restore_box();
	if (box.width < MINWIDTH || box.height < MINHEIGHT) {
		return;
	}


@@ 344,16 344,12 @@ static void handle_button_internal(
		server->input_state = INPUT_STATE_RESIZE_END;
		break;
	case INPUT_STATE_BORDER_DRAG:
		box = wio_which_box(server);
		box = wio_canon_box(server, box);
		goto Done;
	case INPUT_STATE_RESIZE_END:
		box = wio_which_box(server);
		box = wio_restore_box();
		if (box.width < MINWIDTH || box.height < MINHEIGHT) {
			view_end_interactive(server);
			break;
		}
	Done:
		wio_view_move(server->interactive.view, box.x, box.y);
		wlr_xdg_toplevel_set_size(server->interactive.view->xdg_surface, box.width, box.height);
		view_end_interactive(server);

M output.c => output.c +8 -3
@@ 311,8 311,12 @@ static void output_frame(struct wl_listener *listener, void *data) {
	view = server->interactive.view;
	switch (server->input_state) {
	case INPUT_STATE_BORDER_DRAG:
		box = wio_which_box(server);
		box = wio_canon_box(server, box);
		box = wio_which_box(server, output->wlr_output->scale);
		if (box.width < MINWIDTH || box.height < MINHEIGHT) {
			box = wio_restore_box();
		} else {
			wio_save_box(box);
		}
		render_view_border(renderer, output, NULL, box.x, box.y, box.width, box.height, 1);
		break;
	case INPUT_STATE_MOVE:


@@ 325,7 329,8 @@ static void output_frame(struct wl_listener *listener, void *data) {
		break;
	case INPUT_STATE_NEW_END:
	case INPUT_STATE_RESIZE_END:
		box = wio_which_box(server);
		box = wio_which_box(server, output->wlr_output->scale);
		wio_save_box(box);
		if (box.width > 0 && box.height > 0) {
			memcpy(color, surface, sizeof(color));
			wlr_render_rect(renderer, &box, color, output->wlr_output->transform_matrix);

M view.c => view.c +11 -10
@@ 5,9 5,8 @@
#include "server.h"
#include "view.h"

// TODO: scale
#define less_swap1(A, B) { if (A < B) { int C = A; A = B; B = C + window_border * 2; } }
#define less_swap2(A, B) { if (A < B) { int C = A; A = B - window_border * 2; B = C; } }
#define less_swap1(A, B) { if (A < B) { int C = A; A = B; B = C + window_border * 2 * scale; } }
#define less_swap2(A, B) { if (A < B) { int C = A; A = B - window_border * 2 * scale; B = C; } }

static void xdg_surface_map(struct wl_listener *listener, void *data) {
	struct wio_view *view = wl_container_of(listener, view, map);


@@ 184,7 183,7 @@ void wio_view_move(struct wio_view *view, int x, int y) {
	}
}

struct wlr_box wio_which_box(struct wio_server *server) {
struct wlr_box wio_which_box(struct wio_server *server, int scale) {
	struct wlr_box box;
	int x1, x2, y1, y2;



@@ 254,10 253,12 @@ struct wlr_box wio_which_box(struct wio_server *server) {
	return box;
}

struct wlr_box wio_canon_box(struct wio_server *server, struct wlr_box box) {
	static struct wlr_box cache;
	if (box.width < MINWIDTH || box.height < MINHEIGHT) {
		return cache;
	}
	return cache = box;
struct wlr_box cache;

void wio_save_box(struct wlr_box box) {
	cache = box;
}

struct wlr_box wio_restore_box(void) {
	return cache;
}