Split the User Actions Menu out of Workspace

All methods and variables related to the User Actions Menu
(rmb window deco, Alt+F3) is moved out of the Workspace class
into an own UserActionsMenu class.

The class needs only a very small public interface containing
methods to show the menu for a Client, closing the menu and
discarding the menu. Everything else is actually private to the
implementation which is one of the reasons why it makes sense
to split the functionality out of the Workspace class.

As a result the methods and variables have more sane names and
the variable names are standardized.

REVIEW: 106085
BUG: 305832
FIXED-IN: 4.10
icc-effect-5.14.5
Martin Gräßlin 2012-08-19 12:00:53 +02:00
parent bb242d82c5
commit 46996d318e
7 changed files with 989 additions and 732 deletions

View File

@ -39,6 +39,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "atoms.h"
#include "group.h"
#include "rules.h"
#include "useractions.h"
#include <QX11Info>
namespace KWin
@ -228,6 +229,9 @@ void Workspace::setActiveClient(Client* c, allowed_t)
if (active_popup && active_popup_client != c && set_active_client_recursion == 0)
closeActivePopup();
if (m_userActionsMenu->hasClient() && !m_userActionsMenu->isMenuClient(c) && set_active_client_recursion == 0) {
m_userActionsMenu->close();
}
StackingUpdatesBlocker blocker(this);
++set_active_client_recursion;
updateFocusMousePosition(cursorPos());

View File

@ -52,6 +52,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "scene_xrender.h"
#include "scene_opengl.h"
#include "shadow.h"
#include "useractions.h"
#include "compositingprefs.h"
#include "notifications.h"
@ -192,7 +193,7 @@ void Workspace::slotCompositingOptionsInitialized()
c->setupCompositing();
foreach (Unmanaged * c, unmanaged)
c->setupCompositing();
discardPopup(); // force re-creation of the Alt+F3 popup (opacity option)
m_userActionsMenu->discard(); // force re-creation of the Alt+F3 popup (opacity option)
// render at least once
compositeTimer.stop();
@ -238,7 +239,7 @@ void Workspace::finishCompositing()
i.setOpacity(static_cast< unsigned long >((*it)->opacity() * 0xffffffff));
}
}
discardPopup(); // force re-creation of the Alt+F3 popup (opacity option)
m_userActionsMenu->discard(); // force re-creation of the Alt+F3 popup (opacity option)
// discard all Deleted windows (#152914)
while (!deleted.isEmpty())
deleted.first()->discard(Allowed);

View File

