blob: 1390e4f417f4f28f294eda5b179128aaaa5f9cf0 [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 Ossman5156d5e2011-03-09 09:42:34 +000025#include <rfb/Rect.h>
Pierre Ossman947b48d2014-01-27 16:52:35 +010026#include <rfb/Pixel.h>
Pierre Ossmand50b3d12011-04-15 07:46:56 +000027
DRCb65bb932011-06-24 03:17:00 +000028#include <FL/Fl_Window.H>
29
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020030namespace rfb { class ModifiablePixelBuffer; }
31
Pierre Ossman5156d5e2011-03-09 09:42:34 +000032class CConn;
Pierre Ossman3d74d882017-01-02 19:49:52 +010033class Surface;
Pierre Ossman947b48d2014-01-27 16:52:35 +010034class Viewport;
35
Pierre Ossman13548812017-01-03 16:12:30 +010036class Fl_Scrollbar;
Pierre Ossman5156d5e2011-03-09 09:42:34 +000037
Pierre Ossman4f0647d2017-01-04 15:34:26 +010038#ifdef __GNUC__
39# define __printf_attr(a, b) __attribute__((__format__ (__printf__, a, b)))
40#else
41# define __printf_attr(a, b)
42#endif // __GNUC__
43
Pierre Ossman5156d5e2011-03-09 09:42:34 +000044class DesktopWindow : public Fl_Window {
45public:
46
47 DesktopWindow(int w, int h, const char *name,
48 const rfb::PixelFormat& serverPF, CConn* cc_);
49 ~DesktopWindow();
50
Pierre Ossman5156d5e2011-03-09 09:42:34 +000051 // Most efficient format (from DesktopWindow's point of view)
52 const rfb::PixelFormat &getPreferredPF();
53
Pierre Ossman5156d5e2011-03-09 09:42:34 +000054 // Flush updates to screen
55 void updateWindow();
56
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020057 // Updated session title
Pierre Ossman5156d5e2011-03-09 09:42:34 +000058 void setName(const char *name);
59
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020060 // Resize the current framebuffer, but retain the contents
Pierre Ossman6455d852011-06-01 09:33:00 +000061 void resizeFramebuffer(int new_w, int new_h);
62
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020063 // New image for the locally rendered cursor
Pierre Ossman835b4ef2011-06-08 17:02:36 +000064 void setCursor(int width, int height, const rfb::Point& hotspot,
65 void* data, void* mask);
66
Pierre Ossman4ae229f2011-04-15 12:58:31 +000067 // Fl_Window callback methods
Pierre Ossman13548812017-01-03 16:12:30 +010068 void draw();
Pierre Ossman4ae229f2011-04-15 12:58:31 +000069 void resize(int x, int y, int w, int h);
70
Pierre Ossman407a5c32011-05-26 14:48:29 +000071 int handle(int event);
72
Pierre Ossmanaae38912012-07-13 11:22:55 +000073 void fullscreen_on();
74
Pierre Ossman5156d5e2011-03-09 09:42:34 +000075private:
Pierre Ossman4f0647d2017-01-04 15:34:26 +010076 static void menuOverlay(void *data);
77
78 void setOverlay(const char *text, ...) __printf_attr(2, 3);
79 static void clearOverlay(void *data);
80
Pierre Ossmana4f0f182011-06-14 13:36:57 +000081 static int fltkHandle(int event, Fl_Window *win);
82
Pierre Ossman407a5c32011-05-26 14:48:29 +000083 void grabKeyboard();
84 void ungrabKeyboard();
85
86 static void handleGrab(void *data);
87
Peter Åstrand49b11572012-08-01 08:09:09 +000088 void maximizeWindow();
89
Pierre Ossman4c4b66f2012-08-23 14:53:36 +000090 void handleDesktopSize();
Pierre Ossmanff473402012-07-04 11:27:47 +000091 static void handleResizeTimeout(void *data);
Pierre Ossman4c4b66f2012-08-23 14:53:36 +000092 void remoteResize(int width, int height);
Pierre Ossmanff473402012-07-04 11:27:47 +000093
Pierre Ossman13548812017-01-03 16:12:30 +010094 void repositionWidgets();
Pierre Ossman6455d852011-06-01 09:33:00 +000095
Pierre Ossman5156d5e2011-03-09 09:42:34 +000096 static void handleClose(Fl_Widget *wnd, void *data);
97
Pierre Ossman407a5c32011-05-26 14:48:29 +000098 static void handleOptions(void *data);
99
Pierre Ossman4c4b66f2012-08-23 14:53:36 +0000100 static void handleFullscreenTimeout(void *data);
101
Pierre Ossman13548812017-01-03 16:12:30 +0100102 void scrollTo(int x, int y);
103 static void handleScroll(Fl_Widget *wnd, void *data);
Pierre Ossman1d867b62012-09-03 09:25:07 +0000104 static void handleEdgeScroll(void *data);
105
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000106private:
Pierre Ossmanff473402012-07-04 11:27:47 +0000107 CConn* cc;
Pierre Ossman13548812017-01-03 16:12:30 +0100108 Fl_Scrollbar *hscroll, *vscroll;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000109 Viewport *viewport;
Pierre Ossman3d74d882017-01-02 19:49:52 +0100110 Surface *offscreen;
Pierre Ossman4f0647d2017-01-04 15:34:26 +0100111 Surface *overlay;
Pierre Ossmanff473402012-07-04 11:27:47 +0000112
113 bool firstUpdate;
Pierre Ossman4c4b66f2012-08-23 14:53:36 +0000114 bool delayedFullscreen;
115 bool delayedDesktopSize;
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000116};
117
118#endif