blob: eb8d59dc436060a537c2b3f227adee0ebb898ee2 [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>
Pierre Ossman9760ff62009-03-25 10:32:07 +000027#include <rfb/Region.h>
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000028#include <rfb/Timer.h>
29#include "TXWindow.h"
30#include "TXViewport.h"
31#include "TXImage.h"
Adam Tkac20fcb972009-10-07 15:11:08 +000032#include "parameters.h"
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000033
34class CConn;
35
36class DesktopWindow : public TXWindow, public TXEventHandler,
37 public rfb::Timer::Callback {
38public:
39
40 DesktopWindow(Display* dpy, int w, int h,
41 const rfb::PixelFormat& serverPF, CConn* cc_,
42 TXWindow* parent=0);
43 ~DesktopWindow();
44
45 void setViewport(TXViewport* viewport);
46
47 // getPF() and setPF() get and set the TXImage's pixel format
48 const rfb::PixelFormat& getPF() { return im->getPF(); }
49 void setPF(const rfb::PixelFormat& pf) { im->setPF(pf); }
50
51 // setCursor() sets the shape of the local cursor
52 void setCursor(int width, int height, const rfb::Point& hotspot,
53 void* data, void* mask);
54
55 // resetLocalCursor() stops the rendering of the local cursor
56 void resetLocalCursor();
57
Adam Tkac20fcb972009-10-07 15:11:08 +000058 // setNoCursor() sets what to display when no cursor is defined - if dot or
59 // nothing.
60 inline void setNoCursor() {
61 XDefineCursor(dpy, win(), dotWhenNoCursor ? dotCursor : noCursor);
62 }
63
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000064 // Methods forwarded from CConn
65 void setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs);
Adam Tkacacf6c6b2009-02-13 12:42:05 +000066 void serverCutText(const char* str, rdr::U32 len);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000067 void framebufferUpdateEnd();
68
69 void fillRect(const rfb::Rect& r, rfb::Pixel pix) {
70 if (r.overlaps(cursorBackingRect)) hideLocalCursor();
71 im->fillRect(r, pix);
Pierre Ossman9760ff62009-03-25 10:32:07 +000072 damageRect(r);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000073 showLocalCursor();
74 }
75 void imageRect(const rfb::Rect& r, void* pixels) {
76 if (r.overlaps(cursorBackingRect)) hideLocalCursor();
77 im->imageRect(r, pixels);
Pierre Ossman9760ff62009-03-25 10:32:07 +000078 damageRect(r);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000079 showLocalCursor();
80 }
81 void copyRect(const rfb::Rect& r, int srcX, int srcY) {
82 if (r.overlaps(cursorBackingRect) ||
83 cursorBackingRect.overlaps(rfb::Rect(srcX, srcY,
84 srcX+r.width(), srcY+r.height())))
85 hideLocalCursor();
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000086 im->copyRect(r, rfb::Point(r.tl.x-srcX, r.tl.y-srcY));
Pierre Ossman9760ff62009-03-25 10:32:07 +000087 damageRect(r);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000088 showLocalCursor();
89 }
90 void invertRect(const rfb::Rect& r);
91
92 // TXWindow methods
93 virtual void resize(int w, int h);
94 virtual bool selectionRequest(Window requestor,
95 Atom selection, Atom property);
96 virtual void selectionNotify(XSelectionEvent* ev, Atom type, int format,
97 int nitems, void* data);
98 virtual void handleEvent(TXWindow* w, XEvent* ev);
99
100private:
101
102 void createXCursors();
103 void hideLocalCursor();
104 void showLocalCursor();
Pierre Ossman9760ff62009-03-25 10:32:07 +0000105 void damageRect(const rfb::Rect& r) {
106 damage.assign_union(rfb::Region(r));
107 if (!updateTimer.isStarted())
108 updateTimer.start(100);
109 };
110 void updateWindow();
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000111 bool handleTimeout(rfb::Timer* timer);
112 void handlePointerEvent(const rfb::Point& pos, int buttonMask);
113
114 CConn* cc;
115 TXImage* im;
116 GC gc;
Pierre Ossman9760ff62009-03-25 10:32:07 +0000117 rfb::Region damage;
118 rfb::Timer updateTimer;
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000119 ::Cursor dotCursor, noCursor, localXCursor;
120
121 rfb::Cursor cursor;
122 bool cursorVisible; // Is cursor currently rendered?
123 bool cursorAvailable; // Is cursor available for rendering?
124 rfb::Point cursorPos;
125 rfb::ManagedPixelBuffer cursorBacking;
126 rfb::Rect cursorBackingRect;
127
128 Time currentSelectionTime;
129 Atom newSelection;
130 bool gettingInitialSelectionTime;
131 bool newServerCutText;
132 char* serverCutText_;
133
134 rfb::Timer setColourMapEntriesTimer;
135 TXViewport* viewport;
136 rfb::Timer pointerEventTimer;
137 rfb::Point lastPointerPos;
138 int lastButtonMask;
139 rdr::U32 downKeysym[256];
140};
141
142#endif