Skip to content

Enhancement: X11 local input #841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/lib/barrier/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,9 @@ Screen::grabClipboard(ClipboardID id)
void
Screen::screensaver(bool activate)
{
if (!m_isPrimary) {
// activate/deactivation screen saver iff synchronization enabled
if (m_screenSaverSync) {
m_screen->screensaver(activate);
}
// activate/deactivation screen saver iff synchronization enabled
if (m_screenSaverSync) {
m_screen->screensaver(activate);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/lib/barrier/protocol_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* barrier -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* 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 LICENSE 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
Expand All @@ -29,6 +29,7 @@ const char* kMsgCScreenSaver = "CSEC%1i";
const char* kMsgCResetOptions = "CROP";
const char* kMsgCInfoAck = "CIAK";
const char* kMsgCKeepAlive = "CALV";
const char* kMsgCLocalInput = "CLIN%2i%2i";
const char* kMsgDKeyDown = "DKDN%2i%2i%2i";
const char* kMsgDKeyDown1_0 = "DKDN%2i%2i";
const char* kMsgDKeyRepeat = "DKRP%2i%2i%2i%2i";
Expand Down
23 changes: 19 additions & 4 deletions src/lib/barrier/protocol_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
// 1.4: adds crypto support
// 1.5: adds file transfer and removes home brew crypto
// 1.6: adds clipboard streaming
// 1.7: adds focus/screen switch on local input
// adds screensaver sync on client local input
// NOTE: with new version, barrier minor version should increment
static const SInt16 kProtocolMajorVersion = 1;
static const SInt16 kProtocolMinorVersion = 6;
static const SInt16 kProtocolMinorVersion = 7;

// default contact port number
static const UInt16 kDefaultPort = 24800;
Expand Down Expand Up @@ -129,9 +131,16 @@ extern const char* kMsgCClose;
// must return this number with some messages. $4 = modifier key
// mask. this will have bits set for each toggle modifier key
// that is activated on entry to the screen. the secondary screen
// should adjust its toggle modifiers to reflect that state.
// should adjust its toggle modifiers to reflect that state. $5 =
// forScreensaver flag which denotes whether the screen is only
// entered for screensaver management purposes or not and thus
// whether the client can change its screensaver state or should
// not change the screensaver state
extern const char* kMsgCEnter;

// enter screen 1.0: same as above but without respecting the screensaver state
extern const char* kMsgCEnter1_0;

// leave screen: primary -> secondary
// leaving screen. the secondary screen should send clipboard
// data in response to this message for those clipboards that
Expand All @@ -148,8 +157,10 @@ extern const char* kMsgCLeave;
// most recent kMsgCEnter. the primary always sends 0.
extern const char* kMsgCClipboard;

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

// reset options: primary -> secondary
Expand All @@ -172,6 +183,10 @@ extern const char* kMsgCInfoAck;
// defined by an option.
extern const char* kMsgCKeepAlive;

// Local input: secondary -> primary
// Inform primary about local input to request focus
extern const char* kMsgCLocalInput;

//
// data codes
//
Expand Down
1 change: 1 addition & 0 deletions src/lib/base/EventTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ REGISTER_EVENT(IPrimaryScreen, fakeInputEnd)

REGISTER_EVENT(IScreen, error)
REGISTER_EVENT(IScreen, shapeChanged)
REGISTER_EVENT(IScreen, localInput)
REGISTER_EVENT(IScreen, suspend)
REGISTER_EVENT(IScreen, resume)

Expand Down
10 changes: 10 additions & 0 deletions src/lib/base/EventTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ class IScreenEvents : public EventTypes {
IScreenEvents() :
m_error(Event::kUnknown),
m_shapeChanged(Event::kUnknown),
m_localInput(Event::kUnknown),
m_suspend(Event::kUnknown),
m_resume(Event::kUnknown) { }

Expand All @@ -671,6 +672,14 @@ class IScreenEvents : public EventTypes {
*/
Event::Type shapeChanged();

//! Get local input event type
/*!
Returns the local input event type. This is sent when the cursor
is not on the current screen but a local input is detected (e.g.
via touchscreen inputs or mouse movements).
*/
Event::Type localInput();

//! Get suspend event type
/*!
Returns the suspend event type. This is sent whenever the system goes
Expand All @@ -690,6 +699,7 @@ class IScreenEvents : public EventTypes {
private:
Event::Type m_error;
Event::Type m_shapeChanged;
Event::Type m_localInput;
Event::Type m_suspend;
Event::Type m_resume;
};
Expand Down
62 changes: 52 additions & 10 deletions src/lib/client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* barrier -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* 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 LICENSE 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
Expand Down Expand Up @@ -134,11 +134,11 @@ Client::connect()
// being shuttled between various networks). patch by Brent
// Priddy.
m_serverAddress.resolve();

// m_serverAddress will be null if the hostname address is not reolved
if (m_serverAddress.getAddress() != NULL) {
// to help users troubleshoot, show server host name (issue: 60)
LOG((CLOG_NOTE "connecting to '%s': %s:%i",
LOG((CLOG_NOTE "connecting to '%s': %s:%i",
m_serverAddress.getHostname().c_str(),
ARCH->addrToString(m_serverAddress.getAddress()).c_str(),
m_serverAddress.getPort()));
Expand Down Expand Up @@ -237,10 +237,13 @@ Client::getCursorPos(SInt32& x, SInt32& y) const
}

void
Client::enter(SInt32 xAbs, SInt32 yAbs, UInt32, KeyModifierMask mask, bool)
Client::enter(SInt32 xAbs, SInt32 yAbs, UInt32, KeyModifierMask mask, bool forScreensaver)
{
m_active = true;
m_screen->mouseMove(xAbs, yAbs);
if (!forScreensaver) {
m_screen->screensaver(false);
}
m_screen->enter(mask);

if (m_sendFileThread != NULL) {
Expand All @@ -255,7 +258,7 @@ Client::leave()
m_active = false;

m_screen->leave();

if (m_enableClipboard) {
// send clipboards that we own and that have changed
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
Expand All @@ -271,7 +274,7 @@ Client::leave()
void
Client::setClipboard(ClipboardID id, const IClipboard* clipboard)
{
m_screen->setClipboard(id, clipboard);
m_screen->setClipboard(id, clipboard);
m_ownClipboard[id] = false;
m_sentClipboard[id] = false;
}
Expand Down Expand Up @@ -508,6 +511,18 @@ Client::setupScreen()
getEventTarget(),
new TMethodEventJob<Client>(this,
&Client::handleClipboardGrabbed));
m_events->adoptHandler(m_events->forIScreen().localInput(),
getEventTarget(),
new TMethodEventJob<Client>(this,
&Client::handleLocalInputEvent));
m_events->adoptHandler(m_events->forIPrimaryScreen().screensaverActivated(),
getEventTarget(),
new TMethodEventJob<Client>(this,
&Client::handleScreensaverActivatedEvent));
m_events->adoptHandler(m_events->forIPrimaryScreen().screensaverDeactivated(),
getEventTarget(),
new TMethodEventJob<Client>(this,
&Client::handleScreensaverDeactivatedEvent));
}

void
Expand Down Expand Up @@ -564,6 +579,13 @@ Client::cleanupScreen()
getEventTarget());
m_events->removeHandler(m_events->forClipboard().clipboardGrabbed(),
getEventTarget());
m_events->removeHandler(m_events->forIScreen().localInput(),
getEventTarget());
m_events->removeHandler(m_events->forIPrimaryScreen().screensaverActivated(),
getEventTarget());
m_events->removeHandler(m_events->forIPrimaryScreen().screensaverDeactivated(),
getEventTarget());

delete m_server;
m_server = NULL;
}
Expand Down Expand Up @@ -739,6 +761,18 @@ Client::handleResume(const Event&, void*)
}
}

void
Client::handleScreensaverActivatedEvent(const Event&, void*) {
LOG((CLOG_DEBUG "Client received screensaver activate"));
m_server->sendScreensaver(true);
}

void
Client::handleScreensaverDeactivatedEvent(const Event&, void*) {
LOG((CLOG_DEBUG "Client received screensaver deactivate"));
m_server->sendScreensaver(false);
}

void
Client::handleFileChunkSending(const Event& event, void*)
{
Expand Down Expand Up @@ -767,6 +801,14 @@ Client::handleStopRetry(const Event&, void*)
m_args.m_restartable = false;
}

void
Client::handleLocalInputEvent(const Event& event, void*)
{
IPlatformScreen::MotionInfo* info = static_cast<IPlatformScreen::MotionInfo*>(event.getData());
LOG((CLOG_DEBUG "Trigger screen switching caused by local input, screen coordinates (%d, %d)", info->m_x, info->m_y));
m_server->onLocalInput(info->m_x, info->m_y);
}

void
Client::writeToDropDirThread(void*)
{
Expand All @@ -775,7 +817,7 @@ Client::writeToDropDirThread(void*)
while (m_screen->isFakeDraggingStarted()) {
ARCH->sleep(.1f);
}

DropHelper::writeToDir(m_screen->getDropTarget(), m_dragFileList,
m_receivedFileData);
}
Expand All @@ -790,7 +832,7 @@ Client::dragInfoReceived(UInt32 fileNum, std::string data)
}

DragInformation::parseDragInfo(m_dragFileList, fileNum, data);

m_screen->startDraggingFiles(m_dragFileList);
}

Expand All @@ -806,7 +848,7 @@ Client::sendFileToServer(const char* filename)
if (m_sendFileThread != NULL) {
StreamChunker::interruptFile();
}

m_sendFileThread = new Thread(
new TMethodJob<Client>(
this, &Client::sendFileThread,
Expand Down
3 changes: 3 additions & 0 deletions src/lib/client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,12 @@ class Client : public IClient, public INode {
void handleHello(const Event&, void*);
void handleSuspend(const Event& event, void*);
void handleResume(const Event& event, void*);
void handleScreensaverActivatedEvent(const Event&, void*);
void handleScreensaverDeactivatedEvent(const Event&, void*);
void handleFileChunkSending(const Event&, void*);
void handleFileRecieveCompleted(const Event&, void*);
void handleStopRetry(const Event&, void*);
void handleLocalInputEvent(const Event&, void*);
void onFileRecieveCompleted();
void sendClipboardThread(void*);

Expand Down
Loading