mirror of
https://github.com/debauchee/barrier.git
synced 2026-11-30 07:45:04 +08:00
Merged primary and secondary screens into one class.
This commit is contained in:
75
lib/platform/CMSWindowsDesktop.cpp
Normal file
75
lib/platform/CMSWindowsDesktop.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "CMSWindowsDesktop.h"
|
||||
#include "CLog.h"
|
||||
#include "CArchMiscWindows.h"
|
||||
#include <malloc.h>
|
||||
|
||||
//
|
||||
// CMSWindowsDesktop
|
||||
//
|
||||
|
||||
HDESK
|
||||
CMSWindowsDesktop::openInputDesktop()
|
||||
{
|
||||
if (CArchMiscWindows::isWindows95Family()) {
|
||||
// there's only one desktop on windows 95 et al.
|
||||
return GetThreadDesktop(GetCurrentThreadId());
|
||||
}
|
||||
else {
|
||||
return OpenInputDesktop(DF_ALLOWOTHERACCOUNTHOOK, TRUE,
|
||||
DESKTOP_CREATEWINDOW |
|
||||
DESKTOP_HOOKCONTROL |
|
||||
GENERIC_WRITE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CMSWindowsDesktop::closeDesktop(HDESK desk)
|
||||
{
|
||||
// on 95/98/me we don't need to close the desktop returned by
|
||||
// openInputDesktop().
|
||||
if (desk != NULL && !CArchMiscWindows::isWindows95Family()) {
|
||||
CloseDesktop(desk);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
CMSWindowsDesktop::setDesktop(HDESK desk)
|
||||
{
|
||||
// 95/98/me doesn't support multiple desktops so just return
|
||||
// true on those platforms.
|
||||
return (CArchMiscWindows::isWindows95Family() ||
|
||||
SetThreadDesktop(desk) != 0);
|
||||
}
|
||||
|
||||
CString
|
||||
CMSWindowsDesktop::getDesktopName(HDESK desk)
|
||||
{
|
||||
if (desk == NULL) {
|
||||
return CString();
|
||||
}
|
||||
else if (CArchMiscWindows::isWindows95Family()) {
|
||||
return "desktop";
|
||||
}
|
||||
else {
|
||||
DWORD size;
|
||||
GetUserObjectInformation(desk, UOI_NAME, NULL, 0, &size);
|
||||
TCHAR* name = (TCHAR*)alloca(size + sizeof(TCHAR));
|
||||
GetUserObjectInformation(desk, UOI_NAME, name, size, &size);
|
||||
CString result(name);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
52
lib/platform/CMSWindowsDesktop.h
Normal file
52
lib/platform/CMSWindowsDesktop.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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 CMSWINDOWSDESKTOP_H
|
||||
#define CMSWINDOWSDESKTOP_H
|
||||
|
||||
#include "CString.h"
|
||||
#include <windows.h>
|
||||
|
||||
//! Encapsulate Microsoft Windows desktop
|
||||
class CMSWindowsDesktop {
|
||||
public:
|
||||
//! Open the input desktop
|
||||
/*!
|
||||
Opens the input desktop. The caller must close the desktop.
|
||||
*/
|
||||
static HDESK openInputDesktop();
|
||||
|
||||
//! Close a desktop
|
||||
/*!
|
||||
Closes the given desktop.
|
||||
*/
|
||||
static void closeDesktop(HDESK);
|
||||
|
||||
//! Change current desktop
|
||||
/*!
|
||||
Changes the calling thread's desktop, return true iff successful.
|
||||
The call will fail if the calling thread has any windows or a hooks
|
||||
on the current desktop.
|
||||
*/
|
||||
static bool setDesktop(HDESK);
|
||||
|
||||
//! Get the desktop's name.
|
||||
/*!
|
||||
Returns the current desktop's name. Returns a constant string
|
||||
on 95/98/Me.
|
||||
*/
|
||||
static CString getDesktopName(HDESK);
|
||||
};
|
||||
|
||||
#endif
|
||||
1495
lib/platform/CMSWindowsKeyMapper.cpp
Normal file
1495
lib/platform/CMSWindowsKeyMapper.cpp
Normal file
File diff suppressed because it is too large
Load Diff
142
lib/platform/CMSWindowsKeyMapper.h
Normal file
142
lib/platform/CMSWindowsKeyMapper.h
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2003 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 CMSWINDOWSKEYMAPPER_H
|
||||
#define CMSWINDOWSKEYMAPPER_H
|
||||
|
||||
#include "IKeyState.h"
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
//! Microsoft Windows key mapper
|
||||
/*!
|
||||
This class maps KeyIDs to keystrokes.
|
||||
*/
|
||||
class CMSWindowsKeyMapper {
|
||||
public:
|
||||
CMSWindowsKeyMapper();
|
||||
~CMSWindowsKeyMapper();
|
||||
|
||||
//! @name manipulators
|
||||
//@{
|
||||
|
||||
//! Update key mapper
|
||||
/*!
|
||||
Updates the key mapper's internal tables according to the
|
||||
current keyboard mapping and updates \c keyState.
|
||||
*/
|
||||
void update(IKeyState* keyState);
|
||||
|
||||
//! Update shadow key state
|
||||
/*!
|
||||
Updates the shadow keyboard state.
|
||||
*/
|
||||
void updateKey(KeyButton key, bool pressed);
|
||||
|
||||
//@}
|
||||
//! @name accessors
|
||||
//@{
|
||||
|
||||
//! Map key press/repeat to keystrokes
|
||||
/*!
|
||||
Converts a press/repeat of key \c id with the modifiers as given
|
||||
in \c desiredMask into the keystrokes necessary to synthesize
|
||||
that key event. Returns the platform specific code of the key
|
||||
being pressed, or 0 if the key cannot be mapped or \c isAutoRepeat
|
||||
is true and the key does not auto-repeat.
|
||||
*/
|
||||
KeyButton mapKey(IKeyState::Keystrokes&,
|
||||
const IKeyState& keyState, KeyID id,
|
||||
KeyModifierMask desiredMask,
|
||||
bool isAutoRepeat) const;
|
||||
|
||||
//! Map key event to a key
|
||||
/*!
|
||||
Converts a key event into a KeyID and the shadow modifier state
|
||||
to a modifier mask. If \c altgr is non-NULL it's set to true if
|
||||
the key requires AltGr and false otherwise.
|
||||
*/
|
||||
KeyID mapKeyFromEvent(WPARAM vkCode, LPARAM info,
|
||||
KeyModifierMask* maskOut, bool* altgr) const;
|
||||
|
||||
//! Test shadow key state
|
||||
/*!
|
||||
Returns true iff the shadow state indicates the key is pressed.
|
||||
*/
|
||||
bool isPressed(KeyButton key) const;
|
||||
|
||||
//! Map key to a scan code
|
||||
/*!
|
||||
Returns the scan code for \c key and possibly adjusts \c key.
|
||||
*/
|
||||
UINT keyToScanCode(KeyButton* key) const;
|
||||
|
||||
//! Check for extended key
|
||||
/*!
|
||||
Returns true iff \c key is an extended key
|
||||
*/
|
||||
bool isExtendedKey(KeyButton key) const;
|
||||
|
||||
//! Get name of key
|
||||
/*!
|
||||
Return a string describing the given key.
|
||||
*/
|
||||
const char* getKeyName(KeyButton) const;
|
||||
|
||||
//@}
|
||||
|
||||
private:
|
||||
// convert a language ID to a code page
|
||||
UINT getCodePageFromLangID(LANGID langid) const;
|
||||
|
||||
// map character \c c given keyboard layout \c hkl to the keystrokes
|
||||
// to generate it.
|
||||
KeyButton mapCharacter(IKeyState::Keystrokes& keys,
|
||||
const IKeyState& keyState, char c, HKL hkl,
|
||||
bool isAutoRepeat) const;
|
||||
|
||||
// map \c virtualKey to the keystrokes to generate it, along with
|
||||
// keystrokes to update and restore the modifier state.
|
||||
KeyButton mapToKeystrokes(IKeyState::Keystrokes& keys,
|
||||
const IKeyState& keyState, KeyButton virtualKey,
|
||||
KeyModifierMask desiredMask,
|
||||
KeyModifierMask requiredMask,
|
||||
bool isAutoRepeat) const;
|
||||
|
||||
// get keystrokes to get modifiers in a desired state
|
||||
bool adjustModifiers(IKeyState::Keystrokes& keys,
|
||||
IKeyState::Keystrokes& undo,
|
||||
const IKeyState& keyState,
|
||||
KeyModifierMask desiredMask,
|
||||
KeyModifierMask requiredMask) const;
|
||||
|
||||
private:
|
||||
class CModifierKeys {
|
||||
public:
|
||||
enum { s_maxKeys = 2 };
|
||||
KeyModifierMask m_mask;
|
||||
KeyButton m_keys[s_maxKeys];
|
||||
};
|
||||
|
||||
BYTE m_keys[256];
|
||||
|
||||
static const CModifierKeys s_modifiers[];
|
||||
static const char* s_vkToName[];
|
||||
static const KeyID s_virtualKey[][2];
|
||||
static const KeyButton s_mapE000[];
|
||||
static const KeyButton s_mapEE00[];
|
||||
static const KeyButton s_mapEF00[];
|
||||
};
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,140 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
class IScreenReceiver;
|
||||
class IPrimaryScreenReceiver;
|
||||
|
||||
//! Microsoft windows primary screen implementation
|
||||
class CMSWindowsPrimaryScreen :
|
||||
public CPrimaryScreen, public IMSWindowsScreenEventHandler {
|
||||
public:
|
||||
typedef bool (CMSWindowsPrimaryScreen::*HookMethod)(int, WPARAM, LPARAM);
|
||||
|
||||
CMSWindowsPrimaryScreen(IScreenReceiver*, IPrimaryScreenReceiver*);
|
||||
virtual ~CMSWindowsPrimaryScreen();
|
||||
|
||||
// CPrimaryScreen overrides
|
||||
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();
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
InitFunc m_init;
|
||||
CleanupFunc m_cleanup;
|
||||
InstallFunc m_install;
|
||||
UninstallFunc m_uninstall;
|
||||
SetSidesFunc m_setSides;
|
||||
SetZoneFunc m_setZone;
|
||||
SetRelayFunc m_setRelay;
|
||||
bool m_lowLevel;
|
||||
|
||||
// stuff for hiding the cursor
|
||||
DWORD m_cursorThread;
|
||||
};
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -15,7 +15,8 @@
|
||||
#ifndef CMSWINDOWSSCREEN_H
|
||||
#define CMSWINDOWSSCREEN_H
|
||||
|
||||
#include "IScreen.h"
|
||||
#include "IPlatformScreen.h"
|
||||
#include "CMSWindowsKeyMapper.h"
|
||||
#include "CSynergyHook.h"
|
||||
#include "CMutex.h"
|
||||
#include "CString.h"
|
||||
@@ -23,22 +24,13 @@
|
||||
#include <windows.h>
|
||||
|
||||
class CMSWindowsScreenSaver;
|
||||
class CThread;
|
||||
|
||||
// Microsoft windows event
|
||||
class CEvent {
|
||||
public:
|
||||
MSG m_msg;
|
||||
LRESULT m_result;
|
||||
};
|
||||
|
||||
class IScreenReceiver;
|
||||
class IMSWindowsScreenEventHandler;
|
||||
class IPrimaryScreenReceiver;
|
||||
|
||||
//! Implementation of IScreen for Microsoft Windows
|
||||
class CMSWindowsScreen : public IScreen {
|
||||
//! Implementation of IPlatformScreen for Microsoft Windows
|
||||
class CMSWindowsScreen : public IPlatformScreen {
|
||||
public:
|
||||
CMSWindowsScreen(IScreenReceiver*, IMSWindowsScreenEventHandler*);
|
||||
CMSWindowsScreen(IScreenReceiver*, IPrimaryScreenReceiver*);
|
||||
virtual ~CMSWindowsScreen();
|
||||
|
||||
//! @name manipulators
|
||||
@@ -51,37 +43,10 @@ public:
|
||||
*/
|
||||
static void init(HINSTANCE);
|
||||
|
||||
//! Open desktop
|
||||
/*!
|
||||
Open the desktop and create and return the window. Returns NULL
|
||||
on failure.
|
||||
*/
|
||||
HWND openDesktop();
|
||||
|
||||
//! Close desktop
|
||||
/*!
|
||||
Close the window and desktop.
|
||||
*/
|
||||
void closeDesktop();
|
||||
|
||||
//! Install a one-shot timer
|
||||
/*!
|
||||
Installs a one-shot timer for \c timeout seconds and returns the
|
||||
id of the timer (which will be passed to the receiver's
|
||||
\c onTimerExpired()).
|
||||
*/
|
||||
UInt32 addOneShotTimer(double timeout);
|
||||
|
||||
//@}
|
||||
//! @name accessors
|
||||
//@{
|
||||
|
||||
//! Test for multiple monitors
|
||||
/*!
|
||||
Returns true iff the system appears to have multiple monitors.
|
||||
*/
|
||||
bool isMultimon() const;
|
||||
|
||||
//! Get instance
|
||||
/*!
|
||||
Returns the application instance handle passed to init().
|
||||
@@ -90,53 +55,116 @@ public:
|
||||
|
||||
//@}
|
||||
|
||||
// IScreen overrides
|
||||
// note -- this class expects the hook DLL to have been loaded
|
||||
// and initialized before open() is called.
|
||||
void open();
|
||||
void mainLoop();
|
||||
void exitMainLoop();
|
||||
void close();
|
||||
bool setClipboard(ClipboardID, const IClipboard*);
|
||||
void checkClipboards();
|
||||
void openScreensaver(bool notify);
|
||||
void closeScreensaver();
|
||||
void screensaver(bool activate);
|
||||
void syncDesktop();
|
||||
bool getClipboard(ClipboardID, IClipboard*) const;
|
||||
void getShape(SInt32&, SInt32&, SInt32&, SInt32&) const;
|
||||
void getCursorPos(SInt32&, SInt32&) const;
|
||||
void getCursorCenter(SInt32&, SInt32&) const;
|
||||
// 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;
|
||||
|
||||
private:
|
||||
// update screen size cache
|
||||
void updateScreenShape();
|
||||
|
||||
// internal pre-dispatch event processing
|
||||
bool onPreDispatch(const CEvent* event);
|
||||
|
||||
// internal (post-dispatch) event processing
|
||||
bool onEvent(CEvent* event);
|
||||
|
||||
// create the transparent cursor
|
||||
void createBlankCursor();
|
||||
|
||||
// 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);
|
||||
|
||||
// get the input desktop. caller must CloseDesktop() the result.
|
||||
// do not call under windows 95/98/me.
|
||||
HDESK openInputDesktop() const;
|
||||
// make sure we're on the expected desktop
|
||||
void syncDesktop() const;
|
||||
|
||||
// get the desktop's name. do not call under windows 95/98/me.
|
||||
CString getDesktopName(HDESK) const;
|
||||
// handle message before it gets dispatched. returns true iff
|
||||
// the message should not be dispatched.
|
||||
bool onPreDispatch(HWND, UINT, WPARAM, LPARAM);
|
||||
|
||||
// returns true iff desk is the current desk. do not call under
|
||||
// windows 95/98/me.
|
||||
bool isCurrentDesktop(HDESK desk) const;
|
||||
// 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;
|
||||
|
||||
// map a button ID and action to a mouse event
|
||||
DWORD mapButtonToEvent(ButtonID button,
|
||||
bool press, DWORD* inData) const;
|
||||
|
||||
// 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*);
|
||||
|
||||
// our window proc
|
||||
static LRESULT CALLBACK wndProc(HWND, UINT, WPARAM, LPARAM);
|
||||
@@ -144,53 +172,63 @@ private:
|
||||
private:
|
||||
static HINSTANCE s_instance;
|
||||
|
||||
IScreenReceiver* m_receiver;
|
||||
IMSWindowsScreenEventHandler* m_eventHandler;
|
||||
|
||||
ATOM m_class;
|
||||
HICON m_icon;
|
||||
HCURSOR m_cursor;
|
||||
// true if screen is being used as a primary screen, false otherwise
|
||||
bool m_isPrimary;
|
||||
|
||||
// true if windows 95/98/me
|
||||
bool m_is95Family;
|
||||
|
||||
// our window
|
||||
// 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;
|
||||
HWND m_window;
|
||||
|
||||
// screen shape
|
||||
// screen shape stuff
|
||||
SInt32 m_x, m_y;
|
||||
SInt32 m_w, m_h;
|
||||
SInt32 m_xCenter, m_yCenter;
|
||||
|
||||
// true if system appears to have multiple monitors
|
||||
bool m_multimon;
|
||||
|
||||
// last mouse position
|
||||
SInt32 m_xCursor, m_yCursor;
|
||||
|
||||
// used to discard queued messages that are no longer needed
|
||||
UInt32 m_mark;
|
||||
UInt32 m_markReceived;
|
||||
|
||||
// the main loop's thread id
|
||||
DWORD m_threadID;
|
||||
|
||||
// the thread id of the last attached thread
|
||||
DWORD m_lastThreadID;
|
||||
|
||||
// clipboard stuff
|
||||
HWND m_nextClipboardWindow;
|
||||
bool m_ownClipboard;
|
||||
|
||||
// the timer used to check for desktop switching
|
||||
UINT m_timer;
|
||||
|
||||
// the one shot timer
|
||||
UINT m_oneShotTimer;
|
||||
|
||||
// screen saver stuff
|
||||
CMSWindowsScreenSaver* m_screensaver;
|
||||
bool m_screensaverNotify;
|
||||
|
||||
// clipboard stuff
|
||||
HWND m_nextClipboardWindow;
|
||||
bool m_ownClipboard;
|
||||
|
||||
// the current desk and it's name
|
||||
HDESK m_desk;
|
||||
CString m_deskName;
|
||||
|
||||
// screen saver stuff
|
||||
HINSTANCE m_hookLibrary;
|
||||
InstallScreenSaverFunc m_installScreensaver;
|
||||
UninstallScreenSaverFunc m_uninstallScreensaver;
|
||||
CMSWindowsScreenSaver* m_screensaver;
|
||||
bool m_screensaverNotify;
|
||||
|
||||
// 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
|
||||
@@ -198,6 +236,29 @@ private:
|
||||
// handler of that.
|
||||
bool m_inaccessibleDesktop;
|
||||
|
||||
// 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;
|
||||
|
||||
static CMSWindowsScreen* s_screen;
|
||||
};
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
* 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 CMSWINDOWSSECONDARYSCREEN_H
|
||||
#define CMSWINDOWSSECONDARYSCREEN_H
|
||||
|
||||
// ensure that we get SendInput()
|
||||
#if _WIN32_WINNT <= 0x400
|
||||
#undef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x401
|
||||
#endif
|
||||
|
||||
#include "CSecondaryScreen.h"
|
||||
#include "IMSWindowsScreenEventHandler.h"
|
||||
#include "CMutex.h"
|
||||
#include "CString.h"
|
||||
|
||||
class CMSWindowsScreen;
|
||||
class IScreenReceiver;
|
||||
|
||||
//! Microsoft windows secondary screen implementation
|
||||
class CMSWindowsSecondaryScreen :
|
||||
public CSecondaryScreen, public IMSWindowsScreenEventHandler {
|
||||
public:
|
||||
CMSWindowsSecondaryScreen(IScreenReceiver*);
|
||||
virtual ~CMSWindowsSecondaryScreen();
|
||||
|
||||
// CSecondaryScreen overrides
|
||||
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 void postCreateWindow(HWND);
|
||||
virtual void preDestroyWindow(HWND);
|
||||
virtual void onAccessibleDesktop();
|
||||
|
||||
protected:
|
||||
// CSecondaryScreen overrides
|
||||
virtual void onPreMainLoop();
|
||||
virtual void onPreOpen();
|
||||
virtual void onPreEnter();
|
||||
virtual void onPreLeave();
|
||||
virtual void createWindow();
|
||||
virtual void destroyWindow();
|
||||
virtual void showWindow(SInt32 x, SInt32 y);
|
||||
virtual void hideWindow();
|
||||
virtual void updateKeys(KeyState* sysKeyStates);
|
||||
virtual KeyModifierMask getModifiers() const;
|
||||
|
||||
virtual SysKeyID getUnhanded(SysKeyID) const;
|
||||
virtual SysKeyID getOtherHanded(SysKeyID) const;
|
||||
virtual bool isAutoRepeating(SysKeyID) const;
|
||||
virtual KeyModifierMask getModifierKeyMask(SysKeyID) const;
|
||||
virtual bool isModifierActive(SysKeyID) const;
|
||||
virtual SysKeyID getToggleSysKey(KeyID keyID) const;
|
||||
virtual bool synthesizeCtrlAltDel(EKeyAction);
|
||||
virtual void sync() const;
|
||||
virtual KeyModifierMask
|
||||
mapKey(Keystrokes&, SysKeyID& sysKeyID, KeyID,
|
||||
KeyModifierMask, KeyModifierMask, EKeyAction) const;
|
||||
virtual void fakeKeyEvent(SysKeyID, bool press) const;
|
||||
virtual void fakeMouseButton(ButtonID, bool press) const;
|
||||
virtual void fakeMouseMove(SInt32 x, SInt32 y) const;
|
||||
virtual void fakeMouseWheel(SInt32 delta) const;
|
||||
|
||||
private:
|
||||
class CModifierInfo {
|
||||
public:
|
||||
KeyModifierMask m_mask;
|
||||
UINT m_virtualKey;
|
||||
UINT m_virtualKey2;
|
||||
bool m_isToggle;
|
||||
};
|
||||
|
||||
// open/close desktop (for windows 95/98/me)
|
||||
bool openDesktop();
|
||||
void closeDesktop();
|
||||
|
||||
// make desk the thread desktop (for windows NT/2000/XP)
|
||||
bool switchDesktop(HDESK desk);
|
||||
|
||||
// returns true iff there appear to be multiple monitors
|
||||
bool isMultimon() const;
|
||||
|
||||
// key and button queries and operations
|
||||
DWORD mapButton(ButtonID button,
|
||||
bool press, DWORD* data) const;
|
||||
UINT mapCharacter(Keystrokes& keys,
|
||||
char c, HKL hkl,
|
||||
KeyModifierMask currentMask,
|
||||
KeyModifierMask desiredMask,
|
||||
EKeyAction action) const;
|
||||
KeyModifierMask mapToKeystrokes(Keystrokes& keys,
|
||||
UINT virtualKey,
|
||||
KeyModifierMask currentMask,
|
||||
KeyModifierMask desiredMask,
|
||||
EKeyAction action) const;
|
||||
const CModifierInfo* getModifierInfo(UINT virtualKey) const;
|
||||
|
||||
KeyState getKeyState(UINT virtualKey) const;
|
||||
UINT virtualKeyToScanCode(UINT& virtualKey) const;
|
||||
bool isExtendedKey(UINT virtualKey) const;
|
||||
|
||||
UINT getCodePageFromLangID(LANGID) const;
|
||||
|
||||
// thread that generates fake ctrl+alt+del
|
||||
static void ctrlAltDelThread(void*);
|
||||
|
||||
private:
|
||||
CMutex m_mutex;
|
||||
CMSWindowsScreen* m_screen;
|
||||
|
||||
// true if windows 95/98/me
|
||||
bool m_is95Family;
|
||||
|
||||
// our window
|
||||
HWND m_window;
|
||||
|
||||
// modifier table
|
||||
static const CModifierInfo s_modifier[];
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -82,7 +82,7 @@ static HANDLE g_hookEventLL = NULL;
|
||||
static HHOOK g_keyboardLL = NULL;
|
||||
static HHOOK g_mouseLL = NULL;
|
||||
static bool g_screenSaver = false;
|
||||
static bool g_relay = false;
|
||||
static EHookMode g_mode = kHOOK_WATCH_JUMP_ZONE;
|
||||
static UInt32 g_zoneSides = 0;
|
||||
static SInt32 g_zoneSize = 0;
|
||||
static SInt32 g_xScreen = 0;
|
||||
@@ -151,7 +151,7 @@ keyboardHookHandler(WPARAM wParam, LPARAM lParam)
|
||||
// the scroll lock toggle state.
|
||||
PostThreadMessage(g_threadID, SYNERGY_MSG_KEY, wParam, lParam);
|
||||
|
||||
if (g_relay) {
|
||||
if (g_mode == kHOOK_RELAY_EVENTS) {
|
||||
// let certain keys pass through
|
||||
switch (wParam) {
|
||||
case VK_CAPITAL:
|
||||
@@ -202,18 +202,18 @@ mouseHookHandler(WPARAM wParam, SInt32 x, SInt32 y, SInt32 data)
|
||||
case WM_NCXBUTTONUP:
|
||||
// always relay the event. eat it if relaying.
|
||||
PostThreadMessage(g_threadID, SYNERGY_MSG_MOUSE_BUTTON, wParam, data);
|
||||
return g_relay;
|
||||
return (g_mode == kHOOK_RELAY_EVENTS);
|
||||
|
||||
case WM_MOUSEWHEEL:
|
||||
if (g_relay) {
|
||||
if (g_mode == kHOOK_RELAY_EVENTS) {
|
||||
// relay event
|
||||
PostThreadMessage(g_threadID, SYNERGY_MSG_MOUSE_WHEEL, data, 0);
|
||||
}
|
||||
return g_relay;
|
||||
return (g_mode == kHOOK_RELAY_EVENTS);
|
||||
|
||||
case WM_NCMOUSEMOVE:
|
||||
case WM_MOUSEMOVE:
|
||||
if (g_relay) {
|
||||
if (g_mode == kHOOK_RELAY_EVENTS) {
|
||||
// we want the cursor to be hidden at all times so we
|
||||
// hide the cursor on whatever window has it. but then
|
||||
// we have to show the cursor whenever we leave that
|
||||
@@ -329,7 +329,7 @@ getMessageHook(int code, WPARAM wParam, LPARAM lParam)
|
||||
SYNERGY_MSG_SCREEN_SAVER, TRUE, 0);
|
||||
}
|
||||
}
|
||||
if (g_relay) {
|
||||
if (g_mode == kHOOK_RELAY_EVENTS) {
|
||||
MSG* msg = reinterpret_cast<MSG*>(lParam);
|
||||
if (msg->message == g_wmMouseWheel) {
|
||||
// post message to our window
|
||||
@@ -614,7 +614,7 @@ init(DWORD threadID)
|
||||
g_threadID = threadID;
|
||||
|
||||
// set defaults
|
||||
g_relay = false;
|
||||
g_mode = kHOOK_WATCH_JUMP_ZONE;
|
||||
g_zoneSides = 0;
|
||||
g_zoneSize = 0;
|
||||
g_xScreen = 0;
|
||||
@@ -827,14 +827,14 @@ setZone(SInt32 x, SInt32 y, SInt32 w, SInt32 h, SInt32 jumpZoneSize)
|
||||
}
|
||||
|
||||
void
|
||||
setRelay(int enable)
|
||||
setMode(EHookMode mode)
|
||||
{
|
||||
if ((enable != 0) == g_relay) {
|
||||
if (mode == g_mode) {
|
||||
// no change
|
||||
return;
|
||||
}
|
||||
g_relay = (enable != 0);
|
||||
if (!g_relay) {
|
||||
g_mode = mode;
|
||||
if (g_mode != kHOOK_RELAY_EVENTS) {
|
||||
restoreCursor();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,11 @@ enum EHookResult {
|
||||
kHOOK_OKAY_LL
|
||||
};
|
||||
|
||||
enum EHookMode {
|
||||
kHOOK_WATCH_JUMP_ZONE,
|
||||
kHOOK_RELAY_EVENTS
|
||||
};
|
||||
|
||||
typedef int (*InitFunc)(DWORD targetQueueThreadID);
|
||||
typedef int (*CleanupFunc)(void);
|
||||
typedef EHookResult (*InstallFunc)(void);
|
||||
@@ -57,7 +62,7 @@ typedef int (*InstallScreenSaverFunc)(void);
|
||||
typedef int (*UninstallScreenSaverFunc)(void);
|
||||
typedef void (*SetSidesFunc)(UInt32);
|
||||
typedef void (*SetZoneFunc)(SInt32, SInt32, SInt32, SInt32, SInt32);
|
||||
typedef void (*SetRelayFunc)(int);
|
||||
typedef void (*SetModeFunc)(int);
|
||||
|
||||
CSYNERGYHOOK_API int init(DWORD);
|
||||
CSYNERGYHOOK_API int cleanup(void);
|
||||
@@ -68,7 +73,7 @@ CSYNERGYHOOK_API int uninstallScreenSaver(void);
|
||||
CSYNERGYHOOK_API void setSides(UInt32 sides);
|
||||
CSYNERGYHOOK_API void setZone(SInt32 x, SInt32 y, SInt32 w, SInt32 h,
|
||||
SInt32 jumpZoneSize);
|
||||
CSYNERGYHOOK_API void setRelay(int enable); // relay iff enable != 0
|
||||
CSYNERGYHOOK_API void setMode(EHookMode mode);
|
||||
|
||||
}
|
||||
|
||||
|
||||
910
lib/platform/CXWindowsKeyMapper.cpp
Normal file
910
lib/platform/CXWindowsKeyMapper.cpp
Normal file
@@ -0,0 +1,910 @@
|
||||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2003 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.
|
||||
*/
|
||||
|
||||
#include "CXWindowsKeyMapper.h"
|
||||
#include "CXWindowsUtil.h"
|
||||
#include "CLog.h"
|
||||
#if defined(X_DISPLAY_MISSING)
|
||||
# error X11 is required to build synergy
|
||||
#else
|
||||
# include <X11/X.h>
|
||||
# include <X11/Xutil.h>
|
||||
# define XK_MISCELLANY
|
||||
# define XK_XKB_KEYS
|
||||
# include <X11/keysymdef.h>
|
||||
# if defined(HAVE_X11_XF86KEYSYM_H)
|
||||
# include <X11/XF86keysym.h>
|
||||
# endif
|
||||
# if !defined(XF86XK_Launch0)
|
||||
# define XF86XK_Launch0 0x1008FF40
|
||||
# endif
|
||||
# if !defined(XF86XK_Launch1)
|
||||
# define XF86XK_Launch1 0x1008FF41
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// map special KeyID keys to KeySyms
|
||||
#if defined(HAVE_X11_XF86KEYSYM_H)
|
||||
static const KeySym g_mapE000[] =
|
||||
{
|
||||
/* 0x00 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x08 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x10 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x18 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x20 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x28 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x30 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x38 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x40 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x48 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x50 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x58 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x60 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x68 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x70 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x78 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x80 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x88 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x90 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x98 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0xa0 */ 0, 0, 0, 0,
|
||||
/* 0xa4 */ 0, 0,
|
||||
/* 0xa6 */ XF86XK_Back, XF86XK_Forward,
|
||||
/* 0xa8 */ XF86XK_Refresh, XF86XK_Stop,
|
||||
/* 0xaa */ XF86XK_Search, XF86XK_Favorites,
|
||||
/* 0xac */ XF86XK_HomePage, XF86XK_AudioMute,
|
||||
/* 0xae */ XF86XK_AudioLowerVolume, XF86XK_AudioRaiseVolume,
|
||||
/* 0xb0 */ XF86XK_AudioNext, XF86XK_AudioPrev,
|
||||
/* 0xb2 */ XF86XK_AudioStop, XF86XK_AudioPlay,
|
||||
/* 0xb4 */ XF86XK_Mail, XF86XK_AudioMedia,
|
||||
/* 0xb6 */ XF86XK_Launch0, XF86XK_Launch1,
|
||||
/* 0xb8 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0xc0 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0xc8 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0xd0 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0xd8 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0xe0 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0xe8 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0xf0 */ 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0xf8 */ 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
#endif
|
||||
|
||||
CXWindowsKeyMapper::CXWindowsKeyMapper()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
CXWindowsKeyMapper::~CXWindowsKeyMapper()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void
|
||||
CXWindowsKeyMapper::update(Display* display, IKeyState* keyState)
|
||||
{
|
||||
// query which keys are pressed
|
||||
char keys[32];
|
||||
XQueryKeymap(display, keys);
|
||||
|
||||
// query the pointer to get the keyboard state
|
||||
Window root = DefaultRootWindow(display), window;
|
||||
int xRoot, yRoot, xWindow, yWindow;
|
||||
unsigned int state;
|
||||
if (!XQueryPointer(display, root, &root, &window,
|
||||
&xRoot, &yRoot, &xWindow, &yWindow, &state)) {
|
||||
state = 0;
|
||||
}
|
||||
|
||||
// update mappings
|
||||
updateKeysymMap(display, keyState);
|
||||
updateModifiers();
|
||||
|
||||
// transfer to our state
|
||||
for (UInt32 i = 0, j = 0; i < 32; j += 8, ++i) {
|
||||
if ((keys[i] & 0x01) != 0)
|
||||
keyState->setKeyDown(j + 0);
|
||||
if ((keys[i] & 0x02) != 0)
|
||||
keyState->setKeyDown(j + 1);
|
||||
if ((keys[i] & 0x04) != 0)
|
||||
keyState->setKeyDown(j + 2);
|
||||
if ((keys[i] & 0x08) != 0)
|
||||
keyState->setKeyDown(j + 3);
|
||||
if ((keys[i] & 0x10) != 0)
|
||||
keyState->setKeyDown(j + 4);
|
||||
if ((keys[i] & 0x20) != 0)
|
||||
keyState->setKeyDown(j + 5);
|
||||
if ((keys[i] & 0x40) != 0)
|
||||
keyState->setKeyDown(j + 6);
|
||||
if ((keys[i] & 0x80) != 0)
|
||||
keyState->setKeyDown(j + 7);
|
||||
}
|
||||
|
||||
// set toggle modifier states
|
||||
if ((state & LockMask) != 0)
|
||||
keyState->setToggled(KeyModifierCapsLock);
|
||||
if ((state & m_numLockMask) != 0)
|
||||
keyState->setToggled(KeyModifierNumLock);
|
||||
if ((state & m_scrollLockMask) != 0)
|
||||
keyState->setToggled(KeyModifierScrollLock);
|
||||
}
|
||||
|
||||
KeyButton
|
||||
CXWindowsKeyMapper::mapKey(IKeyState::Keystrokes& keys,
|
||||
const IKeyState& keyState, KeyID id,
|
||||
KeyModifierMask desiredMask,
|
||||
bool isAutoRepeat) const
|
||||
{
|
||||
// the system translates key events into characters depending
|
||||
// on the modifier key state at the time of the event. to
|
||||
// generate the right keysym we need to set the modifier key
|
||||
// states appropriately.
|
||||
//
|
||||
// desiredMask is the mask desired by the caller. however, there
|
||||
// may not be a keycode mapping to generate the desired keysym
|
||||
// with that mask. we override the bits in the mask that cannot
|
||||
// be accomodated.
|
||||
|
||||
// convert KeyID to a KeySym
|
||||
KeySym keysym = keyIDToKeySym(id, desiredMask);
|
||||
if (keysym == NoSymbol) {
|
||||
// unknown key
|
||||
return 0;
|
||||
}
|
||||
|
||||
// get the mapping for this keysym
|
||||
KeySymIndex keyIndex = m_keysymMap.find(keysym);
|
||||
|
||||
// if the mapping isn't found and keysym is caps lock sensitive
|
||||
// then convert the case of the keysym and try again.
|
||||
if (keyIndex == m_keysymMap.end()) {
|
||||
KeySym lKey, uKey;
|
||||
XConvertCase(keysym, &lKey, &uKey);
|
||||
if (lKey != uKey) {
|
||||
if (lKey == keysym) {
|
||||
keyIndex = m_keysymMap.find(uKey);
|
||||
}
|
||||
else {
|
||||
keyIndex = m_keysymMap.find(lKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (keyIndex != m_keysymMap.end()) {
|
||||
// the keysym is mapped to some keycode. create the keystrokes
|
||||
// for this keysym.
|
||||
return mapToKeystrokes(keys, keyState, keyIndex, isAutoRepeat);
|
||||
}
|
||||
|
||||
// we can't find the keysym mapped to any keycode. this doesn't
|
||||
// necessarily mean we can't generate the keysym, though. if the
|
||||
// keysym can be created by combining keysyms then we may still
|
||||
// be okay.
|
||||
CXWindowsUtil::KeySyms decomposition;
|
||||
if (!CXWindowsUtil::decomposeKeySym(keysym, decomposition)) {
|
||||
return 0;
|
||||
}
|
||||
LOG((CLOG_DEBUG2 "decomposed keysym 0x%08x into %d keysyms", keysym, decomposition.size()));
|
||||
|
||||
// map each decomposed keysym to keystrokes. we want the mask
|
||||
// and the keycode from the last keysym (which should be the
|
||||
// only non-dead key). the dead keys are not sensitive to
|
||||
// anything but shift and mode switch.
|
||||
KeyButton keycode = 0;
|
||||
for (CXWindowsUtil::KeySyms::const_iterator i = decomposition.begin();
|
||||
i != decomposition.end(); ++i) {
|
||||
// lookup the key
|
||||
keysym = *i;
|
||||
keyIndex = m_keysymMap.find(keysym);
|
||||
if (keyIndex == m_keysymMap.end()) {
|
||||
// missing a required keysym
|
||||
return 0;
|
||||
}
|
||||
|
||||
// the keysym is mapped to some keycode
|
||||
keycode = mapToKeystrokes(keys, keyState, keyIndex, isAutoRepeat);
|
||||
if (keycode == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return keycode;
|
||||
}
|
||||
|
||||
KeyModifierMask
|
||||
CXWindowsKeyMapper::mapModifier(unsigned int state) const
|
||||
{
|
||||
KeyModifierMask mask = 0;
|
||||
if (state & ShiftMask)
|
||||
mask |= KeyModifierShift;
|
||||
if (state & LockMask)
|
||||
mask |= KeyModifierCapsLock;
|
||||
if (state & ControlMask)
|
||||
mask |= KeyModifierControl;
|
||||
if (state & m_altMask)
|
||||
mask |= KeyModifierAlt;
|
||||
if (state & m_metaMask)
|
||||
mask |= KeyModifierMeta;
|
||||
if (state & m_superMask)
|
||||
mask |= KeyModifierSuper;
|
||||
if (state & m_modeSwitchMask)
|
||||
mask |= KeyModifierModeSwitch;
|
||||
if (state & m_numLockMask)
|
||||
mask |= KeyModifierNumLock;
|
||||
if (state & m_scrollLockMask)
|
||||
mask |= KeyModifierScrollLock;
|
||||
return mask;
|
||||
}
|
||||
|
||||
void
|
||||
CXWindowsKeyMapper::updateKeysymMap(Display* display, IKeyState* keyState)
|
||||
{
|
||||
// there are up to 4 keysyms per keycode
|
||||
static const unsigned int maxKeysyms = 4;
|
||||
|
||||
// get the number of keycodes
|
||||
int minKeycode, maxKeycode;
|
||||
XDisplayKeycodes(display, &minKeycode, &maxKeycode);
|
||||
const int numKeycodes = maxKeycode - minKeycode + 1;
|
||||
|
||||
// get the keyboard mapping for all keys
|
||||
int keysymsPerKeycode;
|
||||
KeySym* keysyms = XGetKeyboardMapping(display,
|
||||
minKeycode, numKeycodes,
|
||||
&keysymsPerKeycode);
|
||||
|
||||
// we only understand up to maxKeysyms keysyms per keycodes
|
||||
unsigned int numKeysyms = keysymsPerKeycode;
|
||||
if (numKeysyms > maxKeysyms) {
|
||||
numKeysyms = maxKeysyms;
|
||||
}
|
||||
|
||||
// determine shift and mode switch sensitivity. a keysym is shift
|
||||
// or mode switch sensitive if its keycode is. a keycode is mode
|
||||
// mode switch sensitive if it has keysyms for indices 2 or 3.
|
||||
// it's shift sensitive if the keysym for index 1 (if any) is
|
||||
// different from the keysym for index 0 and, if the keysym for
|
||||
// for index 3 (if any) is different from the keysym for index 2.
|
||||
// that is, if shift changes the generated keysym for the keycode.
|
||||
std::vector<bool> usesShift(numKeycodes);
|
||||
std::vector<bool> usesModeSwitch(numKeycodes);
|
||||
for (int i = 0; i < numKeycodes; ++i) {
|
||||
// check mode switch first
|
||||
if (numKeysyms > 2 &&
|
||||
keysyms[i * keysymsPerKeycode + 2] != NoSymbol ||
|
||||
keysyms[i * keysymsPerKeycode + 3] != NoSymbol) {
|
||||
usesModeSwitch[i] = true;
|
||||
}
|
||||
|
||||
// check index 0 with index 1 keysyms
|
||||
if (keysyms[i * keysymsPerKeycode + 0] != NoSymbol &&
|
||||
keysyms[i * keysymsPerKeycode + 1] != NoSymbol &&
|
||||
keysyms[i * keysymsPerKeycode + 1] !=
|
||||
keysyms[i * keysymsPerKeycode + 0]) {
|
||||
usesShift[i] = true;
|
||||
}
|
||||
|
||||
else if (numKeysyms >= 4 &&
|
||||
keysyms[i * keysymsPerKeycode + 2] != NoSymbol &&
|
||||
keysyms[i * keysymsPerKeycode + 3] != NoSymbol &&
|
||||
keysyms[i * keysymsPerKeycode + 3] !=
|
||||
keysyms[i * keysymsPerKeycode + 2]) {
|
||||
usesShift[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// get modifier map from server
|
||||
XModifierKeymap* modifiers = XGetModifierMapping(display);
|
||||
int keysPerModifier = modifiers->max_keypermod;
|
||||
|
||||
// clear state
|
||||
m_keysymMap.clear();
|
||||
m_modeSwitchKeysym = NoSymbol;
|
||||
m_altMask = 0;
|
||||
m_metaMask = 0;
|
||||
m_superMask = 0;
|
||||
m_modeSwitchMask = 0;
|
||||
m_numLockMask = 0;
|
||||
m_scrollLockMask = 0;
|
||||
|
||||
// work around for my system, which reports this state bit when
|
||||
// mode switch is down, instead of the appropriate modifier bit.
|
||||
// should have no effect on other systems. -crs 9/02.
|
||||
m_modeSwitchMask |= (1 << 13);
|
||||
|
||||
// for each modifier keycode, get the index 0 keycode and add it to
|
||||
// the keysym map. also collect all keycodes for each modifier.
|
||||
for (unsigned int i = 0; i < 8; ++i) {
|
||||
// no keycodes for this modifier yet
|
||||
bool hasKeycode = false;
|
||||
KeyModifierMask mask = 0;
|
||||
IKeyState::KeyButtons modifierKeys;
|
||||
|
||||
// add each keycode for modifier
|
||||
for (unsigned int j = 0; j < keysPerModifier; ++j) {
|
||||
// get keycode and ignore unset keycodes
|
||||
KeyCode keycode = modifiers->modifiermap[i * keysPerModifier + j];
|
||||
if (keycode == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// get keysym and get/create key mapping
|
||||
const int keycodeIndex = keycode - minKeycode;
|
||||
const KeySym keysym = keysyms[keycodeIndex *
|
||||
keysymsPerKeycode + 0];
|
||||
|
||||
// get modifier mask if we haven't yet. this has the side
|
||||
// effect of setting the m_*Mask members.
|
||||
if (mask == 0) {
|
||||
mask = mapToModifierMask(i, keysym);
|
||||
if (mask == 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// save keycode for modifier
|
||||
modifierKeys.push_back(keycode);
|
||||
|
||||
// skip if we already have a keycode for this index
|
||||
KeyMapping& mapping = m_keysymMap[keysym];
|
||||
if (mapping.m_keycode[0] != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// fill in keysym info
|
||||
mapping.m_keycode[0] = keycode;
|
||||
mapping.m_shiftSensitive[0] = usesShift[keycodeIndex];
|
||||
mapping.m_modeSwitchSensitive[0] = usesModeSwitch[keycodeIndex];
|
||||
mapping.m_modifierMask = mask;
|
||||
mapping.m_capsLockSensitive = false;
|
||||
mapping.m_numLockSensitive = false;
|
||||
}
|
||||
|
||||
// tell keyState about this modifier
|
||||
if (mask != 0 && keyState != NULL) {
|
||||
keyState->addModifier(mask, modifierKeys);
|
||||
}
|
||||
}
|
||||
|
||||
// create a convenient NoSymbol entry (if it doesn't exist yet).
|
||||
// sometimes it's useful to handle NoSymbol like a normal keysym.
|
||||
// remove any entry for NoSymbol. that keysym doesn't count.
|
||||
{
|
||||
KeyMapping& mapping = m_keysymMap[NoSymbol];
|
||||
for (unsigned int i = 0; i < numKeysyms; ++i) {
|
||||
mapping.m_keycode[i] = 0;
|
||||
mapping.m_shiftSensitive[i] = false;
|
||||
mapping.m_modeSwitchSensitive[i] = false;
|
||||
}
|
||||
mapping.m_modifierMask = 0;
|
||||
mapping.m_capsLockSensitive = false;
|
||||
mapping.m_numLockSensitive = false;
|
||||
}
|
||||
|
||||
// add each keysym to the map, unless we've already inserted a key
|
||||
// for that keysym index.
|
||||
for (int i = 0; i < numKeycodes; ++i) {
|
||||
for (unsigned int j = 0; j < numKeysyms; ++j) {
|
||||
// lookup keysym
|
||||
const KeySym keysym = keysyms[i * keysymsPerKeycode + j];
|
||||
if (keysym == NoSymbol) {
|
||||
continue;
|
||||
}
|
||||
KeyMapping& mapping = m_keysymMap[keysym];
|
||||
|
||||
// skip if we already have a keycode for this index
|
||||
if (mapping.m_keycode[j] != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// fill in keysym info
|
||||
if (mapping.m_keycode[0] == 0) {
|
||||
mapping.m_modifierMask = 0;
|
||||
}
|
||||
mapping.m_keycode[j] = static_cast<KeyCode>(
|
||||
minKeycode + i);
|
||||
mapping.m_shiftSensitive[j] = usesShift[i];
|
||||
mapping.m_modeSwitchSensitive[j] = usesModeSwitch[i];
|
||||
mapping.m_numLockSensitive = isNumLockSensitive(keysym);
|
||||
mapping.m_capsLockSensitive = isCapsLockSensitive(keysym);
|
||||
}
|
||||
}
|
||||
|
||||
// clean up
|
||||
XFreeModifiermap(modifiers);
|
||||
XFree(keysyms);
|
||||
}
|
||||
|
||||
KeyModifierMask
|
||||
CXWindowsKeyMapper::mapToModifierMask(unsigned int i, KeySym keysym)
|
||||
{
|
||||
// some modifier indices (0,1,2) are dedicated to particular uses,
|
||||
// the rest depend on the keysyms bound.
|
||||
switch (i) {
|
||||
case 0:
|
||||
return KeyModifierShift;
|
||||
|
||||
case 1:
|
||||
return KeyModifierCapsLock;
|
||||
|
||||
case 2:
|
||||
return KeyModifierControl;
|
||||
|
||||
default:
|
||||
switch (keysym) {
|
||||
case XK_Shift_L:
|
||||
case XK_Shift_R:
|
||||
return KeyModifierShift;
|
||||
|
||||
case XK_Control_L:
|
||||
case XK_Control_R:
|
||||
return KeyModifierControl;
|
||||
|
||||
case XK_Alt_L:
|
||||
case XK_Alt_R:
|
||||
m_altMask = (1 << i);
|
||||
return KeyModifierAlt;
|
||||
|
||||
case XK_Meta_L:
|
||||
case XK_Meta_R:
|
||||
m_metaMask = (1 << i);
|
||||
return KeyModifierMeta;
|
||||
|
||||
case XK_Super_L:
|
||||
case XK_Super_R:
|
||||
m_superMask = (1 << i);
|
||||
return KeyModifierSuper;
|
||||
|
||||
case XK_Mode_switch:
|
||||
m_modeSwitchMask = (1 << i);
|
||||
return KeyModifierModeSwitch;
|
||||
|
||||
case XK_Caps_Lock:
|
||||
return KeyModifierCapsLock;
|
||||
|
||||
case XK_Num_Lock:
|
||||
m_numLockMask = (1 << i);
|
||||
return KeyModifierNumLock;
|
||||
|
||||
case XK_Scroll_Lock:
|
||||
m_scrollLockMask = (1 << i);
|
||||
return KeyModifierScrollLock;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CXWindowsKeyMapper::updateModifiers()
|
||||
{
|
||||
struct CModifierBitInfo {
|
||||
public:
|
||||
KeySym CXWindowsKeyMapper::*m_keysym;
|
||||
KeySym m_left;
|
||||
KeySym m_right;
|
||||
};
|
||||
static const CModifierBitInfo s_modifierBitTable[] = {
|
||||
{ &CXWindowsKeyMapper::m_modeSwitchKeysym, XK_Mode_switch, NoSymbol },
|
||||
};
|
||||
|
||||
// choose the keysym to use for some modifiers. if a modifier has
|
||||
// both left and right versions then (arbitrarily) prefer the left.
|
||||
for (size_t i = 0; i < sizeof(s_modifierBitTable) /
|
||||
sizeof(s_modifierBitTable[0]); ++i) {
|
||||
const CModifierBitInfo& info = s_modifierBitTable[i];
|
||||
|
||||
// find available keysym
|
||||
KeySymIndex keyIndex = m_keysymMap.find(info.m_left);
|
||||
if (keyIndex == m_keysymMap.end() && info.m_right != NoSymbol) {
|
||||
keyIndex = m_keysymMap.find(info.m_right);
|
||||
}
|
||||
|
||||
// save modifier info
|
||||
if (keyIndex != m_keysymMap.end() &&
|
||||
keyIndex->second.m_modifierMask != 0) {
|
||||
this->*(info.m_keysym) = keyIndex->first;
|
||||
}
|
||||
}
|
||||
|
||||
// if there's no mode switch key mapped then remove all keycodes
|
||||
// that depend on it and no keycode can be mode switch sensitive.
|
||||
if (m_modeSwitchKeysym == NoSymbol) {
|
||||
LOG((CLOG_DEBUG2 "no mode switch in keymap"));
|
||||
for (KeySymMap::iterator i = m_keysymMap.begin();
|
||||
i != m_keysymMap.end(); ) {
|
||||
i->second.m_keycode[2] = 0;
|
||||
i->second.m_keycode[3] = 0;
|
||||
i->second.m_modeSwitchSensitive[0] = false;
|
||||
i->second.m_modeSwitchSensitive[1] = false;
|
||||
i->second.m_modeSwitchSensitive[2] = false;
|
||||
i->second.m_modeSwitchSensitive[3] = false;
|
||||
|
||||
// if this keysym no has no keycodes then remove it
|
||||
// except for the NoSymbol keysym mapping.
|
||||
if (i->second.m_keycode[0] == 0 && i->second.m_keycode[1] == 0) {
|
||||
m_keysymMap.erase(i++);
|
||||
}
|
||||
else {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KeySym
|
||||
CXWindowsKeyMapper::keyIDToKeySym(KeyID id, KeyModifierMask mask) const
|
||||
{
|
||||
// convert id to keysym
|
||||
KeySym keysym = NoSymbol;
|
||||
if ((id & 0xfffff000) == 0xe000) {
|
||||
// special character
|
||||
switch (id & 0x0000ff00) {
|
||||
#if defined(HAVE_X11_XF86KEYSYM_H)
|
||||
case 0xe000:
|
||||
return g_mapE000[id & 0xff];
|
||||
#endif
|
||||
|
||||
case 0xee00:
|
||||
// ISO 9995 Function and Modifier Keys
|
||||
if (id == kKeyLeftTab) {
|
||||
keysym = XK_ISO_Left_Tab;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0xef00:
|
||||
// MISCELLANY
|
||||
keysym = static_cast<KeySym>(id - 0xef00 + 0xff00);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if ((id >= 0x0020 && id <= 0x007e) ||
|
||||
(id >= 0x00a0 && id <= 0x00ff)) {
|
||||
// Latin-1 maps directly
|
||||
return static_cast<KeySym>(id);
|
||||
}
|
||||
else {
|
||||
// lookup keysym in table
|
||||
return CXWindowsUtil::mapUCS4ToKeySym(id);
|
||||
}
|
||||
|
||||
// fail if unknown key
|
||||
if (keysym == NoSymbol) {
|
||||
return keysym;
|
||||
}
|
||||
|
||||
// if kKeyTab is requested with shift active then try XK_ISO_Left_Tab
|
||||
// instead. if that doesn't work, we'll fall back to XK_Tab with
|
||||
// shift active. this is to handle primary screens that don't map
|
||||
// XK_ISO_Left_Tab sending events to secondary screens that do.
|
||||
if (keysym == XK_Tab && (mask & KeyModifierShift) != 0) {
|
||||
keysym = XK_ISO_Left_Tab;
|
||||
}
|
||||
|
||||
// some keysyms have emergency backups (particularly the numpad
|
||||
// keys since most laptops don't have a separate numpad and the
|
||||
// numpad overlaying the main keyboard may not have movement
|
||||
// key bindings). figure out the emergency backup.
|
||||
KeySym backupKeysym;
|
||||
switch (keysym) {
|
||||
case XK_KP_Home:
|
||||
backupKeysym = XK_Home;
|
||||
break;
|
||||
|
||||
case XK_KP_Left:
|
||||
backupKeysym = XK_Left;
|
||||
break;
|
||||
|
||||
case XK_KP_Up:
|
||||
backupKeysym = XK_Up;
|
||||
break;
|
||||
|
||||
case XK_KP_Right:
|
||||
backupKeysym = XK_Right;
|
||||
break;
|
||||
|
||||
case XK_KP_Down:
|
||||
backupKeysym = XK_Down;
|
||||
break;
|
||||
|
||||
case XK_KP_Prior:
|
||||
backupKeysym = XK_Prior;
|
||||
break;
|
||||
|
||||
case XK_KP_Next:
|
||||
backupKeysym = XK_Next;
|
||||
break;
|
||||
|
||||
case XK_KP_End:
|
||||
backupKeysym = XK_End;
|
||||
break;
|
||||
|
||||
case XK_KP_Insert:
|
||||
backupKeysym = XK_Insert;
|
||||
break;
|
||||
|
||||
case XK_KP_Delete:
|
||||
backupKeysym = XK_Delete;
|
||||
break;
|
||||
|
||||
case XK_ISO_Left_Tab:
|
||||
backupKeysym = XK_Tab;
|
||||
break;
|
||||
|
||||
default:
|
||||
backupKeysym = keysym;
|
||||
break;
|
||||
}
|
||||
|
||||
// see if the keysym is assigned to any keycode. if not and the
|
||||
// backup keysym is then use the backup keysym.
|
||||
if (backupKeysym != keysym &&
|
||||
m_keysymMap.find(keysym) == m_keysymMap.end() &&
|
||||
m_keysymMap.find(backupKeysym) != m_keysymMap.end()) {
|
||||
keysym = backupKeysym;
|
||||
}
|
||||
|
||||
return keysym;
|
||||
}
|
||||
|
||||
KeyButton
|
||||
CXWindowsKeyMapper::mapToKeystrokes(IKeyState::Keystrokes& keys,
|
||||
const IKeyState& keyState,
|
||||
KeySymIndex keyIndex,
|
||||
bool isAutoRepeat) const
|
||||
{
|
||||
// keyIndex must be valid
|
||||
assert(keyIndex != m_keysymMap.end());
|
||||
|
||||
KeyModifierMask currentMask = keyState.getActiveModifiers();
|
||||
|
||||
// get the keysym we're trying to generate and possible keycodes
|
||||
const KeySym keysym = keyIndex->first;
|
||||
const KeyMapping& mapping = keyIndex->second;
|
||||
LOG((CLOG_DEBUG2 "keysym = 0x%08x", keysym));
|
||||
|
||||
// get the best keycode index for the keysym and modifiers. note
|
||||
// that (bestIndex & 1) == 0 if the keycode is a shift modifier
|
||||
// and (bestIndex & 2) == 0 if the keycode is a mode switch
|
||||
// modifier. this is important later because we don't want
|
||||
// adjustModifiers() to adjust a modifier if that's the key we're
|
||||
// mapping.
|
||||
unsigned int bestIndex = findBestKeyIndex(keyIndex, currentMask);
|
||||
|
||||
// get the keycode
|
||||
KeyButton keycode = mapping.m_keycode[bestIndex];
|
||||
|
||||
// flip low bit of bestIndex if shift is inverted. if there's a
|
||||
// keycode for this new index then use it. otherwise use the old
|
||||
// keycode. you'd think we should fail if there isn't a keycode
|
||||
// for the new index but some keymaps only include the upper case
|
||||
// keysyms (notably those on Sun Solaris) so to handle the missing
|
||||
// lower case keysyms we just use the old keycode. note that
|
||||
// isShiftInverted() will always return false for a shift modifier.
|
||||
if (isShiftInverted(keyIndex, currentMask)) {
|
||||
LOG((CLOG_DEBUG2 "shift is inverted"));
|
||||
bestIndex ^= 1;
|
||||
if (mapping.m_keycode[bestIndex] != 0) {
|
||||
keycode = mapping.m_keycode[bestIndex];
|
||||
}
|
||||
}
|
||||
LOG((CLOG_DEBUG2 "bestIndex = %d, keycode = %d", bestIndex, keycode));
|
||||
|
||||
// if this for auto-repeat and this key does not auto-repeat
|
||||
// then return 0.
|
||||
if (isAutoRepeat &&
|
||||
(m_keyControl.auto_repeats[keycode >> 3] &
|
||||
static_cast<char>(1 << (keycode & 7))) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// compute desired mask. the desired mask is the one that matches
|
||||
// bestIndex, except if the key being synthesized is a shift key
|
||||
// where we desire what we already have or if it's the mode switch
|
||||
// key where we only desire to adjust shift. also, if the keycode
|
||||
// is not sensitive to shift then don't adjust it, otherwise
|
||||
// something like shift+home would become just home. similiarly
|
||||
// for mode switch.
|
||||
KeyModifierMask desiredMask = currentMask;
|
||||
if (keyIndex->second.m_modifierMask != KeyModifierShift) {
|
||||
if (keyIndex->second.m_shiftSensitive[bestIndex]) {
|
||||
if ((bestIndex & 1) != 0) {
|
||||
desiredMask |= KeyModifierShift;
|
||||
}
|
||||
else {
|
||||
desiredMask &= ~KeyModifierShift;
|
||||
}
|
||||
}
|
||||
if (keyIndex->second.m_modifierMask != KeyModifierModeSwitch) {
|
||||
if (keyIndex->second.m_modeSwitchSensitive[bestIndex]) {
|
||||
if ((bestIndex & 2) != 0) {
|
||||
desiredMask |= KeyModifierModeSwitch;
|
||||
}
|
||||
else {
|
||||
desiredMask &= ~KeyModifierModeSwitch;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// adjust the modifiers to match the desired modifiers
|
||||
IKeyState::Keystrokes undo;
|
||||
if (!adjustModifiers(keys, undo, keyState, desiredMask)) {
|
||||
LOG((CLOG_DEBUG2 "failed to adjust modifiers"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// add the key event
|
||||
IKeyState::Keystroke keystroke;
|
||||
keystroke.m_key = keycode;
|
||||
if (!isAutoRepeat) {
|
||||
keystroke.m_press = true;
|
||||
keystroke.m_repeat = false;
|
||||
keys.push_back(keystroke);
|
||||
}
|
||||
else {
|
||||
keystroke.m_press = false;
|
||||
keystroke.m_repeat = true;
|
||||
keys.push_back(keystroke);
|
||||
keystroke.m_press = true;
|
||||
keys.push_back(keystroke);
|
||||
}
|
||||
|
||||
// put undo keystrokes at end of keystrokes in reverse order
|
||||
while (!undo.empty()) {
|
||||
keys.push_back(undo.back());
|
||||
undo.pop_back();
|
||||
}
|
||||
|
||||
return keycode;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
CXWindowsKeyMapper::findBestKeyIndex(KeySymIndex keyIndex,
|
||||
KeyModifierMask /*currentMask*/) const
|
||||
{
|
||||
// there are up to 4 keycodes per keysym to choose from. the
|
||||
// best choice is the one that requires the fewest adjustments
|
||||
// to the modifier state. for example, the letter A normally
|
||||
// requires shift + a. if shift isn't already down we'd have
|
||||
// to synthesize a shift press before the a press. however,
|
||||
// if A could also be created with some other keycode without
|
||||
// shift then we'd prefer that when shift wasn't down.
|
||||
//
|
||||
// if the action is an auto-repeat then we don't call this
|
||||
// method since we just need to synthesize a key repeat on the
|
||||
// same keycode that we pressed.
|
||||
// XXX -- do this right
|
||||
for (unsigned int i = 0; i < 4; ++i) {
|
||||
if (keyIndex->second.m_keycode[i] != 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
assert(0 && "no keycode found for keysym");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool
|
||||
CXWindowsKeyMapper::isShiftInverted(KeySymIndex keyIndex,
|
||||
KeyModifierMask currentMask) const
|
||||
{
|
||||
// each keycode has up to 4 keysym associated with it, one each for:
|
||||
// no modifiers, shift, mode switch, and shift and mode switch. if
|
||||
// a keysym is modified by num lock and num lock is active then you
|
||||
// get the shifted keysym when shift is not down and the unshifted
|
||||
// keysym when it is. that is, num lock inverts the sense of the
|
||||
// shift modifier when active. similarly for caps lock. this
|
||||
// method returns true iff the sense of shift should be inverted
|
||||
// for this key given a modifier state.
|
||||
if (keyIndex->second.m_numLockSensitive) {
|
||||
if ((currentMask & KeyModifierNumLock) != 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// if a keysym is num lock sensitive it is never caps lock
|
||||
// sensitive, thus the else here.
|
||||
else if (keyIndex->second.m_capsLockSensitive) {
|
||||
if ((currentMask & KeyModifierCapsLock) != 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
CXWindowsKeyMapper::adjustModifiers(IKeyState::Keystrokes& keys,
|
||||
IKeyState::Keystrokes& undo,
|
||||
const IKeyState& keyState,
|
||||
KeyModifierMask desiredMask) const
|
||||
{
|
||||
KeyModifierMask currentMask = keyState.getActiveModifiers();
|
||||
|
||||
// get mode switch set correctly. do this before shift because
|
||||
// mode switch may be sensitive to the shift modifier and will
|
||||
// set/reset it as necessary.
|
||||
const bool wantModeSwitch = ((desiredMask & KeyModifierModeSwitch) != 0);
|
||||
const bool haveModeSwitch = ((currentMask & KeyModifierModeSwitch) != 0);
|
||||
if (wantModeSwitch != haveModeSwitch) {
|
||||
LOG((CLOG_DEBUG2 "fix mode switch"));
|
||||
|
||||
// adjust shift if necessary
|
||||
KeySymIndex modeSwitchIndex = m_keysymMap.find(m_modeSwitchKeysym);
|
||||
assert(modeSwitchIndex != m_keysymMap.end());
|
||||
if (modeSwitchIndex->second.m_shiftSensitive[0]) {
|
||||
const bool wantShift = false;
|
||||
const bool haveShift = ((currentMask & KeyModifierShift) != 0);
|
||||
if (wantShift != haveShift) {
|
||||
// add shift keystrokes
|
||||
LOG((CLOG_DEBUG2 "fix shift for mode switch"));
|
||||
if (!keyState.mapModifier(keys, undo,
|
||||
KeyModifierShift, wantShift)) {
|
||||
return false;
|
||||
}
|
||||
currentMask ^= KeyModifierShift;
|
||||
}
|
||||
}
|
||||
|
||||
// add mode switch keystrokes
|
||||
if (!keyState.mapModifier(keys, undo,
|
||||
KeyModifierModeSwitch, wantModeSwitch)) {
|
||||
return false;
|
||||
}
|
||||
currentMask ^= KeyModifierModeSwitch;
|
||||
}
|
||||
|
||||
// get shift set correctly
|
||||
const bool wantShift = ((desiredMask & KeyModifierShift) != 0);
|
||||
const bool haveShift = ((currentMask & KeyModifierShift) != 0);
|
||||
if (wantShift != haveShift) {
|
||||
// add shift keystrokes
|
||||
LOG((CLOG_DEBUG2 "fix shift"));
|
||||
if (!keyState.mapModifier(keys, undo, KeyModifierShift, wantShift)) {
|
||||
return false;
|
||||
}
|
||||
currentMask ^= KeyModifierShift;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
CXWindowsKeyMapper::isNumLockSensitive(KeySym keysym) const
|
||||
{
|
||||
return (IsKeypadKey(keysym) || IsPrivateKeypadKey(keysym));
|
||||
}
|
||||
|
||||
bool
|
||||
CXWindowsKeyMapper::isCapsLockSensitive(KeySym keysym) const
|
||||
{
|
||||
KeySym lKey, uKey;
|
||||
XConvertCase(keysym, &lKey, &uKey);
|
||||
return (lKey != uKey);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// CXWindowsKeyMapper::KeyMapping
|
||||
//
|
||||
|
||||
CXWindowsKeyMapper::KeyMapping::KeyMapping()
|
||||
{
|
||||
m_keycode[0] = 0;
|
||||
m_keycode[1] = 0;
|
||||
m_keycode[2] = 0;
|
||||
m_keycode[3] = 0;
|
||||
}
|
||||
153
lib/platform/CXWindowsKeyMapper.h
Normal file
153
lib/platform/CXWindowsKeyMapper.h
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2003 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 CXWINDOWSKEYMAPPER_H
|
||||
#define CXWINDOWSKEYMAPPER_H
|
||||
|
||||
#include "IKeyState.h"
|
||||
#include "stdmap.h"
|
||||
#if defined(X_DISPLAY_MISSING)
|
||||
# error X11 is required to build synergy
|
||||
#else
|
||||
# include <X11/Xlib.h>
|
||||
#endif
|
||||
|
||||
//! X Windows key mapper
|
||||
/*!
|
||||
This class maps KeyIDs to keystrokes.
|
||||
*/
|
||||
class CXWindowsKeyMapper {
|
||||
public:
|
||||
CXWindowsKeyMapper();
|
||||
~CXWindowsKeyMapper();
|
||||
|
||||
//! @name manipulators
|
||||
//@{
|
||||
|
||||
//! Update key mapper
|
||||
/*!
|
||||
Updates the key mapper's internal tables according to the display's
|
||||
current keyboard mapping and updates \c keyState.
|
||||
*/
|
||||
void update(Display*, IKeyState* keyState);
|
||||
|
||||
//@}
|
||||
//! @name accessors
|
||||
//@{
|
||||
|
||||
//! Map key press/repeat to keystrokes
|
||||
/*!
|
||||
Converts a press/repeat of key \c id with the modifiers as given
|
||||
in \c desiredMask into the keystrokes necessary to synthesize
|
||||
that key event. Returns the platform specific code of the key
|
||||
being pressed, or 0 if the key cannot be mapped or \c isAutoRepeat
|
||||
is true and the key does not auto-repeat.
|
||||
*/
|
||||
KeyButton mapKey(IKeyState::Keystrokes&,
|
||||
const IKeyState& keyState, KeyID id,
|
||||
KeyModifierMask desiredMask,
|
||||
bool isAutoRepeat) const;
|
||||
|
||||
//! Convert X modifier mask to synergy mask
|
||||
/*!
|
||||
Returns the synergy modifier mask corresponding to the given X
|
||||
modifier mask.
|
||||
*/
|
||||
KeyModifierMask mapModifier(unsigned int state) const;
|
||||
|
||||
//@}
|
||||
|
||||
private:
|
||||
class KeyMapping {
|
||||
public:
|
||||
KeyMapping();
|
||||
|
||||
public:
|
||||
// KeyCode to generate keysym and whether keycode[i] is
|
||||
// sensitive to shift and mode switch.
|
||||
KeyCode m_keycode[4];
|
||||
bool m_shiftSensitive[4];
|
||||
bool m_modeSwitchSensitive[4];
|
||||
|
||||
// the modifier mask of keysym or 0 if not a modifier
|
||||
KeyModifierMask m_modifierMask;
|
||||
|
||||
// whether keysym is sensitive to caps and num lock
|
||||
bool m_numLockSensitive;
|
||||
bool m_capsLockSensitive;
|
||||
};
|
||||
typedef std::map<KeySym, KeyMapping> KeySymMap;
|
||||
typedef KeySymMap::const_iterator KeySymIndex;
|
||||
|
||||
// save the current keyboard mapping and note the currently
|
||||
// pressed keys in \c keyState.
|
||||
void updateKeysymMap(Display* display, IKeyState* keyState);
|
||||
|
||||
// note interesting modifier KeySyms
|
||||
void updateModifiers();
|
||||
|
||||
// map a modifier index and its KeySym to a modifier mask. also
|
||||
// save the modifier mask in one of m_*Mask.
|
||||
KeyModifierMask mapToModifierMask(unsigned int, KeySym);
|
||||
|
||||
// convert a KeyID to a KeySym
|
||||
KeySym keyIDToKeySym(KeyID id, KeyModifierMask mask) const;
|
||||
|
||||
// map a KeySym into the keystrokes to produce it
|
||||
KeyButton mapToKeystrokes(IKeyState::Keystrokes& keys,
|
||||
const IKeyState& keyState,
|
||||
KeySymIndex keyIndex,
|
||||
bool isAutoRepeat) const;
|
||||
|
||||
// choose the best set of modifiers to generate the KeySym
|
||||
unsigned int findBestKeyIndex(KeySymIndex keyIndex,
|
||||
KeyModifierMask currentMask) const;
|
||||
|
||||
// returns true if the sense of shift is inverted for KeySym
|
||||
bool isShiftInverted(KeySymIndex keyIndex,
|
||||
KeyModifierMask currentMask) const;
|
||||
|
||||
// returns the keystrokes to adjust the modifiers into the desired
|
||||
// state the keystrokes to get back to the current state.
|
||||
bool adjustModifiers(IKeyState::Keystrokes& keys,
|
||||
IKeyState::Keystrokes& undo,
|
||||
const IKeyState& keyState,
|
||||
KeyModifierMask desiredMask) const;
|
||||
|
||||
// returns true if keysym is sensitive to the NumLock state
|
||||
bool isNumLockSensitive(KeySym keysym) const;
|
||||
|
||||
// returns true if keysym is sensitive to the CapsLock state
|
||||
bool isCapsLockSensitive(KeySym keysym) const;
|
||||
|
||||
private:
|
||||
// keysym to keycode mapping
|
||||
KeySymMap m_keysymMap;
|
||||
|
||||
// the keyboard control state the last time this screen was entered
|
||||
XKeyboardState m_keyControl;
|
||||
|
||||
// modifier keysyms
|
||||
KeySym m_modeSwitchKeysym;
|
||||
|
||||
// modifier masks
|
||||
unsigned int m_altMask;
|
||||
unsigned int m_metaMask;
|
||||
unsigned int m_superMask;
|
||||
unsigned int m_modeSwitchMask;
|
||||
unsigned int m_numLockMask;
|
||||
unsigned int m_scrollLockMask;
|
||||
};
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
* 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 CXWINDOWSPRIMARYSCREEN_H
|
||||
#define CXWINDOWSPRIMARYSCREEN_H
|
||||
|
||||
#include "CPrimaryScreen.h"
|
||||
#include "IScreenEventHandler.h"
|
||||
#include "MouseTypes.h"
|
||||
#if defined(X_DISPLAY_MISSING)
|
||||
# error X11 is required to build synergy
|
||||
#else
|
||||
# include <X11/Xlib.h>
|
||||
#endif
|
||||
|
||||
class CXWindowsScreen;
|
||||
class IScreenReceiver;
|
||||
class IPrimaryScreenReceiver;
|
||||
|
||||
//! X11 primary screen implementation
|
||||
class CXWindowsPrimaryScreen :
|
||||
public CPrimaryScreen, public IScreenEventHandler {
|
||||
public:
|
||||
CXWindowsPrimaryScreen(IScreenReceiver*, IPrimaryScreenReceiver*);
|
||||
virtual ~CXWindowsPrimaryScreen();
|
||||
|
||||
// CPrimaryScreen overrides
|
||||
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;
|
||||
|
||||
// IScreenEventHandler 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;
|
||||
|
||||
protected:
|
||||
// CPrimaryScreen overrides
|
||||
virtual void onPreMainLoop();
|
||||
virtual void onPreOpen();
|
||||
virtual void onPostOpen();
|
||||
virtual void onPreClose();
|
||||
virtual void onPreEnter();
|
||||
virtual void onPreLeave();
|
||||
virtual void onEnterScreenSaver();
|
||||
|
||||
virtual void createWindow();
|
||||
virtual void destroyWindow();
|
||||
virtual bool showWindow();
|
||||
virtual void hideWindow();
|
||||
virtual void warpCursorToCenter();
|
||||
|
||||
virtual void updateKeys();
|
||||
|
||||
private:
|
||||
void warpCursorNoFlush(Display*,
|
||||
SInt32 xAbsolute, SInt32 yAbsolute);
|
||||
|
||||
void selectEvents(Display*, Window) const;
|
||||
void doSelectEvents(Display*, Window) const;
|
||||
|
||||
KeyModifierMask mapModifier(unsigned int state) const;
|
||||
KeyID mapKey(XKeyEvent*) const;
|
||||
ButtonID mapButton(unsigned int button) const;
|
||||
|
||||
class CKeyEventInfo {
|
||||
public:
|
||||
int m_event;
|
||||
Window m_window;
|
||||
Time m_time;
|
||||
KeyCode m_keycode;
|
||||
};
|
||||
static Bool findKeyEvent(Display*, XEvent* xevent, XPointer arg);
|
||||
|
||||
private:
|
||||
CXWindowsScreen* m_screen;
|
||||
IPrimaryScreenReceiver* m_receiver;
|
||||
|
||||
// our window
|
||||
Window m_window;
|
||||
|
||||
// note toggle keys that toggle on up/down (false) or on
|
||||
// transition (true)
|
||||
bool m_numLockHalfDuplex;
|
||||
bool m_capsLockHalfDuplex;
|
||||
|
||||
// modifier masks
|
||||
unsigned int m_altMask;
|
||||
unsigned int m_metaMask;
|
||||
unsigned int m_superMask;
|
||||
unsigned int m_modeSwitchMask;
|
||||
unsigned int m_numLockMask;
|
||||
unsigned int m_capsLockMask;
|
||||
unsigned int m_scrollLockMask;
|
||||
|
||||
// last mouse position
|
||||
SInt32 m_x, m_y;
|
||||
|
||||
// position of center pixel of screen
|
||||
SInt32 m_xCenter, m_yCenter;
|
||||
|
||||
// input method stuff
|
||||
XIM m_im;
|
||||
XIC m_ic;
|
||||
KeyCode m_lastKeycode;
|
||||
};
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -15,40 +15,28 @@
|
||||
#ifndef CXWINDOWSSCREEN_H
|
||||
#define CXWINDOWSSCREEN_H
|
||||
|
||||
#include "IScreen.h"
|
||||
#include "IPlatformScreen.h"
|
||||
#include "CXWindowsKeyMapper.h"
|
||||
#include "CMutex.h"
|
||||
#include "CStopwatch.h"
|
||||
#include "CPriorityQueue.h"
|
||||
#include "stdvector.h"
|
||||
#if defined(X_DISPLAY_MISSING)
|
||||
# error X11 is required to build synergy
|
||||
#else
|
||||
# include <X11/Xlib.h>
|
||||
#endif
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
class IJob;
|
||||
class IScreenEventHandler;
|
||||
class IScreenReceiver;
|
||||
class CXWindowsClipboard;
|
||||
class CXWindowsScreenSaver;
|
||||
class IJob;
|
||||
class IScreenReceiver;
|
||||
class IPrimaryScreenReceiver;
|
||||
|
||||
/*!
|
||||
\class CEvent
|
||||
\brief User event data
|
||||
An architecture dependent type holding user event data.
|
||||
*/
|
||||
// X11 event
|
||||
class CEvent {
|
||||
//! Implementation of IPlatformScreen for X11
|
||||
class CXWindowsScreen : public IPlatformScreen {
|
||||
public:
|
||||
XEvent m_event;
|
||||
SInt32 m_result;
|
||||
};
|
||||
|
||||
//! Implementation of IScreen for X11
|
||||
class CXWindowsScreen : public IScreen {
|
||||
public:
|
||||
CXWindowsScreen(IScreenReceiver*, IScreenEventHandler*);
|
||||
CXWindowsScreen(IScreenReceiver*, IPrimaryScreenReceiver*);
|
||||
virtual ~CXWindowsScreen();
|
||||
|
||||
//! @name manipulators
|
||||
@@ -56,10 +44,10 @@ public:
|
||||
|
||||
//! Add timer
|
||||
/*!
|
||||
Add a job to invoke every timeout seconds. The job is
|
||||
called with the display locked. If a job timeout expires twice
|
||||
or more before the job can be called then the job is called
|
||||
just once. The caller retains ownership of the job.
|
||||
Add a job to invoke every timeout seconds. The job is called
|
||||
with the display locked. If a job timeout expires twice or
|
||||
more before the job can be called then the job is called just
|
||||
once. The caller retains ownership of the job.
|
||||
*/
|
||||
void addTimer(IJob*, double timeout);
|
||||
|
||||
@@ -69,64 +57,55 @@ public:
|
||||
*/
|
||||
void removeTimer(IJob*);
|
||||
|
||||
//! Install a one-shot timer
|
||||
/*!
|
||||
Installs a one-shot timer for \c timeout seconds and returns the
|
||||
id of the timer (which will be passed to the receiver's
|
||||
\c onTimerExpired()).
|
||||
*/
|
||||
UInt32 addOneShotTimer(double timeout);
|
||||
|
||||
//! Set window
|
||||
/*!
|
||||
Set the window (created by the subclass). This performs some
|
||||
initialization and saves the window in case it's needed later.
|
||||
*/
|
||||
void setWindow(Window);
|
||||
|
||||
//@}
|
||||
//! @name accessors
|
||||
//@{
|
||||
|
||||
//! Get window
|
||||
/*!
|
||||
Returns the root window of the screen.
|
||||
*/
|
||||
Window getRoot() const;
|
||||
|
||||
//! Get transparent cursor
|
||||
/*!
|
||||
Returns a cursor that is transparent everywhere.
|
||||
*/
|
||||
Cursor getBlankCursor() const;
|
||||
|
||||
//@}
|
||||
|
||||
// IScreen overrides
|
||||
void open();
|
||||
void mainLoop();
|
||||
void exitMainLoop();
|
||||
void close();
|
||||
bool setClipboard(ClipboardID, const IClipboard*);
|
||||
void checkClipboards();
|
||||
void openScreensaver(bool notify);
|
||||
void closeScreensaver();
|
||||
void screensaver(bool activate);
|
||||
void syncDesktop();
|
||||
bool getClipboard(ClipboardID, IClipboard*) const;
|
||||
void getShape(SInt32&, SInt32&, SInt32&, SInt32&) const;
|
||||
void getCursorPos(SInt32&, SInt32&) const;
|
||||
void getCursorCenter(SInt32&, SInt32&) const;
|
||||
// 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;
|
||||
|
||||
private:
|
||||
// update screen size cache
|
||||
void updateScreenShape();
|
||||
|
||||
// process events before dispatching to receiver
|
||||
bool onPreDispatch(CEvent* event);
|
||||
void onEvent(XEvent* event);
|
||||
|
||||
// create the transparent cursor
|
||||
void createBlankCursor();
|
||||
Cursor createBlankCursor() const;
|
||||
|
||||
// remove a timer without locking
|
||||
void removeTimerNoLock(IJob*);
|
||||
@@ -149,78 +128,6 @@ private:
|
||||
static int ioErrorHandler(Display*);
|
||||
|
||||
private:
|
||||
// a priority queue will direct access to the elements
|
||||
template <class T, class Container = std::vector<T>,
|
||||
class Compare = std::greater<typename Container::value_type> >
|
||||
class CPriorityQueue {
|
||||
public:
|
||||
typedef typename Container::value_type value_type;
|
||||
typedef typename Container::size_type size_type;
|
||||
typedef typename Container::iterator iterator;
|
||||
typedef Container container_type;
|
||||
|
||||
CPriorityQueue() { }
|
||||
CPriorityQueue(Container& swappedIn);
|
||||
~CPriorityQueue() { }
|
||||
|
||||
// manipulators
|
||||
|
||||
void push(const value_type& v)
|
||||
{
|
||||
c.push_back(v);
|
||||
std::push_heap(c.begin(), c.end(), comp);
|
||||
}
|
||||
|
||||
void pop()
|
||||
{
|
||||
std::pop_heap(c.begin(), c.end(), comp);
|
||||
c.pop_back();
|
||||
}
|
||||
|
||||
iterator begin()
|
||||
{
|
||||
return c.begin();
|
||||
}
|
||||
|
||||
iterator end()
|
||||
{
|
||||
return c.end();
|
||||
}
|
||||
|
||||
void swap(CPriorityQueue<T, Container, Compare>& q)
|
||||
{
|
||||
c.swap(q.c);
|
||||
}
|
||||
|
||||
void swap(Container& c2)
|
||||
{
|
||||
c.swap(c2);
|
||||
std::make_heap(c.begin(), c.end(), comp);
|
||||
}
|
||||
|
||||
// accessors
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return c.empty();
|
||||
}
|
||||
|
||||
size_type size() const
|
||||
{
|
||||
return c.size();
|
||||
}
|
||||
|
||||
const value_type&
|
||||
top() const
|
||||
{
|
||||
return c.front();
|
||||
}
|
||||
|
||||
private:
|
||||
Container c;
|
||||
Compare comp;
|
||||
};
|
||||
|
||||
// a timer priority queue element
|
||||
class CTimer {
|
||||
public:
|
||||
@@ -252,32 +159,80 @@ private:
|
||||
double m_time;
|
||||
double m_startTime;
|
||||
};
|
||||
class CKeyEventInfo {
|
||||
public:
|
||||
int m_event;
|
||||
Window m_window;
|
||||
Time m_time;
|
||||
KeyCode m_keycode;
|
||||
};
|
||||
|
||||
bool isQuitEvent(XEvent*) const;
|
||||
|
||||
Window createWindow() const;
|
||||
void openIM();
|
||||
|
||||
bool grabMouseAndKeyboard();
|
||||
void onKeyPress(XKeyEvent&);
|
||||
void onKeyRelease(XKeyEvent&);
|
||||
void onMousePress(const XButtonEvent&);
|
||||
void onMouseRelease(const XButtonEvent&);
|
||||
void onMouseMove(const XMotionEvent&);
|
||||
|
||||
void selectEvents(Window) const;
|
||||
void doSelectEvents(Window) const;
|
||||
|
||||
KeyID mapKeyFromX(XKeyEvent*) const;
|
||||
ButtonID mapButtonFromX(const XButtonEvent*) const;
|
||||
unsigned int mapButtonToX(ButtonID id) const;
|
||||
|
||||
void warpCursorNoFlush(SInt32 x, SInt32 y);
|
||||
|
||||
void updateButtons();
|
||||
|
||||
static Bool findKeyEvent(Display*, XEvent* xevent, XPointer arg);
|
||||
|
||||
private:
|
||||
friend class CDisplayLock;
|
||||
|
||||
typedef CPriorityQueue<CTimer> CTimerPriorityQueue;
|
||||
|
||||
// true if screen is being used as a primary screen, false otherwise
|
||||
bool m_isPrimary;
|
||||
|
||||
// X is not thread safe
|
||||
CMutex m_mutex;
|
||||
|
||||
Display* m_display;
|
||||
Window m_root;
|
||||
bool m_stop;
|
||||
|
||||
IScreenReceiver* m_receiver;
|
||||
IScreenEventHandler* m_eventHandler;
|
||||
Window m_window;
|
||||
|
||||
IScreenReceiver* m_receiver;
|
||||
IPrimaryScreenReceiver* m_primaryReceiver;
|
||||
|
||||
// true if mouse has entered the screen
|
||||
bool m_isOnScreen;
|
||||
|
||||
// screen shape stuff
|
||||
SInt32 m_x, m_y;
|
||||
SInt32 m_w, m_h;
|
||||
SInt32 m_xCenter, m_yCenter;
|
||||
|
||||
// last mouse position
|
||||
SInt32 m_xCursor, m_yCursor;
|
||||
|
||||
// keyboard stuff
|
||||
IKeyState* m_keyState;
|
||||
CXWindowsKeyMapper m_keyMapper;
|
||||
|
||||
// input method stuff
|
||||
XIM m_im;
|
||||
XIC m_ic;
|
||||
KeyCode m_lastKeycode;
|
||||
|
||||
// clipboards
|
||||
CXWindowsClipboard* m_clipboard[kClipboardEnd];
|
||||
|
||||
// the transparent cursor
|
||||
Cursor m_cursor;
|
||||
// the quit message
|
||||
Atom m_atomQuit;
|
||||
|
||||
// screen saver stuff
|
||||
CXWindowsScreenSaver* m_screensaver;
|
||||
@@ -290,22 +245,23 @@ private:
|
||||
CMutex m_timersMutex;
|
||||
CTimer* m_oneShotTimer;
|
||||
|
||||
// logical to physical button mapping. m_buttons[i] gives the
|
||||
// physical button for logical button i+1.
|
||||
std::vector<unsigned char> m_buttons;
|
||||
|
||||
// true if global auto-repeat was enabled before we turned it off
|
||||
bool m_autoRepeat;
|
||||
|
||||
// stuff to workaround xtest being xinerama unaware. attempting
|
||||
// to fake a mouse motion under xinerama may behave strangely,
|
||||
// especially if screen 0 is not at 0,0 or if faking a motion on
|
||||
// a screen other than screen 0.
|
||||
bool m_xtestIsXineramaUnaware;
|
||||
bool m_xinerama;
|
||||
|
||||
// pointer to (singleton) screen. this is only needed by
|
||||
// ioErrorHandler().
|
||||
static CXWindowsScreen* s_screen;
|
||||
};
|
||||
|
||||
//! Convenience object to lock/unlock a CXWindowsScreen
|
||||
class CDisplayLock {
|
||||
public:
|
||||
CDisplayLock(const CXWindowsScreen*);
|
||||
~CDisplayLock();
|
||||
|
||||
operator Display*() const;
|
||||
|
||||
private:
|
||||
const CMutex* m_mutex;
|
||||
Display* m_display;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,195 +0,0 @@
|
||||
/*
|
||||
* 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 CXWINDOWSSECONDARYSCREEN_H
|
||||
#define CXWINDOWSSECONDARYSCREEN_H
|
||||
|
||||
#include "CSecondaryScreen.h"
|
||||
#include "IScreenEventHandler.h"
|
||||
#include "stdmap.h"
|
||||
#include "stdvector.h"
|
||||
#if defined(X_DISPLAY_MISSING)
|
||||
# error X11 is required to build synergy
|
||||
#else
|
||||
# include <X11/Xlib.h>
|
||||
#endif
|
||||
|
||||
class CXWindowsScreen;
|
||||
class IScreenReceiver;
|
||||
|
||||
//! X11 secondary screen implementation
|
||||
class CXWindowsSecondaryScreen :
|
||||
public CSecondaryScreen, public IScreenEventHandler {
|
||||
public:
|
||||
CXWindowsSecondaryScreen(IScreenReceiver*);
|
||||
virtual ~CXWindowsSecondaryScreen();
|
||||
|
||||
// CSecondaryScreen overrides
|
||||
virtual void resetOptions();
|
||||
virtual void setOptions(const COptionsList& options);
|
||||
virtual IScreen* getScreen() const;
|
||||
|
||||
// IScreenEventHandler overrides
|
||||
virtual void onScreensaver(bool activated);
|
||||
virtual bool onPreDispatch(const CEvent* event);
|
||||
virtual bool onEvent(CEvent* event);
|
||||
virtual void onOneShotTimerExpired(UInt32 id);
|
||||
|
||||
protected:
|
||||
// CSecondaryScreen overrides
|
||||
virtual void onPreMainLoop();
|
||||
virtual void onPreOpen();
|
||||
virtual void onPostOpen();
|
||||
virtual void onPreClose();
|
||||
virtual void onPreEnter();
|
||||
virtual void onPostEnter();
|
||||
virtual void onPreLeave();
|
||||
virtual void createWindow();
|
||||
virtual void destroyWindow();
|
||||
virtual void showWindow(SInt32 x, SInt32 y);
|
||||
virtual void hideWindow();
|
||||
virtual void updateKeys(KeyState* sysKeyStates);
|
||||
virtual KeyModifierMask getModifiers() const;
|
||||
|
||||
virtual bool isAutoRepeating(SysKeyID) const;
|
||||
virtual KeyModifierMask getModifierKeyMask(SysKeyID) const;
|
||||
virtual bool isModifierActive(SysKeyID) const;
|
||||
virtual SysKeyID getToggleSysKey(KeyID keyID) const;
|
||||
virtual void flush();
|
||||
virtual KeyModifierMask
|
||||
mapKey(Keystrokes&, SysKeyID& sysKeyID, KeyID,
|
||||
KeyModifierMask, KeyModifierMask, EKeyAction) const;
|
||||
virtual void fakeKeyEvent(SysKeyID, bool press) const;
|
||||
virtual void fakeMouseButton(ButtonID, bool press) const;
|
||||
virtual void fakeMouseMove(SInt32 x, SInt32 y) const;
|
||||
virtual void fakeMouseWheel(SInt32 delta) const;
|
||||
|
||||
private:
|
||||
typedef unsigned int ModifierIndex;
|
||||
class KeyMapping {
|
||||
public:
|
||||
KeyMapping();
|
||||
|
||||
public:
|
||||
// KeyCode to generate keysym and whether keycode[i] is
|
||||
// sensitive to shift and mode switch.
|
||||
KeyCode m_keycode[4];
|
||||
bool m_shiftSensitive[4];
|
||||
bool m_modeSwitchSensitive[4];
|
||||
|
||||
// the modifier mask of keysym or 0 if not a modifier
|
||||
KeyModifierMask m_modifierMask;
|
||||
|
||||
// whether keysym is sensitive to caps and num lock
|
||||
bool m_numLockSensitive;
|
||||
bool m_capsLockSensitive;
|
||||
};
|
||||
|
||||
typedef std::vector<KeyCode> KeyCodes;
|
||||
typedef std::map<KeyCode, ModifierIndex> KeyCodeToModifierMap;
|
||||
typedef std::map<KeySym, KeyMapping> KeySymMap;
|
||||
typedef KeySymMap::const_iterator KeySymIndex;
|
||||
typedef std::vector<KeySym> KeySyms;
|
||||
typedef std::map<KeySym, KeySyms> KeySymsMap;
|
||||
|
||||
unsigned int mapButton(ButtonID button) const;
|
||||
|
||||
bool mapToKeystrokes(Keystrokes& keys,
|
||||
SysKeyID& keycode,
|
||||
KeyModifierMask& finalMask,
|
||||
KeySymIndex keyIndex,
|
||||
KeyModifierMask currentMask,
|
||||
EKeyAction action,
|
||||
bool isHalfDuplex) const;
|
||||
bool adjustModifiers(Keystrokes& keys,
|
||||
Keystrokes& undo,
|
||||
KeyModifierMask& inOutMask,
|
||||
KeyModifierMask desiredMask) const;
|
||||
bool adjustModifier(Keystrokes& keys,
|
||||
Keystrokes& undo,
|
||||
KeySym keysym,
|
||||
bool desireActive) const;
|
||||
KeyModifierMask mapToModifierMask(ModifierIndex, KeySym) const;
|
||||
|
||||
unsigned int findBestKeyIndex(KeySymIndex keyIndex,
|
||||
KeyModifierMask currentMask) const;
|
||||
bool isShiftInverted(KeySymIndex keyIndex,
|
||||
KeyModifierMask currentMask) const;
|
||||
|
||||
void doUpdateKeys(Display*);
|
||||
void updateKeysymMap(Display* display);
|
||||
void updateModifiers(Display* display);
|
||||
ModifierIndex keySymToModifierIndex(KeySym) const;
|
||||
static bool isToggleKeysym(KeySym);
|
||||
|
||||
KeySym keyIDToKeySym(KeyID id, KeyModifierMask mask) const;
|
||||
bool adjustForNumLock(KeySym) const;
|
||||
bool adjustForCapsLock(KeySym) const;
|
||||
|
||||
bool decomposeKeySym(KeySym keysym,
|
||||
KeySyms& decomposed) const;
|
||||
static const KeySymsMap& getDecomposedKeySymTable();
|
||||
|
||||
private:
|
||||
CXWindowsScreen* m_screen;
|
||||
Window m_window;
|
||||
|
||||
// logical to physical button mapping. m_buttons[i] gives the
|
||||
// physical button for logical button i+1.
|
||||
std::vector<unsigned char> m_buttons;
|
||||
|
||||
// the modifiers that have keys bound to them
|
||||
KeyModifierMask m_modifierMask;
|
||||
|
||||
// set bits indicate modifiers that toggle (e.g. caps-lock)
|
||||
KeyModifierMask m_toggleModifierMask;
|
||||
|
||||
// keysym to keycode mapping
|
||||
KeySymMap m_keysymMap;
|
||||
|
||||
// modifier index to keycodes
|
||||
KeyCodes m_modifierKeycodes[8];
|
||||
|
||||
// modifier index to modifier mask
|
||||
KeyModifierMask m_modifierIndexToMask[8];
|
||||
|
||||
// keycode to modifier index
|
||||
KeyCodeToModifierMap m_keycodeToModifier;
|
||||
|
||||
// modifier keysyms
|
||||
KeySym m_shiftKeysym;
|
||||
KeySym m_ctrlKeysym;
|
||||
KeySym m_altKeysym;
|
||||
KeySym m_metaKeysym;
|
||||
KeySym m_superKeysym;
|
||||
KeySym m_modeSwitchKeysym;
|
||||
KeySym m_numLockKeysym;
|
||||
KeySym m_capsLockKeysym;
|
||||
KeySym m_scrollLockKeysym;
|
||||
|
||||
// the keyboard control state the last time this screen was entered
|
||||
XKeyboardState m_keyControl;
|
||||
|
||||
// stuff to workaround xtest being xinerama unaware. attempting
|
||||
// to fake a mouse motion under xinerama may behave strangely,
|
||||
// especially if screen 0 is not at 0,0 or if faking a motion on
|
||||
// a screen other than screen 0.
|
||||
bool m_xtestIsXineramaUnaware;
|
||||
bool m_xinerama;
|
||||
|
||||
// a table of keysym decompositions
|
||||
static KeySymsMap s_decomposedKeySyms;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -16,6 +16,14 @@
|
||||
#include "CThread.h"
|
||||
#include "CLog.h"
|
||||
#include <X11/Xatom.h>
|
||||
#define XK_XKB_KEYS
|
||||
#define XK_LATIN1
|
||||
#define XK_LATIN2
|
||||
#define XK_LATIN3
|
||||
#define XK_LATIN4
|
||||
#define XK_LATIN8
|
||||
#define XK_LATIN9
|
||||
#include <X11/keysymdef.h>
|
||||
|
||||
/*
|
||||
* This table maps keysym values into the corresponding ISO 10646
|
||||
@@ -805,6 +813,218 @@ struct codepair {
|
||||
{ 0x20ac, 0x20ac } /* EuroSign EURO SIGN */
|
||||
};
|
||||
|
||||
static const KeySym s_rawDecomposeTable[] = {
|
||||
// non-dead version of dead keys
|
||||
XK_grave, XK_dead_grave, XK_space, 0,
|
||||
XK_acute, XK_dead_acute, XK_space, 0,
|
||||
XK_asciicircum, XK_dead_circumflex, XK_space, 0,
|
||||
XK_asciitilde, XK_dead_tilde, XK_space, 0,
|
||||
XK_cedilla, XK_dead_cedilla, XK_space, 0,
|
||||
XK_ogonek, XK_dead_ogonek, XK_space, 0,
|
||||
XK_caron, XK_dead_caron, XK_space, 0,
|
||||
XK_abovedot, XK_dead_abovedot, XK_space, 0,
|
||||
XK_doubleacute, XK_dead_doubleacute, XK_space, 0,
|
||||
XK_breve, XK_dead_breve, XK_space, 0,
|
||||
XK_macron, XK_dead_macron, XK_space, 0,
|
||||
|
||||
// Latin-1 (ISO 8859-1)
|
||||
XK_Agrave, XK_dead_grave, XK_A, 0,
|
||||
XK_Aacute, XK_dead_acute, XK_A, 0,
|
||||
XK_Acircumflex, XK_dead_circumflex, XK_A, 0,
|
||||
XK_Atilde, XK_dead_tilde, XK_A, 0,
|
||||
XK_Adiaeresis, XK_dead_diaeresis, XK_A, 0,
|
||||
XK_Aring, XK_dead_abovering, XK_A, 0,
|
||||
XK_Ccedilla, XK_dead_cedilla, XK_C, 0,
|
||||
XK_Egrave, XK_dead_grave, XK_E, 0,
|
||||
XK_Eacute, XK_dead_acute, XK_E, 0,
|
||||
XK_Ecircumflex, XK_dead_circumflex, XK_E, 0,
|
||||
XK_Ediaeresis, XK_dead_diaeresis, XK_E, 0,
|
||||
XK_Igrave, XK_dead_grave, XK_I, 0,
|
||||
XK_Iacute, XK_dead_acute, XK_I, 0,
|
||||
XK_Icircumflex, XK_dead_circumflex, XK_I, 0,
|
||||
XK_Idiaeresis, XK_dead_diaeresis, XK_I, 0,
|
||||
XK_Ntilde, XK_dead_tilde, XK_N, 0,
|
||||
XK_Ograve, XK_dead_grave, XK_O, 0,
|
||||
XK_Oacute, XK_dead_acute, XK_O, 0,
|
||||
XK_Ocircumflex, XK_dead_circumflex, XK_O, 0,
|
||||
XK_Otilde, XK_dead_tilde, XK_O, 0,
|
||||
XK_Odiaeresis, XK_dead_diaeresis, XK_O, 0,
|
||||
XK_Ugrave, XK_dead_grave, XK_U, 0,
|
||||
XK_Uacute, XK_dead_acute, XK_U, 0,
|
||||
XK_Ucircumflex, XK_dead_circumflex, XK_U, 0,
|
||||
XK_Udiaeresis, XK_dead_diaeresis, XK_U, 0,
|
||||
XK_Yacute, XK_dead_acute, XK_Y, 0,
|
||||
XK_agrave, XK_dead_grave, XK_a, 0,
|
||||
XK_aacute, XK_dead_acute, XK_a, 0,
|
||||
XK_acircumflex, XK_dead_circumflex, XK_a, 0,
|
||||
XK_atilde, XK_dead_tilde, XK_a, 0,
|
||||
XK_adiaeresis, XK_dead_diaeresis, XK_a, 0,
|
||||
XK_aring, XK_dead_abovering, XK_a, 0,
|
||||
XK_ccedilla, XK_dead_cedilla, XK_c, 0,
|
||||
XK_egrave, XK_dead_grave, XK_e, 0,
|
||||
XK_eacute, XK_dead_acute, XK_e, 0,
|
||||
XK_ecircumflex, XK_dead_circumflex, XK_e, 0,
|
||||
XK_ediaeresis, XK_dead_diaeresis, XK_e, 0,
|
||||
XK_igrave, XK_dead_grave, XK_i, 0,
|
||||
XK_iacute, XK_dead_acute, XK_i, 0,
|
||||
XK_icircumflex, XK_dead_circumflex, XK_i, 0,
|
||||
XK_idiaeresis, XK_dead_diaeresis, XK_i, 0,
|
||||
XK_ntilde, XK_dead_tilde, XK_n, 0,
|
||||
XK_ograve, XK_dead_grave, XK_o, 0,
|
||||
XK_oacute, XK_dead_acute, XK_o, 0,
|
||||
XK_ocircumflex, XK_dead_circumflex, XK_o, 0,
|
||||
XK_otilde, XK_dead_tilde, XK_o, 0,
|
||||
XK_odiaeresis, XK_dead_diaeresis, XK_o, 0,
|
||||
XK_ugrave, XK_dead_grave, XK_u, 0,
|
||||
XK_uacute, XK_dead_acute, XK_u, 0,
|
||||
XK_ucircumflex, XK_dead_circumflex, XK_u, 0,
|
||||
XK_udiaeresis, XK_dead_diaeresis, XK_u, 0,
|
||||
XK_yacute, XK_dead_acute, XK_y, 0,
|
||||
XK_ydiaeresis, XK_dead_diaeresis, XK_y, 0,
|
||||
|
||||
// Latin-2 (ISO 8859-2)
|
||||
XK_Aogonek, XK_dead_ogonek, XK_A, 0,
|
||||
XK_Lcaron, XK_dead_caron, XK_L, 0,
|
||||
XK_Sacute, XK_dead_acute, XK_S, 0,
|
||||
XK_Scaron, XK_dead_caron, XK_S, 0,
|
||||
XK_Scedilla, XK_dead_cedilla, XK_S, 0,
|
||||
XK_Tcaron, XK_dead_caron, XK_T, 0,
|
||||
XK_Zacute, XK_dead_acute, XK_Z, 0,
|
||||
XK_Zcaron, XK_dead_caron, XK_Z, 0,
|
||||
XK_Zabovedot, XK_dead_abovedot, XK_Z, 0,
|
||||
XK_aogonek, XK_dead_ogonek, XK_a, 0,
|
||||
XK_lcaron, XK_dead_caron, XK_l, 0,
|
||||
XK_sacute, XK_dead_acute, XK_s, 0,
|
||||
XK_scaron, XK_dead_caron, XK_s, 0,
|
||||
XK_scedilla, XK_dead_cedilla, XK_s, 0,
|
||||
XK_tcaron, XK_dead_caron, XK_t, 0,
|
||||
XK_zacute, XK_dead_acute, XK_z, 0,
|
||||
XK_zcaron, XK_dead_caron, XK_z, 0,
|
||||
XK_zabovedot, XK_dead_abovedot, XK_z, 0,
|
||||
XK_Racute, XK_dead_acute, XK_R, 0,
|
||||
XK_Abreve, XK_dead_breve, XK_A, 0,
|
||||
XK_Lacute, XK_dead_acute, XK_L, 0,
|
||||
XK_Cacute, XK_dead_acute, XK_C, 0,
|
||||
XK_Ccaron, XK_dead_caron, XK_C, 0,
|
||||
XK_Eogonek, XK_dead_ogonek, XK_E, 0,
|
||||
XK_Ecaron, XK_dead_caron, XK_E, 0,
|
||||
XK_Dcaron, XK_dead_caron, XK_D, 0,
|
||||
XK_Nacute, XK_dead_acute, XK_N, 0,
|
||||
XK_Ncaron, XK_dead_caron, XK_N, 0,
|
||||
XK_Odoubleacute, XK_dead_doubleacute, XK_O, 0,
|
||||
XK_Rcaron, XK_dead_caron, XK_R, 0,
|
||||
XK_Uring, XK_dead_abovering, XK_U, 0,
|
||||
XK_Udoubleacute, XK_dead_doubleacute, XK_U, 0,
|
||||
XK_Tcedilla, XK_dead_cedilla, XK_T, 0,
|
||||
XK_racute, XK_dead_acute, XK_r, 0,
|
||||
XK_abreve, XK_dead_breve, XK_a, 0,
|
||||
XK_lacute, XK_dead_acute, XK_l, 0,
|
||||
XK_cacute, XK_dead_acute, XK_c, 0,
|
||||
XK_ccaron, XK_dead_caron, XK_c, 0,
|
||||
XK_eogonek, XK_dead_ogonek, XK_e, 0,
|
||||
XK_ecaron, XK_dead_caron, XK_e, 0,
|
||||
XK_dcaron, XK_dead_caron, XK_d, 0,
|
||||
XK_nacute, XK_dead_acute, XK_n, 0,
|
||||
XK_ncaron, XK_dead_caron, XK_n, 0,
|
||||
XK_odoubleacute, XK_dead_doubleacute, XK_o, 0,
|
||||
XK_rcaron, XK_dead_caron, XK_r, 0,
|
||||
XK_uring, XK_dead_abovering, XK_u, 0,
|
||||
XK_udoubleacute, XK_dead_doubleacute, XK_u, 0,
|
||||
XK_tcedilla, XK_dead_cedilla, XK_t, 0,
|
||||
|
||||
// Latin-3 (ISO 8859-3)
|
||||
XK_Hcircumflex, XK_dead_circumflex, XK_H, 0,
|
||||
XK_Iabovedot, XK_dead_abovedot, XK_I, 0,
|
||||
XK_Gbreve, XK_dead_breve, XK_G, 0,
|
||||
XK_Jcircumflex, XK_dead_circumflex, XK_J, 0,
|
||||
XK_hcircumflex, XK_dead_circumflex, XK_h, 0,
|
||||
XK_gbreve, XK_dead_breve, XK_g, 0,
|
||||
XK_jcircumflex, XK_dead_circumflex, XK_j, 0,
|
||||
XK_Cabovedot, XK_dead_abovedot, XK_C, 0,
|
||||
XK_Ccircumflex, XK_dead_circumflex, XK_C, 0,
|
||||
XK_Gabovedot, XK_dead_abovedot, XK_G, 0,
|
||||
XK_Gcircumflex, XK_dead_circumflex, XK_G, 0,
|
||||
XK_Ubreve, XK_dead_breve, XK_U, 0,
|
||||
XK_Scircumflex, XK_dead_circumflex, XK_S, 0,
|
||||
XK_cabovedot, XK_dead_abovedot, XK_c, 0,
|
||||
XK_ccircumflex, XK_dead_circumflex, XK_c, 0,
|
||||
XK_gabovedot, XK_dead_abovedot, XK_g, 0,
|
||||
XK_gcircumflex, XK_dead_circumflex, XK_g, 0,
|
||||
XK_ubreve, XK_dead_breve, XK_u, 0,
|
||||
XK_scircumflex, XK_dead_circumflex, XK_s, 0,
|
||||
|
||||
// Latin-4 (ISO 8859-4)
|
||||
XK_scircumflex, XK_dead_circumflex, XK_s, 0,
|
||||
XK_Rcedilla, XK_dead_cedilla, XK_R, 0,
|
||||
XK_Itilde, XK_dead_tilde, XK_I, 0,
|
||||
XK_Lcedilla, XK_dead_cedilla, XK_L, 0,
|
||||
XK_Emacron, XK_dead_macron, XK_E, 0,
|
||||
XK_Gcedilla, XK_dead_cedilla, XK_G, 0,
|
||||
XK_rcedilla, XK_dead_cedilla, XK_r, 0,
|
||||
XK_itilde, XK_dead_tilde, XK_i, 0,
|
||||
XK_lcedilla, XK_dead_cedilla, XK_l, 0,
|
||||
XK_emacron, XK_dead_macron, XK_e, 0,
|
||||
XK_gcedilla, XK_dead_cedilla, XK_g, 0,
|
||||
XK_Amacron, XK_dead_macron, XK_A, 0,
|
||||
XK_Iogonek, XK_dead_ogonek, XK_I, 0,
|
||||
XK_Eabovedot, XK_dead_abovedot, XK_E, 0,
|
||||
XK_Imacron, XK_dead_macron, XK_I, 0,
|
||||
XK_Ncedilla, XK_dead_cedilla, XK_N, 0,
|
||||
XK_Omacron, XK_dead_macron, XK_O, 0,
|
||||
XK_Kcedilla, XK_dead_cedilla, XK_K, 0,
|
||||
XK_Uogonek, XK_dead_ogonek, XK_U, 0,
|
||||
XK_Utilde, XK_dead_tilde, XK_U, 0,
|
||||
XK_Umacron, XK_dead_macron, XK_U, 0,
|
||||
XK_amacron, XK_dead_macron, XK_a, 0,
|
||||
XK_iogonek, XK_dead_ogonek, XK_i, 0,
|
||||
XK_eabovedot, XK_dead_abovedot, XK_e, 0,
|
||||
XK_imacron, XK_dead_macron, XK_i, 0,
|
||||
XK_ncedilla, XK_dead_cedilla, XK_n, 0,
|
||||
XK_omacron, XK_dead_macron, XK_o, 0,
|
||||
XK_kcedilla, XK_dead_cedilla, XK_k, 0,
|
||||
XK_uogonek, XK_dead_ogonek, XK_u, 0,
|
||||
XK_utilde, XK_dead_tilde, XK_u, 0,
|
||||
XK_umacron, XK_dead_macron, XK_u, 0,
|
||||
|
||||
// Latin-8 (ISO 8859-14)
|
||||
#if defined(XK_Babovedot)
|
||||
XK_Babovedot, XK_dead_abovedot, XK_B, 0,
|
||||
XK_babovedot, XK_dead_abovedot, XK_b, 0,
|
||||
XK_Dabovedot, XK_dead_abovedot, XK_D, 0,
|
||||
XK_Wgrave, XK_dead_grave, XK_W, 0,
|
||||
XK_Wacute, XK_dead_acute, XK_W, 0,
|
||||
XK_dabovedot, XK_dead_abovedot, XK_d, 0,
|
||||
XK_Ygrave, XK_dead_grave, XK_Y, 0,
|
||||
XK_Fabovedot, XK_dead_abovedot, XK_F, 0,
|
||||
XK_fabovedot, XK_dead_abovedot, XK_f, 0,
|
||||
XK_Mabovedot, XK_dead_abovedot, XK_M, 0,
|
||||
XK_mabovedot, XK_dead_abovedot, XK_m, 0,
|
||||
XK_Pabovedot, XK_dead_abovedot, XK_P, 0,
|
||||
XK_wgrave, XK_dead_grave, XK_w, 0,
|
||||
XK_pabovedot, XK_dead_abovedot, XK_p, 0,
|
||||
XK_wacute, XK_dead_acute, XK_w, 0,
|
||||
XK_Sabovedot, XK_dead_abovedot, XK_S, 0,
|
||||
XK_ygrave, XK_dead_grave, XK_y, 0,
|
||||
XK_Wdiaeresis, XK_dead_diaeresis, XK_W, 0,
|
||||
XK_wdiaeresis, XK_dead_diaeresis, XK_w, 0,
|
||||
XK_sabovedot, XK_dead_abovedot, XK_s, 0,
|
||||
XK_Wcircumflex, XK_dead_circumflex, XK_W, 0,
|
||||
XK_Tabovedot, XK_dead_abovedot, XK_T, 0,
|
||||
XK_Ycircumflex, XK_dead_circumflex, XK_Y, 0,
|
||||
XK_wcircumflex, XK_dead_circumflex, XK_w, 0,
|
||||
XK_tabovedot, XK_dead_abovedot, XK_t, 0,
|
||||
XK_ycircumflex, XK_dead_circumflex, XK_y, 0,
|
||||
#endif
|
||||
|
||||
// Latin-9 (ISO 8859-15)
|
||||
#if defined(XK_Ydiaeresis)
|
||||
XK_Ydiaeresis, XK_dead_diaeresis, XK_Y, 0,
|
||||
#endif
|
||||
|
||||
// end of table
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// CXWindowsUtil
|
||||
@@ -812,6 +1032,7 @@ struct codepair {
|
||||
|
||||
CXWindowsUtil::CKeySymMap CXWindowsUtil::s_keySymToUCS4;
|
||||
CXWindowsUtil::CUCS4Map CXWindowsUtil::s_UCS4ToKeySym;
|
||||
CXWindowsUtil::CKeySymsMap CXWindowsUtil::s_decomposedKeySyms;
|
||||
|
||||
bool
|
||||
CXWindowsUtil::getWindowProperty(Display* display, Window window,
|
||||
@@ -1008,6 +1229,21 @@ CXWindowsUtil::mapUCS4ToKeySym(UInt32 c)
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
CXWindowsUtil::decomposeKeySym(KeySym keysym, KeySyms& decomposed)
|
||||
{
|
||||
// unfortunately, X11 doesn't appear to have any way of
|
||||
// decomposing a keysym into its component keysyms. we'll
|
||||
// use a lookup table for certain character sets.
|
||||
initKeyMaps();
|
||||
CKeySymsMap::const_iterator i = s_decomposedKeySyms.find(keysym);
|
||||
if (i == s_decomposedKeySyms.end()) {
|
||||
return false;
|
||||
}
|
||||
decomposed = i->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool
|
||||
CXWindowsUtil::propertyNotifyPredicate(Display*, XEvent* xevent, XPointer arg)
|
||||
{
|
||||
@@ -1031,6 +1267,19 @@ CXWindowsUtil::initKeyMaps()
|
||||
s_UCS4ToKeySym[s_keymap[i].ucs4] = s_keymap[i].keysym;
|
||||
}
|
||||
}
|
||||
|
||||
// fill decomposed key table if not filled yet
|
||||
if (s_decomposedKeySyms.empty()) {
|
||||
for (const KeySym* scan = s_rawDecomposeTable; *scan != 0; ++scan) {
|
||||
// add an entry for this keysym
|
||||
KeySyms& entry = s_decomposedKeySyms[*scan];
|
||||
|
||||
// add the decomposed keysyms for the keysym
|
||||
while (*++scan != 0) {
|
||||
entry.push_back(*scan);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "CString.h"
|
||||
#include "BasicTypes.h"
|
||||
#include "stdmap.h"
|
||||
#include "stdvector.h"
|
||||
#if defined(X_DISPLAY_MISSING)
|
||||
# error X11 is required to build synergy
|
||||
#else
|
||||
@@ -27,6 +28,8 @@
|
||||
//! X11 utility functions
|
||||
class CXWindowsUtil {
|
||||
public:
|
||||
typedef std::vector<KeySym> KeySyms;
|
||||
|
||||
//! Get property
|
||||
/*!
|
||||
Gets property \c property on \c window. \b Appends the data to
|
||||
@@ -70,6 +73,14 @@ public:
|
||||
*/
|
||||
static KeySym mapUCS4ToKeySym(UInt32);
|
||||
|
||||
//! Decompose a KeySym
|
||||
/*!
|
||||
Decomposes \c keysym into its component keysyms. All but the last
|
||||
decomposed KeySym are dead keys. Returns true iff the decomposition
|
||||
was successful.
|
||||
*/
|
||||
static bool decomposeKeySym(KeySym keysym, KeySyms& decomposed);
|
||||
|
||||
//! X11 error handler
|
||||
/*!
|
||||
This class sets an X error handler in the c'tor and restores the
|
||||
@@ -133,9 +144,11 @@ private:
|
||||
private:
|
||||
typedef std::map<KeySym, UInt32> CKeySymMap;
|
||||
typedef std::map<UInt32, KeySym> CUCS4Map;
|
||||
typedef std::map<KeySym, KeySyms> CKeySymsMap;
|
||||
|
||||
static CKeySymMap s_keySymToUCS4;
|
||||
static CUCS4Map s_UCS4ToKeySym;
|
||||
static CKeySymsMap s_decomposedKeySyms;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* 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 IMSWINDOWSSCREENEVENTHANDLER_H
|
||||
#define IMSWINDOWSSCREENEVENTHANDLER_H
|
||||
|
||||
#include "IScreenEventHandler.h"
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
//! MS Windows screen event handler interface
|
||||
class IMSWindowsScreenEventHandler : public IScreenEventHandler {
|
||||
public:
|
||||
//! @name manipulators
|
||||
//@{
|
||||
|
||||
//! Notify of window creation
|
||||
/*!
|
||||
This is called after the window is created.
|
||||
*/
|
||||
virtual void postCreateWindow(HWND) = 0;
|
||||
|
||||
//! Notify of window destruction
|
||||
/*!
|
||||
This is called before the window is destroyed.
|
||||
*/
|
||||
virtual void preDestroyWindow(HWND) = 0;
|
||||
|
||||
//! Notify of newly accessible desktop
|
||||
/*!
|
||||
This is called when the user switched from an inaccessible desktop
|
||||
to an accessible desktop.
|
||||
*/
|
||||
virtual void onAccessibleDesktop() = 0;
|
||||
|
||||
//@}
|
||||
|
||||
// IScreenEventHandler overrides
|
||||
virtual void onScreensaver(bool activated) = 0;
|
||||
virtual bool onPreDispatch(const CEvent* event) = 0;
|
||||
virtual bool onEvent(CEvent* event) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -23,21 +23,20 @@ EXTRA_DIST = \
|
||||
CMSWindowsClipboardAnyTextConverter.cpp \
|
||||
CMSWindowsClipboardTextConverter.cpp \
|
||||
CMSWindowsClipboardUTF16Converter.cpp \
|
||||
CMSWindowsPrimaryScreen.cpp \
|
||||
CMSWindowsDesktop.cpp \
|
||||
CMSWindowsKeyMapper.cpp \
|
||||
CMSWindowsScreen.cpp \
|
||||
CMSWindowsScreenSaver.cpp \
|
||||
CMSWindowsSecondaryScreen.cpp \
|
||||
CSynergyHook.cpp \
|
||||
CMSWindowsClipboard.h \
|
||||
CMSWindowsClipboardAnyTextConverter.h \
|
||||
CMSWindowsClipboardTextConverter.h \
|
||||
CMSWindowsClipboardUTF16Converter.h \
|
||||
CMSWindowsPrimaryScreen.h \
|
||||
CMSWindowsDesktop.h \
|
||||
CMSWindowsKeyMapper.h \
|
||||
CMSWindowsScreen.h \
|
||||
CMSWindowsScreenSaver.h \
|
||||
CMSWindowsSecondaryScreen.h \
|
||||
CSynergyHook.h \
|
||||
IMSWindowsScreenEventHandler.h \
|
||||
$(NULL)
|
||||
|
||||
MAINTAINERCLEANFILES = \
|
||||
@@ -50,19 +49,17 @@ libplatform_a_SOURCES = \
|
||||
CXWindowsClipboardTextConverter.cpp \
|
||||
CXWindowsClipboardUCS2Converter.cpp \
|
||||
CXWindowsClipboardUTF8Converter.cpp \
|
||||
CXWindowsPrimaryScreen.cpp \
|
||||
CXWindowsKeyMapper.cpp \
|
||||
CXWindowsScreen.cpp \
|
||||
CXWindowsScreenSaver.cpp \
|
||||
CXWindowsSecondaryScreen.cpp \
|
||||
CXWindowsUtil.cpp \
|
||||
CXWindowsClipboard.h \
|
||||
CXWindowsClipboardTextConverter.h \
|
||||
CXWindowsClipboardUCS2Converter.h \
|
||||
CXWindowsClipboardUTF8Converter.h \
|
||||
CXWindowsPrimaryScreen.h \
|
||||
CXWindowsKeyMapper.h \
|
||||
CXWindowsScreen.h \
|
||||
CXWindowsScreenSaver.h \
|
||||
CXWindowsSecondaryScreen.h \
|
||||
CXWindowsUtil.h \
|
||||
$(NULL)
|
||||
INCLUDES = \
|
||||
|
||||
@@ -103,7 +103,11 @@ SOURCE=.\CMSWindowsClipboardUTF16Converter.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CMSWindowsPrimaryScreen.cpp
|
||||
SOURCE=.\CMSWindowsDesktop.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CMSWindowsKeyMapper.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
@@ -113,10 +117,6 @@ SOURCE=.\CMSWindowsScreen.cpp
|
||||
|
||||
SOURCE=.\CMSWindowsScreenSaver.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CMSWindowsSecondaryScreen.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
@@ -139,7 +139,11 @@ SOURCE=.\CMSWindowsClipboardUTF16Converter.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CMSWindowsPrimaryScreen.h
|
||||
SOURCE=.\CMSWindowsDesktop.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CMSWindowsKeyMapper.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
@@ -149,14 +153,6 @@ SOURCE=.\CMSWindowsScreen.h
|
||||
|
||||
SOURCE=.\CMSWindowsScreenSaver.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CMSWindowsSecondaryScreen.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\IMSWindowsScreenEventHandler.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
|
||||
Reference in New Issue
Block a user