bring edges into wlr

master
Tony Crisci 7 years ago
parent f469784bbc
commit d74ac69f7b

@ -10,13 +10,6 @@ enum roots_cursor_mode {
ROOTS_CURSOR_ROTATE = 3, ROOTS_CURSOR_ROTATE = 3,
}; };
enum roots_cursor_resize_edge {
ROOTS_CURSOR_RESIZE_EDGE_TOP = 1,
ROOTS_CURSOR_RESIZE_EDGE_BOTTOM = 2,
ROOTS_CURSOR_RESIZE_EDGE_LEFT = 4,
ROOTS_CURSOR_RESIZE_EDGE_RIGHT = 8,
};
struct roots_input_event { struct roots_input_event {
uint32_t serial; uint32_t serial;
struct wlr_cursor *cursor; struct wlr_cursor *cursor;

@ -9,6 +9,4 @@
#define ROOTS_XCURSOR_MOVE "grabbing" #define ROOTS_XCURSOR_MOVE "grabbing"
#define ROOTS_XCURSOR_ROTATE "grabbing" #define ROOTS_XCURSOR_ROTATE "grabbing"
const char *roots_xcursor_get_resize_name(uint32_t edges);
#endif #endif

@ -4,6 +4,7 @@
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_cursor.h>
#include <wlr/xcursor.h> #include <wlr/xcursor.h>
#include <wlr/util/edges.h>
/** /**
* A scaled XCursor theme. * A scaled XCursor theme.
@ -50,4 +51,10 @@ struct wlr_xcursor *wlr_xcursor_manager_get_xcursor(
void wlr_xcursor_manager_set_cursor_image(struct wlr_xcursor_manager *manager, void wlr_xcursor_manager_set_cursor_image(struct wlr_xcursor_manager *manager,
const char *name, struct wlr_cursor *cursor); const char *name, struct wlr_cursor *cursor);
/**
* Get the name of the cursor image for the given edges.
*/
const char *wlr_xcursor_manager_get_resize_name(enum wlr_edges edges);
#endif #endif

@ -0,0 +1,12 @@
#ifndef WLR_UTIL_EDGES_H
#define WLR_UTIL_EDGES_H
enum wlr_edges {
WLR_EDGE_NONE = 0,
WLR_EDGE_TOP = 1,
WLR_EDGE_BOTTOM = 2,
WLR_EDGE_LEFT = 4,
WLR_EDGE_RIGHT = 8,
};
#endif

@ -8,6 +8,7 @@
#endif #endif
#include <wlr/types/wlr_xcursor_manager.h> #include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <wlr/util/edges.h>
#include "rootston/xcursor.h" #include "rootston/xcursor.h"
#include "rootston/cursor.h" #include "rootston/cursor.h"
@ -75,22 +76,22 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
double y = view->y; double y = view->y;
int width = cursor->view_width; int width = cursor->view_width;
int height = cursor->view_height; int height = cursor->view_height;
if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) { if (cursor->resize_edges & WLR_EDGE_TOP) {
y = cursor->view_y + dy; y = cursor->view_y + dy;
height -= dy; height -= dy;
if (height < 1) { if (height < 1) {
y += height; y += height;
} }
} else if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_BOTTOM) { } else if (cursor->resize_edges & WLR_EDGE_BOTTOM) {
height += dy; height += dy;
} }
if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) { if (cursor->resize_edges & WLR_EDGE_LEFT) {
x = cursor->view_x + dx; x = cursor->view_x + dx;
width -= dx; width -= dx;
if (width < 1) { if (width < 1) {
x += width; x += width;
} }
} else if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { } else if (cursor->resize_edges & WLR_EDGE_RIGHT) {
width += dx; width += dx;
} }
@ -147,14 +148,14 @@ static void roots_cursor_press_button(struct roots_cursor *cursor,
case BTN_RIGHT: case BTN_RIGHT:
edges = 0; edges = 0;
if (sx < view->wlr_surface->current->width/2) { if (sx < view->wlr_surface->current->width/2) {
edges |= ROOTS_CURSOR_RESIZE_EDGE_LEFT; edges |= WLR_EDGE_LEFT;
} else { } else {
edges |= ROOTS_CURSOR_RESIZE_EDGE_RIGHT; edges |= WLR_EDGE_RIGHT;
} }
if (sy < view->wlr_surface->current->height/2) { if (sy < view->wlr_surface->current->height/2) {
edges |= ROOTS_CURSOR_RESIZE_EDGE_TOP; edges |= WLR_EDGE_TOP;
} else { } else {
edges |= ROOTS_CURSOR_RESIZE_EDGE_BOTTOM; edges |= WLR_EDGE_BOTTOM;
} }
roots_seat_begin_resize(seat, view, edges); roots_seat_begin_resize(seat, view, edges);
break; break;

@ -8,7 +8,6 @@ sources = [
'main.c', 'main.c',
'output.c', 'output.c',
'seat.c', 'seat.c',
'xcursor.c',
'xdg_shell_v6.c', 'xdg_shell_v6.c',
'wl_shell.c', 'wl_shell.c',
] ]

@ -661,8 +661,9 @@ void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view,
view_maximize(view, false); view_maximize(view, false);
wlr_seat_pointer_clear_focus(seat->seat); wlr_seat_pointer_clear_focus(seat->seat);
const char *resize_name = wlr_xcursor_manager_get_resize_name(edges);
wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager, wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
roots_xcursor_get_resize_name(edges), seat->cursor->cursor); resize_name, seat->cursor->cursor);
} }
void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view) { void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view) {

@ -1,28 +0,0 @@
#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <string.h>
#include "rootston/xcursor.h"
#include "rootston/input.h"
const char *roots_xcursor_get_resize_name(uint32_t edges) {
if (edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) {
if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) {
return "ne-resize";
} else if (edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) {
return "nw-resize";
}
return "n-resize";
} else if (edges & ROOTS_CURSOR_RESIZE_EDGE_BOTTOM) {
if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) {
return "se-resize";
} else if (edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) {
return "sw-resize";
}
return "s-resize";
} else if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) {
return "e-resize";
} else if (edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) {
return "w-resize";
}
return "se-resize"; // fallback
}

@ -82,3 +82,26 @@ void wlr_xcursor_manager_set_cursor_image(struct wlr_xcursor_manager *manager,
theme->scale); theme->scale);
} }
} }
const char *wlr_xcursor_manager_get_resize_name(enum wlr_edges edges) {
if (edges & WLR_EDGE_TOP) {
if (edges & WLR_EDGE_RIGHT) {
return "ne-resize";
} else if (edges & WLR_EDGE_LEFT) {
return "nw-resize";
}
return "n-resize";
} else if (edges & WLR_EDGE_BOTTOM) {
if (edges & WLR_EDGE_RIGHT) {
return "se-resize";
} else if (edges & WLR_EDGE_LEFT) {
return "sw-resize";
}
return "s-resize";
} else if (edges & WLR_EDGE_RIGHT) {
return "e-resize";
} else if (edges & WLR_EDGE_LEFT) {
return "w-resize";
}
return "se-resize"; // fallback
}

Loading…
Cancel
Save