Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:alois
glfw
glfw-add-drag-window.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File glfw-add-drag-window.patch of Package glfw
From a4c76fbeed6c1a735b883c86c256e07d4958193b Mon Sep 17 00:00:00 2001 From: Felipe Ferreira da Silva <felipefsdev@gmail.com> Date: Wed, 5 Apr 2017 22:14:09 -0300 Subject: [PATCH 1/4] Add glfwDragWindow This is the initial implementation of glfwDragWindow, with support for X11. The function glfwDragWindow requires only the target window to be dragged. To make the function easier and more portable, the position of the window and of the cursor are grabbed internally, so the end-user do not need to pass them manually. The example 'simple.c' was updated to include this functionality when clicking on the client area of the window. --- examples/simple.c | 7 +++++++ include/GLFW/glfw3.h | 15 +++++++++++++++ src/internal.h | 1 + src/null_window.c | 4 ++++ src/window.c | 10 ++++++++++ src/wl_window.c | 5 +++++ src/x11_window.c | 23 +++++++++++++++++++++++ 7 files changed, 65 insertions(+) Index: glfw-3.3.8/include/GLFW/glfw3.h =================================================================== --- glfw-3.3.8.orig/include/GLFW/glfw3.h +++ glfw-3.3.8/include/GLFW/glfw3.h @@ -3385,6 +3385,21 @@ GLFWAPI void glfwHideWindow(GLFWwindow* */ GLFWAPI void glfwFocusWindow(GLFWwindow* window); +/*! @brief Starts drag operation to the specified window. + * + * This function starts the drag operation of the specified window. + * + * @param[in] window The window to start the dragging operation. + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_drag + * + * @since Added in version 3.3. + * + * @ingroup window + */ +GLFWAPI void glfwDragWindow(GLFWwindow* handle); + /*! @brief Requests user attention to the specified window. * * This function requests user attention to the specified window. On Index: glfw-3.3.8/src/null_window.c =================================================================== --- glfw-3.3.8.orig/src/null_window.c +++ glfw-3.3.8/src/null_window.c @@ -231,6 +231,10 @@ void _glfwPlatformFocusWindow(_GLFWwindo { } +void _glfwPlatformDragWindow(_GLFWwindow* window) +{ +} + int _glfwPlatformWindowFocused(_GLFWwindow* window) { return GLFW_FALSE; Index: glfw-3.3.8/src/window.c =================================================================== --- glfw-3.3.8.orig/src/window.c +++ glfw-3.3.8/src/window.c @@ -797,6 +797,16 @@ GLFWAPI void glfwFocusWindow(GLFWwindow* _glfwPlatformFocusWindow(window); } +GLFWAPI void glfwDragWindow(GLFWwindow* handle) +{ + _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window != NULL); + + _GLFW_REQUIRE_INIT(); + + _glfwPlatformDragWindow(window); +} + GLFWAPI int glfwGetWindowAttrib(GLFWwindow* handle, int attrib) { _GLFWwindow* window = (_GLFWwindow*) handle; Index: glfw-3.3.8/src/wl_window.c =================================================================== --- glfw-3.3.8.orig/src/wl_window.c +++ glfw-3.3.8/src/wl_window.c @@ -2152,6 +2152,11 @@ void _glfwPlatformFocusWindow(_GLFWwindo "Wayland: Focusing a window requires user interaction"); } +void _glfwPlatformDragWindow(_GLFWwindow* window) +{ + wl_shell_surface_move(window->wl.shellSurface, _glfw.wl.seat, _glfw.wl.pointerSerial); +} + void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, Index: glfw-3.3.8/src/x11_window.c =================================================================== --- glfw-3.3.8.orig/src/x11_window.c +++ glfw-3.3.8/src/x11_window.c @@ -49,6 +49,7 @@ #define _NET_WM_STATE_REMOVE 0 #define _NET_WM_STATE_ADD 1 #define _NET_WM_STATE_TOGGLE 2 +#define _NET_WM_MOVERESIZE_MOVE 8 // Additional mouse button names for XButtonEvent #define Button6 6 @@ -2472,6 +2473,28 @@ void _glfwPlatformFocusWindow(_GLFWwindo XFlush(_glfw.x11.display); } +void _glfwPlatformDragWindow(_GLFWwindow* window) +{ + int winXpos, winYpos; + double curXpos, curYpos; + XClientMessageEvent xclient; + memset(&xclient, 0, sizeof(XClientMessageEvent)); + XUngrabPointer(_glfw.x11.display, 0); + XFlush(_glfw.x11.display); + _glfwPlatformGetCursorPos(window, &curXpos, &curYpos); + _glfwPlatformGetWindowPos(window, &winXpos, &winYpos); + xclient.type = ClientMessage; + xclient.window = window->x11.handle; + xclient.message_type = XInternAtom(_glfw.x11.display, "_NET_WM_MOVERESIZE", False); + xclient.format = 32; + xclient.data.l[0] = winXpos + curXpos; + xclient.data.l[1] = winYpos + curYpos; + xclient.data.l[2] = _NET_WM_MOVERESIZE_MOVE; + xclient.data.l[3] = 0; + xclient.data.l[4] = 0; + XSendEvent(_glfw.x11.display, _glfw.x11.root, False, SubstructureRedirectMask | SubstructureNotifyMask, (XEvent *)&xclient); +} + void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, Index: glfw-3.3.8/tests/windows.c =================================================================== --- glfw-3.3.8.orig/tests/windows.c +++ glfw-3.3.8/tests/windows.c @@ -90,6 +90,12 @@ static void key_callback(GLFWwindow* win } } +void mouse_button_callback(GLFWwindow* window, int button, int action, int mods) +{ + if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) + glfwDragWindow(window); +} + int main(int argc, char** argv) { int i, ch; @@ -139,6 +145,7 @@ int main(int argc, char** argv) } glfwSetKeyCallback(windows[i], key_callback); + glfwSetMouseButtonCallback(windows[i], mouse_button_callback); glfwMakeContextCurrent(windows[i]); gladLoadGL(glfwGetProcAddress);
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor