diff --git a/src/windowtools_x11.cpp b/src/windowtools_x11.cpp index b67b6d05..1ffc5e3a 100644 --- a/src/windowtools_x11.cpp +++ b/src/windowtools_x11.cpp @@ -359,6 +359,17 @@ WindowTools_X11::WindowTools_X11() mWinId = None; mHiddenStateCounter = 0; + if ( QX11Info::isPlatformX11() ) + { + display = QX11Info::display(); + root = QX11Info::appRootWindow(); + } + else + { + display = XOpenDisplay(NULL); + root = display ? DefaultRootWindow(display) : 0; + } + connect( &mWindowStateTimer, &QTimer::timeout, this, &WindowTools_X11::timerWindowState ); mWindowStateTimer.setInterval( 250 ); mWindowStateTimer.start(); @@ -370,13 +381,14 @@ WindowTools_X11::~WindowTools_X11() bool WindowTools_X11::lookup() { - if ( QX11Info::appRootWindow() == 0 ) + // Root window is invalid (error connecting?) + if ( root == 0 ) return false; if ( isValid() ) return true; - mWinId = findWindow(QX11Info::display(), QX11Info::appRootWindow(), ! BirdtrayApp::get()->getSettings()->mIgnoreNETWMhints, + mWinId = findWindow(display, root, ! BirdtrayApp::get()->getSettings()->mIgnoreNETWMhints, BirdtrayApp::get()->getSettings()->mThunderbirdWindowMatch); Log::debug("Window ID found: %lX", mWinId ); @@ -389,9 +401,6 @@ bool WindowTools_X11::show() if ( !checkWindow() ) return false; - Display *display = QX11Info::display(); - Window root = QX11Info::appRootWindow(); - // We are still minimizing if ( mHiddenStateCounter == 1 ) return false; @@ -430,7 +439,6 @@ bool WindowTools_X11::hide() } // Get screen number - Display *display = QX11Info::display(); long dummy; XGetWMNormalHints( display, mWinId, &mSizeHint, &dummy ); @@ -444,7 +452,7 @@ bool WindowTools_X11::hide() bool WindowTools_X11::isHidden() { - return mHiddenStateCounter == 2 && mWinId != activeWindow( QX11Info::display() ); + return mHiddenStateCounter == 2 && mWinId != activeWindow( display ); } bool WindowTools_X11::closeWindow() @@ -456,13 +464,13 @@ bool WindowTools_X11::closeWindow() // send _NET_CLOSE_WINDOW long l[5] = {0, 0, 0, 0, 0}; - sendMessage( QX11Info::display(), QX11Info::appRootWindow(), mWinId, "_NET_CLOSE_WINDOW", 32, SubstructureNotifyMask | SubstructureRedirectMask, l, sizeof (l)); + sendMessage( display, root, mWinId, "_NET_CLOSE_WINDOW", 32, SubstructureNotifyMask | SubstructureRedirectMask, l, sizeof (l)); return true; } bool WindowTools_X11::isValid() { - return mWinId != None && isValidWindowId( QX11Info::display(), mWinId ); + return mWinId != None && isValidWindowId( display, mWinId ); } void WindowTools_X11::doHide() @@ -476,7 +484,6 @@ void WindowTools_X11::doHide() return; } - Display *display = QX11Info::display(); long screen = DefaultScreen(display); /* @@ -505,7 +512,7 @@ void WindowTools_X11::timerWindowState() } // _NET_WM_STATE_HIDDEN is set for minimized windows, so if we see it, this means it was minimized by the user - if ( checkWindowState( QX11Info::display(), mWinId, "_NET_WM_STATE_HIDDEN" ) && mHiddenStateCounter == 0 ) + if ( checkWindowState( display, mWinId, "_NET_WM_STATE_HIDDEN" ) && mHiddenStateCounter == 0 ) { mHiddenStateCounter = 1; QTimer::singleShot( 0, this, &WindowTools_X11::doHide ); @@ -514,7 +521,7 @@ void WindowTools_X11::timerWindowState() bool WindowTools_X11::checkWindow() { - if ( mWinId == None || !isValidWindowId( QX11Info::display(), mWinId ) ) + if ( mWinId == None || !isValidWindowId( display, mWinId ) ) return lookup(); return true; diff --git a/src/windowtools_x11.h b/src/windowtools_x11.h index 9d6983a8..cc3d5a33 100644 --- a/src/windowtools_x11.h +++ b/src/windowtools_x11.h @@ -47,6 +47,12 @@ class WindowTools_X11 : public WindowTools // Makes sure our window ID is still valid, or reinitializes it bool checkWindow(); + // The display handle to use to talk to the X server + Display *display; + + // The root window ID + Window root; + // Our Window ID Window mWinId;