Client shortcuts ported to QKeySequence

Pretty straight forward, though not yet tested.
icc-effect-5.14.5
Martin Gräßlin 2013-09-06 10:31:38 +02:00
parent 1c8233ad6d
commit f4a96da547
3 changed files with 22 additions and 26 deletions

View File

@ -29,7 +29,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "toplevel.h" #include "toplevel.h"
#include "xcbutils.h" #include "xcbutils.h"
// KDE // KDE
#include <KDE/KShortcut>
#include <KDE/NETWinInfo> #include <KDE/NETWinInfo>
// Qt // Qt
#include <QPixmap> #include <QPixmap>
@ -461,7 +460,7 @@ public:
void shrinkVertical(); void shrinkVertical();
bool providesContextHelp() const; bool providesContextHelp() const;
KShortcut shortcut() const; const QKeySequence &shortcut() const;
void setShortcut(const QString& cut); void setShortcut(const QString& cut);
WindowOperation mouseButtonToWindowOperation(Qt::MouseButtons button); WindowOperation mouseButtonToWindowOperation(Qt::MouseButtons button);
@ -778,7 +777,7 @@ private:
void setCaption(const QString& s, bool force = false); void setCaption(const QString& s, bool force = false);
bool hasTransientInternal(const Client* c, bool indirect, ConstClientList& set) const; bool hasTransientInternal(const Client* c, bool indirect, ConstClientList& set) const;
void finishWindowRules(); void finishWindowRules();
void setShortcutInternal(const KShortcut& cut); void setShortcutInternal(const QKeySequence &cut = QKeySequence());
void configureRequest(int value_mask, int rx, int ry, int rw, int rh, int gravity, bool from_tool); void configureRequest(int value_mask, int rx, int ry, int rw, int rh, int gravity, bool from_tool);
NETExtendedStrut strut() const; NETExtendedStrut strut() const;
@ -962,7 +961,7 @@ private:
int padding_left, padding_right, padding_top, padding_bottom; int padding_left, padding_right, padding_top, padding_bottom;
QRegion _mask; QRegion _mask;
static bool check_active_modal; ///< \see Client::checkActiveModal() static bool check_active_modal; ///< \see Client::checkActiveModal()
KShortcut _shortcut; QKeySequence _shortcut;
int sm_stacking_order; int sm_stacking_order;
friend struct FetchNameInternalPredicate; friend struct FetchNameInternalPredicate;
friend struct ResetupRulesProcedure; friend struct ResetupRulesProcedure;
@ -1240,7 +1239,7 @@ inline xcb_window_t Client::moveResizeGrabWindow() const
return m_moveResizeGrabWindow; return m_moveResizeGrabWindow;
} }
inline KShortcut Client::shortcut() const inline const QKeySequence &Client::shortcut() const
{ {
return _shortcut; return _shortcut;
} }

View File

