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

COSXScreen.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 COSXSCREEN_H
00016 #define COSXSCREEN_H
00017 
00018 #include <Carbon/Carbon.h>
00019 #include "COSXClipboard.h"
00020 #include "CPlatformScreen.h"
00021 #include "stdmap.h"
00022 #include "stdvector.h"
00023 
00024 #include <mach/mach_port.h>
00025 #include <mach/mach_interface.h>
00026 #include <mach/mach_init.h>
00027 #include <IOKit/pwr_mgt/IOPMLib.h>
00028 #include <IOKit/IOMessage.h>
00029 
00030 template <class T>
00031 class CCondVar;
00032 class CEventQueueTimer;
00033 class CMutex;
00034 class CThread;
00035 class COSXKeyState;
00036 class COSXScreenSaver;
00037 
00039 class COSXScreen : public CPlatformScreen {
00040 public:
00041     COSXScreen(bool isPrimary);
00042     virtual ~COSXScreen();
00043 
00044     // IScreen overrides
00045     virtual void*       getEventTarget() const;
00046     virtual bool        getClipboard(ClipboardID id, IClipboard*) const;
00047     virtual void        getShape(SInt32& x, SInt32& y,
00048                             SInt32& width, SInt32& height) const;
00049     virtual void        getCursorPos(SInt32& x, SInt32& y) const;
00050 
00051     // IPrimaryScreen overrides
00052     virtual void        reconfigure(UInt32 activeSides);
00053     virtual void        warpCursor(SInt32 x, SInt32 y);
00054     virtual UInt32      registerHotKey(KeyID key, KeyModifierMask mask);
00055     virtual void        unregisterHotKey(UInt32 id);
00056     virtual void        fakeInputBegin();
00057     virtual void        fakeInputEnd();
00058     virtual SInt32      getJumpZoneSize() const;
00059     virtual bool        isAnyMouseButtonDown() const;
00060     virtual void        getCursorCenter(SInt32& x, SInt32& y) const;
00061 
00062     // ISecondaryScreen overrides
00063     virtual void        fakeMouseButton(ButtonID id, bool press) const;
00064     virtual void        fakeMouseMove(SInt32 x, SInt32 y) const;
00065     virtual void        fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const;
00066     virtual void        fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const;
00067 
00068     // IPlatformScreen overrides
00069     virtual void        enable();
00070     virtual void        disable();
00071     virtual void        enter();
00072     virtual bool        leave();
00073     virtual bool        setClipboard(ClipboardID, const IClipboard*);
00074     virtual void        checkClipboards();
00075     virtual void        openScreensaver(bool notify);
00076     virtual void        closeScreensaver();
00077     virtual void        screensaver(bool activate);
00078     virtual void        resetOptions();
00079     virtual void        setOptions(const COptionsList& options);
00080     virtual void        setSequenceNumber(UInt32);
00081     virtual bool        isPrimary() const;
00082 
00083 protected:
00084     // IPlatformScreen overrides
00085     virtual void        handleSystemEvent(const CEvent&, void*);
00086     virtual void        updateButtons();
00087     virtual IKeyState*  getKeyState() const;
00088 
00089 private:
00090     void                updateScreenShape(const CGDirectDisplayID, const CGDisplayChangeSummaryFlags);
00091     void                postMouseEvent(CGPoint&) const;
00092     
00093     // convenience function to send events
00094     void                sendEvent(CEvent::Type type, void* = NULL) const;
00095     void                sendClipboardEvent(CEvent::Type type, ClipboardID id) const;
00096 
00097     // message handlers
00098     bool                onMouseMove(SInt32 x, SInt32 y);
00099     // mouse button handler.  pressed is true if this is a mousedown
00100     // event, false if it is a mouseup event.  macButton is the index
00101     // of the button pressed using the mac button mapping.
00102     bool                onMouseButton(bool pressed, UInt16 macButton);
00103     bool                onMouseWheel(SInt32 xDelta, SInt32 yDelta) const;
00104 
00105     bool                onKey(EventRef event);
00106     bool                onHotKey(EventRef event) const;
00107 
00108     // map mac mouse button to synergy buttons
00109     ButtonID            mapMacButtonToSynergy(UInt16) const;
00110 
00111     // map mac scroll wheel value to a synergy scroll wheel value
00112     SInt32              mapScrollWheelToSynergy(SInt32) const;
00113 
00114     // map synergy scroll wheel value to a mac scroll wheel value
00115     SInt32              mapScrollWheelFromSynergy(SInt32) const;
00116 
00117     // get the current scroll wheel speed
00118     double              getScrollSpeed() const;
00119 
00120     // get the current scroll wheel speed
00121     double              getScrollSpeedFactor() const;
00122 
00123     // enable/disable drag handling for buttons 3 and up
00124     void                enableDragTimer(bool enable);
00125 
00126     // drag timer handler
00127     void                handleDrag(const CEvent&, void*);
00128 
00129     // clipboard check timer handler
00130     void                handleClipboardCheck(const CEvent&, void*);
00131 
00132     // Resolution switch callback
00133     static void displayReconfigurationCallback(CGDirectDisplayID,
00134                             CGDisplayChangeSummaryFlags, void*);
00135     
00136     // fast user switch callback
00137     static pascal OSStatus
00138                         userSwitchCallback(EventHandlerCallRef nextHandler,
00139                            EventRef theEvent, void* inUserData);
00140     
00141     // sleep / wakeup support
00142     void                watchSystemPowerThread(void*);
00143     static void         testCanceled(CFRunLoopTimerRef timer, void*info);
00144     static void         powerChangeCallback(void* refcon, io_service_t service,
00145                             natural_t messageType, void* messageArgument);
00146     void                handlePowerChangeRequest(natural_t messageType,
00147                              void* messageArgument);
00148 
00149     static CEvent::Type getConfirmSleepEvent();
00150     void                handleConfirmSleep(const CEvent& event, void*);
00151     
00152     // global hotkey operating mode
00153     static bool         isGlobalHotKeyOperatingModeAvailable();
00154     static void         setGlobalHotKeysEnabled(bool enabled);
00155     static bool         getGlobalHotKeysEnabled();
00156 
00157 private:
00158     struct CHotKeyItem {
00159     public:
00160         CHotKeyItem(UInt32, UInt32);
00161         CHotKeyItem(EventHotKeyRef, UInt32, UInt32);
00162 
00163         EventHotKeyRef  getRef() const;
00164 
00165         bool            operator<(const CHotKeyItem&) const;
00166 
00167     private:
00168         EventHotKeyRef  m_ref;
00169         UInt32          m_keycode;
00170         UInt32          m_mask;
00171     };
00172     typedef std::map<UInt32, CHotKeyItem> HotKeyMap;
00173     typedef std::vector<UInt32> HotKeyIDList;
00174     typedef std::map<KeyModifierMask, UInt32> ModifierHotKeyMap;
00175     typedef std::map<CHotKeyItem, UInt32> HotKeyToIDMap;
00176 
00177     // true if screen is being used as a primary screen, false otherwise
00178     bool                m_isPrimary;
00179 
00180     // true if mouse has entered the screen
00181     bool                m_isOnScreen;
00182 
00183     // the display
00184     CGDirectDisplayID   m_displayID;
00185 
00186     // screen shape stuff
00187     SInt32              m_x, m_y;
00188     SInt32              m_w, m_h;
00189     SInt32              m_xCenter, m_yCenter;
00190 
00191     // mouse state
00192     mutable SInt32      m_xCursor, m_yCursor;
00193     mutable bool        m_cursorPosValid;
00194     mutable boolean_t   m_buttons[5];
00195     bool                m_cursorHidden;
00196     SInt32              m_dragNumButtonsDown;
00197     Point               m_dragLastPoint;
00198     CEventQueueTimer*   m_dragTimer;
00199 
00200     // keyboard stuff
00201     COSXKeyState*       m_keyState;
00202 
00203     // clipboards
00204     COSXClipboard       m_pasteboard;
00205     UInt32              m_sequenceNumber;
00206 
00207     // screen saver stuff
00208     COSXScreenSaver*    m_screensaver;
00209     bool                m_screensaverNotify;
00210 
00211     // clipboard stuff
00212     bool                m_ownClipboard;
00213     CEventQueueTimer*   m_clipboardTimer;
00214 
00215     // window object that gets user input events when the server
00216     // has focus.
00217     WindowRef           m_hiddenWindow;
00218     // window object that gets user input events when the server
00219     // does not have focus.
00220     WindowRef           m_userInputWindow;
00221 
00222     // fast user switching
00223     EventHandlerRef         m_switchEventHandlerRef;
00224 
00225     // sleep / wakeup
00226     CMutex*                 m_pmMutex;
00227     CThread*                m_pmWatchThread;
00228     CCondVar<bool>*         m_pmThreadReady;
00229     CFRunLoopRef            m_pmRunloop;
00230     io_connect_t            m_pmRootPort;
00231 
00232     // hot key stuff
00233     HotKeyMap               m_hotKeys;
00234     HotKeyIDList            m_oldHotKeyIDs;
00235     ModifierHotKeyMap       m_modifierHotKeys;
00236     UInt32                  m_activeModifierHotKey;
00237     KeyModifierMask         m_activeModifierHotKeyMask;
00238     HotKeyToIDMap           m_hotKeyToIDMap;
00239 
00240     // global hotkey operating mode
00241     static bool             s_testedForGHOM;
00242     static bool             s_hasGHOM;
00243 
00244     // events
00245     static CEvent::Type     s_confirmSleepEvent;
00246 };
00247 
00248 #endif

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