-// Code taken from KStatusNotifierItem for handling minimize/restore
-
-bool GraphicalUi::checkMainWidgetVisibility(bool perform) {
-#ifdef Q_WS_WIN
- // the problem is that we lose focus when the systray icon is activated
- // and we don't know the former active window
- // therefore we watch for activation event and use our stopwatch :)
- if(GetTickCount() - _dwTickCount < 300) {
- // we were active in the last 300ms -> hide it
- if(perform)
- minimizeRestore(false);
- return false;
- } else {
- if(perform)
- minimizeRestore(true);
- return true;
- }
-
-#elif defined(HAVE_KDE) && defined(Q_WS_X11)
- KWindowInfo info1 = KWindowSystem::windowInfo(mainWidget()->winId(), NET::XAWMState | NET::WMState | NET::WMDesktop);
- // mapped = visible (but possibly obscured)
- bool mapped = (info1.mappingState() == NET::Visible) && !info1.isMinimized();
-
- // - not mapped -> show, raise, focus
- // - mapped
- // - obscured -> raise, focus
- // - not obscured -> hide
- //info1.mappingState() != NET::Visible -> window on another desktop?
- if(!mapped) {
- if(perform)
- minimizeRestore(true);
- return true;
-
- } else {
- QListIterator< WId > it (KWindowSystem::stackingOrder());
- it.toBack();
- while(it.hasPrevious()) {
- WId id = it.previous();
- if(id == mainWidget()->winId())
- break;
-
- KWindowInfo info2 = KWindowSystem::windowInfo(id, NET::WMDesktop | NET::WMGeometry | NET::XAWMState | NET::WMState | NET::WMWindowType);
-
- if(info2.mappingState() != NET::Visible)
- continue; // not visible on current desktop -> ignore
-
- if(!info2.geometry().intersects(mainWidget()->geometry()))
- continue; // not obscuring the window -> ignore