@ -37,6 +37,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "overlaywindow.h"
#include "rules.h"
#include "unmanaged.h"
#include "useractions.h"
#include "effects.h"
#include <QWhatsThis>
@ -879,7 +880,7 @@ void Client::enterNotifyEvent(XCrossingEvent* e)
}
#undef MOUSE_DRIVEN_FOCUS
if (options->focusPolicy() == Options::ClickToFocus || workspace()->windowMenuShown())
if (options->focusPolicy() == Options::ClickToFocus || workspace()->userActionsMenu()->isShown())
return;
if (options->isAutoRaise() && !isDesktop() &&

File diff suppressed because it is too large Load Diff

255
useractions.h Normal file
View File

@ -0,0 +1,255 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2012 Martin Gräßlin <mgraesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KWIN_USERACTIONS_H
#define KWIN_USERACTIONS_H
#include <QObject>
#include <QWeakPointer>
class QAction;
class QMenu;
class QRect;
namespace KWin
{
class Client;
/**
* @brief Menu shown for a Client.
*
* The UserActionsMenu implements the Menu which is shown on:
* @li context-menu event on Window decoration
* @li window menu button
* @li Keyboard Shortcut (by default Alt+F3)
*
* The menu contains various window management related actions for the Client the menu is opened
* for, this is normally the active Client.
*
* The menu which is shown is tried to be as close as possible to the menu implemented in
* libtaskmanager, though there are differences as there are some actions only the window manager
* can provide and on the other hand the libtaskmanager cares also about things like e.g. grouping.
*
* Whenever the menu is changed it should be tried to also adjust the menu in libtaskmanager.
*
* @author Martin Gräßlin <mgraesslin@kde.org>
**/
class UserActionsMenu : public QObject
{
Q_OBJECT
public:
explicit UserActionsMenu(QObject *parent = 0);
virtual ~UserActionsMenu();
/**
* Discards the constructed menu, so that it gets recreates
* on next show event.
* @see show
**/
void discard();
/**
* @returns Whether the menu is currently visible
**/
bool isShown() const;
/**
* @returns Whether the menu has a Client set to operate on.
**/
bool hasClient() const;
/**
* Checks whether the given Client @p c is the Client
* for which the Menu is shown.
* @param c The Client to compare
* @returns Whether the Client is the one related to this Menu
**/
bool isMenuClient(const Client *c) const;
/**
* Closes the Menu and prepares it for next usage.
**/
void close();
/**
* @brief Shows the menu at the given @p pos for the given @p client.
*
* @param pos The position where the menu should be shown.
* @param client The Client for which the Menu has to be shown.
**/
void show(const QRect &pos, const QWeakPointer<Client> &client);
public slots:
/**
* Delayed initialization of the activity menu.
*
* The call to retrieve the current list of activities is performed in a thread and this
* slot is invoked once the list has been fetched. Only task of this method is to decide
* whether to show the activity menu and to invoke the initialization of it.
*
* @see initActivityPopup
**/
void showHideActivityMenu();
private slots:
/**
* The menu will become visible soon.
*
* Adjust the items according to the respective Client.
**/
void menuAboutToShow();
/**
* Adjusts the add to tab group menu to the current value of the Client.
**/
void rebuildTabGroupPopup();
/**
* Adjusts the switch to tab menu to the current values of the Client.
**/
void rebuildTabListPopup();
/**
* Adds the Client as tab to the Client identified by the @p action.
*
* @param action The invoked action containing the Client to which the active Client should be tabbed.
**/
void entabPopupClient(QAction *action);
/**
* Activates the selected tabbed Client.
*
* @param action The invoked action containing the tabbed Client which should be activated.
**/
void selectPopupClientTab(QAction *action);
/**
* Adjusts the desktop popup to the current values and the location of
* the Client.
**/
void desktopPopupAboutToShow();
/**
* Adjusts the screen popup to the current values and the location of
* the Client.
**/
void screenPopupAboutToShow();
/**
* Adjusts the activity popup to the current values and the location of
* the Client.
**/
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
*
* @param action Invoked Action containing the Screen as data element
**/
void slotSendToScreen(QAction *action);
/**
* Toggles whether the Client is on the \a activity
*
* @param action Invoked Action containing the Id of the Activity to toggle the Client on
**/
void slotToggleOnActivity(QAction *action);
/**
* Performs a window operation.
*
* @param action Invoked Action containing the Window Operation to perform for the Client
**/
void slotWindowOperation(QAction *action);
/**
* Invokes the kcmshell with the Window Manager related config modules.
**/
void configureWM();
private:
/**
* Creates the menu if not already created.
**/
void init();
/**
* Creates the Move To Desktop sub-menu.
**/
void initDesktopPopup();
/**
* Creates the Move To Screen sub-menu.
**/
void initScreenPopup();
/**
* Creates activity popup.
* I'm going with checkable ones instead of "copy to" and "move to" menus; I *think* it's an easier way.
* Oh, and an 'all' option too of course
**/
void initActivityPopup();
/**
* Creates the Window Tabbing related menus.
**/
void initTabbingPopups();
/**
* Shows a helper Dialog to inform the user how to get back in case he triggered
* an action which hides the window decoration (e.g. NoBorder or Fullscreen).
* @param message The message type to be shown
* @param c The Client for which the dialog should be shown.
**/
void helperDialog(const QString &message, const QWeakPointer<Client> &c);
/**
* The actual main context menu which is show when the UserActionsMenu is invoked.
**/
QMenu* m_menu;
/**
* The move to desktop sub menu.
**/
QMenu* m_desktopMenu;
/**
* The move to screen sub menu.
**/
QMenu* m_screenMenu;
/**
* The activities sub menu.
**/
QMenu* m_activityMenu;
/**
* Menu to add the group to other group.
**/
QMenu* m_addTabsMenu;
/**
* Menu to change tab.
**/
QMenu* m_switchToTabMenu;
QAction* m_resizeOperation;
QAction* m_moveOperation;
QAction* m_maximizeOperation;
QAction* m_shadeOperation;
QAction* m_keepAboveOperation;
QAction* m_keepBelowOperation;
QAction* m_fullScreenOperation;
QAction* m_noBorderOperation;
QAction* m_minimizeOperation;
QAction* m_closeOperation;
/**
* Remove client from group.
**/
QAction* m_removeFromTabGroup;
/**
* Close all clients in the group.
**/
QAction* m_closeTabGroup;
/**
* The Client for which the menu is shown.
**/
QWeakPointer<Client> m_client;
};
} // namespace
#endif // KWIN_USERACTIONS_H

View File

@ -59,6 +59,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "deleted.h"
#include "effects.h"
#include "overlaywindow.h"
#include "useractions.h"
#include <kwinglplatform.h>
#include <kwinglutils.h>
#ifdef KWIN_BUILD_SCRIPTING
@ -71,8 +72,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <X11/cursorfont.h>
#include <QX11Info>
#include <stdio.h>
#include <kauthorized.h>
#include <ktoolinvocation.h>
#include <kglobalsettings.h>
#include <kwindowsystem.h>
#include <kwindowinfo.h>
@ -128,13 +127,7 @@ Workspace::Workspace(bool restore)
#ifdef KWIN_BUILD_TABBOX
, tab_box(0)
#endif
, popup(0)
, advanced_popup(0)
, desk_popup(0)
, screen_popup(NULL)
, activity_popup(0)
, add_tabs_popup(0)
, switch_to_tab_popup(0)
, m_userActionsMenu(new UserActionsMenu(this))
, keys(0)
, client_keys(NULL)
, disable_shortcuts_keys(NULL)
@ -520,7 +513,6 @@ Workspace::~Workspace()
for (UnmanagedList::iterator it = unmanaged.begin(), end = unmanaged.end(); it != end; ++it)
(*it)->release(true);
delete m_outline;
discardPopup();
XDeleteProperty(display(), rootWindow(), atoms->kwin_running);
writeWindowRules();
@ -632,6 +624,9 @@ void Workspace::removeClient(Client* c, allowed_t)
if (c == active_popup_client)
closeActivePopup();
if (m_userActionsMenu->isMenuClient(c)) {
m_userActionsMenu->close();
}
c->untab();
@ -932,7 +927,7 @@ void Workspace::slotSettingsChanged(int category)
{
kDebug(1212) << "Workspace::slotSettingsChanged()";
if (category == KGlobalSettings::SETTINGS_SHORTCUTS)
discardPopup();
m_userActionsMenu->discard();
}
/**
@ -957,7 +952,7 @@ void Workspace::slotReconfigure()
unsigned long changed = options->updateSettings();
emit configChanged();
discardPopup();
m_userActionsMenu->discard();
updateToolWindows(true);
if (hasDecorationPlugin() && mgr->reset(changed)) {
@ -1140,35 +1135,6 @@ void Workspace::saveDesktopSettings()
group.sync();
}
QStringList Workspace::configModules(bool controlCenter)
{
QStringList args;
args << "kwindecoration";
if (controlCenter)
args << "kwinoptions";
else if (KAuthorized::authorizeControlModule("kde-kwinoptions.desktop"))
args << "kwinactions" << "kwinfocus" << "kwinmoving" << "kwinadvanced"
<< "kwinrules" << "kwincompositing"
#ifdef KWIN_BUILD_TABBOX
<< "kwintabbox"
#endif
#ifdef KWIN_BUILD_SCREENEDGES
<< "kwinscreenedges"
#endif
#ifdef KWIN_BUILD_SCRIPTING
<< "kwinscripts"
#endif
;
return args;
}
void Workspace::configureWM()
{
QStringList args;
args << "--icon" << "preferences-system-windows" << configModules(false);
KToolInvocation::kdeinitExec("kcmshell4", args);
}
/**
* Avoids managing a window with title \a title
*/
@ -1429,19 +1395,23 @@ fetchActivityListAndCurrent(KActivities::Controller *controller)
return CurrentAndList(c, l);
}
void Workspace::updateActivityList(bool running, bool updateCurrent, QString slot)
void Workspace::updateActivityList(bool running, bool updateCurrent, QObject *target, QString slot)
{
if (updateCurrent) {
QFutureWatcher<CurrentAndList>* watcher = new QFutureWatcher<CurrentAndList>;
connect( watcher, SIGNAL(finished()), SLOT(handleActivityReply()) );
if (!slot.isEmpty())
if (!slot.isEmpty()) {
watcher->setProperty("activityControllerCallback", slot); // "activity reply trigger"
watcher->setProperty("activityControllerCallbackTarget", qVariantFromValue((void*)target));
}
watcher->setFuture(QtConcurrent::run(fetchActivityListAndCurrent, &activityController_ ));
} else {
QFutureWatcher<AssignedList>* watcher = new QFutureWatcher<AssignedList>;
connect(watcher, SIGNAL(finished()), SLOT(handleActivityReply()));
if (!slot.isEmpty())
if (!slot.isEmpty()) {
watcher->setProperty("activityControllerCallback", slot); // "activity reply trigger"
watcher->setProperty("activityControllerCallbackTarget", qVariantFromValue((void*)target));
}
QStringList *target = running ? &openActivities_ : &allActivities_;
watcher->setFuture(QtConcurrent::run(fetchActivityList, &activityController_, target, running));
}
@ -1465,9 +1435,10 @@ void Workspace::handleActivityReply()
if (watcherObject) {
QString slot = watcherObject->property("activityControllerCallback").toString();
QObject *target = static_cast<QObject*>(watcherObject->property("activityControllerCallbackTarget").value<void*>());
watcherObject->deleteLater(); // has done it's job
if (!slot.isEmpty())
QMetaObject::invokeMethod(this, slot.toAscii().data(), Qt::DirectConnection);
QMetaObject::invokeMethod(target, slot.toAscii().data(), Qt::DirectConnection);
}
}
//END threaded activity list fetching
@ -1971,49 +1942,6 @@ void Workspace::focusToNull()
XSetInputFocus(display(), null_focus_window, RevertToPointerRoot, xTime());
}
void Workspace::helperDialog(const QString& message, const Client* c)
{
QStringList args;
QString type;
if (message == "noborderaltf3") {
KAction* action = qobject_cast<KAction*>(keys->action("Window Operations Menu"));
assert(action != NULL);
QString shortcut = QString("%1 (%2)").arg(action->text())
.arg(action->globalShortcut().primary().toString(QKeySequence::NativeText));
args << "--msgbox" << i18n(
"You have selected to show a window without its border.\n"
"Without the border, you will not be able to enable the border "
"again using the mouse: use the window operations menu instead, "
"activated using the %1 keyboard shortcut.",
shortcut);
type = "altf3warning";
} else if (message == "fullscreenaltf3") {
KAction* action = qobject_cast<KAction*>(keys->action("Window Operations Menu"));
assert(action != NULL);
QString shortcut = QString("%1 (%2)").arg(action->text())
.arg(action->globalShortcut().primary().toString(QKeySequence::NativeText));
args << "--msgbox" << i18n(
"You have selected to show a window in fullscreen mode.\n"
"If the application itself does not have an option to turn the fullscreen "
"mode off you will not be able to disable it "
"again using the mouse: use the window operations menu instead, "
"activated using the %1 keyboard shortcut.",
shortcut);
type = "altf3warning";
} else
abort();
if (!type.isEmpty()) {
KConfig cfg("kwin_dialogsrc");
KConfigGroup cg(&cfg, "Notification Messages"); // Depends on KMessageBox
if (!cg.readEntry(type, true))
return;
args << "--dontagain" << "kwin_dialogsrc:" + type;
}
if (c != NULL)
args << "--embed" << QString::number(c->window());
KProcess::startDetached("kdialog", args);
}
void Workspace::setShowingDesktop(bool showing)
{
rootInfo->setShowingDesktop(showing);

View File

@ -78,6 +78,7 @@ class PluginMgr;
class Placement;
class Rules;
class Scripting;
class UserActionsMenu;
class WindowRules;
class Workspace : public QObject, public KDecorationDefines
@ -325,6 +326,12 @@ public:
QStringList activityList() const {
return allActivities_;
}
const QStringList &openActivities() const {
return openActivities_;
}
#ifdef KWIN_BUILD_ACTIVITIES
void updateActivityList(bool running, bool updateCurrent, QObject *target = NULL, QString slot = QString());
#endif
// True when performing Workspace::updateClientArea().
// The calls below are valid only in that case.
bool inUpdateClientArea() const;
@ -397,7 +404,9 @@ public:
*/
void showWindowMenu(int x, int y, Client* cl);
void showWindowMenu(QPoint pos, Client* cl);
bool windowMenuShown();
const UserActionsMenu *userActionsMenu() const {
return m_userActionsMenu;
}
void updateMinimizedOfTransients(Client*);
void updateOnAllDesktopsOfTransients(Client*);
@ -503,8 +512,6 @@ public:
int packPositionUp(const Client* cl, int oldy, bool top_edge) const;
int packPositionDown(const Client* cl, int oldy, bool bottom_edge) const;
static QStringList configModules(bool controlCenter);
void cancelDelayFocus();
void requestDelayFocus(Client*);
void updateFocusMousePosition(const QPoint& pos);
@ -628,19 +635,6 @@ public slots:
void slotUntab(); // Slot to remove the active client from its group.
private slots:
void rebuildTabGroupPopup();
void rebuildTabListPopup();
void entabPopupClient(QAction*);
void selectPopupClientTab(QAction*);
void desktopPopupAboutToShow();
void screenPopupAboutToShow();
void activityPopupAboutToShow();
void clientPopupAboutToShow();
void slotSendToDesktop(QAction*);
void slotSendToScreen(QAction*);
void slotToggleOnActivity(QAction*);
void clientPopupActivated(QAction*);
void configureWM();
void desktopResized();
void screenChangeTimeout();
void slotUpdateToolWindows();
@ -667,7 +661,6 @@ private slots:
void slotActivityAdded(const QString &activity);
void reallyStopActivity(const QString &id); //dbus deadlocks suck
void handleActivityReply();
void showHideActivityMenu();
protected:
void timerEvent(QTimerEvent *te);
@ -717,17 +710,9 @@ signals:
private:
void init();
void initShortcuts();
void initDesktopPopup();
void initScreenPopup();
void initActivityPopup();
void initTabbingPopups();
void restartKWin(const QString &reason);
void discardPopup();
void setupWindowShortcut(Client* c);
void checkCursorPos();
#ifdef KWIN_BUILD_ACTIVITIES
void updateActivityList(bool running, bool updateCurrent, QString slot = QString());
#endif
enum Direction {
DirectionNorth,
DirectionEast,
@ -765,9 +750,6 @@ private:
//---------------------------------------------------------------------
void helperDialog(const QString& message, const Client* c);
QMenu* clientPopup();
void closeActivePopup();
void updateClientArea(bool force);
@ -843,31 +825,17 @@ private:
TabBox::TabBox* tab_box;
#endif
QMenu* popup;
QMenu* advanced_popup;
QMenu* desk_popup;
QMenu* screen_popup;
QMenu* activity_popup;
QMenu* add_tabs_popup; // Menu to add the group to other group
QMenu* switch_to_tab_popup; // Menu to change tab
/**
* Holds the menu containing the user actions which is shown
* on e.g. right click the window decoration.
**/
UserActionsMenu *m_userActionsMenu;
void modalActionsSwitch(bool enabled);
KActionCollection* keys;
KActionCollection* client_keys;
KActionCollection* disable_shortcuts_keys;
QAction* mResizeOpAction;
QAction* mMoveOpAction;
QAction* mMaximizeOpAction;
QAction* mShadeOpAction;
QAction* mKeepAboveOpAction;
QAction* mKeepBelowOpAction;
QAction* mFullScreenOpAction;
QAction* mNoBorderOpAction;
QAction* mMinimizeOpAction;
QAction* mCloseOpAction;
QAction* mRemoveFromTabGroup; // Remove client from group
QAction* mCloseTabGroup; // Close all clients in the group
ShortcutDialog* client_keys_dialog;
Client* client_keys_client;
bool global_shortcuts_disabled;
@ -1068,11 +1036,6 @@ inline void Workspace::showWindowMenu(int x, int y, Client* cl)
showWindowMenu(QRect(QPoint(x, y), QPoint(x, y)), cl);
}
inline bool Workspace::windowMenuShown()
{
return popup && ((QWidget*)popup)->isVisible();
}
inline void Workspace::setWasUserInteraction()
{
was_user_interaction = true;