Merge lp:~dyams/unity-2d/mm-updates-pips into lp:unity-2d

Proposed by Lohith D Shivamurthy
Status: Superseded
Proposed branch: lp:~dyams/unity-2d/mm-updates-pips
Merge into: lp:unity-2d
Diff against target: 1218 lines (+638/-222)
15 files modified
libunity-2d-private/src/launcherapplication.cpp (+88/-0)
libunity-2d-private/src/launcherapplication.h (+5/-0)
libunity-2d-private/src/launcheritem.cpp (+6/-0)
libunity-2d-private/src/launcheritem.h (+2/-0)
libunity-2d-private/src/screeninfo.cpp (+15/-0)
libunity-2d-private/src/screeninfo.h (+2/-0)
shell/Shell.qml (+5/-1)
shell/app/CMakeLists.txt (+2/-0)
shell/app/shell.cpp (+3/-51)
shell/app/shelldeclarativeview.cpp (+52/-147)
shell/app/shelldeclarativeview.h (+16/-20)
shell/app/shellmanager.cpp (+380/-0)
shell/app/shellmanager.h (+58/-0)
shell/launcher/LauncherList.qml (+3/-2)
shell/launcher/LauncherLoader.qml (+1/-1)
To merge this branch: bzr merge lp:~dyams/unity-2d/mm-updates-pips
Reviewer Review Type Date Requested Status
Albert Astals Cid Pending
Review via email: mp+93350@code.launchpad.net

Description of the change

[shell][Multimonitor] update pips to show whether application belongs to current screen or not

To post a comment you must log in.
lp:~dyams/unity-2d/mm-updates-pips updated
922. By Lohith D Shivamurthy

fix comments

Unmerged revisions

922. By Lohith D Shivamurthy

fix comments

921. By Lohith D Shivamurthy

