blob: 880acc212c2dd7f5e0992cabf5aea852a9c1c2fd [file] [log] [blame]
Constantin Kaplinsky95f6f7a2006-04-17 04:17:23 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 *
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00003 * 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// XserverDesktop.h
20//
21
22#ifndef __XSERVERDESKTOP_H__
23#define __XSERVERDESKTOP_H__
24
25#include <rfb/SDesktop.h>
Constantin Kaplinsky95f6f7a2006-04-17 04:17:23 +000026#include <rfb/HTTPServer.h>
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000027#include <rfb/PixelBuffer.h>
28#include <rfb/Configuration.h>
Constantin Kaplinsky95f6f7a2006-04-17 04:17:23 +000029#include <rfb/VNCServerST.h>
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000030#include <rdr/SubstitutingInStream.h>
31
32extern "C" {
33#define class c_class;
34#include <scrnintstr.h>
35#include <os.h>
36#undef class
37}
38
39namespace rfb {
40 class VNCServerST;
41}
42
43namespace network { class TcpListener; class Socket; }
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000044
45class XserverDesktop : public rfb::SDesktop, public rfb::FullFramePixelBuffer,
Constantin Kaplinsky95f6f7a2006-04-17 04:17:23 +000046 public rfb::ColourMap, public rdr::Substitutor,
47 public rfb::VNCServerST::QueryConnectionHandler {
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000048public:
49
50 XserverDesktop(ScreenPtr pScreen, network::TcpListener* listener,
51 network::TcpListener* httpListener_,
52 const char* name, void* fbptr);
53 virtual ~XserverDesktop();
54
55 // methods called from X server code
56 void serverReset(ScreenPtr pScreen);
57 void setColormap(ColormapPtr cmap);
58 void setColourMapEntries(ColormapPtr pColormap, int ndef, xColorItem* pdef);
59 void bell();
60 void serverCutText(const char* str, int len);
61 void setCursor(CursorPtr cursor);
62 void add_changed(RegionPtr reg);
63 void add_copied(RegionPtr dst, int dx, int dy);
64 void positionCursor();
65 void ignoreHooks(bool b) { ignoreHooks_ = b; }
66 void blockHandler(fd_set* fds);
67 void wakeupHandler(fd_set* fds, int nfds);
68 void addClient(network::Socket* sock, bool reverse);
69 void disconnectClients();
70
Constantin Kaplinsky95f6f7a2006-04-17 04:17:23 +000071 // QueryConnect methods called from X server code
72 // getQueryTimeout()
73 // Returns the timeout associated with a particular
74 // connection, identified by an opaque Id passed to the
75 // X code earlier. Also optionally gets the address and
76 // name associated with that connection.
77 // Returns zero if the Id is not recognised.
78 int getQueryTimeout(void* opaqueId,
79 const char** address=0,
80 const char** username=0);
81
82 // approveConnection()
83 // Used by X server code to supply the result of a query.
84 void approveConnection(void* opaqueId, bool accept,
85 const char* rejectMsg=0);
86
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000087 // rfb::SDesktop callbacks
Constantin Kaplinsky95f6f7a2006-04-17 04:17:23 +000088 virtual void pointerEvent(const rfb::Point& pos, int buttonMask);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000089 virtual void keyEvent(rdr::U32 key, bool down);
90 virtual void clientCutText(const char* str, int len);
91 virtual rfb::Point getFbSize() { return rfb::Point(width(), height()); }
92
93 // rfb::PixelBuffer callbacks
94 virtual void grabRegion(const rfb::Region& r);
95
96 // rfb::ColourMap callbacks
97 virtual void lookup(int index, int* r, int* g, int* b);
98
99 // rdr::Substitutor callback
100 virtual char* substitute(const char* varName);
101
Constantin Kaplinsky95f6f7a2006-04-17 04:17:23 +0000102 // rfb::VNCServerST::QueryConnectionHandler callback
103 virtual rfb::VNCServerST::queryResult queryConnection(network::Socket* sock,
104 const char* userName,
105 char** reason);
106
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000107private:
108 void setColourMapEntries(int firstColour, int nColours);
109 static CARD32 deferredUpdateTimerCallback(OsTimerPtr timer, CARD32 now,
110 pointer arg);
Constantin Kaplinsky95f6f7a2006-04-17 04:17:23 +0000111 void deferUpdate();
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000112 ScreenPtr pScreen;
113 OsTimerPtr deferredUpdateTimer, dummyTimer;
114 rfb::VNCServerST* server;
Constantin Kaplinsky95f6f7a2006-04-17 04:17:23 +0000115 rfb::HTTPServer* httpServer;
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000116 network::TcpListener* listener;
117 network::TcpListener* httpListener;
118 ColormapPtr cmap;
119 bool deferredUpdateTimerSet;
120 bool grabbing;
121 bool ignoreHooks_;
122 bool directFbptr;
123 int oldButtonMask;
Constantin Kaplinsky95f6f7a2006-04-17 04:17:23 +0000124 rfb::Point cursorPos, oldCursorPos;
125
126 void* queryConnectId;
127 rfb::CharArray queryConnectAddress;
128 rfb::CharArray queryConnectUsername;
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000129};
130#endif