Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 1 | /* 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 Ossman | 9760ff6 | 2009-03-25 10:32:07 +0000 | [diff] [blame^] | 27 | #include <rfb/Region.h> |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 28 | #include <rfb/Timer.h> |
| 29 | #include "TXWindow.h" |
| 30 | #include "TXViewport.h" |
| 31 | #include "TXImage.h" |
| 32 | |
| 33 | class CConn; |
| 34 | |
| 35 | class DesktopWindow : public TXWindow, public TXEventHandler, |
| 36 | public rfb::Timer::Callback { |
| 37 | public: |
| 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 Tkac | acf6c6b | 2009-02-13 12:42:05 +0000 | [diff] [blame] | 59 | void serverCutText(const char* str, rdr::U32 len); |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 60 | 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 Ossman | 9760ff6 | 2009-03-25 10:32:07 +0000 | [diff] [blame^] | 65 | damageRect(r); |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 66 | showLocalCursor(); |
| 67 | } |
| 68 | void imageRect(const rfb::Rect& r, void* pixels) { |
| 69 | if (r.overlaps(cursorBackingRect)) hideLocalCursor(); |
| 70 | im->imageRect(r, pixels); |
Pierre Ossman | 9760ff6 | 2009-03-25 10:32:07 +0000 | [diff] [blame^] | 71 | damageRect(r); |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 72 | 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 Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 79 | im->copyRect(r, rfb::Point(r.tl.x-srcX, r.tl.y-srcY)); |
Pierre Ossman | 9760ff6 | 2009-03-25 10:32:07 +0000 | [diff] [blame^] | 80 | damageRect(r); |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 81 | 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 | |
| 93 | private: |
| 94 | |
| 95 | void createXCursors(); |
| 96 | void hideLocalCursor(); |
| 97 | void showLocalCursor(); |
Pierre Ossman | 9760ff6 | 2009-03-25 10:32:07 +0000 | [diff] [blame^] | 98 | 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 Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 104 | 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 Ossman | 9760ff6 | 2009-03-25 10:32:07 +0000 | [diff] [blame^] | 110 | rfb::Region damage; |
| 111 | rfb::Timer updateTimer; |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 112 | ::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 |