[shell] update pips to show whether application belongs to current screen or not

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libunity-2d-private/src/launcherapplication.cpp'
--- libunity-2d-private/src/launcherapplication.cpp 2012-02-06 12:07:47 +0000
+++ libunity-2d-private/src/launcherapplication.cpp 2012-02-16 08:16:20 +0000
@@ -43,6 +43,7 @@
43// libunity-2d43// libunity-2d
44#include <unity2dtr.h>44#include <unity2dtr.h>
45#include <debug_p.h>45#include <debug_p.h>
46#include <screeninfo.h>
4647
47// Qt48// Qt
48#include <Qt>49#include <Qt>
@@ -62,6 +63,14 @@
62#include <libsn/sn.h>63#include <libsn/sn.h>
63}64}
6465
66#define GOBJECT_CALLBACK0(callbackName, slot) \
67static void \
68callbackName(GObject* src, QObject* dst) \
69{ \
70 QMetaObject::invokeMethod(dst, slot); \
71}
72GOBJECT_CALLBACK0(geometryChangedCB, "onWindowGeometryChanged")
73
65const char* SHORTCUT_NICK_PROPERTY = "nick";74const char* SHORTCUT_NICK_PROPERTY = "nick";
6675
67LauncherApplication::LauncherApplication()76LauncherApplication::LauncherApplication()
@@ -91,6 +100,7 @@
91100
92LauncherApplication::~LauncherApplication()101LauncherApplication::~LauncherApplication()
93{102{
103 disconnectWindowSignals();
94}104}
95105
96bool106bool
@@ -526,6 +536,29 @@
526 WnckWindow* window = wnck_window_get(xids->at(i));536 WnckWindow* window = wnck_window_get(xids->at(i));
527 g_signal_connect(G_OBJECT(window), "workspace-changed",537 g_signal_connect(G_OBJECT(window), "workspace-changed",
528 G_CALLBACK(LauncherApplication::onWindowWorkspaceChanged), this);538 G_CALLBACK(LauncherApplication::onWindowWorkspaceChanged), this);
539 g_signal_connect(G_OBJECT(window), "geometry-changed", G_CALLBACK(geometryChangedCB), this);
540 }
541}
542
543void
544LauncherApplication::disconnectWindowSignals()
545{
546 if (m_application == NULL || m_application->running() == false) {
547 return;
548 }
549
550 QScopedPointer<BamfUintList> xids(m_application->xids());
551 int size = xids->size();
552 if (size < 1) {
553 return;
554 }
555
556 WnckScreen* screen = wnck_screen_get_default();
557 wnck_screen_force_update(screen);
558
559 for (int i = 0; i < size; ++i) {
560 WnckWindow* window = wnck_window_get(xids->at(i));
561 g_signal_handlers_disconnect_by_func(window, gpointer(geometryChangedCB), this);
529 }562 }
530}563}
531564
@@ -537,6 +570,7 @@
537 WnckWindow* wnck_window = wnck_window_get(window->xid());570 WnckWindow* wnck_window = wnck_window_get(window->xid());
538 g_signal_connect(G_OBJECT(wnck_window), "workspace-changed",571 g_signal_connect(G_OBJECT(wnck_window), "workspace-changed",
539 G_CALLBACK(LauncherApplication::onWindowWorkspaceChanged), this);572 G_CALLBACK(LauncherApplication::onWindowWorkspaceChanged), this);
573 g_signal_connect(G_OBJECT(window), "geometry-changed", G_CALLBACK(geometryChangedCB), this);
540 }574 }
541}575}
542576
@@ -665,6 +699,42 @@
665 return windowCount;699 return windowCount;
666}700}
667701
702int
703LauncherApplication::windowCountOnCurrentScreen(int screen)
704{
705 int windowCount = 0;
706
707 if (!m_application) {
708 return windowCount;
709 }
710
711 ScreenInfo screenInfo(screen);
712 QScopedPointer<BamfUintList> xids(m_application->xids());
713 for (int i = 0; i < xids->size(); i++) {
714 /* When geting the wnck window, it's possible we get a NULL
715 return value because wnck hasn't updated its internal list yet,
716 so we need to force it once to be sure */
717 WnckWindow *window = wnck_window_get(xids->at(i));
718 if (window == NULL) {
719 wnck_screen_force_update(wnck_screen_get_default());
720 window = wnck_window_get(xids->at(i));
721 if (window == NULL) {
722 continue;
723 }
724 }
725
726 // Check the window screen
727 int x, y, width, height;
728 wnck_window_get_geometry(window, &x, &y, &width, &height);
729 QRect windowRect(x, y, width, height);
730 QPoint pos = windowRect.center();
731 if (ScreenInfo::screenNumber(pos) == screen) {
732 windowCount++;
733 }
734 }
735 return windowCount;
736}
737
668void738void
669LauncherApplication::activate()739LauncherApplication::activate()
670{740{
@@ -986,6 +1056,18 @@
986 return false;1056 return false;
987}1057}
9881058
1059bool
1060LauncherApplication::belongsToDifferentScreen(int screen)
1061{
1062 int totalWindows = windowCount();
1063 int windowsInCurrentScreen = windowCountOnCurrentScreen(screen);
1064 if (totalWindows > 0 && windowsInCurrentScreen == 0) {
1065 return true;
1066 }
1067
1068 return false;
1069}
1070
989void1071void
990LauncherApplication::onIndicatorMenuUpdated()1072LauncherApplication::onIndicatorMenuUpdated()
991{1073{
@@ -1110,6 +1192,12 @@
1110}1192}
11111193
1112void1194void
1195LauncherApplication::onWindowGeometryChanged()
1196{
1197 windowGeometryChanged();
1198}
1199
1200void
1113LauncherApplication::onDragEnter(DeclarativeDragDropEvent* event)1201LauncherApplication::onDragEnter(DeclarativeDragDropEvent* event)
1114{1202{
1115 QList<QUrl> urls = validateUrisForLaunch(event->mimeData());1203 QList<QUrl> urls = validateUrisForLaunch(event->mimeData());
11161204
=== modified file 'libunity-2d-private/src/launcherapplication.h'
--- libunity-2d-private/src/launcherapplication.h 2012-02-06 12:07:47 +0000
+++ libunity-2d-private/src/launcherapplication.h 2012-02-16 08:16:20 +0000
@@ -105,7 +105,9 @@
105105
106 Q_INVOKABLE virtual void createMenuActions();106 Q_INVOKABLE virtual void createMenuActions();
107 Q_INVOKABLE virtual bool belongsToDifferentWorkspace();107 Q_INVOKABLE virtual bool belongsToDifferentWorkspace();
108 Q_INVOKABLE virtual bool belongsToDifferentScreen(int screen);
108 Q_INVOKABLE void connectWindowSignals();109 Q_INVOKABLE void connectWindowSignals();
110 void disconnectWindowSignals();
109111
110 void updateOverlaysState(const QString& sender, const QMap<QString, QVariant>& properties);112 void updateOverlaysState(const QString& sender, const QMap<QString, QVariant>& properties);
111113
@@ -151,6 +153,8 @@
151 void onDragEnter(DeclarativeDragDropEvent*);153 void onDragEnter(DeclarativeDragDropEvent*);
152 void onDrop(DeclarativeDragDropEvent*);154 void onDrop(DeclarativeDragDropEvent*);
153155
156 void onWindowGeometryChanged();
157
154private:158private:
155 QPointer<BamfApplication> m_application;159 QPointer<BamfApplication> m_application;
156 QFileSystemWatcher *m_desktopFileWatcher;160 QFileSystemWatcher *m_desktopFileWatcher;
@@ -175,6 +179,7 @@
175 void createDynamicMenuActions();179 void createDynamicMenuActions();
176 void createStaticMenuActions();180 void createStaticMenuActions();
177 int windowCountOnCurrentWorkspace();181 int windowCountOnCurrentWorkspace();
182 int windowCountOnCurrentScreen(int);
178 template<typename T>183 template<typename T>
179 bool updateOverlayState(const QMap<QString, QVariant>& properties,184 bool updateOverlayState(const QMap<QString, QVariant>& properties,
180 const QString& propertyName, T* member);185 const QString& propertyName, T* member);
181186
=== modified file 'libunity-2d-private/src/launcheritem.cpp'
--- libunity-2d-private/src/launcheritem.cpp 2012-02-06 12:07:47 +0000
+++ libunity-2d-private/src/launcheritem.cpp 2012-02-16 08:16:20 +0000
@@ -93,6 +93,12 @@
93}93}
9494
95bool95bool
96LauncherItem::belongsToDifferentScreen(int)
97{
98 return false;
99}
100
101bool
96LauncherItem::progressBarVisible() const102LauncherItem::progressBarVisible() const
97{103{
98 return false;104 return false;
99105
=== modified file 'libunity-2d-private/src/launcheritem.h'
--- libunity-2d-private/src/launcheritem.h 2012-02-06 12:07:47 +0000
+++ libunity-2d-private/src/launcheritem.h 2012-02-16 08:16:20 +0000
@@ -80,6 +80,7 @@
80 Q_INVOKABLE virtual void createMenuActions() = 0;80 Q_INVOKABLE virtual void createMenuActions() = 0;
81 Q_INVOKABLE virtual void launchNewInstance();81 Q_INVOKABLE virtual void launchNewInstance();
82 Q_INVOKABLE virtual bool belongsToDifferentWorkspace();82 Q_INVOKABLE virtual bool belongsToDifferentWorkspace();
83 Q_INVOKABLE virtual bool belongsToDifferentScreen(int);
8384
84protected:85protected:
85 LauncherContextualMenu* m_menu;86 LauncherContextualMenu* m_menu;
@@ -102,6 +103,7 @@
102 void emblemVisibleChanged(bool);103 void emblemVisibleChanged(bool);
103 void emblemChanged(QString);104 void emblemChanged(QString);
104 void windowWorkspaceChanged();105 void windowWorkspaceChanged();
106 void windowGeometryChanged();
105107
106public Q_SLOTS:108public Q_SLOTS:
107 /* Default implementation of drag’n’drop handling, should be overridden in109 /* Default implementation of drag’n’drop handling, should be overridden in
108110
=== modified file 'libunity-2d-private/src/screeninfo.cpp'
--- libunity-2d-private/src/screeninfo.cpp 2012-02-01 16:28:13 +0000
+++ libunity-2d-private/src/screeninfo.cpp 2012-02-16 08:16:20 +0000
@@ -198,6 +198,21 @@
198 return m_corner;198 return m_corner;
199}199}
200200
201int
202ScreenInfo::cursorScreen()
203{
204 QDesktopWidget* desktop = QApplication::desktop();
205 QPoint cursorPos(QCursor::pos());
206 return desktop->screenNumber(cursorPos);
207}
208
209int
210ScreenInfo::screenNumber(QPoint point)
211{
212 QDesktopWidget* desktop = QApplication::desktop();
213 return desktop->screenNumber(point);
214}
215
201void216void
202ScreenInfo::setCorner(Corner corner)217ScreenInfo::setCorner(Corner corner)
203{218{
204219
=== modified file 'libunity-2d-private/src/screeninfo.h'
--- libunity-2d-private/src/screeninfo.h 2012-02-01 15:01:21 +0000
+++ libunity-2d-private/src/screeninfo.h 2012-02-16 08:16:20 +0000
@@ -39,6 +39,8 @@
39 int screen() const;39 int screen() const;
40 QWidget* widget() const;40 QWidget* widget() const;
41 Corner corner() const;41 Corner corner() const;
42 static int cursorScreen();
43 static int screenNumber(QPoint);
4244
43 /* Setters */45 /* Setters */
44 void setScreen(int screen);46 void setScreen(int screen);
4547
=== modified file 'shell/Shell.qml'
--- shell/Shell.qml 2012-02-13 09:15:03 +0000
+++ shell/Shell.qml 2012-02-16 08:16:20 +0000
@@ -106,7 +106,11 @@
106106
107 Loader {107 Loader {
108 id: dashLoader108 id: dashLoader
109 source: "dash/Dash.qml"109 /* TODO : In case of multi-monitors, there should be only one dash,
110 which could be moved to any screen.
111 ATM, we are displaying dash for the leftmost screen only. other screens will not support dash yet.
112 */
113 source: (declarativeView.isTopLeftShell ? "dash/Dash.qml" : "")
110 anchors.top: parent.top114 anchors.top: parent.top
111 x: Utils.isLeftToRight() ? launcherLoader.width : shell.width - width - launcherLoader.width115 x: Utils.isLeftToRight() ? launcherLoader.width : shell.width - width - launcherLoader.width
112 onLoaded: item.focus = true116 onLoaded: item.focus = true
113117
=== modified file 'shell/app/CMakeLists.txt'
--- shell/app/CMakeLists.txt 2012-02-13 23:46:04 +0000
+++ shell/app/CMakeLists.txt 2012-02-16 08:16:20 +0000
@@ -8,12 +8,14 @@
8 dashdbus.cpp8 dashdbus.cpp
9 launcherdbus.cpp9 launcherdbus.cpp
10 shelldeclarativeview.cpp10 shelldeclarativeview.cpp
11 shellmanager.cpp
11 )12 )
1213
13set(shell_MOC_HDRS14set(shell_MOC_HDRS
14 dashdbus.h15 dashdbus.h
15 launcherdbus.h16 launcherdbus.h
16 shelldeclarativeview.h17 shelldeclarativeview.h
18 shellmanager.h
17 )19 )
1820
19qt4_wrap_cpp(shell_MOC_SRCS ${shell_MOC_HDRS})21qt4_wrap_cpp(shell_MOC_SRCS ${shell_MOC_HDRS})
2022
=== modified file 'shell/app/shell.cpp'
--- shell/app/shell.cpp 2012-02-13 23:46:04 +0000
+++ shell/app/shell.cpp 2012-02-16 08:16:20 +0000
@@ -21,30 +21,16 @@
21// QT21// QT
22#include <QApplication>22#include <QApplication>
23#include <QDebug>23#include <QDebug>
24#include <QtDeclarative>
25#include <QDeclarativeEngine>
26#include <QDeclarativeView>
27#include <QDesktopWidget>
28#include <QDBusConnection>
29#include <QDBusConnectionInterface>
30#include <QDeclarativeContext>
31#include <QAbstractEventDispatcher>
32#include <QDir>24#include <QDir>
3325#include <QUrl>
34// X11
35#include <X11/Xlib.h>
3626
37// unity-2d27// unity-2d
38#include <gnomesessionclient.h>28#include <gnomesessionclient.h>
39#include <unity2dapplication.h>29#include <unity2dapplication.h>
40#include <unity2ddebug.h>
4130
42// Local31// Local
43#include "config.h"32#include "config.h"
44#include "shelldeclarativeview.h"33#include "shellmanager.h"
45#include "dashclient.h"
46#include "dashdbus.h"
47#include "launcherdbus.h"
4834
49int main(int argc, char *argv[])35int main(int argc, char *argv[])
50{36{
@@ -71,32 +57,7 @@
71 GnomeSessionClient client(INSTALL_PREFIX "/share/applications/unity-2d-shell.desktop");57 GnomeSessionClient client(INSTALL_PREFIX "/share/applications/unity-2d-shell.desktop");
72 client.connectToSessionManager();58 client.connectToSessionManager();
7359
74 qmlRegisterType<ShellDeclarativeView>("Unity2d", 1, 0, "ShellDeclarativeView");60 ShellManager shells(rootFileUrl);
75 ShellDeclarativeView view;
76 view.setAccessibleName("Shell");
77 if (arguments.contains("-opengl")) {
78 view.setUseOpenGL(true);
79 }
80
81 application.installX11EventFilter(&view);
82
83 view.engine()->addImportPath(unity2dImportPath());
84 view.engine()->setBaseUrl(QUrl::fromLocalFile(unity2dDirectory() + "/shell/"));
85
86 /* Load the QML UI, focus and show the window */
87 view.setResizeMode(QDeclarativeView::SizeViewToRootObject);
88 view.rootContext()->setContextProperty("declarativeView", &view);
89 // WARNING This declaration of dashClient used to be in Unity2d/plugin.cpp
90 // but it lead to locks when both the shell and the spread were started
91 // at the same time since SpreadMonitor QDBusServiceWatcher::serviceRegistered
92 // and DashClient QDBusServiceWatcher::serviceRegistered
93 // triggered at the same time ending up with both creating QDBusInterface
94 // to eachother in the main thread meaning they would block
95 // In case you need to have a DashClient in the spread the fix for the problem
96 // is moving the QDbusInterface creation to a thread so it does not block
97 // the main thread
98 view.rootContext()->setContextProperty("dashClient", DashClient::instance());
99 view.setSource(rootFileUrl);
10061
101 /* Unset DESKTOP_AUTOSTART_ID in order to avoid child processes (launched62 /* Unset DESKTOP_AUTOSTART_ID in order to avoid child processes (launched
102 applications) to use the same client id.63 applications) to use the same client id.
@@ -113,14 +74,5 @@
113 (see e.g. https://bugs.launchpad.net/bugs/684471). */74 (see e.g. https://bugs.launchpad.net/bugs/684471). */
114 QDir::setCurrent(QDir::homePath());75 QDir::setCurrent(QDir::homePath());
11576
116 DashDBus dashDBus(&view);
117 if (!dashDBus.connectToBus()) {
118 qCritical() << "Another instance of the Dash already exists. Quitting.";
119 return -1;
120 }
121
122 LauncherDBus launcherDBus(&view);
123 launcherDBus.connectToBus();
124
125 return application.exec();77 return application.exec();
126}78}
12779
=== modified file 'shell/app/shelldeclarativeview.cpp'
--- shell/app/shelldeclarativeview.cpp 2012-02-13 23:46:04 +0000
+++ shell/app/shelldeclarativeview.cpp 2012-02-16 08:16:20 +0000
@@ -22,11 +22,6 @@
22// libunity-2d-private22// libunity-2d-private
23#include <debug_p.h>23#include <debug_p.h>
24#include <hotkey.h>24#include <hotkey.h>
25#include <hotkeymonitor.h>
26#include <keyboardmodifiersmonitor.h>
27#include <keymonitor.h>
28#include <dashclient.h>
29#include <launcherclient.h>
30#include <screeninfo.h>25#include <screeninfo.h>
31#include <strutmanager.h>26#include <strutmanager.h>
3227
@@ -47,46 +42,20 @@
47#include <X11/Xlib.h>42#include <X11/Xlib.h>
48#include <X11/Xatom.h>43#include <X11/Xatom.h>
4944
50static const int KEY_HOLD_THRESHOLD = 250;
51
52static const char* COMMANDS_LENS_ID = "commands.lens";45static const char* COMMANDS_LENS_ID = "commands.lens";
5346
54ShellDeclarativeView::ShellDeclarativeView()47ShellDeclarativeView::ShellDeclarativeView(const QUrl &sourceFileUrl, bool isTopLeftShell, int screen)
55 : Unity2DDeclarativeView()48 : Unity2DDeclarativeView()
56 , m_mode(DesktopMode)49 , m_mode(DesktopMode)
57 , m_expanded(true)50 , m_expanded(true)
58 , m_active(false)51 , m_active(false)
59 , m_superKeyPressed(false)52 , m_isTopLeftShell(isTopLeftShell)
60 , m_superKeyHeld(false)53 , m_sourceFileUrl(sourceFileUrl)
61{54{
62 setAttribute(Qt::WA_X11NetWmWindowTypeDock, true);55 setAttribute(Qt::WA_X11NetWmWindowTypeDock, true);
63 setTransparentBackground(QX11Info::isCompositingManagerRunning());56 setTransparentBackground(QX11Info::isCompositingManagerRunning());
6457
65 m_screenInfo = new ScreenInfo(ScreenInfo::TopLeft, this);58 m_screenInfo = new ScreenInfo(screen, this);
66
67 m_superKeyHoldTimer.setSingleShot(true);
68 m_superKeyHoldTimer.setInterval(KEY_HOLD_THRESHOLD);
69 connect(&m_superKeyHoldTimer, SIGNAL(timeout()), SLOT(updateSuperKeyHoldState()));
70 connect(this, SIGNAL(superKeyTapped()), SLOT(toggleDash()));
71
72 connect(&launcher2dConfiguration(), SIGNAL(superKeyEnableChanged(bool)), SLOT(updateSuperKeyMonitoring()));
73 updateSuperKeyMonitoring();
74
75 /* Alt+F1 reveal the launcher and gives the keyboard focus to the Dash Button. */
76 Hotkey* altF1 = HotkeyMonitor::instance().getHotkeyFor(Qt::Key_F1, Qt::AltModifier);
77 connect(altF1, SIGNAL(pressed()), SLOT(onAltF1Pressed()));
78
79 /* Alt+F2 shows the dash with the commands lens activated. */
80 Hotkey* altF2 = HotkeyMonitor::instance().getHotkeyFor(Qt::Key_F2, Qt::AltModifier);
81 connect(altF2, SIGNAL(pressed()), SLOT(showCommandsLens()));
82
83 /* Super+{n} for 0 ≤ n ≤ 9 activates the item with index (n + 9) % 10. */
84 for (Qt::Key key = Qt::Key_0; key <= Qt::Key_9; key = (Qt::Key) (key + 1)) {
85 Hotkey* hotkey = HotkeyMonitor::instance().getHotkeyFor(key, Qt::MetaModifier);
86 connect(hotkey, SIGNAL(pressed()), SLOT(forwardNumericHotkey()));
87 hotkey = HotkeyMonitor::instance().getHotkeyFor(key, Qt::MetaModifier | Qt::ShiftModifier);
88 connect(hotkey, SIGNAL(pressed()), SLOT(forwardNumericHotkey()));
89 }
9059
91 connect(m_screenInfo, SIGNAL(availableGeometryChanged(QRect)), SLOT(updateShellPosition()));60 connect(m_screenInfo, SIGNAL(availableGeometryChanged(QRect)), SLOT(updateShellPosition()));
92 updateShellPosition();61 updateShellPosition();
@@ -172,6 +141,9 @@
172 /* Note that this has to be called everytime the window is shown, as the WM141 /* Note that this has to be called everytime the window is shown, as the WM
173 will remove the flags when the window is hidden */142 will remove the flags when the window is hidden */
174 setWMFlags();143 setWMFlags();
144 if (source().isEmpty()) {
145 setSource(m_sourceFileUrl);
146 }
175}147}
176148
177void149void
@@ -262,7 +234,7 @@
262}234}
263235
264void236void
265ShellDeclarativeView::onAltF1Pressed()237ShellDeclarativeView::toggleLauncher()
266{238{
267 if (!isActiveWindow()) {239 if (!isActiveWindow()) {
268 forceActivateWindow();240 forceActivateWindow();
@@ -279,117 +251,27 @@
279 }251 }
280}252}
281253
282/* ----------------- super key handling ---------------- */254void
283255ShellDeclarativeView::processNumericHotkey(Hotkey* hotkey)
284void256{
285ShellDeclarativeView::updateSuperKeyHoldState()257 /* Shortcuts from 1 to 9 should activate the items with index
286{258 from 1 to 9 (index 0 being the so-called "BFB" or Dash launcher).
287 /* If the key was released in the meantime, just do nothing, otherwise259 Shortcut for 0 should activate item with index 10.
288 consider the key being held, unless we're told to ignore it. */260 In other words, the indexes are activated in the same order as
289 if (m_superKeyPressed && !m_superPressIgnored) {261 the keys appear on a standard keyboard. */
290 m_superKeyHeld = true;262 Qt::Key key = hotkey->key();
291 Q_EMIT superKeyHeldChanged(m_superKeyHeld);263 if (key >= Qt::Key_1 && key <= Qt::Key_9) {
292 }264 int index = key - Qt::Key_0;
293}265 if (hotkey->modifiers() & Qt::ShiftModifier) {
294266 Q_EMIT newInstanceShortcutPressed(index);
295void267 } else {
296ShellDeclarativeView::updateSuperKeyMonitoring()268 Q_EMIT activateShortcutPressed(index);
297{269 }
298 KeyboardModifiersMonitor *modifiersMonitor = KeyboardModifiersMonitor::instance();270 } else if (key == Qt::Key_0) {
299 KeyMonitor *keyMonitor = KeyMonitor::instance();271 if (hotkey->modifiers() & Qt::ShiftModifier) {
300 HotkeyMonitor& hotkeyMonitor = HotkeyMonitor::instance();272 Q_EMIT newInstanceShortcutPressed(10);
301273 } else {
302 QVariant value = launcher2dConfiguration().property("superKeyEnable");274 Q_EMIT activateShortcutPressed(10);
303 if (!value.isValid() || value.toBool() == true) {
304 hotkeyMonitor.enableModifiers(Qt::MetaModifier);
305 QObject::connect(modifiersMonitor,
306 SIGNAL(keyboardModifiersChanged(Qt::KeyboardModifiers)),
307 this, SLOT(setHotkeysForModifiers(Qt::KeyboardModifiers)));
308 /* Ignore Super presses if another key was pressed simultaneously
309 (i.e. a shortcut). https://bugs.launchpad.net/unity-2d/+bug/801073 */
310 QObject::connect(keyMonitor,
311 SIGNAL(keyPressed()),
312 this, SLOT(ignoreSuperPress()));
313 setHotkeysForModifiers(modifiersMonitor->keyboardModifiers());
314 } else {
315 hotkeyMonitor.disableModifiers(Qt::MetaModifier);
316 QObject::disconnect(modifiersMonitor,
317 SIGNAL(keyboardModifiersChanged(Qt::KeyboardModifiers)),
318 this, SLOT(setHotkeysForModifiers(Qt::KeyboardModifiers)));
319 QObject::disconnect(keyMonitor,
320 SIGNAL(keyPressed()),
321 this, SLOT(ignoreSuperPress()));
322 m_superKeyHoldTimer.stop();
323 m_superKeyPressed = false;
324 if (m_superKeyHeld) {
325 m_superKeyHeld = false;
326 Q_EMIT superKeyHeldChanged(false);
327 }
328 }
329}
330
331void
332ShellDeclarativeView::setHotkeysForModifiers(Qt::KeyboardModifiers modifiers)
333{
334 /* This is the new new state of the Super key (AKA Meta key), while
335 m_superKeyPressed is the previous state of the key at the last modifiers change. */
336 bool superKeyPressed = modifiers.testFlag(Qt::MetaModifier);
337
338 if (m_superKeyPressed != superKeyPressed) {
339 m_superKeyPressed = superKeyPressed;
340 if (superKeyPressed) {
341 m_superPressIgnored = false;
342 /* If the key is pressed, start up a timer to monitor if it's being held short
343 enough to qualify as just a "tap" or as a proper hold */
344 m_superKeyHoldTimer.start();
345 } else {
346 m_superKeyHoldTimer.stop();
347
348 /* If the key is released, and was not being held, it means that the user just
349 performed a "tap". Unless we're told to ignore that tap, that is. */
350 if (!m_superKeyHeld && !m_superPressIgnored) {
351 Q_EMIT superKeyTapped();
352 }
353 /* Otherwise the user just terminated a hold. */
354 else if(m_superKeyHeld){
355 m_superKeyHeld = false;
356 Q_EMIT superKeyHeldChanged(m_superKeyHeld);
357 }
358 }
359 }
360}
361
362void
363ShellDeclarativeView::ignoreSuperPress()
364{
365 /* There was a key pressed, ignore current super tap/hold */
366 m_superPressIgnored = true;
367}
368
369void
370ShellDeclarativeView::forwardNumericHotkey()
371{
372 Hotkey* hotkey = qobject_cast<Hotkey*>(sender());
373 if (hotkey != NULL) {
374 /* Shortcuts from 1 to 9 should activate the items with index
375 from 1 to 9 (index 0 being the so-called "BFB" or Dash launcher).
376 Shortcut for 0 should activate item with index 10.
377 In other words, the indexes are activated in the same order as
378 the keys appear on a standard keyboard. */
379 Qt::Key key = hotkey->key();
380 if (key >= Qt::Key_1 && key <= Qt::Key_9) {
381 int index = key - Qt::Key_0;
382 if (hotkey->modifiers() & Qt::ShiftModifier) {
383 Q_EMIT newInstanceShortcutPressed(index);
384 } else {
385 Q_EMIT activateShortcutPressed(index);
386 }
387 } else if (key == Qt::Key_0) {
388 if (hotkey->modifiers() & Qt::ShiftModifier) {
389 Q_EMIT newInstanceShortcutPressed(10);
390 } else {
391 Q_EMIT activateShortcutPressed(10);
392 }
393 }275 }
394 }276 }
395}277}
@@ -466,3 +348,26 @@
466{348{
467 return m_monitoredAreaContainsMouse;349 return m_monitoredAreaContainsMouse;
468}350}
351
352void
353ShellDeclarativeView::setIsTopLeftShell(bool ashell)
354{
355 if (m_isTopLeftShell == ashell) {
356 return;
357 }
358
359 m_isTopLeftShell = ashell;
360 Q_EMIT isTopLeftShellChanged(m_isTopLeftShell);
361}
362
363void
364ShellDeclarativeView::setScreenNumber(int screen)
365{
366 m_screenInfo->setScreen(screen);
367}
368
369int
370ShellDeclarativeView::screenNumber() const
371{
372 return m_screenInfo->screen();
373}
469374
=== modified file 'shell/app/shelldeclarativeview.h'
--- shell/app/shelldeclarativeview.h 2012-02-13 23:46:04 +0000
+++ shell/app/shelldeclarativeview.h 2012-02-16 08:16:20 +0000
@@ -27,6 +27,7 @@
27class LauncherClient;27class LauncherClient;
28class DashDBus;28class DashDBus;
29class ScreenInfo;29class ScreenInfo;
30class Hotkey;
3031
31class ShellDeclarativeView : public Unity2DDeclarativeView, public AbstractX11EventFilter32class ShellDeclarativeView : public Unity2DDeclarativeView, public AbstractX11EventFilter
32{33{
@@ -38,7 +39,7 @@
38 Q_PROPERTY(DashMode dashMode READ dashMode WRITE setDashMode NOTIFY dashModeChanged)39 Q_PROPERTY(DashMode dashMode READ dashMode WRITE setDashMode NOTIFY dashModeChanged)
39 Q_PROPERTY(QString activeLens READ activeLens WRITE setActiveLens NOTIFY activeLensChanged)40 Q_PROPERTY(QString activeLens READ activeLens WRITE setActiveLens NOTIFY activeLensChanged)
40 Q_PROPERTY(bool focus READ hasFocus NOTIFY focusChanged) // overridden to add notify41 Q_PROPERTY(bool focus READ hasFocus NOTIFY focusChanged) // overridden to add notify
41 Q_PROPERTY(bool superKeyHeld READ superKeyHeld NOTIFY superKeyHeldChanged)42 Q_PROPERTY(bool isTopLeftShell READ isTopLeftShell WRITE setIsTopLeftShell NOTIFY isTopLeftShellChanged)
42 Q_PROPERTY(bool haveCustomHomeShortcuts READ haveCustomHomeShortcuts)43 Q_PROPERTY(bool haveCustomHomeShortcuts READ haveCustomHomeShortcuts)
4344
44 /* These two properties and mouse movement tracking on the widget are added here only because45 /* These two properties and mouse movement tracking on the widget are added here only because
@@ -56,7 +57,7 @@
56 DesktopMode,57 DesktopMode,
57 FullScreenMode58 FullScreenMode
58 };59 };
59 explicit ShellDeclarativeView();60 explicit ShellDeclarativeView(const QUrl &sourceFileUrl = QUrl(), bool isTopLeftShell = false, int screen = 0);
6061
61 /* getters */62 /* getters */
62 bool dashActive() const;63 bool dashActive() const;
@@ -64,19 +65,28 @@
64 DashMode dashMode() const;65 DashMode dashMode() const;
65 const QString& activeLens() const;66 const QString& activeLens() const;
66 bool expanded() const;67 bool expanded() const;
67 bool superKeyHeld() const { return m_superKeyHeld; }
68 QRect monitoredArea() const;68 QRect monitoredArea() const;
69 bool monitoredAreaContainsMouse() const;69 bool monitoredAreaContainsMouse() const;
70 bool isTopLeftShell() const { return m_isTopLeftShell; }
7071
71 /* setters */72 /* setters */
72 Q_SLOT void setDashActive(bool active);73 Q_SLOT void setDashActive(bool active);
73 Q_INVOKABLE void setDashMode(DashMode);74 Q_INVOKABLE void setDashMode(DashMode);
74 Q_INVOKABLE void setActiveLens(const QString& activeLens);75 Q_INVOKABLE void setActiveLens(const QString& activeLens);
75 Q_INVOKABLE void setExpanded(bool);76 Q_INVOKABLE void setExpanded(bool);
77 void setScreenNumber(int);
78 int screenNumber() const;
76 void setMonitoredArea(QRect monitoredArea);79 void setMonitoredArea(QRect monitoredArea);
80 void setIsTopLeftShell(bool);
7781
78 virtual bool x11EventFilter(XEvent* event);82 virtual bool x11EventFilter(XEvent* event);
7983
84 void toggleDash();
85 void toggleLauncher();
86 void showCommandsLens();
87
88 void processNumericHotkey(Hotkey*);
89
80Q_SIGNALS:90Q_SIGNALS:
81 void dashActiveChanged(bool);91 void dashActiveChanged(bool);
82 void dashModeChanged(DashMode);92 void dashModeChanged(DashMode);
@@ -89,22 +99,10 @@
89 void monitoredAreaContainsMouseChanged();99 void monitoredAreaContainsMouseChanged();
90100
91 void addWebFavoriteRequested(const QUrl& url);101 void addWebFavoriteRequested(const QUrl& url);
92 void superKeyHeldChanged(bool superKeyHeld);
93 void superKeyTapped();
94 void activateShortcutPressed(int itemIndex);102 void activateShortcutPressed(int itemIndex);
95 void newInstanceShortcutPressed(int itemIndex);103 void newInstanceShortcutPressed(int itemIndex);
96 void launcherFocusRequested();104 void launcherFocusRequested();
97105 void isTopLeftShellChanged(bool);
98private Q_SLOTS:
99 void updateSuperKeyMonitoring();
100 void updateSuperKeyHoldState();
101 void setHotkeysForModifiers(Qt::KeyboardModifiers modifiers);
102 void forwardNumericHotkey();
103 void ignoreSuperPress();
104
105 void toggleDash();
106 void showCommandsLens();
107 void onAltF1Pressed();
108106
109protected:107protected:
110 virtual void showEvent(QShowEvent *event);108 virtual void showEvent(QShowEvent *event);
@@ -126,12 +124,10 @@
126 QString m_activeLens; /* Lens id of the active lens */124 QString m_activeLens; /* Lens id of the active lens */
127 bool m_active;125 bool m_active;
128126
129 bool m_superKeyPressed;
130 bool m_superKeyHeld;
131 bool m_superPressIgnored;
132 QTimer m_superKeyHoldTimer;
133 QRect m_monitoredArea;127 QRect m_monitoredArea;
134 bool m_monitoredAreaContainsMouse;128 bool m_monitoredAreaContainsMouse;
129 bool m_isTopLeftShell;
130 QUrl m_sourceFileUrl;
135131
136 friend class DashDBus;132 friend class DashDBus;
137 friend class LauncherDBus;133 friend class LauncherDBus;
138134
=== added file 'shell/app/shellmanager.cpp'
--- shell/app/shellmanager.cpp 1970-01-01 00:00:00 +0000
+++ shell/app/shellmanager.cpp 2012-02-16 08:16:20 +0000
@@ -0,0 +1,380 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2010 Canonical Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>
17 */
18
19#include "shellmanager.h"
20
21// Qt
22#include <QApplication>
23#include <QDebug>
24#include <QtDeclarative>
25#include <QDeclarativeEngine>
26#include <QDeclarativeView>
27#include <QDesktopWidget>
28#include <QDBusConnection>
29#include <QDBusConnectionInterface>
30#include <QDeclarativeContext>
31#include <QAbstractEventDispatcher>
32
33// libunity-2d-private
34#include <hotkeymonitor.h>
35#include <hotkey.h>
36#include <keyboardmodifiersmonitor.h>
37#include <keymonitor.h>
38#include <screeninfo.h>
39
40// Local
41#include "shelldeclarativeview.h"
42#include "dashclient.h"
43#include "dashdbus.h"
44#include "gesturehandler.h"
45#include "launcherdbus.h"
46#include "config.h"
47
48// unity-2d
49#include <unity2ddebug.h>
50#include <unity2dapplication.h>
51
52// X11
53#include <X11/Xlib.h>
54
55static const int KEY_HOLD_THRESHOLD = 250;
56
57struct ShellManagerPrivate
58{
59 ShellManagerPrivate()
60 : q(0)
61 , m_dashDBus(0)
62 , m_launcherDBus(0)
63 , m_superKeyPressed(false)
64 , m_superKeyHeld(false)
65 {}
66
67 ShellDeclarativeView* initShell(bool isTopLeft, int screen);
68 void updateScreenCount(int newCount);
69 ShellDeclarativeView* activeShell() const;
70
71 ShellManager *q;
72 QList<ShellDeclarativeView *> m_viewList;
73 DashDBus * m_dashDBus;
74 LauncherDBus* m_launcherDBus;
75 QUrl m_sourceFileUrl;
76
77 bool m_superKeyPressed;
78 bool m_superKeyHeld;
79 bool m_superPressIgnored;
80 QTimer m_superKeyHoldTimer;
81};
82
83
84ShellDeclarativeView *
85ShellManagerPrivate::initShell(bool isTopLeft, int screen)
86{
87 const QStringList arguments = qApp->arguments();
88 ShellDeclarativeView * view = new ShellDeclarativeView(m_sourceFileUrl, isTopLeft, screen);
89 view->setAccessibleName("Shell");
90 if (arguments.contains("-opengl")) {
91 view->setUseOpenGL(true);
92 }
93
94 Unity2dApplication::instance()->installX11EventFilter(view);
95
96 view->engine()->addImportPath(unity2dImportPath());
97 view->engine()->setBaseUrl(QUrl::fromLocalFile(unity2dDirectory() + "/shell/"));
98
99 /* Load the QML UI, focus and show the window */
100 view->setResizeMode(QDeclarativeView::SizeViewToRootObject);
101 view->rootContext()->setContextProperty("declarativeView", view);
102 view->rootContext()->setContextProperty("shellManager", q);
103 // WARNING This declaration of dashClient used to be in Unity2d/plugin.cpp
104 // but it lead to locks when both the shell and the spread were started
105 // at the same time since SpreadMonitor QDBusServiceWatcher::serviceRegistered
106 // and DashClient QDBusServiceWatcher::serviceRegistered
107 // triggered at the same time ending up with both creating QDBusInterface
108 // to eachother in the main thread meaning they would block
109 // In case you need to have a DashClient in the spread the fix for the problem
110 // is moving the QDbusInterface creation to a thread so it does not block
111 // the main thread
112 view->rootContext()->setContextProperty("dashClient", DashClient::instance());
113
114 if (!m_dashDBus) {
115 m_dashDBus = new DashDBus(view);
116 if (!m_dashDBus->connectToBus()) {
117 qCritical() << "Another instance of the Dash already exists. Quitting.";
118 return 0;
119 }
120 }
121
122 if (!m_launcherDBus) {
123 m_launcherDBus = new LauncherDBus(view);
124 m_launcherDBus->connectToBus();
125 }
126
127 view->show();
128
129 return view;
130}
131
132ShellDeclarativeView *
133ShellManagerPrivate::activeShell() const
134{
135 int cursorScreen = ScreenInfo::cursorScreen();
136 Q_FOREACH(ShellDeclarativeView * shell, m_viewList) {
137 if (shell->screenNumber() == cursorScreen) {
138 return shell;
139 }
140 }
141 return 0;
142}
143
144void
145ShellManagerPrivate::updateScreenCount(int newCount)
146{
147 if (newCount > 0) {
148 QDesktopWidget* desktop = QApplication::desktop();
149 int size = m_viewList.size();
150 ShellDeclarativeView* shell = 0;
151
152 /* The first shell is always the one on the leftmost screen. */
153 QPoint p;
154 if (QApplication::isRightToLeft()) {
155 p = QPoint(desktop->width() - 1, 0);
156 }
157 int leftmost = desktop->screenNumber(p);
158 if (size > 0) {
159 shell = m_viewList[0];
160 } else {
161 shell = initShell(true, leftmost);
162 m_viewList.append(shell);
163 }
164 shell->setScreenNumber(leftmost);
165
166 /* Update the position of other existing Shells, and instantiate new
167 Shells as needed. */
168 int i = 1;
169 for (int screen = 0; screen < newCount; ++screen) {
170 if (screen == leftmost) {
171 continue;
172 }
173 if (i < size) {
174 shell = m_viewList[i];
175 } else {
176 shell = initShell(false, screen);
177 m_viewList.append(shell);
178 }
179 shell->setIsTopLeftShell(false);
180 shell->setScreenNumber(screen);
181 ++i;
182 }
183 }
184 /* Remove extra Shells if any. */
185 while (m_viewList.size() > newCount) {
186 m_viewList.takeLast()->deleteLater();
187 }
188}
189
190/* -------------------------- ShellManager -----------------------------*/
191
192ShellManager::ShellManager(const QUrl &sourceFileUrl, QObject* parent) :
193 QObject(parent)
194 ,d(new ShellManagerPrivate)
195{
196 d->q = this;
197 d->m_sourceFileUrl = sourceFileUrl;
198
199 qmlRegisterType<ShellDeclarativeView>("Unity2d", 1, 0, "ShellDeclarativeView");
200
201 QDesktopWidget* desktop = QApplication::desktop();
202
203 d->updateScreenCount(desktop->screenCount());
204
205 connect(desktop, SIGNAL(screenCountChanged(int)), SLOT(onScreenCountChanged(int)));
206
207 d->m_superKeyHoldTimer.setSingleShot(true);
208 d->m_superKeyHoldTimer.setInterval(KEY_HOLD_THRESHOLD);
209 connect(&d->m_superKeyHoldTimer, SIGNAL(timeout()), SLOT(updateSuperKeyHoldState()));
210
211 connect(&launcher2dConfiguration(), SIGNAL(superKeyEnableChanged(bool)), SLOT(updateSuperKeyMonitoring()));
212 updateSuperKeyMonitoring();
213
214 /* Alt+F1 reveal the launcher and gives the keyboard focus to the Dash Button. */
215 Hotkey* altF1 = HotkeyMonitor::instance().getHotkeyFor(Qt::Key_F1, Qt::AltModifier);
216 connect(altF1, SIGNAL(pressed()), SLOT(onAltF1Pressed()));
217
218 /* Alt+F2 shows the dash with the commands lens activated. */
219 Hotkey* altF2 = HotkeyMonitor::instance().getHotkeyFor(Qt::Key_F2, Qt::AltModifier);
220 connect(altF2, SIGNAL(pressed()), SLOT(onAltF2Pressed()));
221
222 /* Super+{n} for 0 ≤ n ≤ 9 activates the item with index (n + 9) % 10. */
223 for (Qt::Key key = Qt::Key_0; key <= Qt::Key_9; key = (Qt::Key) (key + 1)) {
224 Hotkey* hotkey = HotkeyMonitor::instance().getHotkeyFor(key, Qt::MetaModifier);
225 connect(hotkey, SIGNAL(pressed()), SLOT(onNumericHotkeyPressed()));
226 hotkey = HotkeyMonitor::instance().getHotkeyFor(key, Qt::MetaModifier | Qt::ShiftModifier);
227 connect(hotkey, SIGNAL(pressed()), SLOT(onNumericHotkeyPressed()));
228 }
229}
230
231ShellManager::~ShellManager()
232{
233 qDeleteAll(d->m_viewList);
234 delete d;
235}
236
237void
238ShellManager::onScreenCountChanged(int newCount)
239{
240 d->updateScreenCount(newCount);
241}
242
243/* ----------------- super key handling ---------------- */
244
245void
246ShellManager::updateSuperKeyHoldState()
247{
248 /* If the key was released in the meantime, just do nothing, otherwise
249 consider the key being held, unless we're told to ignore it. */
250 if (d->m_superKeyPressed && !d->m_superPressIgnored) {
251 d->m_superKeyHeld = true;
252 Q_EMIT superKeyHeldChanged(d->m_superKeyHeld);
253 }
254}
255
256void
257ShellManager::updateSuperKeyMonitoring()
258{
259 KeyboardModifiersMonitor *modifiersMonitor = KeyboardModifiersMonitor::instance();
260 KeyMonitor *keyMonitor = KeyMonitor::instance();
261 HotkeyMonitor& hotkeyMonitor = HotkeyMonitor::instance();
262
263 QVariant value = launcher2dConfiguration().property("superKeyEnable");
264 if (!value.isValid() || value.toBool() == true) {
265 hotkeyMonitor.enableModifiers(Qt::MetaModifier);
266 QObject::connect(modifiersMonitor,
267 SIGNAL(keyboardModifiersChanged(Qt::KeyboardModifiers)),
268 this, SLOT(setHotkeysForModifiers(Qt::KeyboardModifiers)));
269 /* Ignore Super presses if another key was pressed simultaneously
270 (i.e. a shortcut). https://bugs.launchpad.net/unity-2d/+bug/801073 */
271 QObject::connect(keyMonitor,
272 SIGNAL(keyPressed()),
273 this, SLOT(ignoreSuperPress()));
274 setHotkeysForModifiers(modifiersMonitor->keyboardModifiers());
275 } else {
276 hotkeyMonitor.disableModifiers(Qt::MetaModifier);
277 QObject::disconnect(modifiersMonitor,
278 SIGNAL(keyboardModifiersChanged(Qt::KeyboardModifiers)),
279 this, SLOT(setHotkeysForModifiers(Qt::KeyboardModifiers)));
280 QObject::disconnect(keyMonitor,
281 SIGNAL(keyPressed()),
282 this, SLOT(ignoreSuperPress()));
283 d->m_superKeyHoldTimer.stop();
284 d->m_superKeyPressed = false;
285 if (d->m_superKeyHeld) {
286 d->m_superKeyHeld = false;
287 Q_EMIT superKeyHeldChanged(false);
288 }
289 }
290}
291
292void
293ShellManager::setHotkeysForModifiers(Qt::KeyboardModifiers modifiers)
294{
295 /* This is the new new state of the Super key (AKA Meta key), while
296 d->m_superKeyPressed is the previous state of the key at the last modifiers change. */
297 bool superKeyPressed = modifiers.testFlag(Qt::MetaModifier);
298
299 if (d->m_superKeyPressed != superKeyPressed) {
300 d->m_superKeyPressed = superKeyPressed;
301 if (superKeyPressed) {
302 d->m_superPressIgnored = false;
303 /* If the key is pressed, start up a timer to monitor if it's being held short
304 enough to qualify as just a "tap" or as a proper hold */
305 d->m_superKeyHoldTimer.start();
306 } else {
307 d->m_superKeyHoldTimer.stop();
308
309 /* If the key is released, and was not being held, it means that the user just
310 performed a "tap". Unless we're told to ignore that tap, that is. */
311 if (!d->m_superKeyHeld && !d->m_superPressIgnored) {
312 onSuperKeyTapped();
313 }
314 /* Otherwise the user just terminated a hold. */
315 else if(d->m_superKeyHeld){
316 d->m_superKeyHeld = false;
317 Q_EMIT superKeyHeldChanged(d->m_superKeyHeld);
318 }
319 }
320 }
321}
322
323void
324ShellManager::ignoreSuperPress()
325{
326 /* There was a key pressed, ignore current super tap/hold */
327 d->m_superPressIgnored = true;
328}
329
330void
331ShellManager::onSuperKeyTapped()
332{
333 // TODO : In future, All shells should be able to handle the Dash
334 // Note: Always, first item in the list is the topLeft shell
335 // In any case, just iterate through the list
336 Q_FOREACH(ShellDeclarativeView *shell, d->m_viewList) {
337 if (shell->isTopLeftShell()) {
338 shell->toggleDash();
339 break;
340 }
341 }
342}
343
344bool
345ShellManager::superKeyHeld() const
346{
347 return d->m_superKeyHeld;
348}
349
350/*------------------ Hotkeys Handling -----------------------*/
351
352void
353ShellManager::onAltF1Pressed()
354{
355 ShellDeclarativeView * activeShell = d->activeShell();
356 if (activeShell) {
357 activeShell->toggleLauncher();
358 }
359}
360
361void
362ShellManager::onAltF2Pressed()
363{
364 ShellDeclarativeView * activeShell = d->activeShell();
365 if (activeShell) {
366 activeShell->showCommandsLens();
367 }
368}
369
370void
371ShellManager::onNumericHotkeyPressed()
372{
373 Hotkey* hotkey = qobject_cast<Hotkey*>(sender());
374 if (hotkey) {
375 ShellDeclarativeView * activeShell = d->activeShell();
376 if (activeShell) {
377 activeShell->processNumericHotkey(hotkey);
378 }
379 }
380}
0381
=== added file 'shell/app/shellmanager.h'
--- shell/app/shellmanager.h 1970-01-01 00:00:00 +0000
+++ shell/app/shellmanager.h 2012-02-16 08:16:20 +0000
@@ -0,0 +1,58 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2010 Canonical Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>
17 */
18#ifndef SHELLMANAGER_H
19#define SHELLMANAGER_H
20
21#include <QObject>
22struct ShellManagerPrivate;
23
24class QUrl;
25
26class ShellManager : public QObject
27{
28 Q_OBJECT
29 Q_PROPERTY(bool superKeyHeld READ superKeyHeld NOTIFY superKeyHeldChanged)
30
31public:
32 ShellManager(const QUrl &sourceFileUrl, QObject* parent = 0);
33 ~ShellManager();
34
35 bool superKeyHeld() const;
36
37Q_SIGNALS:
38 void superKeyHeldChanged(bool superKeyHeld);
39
40private Q_SLOTS:
41 void onScreenCountChanged(int);
42
43 void updateSuperKeyMonitoring();
44 void updateSuperKeyHoldState();
45 void setHotkeysForModifiers(Qt::KeyboardModifiers modifiers);
46 void ignoreSuperPress();
47 void onSuperKeyTapped();
48
49 void onAltF1Pressed();
50 void onAltF2Pressed();
51 void onNumericHotkeyPressed();
52
53private:
54 Q_DISABLE_COPY(ShellManager)
55 ShellManagerPrivate * const d;
56};
57
58#endif // SHELLMANAGER_H
059
=== modified file 'shell/launcher/LauncherList.qml'
--- shell/launcher/LauncherList.qml 2012-02-09 11:59:16 +0000
+++ shell/launcher/LauncherList.qml 2012-02-16 08:16:20 +0000
@@ -93,7 +93,7 @@
93 }93 }
9494
95 function updatePips() {95 function updatePips() {
96 if (item.belongsToDifferentWorkspace()) {96 if (item.belongsToDifferentWorkspace() || item.belongsToDifferentScreen(declarativeView.screen.screen)) {
97 launcherItem.pips = 197 launcherItem.pips = 1
98 launcherItem.pipSource = "launcher/artwork/launcher_arrow_outline_ltr.png";98 launcherItem.pipSource = "launcher/artwork/launcher_arrow_outline_ltr.png";
99 } else {99 } else {
@@ -125,7 +125,7 @@
125 emblemVisible: item.emblemVisible125 emblemVisible: item.emblemVisible
126126
127 /* Launcher of index 0 is the so-called BFB or Dash launcher */127 /* Launcher of index 0 is the so-called BFB or Dash launcher */
128 shortcutVisible: declarativeView.superKeyHeld &&128 shortcutVisible: shellManager.superKeyHeld &&
129 ((item.toString().indexOf("LauncherApplication") == 0 && index > 0 && index <= 10) ||129 ((item.toString().indexOf("LauncherApplication") == 0 && index > 0 && index <= 10) ||
130 item.shortcutKey != 0)130 item.shortcutKey != 0)
131 shortcutText: {131 shortcutText: {
@@ -310,6 +310,7 @@
310 width, height, xid)310 width, height, xid)
311 onWindowCountChanged: updatePips()311 onWindowCountChanged: updatePips()
312 onWindowWorkspaceChanged: updatePips()312 onWindowWorkspaceChanged: updatePips()
313 onWindowGeometryChanged: updatePips()
313 /* Not all items are applications. */314 /* Not all items are applications. */
314 ignoreUnknownSignals: true315 ignoreUnknownSignals: true
315 }316 }
316317
=== modified file 'shell/launcher/LauncherLoader.qml'
--- shell/launcher/LauncherLoader.qml 2012-02-10 11:17:36 +0000
+++ shell/launcher/LauncherLoader.qml 2012-02-16 08:16:20 +0000
@@ -70,7 +70,7 @@
70 }70 }
7171
72 Connections {72 Connections {
73 target: declarativeView73 target: shellManager
74 onSuperKeyHeldChanged: {74 onSuperKeyHeldChanged: {
75 if (superKeyHeld) visibilityController.beginForceVisible()75 if (superKeyHeld) visibilityController.beginForceVisible()
76 else visibilityController.endForceVisible()76 else visibilityController.endForceVisible()

Subscribers

People subscribed via source and target branches