Move ShortcutDialog to useractions
It's only used from useractions.cpp which means that it's not the best fit in utils. We can see the problems with it given that it was in an ifdef and it included quite some headers into everything. REVIEW: 110189
This commit is contained in:
parent
22ecba3b7d
commit
4a28d000cf
8 changed files with 134 additions and 135 deletions
|
@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include "xcbutils.h"
|
||||
#include <kwinglobals.h>
|
||||
#include <QRect>
|
||||
#include <QWidget>
|
||||
|
||||
namespace Plasma {
|
||||
class FrameSvg;
|
||||
|
|
|
@ -30,6 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include "tabbox/tabboxhandler.h"
|
||||
|
||||
class KActionCollection;
|
||||
class KConfigGroup;
|
||||
class QKeyEvent;
|
||||
|
||||
namespace KWin
|
||||
|
|
|
@ -49,6 +49,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <KActivities/Info>
|
||||
#endif
|
||||
|
||||
#include <KDE/KKeySequenceWidget>
|
||||
#include <KDE/KProcess>
|
||||
#include <KDE/KToolInvocation>
|
||||
|
||||
|
@ -66,9 +67,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <KDE/KLocalizedString>
|
||||
#include <kconfig.h>
|
||||
#include <KDE/KGlobal>
|
||||
#include <KDE/KPushButton>
|
||||
#include <kglobalaccel.h>
|
||||
#include <kapplication.h>
|
||||
#include <QRegExp>
|
||||
#include <QLabel>
|
||||
#include <QMenu>
|
||||
#include <QVBoxLayout>
|
||||
#include <kauthorized.h>
|
||||
|
@ -822,6 +825,102 @@ void UserActionsMenu::slotToggleOnActivity(QAction *action)
|
|||
#endif
|
||||
}
|
||||
|
||||
//****************************************
|
||||
// ShortcutDialog
|
||||
//****************************************
|
||||
ShortcutDialog::ShortcutDialog(const QKeySequence& cut)
|
||||
: _shortcut(cut)
|
||||
{
|
||||
QWidget *vBoxContainer = new QWidget(this);
|
||||
vBoxContainer->setLayout(new QVBoxLayout(vBoxContainer));
|
||||
vBoxContainer->layout()->addWidget(widget = new KKeySequenceWidget(vBoxContainer));
|
||||
vBoxContainer->layout()->addWidget(warning = new QLabel(vBoxContainer));
|
||||
warning->hide();
|
||||
widget->setKeySequence(cut);
|
||||
|
||||
// To not check for conflicting shortcuts. The widget would use a message
|
||||
// box which brings down kwin.
|
||||
widget->setCheckForConflictsAgainst(KKeySequenceWidget::None);
|
||||
// It's a global shortcut so don't allow multikey shortcuts
|
||||
widget->setMultiKeyShortcutsAllowed(false);
|
||||
|
||||
// Listen to changed shortcuts
|
||||
connect(
|
||||
widget, SIGNAL(keySequenceChanged(QKeySequence)),
|
||||
SLOT(keySequenceChanged(QKeySequence)));
|
||||
|
||||
setMainWidget(vBoxContainer);
|
||||
widget->setFocus();
|
||||
|
||||
// make it a popup, so that it has the grab
|
||||
XSetWindowAttributes attrs;
|
||||
attrs.override_redirect = True;
|
||||
XChangeWindowAttributes(display(), winId(), CWOverrideRedirect, &attrs);
|
||||
setWindowFlags(Qt::Popup);
|
||||
}
|
||||
|
||||
void ShortcutDialog::accept()
|
||||
{
|
||||
QKeySequence seq = shortcut();
|
||||
if (!seq.isEmpty()) {
|
||||
if (seq[0] == Qt::Key_Escape) {
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
if (seq[0] == Qt::Key_Space
|
||||
|| (seq[0] & Qt::KeyboardModifierMask) == 0) {
|
||||
// clear
|
||||
widget->clearKeySequence();
|
||||
KDialog::accept();
|
||||
return;
|
||||
}
|
||||
}
|
||||
KDialog::accept();
|
||||
}
|
||||
|
||||
void ShortcutDialog::done(int r)
|
||||
{
|
||||
KDialog::done(r);
|
||||
emit dialogDone(r == Accepted);
|
||||
}
|
||||
|
||||
void ShortcutDialog::keySequenceChanged(const QKeySequence &seq)
|
||||
{
|
||||
activateWindow(); // where is the kbd focus lost? cause of popup state?
|
||||
if (_shortcut == seq)
|
||||
return; // don't try to update the same
|
||||
|
||||
if (seq.isEmpty()) { // clear
|
||||
_shortcut = seq;
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the key sequence is used currently
|
||||
QString sc = seq.toString();
|
||||
// NOTICE - seq.toString() & the entries in "conflicting" randomly get invalidated after the next call (if no sc has been set & conflicting isn't empty?!)
|
||||
QList<KGlobalShortcutInfo> conflicting = KGlobalAccel::getGlobalShortcutsByKey(seq);
|
||||
if (!conflicting.isEmpty()) {
|
||||
const KGlobalShortcutInfo &conflict = conflicting.at(0);
|
||||
warning->setText(i18nc("'%1' is a keyboard shortcut like 'ctrl+w'",
|
||||
"<b>%1</b> is already in use", sc));
|
||||
warning->setToolTip(i18nc("keyboard shortcut '%1' is used by action '%2' in application '%3'",
|
||||
"<b>%1</b> is used by %2 in %3", sc, conflict.friendlyName(), conflict.componentFriendlyName()));
|
||||
warning->show();
|
||||
widget->setKeySequence(shortcut());
|
||||
} else if (seq != _shortcut) {
|
||||
warning->hide();
|
||||
if (KPushButton *ok = button(KDialog::Ok))
|
||||
ok->setFocus();
|
||||
}
|
||||
|
||||
_shortcut = seq;
|
||||
}
|
||||
|
||||
QKeySequence ShortcutDialog::shortcut() const
|
||||
{
|
||||
return _shortcut;
|
||||
}
|
||||
|
||||
//****************************************
|
||||
// Workspace
|
||||
//****************************************
|
||||
|
|
|
@ -20,10 +20,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#ifndef KWIN_USERACTIONS_H
|
||||
#define KWIN_USERACTIONS_H
|
||||
|
||||
// KDE
|
||||
#include <KDE/KDialog>
|
||||
// Qt
|
||||
#include <QObject>
|
||||
#include <QWeakPointer>
|
||||
|
||||
class KKeySequenceWidget;
|
||||
class QAction;
|
||||
class QLabel;
|
||||
class QMenu;
|
||||
class QRect;
|
||||
|
||||
|
@ -254,6 +259,27 @@ private:
|
|||
**/
|
||||
QWeakPointer<Client> m_client;
|
||||
};
|
||||
|
||||
class ShortcutDialog
|
||||
: public KDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ShortcutDialog(const QKeySequence& cut);
|
||||
virtual void accept();
|
||||
QKeySequence shortcut() const;
|
||||
public Q_SLOTS:
|
||||
void keySequenceChanged(const QKeySequence &seq);
|
||||
signals:
|
||||
void dialogDone(bool ok);
|
||||
protected:
|
||||
virtual void done(int r);
|
||||
private:
|
||||
KKeySequenceWidget* widget;
|
||||
QKeySequence _shortcut;
|
||||
QLabel *warning;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // KWIN_USERACTIONS_H
|
||||
|
|
104
utils.cpp
104
utils.cpp
|
@ -29,23 +29,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
#include <kxerrorhandler.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <KDE/KLocalizedString>
|
||||
#include <KDE/KKeySequenceWidget>
|
||||
|
||||
#ifndef KCMRULES
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
#include <assert.h>
|
||||
#include <kdebug.h>
|
||||
#include <kglobalaccel.h>
|
||||
#include <kshortcut.h>
|
||||
#include <kkeyserver.h>
|
||||
#include <KPushButton>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/extensions/shape.h>
|
||||
#include <QX11Info>
|
||||
#include <QtGui/QKeySequence>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -407,102 +399,6 @@ Qt::KeyboardModifiers x11ToQtKeyboardModifiers(int state)
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef KCMRULES
|
||||
ShortcutDialog::ShortcutDialog(const QKeySequence& cut)
|
||||
: _shortcut(cut)
|
||||
{
|
||||
QWidget *vBoxContainer = new QWidget(this);
|
||||
vBoxContainer->setLayout(new QVBoxLayout(vBoxContainer));
|
||||
vBoxContainer->layout()->addWidget(widget = new KKeySequenceWidget(vBoxContainer));
|
||||
vBoxContainer->layout()->addWidget(warning = new QLabel(vBoxContainer));
|
||||
warning->hide();
|
||||
widget->setKeySequence(cut);
|
||||
|
||||
// To not check for conflicting shortcuts. The widget would use a message
|
||||
// box which brings down kwin.
|
||||
widget->setCheckForConflictsAgainst(KKeySequenceWidget::None);
|
||||
// It's a global shortcut so don't allow multikey shortcuts
|
||||
widget->setMultiKeyShortcutsAllowed(false);
|
||||
|
||||
// Listen to changed shortcuts
|
||||
connect(
|
||||
widget, SIGNAL(keySequenceChanged(QKeySequence)),
|
||||
SLOT(keySequenceChanged(QKeySequence)));
|
||||
|
||||
setMainWidget(vBoxContainer);
|
||||
widget->setFocus();
|
||||
|
||||
// make it a popup, so that it has the grab
|
||||
XSetWindowAttributes attrs;
|
||||
attrs.override_redirect = True;
|
||||
XChangeWindowAttributes(display(), winId(), CWOverrideRedirect, &attrs);
|
||||
setWindowFlags(Qt::Popup);
|
||||
}
|
||||
|
||||
void ShortcutDialog::accept()
|
||||
{
|
||||
QKeySequence seq = shortcut();
|
||||
if (!seq.isEmpty()) {
|
||||
if (seq[0] == Qt::Key_Escape) {
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
if (seq[0] == Qt::Key_Space
|
||||
|| (seq[0] & Qt::KeyboardModifierMask) == 0) {
|
||||
// clear
|
||||
widget->clearKeySequence();
|
||||
KDialog::accept();
|
||||
return;
|
||||
}
|
||||
}
|
||||
KDialog::accept();
|
||||
}
|
||||
|
||||
void ShortcutDialog::done(int r)
|
||||
{
|
||||
KDialog::done(r);
|
||||
emit dialogDone(r == Accepted);
|
||||
}
|
||||
|
||||
void ShortcutDialog::keySequenceChanged(const QKeySequence &seq)
|
||||
{
|
||||
activateWindow(); // where is the kbd focus lost? cause of popup state?
|
||||
if (_shortcut == seq)
|
||||
return; // don't try to update the same
|
||||
|
||||
if (seq.isEmpty()) { // clear
|
||||
_shortcut = seq;
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the key sequence is used currently
|
||||
QString sc = seq.toString();
|
||||
// NOTICE - seq.toString() & the entries in "conflicting" randomly get invalidated after the next call (if no sc has been set & conflicting isn't empty?!)
|
||||
QList<KGlobalShortcutInfo> conflicting = KGlobalAccel::getGlobalShortcutsByKey(seq);
|
||||
if (!conflicting.isEmpty()) {
|
||||
const KGlobalShortcutInfo &conflict = conflicting.at(0);
|
||||
warning->setText(i18nc("'%1' is a keyboard shortcut like 'ctrl+w'",
|
||||
"<b>%1</b> is already in use", sc));
|
||||
warning->setToolTip(i18nc("keyboard shortcut '%1' is used by action '%2' in application '%3'",
|
||||
"<b>%1</b> is used by %2 in %3", sc, conflict.friendlyName(), conflict.componentFriendlyName()));
|
||||
warning->show();
|
||||
widget->setKeySequence(shortcut());
|
||||
} else if (seq != _shortcut) {
|
||||
warning->hide();
|
||||
if (KPushButton *ok = button(KDialog::Ok))
|
||||
ok->setFocus();
|
||||
}
|
||||
|
||||
_shortcut = seq;
|
||||
}
|
||||
|
||||
QKeySequence ShortcutDialog::shortcut() const
|
||||
{
|
||||
return _shortcut;
|
||||
}
|
||||
|
||||
#endif //KCMRULES
|
||||
} // namespace
|
||||
|
||||
#ifndef KCMRULES
|
||||
|
|
35
utils.h
35
utils.h
|
@ -29,10 +29,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
// kwin
|
||||
#include <kwinglobals.h>
|
||||
// KDE
|
||||
#include <KDE/KDialog>
|
||||
#include <KDE/NET>
|
||||
#include <KDE/KSelectionWatcher>
|
||||
// Qt
|
||||
#include <QPoint>
|
||||
#include <QRect>
|
||||
#include <QScopedPointer>
|
||||
// X
|
||||
#include <X11/Xlib.h>
|
||||
|
@ -40,10 +41,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
// system
|
||||
#include <limits.h>
|
||||
|
||||
// forward declarations
|
||||
class KKeySequenceWidget;
|
||||
class QLabel;
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
|
@ -179,7 +176,7 @@ public:
|
|||
// property. If it explicitly requests that decorations be shown
|
||||
// or hidden, 'got_noborder' is set to true and 'noborder' is set
|
||||
// appropriately.
|
||||
static void readFlags(WId w, bool& got_noborder, bool& noborder,
|
||||
static void readFlags(Window w, bool& got_noborder, bool& noborder,
|
||||
bool& resize, bool& move, bool& minimize, bool& maximize,
|
||||
bool& close);
|
||||
struct MwmHints {
|
||||
|
@ -244,7 +241,7 @@ public:
|
|||
ScopedCPointer(T *p = 0) : QScopedPointer<T, QScopedPointerPodDeleter>(p) {}
|
||||
};
|
||||
|
||||
QByteArray getStringProperty(WId w, Atom prop, char separator = 0);
|
||||
QByteArray getStringProperty(Window w, Atom prop, char separator = 0);
|
||||
void updateXTime();
|
||||
void grabXServer();
|
||||
void ungrabXServer();
|
||||
|
@ -340,30 +337,6 @@ Qt::KeyboardModifiers x11ToQtKeyboardModifiers(int state);
|
|||
|
||||
void checkNonExistentClients();
|
||||
|
||||
#ifndef KCMRULES
|
||||
// Qt dialogs emit no signal when closed :(
|
||||
class ShortcutDialog
|
||||
: public KDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ShortcutDialog(const QKeySequence& cut);
|
||||
virtual void accept();
|
||||
QKeySequence shortcut() const;
|
||||
public Q_SLOTS:
|
||||
void keySequenceChanged(const QKeySequence &seq);
|
||||
signals:
|
||||
void dialogDone(bool ok);
|
||||
protected:
|
||||
virtual void done(int r);
|
||||
private:
|
||||
KKeySequenceWidget* widget;
|
||||
QKeySequence _shortcut;
|
||||
QLabel *warning;
|
||||
};
|
||||
|
||||
#endif //KCMRULES
|
||||
|
||||
} // namespace
|
||||
|
||||
// Must be outside namespace
|
||||
|
|
|
@ -53,6 +53,7 @@ class Client;
|
|||
class KillWindow;
|
||||
class RootInfo;
|
||||
class Rules;
|
||||
class ShortcutDialog;
|
||||
class UserActionsMenu;
|
||||
class WindowRules;
|
||||
class Compositor;
|
||||
|
|
|
@ -24,6 +24,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include "utils.h"
|
||||
|
||||
#include <QRect>
|
||||
#include <QRegion>
|
||||
#include <QVector>
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/composite.h>
|
||||
|
|
Loading…
Reference in a new issue