blob: 433ac33b55ff9df78011ed8e7e8b8324ea7d586e [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"
32
33class CConn;
34
35class DesktopWindow : public TXWindow, public TXEventHandler,
36 public rfb::Timer::Callback {
37public:
38
39 DesktopWindow(Display* dpy, int w, int h,
40 const rfb::PixelFormat& serverPF, CConn* cc_,
41 TXWindow* parent=0);
42 ~DesktopWindow();
43
44 void setViewport(TXViewport* viewport);
45
46 // getPF() and setPF() get and set the TXImage's pixel format
47 const rfb::PixelFormat& getPF() { return im->getPF(); }
48 void setPF(const rfb::PixelFormat& pf) { im->setPF(pf); }
49
50 // setCursor() sets the shape of the local cursor
51 void setCursor(int width, int height, const rfb::Point& hotspot,
52 void* data, void* mask);
53
54 // resetLocalCursor() stops the rendering of the local cursor
55 void resetLocalCursor();
56
57 // Methods forwarded from CConn
58 void setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs);
Adam Tkacacf6c6b2009-02-13 12:42:05 +000059 void serverCutText(const char* str, rdr::U32 len);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000060 void framebufferUpdateEnd();
61
62 void fillRect(const rfb::Rect& r, rfb::Pixel pix) {
63 if (r.overlaps(cursorBackingRect)) hideLocalCursor();
64 im->fillRect(r, pix);
Pierre Ossman9760ff62009-03-25 10:32:07 +000065 damageRect(r);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000066 showLocalCursor();
67 }
68 void imageRect(const rfb::Rect& r, void* pixels) {
69 if (r.overlaps(cursorBackingRect)) hideLocalCursor();
70 im->imageRect(r, pixels);
Pierre Ossman9760ff62009-03-25 10:32:07 +000071 damageRect(r);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000072 showLocalCursor();
73 }
74 void copyRect(const rfb::Rect& r, int srcX, int srcY) {
75 if (r.overlaps(cursorBackingRect) ||
76 cursorBackingRect.overlaps(rfb::Rect(srcX, srcY,
77 srcX+r.width(), srcY+r.height())))
78 hideLocalCursor();
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000079 im->copyRect(r, rfb::Point(r.tl.x-srcX, r.tl.y-srcY));
Pierre Ossman9760ff62009-03-25 10:32:07 +000080 damageRect(r);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000081 showLocalCursor();
82 }
83 void invertRect(const rfb::Rect& r);
84
85 // TXWindow methods
86 virtual void resize(int w, int h);
87 virtual bool selectionRequest(Window requestor,
88 Atom selection, Atom property);
89 virtual void selectionNotify(XSelectionEvent* ev, Atom type, int format,
90 int nitems, void* data);
91 virtual void handleEvent(TXWindow* w, XEvent* ev);
92
93private:
94
95 void createXCursors();
96 void hideLocalCursor();
97 void showLocalCursor();
Pierre Ossman9760ff62009-03-25 10:32:07 +000098 void damageRect(const rfb::Rect& r) {
99 damage.assign_union(rfb::Region(r));
100 if (!updateTimer.isStarted())
101 updateTimer.start(100);
102 };
103 void updateWindow();
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000104 bool handleTimeout(rfb::Timer* timer);
105 void handlePointerEvent(const rfb::Point& pos, int buttonMask);
106
107 CConn* cc;
108 TXImage* im;
109 GC gc;
Pierre Ossman9760ff62009-03-25 10:32:07 +0000110 rfb::Region damage;
111 rfb::Timer updateTimer;
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000112 ::Cursor dotCursor, noCursor, localXCursor;
113
114 rfb::Cursor cursor;
115 bool cursorVisible; // Is cursor currently rendered?
116 bool cursorAvailable; // Is cursor available for rendering?
117 rfb::Point cursorPos;
118 rfb::ManagedPixelBuffer cursorBacking;
119 rfb::Rect cursorBackingRect;
120
121 Time currentSelectionTime;
122 Atom newSelection;
123 bool gettingInitialSelectionTime;
124 bool newServerCutText;
125 char* serverCutText_;
126
127 rfb::Timer setColourMapEntriesTimer;
128 TXViewport* viewport;
129 rfb::Timer pointerEventTimer;
130 rfb::Point lastPointerPos;
131 int lastButtonMask;
132 rdr::U32 downKeysym[256];
133};
134
135#endif