2002-08-02 19:57:46 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2002 Chris Schoeneman
|
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2001-11-19 00:33:36 +00:00
|
|
|
#ifndef CMSWINDOWSSCREEN_H
|
|
|
|
#define CMSWINDOWSSCREEN_H
|
|
|
|
|
2003-09-02 22:05:47 +00:00
|
|
|
#include "IPlatformScreen.h"
|
|
|
|
#include "CMSWindowsKeyMapper.h"
|
2002-07-15 15:01:36 +00:00
|
|
|
#include "CSynergyHook.h"
|
2002-06-10 22:06:45 +00:00
|
|
|
#include "CMutex.h"
|
2002-06-11 20:09:59 +00:00
|
|
|
#include "CString.h"
|
2002-06-10 16:49:46 +00:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2001-11-19 00:33:36 +00:00
|
|
|
#include <windows.h>
|
|
|
|
|
2002-06-23 21:53:31 +00:00
|
|
|
class CMSWindowsScreenSaver;
|
2002-07-15 15:01:36 +00:00
|
|
|
class IScreenReceiver;
|
2003-09-02 22:05:47 +00:00
|
|
|
class IPrimaryScreenReceiver;
|
2002-07-15 15:01:36 +00:00
|
|
|
|
2003-09-02 22:05:47 +00:00
|
|
|
//! Implementation of IPlatformScreen for Microsoft Windows
|
|
|
|
class CMSWindowsScreen : public IPlatformScreen {
|
2002-04-29 14:40:01 +00:00
|
|
|
public:
|
2003-09-02 22:05:47 +00:00
|
|
|
CMSWindowsScreen(IScreenReceiver*, IPrimaryScreenReceiver*);
|
2001-11-19 00:33:36 +00:00
|
|
|
virtual ~CMSWindowsScreen();
|
|
|
|
|
2002-07-29 17:03:55 +00:00
|
|
|
//! @name manipulators
|
|
|
|
//@{
|
2001-11-19 00:33:36 +00:00
|
|
|
|
2002-07-29 17:03:55 +00:00
|
|
|
//! Initialize
|
|
|
|
/*!
|
|
|
|
Saves the application's HINSTANCE. This \b must be called by
|
|
|
|
WinMain with the HINSTANCE it was passed.
|
|
|
|
*/
|
2001-11-19 00:33:36 +00:00
|
|
|
static void init(HINSTANCE);
|
|
|
|
|
2002-07-29 17:03:55 +00:00
|
|
|
//@}
|
|
|
|
//! @name accessors
|
|
|
|
//@{
|
2002-06-08 21:48:00 +00:00
|
|
|
|
2002-07-29 17:03:55 +00:00
|
|
|
//! Get instance
|
|
|
|
/*!
|
|
|
|
Returns the application instance handle passed to init().
|
|
|
|
*/
|
2002-06-08 21:48:00 +00:00
|
|
|
static HINSTANCE getInstance();
|
|
|
|
|
2002-07-29 17:03:55 +00:00
|
|
|
//@}
|
|
|
|
|
2003-09-02 22:05:47 +00:00
|
|
|
// IPlatformScreen overrides
|
|
|
|
virtual void open(IKeyState*);
|
|
|
|
virtual void close();
|
|
|
|
virtual void enable();
|
|
|
|
virtual void disable();
|
|
|
|
virtual void mainLoop();
|
|
|
|
virtual void exitMainLoop();
|
|
|
|
virtual void enter();
|
|
|
|
virtual bool leave();
|
|
|
|
virtual bool setClipboard(ClipboardID, const IClipboard*);
|
|
|
|
virtual void checkClipboards();
|
|
|
|
virtual void openScreensaver(bool notify);
|
|
|
|
virtual void closeScreensaver();
|
|
|
|
virtual void screensaver(bool activate);
|
|
|
|
virtual void resetOptions();
|
|
|
|
virtual void setOptions(const COptionsList& options);
|
|
|
|
virtual void updateKeys();
|
|
|
|
virtual bool isPrimary() const;
|
|
|
|
virtual bool getClipboard(ClipboardID, IClipboard*) const;
|
|
|
|
virtual void getShape(SInt32&, SInt32&, SInt32&, SInt32&) const;
|
|
|
|
virtual void getCursorPos(SInt32&, SInt32&) const;
|
|
|
|
|
|
|
|
// IPrimaryScreen overrides
|
|
|
|
virtual void reconfigure(UInt32 activeSides);
|
|
|
|
virtual void warpCursor(SInt32 x, SInt32 y);
|
|
|
|
virtual UInt32 addOneShotTimer(double timeout);
|
|
|
|
virtual SInt32 getJumpZoneSize() const;
|
|
|
|
virtual bool isAnyMouseButtonDown() const;
|
|
|
|
virtual const char* getKeyName(KeyButton) const;
|
|
|
|
|
|
|
|
// ISecondaryScreen overrides
|
|
|
|
virtual void fakeKeyEvent(KeyButton id, bool press) const;
|
|
|
|
virtual bool fakeCtrlAltDel() const;
|
|
|
|
virtual void fakeMouseButton(ButtonID id, bool press) const;
|
|
|
|
virtual void fakeMouseMove(SInt32 x, SInt32 y) const;
|
|
|
|
virtual void fakeMouseWheel(SInt32 delta) const;
|
|
|
|
virtual KeyButton mapKey(IKeyState::Keystrokes&,
|
|
|
|
const IKeyState& keyState, KeyID id,
|
|
|
|
KeyModifierMask desiredMask,
|
|
|
|
bool isAutoRepeat) const;
|
2001-11-19 00:33:36 +00:00
|
|
|
|
2002-07-15 15:01:36 +00:00
|
|
|
private:
|
2002-05-24 17:54:28 +00:00
|
|
|
// update screen size cache
|
2002-06-19 17:03:29 +00:00
|
|
|
void updateScreenShape();
|
2002-05-24 17:54:28 +00:00
|
|
|
|
2002-07-15 15:01:36 +00:00
|
|
|
// switch to the given desktop. this destroys the window and unhooks
|
|
|
|
// all hooks, switches the desktop, then creates the window and rehooks
|
|
|
|
// all hooks (because you can't switch the thread's desktop if it has
|
|
|
|
// any windows or hooks).
|
|
|
|
bool switchDesktop(HDESK desk);
|
2002-07-11 18:58:49 +00:00
|
|
|
|
2003-09-02 22:05:47 +00:00
|
|
|
// make sure we're on the expected desktop
|
|
|
|
void syncDesktop() const;
|
|
|
|
|
|
|
|
// handle message before it gets dispatched. returns true iff
|
|
|
|
// the message should not be dispatched.
|
|
|
|
bool onPreDispatch(HWND, UINT, WPARAM, LPARAM);
|
|
|
|
|
|
|
|
// handle message before it gets dispatched. returns true iff
|
|
|
|
// the message should not be dispatched.
|
|
|
|
bool onPreDispatchPrimary(HWND, UINT, WPARAM, LPARAM);
|
|
|
|
|
|
|
|
// handle message. returns true iff handled and optionally sets
|
|
|
|
// \c *result (which defaults to 0).
|
|
|
|
bool onEvent(HWND, UINT, WPARAM, LPARAM, LRESULT* result);
|
|
|
|
|
|
|
|
// message handlers
|
|
|
|
bool onMark(UInt32 mark);
|
|
|
|
bool onKey(WPARAM, LPARAM);
|
|
|
|
bool onMouseButton(WPARAM, LPARAM);
|
|
|
|
bool onMouseMove(SInt32 x, SInt32 y);
|
|
|
|
bool onMouseWheel(SInt32 delta);
|
|
|
|
bool onScreensaver(bool activated);
|
|
|
|
bool onTimer(UINT timerID);
|
|
|
|
bool onDisplayChange();
|
|
|
|
bool onClipboardChange();
|
|
|
|
bool onActivate(bool activated);
|
|
|
|
|
|
|
|
// XXX
|
|
|
|
// warp cursor without discarding queued events
|
|
|
|
void warpCursorNoFlush(SInt32 x, SInt32 y);
|
|
|
|
|
|
|
|
// discard posted messages
|
|
|
|
void nextMark();
|
|
|
|
|
|
|
|
// test if event should be ignored
|
|
|
|
bool ignore() const;
|
|
|
|
// XXX
|
|
|
|
|
|
|
|
// create the transparent cursor
|
|
|
|
HCURSOR createBlankCursor() const;
|
|
|
|
|
|
|
|
// show/hide the cursor
|
|
|
|
void showCursor(bool) const;
|
|
|
|
|
|
|
|
// enable/disable special key combinations so we can catch/pass them
|
|
|
|
void enableSpecialKeys(bool) const;
|
2002-06-08 21:48:00 +00:00
|
|
|
|
2003-09-02 22:05:47 +00:00
|
|
|
// map a button ID and action to a mouse event
|
|
|
|
DWORD mapButtonToEvent(ButtonID button,
|
|
|
|
bool press, DWORD* inData) const;
|
2002-06-08 21:48:00 +00:00
|
|
|
|
2003-09-02 22:05:47 +00:00
|
|
|
// map a button event to a button ID
|
|
|
|
ButtonID mapButtonFromEvent(WPARAM msg, LPARAM button) const;
|
|
|
|
|
|
|
|
// return true iff the given virtual key is a modifier
|
|
|
|
bool isModifier(UINT vkCode) const;
|
|
|
|
|
|
|
|
// send ctrl+alt+del hotkey event
|
|
|
|
static void ctrlAltDelThread(void*);
|
2002-06-08 21:48:00 +00:00
|
|
|
|
2002-07-12 20:41:23 +00:00
|
|
|
// our window proc
|
2001-11-19 00:33:36 +00:00
|
|
|
static LRESULT CALLBACK wndProc(HWND, UINT, WPARAM, LPARAM);
|
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
private:
|
2001-11-19 00:33:36 +00:00
|
|
|
static HINSTANCE s_instance;
|
2002-07-15 15:01:36 +00:00
|
|
|
|
2003-09-02 22:05:47 +00:00
|
|
|
// true if screen is being used as a primary screen, false otherwise
|
|
|
|
bool m_isPrimary;
|
2002-07-15 15:01:36 +00:00
|
|
|
|
|
|
|
// true if windows 95/98/me
|
|
|
|
bool m_is95Family;
|
|
|
|
|
2003-09-02 22:05:47 +00:00
|
|
|
// receivers
|
|
|
|
IScreenReceiver* m_receiver;
|
|
|
|
IPrimaryScreenReceiver* m_primaryReceiver;
|
|
|
|
|
|
|
|
// true if mouse has entered the screen
|
|
|
|
bool m_isOnScreen;
|
|
|
|
|
|
|
|
// our resources
|
|
|
|
ATOM m_class;
|
|
|
|
HCURSOR m_cursor;
|
2002-07-15 15:01:36 +00:00
|
|
|
HWND m_window;
|
|
|
|
|
2003-09-02 22:05:47 +00:00
|
|
|
// screen shape stuff
|
2002-06-19 17:03:29 +00:00
|
|
|
SInt32 m_x, m_y;
|
2001-11-19 00:33:36 +00:00
|
|
|
SInt32 m_w, m_h;
|
2003-09-02 22:05:47 +00:00
|
|
|
SInt32 m_xCenter, m_yCenter;
|
2002-07-15 15:01:36 +00:00
|
|
|
|
|
|
|
// true if system appears to have multiple monitors
|
|
|
|
bool m_multimon;
|
|
|
|
|
2003-09-02 22:05:47 +00:00
|
|
|
// last mouse position
|
|
|
|
SInt32 m_xCursor, m_yCursor;
|
|
|
|
|
|
|
|
// used to discard queued messages that are no longer needed
|
|
|
|
UInt32 m_mark;
|
|
|
|
UInt32 m_markReceived;
|
|
|
|
|
2002-07-15 15:01:36 +00:00
|
|
|
// the main loop's thread id
|
|
|
|
DWORD m_threadID;
|
|
|
|
|
|
|
|
// the thread id of the last attached thread
|
|
|
|
DWORD m_lastThreadID;
|
|
|
|
|
|
|
|
// the timer used to check for desktop switching
|
|
|
|
UINT m_timer;
|
|
|
|
|
2003-03-12 22:34:07 +00:00
|
|
|
// the one shot timer
|
|
|
|
UINT m_oneShotTimer;
|
|
|
|
|
2003-09-02 22:05:47 +00:00
|
|
|
// screen saver stuff
|
|
|
|
CMSWindowsScreenSaver* m_screensaver;
|
|
|
|
bool m_screensaverNotify;
|
|
|
|
|
|
|
|
// clipboard stuff
|
|
|
|
HWND m_nextClipboardWindow;
|
|
|
|
bool m_ownClipboard;
|
|
|
|
|
2002-07-15 15:01:36 +00:00
|
|
|
// the current desk and it's name
|
|
|
|
HDESK m_desk;
|
|
|
|
CString m_deskName;
|
|
|
|
|
2003-05-17 20:58:27 +00:00
|
|
|
// true when the current desktop is inaccessible. while
|
|
|
|
// the desktop is inaccessible we won't receive user input
|
|
|
|
// and we'll lose track of the keyboard state. when the
|
|
|
|
// desktop becomes accessible again we'll notify the event
|
|
|
|
// handler of that.
|
|
|
|
bool m_inaccessibleDesktop;
|
|
|
|
|
2003-09-02 22:05:47 +00:00
|
|
|
// hook library stuff
|
|
|
|
HINSTANCE m_hookLibrary;
|
|
|
|
InitFunc m_init;
|
|
|
|
CleanupFunc m_cleanup;
|
|
|
|
InstallFunc m_install;
|
|
|
|
UninstallFunc m_uninstall;
|
|
|
|
SetSidesFunc m_setSides;
|
|
|
|
SetZoneFunc m_setZone;
|
|
|
|
SetModeFunc m_setMode;
|
|
|
|
InstallScreenSaverFunc m_installScreensaver;
|
|
|
|
UninstallScreenSaverFunc m_uninstallScreensaver;
|
|
|
|
bool m_lowLevel;
|
|
|
|
|
|
|
|
// keyboard stuff
|
|
|
|
IKeyState* m_keyState;
|
|
|
|
CMSWindowsKeyMapper m_keyMapper;
|
|
|
|
|
|
|
|
// map of button state
|
|
|
|
BYTE m_buttons[1 + kButtonExtra0 + 1];
|
|
|
|
|
|
|
|
// stuff for hiding the cursor
|
|
|
|
DWORD m_cursorThread;
|
|
|
|
|
2001-11-25 18:32:41 +00:00
|
|
|
static CMSWindowsScreen* s_screen;
|
2001-11-19 00:33:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|