From fda0344c47b3b825fb378e19933100ef48c66707 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sat, 22 Feb 2025 21:04:55 +0900 Subject: Rename kglobalaccel* files to tdeglobalaccel*. A dummy 'kglobalaccel.h' has been added to allow TDE to built till renaming is carried out across the whole code base. It will then be removed. Signed-off-by: Michele Calgaro --- tdecore/CMakeLists.txt | 4 +- tdecore/MAINTAINERS | 6 +- tdecore/Makefile.am | 6 +- tdecore/kglobalaccel.cpp | 139 ------------ tdecore/kglobalaccel.h | 240 +------------------- tdecore/kglobalaccel_emb.h | 18 -- tdecore/kglobalaccel_mac.h | 31 --- tdecore/kglobalaccel_win.cpp | 345 ----------------------------- tdecore/kglobalaccel_win.h | 77 ------- tdecore/kglobalaccel_x11.cpp | 451 -------------------------------------- tdecore/kglobalaccel_x11.h | 110 ---------- tdecore/tdeapplication.cpp | 2 +- tdecore/tdeglobalaccel.cpp | 139 ++++++++++++ tdecore/tdeglobalaccel.h | 239 ++++++++++++++++++++ tdecore/tdeglobalaccel_emb.h | 18 ++ tdecore/tdeglobalaccel_mac.h | 31 +++ tdecore/tdeglobalaccel_win.cpp | 345 +++++++++++++++++++++++++++++ tdecore/tdeglobalaccel_win.h | 77 +++++++ tdecore/tdeglobalaccel_x11.cpp | 451 ++++++++++++++++++++++++++++++++++++++ tdecore/tdeglobalaccel_x11.h | 110 ++++++++++ tdecore/tdeshortcutlist.cpp | 2 +- tdeui/kkeybutton.cpp | 2 +- tdeui/kkeydialog.cpp | 2 +- win/pro_files/tdecore/tdecore.pro | 4 +- 24 files changed, 1425 insertions(+), 1424 deletions(-) delete mode 100644 tdecore/kglobalaccel.cpp delete mode 100644 tdecore/kglobalaccel_emb.h delete mode 100644 tdecore/kglobalaccel_mac.h delete mode 100644 tdecore/kglobalaccel_win.cpp delete mode 100644 tdecore/kglobalaccel_win.h delete mode 100644 tdecore/kglobalaccel_x11.cpp delete mode 100644 tdecore/kglobalaccel_x11.h create mode 100644 tdecore/tdeglobalaccel.cpp create mode 100644 tdecore/tdeglobalaccel.h create mode 100644 tdecore/tdeglobalaccel_emb.h create mode 100644 tdecore/tdeglobalaccel_mac.h create mode 100644 tdecore/tdeglobalaccel_win.cpp create mode 100644 tdecore/tdeglobalaccel_win.h create mode 100644 tdecore/tdeglobalaccel_x11.cpp create mode 100644 tdecore/tdeglobalaccel_x11.h diff --git a/tdecore/CMakeLists.txt b/tdecore/CMakeLists.txt index 2b6d4c67e..adaf2493b 100644 --- a/tdecore/CMakeLists.txt +++ b/tdecore/CMakeLists.txt @@ -56,7 +56,7 @@ install( FILES kcharsets.h tdeversion.h kpty.h tdeprocess.h tdeprocctrl.h tdelocale.h kicontheme.h kiconloader.h kdebug.h twinmodule.h twin.h krootprop.h tdeshortcut.h kkeynative.h tdeaccel.h - kglobalaccel.h tdestdaccel.h tdeshortcutlist.h kcatalogue.h + kglobalaccel.h tdeglobalaccel.h tdestdaccel.h tdeshortcutlist.h kcatalogue.h kregexp.h kcompletion.h kstringhandler.h kstddirs.h kstandarddirs.h tdeglobal.h tdeglobalsettings.h ksharedptr.h kallocator.h kvmallocator.h tdecrash.h krfcdate.h kinstance.h @@ -113,7 +113,7 @@ set( ${target}_SRCS twin.cpp twinmodule.cpp krootprop.cpp kcharsets.cpp kckey.cpp tdeshortcut.cpp kkeynative_x11.cpp kkeyserver_x11.cpp tdeaccelaction.cpp tdeshortcutmenu.cpp tdeaccelbase.cpp tdeaccel.cpp - kglobalaccel_x11.cpp kglobalaccel.cpp tdestdaccel.cpp tdeshortcutlist.cpp + tdeglobalaccel_x11.cpp tdeglobalaccel.cpp tdestdaccel.cpp tdeshortcutlist.cpp tdecrash.cpp kurl.cpp kregexp.cpp tdeglobal.cpp tdeglobalsettings.cpp kallocator.cpp kvmallocator.cpp kmimesourcefactory.cpp kinstance.cpp kpalette.cpp kipc.cpp klibloader.cpp tdetempfile.cpp diff --git a/tdecore/MAINTAINERS b/tdecore/MAINTAINERS index 39b3a1424..efc01568a 100644 --- a/tdecore/MAINTAINERS +++ b/tdecore/MAINTAINERS @@ -28,8 +28,8 @@ kdcoppropertyproxy.cpp kdebug.cpp Stephan Kulow kdesktopfile.cpp tdeglobal.cpp Stephan Kulow -kglobalaccel.cpp Ellis Whitehead -kglobalaccel_x11.cpp Ellis Whitehead +tdeglobalaccel.cpp Ellis Whitehead +tdeglobalaccel_x11.cpp Ellis Whitehead tdeglobalsettings.cpp David Faure kiconeffect.cpp kiconloader.cpp @@ -98,7 +98,7 @@ tdeconfigdialogmanager.cpp tdeconfigskeleton.cpp kdebugdcopiface.cpp Andreas Beckermann (b_mann@gmx.de) (copyright) tdeversion.cpp -kglobalaccel_win.cpp Ellis Whitehead (copyright) +tdeglobalaccel_win.cpp Ellis Whitehead (copyright) kkeyserver_x11.cpp klockfile.cpp Waldo Bastian (copyright) kmacroexpander.cpp diff --git a/tdecore/Makefile.am b/tdecore/Makefile.am index 924362b3f..bcd5f63d2 100644 --- a/tdecore/Makefile.am +++ b/tdecore/Makefile.am @@ -43,7 +43,7 @@ include_HEADERS = tdeconfig.h tdeconfigskeleton.h \ tdeuniqueapplication.h kcharsets.h tdeversion.h kpty.h tdeprocess.h \ tdeprocctrl.h tdelocale.h kicontheme.h kiconloader.h kdebug.h \ twinmodule.h twin.h krootprop.h tdeshortcut.h kkeynative.h tdeaccel.h \ - kglobalaccel.h tdestdaccel.h tdeshortcutlist.h kcatalogue.h \ + kglobalaccel.h tdeglobalaccel.h tdestdaccel.h tdeshortcutlist.h kcatalogue.h \ kregexp.h kcompletion.h kstringhandler.h \ kstddirs.h kstandarddirs.h tdeglobal.h tdeglobalsettings.h ksharedptr.h \ kallocator.h kvmallocator.h tdecrash.h krfcdate.h \ @@ -83,7 +83,7 @@ libtdefakes_pic.a: libtdefakes.la noinst_HEADERS = tdeaccelaction.h tdeaccelbase.h tdeaccelprivate.h kckey.h \ kcompletion_private.h netwm_p.h \ - kglobalaccel_x11.h kglobalaccel_win.h kkeyserver_x11.h kkeyserver.h \ + tdeglobalaccel_x11.h tdeglobalaccel_win.h kkeyserver_x11.h kkeyserver.h \ kregpriv.h tdeshortcutmenu.h tdesycocadict.h tdesycocafactory.h netsupp.h \ kcheckaccelerators.h kcalendarsystemgregorian.h \ kcalendarsystemhijri.h kcalendarsystemhebrew.h kcalendarsystemjalali.h \ @@ -97,7 +97,7 @@ libtdecore_la_SOURCES = libintl.cpp tdeapplication.cpp \ kiconloader.cpp twin.cpp twinmodule.cpp krootprop.cpp kcharsets.cpp \ kckey.cpp tdeshortcut.cpp kkeynative_x11.cpp kkeyserver_x11.cpp \ tdeaccelaction.cpp tdeshortcutmenu.cpp tdeaccelbase.cpp tdeaccel.cpp \ - kglobalaccel_x11.cpp kglobalaccel.cpp tdestdaccel.cpp tdeshortcutlist.cpp \ + tdeglobalaccel_x11.cpp tdeglobalaccel.cpp tdestdaccel.cpp tdeshortcutlist.cpp \ tdecrash.cpp kurl.cpp kregexp.cpp tdeglobal.cpp tdeglobalsettings.cpp \ kallocator.cpp kvmallocator.cpp kmimesourcefactory.cpp \ kinstance.cpp kpalette.cpp kipc.cpp klibloader.cpp tdetempfile.cpp \ diff --git a/tdecore/kglobalaccel.cpp b/tdecore/kglobalaccel.cpp deleted file mode 100644 index 5da0093a2..000000000 --- a/tdecore/kglobalaccel.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2001,2002 Ellis Whitehead - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "kglobalaccel.h" -#ifdef TQ_WS_X11 -#include "kglobalaccel_x11.h" -#elif defined(TQ_WS_WIN) -#include "kglobalaccel_win.h" -#elif defined(TQ_WS_MACX) -#include "kglobalaccel_mac.h" -#else -#include "kglobalaccel_emb.h" -#endif - -#include -#include "tdeaccelbase.h" -#include -#include -#include - -//---------------------------------------------------- - -TDEGlobalAccel::TDEGlobalAccel( TQObject* pParent, const char* psName ) -: TQObject( pParent, psName ) -{ - kdDebug(125) << "TDEGlobalAccel(): this = " << this << endl; - d = new TDEGlobalAccelPrivate(); -} - -TDEGlobalAccel::~TDEGlobalAccel() -{ - kdDebug(125) << "~TDEGlobalAccel(): this = " << this << endl; - delete d; -} - -/* -void TDEGlobalAccel::clear() - { d->clearActions(); } -*/ -TDEAccelActions& TDEGlobalAccel::actions() - { return d->TDEAccelBase::actions(); } - -const TDEAccelActions& TDEGlobalAccel::actions() const - { return d->TDEAccelBase::actions(); } - -bool TDEGlobalAccel::isEnabled() - { return ((TDEAccelBase*)d)->isEnabled(); } - -void TDEGlobalAccel::setEnabled( bool bEnabled ) - { d->setEnabled( bEnabled ); } - -void TDEGlobalAccel::suspend( bool s ) - { d->suspend( s ); } - -void TDEGlobalAccel::blockShortcuts( bool block ) - { TDEGlobalAccelPrivate::blockShortcuts( block ); } - -void TDEGlobalAccel::disableBlocking( bool disable ) - { d->disableBlocking( disable ); } - -TDEAccelAction* TDEGlobalAccel::insert( const TQString& sAction, const TQString& sDesc, const TQString& sHelp, - const TDEShortcut& cutDef3, const TDEShortcut& cutDef4, - const TQObject* pObjSlot, const char* psMethodSlot, - bool bConfigurable, bool bEnabled ) -{ - return d->insert( sAction, sDesc, sHelp, - cutDef3, cutDef4, - pObjSlot, psMethodSlot, - bConfigurable, bEnabled ); -} - -TDEAccelAction* TDEGlobalAccel::insert( const TQString& sName, const TQString& sDesc ) - { return d->insert( sName, sDesc ); } -bool TDEGlobalAccel::updateConnections() - { return d->updateConnections(); } - -bool TDEGlobalAccel::remove( const TQString& sAction ) - { return d->remove( sAction ); } - -const TDEShortcut& TDEGlobalAccel::shortcut( const TQString& sAction ) const -{ - const TDEAccelAction* pAction = d->TDEAccelBase::actions().actionPtr( sAction ); - return (pAction) ? pAction->shortcut() : TDEShortcut::null(); -} - -bool TDEGlobalAccel::setShortcut( const TQString& sAction, const TDEShortcut& cut ) - { return d->setShortcut( sAction, cut ); } -bool TDEGlobalAccel::setSlot( const TQString& sAction, const TQObject* pObjSlot, const char* psMethodSlot ) - { return d->setActionSlot( sAction, pObjSlot, psMethodSlot ); } -TQString TDEGlobalAccel::label( const TQString& sAction ) const -{ - const TDEAccelAction* pAction = d->TDEAccelBase::actions().actionPtr( sAction ); - return (pAction) ? pAction->label() : TQString(); -} -bool TDEGlobalAccel::setActionEnabled( const TQString& sAction, bool bEnable ) -{ - return d->setActionEnabled( sAction, bEnable ); -} - -const TQString& TDEGlobalAccel::configGroup() const - { return d->configGroup(); } -// for tdemultimedia/kmix -void TDEGlobalAccel::setConfigGroup( const TQString& s ) - { d->setConfigGroup( s ); } - -bool TDEGlobalAccel::readSettings( TDEConfigBase* pConfig ) - { d->readSettings( pConfig ); return true; } -bool TDEGlobalAccel::writeSettings( TDEConfigBase* pConfig ) const - { d->writeSettings( pConfig ); return true; } -bool TDEGlobalAccel::writeSettings( TDEConfigBase* pConfig, bool bGlobal ) const -{ - d->setConfigGlobal( bGlobal ); - d->writeSettings( pConfig ); - return true; -} - -bool TDEGlobalAccel::useFourModifierKeys() - { return TDEAccelAction::useFourModifierKeys(); } - -void TDEGlobalAccel::virtual_hook( int, void* ) -{ /*BASE::virtual_hook( id, data );*/ } - -#include "kglobalaccel.moc" diff --git a/tdecore/kglobalaccel.h b/tdecore/kglobalaccel.h index 22dedd513..730adf02c 100644 --- a/tdecore/kglobalaccel.h +++ b/tdecore/kglobalaccel.h @@ -1,239 +1 @@ -/* This file is part of the KDE libraries - Copyright (C) 2001,2002 Ellis Whitehead - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef _KGLOBALACCEL_H_ -#define _KGLOBALACCEL_H_ - -#include -#include - -class TQPopupMenu; -class TQWidget; -class TDEAccelAction; -class TDEAccelActions; -class TDEConfigBase; - -class TDEGlobalAccelPrivate; - -/** -* TDEGlobalAccel allows you to have global accelerators that are independent of -* the focused window. Unlike TDEAccel it does not matter which window is -* currently active. -* -* @see TDEAccel -* @see TDEAccelShortcutList -* @see KKeyChooser -* @see KKeyDialog -* @short Configurable global shortcut support -*/ -class TDECORE_EXPORT TDEGlobalAccel : public TQObject -{ - TQ_OBJECT - public: - /** - * Creates a new TDEGlobalAccel object with the given pParent and - * psName. - * @param pParent the parent of the TQObject - * @param psName the name of the TQObject - */ - TDEGlobalAccel( TQObject* pParent, const char* psName = 0 ); - virtual ~TDEGlobalAccel(); - - /** - * Checks whether the accelerators are enabled. - * @return true if the TDEGlobalAccel is enabled - */ - bool isEnabled(); - - /** - * Enables or disables the TDEGlobalAccel - * @param bEnabled true if the TDEGlobalAccel should be enabled, false if it - * should be disabled. - */ - void setEnabled( bool bEnabled ); - - /** - * Create an accelerator action. - * - * Usage: - *\code - * insert( "Do Something", i18n("Do Something"), - * i18n("This action allows you to do something really great with this program to " - * "the currently open document."), - * ALT+CTRL+Key_Q, KKey::QtWIN+CTRL+Key_Q, this, TQ_SLOT(slotDoSomething()) ); - *\endcode - * - * @param sAction The internal name of the action. - * @param sLabel An i18n'ized short description of the action displayed when - * using KKeyChooser to reconfigure the shortcuts. - * @param sWhatsThis An extended description of the action. - * @param cutDef3 The default 3 modifier scheme shortcut. - * @param cutDef4 The default 4 modifier scheme shortcut. - * @param pObjSlot Pointer to the slot object. - * @param psMethodSlot Pointer to the slot method. - * @param bConfigurable Allow the user to change this shortcut if set to 'true'. - * @param bEnabled The action will be activated by the shortcut if set to 'true'. - */ - TDEAccelAction* insert( const TQString& sAction, const TQString& sLabel, const TQString& sWhatsThis, - const TDEShortcut& cutDef3, const TDEShortcut& cutDef4, - const TQObject* pObjSlot, const char* psMethodSlot, - bool bConfigurable = true, bool bEnabled = true ); - - /** - * Removes the accelerator action identified by the name. - * Remember to also call updateConnections(). - * @param sAction the name of the action to remove - * @since 3.1 - */ - bool remove( const TQString& sAction ); - - /** - * Use this to insert a label into the action list. This will be - * displayed when the user configures shortcuts. - * @param sName of the of the action to insert - * @param sLabel a user-readable (i18n!) name for the action - * @return the TDEAccelAction of the action - */ - TDEAccelAction* insert( const TQString& sName, const TQString& sLabel ); - - /** - * Updates the connections of the accelerations after changing them. - * @return true if successful, false otherwise - */ - bool updateConnections(); - - /** - * Return the shortcut associated with the action named by @p sAction. - * @param sAction the name of the action - * @return the shortcut. If the action does not exist a null shortcut will be returned. - */ - const TDEShortcut& shortcut( const TQString& sAction ) const; - /** - * Set the shortcut to be associated with the action named by @p sAction. - * @param sAction the name of the action - * @param shortcut the shortcut for the action - * @return true if successful, false otherwise - */ - bool setShortcut( const TQString& sAction, const TDEShortcut &shortcut ); - /** - * Set the slot to be called when the shortcut of the action named - * by @p sAction is pressed. - * @param sAction the name of the action - * @param pObjSlot the receiver of the signal - * @param psMethodSlot the slot to receive the signal - * @return true if successful, false otherwise - */ - bool setSlot( const TQString& sAction, const TQObject* pObjSlot, const char* psMethodSlot ); - - /** - * Enables or disables action @p sAction. - * @since 3.4 - */ - bool setActionEnabled( const TQString& sAction, bool bEnable ); - /** - * Return the label (i18n'ized short description) associated with the action named by @p sAction. - * @param sAction the name of the action - * @return the label - * @since 3.3 - */ - TQString label( const TQString& sAction ) const; - - /** - * Returns the configuration group that is used to save the accelerators. - * @return the configuration group - * @see TDEConfig - */ - const TQString& configGroup() const; - - /** - * Sets the configuration group that is used to save the accelerators. - * @param cg the configuration group - * @see TDEConfig - */ - void setConfigGroup( const TQString &cg ); - - /** - * Read all shortcuts from @p pConfig, or (if @p pConfig - * is zero) from the application's configuration file - * TDEGlobal::config(). - * @param pConfig the configuration file to read from, or 0 for the application - * configuration file - * @return true if successful, false otherwise - */ - bool readSettings( TDEConfigBase* pConfig = 0 ); - - /** - * Write the current shortcuts to @p pConfig, - * or (if @p pConfig is zero) to the application's - * configuration file. - * @param pConfig the configuration file to read from, or 0 for the application - * configuration file - * @return true if successful, false otherwise - * @since 3.1 - */ - bool writeSettings( TDEConfigBase* pConfig = 0 ) const; - // BCI: merge these two writeSettings methods in KDE 4.0 - /** - * Write the current shortcuts to @p pConfig, - * or (if @p pConfig is zero) to the application's - * configuration file. Alternatively, if bGlobal is true, then write - * to kdeglobals. - * @param pConfig the configuration file to read from, or 0 for the application - * configuration file - * @param bGlobal if true write the configuration to the kde global settings - * @return true if successful, false otherwise - */ - bool writeSettings( TDEConfigBase* pConfig, bool bGlobal ) const; - - /** - * @internal -- this a wrapper function to - * TDEAccelActions::useFourModifierKeys(). - */ - static bool useFourModifierKeys(); - - /** - * @internal - */ - static void blockShortcuts( bool block ); - /** - * @internal - */ - void disableBlocking( bool disable ); - - /** - * @internal - */ - // like setEnabled(), but doesn't ungrab (see in TDEGlobalAccelPrivate) - void suspend( bool s ); - -private: - - TDEAccelActions& actions(); - const TDEAccelActions& actions() const; - - friend class TDEGlobalAccelPrivate; - friend class TDEAccelShortcutList; -protected: - /** \internal */ - virtual void virtual_hook( int id, void* data ); -private: - class TDEGlobalAccelPrivate* d; -}; - -#endif // _KGLOBALACCEL_H_ +#include diff --git a/tdecore/kglobalaccel_emb.h b/tdecore/kglobalaccel_emb.h deleted file mode 100644 index 5e5145d66..000000000 --- a/tdecore/kglobalaccel_emb.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _KGLOBALACCEL_EMB_H -#define _KGLOBALACCEL_EMB_H - -#include "tdeaccelbase.h" -#include "tdeshortcut.h" - -class TDEGlobalAccelPrivate -{ -public: - TDEGlobalAccelPrivate(); - - virtual void setEnabled( bool bEnabled ); - - virtual bool connectKey( TDEAccelAction&, KKeySequence ); - virtual bool disconnectKey( TDEAccelAction&, KKeySequence ); -}; - -#endif // _KGLOBALACCEL_EMB_H diff --git a/tdecore/kglobalaccel_mac.h b/tdecore/kglobalaccel_mac.h deleted file mode 100644 index b2803b0c0..000000000 --- a/tdecore/kglobalaccel_mac.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef _KGLOBALACCEL_MAC_H -#define _KGLOBALACCEL_MAC_H - -#include - -#include "tdeshortcut.h" -#include "tdeaccelbase.h" - -class TDEGlobalAccelPrivate: public TDEAccelBase -{ -public: - TDEGlobalAccelPrivate() - : TDEAccelBase(TDEAccelBase::NATIVE_KEYS) - {} - - // reimplemented pure virtuals - void setEnabled( bool bEnabled ) - { Q_UNUSED(bEnabled); } - bool emitSignal( Signal signal ) - { Q_UNUSED(signal); return false; } - bool connectKey( TDEAccelAction& action, const KKeyServer::Key& key) - { Q_UNUSED(action); Q_UNUSED(key); return false; } - bool connectKey( const KKeyServer::Key& key) - { Q_UNUSED(key); return false; } - bool disconnectKey( TDEAccelAction&, const KKeyServer::Key& key) - { Q_UNUSED(key); return false; } - bool disconnectKey( const KKeyServer::Key& ) - { return false; } -}; - -#endif // _KGLOBALACCEL_EMB_H diff --git a/tdecore/kglobalaccel_win.cpp b/tdecore/kglobalaccel_win.cpp deleted file mode 100644 index a222d0242..000000000 --- a/tdecore/kglobalaccel_win.cpp +++ /dev/null @@ -1,345 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2001,2002 Ellis Whitehead - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "config.h" - -#include -#ifdef TQ_WS_WIN - -#include "kglobalaccel_win.h" -#include "kglobalaccel.h" -#include "kkeyserver_x11.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -//---------------------------------------------------- - -static TQValueList< TDEGlobalAccelPrivate* >* all_accels = 0; - -TDEGlobalAccelPrivate::TDEGlobalAccelPrivate() -: TDEAccelBase( TDEAccelBase::NATIVE_KEYS ) -, m_blocked( false ) -, m_blockingDisabled( false ) -{ - if( all_accels == NULL ) - all_accels = new TQValueList< TDEGlobalAccelPrivate* >; - all_accels->append( this ); - m_sConfigGroup = "Global Shortcuts"; -// tdeApp->installX11EventFilter( this ); -} - -TDEGlobalAccelPrivate::~TDEGlobalAccelPrivate() -{ - // TODO: Need to release all grabbed keys if the main window is not shutting down. - //for( CodeModMap::ConstIterator it = m_rgCodeModToAction.begin(); it != m_rgCodeModToAction.end(); ++it ) { - // const CodeMod& codemod = it.key(); - //} - all_accels->remove( this ); - if( all_accels->count() == 0 ) { - delete all_accels; - all_accels = NULL; - } -} - -void TDEGlobalAccelPrivate::setEnabled( bool bEnable ) -{ - m_bEnabled = bEnable; - //updateConnections(); -} - -void TDEGlobalAccelPrivate::blockShortcuts( bool block ) -{ - if( all_accels == NULL ) - return; - for( TQValueList< TDEGlobalAccelPrivate* >::ConstIterator it = all_accels->begin(); - it != all_accels->end(); - ++it ) { - if( (*it)->m_blockingDisabled ) - continue; - (*it)->m_blocked = block; - (*it)->updateConnections(); - } -} - -void TDEGlobalAccelPrivate::disableBlocking( bool block ) -{ - m_blockingDisabled = block; -} - -bool TDEGlobalAccelPrivate::isEnabledInternal() const -{ - return TDEAccelBase::isEnabled() && !m_blocked; -} - -bool TDEGlobalAccelPrivate::emitSignal( Signal ) -{ - return false; -} - -bool TDEGlobalAccelPrivate::connectKey( TDEAccelAction& action, const KKeyServer::Key& key ) - { return grabKey( key, true, &action ); } -bool TDEGlobalAccelPrivate::connectKey( const KKeyServer::Key& key ) - { return grabKey( key, true, 0 ); } -bool TDEGlobalAccelPrivate::disconnectKey( TDEAccelAction& action, const KKeyServer::Key& key ) - { return grabKey( key, false, &action ); } -bool TDEGlobalAccelPrivate::disconnectKey( const KKeyServer::Key& key ) - { return grabKey( key, false, 0 ); } - -bool TDEGlobalAccelPrivate::grabKey( const KKeyServer::Key& key, bool bGrab, TDEAccelAction* pAction ) -{ - /* - if( !key.code() ) { - kdWarning(125) << "TDEGlobalAccelPrivate::grabKey( " << key.key().toStringInternal() << ", " << bGrab << ", \"" << (pAction ? pAction->name().latin1() : "(null)") << "\" ): Tried to grab key with null code." << endl; - return false; - } - - // Make sure that grab masks have been initialized. - if( g_keyModMaskXOnOrOff == 0 ) - calculateGrabMasks(); - - uchar keyCodeX = key.code(); - uint keyModX = key.mod() & g_keyModMaskXAccel; // Get rid of any non-relevant bits in mod - // HACK: make Alt+Print work - if( key.sym() == XK_Sys_Req ) { - keyModX |= KKeyServer::modXAlt(); - keyCodeX = 111; - } - - kdDebug(125) << TQString( "grabKey( key: '%1', bGrab: %2 ): keyCodeX: %3 keyModX: %4\n" ) - .arg( key.key().toStringInternal() ).arg( bGrab ) - .arg( keyCodeX, 0, 16 ).arg( keyModX, 0, 16 ); - if( !keyCodeX ) - return false; - - // We'll have to grab 8 key modifier combinations in order to cover all - // combinations of CapsLock, NumLock, ScrollLock. - // Does anyone with more X-savvy know how to set a mask on tqt_xrootwin so that - // the irrelevant bits are always ignored and we can just make one XGrabKey - // call per accelerator? -- ellis -#ifndef NDEBUG - TQString sDebug = TQString("\tcode: 0x%1 state: 0x%2 | ").arg(keyCodeX,0,16).arg(keyModX,0,16); -#endif - uint keyModMaskX = ~g_keyModMaskXOnOrOff; - for( uint irrelevantBitsMask = 0; irrelevantBitsMask <= 0xff; irrelevantBitsMask++ ) { - if( (irrelevantBitsMask & keyModMaskX) == 0 ) { -#ifndef NDEBUG - sDebug += TQString("0x%3, ").arg(irrelevantBitsMask, 0, 16); -#endif - if( bGrab ) - XGrabKey( tqt_xdisplay(), keyCodeX, keyModX | irrelevantBitsMask, - tqt_xrootwin(), True, GrabModeAsync, GrabModeSync ); - else - XUngrabKey( tqt_xdisplay(), keyCodeX, keyModX | irrelevantBitsMask, tqt_xrootwin() ); - } - } -#ifndef NDEBUG - kdDebug(125) << sDebug << endl; -#endif - - bool failed = false; - if( bGrab ) { -#ifdef TQ_WS_X11 - failed = handler.error( true ); // sync now -#endif - // If grab failed, then ungrab any grabs that could possibly succeed - if( failed ) { - kdDebug(125) << "grab failed!\n"; - for( uint m = 0; m <= 0xff; m++ ) { - if( m & keyModMaskX == 0 ) - XUngrabKey( tqt_xdisplay(), keyCodeX, keyModX | m, tqt_xrootwin() ); - } - } - } - if( !failed ) - { - CodeMod codemod; - codemod.code = keyCodeX; - codemod.mod = keyModX; - if( key.mod() & KKeyServer::MODE_SWITCH ) - codemod.mod |= KKeyServer::MODE_SWITCH; - - if( bGrab ) - m_rgCodeModToAction.insert( codemod, pAction ); - else - m_rgCodeModToAction.remove( codemod ); - } - return !failed;*/ - return false; -} - -/*bool TDEGlobalAccelPrivate::x11Event( XEvent* pEvent ) -{ - //kdDebug(125) << "x11EventFilter( type = " << pEvent->type << " )" << endl; - switch( pEvent->type ) { - case MappingNotify: - XRefreshKeyboardMapping( &pEvent->xmapping ); - x11MappingNotify(); - return false; - case XKeyPress: - if( x11KeyPress( pEvent ) ) - return true; - default: - return TQWidget::x11Event( pEvent ); - } -} - -void TDEGlobalAccelPrivate::x11MappingNotify() -{ - kdDebug(125) << "TDEGlobalAccelPrivate::x11MappingNotify()" << endl; - if( m_bEnabled ) { - // Maybe the X modifier map has been changed. - KKeyServer::initializeMods(); - calculateGrabMasks(); - // Do new XGrabKey()s. - updateConnections(); - } -} - -bool TDEGlobalAccelPrivate::x11KeyPress( const XEvent *pEvent ) -{ - // do not change this line unless you really really know what you are doing (Matthias) - if ( !TQWidget::keyboardGrabber() && !TQApplication::activePopupWidget() ) { - XUngrabKeyboard( tqt_xdisplay(), pEvent->xkey.time ); - XFlush( tqt_xdisplay()); // avoid X(?) bug - } - - if( !m_bEnabled ) - return false; - - CodeMod codemod; - codemod.code = pEvent->xkey.keycode; - codemod.mod = pEvent->xkey.state & (g_keyModMaskXAccel | KKeyServer::MODE_SWITCH); - - // If numlock is active and a keypad key is pressed, XOR the SHIFT state. - // e.g., KP_4 => Shift+KP_Left, and Shift+KP_4 => KP_Left. - if( pEvent->xkey.state & KKeyServer::modXNumLock() ) { - // TODO: what's the xor operator in c++? - uint sym = XkbKeycodeToKeysym( tqt_xdisplay(), codemod.code, 0, 0 ); - // If this is a keypad key, - if( sym >= XK_KP_Space && sym <= XK_KP_9 ) { - switch( sym ) { - // Leave the following keys unaltered - // FIXME: The proper solution is to see which keysyms don't change when shifted. - case XK_KP_Multiply: - case XK_KP_Add: - case XK_KP_Subtract: - case XK_KP_Divide: - break; - default: - if( codemod.mod & KKeyServer::modXShift() ) - codemod.mod &= ~KKeyServer::modXShift(); - else - codemod.mod |= KKeyServer::modXShift(); - } - } - } - - KKeyNative keyNative( pEvent ); - KKey key = keyNative; - - kdDebug(125) << "x11KeyPress: seek " << key.toStringInternal() - << TQString( " keyCodeX: %1 state: %2 keyModX: %3" ) - .arg( codemod.code, 0, 16 ).arg( pEvent->xkey.state, 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 ) { - TDEAccelAction* pAction = *it; - kdDebug(125) << "\tcode: " << TQString::number(it.key().code, 16) << " mod: " << TQString::number(it.key().mod, 16) - << (pAction ? TQString(" name: \"%1\" shortcut: %2").arg(pAction->name()).arg(pAction->shortcut().toStringInternal()) : TQString::null) - << endl; - } -#endif - return false; - } - TDEAccelAction* pAction = m_rgCodeModToAction[codemod]; - - if( !pAction ) { - static bool recursion_block = false; - if( !recursion_block ) { - recursion_block = true; - TQPopupMenu* pMenu = createPopupMenu( 0, KKeySequence(key) ); - connect( pMenu, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotActivated(int)) ); - pMenu->exec( TQPoint( 0, 0 ) ); - disconnect( pMenu, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotActivated(int))); - delete pMenu; - recursion_block = false; - } - } else if( !pAction->objSlotPtr() || !pAction->isEnabled() ) - return false; - else - activate( pAction, KKeySequence(key) ); - - return true; -}*/ - -void TDEGlobalAccelPrivate::activate( TDEAccelAction* pAction, const KKeySequence& seq ) -{ - kdDebug(125) << "TDEGlobalAccelPrivate::activate( \"" << pAction->name() << "\" ) " << endl; - - TQRegExp rexPassIndex( "([ ]*int[ ]*)" ); - TQRegExp rexPassInfo( " TQString" ); - TQRegExp rexIndex( " ([0-9]+)$" ); - - // If the slot to be called accepts an integer index - // and an index is present at the end of the action's name, - // then send the slot the given index #. - if( rexPassIndex.search( pAction->methodSlotPtr() ) >= 0 && rexIndex.search( pAction->name() ) >= 0 ) { - int n = rexIndex.cap(1).toInt(); - kdDebug(125) << "Calling " << pAction->methodSlotPtr() << " int = " << n << endl; - int slot_id = pAction->objSlotPtr()->metaObject()->findSlot( normalizeSignalSlot( pAction->methodSlotPtr() ).data() + 1, true ); - if( slot_id >= 0 ) { - QUObject o[2]; - static_QUType_int.set(o+1,n); - const_cast< TQObject* >( pAction->objSlotPtr())->tqt_invoke( slot_id, o ); - } - } else if( rexPassInfo.search( pAction->methodSlotPtr() ) ) { - int slot_id = pAction->objSlotPtr()->metaObject()->findSlot( normalizeSignalSlot( pAction->methodSlotPtr() ).data() + 1, true ); - if( slot_id >= 0 ) { - QUObject o[4]; - static_QUType_QString.set(o+1,pAction->name()); - static_QUType_QString.set(o+2,pAction->label()); - static_QUType_ptr.set(o+3,&seq); - const_cast< TQObject* >( pAction->objSlotPtr())->tqt_invoke( slot_id, o ); - } - } else { - int slot_id = pAction->objSlotPtr()->metaObject()->findSlot( normalizeSignalSlot( pAction->methodSlotPtr() ).data() + 1, true ); - if( slot_id >= 0 ) - const_cast< TQObject* >( pAction->objSlotPtr())->tqt_invoke( slot_id, 0 ); - } -} - -void TDEGlobalAccelPrivate::slotActivated( int iAction ) -{ - TDEAccelAction* pAction = actions().actionPtr( iAction ); - if( pAction ) - activate( pAction, KKeySequence() ); -} - -#include "kglobalaccel_win.moc" - -#endif // !TQ_WS_WIN diff --git a/tdecore/kglobalaccel_win.h b/tdecore/kglobalaccel_win.h deleted file mode 100644 index 45943b071..000000000 --- a/tdecore/kglobalaccel_win.h +++ /dev/null @@ -1,77 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2001,2002 Ellis Whitehead - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef _KGLOBALACCEL_WIN_H -#define _KGLOBALACCEL_WIN_H - -#include -#include - -#include "tdeaccelbase.h" -#include "kkeyserver.h" -#include "tdeshortcut.h" - -/** - * @internal - */ -class TDEGlobalAccelPrivate : public TQWidget, public TDEAccelBase -{ - friend class TDEGlobalAccel; - TQ_OBJECT - public: - TDEGlobalAccelPrivate(); - virtual ~TDEGlobalAccelPrivate(); - - virtual void setEnabled( bool bEnabled ); - - virtual bool emitSignal( Signal signal ); - virtual bool connectKey( TDEAccelAction& action, const KKeyServer::Key& key ); - virtual bool connectKey( const KKeyServer::Key& key ); - virtual bool disconnectKey( TDEAccelAction& action, const KKeyServer::Key& key ); - virtual bool disconnectKey( const KKeyServer::Key& key ); - - protected: - - /** - * @param bGrab Set to true to grab key, false to ungrab key. - */ - bool grabKey( const KKeyServer::Key&, bool bGrab, TDEAccelAction* ); - - /** - * Filters X11 events ev for key bindings in the accelerator dictionary. - * If a match is found the activated activated is emitted and the function - * returns true. Return false if the event is not processed. - * - * This is public for compatibility only. You do not need to call it. - */ -// virtual bool x11Event( XEvent* ); -// void x11MappingNotify(); -// bool x11KeyPress( const XEvent *pEvent ); - void activate( TDEAccelAction* pAction, const KKeySequence& seq ); - virtual bool isEnabledInternal() const; - static void blockShortcuts( bool block ); - void disableBlocking( bool disable ); - - protected slots: - void slotActivated( int iAction ); - bool m_blocked; - bool m_blockingDisabled; -}; - -#endif // _KGLOBALACCEL_WIN_H diff --git a/tdecore/kglobalaccel_x11.cpp b/tdecore/kglobalaccel_x11.cpp deleted file mode 100644 index a518c58c8..000000000 --- a/tdecore/kglobalaccel_x11.cpp +++ /dev/null @@ -1,451 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2001,2002 Ellis Whitehead - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "config.h" - -#include -#ifdef TQ_WS_X11 - -#include "kglobalaccel_x11.h" -#include "kglobalaccel.h" -#include "kkeyserver_x11.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef TQ_WS_X11 -#include -#endif - -#include -#include -#include -#include -#include - -extern "C" { - static int XGrabErrorHandler( Display *, XErrorEvent *e ) { - if ( e->error_code != BadAccess ) { - kdWarning() << "grabKey: got X error " << e->type << " instead of BadAccess\n"; - } - return 1; - } -} - -// g_keyModMaskXAccel -// mask of modifiers which can be used in shortcuts -// (meta, alt, ctrl, shift) -// g_keyModMaskXOnOrOff -// mask of modifiers where we don't care whether they are on or off -// (caps lock, num lock, scroll lock) -static uint g_keyModMaskXAccel = 0; -static uint g_keyModMaskXOnOrOff = 0; - -static void calculateGrabMasks() -{ - g_keyModMaskXAccel = KKeyServer::accelModMaskX(); - g_keyModMaskXOnOrOff = - KKeyServer::modXLock() | - KKeyServer::modXNumLock() | - KKeyServer::modXScrollLock() | - KKeyServer::modXModeSwitch(); - //kdDebug() << "g_keyModMaskXAccel = " << g_keyModMaskXAccel - // << "g_keyModMaskXOnOrOff = " << g_keyModMaskXOnOrOff << endl; -} - -//---------------------------------------------------- - -static TQValueList< TDEGlobalAccelPrivate* >* all_accels = 0; - -TDEGlobalAccelPrivate::TDEGlobalAccelPrivate() -: TDEAccelBase( TDEAccelBase::NATIVE_KEYS ) -, m_blocked( false ) -, m_blockingDisabled( false ) -, m_suspended( false ) -{ - if( all_accels == NULL ) - all_accels = new TQValueList< TDEGlobalAccelPrivate* >; - all_accels->append( this ); - m_sConfigGroup = "Global Shortcuts"; - tdeApp->installX11EventFilter( this ); - connect(tdeApp, TQ_SIGNAL(coreFakeKeyPress(unsigned int)), this, TQ_SLOT(fakeKeyPressed(unsigned int))); -} - -TDEGlobalAccelPrivate::~TDEGlobalAccelPrivate() -{ - // TODO: Need to release all grabbed keys if the main window is not shutting down. - //for( CodeModMap::ConstIterator it = m_rgCodeModToAction.begin(); it != m_rgCodeModToAction.end(); ++it ) { - // const CodeMod& codemod = it.key(); - //} - all_accels->remove( this ); - if( all_accels->count() == 0 ) { - delete all_accels; - all_accels = NULL; - } -} - -void TDEGlobalAccelPrivate::setEnabled( bool bEnable ) -{ - m_bEnabled = bEnable; - updateConnections(); -} - -void TDEGlobalAccelPrivate::blockShortcuts( bool block ) -{ - if( all_accels == NULL ) - return; - for( TQValueList< TDEGlobalAccelPrivate* >::ConstIterator it = all_accels->begin(); - it != all_accels->end(); - ++it ) { - if( (*it)->m_blockingDisabled ) - continue; - (*it)->m_blocked = block; - (*it)->updateConnections(); - } -} - -void TDEGlobalAccelPrivate::disableBlocking( bool block ) -{ - m_blockingDisabled = block; -} - -bool TDEGlobalAccelPrivate::isEnabledInternal() const -{ - return TDEAccelBase::isEnabled() && !m_blocked; -} - -// see #117169 - the bug is hard to reproduce, probably somewhere in X, testcase would be probably -// difficult to make, and so on - just don't release the grabs and only ignore the events instead -void TDEGlobalAccelPrivate::suspend( bool s ) -{ - m_suspended = s; -} - -bool TDEGlobalAccelPrivate::emitSignal( Signal ) -{ - return false; -} - -bool TDEGlobalAccelPrivate::connectKey( TDEAccelAction& action, const KKeyServer::Key& key ) - { return grabKey( key, true, &action ); } -bool TDEGlobalAccelPrivate::connectKey( const KKeyServer::Key& key ) - { return grabKey( key, true, 0 ); } -bool TDEGlobalAccelPrivate::disconnectKey( TDEAccelAction& action, const KKeyServer::Key& key ) - { return grabKey( key, false, &action ); } -bool TDEGlobalAccelPrivate::disconnectKey( const KKeyServer::Key& key ) - { return grabKey( key, false, 0 ); } - -bool TDEGlobalAccelPrivate::grabKey( const KKeyServer::Key& key, bool bGrab, TDEAccelAction* pAction ) -{ - if( !key.code() ) { - kdWarning(125) << "TDEGlobalAccelPrivate::grabKey( " << key.key().toStringInternal() << ", " << bGrab << ", \"" << (pAction ? pAction->name().latin1() : "(null)") << "\" ): Tried to grab key with null code." << endl; - return false; - } - - // Make sure that grab masks have been initialized. - if( g_keyModMaskXOnOrOff == 0 ) { - calculateGrabMasks(); - } - - uchar keyCodeX = key.code(); - uint keyModX = key.mod() & g_keyModMaskXAccel; // Get rid of any non-relevant bits in mod - // HACK: make Alt+Print work - // only do this for the Xorg default keyboard keycodes, - // other mappings (e.g. evdev) don't need or want it - if( key.sym() == XK_Sys_Req && XkbKeycodeToKeysym( tqt_xdisplay(), 111, 0, 0 ) == XK_Print ) { - keyModX |= KKeyServer::modXAlt(); - keyCodeX = 111; - } - // If the MODE_SWITCH modifier was set in the original key, and was truncated in g_keyModMaskXAccel, XGrabKey will grab the wrong key - // See Bug 1676 - if ((key.mod() & KKeyServer::MODE_SWITCH) && (!(g_keyModMaskXAccel & KKeyServer::MODE_SWITCH))) { - // FIXME - // Is there any way to make AltGr-based character sequences work with XGrabKey? - kdWarning(125) << "TDEGlobalAccelPrivate::grabKey( " << key.key().toStringInternal() << ", " << bGrab << ", \"" << (pAction ? pAction->name().latin1() : "(null)") << "\" ): Tried to grab key requiring ISO_Level3_Shift (AltGr) sequence." << endl; - return false; - } - - kdDebug(125) << TQString(TQString( "grabKey( key: '%1', bGrab: %2 ): keyCodeX: %3 keyModX: %4\n" ) - .arg( key.key().toStringInternal() ).arg( bGrab ) - .arg( keyCodeX, 0, 16 ).arg( keyModX, 0, 16 )); - if( !keyCodeX ) { - return false; - } - -#ifdef TQ_WS_X11 - KXErrorHandler handler( XGrabErrorHandler ); -#endif - // We'll have to grab 8 key modifier combinations in order to cover all - // combinations of CapsLock, NumLock, ScrollLock. - // Does anyone with more X-savvy know how to set a mask on tqt_xrootwin so that - // the irrelevant bits are always ignored and we can just make one XGrabKey - // call per accelerator? -- ellis -#ifndef NDEBUG - TQString sDebug = TQString("\tcode: 0x%1 state: 0x%2 | ").arg(keyCodeX,0,16).arg(keyModX,0,16); -#endif - uint keyModMaskX = ~g_keyModMaskXOnOrOff; - for( uint irrelevantBitsMask = 0; irrelevantBitsMask <= 0xff; irrelevantBitsMask++ ) { - if( (irrelevantBitsMask & keyModMaskX) == 0 ) { -#ifndef NDEBUG - sDebug += TQString("0x%3, ").arg(irrelevantBitsMask, 0, 16); -#endif - if( bGrab ) - XGrabKey( tqt_xdisplay(), keyCodeX, keyModX | irrelevantBitsMask, - tqt_xrootwin(), True, GrabModeAsync, GrabModeSync ); - else - XUngrabKey( tqt_xdisplay(), keyCodeX, keyModX | irrelevantBitsMask, tqt_xrootwin() ); - } - } -#ifndef NDEBUG - kdDebug(125) << sDebug << endl; -#endif - - bool failed = false; - if( bGrab ) { -#ifdef TQ_WS_X11 - failed = handler.error( true ); // sync now -#endif - // If grab failed, then ungrab any grabs that could possibly succeed - if( failed ) { - kdDebug(125) << "grab failed!\n"; - for( uint m = 0; m <= 0xff; m++ ) { - if(( m & keyModMaskX ) == 0 ) - XUngrabKey( tqt_xdisplay(), keyCodeX, keyModX | m, tqt_xrootwin() ); - } - } - } - if( !failed ) - { - CodeMod codemod; - codemod.code = keyCodeX; - codemod.mod = keyModX; - if( key.mod() & KKeyServer::MODE_SWITCH ) - codemod.mod |= KKeyServer::MODE_SWITCH; - - if( bGrab ) - m_rgCodeModToAction.insert( codemod, pAction ); - else - m_rgCodeModToAction.remove( codemod ); - } - return !failed; -} - -bool TDEGlobalAccelPrivate::x11Event( XEvent* pEvent ) -{ - //kdDebug(125) << "x11EventFilter( type = " << pEvent->type << " )" << endl; - switch( pEvent->type ) { - case MappingNotify: - XRefreshKeyboardMapping( &pEvent->xmapping ); - x11MappingNotify(); - return false; - case XKeyPress: - if( x11KeyPress( pEvent ) ) { - return true; - } - default: - return TQWidget::x11Event( pEvent ); - } -} - -void TDEGlobalAccelPrivate::x11MappingNotify() -{ - kdDebug(125) << "TDEGlobalAccelPrivate::x11MappingNotify()" << endl; - // Maybe the X modifier map has been changed. - KKeyServer::initializeMods(); - calculateGrabMasks(); - // Do new XGrabKey()s. - updateConnections(); -} - -void TDEGlobalAccelPrivate::fakeKeyPressed(unsigned int keyCode) { - CodeMod codemod; - codemod.code = keyCode; - codemod.mod = 0; - - KKey key(keyCode, 0); - - kdDebug(125) << "fakeKeyPressed: seek " << key.toStringInternal() - << TQString(TQString( " 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 ) { - TDEAccelAction* pAction = *it; - kdDebug(125) << "\tcode: " << TQString::number(it.key().code, 16) << " mod: " << TQString::number(it.key().mod, 16) - << (pAction ? TQString(" name: \"%1\" shortcut: %2").arg(pAction->name()).arg(pAction->shortcut().toStringInternal()) : TQString()) - << endl; - } -#endif - return; - } - - TDEAccelAction* pAction = m_rgCodeModToAction[codemod]; - - if( !pAction ) { - static bool recursion_block = false; - if( !recursion_block ) { - recursion_block = true; - TQPopupMenu* pMenu = createPopupMenu( 0, KKeySequence(key) ); - connect( pMenu, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotActivated(int)) ); - pMenu->exec( TQPoint( 0, 0 ) ); - disconnect( pMenu, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotActivated(int))); - delete pMenu; - recursion_block = false; - } - } else if( !pAction->objSlotPtr() || !pAction->isEnabled() ) - return; - else - activate( pAction, KKeySequence(key) ); -} - -bool TDEGlobalAccelPrivate::x11KeyPress( const XEvent *pEvent ) -{ - // do not change this line unless you really really know what you are doing (Matthias) - if ( !TQWidget::keyboardGrabber() && !TQApplication::activePopupWidget() ) { - XUngrabKeyboard( tqt_xdisplay(), pEvent->xkey.time ); - XFlush( tqt_xdisplay()); // avoid X(?) bug - } - - if( !isEnabledInternal() || m_suspended ) { - return false; - } - - CodeMod codemod; - codemod.code = pEvent->xkey.keycode; - codemod.mod = pEvent->xkey.state & (g_keyModMaskXAccel | KKeyServer::MODE_SWITCH); - - // If numlock is active and a keypad key is pressed, XOR the SHIFT state. - // e.g., KP_4 => Shift+KP_Left, and Shift+KP_4 => KP_Left. - if( pEvent->xkey.state & KKeyServer::modXNumLock() ) { - // TODO: what's the xor operator in c++? - uint sym = XkbKeycodeToKeysym( tqt_xdisplay(), codemod.code, 0, 0 ); - // If this is a keypad key, - if( sym >= XK_KP_Space && sym <= XK_KP_9 ) { - switch( sym ) { - // Leave the following keys unaltered - // FIXME: The proper solution is to see which keysyms don't change when shifted. - case XK_KP_Multiply: - case XK_KP_Add: - case XK_KP_Subtract: - case XK_KP_Divide: - break; - default: - if( codemod.mod & KKeyServer::modXShift() ) - codemod.mod &= ~KKeyServer::modXShift(); - else - codemod.mod |= KKeyServer::modXShift(); - } - } - } - - KKeyNative keyNative( pEvent ); - KKey key = keyNative; - - kdDebug(125) << "x11KeyPress: seek " << key.toStringInternal() - << TQString(TQString( " keyCodeX: %1 state: %2 keyModX: %3" ) - .arg( codemod.code, 0, 16 ).arg( pEvent->xkey.state, 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 ) { - TDEAccelAction* pAction = *it; - kdDebug(125) << "\tcode: " << TQString::number(it.key().code, 16) << " mod: " << TQString::number(it.key().mod, 16) - << (pAction ? TQString(" name: \"%1\" shortcut: %2").arg(pAction->name()).arg(pAction->shortcut().toStringInternal()) : TQString()) - << endl; - } -#endif - return false; - } - - TDEAccelAction* pAction = m_rgCodeModToAction[codemod]; - - if( !pAction ) { - static bool recursion_block = false; - if( !recursion_block ) { - recursion_block = true; - TQPopupMenu* pMenu = createPopupMenu( 0, KKeySequence(key) ); - connect( pMenu, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotActivated(int)) ); - pMenu->exec( TQPoint( 0, 0 ) ); - disconnect( pMenu, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotActivated(int))); - delete pMenu; - recursion_block = false; - } - } else if( !pAction->objSlotPtr() || !pAction->isEnabled() ) - return false; - else - activate( pAction, KKeySequence(key) ); - - return true; -} - -void TDEGlobalAccelPrivate::activate( TDEAccelAction* pAction, const KKeySequence& seq ) -{ - kdDebug(125) << "TDEGlobalAccelPrivate::activate( \"" << pAction->name() << "\" ) " << endl; - - TQRegExp rexPassIndex( "([ ]*int[ ]*)" ); - TQRegExp rexPassInfo( " TQString" ); - TQRegExp rexIndex( " ([0-9]+)$" ); - - // If the slot to be called accepts an integer index - // and an index is present at the end of the action's name, - // then send the slot the given index #. - if( rexPassIndex.search( pAction->methodSlotPtr() ) >= 0 && rexIndex.search( pAction->name() ) >= 0 ) { - int n = rexIndex.cap(1).toInt(); - kdDebug(125) << "Calling " << pAction->methodSlotPtr() << " int = " << n << endl; - int slot_id = pAction->objSlotPtr()->metaObject()->findSlot( normalizeSignalSlot( pAction->methodSlotPtr() ).data() + 1, true ); - if( slot_id >= 0 ) { - TQUObject o[2]; - static_QUType_int.set(o+1,n); - const_cast< TQObject* >( pAction->objSlotPtr())->tqt_invoke( slot_id, o ); - } - } else if( rexPassInfo.search( pAction->methodSlotPtr() ) ) { - int slot_id = pAction->objSlotPtr()->metaObject()->findSlot( normalizeSignalSlot( pAction->methodSlotPtr() ).data() + 1, true ); - if( slot_id >= 0 ) { - TQUObject o[4]; - static_QUType_TQString.set(o+1,pAction->name()); - static_QUType_TQString.set(o+2,pAction->label()); - static_QUType_ptr.set(o+3,&seq); - const_cast< TQObject* >( pAction->objSlotPtr())->tqt_invoke( slot_id, o ); - } - } else { - int slot_id = pAction->objSlotPtr()->metaObject()->findSlot( normalizeSignalSlot( pAction->methodSlotPtr() ).data() + 1, true ); - if( slot_id >= 0 ) - const_cast< TQObject* >( pAction->objSlotPtr())->tqt_invoke( slot_id, 0 ); - } -} - -void TDEGlobalAccelPrivate::slotActivated( int iAction ) -{ - TDEAccelAction* pAction = TDEAccelBase::actions().actionPtr( iAction ); - if( pAction ) - activate( pAction, KKeySequence() ); -} - -#include "kglobalaccel_x11.moc" - -#endif // !TQ_WS_X11 diff --git a/tdecore/kglobalaccel_x11.h b/tdecore/kglobalaccel_x11.h deleted file mode 100644 index 1502d89cb..000000000 --- a/tdecore/kglobalaccel_x11.h +++ /dev/null @@ -1,110 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2001,2002 Ellis Whitehead - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef _KGLOBALACCEL_X11_H -#define _KGLOBALACCEL_X11_H - -#include -#include - -#include "tdeaccelbase.h" -#include "kkeyserver_x11.h" -#include "tdeshortcut.h" - -/** - * @internal - */ -class TDEGlobalAccelPrivate : public TQWidget, public TDEAccelBase -{ - friend class TDEGlobalAccel; - TQ_OBJECT - public: - TDEGlobalAccelPrivate(); - virtual ~TDEGlobalAccelPrivate(); - - virtual void setEnabled( bool bEnabled ); - - virtual bool emitSignal( Signal signal ); - virtual bool connectKey( TDEAccelAction& action, const KKeyServer::Key& key ); - virtual bool connectKey( const KKeyServer::Key& key ); - virtual bool disconnectKey( TDEAccelAction& action, const KKeyServer::Key& key ); - virtual bool disconnectKey( const KKeyServer::Key& key ); - - protected: - /** - * @internal - * Represents a key code and modifier combination. - */ - class CodeMod - { - public: - /** - * The key code of the CodeMod. - */ - uchar code; - /** - * The modifier flags of the CodeMod. - */ - uint mod; - - /** - * Compares two CodeMods. - */ - bool operator < ( const CodeMod& b ) const - { - if( code < b.code ) return true; - if( code == b.code && mod < b.mod ) return true; - return false; - } - }; - typedef TQMap CodeModMap; - - CodeModMap m_rgCodeModToAction; - - /** - * @param bGrab Set to true to grab key, false to ungrab key. - */ - bool grabKey( const KKeyServer::Key&, bool bGrab, TDEAccelAction* ); - - /** - * Filters X11 events ev for key bindings in the accelerator dictionary. - * If a match is found the activated activated is emitted and the function - * returns true. Return false if the event is not processed. - * - * This is public for compatibility only. You do not need to call it. - */ - virtual bool x11Event( XEvent* ); - void x11MappingNotify(); - bool x11KeyPress( const XEvent *pEvent ); - void activate( TDEAccelAction* pAction, const KKeySequence& seq ); - virtual bool isEnabledInternal() const; - static void blockShortcuts( bool block ); - void disableBlocking( bool disable ); - void suspend( bool s ); - - protected slots: - void slotActivated( int iAction ); - void fakeKeyPressed(unsigned int keyCode); - private: - bool m_blocked; - bool m_blockingDisabled; - bool m_suspended; -}; - -#endif // _KGLOBALACCEL_X11_H diff --git a/tdecore/tdeapplication.cpp b/tdecore/tdeapplication.cpp index 2cdc4b3a4..985817732 100644 --- a/tdecore/tdeapplication.cpp +++ b/tdecore/tdeapplication.cpp @@ -93,7 +93,7 @@ #include #include #include -#include +#include #if defined TQ_WS_X11 #include diff --git a/tdecore/tdeglobalaccel.cpp b/tdecore/tdeglobalaccel.cpp new file mode 100644 index 000000000..dd2a93b6f --- /dev/null +++ b/tdecore/tdeglobalaccel.cpp @@ -0,0 +1,139 @@ +/* This file is part of the KDE libraries + Copyright (C) 2001,2002 Ellis Whitehead + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "tdeglobalaccel.h" +#ifdef TQ_WS_X11 +#include "tdeglobalaccel_x11.h" +#elif defined(TQ_WS_WIN) +#include "tdeglobalaccel_win.h" +#elif defined(TQ_WS_MACX) +#include "tdeglobalaccel_mac.h" +#else +#include "tdeglobalaccel_emb.h" +#endif + +#include +#include "tdeaccelbase.h" +#include +#include +#include + +//---------------------------------------------------- + +TDEGlobalAccel::TDEGlobalAccel( TQObject* pParent, const char* psName ) +: TQObject( pParent, psName ) +{ + kdDebug(125) << "TDEGlobalAccel(): this = " << this << endl; + d = new TDEGlobalAccelPrivate(); +} + +TDEGlobalAccel::~TDEGlobalAccel() +{ + kdDebug(125) << "~TDEGlobalAccel(): this = " << this << endl; + delete d; +} + +/* +void TDEGlobalAccel::clear() + { d->clearActions(); } +*/ +TDEAccelActions& TDEGlobalAccel::actions() + { return d->TDEAccelBase::actions(); } + +const TDEAccelActions& TDEGlobalAccel::actions() const + { return d->TDEAccelBase::actions(); } + +bool TDEGlobalAccel::isEnabled() + { return ((TDEAccelBase*)d)->isEnabled(); } + +void TDEGlobalAccel::setEnabled( bool bEnabled ) + { d->setEnabled( bEnabled ); } + +void TDEGlobalAccel::suspend( bool s ) + { d->suspend( s ); } + +void TDEGlobalAccel::blockShortcuts( bool block ) + { TDEGlobalAccelPrivate::blockShortcuts( block ); } + +void TDEGlobalAccel::disableBlocking( bool disable ) + { d->disableBlocking( disable ); } + +TDEAccelAction* TDEGlobalAccel::insert( const TQString& sAction, const TQString& sDesc, const TQString& sHelp, + const TDEShortcut& cutDef3, const TDEShortcut& cutDef4, + const TQObject* pObjSlot, const char* psMethodSlot, + bool bConfigurable, bool bEnabled ) +{ + return d->insert( sAction, sDesc, sHelp, + cutDef3, cutDef4, + pObjSlot, psMethodSlot, + bConfigurable, bEnabled ); +} + +TDEAccelAction* TDEGlobalAccel::insert( const TQString& sName, const TQString& sDesc ) + { return d->insert( sName, sDesc ); } +bool TDEGlobalAccel::updateConnections() + { return d->updateConnections(); } + +bool TDEGlobalAccel::remove( const TQString& sAction ) + { return d->remove( sAction ); } + +const TDEShortcut& TDEGlobalAccel::shortcut( const TQString& sAction ) const +{ + const TDEAccelAction* pAction = d->TDEAccelBase::actions().actionPtr( sAction ); + return (pAction) ? pAction->shortcut() : TDEShortcut::null(); +} + +bool TDEGlobalAccel::setShortcut( const TQString& sAction, const TDEShortcut& cut ) + { return d->setShortcut( sAction, cut ); } +bool TDEGlobalAccel::setSlot( const TQString& sAction, const TQObject* pObjSlot, const char* psMethodSlot ) + { return d->setActionSlot( sAction, pObjSlot, psMethodSlot ); } +TQString TDEGlobalAccel::label( const TQString& sAction ) const +{ + const TDEAccelAction* pAction = d->TDEAccelBase::actions().actionPtr( sAction ); + return (pAction) ? pAction->label() : TQString(); +} +bool TDEGlobalAccel::setActionEnabled( const TQString& sAction, bool bEnable ) +{ + return d->setActionEnabled( sAction, bEnable ); +} + +const TQString& TDEGlobalAccel::configGroup() const + { return d->configGroup(); } +// for tdemultimedia/kmix +void TDEGlobalAccel::setConfigGroup( const TQString& s ) + { d->setConfigGroup( s ); } + +bool TDEGlobalAccel::readSettings( TDEConfigBase* pConfig ) + { d->readSettings( pConfig ); return true; } +bool TDEGlobalAccel::writeSettings( TDEConfigBase* pConfig ) const + { d->writeSettings( pConfig ); return true; } +bool TDEGlobalAccel::writeSettings( TDEConfigBase* pConfig, bool bGlobal ) const +{ + d->setConfigGlobal( bGlobal ); + d->writeSettings( pConfig ); + return true; +} + +bool TDEGlobalAccel::useFourModifierKeys() + { return TDEAccelAction::useFourModifierKeys(); } + +void TDEGlobalAccel::virtual_hook( int, void* ) +{ /*BASE::virtual_hook( id, data );*/ } + +#include "tdeglobalaccel.moc" diff --git a/tdecore/tdeglobalaccel.h b/tdecore/tdeglobalaccel.h new file mode 100644 index 000000000..be34a3cdd --- /dev/null +++ b/tdecore/tdeglobalaccel.h @@ -0,0 +1,239 @@ +/* This file is part of the KDE libraries + Copyright (C) 2001,2002 Ellis Whitehead + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _TDEGLOBALACCEL_H_ +#define _TDEGLOBALACCEL_H_ + +#include +#include + +class TQPopupMenu; +class TQWidget; +class TDEAccelAction; +class TDEAccelActions; +class TDEConfigBase; + +class TDEGlobalAccelPrivate; + +/** +* TDEGlobalAccel allows you to have global accelerators that are independent of +* the focused window. Unlike TDEAccel it does not matter which window is +* currently active. +* +* @see TDEAccel +* @see TDEAccelShortcutList +* @see KKeyChooser +* @see KKeyDialog +* @short Configurable global shortcut support +*/ +class TDECORE_EXPORT TDEGlobalAccel : public TQObject +{ + TQ_OBJECT + public: + /** + * Creates a new TDEGlobalAccel object with the given pParent and + * psName. + * @param pParent the parent of the TQObject + * @param psName the name of the TQObject + */ + TDEGlobalAccel( TQObject* pParent, const char* psName = 0 ); + virtual ~TDEGlobalAccel(); + + /** + * Checks whether the accelerators are enabled. + * @return true if the TDEGlobalAccel is enabled + */ + bool isEnabled(); + + /** + * Enables or disables the TDEGlobalAccel + * @param bEnabled true if the TDEGlobalAccel should be enabled, false if it + * should be disabled. + */ + void setEnabled( bool bEnabled ); + + /** + * Create an accelerator action. + * + * Usage: + *\code + * insert( "Do Something", i18n("Do Something"), + * i18n("This action allows you to do something really great with this program to " + * "the currently open document."), + * ALT+CTRL+Key_Q, KKey::QtWIN+CTRL+Key_Q, this, TQ_SLOT(slotDoSomething()) ); + *\endcode + * + * @param sAction The internal name of the action. + * @param sLabel An i18n'ized short description of the action displayed when + * using KKeyChooser to reconfigure the shortcuts. + * @param sWhatsThis An extended description of the action. + * @param cutDef3 The default 3 modifier scheme shortcut. + * @param cutDef4 The default 4 modifier scheme shortcut. + * @param pObjSlot Pointer to the slot object. + * @param psMethodSlot Pointer to the slot method. + * @param bConfigurable Allow the user to change this shortcut if set to 'true'. + * @param bEnabled The action will be activated by the shortcut if set to 'true'. + */ + TDEAccelAction* insert( const TQString& sAction, const TQString& sLabel, const TQString& sWhatsThis, + const TDEShortcut& cutDef3, const TDEShortcut& cutDef4, + const TQObject* pObjSlot, const char* psMethodSlot, + bool bConfigurable = true, bool bEnabled = true ); + + /** + * Removes the accelerator action identified by the name. + * Remember to also call updateConnections(). + * @param sAction the name of the action to remove + * @since 3.1 + */ + bool remove( const TQString& sAction ); + + /** + * Use this to insert a label into the action list. This will be + * displayed when the user configures shortcuts. + * @param sName of the of the action to insert + * @param sLabel a user-readable (i18n!) name for the action + * @return the TDEAccelAction of the action + */ + TDEAccelAction* insert( const TQString& sName, const TQString& sLabel ); + + /** + * Updates the connections of the accelerations after changing them. + * @return true if successful, false otherwise + */ + bool updateConnections(); + + /** + * Return the shortcut associated with the action named by @p sAction. + * @param sAction the name of the action + * @return the shortcut. If the action does not exist a null shortcut will be returned. + */ + const TDEShortcut& shortcut( const TQString& sAction ) const; + /** + * Set the shortcut to be associated with the action named by @p sAction. + * @param sAction the name of the action + * @param shortcut the shortcut for the action + * @return true if successful, false otherwise + */ + bool setShortcut( const TQString& sAction, const TDEShortcut &shortcut ); + /** + * Set the slot to be called when the shortcut of the action named + * by @p sAction is pressed. + * @param sAction the name of the action + * @param pObjSlot the receiver of the signal + * @param psMethodSlot the slot to receive the signal + * @return true if successful, false otherwise + */ + bool setSlot( const TQString& sAction, const TQObject* pObjSlot, const char* psMethodSlot ); + + /** + * Enables or disables action @p sAction. + * @since 3.4 + */ + bool setActionEnabled( const TQString& sAction, bool bEnable ); + /** + * Return the label (i18n'ized short description) associated with the action named by @p sAction. + * @param sAction the name of the action + * @return the label + * @since 3.3 + */ + TQString label( const TQString& sAction ) const; + + /** + * Returns the configuration group that is used to save the accelerators. + * @return the configuration group + * @see TDEConfig + */ + const TQString& configGroup() const; + + /** + * Sets the configuration group that is used to save the accelerators. + * @param cg the configuration group + * @see TDEConfig + */ + void setConfigGroup( const TQString &cg ); + + /** + * Read all shortcuts from @p pConfig, or (if @p pConfig + * is zero) from the application's configuration file + * TDEGlobal::config(). + * @param pConfig the configuration file to read from, or 0 for the application + * configuration file + * @return true if successful, false otherwise + */ + bool readSettings( TDEConfigBase* pConfig = 0 ); + + /** + * Write the current shortcuts to @p pConfig, + * or (if @p pConfig is zero) to the application's + * configuration file. + * @param pConfig the configuration file to read from, or 0 for the application + * configuration file + * @return true if successful, false otherwise + * @since 3.1 + */ + bool writeSettings( TDEConfigBase* pConfig = 0 ) const; + // BCI: merge these two writeSettings methods in KDE 4.0 + /** + * Write the current shortcuts to @p pConfig, + * or (if @p pConfig is zero) to the application's + * configuration file. Alternatively, if bGlobal is true, then write + * to kdeglobals. + * @param pConfig the configuration file to read from, or 0 for the application + * configuration file + * @param bGlobal if true write the configuration to the kde global settings + * @return true if successful, false otherwise + */ + bool writeSettings( TDEConfigBase* pConfig, bool bGlobal ) const; + + /** + * @internal -- this a wrapper function to + * TDEAccelActions::useFourModifierKeys(). + */ + static bool useFourModifierKeys(); + + /** + * @internal + */ + static void blockShortcuts( bool block ); + /** + * @internal + */ + void disableBlocking( bool disable ); + + /** + * @internal + */ + // like setEnabled(), but doesn't ungrab (see in TDEGlobalAccelPrivate) + void suspend( bool s ); + +private: + + TDEAccelActions& actions(); + const TDEAccelActions& actions() const; + + friend class TDEGlobalAccelPrivate; + friend class TDEAccelShortcutList; +protected: + /** \internal */ + virtual void virtual_hook( int id, void* data ); +private: + class TDEGlobalAccelPrivate* d; +}; + +#endif // _TDEGLOBALACCEL_H_ diff --git a/tdecore/tdeglobalaccel_emb.h b/tdecore/tdeglobalaccel_emb.h new file mode 100644 index 000000000..2fd16bd44 --- /dev/null +++ b/tdecore/tdeglobalaccel_emb.h @@ -0,0 +1,18 @@ +#ifndef _TDEGLOBALACCEL_EMB_H +#define _TDEGLOBALACCEL_EMB_H + +#include "tdeaccelbase.h" +#include "tdeshortcut.h" + +class TDEGlobalAccelPrivate +{ +public: + TDEGlobalAccelPrivate(); + + virtual void setEnabled( bool bEnabled ); + + virtual bool connectKey( TDEAccelAction&, KKeySequence ); + virtual bool disconnectKey( TDEAccelAction&, KKeySequence ); +}; + +#endif // _TDEGLOBALACCEL_EMB_H diff --git a/tdecore/tdeglobalaccel_mac.h b/tdecore/tdeglobalaccel_mac.h new file mode 100644 index 000000000..c21533916 --- /dev/null +++ b/tdecore/tdeglobalaccel_mac.h @@ -0,0 +1,31 @@ +#ifndef _TDEGLOBALACCEL_MAC_H +#define _TDEGLOBALACCEL_MAC_H + +#include + +#include "tdeshortcut.h" +#include "tdeaccelbase.h" + +class TDEGlobalAccelPrivate: public TDEAccelBase +{ +public: + TDEGlobalAccelPrivate() + : TDEAccelBase(TDEAccelBase::NATIVE_KEYS) + {} + + // reimplemented pure virtuals + void setEnabled( bool bEnabled ) + { Q_UNUSED(bEnabled); } + bool emitSignal( Signal signal ) + { Q_UNUSED(signal); return false; } + bool connectKey( TDEAccelAction& action, const KKeyServer::Key& key) + { Q_UNUSED(action); Q_UNUSED(key); return false; } + bool connectKey( const KKeyServer::Key& key) + { Q_UNUSED(key); return false; } + bool disconnectKey( TDEAccelAction&, const KKeyServer::Key& key) + { Q_UNUSED(key); return false; } + bool disconnectKey( const KKeyServer::Key& ) + { return false; } +}; + +#endif // _TDEGLOBALACCEL_MAC_H diff --git a/tdecore/tdeglobalaccel_win.cpp b/tdecore/tdeglobalaccel_win.cpp new file mode 100644 index 000000000..faf3708f4 --- /dev/null +++ b/tdecore/tdeglobalaccel_win.cpp @@ -0,0 +1,345 @@ +/* This file is part of the KDE libraries + Copyright (C) 2001,2002 Ellis Whitehead + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#include +#ifdef TQ_WS_WIN + +#include "tdeglobalaccel_win.h" +#include "tdeglobalaccel.h" +#include "kkeyserver_x11.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +//---------------------------------------------------- + +static TQValueList< TDEGlobalAccelPrivate* >* all_accels = 0; + +TDEGlobalAccelPrivate::TDEGlobalAccelPrivate() +: TDEAccelBase( TDEAccelBase::NATIVE_KEYS ) +, m_blocked( false ) +, m_blockingDisabled( false ) +{ + if( all_accels == NULL ) + all_accels = new TQValueList< TDEGlobalAccelPrivate* >; + all_accels->append( this ); + m_sConfigGroup = "Global Shortcuts"; +// tdeApp->installX11EventFilter( this ); +} + +TDEGlobalAccelPrivate::~TDEGlobalAccelPrivate() +{ + // TODO: Need to release all grabbed keys if the main window is not shutting down. + //for( CodeModMap::ConstIterator it = m_rgCodeModToAction.begin(); it != m_rgCodeModToAction.end(); ++it ) { + // const CodeMod& codemod = it.key(); + //} + all_accels->remove( this ); + if( all_accels->count() == 0 ) { + delete all_accels; + all_accels = NULL; + } +} + +void TDEGlobalAccelPrivate::setEnabled( bool bEnable ) +{ + m_bEnabled = bEnable; + //updateConnections(); +} + +void TDEGlobalAccelPrivate::blockShortcuts( bool block ) +{ + if( all_accels == NULL ) + return; + for( TQValueList< TDEGlobalAccelPrivate* >::ConstIterator it = all_accels->begin(); + it != all_accels->end(); + ++it ) { + if( (*it)->m_blockingDisabled ) + continue; + (*it)->m_blocked = block; + (*it)->updateConnections(); + } +} + +void TDEGlobalAccelPrivate::disableBlocking( bool block ) +{ + m_blockingDisabled = block; +} + +bool TDEGlobalAccelPrivate::isEnabledInternal() const +{ + return TDEAccelBase::isEnabled() && !m_blocked; +} + +bool TDEGlobalAccelPrivate::emitSignal( Signal ) +{ + return false; +} + +bool TDEGlobalAccelPrivate::connectKey( TDEAccelAction& action, const KKeyServer::Key& key ) + { return grabKey( key, true, &action ); } +bool TDEGlobalAccelPrivate::connectKey( const KKeyServer::Key& key ) + { return grabKey( key, true, 0 ); } +bool TDEGlobalAccelPrivate::disconnectKey( TDEAccelAction& action, const KKeyServer::Key& key ) + { return grabKey( key, false, &action ); } +bool TDEGlobalAccelPrivate::disconnectKey( const KKeyServer::Key& key ) + { return grabKey( key, false, 0 ); } + +bool TDEGlobalAccelPrivate::grabKey( const KKeyServer::Key& key, bool bGrab, TDEAccelAction* pAction ) +{ + /* + if( !key.code() ) { + kdWarning(125) << "TDEGlobalAccelPrivate::grabKey( " << key.key().toStringInternal() << ", " << bGrab << ", \"" << (pAction ? pAction->name().latin1() : "(null)") << "\" ): Tried to grab key with null code." << endl; + return false; + } + + // Make sure that grab masks have been initialized. + if( g_keyModMaskXOnOrOff == 0 ) + calculateGrabMasks(); + + uchar keyCodeX = key.code(); + uint keyModX = key.mod() & g_keyModMaskXAccel; // Get rid of any non-relevant bits in mod + // HACK: make Alt+Print work + if( key.sym() == XK_Sys_Req ) { + keyModX |= KKeyServer::modXAlt(); + keyCodeX = 111; + } + + kdDebug(125) << TQString( "grabKey( key: '%1', bGrab: %2 ): keyCodeX: %3 keyModX: %4\n" ) + .arg( key.key().toStringInternal() ).arg( bGrab ) + .arg( keyCodeX, 0, 16 ).arg( keyModX, 0, 16 ); + if( !keyCodeX ) + return false; + + // We'll have to grab 8 key modifier combinations in order to cover all + // combinations of CapsLock, NumLock, ScrollLock. + // Does anyone with more X-savvy know how to set a mask on tqt_xrootwin so that + // the irrelevant bits are always ignored and we can just make one XGrabKey + // call per accelerator? -- ellis +#ifndef NDEBUG + TQString sDebug = TQString("\tcode: 0x%1 state: 0x%2 | ").arg(keyCodeX,0,16).arg(keyModX,0,16); +#endif + uint keyModMaskX = ~g_keyModMaskXOnOrOff; + for( uint irrelevantBitsMask = 0; irrelevantBitsMask <= 0xff; irrelevantBitsMask++ ) { + if( (irrelevantBitsMask & keyModMaskX) == 0 ) { +#ifndef NDEBUG + sDebug += TQString("0x%3, ").arg(irrelevantBitsMask, 0, 16); +#endif + if( bGrab ) + XGrabKey( tqt_xdisplay(), keyCodeX, keyModX | irrelevantBitsMask, + tqt_xrootwin(), True, GrabModeAsync, GrabModeSync ); + else + XUngrabKey( tqt_xdisplay(), keyCodeX, keyModX | irrelevantBitsMask, tqt_xrootwin() ); + } + } +#ifndef NDEBUG + kdDebug(125) << sDebug << endl; +#endif + + bool failed = false; + if( bGrab ) { +#ifdef TQ_WS_X11 + failed = handler.error( true ); // sync now +#endif + // If grab failed, then ungrab any grabs that could possibly succeed + if( failed ) { + kdDebug(125) << "grab failed!\n"; + for( uint m = 0; m <= 0xff; m++ ) { + if( m & keyModMaskX == 0 ) + XUngrabKey( tqt_xdisplay(), keyCodeX, keyModX | m, tqt_xrootwin() ); + } + } + } + if( !failed ) + { + CodeMod codemod; + codemod.code = keyCodeX; + codemod.mod = keyModX; + if( key.mod() & KKeyServer::MODE_SWITCH ) + codemod.mod |= KKeyServer::MODE_SWITCH; + + if( bGrab ) + m_rgCodeModToAction.insert( codemod, pAction ); + else + m_rgCodeModToAction.remove( codemod ); + } + return !failed;*/ + return false; +} + +/*bool TDEGlobalAccelPrivate::x11Event( XEvent* pEvent ) +{ + //kdDebug(125) << "x11EventFilter( type = " << pEvent->type << " )" << endl; + switch( pEvent->type ) { + case MappingNotify: + XRefreshKeyboardMapping( &pEvent->xmapping ); + x11MappingNotify(); + return false; + case XKeyPress: + if( x11KeyPress( pEvent ) ) + return true; + default: + return TQWidget::x11Event( pEvent ); + } +} + +void TDEGlobalAccelPrivate::x11MappingNotify() +{ + kdDebug(125) << "TDEGlobalAccelPrivate::x11MappingNotify()" << endl; + if( m_bEnabled ) { + // Maybe the X modifier map has been changed. + KKeyServer::initializeMods(); + calculateGrabMasks(); + // Do new XGrabKey()s. + updateConnections(); + } +} + +bool TDEGlobalAccelPrivate::x11KeyPress( const XEvent *pEvent ) +{ + // do not change this line unless you really really know what you are doing (Matthias) + if ( !TQWidget::keyboardGrabber() && !TQApplication::activePopupWidget() ) { + XUngrabKeyboard( tqt_xdisplay(), pEvent->xkey.time ); + XFlush( tqt_xdisplay()); // avoid X(?) bug + } + + if( !m_bEnabled ) + return false; + + CodeMod codemod; + codemod.code = pEvent->xkey.keycode; + codemod.mod = pEvent->xkey.state & (g_keyModMaskXAccel | KKeyServer::MODE_SWITCH); + + // If numlock is active and a keypad key is pressed, XOR the SHIFT state. + // e.g., KP_4 => Shift+KP_Left, and Shift+KP_4 => KP_Left. + if( pEvent->xkey.state & KKeyServer::modXNumLock() ) { + // TODO: what's the xor operator in c++? + uint sym = XkbKeycodeToKeysym( tqt_xdisplay(), codemod.code, 0, 0 ); + // If this is a keypad key, + if( sym >= XK_KP_Space && sym <= XK_KP_9 ) { + switch( sym ) { + // Leave the following keys unaltered + // FIXME: The proper solution is to see which keysyms don't change when shifted. + case XK_KP_Multiply: + case XK_KP_Add: + case XK_KP_Subtract: + case XK_KP_Divide: + break; + default: + if( codemod.mod & KKeyServer::modXShift() ) + codemod.mod &= ~KKeyServer::modXShift(); + else + codemod.mod |= KKeyServer::modXShift(); + } + } + } + + KKeyNative keyNative( pEvent ); + KKey key = keyNative; + + kdDebug(125) << "x11KeyPress: seek " << key.toStringInternal() + << TQString( " keyCodeX: %1 state: %2 keyModX: %3" ) + .arg( codemod.code, 0, 16 ).arg( pEvent->xkey.state, 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 ) { + TDEAccelAction* pAction = *it; + kdDebug(125) << "\tcode: " << TQString::number(it.key().code, 16) << " mod: " << TQString::number(it.key().mod, 16) + << (pAction ? TQString(" name: \"%1\" shortcut: %2").arg(pAction->name()).arg(pAction->shortcut().toStringInternal()) : TQString::null) + << endl; + } +#endif + return false; + } + TDEAccelAction* pAction = m_rgCodeModToAction[codemod]; + + if( !pAction ) { + static bool recursion_block = false; + if( !recursion_block ) { + recursion_block = true; + TQPopupMenu* pMenu = createPopupMenu( 0, KKeySequence(key) ); + connect( pMenu, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotActivated(int)) ); + pMenu->exec( TQPoint( 0, 0 ) ); + disconnect( pMenu, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotActivated(int))); + delete pMenu; + recursion_block = false; + } + } else if( !pAction->objSlotPtr() || !pAction->isEnabled() ) + return false; + else + activate( pAction, KKeySequence(key) ); + + return true; +}*/ + +void TDEGlobalAccelPrivate::activate( TDEAccelAction* pAction, const KKeySequence& seq ) +{ + kdDebug(125) << "TDEGlobalAccelPrivate::activate( \"" << pAction->name() << "\" ) " << endl; + + TQRegExp rexPassIndex( "([ ]*int[ ]*)" ); + TQRegExp rexPassInfo( " TQString" ); + TQRegExp rexIndex( " ([0-9]+)$" ); + + // If the slot to be called accepts an integer index + // and an index is present at the end of the action's name, + // then send the slot the given index #. + if( rexPassIndex.search( pAction->methodSlotPtr() ) >= 0 && rexIndex.search( pAction->name() ) >= 0 ) { + int n = rexIndex.cap(1).toInt(); + kdDebug(125) << "Calling " << pAction->methodSlotPtr() << " int = " << n << endl; + int slot_id = pAction->objSlotPtr()->metaObject()->findSlot( normalizeSignalSlot( pAction->methodSlotPtr() ).data() + 1, true ); + if( slot_id >= 0 ) { + QUObject o[2]; + static_QUType_int.set(o+1,n); + const_cast< TQObject* >( pAction->objSlotPtr())->tqt_invoke( slot_id, o ); + } + } else if( rexPassInfo.search( pAction->methodSlotPtr() ) ) { + int slot_id = pAction->objSlotPtr()->metaObject()->findSlot( normalizeSignalSlot( pAction->methodSlotPtr() ).data() + 1, true ); + if( slot_id >= 0 ) { + QUObject o[4]; + static_QUType_QString.set(o+1,pAction->name()); + static_QUType_QString.set(o+2,pAction->label()); + static_QUType_ptr.set(o+3,&seq); + const_cast< TQObject* >( pAction->objSlotPtr())->tqt_invoke( slot_id, o ); + } + } else { + int slot_id = pAction->objSlotPtr()->metaObject()->findSlot( normalizeSignalSlot( pAction->methodSlotPtr() ).data() + 1, true ); + if( slot_id >= 0 ) + const_cast< TQObject* >( pAction->objSlotPtr())->tqt_invoke( slot_id, 0 ); + } +} + +void TDEGlobalAccelPrivate::slotActivated( int iAction ) +{ + TDEAccelAction* pAction = actions().actionPtr( iAction ); + if( pAction ) + activate( pAction, KKeySequence() ); +} + +#include "tdeglobalaccel_win.moc" + +#endif // !TQ_WS_WIN diff --git a/tdecore/tdeglobalaccel_win.h b/tdecore/tdeglobalaccel_win.h new file mode 100644 index 000000000..ec224a0f7 --- /dev/null +++ b/tdecore/tdeglobalaccel_win.h @@ -0,0 +1,77 @@ +/* This file is part of the KDE libraries + Copyright (C) 2001,2002 Ellis Whitehead + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _TDEGLOBALACCEL_WIN_H +#define _TDEGLOBALACCEL_WIN_H + +#include +#include + +#include "tdeaccelbase.h" +#include "kkeyserver.h" +#include "tdeshortcut.h" + +/** + * @internal + */ +class TDEGlobalAccelPrivate : public TQWidget, public TDEAccelBase +{ + friend class TDEGlobalAccel; + TQ_OBJECT + public: + TDEGlobalAccelPrivate(); + virtual ~TDEGlobalAccelPrivate(); + + virtual void setEnabled( bool bEnabled ); + + virtual bool emitSignal( Signal signal ); + virtual bool connectKey( TDEAccelAction& action, const KKeyServer::Key& key ); + virtual bool connectKey( const KKeyServer::Key& key ); + virtual bool disconnectKey( TDEAccelAction& action, const KKeyServer::Key& key ); + virtual bool disconnectKey( const KKeyServer::Key& key ); + + protected: + + /** + * @param bGrab Set to true to grab key, false to ungrab key. + */ + bool grabKey( const KKeyServer::Key&, bool bGrab, TDEAccelAction* ); + + /** + * Filters X11 events ev for key bindings in the accelerator dictionary. + * If a match is found the activated activated is emitted and the function + * returns true. Return false if the event is not processed. + * + * This is public for compatibility only. You do not need to call it. + */ +// virtual bool x11Event( XEvent* ); +// void x11MappingNotify(); +// bool x11KeyPress( const XEvent *pEvent ); + void activate( TDEAccelAction* pAction, const KKeySequence& seq ); + virtual bool isEnabledInternal() const; + static void blockShortcuts( bool block ); + void disableBlocking( bool disable ); + + protected slots: + void slotActivated( int iAction ); + bool m_blocked; + bool m_blockingDisabled; +}; + +#endif // _TDEGLOBALACCEL_WIN_H diff --git a/tdecore/tdeglobalaccel_x11.cpp b/tdecore/tdeglobalaccel_x11.cpp new file mode 100644 index 000000000..2bf6e0d3e --- /dev/null +++ b/tdecore/tdeglobalaccel_x11.cpp @@ -0,0 +1,451 @@ +/* This file is part of the KDE libraries + Copyright (C) 2001,2002 Ellis Whitehead + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#include +#ifdef TQ_WS_X11 + +#include "tdeglobalaccel_x11.h" +#include "tdeglobalaccel.h" +#include "kkeyserver_x11.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef TQ_WS_X11 +#include +#endif + +#include +#include +#include +#include +#include + +extern "C" { + static int XGrabErrorHandler( Display *, XErrorEvent *e ) { + if ( e->error_code != BadAccess ) { + kdWarning() << "grabKey: got X error " << e->type << " instead of BadAccess\n"; + } + return 1; + } +} + +// g_keyModMaskXAccel +// mask of modifiers which can be used in shortcuts +// (meta, alt, ctrl, shift) +// g_keyModMaskXOnOrOff +// mask of modifiers where we don't care whether they are on or off +// (caps lock, num lock, scroll lock) +static uint g_keyModMaskXAccel = 0; +static uint g_keyModMaskXOnOrOff = 0; + +static void calculateGrabMasks() +{ + g_keyModMaskXAccel = KKeyServer::accelModMaskX(); + g_keyModMaskXOnOrOff = + KKeyServer::modXLock() | + KKeyServer::modXNumLock() | + KKeyServer::modXScrollLock() | + KKeyServer::modXModeSwitch(); + //kdDebug() << "g_keyModMaskXAccel = " << g_keyModMaskXAccel + // << "g_keyModMaskXOnOrOff = " << g_keyModMaskXOnOrOff << endl; +} + +//---------------------------------------------------- + +static TQValueList< TDEGlobalAccelPrivate* >* all_accels = 0; + +TDEGlobalAccelPrivate::TDEGlobalAccelPrivate() +: TDEAccelBase( TDEAccelBase::NATIVE_KEYS ) +, m_blocked( false ) +, m_blockingDisabled( false ) +, m_suspended( false ) +{ + if( all_accels == NULL ) + all_accels = new TQValueList< TDEGlobalAccelPrivate* >; + all_accels->append( this ); + m_sConfigGroup = "Global Shortcuts"; + tdeApp->installX11EventFilter( this ); + connect(tdeApp, TQ_SIGNAL(coreFakeKeyPress(unsigned int)), this, TQ_SLOT(fakeKeyPressed(unsigned int))); +} + +TDEGlobalAccelPrivate::~TDEGlobalAccelPrivate() +{ + // TODO: Need to release all grabbed keys if the main window is not shutting down. + //for( CodeModMap::ConstIterator it = m_rgCodeModToAction.begin(); it != m_rgCodeModToAction.end(); ++it ) { + // const CodeMod& codemod = it.key(); + //} + all_accels->remove( this ); + if( all_accels->count() == 0 ) { + delete all_accels; + all_accels = NULL; + } +} + +void TDEGlobalAccelPrivate::setEnabled( bool bEnable ) +{ + m_bEnabled = bEnable; + updateConnections(); +} + +void TDEGlobalAccelPrivate::blockShortcuts( bool block ) +{ + if( all_accels == NULL ) + return; + for( TQValueList< TDEGlobalAccelPrivate* >::ConstIterator it = all_accels->begin(); + it != all_accels->end(); + ++it ) { + if( (*it)->m_blockingDisabled ) + continue; + (*it)->m_blocked = block; + (*it)->updateConnections(); + } +} + +void TDEGlobalAccelPrivate::disableBlocking( bool block ) +{ + m_blockingDisabled = block; +} + +bool TDEGlobalAccelPrivate::isEnabledInternal() const +{ + return TDEAccelBase::isEnabled() && !m_blocked; +} + +// see #117169 - the bug is hard to reproduce, probably somewhere in X, testcase would be probably +// difficult to make, and so on - just don't release the grabs and only ignore the events instead +void TDEGlobalAccelPrivate::suspend( bool s ) +{ + m_suspended = s; +} + +bool TDEGlobalAccelPrivate::emitSignal( Signal ) +{ + return false; +} + +bool TDEGlobalAccelPrivate::connectKey( TDEAccelAction& action, const KKeyServer::Key& key ) + { return grabKey( key, true, &action ); } +bool TDEGlobalAccelPrivate::connectKey( const KKeyServer::Key& key ) + { return grabKey( key, true, 0 ); } +bool TDEGlobalAccelPrivate::disconnectKey( TDEAccelAction& action, const KKeyServer::Key& key ) + { return grabKey( key, false, &action ); } +bool TDEGlobalAccelPrivate::disconnectKey( const KKeyServer::Key& key ) + { return grabKey( key, false, 0 ); } + +bool TDEGlobalAccelPrivate::grabKey( const KKeyServer::Key& key, bool bGrab, TDEAccelAction* pAction ) +{ + if( !key.code() ) { + kdWarning(125) << "TDEGlobalAccelPrivate::grabKey( " << key.key().toStringInternal() << ", " << bGrab << ", \"" << (pAction ? pAction->name().latin1() : "(null)") << "\" ): Tried to grab key with null code." << endl; + return false; + } + + // Make sure that grab masks have been initialized. + if( g_keyModMaskXOnOrOff == 0 ) { + calculateGrabMasks(); + } + + uchar keyCodeX = key.code(); + uint keyModX = key.mod() & g_keyModMaskXAccel; // Get rid of any non-relevant bits in mod + // HACK: make Alt+Print work + // only do this for the Xorg default keyboard keycodes, + // other mappings (e.g. evdev) don't need or want it + if( key.sym() == XK_Sys_Req && XkbKeycodeToKeysym( tqt_xdisplay(), 111, 0, 0 ) == XK_Print ) { + keyModX |= KKeyServer::modXAlt(); + keyCodeX = 111; + } + // If the MODE_SWITCH modifier was set in the original key, and was truncated in g_keyModMaskXAccel, XGrabKey will grab the wrong key + // See Bug 1676 + if ((key.mod() & KKeyServer::MODE_SWITCH) && (!(g_keyModMaskXAccel & KKeyServer::MODE_SWITCH))) { + // FIXME + // Is there any way to make AltGr-based character sequences work with XGrabKey? + kdWarning(125) << "TDEGlobalAccelPrivate::grabKey( " << key.key().toStringInternal() << ", " << bGrab << ", \"" << (pAction ? pAction->name().latin1() : "(null)") << "\" ): Tried to grab key requiring ISO_Level3_Shift (AltGr) sequence." << endl; + return false; + } + + kdDebug(125) << TQString(TQString( "grabKey( key: '%1', bGrab: %2 ): keyCodeX: %3 keyModX: %4\n" ) + .arg( key.key().toStringInternal() ).arg( bGrab ) + .arg( keyCodeX, 0, 16 ).arg( keyModX, 0, 16 )); + if( !keyCodeX ) { + return false; + } + +#ifdef TQ_WS_X11 + KXErrorHandler handler( XGrabErrorHandler ); +#endif + // We'll have to grab 8 key modifier combinations in order to cover all + // combinations of CapsLock, NumLock, ScrollLock. + // Does anyone with more X-savvy know how to set a mask on tqt_xrootwin so that + // the irrelevant bits are always ignored and we can just make one XGrabKey + // call per accelerator? -- ellis +#ifndef NDEBUG + TQString sDebug = TQString("\tcode: 0x%1 state: 0x%2 | ").arg(keyCodeX,0,16).arg(keyModX,0,16); +#endif + uint keyModMaskX = ~g_keyModMaskXOnOrOff; + for( uint irrelevantBitsMask = 0; irrelevantBitsMask <= 0xff; irrelevantBitsMask++ ) { + if( (irrelevantBitsMask & keyModMaskX) == 0 ) { +#ifndef NDEBUG + sDebug += TQString("0x%3, ").arg(irrelevantBitsMask, 0, 16); +#endif + if( bGrab ) + XGrabKey( tqt_xdisplay(), keyCodeX, keyModX | irrelevantBitsMask, + tqt_xrootwin(), True, GrabModeAsync, GrabModeSync ); + else + XUngrabKey( tqt_xdisplay(), keyCodeX, keyModX | irrelevantBitsMask, tqt_xrootwin() ); + } + } +#ifndef NDEBUG + kdDebug(125) << sDebug << endl; +#endif + + bool failed = false; + if( bGrab ) { +#ifdef TQ_WS_X11 + failed = handler.error( true ); // sync now +#endif + // If grab failed, then ungrab any grabs that could possibly succeed + if( failed ) { + kdDebug(125) << "grab failed!\n"; + for( uint m = 0; m <= 0xff; m++ ) { + if(( m & keyModMaskX ) == 0 ) + XUngrabKey( tqt_xdisplay(), keyCodeX, keyModX | m, tqt_xrootwin() ); + } + } + } + if( !failed ) + { + CodeMod codemod; + codemod.code = keyCodeX; + codemod.mod = keyModX; + if( key.mod() & KKeyServer::MODE_SWITCH ) + codemod.mod |= KKeyServer::MODE_SWITCH; + + if( bGrab ) + m_rgCodeModToAction.insert( codemod, pAction ); + else + m_rgCodeModToAction.remove( codemod ); + } + return !failed; +} + +bool TDEGlobalAccelPrivate::x11Event( XEvent* pEvent ) +{ + //kdDebug(125) << "x11EventFilter( type = " << pEvent->type << " )" << endl; + switch( pEvent->type ) { + case MappingNotify: + XRefreshKeyboardMapping( &pEvent->xmapping ); + x11MappingNotify(); + return false; + case XKeyPress: + if( x11KeyPress( pEvent ) ) { + return true; + } + default: + return TQWidget::x11Event( pEvent ); + } +} + +void TDEGlobalAccelPrivate::x11MappingNotify() +{ + kdDebug(125) << "TDEGlobalAccelPrivate::x11MappingNotify()" << endl; + // Maybe the X modifier map has been changed. + KKeyServer::initializeMods(); + calculateGrabMasks(); + // Do new XGrabKey()s. + updateConnections(); +} + +void TDEGlobalAccelPrivate::fakeKeyPressed(unsigned int keyCode) { + CodeMod codemod; + codemod.code = keyCode; + codemod.mod = 0; + + KKey key(keyCode, 0); + + kdDebug(125) << "fakeKeyPressed: seek " << key.toStringInternal() + << TQString(TQString( " 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 ) { + TDEAccelAction* pAction = *it; + kdDebug(125) << "\tcode: " << TQString::number(it.key().code, 16) << " mod: " << TQString::number(it.key().mod, 16) + << (pAction ? TQString(" name: \"%1\" shortcut: %2").arg(pAction->name()).arg(pAction->shortcut().toStringInternal()) : TQString()) + << endl; + } +#endif + return; + } + + TDEAccelAction* pAction = m_rgCodeModToAction[codemod]; + + if( !pAction ) { + static bool recursion_block = false; + if( !recursion_block ) { + recursion_block = true; + TQPopupMenu* pMenu = createPopupMenu( 0, KKeySequence(key) ); + connect( pMenu, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotActivated(int)) ); + pMenu->exec( TQPoint( 0, 0 ) ); + disconnect( pMenu, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotActivated(int))); + delete pMenu; + recursion_block = false; + } + } else if( !pAction->objSlotPtr() || !pAction->isEnabled() ) + return; + else + activate( pAction, KKeySequence(key) ); +} + +bool TDEGlobalAccelPrivate::x11KeyPress( const XEvent *pEvent ) +{ + // do not change this line unless you really really know what you are doing (Matthias) + if ( !TQWidget::keyboardGrabber() && !TQApplication::activePopupWidget() ) { + XUngrabKeyboard( tqt_xdisplay(), pEvent->xkey.time ); + XFlush( tqt_xdisplay()); // avoid X(?) bug + } + + if( !isEnabledInternal() || m_suspended ) { + return false; + } + + CodeMod codemod; + codemod.code = pEvent->xkey.keycode; + codemod.mod = pEvent->xkey.state & (g_keyModMaskXAccel | KKeyServer::MODE_SWITCH); + + // If numlock is active and a keypad key is pressed, XOR the SHIFT state. + // e.g., KP_4 => Shift+KP_Left, and Shift+KP_4 => KP_Left. + if( pEvent->xkey.state & KKeyServer::modXNumLock() ) { + // TODO: what's the xor operator in c++? + uint sym = XkbKeycodeToKeysym( tqt_xdisplay(), codemod.code, 0, 0 ); + // If this is a keypad key, + if( sym >= XK_KP_Space && sym <= XK_KP_9 ) { + switch( sym ) { + // Leave the following keys unaltered + // FIXME: The proper solution is to see which keysyms don't change when shifted. + case XK_KP_Multiply: + case XK_KP_Add: + case XK_KP_Subtract: + case XK_KP_Divide: + break; + default: + if( codemod.mod & KKeyServer::modXShift() ) + codemod.mod &= ~KKeyServer::modXShift(); + else + codemod.mod |= KKeyServer::modXShift(); + } + } + } + + KKeyNative keyNative( pEvent ); + KKey key = keyNative; + + kdDebug(125) << "x11KeyPress: seek " << key.toStringInternal() + << TQString(TQString( " keyCodeX: %1 state: %2 keyModX: %3" ) + .arg( codemod.code, 0, 16 ).arg( pEvent->xkey.state, 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 ) { + TDEAccelAction* pAction = *it; + kdDebug(125) << "\tcode: " << TQString::number(it.key().code, 16) << " mod: " << TQString::number(it.key().mod, 16) + << (pAction ? TQString(" name: \"%1\" shortcut: %2").arg(pAction->name()).arg(pAction->shortcut().toStringInternal()) : TQString()) + << endl; + } +#endif + return false; + } + + TDEAccelAction* pAction = m_rgCodeModToAction[codemod]; + + if( !pAction ) { + static bool recursion_block = false; + if( !recursion_block ) { + recursion_block = true; + TQPopupMenu* pMenu = createPopupMenu( 0, KKeySequence(key) ); + connect( pMenu, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotActivated(int)) ); + pMenu->exec( TQPoint( 0, 0 ) ); + disconnect( pMenu, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotActivated(int))); + delete pMenu; + recursion_block = false; + } + } else if( !pAction->objSlotPtr() || !pAction->isEnabled() ) + return false; + else + activate( pAction, KKeySequence(key) ); + + return true; +} + +void TDEGlobalAccelPrivate::activate( TDEAccelAction* pAction, const KKeySequence& seq ) +{ + kdDebug(125) << "TDEGlobalAccelPrivate::activate( \"" << pAction->name() << "\" ) " << endl; + + TQRegExp rexPassIndex( "([ ]*int[ ]*)" ); + TQRegExp rexPassInfo( " TQString" ); + TQRegExp rexIndex( " ([0-9]+)$" ); + + // If the slot to be called accepts an integer index + // and an index is present at the end of the action's name, + // then send the slot the given index #. + if( rexPassIndex.search( pAction->methodSlotPtr() ) >= 0 && rexIndex.search( pAction->name() ) >= 0 ) { + int n = rexIndex.cap(1).toInt(); + kdDebug(125) << "Calling " << pAction->methodSlotPtr() << " int = " << n << endl; + int slot_id = pAction->objSlotPtr()->metaObject()->findSlot( normalizeSignalSlot( pAction->methodSlotPtr() ).data() + 1, true ); + if( slot_id >= 0 ) { + TQUObject o[2]; + static_QUType_int.set(o+1,n); + const_cast< TQObject* >( pAction->objSlotPtr())->tqt_invoke( slot_id, o ); + } + } else if( rexPassInfo.search( pAction->methodSlotPtr() ) ) { + int slot_id = pAction->objSlotPtr()->metaObject()->findSlot( normalizeSignalSlot( pAction->methodSlotPtr() ).data() + 1, true ); + if( slot_id >= 0 ) { + TQUObject o[4]; + static_QUType_TQString.set(o+1,pAction->name()); + static_QUType_TQString.set(o+2,pAction->label()); + static_QUType_ptr.set(o+3,&seq); + const_cast< TQObject* >( pAction->objSlotPtr())->tqt_invoke( slot_id, o ); + } + } else { + int slot_id = pAction->objSlotPtr()->metaObject()->findSlot( normalizeSignalSlot( pAction->methodSlotPtr() ).data() + 1, true ); + if( slot_id >= 0 ) + const_cast< TQObject* >( pAction->objSlotPtr())->tqt_invoke( slot_id, 0 ); + } +} + +void TDEGlobalAccelPrivate::slotActivated( int iAction ) +{ + TDEAccelAction* pAction = TDEAccelBase::actions().actionPtr( iAction ); + if( pAction ) + activate( pAction, KKeySequence() ); +} + +#include "tdeglobalaccel_x11.moc" + +#endif // !TQ_WS_X11 diff --git a/tdecore/tdeglobalaccel_x11.h b/tdecore/tdeglobalaccel_x11.h new file mode 100644 index 000000000..2162299ee --- /dev/null +++ b/tdecore/tdeglobalaccel_x11.h @@ -0,0 +1,110 @@ +/* This file is part of the KDE libraries + Copyright (C) 2001,2002 Ellis Whitehead + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _TDEGLOBALACCEL_X11_H +#define _TDEGLOBALACCEL_X11_H + +#include +#include + +#include "tdeaccelbase.h" +#include "kkeyserver_x11.h" +#include "tdeshortcut.h" + +/** + * @internal + */ +class TDEGlobalAccelPrivate : public TQWidget, public TDEAccelBase +{ + friend class TDEGlobalAccel; + TQ_OBJECT + public: + TDEGlobalAccelPrivate(); + virtual ~TDEGlobalAccelPrivate(); + + virtual void setEnabled( bool bEnabled ); + + virtual bool emitSignal( Signal signal ); + virtual bool connectKey( TDEAccelAction& action, const KKeyServer::Key& key ); + virtual bool connectKey( const KKeyServer::Key& key ); + virtual bool disconnectKey( TDEAccelAction& action, const KKeyServer::Key& key ); + virtual bool disconnectKey( const KKeyServer::Key& key ); + + protected: + /** + * @internal + * Represents a key code and modifier combination. + */ + class CodeMod + { + public: + /** + * The key code of the CodeMod. + */ + uchar code; + /** + * The modifier flags of the CodeMod. + */ + uint mod; + + /** + * Compares two CodeMods. + */ + bool operator < ( const CodeMod& b ) const + { + if( code < b.code ) return true; + if( code == b.code && mod < b.mod ) return true; + return false; + } + }; + typedef TQMap CodeModMap; + + CodeModMap m_rgCodeModToAction; + + /** + * @param bGrab Set to true to grab key, false to ungrab key. + */ + bool grabKey( const KKeyServer::Key&, bool bGrab, TDEAccelAction* ); + + /** + * Filters X11 events ev for key bindings in the accelerator dictionary. + * If a match is found the activated activated is emitted and the function + * returns true. Return false if the event is not processed. + * + * This is public for compatibility only. You do not need to call it. + */ + virtual bool x11Event( XEvent* ); + void x11MappingNotify(); + bool x11KeyPress( const XEvent *pEvent ); + void activate( TDEAccelAction* pAction, const KKeySequence& seq ); + virtual bool isEnabledInternal() const; + static void blockShortcuts( bool block ); + void disableBlocking( bool disable ); + void suspend( bool s ); + + protected slots: + void slotActivated( int iAction ); + void fakeKeyPressed(unsigned int keyCode); + private: + bool m_blocked; + bool m_blockingDisabled; + bool m_suspended; +}; + +#endif // _TDEGLOBALACCEL_X11_H diff --git a/tdecore/tdeshortcutlist.cpp b/tdecore/tdeshortcutlist.cpp index ffacd001c..cc9961199 100644 --- a/tdecore/tdeshortcutlist.cpp +++ b/tdecore/tdeshortcutlist.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include "tdeshortcutlist.h" diff --git a/tdeui/kkeybutton.cpp b/tdeui/kkeybutton.cpp index 201ade557..260cba34b 100644 --- a/tdeui/kkeybutton.cpp +++ b/tdeui/kkeybutton.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include "config.h" diff --git a/tdeui/kkeydialog.cpp b/tdeui/kkeydialog.cpp index 15c8ef78e..5c028e4f7 100644 --- a/tdeui/kkeydialog.cpp +++ b/tdeui/kkeydialog.cpp @@ -43,7 +43,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/win/pro_files/tdecore/tdecore.pro b/win/pro_files/tdecore/tdecore.pro index 28b353e85..7ad7d4414 100644 --- a/win/pro_files/tdecore/tdecore.pro +++ b/win/pro_files/tdecore/tdecore.pro @@ -76,8 +76,8 @@ kiconloader.cpp \ kiconeffect.cpp \ tdeglobalsettings.cpp \ kckey.cpp \ -kglobalaccel.cpp \ -kglobalaccel_win.cpp \ +tdeglobalaccel.cpp \ +tdeglobalaccel_win.cpp \ tdeaccelaction.cpp \ tdeuniqueapplication.cpp \ tdesycoca.cpp \ -- cgit v1.2.1