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
|
|
|
|
|
2004-03-26 20:59:26 +00:00
|
|
|
#include "CPlatformScreen.h"
|
2002-07-15 15:01:36 +00:00
|
|
|
#include "CSynergyHook.h"
|
2004-02-28 12:19:49 +00:00
|
|
|
#include "CCondVar.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>
|
|
|
|
|
2004-03-28 14:07:58 +00:00
|
|
|
class CEventQueueTimer;
|
2004-03-26 20:59:26 +00:00
|
|
|
class CMSWindowsDesks;
|
|
|
|
class CMSWindowsKeyState;
|
2002-06-23 21:53:31 +00:00
|
|
|
class CMSWindowsScreenSaver;
|
2004-02-28 12:19:49 +00:00
|
|
|
class CThread;
|
2004-03-13 18:58:20 +00:00
|
|
|
class IJob;
|
2002-07-15 15:01:36 +00:00
|
|
|
|
2003-09-02 22:05:47 +00:00
|
|
|
//! Implementation of IPlatformScreen for Microsoft Windows
|
2004-03-26 20:59:26 +00:00
|
|
|
class CMSWindowsScreen : public CPlatformScreen {
|
2002-04-29 14:40:01 +00:00
|
|
|
public:
|
2004-03-13 17:13:55 +00:00
|
|
|
CMSWindowsScreen(bool isPrimary, IJob* suspend, IJob* resume);
|
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
|
|
|
//@}
|
|
|
|
|
2004-02-28 12:19:49 +00:00
|
|
|
// IScreen overrides
|
|
|
|
virtual void* getEventTarget() const;
|
|
|
|
virtual bool getClipboard(ClipboardID id, IClipboard*) const;
|
|
|
|
virtual void getShape(SInt32& x, SInt32& y,
|
|
|
|
SInt32& width, SInt32& height) const;
|
|
|
|
virtual void getCursorPos(SInt32& x, SInt32& y) const;
|
2003-09-02 22:05:47 +00:00
|
|
|
|
|
|
|
// IPrimaryScreen overrides
|
|
|
|
virtual void reconfigure(UInt32 activeSides);
|
|
|
|
virtual void warpCursor(SInt32 x, SInt32 y);
|
|
|
|
virtual SInt32 getJumpZoneSize() const;
|
|
|
|
virtual bool isAnyMouseButtonDown() const;
|
2004-02-28 12:19:49 +00:00
|
|
|
virtual void getCursorCenter(SInt32& x, SInt32& y) const;
|
2003-09-02 22:05:47 +00:00
|
|
|
|
|
|
|
// ISecondaryScreen overrides
|
|
|
|
virtual void fakeMouseButton(ButtonID id, bool press) const;
|
|
|
|
virtual void fakeMouseMove(SInt32 x, SInt32 y) const;
|
2004-05-02 08:04:15 +00:00
|
|
|
virtual void fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const;
|
2003-09-02 22:05:47 +00:00
|
|
|
virtual void fakeMouseWheel(SInt32 delta) const;
|
2001-11-19 00:33:36 +00:00
|
|
|
|
2004-03-26 20:59:26 +00:00
|
|
|
// IKeyState overrides
|
|
|
|
virtual void updateKeys();
|
2004-05-02 16:06:04 +00:00
|
|
|
virtual void fakeKeyDown(KeyID id, KeyModifierMask mask,
|
|
|
|
KeyButton button);
|
|
|
|
virtual void fakeKeyRepeat(KeyID id, KeyModifierMask mask,
|
|
|
|
SInt32 count, KeyButton button);
|
|
|
|
virtual void fakeKeyUp(KeyButton button);
|
|
|
|
virtual void fakeToggle(KeyModifierMask modifier);
|
2004-02-28 12:19:49 +00:00
|
|
|
|
2004-03-26 20:59:26 +00:00
|
|
|
// IPlatformScreen overrides
|
|
|
|
virtual void enable();
|
|
|
|
virtual void disable();
|
|
|
|
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 setSequenceNumber(UInt32);
|
|
|
|
virtual bool isPrimary() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// IPlatformScreen overrides
|
|
|
|
virtual void handleSystemEvent(const CEvent&, void*);
|
|
|
|
virtual void updateButtons();
|
|
|
|
virtual IKeyState* getKeyState() const;
|
|
|
|
|
|
|
|
private:
|
2004-03-13 17:13:55 +00:00
|
|
|
// initialization and shutdown operations
|
2004-02-28 12:19:49 +00:00
|
|
|
HINSTANCE openHookLibrary(const char* name);
|
|
|
|
void closeHookLibrary(HINSTANCE hookLibrary) const;
|
|
|
|
HCURSOR createBlankCursor() const;
|
|
|
|
void destroyCursor(HCURSOR cursor) const;
|
|
|
|
ATOM createWindowClass() const;
|
|
|
|
ATOM createDeskWindowClass(bool isPrimary) const;
|
|
|
|
void destroyClass(ATOM windowClass) const;
|
|
|
|
HWND createWindow(ATOM windowClass, const char* name) const;
|
|
|
|
void destroyWindow(HWND) const;
|
2004-03-13 17:13:55 +00:00
|
|
|
|
|
|
|
// convenience function to send events
|
2004-02-28 12:19:49 +00:00
|
|
|
void sendEvent(CEvent::Type type, void* = NULL);
|
|
|
|
void sendClipboardEvent(CEvent::Type type, ClipboardID id);
|
2004-03-13 17:13:55 +00:00
|
|
|
|
2003-09-02 22:05:47 +00:00
|
|
|
// 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 onDisplayChange();
|
|
|
|
bool onClipboardChange();
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2004-02-28 12:19:49 +00:00
|
|
|
// update screen size cache
|
|
|
|
void updateScreenShape();
|
2003-09-02 22:05:47 +00:00
|
|
|
|
|
|
|
// 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 event to a button ID
|
|
|
|
ButtonID mapButtonFromEvent(WPARAM msg, LPARAM button) const;
|
|
|
|
|
2004-05-01 08:56:24 +00:00
|
|
|
// map a button event to a press (true) or release (false)
|
|
|
|
bool mapPressFromEvent(WPARAM msg, LPARAM button) const;
|
|
|
|
|
2004-03-28 14:07:58 +00:00
|
|
|
// fix the key state, synthesizing fake key releases for keys
|
|
|
|
// that aren't down anymore.
|
|
|
|
void fixKeys();
|
|
|
|
|
|
|
|
// (un)schedule a later call to fixKeys
|
|
|
|
void scheduleFixKeys();
|
|
|
|
|
|
|
|
// event handler to fix the key state
|
|
|
|
void handleFixKeys(const CEvent&, void*);
|
|
|
|
|
2004-03-26 20:59:26 +00:00
|
|
|
// job to update the key state
|
|
|
|
void updateKeysCB(void*);
|
2002-06-08 21:48:00 +00:00
|
|
|
|
2004-05-02 16:06:04 +00:00
|
|
|
// determine whether the mouse is hidden by the system and force
|
|
|
|
// it to be displayed if user has entered this secondary screen.
|
|
|
|
void forceShowCursor();
|
|
|
|
|
|
|
|
// forceShowCursor uses MouseKeys to show the cursor. since we
|
|
|
|
// don't actually want MouseKeys behavior we have to make sure
|
|
|
|
// it applies when NumLock is in whatever state it's not in now.
|
|
|
|
// this method does that.
|
|
|
|
void updateForceShowCursor();
|
|
|
|
|
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
|
|
|
// true if mouse has entered the screen
|
|
|
|
bool m_isOnScreen;
|
|
|
|
|
|
|
|
// our resources
|
|
|
|
ATOM m_class;
|
2002-07-15 15:01:36 +00:00
|
|
|
|
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;
|
|
|
|
|
2004-04-05 21:08:49 +00:00
|
|
|
// last clipboard
|
2004-02-28 12:19:49 +00:00
|
|
|
UInt32 m_sequenceNumber;
|
|
|
|
|
2003-09-02 22:05:47 +00:00
|
|
|
// 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;
|
|
|
|
|
2004-03-08 20:53:32 +00:00
|
|
|
// the keyboard layout to use when off primary screen
|
|
|
|
HKL m_keyLayout;
|
|
|
|
|
2004-03-28 14:07:58 +00:00
|
|
|
// the timer used to check for fixing key state
|
|
|
|
CEventQueueTimer* m_fixTimer;
|
|
|
|
|
2003-09-02 22:05:47 +00:00
|
|
|
// screen saver stuff
|
|
|
|
CMSWindowsScreenSaver* m_screensaver;
|
|
|
|
bool m_screensaverNotify;
|
2004-11-06 16:13:52 +00:00
|
|
|
bool m_screensaverActive;
|
2003-09-02 22:05:47 +00:00
|
|
|
|
2004-02-28 12:19:49 +00:00
|
|
|
// clipboard stuff. our window is used mainly as a clipboard
|
|
|
|
// owner and as a link in the clipboard viewer chain.
|
|
|
|
HWND m_window;
|
2003-09-02 22:05:47 +00:00
|
|
|
HWND m_nextClipboardWindow;
|
|
|
|
bool m_ownClipboard;
|
|
|
|
|
2004-02-28 12:19:49 +00:00
|
|
|
// one desk per desktop and a cond var to communicate with it
|
2004-03-26 20:59:26 +00:00
|
|
|
CMSWindowsDesks* m_desks;
|
2003-05-17 20:58:27 +00:00
|
|
|
|
2003-09-02 22:05:47 +00:00
|
|
|
// hook library stuff
|
|
|
|
HINSTANCE m_hookLibrary;
|
|
|
|
InitFunc m_init;
|
|
|
|
CleanupFunc m_cleanup;
|
|
|
|
SetSidesFunc m_setSides;
|
|
|
|
SetZoneFunc m_setZone;
|
|
|
|
SetModeFunc m_setMode;
|
|
|
|
|
|
|
|
// keyboard stuff
|
2004-03-26 20:59:26 +00:00
|
|
|
CMSWindowsKeyState* m_keyState;
|
2003-09-02 22:05:47 +00:00
|
|
|
|
|
|
|
// map of button state
|
2004-03-26 20:59:26 +00:00
|
|
|
bool m_buttons[1 + kButtonExtra0 + 1];
|
2003-09-02 22:05:47 +00:00
|
|
|
|
2004-03-13 17:13:55 +00:00
|
|
|
// suspend/resume callbacks
|
|
|
|
IJob* m_suspend;
|
|
|
|
IJob* m_resume;
|
|
|
|
|
2004-05-02 16:06:04 +00:00
|
|
|
// the system shows the mouse cursor when an internal display count
|
|
|
|
// is >= 0. this count is maintained per application but there's
|
|
|
|
// apparently a system wide count added to the application's count.
|
|
|
|
// this system count is 0 if there's a mouse attached to the system
|
|
|
|
// and -1 otherwise. the MouseKeys accessibility feature can modify
|
|
|
|
// this system count by making the system appear to have a mouse.
|
|
|
|
//
|
|
|
|
// m_hasMouse is true iff there's a mouse attached to the system or
|
|
|
|
// MouseKeys is simulating one. we track this so we can force the
|
|
|
|
// cursor to be displayed when the user has entered this screen.
|
|
|
|
// m_showingMouse is true when we're doing that.
|
|
|
|
bool m_hasMouse;
|
|
|
|
bool m_showingMouse;
|
|
|
|
bool m_gotOldMouseKeys;
|
|
|
|
MOUSEKEYS m_mouseKeys;
|
|
|
|
MOUSEKEYS m_oldMouseKeys;
|
|
|
|
|
2001-11-25 18:32:41 +00:00
|
|
|
static CMSWindowsScreen* s_screen;
|
2001-11-19 00:33:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|