mirror of
https://github.com/debauchee/barrier.git
synced 2026-05-05 21:02:39 +08:00
checkpoint. initial support for multiple displays on win32.
This commit is contained in:
@@ -111,15 +111,15 @@ CMSWindowsPrimaryScreen::open(CServer* server)
|
||||
nextMark();
|
||||
|
||||
// send screen info
|
||||
SInt32 w, h;
|
||||
getScreenSize(&w, &h);
|
||||
SInt32 x, y, w, h;
|
||||
getScreenShape(x, y, w, h);
|
||||
POINT pos;
|
||||
GetCursorPos(&pos);
|
||||
m_server->setInfo(w, h, getJumpZoneSize(), pos.x, pos.y);
|
||||
m_server->setInfo(x, y, w, h, getJumpZoneSize(), pos.x, pos.y);
|
||||
|
||||
// compute center pixel of screen
|
||||
m_xCenter = w >> 1;
|
||||
m_yCenter = h >> 1;
|
||||
// compute center pixel of primary screen
|
||||
m_xCenter = GetSystemMetrics(SM_CXSCREEN) >> 1;
|
||||
m_yCenter = GetSystemMetrics(SM_CYSCREEN) >> 1;
|
||||
|
||||
// get keyboard state
|
||||
updateKeys();
|
||||
@@ -228,10 +228,10 @@ void
|
||||
CMSWindowsPrimaryScreen::onConfigure()
|
||||
{
|
||||
if ((m_is95Family || m_desk != NULL) && !m_active) {
|
||||
SInt32 w, h;
|
||||
getScreenSize(&w, &h);
|
||||
SInt32 x, y, w, h;
|
||||
getScreenShape(x, y, w, h);
|
||||
m_setZone(m_server->getActivePrimarySides(),
|
||||
w, h, getJumpZoneSize());
|
||||
x, y, w, h, getJumpZoneSize());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,9 +264,10 @@ CMSWindowsPrimaryScreen::grabClipboard(ClipboardID /*id*/)
|
||||
}
|
||||
|
||||
void
|
||||
CMSWindowsPrimaryScreen::getSize(SInt32* width, SInt32* height) const
|
||||
CMSWindowsPrimaryScreen::getShape(
|
||||
SInt32& x, SInt32& y, SInt32& w, SInt32& h) const
|
||||
{
|
||||
getScreenSize(width, height);
|
||||
getScreenShape(x, y, w, h);
|
||||
}
|
||||
|
||||
SInt32
|
||||
@@ -551,17 +552,17 @@ CMSWindowsPrimaryScreen::onEvent(HWND hwnd, UINT msg,
|
||||
case WM_DISPLAYCHANGE:
|
||||
{
|
||||
// screen resolution may have changed
|
||||
SInt32 wOld, hOld;
|
||||
getScreenSize(&wOld, &hOld);
|
||||
SInt32 w, h;
|
||||
updateScreenSize();
|
||||
getScreenSize(&w, &h);
|
||||
SInt32 xOld, yOld, wOld, hOld;
|
||||
getScreenShape(xOld, yOld, wOld, hOld);
|
||||
updateScreenShape();
|
||||
SInt32 x, y, w, h;
|
||||
getScreenShape(x, y, w, h);
|
||||
|
||||
// do nothing if resolution hasn't changed
|
||||
if (w != wOld || h != hOld) {
|
||||
// recompute center pixel of screen
|
||||
m_xCenter = w >> 1;
|
||||
m_yCenter = h >> 1;
|
||||
if (x != xOld || y != yOld || w != wOld || h != hOld) {
|
||||
// recompute center pixel of primary screen
|
||||
m_xCenter = GetSystemMetrics(SM_CXSCREEN) >> 1;
|
||||
m_yCenter = GetSystemMetrics(SM_CYSCREEN) >> 1;
|
||||
|
||||
// warp mouse to center if active
|
||||
if (m_active) {
|
||||
@@ -576,7 +577,7 @@ CMSWindowsPrimaryScreen::onEvent(HWND hwnd, UINT msg,
|
||||
// send new screen info
|
||||
POINT pos;
|
||||
GetCursorPos(&pos);
|
||||
m_server->setInfo(w, h, getJumpZoneSize(), pos.x, pos.y);
|
||||
m_server->setInfo(x, y, w, h, getJumpZoneSize(), pos.x, pos.y);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -682,8 +683,8 @@ CMSWindowsPrimaryScreen::openDesktop()
|
||||
// with losing keyboard input (focus?) in that case.
|
||||
// unfortunately, hiding the full screen window (when entering
|
||||
// the scren causes all other windows to redraw).
|
||||
SInt32 w, h;
|
||||
getScreenSize(&w, &h);
|
||||
SInt32 x, y, w, h;
|
||||
getScreenShape(x, y, w, h);
|
||||
|
||||
// create the window
|
||||
m_window = CreateWindowEx(WS_EX_TOPMOST |
|
||||
@@ -692,7 +693,7 @@ CMSWindowsPrimaryScreen::openDesktop()
|
||||
(LPCTSTR)getClass(),
|
||||
"Synergy",
|
||||
WS_POPUP,
|
||||
0, 0, w, h, NULL, NULL,
|
||||
x, y, w, h, NULL, NULL,
|
||||
getInstance(),
|
||||
NULL);
|
||||
if (m_window == NULL) {
|
||||
@@ -792,8 +793,8 @@ CMSWindowsPrimaryScreen::switchDesktop(HDESK desk)
|
||||
// with losing keyboard input (focus?) in that case.
|
||||
// unfortunately, hiding the full screen window (when entering
|
||||
// the scren causes all other windows to redraw).
|
||||
SInt32 w, h;
|
||||
getScreenSize(&w, &h);
|
||||
SInt32 x, y, w, h;
|
||||
getScreenShape(x, y, w, h);
|
||||
|
||||
// create the window
|
||||
m_window = CreateWindowEx(WS_EX_TOPMOST |
|
||||
@@ -802,7 +803,7 @@ CMSWindowsPrimaryScreen::switchDesktop(HDESK desk)
|
||||
(LPCTSTR)getClass(),
|
||||
"Synergy",
|
||||
WS_POPUP,
|
||||
0, 0, w, h, NULL, NULL,
|
||||
x, y, w, h, NULL, NULL,
|
||||
getInstance(),
|
||||
NULL);
|
||||
if (m_window == NULL) {
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
virtual void warpCursor(SInt32 xAbsolute, SInt32 yAbsolute);
|
||||
virtual void setClipboard(ClipboardID, const IClipboard*);
|
||||
virtual void grabClipboard(ClipboardID);
|
||||
virtual void getSize(SInt32* width, SInt32* height) const;
|
||||
virtual void getShape(SInt32&, SInt32&, SInt32&, SInt32&) const;
|
||||
virtual SInt32 getJumpZoneSize() const;
|
||||
virtual void getClipboard(ClipboardID, IClipboard*) const;
|
||||
virtual KeyModifierMask getToggleMask() const;
|
||||
|
||||
@@ -260,24 +260,27 @@ CServer::getActivePrimarySides() const
|
||||
}
|
||||
|
||||
void
|
||||
CServer::setInfo(SInt32 w, SInt32 h, SInt32 zoneSize, SInt32 x, SInt32 y)
|
||||
CServer::setInfo(SInt32 x, SInt32 y, SInt32 w, SInt32 h,
|
||||
SInt32 zoneSize, SInt32 mx, SInt32 my)
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
assert(m_primaryInfo != NULL);
|
||||
setInfoNoLock(m_primaryInfo->m_name, w, h, zoneSize, x, y);
|
||||
setInfoNoLock(m_primaryInfo->m_name, x, y, w, h, zoneSize, mx, my);
|
||||
}
|
||||
|
||||
void
|
||||
CServer::setInfo(const CString& client,
|
||||
SInt32 w, SInt32 h, SInt32 zoneSize, SInt32 x, SInt32 y)
|
||||
SInt32 x, SInt32 y, SInt32 w, SInt32 h,
|
||||
SInt32 zoneSize, SInt32 mx, SInt32 my)
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
setInfoNoLock(client, w, h, zoneSize, x, y);
|
||||
setInfoNoLock(client, x, y, w, h, zoneSize, mx, my);
|
||||
}
|
||||
|
||||
void
|
||||
CServer::setInfoNoLock(const CString& screen,
|
||||
SInt32 w, SInt32 h, SInt32 zoneSize, SInt32 x, SInt32 y)
|
||||
SInt32 x, SInt32 y, SInt32 w, SInt32 h,
|
||||
SInt32 zoneSize, SInt32 mx, SInt32 my)
|
||||
{
|
||||
assert(!screen.empty());
|
||||
assert(w > 0);
|
||||
@@ -297,13 +300,15 @@ CServer::setInfoNoLock(const CString& screen,
|
||||
// update screen info
|
||||
if (info == m_active) {
|
||||
// update the remote mouse coordinates
|
||||
m_x = x;
|
||||
m_y = y;
|
||||
m_x = mx;
|
||||
m_y = my;
|
||||
}
|
||||
info->m_width = w;
|
||||
info->m_height = h;
|
||||
info->m_x = x;
|
||||
info->m_y = y;
|
||||
info->m_w = w;
|
||||
info->m_h = h;
|
||||
info->m_zoneSize = zoneSize;
|
||||
log((CLOG_INFO "screen \"%s\" size=%dx%d zone=%d pos=%d,%d", screen.c_str(), w, h, zoneSize, x, y));
|
||||
log((CLOG_INFO "screen \"%s\" shape=%d,%d %dx%d zone=%d pos=%d,%d", screen.c_str(), x, y, w, h, zoneSize, mx, my));
|
||||
|
||||
// send acknowledgement (if screen isn't the primary)
|
||||
if (info->m_protocol != NULL) {
|
||||
@@ -313,7 +318,7 @@ CServer::setInfoNoLock(const CString& screen,
|
||||
// handle resolution change to primary screen
|
||||
else {
|
||||
if (info == m_active) {
|
||||
onMouseMovePrimaryNoLock(x, y);
|
||||
onMouseMovePrimaryNoLock(mx, my);
|
||||
}
|
||||
else {
|
||||
onMouseMoveSecondaryNoLock(0, 0);
|
||||
@@ -536,22 +541,22 @@ CServer::onMouseMovePrimaryNoLock(SInt32 x, SInt32 y)
|
||||
|
||||
// see if we should change screens
|
||||
CConfig::EDirection dir;
|
||||
if (x < m_active->m_zoneSize) {
|
||||
if (x < m_active->m_x + m_active->m_zoneSize) {
|
||||
x -= m_active->m_zoneSize;
|
||||
dir = CConfig::kLeft;
|
||||
log((CLOG_DEBUG1 "switch to left"));
|
||||
}
|
||||
else if (x >= m_active->m_width - m_active->m_zoneSize) {
|
||||
else if (x >= m_active->m_x + m_active->m_w - m_active->m_zoneSize) {
|
||||
x += m_active->m_zoneSize;
|
||||
dir = CConfig::kRight;
|
||||
log((CLOG_DEBUG1 "switch to right"));
|
||||
}
|
||||
else if (y < m_active->m_zoneSize) {
|
||||
else if (y < m_active->m_y + m_active->m_zoneSize) {
|
||||
y -= m_active->m_zoneSize;
|
||||
dir = CConfig::kTop;
|
||||
log((CLOG_DEBUG1 "switch to top"));
|
||||
}
|
||||
else if (y >= m_active->m_height - m_active->m_zoneSize) {
|
||||
else if (y >= m_active->m_y + m_active->m_h - m_active->m_zoneSize) {
|
||||
y += m_active->m_zoneSize;
|
||||
dir = CConfig::kBottom;
|
||||
log((CLOG_DEBUG1 "switch to bottom"));
|
||||
@@ -561,17 +566,13 @@ CServer::onMouseMovePrimaryNoLock(SInt32 x, SInt32 y)
|
||||
return false;
|
||||
}
|
||||
|
||||
// get jump destination
|
||||
// get jump destination and, if no screen in jump direction,
|
||||
// then ignore the move.
|
||||
CScreenInfo* newScreen = getNeighbor(m_active, dir, x, y);
|
||||
|
||||
// if no screen in jump direction then ignore the move
|
||||
if (newScreen == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// remap position to account for resolution differences
|
||||
mapPosition(m_active, dir, newScreen, x, y);
|
||||
|
||||
// switch screen
|
||||
switchScreen(newScreen, x, y);
|
||||
return true;
|
||||
@@ -615,16 +616,16 @@ CServer::onMouseMoveSecondaryNoLock(SInt32 dx, SInt32 dy)
|
||||
if (!isLockedToScreenNoLock()) {
|
||||
// find direction of neighbor
|
||||
CConfig::EDirection dir;
|
||||
if (m_x < 0) {
|
||||
if (m_x < m_active->m_x) {
|
||||
dir = CConfig::kLeft;
|
||||
}
|
||||
else if (m_x > m_active->m_width - 1) {
|
||||
else if (m_x > m_active->m_x + m_active->m_w - 1) {
|
||||
dir = CConfig::kRight;
|
||||
}
|
||||
else if (m_y < 0) {
|
||||
else if (m_y < m_active->m_y) {
|
||||
dir = CConfig::kTop;
|
||||
}
|
||||
else if (m_y > m_active->m_height - 1) {
|
||||
else if (m_y > m_active->m_y + m_active->m_h - 1) {
|
||||
dir = CConfig::kBottom;
|
||||
}
|
||||
else {
|
||||
@@ -638,39 +639,32 @@ CServer::onMouseMoveSecondaryNoLock(SInt32 dx, SInt32 dy)
|
||||
if (newScreen == NULL) {
|
||||
log((CLOG_DEBUG1 "leave \"%s\" on %s", m_active->m_name.c_str(), CConfig::dirName(dir)));
|
||||
|
||||
SInt32 x = m_x, y = m_y;
|
||||
newScreen = getNeighbor(m_active, dir, x, y);
|
||||
|
||||
// remap position to account for resolution differences
|
||||
if (newScreen != NULL) {
|
||||
mapPosition(m_active, dir, newScreen, x, y);
|
||||
m_x = x;
|
||||
m_y = y;
|
||||
}
|
||||
else {
|
||||
// get new position or clamp to current screen
|
||||
newScreen = getNeighbor(m_active, dir, m_x, m_y);
|
||||
if (newScreen == NULL) {
|
||||
log((CLOG_DEBUG1 "no neighbor; clamping"));
|
||||
if (m_x < 0)
|
||||
m_x = 0;
|
||||
else if (m_x > m_active->m_width - 1)
|
||||
m_x = m_active->m_width - 1;
|
||||
if (m_y < 0)
|
||||
m_y = 0;
|
||||
else if (m_y > m_active->m_height - 1)
|
||||
m_y = m_active->m_height - 1;
|
||||
if (m_x < m_active->m_x)
|
||||
m_x = m_active->m_x;
|
||||
else if (m_x > m_active->m_x + m_active->m_w - 1)
|
||||
m_x = m_active->m_x + m_active->m_w - 1;
|
||||
if (m_y < m_active->m_y)
|
||||
m_y = m_active->m_y;
|
||||
else if (m_y > m_active->m_y + m_active->m_h - 1)
|
||||
m_y = m_active->m_y + m_active->m_h - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// clamp to edge when locked
|
||||
log((CLOG_DEBUG1 "clamp to \"%s\"", m_active->m_name.c_str()));
|
||||
if (m_x < 0)
|
||||
m_x = 0;
|
||||
else if (m_x > m_active->m_width - 1)
|
||||
m_x = m_active->m_width - 1;
|
||||
if (m_y < 0)
|
||||
m_y = 0;
|
||||
else if (m_y > m_active->m_height - 1)
|
||||
m_y = m_active->m_height - 1;
|
||||
if (m_x < m_active->m_x)
|
||||
m_x = m_active->m_x;
|
||||
else if (m_x > m_active->m_x + m_active->m_w - 1)
|
||||
m_x = m_active->m_x + m_active->m_w - 1;
|
||||
if (m_y < m_active->m_y)
|
||||
m_y = m_active->m_y;
|
||||
else if (m_y > m_active->m_y + m_active->m_h - 1)
|
||||
m_y = m_active->m_y + m_active->m_h - 1;
|
||||
}
|
||||
|
||||
// warp cursor if on same screen
|
||||
@@ -729,7 +723,8 @@ void
|
||||
CServer::switchScreen(CScreenInfo* dst, SInt32 x, SInt32 y)
|
||||
{
|
||||
assert(dst != NULL);
|
||||
assert(x >= 0 && y >= 0 && x < dst->m_width && y < dst->m_height);
|
||||
assert(x >= dst->m_x && y >= dst->m_y);
|
||||
assert(x < dst->m_x + dst->m_w && y < dst->m_y + dst->m_h);
|
||||
assert(m_active != NULL);
|
||||
|
||||
log((CLOG_INFO "switch from \"%s\" to \"%s\" at %d,%d", m_active->m_name.c_str(), dst->m_name.c_str(), x, y));
|
||||
@@ -832,22 +827,27 @@ CServer::getNeighbor(CScreenInfo* src,
|
||||
assert(src != NULL);
|
||||
|
||||
// get the first neighbor
|
||||
CScreenInfo* lastGoodScreen = src;
|
||||
CScreenInfo* dst = getNeighbor(src, srcSide);
|
||||
if (dst == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// get the source screen's size (needed for kRight and kBottom)
|
||||
SInt32 w = src->m_width, h = src->m_height;
|
||||
SInt32 w = src->m_w, h = src->m_h;
|
||||
|
||||
// find destination screen, adjusting x or y (but not both)
|
||||
// find destination screen, adjusting x or y (but not both). the
|
||||
// searches are done in a sort of canonical screen space where
|
||||
// the upper-left corner is 0,0 for each screen. we adjust from
|
||||
// actual to canonical position on entry to and from canonical to
|
||||
// actual on exit from the search.
|
||||
CScreenInfo* lastGoodScreen = src;
|
||||
switch (srcSide) {
|
||||
case CConfig::kLeft:
|
||||
x -= src->m_x;
|
||||
while (dst != NULL && dst != lastGoodScreen) {
|
||||
lastGoodScreen = dst;
|
||||
w = lastGoodScreen->m_width;
|
||||
h = lastGoodScreen->m_height;
|
||||
w = lastGoodScreen->m_w;
|
||||
h = lastGoodScreen->m_h;
|
||||
x += w;
|
||||
if (x >= 0) {
|
||||
break;
|
||||
@@ -855,27 +855,33 @@ CServer::getNeighbor(CScreenInfo* src,
|
||||
log((CLOG_DEBUG2 "skipping over screen %s", dst->m_name.c_str()));
|
||||
dst = getNeighbor(lastGoodScreen, srcSide);
|
||||
}
|
||||
assert(lastGoodScreen != NULL);
|
||||
x += lastGoodScreen->m_x;
|
||||
break;
|
||||
|
||||
case CConfig::kRight:
|
||||
x -= src->m_x;
|
||||
while (dst != NULL) {
|
||||
lastGoodScreen = dst;
|
||||
x -= w;
|
||||
w = lastGoodScreen->m_width;
|
||||
h = lastGoodScreen->m_height;
|
||||
w = lastGoodScreen->m_w;
|
||||
h = lastGoodScreen->m_h;
|
||||
if (x < w) {
|
||||
break;
|
||||
}
|
||||
log((CLOG_DEBUG2 "skipping over screen %s", dst->m_name.c_str()));
|
||||
dst = getNeighbor(lastGoodScreen, srcSide);
|
||||
}
|
||||
assert(lastGoodScreen != NULL);
|
||||
x += lastGoodScreen->m_x;
|
||||
break;
|
||||
|
||||
case CConfig::kTop:
|
||||
y -= src->m_y;
|
||||
while (dst != NULL) {
|
||||
lastGoodScreen = dst;
|
||||
w = lastGoodScreen->m_width;
|
||||
h = lastGoodScreen->m_height;
|
||||
w = lastGoodScreen->m_w;
|
||||
h = lastGoodScreen->m_h;
|
||||
y += h;
|
||||
if (y >= 0) {
|
||||
break;
|
||||
@@ -883,106 +889,108 @@ CServer::getNeighbor(CScreenInfo* src,
|
||||
log((CLOG_DEBUG2 "skipping over screen %s", dst->m_name.c_str()));
|
||||
dst = getNeighbor(lastGoodScreen, srcSide);
|
||||
}
|
||||
assert(lastGoodScreen != NULL);
|
||||
y += lastGoodScreen->m_y;
|
||||
break;
|
||||
|
||||
case CConfig::kBottom:
|
||||
y -= src->m_y;
|
||||
while (dst != NULL) {
|
||||
lastGoodScreen = dst;
|
||||
y -= h;
|
||||
w = lastGoodScreen->m_width;
|
||||
h = lastGoodScreen->m_height;
|
||||
w = lastGoodScreen->m_w;
|
||||
h = lastGoodScreen->m_h;
|
||||
if (y < h) {
|
||||
break;
|
||||
}
|
||||
log((CLOG_DEBUG2 "skipping over screen %s", dst->m_name.c_str()));
|
||||
dst = getNeighbor(lastGoodScreen, srcSide);
|
||||
}
|
||||
assert(lastGoodScreen != NULL);
|
||||
y += lastGoodScreen->m_y;
|
||||
break;
|
||||
}
|
||||
assert(lastGoodScreen != NULL);
|
||||
|
||||
/* allow screen to be it's own neighbor to allow wrapping
|
||||
// no neighbor if best neighbor is the source itself
|
||||
if (lastGoodScreen == src)
|
||||
return NULL;
|
||||
*/
|
||||
// save destination screen
|
||||
assert(lastGoodScreen != NULL);
|
||||
dst = lastGoodScreen;
|
||||
|
||||
// if entering primary screen then be sure to move in far enough
|
||||
// to avoid the jump zone. if entering a side that doesn't have
|
||||
// a neighbor (i.e. an asymmetrical side) then we don't need to
|
||||
// move inwards because that side can't provoke a jump.
|
||||
if (lastGoodScreen->m_protocol == NULL) {
|
||||
const CString dstName(lastGoodScreen->m_name);
|
||||
if (dst->m_protocol == NULL) {
|
||||
const CString dstName(dst->m_name);
|
||||
switch (srcSide) {
|
||||
case CConfig::kLeft:
|
||||
if (!m_config.getNeighbor(dstName, CConfig::kRight).empty() &&
|
||||
x > w - 1 - lastGoodScreen->m_zoneSize)
|
||||
x = w - 1 - lastGoodScreen->m_zoneSize;
|
||||
x > dst->m_x + w - 1 - dst->m_zoneSize)
|
||||
x = dst->m_x + w - 1 - dst->m_zoneSize;
|
||||
break;
|
||||
|
||||
case CConfig::kRight:
|
||||
if (!m_config.getNeighbor(dstName, CConfig::kLeft).empty() &&
|
||||
x < lastGoodScreen->m_zoneSize)
|
||||
x = lastGoodScreen->m_zoneSize;
|
||||
x < dst->m_x + dst->m_zoneSize)
|
||||
x = dst->m_x + dst->m_zoneSize;
|
||||
break;
|
||||
|
||||
case CConfig::kTop:
|
||||
if (!m_config.getNeighbor(dstName, CConfig::kBottom).empty() &&
|
||||
y > h - 1 - lastGoodScreen->m_zoneSize)
|
||||
y = h - 1 - lastGoodScreen->m_zoneSize;
|
||||
y > dst->m_y + h - 1 - dst->m_zoneSize)
|
||||
y = dst->m_y + h - 1 - dst->m_zoneSize;
|
||||
break;
|
||||
|
||||
case CConfig::kBottom:
|
||||
if (!m_config.getNeighbor(dstName, CConfig::kTop).empty() &&
|
||||
y < lastGoodScreen->m_zoneSize)
|
||||
y = lastGoodScreen->m_zoneSize;
|
||||
y < dst->m_y + dst->m_zoneSize)
|
||||
y = dst->m_y + dst->m_zoneSize;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return lastGoodScreen;
|
||||
}
|
||||
|
||||
void
|
||||
CServer::mapPosition(CScreenInfo* src, CConfig::EDirection srcSide,
|
||||
CScreenInfo* dst, SInt32& x, SInt32& y) const
|
||||
{
|
||||
assert(src != NULL);
|
||||
assert(dst != NULL);
|
||||
assert(srcSide >= CConfig::kFirstDirection &&
|
||||
srcSide <= CConfig::kLastDirection);
|
||||
|
||||
// adjust the coordinate orthogonal to srcSide to account for
|
||||
// resolution differences. for example, if y is 200 pixels from
|
||||
// the top on a screen 1000 pixels high (20% from the top) when
|
||||
// we cross the left edge onto a screen 600 pixels high then y
|
||||
// should be set 120 pixels from the top (again 20% from the
|
||||
// top).
|
||||
switch (srcSide) {
|
||||
case CConfig::kLeft:
|
||||
case CConfig::kRight:
|
||||
y -= src->m_y;
|
||||
if (y < 0) {
|
||||
y = 0;
|
||||
}
|
||||
else if (y >= src->m_height) {
|
||||
y = dst->m_height - 1;
|
||||
else if (y >= src->m_h) {
|
||||
y = dst->m_h - 1;
|
||||
}
|
||||
else {
|
||||
y = static_cast<SInt32>(0.5 + y *
|
||||
static_cast<double>(dst->m_height - 1) /
|
||||
(src->m_height - 1));
|
||||
static_cast<double>(dst->m_h - 1) /
|
||||
(src->m_h - 1));
|
||||
}
|
||||
y += dst->m_y;
|
||||
break;
|
||||
|
||||
case CConfig::kTop:
|
||||
case CConfig::kBottom:
|
||||
x -= src->m_x;
|
||||
if (x < 0) {
|
||||
x = 0;
|
||||
}
|
||||
else if (x >= src->m_width) {
|
||||
x = dst->m_width - 1;
|
||||
else if (x >= src->m_w) {
|
||||
x = dst->m_w - 1;
|
||||
}
|
||||
else {
|
||||
x = static_cast<SInt32>(0.5 + x *
|
||||
static_cast<double>(dst->m_width - 1) /
|
||||
(src->m_width - 1));
|
||||
static_cast<double>(dst->m_w - 1) /
|
||||
(src->m_w - 1));
|
||||
}
|
||||
x += dst->m_x;
|
||||
break;
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
#include "CTCPListenSocket.h"
|
||||
@@ -1536,8 +1544,8 @@ CServer::removeConnection(const CString& name)
|
||||
// if this is active screen then we have to jump off of it
|
||||
if (m_active == index->second && m_active != m_primaryInfo) {
|
||||
// record new position (center of primary screen)
|
||||
m_x = m_primaryInfo->m_width >> 1;
|
||||
m_y = m_primaryInfo->m_height >> 1;
|
||||
m_x = m_primaryInfo->m_x + (m_primaryInfo->m_w >> 1);
|
||||
m_y = m_primaryInfo->m_y + (m_primaryInfo->m_h >> 1);
|
||||
|
||||
// don't notify active screen since it probably already disconnected
|
||||
log((CLOG_INFO "jump from \"%s\" to \"%s\" at %d,%d", m_active->m_name.c_str(), m_primaryInfo->m_name.c_str(), m_x, m_y));
|
||||
@@ -1601,8 +1609,10 @@ CServer::CScreenInfo::CScreenInfo(const CString& name,
|
||||
m_name(name),
|
||||
m_protocol(protocol),
|
||||
m_ready(false),
|
||||
m_width(0),
|
||||
m_height(0),
|
||||
m_x(0),
|
||||
m_y(0),
|
||||
m_w(0),
|
||||
m_h(0),
|
||||
m_zoneSize(0)
|
||||
{
|
||||
for (ClipboardID id = 0; id < kClipboardEnd; ++id)
|
||||
|
||||
@@ -55,12 +55,14 @@ public:
|
||||
void grabClipboard(ClipboardID);
|
||||
|
||||
// handle updates from primary
|
||||
void setInfo(SInt32 wScreen, SInt32 hScreen,
|
||||
void setInfo(SInt32 xScreen, SInt32 yScreen,
|
||||
SInt32 wScreen, SInt32 hScreen,
|
||||
SInt32 zoneSize,
|
||||
SInt32 xMouse, SInt32 yMouse);
|
||||
|
||||
// handle messages from clients
|
||||
void setInfo(const CString& clientName,
|
||||
SInt32 xScreen, SInt32 yScreen,
|
||||
SInt32 wScreen, SInt32 hScreen,
|
||||
SInt32 zoneSize,
|
||||
SInt32 xMouse, SInt32 yMouse);
|
||||
@@ -119,8 +121,12 @@ private:
|
||||
CString m_name;
|
||||
IServerProtocol* m_protocol;
|
||||
bool m_ready;
|
||||
SInt32 m_width, m_height;
|
||||
|
||||
// screen shape and jump zone size
|
||||
SInt32 m_x, m_y;
|
||||
SInt32 m_w, m_h;
|
||||
SInt32 m_zoneSize;
|
||||
|
||||
bool m_gotClipboard[kClipboardEnd];
|
||||
};
|
||||
|
||||
@@ -130,6 +136,7 @@ private:
|
||||
|
||||
// update screen info
|
||||
void setInfoNoLock(const CString& screenName,
|
||||
SInt32 xScreen, SInt32 yScreen,
|
||||
SInt32 wScreen, SInt32 hScreen,
|
||||
SInt32 zoneSize,
|
||||
SInt32 xMouse, SInt32 yMouse);
|
||||
@@ -150,19 +157,12 @@ private:
|
||||
// lookup neighboring screen. given a position relative to the
|
||||
// source screen, find the screen we should move onto and where.
|
||||
// if the position is sufficiently far from the source then we
|
||||
// cross multiple screens.
|
||||
// cross multiple screens. if there is no suitable screen then
|
||||
// return NULL and x,y are not modified.
|
||||
CScreenInfo* getNeighbor(CScreenInfo*,
|
||||
CConfig::EDirection,
|
||||
SInt32& x, SInt32& y) const;
|
||||
|
||||
// adjust coordinates to account for resolution differences. the
|
||||
// position is converted to a resolution independent form then
|
||||
// converted back to screen coordinates on the destination screen.
|
||||
void mapPosition(CScreenInfo* src,
|
||||
CConfig::EDirection srcSide,
|
||||
CScreenInfo* dst,
|
||||
SInt32& x, SInt32& y) const;
|
||||
|
||||
// open/close the primary screen
|
||||
void openPrimaryScreen();
|
||||
void closePrimaryScreen();
|
||||
|
||||
@@ -199,21 +199,21 @@ void
|
||||
CServerProtocol1_0::recvInfo()
|
||||
{
|
||||
// parse the message
|
||||
SInt16 x, y, w, h, zoneInfo;
|
||||
SInt16 x, y, w, h, zoneInfo, mx, my;
|
||||
CProtocolUtil::readf(getInputStream(), kMsgDInfo + 4,
|
||||
&w, &h, &zoneInfo, &x, &y);
|
||||
log((CLOG_DEBUG "received client \"%s\" info size=%dx%d, zone=%d, pos=%d,%d", getClient().c_str(), w, h, zoneInfo, x, y));
|
||||
&x, &y, &w, &h, &zoneInfo, &mx, &my);
|
||||
log((CLOG_DEBUG "received client \"%s\" info shape=%d,%d %dx%d, zone=%d, pos=%d,%d", getClient().c_str(), x, y, w, h, zoneInfo, mx, my));
|
||||
|
||||
// validate
|
||||
if (w <= 0 || h <= 0 || zoneInfo < 0) {
|
||||
throw XBadClient();
|
||||
}
|
||||
if (x < 0 || y < 0 || x >= w || y >= h) {
|
||||
if (mx < x || my < y || mx >= x + w || my >= y + h) {
|
||||
throw XBadClient();
|
||||
}
|
||||
|
||||
// tell server of change
|
||||
getServer()->setInfo(getClient(), w, h, zoneInfo, x, y);
|
||||
getServer()->setInfo(getClient(), x, y, w, h, zoneInfo, mx, my);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -48,6 +48,8 @@ static HHOOK g_keyboardLL = NULL;
|
||||
static bool g_relay = false;
|
||||
static SInt32 g_zoneSize = 0;
|
||||
static UInt32 g_zoneSides = 0;
|
||||
static SInt32 g_xScreen = 0;
|
||||
static SInt32 g_yScreen = 0;
|
||||
static SInt32 g_wScreen = 0;
|
||||
static SInt32 g_hScreen = 0;
|
||||
static HCURSOR g_cursor = NULL;
|
||||
@@ -196,16 +198,16 @@ mouseHook(int code, WPARAM wParam, LPARAM lParam)
|
||||
SInt32 x = (SInt32)info->pt.x;
|
||||
SInt32 y = (SInt32)info->pt.y;
|
||||
if (!inside && (g_zoneSides & CConfig::kLeftMask) != 0) {
|
||||
inside = (x < g_zoneSize);
|
||||
inside = (x < g_xScreen + g_zoneSize);
|
||||
}
|
||||
if (!inside && (g_zoneSides & CConfig::kRightMask) != 0) {
|
||||
inside = (x >= g_wScreen - g_zoneSize);
|
||||
inside = (x >= g_xScreen + g_wScreen - g_zoneSize);
|
||||
}
|
||||
if (!inside && (g_zoneSides & CConfig::kTopMask) != 0) {
|
||||
inside = (y < g_zoneSize);
|
||||
inside = (y < g_yScreen + g_zoneSize);
|
||||
}
|
||||
if (!inside && (g_zoneSides & CConfig::kBottomMask) != 0) {
|
||||
inside = (y >= g_hScreen - g_zoneSize);
|
||||
inside = (y >= g_yScreen + g_hScreen - g_zoneSize);
|
||||
}
|
||||
|
||||
// if inside then eat event and notify our window
|
||||
@@ -463,6 +465,8 @@ install(DWORD threadID)
|
||||
g_relay = false;
|
||||
g_zoneSize = 0;
|
||||
g_zoneSides = 0;
|
||||
g_xScreen = 0;
|
||||
g_yScreen = 0;
|
||||
g_wScreen = 0;
|
||||
g_hScreen = 0;
|
||||
g_cursor = NULL;
|
||||
@@ -585,10 +589,14 @@ uninstall(void)
|
||||
}
|
||||
|
||||
void
|
||||
setZone(UInt32 sides, SInt32 w, SInt32 h, SInt32 jumpZoneSize)
|
||||
setZone(UInt32 sides,
|
||||
SInt32 x, SInt32 y, SInt32 w, SInt32 h,
|
||||
SInt32 jumpZoneSize)
|
||||
{
|
||||
g_zoneSize = jumpZoneSize;
|
||||
g_zoneSides = sides;
|
||||
g_xScreen = x;
|
||||
g_yScreen = y;
|
||||
g_wScreen = w;
|
||||
g_hScreen = h;
|
||||
g_relay = false;
|
||||
@@ -601,6 +609,8 @@ setRelay(void)
|
||||
g_relay = true;
|
||||
g_zoneSize = 0;
|
||||
g_zoneSides = 0;
|
||||
g_xScreen = 0;
|
||||
g_yScreen = 0;
|
||||
g_wScreen = 0;
|
||||
g_hScreen = 0;
|
||||
}
|
||||
|
||||
@@ -26,13 +26,15 @@ extern "C" {
|
||||
|
||||
typedef int (*InstallFunc)(DWORD targetQueueThreadID);
|
||||
typedef int (*UninstallFunc)(void);
|
||||
typedef void (*SetZoneFunc)(UInt32, SInt32, SInt32, SInt32);
|
||||
typedef void (*SetZoneFunc)(UInt32,
|
||||
SInt32, SInt32, SInt32, SInt32, SInt32);
|
||||
typedef void (*SetRelayFunc)(void);
|
||||
|
||||
CSYNERGYHOOK_API int install(DWORD);
|
||||
CSYNERGYHOOK_API int uninstall(void);
|
||||
CSYNERGYHOOK_API void setZone(UInt32 sides,
|
||||
SInt32 w, SInt32 h, SInt32 jumpZoneSize);
|
||||
SInt32 x, SInt32 y, SInt32 w, SInt32 h,
|
||||
SInt32 jumpZoneSize);
|
||||
CSYNERGYHOOK_API void setRelay(void);
|
||||
|
||||
}
|
||||
|
||||
@@ -161,6 +161,7 @@ CXWindowsPrimaryScreen::run()
|
||||
// FIXME -- slurp up all remaining motion events?
|
||||
// probably not since keystrokes may go to wrong place.
|
||||
|
||||
// XXX -- why call XQueryPointer?
|
||||
// get mouse deltas
|
||||
{
|
||||
CDisplayLock display(this);
|
||||
@@ -173,8 +174,8 @@ CXWindowsPrimaryScreen::run()
|
||||
}
|
||||
|
||||
// compute position of center of window
|
||||
SInt32 w, h;
|
||||
getScreenSize(&w, &h);
|
||||
SInt32 x0, y0, w, h;
|
||||
getScreenShape(x0, y0, w, h);
|
||||
x = xRoot - (w >> 1);
|
||||
y = yRoot - (h >> 1);
|
||||
|
||||
@@ -216,11 +217,11 @@ CXWindowsPrimaryScreen::open(CServer* server)
|
||||
// m_numLockHalfDuplex = true;
|
||||
// m_capsLockHalfDuplex = true;
|
||||
|
||||
// get screen size
|
||||
SInt32 w, h;
|
||||
getScreenSize(&w, &h);
|
||||
// get screen shape
|
||||
SInt32 x, y, w, h;
|
||||
getScreenShape(x, y, w, h);
|
||||
|
||||
int x, y;
|
||||
int mx, my;
|
||||
{
|
||||
CDisplayLock display(this);
|
||||
|
||||
@@ -232,14 +233,14 @@ CXWindowsPrimaryScreen::open(CServer* server)
|
||||
int xWindow, yWindow;
|
||||
unsigned int mask;
|
||||
if (!XQueryPointer(display, m_window, &root, &window,
|
||||
&x, &y, &xWindow, &yWindow, &mask)) {
|
||||
x = w >> 1;
|
||||
y = h >> 1;
|
||||
&mx, &my, &xWindow, &yWindow, &mask)) {
|
||||
mx = w >> 1;
|
||||
my = h >> 1;
|
||||
}
|
||||
}
|
||||
|
||||
// send screen info
|
||||
m_server->setInfo(w, h, getJumpZoneSize(), x, y);
|
||||
m_server->setInfo(x, y, w, h, getJumpZoneSize(), mx, my);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -340,8 +341,8 @@ CXWindowsPrimaryScreen::leave()
|
||||
log((CLOG_DEBUG1 "grabbed pointer and keyboard"));
|
||||
|
||||
// move the mouse to the center of grab window
|
||||
SInt32 w, h;
|
||||
getScreenSize(&w, &h);
|
||||
SInt32 x, y, w, h;
|
||||
getScreenShape(x, y, w, h);
|
||||
warpCursorNoLock(display, w >> 1, h >> 1);
|
||||
|
||||
// local client now active
|
||||
@@ -396,9 +397,10 @@ CXWindowsPrimaryScreen::grabClipboard(ClipboardID id)
|
||||
}
|
||||
|
||||
void
|
||||
CXWindowsPrimaryScreen::getSize(SInt32* width, SInt32* height) const
|
||||
CXWindowsPrimaryScreen::getShape(
|
||||
SInt32& x, SInt32& y, SInt32& w, SInt32& h) const
|
||||
{
|
||||
getScreenSize(width, height);
|
||||
getScreenShape(x, y, w, h);
|
||||
}
|
||||
|
||||
SInt32
|
||||
@@ -480,8 +482,8 @@ CXWindowsPrimaryScreen::onOpenDisplay(Display* display)
|
||||
assert(m_window == None);
|
||||
|
||||
// get size of screen
|
||||
SInt32 w, h;
|
||||
getScreenSize(&w, &h);
|
||||
SInt32 x, y, w, h;
|
||||
getScreenShape(x, y, w, h);
|
||||
|
||||
// create the grab window. this window is used to capture user
|
||||
// input when the user is focussed on another client. don't let
|
||||
@@ -494,7 +496,7 @@ CXWindowsPrimaryScreen::onOpenDisplay(Display* display)
|
||||
attr.do_not_propagate_mask = 0;
|
||||
attr.override_redirect = True;
|
||||
attr.cursor = createBlankCursor();
|
||||
m_window = XCreateWindow(display, getRoot(), 0, 0, w, h, 0, 0,
|
||||
m_window = XCreateWindow(display, getRoot(), x, y, w, h, 0, 0,
|
||||
InputOnly, CopyFromParent,
|
||||
CWDontPropagate | CWEventMask |
|
||||
CWOverrideRedirect | CWCursor,
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
virtual void warpCursor(SInt32 xAbsolute, SInt32 yAbsolute);
|
||||
virtual void setClipboard(ClipboardID, const IClipboard*);
|
||||
virtual void grabClipboard(ClipboardID);
|
||||
virtual void getSize(SInt32* width, SInt32* height) const;
|
||||
virtual void getShape(SInt32&, SInt32&, SInt32&, SInt32&) const;
|
||||
virtual SInt32 getJumpZoneSize() const;
|
||||
virtual void getClipboard(ClipboardID, IClipboard*) const;
|
||||
virtual KeyModifierMask getToggleMask() const;
|
||||
|
||||
Reference in New Issue
Block a user