Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions src/windowtools_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 );
Expand All @@ -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;
Expand Down Expand Up @@ -430,7 +439,6 @@ bool WindowTools_X11::hide()
}

// Get screen number
Display *display = QX11Info::display();
long dummy;

XGetWMNormalHints( display, mWinId, &mSizeHint, &dummy );
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -476,7 +484,6 @@ void WindowTools_X11::doHide()
return;
}

Display *display = QX11Info::display();
long screen = DefaultScreen(display);

/*
Expand Down Expand Up @@ -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 );
Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/windowtools_x11.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down