From 3c86967a318c01499b4129a6620f33f5118fb204 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 20 Jun 2013 12:28:49 -0500 Subject: Add ability to set active window to TDEMainWindow (cherry picked from commit 6f1973a708396873d12b51b32667bd0b9a530263) --- kdeui/kmainwindowiface.cpp | 37 +++++++++++++++++++++++++++++++++++++ kdeui/kmainwindowiface.h | 2 ++ 2 files changed, 39 insertions(+) (limited to 'kdeui') diff --git a/kdeui/kmainwindowiface.cpp b/kdeui/kmainwindowiface.cpp index f8ef88c31..da4d468a6 100644 --- a/kdeui/kmainwindowiface.cpp +++ b/kdeui/kmainwindowiface.cpp @@ -27,6 +27,29 @@ #include #include +#include +#include + +// INTERNAL +// Originally from http://permalink.gmane.org/gmane.comp.lib.qt.general/4733 +void wmMessage(KMainWindow * mainWindow, long type, long l0, long l1, long l2, long l3, long l4) +{ + XClientMessageEvent xev; + + xev.type = ClientMessage; + xev.window = mainWindow->winId(); + xev.message_type = type; + xev.format = 32; + xev.data.l[0] = l0; + xev.data.l[1] = l1; + xev.data.l[2] = l2; + xev.data.l[3] = l3; + xev.data.l[4] = l4; + + XSendEvent(mainWindow->x11Display(), mainWindow->winId(), False, + (SubstructureNotifyMask | SubstructureRedirectMask), + (XEvent *)&xev); +} KMainWindowInterface::KMainWindowInterface(KMainWindow * mainWindow) : DCOPObject( mainWindow->name()) @@ -182,6 +205,20 @@ void KMainWindowInterface::show() { m_MainWindow->show(); } +void KMainWindowInterface::setActiveWindow() +{ + m_MainWindow->setActiveWindow(); +} +void KMainWindowInterface::setActiveWindowFocused() +{ + // just in case we don't have a WM running + m_MainWindow->raise(); + m_MainWindow->setActiveWindow(); + + // activate window (try to work around focus-stealing prevention) + static Atom NET_ACTIVE_WINDOW = XInternAtom(m_MainWindow->x11Display(), "_NET_ACTIVE_WINDOW", False); + wmMessage(m_MainWindow, NET_ACTIVE_WINDOW, 2, CurrentTime, 0, 0, 0); +} QCStringList KMainWindowInterface::functionsDynamic() { return m_dcopPropertyProxy->functions(); diff --git a/kdeui/kmainwindowiface.h b/kdeui/kmainwindowiface.h index f7f7a0bb8..8e56a2532 100644 --- a/kdeui/kmainwindowiface.h +++ b/kdeui/kmainwindowiface.h @@ -147,6 +147,8 @@ k_dcop: void restore(); void show(); void close(); + void setActiveWindow(); + void setActiveWindowFocused(); // QCStringList getQTProperties(); -- cgit v1.2.1