Skip to content
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

Allow changing screens from non-rectangular multi-monitor setups #1626

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
12 changes: 12 additions & 0 deletions src/lib/barrier/Display.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <Carbon/Carbon.h>
/**
* Platform-independent display.
*/
class Display {
public:
UInt32 displayId;
SInt32 x;
SInt32 y;
SInt32 width;
SInt32 height;
};
3 changes: 3 additions & 0 deletions src/lib/barrier/IScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "base/Event.h"
#include "base/EventTypes.h"
#include "common/IInterface.h"
#include "Display.h"

class IClipboard;

Expand Down Expand Up @@ -67,5 +68,7 @@ class IScreen : public IInterface {
*/
virtual void getCursorPos(SInt32& x, SInt32& y) const = 0;

virtual std::vector<Display*> getDisplays() const = 0;

//@}
};
6 changes: 3 additions & 3 deletions src/lib/barrier/PlatformScreen.h
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) 2004 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 @@ -97,7 +97,7 @@ class PlatformScreen : public IPlatformScreen {
virtual void setOptions(const OptionsList& options) = 0;
virtual void setSequenceNumber(UInt32) = 0;
virtual bool isPrimary() const = 0;

virtual void fakeDraggingFiles(DragFileList fileList) { throw std::runtime_error("fakeDraggingFiles not implemented"); }
virtual const String&
getDropTarget() const { throw std::runtime_error("getDropTarget not implemented"); }
Expand Down
5 changes: 5 additions & 0 deletions src/lib/barrier/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,4 +562,9 @@ Screen::leaveSecondary()
m_screen->fakeAllKeysUp();
}

std::vector<Display*>
Screen::getDisplays() const {
return m_screen->getDisplays();
}

}
1 change: 1 addition & 0 deletions src/lib/barrier/Screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ class Screen : public IScreen {
virtual void getShape(SInt32& x, SInt32& y,
SInt32& width, SInt32& height) const;
virtual void getCursorPos(SInt32& x, SInt32& y) const;
virtual std::vector<Display*> getDisplays() const;

IPlatformScreen* getPlatformScreen() { return m_screen; }

Expand Down
6 changes: 6 additions & 0 deletions src/lib/client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ Client::getShape(SInt32& x, SInt32& y, SInt32& w, SInt32& h) const
m_screen->getShape(x, y, w, h);
}

std::vector<Display*>
Client::getDisplays() const
{
// TODO(vjpr):
}

