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);
59 WId Application::activeDesktopWindow(Display *display, WId rootWindow)
61 qDebug() << __PRETTY_FUNCTION__;
65 unsigned long n, extra;
66 unsigned char *data = 0;
68 Atom atom = XInternAtom(display, ACTIVE_APP_ATOM, false);
70 status = XGetWindowProperty(display, rootWindow, atom, 0L, 16L,
71 0, XA_WINDOW, &realType, &format,
73 if (status == Success && realType == XA_WINDOW &&
74 format == 32 && n == 1 && data != NULL)
75 activeWindow = ((WId*)data)[0];
85 bool Application::x11EventFilter(XEvent *event)
87 qDebug() << __PRETTY_FUNCTION__;
89 static Qt::HANDLE rootWindow = QX11Info::appRootWindow();
90 static Atom activeAppAtom = XInternAtom(QX11Info::display(), ACTIVE_APP_ATOM, false);
92 switch (event->type) {
93 case PropertyNotify: {
94 XPropertyEvent *pevent = (XPropertyEvent*)event;
95 if (pevent->window == rootWindow) {
96 if (pevent->atom == activeAppAtom) {
97 WId activeWindow = activeDesktopWindow(pevent->display, rootWindow);
99 if(m_topmost != m_windows.contains(activeWindow)) {
100 m_topmost = !m_topmost;
101 emit topmostWindowChanged(m_topmost);
112 case EnterNotify: // required when returning from statusbar menu
113 case FocusIn: // required when returning from update location dialog
114 emit showFullScreenButton();
118 // don't block any events here, so false is returned