From d6df278f4924e99c19160112d868fd13841172d3 Mon Sep 17 00:00:00 2001 From: Michael Jansen Date: Sun, 21 Sep 2008 18:03:59 +0000 Subject: [PATCH] Use the new session shortcut feature for kwins "Window Shorcut" feature. @Lubos: Please have a look at commit 863096 too. I accidently commited a part of this part there. Please have a look at the todo "Add the window title" and possibly implement it. That would look much nicer in the global shortcuts kcm. Btw. There are two shortcuts dialogs in kwin. I haven't change the other one (kwinrules) because it look it works better with KKeySequenceWidget doing the message box. CCMAIL:l.lunak@kde.org svn path=/trunk/KDE/kdebase/workspace/; revision=863292 --- utils.cpp | 27 ++++++++++++++++++++++++++- utils.h | 3 +++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/utils.cpp b/utils.cpp index a983b37e43..9f57b9cf28 100644 --- a/utils.cpp +++ b/utils.cpp @@ -34,6 +34,7 @@ along with this program. If not, see . #include #include #include +#include #include #include @@ -41,6 +42,7 @@ along with this program. If not, see . #include #include #include +#include #include @@ -408,9 +410,21 @@ bool isLocalMachine( const QByteArray& host ) #ifndef KCMRULES ShortcutDialog::ShortcutDialog( const QKeySequence& cut ) : widget( new KKeySequenceWidget( this )) + ,_shortcut(cut) { widget->setKeySequence( cut ); + + // To not check for conflicting shortcuts. The widget would use a message + // box which brings down kwin. + widget->setCheckForConflictsAgainst(KKeySequenceWidget::None); + + // Listen to changed shortcuts + connect( + widget, SIGNAL(keySequenceChanged(const QKeySequence&)), + SLOT(keySequenceChanged(const QKeySequence&))); + setMainWidget( widget ); + // make it a popup, so that it has the grab XSetWindowAttributes attrs; attrs.override_redirect = True; @@ -445,9 +459,20 @@ void ShortcutDialog::done( int r ) emit dialogDone( r == Accepted ); } +void ShortcutDialog::keySequenceChanged(const QKeySequence &seq) + { + // Check if the key sequence is used currently + QStringList conflicting = KGlobalAccel::findActionNameSystemwide(seq); + if (!conflicting.isEmpty()) { + // TODO: Inform the user somehow instead of just ignoring his wish + widget->setKeySequence(shortcut()); + } + _shortcut = seq; + } + QKeySequence ShortcutDialog::shortcut() const { - return widget->keySequence(); + return _shortcut; } #endif //KCMRULES diff --git a/utils.h b/utils.h index 88dc38fbf4..8e0cdd9a8e 100644 --- a/utils.h +++ b/utils.h @@ -326,12 +326,15 @@ class ShortcutDialog 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; }; #endif //KCMRULES