void
Client::getCursorPos(SInt32& x, SInt32& y) const
{
Expand Down
1 change: 1 addition & 0 deletions src/lib/client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class Client : public IClient, public INode {
virtual void getShape(SInt32& x, SInt32& y,
SInt32& width, SInt32& height) const;
virtual void getCursorPos(SInt32& x, SInt32& y) const;
virtual std::vector<Display*> getDisplays() const;

// IClient overrides
virtual void enter(SInt32 xAbs, SInt32 yAbs,
Expand Down
5 changes: 5 additions & 0 deletions src/lib/platform/OSXScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "base/EventTypes.h"
#include "common/stdmap.h"
#include "common/stdvector.h"
#import "barrier/Display.h"

#include <bitset>
#include <Carbon/Carbon.h>
Expand Down Expand Up @@ -53,6 +54,9 @@ class Mutex;
//! Implementation of IPlatformScreen for OS X
class OSXScreen : public PlatformScreen {
public:
// TODO(vjpr): make private.
std::vector<Display*> m_displays;

OSXScreen(IEventQueue* events, bool isPrimary, bool autoShowHideCursor=true);
virtual ~OSXScreen();

Expand All @@ -64,6 +68,7 @@ class OSXScreen : public PlatformScreen {
virtual void getShape(SInt32& x, SInt32& y,
SInt32& width, SInt32& height) const;
virtual void getCursorPos(SInt32& x, SInt32& y) const;
virtual std::vector<Display*> getDisplays() const;

// IPrimaryScreen overrides
virtual void reconfigure(UInt32 activeSides);
Expand Down
23 changes: 23 additions & 0 deletions src/lib/platform/OSXScreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "base/Log.h"
#include "base/IEventQueue.h"
#include "base/TMethodEventJob.h"
#import "barrier/Display.h"

#include <math.h>
#include <mach-o/dyld.h>
Expand Down Expand Up @@ -244,6 +245,11 @@
h = m_h;
}

std::vector<Display*>
OSXScreen::getDisplays() const {
return m_displays;
}

void
OSXScreen::getCursorPos(SInt32& x, SInt32& y) const
{
Expand All @@ -270,6 +276,7 @@
CGPoint pos;
pos.x = x;
pos.y = y;
// NOTE: If y is invalid, it sets it to 0.
CGWarpMouseCursorPosition(pos);

// save new cursor position
Expand Down Expand Up @@ -1546,6 +1553,21 @@
return;
}

// save displays as generic displays.
for (CGDisplayCount i = 0; i < displayCount; ++i) {
CGRect bounds = CGDisplayBounds(displays[i]);
Display* display = new Display{
// TODO(vjpr): Display numbers are simply the enumeration order. This is not stable between reboots I don't think.
i,
// --
(SInt32)bounds.origin.x,
(SInt32)bounds.origin.y,
(SInt32)bounds.size.width,
(SInt32)bounds.size.height};
m_displays.push_back(display);
}


// get smallest rect enclosing all display rects
CGRect totalBounds = CGRectZero;
for (CGDisplayCount i = 0; i < displayCount; ++i) {
Expand All @@ -1566,6 +1588,7 @@
m_yCenter = (rect.origin.y + rect.size.height) / 2;

delete[] displays;

// We want to notify the peer screen whether we are primary screen or not
sendEvent(m_events->forIScreen().shapeChanged());

Expand Down
1 change: 1 addition & 0 deletions src/lib/server/BaseClientProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class BaseClientProxy : public IClient {
virtual bool getClipboard(ClipboardID id, IClipboard*) const = 0;
virtual void getShape(SInt32& x, SInt32& y,
SInt32& width, SInt32& height) const = 0;
virtual std::vector<Display*> getDisplays() const = 0;
virtual void getCursorPos(SInt32& x, SInt32& y) const = 0;

// IClient overrides
Expand Down
9 changes: 9 additions & 0 deletions src/lib/server/ClientProxy1_0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,12 @@ ClientProxy1_0::ClientClipboard::ClientClipboard() :
{
// do nothing
}

std::vector<Display*>
ClientProxy1_0::getDisplays() const {

// TODO(vjpr):
std::vector<Display*> vec;
return vec;

}
1 change: 1 addition & 0 deletions src/lib/server/ClientProxy1_0.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ClientProxy1_0 : public ClientProxy {
virtual void getShape(SInt32& x, SInt32& y,
SInt32& width, SInt32& height) const;
virtual void getCursorPos(SInt32& x, SInt32& y) const;
virtual std::vector<Display*> getDisplays() const;

// IClient overrides
virtual void enter(SInt32 xAbs, SInt32 yAbs,
Expand Down
8 changes: 8 additions & 0 deletions src/lib/server/ClientProxy1_6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,11 @@ ClientProxy1_6::recvClipboard()

return true;
}

std::vector<Display*> getDisplays() {

// TODO(vjpr):
std::vector<Display*> vec;
return vec;

}
1 change: 1 addition & 0 deletions src/lib/server/ClientProxy1_6.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ClientProxy1_6 : public ClientProxy1_5 {

virtual void setClipboard(ClipboardID id, const IClipboard* clipboard);
virtual bool recvClipboard();
//virtual std::vector<Display*> getDisplays();

private:
void handleClipboardSendingEvent(const Event&, void*);
Expand Down
12 changes: 12 additions & 0 deletions src/lib/server/PrimaryClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "barrier/Screen.h"
#include "barrier/Clipboard.h"
#include "base/Log.h"
#include "platform/OSXScreen.h"

//
// PrimaryClient
Expand Down Expand Up @@ -272,3 +273,14 @@ PrimaryClient::setOptions(const OptionsList& options)
{
m_screen->setOptions(options);
}

std::vector<Display*>
PrimaryClient::getDisplays() const {

// TODO(vjpr): Only works for osx!
IPlatformScreen* screen = m_screen->getPlatformScreen();
OSXScreen* platformScreen = dynamic_cast<OSXScreen*>(screen);
std::vector<Display*> displays = platformScreen->m_displays;
return displays;

}
1 change: 1 addition & 0 deletions src/lib/server/PrimaryClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class PrimaryClient : public BaseClientProxy {
virtual void getShape(SInt32& x, SInt32& y,
SInt32& width, SInt32& height) const;
virtual void getCursorPos(SInt32& x, SInt32& y) const;
virtual std::vector<Display*> getDisplays() const;

// IClient overrides
virtual void enter(SInt32 xAbs, SInt32 yAbs,
Expand Down
Loading