From 6f1973a708396873d12b51b32667bd0b9a530263 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 --- tdeui/tdemainwindowiface.cpp | 37 +++++++++++++++++++++++++++++++++++++ tdeui/tdemainwindowiface.h | 2 ++ 2 files changed, 39 insertions(+) diff --git a/tdeui/tdemainwindowiface.cpp b/tdeui/tdemainwindowiface.cpp index 8f8a9d40c..7161ec86f 100644 --- a/tdeui/tdemainwindowiface.cpp +++ b/tdeui/tdemainwindowiface.cpp @@ -27,6 +27,29 @@ #include #include +#include +#include + +// INTERNAL +// Originally from http://permalink.gmane.org/gmane.comp.lib.qt.general/4733 +void wmMessage(TDEMainWindow * 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); +} TDEMainWindowInterface::TDEMainWindowInterface(TDEMainWindow * mainWindow) : DCOPObject( mainWindow->name()) @@ -182,6 +205,20 @@ void TDEMainWindowInterface::show() { m_MainWindow->show(); } +void TDEMainWindowInterface::setActiveWindow() +{ + m_MainWindow->setActiveWindow(); +} +void TDEMainWindowInterface::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 TDEMainWindowInterface::functionsDynamic() { return m_dcopPropertyProxy->functions(); diff --git a/tdeui/tdemainwindowiface.h b/tdeui/tdemainwindowiface.h index f469096ef..736aefc1d 100644 --- a/tdeui/tdemainwindowiface.h +++ b/tdeui/tdemainwindowiface.h @@ -147,6 +147,8 @@ k_dcop: void restore(); void show(); void close(); + void setActiveWindow(); + void setActiveWindowFocused(); // QCStringList getQTProperties(); -- cgit v1.2.1