blob: 97a8178db2b6e5c079e7d1ed13df80f5149cbb91 [file] [log] [blame]
Pierre Ossman5156d5e2011-03-09 09:42:34 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 * Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB
3 *
4 * This is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this software; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 * USA.
18 */
19
20#ifndef __DESKTOPWINDOW_H__
21#define __DESKTOPWINDOW_H__
22
Pierre Ossmand7c5b042011-04-14 14:05:13 +000023#include <map>
24
Pierre Ossman921f6c82017-02-24 12:33:09 +010025#include <sys/time.h>
26
Pierre Ossman5156d5e2011-03-09 09:42:34 +000027#include <rfb/Rect.h>
Pierre Ossman947b48d2014-01-27 16:52:35 +010028#include <rfb/Pixel.h>
Pierre Ossmand50b3d12011-04-15 07:46:56 +000029
DRCb65bb932011-06-24 03:17:00 +000030#include <FL/Fl_Window.H>
31
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020032namespace rfb { class ModifiablePixelBuffer; }
33
Pierre Ossman5156d5e2011-03-09 09:42:34 +000034class CConn;
Pierre Ossman3d74d882017-01-02 19:49:52 +010035class Surface;
Pierre Ossman947b48d2014-01-27 16:52:35 +010036class Viewport;
37
Pierre Ossman13548812017-01-03 16:12:30 +010038class Fl_Scrollbar;
Pierre Ossman5156d5e2011-03-09 09:42:34 +000039
Pierre Ossman4f0647d2017-01-04 15:34:26 +010040#ifdef __GNUC__
41# define __printf_attr(a, b) __attribute__((__format__ (__printf__, a, b)))
42#else
43# define __printf_attr(a, b)
44#endif // __GNUC__
45
Pierre Ossman5156d5e2011-03-09 09:42:34 +000046class DesktopWindow : public Fl_Window {
47public:
48
49 DesktopWindow(int w, int h, const char *name,
50 const rfb::PixelFormat& serverPF, CConn* cc_);
51 ~DesktopWindow();
52
Pierre Ossman5156d5e2011-03-09 09:42:34 +000053 // Most efficient format (from DesktopWindow's point of view)
54 const rfb::PixelFormat &getPreferredPF();
55
Pierre Ossman5156d5e2011-03-09 09:42:34 +000056 // Flush updates to screen
57 void updateWindow();
58
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020059 // Updated session title
Pierre Ossman5156d5e2011-03-09 09:42:34 +000060 void setName(const char *name);
61
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020062 // Resize the current framebuffer, but retain the contents
Pierre Ossman6455d852011-06-01 09:33:00 +000063 void resizeFramebuffer(int new_w, int new_h);
64
Pierre Ossman4c204232018-03-26 13:32:49 +020065 // Incoming clipboard from server
66 void serverCutText(const char* str, rdr::U32 len);
67
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020068 // New image for the locally rendered cursor
Pierre Ossman835b4ef2011-06-08 17:02:36 +000069 void setCursor(int width, int height, const rfb::Point& hotspot,
Pierre Ossman6a1a0d02017-02-19 15:48:17 +010070 const rdr::U8* data);
Pierre Ossman835b4ef2011-06-08 17:02:36 +000071
Pierre Ossman2fa63f82016-12-05 15:26:21 +010072 // Change client LED state
73 void setLEDState(unsigned int state);
74
Pierre Ossman4ae229f2011-04-15 12:58:31 +000075 // Fl_Window callback methods
Pierre Ossmanda103432019-06-18 16:25:51 +020076 virtual void show();
Pierre Ossman01dd7af2019-06-18 16:26:57 +020077 virtual void draw();
78 virtual void resize(int x, int y, int w, int h);
Pierre Ossman4ae229f2011-04-15 12:58:31 +000079
Pierre Ossman01dd7af2019-06-18 16:26:57 +020080 virtual int handle(int event);
Pierre Ossman407a5c32011-05-26 14:48:29 +000081
Pierre Ossmanaae38912012-07-13 11:22:55 +000082 void fullscreen_on();
83
Pierre Ossman5156d5e2011-03-09 09:42:34 +000084private:
Pierre Ossman4f0647d2017-01-04 15:34:26 +010085 static void menuOverlay(void *data);
86
87 void setOverlay(const char *text, ...) __printf_attr(2, 3);
Pierre Ossman455566e2017-02-10 16:37:52 +010088 static void updateOverlay(void *data);
Pierre Ossman4f0647d2017-01-04 15:34:26 +010089
Pierre Ossmana4f0f182011-06-14 13:36:57 +000090 static int fltkHandle(int event, Fl_Window *win);
91
Pierre Ossman407a5c32011-05-26 14:48:29 +000092 void grabKeyboard();
93 void ungrabKeyboard();
Pierre Ossman7e546fe2017-09-18 16:05:48 +020094 void grabPointer();
95 void ungrabPointer();
Pierre Ossman407a5c32011-05-26 14:48:29 +000096
97 static void handleGrab(void *data);
98
Peter Åstrand49b11572012-08-01 08:09:09 +000099 void maximizeWindow();
100
Pierre Ossman4c4b66f2012-08-23 14:53:36 +0000101 void handleDesktopSize();
Pierre Ossmanff473402012-07-04 11:27:47 +0000102 static void handleResizeTimeout(void *data);
Pierre Ossman4c4b66f2012-08-23 14:53:36 +0000103 void remoteResize(int width, int height);
Pierre Ossmanff473402012-07-04 11:27:47 +0000104
Pierre Ossman13548812017-01-03 16:12:30 +0100105 void repositionWidgets();
Pierre Ossman6455d852011-06-01 09:33:00 +0000106
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000107 static void handleClose(Fl_Widget *wnd, void *data);
108
Pierre Ossman407a5c32011-05-26 14:48:29 +0000109 static void handleOptions(void *data);
110
Pierre Ossman4c4b66f2012-08-23 14:53:36 +0000111 static void handleFullscreenTimeout(void *data);
112
Pierre Ossman13548812017-01-03 16:12:30 +0100113 void scrollTo(int x, int y);
114 static void handleScroll(Fl_Widget *wnd, void *data);
Pierre Ossman1d867b62012-09-03 09:25:07 +0000115 static void handleEdgeScroll(void *data);
116
Pierre Ossman921f6c82017-02-24 12:33:09 +0100117 static void handleStatsTimeout(void *data);
118
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000119private:
Pierre Ossmanff473402012-07-04 11:27:47 +0000120 CConn* cc;
Pierre Ossman13548812017-01-03 16:12:30 +0100121 Fl_Scrollbar *hscroll, *vscroll;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000122 Viewport *viewport;
Pierre Ossman3d74d882017-01-02 19:49:52 +0100123 Surface *offscreen;
Pierre Ossman4f0647d2017-01-04 15:34:26 +0100124 Surface *overlay;
Pierre Ossman455566e2017-02-10 16:37:52 +0100125 unsigned char overlayAlpha;
126 struct timeval overlayStart;
Pierre Ossmanff473402012-07-04 11:27:47 +0000127
128 bool firstUpdate;
Pierre Ossman4c4b66f2012-08-23 14:53:36 +0000129 bool delayedFullscreen;
130 bool delayedDesktopSize;
Pierre Ossman921f6c82017-02-24 12:33:09 +0100131
Pierre Ossman7e546fe2017-09-18 16:05:48 +0200132 bool keyboardGrabbed;
133 bool mouseGrabbed;
134
Pierre Ossman921f6c82017-02-24 12:33:09 +0100135 struct statsEntry {
Pierre Ossmanfecf0a42018-03-26 12:22:47 +0200136 unsigned ups;
Pierre Ossman921f6c82017-02-24 12:33:09 +0100137 unsigned pps;
138 unsigned bps;
139 };
140 struct statsEntry stats[100];
141
142 struct timeval statsLastTime;
Pierre Ossmanfecf0a42018-03-26 12:22:47 +0200143 unsigned statsLastUpdates;
Pierre Ossman921f6c82017-02-24 12:33:09 +0100144 unsigned statsLastPixels;
145 unsigned statsLastPosition;
146
147 Surface *statsGraph;
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000148};
149
150#endif