From d74ac69f7b932a8833527a41351e3310ad391d7c Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 7 Dec 2017 11:19:43 -0500 Subject: [PATCH 1/3] bring edges into wlr --- include/rootston/cursor.h | 7 ------- include/rootston/xcursor.h | 2 -- include/wlr/types/wlr_xcursor_manager.h | 7 +++++++ include/wlr/util/edges.h | 12 +++++++++++ rootston/cursor.c | 17 ++++++++------- rootston/meson.build | 1 - rootston/seat.c | 3 ++- rootston/xcursor.c | 28 ------------------------- types/wlr_xcursor_manager.c | 23 ++++++++++++++++++++ 9 files changed, 53 insertions(+), 47 deletions(-) create mode 100644 include/wlr/util/edges.h delete mode 100644 rootston/xcursor.c diff --git a/include/rootston/cursor.h b/include/rootston/cursor.h index e2a371bf..2d9a9215 100644 --- a/include/rootston/cursor.h +++ b/include/rootston/cursor.h @@ -10,13 +10,6 @@ enum roots_cursor_mode { 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 { uint32_t serial; struct wlr_cursor *cursor; diff --git a/include/rootston/xcursor.h b/include/rootston/xcursor.h index bc00f79c..285db78d 100644 --- a/include/rootston/xcursor.h +++ b/include/rootston/xcursor.h @@ -9,6 +9,4 @@ #define ROOTS_XCURSOR_MOVE "grabbing" #define ROOTS_XCURSOR_ROTATE "grabbing" -const char *roots_xcursor_get_resize_name(uint32_t edges); - #endif diff --git a/include/wlr/types/wlr_xcursor_manager.h b/include/wlr/types/wlr_xcursor_manager.h index c78a6e8d..63eb5386 100644 --- a/include/wlr/types/wlr_xcursor_manager.h +++ b/include/wlr/types/wlr_xcursor_manager.h @@ -4,6 +4,7 @@ #include #include #include +#include /** * 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, 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 diff --git a/include/wlr/util/edges.h b/include/wlr/util/edges.h new file mode 100644 index 00000000..53268323 --- /dev/null +++ b/include/wlr/util/edges.h @@ -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 diff --git a/rootston/cursor.c b/rootston/cursor.c index f0e3d70d..d38e40a1 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -8,6 +8,7 @@ #endif #include #include +#include #include "rootston/xcursor.h" #include "rootston/cursor.h" @@ -75,22 +76,22 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, double y = view->y; int width = cursor->view_width; 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; height -= dy; if (height < 1) { y += height; } - } else if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_BOTTOM) { + } else if (cursor->resize_edges & WLR_EDGE_BOTTOM) { height += dy; } - if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) { + if (cursor->resize_edges & WLR_EDGE_LEFT) { x = cursor->view_x + dx; width -= dx; if (width < 1) { x += width; } - } else if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { + } else if (cursor->resize_edges & WLR_EDGE_RIGHT) { width += dx; } @@ -147,14 +148,14 @@ static void roots_cursor_press_button(struct roots_cursor *cursor, case BTN_RIGHT: edges = 0; if (sx < view->wlr_surface->current->width/2) { - edges |= ROOTS_CURSOR_RESIZE_EDGE_LEFT; + edges |= WLR_EDGE_LEFT; } else { - edges |= ROOTS_CURSOR_RESIZE_EDGE_RIGHT; + edges |= WLR_EDGE_RIGHT; } if (sy < view->wlr_surface->current->height/2) { - edges |= ROOTS_CURSOR_RESIZE_EDGE_TOP; + edges |= WLR_EDGE_TOP; } else { - edges |= ROOTS_CURSOR_RESIZE_EDGE_BOTTOM; + edges |= WLR_EDGE_BOTTOM; } roots_seat_begin_resize(seat, view, edges); break; diff --git a/rootston/meson.build b/rootston/meson.build index 9c543c4f..36b6241a 100644 --- a/rootston/meson.build +++ b/rootston/meson.build @@ -8,7 +8,6 @@ sources = [ 'main.c', 'output.c', 'seat.c', - 'xcursor.c', 'xdg_shell_v6.c', 'wl_shell.c', ] diff --git a/rootston/seat.c b/rootston/seat.c index 737bbd67..f6473581 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -661,8 +661,9 @@ void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view, view_maximize(view, false); 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, - 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) { diff --git a/rootston/xcursor.c b/rootston/xcursor.c deleted file mode 100644 index 74e732c9..00000000 --- a/rootston/xcursor.c +++ /dev/null @@ -1,28 +0,0 @@ -#define _POSIX_C_SOURCE 200809L -#include -#include -#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 -} diff --git a/types/wlr_xcursor_manager.c b/types/wlr_xcursor_manager.c index f32a96bc..9350d721 100644 --- a/types/wlr_xcursor_manager.c +++ b/types/wlr_xcursor_manager.c @@ -82,3 +82,26 @@ void wlr_xcursor_manager_set_cursor_image(struct wlr_xcursor_manager *manager, 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 +} From 31bafc24614cb5a66348ca965f1b4fae9209e35c Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 7 Dec 2017 12:04:02 -0500 Subject: [PATCH 2/3] xwm: use edges enum --- xwayland/xwm.c | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 562f2052..a86fbd0e 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -8,6 +8,7 @@ #include #include #include "wlr/util/log.h" +#include "wlr/util/edges.h" #include "wlr/types/wlr_surface.h" #include "wlr/xwayland.h" #include "wlr/xcursor.h" @@ -742,14 +743,43 @@ static void xwm_handle_surface_id_message(struct wlr_xwm *xwm, #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 // move via keyboard #define _NET_WM_MOVERESIZE_CANCEL 11 // cancel operation +static enum wlr_edges net_wm_edges_to_wlr(uint32_t net_wm_edges) { + enum wlr_edges edges = WLR_EDGE_NONE; + + switch(net_wm_edges) { + case _NET_WM_MOVERESIZE_SIZE_TOPLEFT: + edges = WLR_EDGE_TOP | WLR_EDGE_LEFT; + break; + case _NET_WM_MOVERESIZE_SIZE_TOP: + edges = WLR_EDGE_TOP; + break; + case _NET_WM_MOVERESIZE_SIZE_TOPRIGHT: + edges = WLR_EDGE_TOP | WLR_EDGE_RIGHT; + break; + case _NET_WM_MOVERESIZE_SIZE_RIGHT: + edges = WLR_EDGE_RIGHT; + break; + case _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT: + edges = WLR_EDGE_BOTTOM | WLR_EDGE_RIGHT; + break; + case _NET_WM_MOVERESIZE_SIZE_BOTTOM: + edges = WLR_EDGE_BOTTOM; + break; + case _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT: + edges = WLR_EDGE_BOTTOM | WLR_EDGE_LEFT; + break; + case _NET_WM_MOVERESIZE_SIZE_LEFT: + edges = WLR_EDGE_LEFT; + break; + default: + break; + } + + return edges; +} + static void xwm_handle_net_wm_moveresize_message(struct wlr_xwm *xwm, xcb_client_message_event_t *ev) { - // same as xdg-toplevel-v6 - // TODO need a common enum for this - static const int map[] = { - 5, 1, 9, 8, 10, 2, 6, 4 - }; - struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window); if (!xsurface) { return; @@ -775,7 +805,7 @@ static void xwm_handle_net_wm_moveresize_message(struct wlr_xwm *xwm, case _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT: case _NET_WM_MOVERESIZE_SIZE_LEFT: resize_event.surface = xsurface; - resize_event.edges = map[detail]; + resize_event.edges = net_wm_edges_to_wlr(detail); wl_signal_emit(&xsurface->events.request_resize, &resize_event); break; case _NET_WM_MOVERESIZE_CANCEL: From 4c60072be584a7ed5b97de325994217a9e96bbd4 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Fri, 8 Dec 2017 06:08:06 -0500 Subject: [PATCH 3/3] move get_resize_name to xcursor --- include/wlr/types/wlr_xcursor_manager.h | 7 ------- include/wlr/xcursor.h | 6 ++++++ rootston/seat.c | 2 +- types/wlr_xcursor_manager.c | 23 ----------------------- xcursor/wlr_xcursor.c | 23 +++++++++++++++++++++++ 5 files changed, 30 insertions(+), 31 deletions(-) diff --git a/include/wlr/types/wlr_xcursor_manager.h b/include/wlr/types/wlr_xcursor_manager.h index 63eb5386..c78a6e8d 100644 --- a/include/wlr/types/wlr_xcursor_manager.h +++ b/include/wlr/types/wlr_xcursor_manager.h @@ -4,7 +4,6 @@ #include #include #include -#include /** * A scaled XCursor theme. @@ -51,10 +50,4 @@ struct wlr_xcursor *wlr_xcursor_manager_get_xcursor( void wlr_xcursor_manager_set_cursor_image(struct wlr_xcursor_manager *manager, 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 diff --git a/include/wlr/xcursor.h b/include/wlr/xcursor.h index b6362b06..42fcedb9 100644 --- a/include/wlr/xcursor.h +++ b/include/wlr/xcursor.h @@ -32,6 +32,7 @@ #define WLR_XCURSOR_H #include +#include struct wlr_xcursor_image { uint32_t width; /* actual width */ @@ -65,4 +66,9 @@ struct wlr_xcursor *wlr_xcursor_theme_get_cursor( int wlr_xcursor_frame(struct wlr_xcursor *cursor, uint32_t time); +/** + * Get the name of the resize cursor image for the given edges. + */ +const char *wlr_xcursor_get_resize_name(enum wlr_edges edges); + #endif diff --git a/rootston/seat.c b/rootston/seat.c index f6473581..1fa09ad6 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -661,7 +661,7 @@ void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view, view_maximize(view, false); wlr_seat_pointer_clear_focus(seat->seat); - const char *resize_name = wlr_xcursor_manager_get_resize_name(edges); + const char *resize_name = wlr_xcursor_get_resize_name(edges); wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager, resize_name, seat->cursor->cursor); } diff --git a/types/wlr_xcursor_manager.c b/types/wlr_xcursor_manager.c index 9350d721..f32a96bc 100644 --- a/types/wlr_xcursor_manager.c +++ b/types/wlr_xcursor_manager.c @@ -82,26 +82,3 @@ void wlr_xcursor_manager_set_cursor_image(struct wlr_xcursor_manager *manager, 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 -} diff --git a/xcursor/wlr_xcursor.c b/xcursor/wlr_xcursor.c index fdebe1af..b1678223 100644 --- a/xcursor/wlr_xcursor.c +++ b/xcursor/wlr_xcursor.c @@ -326,3 +326,26 @@ static int wlr_xcursor_frame_and_duration(struct wlr_xcursor *cursor, int wlr_xcursor_frame(struct wlr_xcursor *_cursor, uint32_t time) { return wlr_xcursor_frame_and_duration(_cursor, time, NULL); } + +const char *wlr_xcursor_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 +}