Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

COSXKeyState.h

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2004 Chris Schoeneman
00004  * 
00005  * This package is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * found in the file COPYING that should have accompanied this file.
00008  * 
00009  * This package is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  */
00014 
00015 #ifndef COSXKEYSTATE_H
00016 #define COSXKEYSTATE_H
00017 
00018 #include <Carbon/Carbon.h>
00019 #include "CKeyState.h"
00020 #include "stdmap.h"
00021 #include "stdset.h"
00022 #include "stdvector.h"
00023 
00025 
00028 class COSXKeyState : public CKeyState {
00029 public:
00030     typedef std::vector<KeyID> CKeyIDs;
00031 
00032     COSXKeyState();
00033     virtual ~COSXKeyState();
00034 
00036 
00037 
00039 
00043     void                handleModifierKeys(void* target,
00044                             KeyModifierMask oldMask, KeyModifierMask newMask);
00045 
00047 
00048 
00049 
00051 
00055     KeyModifierMask     mapModifiersFromOSX(UInt32 mask) const;
00056 
00058 
00065     KeyButton           mapKeyFromEvent(CKeyIDs& ids,
00066                             KeyModifierMask* maskOut, EventRef event) const;
00067 
00069 
00073     bool                mapSynergyHotKeyToMac(KeyID key, KeyModifierMask mask,
00074                             UInt32& macVirtualKey,
00075                             UInt32& macModifierMask) const;
00076 
00078 
00079     // IKeyState overrides
00080     virtual bool        fakeCtrlAltDel();
00081     virtual KeyModifierMask
00082                         pollActiveModifiers() const;
00083     virtual SInt32      pollActiveGroup() const;
00084     virtual void        pollPressedKeys(KeyButtonSet& pressedKeys) const;
00085 
00086 protected:
00087     // CKeyState overrides
00088     virtual void        getKeyMap(CKeyMap& keyMap);
00089     virtual void        fakeKey(const Keystroke& keystroke);
00090 
00091 private:
00092     class CKeyResource;
00093     typedef std::vector<TISInputSourceRef> GroupList;
00094 
00095     // Add hard coded special keys to a CKeyMap.
00096     void                getKeyMapForSpecialKeys(
00097                             CKeyMap& keyMap, SInt32 group) const;
00098 
00099     // Convert keyboard resource to a key map
00100     bool                getKeyMap(CKeyMap& keyMap,
00101                             SInt32 group, const CKeyResource& r) const;
00102 
00103     // Get the available keyboard groups
00104     bool                getGroups(GroupList&) const;
00105 
00106     // Change active keyboard group to group
00107     void                setGroup(SInt32 group);
00108 
00109     // Check if the keyboard layout has changed and update keyboard state
00110     // if so.
00111     void                checkKeyboardLayout();
00112 
00113     // Send an event for the given modifier key
00114     void                handleModifierKey(void* target,
00115                             UInt32 virtualKey, KeyID id,
00116                             bool down, KeyModifierMask newMask);
00117 
00118     // Checks if any in \p ids is a glyph key and if \p isCommand is false.
00119     // If so it adds the AltGr modifier to \p mask.  This allows OS X
00120     // servers to use the option key both as AltGr and as a modifier.  If
00121     // option is acting as AltGr (i.e. it generates a glyph and there are
00122     // no command modifiers active) then we don't send the super modifier
00123     // to clients because they'd try to match it as a command modifier.
00124     void                adjustAltGrModifier(const CKeyIDs& ids,
00125                             KeyModifierMask* mask, bool isCommand) const;
00126 
00127     // Maps an OS X virtual key id to a KeyButton.  This simply remaps
00128     // the ids so we don't use KeyButton 0.
00129     static KeyButton    mapVirtualKeyToKeyButton(UInt32 keyCode);
00130 
00131     // Maps a KeyButton to an OS X key code.  This is the inverse of
00132     // mapVirtualKeyToKeyButton.
00133     static UInt32       mapKeyButtonToVirtualKey(KeyButton keyButton);
00134 
00135 private:
00136     class CKeyResource : public IInterface {
00137     public:
00138         virtual bool    isValid() const = 0;
00139         virtual UInt32  getNumModifierCombinations() const = 0;
00140         virtual UInt32  getNumTables() const = 0;
00141         virtual UInt32  getNumButtons() const = 0;
00142         virtual UInt32  getTableForModifier(UInt32 mask) const = 0;
00143         virtual KeyID   getKey(UInt32 table, UInt32 button) const = 0;
00144 
00145         // Convert a character in the current script to the equivalent KeyID
00146         static KeyID    getKeyID(UInt8);
00147 
00148         // Convert a unicode character to the equivalent KeyID.
00149         static KeyID    unicharToKeyID(UniChar);
00150     };
00151 
00152 
00153     class CUCHRKeyResource : public CKeyResource {
00154     public:
00155         CUCHRKeyResource(const void*, UInt32 keyboardType);
00156 
00157         // CKeyResource overrides
00158         virtual bool    isValid() const;
00159         virtual UInt32  getNumModifierCombinations() const;
00160         virtual UInt32  getNumTables() const;
00161         virtual UInt32  getNumButtons() const;
00162         virtual UInt32  getTableForModifier(UInt32 mask) const;
00163         virtual KeyID   getKey(UInt32 table, UInt32 button) const;
00164 
00165     private:
00166         typedef std::vector<KeyID> KeySequence;
00167 
00168         bool            getDeadKey(KeySequence& keys, UInt16 index) const;
00169         bool            getKeyRecord(KeySequence& keys,
00170                             UInt16 index, UInt16& state) const;
00171         bool            addSequence(KeySequence& keys, UCKeyCharSeq c) const;
00172 
00173     private:
00174         const UCKeyboardLayout*         m_resource;
00175         const UCKeyModifiersToTableNum* m_m;
00176         const UCKeyToCharTableIndex*    m_cti;
00177         const UCKeySequenceDataIndex*   m_sdi;
00178         const UCKeyStateRecordsIndex*   m_sri;
00179         const UCKeyStateTerminators*    m_st;
00180         UInt16                          m_spaceOutput;
00181     };
00182 
00183     // OS X uses a physical key if 0 for the 'A' key.  synergy reserves
00184     // KeyButton 0 so we offset all OS X physical key ids by this much
00185     // when used as a KeyButton and by minus this much to map a KeyButton
00186     // to a physical button.
00187     enum {
00188         KeyButtonOffset = 1
00189     };
00190 
00191     typedef std::map<TISInputSourceRef, SInt32> GroupMap;
00192     typedef std::map<UInt32, KeyID> CVirtualKeyMap;
00193 
00194     CVirtualKeyMap      m_virtualKeyMap;
00195     mutable UInt32      m_deadKeyState;
00196     GroupList           m_groups;
00197     GroupMap            m_groupMap;
00198 };
00199 
00200 #endif

Generated on Fri Nov 6 00:21:14 2009 for synergy-plus by  doxygen 1.3.9.1