Make X11 and Wayland ProcessHitTest() code less verbose.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 12 Apr 2015 20:59:48 -0400
changeset 9555fff4b6354b99
parent 9554 879f71e1478b
child 9556 db92b9d74129
Make X11 and Wayland ProcessHitTest() code less verbose.
src/video/wayland/SDL_waylandevents.c
src/video/x11/SDL_x11events.c
     1.1 --- a/src/video/wayland/SDL_waylandevents.c	Sun Apr 12 20:40:06 2015 -0400
     1.2 +++ b/src/video/wayland/SDL_waylandevents.c	Sun Apr 12 20:59:48 2015 -0400
     1.3 @@ -137,63 +137,37 @@
     1.4  {
     1.5      SDL_WindowData *window_data = input->pointer_focus;
     1.6      SDL_Window *window = window_data->sdlwindow;
     1.7 -    SDL_bool ret = SDL_FALSE;
     1.8  
     1.9      if (window->hit_test) {
    1.10          const SDL_Point point = { wl_fixed_to_int(input->sx_w), wl_fixed_to_int(input->sy_w) };
    1.11          const SDL_HitTestResult rc = window->hit_test(window, &point, window->hit_test_data);
    1.12 +        static const uint32_t directions[] = {
    1.13 +            WL_SHELL_SURFACE_RESIZE_TOP_LEFT, WL_SHELL_SURFACE_RESIZE_TOP,
    1.14 +            WL_SHELL_SURFACE_RESIZE_TOP_RIGHT, WL_SHELL_SURFACE_RESIZE_RIGHT,
    1.15 +            WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT, WL_SHELL_SURFACE_RESIZE_BOTTOM,
    1.16 +            WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT, WL_SHELL_SURFACE_RESIZE_LEFT
    1.17 +        };
    1.18          switch (rc) {
    1.19 -            case SDL_HITTEST_DRAGGABLE: {
    1.20 -                    wl_shell_surface_move(window_data->shell_surface, input->seat, serial);
    1.21 -                    ret = SDL_TRUE;
    1.22 -                }
    1.23 -                break;
    1.24 -            case SDL_HITTEST_RESIZE_TOPLEFT: {
    1.25 -                    wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_TOP_LEFT);
    1.26 -                    ret = SDL_TRUE;
    1.27 -                }
    1.28 -                break;
    1.29 -            case SDL_HITTEST_RESIZE_TOP: {
    1.30 -                    wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_TOP);
    1.31 -                    ret = SDL_TRUE;
    1.32 -                }
    1.33 -                break;
    1.34 -            case SDL_HITTEST_RESIZE_TOPRIGHT: {
    1.35 -                    wl_shell_surface_resize(window_data->shell_surface, input->seat, serial,  WL_SHELL_SURFACE_RESIZE_TOP_RIGHT);
    1.36 -                    ret = SDL_TRUE;
    1.37 -                }
    1.38 -                break;
    1.39 -            case SDL_HITTEST_RESIZE_RIGHT: {
    1.40 -                    wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_RIGHT);
    1.41 -                    ret = SDL_TRUE;
    1.42 -                }
    1.43 -                break;
    1.44 -            case SDL_HITTEST_RESIZE_BOTTOMRIGHT: {
    1.45 -                    wl_shell_surface_resize(window_data->shell_surface, input->seat, serial,  WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT);
    1.46 -                    ret = SDL_TRUE;
    1.47 -                }
    1.48 -                break;
    1.49 -            case SDL_HITTEST_RESIZE_BOTTOM: {
    1.50 -                    wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_BOTTOM);
    1.51 -                    ret = SDL_TRUE;
    1.52 -                }
    1.53 -                break;
    1.54 -            case SDL_HITTEST_RESIZE_BOTTOMLEFT: {
    1.55 -                    wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT);
    1.56 -                    ret = SDL_TRUE;
    1.57 -                }
    1.58 -                break;
    1.59 -            case SDL_HITTEST_RESIZE_LEFT: {
    1.60 -                    wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_LEFT);
    1.61 -                    ret = SDL_TRUE;
    1.62 -                }
    1.63 -                break;
    1.64 -            default:
    1.65 -                break;
    1.66 +            case SDL_HITTEST_DRAGGABLE:
    1.67 +                wl_shell_surface_move(window_data->shell_surface, input->seat, serial);
    1.68 +                return SDL_TRUE;
    1.69 +
    1.70 +            case SDL_HITTEST_RESIZE_TOPLEFT:
    1.71 +            case SDL_HITTEST_RESIZE_TOP:
    1.72 +            case SDL_HITTEST_RESIZE_TOPRIGHT:
    1.73 +            case SDL_HITTEST_RESIZE_RIGHT:
    1.74 +            case SDL_HITTEST_RESIZE_BOTTOMRIGHT:
    1.75 +            case SDL_HITTEST_RESIZE_BOTTOM:
    1.76 +            case SDL_HITTEST_RESIZE_BOTTOMLEFT:
    1.77 +            case SDL_HITTEST_RESIZE_LEFT:
    1.78 +                wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, directions[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
    1.79 +                return SDL_TRUE;
    1.80 +
    1.81 +            default: return SDL_FALSE;
    1.82          }
    1.83      }
    1.84  
    1.85 -    return ret;
    1.86 +    return SDL_FALSE;
    1.87  }
    1.88  
    1.89  static void
     2.1 --- a/src/video/x11/SDL_x11events.c	Sun Apr 12 20:40:06 2015 -0400
     2.2 +++ b/src/video/x11/SDL_x11events.c	Sun Apr 12 20:59:48 2015 -0400
     2.3 @@ -448,63 +448,38 @@
     2.4  ProcessHitTest(_THIS, const SDL_WindowData *data, const XEvent *xev)
     2.5  {
     2.6      SDL_Window *window = data->window;
     2.7 -    SDL_bool ret = SDL_FALSE;
     2.8  
     2.9      if (window->hit_test) {
    2.10          const SDL_Point point = { xev->xbutton.x, xev->xbutton.y };
    2.11          const SDL_HitTestResult rc = window->hit_test(window, &point, window->hit_test_data);
    2.12 +        static const int directions[] = {
    2.13 +            _NET_WM_MOVERESIZE_SIZE_TOPLEFT, _NET_WM_MOVERESIZE_SIZE_TOP,
    2.14 +            _NET_WM_MOVERESIZE_SIZE_TOPRIGHT, _NET_WM_MOVERESIZE_SIZE_RIGHT,
    2.15 +            _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT, _NET_WM_MOVERESIZE_SIZE_BOTTOM,
    2.16 +            _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT, _NET_WM_MOVERESIZE_SIZE_LEFT
    2.17 +        };
    2.18 +
    2.19          switch (rc) {
    2.20 -            case SDL_HITTEST_DRAGGABLE: {
    2.21 -                    InitiateWindowMove(_this, data, &point);
    2.22 -                    ret = SDL_TRUE;
    2.23 -                }
    2.24 -                break;
    2.25 -            case SDL_HITTEST_RESIZE_TOPLEFT: {
    2.26 -                    InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_TOPLEFT);
    2.27 -                    ret = SDL_TRUE;
    2.28 -                }
    2.29 -                break;
    2.30 -            case SDL_HITTEST_RESIZE_TOP: {
    2.31 -                    InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_TOP);
    2.32 -                    ret = SDL_TRUE;
    2.33 -                }
    2.34 -                break;
    2.35 -            case SDL_HITTEST_RESIZE_TOPRIGHT: {
    2.36 -                    InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_TOPRIGHT);
    2.37 -                    ret = SDL_TRUE;
    2.38 -                }
    2.39 -                break;
    2.40 -            case SDL_HITTEST_RESIZE_RIGHT: {
    2.41 -                    InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_RIGHT);
    2.42 -                    ret = SDL_TRUE;
    2.43 -                }
    2.44 -                break;
    2.45 -            case SDL_HITTEST_RESIZE_BOTTOMRIGHT: {
    2.46 -                    InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT);
    2.47 -                    ret = SDL_TRUE;
    2.48 -                }
    2.49 -                break;
    2.50 -            case SDL_HITTEST_RESIZE_BOTTOM: {
    2.51 -                    InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_BOTTOM);
    2.52 -                    ret = SDL_TRUE;
    2.53 -                }
    2.54 -                break;
    2.55 -            case SDL_HITTEST_RESIZE_BOTTOMLEFT: {
    2.56 -                    InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT);
    2.57 -                    ret = SDL_TRUE;
    2.58 -                }
    2.59 -                break;
    2.60 -            case SDL_HITTEST_RESIZE_LEFT: {
    2.61 -                    InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_LEFT);
    2.62 -                    ret = SDL_TRUE;
    2.63 -                }
    2.64 -                break;
    2.65 -            default:
    2.66 -                break;
    2.67 +            case SDL_HITTEST_DRAGGABLE:
    2.68 +                InitiateWindowMove(_this, data, &point);
    2.69 +                return SDL_TRUE;
    2.70 +
    2.71 +            case SDL_HITTEST_RESIZE_TOPLEFT:
    2.72 +            case SDL_HITTEST_RESIZE_TOP:
    2.73 +            case SDL_HITTEST_RESIZE_TOPRIGHT:
    2.74 +            case SDL_HITTEST_RESIZE_RIGHT:
    2.75 +            case SDL_HITTEST_RESIZE_BOTTOMRIGHT:
    2.76 +            case SDL_HITTEST_RESIZE_BOTTOM:
    2.77 +            case SDL_HITTEST_RESIZE_BOTTOMLEFT:
    2.78 +            case SDL_HITTEST_RESIZE_LEFT:
    2.79 +                InitiateWindowResize(_this, data, &point, directions[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
    2.80 +                return SDL_TRUE;
    2.81 +
    2.82 +            default: return SDL_FALSE;
    2.83          }
    2.84      }
    2.85  
    2.86 -    return ret;
    2.87 +    return SDL_FALSE;
    2.88  }
    2.89  
    2.90  static void