From kde-core-devel Wed Jan 30 17:57:07 2002 From: Ellis Whitehead Date: Wed, 30 Jan 2002 17:57:07 +0000 To: kde-core-devel Subject: PATCH: kshortcutdialog X-MARC-Message: https://marc.info/?l=kde-core-devel&m=101241342717340 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--------------Boundary-00=_VJJR7O59CMNV54MLERKJ" --------------Boundary-00=_VJJR7O59CMNV54MLERKJ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8bit This is a patch for the shortcut dialog to release the keyboard when the focus is moved to another program. That much works now, but when you press a key which has a conflicting shortcut, a dialog pops up telling you this, but it doesn't receive any keyboard input. I don't why yet, since releaseKeyboard() is called. Ciao, Ellis --------------Boundary-00=_VJJR7O59CMNV54MLERKJ Content-Type: text/x-diff; charset="us-ascii"; name="kdeui.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="kdeui.diff" Index: kshortcutdialog.cpp =================================================================== RCS file: /home/kde/kdelibs/kdeui/kshortcutdialog.cpp,v retrieving revision 1.4 diff -u -3 -d -p -b -B -r1.4 kshortcutdialog.cpp --- kshortcutdialog.cpp 2002/01/28 00:46:57 1.4 +++ kshortcutdialog.cpp 2002/01/30 17:48:13 @@ -53,6 +53,7 @@ KShortcutDialog::KShortcutDialog( const : KDialog( parent, name ), m_cut( cut ) { + m_bGrabKeyboardOnFocusIn = true; m_bKeyboardGrabbed = false; m_iSeq = 0; m_iKey = 0; @@ -65,8 +66,10 @@ KShortcutDialog::KShortcutDialog( const KShortcutDialog::~KShortcutDialog() { + if( m_bKeyboardGrabbed ) { + kdWarning(125) << "KShortcutDialog::~KShortcutDialog(): m_bKeyboardGrabbed still true." << endl; releaseKeyboard(); - //releaseMouse(); + } } void KShortcutDialog::initGUI() @@ -148,36 +151,11 @@ void KShortcutDialog::clearSeq( uint i ) m_peditSeq[i]->setSeq( KKeySequence::null() ); m_cut.setSeq( i, KKeySequence::null() ); selectSeq( i ); -} - -void KShortcutDialog::focusInEvent( QFocusEvent* ) -{ - kdDebug(125) << "KShortcutDialog::focusInEvent()" << endl; - setFocus(); - grabKeyboard(); - //grabMouse(); -} -void KShortcutDialog::focusOutEvent( QFocusEvent* ) -{ - kdDebug(125) << "KShortcutDialog::focusOutEvent()" << endl; - releaseKeyboard(); - //releaseMouse(); -} - -void KShortcutDialog::paintEvent( QPaintEvent* pEvent ) -{ - kdDebug(125) << "KShortcutDialog::paintEvent( QPaintEvent* )" << endl; - kdDebug(125) << "m_bKeyboardGrabbed = " << m_bKeyboardGrabbed << endl; - kdDebug(125) << "hasFocus() = " << hasFocus() << endl; - if( !m_bKeyboardGrabbed ) { - kdDebug(125) << "KShortcutDialog::2paintEvent( QPaintEvent* )" << endl; - m_bKeyboardGrabbed = true; - setFocus(); - grabKeyboard(); - //grabMouse(); - } - KDialog::paintEvent( pEvent ); + // If we're clearing the alternate, then we need to set m_cut.count() + // back to 1 if there is a primary sequence. + if( i == 1 && m_cut.count() > 0 ) + m_cut = m_cut.seq(0); } void KShortcutDialog::slotSeq0Selected() { selectSeq( 0 ); } @@ -185,6 +163,13 @@ void KShortcutDialog::slotSeq1Selected() void KShortcutDialog::slotClearSeq0() { clearSeq( 0 ); } void KShortcutDialog::slotClearSeq1() { clearSeq( 1 ); } +void KShortcutDialog::accept() +{ + kdDebug(125) << "KShortcutDialog::accept()" << endl; + m_bGrabKeyboardOnFocusIn = false; + KDialog::accept(); +} + #ifdef Q_WS_X11 bool KShortcutDialog::x11Event( XEvent *pEvent ) { @@ -195,6 +180,26 @@ bool KShortcutDialog::x11Event( XEvent * return true; case ButtonPress: m_iKey = 0; + break; + case XFocusIn: + kdDebug(125) << "FocusIn" << endl; + if( m_bGrabKeyboardOnFocusIn ) { + kdDebug(125) << "\tkeyboard grabbed." << endl; + m_bKeyboardGrabbed = true; + grabKeyboard(); + } + break; + case XFocusOut: + kdDebug(125) << "FocusOut" << endl; + if( m_bKeyboardGrabbed ) { + kdDebug(125) << "\tkeyboard released." << endl; + m_bKeyboardGrabbed = false; + releaseKeyboard(); + } + break; + default: + //kdDebug(125) << "x11Event->type = " << pEvent->type << endl; + break; } return QWidget::x11Event( pEvent ); } @@ -214,8 +219,9 @@ void KShortcutDialog::x11EventKeyPress( case XK_Shift_L: case XK_Shift_R: keyModX = KKeyNative::modX(KKey::SHIFT); break; case XK_Control_L: case XK_Control_R: keyModX = KKeyNative::modX(KKey::CTRL); break; case XK_Alt_L: case XK_Alt_R: keyModX = KKeyNative::modX(KKey::ALT); break; - case XK_Meta_L: case XK_Meta_R: keyModX = KKeyNative::modX(KKey::WIN); break; - case XK_Super_L: case XK_Super_R: + // FIXME: check whether the Meta or Super key are for the Win modifier + case XK_Meta_L: case XK_Meta_R: + case XK_Super_L: case XK_Super_R: keyModX = KKeyNative::modX(KKey::WIN); break; case XK_Hyper_L: case XK_Hyper_R: case XK_Mode_switch: break; @@ -224,8 +230,6 @@ void KShortcutDialog::x11EventKeyPress( // If RETURN was pressed and we are recording a // multi-key shortcut, then we are done. if( keyNative.sym() == XK_Return && m_iKey > 0 ) { - // HACK: releaseKeyboard should be called from accept() - releaseKeyboard(); accept(); return; } @@ -249,11 +253,9 @@ void KShortcutDialog::x11EventKeyPress( // key, and if so, call setShortcut(uint) with the new value. //emit capturedShortcut( KShortcut(KKey(keyNative)) ); kdDebug(125) << "m_cut = " << m_cut.toString() << endl; - if( m_pcbAutoClose->isEnabled() && m_pcbAutoClose->isChecked() ) { - releaseKeyboard(); + if( m_pcbAutoClose->isEnabled() && m_pcbAutoClose->isChecked() ) accept(); } - } return; } @@ -266,11 +268,10 @@ void KShortcutDialog::x11EventKeyPress( keyModX = pEvent->xkey.state & ~keyModX; QString keyModStr; - // FIXME: use KKey::modFlagLabel(KKey::xxx) - if( keyModX & KKeyNative::modX(KKey::WIN) ) keyModStr += i18n("Win") + "+"; - if( keyModX & KKeyNative::modX(KKey::ALT) ) keyModStr += i18n("Alt") + "+"; - if( keyModX & KKeyNative::modX(KKey::CTRL) ) keyModStr += i18n("Ctrl") + "+"; - if( keyModX & KKeyNative::modX(KKey::SHIFT) ) keyModStr += i18n("Shift") + "+"; + if( keyModX & KKeyNative::modX(KKey::WIN) ) keyModStr += KKey::modFlagLabel(KKey::WIN) + "+"; + if( keyModX & KKeyNative::modX(KKey::ALT) ) keyModStr += KKey::modFlagLabel(KKey::ALT) + "+"; + if( keyModX & KKeyNative::modX(KKey::CTRL) ) keyModStr += KKey::modFlagLabel(KKey::CTRL) + "+"; + if( keyModX & KKeyNative::modX(KKey::SHIFT) ) keyModStr += KKey::modFlagLabel(KKey::SHIFT) + "+"; // Display currently selected modifiers, or redisplay old key. if( !keyModStr.isEmpty() ) Index: kshortcutdialog.h =================================================================== RCS file: /home/kde/kdelibs/kdeui/kshortcutdialog.h,v retrieving revision 1.3 diff -u -3 -d -p -b -B -r1.3 kshortcutdialog.h --- kshortcutdialog.h 2002/01/19 03:35:49 1.3 +++ kshortcutdialog.h 2002/01/30 17:48:13 @@ -31,6 +31,7 @@ class KShortcutDialog : public KDialog const KShortcut& cut() const { return m_cut; } protected: + bool m_bGrabKeyboardOnFocusIn; bool m_bKeyboardGrabbed; KShortcut m_cut; QRadioButton* m_prbSeq[2]; @@ -45,15 +46,13 @@ class KShortcutDialog : public KDialog void selectSeq( uint ); void clearSeq( uint ); - virtual void focusInEvent( QFocusEvent* ); - virtual void focusOutEvent( QFocusEvent* ); - virtual void paintEvent( QPaintEvent* ); - protected slots: void slotSeq0Selected(); void slotSeq1Selected(); void slotClearSeq0(); void slotClearSeq1(); + + virtual void accept(); // override parent's accept() private: void initGUI(); --------------Boundary-00=_VJJR7O59CMNV54MLERKJ--