~ubuntu-branches/ubuntu/wily/kwin/wily-proposed

« back to all changes in this revision

Viewing changes to useractions.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2015-08-10 23:16:37 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20150810231637-5zb2tstjkez93hml
Tags: 4:5.3.95-0ubuntu1
new upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
#endif
48
48
 
49
49
#include <KProcess>
50
 
#include <KToolInvocation>
51
50
 
52
51
#include <QAction>
53
52
#include <QCheckBox>
92
91
    , m_closeOperation(NULL)
93
92
    , m_removeFromTabGroup(NULL)
94
93
    , m_closeTabGroup(NULL)
95
 
    , m_client(QWeakPointer<Client>())
 
94
    , m_client(QWeakPointer<AbstractClient>())
96
95
{
97
96
}
98
97
 
120
119
    m_client.clear();
121
120
}
122
121
 
123
 
bool UserActionsMenu::isMenuClient(const Client *c) const
 
122
bool UserActionsMenu::isMenuClient(const AbstractClient *c) const
124
123
{
125
124
    if (!c || m_client.isNull()) {
126
125
        return false;
128
127
    return c == m_client.data();
129
128
}
130
129
 
131
 
void UserActionsMenu::show(const QRect &pos, const QWeakPointer<Client> &cl)
 
130
void UserActionsMenu::show(const QRect &pos, const QWeakPointer<AbstractClient> &cl)
132
131
{
133
132
    if (!KAuthorized::authorizeKAction(QStringLiteral("kwin_rmb")))
134
133
        return;
165
164
    }
166
165
}
167
166
 
168
 
void UserActionsMenu::helperDialog(const QString& message, const QWeakPointer<Client> &c)
 
167
void UserActionsMenu::helperDialog(const QString& message, const QWeakPointer<AbstractClient> &c)
169
168
{
170
169
    QStringList args;
171
170
    QString type;
288
287
 
289
288
    advancedMenu->addSeparator();
290
289
 
291
 
    QAction *action = advancedMenu->addAction(i18n("Window &Shortcut..."));
292
 
    action->setIcon(QIcon::fromTheme(QStringLiteral("configure-shortcuts")));
293
 
    setShortcut(action, QStringLiteral("Setup Window Shortcut"));
294
 
    action->setData(Options::SetupWindowShortcutOp);
 
290
    m_shortcutOperation = advancedMenu->addAction(i18n("Window &Shortcut..."));
 
291
    m_shortcutOperation->setIcon(QIcon::fromTheme(QStringLiteral("configure-shortcuts")));
 
292
    setShortcut(m_shortcutOperation, QStringLiteral("Setup Window Shortcut"));
 
293
    m_shortcutOperation->setData(Options::SetupWindowShortcutOp);
295
294
 
296
 
    action = advancedMenu->addAction(i18n("&Special Window Settings..."));
 
295
    QAction *action = advancedMenu->addAction(i18n("&Special Window Settings..."));
297
296
    action->setIcon(QIcon::fromTheme(QStringLiteral("preferences-system-windows-actions")));
298
297
    action->setData(Options::WindowRulesOp);
299
298
 
307
306
                                        "Window &Manager Settings..."));
308
307
        action->setIcon(QIcon::fromTheme(QStringLiteral("configure")));
309
308
        connect(action, &QAction::triggered, this,
310
 
            []() {
 
309
            [this]() {
311
310
                // opens the KWin configuration
312
311
                QStringList args;
313
312
                args << QStringLiteral("--icon") << QStringLiteral("preferences-system-windows") << configModules(false);
314
 
                QString error;
315
 
                if (KToolInvocation::kdeinitExec(QStringLiteral("kcmshell5"), args, &error) != 0) {
316
 
                    qCDebug(KWIN_CORE) << "Failed to start kcmshell5: " << error;
317
 
                }
 
313
                QProcess *p = new QProcess(this);
 
314
                p->setArguments(args);
 
315
                p->setProcessEnvironment(kwinApp()->processStartupEnvironment());
 
316
                p->setProgram(QStringLiteral("kcmshell5"));
 
317
                connect(p, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this, &QProcess::deleteLater);
 
318
                connect(p, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error), this,
 
319
                    [p] (QProcess::ProcessError e) {
 
320
                        if (e == QProcess::FailedToStart) {
 
321
                            qCDebug(KWIN_CORE) << "Failed to start kcmshell5";
 
322
                        }
 
323
                    }
 
324
                );
 
325
                p->start();
318
326
            }
319
327
        );
320
328
    }
