diff options
-rw-r--r-- | include/rootston/cursor.h | 7 | ||||
-rw-r--r-- | include/rootston/xcursor.h | 2 | ||||
-rw-r--r-- | include/wlr/util/edges.h | 12 | ||||
-rw-r--r-- | include/wlr/xcursor.h | 6 | ||||
-rw-r--r-- | rootston/cursor.c | 17 | ||||
-rw-r--r-- | rootston/meson.build | 1 | ||||
-rw-r--r-- | rootston/seat.c | 3 | ||||
-rw-r--r-- | rootston/xcursor.c | 28 | ||||
-rw-r--r-- | xcursor/wlr_xcursor.c | 23 | ||||
-rw-r--r-- | xwayland/xwm.c | 44 |
10 files changed, 89 insertions, 54 deletions
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/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/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 <stdint.h> +#include <wlr/util/edges.h> 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/cursor.c b/rootston/cursor.c index f0e3d70d..d38e40a1 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -8,6 +8,7 @@ #endif #include <wlr/types/wlr_xcursor_manager.h> #include <wlr/util/log.h> +#include <wlr/util/edges.h> #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..1fa09ad6 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_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 <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 -} 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 +} 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 <xcb/xcb_image.h> #include <xcb/render.h> #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: |