1 /*
2  * synergy -- mouse and keyboard sharing utility
3  * Copyright (C) 2012-2016 Symless Ltd.
4  * Copyright (C) 2002 Chris Schoeneman
5  *
6  * This package is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * found in the file LICENSE that should have accompanied this file.
9  *
10  * This package is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #include "synergy/DragInformation.h"
22 #include "synergy/clipboard_types.h"
23 #include "synergy/IScreen.h"
24 #include "synergy/IPrimaryScreen.h"
25 #include "synergy/ISecondaryScreen.h"
26 #include "synergy/IKeyState.h"
27 #include "synergy/option_types.h"
28 
29 class IClipboard;
30 
31 //! Screen interface
32 /*!
33 This interface defines the methods common to all platform dependent
34 screen implementations that are used by both primary and secondary
35 screens.
36 */
37 class IPlatformScreen : public IScreen,
38                 public IPrimaryScreen, public ISecondaryScreen,
39                 public IKeyState {
40 public:
41     //! @name manipulators
42     //@{
43 
IPlatformScreen(IEventQueue * events)44     IPlatformScreen(IEventQueue* events) : IKeyState(events) { }
45 
46     //! Enable screen
47     /*!
48     Enable the screen, preparing it to report system and user events.
49     For a secondary screen it also means preparing to synthesize events
50     and hiding the cursor.
51     */
52     virtual void        enable() = 0;
53 
54     //! Disable screen
55     /*!
56     Undoes the operations in enable() and events should no longer
57     be reported.
58     */
59     virtual void        disable() = 0;
60 
61     //! Enter screen
62     /*!
63     Called when the user navigates to this screen.
64     */
65     virtual void        enter() = 0;
66 
67     //! Leave screen
68     /*!
69     Called when the user navigates off the screen.  Returns true on
70     success, false on failure.  A typical reason for failure is being
71     unable to install the keyboard and mouse snoopers on a primary
72     screen.  Secondary screens should not fail.
73     */
74     virtual bool        leave() = 0;
75 
76     //! Set clipboard
77     /*!
78     Set the contents of the system clipboard indicated by \c id.
79     */
80     virtual bool        setClipboard(ClipboardID id, const IClipboard*) = 0;
81 
82     //! Check clipboard owner
83     /*!
84     Check ownership of all clipboards and post grab events for any that
85     have changed.  This is used as a backup in case the system doesn't
86     reliably report clipboard ownership changes.
87     */
88     virtual void        checkClipboards() = 0;
89 
90     //! Open screen saver
91     /*!
92     Open the screen saver.  If \c notify is true then this object must
93     send events when the screen saver activates or deactivates until
94     \c closeScreensaver() is called.  If \c notify is false then the
95     screen saver is disabled and restored on \c closeScreensaver().
96     */
97     virtual void        openScreensaver(bool notify) = 0;
98 
99     //! Close screen saver
100     /*!
101     // Close the screen saver.  Stop reporting screen saver activation
102     and deactivation and, if the screen saver was disabled by
103     openScreensaver(), enable the screen saver.
104     */
105     virtual void        closeScreensaver() = 0;
106 
107     //! Activate/deactivate screen saver
108     /*!
109     Forcibly activate the screen saver if \c activate is true otherwise
110     forcibly deactivate it.
111     */
112     virtual void        screensaver(bool activate) = 0;
113 
114     //! Notify of options changes
115     /*!
116     Reset all options to their default values.
117     */
118     virtual void        resetOptions() = 0;
119 
120     //! Notify of options changes
121     /*!
122     Set options to given values.  Ignore unknown options and don't
123     modify options that aren't given in \c options.
124     */
125     virtual void        setOptions(const OptionsList& options) = 0;
126 
127     //! Set clipboard sequence number
128     /*!
129     Sets the sequence number to use in subsequent clipboard events.
130     */
131     virtual void        setSequenceNumber(UInt32) = 0;
132 
133     //! Change dragging status
134     virtual void        setDraggingStarted(bool started) = 0;
135 
136     //@}
137     //! @name accessors
138     //@{
139 
140     //! Test if is primary screen
141     /*!
142     Return true iff this screen is a primary screen.
143     */
144     virtual bool        isPrimary() const = 0;
145 
146     //@}
147 
148     // IScreen overrides
149     virtual void*        getEventTarget() const = 0;
150     virtual bool        getClipboard(ClipboardID id, IClipboard*) const = 0;
151     virtual void        getShape(SInt32& x, SInt32& y,
152                             SInt32& width, SInt32& height) const = 0;
153     virtual void        getCursorPos(SInt32& x, SInt32& y) const = 0;
154 
155     // IPrimaryScreen overrides
156     virtual void        reconfigure(UInt32 activeSides) = 0;
157     virtual void        warpCursor(SInt32 x, SInt32 y) = 0;
158     virtual UInt32        registerHotKey(KeyID key, KeyModifierMask mask) = 0;
159     virtual void        unregisterHotKey(UInt32 id) = 0;
160     virtual void        fakeInputBegin() = 0;
161     virtual void        fakeInputEnd() = 0;
162     virtual SInt32        getJumpZoneSize() const = 0;
163     virtual bool        isAnyMouseButtonDown(UInt32& buttonID) const = 0;
164     virtual void        getCursorCenter(SInt32& x, SInt32& y) const = 0;
165 
166     // ISecondaryScreen overrides
167     virtual void        fakeMouseButton(ButtonID id, bool press) = 0;
168     virtual void        fakeMouseMove(SInt32 x, SInt32 y) = 0;
169     virtual void        fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const = 0;
170     virtual void        fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const = 0;
171 
172     // IKeyState overrides
173     virtual void        updateKeyMap() = 0;
174     virtual void        updateKeyState() = 0;
175     virtual void        setHalfDuplexMask(KeyModifierMask) = 0;
176     virtual void        fakeKeyDown(KeyID id, KeyModifierMask mask,
177                             KeyButton button) = 0;
178     virtual bool        fakeKeyRepeat(KeyID id, KeyModifierMask mask,
179                             SInt32 count, KeyButton button) = 0;
180     virtual bool        fakeKeyUp(KeyButton button) = 0;
181     virtual void        fakeAllKeysUp() = 0;
182     virtual bool        fakeCtrlAltDel() = 0;
183     virtual bool        fakeMediaKey(KeyID id);
184     virtual bool        isKeyDown(KeyButton) const = 0;
185     virtual KeyModifierMask
186                         getActiveModifiers() const = 0;
187     virtual KeyModifierMask
188                         pollActiveModifiers() const = 0;
189     virtual SInt32        pollActiveGroup() const = 0;
190     virtual void        pollPressedKeys(KeyButtonSet& pressedKeys) const = 0;
191 
192     virtual String&    getDraggingFilename() = 0;
193     virtual void        clearDraggingFilename() = 0;
194     virtual bool        isDraggingStarted() = 0;
195     virtual bool        isFakeDraggingStarted() = 0;
196 
197     virtual void        fakeDraggingFiles(DragFileList fileList) = 0;
198     virtual const String&
199                         getDropTarget() const = 0;
200 
201 protected:
202     //! Handle system event
203     /*!
204     A platform screen is expected to install a handler for system
205     events in its c'tor like so:
206     \code
207     m_events->adoptHandler(Event::kSystem,
208                           m_events->getSystemTarget(),
209                           new TMethodEventJob<CXXXPlatformScreen>(this,
210                               &CXXXPlatformScreen::handleSystemEvent));
211     \endcode
212     It should remove the handler in its d'tor.  Override the
213     \c handleSystemEvent() method to process system events.
214     It should post the events \c IScreen as appropriate.
215 
216     A primary screen has further responsibilities.  It should post
217     the events in \c IPrimaryScreen as appropriate.  It should also
218     call \c onKey() on its \c KeyState whenever a key is pressed
219     or released (but not for key repeats).  And it should call
220     \c updateKeyMap() on its \c KeyState if necessary when the keyboard
221     mapping changes.
222 
223     The target of all events should be the value returned by
224     \c getEventTarget().
225     */
226     virtual void        handleSystemEvent(const Event& event, void*) = 0;
227 };
228