Port X11 desktop user actions menu to VirtualDesktop

It's mostly identical to the virtual desktop user actions menu on
Wayland.
This commit is contained in:
Vlad Zahorodnii 2021-08-17 09:42:09 +03:00
parent d5c2518973
commit 7937aa78ef
2 changed files with 31 additions and 41 deletions

View file

@ -455,7 +455,6 @@ void UserActionsMenu::initDesktopPopup()
return; return;
m_desktopMenu = new QMenu(m_menu); m_desktopMenu = new QMenu(m_menu);
connect(m_desktopMenu, &QMenu::triggered, this, &UserActionsMenu::slotSendToDesktop);
connect(m_desktopMenu, &QMenu::aboutToShow, this, &UserActionsMenu::desktopPopupAboutToShow); connect(m_desktopMenu, &QMenu::aboutToShow, this, &UserActionsMenu::desktopPopupAboutToShow);
QAction *action = m_desktopMenu->menuAction(); QAction *action = m_desktopMenu->menuAction();
@ -511,8 +510,15 @@ void UserActionsMenu::desktopPopupAboutToShow()
} }
QActionGroup *group = new QActionGroup(m_desktopMenu); QActionGroup *group = new QActionGroup(m_desktopMenu);
QAction *action = m_desktopMenu->addAction(i18n("&All Desktops")); QAction *action = m_desktopMenu->addAction(i18n("&All Desktops"));
action->setData(0); connect(action, &QAction::triggered, this, [this]() {
if (m_client) {
m_client->setOnAllDesktops(!m_client->isOnAllDesktops());
}
});
action->setCheckable(true); action->setCheckable(true);
if (m_client && m_client->isOnAllDesktops()) {
action->setChecked(true);
}
group->addAction(action); group->addAction(action);
if (m_client && m_client->isOnAllDesktops()) { if (m_client && m_client->isOnAllDesktops()) {
@ -522,27 +528,41 @@ void UserActionsMenu::desktopPopupAboutToShow()
const uint BASE = 10; const uint BASE = 10;
for (uint i = 1; i <= vds->count(); ++i) { const auto desktops = vds->desktops();
for (VirtualDesktop *desktop : desktops) {
const uint legacyId = desktop->x11DesktopNumber();
QString basic_name(QStringLiteral("%1 %2")); QString basic_name(QStringLiteral("%1 %2"));
if (i < BASE) { if (legacyId < BASE) {
basic_name.prepend(QLatin1Char('&')); basic_name.prepend(QLatin1Char('&'));
} }
action = m_desktopMenu->addAction(basic_name.arg(i).arg(vds->name(i).replace(QLatin1Char('&'), QStringLiteral("&&")))); action = m_desktopMenu->addAction(basic_name.arg(legacyId).arg(desktop->name().replace(QLatin1Char('&'), QStringLiteral("&&"))));
action->setData(i); connect(action, &QAction::triggered, this, [this, desktop]() {
if (m_client) {
workspace()->sendClientToDesktop(m_client, desktop->x11DesktopNumber(), false);
}
});
action->setCheckable(true); action->setCheckable(true);
group->addAction(action); group->addAction(action);
if (m_client && !m_client->isOnAllDesktops() && m_client->isOnDesktop(i)) { if (m_client && !m_client->isOnAllDesktops() && m_client->isOnDesktop(desktop)) {
action->setChecked(true); action->setChecked(true);
} }
} }
m_desktopMenu->addSeparator(); m_desktopMenu->addSeparator();
action = m_desktopMenu->addAction(i18nc("Create a new desktop and move the window there", "&New Desktop")); action = m_desktopMenu->addAction(i18nc("Create a new desktop and move the window there", "&New Desktop"));
action->setData(vds->count() + 1); connect(action, &QAction::triggered, this, [this]() {
if (!m_client) {
if (vds->count() >= vds->maximum()) return;
action->setEnabled(false); }
VirtualDesktopManager *vds = VirtualDesktopManager::self();
VirtualDesktop *desktop = vds->createVirtualDesktop(vds->count());
if (desktop) {
workspace()->sendClientToDesktop(m_client, desktop->x11DesktopNumber(), false);
}
});
action->setEnabled(vds->count() < vds->maximum());
} }
void UserActionsMenu::multipleDesktopsPopupAboutToShow() void UserActionsMenu::multipleDesktopsPopupAboutToShow()
@ -748,30 +768,6 @@ void UserActionsMenu::slotWindowOperation(QAction *action)
Q_ARG(Options::WindowOperation, op)); Q_ARG(Options::WindowOperation, op));
} }
void UserActionsMenu::slotSendToDesktop(QAction *action)
{
bool ok = false;
uint desk = action->data().toUInt(&ok);
if (!ok) {
return;
}
if (m_client.isNull())
return;
Workspace *ws = Workspace::self();
VirtualDesktopManager *vds = VirtualDesktopManager::self();
if (desk == 0) {
// the 'on_all_desktops' menu entry
if (m_client) {
m_client->setOnAllDesktops(!m_client->isOnAllDesktops());
}
return;
} else if (desk > vds->count()) {
vds->setCount(desk);
}
ws->sendClientToDesktop(m_client.data(), desk, false);
}
void UserActionsMenu::slotSendToScreen(QAction *action) void UserActionsMenu::slotSendToScreen(QAction *action)
{ {
const int screen = action->data().toInt(); const int screen = action->data().toInt();

View file

@ -128,12 +128,6 @@ private Q_SLOTS:
* the Client. * the Client.
*/ */
void activityPopupAboutToShow(); void activityPopupAboutToShow();
/**
* Sends the client to desktop \a desk
*
* @param action Invoked Action containing the Desktop as data element
*/
void slotSendToDesktop(QAction *action);
/** /**
* Sends the Client to screen \a screen * Sends the Client to screen \a screen
* *