• Main Page
  • Classes
  • Files
  • File List

CMSWindowsDesks.h

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2012 Bolton Software Ltd.
00004  * Copyright (C) 2004 Chris Schoeneman
00005  * 
00006  * This package is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * found in the file COPYING that should have accompanied this file.
00009  * 
00010  * This package is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 #ifndef CMSWINDOWSDESKS_H
00020 #define CMSWINDOWSDESKS_H
00021 
00022 #include "CSynergyHook.h"
00023 #include "KeyTypes.h"
00024 #include "MouseTypes.h"
00025 #include "OptionTypes.h"
00026 #include "CCondVar.h"
00027 #include "CMutex.h"
00028 #include "CString.h"
00029 #include "stdmap.h"
00030 #define WIN32_LEAN_AND_MEAN
00031 #include <windows.h>
00032 
00033 class CEvent;
00034 class CEventQueueTimer;
00035 class CThread;
00036 class IJob;
00037 class IScreenSaver;
00038 class IEventQueue;
00039 
00041 
00056 class CMSWindowsDesks {
00057 public:
00059 
00067     CMSWindowsDesks(
00068         bool isPrimary, bool noHooks, HINSTANCE hookLibrary,
00069         const IScreenSaver* screensaver, IEventQueue& eventQueue,
00070         IJob* updateKeys, bool stopOnDeskSwitch);
00071     ~CMSWindowsDesks();
00072 
00074 
00075 
00077 
00083     void                enable();
00084 
00086 
00089     void                disable();
00090 
00092 
00095     void                enter();
00096 
00098 
00101     void                leave(HKL keyLayout);
00102 
00104 
00107     void                resetOptions();
00108 
00110 
00114     void                setOptions(const COptionsList& options);
00115 
00117 
00121     void                updateKeys();
00122 
00124 
00127     void                setShape(SInt32 x, SInt32 y,
00128                             SInt32 width, SInt32 height,
00129                             SInt32 xCenter, SInt32 yCenter, bool isMultimon);
00130 
00132 
00137     void                installScreensaverHooks(bool install);
00138 
00140 
00143     void                fakeInputBegin();
00144 
00146 
00149     void                fakeInputEnd();
00150 
00152 
00153 
00154 
00156 
00159     void                getCursorPos(SInt32& x, SInt32& y) const;
00160 
00162 
00165     void                fakeKeyEvent(KeyButton button, UINT virtualKey,
00166                             bool press, bool isAutoRepeat) const;
00167 
00169 
00172     void                fakeMouseButton(ButtonID id, bool press);
00173 
00175 
00178     void                fakeMouseMove(SInt32 x, SInt32 y) const;
00179 
00181 
00184     void                fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const;
00185 
00187 
00190     void                fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const;
00191 
00193 
00194 private:
00195     class CDesk {
00196     public:
00197         CString         m_name;
00198         CThread*        m_thread;
00199         DWORD           m_threadID;
00200         DWORD           m_targetID;
00201         HDESK           m_desk;
00202         HWND            m_window;
00203         HWND            m_foregroundWindow;
00204         bool            m_lowLevel;
00205     };
00206     typedef std::map<CString, CDesk*> CDesks;
00207 
00208     // initialization and shutdown operations
00209     void                queryHookLibrary(HINSTANCE hookLibrary);
00210     HCURSOR             createBlankCursor() const;
00211     void                destroyCursor(HCURSOR cursor) const;
00212     ATOM                createDeskWindowClass(bool isPrimary) const;
00213     void                destroyClass(ATOM windowClass) const;
00214     HWND                createWindow(ATOM windowClass, const char* name) const;
00215     void                destroyWindow(HWND) const;
00216 
00217     // message handlers
00218     void                deskMouseMove(SInt32 x, SInt32 y) const;
00219     void                deskMouseRelativeMove(SInt32 dx, SInt32 dy) const;
00220     void                deskEnter(CDesk* desk);
00221     void                deskLeave(CDesk* desk, HKL keyLayout);
00222     void                deskThread(void* vdesk);
00223     void                xinputThread();
00224 
00225     // desk switch checking and handling
00226     CDesk*              addDesk(const CString& name, HDESK hdesk);
00227     void                removeDesks();
00228     void                checkDesk();
00229     bool                isDeskAccessible(const CDesk* desk) const;
00230     void                handleCheckDesk(const CEvent& event, void*);
00231 
00232     // communication with desk threads
00233     void                waitForDesk() const;
00234     void                sendMessage(UINT, WPARAM, LPARAM) const;
00235 
00236     // work around for messed up keyboard events from low-level hooks
00237     HWND                getForegroundWindow() const;
00238 
00239     // desk API wrappers
00240     HDESK               openInputDesktop();
00241     void                closeDesktop(HDESK);
00242     CString             getDesktopName(HDESK);
00243 
00244     // our desk window procs
00245     static LRESULT CALLBACK primaryDeskProc(HWND, UINT, WPARAM, LPARAM);
00246     static LRESULT CALLBACK secondaryDeskProc(HWND, UINT, WPARAM, LPARAM);
00247 
00248 private:
00249     // true if screen is being used as a primary screen, false otherwise
00250     bool                m_isPrimary;
00251 
00252     // true if hooks are not to be installed (useful for debugging)
00253     bool                m_noHooks;
00254 
00255     // true if windows 95/98/me
00256     bool                m_is95Family;
00257 
00258     // true if windows 98/2k or higher (i.e. not 95/nt)
00259     bool                m_isModernFamily;
00260 
00261     // true if mouse has entered the screen
00262     bool                m_isOnScreen;
00263 
00264     // our resources
00265     ATOM                m_deskClass;
00266     HCURSOR             m_cursor;
00267 
00268     // screen shape stuff
00269     SInt32              m_x, m_y;
00270     SInt32              m_w, m_h;
00271     SInt32              m_xCenter, m_yCenter;
00272 
00273     // true if system appears to have multiple monitors
00274     bool                m_multimon;
00275 
00276     // the timer used to check for desktop switching
00277     CEventQueueTimer*   m_timer;
00278 
00279     // screen saver stuff
00280     DWORD               m_threadID;
00281     const IScreenSaver* m_screensaver;
00282     bool                m_screensaverNotify;
00283 
00284     // the current desk and it's name
00285     CDesk*              m_activeDesk;
00286     CString             m_activeDeskName;
00287 
00288     // one desk per desktop and a cond var to communicate with it
00289     CMutex              m_mutex;
00290     CCondVar<bool>      m_deskReady;
00291     CDesks              m_desks;
00292 
00293     // hook library stuff
00294     InstallFunc         m_install;
00295     UninstallFunc       m_uninstall;
00296     InstallScreenSaverFunc
00297                         m_installScreensaver;
00298     UninstallScreenSaverFunc
00299                         m_uninstallScreensaver;
00300 
00301     // keyboard stuff
00302     IJob*               m_updateKeys;
00303     HKL                 m_keyLayout;
00304 
00305     // options
00306     bool                m_leaveForegroundOption;
00307 
00308     IEventQueue&        m_eventQueue;
00309 
00310     // true if program should stop on desk switch.
00311     bool                m_stopOnDeskSwitch;
00312 };
00313 
00314 #endif

Generated on Thu Jun 20 2013 00:00:05 for Synergy by  doxygen 1.7.1