deskflow/src/lib/platform/XWindowsScreen.h

267 lines
8.9 KiB
C
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* synergy -- mouse and keyboard sharing utility
2016-09-07 14:24:00 +00:00
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2002 Chris Schoeneman
2012-06-10 16:50:54 +00:00
*
* 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.
2012-06-10 16:50:54 +00:00
*
* 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "arch/Arch.h"
#include "synergy/PlatformScreen.h"
#include "synergy/KeyMap.h"
#include "common/stdset.h"
#include "common/stdvector.h"
2012-06-10 16:50:54 +00:00
#if X_DISPLAY_MISSING
# error X11 is required to build synergy
2012-06-10 16:50:54 +00:00
#else
# include <X11/Xlib.h>
2012-06-10 16:50:54 +00:00
#endif
2014-11-12 11:28:41 +00:00
class XWindowsClipboard;
class XWindowsKeyState;
class XWindowsScreenSaver;
2012-06-10 16:50:54 +00:00
//! Implementation of IPlatformScreen for X11
2014-11-12 11:28:41 +00:00
class XWindowsScreen : public PlatformScreen {
2012-06-10 16:50:54 +00:00
public:
XWindowsScreen(const char* displayName, bool isPrimary,
bool disableXInitThreads, int mouseScrollDelta,
IEventQueue* events);
virtual ~XWindowsScreen();
//! @name manipulators
//@{
//@}
// IScreen overrides
virtual void* getEventTarget() const;
virtual bool getClipboard(ClipboardID id, IClipboard*) const;
virtual void getShape(SInt32& x, SInt32& y,
SInt32& width, SInt32& height) const;
virtual void getCursorPos(SInt32& x, SInt32& y) const;
// IPrimaryScreen overrides
virtual void reconfigure(UInt32 activeSides);
virtual void warpCursor(SInt32 x, SInt32 y);
virtual UInt32 registerHotKey(KeyID key, KeyModifierMask mask);
virtual void unregisterHotKey(UInt32 id);
virtual void fakeInputBegin();
virtual void fakeInputEnd();
virtual SInt32 getJumpZoneSize() const;
virtual bool isAnyMouseButtonDown(UInt32& buttonID) const;
virtual void getCursorCenter(SInt32& x, SInt32& y) const;
// ISecondaryScreen overrides
virtual void fakeMouseButton(ButtonID id, bool press);
virtual void fakeMouseMove(SInt32 x, SInt32 y);
virtual void fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const;
virtual void fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const;
// IPlatformScreen overrides
virtual void enable();
virtual void disable();
virtual void enter();
virtual bool leave();
virtual bool setClipboard(ClipboardID, const IClipboard*);
virtual void checkClipboards();
virtual void openScreensaver(bool notify);
virtual void closeScreensaver();
virtual void screensaver(bool activate);
virtual void resetOptions();
virtual void setOptions(const OptionsList& options);
virtual void setSequenceNumber(UInt32);
virtual bool isPrimary() const;
SYNERGY-1032 - Send secure input notifications to client (#7043) * SYNERGY-1017 - Try usnig NSUserNotification * SYNERGY-1032 - Use UNUserNotificationCenter instead of deprecated notifications * SYNERGY-1032 - Update app delegate and add log after notification access * SYNERGY-1032 - Try using deprecated notification * SYNERGY-1032 - Add notifications to the platform dependant code * SYNERGY-1032 - Check for development builds before asking permission for notifications * SYNERGY-1032 - Remove old notification and secure input detection * SYNERGY-1032 - Add permission request to the main app * SYNERGY-1032 - Only show notifications on server * SYNERGY-1032 - Request and show notification from main app * SYNERGY-1032 - Remove logging from OSX helpers * SYNERGY-1032 - Add UN notification for testing * SYNERGY-1032 - Show notification once * SYNERGY-1032 - Try replicating old flow * SYNERGY-1032 - Reuse notification center * SYNERGY-1032 - Send notification after granting permission * SYNERGY-1032 - Update app delegate * SYNERGY-1032 - Remove deprecated property * SYNERGY-1032 - Add output for debugging * SYNERGY-1032 - Try updating delegate * SYNERGY-1032 - Print current bundle name * SYNERGY-1032 - Add AppDelegate to the server * SYNERGY-1032 - Move notification creation to synergy app * SYNERGY-1032 - Update notification text * SYNERGY-1032 - Fix QString conversion for notification * SYNERGY-1032 - Move notification creation outside the handler * SYNERGY-1032 - Remove debug notification, show notification with no delay * SYNERGY-1032 - Show notification inside the completion handler * SYNERGY-1032 - Remove timed notification trigger * SYNERGY-1032 - Request permissions on synergy start * SYNERGY-1032 - Remove unused includes * SYNERGY-1032 - Update changelog * SYNERGY-1032 - Add empty notification implementations for Windows and Linux * SYNERGY-1032 - Removed temporary debug messages * SYNERGY-1032 - Resolve code smell * SYNERGY-1032 - Add base code for handling sending secure input notification * SYNERGY-1032 - Compile on Mac * SYNERGY-1032 - Allow client downgrade for 1.7 down to 1.6 * SYNERGY-1032 - Add utility to show notifications. Update secure input message format * SYNERGY-1032 - Update notification util on Mac * SYNERGY-1032 - Don't disconnect on invalid message from client * SYNERGY-1032 - Remove unused code * SYNERGY-1032 - Update changelog * SYNERGY-1032 - Update secure input notification message * SYNERGY-1032 - Better formatting for debug comments * SYNERGY-1032 - Resolve code smells * SYNERGY-1032 - Resolve more code smells * SYNERGY-1032 - Revert log level change * SYNERGY-1032 - Resolve merge error
2021-06-29 15:45:15 +00:00
String getSecureInputApp() const override;
2012-06-10 16:50:54 +00:00
void updateScrollDirection() override;
2012-06-10 16:50:54 +00:00
protected:
// IPlatformScreen overrides
virtual void handleSystemEvent(const Event&, void*);
virtual void updateButtons();
virtual IKeyState* getKeyState() const;
2012-06-10 16:50:54 +00:00
private:
// event sending
void sendEvent(Event::Type, void* = NULL);
void sendClipboardEvent(Event::Type, ClipboardID);
2012-06-10 16:50:54 +00:00
// create the transparent cursor
Cursor createBlankCursor() const;
2012-06-10 16:50:54 +00:00
// determine the clipboard from the X selection. returns
// kClipboardEnd if no such clipboard.
ClipboardID getClipboardID(Atom selection) const;
2012-06-10 16:50:54 +00:00
// continue processing a selection request
void processClipboardRequest(Window window,
Time time, Atom property);
2012-06-10 16:50:54 +00:00
// terminate a selection request
void destroyClipboardRequest(Window window);
2012-06-10 16:50:54 +00:00
// X I/O error handler
void onError();
static int ioErrorHandler(Display*);
2012-06-10 16:50:54 +00:00
// sleep management
static bool sleepInhibitCall(bool state, ArchSystemUnix::InhibitScreenServices serviceID);
static bool disableIdleSleep();
static bool enableIdleSleep();
2012-06-10 16:50:54 +00:00
private:
class KeyEventFilter {
public:
int m_event;
Window m_window;
Time m_time;
KeyCode m_keycode;
};
Display* openDisplay(const char* displayName);
void saveShape();
void setShape(SInt32 width, SInt32 height);
Window openWindow() const;
void openIM();
bool grabMouseAndKeyboard();
void onKeyPress(XKeyEvent&);
void onKeyRelease(XKeyEvent&, bool isRepeat);
bool onHotKey(XKeyEvent&, bool isRepeat);
void onMousePress(const XButtonEvent&);
void onMouseRelease(const XButtonEvent&);
void onMouseMove(const XMotionEvent&);
bool detectXI2();
#ifdef HAVE_XI2
void selectXIRawMotion();
#endif
void selectEvents(Window) const;
void doSelectEvents(Window) const;
KeyID mapKeyFromX(XKeyEvent*) const;
ButtonID mapButtonFromX(const XButtonEvent*) const;
unsigned int mapButtonToX(ButtonID id) const;
2012-06-10 16:50:54 +00:00
void warpCursorNoFlush(SInt32 x, SInt32 y);
2012-06-10 16:50:54 +00:00
void refreshKeyboard(XEvent*);
2012-06-10 16:50:54 +00:00
static Bool findKeyEvent(Display*, XEvent* xevent, XPointer arg);
2012-06-10 16:50:54 +00:00
private:
struct HotKeyItem {
public:
HotKeyItem(int, unsigned int);
bool operator<(const HotKeyItem&) const;
private:
int m_keycode;
unsigned int m_mask;
};
typedef std::set<bool> FilteredKeycodes;
typedef std::vector<std::pair<int, unsigned int> > HotKeyList;
typedef std::map<UInt32, HotKeyList> HotKeyMap;
typedef std::vector<UInt32> HotKeyIDList;
typedef std::map<HotKeyItem, UInt32> HotKeyToIDMap;
// true if screen is being used as a primary screen, false otherwise
bool m_isPrimary;
int m_mouseScrollDelta;
Display* m_display;
Window m_root;
Window m_window;
// true if mouse has entered the screen
bool m_isOnScreen;
// screen shape stuff
SInt32 m_x, m_y;
SInt32 m_w, m_h;
SInt32 m_xCenter, m_yCenter;
// last mouse position
SInt32 m_xCursor, m_yCursor;
// keyboard stuff
XWindowsKeyState* m_keyState;
// hot key stuff
HotKeyMap m_hotKeys;
HotKeyIDList m_oldHotKeyIDs;
HotKeyToIDMap m_hotKeyToIDMap;
// input focus stuff
Window m_lastFocus;
int m_lastFocusRevert;
// input method stuff
XIM m_im;
XIC m_ic;
KeyCode m_lastKeycode;
FilteredKeycodes m_filtered;
// clipboards
XWindowsClipboard* m_clipboard[kClipboardEnd];
UInt32 m_sequenceNumber;
// screen saver stuff
XWindowsScreenSaver* m_screensaver;
bool m_screensaverNotify;
// logical to physical button mapping. m_buttons[i] gives the
// physical button for logical button i+1.
std::vector<unsigned char> m_buttons;
// true if global auto-repeat was enabled before we turned it off
bool m_autoRepeat;
// stuff to workaround xtest being xinerama unaware. attempting
// to fake a mouse motion under xinerama may behave strangely,
// especially if screen 0 is not at 0,0 or if faking a motion on
// a screen other than screen 0.
bool m_xtestIsXineramaUnaware;
bool m_xinerama;
// stuff to work around lost focus issues on certain systems
// (ie: a MythTV front-end).
bool m_preserveFocus;
// XKB extension stuff
bool m_xkb;
int m_xkbEventBase;
bool m_xi2detected;
// XRandR extension stuff
bool m_xrandr;
int m_xrandrEventBase;
IEventQueue* m_events;
synergy::KeyMap m_keyMap;
// pointer to (singleton) screen. this is only needed by
// ioErrorHandler().
static XWindowsScreen* s_screen;
// -1 for natural scrolling direction, 1 otherwise
SInt32 m_scrollDirectionMouse = 1;
SInt32 m_scrollDirectionTouchpad = 1;
2012-06-10 16:50:54 +00:00
};