Skip to content

Commit deb10b2

Browse files
Allow XScreensaver syncing from client to server
Allows to deactivate the screensaver and postpone screensaver activation if local input is detected on a client. This fixes the screensavers getting out of sync if a client has a local input device such as a touchscreen
1 parent 1436c8b commit deb10b2

18 files changed

+3464
-3344
lines changed

src/lib/barrier/Screen.cpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
* barrier -- mouse and keyboard sharing utility
33
* Copyright (C) 2012-2016 Symless Ltd.
44
* Copyright (C) 2003 Chris Schoeneman
5-
*
5+
*
66
* This package is free software; you can redistribute it and/or
77
* modify it under the terms of the GNU General Public License
88
* found in the file LICENSE that should have accompanied this file.
9-
*
9+
*
1010
* This package is distributed in the hope that it will be useful,
1111
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -178,11 +178,9 @@ Screen::grabClipboard(ClipboardID id)
178178
void
179179
Screen::screensaver(bool activate)
180180
{
181-
if (!m_isPrimary) {
182-
// activate/deactivation screen saver iff synchronization enabled
183-
if (m_screenSaverSync) {
184-
m_screen->screensaver(activate);
185-
}
181+
// activate/deactivation screen saver iff synchronization enabled
182+
if (m_screenSaverSync) {
183+
m_screen->screensaver(activate);
186184
}
187185
}
188186

@@ -376,7 +374,7 @@ Screen::isLockedToScreen() const
376374
if (buttonID != kButtonLeft) {
377375
LOG((CLOG_DEBUG "locked by mouse buttonID: %d", buttonID));
378376
}
379-
377+
380378
if (m_enableDragDrop) {
381379
return (buttonID == kButtonLeft) ? false : true;
382380
}

src/lib/barrier/Screen.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
* barrier -- mouse and keyboard sharing utility
33
* Copyright (C) 2012-2016 Symless Ltd.
44
* Copyright (C) 2002 Chris Schoeneman
5-
*
5+
*
66
* This package is free software; you can redistribute it and/or
77
* modify it under the terms of the GNU General Public License
88
* found in the file LICENSE that should have accompanied this file.
9-
*
9+
*
1010
* This package is distributed in the hope that it will be useful,
1111
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -223,7 +223,7 @@ class Screen : public IScreen {
223223

224224
//! Change dragging status
225225
void setDraggingStarted(bool started);
226-
226+
227227
//! Fake a files dragging operation
228228
void startDraggingFiles(DragFileList& fileList);
229229

@@ -278,7 +278,7 @@ class Screen : public IScreen {
278278

279279
//! Test if file is dragged on primary screen
280280
bool isDraggingStarted() const;
281-
281+
282282
//! Test if file is dragged on secondary screen
283283
bool isFakeDraggingStarted() const;
284284

@@ -299,7 +299,7 @@ class Screen : public IScreen {
299299
virtual void getShape(SInt32& x, SInt32& y,
300300
SInt32& width, SInt32& height) const;
301301
virtual void getCursorPos(SInt32& x, SInt32& y) const;
302-
302+
303303
IPlatformScreen* getPlatformScreen() { return m_screen; }
304304

305305
protected:

src/lib/barrier/protocol_types.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ const char* kMsgHello = "Barrier%2i%2i";
2222
const char* kMsgHelloBack = "Barrier%2i%2i%s";
2323
const char* kMsgCNoop = "CNOP";
2424
const char* kMsgCClose = "CBYE";
25-
const char* kMsgCEnter = "CINN%2i%2i%4i%2i";
25+
const char* kMsgCEnter = "CINN%2i%2i%4i%2i%1i";
26+
const char* kMsgCEnter1_0 = "CINN%2i%2i%4i%2i";
2627
const char* kMsgCLeave = "COUT";
2728
const char* kMsgCClipboard = "CCLP%1i%4i";
2829
const char* kMsgCScreenSaver = "CSEC%1i";

src/lib/barrier/protocol_types.h

+15-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
* barrier -- mouse and keyboard sharing utility
33
* Copyright (C) 2012-2016 Symless Ltd.
44
* Copyright (C) 2002 Chris Schoeneman
5-
*
5+
*
66
* This package is free software; you can redistribute it and/or
77
* modify it under the terms of the GNU General Public License
88
* found in the file LICENSE that should have accompanied this file.
9-
*
9+
*
1010
* This package is distributed in the hope that it will be useful,
1111
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -30,6 +30,7 @@
3030
// 1.5: adds file transfer and removes home brew crypto
3131
// 1.6: adds clipboard streaming
3232
// 1.7: adds focus/screen switch on local input
33+
// adds screensaver sync on client local input
3334
// NOTE: with new version, barrier minor version should increment
3435
static const SInt16 kProtocolMajorVersion = 1;
3536
static const SInt16 kProtocolMinorVersion = 7;
@@ -130,9 +131,16 @@ extern const char* kMsgCClose;
130131
// must return this number with some messages. $4 = modifier key
131132
// mask. this will have bits set for each toggle modifier key
132133
// that is activated on entry to the screen. the secondary screen
133-
// should adjust its toggle modifiers to reflect that state.
134+
// should adjust its toggle modifiers to reflect that state. $5 =
135+
// forScreensaver flag which denotes whether the screen is only
136+
// entered for screensaver management purposes or not and thus
137+
// whether the client can change its screensaver state or should
138+
// not change the screensaver state
134139
extern const char* kMsgCEnter;
135140

141+
// enter screen 1.0: same as above but without respecting the screensaver state
142+
extern const char* kMsgCEnter1_0;
143+
136144
// leave screen: primary -> secondary
137145
// leaving screen. the secondary screen should send clipboard
138146
// data in response to this message for those clipboards that
@@ -149,8 +157,10 @@ extern const char* kMsgCLeave;
149157
// most recent kMsgCEnter. the primary always sends 0.
150158
extern const char* kMsgCClipboard;
151159

152-
// screensaver change: primary -> secondary
153-
// screensaver on primary has started ($1 == 1) or closed ($1 == 0)
160+
// screensaver change: primary <-> secondary
161+
// screensaver has started ($1 == 1) or closed ($1 == 0).
162+
// sync screensavers by dispatching information to all clients via
163+
// the server
154164
extern const char* kMsgCScreenSaver;
155165

156166
// reset options: primary -> secondary

src/lib/client/Client.cpp

+32-4
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,13 @@ Client::getCursorPos(SInt32& x, SInt32& y) const
237237
}
238238

239239
void
240-
Client::enter(SInt32 xAbs, SInt32 yAbs, UInt32, KeyModifierMask mask, bool)
240+
Client::enter(SInt32 xAbs, SInt32 yAbs, UInt32, KeyModifierMask mask, bool forScreensaver)
241241
{
242242
m_active = true;
243243
m_screen->mouseMove(xAbs, yAbs);
244+
if (!forScreensaver) {
245+
m_screen->screensaver(false);
246+
}
244247
m_screen->enter(mask);
245248

246249
if (m_sendFileThread != NULL) {
@@ -509,9 +512,17 @@ Client::setupScreen()
509512
new TMethodEventJob<Client>(this,
510513
&Client::handleClipboardGrabbed));
511514
m_events->adoptHandler(m_events->forIScreen().localInput(),
512-
getEventTarget(),
513-
new TMethodEventJob<Client>(this,
514-
&Client::handleLocalInputEvent));
515+
getEventTarget(),
516+
new TMethodEventJob<Client>(this,
517+
&Client::handleLocalInputEvent));
518+
m_events->adoptHandler(m_events->forIPrimaryScreen().screensaverActivated(),
519+
getEventTarget(),
520+
new TMethodEventJob<Client>(this,
521+
&Client::handleScreensaverActivatedEvent));
522+
m_events->adoptHandler(m_events->forIPrimaryScreen().screensaverDeactivated(),
523+
getEventTarget(),
524+
new TMethodEventJob<Client>(this,
525+
&Client::handleScreensaverDeactivatedEvent));
515526
}
516527

517528
void
@@ -570,6 +581,11 @@ Client::cleanupScreen()
570581
getEventTarget());
571582
m_events->removeHandler(m_events->forIScreen().localInput(),
572583
getEventTarget());
584+
m_events->removeHandler(m_events->forIPrimaryScreen().screensaverActivated(),
585+
getEventTarget());
586+
m_events->removeHandler(m_events->forIPrimaryScreen().screensaverDeactivated(),
587+
getEventTarget());
588+
573589
delete m_server;
574590
m_server = NULL;
575591
}
@@ -745,6 +761,18 @@ Client::handleResume(const Event&, void*)
745761
}
746762
}
747763

