00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
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
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
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
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
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
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
00094 void sendEvent(CEvent::Type type, void* = NULL) const;
00095 void sendClipboardEvent(CEvent::Type type, ClipboardID id) const;
00096
00097
00098 bool onMouseMove(SInt32 x, SInt32 y);
00099
00100
00101
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
00109 ButtonID mapMacButtonToSynergy(UInt16) const;
00110
00111
00112 SInt32 mapScrollWheelToSynergy(SInt32) const;
00113
00114
00115 SInt32 mapScrollWheelFromSynergy(SInt32) const;
00116
00117
00118 double getScrollSpeed() const;
00119
00120
00121 double getScrollSpeedFactor() const;
00122
00123
00124 void enableDragTimer(bool enable);
00125
00126
00127 void handleDrag(const CEvent&, void*);
00128
00129
00130 void handleClipboardCheck(const CEvent&, void*);
00131
00132
00133 static void displayReconfigurationCallback(CGDirectDisplayID,
00134 CGDisplayChangeSummaryFlags, void*);
00135
00136
00137 static pascal OSStatus
00138 userSwitchCallback(EventHandlerCallRef nextHandler,
00139 EventRef theEvent, void* inUserData);
00140
00141
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
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
00178 bool m_isPrimary;
00179
00180
00181 bool m_isOnScreen;
00182
00183
00184 CGDirectDisplayID m_displayID;
00185
00186
00187 SInt32 m_x, m_y;
00188 SInt32 m_w, m_h;
00189 SInt32 m_xCenter, m_yCenter;
00190
00191
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
00201 COSXKeyState* m_keyState;
00202
00203
00204 COSXClipboard m_pasteboard;
00205 UInt32 m_sequenceNumber;
00206
00207
00208 COSXScreenSaver* m_screensaver;
00209 bool m_screensaverNotify;
00210
00211
00212 bool m_ownClipboard;
00213 CEventQueueTimer* m_clipboardTimer;
00214
00215
00216
00217 WindowRef m_hiddenWindow;
00218
00219
00220 WindowRef m_userInputWindow;
00221
00222
00223 EventHandlerRef m_switchEventHandlerRef;
00224
00225
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
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
00241 static bool s_testedForGHOM;
00242 static bool s_hasGHOM;
00243
00244
00245 static CEvent::Type s_confirmSleepEvent;
00246 };
00247
00248 #endif