From ee9530762816686863f01e9cee61d5e5e021992b Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Sat, 28 May 2022 09:38:10 +0800 Subject: [PATCH] fix:remove x11extra private --- goldendict.pro | 2 +- hotkeywrapper.cc | 58 +++++++++++++++++++++++++++++++++++++++++------- hotkeywrapper.hh | 2 +- keyboardstate.cc | 12 ++++++++-- mainwindow.cc | 20 +++++++++++------ 5 files changed, 75 insertions(+), 19 deletions(-) diff --git a/goldendict.pro b/goldendict.pro index 853ce5ab..c854d055 100644 --- a/goldendict.pro +++ b/goldendict.pro @@ -124,7 +124,7 @@ unix:!mac { DEFINES += HAVE_X11 lessThan(QT_MAJOR_VERSION, 6): QT += x11extras - greaterThan(QT_MAJOR_VERSION, 5): QT += gui-private +# greaterThan(QT_MAJOR_VERSION, 5): QT += gui-private CONFIG += link_pkgconfig diff --git a/hotkeywrapper.cc b/hotkeywrapper.cc index c942253c..1a26d9a4 100644 --- a/hotkeywrapper.cc +++ b/hotkeywrapper.cc @@ -468,10 +468,17 @@ void HotkeyWrapper::init() { keyToUngrab = grabbedKeys.end(); +#if QT_VERSION < 0x060000 + Display *displayID = QX11Info::display(); +#else + QNativeInterface::QX11Application *x11AppInfo = qApp->nativeInterface(); + Display *displayID = x11AppInfo->display(); +#endif + // We use RECORD extension instead of XGrabKey. That's because XGrabKey // prevents other clients from getting their input if it's grabbed. - Display * display = QX11Info::display(); + Display * display = displayID; lShiftCode = XKeysymToKeycode( display, XK_Shift_L ); rShiftCode = XKeysymToKeycode( display, XK_Shift_R ); @@ -678,13 +685,25 @@ public: ~X11GrabUngrabErrorHandler() { - XFlush( QX11Info::display() ); +#if QT_VERSION < 0x060000 + Display *displayID = QX11Info::display(); +#else + QNativeInterface::QX11Application *x11AppInfo = qApp->nativeInterface(); + Display *displayID = x11AppInfo->display(); +#endif + XFlush( displayID ); (void) XSetErrorHandler( previousErrorHandler_ ); } bool isError() const { - XFlush( QX11Info::display() ); +#if QT_VERSION < 0x060000 + Display *displayID = QX11Info::display(); +#else + QNativeInterface::QX11Application *x11AppInfo = qApp->nativeInterface(); + Display *displayID = x11AppInfo->display(); +#endif + XFlush( displayID ); return error; } @@ -706,8 +725,14 @@ HotkeyWrapper::GrabbedKeys::iterator HotkeyWrapper::grabKey( quint32 keyCode, if ( result.second ) { +#if QT_VERSION < 0x060000 + Display *displayID = QX11Info::display(); +#else + QNativeInterface::QX11Application *x11AppInfo = qApp->nativeInterface(); + Display *displayID = x11AppInfo->display(); +#endif X11GrabUngrabErrorHandler errorHandler; - XGrabKey( QX11Info::display(), keyCode, modifiers, QX11Info::appRootWindow(), + XGrabKey( displayID, keyCode, modifiers, DefaultRootWindow(displayID), True, GrabModeAsync, GrabModeAsync ); if ( errorHandler.isError() ) @@ -722,8 +747,14 @@ HotkeyWrapper::GrabbedKeys::iterator HotkeyWrapper::grabKey( quint32 keyCode, void HotkeyWrapper::ungrabKey( GrabbedKeys::iterator i ) { +#if QT_VERSION < 0x060000 + Display *displayID = QX11Info::display(); +#else + QNativeInterface::QX11Application *x11AppInfo = qApp->nativeInterface(); + Display *displayID = x11AppInfo->display(); +#endif X11GrabUngrabErrorHandler errorHandler; - XUngrabKey( QX11Info::display(), i->first, i->second, QX11Info::appRootWindow() ); + XUngrabKey( displayID, i->first, i->second, XDefaultRootWindow(displayID) ); grabbedKeys.erase( i ); @@ -746,14 +777,25 @@ quint32 HotkeyWrapper::nativeKey(int key) keySymName = QKeySequence( key ).toString(); break; } - - Display * display = QX11Info::display(); +#if QT_VERSION < 0x060000 + Display *displayID = QX11Info::display(); +#else + QNativeInterface::QX11Application *x11AppInfo = qApp->nativeInterface(); + Display *displayID = x11AppInfo->display(); +#endif + Display * display = displayID; return XKeysymToKeycode( display, XStringToKeysym( keySymName.toLatin1().data() ) ); } void HotkeyWrapper::unregister() { - Display * display = QX11Info::display(); +#if QT_VERSION < 0x060000 + Display *displayID = QX11Info::display(); +#else + QNativeInterface::QX11Application *x11AppInfo = qApp->nativeInterface(); + Display *displayID = x11AppInfo->display(); +#endif + Display * display = displayID; XRecordDisableContext( display, recordContext ); XSync( display, False ); diff --git a/hotkeywrapper.hh b/hotkeywrapper.hh index 844458b2..00ad0965 100644 --- a/hotkeywrapper.hh +++ b/hotkeywrapper.hh @@ -10,7 +10,7 @@ #include #include #if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) -#include +#include #else #include #endif diff --git a/keyboardstate.cc b/keyboardstate.cc index b6163f19..2d336ed0 100644 --- a/keyboardstate.cc +++ b/keyboardstate.cc @@ -8,7 +8,7 @@ #include #elif defined(HAVE_X11) #if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) -#include +#include #else #include #endif @@ -44,9 +44,17 @@ bool KeyboardState::checkModifiersPressed( int mask ) ( mask & Shift && !( keys & ( 1 << shiftKeyBit ) ) ) || ( mask & Win && !( keys & ( 1 << controlKeyBit ) ) ) ); #else + +#if QT_VERSION < 0x060000 + Display *displayID = QX11Info::display(); +#else + QNativeInterface::QX11Application *x11AppInfo = qApp->nativeInterface(); + Display *displayID = x11AppInfo->display(); +#endif + XkbStateRec state; - XkbGetState( QX11Info::display(), XkbUseCoreKbd, &state ); + XkbGetState( displayID, XkbUseCoreKbd, &state ); return !( ( mask & Alt && !( state.base_mods & Mod1Mask ) ) || diff --git a/mainwindow.cc b/mainwindow.cc index 9876c8b4..11b523a0 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -65,7 +65,7 @@ #ifdef HAVE_X11 #if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) -#include +#include #else #include #endif @@ -2903,9 +2903,15 @@ void MainWindow::toggleMainWindow( bool onlyShow ) focusTranslateLine(); #ifdef HAVE_X11 +#if QT_VERSION < 0x060000 + Display *displayID = QX11Info::display(); +#else + QNativeInterface::QX11Application *x11AppInfo = qApp->nativeInterface(); + Display *displayID = x11AppInfo->display(); +#endif Window wh = 0; int rev = 0; - XGetInputFocus( QX11Info::display(), &wh, &rev ); + XGetInputFocus( displayID, &wh, &rev ); if( wh != translateLine->internalWinId() && !byIconClick ) { QPoint p( 1, 1 ); @@ -2918,17 +2924,17 @@ void MainWindow::toggleMainWindow( bool onlyShow ) event.xbutton.x_root = p.x(); event.xbutton.y_root = p.y(); event.xbutton.window = internalWinId(); - event.xbutton.root = QX11Info::appRootWindow( QX11Info::appScreen() ); + event.xbutton.root = XDefaultRootWindow(displayID); event.xbutton.state = Button1Mask; event.xbutton.button = Button1; event.xbutton.same_screen = true; event.xbutton.time = CurrentTime; - XSendEvent( QX11Info::display(), internalWinId(), true, 0xfff, &event ); - XFlush( QX11Info::display() ); + XSendEvent( displayID, internalWinId(), true, 0xfff, &event ); + XFlush( displayID ); event.type = ButtonRelease; - XSendEvent( QX11Info::display(), internalWinId(), true, 0xfff, &event ); - XFlush( QX11Info::display() ); + XSendEvent( displayID, internalWinId(), true, 0xfff, &event ); + XFlush( displayID ); } #endif }