Initial work on X11 implementation of SDL_SetWindowDragAreas().
parent
3cbc83ef11
commit
2744c0195a
|
@ -272,6 +272,51 @@ X11_DispatchUnmapNotify(SDL_WindowData *data)
|
||||||
SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
|
SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
InitiateWindowMove(SDL_Window *window)
|
||||||
|
{
|
||||||
|
SDL_SysWMinfo info;
|
||||||
|
SDL_VERSION(&info.version);
|
||||||
|
SDL_GetWindowWMInfo(window, &info);
|
||||||
|
Display *display = info.info.x11.display;
|
||||||
|
|
||||||
|
int bx, by, dx, dy;
|
||||||
|
SDL_GetWindowPosition(window, &bx, &by);
|
||||||
|
SDL_GetMouseState(&dx, &dy);
|
||||||
|
X11_XUngrabPointer(display, 0L);
|
||||||
|
X11_XFlush(display);
|
||||||
|
|
||||||
|
XEvent evt;
|
||||||
|
evt.xclient.type = ClientMessage;
|
||||||
|
evt.xclient.window = info.info.x11.window;
|
||||||
|
evt.xclient.message_type = X11_XInternAtom(display, "_NET_WM_MOVERESIZE", False);
|
||||||
|
evt.xclient.format = 32;
|
||||||
|
evt.xclient.data.l[0] = bx + dx;
|
||||||
|
evt.xclient.data.l[1] = by + dy;
|
||||||
|
evt.xclient.data.l[2] = 8; /* _NET_WM_MOVERESIZE_MOVE */
|
||||||
|
evt.xclient.data.l[3] = Button1;
|
||||||
|
evt.xclient.data.l[4] = 0;
|
||||||
|
X11_XSendEvent(display, DefaultRootWindow(display), False, SubstructureRedirectMask | SubstructureNotifyMask, &evt);
|
||||||
|
|
||||||
|
X11_XSync(display, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ProcessDragArea(SDL_WindowData* data)
|
||||||
|
{
|
||||||
|
SDL_Window* window = data->window;
|
||||||
|
SDL_Mouse* mouse = SDL_GetMouse();
|
||||||
|
int i;
|
||||||
|
const int num_areas = window->num_drag_areas;
|
||||||
|
const SDL_Point point = {mouse->x, mouse->y};
|
||||||
|
const SDL_Rect *areas = window->drag_areas;
|
||||||
|
for(i = 0;i < num_areas;++i) {
|
||||||
|
if (SDL_PointInRect(&point, &areas[i])) {
|
||||||
|
InitiateWindowMove(window);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
X11_DispatchEvent(_THIS)
|
X11_DispatchEvent(_THIS)
|
||||||
{
|
{
|
||||||
|
@ -709,6 +754,9 @@ X11_DispatchEvent(_THIS)
|
||||||
if (X11_IsWheelEvent(display,&xevent,&ticks)) {
|
if (X11_IsWheelEvent(display,&xevent,&ticks)) {
|
||||||
SDL_SendMouseWheel(data->window, 0, 0, ticks);
|
SDL_SendMouseWheel(data->window, 0, 0, ticks);
|
||||||
} else {
|
} else {
|
||||||
|
if(xevent.xbutton.button == SDL_BUTTON_LEFT) {
|
||||||
|
ProcessDragArea(data);
|
||||||
|
}
|
||||||
SDL_SendMouseButton(data->window, 0, SDL_PRESSED, xevent.xbutton.button);
|
SDL_SendMouseButton(data->window, 0, SDL_PRESSED, xevent.xbutton.button);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -457,6 +457,7 @@ X11_CreateDevice(int devindex)
|
||||||
device->UpdateWindowFramebuffer = X11_UpdateWindowFramebuffer;
|
device->UpdateWindowFramebuffer = X11_UpdateWindowFramebuffer;
|
||||||
device->DestroyWindowFramebuffer = X11_DestroyWindowFramebuffer;
|
device->DestroyWindowFramebuffer = X11_DestroyWindowFramebuffer;
|
||||||
device->GetWindowWMInfo = X11_GetWindowWMInfo;
|
device->GetWindowWMInfo = X11_GetWindowWMInfo;
|
||||||
|
device->SetWindowDragAreas = X11_SetWindowDragAreas;
|
||||||
|
|
||||||
device->shape_driver.CreateShaper = X11_CreateShaper;
|
device->shape_driver.CreateShaper = X11_CreateShaper;
|
||||||
device->shape_driver.SetWindowShape = X11_SetWindowShape;
|
device->shape_driver.SetWindowShape = X11_SetWindowShape;
|
||||||
|
|
|
@ -1444,6 +1444,12 @@ X11_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
X11_SetWindowDragAreas(SDL_Window *window, const SDL_Rect *areas, int num_areas)
|
||||||
|
{
|
||||||
|
return 0; // nothing to do, will be handled in event handler
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* SDL_VIDEO_DRIVER_X11 */
|
#endif /* SDL_VIDEO_DRIVER_X11 */
|
||||||
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
/* vi: set ts=4 sw=4 expandtab: */
|
||||||
|
|
|
@ -93,6 +93,7 @@ extern void X11_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
|
||||||
extern void X11_DestroyWindow(_THIS, SDL_Window * window);
|
extern void X11_DestroyWindow(_THIS, SDL_Window * window);
|
||||||
extern SDL_bool X11_GetWindowWMInfo(_THIS, SDL_Window * window,
|
extern SDL_bool X11_GetWindowWMInfo(_THIS, SDL_Window * window,
|
||||||
struct SDL_SysWMinfo *info);
|
struct SDL_SysWMinfo *info);
|
||||||
|
extern int X11_SetWindowDragAreas(SDL_Window *window, const SDL_Rect *areas, int num_areas);
|
||||||
|
|
||||||
#endif /* _SDL_x11window_h */
|
#endif /* _SDL_x11window_h */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue