Make X11 and Wayland ProcessHitTest() code less verbose.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c
index 59280b5..3c44ba4 100644
--- a/src/video/wayland/SDL_waylandevents.c
+++ b/src/video/wayland/SDL_waylandevents.c
@@ -137,63 +137,37 @@ ProcessHitTest(struct SDL_WaylandInput *input, uint32_t serial)
{
SDL_WindowData *window_data = input->pointer_focus;
SDL_Window *window = window_data->sdlwindow;
- SDL_bool ret = SDL_FALSE;
if (window->hit_test) {
const SDL_Point point = { wl_fixed_to_int(input->sx_w), wl_fixed_to_int(input->sy_w) };
const SDL_HitTestResult rc = window->hit_test(window, &point, window->hit_test_data);
+ static const uint32_t directions[] = {
+ WL_SHELL_SURFACE_RESIZE_TOP_LEFT, WL_SHELL_SURFACE_RESIZE_TOP,
+ WL_SHELL_SURFACE_RESIZE_TOP_RIGHT, WL_SHELL_SURFACE_RESIZE_RIGHT,
+ WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT, WL_SHELL_SURFACE_RESIZE_BOTTOM,
+ WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT, WL_SHELL_SURFACE_RESIZE_LEFT
+ };
switch (rc) {
- case SDL_HITTEST_DRAGGABLE: {
- wl_shell_surface_move(window_data->shell_surface, input->seat, serial);
- ret = SDL_TRUE;
- }
- break;
- case SDL_HITTEST_RESIZE_TOPLEFT: {
- wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_TOP_LEFT);
- ret = SDL_TRUE;
- }
- break;
- case SDL_HITTEST_RESIZE_TOP: {
- wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_TOP);
- ret = SDL_TRUE;
- }
- break;
- case SDL_HITTEST_RESIZE_TOPRIGHT: {
- wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_TOP_RIGHT);
- ret = SDL_TRUE;
- }
- break;
- case SDL_HITTEST_RESIZE_RIGHT: {
- wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_RIGHT);
- ret = SDL_TRUE;
- }
- break;
- case SDL_HITTEST_RESIZE_BOTTOMRIGHT: {
- wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT);
- ret = SDL_TRUE;
- }
- break;
- case SDL_HITTEST_RESIZE_BOTTOM: {
- wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_BOTTOM);
- ret = SDL_TRUE;
- }
- break;
- case SDL_HITTEST_RESIZE_BOTTOMLEFT: {
- wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT);
- ret = SDL_TRUE;
- }
- break;
- case SDL_HITTEST_RESIZE_LEFT: {
- wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_LEFT);
- ret = SDL_TRUE;
- }
- break;
- default:
- break;
+ case SDL_HITTEST_DRAGGABLE:
+ wl_shell_surface_move(window_data->shell_surface, input->seat, serial);
+ return SDL_TRUE;
+
+ case SDL_HITTEST_RESIZE_TOPLEFT:
+ case SDL_HITTEST_RESIZE_TOP:
+ case SDL_HITTEST_RESIZE_TOPRIGHT:
+ case SDL_HITTEST_RESIZE_RIGHT:
+ case SDL_HITTEST_RESIZE_BOTTOMRIGHT:
+ case SDL_HITTEST_RESIZE_BOTTOM:
+ case SDL_HITTEST_RESIZE_BOTTOMLEFT:
+ case SDL_HITTEST_RESIZE_LEFT:
+ wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, directions[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
+ return SDL_TRUE;
+
+ default: return SDL_FALSE;
}
}
- return ret;
+ return SDL_FALSE;
}
static void
diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c
index 02dc8a9..e5a9c28 100644
--- a/src/video/x11/SDL_x11events.c
+++ b/src/video/x11/SDL_x11events.c
@@ -448,63 +448,38 @@ static SDL_bool
ProcessHitTest(_THIS, const SDL_WindowData *data, const XEvent *xev)
{
SDL_Window *window = data->window;
- SDL_bool ret = SDL_FALSE;
if (window->hit_test) {
const SDL_Point point = { xev->xbutton.x, xev->xbutton.y };
const SDL_HitTestResult rc = window->hit_test(window, &point, window->hit_test_data);
+ static const int directions[] = {
+ _NET_WM_MOVERESIZE_SIZE_TOPLEFT, _NET_WM_MOVERESIZE_SIZE_TOP,
+ _NET_WM_MOVERESIZE_SIZE_TOPRIGHT, _NET_WM_MOVERESIZE_SIZE_RIGHT,
+ _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT, _NET_WM_MOVERESIZE_SIZE_BOTTOM,
+ _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT, _NET_WM_MOVERESIZE_SIZE_LEFT
+ };
+
switch (rc) {
- case SDL_HITTEST_DRAGGABLE: {
- InitiateWindowMove(_this, data, &point);
- ret = SDL_TRUE;
- }
- break;
- case SDL_HITTEST_RESIZE_TOPLEFT: {
- InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_TOPLEFT);
- ret = SDL_TRUE;
- }
- break;
- case SDL_HITTEST_RESIZE_TOP: {
- InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_TOP);
- ret = SDL_TRUE;
- }
- break;
- case SDL_HITTEST_RESIZE_TOPRIGHT: {
- InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_TOPRIGHT);
- ret = SDL_TRUE;
- }
- break;
- case SDL_HITTEST_RESIZE_RIGHT: {
- InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_RIGHT);
- ret = SDL_TRUE;
- }
- break;
- case SDL_HITTEST_RESIZE_BOTTOMRIGHT: {
- InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT);
- ret = SDL_TRUE;
- }
- break;
- case SDL_HITTEST_RESIZE_BOTTOM: {
- InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_BOTTOM);
- ret = SDL_TRUE;
- }
- break;
- case SDL_HITTEST_RESIZE_BOTTOMLEFT: {
- InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT);
- ret = SDL_TRUE;
- }
- break;
- case SDL_HITTEST_RESIZE_LEFT: {
- InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_LEFT);
- ret = SDL_TRUE;
- }
- break;
- default:
- break;
+ case SDL_HITTEST_DRAGGABLE:
+ InitiateWindowMove(_this, data, &point);
+ return SDL_TRUE;
+
+ case SDL_HITTEST_RESIZE_TOPLEFT:
+ case SDL_HITTEST_RESIZE_TOP:
+ case SDL_HITTEST_RESIZE_TOPRIGHT:
+ case SDL_HITTEST_RESIZE_RIGHT:
+ case SDL_HITTEST_RESIZE_BOTTOMRIGHT:
+ case SDL_HITTEST_RESIZE_BOTTOM:
+ case SDL_HITTEST_RESIZE_BOTTOMLEFT:
+ case SDL_HITTEST_RESIZE_LEFT:
+ InitiateWindowResize(_this, data, &point, directions[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
+ return SDL_TRUE;
+
+ default: return SDL_FALSE;
}
}
- return ret;
+ return SDL_FALSE;
}
static void