Changeset View
Standalone View
useractions.cpp
Show First 20 Lines • Show All 105 Lines • ▼ Show 20 Line(s) | |||||
106 | 106 | | |||
107 | bool UserActionsMenu::isShown() const | 107 | bool UserActionsMenu::isShown() const | ||
108 | { | 108 | { | ||
109 | return m_menu && m_menu->isVisible(); | 109 | return m_menu && m_menu->isVisible(); | ||
110 | } | 110 | } | ||
111 | 111 | | |||
112 | bool UserActionsMenu::hasClient() const | 112 | bool UserActionsMenu::hasClient() const | ||
113 | { | 113 | { | ||
114 | return !m_client.isNull() && isShown(); | 114 | return m_client && isShown(); | ||
115 | } | 115 | } | ||
116 | 116 | | |||
117 | void UserActionsMenu::close() | 117 | void UserActionsMenu::close() | ||
118 | { | 118 | { | ||
119 | if (!m_menu) { | 119 | if (!m_menu) { | ||
120 | return; | 120 | return; | ||
121 | } | 121 | } | ||
122 | m_menu->close(); | 122 | m_menu->close(); | ||
123 | m_client.clear(); | 123 | m_client.clear(); | ||
124 | } | 124 | } | ||
125 | 125 | | |||
126 | bool UserActionsMenu::isMenuClient(const AbstractClient *c) const | 126 | bool UserActionsMenu::isMenuClient(const AbstractClient *c) const | ||
127 | { | 127 | { | ||
128 | if (!c || m_client.isNull()) { | 128 | return c && c == m_client; | ||
129 | return false; | | |||
130 | } | | |||
131 | return c == m_client.data(); | | |||
132 | } | 129 | } | ||
133 | 130 | | |||
134 | void UserActionsMenu::show(const QRect &pos, AbstractClient *client) | 131 | void UserActionsMenu::show(const QRect &pos, AbstractClient *client) | ||
135 | { | 132 | { | ||
133 | Q_ASSERT(client); | ||||
136 | QPointer<AbstractClient> cl(client); | 134 | QPointer<AbstractClient> cl(client); | ||
137 | if (!KAuthorized::authorizeAction(QStringLiteral("kwin_rmb"))) | 135 | if (!KAuthorized::authorizeAction(QStringLiteral("kwin_rmb"))) | ||
138 | return; | 136 | return; | ||
139 | if (cl.isNull()) | 137 | if (cl.isNull()) | ||
romangg: If we assert client in the beginning then cl must be non-null, right? Would make all the below… | |||||
You're right. Passing nullptr for client doesn't make sense. This if statement can be dropped. zzag: You're right. Passing nullptr for client doesn't make sense. This if statement can be dropped. | |||||
Asserts are not active in release mode. I was very conservative, but I assume all of this is single-threaded? In that case I would indeed assume that m_client is not nullptr. gladhorn: Asserts are not active in release mode. I was very conservative, but I assume all of this is… | |||||
Ok, how about:
But looking at Workspace::slotWindowOperations, the only place show is called from, it checks before that the argument is non-null. So we should not need a check. romangg: Ok, how about:
* Leave the assert
* Afterwards directly do the cl.isNull() check
* Add a… | |||||
I generally agree, but I wonder if the checks are there for a reason. And keep in mind, that this kind of nullptr check is very cheap, it's something that is so common that it's very optimized. I don't mind removing the first checks, as it was before, but I'd rather not cause a regression with the later ones. As soon as the popup is open, I'd assume nothing is guaranteed any more, since the actions in the menu could lead to clients being deleted (I'm not entirely sure). show is called by Workspace::showWindowMenu which is called by three places without checking itself as far as I can tell (Workspace::slotWindowOperations, AbstractClient::performMouseCommand and DecoratedClientImpl::requestShowWindowMenu). gladhorn: I generally agree, but I wonder if the checks are there for a reason. And keep in mind, that… | |||||
zzag: This piece of code contradicts to Q_ASSERT above. Delete the if statement. | |||||
Remember that asserts are only in debug builds, most users will run release builds. I do agree though that this is somewhat redundant. If the assert is valid, which I think it is, then it should never trigger and we can remove the if, if the assert turns out to be wrong, then it can be removed. In either case, release builds should work and not crash, while debug builds will expose potential issues. gladhorn: Remember that asserts are only in debug builds, most users will run release builds. I do agree… | |||||
140 | return; | 138 | return; | ||
141 | if (isShown()) // recursion | 139 | if (isShown()) // recursion | ||
142 | return; | 140 | return; | ||
143 | if (cl.data()->isDesktop() | 141 | if (cl->isDesktop() || cl->isDock()) | ||
romangg: Also add braces here and below. | |||||
144 | || cl.data()->isDock()) | | |||
145 | return; | 142 | return; | ||
146 | 143 | | |||
147 | m_client = cl; | 144 | m_client = cl; | ||
148 | init(); | 145 | init(); | ||
149 | Workspace *ws = Workspace::self(); | 146 | Workspace *ws = Workspace::self(); | ||
150 | int x = pos.left(); | 147 | int x = pos.left(); | ||
151 | int y = pos.bottom(); | 148 | int y = pos.bottom(); | ||
152 | const bool needsPopup = kwinApp()->shouldUseWaylandForCompositing(); | 149 | const bool needsPopup = kwinApp()->shouldUseWaylandForCompositing(); | ||
153 | if (y == pos.top()) { | 150 | if (y == pos.top()) { | ||
154 | m_client.data()->blockActivityUpdates(true); | 151 | if (m_client) { | ||
152 | m_client->blockActivityUpdates(true); | ||||
153 | } | ||||
155 | if (needsPopup) { | 154 | if (needsPopup) { | ||
Use curly braces even when the body of a conditional statement contains only one line. zzag: Use curly braces even when the body of a conditional statement contains only one line. | |||||
OK, the previous few lines don't do that, but I'm happy to follow kdelibs style. gladhorn: OK, the previous few lines don't do that, but I'm happy to follow kdelibs style. | |||||
156 | m_menu->popup(QPoint(x, y)); | 155 | m_menu->popup(QPoint(x, y)); | ||
157 | } else { | 156 | } else { | ||
158 | m_menu->exec(QPoint(x, y)); | 157 | m_menu->exec(QPoint(x, y)); | ||
159 | } | 158 | } | ||
160 | if (!m_client.isNull()) | 159 | if (m_client) { | ||
161 | m_client.data()->blockActivityUpdates(false); | 160 | m_client->blockActivityUpdates(false); | ||
161 | } | ||||
162 | } | 162 | } | ||
163 | else { | 163 | else { | ||
164 | m_client.data()->blockActivityUpdates(true); | 164 | if (m_client) { | ||
165 | m_client->blockActivityUpdates(true); | ||||
166 | } | ||||
We set m_client = cl above and cl is guaranteed to be non-null at this point so check is not necessary. romangg: We set `m_client = cl` above and cl is guaranteed to be non-null at this point so check is not… | |||||
But m_menu->exec spins an event loop. Are you sure this cannot make the client go away? What is in the user actions menu? m_closeOperation = m_menu->addAction(i18n("&Close")); gladhorn: But m_menu->exec spins an event loop. Are you sure this cannot make the client go away? What is… | |||||
romangg: Yea, you're right. Thanks for explanation. | |||||
165 | QRect area = ws->clientArea(ScreenArea, QPoint(x, y), VirtualDesktopManager::self()->current()); | 167 | QRect area = ws->clientArea(ScreenArea, QPoint(x, y), VirtualDesktopManager::self()->current()); | ||
166 | menuAboutToShow(); // needed for sizeHint() to be correct :-/ | 168 | menuAboutToShow(); // needed for sizeHint() to be correct :-/ | ||
167 | int popupHeight = m_menu->sizeHint().height(); | 169 | int popupHeight = m_menu->sizeHint().height(); | ||
168 | if (y + popupHeight < area.height()) { | 170 | if (y + popupHeight < area.height()) { | ||
169 | if (needsPopup) { | 171 | if (needsPopup) { | ||
170 | m_menu->popup(QPoint(x, y)); | 172 | m_menu->popup(QPoint(x, y)); | ||
171 | } else { | 173 | } else { | ||
172 | m_menu->exec(QPoint(x, y)); | 174 | m_menu->exec(QPoint(x, y)); | ||
173 | } | 175 | } | ||
174 | } else { | 176 | } else { | ||
175 | if (needsPopup) { | 177 | if (needsPopup) { | ||
176 | m_menu->popup(QPoint(x, pos.top() - popupHeight)); | 178 | m_menu->popup(QPoint(x, pos.top() - popupHeight)); | ||
177 | } else { | 179 | } else { | ||
178 | m_menu->exec(QPoint(x, pos.top() - popupHeight)); | 180 | m_menu->exec(QPoint(x, pos.top() - popupHeight)); | ||
179 | } | 181 | } | ||
180 | } | 182 | } | ||
181 | if (!m_client.isNull()) | 183 | if (m_client) { | ||
182 | m_client.data()->blockActivityUpdates(false); | 184 | m_client->blockActivityUpdates(false); | ||
185 | } | ||||
romangg: Here check also not necessary. | |||||
zzag: https://blogs.kde.org/2009/03/26/how-crash-almost-every-qtkde-application-and-how-fix-it-0 | |||||
183 | } | 186 | } | ||
184 | } | 187 | } | ||
185 | 188 | | |||
186 | void UserActionsMenu::grabInput() | 189 | void UserActionsMenu::grabInput() | ||
187 | { | 190 | { | ||
188 | m_menu->windowHandle()->setMouseGrabEnabled(true); | 191 | m_menu->windowHandle()->setMouseGrabEnabled(true); | ||
189 | m_menu->windowHandle()->setKeyboardGrabEnabled(true); | 192 | m_menu->windowHandle()->setKeyboardGrabEnabled(true); | ||
190 | } | 193 | } | ||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | 260 | if (m_menu) { | |||
258 | return; | 261 | return; | ||
259 | } | 262 | } | ||
260 | m_menu = new QMenu; | 263 | m_menu = new QMenu; | ||
261 | connect(m_menu, &QMenu::aboutToShow, this, &UserActionsMenu::menuAboutToShow); | 264 | connect(m_menu, &QMenu::aboutToShow, this, &UserActionsMenu::menuAboutToShow); | ||
262 | connect(m_menu, &QMenu::triggered, this, &UserActionsMenu::slotWindowOperation, Qt::QueuedConnection); | 265 | connect(m_menu, &QMenu::triggered, this, &UserActionsMenu::slotWindowOperation, Qt::QueuedConnection); | ||
263 | 266 | | |||
264 | QMenu *advancedMenu = new QMenu(m_menu); | 267 | QMenu *advancedMenu = new QMenu(m_menu); | ||
265 | connect(advancedMenu, &QMenu::aboutToShow, [this, advancedMenu]() { | 268 | connect(advancedMenu, &QMenu::aboutToShow, [this, advancedMenu]() { | ||
266 | advancedMenu->setPalette(m_client.data()->palette()); | 269 | if (m_client) { | ||
270 | advancedMenu->setPalette(m_client->palette()); | ||||
271 | } | ||||
267 | }); | 272 | }); | ||
268 | 273 | | |||
269 | auto setShortcut = [](QAction *action, const QString &actionName) { | 274 | auto setShortcut = [](QAction *action, const QString &actionName) { | ||
270 | const auto shortcuts = KGlobalAccel::self()->shortcut(Workspace::self()->findChild<QAction*>(actionName)); | 275 | const auto shortcuts = KGlobalAccel::self()->shortcut(Workspace::self()->findChild<QAction*>(actionName)); | ||
271 | if (!shortcuts.isEmpty()) { | 276 | if (!shortcuts.isEmpty()) { | ||
272 | action->setShortcut(shortcuts.first()); | 277 | action->setShortcut(shortcuts.first()); | ||
273 | } | 278 | } | ||
274 | }; | 279 | }; | ||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Line(s) | 420 | { | |||
419 | if (VirtualDesktopManager::self()->count() == 1) { | 424 | if (VirtualDesktopManager::self()->count() == 1) { | ||
420 | delete m_desktopMenu; | 425 | delete m_desktopMenu; | ||
421 | m_desktopMenu = 0; | 426 | m_desktopMenu = 0; | ||
422 | delete m_multipleDesktopsMenu; | 427 | delete m_multipleDesktopsMenu; | ||
423 | m_multipleDesktopsMenu = nullptr; | 428 | m_multipleDesktopsMenu = nullptr; | ||
424 | } else { | 429 | } else { | ||
425 | initDesktopPopup(); | 430 | initDesktopPopup(); | ||
426 | } | 431 | } | ||
427 | if (screens()->count() == 1 || (!m_client.data()->isMovable() && !m_client.data()->isMovableAcrossScreens())) { | 432 | if (screens()->count() == 1 || (!m_client->isMovable() && !m_client->isMovableAcrossScreens())) { | ||
428 | delete m_screenMenu; | 433 | delete m_screenMenu; | ||
429 | m_screenMenu = NULL; | 434 | m_screenMenu = NULL; | ||
430 | } else { | 435 | } else { | ||
431 | initScreenPopup(); | 436 | initScreenPopup(); | ||
432 | } | 437 | } | ||
433 | 438 | | |||
434 | m_menu->setPalette(m_client.data()->palette()); | 439 | m_menu->setPalette(m_client->palette()); | ||
435 | m_resizeOperation->setEnabled(m_client.data()->isResizable()); | 440 | m_resizeOperation->setEnabled(m_client->isResizable()); | ||
436 | m_moveOperation->setEnabled(m_client.data()->isMovableAcrossScreens()); | 441 | m_moveOperation->setEnabled(m_client->isMovableAcrossScreens()); | ||
437 | m_maximizeOperation->setEnabled(m_client.data()->isMaximizable()); | 442 | m_maximizeOperation->setEnabled(m_client->isMaximizable()); | ||
438 | m_maximizeOperation->setChecked(m_client.data()->maximizeMode() == MaximizeFull); | 443 | m_maximizeOperation->setChecked(m_client->maximizeMode() == MaximizeFull); | ||
439 | m_shadeOperation->setEnabled(m_client.data()->isShadeable()); | 444 | m_shadeOperation->setEnabled(m_client->isShadeable()); | ||
440 | m_shadeOperation->setChecked(m_client.data()->shadeMode() != ShadeNone); | 445 | m_shadeOperation->setChecked(m_client->shadeMode() != ShadeNone); | ||
441 | m_keepAboveOperation->setChecked(m_client.data()->keepAbove()); | 446 | m_keepAboveOperation->setChecked(m_client->keepAbove()); | ||
442 | m_keepBelowOperation->setChecked(m_client.data()->keepBelow()); | 447 | m_keepBelowOperation->setChecked(m_client->keepBelow()); | ||
443 | m_fullScreenOperation->setEnabled(m_client.data()->userCanSetFullScreen()); | 448 | m_fullScreenOperation->setEnabled(m_client->userCanSetFullScreen()); | ||
444 | m_fullScreenOperation->setChecked(m_client.data()->isFullScreen()); | 449 | m_fullScreenOperation->setChecked(m_client->isFullScreen()); | ||
445 | m_noBorderOperation->setEnabled(m_client.data()->userCanSetNoBorder()); | 450 | m_noBorderOperation->setEnabled(m_client->userCanSetNoBorder()); | ||
446 | m_noBorderOperation->setChecked(m_client.data()->noBorder()); | 451 | m_noBorderOperation->setChecked(m_client->noBorder()); | ||
447 | m_minimizeOperation->setEnabled(m_client.data()->isMinimizable()); | 452 | m_minimizeOperation->setEnabled(m_client->isMinimizable()); | ||
448 | m_closeOperation->setEnabled(m_client.data()->isCloseable()); | 453 | m_closeOperation->setEnabled(m_client->isCloseable()); | ||
449 | m_shortcutOperation->setEnabled(m_client.data()->rules()->checkShortcut(QString()).isNull()); | 454 | m_shortcutOperation->setEnabled(m_client->rules()->checkShortcut(QString()).isNull()); | ||
450 | 455 | | |||
451 | if (false) { | 456 | if (false) { | ||
452 | initTabbingPopups(); | 457 | initTabbingPopups(); | ||
453 | m_addTabsMenu->setPalette(m_client.data()->palette()); | 458 | m_addTabsMenu->setPalette(m_client->palette()); | ||
454 | } else { | 459 | } else { | ||
455 | delete m_addTabsMenu; | 460 | delete m_addTabsMenu; | ||
456 | m_addTabsMenu = 0; | 461 | m_addTabsMenu = 0; | ||
457 | } | 462 | } | ||
458 | 463 | | |||
459 | // drop the existing scripts menu | 464 | // drop the existing scripts menu | ||
460 | delete m_scriptsMenu; | 465 | delete m_scriptsMenu; | ||
461 | m_scriptsMenu = NULL; | 466 | m_scriptsMenu = NULL; | ||
462 | // ask scripts whether they want to add entries for the given Client | 467 | // ask scripts whether they want to add entries for the given Client | ||
463 | QList<QAction*> scriptActions = Scripting::self()->actionsForUserActionMenu(m_client.data(), m_scriptsMenu); | 468 | QList<QAction*> scriptActions = Scripting::self()->actionsForUserActionMenu(m_client.data(), m_scriptsMenu); | ||
464 | if (!scriptActions.isEmpty()) { | 469 | if (!scriptActions.isEmpty()) { | ||
465 | m_scriptsMenu = new QMenu(m_menu); | 470 | m_scriptsMenu = new QMenu(m_menu); | ||
466 | m_scriptsMenu->setPalette(m_client.data()->palette()); | 471 | m_scriptsMenu->setPalette(m_client->palette()); | ||
467 | m_scriptsMenu->addActions(scriptActions); | 472 | m_scriptsMenu->addActions(scriptActions); | ||
468 | 473 | | |||
469 | QAction *action = m_scriptsMenu->menuAction(); | 474 | QAction *action = m_scriptsMenu->menuAction(); | ||
470 | // set it as the first item after desktop | 475 | // set it as the first item after desktop | ||
471 | m_menu->insertAction(m_closeOperation, action); | 476 | m_menu->insertAction(m_closeOperation, action); | ||
472 | action->setText(i18n("&Extensions")); | 477 | action->setText(i18n("&Extensions")); | ||
473 | } | 478 | } | ||
474 | 479 | | |||
475 | m_rulesOperation->setEnabled(m_client.data()->supportsWindowRules()); | 480 | m_rulesOperation->setEnabled(m_client->supportsWindowRules()); | ||
476 | m_applicationRulesOperation->setEnabled(m_client.data()->supportsWindowRules()); | 481 | m_applicationRulesOperation->setEnabled(m_client->supportsWindowRules()); | ||
477 | 482 | | |||
478 | showHideActivityMenu(); | 483 | showHideActivityMenu(); | ||
479 | } | 484 | } | ||
480 | 485 | | |||
481 | void UserActionsMenu::showHideActivityMenu() | 486 | void UserActionsMenu::showHideActivityMenu() | ||
482 | { | 487 | { | ||
483 | #ifdef KWIN_BUILD_ACTIVITIES | 488 | #ifdef KWIN_BUILD_ACTIVITIES | ||
484 | if (!Activities::self()) { | 489 | if (!Activities::self()) { | ||
485 | return; | 490 | return; | ||
486 | } | 491 | } | ||
487 | const QStringList &openActivities_ = Activities::self()->running(); | 492 | const QStringList &openActivities_ = Activities::self()->running(); | ||
488 | qCDebug(KWIN_CORE) << "activities:" << openActivities_.size(); | 493 | qCDebug(KWIN_CORE) << "activities:" << openActivities_.size(); | ||
489 | if (openActivities_.size() < 2) { | 494 | if (openActivities_.size() < 2) { | ||
490 | delete m_activityMenu; | 495 | delete m_activityMenu; | ||
491 | m_activityMenu = 0; | 496 | m_activityMenu = 0; | ||
492 | } else { | 497 | } else { | ||
493 | initActivityPopup(); | 498 | initActivityPopup(); | ||
494 | } | 499 | } | ||
495 | #endif | 500 | #endif | ||
496 | } | 501 | } | ||
497 | 502 | | |||
498 | void UserActionsMenu::selectPopupClientTab(QAction* action) | 503 | void UserActionsMenu::selectPopupClientTab(QAction* action) | ||
499 | { | 504 | { | ||
500 | if (!(!m_client.isNull() && m_client.data()->tabGroup()) || !action->data().isValid()) | 505 | if (!m_client || !m_client->tabGroup() || !action->data().isValid()) { | ||
501 | return; | 506 | return; | ||
507 | } | ||||
502 | 508 | | |||
503 | if (AbstractClient *other = action->data().value<AbstractClient*>()) { | 509 | if (AbstractClient *other = action->data().value<AbstractClient*>()) { | ||
504 | m_client.data()->tabGroup()->setCurrent(other); | 510 | m_client->tabGroup()->setCurrent(other); | ||
505 | return; | 511 | return; | ||
506 | } | 512 | } | ||
507 | 513 | | |||
508 | // failed conversion, try "1" & "2", being prev and next | 514 | // failed conversion, try "1" & "2", being prev and next | ||
509 | int direction = action->data().toInt(); | 515 | int direction = action->data().toInt(); | ||
510 | if (direction == 1) | 516 | if (direction == 1) { | ||
511 | m_client.data()->tabGroup()->activatePrev(); | 517 | m_client->tabGroup()->activatePrev(); | ||
512 | else if (direction == 2) | 518 | } else if (direction == 2) { | ||
513 | m_client.data()->tabGroup()->activateNext(); | 519 | m_client->tabGroup()->activateNext(); | ||
520 | } | ||||
514 | } | 521 | } | ||
515 | 522 | | |||
516 | static QString shortCaption(const QString &s) | 523 | static QString shortCaption(const QString &s) | ||
517 | { | 524 | { | ||
518 | if (s.length() < 64) | 525 | if (s.length() < 64) | ||
519 | return s; | 526 | return s; | ||
520 | QString ss = s; | 527 | QString ss = s; | ||
521 | return ss.replace(32,s.length()-64, QStringLiteral("...")); | 528 | return ss.replace(32,s.length()-64, QStringLiteral("...")); | ||
522 | } | 529 | } | ||
523 | 530 | | |||
524 | void UserActionsMenu::rebuildTabListPopup() | 531 | void UserActionsMenu::rebuildTabListPopup() | ||
525 | { | 532 | { | ||
526 | Q_ASSERT(m_switchToTabMenu); | 533 | Q_ASSERT(m_switchToTabMenu); | ||
527 | 534 | | |||
528 | m_switchToTabMenu->clear(); | 535 | m_switchToTabMenu->clear(); | ||
529 | // whatever happens "0x1" and "0x2" are no heap positions ;-) | 536 | // whatever happens "0x1" and "0x2" are no heap positions ;-) | ||
530 | m_switchToTabMenu->addAction(i18nc("Switch to tab -> Previous", "Previous"))->setData(1); | 537 | m_switchToTabMenu->addAction(i18nc("Switch to tab -> Previous", "Previous"))->setData(1); | ||
531 | m_switchToTabMenu->addAction(i18nc("Switch to tab -> Next", "Next"))->setData(2); | 538 | m_switchToTabMenu->addAction(i18nc("Switch to tab -> Next", "Next"))->setData(2); | ||
532 | 539 | | |||
533 | m_switchToTabMenu->addSeparator(); | 540 | m_switchToTabMenu->addSeparator(); | ||
534 | 541 | | |||
535 | for (auto i = m_client.data()->tabGroup()->clients().constBegin(), | 542 | if (!m_client) { | ||
536 | end = m_client.data()->tabGroup()->clients().constEnd(); i != end; ++i) { | 543 | return; | ||
537 | if ((*i)->noBorder() || *i == m_client.data()->tabGroup()->current()) | 544 | } | ||
545 | for (auto i = m_client->tabGroup()->clients().constBegin(), | ||||
546 | end = m_client->tabGroup()->clients().constEnd(); i != end; ++i) { | ||||
547 | if ((*i)->noBorder() || *i == m_client->tabGroup()->current()) | ||||
538 | continue; // cannot tab there anyway | 548 | continue; // cannot tab there anyway | ||
539 | m_switchToTabMenu->addAction(shortCaption((*i)->caption()))->setData(QVariant::fromValue(*i)); | 549 | m_switchToTabMenu->addAction(shortCaption((*i)->caption()))->setData(QVariant::fromValue(*i)); | ||
540 | } | 550 | } | ||
541 | | ||||
542 | } | 551 | } | ||
543 | 552 | | |||
544 | void UserActionsMenu::entabPopupClient(QAction* action) | 553 | void UserActionsMenu::entabPopupClient(QAction* action) | ||
545 | { | 554 | { | ||
546 | if (m_client.isNull() || !action->data().isValid()) | 555 | if (m_client.isNull() || !action->data().isValid()) { | ||
547 | return; | 556 | return; | ||
557 | } | ||||
548 | AbstractClient *other = action->data().value<AbstractClient*>(); | 558 | AbstractClient *other = action->data().value<AbstractClient*>(); | ||
549 | if (!Workspace::self()->allClientList().contains(other)) // might have been lost betwenn pop-up and selection | 559 | if (!Workspace::self()->allClientList().contains(other)) { // might have been lost betwenn pop-up and selection | ||
550 | return; | | |||
551 | AbstractClient *c = m_client.data(); | | |||
552 | if (!c) { | | |||
553 | return; | 560 | return; | ||
554 | } | 561 | } | ||
555 | c->tabBehind(other, true); | 562 | | ||
556 | if (options->focusPolicyIsReasonable()) | 563 | m_client->tabBehind(other, true); | ||
557 | Workspace::self()->requestFocus(c); | 564 | if (options->focusPolicyIsReasonable()) { | ||
565 | Workspace::self()->requestFocus(m_client); | ||||
566 | } | ||||
558 | } | 567 | } | ||
559 | 568 | | |||
560 | void UserActionsMenu::rebuildTabGroupPopup() | 569 | void UserActionsMenu::rebuildTabGroupPopup() | ||
561 | { | 570 | { | ||
562 | Q_ASSERT(m_addTabsMenu); | 571 | Q_ASSERT(m_addTabsMenu); | ||
563 | 572 | | |||
564 | m_addTabsMenu->clear(); | 573 | m_addTabsMenu->clear(); | ||
565 | const auto &clientList = Workspace::self()->allClientList(); | 574 | const auto &clientList = Workspace::self()->allClientList(); | ||
566 | for (auto i = clientList.constBegin(), end = clientList.constEnd(); i != end; ++i) { | 575 | for (auto i = clientList.constBegin(), end = clientList.constEnd(); i != end; ++i) { | ||
567 | if (*i == m_client.data() || (*i)->noBorder()) | 576 | if (*i == m_client.data() || (*i)->noBorder()) | ||
568 | continue; | 577 | continue; | ||
569 | m_addTabsMenu->addAction(shortCaption((*i)->caption()))->setData(QVariant::fromValue(*i)); | 578 | m_addTabsMenu->addAction(shortCaption((*i)->caption()))->setData(QVariant::fromValue(*i)); | ||
570 | } | 579 | } | ||
571 | if (m_addTabsMenu->actions().isEmpty()) | 580 | if (m_addTabsMenu->actions().isEmpty()) | ||
572 | m_addTabsMenu->addAction(i18nc("There's no window available to be attached as tab to this one", "None available"))->setEnabled(false); | 581 | m_addTabsMenu->addAction(i18nc("There's no window available to be attached as tab to this one", "None available"))->setEnabled(false); | ||
573 | } | 582 | } | ||
574 | 583 | | |||
575 | void UserActionsMenu::initTabbingPopups() | 584 | void UserActionsMenu::initTabbingPopups() | ||
576 | { | 585 | { | ||
577 | bool needTabManagers = false; | 586 | bool needTabManagers = false; | ||
578 | if (m_client.data()->tabGroup() && m_client.data()->tabGroup()->count() > 1) { | 587 | Q_ASSERT(m_client); | ||
588 | if (!m_client) | ||||
589 | return; | ||||
590 | if (m_client->tabGroup() && m_client->tabGroup()->count() > 1) { | ||||
579 | needTabManagers = true; | 591 | needTabManagers = true; | ||
580 | if (!m_switchToTabMenu) { | 592 | if (!m_switchToTabMenu) { | ||
581 | m_switchToTabMenu = new QMenu(i18n("Switch to Tab"), m_menu); | 593 | m_switchToTabMenu = new QMenu(i18n("Switch to Tab"), m_menu); | ||
582 | connect(m_switchToTabMenu, &QMenu::triggered, this, &UserActionsMenu::selectPopupClientTab); | 594 | connect(m_switchToTabMenu, &QMenu::triggered, this, &UserActionsMenu::selectPopupClientTab); | ||
583 | connect(m_switchToTabMenu, &QMenu::aboutToShow, this, &UserActionsMenu::rebuildTabListPopup); | 595 | connect(m_switchToTabMenu, &QMenu::aboutToShow, this, &UserActionsMenu::rebuildTabListPopup); | ||
584 | m_menu->insertMenu(m_removeFromTabGroup, m_switchToTabMenu); | 596 | m_menu->insertMenu(m_removeFromTabGroup, m_switchToTabMenu); | ||
585 | } | 597 | } | ||
586 | } else { | 598 | } else { | ||
587 | delete m_switchToTabMenu; | 599 | delete m_switchToTabMenu; | ||
588 | m_switchToTabMenu = 0; | 600 | m_switchToTabMenu = 0; | ||
589 | } | 601 | } | ||
590 | 602 | | |||
591 | if (!m_addTabsMenu) { | 603 | if (!m_addTabsMenu) { | ||
592 | m_addTabsMenu = new QMenu(i18n("&Attach as tab to"), m_menu); | 604 | m_addTabsMenu = new QMenu(i18n("&Attach as tab to"), m_menu); | ||
593 | connect(m_addTabsMenu, &QMenu::triggered, this, &UserActionsMenu::entabPopupClient); | 605 | connect(m_addTabsMenu, &QMenu::triggered, this, &UserActionsMenu::entabPopupClient); | ||
594 | connect(m_addTabsMenu, &QMenu::aboutToShow, this, &UserActionsMenu::rebuildTabGroupPopup); | 606 | connect(m_addTabsMenu, &QMenu::aboutToShow, this, &UserActionsMenu::rebuildTabGroupPopup); | ||
595 | m_menu->insertMenu(m_removeFromTabGroup, m_addTabsMenu); | 607 | m_menu->insertMenu(m_removeFromTabGroup, m_addTabsMenu); | ||
596 | } | 608 | } | ||
597 | 609 | | |||
598 | m_addTabsMenu->menuAction()->setEnabled(!m_client.data()->isFullScreen()); | 610 | m_addTabsMenu->menuAction()->setEnabled(!m_client->isFullScreen()); | ||
599 | m_removeFromTabGroup->setVisible(needTabManagers); | 611 | m_removeFromTabGroup->setVisible(needTabManagers); | ||
600 | m_closeTabGroup->setVisible(needTabManagers); | 612 | m_closeTabGroup->setVisible(needTabManagers); | ||
601 | } | 613 | } | ||
602 | 614 | | |||
603 | void UserActionsMenu::initDesktopPopup() | 615 | void UserActionsMenu::initDesktopPopup() | ||
604 | { | 616 | { | ||
605 | if (kwinApp()->operationMode() == Application::OperationModeWaylandOnly || | 617 | if (kwinApp()->operationMode() == Application::OperationModeWaylandOnly || | ||
606 | kwinApp()->operationMode() == Application::OperationModeXwayland) { | 618 | kwinApp()->operationMode() == Application::OperationModeXwayland) { | ||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | |||||
665 | 677 | | |||
666 | void UserActionsMenu::desktopPopupAboutToShow() | 678 | void UserActionsMenu::desktopPopupAboutToShow() | ||
667 | { | 679 | { | ||
668 | if (!m_desktopMenu) | 680 | if (!m_desktopMenu) | ||
669 | return; | 681 | return; | ||
670 | const VirtualDesktopManager *vds = VirtualDesktopManager::self(); | 682 | const VirtualDesktopManager *vds = VirtualDesktopManager::self(); | ||
671 | 683 | | |||
672 | m_desktopMenu->clear(); | 684 | m_desktopMenu->clear(); | ||
673 | m_desktopMenu->setPalette(m_client.data()->palette()); | 685 | if (m_client) { | ||
686 | m_desktopMenu->setPalette(m_client->palette()); | ||||
687 | } | ||||
674 | QActionGroup *group = new QActionGroup(m_desktopMenu); | 688 | QActionGroup *group = new QActionGroup(m_desktopMenu); | ||
675 | QAction *action = m_desktopMenu->addAction(i18n("&All Desktops")); | 689 | QAction *action = m_desktopMenu->addAction(i18n("&All Desktops")); | ||
676 | action->setData(0); | 690 | action->setData(0); | ||
677 | action->setCheckable(true); | 691 | action->setCheckable(true); | ||
678 | group->addAction(action); | 692 | group->addAction(action); | ||
679 | 693 | | |||
680 | if (!m_client.isNull() && m_client.data()->isOnAllDesktops()) | 694 | if (m_client && m_client->isOnAllDesktops()) { | ||
681 | action->setChecked(true); | 695 | action->setChecked(true); | ||
696 | } | ||||
682 | m_desktopMenu->addSeparator(); | 697 | m_desktopMenu->addSeparator(); | ||
683 | 698 | | |||
684 | const uint BASE = 10; | 699 | const uint BASE = 10; | ||
685 | 700 | | |||
686 | for (uint i = 1; i <= vds->count(); ++i) { | 701 | for (uint i = 1; i <= vds->count(); ++i) { | ||
687 | QString basic_name(QStringLiteral("%1 %2")); | 702 | QString basic_name(QStringLiteral("%1 %2")); | ||
688 | if (i < BASE) { | 703 | if (i < BASE) { | ||
689 | basic_name.prepend(QLatin1Char('&')); | 704 | basic_name.prepend(QLatin1Char('&')); | ||
690 | } | 705 | } | ||
691 | action = m_desktopMenu->addAction(basic_name.arg(i).arg(vds->name(i).replace(QLatin1Char('&'), QStringLiteral("&&")))); | 706 | action = m_desktopMenu->addAction(basic_name.arg(i).arg(vds->name(i).replace(QLatin1Char('&'), QStringLiteral("&&")))); | ||
692 | action->setData(i); | 707 | action->setData(i); | ||
693 | action->setCheckable(true); | 708 | action->setCheckable(true); | ||
694 | group->addAction(action); | 709 | group->addAction(action); | ||
695 | 710 | | |||
696 | if (!m_client.isNull() && | 711 | if (m_client && !m_client->isOnAllDesktops() && m_client->isOnDesktop(i)) { | ||
697 | !m_client.data()->isOnAllDesktops() && m_client.data()->isOnDesktop(i)) | | |||
698 | action->setChecked(true); | 712 | action->setChecked(true); | ||
699 | } | 713 | } | ||
714 | } | ||||
700 | 715 | | |||
701 | m_desktopMenu->addSeparator(); | 716 | m_desktopMenu->addSeparator(); | ||
702 | action = m_desktopMenu->addAction(i18nc("Create a new desktop and move there the window", "&New Desktop")); | 717 | action = m_desktopMenu->addAction(i18nc("Create a new desktop and move there the window", "&New Desktop")); | ||
703 | action->setData(vds->count() + 1); | 718 | action->setData(vds->count() + 1); | ||
704 | 719 | | |||
705 | if (vds->count() >= vds->maximum()) | 720 | if (vds->count() >= vds->maximum()) | ||
706 | action->setEnabled(false); | 721 | action->setEnabled(false); | ||
707 | } | 722 | } | ||
708 | 723 | | |||
709 | void UserActionsMenu::multipleDesktopsPopupAboutToShow() | 724 | void UserActionsMenu::multipleDesktopsPopupAboutToShow() | ||
710 | { | 725 | { | ||
711 | if (!m_multipleDesktopsMenu) | 726 | if (!m_multipleDesktopsMenu) | ||
712 | return; | 727 | return; | ||
713 | const VirtualDesktopManager *vds = VirtualDesktopManager::self(); | 728 | const VirtualDesktopManager *vds = VirtualDesktopManager::self(); | ||
714 | 729 | | |||
715 | m_multipleDesktopsMenu->clear(); | 730 | m_multipleDesktopsMenu->clear(); | ||
716 | m_multipleDesktopsMenu->setPalette(m_client.data()->palette()); | 731 | if (m_client) { | ||
732 | m_multipleDesktopsMenu->setPalette(m_client->palette()); | ||||
733 | } | ||||
717 | QAction *action = m_multipleDesktopsMenu->addAction(i18n("&All Desktops")); | 734 | QAction *action = m_multipleDesktopsMenu->addAction(i18n("&All Desktops")); | ||
718 | action->setData(0); | 735 | action->setData(0); | ||
719 | action->setCheckable(true); | 736 | action->setCheckable(true); | ||
720 | QActionGroup *allDesktopsGroup = new QActionGroup(m_multipleDesktopsMenu); | 737 | QActionGroup *allDesktopsGroup = new QActionGroup(m_multipleDesktopsMenu); | ||
721 | allDesktopsGroup->addAction(action); | 738 | allDesktopsGroup->addAction(action); | ||
722 | 739 | | |||
723 | if (!m_client.isNull() && m_client.data()->isOnAllDesktops()) { | 740 | if (m_client && m_client->isOnAllDesktops()) { | ||
724 | action->setChecked(true); | 741 | action->setChecked(true); | ||
725 | } | 742 | } | ||
726 | m_multipleDesktopsMenu->addSeparator(); | 743 | m_multipleDesktopsMenu->addSeparator(); | ||
727 | 744 | | |||
728 | 745 | | |||
729 | const uint BASE = 10; | 746 | const uint BASE = 10; | ||
730 | 747 | | |||
731 | for (uint i = 1; i <= vds->count(); ++i) { | 748 | for (uint i = 1; i <= vds->count(); ++i) { | ||
732 | QString basic_name(QStringLiteral("%1 %2")); | 749 | QString basic_name(QStringLiteral("%1 %2")); | ||
733 | if (i < BASE) { | 750 | if (i < BASE) { | ||
734 | basic_name.prepend(QLatin1Char('&')); | 751 | basic_name.prepend(QLatin1Char('&')); | ||
735 | } | 752 | } | ||
736 | QWidgetAction *action = new QWidgetAction(m_multipleDesktopsMenu); | 753 | QWidgetAction *action = new QWidgetAction(m_multipleDesktopsMenu); | ||
737 | QCheckBox *box = new QCheckBox(basic_name.arg(i).arg(vds->name(i).replace(QLatin1Char('&'), QStringLiteral("&&"))), m_multipleDesktopsMenu); | 754 | QCheckBox *box = new QCheckBox(basic_name.arg(i).arg(vds->name(i).replace(QLatin1Char('&'), QStringLiteral("&&"))), m_multipleDesktopsMenu); | ||
738 | action->setDefaultWidget(box); | 755 | action->setDefaultWidget(box); | ||
739 | 756 | | |||
740 | box->setBackgroundRole(m_multipleDesktopsMenu->backgroundRole()); | 757 | box->setBackgroundRole(m_multipleDesktopsMenu->backgroundRole()); | ||
741 | box->setForegroundRole(m_multipleDesktopsMenu->foregroundRole()); | 758 | box->setForegroundRole(m_multipleDesktopsMenu->foregroundRole()); | ||
742 | box->setPalette(m_multipleDesktopsMenu->palette()); | 759 | box->setPalette(m_multipleDesktopsMenu->palette()); | ||
743 | connect(box, &QCheckBox::clicked, action, &QAction::triggered); | 760 | connect(box, &QCheckBox::clicked, action, &QAction::triggered); | ||
744 | m_multipleDesktopsMenu->addAction(action); | 761 | m_multipleDesktopsMenu->addAction(action); | ||
745 | action->setData(i); | 762 | action->setData(i); | ||
746 | 763 | | |||
747 | if (!m_client.isNull() && | 764 | if (m_client && !m_client->isOnAllDesktops() && m_client->isOnDesktop(i)) { | ||
748 | !m_client.data()->isOnAllDesktops() && m_client.data()->isOnDesktop(i)) { | | |||
749 | box->setChecked(true); | 765 | box->setChecked(true); | ||
750 | } | 766 | } | ||
751 | } | 767 | } | ||
752 | 768 | | |||
753 | m_multipleDesktopsMenu->addSeparator(); | 769 | m_multipleDesktopsMenu->addSeparator(); | ||
754 | action = m_multipleDesktopsMenu->addAction(i18nc("Create a new desktop and move there the window", "&New Desktop")); | 770 | action = m_multipleDesktopsMenu->addAction(i18nc("Create a new desktop and move there the window", "&New Desktop")); | ||
755 | action->setData(vds->count() + 1); | 771 | action->setData(vds->count() + 1); | ||
756 | 772 | | |||
757 | if (vds->count() >= vds->maximum()) | 773 | if (vds->count() >= vds->maximum()) | ||
758 | action->setEnabled(false); | 774 | action->setEnabled(false); | ||
759 | } | 775 | } | ||
760 | 776 | | |||
761 | void UserActionsMenu::screenPopupAboutToShow() | 777 | void UserActionsMenu::screenPopupAboutToShow() | ||
762 | { | 778 | { | ||
763 | if (!m_screenMenu) { | 779 | if (!m_screenMenu) { | ||
764 | return; | 780 | return; | ||
765 | } | 781 | } | ||
766 | | ||||
767 | m_screenMenu->clear(); | 782 | m_screenMenu->clear(); | ||
768 | m_screenMenu->setPalette(m_client.data()->palette()); | 783 | | ||
784 | if (!m_client) { | ||||
785 | return; | ||||
786 | } | ||||
787 | m_screenMenu->setPalette(m_client->palette()); | ||||
769 | QActionGroup *group = new QActionGroup(m_screenMenu); | 788 | QActionGroup *group = new QActionGroup(m_screenMenu); | ||
770 | 789 | | |||
771 | for (int i = 0; i<screens()->count(); ++i) { | 790 | for (int i = 0; i<screens()->count(); ++i) { | ||
772 | // assumption: there are not more than 9 screens attached. | 791 | // assumption: there are not more than 9 screens attached. | ||
773 | 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)", | 792 | 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)", | ||
774 | "Screen &%1 (%2)", (i+1), screens()->name(i))); | 793 | "Screen &%1 (%2)", (i+1), screens()->name(i))); | ||
775 | action->setData(i); | 794 | action->setData(i); | ||
776 | action->setCheckable(true); | 795 | action->setCheckable(true); | ||
777 | if (!m_client.isNull() && i == m_client.data()->screen()) { | 796 | if (m_client && i == m_client->screen()) { | ||
778 | action->setChecked(true); | 797 | action->setChecked(true); | ||
779 | } | 798 | } | ||
780 | group->addAction(action); | 799 | group->addAction(action); | ||
781 | } | 800 | } | ||
782 | } | 801 | } | ||
783 | 802 | | |||
784 | void UserActionsMenu::activityPopupAboutToShow() | 803 | void UserActionsMenu::activityPopupAboutToShow() | ||
785 | { | 804 | { | ||
786 | if (!m_activityMenu) | 805 | if (!m_activityMenu) | ||
787 | return; | 806 | return; | ||
788 | 807 | | |||
789 | #ifdef KWIN_BUILD_ACTIVITIES | 808 | #ifdef KWIN_BUILD_ACTIVITIES | ||
790 | if (!Activities::self()) { | 809 | if (!Activities::self()) { | ||
791 | return; | 810 | return; | ||
792 | } | 811 | } | ||
793 | m_activityMenu->clear(); | 812 | m_activityMenu->clear(); | ||
794 | m_activityMenu->setPalette(m_client.data()->palette()); | 813 | if (m_client) { | ||
814 | m_activityMenu->setPalette(m_client->palette()); | ||||
815 | } | ||||
795 | QAction *action = m_activityMenu->addAction(i18n("&All Activities")); | 816 | QAction *action = m_activityMenu->addAction(i18n("&All Activities")); | ||
796 | action->setData(QString()); | 817 | action->setData(QString()); | ||
797 | action->setCheckable(true); | 818 | action->setCheckable(true); | ||
798 | static QPointer<QActionGroup> allActivitiesGroup; | 819 | static QPointer<QActionGroup> allActivitiesGroup; | ||
799 | if (!allActivitiesGroup) { | 820 | if (!allActivitiesGroup) { | ||
800 | allActivitiesGroup = new QActionGroup(m_activityMenu); | 821 | allActivitiesGroup = new QActionGroup(m_activityMenu); | ||
801 | } | 822 | } | ||
802 | allActivitiesGroup->addAction(action); | 823 | allActivitiesGroup->addAction(action); | ||
803 | 824 | | |||
804 | if (!m_client.isNull() && m_client.data()->isOnAllActivities()) | 825 | if (m_client && m_client->isOnAllActivities()) { | ||
805 | action->setChecked(true); | 826 | action->setChecked(true); | ||
827 | } | ||||
806 | m_activityMenu->addSeparator(); | 828 | m_activityMenu->addSeparator(); | ||
807 | 829 | | |||
808 | foreach (const QString &id, Activities::self()->running()) { | 830 | foreach (const QString &id, Activities::self()->running()) { | ||
809 | KActivities::Info activity(id); | 831 | KActivities::Info activity(id); | ||
810 | QString name = activity.name(); | 832 | QString name = activity.name(); | ||
811 | name.replace('&', "&&"); | 833 | name.replace('&', "&&"); | ||
812 | QWidgetAction *action = new QWidgetAction(m_activityMenu); | 834 | QWidgetAction *action = new QWidgetAction(m_activityMenu); | ||
813 | QCheckBox *box = new QCheckBox(name, m_activityMenu); | 835 | QCheckBox *box = new QCheckBox(name, m_activityMenu); | ||
814 | action->setDefaultWidget(box); | 836 | action->setDefaultWidget(box); | ||
815 | const QString icon = activity.icon(); | 837 | const QString icon = activity.icon(); | ||
816 | if (!icon.isEmpty()) | 838 | if (!icon.isEmpty()) | ||
817 | box->setIcon(QIcon::fromTheme(icon)); | 839 | box->setIcon(QIcon::fromTheme(icon)); | ||
818 | box->setBackgroundRole(m_activityMenu->backgroundRole()); | 840 | box->setBackgroundRole(m_activityMenu->backgroundRole()); | ||
819 | box->setForegroundRole(m_activityMenu->foregroundRole()); | 841 | box->setForegroundRole(m_activityMenu->foregroundRole()); | ||
820 | box->setPalette(m_activityMenu->palette()); | 842 | box->setPalette(m_activityMenu->palette()); | ||
821 | connect(box, &QCheckBox::clicked, action, &QAction::triggered); | 843 | connect(box, &QCheckBox::clicked, action, &QAction::triggered); | ||
822 | m_activityMenu->addAction(action); | 844 | m_activityMenu->addAction(action); | ||
823 | action->setData(id); | 845 | action->setData(id); | ||
824 | 846 | | |||
825 | if (!m_client.isNull() && | 847 | if (m_client && !m_client->isOnAllActivities() && m_client->isOnActivity(id)) { | ||
826 | !m_client.data()->isOnAllActivities() && m_client.data()->isOnActivity(id)) | | |||
827 | box->setChecked(true); | 848 | box->setChecked(true); | ||
828 | } | 849 | } | ||
850 | } | ||||
829 | #endif | 851 | #endif | ||
830 | } | 852 | } | ||
831 | 853 | | |||
832 | void UserActionsMenu::slotWindowOperation(QAction *action) | 854 | void UserActionsMenu::slotWindowOperation(QAction *action) | ||
833 | { | 855 | { | ||
834 | if (!action->data().isValid()) | 856 | if (!action->data().isValid()) | ||
835 | return; | 857 | return; | ||
836 | 858 | | |||
Show All 33 Lines | 891 | if (!ok) { | |||
870 | return; | 892 | return; | ||
871 | } | 893 | } | ||
872 | if (m_client.isNull()) | 894 | if (m_client.isNull()) | ||
873 | return; | 895 | return; | ||
874 | Workspace *ws = Workspace::self(); | 896 | Workspace *ws = Workspace::self(); | ||
875 | VirtualDesktopManager *vds = VirtualDesktopManager::self(); | 897 | VirtualDesktopManager *vds = VirtualDesktopManager::self(); | ||
876 | if (desk == 0) { | 898 | if (desk == 0) { | ||
877 | // the 'on_all_desktops' menu entry | 899 | // the 'on_all_desktops' menu entry | ||
878 | m_client.data()->setOnAllDesktops(!m_client.data()->isOnAllDesktops()); | 900 | if (m_client) { | ||
901 | m_client->setOnAllDesktops(!m_client->isOnAllDesktops()); | ||||
902 | } | ||||
879 | return; | 903 | return; | ||
880 | } else if (desk > vds->count()) { | 904 | } else if (desk > vds->count()) { | ||
881 | vds->setCount(desk); | 905 | vds->setCount(desk); | ||
882 | } | 906 | } | ||
883 | 907 | | |||
884 | ws->sendClientToDesktop(m_client.data(), desk, false); | 908 | ws->sendClientToDesktop(m_client.data(), desk, false); | ||
885 | } | 909 | } | ||
886 | 910 | | |||
887 | void UserActionsMenu::slotToggleOnVirtualDesktop(QAction *action) | 911 | void UserActionsMenu::slotToggleOnVirtualDesktop(QAction *action) | ||
888 | { | 912 | { | ||
889 | bool ok = false; | 913 | bool ok = false; | ||
890 | uint desk = action->data().toUInt(&ok); | 914 | uint desk = action->data().toUInt(&ok); | ||
891 | if (!ok) { | 915 | if (!ok) { | ||
892 | return; | 916 | return; | ||
893 | } | 917 | } | ||
894 | if (m_client.isNull()) { | 918 | if (m_client.isNull()) { | ||
895 | return; | 919 | return; | ||
896 | } | 920 | } | ||
897 | 921 | | |||
898 | VirtualDesktopManager *vds = VirtualDesktopManager::self(); | 922 | VirtualDesktopManager *vds = VirtualDesktopManager::self(); | ||
899 | if (desk == 0) { | 923 | if (desk == 0) { | ||
900 | // the 'on_all_desktops' menu entry | 924 | // the 'on_all_desktops' menu entry | ||
901 | m_client.data()->setOnAllDesktops(!m_client.data()->isOnAllDesktops()); | 925 | m_client->setOnAllDesktops(!m_client->isOnAllDesktops()); | ||
902 | return; | 926 | return; | ||
903 | } else if (desk > vds->count()) { | 927 | } else if (desk > vds->count()) { | ||
904 | vds->setCount(desk); | 928 | vds->setCount(desk); | ||
905 | } | 929 | } | ||
906 | 930 | | |||
907 | VirtualDesktop *virtualDesktop = VirtualDesktopManager::self()->desktopForX11Id(desk); | 931 | VirtualDesktop *virtualDesktop = VirtualDesktopManager::self()->desktopForX11Id(desk); | ||
908 | if (m_client.data()->desktops().contains(virtualDesktop)) { | 932 | if (m_client->desktops().contains(virtualDesktop)) { | ||
909 | m_client.data()->leaveDesktop(virtualDesktop); | 933 | m_client->leaveDesktop(virtualDesktop); | ||
910 | } else { | 934 | } else { | ||
911 | m_client.data()->enterDesktop(virtualDesktop); | 935 | m_client->enterDesktop(virtualDesktop); | ||
912 | } | 936 | } | ||
913 | } | 937 | } | ||
914 | 938 | | |||
915 | void UserActionsMenu::slotSendToScreen(QAction *action) | 939 | void UserActionsMenu::slotSendToScreen(QAction *action) | ||
916 | { | 940 | { | ||
917 | const int screen = action->data().toInt(); | 941 | const int screen = action->data().toInt(); | ||
918 | if (m_client.isNull()) { | 942 | if (m_client.isNull()) { | ||
919 | return; | 943 | return; | ||
Show All 11 Lines | 954 | #ifdef KWIN_BUILD_ACTIVITIES | |||
931 | if (!Activities::self()) { | 955 | if (!Activities::self()) { | ||
932 | return; | 956 | return; | ||
933 | } | 957 | } | ||
934 | QString activity = action->data().toString(); | 958 | QString activity = action->data().toString(); | ||
935 | if (m_client.isNull()) | 959 | if (m_client.isNull()) | ||
936 | return; | 960 | return; | ||
937 | if (activity.isEmpty()) { | 961 | if (activity.isEmpty()) { | ||
938 | // the 'on_all_activities' menu entry | 962 | // the 'on_all_activities' menu entry | ||
939 | m_client.data()->setOnAllActivities(!m_client.data()->isOnAllActivities()); | 963 | m_client->setOnAllActivities(!m_client->isOnAllActivities()); | ||
940 | return; | 964 | return; | ||
941 | } | 965 | } | ||
942 | 966 | | |||
943 | Client *c = dynamic_cast<Client*>(m_client.data()); | 967 | Client *c = dynamic_cast<Client*>(m_client.data()); | ||
944 | if (!c) { | 968 | if (!c) { | ||
945 | return; | 969 | return; | ||
946 | } | 970 | } | ||
947 | 971 | | |||
948 | Activities::self()->toggleClientOnActivity(c, activity, false); | 972 | Activities::self()->toggleClientOnActivity(c, activity, false); | ||
949 | if (m_activityMenu && m_activityMenu->isVisible() && m_activityMenu->actions().count()) { | 973 | if (m_activityMenu && m_activityMenu->isVisible() && m_activityMenu->actions().count()) { | ||
950 | const bool isOnAll = m_client.data()->isOnAllActivities(); | 974 | const bool isOnAll = m_client->isOnAllActivities(); | ||
951 | m_activityMenu->actions().at(0)->setChecked(isOnAll); | 975 | m_activityMenu->actions().at(0)->setChecked(isOnAll); | ||
952 | if (isOnAll) { | 976 | if (isOnAll) { | ||
953 | // toggleClientOnActivity interprets "on all" as "on none" and | 977 | // toggleClientOnActivity interprets "on all" as "on none" and | ||
954 | // susequent toggling ("off") would move the client to only that activity. | 978 | // susequent toggling ("off") would move the client to only that activity. | ||
955 | // bug #330838 -> set all but "on all" off to "force proper usage" | 979 | // bug #330838 -> set all but "on all" off to "force proper usage" | ||
956 | for (int i = 1; i < m_activityMenu->actions().count(); ++i) { | 980 | for (int i = 1; i < m_activityMenu->actions().count(); ++i) { | ||
957 | if (QWidgetAction *qwa = qobject_cast<QWidgetAction*>(m_activityMenu->actions().at(i))) { | 981 | if (QWidgetAction *qwa = qobject_cast<QWidgetAction*>(m_activityMenu->actions().at(i))) { | ||
958 | if (QCheckBox *qcb = qobject_cast<QCheckBox*>(qwa->defaultWidget())) { | 982 | if (QCheckBox *qcb = qobject_cast<QCheckBox*>(qwa->defaultWidget())) { | ||
▲ Show 20 Lines • Show All 968 Lines • Show Last 20 Lines |
If we assert client in the beginning then cl must be non-null, right? Would make all the below checks on m_client superfluous as well though.