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

CMSWindowsDesks.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 CMSWINDOWSDESKS_H
00016 #define CMSWINDOWSDESKS_H
00017 
00018 #include "CSynergyHook.h"
00019 #include "KeyTypes.h"
00020 #include "MouseTypes.h"
00021 #include "OptionTypes.h"
00022 #include "CCondVar.h"
00023 #include "CMutex.h"
00024 #include "CString.h"
00025 #include "stdmap.h"
00026 #define WIN32_LEAN_AND_MEAN
00027 #include <windows.h>
00028 
00029 class CEvent;
00030 class CEventQueueTimer;
00031 class CThread;
00032 class IJob;
00033 class IScreenSaver;
00034 
00036 
00051 class CMSWindowsDesks {
00052 public:
00054 
00062     CMSWindowsDesks(bool isPrimary, HINSTANCE hookLibrary,
00063                             const IScreenSaver* screensaver, IJob* updateKeys);
00064     ~CMSWindowsDesks();
00065 
00067 
00068 
00070 
00076     void                enable();
00077 
00079 
00082     void                disable();
00083 
00085 
00088     void                enter();
00089 
00091 
00094     void                leave(HKL keyLayout);
00095 
00097 
00100     void                resetOptions();
00101 
00103 
00107     void                setOptions(const COptionsList& options);
00108 
00110 
00114     void                updateKeys();
00115 
00117 
00120     void                setShape(SInt32 x, SInt32 y,
00121                             SInt32 width, SInt32 height,
00122                             SInt32 xCenter, SInt32 yCenter, bool isMultimon);
00123 
00125 
00130     void                installScreensaverHooks(bool install);
00131 
00133 
00136     void                fakeInputBegin();
00137 
00139 
00142     void                fakeInputEnd();
00143 
00145 
00146 
00147 
00149 
00152     void                getCursorPos(SInt32& x, SInt32& y) const;
00153 
00155 
00158     void                fakeKeyEvent(KeyButton button, UINT virtualKey,
00159                             bool press, bool isAutoRepeat) const;
00160 
00162 
00165     void                fakeMouseButton(ButtonID id, bool press) const;
00166 
00168 
00171     void                fakeMouseMove(SInt32 x, SInt32 y) const;
00172 
00174 
00177     void                fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const;
00178 
00180 
00183     void                fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const;
00184 
00186 
00187 private:
00188     class CDesk {
00189     public:
00190         CString         m_name;
00191         CThread*        m_thread;
00192         DWORD           m_threadID;
00193         DWORD           m_targetID;
00194         HDESK           m_desk;
00195         HWND            m_window;
00196         HWND            m_foregroundWindow;
00197         bool            m_lowLevel;
00198     };
00199     typedef std::map<CString, CDesk*> CDesks;
00200 
00201     // initialization and shutdown operations
00202     void                queryHookLibrary(HINSTANCE hookLibrary);
00203     HCURSOR             createBlankCursor() const;
00204     void                destroyCursor(HCURSOR cursor) const;
00205     ATOM                createDeskWindowClass(bool isPrimary) const;
00206     void                destroyClass(ATOM windowClass) const;
00207     HWND                createWindow(ATOM windowClass, const char* name) const;
00208     void                destroyWindow(HWND) const;
00209 
00210     // message handlers
00211     void                deskMouseMove(SInt32 x, SInt32 y) const;
00212     void                deskMouseRelativeMove(SInt32 dx, SInt32 dy) const;
00213     void                deskEnter(CDesk* desk);
00214     void                deskLeave(CDesk* desk, HKL keyLayout);
00215     void                deskThread(void* vdesk);
00216 
00217     // desk switch checking and handling
00218     CDesk*              addDesk(const CString& name, HDESK hdesk);
00219     void                removeDesks();
00220     void                checkDesk();
00221     bool                isDeskAccessible(const CDesk* desk) const;
00222     void                handleCheckDesk(const CEvent& event, void*);
00223 
00224     // communication with desk threads
00225     void                waitForDesk() const;
00226     void                sendMessage(UINT, WPARAM, LPARAM) const;
00227 
00228     // work around for messed up keyboard events from low-level hooks
00229     HWND                getForegroundWindow() const;
00230 
00231     // desk API wrappers
00232     HDESK               openInputDesktop();
00233     void                closeDesktop(HDESK);
00234     CString             getDesktopName(HDESK);
00235 
00236     // our desk window procs
00237     static LRESULT CALLBACK primaryDeskProc(HWND, UINT, WPARAM, LPARAM);
00238     static LRESULT CALLBACK secondaryDeskProc(HWND, UINT, WPARAM, LPARAM);
00239 
00240 private:
00241     // true if screen is being used as a primary screen, false otherwise
00242     bool                m_isPrimary;
00243 
00244     // true if windows 95/98/me
00245     bool                m_is95Family;
00246 
00247     // true if windows 98/2k or higher (i.e. not 95/nt)
00248     bool                m_isModernFamily;
00249 
00250     // true if mouse has entered the screen
00251     bool                m_isOnScreen;
00252 
00253     // our resources
00254     ATOM                m_deskClass;
00255     HCURSOR             m_cursor;
00256 
00257     // screen shape stuff
00258     SInt32              m_x, m_y;
00259     SInt32              m_w, m_h;
00260     SInt32              m_xCenter, m_yCenter;
00261 
00262     // true if system appears to have multiple monitors
00263     bool                m_multimon;
00264 
00265     // the timer used to check for desktop switching
00266     CEventQueueTimer*   m_timer;
00267 
00268     // screen saver stuff
00269     DWORD               m_threadID;
00270     const IScreenSaver* m_screensaver;
00271     bool                m_screensaverNotify;
00272 
00273     // the current desk and it's name
00274     CDesk*              m_activeDesk;
00275     CString             m_activeDeskName;
00276 
00277     // one desk per desktop and a cond var to communicate with it
00278     CMutex              m_mutex;
00279     CCondVar<bool>      m_deskReady;
00280     CDesks              m_desks;
00281 
00282     // hook library stuff
00283     InstallFunc         m_install;
00284     UninstallFunc       m_uninstall;
00285     InstallScreenSaverFunc      m_installScreensaver;
00286     UninstallScreenSaverFunc    m_uninstallScreensaver;
00287 
00288     // keyboard stuff
00289     IJob*               m_updateKeys;
00290     HKL                 m_keyLayout;
00291 
00292     // options
00293     bool                m_leaveForegroundOption;
00294 };
00295 
00296 #endif

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