blob: ef3dbb08ec82b3565a5bf11293de532c971b420d [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 Ossman0c9bd4b2014-07-09 16:44:11 +020065 // New image for the locally rendered cursor
Pierre Ossman835b4ef2011-06-08 17:02:36 +000066 void setCursor(int width, int height, const rfb::Point& hotspot,
Pierre Ossman6a1a0d02017-02-19 15:48:17 +010067 const rdr::U8* data);
Pierre Ossman835b4ef2011-06-08 17:02:36 +000068
Pierre Ossman2fa63f82016-12-05 15:26:21 +010069 // Change client LED state
70 void setLEDState(unsigned int state);
71
Pierre Ossman615d16b2019-05-03 10:53:06 +020072 // Clipboard events
73 void handleClipboardRequest();
74 void handleClipboardAnnounce(bool available);
75 void handleClipboardData(const char* data);
76
Pierre Ossman4ae229f2011-04-15 12:58:31 +000077 // Fl_Window callback methods
Pierre Ossmanda103432019-06-18 16:25:51 +020078 virtual void show();
Pierre Ossman01dd7af2019-06-18 16:26:57 +020079 virtual void draw();
80 virtual void resize(int x, int y, int w, int h);
Pierre Ossman4ae229f2011-04-15 12:58:31 +000081
Pierre Ossman01dd7af2019-06-18 16:26:57 +020082 virtual int handle(int event);
Pierre Ossman407a5c32011-05-26 14:48:29 +000083
Pierre Ossmanaae38912012-07-13 11:22:55 +000084 void fullscreen_on();
85
Pierre Ossman5156d5e2011-03-09 09:42:34 +000086private:
Pierre Ossman4f0647d2017-01-04 15:34:26 +010087 static void menuOverlay(void *data);
88
89 void setOverlay(const char *text, ...) __printf_attr(2, 3);
Pierre Ossman455566e2017-02-10 16:37:52 +010090 static void updateOverlay(void *data);
Pierre Ossman4f0647d2017-01-04 15:34:26 +010091
Pierre Ossmana4f0f182011-06-14 13:36:57 +000092 static int fltkHandle(int event, Fl_Window *win);
93
Pierre Ossman407a5c32011-05-26 14:48:29 +000094 void grabKeyboard();
95 void ungrabKeyboard();
Pierre Ossman7e546fe2017-09-18 16:05:48 +020096 void grabPointer();
97 void ungrabPointer();
Pierre Ossman407a5c32011-05-26 14:48:29 +000098
99 static void handleGrab(void *data);
100
Peter Åstrand49b11572012-08-01 08:09:09 +0000101 void maximizeWindow();
102
Pierre Ossman4c4b66f2012-08-23 14:53:36 +0000103 void handleDesktopSize();
Pierre Ossmanff473402012-07-04 11:27:47 +0000104 static void handleResizeTimeout(void *data);
Pierre Ossman4c4b66f2012-08-23 14:53:36 +0000105 void remoteResize(int width, int height);
Pierre Ossmanff473402012-07-04 11:27:47 +0000106
Pierre Ossman13548812017-01-03 16:12:30 +0100107 void repositionWidgets();
Pierre Ossman6455d852011-06-01 09:33:00 +0000108
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000109 static void handleClose(Fl_Widget *wnd, void *data);
110
Pierre Ossman407a5c32011-05-26 14:48:29 +0000111 static void handleOptions(void *data);
112
Pierre Ossman4c4b66f2012-08-23 14:53:36 +0000113 static void handleFullscreenTimeout(void *data);
114
Pierre Ossman13548812017-01-03 16:12:30 +0100115 void scrollTo(int x, int y);
116 static void handleScroll(Fl_Widget *wnd, void *data);
Pierre Ossman1d867b62012-09-03 09:25:07 +0000117 static void handleEdgeScroll(void *data);
118
Pierre Ossman921f6c82017-02-24 12:33:09 +0100119 static void handleStatsTimeout(void *data);
120
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000121private:
Pierre Ossmanff473402012-07-04 11:27:47 +0000122 CConn* cc;
Pierre Ossman13548812017-01-03 16:12:30 +0100123 Fl_Scrollbar *hscroll, *vscroll;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000124 Viewport *viewport;
Pierre Ossman3d74d882017-01-02 19:49:52 +0100125 Surface *offscreen;
Pierre Ossman4f0647d2017-01-04 15:34:26 +0100126 Surface *overlay;
Pierre Ossman455566e2017-02-10 16:37:52 +0100127 unsigned char overlayAlpha;
128 struct timeval overlayStart;
Pierre Ossmanff473402012-07-04 11:27:47 +0000129
130 bool firstUpdate;
Pierre Ossman4c4b66f2012-08-23 14:53:36 +0000131 bool delayedFullscreen;
132 bool delayedDesktopSize;
Pierre Ossman921f6c82017-02-24 12:33:09 +0100133
Pierre Ossman7e546fe2017-09-18 16:05:48 +0200134 bool keyboardGrabbed;
135 bool mouseGrabbed;
136
Pierre Ossman921f6c82017-02-24 12:33:09 +0100137 struct statsEntry {
Pierre Ossmanfecf0a42018-03-26 12:22:47 +0200138 unsigned ups;
Pierre Ossman921f6c82017-02-24 12:33:09 +0100139 unsigned pps;
140 unsigned bps;
141 };
142 struct statsEntry stats[100];
143
144 struct timeval statsLastTime;
Pierre Ossmanfecf0a42018-03-26 12:22:47 +0200145 unsigned statsLastUpdates;
Pierre Ossman921f6c82017-02-24 12:33:09 +0100146 unsigned statsLastPixels;
147 unsigned statsLastPosition;
148
149 Surface *statsGraph;
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000150};
151
152#endif