764+
void
765+
Client::handleScreensaverActivatedEvent(const Event&, void*) {
766+
LOG((CLOG_DEBUG "Client received screensaver activate"));
767+
m_server->sendScreensaver(true);
768+
}
769+
770+
void
771+
Client::handleScreensaverDeactivatedEvent(const Event&, void*) {
772+
LOG((CLOG_DEBUG "Client received screensaver deactivate"));
773+
m_server->sendScreensaver(false);
774+
}
775+
748776
void
749777
Client::handleFileChunkSending(const Event& event, void*)
750778
{

src/lib/client/Client.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
* barrier -- mouse and keyboard sharing utility
33
* Copyright (C) 2012-2016 Symless Ltd.
44
* Copyright (C) 2002 Chris Schoeneman
5-
*
5+
*
66
* This package is free software; you can redistribute it and/or
77
* modify it under the terms of the GNU General Public License
88
* found in the file LICENSE that should have accompanied this file.
9-
*
9+
*
1010
* This package is distributed in the hope that it will be useful,
1111
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -90,11 +90,11 @@ class Client : public IClient, public INode {
9090

9191
//! Create a new thread and use it to send file to Server
9292
void sendFileToServer(const char* filename);
93-
93+
9494
//! Send dragging file information back to server
9595
void sendDragInfo(UInt32 fileCount, std::string& info, size_t size);
9696

97-
97+
9898
//@}
9999
//! @name accessors
100100
//@{
@@ -118,7 +118,7 @@ class Client : public IClient, public INode {
118118
to connect) to.
119119
*/
120120
NetworkAddress getServerAddress() const;
121-
121+
122122
//! Return true if recieved file size is valid
123123
bool isReceivedFileSizeValid();
124124

@@ -188,6 +188,8 @@ class Client : public IClient, public INode {
188188
void handleHello(const Event&, void*);
189189
void handleSuspend(const Event& event, void*);
190190
void handleResume(const Event& event, void*);
191+
void handleScreensaverActivatedEvent(const Event&, void*);
192+
void handleScreensaverDeactivatedEvent(const Event&, void*);
191193
void handleFileChunkSending(const Event&, void*);
192194
void handleFileRecieveCompleted(const Event&, void*);
193195
void handleStopRetry(const Event&, void*);

src/lib/client/ServerProxy.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ ServerProxy::parseMessage(const UInt8* code)
275275
}
276276

277277
else if (memcmp(code, kMsgCScreenSaver, 4) == 0) {
278-
screensaver();
278+
rcvScreensaver();
279279
}
280280

281281
else if (memcmp(code, kMsgQInfo, 4) == 0) {
@@ -524,11 +524,12 @@ void
524524
ServerProxy::enter()
525525
{
526526
// parse
527+
SInt8 forScreensaver;
527528
SInt16 x, y;
528529
UInt16 mask;
529530
UInt32 seqNum;
530-
ProtocolUtil::readf(m_stream, kMsgCEnter + 4, &x, &y, &seqNum, &mask);
531-
LOG((CLOG_DEBUG1 "recv enter, %d,%d %d %04x", x, y, seqNum, mask));
531+
ProtocolUtil::readf(m_stream, kMsgCEnter + 4, &x, &y, &seqNum, &mask, &forScreensaver);
532+
LOG((CLOG_DEBUG1 "recv enter, %d,%d %d %04x, forScreensaver=%d", x, y, seqNum, mask, forScreensaver));
532533

533534
// discard old compressed mouse motion, if any
534535
m_compressMouse = false;
@@ -538,7 +539,7 @@ ServerProxy::enter()
538539
m_seqNum = seqNum;
539540

540541
// forward
541-
m_client->enter(x, y, seqNum, static_cast<KeyModifierMask>(mask), false);
542+
m_client->enter(x, y, seqNum, static_cast<KeyModifierMask>(mask), forScreensaver != 0);
542543
}
543544

544545
void
@@ -777,7 +778,7 @@ ServerProxy::mouseWheel()
777778
}
778779

779780
void
780-
ServerProxy::screensaver()
781+
ServerProxy::rcvScreensaver()
781782
{
782783
// parse
783784
SInt8 on;
@@ -788,6 +789,12 @@ ServerProxy::screensaver()
788789
m_client->screensaver(on != 0);
789790
}
790791

792+
void
793+
ServerProxy::sendScreensaver(bool activate) {
794+
// Notify server about screensaver state of client
795+
ProtocolUtil::writef(m_stream, kMsgCScreenSaver, activate ? 1 : 0);
796+
}
797+
791798
void
792799
ServerProxy::resetOptions()
793800
{

src/lib/client/ServerProxy.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class ServerProxy {
6060
// sending dragging information to server
6161
void sendDragInfo(UInt32 fileCount, const char* info, size_t size);
6262

63+
// Send screensaver information to server
64+
void sendScreensaver(bool activate);
65+
6366
#ifdef TEST_ENV
6467
void handleDataForTest() { handleData(Event(), NULL); }
6568
#endif
@@ -99,7 +102,7 @@ class ServerProxy {
99102
void mouseMove();
100103
void mouseRelativeMove();
101104
void mouseWheel();
102-
void screensaver();
105+
void rcvScreensaver();
103106
void resetOptions();
104107
void setOptions();
105108
void queryInfo();

0 commit comments

Comments
 (0)