~dyams/unity-2d/mm-updates-pips

« back to all changes in this revision

Viewing changes to shell/app/shellmanager.cpp

  • Committer: LDS
  • Date: 2012-02-14 14:43:58 UTC
  • mfrom: (917.1.6 centralized-hotkeys)
  • Revision ID: lohith.shivamurthy@canonical.com-20120214144358-rpfavv1xjp4migy5
merge bzr merge lp:~dyams/unity-2d/centralized-hotkeys

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include <QDeclarativeContext>
31
31
#include <QAbstractEventDispatcher>
32
32
 
 
33
// libunity-2d-private
 
34
#include <hotkeymonitor.h>
 
35
#include <hotkey.h>
 
36
#include <screeninfo.h>
 
37
 
33
38
// Local
34
39
#include "shelldeclarativeview.h"
35
40
#include "dashclient.h"
53
58
 
54
59
    ShellDeclarativeView* initShell(bool isTopLeft, int screen);
55
60
    void updateScreenCount(int newCount);
 
61
    ShellDeclarativeView* activeShell() const;
56
62
 
57
63
    ShellManager *q;
58
64
    QList<ShellDeclarativeView *> m_viewList;
61
67
    QUrl m_sourceFileUrl;
62
68
};
63
69
 
64
 
ShellDeclarativeView* ShellManagerPrivate::initShell(bool isTopLeft, int screen)
 
70
 
 
71
ShellDeclarativeView *
 
72
ShellManagerPrivate::initShell(bool isTopLeft, int screen)
65
73
{
66
74
    const QStringList arguments = qApp->arguments();
67
75
    ShellDeclarativeView * view = new ShellDeclarativeView(m_sourceFileUrl, isTopLeft, screen);
107
115
    return view;
108
116
}
109
117
 
110
 
void ShellManagerPrivate::updateScreenCount(int newCount)
 
118
ShellDeclarativeView *
 
119
ShellManagerPrivate::activeShell() const
 
120
{
 
121
    int cursorScreen = ScreenInfo::cursorScreen();
 
122
    Q_FOREACH(ShellDeclarativeView * shell, m_viewList) {
 
123
        if (shell->screenNumber() == cursorScreen) {
 
124
            return shell;
 
125
        }
 
126
    }
 
127
    return 0;
 
128
}
 
129
 
 
130
void
 
131
ShellManagerPrivate::updateScreenCount(int newCount)
111
132
{
112
133
    if (newCount > 0) {
113
134
        QDesktopWidget* desktop = QApplication::desktop();
168
189
    d->updateScreenCount(desktop->screenCount());
169
190
 
170
191
    connect(desktop, SIGNAL(screenCountChanged(int)), SLOT(onScreenCountChanged(int)));
 
192
 
 
193
    /* Alt+F1 reveal the launcher and gives the keyboard focus to the Dash Button. */
 
194
    Hotkey* altF1 = HotkeyMonitor::instance().getHotkeyFor(Qt::Key_F1, Qt::AltModifier);
 
195
    connect(altF1, SIGNAL(pressed()), SLOT(onAltF1Pressed()));
 
196
 
 
197
    /* Alt+F2 shows the dash with the commands lens activated. */
 
198
    Hotkey* altF2 = HotkeyMonitor::instance().getHotkeyFor(Qt::Key_F2, Qt::AltModifier);
 
199
    connect(altF2, SIGNAL(pressed()), SLOT(onAltF2Pressed()));
 
200
 
 
201
    /* Super+{n} for 0 ≤ n ≤ 9 activates the item with index (n + 9) % 10. */
 
202
    for (Qt::Key key = Qt::Key_0; key <= Qt::Key_9; key = (Qt::Key) (key + 1)) {
 
203
        Hotkey* hotkey = HotkeyMonitor::instance().getHotkeyFor(key, Qt::MetaModifier);
 
204
        connect(hotkey, SIGNAL(pressed()), SLOT(onNumericHotkeyPressed()));
 
205
        hotkey = HotkeyMonitor::instance().getHotkeyFor(key, Qt::MetaModifier | Qt::ShiftModifier);
 
206
        connect(hotkey, SIGNAL(pressed()), SLOT(onNumericHotkeyPressed()));
 
207
    }
171
208
}
172
209
 
173
210
ShellManager::~ShellManager()
181
218
{
182
219
    d->updateScreenCount(newCount);
183
220
}
 
221
 
 
222
/*------------------ Hotkeys Handling -----------------------*/
 
223
 
 
224
void
 
225
ShellManager::onAltF1Pressed()
 
226
{
 
227
    ShellDeclarativeView * activeShell = d->activeShell();
 
228
    if (activeShell) {
 
229
        activeShell->toggleLauncher();
 
230
    }
 
231
}
 
232
 
 
233
void
 
234
ShellManager::onAltF2Pressed()
 
235
{
 
236
    ShellDeclarativeView * activeShell = d->activeShell();
 
237
    if (activeShell) {
 
238
        activeShell->showCommandsLens();
 
239
    }
 
240
}
 
241
 
 
242
void
 
243
ShellManager::onNumericHotkeyPressed()
 
244
{
 
245
    Hotkey* hotkey = qobject_cast<Hotkey*>(sender());
 
246
    if (hotkey) {
 
247
        ShellDeclarativeView * activeShell = d->activeShell();
 
248
        if (activeShell) {
 
249
            activeShell->processNumericHotkey(hotkey);
 
250
        }
 
251
    }
 
252
}