@ -985,7 +985,7 @@ void Workspace::setupWindowShortcut(Client* c)
//keys->setEnabled( false ); //keys->setEnabled( false );
//disable_shortcuts_keys->setEnabled( false ); //disable_shortcuts_keys->setEnabled( false );
//client_keys->setEnabled( false ); //client_keys->setEnabled( false );
client_keys_dialog = new ShortcutDialog(c->shortcut().primary()); client_keys_dialog = new ShortcutDialog(c->shortcut());
client_keys_client = c; client_keys_client = c;
connect(client_keys_dialog, SIGNAL(dialogDone(bool)), SLOT(setupWindowShortcutDone(bool))); connect(client_keys_dialog, SIGNAL(dialogDone(bool)), SLOT(setupWindowShortcutDone(bool)));
QRect r = clientArea(ScreenArea, c); QRect r = clientArea(ScreenArea, c);
@ -1007,7 +1007,7 @@ void Workspace::setupWindowShortcutDone(bool ok)
// disable_shortcuts_keys->setEnabled( true ); // disable_shortcuts_keys->setEnabled( true );
// client_keys->setEnabled( true ); // client_keys->setEnabled( true );
if (ok) if (ok)
client_keys_client->setShortcut(KShortcut(client_keys_dialog->shortcut()).toString()); client_keys_client->setShortcut(client_keys_dialog->shortcut().toString());
closeActivePopup(); closeActivePopup();
client_keys_dialog->deleteLater(); client_keys_dialog->deleteLater();
client_keys_dialog = NULL; client_keys_dialog = NULL;
@ -1029,7 +1029,7 @@ void Workspace::clientShortcutUpdated(Client* c)
// no autoloading, since it's configured explicitly here and is not meant to be reused // no autoloading, since it's configured explicitly here and is not meant to be reused
// (the key is the window id anyway, which is kind of random) // (the key is the window id anyway, which is kind of random)
KGlobalAccel::self()->setShortcut(action, QList<QKeySequence>() << c->shortcut().primary(), KGlobalAccel::self()->setShortcut(action, QList<QKeySequence>() << c->shortcut(),
KGlobalAccel::NoAutoloading); KGlobalAccel::NoAutoloading);
action->setEnabled(true); action->setEnabled(true);
} else { } else {
@ -1925,18 +1925,18 @@ void Client::setShortcut(const QString& _cut)
{ {
QString cut = rules()->checkShortcut(_cut); QString cut = rules()->checkShortcut(_cut);
if (cut.isEmpty()) if (cut.isEmpty())
return setShortcutInternal(KShortcut()); return setShortcutInternal();
// Format: // Format:
// base+(abcdef)<space>base+(abcdef) // base+(abcdef)<space>base+(abcdef)
// E.g. Alt+Ctrl+(ABCDEF);Meta+X,Meta+(ABCDEF) // E.g. Alt+Ctrl+(ABCDEF);Meta+X,Meta+(ABCDEF)
if (!cut.contains(QStringLiteral("(")) && !cut.contains(QStringLiteral(")")) && !cut.contains(QStringLiteral(" - "))) { if (!cut.contains(QStringLiteral("(")) && !cut.contains(QStringLiteral(")")) && !cut.contains(QStringLiteral(" - "))) {
if (workspace()->shortcutAvailable(KShortcut(cut), this)) if (workspace()->shortcutAvailable(cut, this))
setShortcutInternal(KShortcut(cut)); setShortcutInternal(QKeySequence(cut));
else else
setShortcutInternal(KShortcut()); setShortcutInternal();
return; return;
} }
QList< KShortcut > keys; QList< QKeySequence > keys;
QStringList groups = cut.split(QStringLiteral(" - ")); QStringList groups = cut.split(QStringLiteral(" - "));
for (QStringList::ConstIterator it = groups.constBegin(); for (QStringList::ConstIterator it = groups.constBegin();
it != groups.constEnd(); it != groups.constEnd();
@ -1948,25 +1948,25 @@ void Client::setShortcut(const QString& _cut)
for (int i = 0; for (int i = 0;
i < list.length(); i < list.length();
++i) { ++i) {
KShortcut c(base + list[ i ]); QKeySequence c(base + list[ i ]);
if (!c.isEmpty()) if (!c.isEmpty())
keys.append(c); keys.append(c);
} }
} else { } else {
// regexp doesn't match, so it should be a normal shortcut // regexp doesn't match, so it should be a normal shortcut
KShortcut c(*it); QKeySequence c(*it);
if (!c.isEmpty()) { if (!c.isEmpty()) {
keys.append(c); keys.append(c);
} }
} }
} }
for (QList< KShortcut >::ConstIterator it = keys.constBegin(); for (auto it = keys.constBegin();
it != keys.constEnd(); it != keys.constEnd();
++it) { ++it) {
if (_shortcut == *it) // current one is in the list if (_shortcut == *it) // current one is in the list
return; return;
} }
for (QList< KShortcut >::ConstIterator it = keys.constBegin(); for (auto it = keys.constBegin();
it != keys.constEnd(); it != keys.constEnd();
++it) { ++it) {
if (workspace()->shortcutAvailable(*it, this)) { if (workspace()->shortcutAvailable(*it, this)) {
@ -1974,10 +1974,10 @@ void Client::setShortcut(const QString& _cut)
return; return;
} }
} }
setShortcutInternal(KShortcut()); setShortcutInternal();
} }
void Client::setShortcutInternal(const KShortcut& cut) void Client::setShortcutInternal(const QKeySequence &cut)
{ {
if (_shortcut == cut) if (_shortcut == cut)
return; return;
@ -1998,13 +1998,11 @@ void Client::delayedSetShortcut()
workspace()->clientShortcutUpdated(this); workspace()->clientShortcutUpdated(this);
} }
bool Workspace::shortcutAvailable(const KShortcut& cut, Client* ignore) const bool Workspace::shortcutAvailable(const QKeySequence &cut, Client* ignore) const
{ {
Q_FOREACH (const QKeySequence &seq, cut.toList()) { if (!KGlobalAccel::getGlobalShortcutsByKey(cut).isEmpty()) {
if (!KGlobalAccel::getGlobalShortcutsByKey(seq).isEmpty()) { return false;
return false;
}
} }
for (ClientList::ConstIterator it = clients.constBegin(); for (ClientList::ConstIterator it = clients.constBegin();
it != clients.constEnd(); it != clients.constEnd();

View File

@ -39,7 +39,6 @@ class QStringList;
class KConfig; class KConfig;
class KConfigGroup; class KConfigGroup;
class KActionCollection; class KActionCollection;
class KShortcut;
class KStartupInfo; class KStartupInfo;
class KStartupInfoId; class KStartupInfoId;
class KStartupInfoData; class KStartupInfoData;
@ -268,7 +267,7 @@ public:
bool forcedGlobalMouseGrab() const; bool forcedGlobalMouseGrab() const;
void clientShortcutUpdated(Client* c); void clientShortcutUpdated(Client* c);
bool shortcutAvailable(const KShortcut& cut, Client* ignore = NULL) const; bool shortcutAvailable(const QKeySequence &cut, Client* ignore = NULL) const;
bool globalShortcutsDisabled() const; bool globalShortcutsDisabled() const;
void disableGlobalShortcutsForClient(bool disable); void disableGlobalShortcutsForClient(bool disable);