CXWindowsScreen.h

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2002 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 CXWINDOWSSCREEN_H
00016 #define CXWINDOWSSCREEN_H
00017 
00018 #include "CPlatformScreen.h"
00019 #include "stdset.h"
00020 #include "stdvector.h"
00021 #if X_DISPLAY_MISSING
00022 #   error X11 is required to build synergy
00023 #else
00024 #   include <X11/Xlib.h>
00025 #endif
00026 
00027 class CXWindowsClipboard;
00028 class CXWindowsKeyState;
00029 class CXWindowsScreenSaver;
00030 
00032 class CXWindowsScreen : public CPlatformScreen {
00033 public:
00034     CXWindowsScreen(const char* displayName, bool isPrimary, int mouseScrollDelta=0);
00035     virtual ~CXWindowsScreen();
00036 
00038 
00039 
00041 
00042     // IScreen overrides
00043     virtual void*       getEventTarget() const;
00044     virtual bool        getClipboard(ClipboardID id, IClipboard*) const;
00045     virtual void        getShape(SInt32& x, SInt32& y,
00046                             SInt32& width, SInt32& height) const;
00047     virtual void        getCursorPos(SInt32& x, SInt32& y) const;
00048 
00049     // IPrimaryScreen overrides
00050     virtual void        reconfigure(UInt32 activeSides);
00051     virtual void        warpCursor(SInt32 x, SInt32 y);
00052     virtual UInt32      registerHotKey(KeyID key, KeyModifierMask mask);
00053     virtual void        unregisterHotKey(UInt32 id);
00054     virtual void        fakeInputBegin();
00055     virtual void        fakeInputEnd();
00056     virtual SInt32      getJumpZoneSize() const;
00057     virtual bool        isAnyMouseButtonDown() const;
00058     virtual void        getCursorCenter(SInt32& x, SInt32& y) const;
00059 
00060     // ISecondaryScreen overrides
00061     virtual void        fakeMouseButton(ButtonID id, bool press) const;
00062     virtual void        fakeMouseMove(SInt32 x, SInt32 y) const;
00063     virtual void        fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const;
00064     virtual void        fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const;
00065 
00066     // IPlatformScreen overrides
00067     virtual void        enable();
00068     virtual void        disable();
00069     virtual void        enter();
00070     virtual bool        leave();
00071     virtual bool        setClipboard(ClipboardID, const IClipboard*);
00072     virtual void        checkClipboards();
00073     virtual void        openScreensaver(bool notify);
00074     virtual void        closeScreensaver();
00075     virtual void        screensaver(bool activate);
00076     virtual void        resetOptions();
00077     virtual void        setOptions(const COptionsList& options);
00078     virtual void        setSequenceNumber(UInt32);
00079     virtual bool        isPrimary() const;
00080 
00081 protected:
00082     // IPlatformScreen overrides
00083     virtual void        handleSystemEvent(const CEvent&, void*);
00084     virtual void        updateButtons();
00085     virtual IKeyState*  getKeyState() const;
00086 
00087 private:
00088     // event sending
00089     void                sendEvent(CEvent::Type, void* = NULL);
00090     void                sendClipboardEvent(CEvent::Type, ClipboardID);
00091 
00092     // create the transparent cursor
00093     Cursor              createBlankCursor() const;
00094 
00095     // determine the clipboard from the X selection.  returns
00096     // kClipboardEnd if no such clipboard.
00097     ClipboardID         getClipboardID(Atom selection) const;
00098 
00099     // continue processing a selection request
00100     void                processClipboardRequest(Window window,
00101                             Time time, Atom property);
00102 
00103     // terminate a selection request
00104     void                destroyClipboardRequest(Window window);
00105 
00106     // X I/O error handler
00107     void                onError();
00108     static int          ioErrorHandler(Display*);
00109 
00110 private:
00111     class CKeyEventFilter {
00112     public:
00113         int             m_event;
00114         Window          m_window;
00115         Time            m_time;
00116         KeyCode         m_keycode;
00117     };
00118 
00119     Display*            openDisplay(const char* displayName);
00120     void                saveShape();
00121     Window              openWindow() const;
00122     void                openIM();
00123 
00124     bool                grabMouseAndKeyboard();
00125     void                onKeyPress(XKeyEvent&);
00126     void                onKeyRelease(XKeyEvent&, bool isRepeat);
00127     bool                onHotKey(XKeyEvent&, bool isRepeat);
00128     void                onMousePress(const XButtonEvent&);
00129     void                onMouseRelease(const XButtonEvent&);
00130     void                onMouseMove(const XMotionEvent&);
00131 
00132     void                selectEvents(Window) const;
00133     void                doSelectEvents(Window) const;
00134 
00135     KeyID               mapKeyFromX(XKeyEvent*) const;
00136     ButtonID            mapButtonFromX(const XButtonEvent*) const;
00137     unsigned int        mapButtonToX(ButtonID id) const;
00138 
00139     void                warpCursorNoFlush(SInt32 x, SInt32 y);
00140 
00141     void                refreshKeyboard(XEvent*);
00142 
00143     static Bool         findKeyEvent(Display*, XEvent* xevent, XPointer arg);
00144 
00145 private:
00146     struct CHotKeyItem {
00147     public:
00148         CHotKeyItem(int, unsigned int);
00149 
00150         bool            operator<(const CHotKeyItem&) const;
00151 
00152     private:
00153         int             m_keycode;
00154         unsigned int    m_mask;
00155     };
00156     typedef std::set<bool> CFilteredKeycodes;
00157     typedef std::vector<std::pair<int, unsigned int> > HotKeyList;
00158     typedef std::map<UInt32, HotKeyList> HotKeyMap;
00159     typedef std::vector<UInt32> HotKeyIDList;
00160     typedef std::map<CHotKeyItem, UInt32> HotKeyToIDMap;
00161 
00162     // true if screen is being used as a primary screen, false otherwise
00163     bool                m_isPrimary;
00164     int                 m_mouseScrollDelta;
00165 
00166     Display*            m_display;
00167     Window              m_root;
00168     Window              m_window;
00169 
00170     // true if mouse has entered the screen
00171     bool                m_isOnScreen;
00172 
00173     // screen shape stuff
00174     SInt32              m_x, m_y;
00175     SInt32              m_w, m_h;
00176     SInt32              m_xCenter, m_yCenter;
00177 
00178     // last mouse position
00179     SInt32              m_xCursor, m_yCursor;
00180 
00181     // keyboard stuff
00182     CXWindowsKeyState*  m_keyState;
00183 
00184     // hot key stuff
00185     HotKeyMap           m_hotKeys;
00186     HotKeyIDList        m_oldHotKeyIDs;
00187     HotKeyToIDMap       m_hotKeyToIDMap;
00188 
00189     // input focus stuff
00190     Window              m_lastFocus;
00191     int                 m_lastFocusRevert;
00192 
00193     // input method stuff
00194     XIM                 m_im;
00195     XIC                 m_ic;
00196     KeyCode             m_lastKeycode;
00197     CFilteredKeycodes   m_filtered;
00198 
00199     // clipboards
00200     CXWindowsClipboard* m_clipboard[kClipboardEnd];
00201     UInt32              m_sequenceNumber;
00202 
00203     // screen saver stuff
00204     CXWindowsScreenSaver*   m_screensaver;
00205     bool                m_screensaverNotify;
00206 
00207     // logical to physical button mapping.  m_buttons[i] gives the
00208     // physical button for logical button i+1.
00209     std::vector<unsigned char>  m_buttons;
00210 
00211     // true if global auto-repeat was enabled before we turned it off
00212     bool                m_autoRepeat;
00213 
00214     // stuff to workaround xtest being xinerama unaware.  attempting
00215     // to fake a mouse motion under xinerama may behave strangely,
00216     // especially if screen 0 is not at 0,0 or if faking a motion on
00217     // a screen other than screen 0.
00218     bool                m_xtestIsXineramaUnaware;
00219     bool                m_xinerama;
00220 
00221     // stuff to work around lost focus issues on certain systems
00222     // (ie: a MythTV front-end).
00223     bool                m_preserveFocus;
00224 
00225     // XKB extension stuff
00226     bool                m_xkb;
00227     int                 m_xkbEventBase;
00228 
00229     // pointer to (singleton) screen.  this is only needed by
00230     // ioErrorHandler().
00231     static CXWindowsScreen* s_screen;
00232 };
00233 
00234 #endif

Generated on Fri Nov 6 00:18:46 2009 for synergy-plus by  doxygen 1.4.7