+#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
+
+ if (!info1.hasState(NET::KeepAbove) && info2.hasState(NET::KeepAbove))
+ continue; // obscured by window kept above -> ignore
+
+ NET::WindowType type = info2.windowType(NET::NormalMask | NET::DesktopMask
+ | NET::DockMask | NET::ToolbarMask | NET::MenuMask | NET::DialogMask
+ | NET::OverrideMask | NET::TopMenuMask | NET::UtilityMask | NET::SplashMask);
+
+ if (type == NET::Dock || type == NET::TopMenu)
+ continue; // obscured by dock or topmenu -> ignore
+
+ if (perform) {
+ KWindowSystem::raiseWindow(mainWidget()->winId());
+ KWindowSystem::activateWindow(mainWidget()->winId());
+ }
+ return true;
+ }
+
+ //not on current desktop?
+ if (!info1.isOnCurrentDesktop()) {
+ if (perform)
+ KWindowSystem::activateWindow(mainWidget()->winId());
+ return true;
+ }
+
+ if (perform)
+ minimizeRestore(false); // hide
+ return false;
+ }