blob: fe5ef82a306a9e97ca47b6fe910a0c406aad1613 [file] [log] [blame]
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +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// DesktopWindow is a TXWindow representing a VNC desktop.
20//
21
22#ifndef __DESKTOPWINDOW_H__
23#define __DESKTOPWINDOW_H__
24
25#include <rfb/Cursor.h>
26#include <rfb/Rect.h>
27#include <rfb/Timer.h>
28#include "TXWindow.h"
29#include "TXViewport.h"
30#include "TXImage.h"
31
32class CConn;
33
34class DesktopWindow : public TXWindow, public TXEventHandler,
35 public rfb::Timer::Callback {
36public:
37
38 DesktopWindow(Display* dpy, int w, int h,
39 const rfb::PixelFormat& serverPF, CConn* cc_,
40 TXWindow* parent=0);
41 ~DesktopWindow();
42
43 void setViewport(TXViewport* viewport);
44
45 // getPF() and setPF() get and set the TXImage's pixel format
46 const rfb::PixelFormat& getPF() { return im->getPF(); }
47 void setPF(const rfb::PixelFormat& pf) { im->setPF(pf); }
48
49 // setCursor() sets the shape of the local cursor
50 void setCursor(int width, int height, const rfb::Point& hotspot,
51 void* data, void* mask);
52
53 // resetLocalCursor() stops the rendering of the local cursor
54 void resetLocalCursor();
55
56 // Methods forwarded from CConn
57 void setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs);
Adam Tkacacf6c6b2009-02-13 12:42:05 +000058 void serverCutText(const char* str, rdr::U32 len);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000059 void framebufferUpdateEnd();
60
61 void fillRect(const rfb::Rect& r, rfb::Pixel pix) {
62 if (r.overlaps(cursorBackingRect)) hideLocalCursor();
63 im->fillRect(r, pix);
64 im->put(win(), gc, r);
65 showLocalCursor();
66 }
67 void imageRect(const rfb::Rect& r, void* pixels) {
68 if (r.overlaps(cursorBackingRect)) hideLocalCursor();
69 im->imageRect(r, pixels);
70 im->put(win(), gc, r);
71 showLocalCursor();
72 }
73 void copyRect(const rfb::Rect& r, int srcX, int srcY) {
74 if (r.overlaps(cursorBackingRect) ||
75 cursorBackingRect.overlaps(rfb::Rect(srcX, srcY,
76 srcX+r.width(), srcY+r.height())))
77 hideLocalCursor();
78 if (im->usingShm())
79 XSync(dpy, False);
80 im->copyRect(r, rfb::Point(r.tl.x-srcX, r.tl.y-srcY));
81 XCopyArea(dpy, win(), win(), gc, srcX, srcY,
82 r.width(), r.height(), r.tl.x, r.tl.y);
83 showLocalCursor();
84 }
85 void invertRect(const rfb::Rect& r);
86
87 // TXWindow methods
88 virtual void resize(int w, int h);
89 virtual bool selectionRequest(Window requestor,
90 Atom selection, Atom property);
91 virtual void selectionNotify(XSelectionEvent* ev, Atom type, int format,
92 int nitems, void* data);
93 virtual void handleEvent(TXWindow* w, XEvent* ev);
94
95private:
96
97 void createXCursors();
98 void hideLocalCursor();
99 void showLocalCursor();
100 bool handleTimeout(rfb::Timer* timer);
101 void handlePointerEvent(const rfb::Point& pos, int buttonMask);
102
103 CConn* cc;
104 TXImage* im;
105 GC gc;
106 ::Cursor dotCursor, noCursor, localXCursor;
107
108 rfb::Cursor cursor;
109 bool cursorVisible; // Is cursor currently rendered?
110 bool cursorAvailable; // Is cursor available for rendering?
111 rfb::Point cursorPos;
112 rfb::ManagedPixelBuffer cursorBacking;
113 rfb::Rect cursorBackingRect;
114
115 Time currentSelectionTime;
116 Atom newSelection;
117 bool gettingInitialSelectionTime;
118 bool newServerCutText;
119 char* serverCutText_;
120
121 rfb::Timer setColourMapEntriesTimer;
122 TXViewport* viewport;
123 rfb::Timer pointerEventTimer;
124 rfb::Point lastPointerPos;
125 int lastButtonMask;
126 rdr::U32 downKeysym[256];
127};
128
129#endif