2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Henri Lampela - henri.lampela@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25 #include "application.h"
28 #include <X11/Xatom.h>
29 #include <X11/Xutil.h>
32 #define ACTIVE_APP_ATOM "_MB_CURRENT_APP_WINDOW"
34 #define ACTIVE_APP_ATOM "_NET_ACTIVE_WINDOW"
37 Application::Application(int &argc, char **argv)
38 : QApplication(argc, argv),
41 qDebug() << __PRETTY_FUNCTION__;
44 void Application::registerWindow(WId window)
46 qDebug() << __PRETTY_FUNCTION__;
48 m_windows.append(window);
51 void Application::unregisterWindow(WId window)
53 qDebug() << __PRETTY_FUNCTION__;
55 m_windows.removeOne(window);
58 WId Application::activeDesktopWindow(Display *display, WId rootWindow)
60 qDebug() << __PRETTY_FUNCTION__;
64 unsigned long n, extra;
65 unsigned char *data = 0;
67 Atom atom = XInternAtom(display, ACTIVE_APP_ATOM, false);
69 status = XGetWindowProperty(display, rootWindow, atom, 0L, 16L,
70 0, XA_WINDOW, &realType, &format,
72 if (status == Success && realType == XA_WINDOW &&
73 format == 32 && n == 1 && data != NULL)
74 activeWindow = ((WId*)data)[0];
84 bool Application::x11EventFilter(XEvent *event)
86 qDebug() << __PRETTY_FUNCTION__;
88 static Qt::HANDLE rootWindow = QX11Info::appRootWindow();
89 static Atom activeAppAtom = XInternAtom(QX11Info::display(), ACTIVE_APP_ATOM, false);
91 switch (event->type) {
92 case PropertyNotify: {
93 XPropertyEvent *pevent = (XPropertyEvent*)event;
94 if (pevent->window == rootWindow) {
95 if (pevent->atom == activeAppAtom) {
96 WId activeWindow = activeDesktopWindow(pevent->display, rootWindow);
98 if(m_topmost != m_windows.contains(activeWindow)) {
99 m_topmost = !m_topmost;
100 emit topmostWindowChanged(m_topmost);
111 case EnterNotify: // required when returning from statusbar menu
112 case FocusIn: // required when returning from update location dialog
113 emit showFullScreenButton();
117 // don't block any events here, so false is returned