mirror of
https://github.com/debauchee/barrier.git
synced 2026-11-26 22:03:24 +08:00
added screen locking support to win32. added support for
resolution changing (only semi-supported on X because that has no means for resizing screen anyway). also fixed some clipboard problems on win32.
This commit is contained in:
@@ -61,6 +61,11 @@ void CMSWindowsPrimaryScreen::open(CServer* server)
|
||||
// get keyboard state
|
||||
updateKeys();
|
||||
|
||||
// send screen info
|
||||
SInt32 w, h;
|
||||
getScreenSize(&w, &h);
|
||||
m_server->setInfo(w, h, getJumpZoneSize(), 0, 0);
|
||||
|
||||
// enter the screen
|
||||
doEnter();
|
||||
}
|
||||
@@ -246,18 +251,35 @@ void CMSWindowsPrimaryScreen::getClipboard(
|
||||
KeyModifierMask CMSWindowsPrimaryScreen::getToggleMask() const
|
||||
{
|
||||
KeyModifierMask mask = 0;
|
||||
if ((m_keys[VK_CAPITAL] & 0x01) != 0)
|
||||
if ((GetKeyState(VK_CAPITAL) & 0x01) != 0)
|
||||
mask |= KeyModifierCapsLock;
|
||||
if ((m_keys[VK_NUMLOCK] & 0x01) != 0)
|
||||
if ((GetKeyState(VK_NUMLOCK) & 0x01) != 0)
|
||||
mask |= KeyModifierNumLock;
|
||||
if ((m_keys[VK_SCROLL] & 0x01) != 0)
|
||||
if ((GetKeyState(VK_SCROLL) & 0x01) != 0)
|
||||
mask |= KeyModifierScrollLock;
|
||||
return mask;
|
||||
}
|
||||
|
||||
bool CMSWindowsPrimaryScreen::isLockedToScreen() const
|
||||
{
|
||||
// FIXME
|
||||
// check buttons
|
||||
if (GetAsyncKeyState(VK_LBUTTON) < 0 ||
|
||||
GetAsyncKeyState(VK_MBUTTON) < 0 ||
|
||||
GetAsyncKeyState(VK_RBUTTON) < 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// check keys
|
||||
BYTE keys[256];
|
||||
if (GetKeyboardState(keys)) {
|
||||
for (unsigned int i = 0; i < sizeof(keys); ++i) {
|
||||
if ((keys[i] & 0x80) != 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// not locked
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -433,13 +455,17 @@ bool CMSWindowsPrimaryScreen::onPreTranslate(MSG* msg)
|
||||
// get mouse deltas
|
||||
x -= m_xCenter;
|
||||
y -= m_yCenter;
|
||||
log((CLOG_DEBUG2 "event: active move %d,%d", x, y));
|
||||
|
||||
// warp mouse back to center
|
||||
warpCursor(m_xCenter, m_yCenter);
|
||||
// ignore if the mouse didn't move
|
||||
if (x != 0 && y != 0) {
|
||||
log((CLOG_DEBUG2 "event: active move %d,%d", x, y));
|
||||
|
||||
// send motion
|
||||
m_server->onMouseMoveSecondary(x, y);
|
||||
// warp mouse back to center
|
||||
warpCursor(m_xCenter, m_yCenter);
|
||||
|
||||
// send motion
|
||||
m_server->onMouseMoveSecondary(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -485,6 +511,36 @@ LRESULT CMSWindowsPrimaryScreen::onEvent(
|
||||
else
|
||||
SendMessage(m_nextClipboardWindow, msg, wParam, lParam);
|
||||
return 0;
|
||||
|
||||
case WM_DISPLAYCHANGE: {
|
||||
// screen resolution has changed
|
||||
SInt32 w, h;
|
||||
updateScreenSize();
|
||||
getScreenSize(&w, &h);
|
||||
|
||||
// recompute center pixel of screen
|
||||
m_xCenter = w >> 1;
|
||||
m_yCenter = h >> 1;
|
||||
|
||||
// warp mouse to center if active
|
||||
if (m_active) {
|
||||
warpCursor(m_xCenter, m_yCenter);
|
||||
}
|
||||
|
||||
// tell hook about resize if not active
|
||||
else {
|
||||
SetZoneFunc setZone = (SetZoneFunc)GetProcAddress(
|
||||
m_hookLibrary, "setZone");
|
||||
setZone(m_server->getActivePrimarySides(), w, h, getJumpZoneSize());
|
||||
}
|
||||
|
||||
// send new screen info
|
||||
POINT pos;
|
||||
GetCursorPos(&pos);
|
||||
m_server->setInfo(w, h, getJumpZoneSize(), pos.x, pos.y);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||
|
||||
@@ -132,8 +132,16 @@ UInt32 CServer::getActivePrimarySides() const
|
||||
return sides;
|
||||
}
|
||||
|
||||
void CServer::setInfo(
|
||||
SInt32 w, SInt32 h, SInt32 zoneSize,
|
||||
SInt32 x, SInt32 y)
|
||||
{
|
||||
setInfo(m_primaryInfo->m_name, w, h, zoneSize, x, y);
|
||||
}
|
||||
|
||||
void CServer::setInfo(const CString& client,
|
||||
SInt32 w, SInt32 h, SInt32 zoneSize)
|
||||
SInt32 w, SInt32 h, SInt32 zoneSize,
|
||||
SInt32 x, SInt32 y)
|
||||
{
|
||||
assert(!client.empty());
|
||||
assert(w > 0);
|
||||
@@ -151,12 +159,29 @@ void CServer::setInfo(const CString& client,
|
||||
// update client info
|
||||
CScreenInfo* info = index->second;
|
||||
if (info == m_active) {
|
||||
// FIXME -- ensure mouse is still on screen. warp it if necessary.
|
||||
// update the remote mouse coordinates
|
||||
m_x = x;
|
||||
m_y = y;
|
||||
}
|
||||
info->m_width = w;
|
||||
info->m_height = h;
|
||||
info->m_zoneSize = zoneSize;
|
||||
log((CLOG_NOTE "client \"%s\" size=%dx%d zone=%d", client.c_str(), w, h, zoneSize));
|
||||
log((CLOG_NOTE "client \"%s\" size=%dx%d zone=%d pos=%d,%d", client.c_str(), w, h, zoneSize, x, y));
|
||||
|
||||
// send acknowledgement (if client isn't the primary)
|
||||
if (info->m_protocol != NULL) {
|
||||
info->m_protocol->sendInfoAcknowledgment();
|
||||
}
|
||||
|
||||
// handle resolution change to primary screen
|
||||
else {
|
||||
if (info == m_active) {
|
||||
onMouseMovePrimary(x, y);
|
||||
}
|
||||
else {
|
||||
onMouseMoveSecondary(0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CServer::grabClipboard(ClipboardID id)
|
||||
@@ -1011,6 +1036,10 @@ void CServer::openPrimaryScreen()
|
||||
// reset sequence number
|
||||
m_seqNum = 0;
|
||||
|
||||
// add connection
|
||||
m_active = addConnection(CString("primary"/* FIXME */), NULL);
|
||||
m_primaryInfo = m_active;
|
||||
|
||||
// open screen
|
||||
log((CLOG_DEBUG1 "creating primary screen"));
|
||||
#if defined(CONFIG_PLATFORM_WIN32)
|
||||
@@ -1021,16 +1050,6 @@ void CServer::openPrimaryScreen()
|
||||
log((CLOG_DEBUG1 "opening primary screen"));
|
||||
m_primary->open(this);
|
||||
|
||||
// add connection
|
||||
m_active = addConnection(CString("primary"/* FIXME */), NULL);
|
||||
m_primaryInfo = m_active;
|
||||
|
||||
// update info
|
||||
m_primary->getSize(&m_active->m_width, &m_active->m_height);
|
||||
m_active->m_zoneSize = m_primary->getJumpZoneSize();
|
||||
log((CLOG_NOTE "server size=%dx%d zone=%d", m_active->m_width, m_active->m_height, m_active->m_zoneSize));
|
||||
// FIXME -- need way for primary screen to call us back
|
||||
|
||||
// set the clipboard owner to the primary screen and then get the
|
||||
// current clipboard data.
|
||||
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
|
||||
|
||||
@@ -46,9 +46,16 @@ public:
|
||||
void onMouseWheel(SInt32 delta);
|
||||
void grabClipboard(ClipboardID);
|
||||
|
||||
// handle updates from primary
|
||||
void setInfo(SInt32 wScreen, SInt32 hScreen,
|
||||
SInt32 zoneSize,
|
||||
SInt32 xMouse, SInt32 yMouse);
|
||||
|
||||
// handle messages from clients
|
||||
void setInfo(const CString& clientName,
|
||||
SInt32 w, SInt32 h, SInt32 zoneSize);
|
||||
SInt32 wScreen, SInt32 hScreen,
|
||||
SInt32 zoneSize,
|
||||
SInt32 xMouse, SInt32 yMouse);
|
||||
void grabClipboard(ClipboardID,
|
||||
UInt32 seqNum, const CString& clientName);
|
||||
void setClipboard(ClipboardID,
|
||||
@@ -187,6 +194,7 @@ private:
|
||||
// the sequence number of enter messages
|
||||
UInt32 m_seqNum;
|
||||
|
||||
// current mouse position (in absolute secondary screen coordinates)
|
||||
SInt32 m_x, m_y;
|
||||
|
||||
CScreenMap m_screenMap;
|
||||
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
virtual void sendClipboard(ClipboardID, const CString&) = 0;
|
||||
virtual void sendGrabClipboard(ClipboardID) = 0;
|
||||
virtual void sendScreenSaver(bool on) = 0;
|
||||
virtual void sendInfoAcknowledgment() = 0;
|
||||
virtual void sendKeyDown(KeyID, KeyModifierMask) = 0;
|
||||
virtual void sendKeyRepeat(KeyID, KeyModifierMask, SInt32 count) = 0;
|
||||
virtual void sendKeyUp(KeyID, KeyModifierMask) = 0;
|
||||
|
||||
@@ -124,6 +124,12 @@ void CServerProtocol1_0::sendScreenSaver(bool on)
|
||||
CProtocolUtil::writef(getOutputStream(), kMsgCScreenSaver, on ? 1 : 0);
|
||||
}
|
||||
|
||||
void CServerProtocol1_0::sendInfoAcknowledgment()
|
||||
{
|
||||
log((CLOG_DEBUG1 "send info ack to \"%s\"", getClient().c_str()));
|
||||
CProtocolUtil::writef(getOutputStream(), kMsgCInfoAck);
|
||||
}
|
||||
|
||||
void CServerProtocol1_0::sendKeyDown(
|
||||
KeyID key, KeyModifierMask mask)
|
||||
{
|
||||
@@ -176,17 +182,21 @@ void CServerProtocol1_0::sendMouseWheel(
|
||||
void CServerProtocol1_0::recvInfo()
|
||||
{
|
||||
// parse the message
|
||||
SInt16 w, h, zoneInfo;
|
||||
CProtocolUtil::readf(getInputStream(), kMsgDInfo + 4, &w, &h, &zoneInfo);
|
||||
log((CLOG_DEBUG "received client \"%s\" info size=%dx%d, zone=%d", getClient().c_str(), w, h, zoneInfo));
|
||||
SInt16 x, y, w, h, zoneInfo;
|
||||
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));
|
||||
|
||||
// validate
|
||||
if (w <= 0 || h <= 0 || zoneInfo < 0) {
|
||||
throw XBadClient();
|
||||
}
|
||||
if (x < 0 || y < 0 || x >= w || y >= h) {
|
||||
throw XBadClient();
|
||||
}
|
||||
|
||||
// tell server of change
|
||||
getServer()->setInfo(getClient(), w, h, zoneInfo);
|
||||
getServer()->setInfo(getClient(), w, h, zoneInfo, x, y);
|
||||
}
|
||||
|
||||
void CServerProtocol1_0::recvClipboard()
|
||||
|
||||
@@ -22,6 +22,7 @@ public:
|
||||
virtual void sendClipboard(ClipboardID, const CString&);
|
||||
virtual void sendGrabClipboard(ClipboardID);
|
||||
virtual void sendScreenSaver(bool on);
|
||||
virtual void sendInfoAcknowledgment();
|
||||
virtual void sendKeyDown(KeyID, KeyModifierMask);
|
||||
virtual void sendKeyRepeat(KeyID, KeyModifierMask, SInt32 count);
|
||||
virtual void sendKeyUp(KeyID, KeyModifierMask);
|
||||
|
||||
@@ -268,6 +268,11 @@ void CXWindowsPrimaryScreen::open(CServer* server)
|
||||
CDisplayLock display(this);
|
||||
updateModifierMap(display);
|
||||
}
|
||||
|
||||
// send screen info
|
||||
SInt32 w, h;
|
||||
getScreenSize(&w, &h);
|
||||
m_server->setInfo(w, h, getJumpZoneSize(), 0, 0);
|
||||
}
|
||||
|
||||
void CXWindowsPrimaryScreen::close()
|
||||
|
||||
Reference in New Issue
Block a user