402
410
    m_noBorderOperation->setChecked(m_client.data()->noBorder());
403
411
    m_minimizeOperation->setEnabled(m_client.data()->isMinimizable());
404
412
    m_closeOperation->setEnabled(m_client.data()->isCloseable());
 
413
    m_shortcutOperation->setEnabled(m_client.data()->rules()->checkShortcut(QString()).isNull());
405
414
 
406
415
    if (false) {
407
416
        initTabbingPopups();
436
445
void UserActionsMenu::showHideActivityMenu()
437
446
{
438
447
#ifdef KWIN_BUILD_ACTIVITIES
 
448
    if (!Activities::self()) {
 
449
        return;
 
450
    }
439
451
    const QStringList &openActivities_ = Activities::self()->running();
440
452
    qCDebug(KWIN_CORE) << "activities:" << openActivities_.size();
441
453
    if (openActivities_.size() < 2) {
497
509
{
498
510
    if (m_client.isNull() || !action->data().isValid())
499
511
        return;
500
 
    Client *other = action->data().value<Client*>();
 
512
    Client *other = dynamic_cast<Client*>(action->data().value<AbstractClient*>());
501
513
    if (!Workspace::self()->clientList().contains(other)) // might have been lost betwenn pop-up and selection
502
514
        return;
503
 
    m_client.data()->tabBehind(other, true);
 
515
    Client *c = dynamic_cast<Client*>(m_client.data());
 
516
    if (!c) {
 
517
        return;
 
518
    }
 
519
    c->tabBehind(other, true);
504
520
    if (options->focusPolicyIsReasonable())
505
 
        Workspace::self()->requestFocus(m_client.data());
 
521
        Workspace::self()->requestFocus(c);
506
522
}
507
523
 
508
524
void UserActionsMenu::rebuildTabGroupPopup()
648
664
    QActionGroup *group = new QActionGroup(m_screenMenu);
649
665
 
650
666
    for (int i = 0; i<screens()->count(); ++i) {
651
 
        // TODO: retrieve the screen name?
652
667
        // assumption: there are not more than 9 screens attached.
653
 
        QAction *action = m_screenMenu->addAction(i18nc("@item:inmenu List of all Screens to send a window to",
654
 
                                                        "Screen &%1", (i+1)));
 
668
        QAction *action = m_screenMenu->addAction(i18nc("@item:inmenu List of all Screens to send a window to. First argument is a number, second the output identifier. E.g. Screen 1 (HDMI1)",
 
669
                                                        "Screen &%1 (%2)", (i+1), screens()->name(i)));
655
670
        action->setData(i);
656
671
        action->setCheckable(true);
657
672
        if (!m_client.isNull() && i == m_client.data()->screen()) {
667
682
        return;
668
683
 
669
684
#ifdef KWIN_BUILD_ACTIVITIES
 
685
    if (!Activities::self()) {
 
686
        return;
 
687
    }
670
688
    m_activityMenu->clear();
671
689
    m_activityMenu->setPalette(m_client.data()->palette());
672
690
    QAction *action = m_activityMenu->addAction(i18n("&All Activities"));
712
730
        return;
713
731
 
714
732
    Options::WindowOperation op = static_cast< Options::WindowOperation >(action->data().toInt());
715
 
    QWeakPointer<Client> c = (!m_client.isNull()) ? m_client : QWeakPointer<Client>(Workspace::self()->activeClient());
 
733
    QWeakPointer<AbstractClient> c = (!m_client.isNull()) ? m_client : QWeakPointer<AbstractClient>(Workspace::self()->activeClient());
716
734
    if (c.isNull())
717
735
        return;
718
736
    QString type;
735
753
    qRegisterMetaType<Options::WindowOperation>();
736
754
    QMetaObject::invokeMethod(workspace(), "performWindowOperation",
737
755
                              Qt::QueuedConnection,
738
 
                              Q_ARG(KWin::Client*, c.data()),
 
756
                              Q_ARG(KWin::AbstractClient*, c.data()),
739
757
                              Q_ARG(Options::WindowOperation, op));
740
758
}
741
759
 
777
795
void UserActionsMenu::slotToggleOnActivity(QAction *action)
778
796
{
779
797
#ifdef KWIN_BUILD_ACTIVITIES
 
798
    if (!Activities::self()) {
 
799
        return;
 
800
    }
780
801
    QString activity = action->data().toString();
781
802
    if (m_client.isNull())
782
803
        return;
786
807
        return;
787
808
    }
788
809
 
789
 
    Activities::self()->toggleClientOnActivity(m_client.data(), activity, false);
 
810
    Client *c = dynamic_cast<Client*>(m_client.data());
 
811
    if (!c) {
 
812
        return;
 
813
    }
 
814
 
 
815
    Activities::self()->toggleClientOnActivity(c, activity, false);
790
816
    if (m_activityMenu && m_activityMenu->isVisible() && m_activityMenu->actions().count()) {
791
817
        const bool isOnAll = m_client.data()->isOnAllActivities();
792
818
        m_activityMenu->actions().at(0)->setChecked(isOnAll);
954
980
    m_userActionsMenu->discard(); // so that it's recreated next time
955
981
}
956
982
 
957
 
void Workspace::setupWindowShortcut(Client* c)
 
983
void Workspace::setupWindowShortcut(AbstractClient* c)
958
984
{
959
985
    assert(client_keys_dialog == NULL);
960
986
    // TODO: PORT ME (KGlobalAccel related)
1019
1045
    }
1020
1046
}
1021
1047
 
1022
 
void Workspace::performWindowOperation(Client* c, Options::WindowOperation op)
 
1048
void Workspace::performWindowOperation(AbstractClient* c, Options::WindowOperation op)
1023
1049
{
1024
1050
    if (!c)
1025
1051
        return;
1156
1182
{
1157
1183
    bool replay = false;
1158
1184
    switch(command) {
1159
 
    case Options::MouseRaise:
1160
 
        workspace()->raiseClient(this);
1161
 
        break;
1162
1185
    case Options::MouseLower: {
1163
1186
        workspace()->lowerClient(this);
1164
1187
        // used to be activateNextClient(this), then topClientOnDesktop
1182
1205
        setShade(ShadeNone);
1183
1206
        cancelShadeHoverTimer();
1184
1207
        break;
1185
 
    case Options::MouseOperationsMenu:
1186
 
        if (isActive() && options->isClickRaise())
1187
 
            autoRaise();
1188
 
        workspace()->showWindowMenu(QRect(globalPos, globalPos), this);
1189
 
        break;
1190
 
    case Options::MouseToggleRaiseAndLower:
1191
 
        workspace()->raiseOrLowerClient(this);
1192
 
        break;
1193
 
    case Options::MouseActivateAndRaise: {
1194
 
        replay = isActive(); // for clickraise mode
1195
 
        bool mustReplay = !rules()->checkAcceptFocus(info->input());
1196
 
        if (mustReplay) {
1197
 
            ToplevelList::const_iterator  it = workspace()->stackingOrder().constEnd(),
1198
 
                                     begin = workspace()->stackingOrder().constBegin();
1199
 
            while (mustReplay && --it != begin && *it != this) {
1200
 
                Client *c = qobject_cast<Client*>(*it);
1201
 
                if (!c || (c->keepAbove() && !keepAbove()) || (keepBelow() && !c->keepBelow()))
1202
 
                    continue; // can never raise above "it"
1203
 
                mustReplay = !(c->isOnCurrentDesktop() && c->isOnCurrentActivity() && c->geometry().intersects(geometry()));
1204
 
            }
1205
 
        }
1206
 
        workspace()->takeActivity(this, Workspace::ActivityFocus | Workspace::ActivityRaise);
1207
 
        screens()->setCurrent(globalPos);
1208
 
        replay = replay || mustReplay;
1209
 
        break;
1210
 
    }
1211
 
    case Options::MouseActivateAndLower:
1212
 
        workspace()->requestFocus(this);
1213
 
        workspace()->lowerClient(this);
1214
 
        screens()->setCurrent(globalPos);
1215
 
        replay = replay || !rules()->checkAcceptFocus(info->input());
1216
 
        break;
1217
 
    case Options::MouseActivate:
1218
 
        replay = isActive(); // for clickraise mode
1219
 
        workspace()->takeActivity(this, Workspace::ActivityFocus);
1220
 
        screens()->setCurrent(globalPos);
1221
 
        replay = replay || !rules()->checkAcceptFocus(info->input());
1222
 
        break;
1223
 
    case Options::MouseActivateRaiseAndPassClick:
1224
 
        workspace()->takeActivity(this, Workspace::ActivityFocus | Workspace::ActivityRaise);
1225
 
        screens()->setCurrent(globalPos);
1226
 
        replay = true;
1227
 
        break;
1228
 
    case Options::MouseActivateAndPassClick:
1229
 
        workspace()->takeActivity(this, Workspace::ActivityFocus);
1230
 
        screens()->setCurrent(globalPos);
1231
 
        replay = true;
1232
 
        break;
1233
1208
    case Options::MouseActivateRaiseAndMove:
1234
1209
    case Options::MouseActivateRaiseAndUnrestrictedMove:
1235
1210
        workspace()->raiseClient(this);
1279
1254
        updateCursor();
1280
1255
        break;
1281
1256
    }
1282
 
    case Options::MouseMaximize:
1283
 
        maximize(MaximizeFull);
1284
 
        break;
1285
 
    case Options::MouseRestore:
1286
 
        maximize(MaximizeRestore);
1287
 
        break;
1288
 
    case Options::MouseMinimize:
1289
 
        minimize();
1290
 
        break;
1291
 
    case Options::MouseAbove: {
1292
 
        StackingUpdatesBlocker blocker(workspace());
1293
 
        if (keepBelow())
1294
 
            setKeepBelow(false);
1295
 
        else
1296
 
            setKeepAbove(true);
1297
 
        break;
1298
 
    }
1299
 
    case Options::MouseBelow: {
1300
 
        StackingUpdatesBlocker blocker(workspace());
1301
 
        if (keepAbove())
1302
 
            setKeepAbove(false);
1303
 
        else
1304
 
            setKeepBelow(true);
1305
 
        break;
1306
 
    }
1307
 
    case Options::MousePreviousDesktop:
1308
 
        workspace()->windowToPreviousDesktop(this);
1309
 
        break;
1310
 
    case Options::MouseNextDesktop:
1311
 
        workspace()->windowToNextDesktop(this);
1312
 
        break;
1313
 
    case Options::MouseOpacityMore:
1314
 
        if (!isDesktop())   // No point in changing the opacity of the desktop
1315
 
            setOpacity(qMin(opacity() + 0.1, 1.0));
1316
 
        break;
1317
 
    case Options::MouseOpacityLess:
1318
 
        if (!isDesktop())   // No point in changing the opacity of the desktop
1319
 
            setOpacity(qMax(opacity() - 0.1, 0.1));
1320
 
        break;
1321
 
    case Options::MousePreviousTab:
1322
 
        if (tabGroup())
1323
 
            tabGroup()->activatePrev();
1324
 
    break;
1325
 
    case Options::MouseNextTab:
1326
 
        if (tabGroup())
1327
 
            tabGroup()->activateNext();
1328
 
    break;
1329
 
    case Options::MouseClose:
1330
 
        closeWindow();
1331
 
        break;
1332
 
    case Options::MouseDragTab:
1333
 
    case Options::MouseNothing:
1334
 
        replay = true;
1335
 
        break;
 
1257
    default:
 
1258
        return AbstractClient::performMouseCommand(command, globalPos);
1336
1259
    }
1337
1260
    return replay;
1338
1261
}
1556
1479
}
1557
1480
 
1558
1481
template <typename Direction>
1559
 
void windowToDesktop(Client *c)
 
1482
void windowToDesktop(AbstractClient *c)
1560
1483
{
1561
1484
    VirtualDesktopManager *vds = VirtualDesktopManager::self();
1562
1485
    Workspace *ws = Workspace::self();
1580
1503
        windowToNextDesktop(active_client);
1581
1504
}
1582
1505
 
1583
 
void Workspace::windowToNextDesktop(Client* c)
 
1506
void Workspace::windowToNextDesktop(AbstractClient* c)
1584
1507
{
1585
1508
    windowToDesktop<DesktopNext>(c);
1586
1509
}
1594
1517
        windowToPreviousDesktop(active_client);
1595
1518
}
1596
1519
 
1597
 
void Workspace::windowToPreviousDesktop(Client* c)
 
1520
void Workspace::windowToPreviousDesktop(AbstractClient* c)
1598
1521
{
1599
1522
    windowToDesktop<DesktopPrevious>(c);
1600
1523
}
1679
1602
{
1680
1603
    if (!active_client)
1681
1604
        return;
1682
 
    Client *c = active_client;
 
1605
    AbstractClient *c = active_client;
1683
1606
    Client *switchTo = 0;
1684
1607
    int bestScore = 0;
1685
1608
    int d = c->isOnAllDesktops() ? VirtualDesktopManager::self()->current() : c->desktop();
1783
1706
    showWindowMenu(QRect(pos, pos), active_client);
1784
1707
}
1785
1708
 
1786
 
void Workspace::showWindowMenu(const QRect &pos, Client* cl)
 
1709
void Workspace::showWindowMenu(const QRect &pos, AbstractClient* cl)
1787
1710
{
1788
1711
    m_userActionsMenu->show(pos, cl);
1789
1712
}