Changeset View
Changeset View
Standalone View
Standalone View
intern/ghost/intern/GHOST_SystemX11.cpp
| Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | |||||
| #endif | #endif | ||||
| #include "GHOST_Debug.h" | #include "GHOST_Debug.h" | ||||
| #ifdef WITH_XF86KEYSYM | #ifdef WITH_XF86KEYSYM | ||||
| #include <X11/XF86keysym.h> | #include <X11/XF86keysym.h> | ||||
| #endif | #endif | ||||
| #ifdef WITH_X11_XFIXES | |||||
| # include <X11/extensions/Xfixes.h> | |||||
| /* Workaround for XWayland grab glitch: T53004. */ | |||||
sergey: Indentation. | |||||
| #define WITH_XWAYLAND_HACK | |||||
| #endif | |||||
| /* for XIWarpPointer */ | /* for XIWarpPointer */ | ||||
| #ifdef WITH_X11_XINPUT | #ifdef WITH_X11_XINPUT | ||||
| # include <X11/extensions/XInput2.h> | # include <X11/extensions/XInput2.h> | ||||
| #endif | #endif | ||||
| /* For timing */ | /* For timing */ | ||||
| #include <sys/time.h> | #include <sys/time.h> | ||||
| #include <unistd.h> | #include <unistd.h> | ||||
| Show All 18 Lines | |||||
| #define USE_NON_LATIN_KB_WORKAROUND | #define USE_NON_LATIN_KB_WORKAROUND | ||||
| static GHOST_TKey convertXKey(KeySym key); | static GHOST_TKey convertXKey(KeySym key); | ||||
| /* these are for copy and select copy */ | /* these are for copy and select copy */ | ||||
| static char *txt_cut_buffer = NULL; | static char *txt_cut_buffer = NULL; | ||||
| static char *txt_select_buffer = NULL; | static char *txt_select_buffer = NULL; | ||||
| #ifdef WITH_XWAYLAND_HACK | |||||
| static bool use_xwayland_hack = false; | |||||
| #endif | |||||
| using namespace std; | using namespace std; | ||||
| GHOST_SystemX11:: | GHOST_SystemX11:: | ||||
| GHOST_SystemX11( | GHOST_SystemX11( | ||||
| ) | ) | ||||
| : GHOST_System(), | : GHOST_System(), | ||||
| m_start_time(0) | m_start_time(0) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | #undef GHOST_INTERN_ATOM | ||||
| int use_xkb; | int use_xkb; | ||||
| int xkb_opcode, xkb_event, xkb_error; | int xkb_opcode, xkb_event, xkb_error; | ||||
| int xkb_major = XkbMajorVersion, xkb_minor = XkbMinorVersion; | int xkb_major = XkbMajorVersion, xkb_minor = XkbMinorVersion; | ||||
| use_xkb = XkbQueryExtension(m_display, &xkb_opcode, &xkb_event, &xkb_error, &xkb_major, &xkb_minor); | use_xkb = XkbQueryExtension(m_display, &xkb_opcode, &xkb_event, &xkb_error, &xkb_major, &xkb_minor); | ||||
| if (use_xkb) { | if (use_xkb) { | ||||
| XkbSetDetectableAutoRepeat(m_display, true, NULL); | XkbSetDetectableAutoRepeat(m_display, true, NULL); | ||||
| } | } | ||||
| #ifdef WITH_XWAYLAND_HACK | |||||
| use_xwayland_hack = getenv("WAYLAND_DISPLAY") != NULL; | |||||
| #endif | |||||
| #ifdef WITH_X11_XINPUT | #ifdef WITH_X11_XINPUT | ||||
| /* detect if we have xinput (for reuse) */ | /* detect if we have xinput (for reuse) */ | ||||
| { | { | ||||
| memset(&m_xinput_version, 0, sizeof(m_xinput_version)); | memset(&m_xinput_version, 0, sizeof(m_xinput_version)); | ||||
| XExtensionVersion *version = XGetExtensionVersion(m_display, INAME); | XExtensionVersion *version = XGetExtensionVersion(m_display, INAME); | ||||
| if (version && (version != (XExtensionVersion *)NoSuchExtension)) { | if (version && (version != (XExtensionVersion *)NoSuchExtension)) { | ||||
| if (version->present) { | if (version->present) { | ||||
| m_xinput_version = *version; | m_xinput_version = *version; | ||||
| ▲ Show 20 Lines • Show All 1,279 Lines • ▼ Show 20 Lines | getButtons( | ||||
| } | } | ||||
| else { | else { | ||||
| return GHOST_kFailure; | return GHOST_kFailure; | ||||
| } | } | ||||
| return GHOST_kSuccess; | return GHOST_kSuccess; | ||||
| } | } | ||||
| static GHOST_TSuccess getCursorPosition_impl( | |||||
| GHOST_TSuccess | Display *display, | ||||
| GHOST_SystemX11:: | |||||
| getCursorPosition( | |||||
| GHOST_TInt32& x, | GHOST_TInt32& x, | ||||
| GHOST_TInt32& y) const | GHOST_TInt32& y, | ||||
| Window *child_return) | |||||
| { | { | ||||
| Window root_return, child_return; | |||||
| int rx, ry, wx, wy; | int rx, ry, wx, wy; | ||||
| unsigned int mask_return; | unsigned int mask_return; | ||||
| Window root_return; | |||||
| if (XQueryPointer( | if (XQueryPointer( | ||||
| m_display, | display, | ||||
| RootWindow(m_display, DefaultScreen(m_display)), | RootWindow(display, DefaultScreen(display)), | ||||
| &root_return, | &root_return, | ||||
| &child_return, | child_return, | ||||
| &rx, &ry, | &rx, &ry, | ||||
| &wx, &wy, | &wx, &wy, | ||||
| &mask_return | &mask_return | ||||
| ) == False) { | ) == False) { | ||||
| return GHOST_kFailure; | return GHOST_kFailure; | ||||
| } | } | ||||
| else { | else { | ||||
| x = rx; | x = rx; | ||||
| y = ry; | y = ry; | ||||
| } | } | ||||
| return GHOST_kSuccess; | return GHOST_kSuccess; | ||||
| } | } | ||||
| GHOST_TSuccess | |||||
| GHOST_SystemX11:: | |||||
| getCursorPosition( | |||||
| GHOST_TInt32& x, | |||||
| GHOST_TInt32& y) const | |||||
| { | |||||
| Window child_return; | |||||
| return getCursorPosition_impl(m_display, x, y, &child_return); | |||||
| } | |||||
| GHOST_TSuccess | GHOST_TSuccess | ||||
| GHOST_SystemX11:: | GHOST_SystemX11:: | ||||
| setCursorPosition( | setCursorPosition( | ||||
| GHOST_TInt32 x, | GHOST_TInt32 x, | ||||
| GHOST_TInt32 y) | GHOST_TInt32 y) | ||||
| { | { | ||||
| /* This is a brute force move in screen coordinates | /* This is a brute force move in screen coordinates | ||||
| * XWarpPointer does relative moves so first determine the | * XWarpPointer does relative moves so first determine the | ||||
| * current pointer position. */ | * current pointer position. */ | ||||
| int cx, cy; | int cx, cy; | ||||
| #ifdef WITH_XWAYLAND_HACK | |||||
| Window child_return = None; | |||||
| if (getCursorPosition_impl(m_display, cx, cy, &child_return) == GHOST_kFailure) { | |||||
| return GHOST_kFailure; | |||||
| } | |||||
| #else | |||||
| if (getCursorPosition(cx, cy) == GHOST_kFailure) { | if (getCursorPosition(cx, cy) == GHOST_kFailure) { | ||||
| return GHOST_kFailure; | return GHOST_kFailure; | ||||
| } | } | ||||
| #endif | |||||
| int relx = x - cx; | int relx = x - cx; | ||||
| int rely = y - cy; | int rely = y - cy; | ||||
| #ifdef WITH_XWAYLAND_HACK | |||||
| if (use_xwayland_hack) { | |||||
| if (child_return != None) { | |||||
| XFixesHideCursor(m_display, child_return); | |||||
| } | |||||
| } | |||||
| #endif | |||||
| #ifdef WITH_X11_XINPUT | #ifdef WITH_X11_XINPUT | ||||
| if ((m_xinput_version.present) && | if ((m_xinput_version.present) && | ||||
| (m_xinput_version.major_version >= 2)) | (m_xinput_version.major_version >= 2)) | ||||
| { | { | ||||
| /* Needed to account for XInput "Coordinate Transformation Matrix", see T48901 */ | /* Needed to account for XInput "Coordinate Transformation Matrix", see T48901 */ | ||||
| int device_id; | int device_id; | ||||
| if (XIGetClientPointer(m_display, None, &device_id) != False) { | if (XIGetClientPointer(m_display, None, &device_id) != False) { | ||||
| XIWarpPointer(m_display, device_id, None, None, 0, 0, 0, 0, relx, rely); | XIWarpPointer(m_display, device_id, None, None, 0, 0, 0, 0, relx, rely); | ||||
| } | } | ||||
| } | } | ||||
| else | else | ||||
| #endif | #endif | ||||
| { | { | ||||
| XWarpPointer(m_display, None, None, 0, 0, 0, 0, relx, rely); | XWarpPointer(m_display, None, None, 0, 0, 0, 0, relx, rely); | ||||
| } | } | ||||
| #ifdef WITH_XWAYLAND_HACK | |||||
| if (use_xwayland_hack) { | |||||
| if (child_return != None) { | |||||
| XFixesShowCursor(m_display, child_return); | |||||
| } | |||||
| } | |||||
| #endif | |||||
| XSync(m_display, 0); /* Sync to process all requests */ | XSync(m_display, 0); /* Sync to process all requests */ | ||||
| return GHOST_kSuccess; | return GHOST_kSuccess; | ||||
| } | } | ||||
| void | void | ||||
| GHOST_SystemX11:: | GHOST_SystemX11:: | ||||
| ▲ Show 20 Lines • Show All 690 Lines • Show Last 20 Lines | |||||
Indentation.