blob: 322fe3200e026a4815deb3ca4e1cda88c7fb76dc [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19/////////////////////////////////////////////////////////////////////////////
20
21// SDesktop is an interface implemented by back-ends, on which callbacks are
22// made by the VNCServer as appropriate for pointer and keyboard events, etc.
23// SDesktop objects are always created before the VNCServer - the SDesktop
24// will be passed a pointer to the VNCServer in the start() call. If a more
25// implementation-specific pointer to the VNCServer is required then this
26// can be provided to the SDesktop via an implementation-specific method.
27//
28// An SDesktop usually has an associated PixelBuffer which it tells the
29// VNCServer via the VNCServer's setPixelBuffer() method. It can do this at
30// any time, but the PixelBuffer MUST be valid by the time the call to start()
31// returns. The PixelBuffer may be set to null again if desired when stop() is
32// called. Note that start() and stop() are guaranteed to be called
33// alternately; there should never be two calls to start() without an
34// intervening stop() and vice-versa.
35//
36
37#ifndef __RFB_SDESKTOP_H__
38#define __RFB_SDESKTOP_H__
39
40#include <rfb/PixelBuffer.h>
41#include <rfb/VNCServer.h>
42#include <rfb/InputHandler.h>
43#include <rfb/Exception.h>
Pierre Ossman04e62db2009-03-23 16:57:07 +000044#include <rfb/screenTypes.h>
Steve Kondik0c81bbb2017-07-10 08:56:00 -070045#include <rfb/util.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000046
47namespace rfb {
48
49 class VNCServer;
50
51 class SDesktop : public InputHandler {
52 public:
53 // start() is called by the server when the first client authenticates
54 // successfully, and can be used to begin any expensive tasks which are not
55 // needed when there are no clients. A valid PixelBuffer must have been
56 // set via the VNCServer's setPixelBuffer() method by the time this call
57 // returns.
58
Steve Kondik0c81bbb2017-07-10 08:56:00 -070059 virtual void start(VNCServer* __unused_attr vs) {}
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000060
61 // stop() is called by the server when there are no longer any
62 // authenticated clients, and therefore the desktop can cease any
63 // expensive tasks. No further calls to the VNCServer passed to start()
64 // can be made once stop has returned.
65
66 virtual void stop() {}
67
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000068 // getFbSize() returns the current dimensions of the framebuffer.
69 // This can be called even while the SDesktop is not start()ed.
70
71 virtual Point getFbSize() = 0;
72
Pierre Ossman04e62db2009-03-23 16:57:07 +000073 // setScreenLayout() requests to reconfigure the framebuffer and/or
74 // the layout of screens.
Steve Kondik0c81bbb2017-07-10 08:56:00 -070075 virtual unsigned int setScreenLayout(int __unused_attr fb_width,
76 int __unused_attr fb_height,
77 const ScreenSet& __unused_attr layout) {
Pierre Ossman04e62db2009-03-23 16:57:07 +000078 return resultProhibited;
79 }
80
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000081 // InputHandler interface
82 // pointerEvent(), keyEvent() and clientCutText() are called in response to
83 // the relevant RFB protocol messages from clients.
84 // See InputHandler for method signatures.
85 protected:
86 virtual ~SDesktop() {}
87 };
88
89 // -=- SStaticDesktop
90 // Trivial implementation of the SDesktop interface, which provides
91 // dummy input handlers and event processing routine, and exports
92 // a plain black desktop of the specified format.
93 class SStaticDesktop : public SDesktop {
94 public:
95 SStaticDesktop(const Point& size) : server(0), buffer(0) {
96 PixelFormat pf;
Pierre Ossman56f99d62015-06-05 12:57:02 +020097 const rdr::U8 black[4] = { 0, 0, 0, 0 };
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000098 buffer = new ManagedPixelBuffer(pf, size.x, size.y);
Pierre Ossman56f99d62015-06-05 12:57:02 +020099 if (buffer)
100 buffer->fillRect(buffer->getRect(), black);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000101 }
102 SStaticDesktop(const Point& size, const PixelFormat& pf) : buffer(0) {
Pierre Ossman56f99d62015-06-05 12:57:02 +0200103 const rdr::U8 black[4] = { 0, 0, 0, 0 };
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000104 buffer = new ManagedPixelBuffer(pf, size.x, size.y);
Pierre Ossman56f99d62015-06-05 12:57:02 +0200105 if (buffer)
106 buffer->fillRect(buffer->getRect(), black);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000107 }
108 virtual ~SStaticDesktop() {
109 if (buffer) delete buffer;
110 }
111
112 virtual void start(VNCServer* vs) {
113 server = vs;
114 server->setPixelBuffer(buffer);
115 }
116 virtual void stop() {
117 server->setPixelBuffer(0);
118 server = 0;
119 }
120
121 protected:
122 VNCServer* server;
123 ManagedPixelBuffer* buffer;
124 };
125
126};
127
128#endif // __RFB_SDESKTOP_H__