diff options
author | Maxim Monastirsky <momonasmon@gmail.com> | 2017-05-05 01:30:30 +0300 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2017-05-25 21:42:02 +0200 |
commit | 30c17a288b03656633b626f6e7f679ca7c1aa6ff (patch) | |
tree | 63e4f34dae2459aaaf34a0cda4fa82367bcd5659 | |
parent | f750372ac81cb51177cd6cbda39ecacd5f821590 (diff) |
tdf#103158 ctrl+shift should work on key up
Under gtk/gtk3 we send CommandEventId::ModKeyChange on
key down, to support the auto-accelerator feature. But
at least the handler in SwEditWin::Command must get it
on key up, in order to not interfere with other
ctrl+shift+X shortcuts, which work on key down.
To achieve that, we need:
- On key up pass the key that was just released, instead
of the current state of nothing being pressed.
- Have a flag of whether it's a key down or up event, so
it can be checked by the application code.
Reviewed-on: https://gerrit.libreoffice.org/37275
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Maxim Monastirsky <momonasmon@gmail.com>
(cherry picked from commit fe0451259d2fb93c809c1bfa3baf5abd90019c58)
Conflicts:
include/vcl/commandevent.hxx
vcl/source/window/commandevent.cxx
vcl/unx/generic/window/salframe.cxx
vcl/unx/gtk/gtksalframe.cxx
vcl/unx/gtk3/gtk3gtkframe.cxx
Change-Id: If188d6ccdc3b214a2c3ed20aad291d74d46b358f
Reviewed-on: https://gerrit.libreoffice.org/37516
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | include/vcl/commandevent.hxx | 4 | ||||
-rw-r--r-- | sw/source/uibase/docvw/edtwin.cxx | 2 | ||||
-rw-r--r-- | vcl/inc/salwtype.hxx | 1 | ||||
-rw-r--r-- | vcl/inc/unx/gtk/gtkframe.hxx | 1 | ||||
-rw-r--r-- | vcl/source/window/commandevent.cxx | 3 | ||||
-rw-r--r-- | vcl/source/window/menu.cxx | 2 | ||||
-rw-r--r-- | vcl/source/window/syswin.cxx | 2 | ||||
-rw-r--r-- | vcl/source/window/winproc.cxx | 2 | ||||
-rw-r--r-- | vcl/unx/generic/window/salframe.cxx | 1 | ||||
-rw-r--r-- | vcl/unx/gtk/gtksalframe.cxx | 32 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkframe.cxx | 32 | ||||
-rw-r--r-- | vcl/win/window/salframe.cxx | 1 |
12 files changed, 30 insertions, 53 deletions
diff --git a/include/vcl/commandevent.hxx b/include/vcl/commandevent.hxx index 371fd54716d9..adaa8ad953bb 100644 --- a/include/vcl/commandevent.hxx +++ b/include/vcl/commandevent.hxx @@ -187,11 +187,13 @@ public: class VCL_DLLPUBLIC CommandModKeyData { private: + bool mbDown; sal_uInt16 mnCode; public: - CommandModKeyData( sal_uInt16 nCode ); + CommandModKeyData( sal_uInt16 nCode, bool bDown ); + bool IsDown() const { return mbDown; } bool IsMod1() const { return (mnCode & MODKEY_MOD1) != 0; } bool IsMod2() const { return (mnCode & MODKEY_MOD2) != 0; } bool IsLeftShift() const { return (mnCode & MODKEY_LSHIFT) != 0; } diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx index e8665d2466a7..4d104ed84567 100644 --- a/sw/source/uibase/docvw/edtwin.cxx +++ b/sw/source/uibase/docvw/edtwin.cxx @@ -5523,7 +5523,7 @@ void SwEditWin::Command( const CommandEvent& rCEvt ) case CommandEventId::ModKeyChange : { const CommandModKeyData* pCommandData = rCEvt.GetModKeyData(); - if (pCommandData->IsMod1() && !pCommandData->IsMod2()) + if (!pCommandData->IsDown() && pCommandData->IsMod1() && !pCommandData->IsMod2()) { sal_uInt16 nSlot = 0; if(pCommandData->IsLeftShift() && !pCommandData->IsRightShift()) diff --git a/vcl/inc/salwtype.hxx b/vcl/inc/salwtype.hxx index c25ca80909dc..a52d887e6cdc 100644 --- a/vcl/inc/salwtype.hxx +++ b/vcl/inc/salwtype.hxx @@ -121,6 +121,7 @@ struct SalMenuEvent // KEYMODCHANGE struct SalKeyModEvent { + bool mbDown; // Whether the change occurred on a key down event sal_uInt64 mnTime; // Time in ms, when event is created sal_uInt16 mnCode; // SV-Modifiercode (KEY_SHIFT|KEY_MOD1|KEY_MOD2) sal_uInt16 mnModKeyCode; // extended Modifier (MODKEY_LEFT,MODKEY_RIGHT,MODKEY_PRESS,MODKEY_RELEASE) diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx index fcb4498512d9..f2631604606f 100644 --- a/vcl/inc/unx/gtk/gtkframe.hxx +++ b/vcl/inc/unx/gtk/gtkframe.hxx @@ -197,7 +197,6 @@ class GtkSalFrame : public SalFrame bool m_bSpanMonitorsWhenFullscreen; bool m_bDefaultPos; bool m_bDefaultSize; - bool m_bSendModChangeOnRelease; bool m_bWindowIsGtkPlug; OUString m_aTitle; OUString m_sWMClass; diff --git a/vcl/source/window/commandevent.cxx b/vcl/source/window/commandevent.cxx index 8ef928f3a571..a07086a3e8cb 100644 --- a/vcl/source/window/commandevent.cxx +++ b/vcl/source/window/commandevent.cxx @@ -100,8 +100,9 @@ CommandScrollData::CommandScrollData( long nDeltaX, long nDeltaY ) mnDeltaY = nDeltaY; } -CommandModKeyData::CommandModKeyData( sal_uInt16 nCode ) +CommandModKeyData::CommandModKeyData( sal_uInt16 nCode, bool bDown ) { + mbDown = bDown; mnCode = nCode; } diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx index 012131f33962..592c69765388 100644 --- a/vcl/source/window/menu.cxx +++ b/vcl/source/window/menu.cxx @@ -2568,7 +2568,7 @@ bool MenuBar::ImplHandleCmdEvent( const CommandEvent& rCEvent ) const CommandModKeyData* pCData = rCEvent.GetModKeyData (); if (pWin->nHighlightedItem == ITEMPOS_INVALID) { - if (pCData && pCData->IsMod2()) + if (pCData && pCData->IsMod2() && pCData->IsDown()) pWin->SetMBWHideAccel(false); else pWin->SetMBWHideAccel(true); diff --git a/vcl/source/window/syswin.cxx b/vcl/source/window/syswin.cxx index f31dff20abf4..d4a2bfac521c 100644 --- a/vcl/source/window/syswin.cxx +++ b/vcl/source/window/syswin.cxx @@ -167,7 +167,7 @@ bool Accelerator::ToggleMnemonicsOnHierarchy(const CommandEvent& rCEvent, vcl::W if (rCEvent.GetCommand() == CommandEventId::ModKeyChange && ImplGetSVData()->maNWFData.mbAutoAccel) { const CommandModKeyData *pCData = rCEvent.GetModKeyData(); - const bool bShowAccel = pCData && pCData->IsMod2(); + const bool bShowAccel = pCData && pCData->IsMod2() && pCData->IsDown(); processChildren(pWindow, bShowAccel); return true; } diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx index 8defcd3614ea..3133990e158f 100644 --- a/vcl/source/window/winproc.cxx +++ b/vcl/source/window/winproc.cxx @@ -2102,7 +2102,7 @@ static void ImplHandleSalKeyMod( vcl::Window* pWindow, SalKeyModEvent* pEvent ) if ( !pChild ) return; - CommandModKeyData data( pEvent->mnModKeyCode ); + CommandModKeyData data( pEvent->mnModKeyCode, pEvent->mbDown ); ImplCallCommand( pChild, CommandEventId::ModKeyChange, &data ); } diff --git a/vcl/unx/generic/window/salframe.cxx b/vcl/unx/generic/window/salframe.cxx index f71eecf239ea..6b2a3e543600 100644 --- a/vcl/unx/generic/window/salframe.cxx +++ b/vcl/unx/generic/window/salframe.cxx @@ -3044,6 +3044,7 @@ long X11SalFrame::HandleKeyEvent( XKeyEvent *pEvent ) || nKeySym == XK_Super_L || nKeySym == XK_Super_R ) { SalKeyModEvent aModEvt; + aModEvt.mbDown = false; // auto-accelerator feature not supported here aModEvt.mnModKeyCode = 0; if( pEvent->type == KeyPress && mnExtKeyMod == 0 ) mbSendExtKeyModChange = true; diff --git a/vcl/unx/gtk/gtksalframe.cxx b/vcl/unx/gtk/gtksalframe.cxx index 2bb6718725dc..1e28c041ea47 100644 --- a/vcl/unx/gtk/gtksalframe.cxx +++ b/vcl/unx/gtk/gtksalframe.cxx @@ -968,7 +968,6 @@ void GtkSalFrame::InitCommon() m_bSpanMonitorsWhenFullscreen = false; m_nState = GDK_WINDOW_STATE_WITHDRAWN; m_nVisibility = GDK_VISIBILITY_FULLY_OBSCURED; - m_bSendModChangeOnRelease = false; m_pIMHandler = nullptr; m_nExtStyle = 0; m_pRegion = nullptr; @@ -2985,10 +2984,7 @@ gboolean GtkSalFrame::signalFocus( GtkWidget*, GdkEventFocus* pEvent, gpointer f pSalInstance->updatePrinterUpdate(); if( !pEvent->in ) - { pThis->m_nKeyModifiers = 0; - pThis->m_bSendModChangeOnRelease = false; - } if( pThis->m_pIMHandler ) pThis->m_pIMHandler->focusChanged( pEvent->in ); @@ -3101,20 +3097,7 @@ gboolean GtkSalFrame::signalKey( GtkWidget*, GdkEventKey* pEvent, gpointer frame pEvent->keyval == GDK_KEY_Meta_L || pEvent->keyval == GDK_KEY_Meta_R || pEvent->keyval == GDK_KEY_Super_L || pEvent->keyval == GDK_KEY_Super_R ) { - SalKeyModEvent aModEvt; - sal_uInt16 nModCode = GetKeyModCode( pEvent->state ); - - aModEvt.mnModKeyCode = 0; // emit no MODKEYCHANGE events - if( pEvent->type == GDK_KEY_PRESS && !pThis->m_nKeyModifiers ) - pThis->m_bSendModChangeOnRelease = true; - - else if( pEvent->type == GDK_KEY_RELEASE && - pThis->m_bSendModChangeOnRelease ) - { - aModEvt.mnModKeyCode = pThis->m_nKeyModifiers; - } - sal_uInt16 nExtModMask = 0; sal_uInt16 nModMask = 0; // pressing just the ctrl key leads to a keysym of XK_Control but @@ -3160,8 +3143,15 @@ gboolean GtkSalFrame::signalKey( GtkWidget*, GdkEventKey* pEvent, gpointer frame nModMask = KEY_MOD3; break; } + + SalKeyModEvent aModEvt; + aModEvt.mbDown = pEvent->type == GDK_KEY_PRESS; + aModEvt.mnTime = pEvent->time; + aModEvt.mnCode = nModCode; + if( pEvent->type == GDK_KEY_RELEASE ) { + aModEvt.mnModKeyCode = pThis->m_nKeyModifiers; nModCode &= ~nModMask; pThis->m_nKeyModifiers &= ~nExtModMask; } @@ -3169,14 +3159,10 @@ gboolean GtkSalFrame::signalKey( GtkWidget*, GdkEventKey* pEvent, gpointer frame { nModCode |= nModMask; pThis->m_nKeyModifiers |= nExtModMask; + aModEvt.mnModKeyCode = pThis->m_nKeyModifiers; } - aModEvt.mnCode = nModCode; - aModEvt.mnTime = pEvent->time; - aModEvt.mnModKeyCode = pThis->m_nKeyModifiers; - pThis->CallCallback( SalEvent::KeyModChange, &aModEvt ); - } else { @@ -3189,7 +3175,7 @@ gboolean GtkSalFrame::signalKey( GtkWidget*, GdkEventKey* pEvent, gpointer frame (pEvent->type == GDK_KEY_PRESS), false ); if( ! aDel.isDeleted() ) - pThis->m_bSendModChangeOnRelease = false; + pThis->m_nKeyModifiers = 0; } if( !aDel.isDeleted() && pThis->m_pIMHandler ) diff --git a/vcl/unx/gtk3/gtk3gtkframe.cxx b/vcl/unx/gtk3/gtk3gtkframe.cxx index f22e8ebcbaa7..67caeb516770 100644 --- a/vcl/unx/gtk3/gtk3gtkframe.cxx +++ b/vcl/unx/gtk3/gtk3gtkframe.cxx @@ -1075,7 +1075,6 @@ void GtkSalFrame::InitCommon() m_bSpanMonitorsWhenFullscreen = false; m_nState = GDK_WINDOW_STATE_WITHDRAWN; m_nVisibility = GDK_VISIBILITY_FULLY_OBSCURED; - m_bSendModChangeOnRelease = false; m_pIMHandler = nullptr; m_nExtStyle = 0; m_pRegion = nullptr; @@ -3021,10 +3020,7 @@ gboolean GtkSalFrame::signalFocus( GtkWidget*, GdkEventFocus* pEvent, gpointer f pSalInstance->updatePrinterUpdate(); if( !pEvent->in ) - { pThis->m_nKeyModifiers = 0; - pThis->m_bSendModChangeOnRelease = false; - } if( pThis->m_pIMHandler ) pThis->m_pIMHandler->focusChanged( pEvent->in ); @@ -3088,20 +3084,7 @@ gboolean GtkSalFrame::signalKey(GtkWidget* pWidget, GdkEventKey* pEvent, gpointe pEvent->keyval == GDK_KEY_Meta_L || pEvent->keyval == GDK_KEY_Meta_R || pEvent->keyval == GDK_KEY_Super_L || pEvent->keyval == GDK_KEY_Super_R ) { - SalKeyModEvent aModEvt; - sal_uInt16 nModCode = GetKeyModCode( pEvent->state ); - - aModEvt.mnModKeyCode = 0; // emit no MODKEYCHANGE events - if( pEvent->type == GDK_KEY_PRESS && !pThis->m_nKeyModifiers ) - pThis->m_bSendModChangeOnRelease = true; - - else if( pEvent->type == GDK_KEY_RELEASE && - pThis->m_bSendModChangeOnRelease ) - { - aModEvt.mnModKeyCode = pThis->m_nKeyModifiers; - } - sal_uInt16 nExtModMask = 0; sal_uInt16 nModMask = 0; // pressing just the ctrl key leads to a keysym of XK_Control but @@ -3147,8 +3130,15 @@ gboolean GtkSalFrame::signalKey(GtkWidget* pWidget, GdkEventKey* pEvent, gpointe nModMask = KEY_MOD3; break; } + + SalKeyModEvent aModEvt; + aModEvt.mbDown = pEvent->type == GDK_KEY_PRESS; + aModEvt.mnTime = pEvent->time; + aModEvt.mnCode = nModCode; + if( pEvent->type == GDK_KEY_RELEASE ) { + aModEvt.mnModKeyCode = pThis->m_nKeyModifiers; nModCode &= ~nModMask; pThis->m_nKeyModifiers &= ~nExtModMask; } @@ -3156,14 +3146,10 @@ gboolean GtkSalFrame::signalKey(GtkWidget* pWidget, GdkEventKey* pEvent, gpointe { nModCode |= nModMask; pThis->m_nKeyModifiers |= nExtModMask; + aModEvt.mnModKeyCode = pThis->m_nKeyModifiers; } - aModEvt.mnCode = nModCode; - aModEvt.mnTime = pEvent->time; - aModEvt.mnModKeyCode = pThis->m_nKeyModifiers; - pThis->CallCallbackExc( SalEvent::KeyModChange, &aModEvt ); - } else { @@ -3176,7 +3162,7 @@ gboolean GtkSalFrame::signalKey(GtkWidget* pWidget, GdkEventKey* pEvent, gpointe (pEvent->type == GDK_KEY_PRESS), false ); if( ! aDel.isDeleted() ) - pThis->m_bSendModChangeOnRelease = false; + pThis->m_nKeyModifiers = 0; } if( !aDel.isDeleted() && pThis->m_pIMHandler ) diff --git a/vcl/win/window/salframe.cxx b/vcl/win/window/salframe.cxx index 42baae8ef715..e85c1594e548 100644 --- a/vcl/win/window/salframe.cxx +++ b/vcl/win/window/salframe.cxx @@ -3477,6 +3477,7 @@ static long ImplHandleKeyMsg( HWND hWnd, UINT nMsg, if ( (wParam == VK_SHIFT) || (wParam == VK_CONTROL) || (wParam == VK_MENU) ) { SalKeyModEvent aModEvt; + aModEvt.mbDown = false; // auto-accelerator feature not supported here. aModEvt.mnTime = GetMessageTime(); aModEvt.mnCode = nModCode; aModEvt.mnModKeyCode = 0; // no command events will be sent if this member is 0 |