Some updates for the X11 drag areas work.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 27 May 2014 15:40:03 -0400
changeset 8933063ef6957a12
parent 8932 7eacbfcbb313
child 8934 57fe4bf1b84b
Some updates for the X11 drag areas work.
src/video/x11/SDL_x11events.c
     1.1 --- a/src/video/x11/SDL_x11events.c	Tue May 27 14:41:16 2014 -0400
     1.2 +++ b/src/video/x11/SDL_x11events.c	Tue May 27 15:40:03 2014 -0400
     1.3 @@ -273,27 +273,24 @@
     1.4  }
     1.5  
     1.6  static void
     1.7 -InitiateWindowMove(SDL_Window *window)
     1.8 +InitiateWindowMove(_THIS, const SDL_WindowData *data, const SDL_Point *point)
     1.9  {
    1.10 -    SDL_SysWMinfo info;
    1.11 -    SDL_VERSION(&info.version);
    1.12 -    SDL_GetWindowWMInfo(window, &info);
    1.13 -    Display *display = info.info.x11.display;
    1.14 +    SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
    1.15 +    SDL_Window* window = data->window;
    1.16 +    Display *display = viddata->display;
    1.17  
    1.18 -    int bx, by, dx, dy;
    1.19 -    SDL_GetWindowPosition(window, &bx, &by);
    1.20 -    SDL_GetMouseState(&dx, &dy);
    1.21 +    /* !!! FIXME: we need to regrab this if necessary when the drag is done. */
    1.22      X11_XUngrabPointer(display, 0L);
    1.23      X11_XFlush(display);
    1.24  
    1.25      XEvent evt;
    1.26      evt.xclient.type = ClientMessage;
    1.27 -    evt.xclient.window = info.info.x11.window;
    1.28 +    evt.xclient.window = data->xwindow;
    1.29      evt.xclient.message_type = X11_XInternAtom(display, "_NET_WM_MOVERESIZE", False);
    1.30      evt.xclient.format = 32;
    1.31 -    evt.xclient.data.l[0] = bx + dx;
    1.32 -    evt.xclient.data.l[1] = by + dy;
    1.33 -    evt.xclient.data.l[2] = 8; /* _NET_WM_MOVERESIZE_MOVE */
    1.34 +    evt.xclient.data.l[0] = window->x + point->x;
    1.35 +    evt.xclient.data.l[1] = window->y + point->y;
    1.36 +    evt.xclient.data.l[2] = 8; /* _NET_WM_MOVERESIZE_MOVE */  /* !!! FIXME: hardcoded 8? */
    1.37      evt.xclient.data.l[3] = Button1;
    1.38      evt.xclient.data.l[4] = 0;
    1.39      X11_XSendEvent(display, DefaultRootWindow(display), False, SubstructureRedirectMask | SubstructureNotifyMask, &evt);
    1.40 @@ -301,20 +298,26 @@
    1.41      X11_XSync(display, 0);
    1.42  }
    1.43  
    1.44 -static void
    1.45 -ProcessDragArea(SDL_WindowData* data)
    1.46 +static SDL_bool
    1.47 +ProcessDragArea(_THIS, const SDL_WindowData *data, const XEvent *xev)
    1.48  {
    1.49 -    SDL_Window* window = data->window;
    1.50 -    SDL_Mouse* mouse = SDL_GetMouse();
    1.51 -    int i;
    1.52 +    const SDL_Window *window = data->window;
    1.53      const int num_areas = window->num_drag_areas;
    1.54 -    const SDL_Point point = {mouse->x, mouse->y};
    1.55 -    const SDL_Rect *areas = window->drag_areas;
    1.56 -    for(i = 0;i < num_areas;++i) {
    1.57 -        if (SDL_PointInRect(&point, &areas[i])) {
    1.58 -            InitiateWindowMove(window);
    1.59 +
    1.60 +    if (num_areas > 0) {
    1.61 +        const SDL_Point point = { xev->xbutton.x, xev->xbutton.y };
    1.62 +        const SDL_Rect *areas = window->drag_areas;
    1.63 +        int i;
    1.64 +
    1.65 +        for (i = 0; i < num_areas; i++) {
    1.66 +            if (SDL_PointInRect(&point, &areas[i])) {
    1.67 +                InitiateWindowMove(_this, data, &point);
    1.68 +                return SDL_TRUE;  /* dragging, drop this event. */
    1.69 +            }
    1.70          }
    1.71      }
    1.72 +
    1.73 +    return SDL_FALSE;  /* not a drag area. */
    1.74  }
    1.75  
    1.76  static void
    1.77 @@ -754,8 +757,10 @@
    1.78              if (X11_IsWheelEvent(display,&xevent,&ticks)) {
    1.79                  SDL_SendMouseWheel(data->window, 0, 0, ticks);
    1.80              } else {
    1.81 -                if(xevent.xbutton.button == SDL_BUTTON_LEFT) {
    1.82 -                    ProcessDragArea(data);
    1.83 +                if(xevent.xbutton.button == Button1) {
    1.84 +                    if (ProcessDragArea(_this, data, &xevent)) {
    1.85 +                        break;  /* don't pass this event on to app. */
    1.86 +                    }
    1.87                  }
    1.88                  SDL_SendMouseButton(data->window, 0, SDL_PRESSED, xevent.xbutton.button);
    1.89              }