From 9f2307382d4acc636b621570ed7770dcab0d652a Mon Sep 17 00:00:00 2001 From: tpearson Date: Mon, 19 Apr 2010 02:37:55 +0000 Subject: Part II of the previous kdebase commit, adding the global hotkeys<-->DBUS connection. git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1116280 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kdecore/kglobalaccel_x11.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'kdecore/kglobalaccel_x11.cpp') diff --git a/kdecore/kglobalaccel_x11.cpp b/kdecore/kglobalaccel_x11.cpp index 542e04361..249c06460 100644 --- a/kdecore/kglobalaccel_x11.cpp +++ b/kdecore/kglobalaccel_x11.cpp @@ -89,6 +89,7 @@ KGlobalAccelPrivate::KGlobalAccelPrivate() all_accels->append( this ); m_sConfigGroup = "Global Shortcuts"; kapp->installX11EventFilter( this ); + connect(kapp, SIGNAL(coreFakeKeyPress(unsigned int)), this, SLOT(fakeKeyPressed(unsigned int))); } KGlobalAccelPrivate::~KGlobalAccelPrivate() @@ -269,6 +270,49 @@ void KGlobalAccelPrivate::x11MappingNotify() updateConnections(); } +void KGlobalAccelPrivate::fakeKeyPressed(unsigned int keyCode) { + CodeMod codemod; + codemod.code = keyCode; + codemod.mod = 0; + + KKey key = (keyCode, 0); + + kdDebug(125) << "fakeKeyPressed: seek " << key.toStringInternal() + << QString( " keyCodeX: %1 keyCode: %2 keyModX: %3" ) + .arg( codemod.code, 0, 16 ).arg( keyCode, 0, 16 ).arg( codemod.mod, 0, 16 ) << endl; + + // Search for which accelerator activated this event: + if( !m_rgCodeModToAction.contains( codemod ) ) { +#ifndef NDEBUG + for( CodeModMap::ConstIterator it = m_rgCodeModToAction.begin(); it != m_rgCodeModToAction.end(); ++it ) { + KAccelAction* pAction = *it; + kdDebug(125) << "\tcode: " << QString::number(it.key().code, 16) << " mod: " << QString::number(it.key().mod, 16) + << (pAction ? QString(" name: \"%1\" shortcut: %2").arg(pAction->name()).arg(pAction->shortcut().toStringInternal()) : QString::null) + << endl; + } +#endif + return; + } + + KAccelAction* pAction = m_rgCodeModToAction[codemod]; + + if( !pAction ) { + static bool recursion_block = false; + if( !recursion_block ) { + recursion_block = true; + QPopupMenu* pMenu = createPopupMenu( 0, KKeySequence(key) ); + connect( pMenu, SIGNAL(activated(int)), this, SLOT(slotActivated(int)) ); + pMenu->exec( QPoint( 0, 0 ) ); + disconnect( pMenu, SIGNAL(activated(int)), this, SLOT(slotActivated(int))); + delete pMenu; + recursion_block = false; + } + } else if( !pAction->objSlotPtr() || !pAction->isEnabled() ) + return; + else + activate( pAction, KKeySequence(key) ); +} + bool KGlobalAccelPrivate::x11KeyPress( const XEvent *pEvent ) { // do not change this line unless you really really know what you are doing (Matthias) -- cgit v1.2.1