blob: 0f627229b40c17ab31e5ebb58fb8b7de01bfe192 [file] [log] [blame]
Pierre Ossmand50b3d12011-04-15 07:46:56 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
Pierre Ossmanff9eb5a2014-01-30 17:47:31 +01002 * Copyright 2011-2014 Pierre Ossman for Cendio AB
Pierre Ossmand50b3d12011-04-15 07:46:56 +00003 *
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
Peter Åstrandc359f362011-08-23 12:04:46 +000020#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
Pierre Ossmand50b3d12011-04-15 07:46:56 +000024#include <assert.h>
25#include <stdio.h>
26#include <string.h>
27
Pierre Ossmand50b3d12011-04-15 07:46:56 +000028#include <rfb/CMsgWriter.h>
29#include <rfb/LogWriter.h>
30
31// FLTK can pull in the X11 headers on some systems
32#ifndef XK_VoidSymbol
Pierre Ossman13a809a2014-08-22 15:09:54 +020033#define XK_LATIN1
Pierre Ossmand50b3d12011-04-15 07:46:56 +000034#define XK_MISCELLANY
35#define XK_XKB_KEYS
36#include <rfb/keysymdef.h>
37#endif
38
Pierre Ossmancb0cffe2011-05-20 14:55:10 +000039#ifndef XF86XK_ModeLock
40#include <rfb/XF86keysym.h>
41#endif
42
Pierre Ossman7b8bff62014-07-21 16:17:23 +020043#ifndef NoSymbol
44#define NoSymbol 0
45#endif
46
Pierre Ossmand50b3d12011-04-15 07:46:56 +000047#include "Viewport.h"
48#include "CConn.h"
Pierre Ossmand463b572011-05-16 12:04:43 +000049#include "OptionsDialog.h"
Pierre Ossman947b48d2014-01-27 16:52:35 +010050#include "DesktopWindow.h"
Pierre Ossmand50b3d12011-04-15 07:46:56 +000051#include "i18n.h"
Pierre Ossmanc628ba42011-05-23 12:21:21 +000052#include "fltk_layout.h"
Pierre Ossmand50b3d12011-04-15 07:46:56 +000053#include "parameters.h"
54#include "keysym2ucs.h"
Martin Koegler498ef462011-09-04 07:04:43 +000055#include "menukey.h"
Pierre Ossman39ceb502011-07-12 15:54:25 +000056#include "vncviewer.h"
Pierre Ossmand50b3d12011-04-15 07:46:56 +000057
Pierre Ossmanac13abe2014-02-07 14:46:26 +010058#include "PlatformPixelBuffer.h"
59#include "FLTKPixelBuffer.h"
60
Pierre Ossman947b48d2014-01-27 16:52:35 +010061#if defined(WIN32)
62#include "Win32PixelBuffer.h"
63#elif defined(__APPLE__)
64#include "OSXPixelBuffer.h"
65#else
66#include "X11PixelBuffer.h"
67#endif
68
DRCb65bb932011-06-24 03:17:00 +000069#include <FL/fl_draw.H>
70#include <FL/fl_ask.H>
71
Pierre Ossman769963f2014-01-20 14:43:52 +010072#include <FL/Fl_Menu.H>
73#include <FL/Fl_Menu_Button.H>
74
DRCb65bb932011-06-24 03:17:00 +000075#ifdef WIN32
76#include "win32.h"
77#endif
78
Pierre Ossmand50b3d12011-04-15 07:46:56 +000079using namespace rfb;
Pierre Ossman835b4ef2011-06-08 17:02:36 +000080using namespace rdr;
Pierre Ossmand50b3d12011-04-15 07:46:56 +000081
Pierre Ossmand50b3d12011-04-15 07:46:56 +000082static rfb::LogWriter vlog("Viewport");
83
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +000084// Menu constants
85
Pierre Ossman8dc8bca2012-07-04 11:37:10 +000086enum { ID_EXIT, ID_FULLSCREEN, ID_RESIZE,
87 ID_CTRL, ID_ALT, ID_MENUKEY, ID_CTRLALTDEL,
Pierre Ossman2eb1d112011-05-16 12:18:08 +000088 ID_REFRESH, ID_OPTIONS, ID_INFO, ID_ABOUT, ID_DISMISS };
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +000089
Pierre Ossman25188c42014-07-21 16:30:08 +020090// Fake key presses use this value and above
91static const int fakeKeyBase = 0x200;
92
Pierre Ossmand50b3d12011-04-15 07:46:56 +000093Viewport::Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_)
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020094 : Fl_Widget(0, 0, w, h), cc(cc_), frameBuffer(NULL),
Pierre Ossmanb6b4dc62014-01-20 15:05:21 +010095 lastPointerPos(0, 0), lastButtonMask(0),
Henrik Andersson3a848322011-09-14 08:33:15 +000096 cursor(NULL), menuCtrlKey(false), menuAltKey(false)
Pierre Ossmand50b3d12011-04-15 07:46:56 +000097{
Pierre Ossman4a6be4a2011-05-19 14:49:18 +000098// FLTK STR #2636 gives us the ability to monitor clipboard changes
99#ifdef HAVE_FLTK_CLIPBOARD
100 Fl::add_clipboard_notify(handleClipboardChange, this);
101#endif
102
Pierre Ossman4f3ac692014-08-22 15:10:22 +0200103#ifdef HAVE_FLTK_XHANDLERS
104 // We need to intercept keyboard events early
105 Fl::add_xhandler(handleXEvent, this);
106#endif
107
Pierre Ossmanac13abe2014-02-07 14:46:26 +0100108 frameBuffer = createFramebuffer(w, h);
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000109 assert(frameBuffer);
110
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000111 contextMenu = new Fl_Menu_Button(0, 0, 0, 0);
Pierre Ossmanad9d1ae2011-05-26 14:16:02 +0000112 // Setting box type to FL_NO_BOX prevents it from trying to draw the
113 // button component (which we don't want)
114 contextMenu->box(FL_NO_BOX);
115
Pierre Ossmanb043ad12011-06-01 09:26:57 +0000116 // The (invisible) button associated with this widget can mess with
117 // things like Fl_Scroll so we need to get rid of any parents.
118 // Unfortunately that's not possible because of STR #2654, but
119 // reparenting to the current window works for most cases.
120 window()->add(contextMenu);
121
Pierre Ossman4e7271e2011-05-24 12:47:12 +0000122 setMenuKey();
123
124 OptionsDialog::addCallback(handleOptions, this);
Pierre Ossmande673132011-11-10 14:59:24 +0000125
126 // Send a fake pointer event so that the server will stop rendering
127 // a server-side cursor. Ideally we'd like to send the actual pointer
128 // position, but we can't really tell when the window manager is done
129 // placing us so we don't have a good time for that.
130 handlePointerEvent(Point(w/2, h/2), 0);
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000131}
132
133
134Viewport::~Viewport()
135{
136 // Unregister all timeouts in case they get a change tro trigger
137 // again later when this object is already gone.
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000138 Fl::remove_timeout(handlePointerTimeout, this);
139
Pierre Ossman4f3ac692014-08-22 15:10:22 +0200140#ifdef HAVE_FLTK_XHANDLERS
141 Fl::remove_xhandler(handleXEvent);
142#endif
143
Pierre Ossman4a6be4a2011-05-19 14:49:18 +0000144#ifdef HAVE_FLTK_CLIPBOARD
145 Fl::remove_clipboard_notify(handleClipboardChange);
146#endif
147
Pierre Ossman4e7271e2011-05-24 12:47:12 +0000148 OptionsDialog::removeCallback(handleOptions);
149
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000150 delete frameBuffer;
151
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000152 if (cursor) {
Pierre Ossmanf741d342011-06-09 08:32:49 +0000153 if (!cursor->alloc_array)
154 delete [] cursor->array;
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000155 delete cursor;
156 }
157
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000158 // FLTK automatically deletes all child widgets, so we shouldn't touch
159 // them ourselves here
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000160}
161
162
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000163const rfb::PixelFormat &Viewport::getPreferredPF()
164{
Pierre Ossman132b3d02011-06-13 11:19:32 +0000165 return frameBuffer->getPF();
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000166}
167
168
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000169// Copy the areas of the framebuffer that have been changed (damaged)
170// to the displayed window.
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +0200171// FIXME: Make sure this gets called on slow updates
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000172
173void Viewport::updateWindow()
174{
175 Rect r;
176
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +0200177 r = frameBuffer->getDamage();
178 damage(FL_DAMAGE_USER1, r.tl.x + x(), r.tl.y + y(), r.width(), r.height());
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000179}
180
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +0200181rfb::ModifiablePixelBuffer* Viewport::getFramebuffer(void)
182{
183 return frameBuffer;
Pierre Ossman947b48d2014-01-27 16:52:35 +0100184}
185
Pierre Ossmanf741d342011-06-09 08:32:49 +0000186#ifdef HAVE_FLTK_CURSOR
187static const char * dotcursor_xpm[] = {
188 "5 5 2 1",
189 ". c #000000",
190 " c #FFFFFF",
191 " ",
192 " ... ",
193 " ... ",
194 " ... ",
195 " "};
196#endif
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000197
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000198void Viewport::setCursor(int width, int height, const Point& hotspot,
199 void* data, void* mask)
200{
201#ifdef HAVE_FLTK_CURSOR
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000202 if (cursor) {
Pierre Ossmanf741d342011-06-09 08:32:49 +0000203 if (!cursor->alloc_array)
204 delete [] cursor->array;
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000205 delete cursor;
206 }
207
Pierre Ossmanf741d342011-06-09 08:32:49 +0000208 int mask_len = ((width+7)/8) * height;
209 int i;
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000210
Pierre Ossmanf741d342011-06-09 08:32:49 +0000211 for (i = 0; i < mask_len; i++)
212 if (((rdr::U8*)mask)[i]) break;
213
Pierre Ossmana51574a2011-06-09 08:39:35 +0000214 if ((i == mask_len) && dotWhenNoCursor) {
215 vlog.debug("cursor is empty - using dot");
Pierre Ossmanf741d342011-06-09 08:32:49 +0000216
217 Fl_Pixmap pxm(dotcursor_xpm);
218 cursor = new Fl_RGB_Image(&pxm);
219 cursorHotspot.x = cursorHotspot.y = 2;
220 } else {
Pierre Ossman17a48f02011-06-09 08:42:04 +0000221 if ((width == 0) || (height == 0)) {
222 U8 *buffer = new U8[4];
223 memset(buffer, 0, 4);
224 cursor = new Fl_RGB_Image(buffer, 1, 1, 4);
225 cursorHotspot.x = cursorHotspot.y = 0;
226 } else {
227 U8 *buffer = new U8[width*height*4];
228 U8 *i, *o, *m;
229 int m_width;
Pierre Ossmanf741d342011-06-09 08:32:49 +0000230
Pierre Ossmand8f84872011-07-15 08:26:51 +0000231 const PixelFormat *pf;
232
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +0200233 pf = &cc->cp.pf();
Pierre Ossmanf741d342011-06-09 08:32:49 +0000234
Pierre Ossman17a48f02011-06-09 08:42:04 +0000235 i = (U8*)data;
236 o = buffer;
237 m = (U8*)mask;
238 m_width = (width+7)/8;
239 for (int y = 0;y < height;y++) {
240 for (int x = 0;x < width;x++) {
Pierre Ossmanb6b4dc62014-01-20 15:05:21 +0100241 pf->rgbFromBuffer(o, i, 1);
Pierre Ossmanf741d342011-06-09 08:32:49 +0000242
Pierre Ossman17a48f02011-06-09 08:42:04 +0000243 if (m[(m_width*y)+(x/8)] & 0x80>>(x%8))
244 o[3] = 255;
245 else
246 o[3] = 0;
Pierre Ossmanf741d342011-06-09 08:32:49 +0000247
Pierre Ossman17a48f02011-06-09 08:42:04 +0000248 o += 4;
Pierre Ossmand8f84872011-07-15 08:26:51 +0000249 i += pf->bpp/8;
Pierre Ossman17a48f02011-06-09 08:42:04 +0000250 }
Pierre Ossmanf741d342011-06-09 08:32:49 +0000251 }
Pierre Ossman17a48f02011-06-09 08:42:04 +0000252
253 cursor = new Fl_RGB_Image(buffer, width, height, 4);
254
255 cursorHotspot = hotspot;
Pierre Ossmanf741d342011-06-09 08:32:49 +0000256 }
Pierre Ossmanf741d342011-06-09 08:32:49 +0000257 }
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000258
259 if (Fl::belowmouse() == this)
260 window()->cursor(cursor, cursorHotspot.x, cursorHotspot.y);
261#endif
262}
263
264
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000265void Viewport::draw()
266{
267 int X, Y, W, H;
268
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000269 // Check what actually needs updating
Pierre Ossmana6e20772011-04-15 11:10:52 +0000270 fl_clip_box(x(), y(), w(), h(), X, Y, W, H);
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000271 if ((W == 0) || (H == 0))
272 return;
273
Pierre Ossman132b3d02011-06-13 11:19:32 +0000274 frameBuffer->draw(X - x(), Y - y(), X, Y, W, H);
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000275}
276
277
Pierre Ossmane00f0aa2011-06-01 09:31:53 +0000278void Viewport::resize(int x, int y, int w, int h)
279{
Pierre Ossman132b3d02011-06-13 11:19:32 +0000280 PlatformPixelBuffer* newBuffer;
Pierre Ossmane00f0aa2011-06-01 09:31:53 +0000281 rfb::Rect rect;
282
Pierre Ossmanff9eb5a2014-01-30 17:47:31 +0100283 const rdr::U8* data;
284 int stride;
285
Pierre Ossman132b3d02011-06-13 11:19:32 +0000286 // FIXME: Resize should probably be a feature of the pixel buffer itself
Pierre Ossmane00f0aa2011-06-01 09:31:53 +0000287
288 if ((w == frameBuffer->width()) && (h == frameBuffer->height()))
289 goto end;
290
Pierre Ossmana23989b2012-07-04 11:10:46 +0000291 vlog.debug("Resizing framebuffer from %dx%d to %dx%d",
Pierre Ossman773125e2011-07-15 13:41:02 +0000292 frameBuffer->width(), frameBuffer->height(), w, h);
293
Pierre Ossmanac13abe2014-02-07 14:46:26 +0100294 newBuffer = createFramebuffer(w, h);
Pierre Ossmane00f0aa2011-06-01 09:31:53 +0000295 assert(newBuffer);
296
297 rect.setXYWH(0, 0,
298 __rfbmin(newBuffer->width(), frameBuffer->width()),
299 __rfbmin(newBuffer->height(), frameBuffer->height()));
Pierre Ossmanff9eb5a2014-01-30 17:47:31 +0100300 data = frameBuffer->getBuffer(frameBuffer->getRect(), &stride);
301 newBuffer->imageRect(rect, data, stride);
Pierre Ossmane00f0aa2011-06-01 09:31:53 +0000302
303 // Black out any new areas
304
305 if (newBuffer->width() > frameBuffer->width()) {
306 rect.setXYWH(frameBuffer->width(), 0,
307 newBuffer->width() - frameBuffer->width(),
308 newBuffer->height());
309 newBuffer->fillRect(rect, 0);
310 }
311
312 if (newBuffer->height() > frameBuffer->height()) {
313 rect.setXYWH(0, frameBuffer->height(),
314 newBuffer->width(),
315 newBuffer->height() - frameBuffer->height());
316 newBuffer->fillRect(rect, 0);
317 }
318
319 delete frameBuffer;
320 frameBuffer = newBuffer;
321
322end:
323 Fl_Widget::resize(x, y, w, h);
324}
325
326
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000327int Viewport::handle(int event)
328{
Pierre Ossman689c4582011-05-26 15:39:41 +0000329 char *buffer;
Pierre Ossman4a6be4a2011-05-19 14:49:18 +0000330 int ret;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000331 int buttonMask, wheelMask;
332 DownMap::const_iterator iter;
333
334 switch (event) {
Pierre Ossman4a6be4a2011-05-19 14:49:18 +0000335 case FL_PASTE:
Pierre Ossman689c4582011-05-26 15:39:41 +0000336 buffer = new char[Fl::event_length() + 1];
337
Pierre Ossman4a6be4a2011-05-19 14:49:18 +0000338 // This is documented as to ASCII, but actually does to 8859-1
Pierre Ossman689c4582011-05-26 15:39:41 +0000339 ret = fl_utf8toa(Fl::event_text(), Fl::event_length(), buffer,
340 Fl::event_length() + 1);
341 assert(ret < (Fl::event_length() + 1));
342
Pierre Ossman5803d3b2013-09-05 14:25:40 +0000343 vlog.debug("Sending clipboard data (%d bytes)", strlen(buffer));
Pierre Ossman829cdeb2011-07-12 16:58:12 +0000344
345 try {
346 cc->writer()->clientCutText(buffer, ret);
347 } catch (rdr::Exception& e) {
Pierre Ossmanad8609a2012-04-26 09:04:14 +0000348 vlog.error("%s", e.str());
Pierre Ossman829cdeb2011-07-12 16:58:12 +0000349 exit_vncviewer(e.str());
350 }
Pierre Ossman689c4582011-05-26 15:39:41 +0000351
352 delete [] buffer;
353
Pierre Ossman4a6be4a2011-05-19 14:49:18 +0000354 return 1;
Pierre Ossman689c4582011-05-26 15:39:41 +0000355
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000356 case FL_ENTER:
357 // Yes, we would like some pointer events please!
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000358#ifdef HAVE_FLTK_CURSOR
Pierre Ossman1f1f6fd2011-06-09 08:33:29 +0000359 if (cursor)
360 window()->cursor(cursor, cursorHotspot.x, cursorHotspot.y);
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000361#endif
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000362 return 1;
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000363
364 case FL_LEAVE:
365#ifdef HAVE_FLTK_CURSOR
366 window()->cursor(FL_CURSOR_DEFAULT);
367#endif
Pierre Ossman164865a2011-11-10 13:30:39 +0000368 // Fall through as we want a last move event to help trigger edge stuff
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000369 case FL_PUSH:
370 case FL_RELEASE:
371 case FL_DRAG:
372 case FL_MOVE:
373 case FL_MOUSEWHEEL:
374 buttonMask = 0;
375 if (Fl::event_button1())
376 buttonMask |= 1;
377 if (Fl::event_button2())
378 buttonMask |= 2;
379 if (Fl::event_button3())
380 buttonMask |= 4;
381
382 if (event == FL_MOUSEWHEEL) {
Pierre Ossmandf0ed9f2011-05-24 11:33:43 +0000383 wheelMask = 0;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000384 if (Fl::event_dy() < 0)
Pierre Ossmandf0ed9f2011-05-24 11:33:43 +0000385 wheelMask |= 8;
386 if (Fl::event_dy() > 0)
387 wheelMask |= 16;
388 if (Fl::event_dx() < 0)
389 wheelMask |= 32;
390 if (Fl::event_dx() > 0)
391 wheelMask |= 64;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000392
393 // A quick press of the wheel "button", followed by a immediate
394 // release below
Pierre Ossman6a464be2011-04-15 12:57:31 +0000395 handlePointerEvent(Point(Fl::event_x() - x(), Fl::event_y() - y()),
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000396 buttonMask | wheelMask);
397 }
398
Pierre Ossman6a464be2011-04-15 12:57:31 +0000399 handlePointerEvent(Point(Fl::event_x() - x(), Fl::event_y() - y()), buttonMask);
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000400 return 1;
401
402 case FL_FOCUS:
403 // Yes, we would like some focus please!
404 return 1;
405
406 case FL_UNFOCUS:
407 // Release all keys that were pressed as that generally makes most
408 // sense (e.g. Alt+Tab where we only see the Alt press)
Pierre Ossmanf8450ca2011-07-12 16:10:16 +0000409 while (!downKeySym.empty())
Pierre Ossman25188c42014-07-21 16:30:08 +0200410 handleKeyRelease(downKeySym.begin()->first);
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000411 return 1;
412
413 case FL_KEYDOWN:
Pierre Ossman25188c42014-07-21 16:30:08 +0200414 handleFLTKKeyPress();
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000415 return 1;
416
417 case FL_KEYUP:
Pierre Ossman25188c42014-07-21 16:30:08 +0200418 handleKeyRelease(Fl::event_original_key());
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000419 return 1;
420 }
421
422 return Fl_Widget::handle(event);
423}
424
425
Pierre Ossmanac13abe2014-02-07 14:46:26 +0100426PlatformPixelBuffer* Viewport::createFramebuffer(int w, int h)
427{
428 PlatformPixelBuffer *fb;
429
430 try {
431#if defined(WIN32)
432 fb = new Win32PixelBuffer(w, h);
433#elif defined(__APPLE__)
434 fb = new OSXPixelBuffer(w, h);
435#else
436 fb = new X11PixelBuffer(w, h);
437#endif
438 } catch (rdr::Exception& e) {
439 fb = new FLTKPixelBuffer(w, h);
440 }
441
442 return fb;
443}
444
445
Pierre Ossman4a6be4a2011-05-19 14:49:18 +0000446void Viewport::handleClipboardChange(int source, void *data)
447{
448 Viewport *self = (Viewport *)data;
449
450 assert(self);
451
452 if (!sendPrimary && (source == 0))
453 return;
454
455 Fl::paste(*self, source);
456}
457
458
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000459void Viewport::handlePointerEvent(const rfb::Point& pos, int buttonMask)
460{
461 if (!viewOnly) {
462 if (pointerEventInterval == 0 || buttonMask != lastButtonMask) {
Pierre Ossman829cdeb2011-07-12 16:58:12 +0000463 try {
464 cc->writer()->pointerEvent(pos, buttonMask);
465 } catch (rdr::Exception& e) {
Pierre Ossmanad8609a2012-04-26 09:04:14 +0000466 vlog.error("%s", e.str());
Pierre Ossman829cdeb2011-07-12 16:58:12 +0000467 exit_vncviewer(e.str());
468 }
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000469 } else {
470 if (!Fl::has_timeout(handlePointerTimeout, this))
471 Fl::add_timeout((double)pointerEventInterval/1000.0,
472 handlePointerTimeout, this);
473 }
474 lastPointerPos = pos;
475 lastButtonMask = buttonMask;
476 }
477}
478
479
480void Viewport::handlePointerTimeout(void *data)
481{
482 Viewport *self = (Viewport *)data;
483
484 assert(self);
485
Pierre Ossman829cdeb2011-07-12 16:58:12 +0000486 try {
487 self->cc->writer()->pointerEvent(self->lastPointerPos, self->lastButtonMask);
488 } catch (rdr::Exception& e) {
Pierre Ossmanad8609a2012-04-26 09:04:14 +0000489 vlog.error("%s", e.str());
Pierre Ossman829cdeb2011-07-12 16:58:12 +0000490 exit_vncviewer(e.str());
491 }
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000492}
493
494
Pierre Ossman25188c42014-07-21 16:30:08 +0200495void Viewport::handleKeyPress(int keyCode, rdr::U32 keySym)
496{
497 static bool menuRecursion = false;
498
499 // Prevent recursion if the menu wants to send its own
500 // activation key.
501 if (menuKeySym && (keySym == menuKeySym) && !menuRecursion) {
502 menuRecursion = true;
503 popupContextMenu();
504 menuRecursion = false;
505 return;
506 }
507
508 if (viewOnly)
509 return;
510
511#ifdef __APPLE__
512 // Alt on OS X behaves more like AltGr on other systems, and to get
513 // sane behaviour we should translate things in that manner for the
514 // remote VNC server. However that means we lose the ability to use
515 // Alt as a shortcut modifier. Do what RealVNC does and hijack the
516 // left command key as an Alt replacement.
517 switch (keySym) {
518 case XK_Super_L:
519 keySym = XK_Alt_L;
520 break;
521 case XK_Super_R:
522 keySym = XK_Super_L;
523 break;
524 case XK_Alt_L:
525 case XK_Alt_R:
526 keySym = XK_ISO_Level3_Shift;
527 break;
528 }
529#endif
530
531#ifdef WIN32
532 // Ugly hack alert!
533 //
534 // Windows doesn't have a proper AltGr, but handles it using fake
535 // Ctrl+Alt. Unfortunately X11 doesn't generally like the combination
536 // Ctrl+Alt+AltGr, which we usually end up with when Xvnc tries to
537 // get everything in the correct state. Cheat and temporarily release
538 // Ctrl and Alt when we send some other symbol.
539 bool ctrlPressed, altPressed;
540 DownMap::iterator iter;
541
542 ctrlPressed = false;
543 altPressed = false;
544 for (iter = downKeySym.begin();iter != downKeySym.end();++iter) {
545 if (iter->second == XK_Control_L)
546 ctrlPressed = true;
547 else if (iter->second == XK_Alt_R)
548 altPressed = true;
549 }
550
551 if (ctrlPressed && altPressed) {
552 vlog.debug("Faking release of AltGr (Ctrl_L+Alt_R)");
553 try {
554 cc->writer()->keyEvent(XK_Control_L, false);
555 cc->writer()->keyEvent(XK_Alt_R, false);
556 } catch (rdr::Exception& e) {
557 vlog.error("%s", e.str());
558 exit_vncviewer(e.str());
559 }
560 }
561#endif
562
563 // Because of the way keyboards work, we cannot expect to have the same
564 // symbol on release as when pressed. This breaks the VNC protocol however,
565 // so we need to keep track of what keysym a key _code_ generated on press
566 // and send the same on release.
567 downKeySym[keyCode] = keySym;
568
569#if defined(WIN32) || defined(__APPLE__)
570 vlog.debug("Key pressed: 0x%04x => 0x%04x", keyCode, keySym);
571#else
572 vlog.debug("Key pressed: 0x%04x => XK_%s (0x%04x)",
573 keyCode, XKeysymToString(keySym), keySym);
574#endif
575
576 try {
577 cc->writer()->keyEvent(keySym, true);
578 } catch (rdr::Exception& e) {
579 vlog.error("%s", e.str());
580 exit_vncviewer(e.str());
581 }
582
583#ifdef WIN32
584 // Ugly hack continued...
585 if (ctrlPressed && altPressed) {
586 vlog.debug("Restoring AltGr state");
587 try {
588 cc->writer()->keyEvent(XK_Control_L, true);
589 cc->writer()->keyEvent(XK_Alt_R, true);
590 } catch (rdr::Exception& e) {
591 vlog.error("%s", e.str());
592 exit_vncviewer(e.str());
593 }
594 }
595#endif
596}
597
598
599void Viewport::handleKeyRelease(int keyCode)
600{
601 DownMap::iterator iter;
602
603 if (viewOnly)
604 return;
605
606 iter = downKeySym.find(keyCode);
607 if (iter == downKeySym.end()) {
608 // These occur somewhat frequently so let's not spam them unless
609 // logging is turned up.
610 vlog.debug("Unexpected release of key code %d", keyCode);
611 return;
612 }
613
614#if defined(WIN32) || defined(__APPLE__)
615 vlog.debug("Key released: 0x%04x => 0x%04x", keyCode, iter->second);
616#else
617 vlog.debug("Key released: 0x%04x => XK_%s (0x%04x)",
618 keyCode, XKeysymToString(iter->second), iter->second);
619#endif
620
621 try {
622 cc->writer()->keyEvent(iter->second, false);
623 } catch (rdr::Exception& e) {
624 vlog.error("%s", e.str());
625 exit_vncviewer(e.str());
626 }
627
628 downKeySym.erase(iter);
629}
630
631
Pierre Ossman4f3ac692014-08-22 15:10:22 +0200632bool Viewport::handleXEvent(void *event, void *data)
633{
634 Viewport *self = (Viewport *)data;
635 Fl_Widget *focus;
636
637 assert(self);
638
639 focus = Fl::grab();
640 if (!focus)
641 focus = Fl::focus();
642 if (!focus)
643 return false;
644
645 if (focus != self)
646 return false;
647
648 assert(event);
649
Pierre Ossman6b9622d2014-07-21 16:42:12 +0200650#if !defined(WIN32) && !defined(__APPLE__)
651 XEvent *xevent = (XEvent*)event;
652
653 if (xevent->type == KeyPress) {
654 char str;
655 KeySym keysym;
656
657 XLookupString(&xevent->xkey, &str, 1, &keysym, NULL);
658 if (keysym == NoSymbol) {
659 vlog.error(_("No symbol for key code %d (in the current state)"),
660 (int)xevent->xkey.keycode);
661 return true;
662 }
663
664 switch (keysym) {
665 // For the first few years, there wasn't a good consensus on what the
666 // Windows keys should be mapped to for X11. So we need to help out a
667 // bit and map all variants to the same key...
668 case XK_Meta_L:
669 case XK_Hyper_L:
670 keysym = XK_Super_L;
671 break;
672 case XK_Meta_R:
673 case XK_Hyper_R:
674 keysym = XK_Super_R;
675 break;
676 // There has been several variants for Shift-Tab over the years.
677 // RFB states that we should always send a normal tab.
678 case XK_ISO_Left_Tab:
679 keysym = XK_Tab;
680 break;
681 }
682
683 self->handleKeyPress(xevent->xkey.keycode, keysym);
684 return true;
685 } else if (xevent->type == KeyRelease) {
686 self->handleKeyRelease(xevent->xkey.keycode);
687 return true;
688 }
689#endif
690
Pierre Ossman4f3ac692014-08-22 15:10:22 +0200691 return false;
692}
693
694
Pierre Ossman25188c42014-07-21 16:30:08 +0200695rdr::U32 Viewport::translateKeyEvent(void)
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000696{
697 unsigned ucs;
Pierre Ossman25188c42014-07-21 16:30:08 +0200698 int keyCode, origKeyCode;
699 const char *keyText;
700 int keyTextLen;
701
702 keyCode = Fl::event_key();
703 origKeyCode = Fl::event_original_key();
704 keyText = Fl::event_text();
705 keyTextLen = Fl::event_length();
706
707 vlog.debug("FLTK key %d (%d) '%s'[%d]", origKeyCode, keyCode, keyText, keyTextLen);
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000708
709 // First check for function keys
710 if ((keyCode > FL_F) && (keyCode <= FL_F_Last))
711 return XK_F1 + (keyCode - FL_F - 1);
712
713 // Numpad numbers
714 if ((keyCode >= (FL_KP + '0')) && (keyCode <= (FL_KP + '9')))
715 return XK_KP_0 + (keyCode - (FL_KP + '0'));
716
Pierre Ossmancd6ddef2011-05-20 12:05:20 +0000717 // FLTK does some special remapping of numpad keys when numlock is off
718 if ((origKeyCode >= FL_KP) && (origKeyCode <= FL_KP_Last)) {
719 switch (keyCode) {
720 case FL_F+1:
721 return XK_KP_F1;
722 case FL_F+2:
723 return XK_KP_F2;
724 case FL_F+3:
725 return XK_KP_F3;
726 case FL_F+4:
727 return XK_KP_F4;
728 case FL_Home:
729 return XK_KP_Home;
730 case FL_Left:
731 return XK_KP_Left;
732 case FL_Up:
733 return XK_KP_Up;
734 case FL_Right:
735 return XK_KP_Right;
736 case FL_Down:
737 return XK_KP_Down;
738 case FL_Page_Up:
739 return XK_KP_Page_Up;
740 case FL_Page_Down:
741 return XK_KP_Page_Down;
742 case FL_End:
743 return XK_KP_End;
744 case FL_Insert:
745 return XK_KP_Insert;
746 case FL_Delete:
747 return XK_KP_Delete;
748 }
749 }
750
Pierre Ossman159cb832013-05-29 12:33:59 +0000751#if defined(WIN32) || defined(__APPLE__)
Pierre Ossman7e8ace12013-04-16 11:56:29 +0000752 // X11 fairly consistently uses XK_KP_Separator for comma and
Pierre Ossman159cb832013-05-29 12:33:59 +0000753 // XK_KP_Decimal for period. Windows and OS X are a different matter
754 // though.
755 //
756 // OS X will consistently generate the same key code no matter what
757 // layout is being used.
758 //
759 // Windows is terribly inconcistent, and is not something that's
760 // likely to change:
Pierre Ossman7e8ace12013-04-16 11:56:29 +0000761 // http://blogs.msdn.com/michkap/archive/2006/09/13/752377.aspx
Pierre Ossman159cb832013-05-29 12:33:59 +0000762 //
763 // To get X11 behaviour, we instead look at the text generated by
764 // they key.
Pierre Ossman7e8ace12013-04-16 11:56:29 +0000765 if ((keyCode == (FL_KP + ',')) || (keyCode == (FL_KP + '.'))) {
766 switch (keyText[0]) {
767 case ',':
768 return XK_KP_Separator;
769 case '.':
770 return XK_KP_Decimal;
771 default:
772 vlog.error(_("Unknown decimal separator: '%s'"), keyText);
773 return XK_KP_Decimal;
774 }
775 }
776#endif
777
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000778 // Then other special keys
779 switch (keyCode) {
780 case FL_BackSpace:
781 return XK_BackSpace;
782 case FL_Tab:
783 return XK_Tab;
784 case FL_Enter:
785 return XK_Return;
786 case FL_Pause:
787 return XK_Pause;
788 case FL_Scroll_Lock:
789 return XK_Scroll_Lock;
790 case FL_Escape:
791 return XK_Escape;
792 case FL_Home:
793 return XK_Home;
794 case FL_Left:
795 return XK_Left;
796 case FL_Up:
797 return XK_Up;
798 case FL_Right:
799 return XK_Right;
800 case FL_Down:
801 return XK_Down;
802 case FL_Page_Up:
803 return XK_Page_Up;
804 case FL_Page_Down:
805 return XK_Page_Down;
806 case FL_End:
807 return XK_End;
808 case FL_Print:
809 return XK_Print;
810 case FL_Insert:
811 return XK_Insert;
812 case FL_Menu:
813 return XK_Menu;
814 case FL_Help:
815 return XK_Help;
816 case FL_Num_Lock:
817 return XK_Num_Lock;
818 case FL_Shift_L:
819 return XK_Shift_L;
820 case FL_Shift_R:
821 return XK_Shift_R;
822 case FL_Control_L:
823 return XK_Control_L;
824 case FL_Control_R:
825 return XK_Control_R;
826 case FL_Caps_Lock:
827 return XK_Caps_Lock;
828 case FL_Meta_L:
829 return XK_Super_L;
830 case FL_Meta_R:
831 return XK_Super_R;
832 case FL_Alt_L:
833 return XK_Alt_L;
834 case FL_Alt_R:
835 return XK_Alt_R;
836 case FL_Delete:
837 return XK_Delete;
838 case FL_KP_Enter:
839 return XK_KP_Enter;
840 case FL_KP + '=':
841 return XK_KP_Equal;
842 case FL_KP + '*':
843 return XK_KP_Multiply;
844 case FL_KP + '+':
845 return XK_KP_Add;
846 case FL_KP + ',':
847 return XK_KP_Separator;
848 case FL_KP + '-':
849 return XK_KP_Subtract;
850 case FL_KP + '.':
851 return XK_KP_Decimal;
852 case FL_KP + '/':
853 return XK_KP_Divide;
Pierre Ossmancb0cffe2011-05-20 14:55:10 +0000854#ifdef HAVE_FLTK_MEDIAKEYS
855 case FL_Volume_Down:
856 return XF86XK_AudioLowerVolume;
857 case FL_Volume_Mute:
858 return XF86XK_AudioMute;
859 case FL_Volume_Up:
860 return XF86XK_AudioRaiseVolume;
861 case FL_Media_Play:
862 return XF86XK_AudioPlay;
863 case FL_Media_Stop:
864 return XF86XK_AudioStop;
865 case FL_Media_Prev:
866 return XF86XK_AudioPrev;
867 case FL_Media_Next:
868 return XF86XK_AudioNext;
869 case FL_Home_Page:
870 return XF86XK_HomePage;
871 case FL_Mail:
872 return XF86XK_Mail;
873 case FL_Search:
874 return XF86XK_Search;
875 case FL_Back:
876 return XF86XK_Back;
877 case FL_Forward:
878 return XF86XK_Forward;
879 case FL_Stop:
880 return XF86XK_Stop;
881 case FL_Refresh:
882 return XF86XK_Refresh;
883 case FL_Sleep:
884 return XF86XK_Sleep;
885 case FL_Favorites:
886 return XF86XK_Favorites;
887#endif
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000888 case XK_ISO_Level3_Shift:
889 // FLTK tends to let this one leak through on X11...
890 return XK_ISO_Level3_Shift;
Pierre Ossmana75f8f82011-04-29 11:12:02 +0000891 case XK_Multi_key:
892 // Same for this...
893 return XK_Multi_key;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000894 }
895
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000896 // Unknown special key?
Pierre Ossman13a809a2014-08-22 15:09:54 +0200897 if (keyTextLen == 0) {
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000898 vlog.error(_("Unknown FLTK key code %d (0x%04x)"), keyCode, keyCode);
Pierre Ossman7b8bff62014-07-21 16:17:23 +0200899 return NoSymbol;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000900 }
901
Pierre Ossman13a809a2014-08-22 15:09:54 +0200902 // Control character?
903 if ((keyTextLen == 1) && ((keyText[0] < 0x20) | (keyText[0] == 0x7f))) {
904 if (keyText[0] == 0x00)
905 return XK_2;
906 else if (keyText[0] < 0x1b) {
907 if (!!Fl::event_state(FL_SHIFT) != !!Fl::event_state(FL_CAPS_LOCK))
908 return keyText[0] + XK_A - 0x01;
909 else
910 return keyText[0] + XK_a - 0x01;
911 } else if (keyText[0] < 0x20)
912 return keyText[0] + XK_3 - 0x1b;
913 else
914 return XK_8;
915 }
916
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000917 // Look up the symbol the key produces and translate that from Unicode
918 // to a X11 keysym.
919 if (fl_utf_nb_char((const unsigned char*)keyText, strlen(keyText)) != 1) {
920 vlog.error(_("Multiple characters given for key code %d (0x%04x): '%s'"),
921 keyCode, keyCode, keyText);
Pierre Ossman7b8bff62014-07-21 16:17:23 +0200922 return NoSymbol;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000923 }
924
925 ucs = fl_utf8decode(keyText, NULL, NULL);
926 return ucs2keysym(ucs);
927}
928
929
Pierre Ossman25188c42014-07-21 16:30:08 +0200930void Viewport::handleFLTKKeyPress(void)
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000931{
932 rdr::U32 keySym;
933
Pierre Ossman25188c42014-07-21 16:30:08 +0200934 keySym = translateKeyEvent();
Pierre Ossman7b8bff62014-07-21 16:17:23 +0200935 if (keySym == NoSymbol)
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000936 return;
937
Pierre Ossman25188c42014-07-21 16:30:08 +0200938 handleKeyPress(Fl::event_original_key(), keySym);
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000939}
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000940
941
942void Viewport::initContextMenu()
943{
Pierre Ossman4e7271e2011-05-24 12:47:12 +0000944 contextMenu->clear();
945
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000946 contextMenu->add(_("Exit viewer"), 0, NULL, (void*)ID_EXIT, FL_MENU_DIVIDER);
947
Pierre Ossman4c613d32011-05-26 14:14:06 +0000948#ifdef HAVE_FLTK_FULLSCREEN
Henrik Anderssonabd70ce2011-09-14 06:31:06 +0000949 contextMenu->add(_("Full screen"), 0, NULL, (void*)ID_FULLSCREEN,
950 FL_MENU_TOGGLE | (window()->fullscreen_active()?FL_MENU_VALUE:0));
Pierre Ossman4c613d32011-05-26 14:14:06 +0000951#endif
Pierre Ossman8dc8bca2012-07-04 11:37:10 +0000952 contextMenu->add(_("Resize window to session"), 0, NULL, (void*)ID_RESIZE,
953#ifdef HAVE_FLTK_FULLSCREEN
954 (window()->fullscreen_active()?FL_MENU_INACTIVE:0) |
955#endif
956 FL_MENU_DIVIDER);
Pierre Ossman4c613d32011-05-26 14:14:06 +0000957
Henrik Anderssonabd70ce2011-09-14 06:31:06 +0000958 contextMenu->add(_("Ctrl"), 0, NULL, (void*)ID_CTRL,
959 FL_MENU_TOGGLE | (menuCtrlKey?FL_MENU_VALUE:0));
960 contextMenu->add(_("Alt"), 0, NULL, (void*)ID_ALT,
961 FL_MENU_TOGGLE | (menuAltKey?FL_MENU_VALUE:0));
Pierre Ossman4e7271e2011-05-24 12:47:12 +0000962
Pierre Ossman25188c42014-07-21 16:30:08 +0200963 if (menuKeySym) {
Pierre Ossman4e7271e2011-05-24 12:47:12 +0000964 char sendMenuKey[64];
965 snprintf(sendMenuKey, 64, _("Send %s"), (const char *)menuKey);
966 contextMenu->add(sendMenuKey, 0, NULL, (void*)ID_MENUKEY, 0);
967 contextMenu->add("Secret shortcut menu key", menuKeyCode, NULL, (void*)ID_MENUKEY, FL_MENU_INVISIBLE);
968 }
969
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000970 contextMenu->add(_("Send Ctrl-Alt-Del"), 0, NULL, (void*)ID_CTRLALTDEL, FL_MENU_DIVIDER);
971
Pierre Ossmand4c61ce2011-04-29 11:18:12 +0000972 contextMenu->add(_("Refresh screen"), 0, NULL, (void*)ID_REFRESH, FL_MENU_DIVIDER);
973
Pierre Ossmand463b572011-05-16 12:04:43 +0000974 contextMenu->add(_("Options..."), 0, NULL, (void*)ID_OPTIONS, 0);
Pierre Ossman2eb1d112011-05-16 12:18:08 +0000975 contextMenu->add(_("Connection info..."), 0, NULL, (void*)ID_INFO, 0);
Pierre Ossmanb8858222011-04-29 11:51:38 +0000976 contextMenu->add(_("About TigerVNC viewer..."), 0, NULL, (void*)ID_ABOUT, FL_MENU_DIVIDER);
977
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000978 contextMenu->add(_("Dismiss menu"), 0, NULL, (void*)ID_DISMISS, 0);
979}
980
981
982void Viewport::popupContextMenu()
983{
984 const Fl_Menu_Item *m;
Pierre Ossmanc628ba42011-05-23 12:21:21 +0000985 char buffer[1024];
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000986
Pierre Ossmanb3ff4372011-06-03 11:45:15 +0000987 // Make sure the menu is reset to its initial state between goes or
988 // it will start up highlighting the previously selected entry.
989 contextMenu->value(-1);
990
Henrik Anderssonabd70ce2011-09-14 06:31:06 +0000991 // initialize context menu before display
992 initContextMenu();
993
Pierre Ossmanfd177f32012-01-05 12:37:04 +0000994 // Unfortunately FLTK doesn't reliably restore the mouse pointer for
995 // menus, so we have to help it out.
Pierre Ossmanbfbdb102012-01-05 12:32:03 +0000996#ifdef HAVE_FLTK_CURSOR
997 if (Fl::belowmouse() == this)
998 window()->cursor(FL_CURSOR_DEFAULT);
999#endif
1000
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +00001001 m = contextMenu->popup();
Pierre Ossmanbfbdb102012-01-05 12:32:03 +00001002
Pierre Ossmanfd177f32012-01-05 12:37:04 +00001003 // Back to our proper mouse pointer.
Pierre Ossmanbfbdb102012-01-05 12:32:03 +00001004#ifdef HAVE_FLTK_CURSOR
Pierre Ossmande1a3b92014-03-17 14:29:49 +01001005 if ((Fl::belowmouse() == this) && cursor)
Pierre Ossmanbfbdb102012-01-05 12:32:03 +00001006 window()->cursor(cursor, cursorHotspot.x, cursorHotspot.y);
1007#endif
1008
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +00001009 if (m == NULL)
1010 return;
1011
1012 switch (m->argument()) {
1013 case ID_EXIT:
1014 exit_vncviewer();
1015 break;
Pierre Ossman4c613d32011-05-26 14:14:06 +00001016#ifdef HAVE_FLTK_FULLSCREEN
1017 case ID_FULLSCREEN:
1018 if (window()->fullscreen_active())
1019 window()->fullscreen_off();
Pierre Ossman275284f2012-07-04 11:37:48 +00001020 else
Pierre Ossmanaae38912012-07-13 11:22:55 +00001021 ((DesktopWindow*)window())->fullscreen_on();
Pierre Ossman4c613d32011-05-26 14:14:06 +00001022 break;
1023#endif
Pierre Ossman8dc8bca2012-07-04 11:37:10 +00001024 case ID_RESIZE:
1025#ifdef HAVE_FLTK_FULLSCREEN
1026 if (window()->fullscreen_active())
1027 break;
1028#endif
1029 window()->size(w(), h());
1030 break;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +00001031 case ID_CTRL:
Pierre Ossman25188c42014-07-21 16:30:08 +02001032 if (m->value())
1033 handleKeyPress(fakeKeyBase + 0, XK_Control_L);
1034 else
1035 handleKeyRelease(fakeKeyBase + 0);
Henrik Anderssonabd70ce2011-09-14 06:31:06 +00001036 menuCtrlKey = !menuCtrlKey;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +00001037 break;
1038 case ID_ALT:
Pierre Ossman25188c42014-07-21 16:30:08 +02001039 if (m->value())
1040 handleKeyPress(fakeKeyBase + 1, XK_Alt_L);
1041 else
1042 handleKeyRelease(fakeKeyBase + 1);
Henrik Anderssonabd70ce2011-09-14 06:31:06 +00001043 menuAltKey = !menuAltKey;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +00001044 break;
1045 case ID_MENUKEY:
Pierre Ossman25188c42014-07-21 16:30:08 +02001046 handleKeyPress(fakeKeyBase + 2, menuKeySym);
1047 handleKeyRelease(fakeKeyBase + 2);
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +00001048 break;
1049 case ID_CTRLALTDEL:
Pierre Ossman25188c42014-07-21 16:30:08 +02001050 handleKeyPress(fakeKeyBase + 3, XK_Control_L);
1051 handleKeyPress(fakeKeyBase + 4, XK_Alt_L);
1052 handleKeyPress(fakeKeyBase + 5, XK_Delete);
Pierre Ossman991b4fe2011-07-12 16:02:30 +00001053
Pierre Ossman25188c42014-07-21 16:30:08 +02001054 handleKeyRelease(fakeKeyBase + 5);
1055 handleKeyRelease(fakeKeyBase + 4);
1056 handleKeyRelease(fakeKeyBase + 3);
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +00001057 break;
Pierre Ossmand4c61ce2011-04-29 11:18:12 +00001058 case ID_REFRESH:
1059 cc->refreshFramebuffer();
1060 break;
Pierre Ossmand463b572011-05-16 12:04:43 +00001061 case ID_OPTIONS:
1062 OptionsDialog::showDialog();
1063 break;
Pierre Ossman2eb1d112011-05-16 12:18:08 +00001064 case ID_INFO:
Pierre Ossmanc628ba42011-05-23 12:21:21 +00001065 if (fltk_escape(cc->connectionInfo(), buffer, sizeof(buffer)) < sizeof(buffer)) {
1066 fl_message_title(_("VNC connection info"));
Pierre Ossmanf52740e2012-04-25 15:43:56 +00001067 fl_message("%s", buffer);
Pierre Ossmanc628ba42011-05-23 12:21:21 +00001068 }
Pierre Ossman2eb1d112011-05-16 12:18:08 +00001069 break;
Pierre Ossmanb8858222011-04-29 11:51:38 +00001070 case ID_ABOUT:
1071 about_vncviewer();
1072 break;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +00001073 case ID_DISMISS:
1074 // Don't need to do anything
1075 break;
1076 }
1077}
Pierre Ossman4e7271e2011-05-24 12:47:12 +00001078
1079
1080void Viewport::setMenuKey()
1081{
Pierre Ossman25188c42014-07-21 16:30:08 +02001082 getMenuKey(&menuKeyCode, &menuKeySym);
Pierre Ossman4e7271e2011-05-24 12:47:12 +00001083}
1084
1085
1086void Viewport::handleOptions(void *data)
1087{
1088 Viewport *self = (Viewport*)data;
1089
1090 self->setMenuKey();
1091}