Initial work on X11 implementation of SDL_SetWindowDragAreas().
authorDamian Kaczmarek
Tue, 27 May 2014 14:41:16 -0400
changeset 89327eacbfcbb313
parent 8931 44d8a2f4b431
child 8933 063ef6957a12
Initial work on X11 implementation of SDL_SetWindowDragAreas().
src/video/x11/SDL_x11events.c
src/video/x11/SDL_x11video.c
src/video/x11/SDL_x11window.c
src/video/x11/SDL_x11window.h
     1.1 --- a/src/video/x11/SDL_x11events.c	Tue May 27 01:27:42 2014 -0400
     1.2 +++ b/src/video/x11/SDL_x11events.c	Tue May 27 14:41:16 2014 -0400
     1.3 @@ -273,6 +273,51 @@
     1.4  }
     1.5  
     1.6  static void
     1.7 +InitiateWindowMove(SDL_Window *window)
     1.8 +{
     1.9 +    SDL_SysWMinfo info;
    1.10 +    SDL_VERSION(&info.version);
    1.11 +    SDL_GetWindowWMInfo(window, &info);
    1.12 +    Display *display = info.info.x11.display;
    1.13 +
    1.14 +    int bx, by, dx, dy;
    1.15 +    SDL_GetWindowPosition(window, &bx, &by);
    1.16 +    SDL_GetMouseState(&dx, &dy);
    1.17 +    X11_XUngrabPointer(display, 0L);
    1.18 +    X11_XFlush(display);
    1.19 +
    1.20 +    XEvent evt;
    1.21 +    evt.xclient.type = ClientMessage;
    1.22 +    evt.xclient.window = info.info.x11.window;
    1.23 +    evt.xclient.message_type = X11_XInternAtom(display, "_NET_WM_MOVERESIZE", False);
    1.24 +    evt.xclient.format = 32;
    1.25 +    evt.xclient.data.l[0] = bx + dx;
    1.26 +    evt.xclient.data.l[1] = by + dy;
    1.27 +    evt.xclient.data.l[2] = 8; /* _NET_WM_MOVERESIZE_MOVE */
    1.28 +    evt.xclient.data.l[3] = Button1;
    1.29 +    evt.xclient.data.l[4] = 0;
    1.30 +    X11_XSendEvent(display, DefaultRootWindow(display), False, SubstructureRedirectMask | SubstructureNotifyMask, &evt);
    1.31 +
    1.32 +    X11_XSync(display, 0);
    1.33 +}
    1.34 +
    1.35 +static void
    1.36 +ProcessDragArea(SDL_WindowData* data)
    1.37 +{
    1.38 +    SDL_Window* window = data->window;
    1.39 +    SDL_Mouse* mouse = SDL_GetMouse();
    1.40 +    int i;
    1.41 +    const int num_areas = window->num_drag_areas;
    1.42 +    const SDL_Point point = {mouse->x, mouse->y};
    1.43 +    const SDL_Rect *areas = window->drag_areas;
    1.44 +    for(i = 0;i < num_areas;++i) {
    1.45 +        if (SDL_PointInRect(&point, &areas[i])) {
    1.46 +            InitiateWindowMove(window);
    1.47 +        }
    1.48 +    }
    1.49 +}
    1.50 +
    1.51 +static void
    1.52  X11_DispatchEvent(_THIS)
    1.53  {
    1.54      SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
    1.55 @@ -709,6 +754,9 @@
    1.56              if (X11_IsWheelEvent(display,&xevent,&ticks)) {
    1.57                  SDL_SendMouseWheel(data->window, 0, 0, ticks);
    1.58              } else {
    1.59 +                if(xevent.xbutton.button == SDL_BUTTON_LEFT) {
    1.60 +                    ProcessDragArea(data);
    1.61 +                }
    1.62                  SDL_SendMouseButton(data->window, 0, SDL_PRESSED, xevent.xbutton.button);
    1.63              }
    1.64          }
     2.1 --- a/src/video/x11/SDL_x11video.c	Tue May 27 01:27:42 2014 -0400
     2.2 +++ b/src/video/x11/SDL_x11video.c	Tue May 27 14:41:16 2014 -0400
     2.3 @@ -457,6 +457,7 @@
     2.4      device->UpdateWindowFramebuffer = X11_UpdateWindowFramebuffer;
     2.5      device->DestroyWindowFramebuffer = X11_DestroyWindowFramebuffer;
     2.6      device->GetWindowWMInfo = X11_GetWindowWMInfo;
     2.7 +    device->SetWindowDragAreas = X11_SetWindowDragAreas;
     2.8  
     2.9      device->shape_driver.CreateShaper = X11_CreateShaper;
    2.10      device->shape_driver.SetWindowShape = X11_SetWindowShape;
     3.1 --- a/src/video/x11/SDL_x11window.c	Tue May 27 01:27:42 2014 -0400
     3.2 +++ b/src/video/x11/SDL_x11window.c	Tue May 27 14:41:16 2014 -0400
     3.3 @@ -1444,6 +1444,12 @@
     3.4      }
     3.5  }
     3.6  
     3.7 +int
     3.8 +X11_SetWindowDragAreas(SDL_Window *window, const SDL_Rect *areas, int num_areas)
     3.9 +{
    3.10 +    return 0; // nothing to do, will be handled in event handler
    3.11 +}
    3.12 +
    3.13  #endif /* SDL_VIDEO_DRIVER_X11 */
    3.14  
    3.15  /* vi: set ts=4 sw=4 expandtab: */
     4.1 --- a/src/video/x11/SDL_x11window.h	Tue May 27 01:27:42 2014 -0400
     4.2 +++ b/src/video/x11/SDL_x11window.h	Tue May 27 14:41:16 2014 -0400
     4.3 @@ -93,6 +93,7 @@
     4.4  extern void X11_DestroyWindow(_THIS, SDL_Window * window);
     4.5  extern SDL_bool X11_GetWindowWMInfo(_THIS, SDL_Window * window,
     4.6                                      struct SDL_SysWMinfo *info);
     4.7 +extern int X11_SetWindowDragAreas(SDL_Window *window, const SDL_Rect *areas, int num_areas);
     4.8  
     4.9  #endif /* _SDL_x11window_h */
    4.10