1 | /******************************************************************** |
2 | KWin - the KDE window manager |
3 | This file is part of the KDE project. |
4 | |
5 | Copyright (c) 2011 Lionel Chauvin <megabigbug@yahoo.fr> |
6 | Copyright (c) 2011,2012 Cédric Bellegarde <gnumdk@gmail.com> |
7 | Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org> |
8 | |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by |
11 | the Free Software Foundation; either version 2 of the License, or |
12 | (at your option) any later version. |
13 | |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | GNU General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU General Public License |
20 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | *********************************************************************/ |
22 | #include "appmenu.h" |
23 | #include "client.h" |
24 | #include "workspace.h" |
25 | // Qt |
26 | #include <QtDBus/QDBusConnection> |
27 | #include <QtDBus/QDBusMessage> |
28 | #include <QtDBus/QDBusPendingCall> |
29 | |
30 | namespace KWin { |
31 | |
32 | static const char *KDED_SERVICE = "org.kde.kded" ; |
33 | static const char * = "/modules/appmenu" ; |
34 | static const char *KDED_INTERFACE = "org.kde.kded" ; |
35 | |
36 | KWIN_SINGLETON_FACTORY(ApplicationMenu) |
37 | |
38 | ApplicationMenu::(QObject *parent) |
39 | : QObject(parent) |
40 | { |
41 | QDBusConnection dbus = QDBusConnection::sessionBus(); |
42 | dbus.connect(KDED_SERVICE, KDED_APPMENU_PATH, KDED_INTERFACE, "showRequest" , |
43 | this, SLOT(slotShowRequest(qulonglong))); |
44 | dbus.connect(KDED_SERVICE, KDED_APPMENU_PATH, KDED_INTERFACE, "menuAvailable" , |
45 | this, SLOT(slotMenuAvailable(qulonglong))); |
46 | dbus.connect(KDED_SERVICE, KDED_APPMENU_PATH, KDED_INTERFACE, "menuHidden" , |
47 | this, SLOT(slotMenuHidden(qulonglong))); |
48 | dbus.connect(KDED_SERVICE, KDED_APPMENU_PATH, KDED_INTERFACE, "clearMenus" , |
49 | this, SLOT(slotClearMenus())); |
50 | } |
51 | |
52 | ApplicationMenu::() |
53 | { |
54 | s_self = NULL; |
55 | } |
56 | |
57 | bool ApplicationMenu::(xcb_window_t window) |
58 | { |
59 | return m_windowsMenu.removeOne(window); |
60 | } |
61 | |
62 | void ApplicationMenu::(qulonglong wid) |
63 | { |
64 | if (Client *c = Workspace::self()->findClient(WindowMatchPredicate(wid))) |
65 | c->emitShowRequest(); |
66 | } |
67 | |
68 | void ApplicationMenu::(qulonglong wid) |
69 | { |
70 | if (Client *c = Workspace::self()->findClient(WindowMatchPredicate(wid))) |
71 | c->setAppMenuAvailable(); |
72 | else |
73 | m_windowsMenu.append(wid); |
74 | } |
75 | |
76 | void ApplicationMenu::(qulonglong wid) |
77 | { |
78 | if (Client *c = Workspace::self()->findClient(WindowMatchPredicate(wid))) |
79 | c->emitMenuHidden(); |
80 | } |
81 | |
82 | void ApplicationMenu::() |
83 | { |
84 | foreach (Client *c, Workspace::self()->clientList()) { |
85 | c->setAppMenuUnavailable(); |
86 | } |
87 | } |
88 | |
89 | void ApplicationMenu::(const QPoint &p, const xcb_window_t id) |
90 | { |
91 | QList<QVariant> args = QList<QVariant>() << p.x() << p.y() << qulonglong(id); |
92 | QDBusMessage method = QDBusMessage::createMethodCall(KDED_SERVICE, KDED_APPMENU_PATH, KDED_INTERFACE, "showMenu" ); |
93 | method.setArguments(args); |
94 | QDBusConnection::sessionBus().asyncCall(method); |
95 | } |
96 | |
97 | } // namespace |
98 | |