barrier/lib/platform/CMSWindowsPrimaryScreen.h

141 lines
3.8 KiB
C
Raw Normal View History

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.
*/
#ifndef CMSWINDOWSPRIMARYSCREEN_H
#define CMSWINDOWSPRIMARYSCREEN_H
#include "CPrimaryScreen.h"
#include "IMSWindowsScreenEventHandler.h"
#include "CSynergyHook.h"
#include "MouseTypes.h"
#include "CString.h"
class CMSWindowsScreen;
2002-07-11 13:13:37 +00:00
class IScreenReceiver;
class IPrimaryScreenReceiver;
//! Microsoft windows primary screen implementation
class CMSWindowsPrimaryScreen :
public CPrimaryScreen, public IMSWindowsScreenEventHandler {
2002-04-29 14:40:01 +00:00
public:
typedef bool (CMSWindowsPrimaryScreen::*HookMethod)(int, WPARAM, LPARAM);
2002-07-11 13:13:37 +00:00
CMSWindowsPrimaryScreen(IScreenReceiver*, IPrimaryScreenReceiver*);
virtual ~CMSWindowsPrimaryScreen();
// CPrimaryScreen overrides
2002-07-11 13:13:37 +00:00
virtual void reconfigure(UInt32 activeSides);
virtual void warpCursor(SInt32 x, SInt32 y);
virtual void resetOptions();
virtual void setOptions(const COptionsList& options);
virtual UInt32 addOneShotTimer(double timeout);
virtual KeyModifierMask getToggleMask() const;
virtual bool isLockedToScreen() const;
virtual IScreen* getScreen() const;
// IMSWindowsScreenEventHandler overrides
virtual void onScreensaver(bool activated);
virtual bool onPreDispatch(const CEvent* event);
virtual bool onEvent(CEvent* event);
virtual void onOneShotTimerExpired(UInt32 id);
virtual SInt32 getJumpZoneSize() const;
virtual void postCreateWindow(HWND);
virtual void preDestroyWindow(HWND);
virtual void onAccessibleDesktop();
2002-07-11 13:13:37 +00:00
protected:
// CPrimaryScreen overrides
virtual void onPreMainLoop();
virtual void onPreOpen();
virtual void onPostOpen();
virtual void onPostClose();
virtual void onPreEnter();
virtual void onPostEnter();
virtual void onPreLeave();
virtual void onPostLeave(bool);
virtual void createWindow();
virtual void destroyWindow();
virtual bool showWindow();
virtual void hideWindow();
virtual void warpCursorToCenter();
virtual void updateKeys();
private:
void enterNoWarp();
// 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;
// key and button queries
KeyID mapKey(WPARAM keycode, LPARAM info,
KeyModifierMask* maskOut, bool* altgr);
ButtonID mapButton(WPARAM msg, LPARAM button) const;
void updateKey(UINT vkCode, bool press);
bool isModifier(UINT vkCode) const;
KeyButton mapKeyToScanCode(UINT vk1, UINT vk2) const;
2002-04-29 14:40:01 +00:00
private:
IPrimaryScreenReceiver* m_receiver;
CMSWindowsScreen* m_screen;
// true if windows 95/98/me
bool m_is95Family;
// the main loop's thread id
DWORD m_threadID;
// my window
HWND m_window;
// used to discard queued messages that are no longer needed
UInt32 m_mark;
UInt32 m_markReceived;
// map of key state
BYTE m_keys[256];
// map of button state
BYTE m_buttons[1 + kButtonExtra0 + 1];
// last mouse position
SInt32 m_x, m_y;
// position of center pixel of screen
SInt32 m_xCenter, m_yCenter;
// hook library stuff
HINSTANCE m_hookLibrary;
2002-06-23 21:53:31 +00:00
InitFunc m_init;
CleanupFunc m_cleanup;
InstallFunc m_install;
UninstallFunc m_uninstall;
2002-07-11 13:13:37 +00:00
SetSidesFunc m_setSides;
SetZoneFunc m_setZone;
SetRelayFunc m_setRelay;
Fixed a few win32 keyboard/mouse problems. First, the mouse hook now captures non-client area mouse messages. Previously, these were ignored (because i forgot about them) and they caused all kinds of problems because they weren't forwarded. For example, clicking on a window border would cause the window to start resizing when the mouse came back to the server screen. Moving inside a title bar meant that the mouse wouldn't move on the client screen. Second, because non-client messages are now handled, the full screen transparent window is no longer necessary to capture input so it's never displayed. (The window is still necessary for clipboard ownership so it's still created.) No transparent window means no screen flashing. It also means we don't have to become the foreground and active window. This plays better with apps that minimize or restore when they're no longer the foreground application/active window. Third, fixed the low level keyboard hook to forward toggle key updates, which it was neglecting to do. Finally, keyboard and mouse input is always forwarded from the hook to the primary screen handler which then shadows the current key and mouse button state. If we're using low level hooks then this isn't really necessary and GetKeyState() always returns the right info but without low level hooks it means we can just use the shadow state. It also means we don't have to show our window in order to get the system's key state table up to date, fixing the screen flash when checking for the scroll lock state.
2003-05-03 12:54:22 +00:00
bool m_lowLevel;
// stuff for hiding the cursor
DWORD m_cursorThread;
};
#endif