mirror of
https://github.com/debauchee/barrier.git
synced 2026-05-10 00:11:43 +08:00
Added support for a global relative mouse motion option. When true
and on a secondary screen and locked to the screen (via scroll lock) mouse motion is sent as motion deltas. When true and scroll lock is toggled off the mouse is warped to the secondary screen's center so the server knows where it is. This option is intended to support games and other programs that repeatedly warp the mouse to the center of the screen. This change adds general and X11 support but not win32. The option name is "relativeMouseMoves".
This commit is contained in:
@@ -96,6 +96,7 @@ public:
|
||||
virtual void mouseDown(ButtonID) = 0;
|
||||
virtual void mouseUp(ButtonID) = 0;
|
||||
virtual void mouseMove(SInt32 xAbs, SInt32 yAbs) = 0;
|
||||
virtual void mouseRelativeMove(SInt32 xRel, SInt32 yRel) = 0;
|
||||
virtual void mouseWheel(SInt32 delta) = 0;
|
||||
virtual void screensaver(bool activate) = 0;
|
||||
virtual void resetOptions() = 0;
|
||||
|
||||
@@ -316,6 +316,12 @@ CClientProxy1_0::mouseMove(SInt32 xAbs, SInt32 yAbs)
|
||||
CProtocolUtil::writef(getStream(), kMsgDMouseMove, xAbs, yAbs);
|
||||
}
|
||||
|
||||
void
|
||||
CClientProxy1_0::mouseRelativeMove(SInt32, SInt32)
|
||||
{
|
||||
// ignore -- not supported in protocol 1.0
|
||||
}
|
||||
|
||||
void
|
||||
CClientProxy1_0::mouseWheel(SInt32 delta)
|
||||
{
|
||||
|
||||
@@ -49,6 +49,7 @@ public:
|
||||
virtual void mouseDown(ButtonID);
|
||||
virtual void mouseUp(ButtonID);
|
||||
virtual void mouseMove(SInt32 xAbs, SInt32 yAbs);
|
||||
virtual void mouseRelativeMove(SInt32 xRel, SInt32 yRel);
|
||||
virtual void mouseWheel(SInt32 delta);
|
||||
virtual void screensaver(bool activate);
|
||||
virtual void resetOptions();
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "CClientProxyUnknown.h"
|
||||
#include "CClientProxy1_0.h"
|
||||
#include "CClientProxy1_1.h"
|
||||
#include "CClientProxy1_2.h"
|
||||
#include "ProtocolTypes.h"
|
||||
#include "CProtocolUtil.h"
|
||||
#include "XSynergy.h"
|
||||
@@ -214,6 +215,10 @@ CClientProxyUnknown::handleData(const CEvent&, void*)
|
||||
case 1:
|
||||
m_proxy = new CClientProxy1_1(name, m_stream);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
m_proxy = new CClientProxy1_2(name, m_stream);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -629,6 +629,9 @@ CConfig::getOptionName(OptionID id)
|
||||
if (id == kOptionXTestXineramaUnaware) {
|
||||
return "xtestIsXineramaUnaware";
|
||||
}
|
||||
if (id == kOptionRelativeMouseMoves) {
|
||||
return "relativeMouseMoves";
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -638,7 +641,8 @@ CConfig::getOptionValue(OptionID id, OptionValue value)
|
||||
if (id == kOptionHalfDuplexCapsLock ||
|
||||
id == kOptionHalfDuplexNumLock ||
|
||||
id == kOptionScreenSaverSync ||
|
||||
id == kOptionXTestXineramaUnaware) {
|
||||
id == kOptionXTestXineramaUnaware ||
|
||||
id == kOptionRelativeMouseMoves) {
|
||||
return (value != 0) ? "true" : "false";
|
||||
}
|
||||
if (id == kOptionModifierMapForShift ||
|
||||
@@ -778,6 +782,9 @@ CConfig::readSectionOptions(std::istream& s)
|
||||
else if (name == "screenSaverSync") {
|
||||
addOption("", kOptionScreenSaverSync, parseBoolean(value));
|
||||
}
|
||||
else if (name == "relativeMouseMoves") {
|
||||
addOption("", kOptionRelativeMouseMoves, parseBoolean(value));
|
||||
}
|
||||
else {
|
||||
throw XConfigRead("unknown argument");
|
||||
}
|
||||
|
||||
@@ -185,6 +185,12 @@ CPrimaryClient::mouseMove(SInt32 x, SInt32 y)
|
||||
m_screen->warpCursor(x, y);
|
||||
}
|
||||
|
||||
void
|
||||
CPrimaryClient::mouseRelativeMove(SInt32, SInt32)
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
void
|
||||
CPrimaryClient::mouseWheel(SInt32)
|
||||
{
|
||||
|
||||
@@ -102,6 +102,7 @@ public:
|
||||
virtual void mouseDown(ButtonID);
|
||||
virtual void mouseUp(ButtonID);
|
||||
virtual void mouseMove(SInt32 xAbs, SInt32 yAbs);
|
||||
virtual void mouseRelativeMove(SInt32 xRel, SInt32 yRel);
|
||||
virtual void mouseWheel(SInt32 delta);
|
||||
virtual void screensaver(bool activate);
|
||||
virtual void resetOptions();
|
||||
|
||||
@@ -53,7 +53,8 @@ CServer::CServer(const CConfig& config, CPrimaryClient* primaryClient) :
|
||||
m_switchTwoTapDelay(0.0),
|
||||
m_switchTwoTapEngaged(false),
|
||||
m_switchTwoTapArmed(false),
|
||||
m_switchTwoTapZone(3)
|
||||
m_switchTwoTapZone(3),
|
||||
m_relativeMoves(false)
|
||||
{
|
||||
// must have a primary client and it must have a canonical name
|
||||
assert(m_primaryClient != NULL);
|
||||
@@ -283,6 +284,9 @@ CServer::onCommandKey(KeyID id, KeyModifierMask /*mask*/, bool /*down*/)
|
||||
{
|
||||
if (id == kKeyScrollLock) {
|
||||
m_primaryClient->reconfigure(getActivePrimarySides());
|
||||
if (!isLockedToScreenServer()) {
|
||||
stopRelativeMoves();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -322,13 +326,7 @@ bool
|
||||
CServer::isLockedToScreenServer() const
|
||||
{
|
||||
// locked if scroll-lock is toggled on
|
||||
if ((m_primaryClient->getToggleMask() & KeyModifierScrollLock) != 0) {
|
||||
LOG((CLOG_DEBUG "locked by ScrollLock"));
|
||||
return true;
|
||||
}
|
||||
|
||||
// not locked
|
||||
return false;
|
||||
return ((m_primaryClient->getToggleMask() & KeyModifierScrollLock) != 0);
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -336,6 +334,7 @@ CServer::isLockedToScreen() const
|
||||
{
|
||||
// locked if we say we're locked
|
||||
if (isLockedToScreenServer()) {
|
||||
LOG((CLOG_DEBUG "locked by ScrollLock"));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -841,6 +840,24 @@ CServer::isSwitchWaitStarted() const
|
||||
return (m_switchWaitTimer != NULL);
|
||||
}
|
||||
|
||||
void
|
||||
CServer::stopRelativeMoves()
|
||||
{
|
||||
if (m_relativeMoves && m_active != m_primaryClient) {
|
||||
// warp to the center of the active client so we know where we are
|
||||
SInt32 ax, ay, aw, ah;
|
||||
m_active->getShape(ax, ay, aw, ah);
|
||||
m_x = ax + (aw >> 1);
|
||||
m_y = ay + (ah >> 1);
|
||||
m_xDelta = 0;
|
||||
m_yDelta = 0;
|
||||
m_xDelta2 = 0;
|
||||
m_yDelta2 = 0;
|
||||
LOG((CLOG_DEBUG2 "synchronize move on %s by %d,%d", getName(m_active).c_str(), m_x, m_y));
|
||||
m_active->mouseMove(m_x, m_y);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CServer::sendOptions(IClient* client) const
|
||||
{
|
||||
@@ -883,6 +900,7 @@ CServer::processOptions()
|
||||
return;
|
||||
}
|
||||
|
||||
bool newRelativeMoves = m_relativeMoves;
|
||||
for (CConfig::CScreenOptions::const_iterator index = options->begin();
|
||||
index != options->end(); ++index) {
|
||||
const OptionID id = index->first;
|
||||
@@ -901,7 +919,15 @@ CServer::processOptions()
|
||||
}
|
||||
stopSwitchTwoTap();
|
||||
}
|
||||
else if (id == kOptionRelativeMouseMoves) {
|
||||
newRelativeMoves = (value != 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_relativeMoves && !newRelativeMoves) {
|
||||
stopRelativeMoves();
|
||||
}
|
||||
m_relativeMoves = newRelativeMoves;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1339,6 +1365,18 @@ CServer::onMouseMoveSecondary(SInt32 dx, SInt32 dy)
|
||||
return;
|
||||
}
|
||||
|
||||
// if doing relative motion on secondary screens and we're locked
|
||||
// to the screen (which activates relative moves) then send a
|
||||
// relative mouse motion. when we're doing this we pretend as if
|
||||
// the mouse isn't actually moving because we're expecting some
|
||||
// program on the secondary screen to warp the mouse on us, so we
|
||||
// have no idea where it really is.
|
||||
if (m_relativeMoves && isLockedToScreenServer()) {
|
||||
LOG((CLOG_DEBUG2 "relative move on %s by %d,%d", getName(m_active).c_str(), dx, dy));
|
||||
m_active->mouseRelativeMove(dx, dy);
|
||||
return;
|
||||
}
|
||||
|
||||
// save old position
|
||||
const SInt32 xOld = m_x;
|
||||
const SInt32 yOld = m_y;
|
||||
|
||||
@@ -26,8 +26,6 @@
|
||||
#include "stdset.h"
|
||||
#include "stdvector.h"
|
||||
|
||||
class CClientProxy;
|
||||
class CClientProxyUnknown;
|
||||
class CEventQueueTimer;
|
||||
class CPrimaryClient;
|
||||
class IClient;
|
||||
@@ -183,6 +181,9 @@ private:
|
||||
// returns true iff the delay switch timer is started
|
||||
bool isSwitchWaitStarted() const;
|
||||
|
||||
// stop relative mouse moves
|
||||
void stopRelativeMoves();
|
||||
|
||||
// send screen options to \c client
|
||||
void sendOptions(IClient* client) const;
|
||||
|
||||
@@ -312,6 +313,9 @@ private:
|
||||
bool m_switchTwoTapArmed;
|
||||
SInt32 m_switchTwoTapZone;
|
||||
|
||||
// relative mouse move option
|
||||
bool m_relativeMoves;
|
||||
|
||||
static CEvent::Type s_errorEvent;
|
||||
static CEvent::Type s_disconnectedEvent;
|
||||
};
|
||||
|
||||
@@ -27,6 +27,7 @@ libserver_a_SOURCES = \
|
||||
CClientProxy.cpp \
|
||||
CClientProxy1_0.cpp \
|
||||
CClientProxy1_1.cpp \
|
||||
CClientProxy1_2.cpp \
|
||||
CClientProxyUnknown.cpp \
|
||||
CConfig.cpp \
|
||||
CPrimaryClient.cpp \
|
||||
@@ -35,6 +36,7 @@ libserver_a_SOURCES = \
|
||||
CClientProxy.h \
|
||||
CClientProxy1_0.h \
|
||||
CClientProxy1_1.h \
|
||||
CClientProxy1_2.h \
|
||||
CClientProxyUnknown.h \
|
||||
CConfig.h \
|
||||
CPrimaryClient.h \
|
||||
|
||||
Reference in New Issue
Block a user