Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 1 | /* 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 | #include <assert.h> |
| 21 | #include <stdio.h> |
| 22 | #include <string.h> |
| 23 | |
| 24 | #include <FL/fl_draw.H> |
Pierre Ossman | 2eb1d11 | 2011-05-16 12:18:08 +0000 | [diff] [blame] | 25 | #include <FL/fl_ask.H> |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 26 | |
| 27 | #include <rfb/CMsgWriter.h> |
| 28 | #include <rfb/LogWriter.h> |
| 29 | |
| 30 | // FLTK can pull in the X11 headers on some systems |
| 31 | #ifndef XK_VoidSymbol |
| 32 | #define XK_MISCELLANY |
| 33 | #define XK_XKB_KEYS |
| 34 | #include <rfb/keysymdef.h> |
| 35 | #endif |
| 36 | |
Pierre Ossman | cb0cffe | 2011-05-20 14:55:10 +0000 | [diff] [blame] | 37 | #ifndef XF86XK_ModeLock |
| 38 | #include <rfb/XF86keysym.h> |
| 39 | #endif |
| 40 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 41 | #include "Viewport.h" |
| 42 | #include "CConn.h" |
Pierre Ossman | d463b57 | 2011-05-16 12:04:43 +0000 | [diff] [blame] | 43 | #include "OptionsDialog.h" |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 44 | #include "i18n.h" |
Pierre Ossman | c628ba4 | 2011-05-23 12:21:21 +0000 | [diff] [blame] | 45 | #include "fltk_layout.h" |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 46 | #include "parameters.h" |
| 47 | #include "keysym2ucs.h" |
| 48 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 49 | using namespace rfb; |
Pierre Ossman | 835b4ef | 2011-06-08 17:02:36 +0000 | [diff] [blame^] | 50 | using namespace rdr; |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 51 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 52 | extern void exit_vncviewer(); |
Pierre Ossman | b885822 | 2011-04-29 11:51:38 +0000 | [diff] [blame] | 53 | extern void about_vncviewer(); |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 54 | |
| 55 | static rfb::LogWriter vlog("Viewport"); |
| 56 | |
Pierre Ossman | c7bfaac | 2011-04-29 11:08:11 +0000 | [diff] [blame] | 57 | // Menu constants |
| 58 | |
Pierre Ossman | 4c613d3 | 2011-05-26 14:14:06 +0000 | [diff] [blame] | 59 | enum { ID_EXIT, ID_FULLSCREEN, ID_CTRL, ID_ALT, ID_MENUKEY, ID_CTRLALTDEL, |
Pierre Ossman | 2eb1d11 | 2011-05-16 12:18:08 +0000 | [diff] [blame] | 60 | ID_REFRESH, ID_OPTIONS, ID_INFO, ID_ABOUT, ID_DISMISS }; |
Pierre Ossman | c7bfaac | 2011-04-29 11:08:11 +0000 | [diff] [blame] | 61 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 62 | Viewport::Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_) |
| 63 | : Fl_Widget(0, 0, w, h), cc(cc_), frameBuffer(NULL), pixelTrans(NULL), |
Pierre Ossman | 835b4ef | 2011-06-08 17:02:36 +0000 | [diff] [blame^] | 64 | lastPointerPos(0, 0), lastButtonMask(0), cursor(NULL) |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 65 | { |
Pierre Ossman | f8c5ef6 | 2011-05-13 12:47:54 +0000 | [diff] [blame] | 66 | // FLTK STR #2599 must be fixed for proper dead keys support |
| 67 | #ifdef HAVE_FLTK_DEAD_KEYS |
| 68 | set_simple_keyboard(); |
| 69 | #endif |
| 70 | |
Pierre Ossman | 4a6be4a | 2011-05-19 14:49:18 +0000 | [diff] [blame] | 71 | // FLTK STR #2636 gives us the ability to monitor clipboard changes |
| 72 | #ifdef HAVE_FLTK_CLIPBOARD |
| 73 | Fl::add_clipboard_notify(handleClipboardChange, this); |
| 74 | #endif |
| 75 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 76 | frameBuffer = new ManagedPixelBuffer(getPreferredPF(), w, h); |
| 77 | assert(frameBuffer); |
| 78 | |
| 79 | setServerPF(serverPF); |
Pierre Ossman | c7bfaac | 2011-04-29 11:08:11 +0000 | [diff] [blame] | 80 | |
| 81 | contextMenu = new Fl_Menu_Button(0, 0, 0, 0); |
Pierre Ossman | ad9d1ae | 2011-05-26 14:16:02 +0000 | [diff] [blame] | 82 | // Setting box type to FL_NO_BOX prevents it from trying to draw the |
| 83 | // button component (which we don't want) |
| 84 | contextMenu->box(FL_NO_BOX); |
| 85 | |
Pierre Ossman | b043ad1 | 2011-06-01 09:26:57 +0000 | [diff] [blame] | 86 | // The (invisible) button associated with this widget can mess with |
| 87 | // things like Fl_Scroll so we need to get rid of any parents. |
| 88 | // Unfortunately that's not possible because of STR #2654, but |
| 89 | // reparenting to the current window works for most cases. |
| 90 | window()->add(contextMenu); |
| 91 | |
Pierre Ossman | c7bfaac | 2011-04-29 11:08:11 +0000 | [diff] [blame] | 92 | initContextMenu(); |
Pierre Ossman | 4e7271e | 2011-05-24 12:47:12 +0000 | [diff] [blame] | 93 | |
| 94 | setMenuKey(); |
| 95 | |
| 96 | OptionsDialog::addCallback(handleOptions, this); |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | |
| 100 | Viewport::~Viewport() |
| 101 | { |
| 102 | // Unregister all timeouts in case they get a change tro trigger |
| 103 | // again later when this object is already gone. |
| 104 | Fl::remove_timeout(handleUpdateTimeout, this); |
| 105 | Fl::remove_timeout(handleColourMap, this); |
| 106 | Fl::remove_timeout(handlePointerTimeout, this); |
| 107 | |
Pierre Ossman | 4a6be4a | 2011-05-19 14:49:18 +0000 | [diff] [blame] | 108 | #ifdef HAVE_FLTK_CLIPBOARD |
| 109 | Fl::remove_clipboard_notify(handleClipboardChange); |
| 110 | #endif |
| 111 | |
Pierre Ossman | 4e7271e | 2011-05-24 12:47:12 +0000 | [diff] [blame] | 112 | OptionsDialog::removeCallback(handleOptions); |
| 113 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 114 | delete frameBuffer; |
| 115 | |
| 116 | if (pixelTrans) |
| 117 | delete pixelTrans; |
Pierre Ossman | c7bfaac | 2011-04-29 11:08:11 +0000 | [diff] [blame] | 118 | |
Pierre Ossman | 835b4ef | 2011-06-08 17:02:36 +0000 | [diff] [blame^] | 119 | if (cursor) { |
| 120 | delete [] cursor->array; |
| 121 | delete cursor; |
| 122 | } |
| 123 | |
Pierre Ossman | c7bfaac | 2011-04-29 11:08:11 +0000 | [diff] [blame] | 124 | // FLTK automatically deletes all child widgets, so we shouldn't touch |
| 125 | // them ourselves here |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | |
| 129 | void Viewport::setServerPF(const rfb::PixelFormat& pf) |
| 130 | { |
| 131 | if (pixelTrans) |
| 132 | delete pixelTrans; |
| 133 | pixelTrans = NULL; |
| 134 | |
| 135 | if (pf.equal(getPreferredPF())) |
| 136 | return; |
| 137 | |
| 138 | pixelTrans = new PixelTransformer(); |
| 139 | pixelTrans->init(pf, &colourMap, getPreferredPF()); |
| 140 | } |
| 141 | |
| 142 | |
| 143 | const rfb::PixelFormat &Viewport::getPreferredPF() |
| 144 | { |
| 145 | static PixelFormat prefPF(32, 24, false, true, 255, 255, 255, 0, 8, 16); |
| 146 | |
| 147 | return prefPF; |
| 148 | } |
| 149 | |
| 150 | |
| 151 | // setColourMapEntries() changes some of the entries in the colourmap. |
| 152 | // Unfortunately these messages are often sent one at a time, so we delay the |
| 153 | // settings taking effect by 100ms. This is because recalculating the internal |
| 154 | // translation table can be expensive. |
| 155 | void Viewport::setColourMapEntries(int firstColour, int nColours, |
| 156 | rdr::U16* rgbs) |
| 157 | { |
| 158 | for (int i = 0; i < nColours; i++) |
| 159 | colourMap.set(firstColour+i, rgbs[i*3], rgbs[i*3+1], rgbs[i*3+2]); |
| 160 | |
| 161 | if (!Fl::has_timeout(handleColourMap, this)) |
| 162 | Fl::add_timeout(0.100, handleColourMap, this); |
| 163 | } |
| 164 | |
| 165 | |
| 166 | // Copy the areas of the framebuffer that have been changed (damaged) |
| 167 | // to the displayed window. |
| 168 | |
| 169 | void Viewport::updateWindow() |
| 170 | { |
| 171 | Rect r; |
| 172 | |
| 173 | Fl::remove_timeout(handleUpdateTimeout, this); |
| 174 | |
| 175 | r = damage.get_bounding_rect(); |
Pierre Ossman | a6e2077 | 2011-04-15 11:10:52 +0000 | [diff] [blame] | 176 | Fl_Widget::damage(FL_DAMAGE_USER1, r.tl.x + x(), r.tl.y + y(), r.width(), r.height()); |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 177 | |
| 178 | damage.clear(); |
| 179 | } |
| 180 | |
| 181 | |
Pierre Ossman | 835b4ef | 2011-06-08 17:02:36 +0000 | [diff] [blame^] | 182 | void Viewport::setCursor(int width, int height, const Point& hotspot, |
| 183 | void* data, void* mask) |
| 184 | { |
| 185 | #ifdef HAVE_FLTK_CURSOR |
| 186 | U8 *buffer = new U8[width*height*4]; |
| 187 | U8 *i, *o, *m; |
| 188 | int m_width; |
| 189 | |
| 190 | const PixelFormat &pf = frameBuffer->getPF(); |
| 191 | |
| 192 | i = (U8*)data; |
| 193 | o = buffer; |
| 194 | m = (U8*)mask; |
| 195 | m_width = (width+7)/8; |
| 196 | for (int y = 0;y < height;y++) { |
| 197 | for (int x = 0;x < width;x++) { |
| 198 | pf.rgbFromBuffer(o, i, 1, &colourMap); |
| 199 | |
| 200 | if (m[(m_width*y)+(x/8)] & 0x80>>(x%8)) |
| 201 | o[3] = 255; |
| 202 | else |
| 203 | o[3] = 0; |
| 204 | |
| 205 | o += 4; |
| 206 | i += pf.bpp/8; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | if (cursor) { |
| 211 | delete [] cursor->array; |
| 212 | delete cursor; |
| 213 | } |
| 214 | |
| 215 | cursor = new Fl_RGB_Image(buffer, width, height, 4); |
| 216 | |
| 217 | cursorHotspot = hotspot; |
| 218 | |
| 219 | if (Fl::belowmouse() == this) |
| 220 | window()->cursor(cursor, cursorHotspot.x, cursorHotspot.y); |
| 221 | #endif |
| 222 | } |
| 223 | |
| 224 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 225 | void Viewport::draw() |
| 226 | { |
| 227 | int X, Y, W, H; |
| 228 | |
| 229 | int pixel_bytes, stride_bytes; |
| 230 | const uchar *buf_start; |
| 231 | |
| 232 | // Check what actually needs updating |
Pierre Ossman | a6e2077 | 2011-04-15 11:10:52 +0000 | [diff] [blame] | 233 | fl_clip_box(x(), y(), w(), h(), X, Y, W, H); |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 234 | if ((W == 0) || (H == 0)) |
| 235 | return; |
| 236 | |
| 237 | pixel_bytes = frameBuffer->getPF().bpp/8; |
| 238 | stride_bytes = pixel_bytes * frameBuffer->getStride(); |
| 239 | buf_start = frameBuffer->data + |
Pierre Ossman | a6e2077 | 2011-04-15 11:10:52 +0000 | [diff] [blame] | 240 | pixel_bytes * (X - x()) + |
| 241 | stride_bytes * (Y - y()); |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 242 | |
| 243 | // FIXME: Check how efficient this thing really is |
| 244 | fl_draw_image(buf_start, X, Y, W, H, pixel_bytes, stride_bytes); |
| 245 | } |
| 246 | |
| 247 | |
Pierre Ossman | e00f0aa | 2011-06-01 09:31:53 +0000 | [diff] [blame] | 248 | void Viewport::resize(int x, int y, int w, int h) |
| 249 | { |
| 250 | rfb::ManagedPixelBuffer* newBuffer; |
| 251 | rfb::Rect rect; |
| 252 | |
| 253 | // FIXME: Resize should probably be a feature of ManagedPixelBuffer |
| 254 | |
| 255 | if ((w == frameBuffer->width()) && (h == frameBuffer->height())) |
| 256 | goto end; |
| 257 | |
| 258 | newBuffer = new ManagedPixelBuffer(frameBuffer->getPF(), w, h); |
| 259 | assert(newBuffer); |
| 260 | |
| 261 | rect.setXYWH(0, 0, |
| 262 | __rfbmin(newBuffer->width(), frameBuffer->width()), |
| 263 | __rfbmin(newBuffer->height(), frameBuffer->height())); |
| 264 | newBuffer->imageRect(rect, frameBuffer->data, frameBuffer->getStride()); |
| 265 | |
| 266 | // Black out any new areas |
| 267 | |
| 268 | if (newBuffer->width() > frameBuffer->width()) { |
| 269 | rect.setXYWH(frameBuffer->width(), 0, |
| 270 | newBuffer->width() - frameBuffer->width(), |
| 271 | newBuffer->height()); |
| 272 | newBuffer->fillRect(rect, 0); |
| 273 | } |
| 274 | |
| 275 | if (newBuffer->height() > frameBuffer->height()) { |
| 276 | rect.setXYWH(0, frameBuffer->height(), |
| 277 | newBuffer->width(), |
| 278 | newBuffer->height() - frameBuffer->height()); |
| 279 | newBuffer->fillRect(rect, 0); |
| 280 | } |
| 281 | |
| 282 | delete frameBuffer; |
| 283 | frameBuffer = newBuffer; |
| 284 | |
| 285 | end: |
| 286 | Fl_Widget::resize(x, y, w, h); |
| 287 | } |
| 288 | |
| 289 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 290 | int Viewport::handle(int event) |
| 291 | { |
Pierre Ossman | 689c458 | 2011-05-26 15:39:41 +0000 | [diff] [blame] | 292 | char *buffer; |
Pierre Ossman | 4a6be4a | 2011-05-19 14:49:18 +0000 | [diff] [blame] | 293 | int ret; |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 294 | int buttonMask, wheelMask; |
| 295 | DownMap::const_iterator iter; |
| 296 | |
| 297 | switch (event) { |
Pierre Ossman | 4a6be4a | 2011-05-19 14:49:18 +0000 | [diff] [blame] | 298 | case FL_PASTE: |
Pierre Ossman | 689c458 | 2011-05-26 15:39:41 +0000 | [diff] [blame] | 299 | buffer = new char[Fl::event_length() + 1]; |
| 300 | |
Pierre Ossman | 4a6be4a | 2011-05-19 14:49:18 +0000 | [diff] [blame] | 301 | // This is documented as to ASCII, but actually does to 8859-1 |
Pierre Ossman | 689c458 | 2011-05-26 15:39:41 +0000 | [diff] [blame] | 302 | ret = fl_utf8toa(Fl::event_text(), Fl::event_length(), buffer, |
| 303 | Fl::event_length() + 1); |
| 304 | assert(ret < (Fl::event_length() + 1)); |
| 305 | |
Pierre Ossman | 4a6be4a | 2011-05-19 14:49:18 +0000 | [diff] [blame] | 306 | vlog.debug("Sending clipboard data: '%s'", buffer); |
| 307 | cc->writer()->clientCutText(buffer, ret); |
Pierre Ossman | 689c458 | 2011-05-26 15:39:41 +0000 | [diff] [blame] | 308 | |
| 309 | delete [] buffer; |
| 310 | |
Pierre Ossman | 4a6be4a | 2011-05-19 14:49:18 +0000 | [diff] [blame] | 311 | return 1; |
Pierre Ossman | 689c458 | 2011-05-26 15:39:41 +0000 | [diff] [blame] | 312 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 313 | case FL_ENTER: |
| 314 | // Yes, we would like some pointer events please! |
Pierre Ossman | 835b4ef | 2011-06-08 17:02:36 +0000 | [diff] [blame^] | 315 | #ifdef HAVE_FLTK_CURSOR |
| 316 | window()->cursor(cursor, cursorHotspot.x, cursorHotspot.y); |
| 317 | #endif |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 318 | return 1; |
Pierre Ossman | 835b4ef | 2011-06-08 17:02:36 +0000 | [diff] [blame^] | 319 | |
| 320 | case FL_LEAVE: |
| 321 | #ifdef HAVE_FLTK_CURSOR |
| 322 | window()->cursor(FL_CURSOR_DEFAULT); |
| 323 | #endif |
| 324 | return 1; |
| 325 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 326 | case FL_PUSH: |
| 327 | case FL_RELEASE: |
| 328 | case FL_DRAG: |
| 329 | case FL_MOVE: |
| 330 | case FL_MOUSEWHEEL: |
| 331 | buttonMask = 0; |
| 332 | if (Fl::event_button1()) |
| 333 | buttonMask |= 1; |
| 334 | if (Fl::event_button2()) |
| 335 | buttonMask |= 2; |
| 336 | if (Fl::event_button3()) |
| 337 | buttonMask |= 4; |
| 338 | |
| 339 | if (event == FL_MOUSEWHEEL) { |
Pierre Ossman | df0ed9f | 2011-05-24 11:33:43 +0000 | [diff] [blame] | 340 | wheelMask = 0; |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 341 | if (Fl::event_dy() < 0) |
Pierre Ossman | df0ed9f | 2011-05-24 11:33:43 +0000 | [diff] [blame] | 342 | wheelMask |= 8; |
| 343 | if (Fl::event_dy() > 0) |
| 344 | wheelMask |= 16; |
| 345 | if (Fl::event_dx() < 0) |
| 346 | wheelMask |= 32; |
| 347 | if (Fl::event_dx() > 0) |
| 348 | wheelMask |= 64; |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 349 | |
| 350 | // A quick press of the wheel "button", followed by a immediate |
| 351 | // release below |
Pierre Ossman | 6a464be | 2011-04-15 12:57:31 +0000 | [diff] [blame] | 352 | handlePointerEvent(Point(Fl::event_x() - x(), Fl::event_y() - y()), |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 353 | buttonMask | wheelMask); |
| 354 | } |
| 355 | |
Pierre Ossman | 6a464be | 2011-04-15 12:57:31 +0000 | [diff] [blame] | 356 | handlePointerEvent(Point(Fl::event_x() - x(), Fl::event_y() - y()), buttonMask); |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 357 | return 1; |
| 358 | |
| 359 | case FL_FOCUS: |
| 360 | // Yes, we would like some focus please! |
| 361 | return 1; |
| 362 | |
| 363 | case FL_UNFOCUS: |
| 364 | // Release all keys that were pressed as that generally makes most |
| 365 | // sense (e.g. Alt+Tab where we only see the Alt press) |
Pierre Ossman | 71f295a | 2011-05-19 14:55:12 +0000 | [diff] [blame] | 366 | for (iter = downKeySym.begin();iter != downKeySym.end();++iter) { |
| 367 | vlog.debug("Key released: 0x%04x => 0x%04x", iter->first, iter->second); |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 368 | cc->writer()->keyEvent(iter->second, false); |
Pierre Ossman | 71f295a | 2011-05-19 14:55:12 +0000 | [diff] [blame] | 369 | } |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 370 | downKeySym.clear(); |
| 371 | return 1; |
| 372 | |
| 373 | case FL_KEYDOWN: |
Pierre Ossman | 4e7271e | 2011-05-24 12:47:12 +0000 | [diff] [blame] | 374 | if (menuKeyCode && (Fl::event_key() == menuKeyCode)) { |
Pierre Ossman | c7bfaac | 2011-04-29 11:08:11 +0000 | [diff] [blame] | 375 | popupContextMenu(); |
| 376 | return 1; |
| 377 | } |
| 378 | |
Pierre Ossman | cd6ddef | 2011-05-20 12:05:20 +0000 | [diff] [blame] | 379 | handleKeyEvent(Fl::event_key(), Fl::event_original_key(), |
| 380 | Fl::event_text(), true); |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 381 | return 1; |
| 382 | |
| 383 | case FL_KEYUP: |
Pierre Ossman | 4e7271e | 2011-05-24 12:47:12 +0000 | [diff] [blame] | 384 | if (menuKeyCode && (Fl::event_key() == menuKeyCode)) |
| 385 | return 1; |
| 386 | |
Pierre Ossman | cd6ddef | 2011-05-20 12:05:20 +0000 | [diff] [blame] | 387 | handleKeyEvent(Fl::event_key(), Fl::event_original_key(), |
| 388 | Fl::event_text(), false); |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 389 | return 1; |
| 390 | } |
| 391 | |
| 392 | return Fl_Widget::handle(event); |
| 393 | } |
| 394 | |
| 395 | |
| 396 | void Viewport::handleUpdateTimeout(void *data) |
| 397 | { |
| 398 | Viewport *self = (Viewport *)data; |
| 399 | |
| 400 | assert(self); |
| 401 | |
| 402 | self->updateWindow(); |
| 403 | } |
| 404 | |
| 405 | |
| 406 | void Viewport::handleColourMap(void *data) |
| 407 | { |
| 408 | Viewport *self = (Viewport *)data; |
| 409 | |
| 410 | assert(self); |
| 411 | |
| 412 | if (self->pixelTrans != NULL) |
| 413 | self->pixelTrans->setColourMapEntries(0, 0); |
| 414 | |
| 415 | self->Fl_Widget::damage(FL_DAMAGE_ALL); |
| 416 | } |
| 417 | |
| 418 | |
Pierre Ossman | 4a6be4a | 2011-05-19 14:49:18 +0000 | [diff] [blame] | 419 | void Viewport::handleClipboardChange(int source, void *data) |
| 420 | { |
| 421 | Viewport *self = (Viewport *)data; |
| 422 | |
| 423 | assert(self); |
| 424 | |
| 425 | if (!sendPrimary && (source == 0)) |
| 426 | return; |
| 427 | |
| 428 | Fl::paste(*self, source); |
| 429 | } |
| 430 | |
| 431 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 432 | void Viewport::handlePointerEvent(const rfb::Point& pos, int buttonMask) |
| 433 | { |
| 434 | if (!viewOnly) { |
| 435 | if (pointerEventInterval == 0 || buttonMask != lastButtonMask) { |
| 436 | cc->writer()->pointerEvent(pos, buttonMask); |
| 437 | } else { |
| 438 | if (!Fl::has_timeout(handlePointerTimeout, this)) |
| 439 | Fl::add_timeout((double)pointerEventInterval/1000.0, |
| 440 | handlePointerTimeout, this); |
| 441 | } |
| 442 | lastPointerPos = pos; |
| 443 | lastButtonMask = buttonMask; |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | |
| 448 | void Viewport::handlePointerTimeout(void *data) |
| 449 | { |
| 450 | Viewport *self = (Viewport *)data; |
| 451 | |
| 452 | assert(self); |
| 453 | |
| 454 | self->cc->writer()->pointerEvent(self->lastPointerPos, self->lastButtonMask); |
| 455 | } |
| 456 | |
| 457 | |
Pierre Ossman | cd6ddef | 2011-05-20 12:05:20 +0000 | [diff] [blame] | 458 | rdr::U32 Viewport::translateKeyEvent(int keyCode, int origKeyCode, const char *keyText) |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 459 | { |
| 460 | unsigned ucs; |
| 461 | |
| 462 | // First check for function keys |
| 463 | if ((keyCode > FL_F) && (keyCode <= FL_F_Last)) |
| 464 | return XK_F1 + (keyCode - FL_F - 1); |
| 465 | |
| 466 | // Numpad numbers |
| 467 | if ((keyCode >= (FL_KP + '0')) && (keyCode <= (FL_KP + '9'))) |
| 468 | return XK_KP_0 + (keyCode - (FL_KP + '0')); |
| 469 | |
Pierre Ossman | cd6ddef | 2011-05-20 12:05:20 +0000 | [diff] [blame] | 470 | // FLTK does some special remapping of numpad keys when numlock is off |
| 471 | if ((origKeyCode >= FL_KP) && (origKeyCode <= FL_KP_Last)) { |
| 472 | switch (keyCode) { |
| 473 | case FL_F+1: |
| 474 | return XK_KP_F1; |
| 475 | case FL_F+2: |
| 476 | return XK_KP_F2; |
| 477 | case FL_F+3: |
| 478 | return XK_KP_F3; |
| 479 | case FL_F+4: |
| 480 | return XK_KP_F4; |
| 481 | case FL_Home: |
| 482 | return XK_KP_Home; |
| 483 | case FL_Left: |
| 484 | return XK_KP_Left; |
| 485 | case FL_Up: |
| 486 | return XK_KP_Up; |
| 487 | case FL_Right: |
| 488 | return XK_KP_Right; |
| 489 | case FL_Down: |
| 490 | return XK_KP_Down; |
| 491 | case FL_Page_Up: |
| 492 | return XK_KP_Page_Up; |
| 493 | case FL_Page_Down: |
| 494 | return XK_KP_Page_Down; |
| 495 | case FL_End: |
| 496 | return XK_KP_End; |
| 497 | case FL_Insert: |
| 498 | return XK_KP_Insert; |
| 499 | case FL_Delete: |
| 500 | return XK_KP_Delete; |
| 501 | } |
| 502 | } |
| 503 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 504 | // Then other special keys |
| 505 | switch (keyCode) { |
| 506 | case FL_BackSpace: |
| 507 | return XK_BackSpace; |
| 508 | case FL_Tab: |
| 509 | return XK_Tab; |
| 510 | case FL_Enter: |
| 511 | return XK_Return; |
| 512 | case FL_Pause: |
| 513 | return XK_Pause; |
| 514 | case FL_Scroll_Lock: |
| 515 | return XK_Scroll_Lock; |
| 516 | case FL_Escape: |
| 517 | return XK_Escape; |
| 518 | case FL_Home: |
| 519 | return XK_Home; |
| 520 | case FL_Left: |
| 521 | return XK_Left; |
| 522 | case FL_Up: |
| 523 | return XK_Up; |
| 524 | case FL_Right: |
| 525 | return XK_Right; |
| 526 | case FL_Down: |
| 527 | return XK_Down; |
| 528 | case FL_Page_Up: |
| 529 | return XK_Page_Up; |
| 530 | case FL_Page_Down: |
| 531 | return XK_Page_Down; |
| 532 | case FL_End: |
| 533 | return XK_End; |
| 534 | case FL_Print: |
| 535 | return XK_Print; |
| 536 | case FL_Insert: |
| 537 | return XK_Insert; |
| 538 | case FL_Menu: |
| 539 | return XK_Menu; |
| 540 | case FL_Help: |
| 541 | return XK_Help; |
| 542 | case FL_Num_Lock: |
| 543 | return XK_Num_Lock; |
| 544 | case FL_Shift_L: |
| 545 | return XK_Shift_L; |
| 546 | case FL_Shift_R: |
| 547 | return XK_Shift_R; |
| 548 | case FL_Control_L: |
| 549 | return XK_Control_L; |
| 550 | case FL_Control_R: |
| 551 | return XK_Control_R; |
| 552 | case FL_Caps_Lock: |
| 553 | return XK_Caps_Lock; |
| 554 | case FL_Meta_L: |
| 555 | return XK_Super_L; |
| 556 | case FL_Meta_R: |
| 557 | return XK_Super_R; |
| 558 | case FL_Alt_L: |
| 559 | return XK_Alt_L; |
| 560 | case FL_Alt_R: |
| 561 | return XK_Alt_R; |
| 562 | case FL_Delete: |
| 563 | return XK_Delete; |
| 564 | case FL_KP_Enter: |
| 565 | return XK_KP_Enter; |
| 566 | case FL_KP + '=': |
| 567 | return XK_KP_Equal; |
| 568 | case FL_KP + '*': |
| 569 | return XK_KP_Multiply; |
| 570 | case FL_KP + '+': |
| 571 | return XK_KP_Add; |
| 572 | case FL_KP + ',': |
| 573 | return XK_KP_Separator; |
| 574 | case FL_KP + '-': |
| 575 | return XK_KP_Subtract; |
| 576 | case FL_KP + '.': |
| 577 | return XK_KP_Decimal; |
| 578 | case FL_KP + '/': |
| 579 | return XK_KP_Divide; |
Pierre Ossman | cb0cffe | 2011-05-20 14:55:10 +0000 | [diff] [blame] | 580 | #ifdef HAVE_FLTK_MEDIAKEYS |
| 581 | case FL_Volume_Down: |
| 582 | return XF86XK_AudioLowerVolume; |
| 583 | case FL_Volume_Mute: |
| 584 | return XF86XK_AudioMute; |
| 585 | case FL_Volume_Up: |
| 586 | return XF86XK_AudioRaiseVolume; |
| 587 | case FL_Media_Play: |
| 588 | return XF86XK_AudioPlay; |
| 589 | case FL_Media_Stop: |
| 590 | return XF86XK_AudioStop; |
| 591 | case FL_Media_Prev: |
| 592 | return XF86XK_AudioPrev; |
| 593 | case FL_Media_Next: |
| 594 | return XF86XK_AudioNext; |
| 595 | case FL_Home_Page: |
| 596 | return XF86XK_HomePage; |
| 597 | case FL_Mail: |
| 598 | return XF86XK_Mail; |
| 599 | case FL_Search: |
| 600 | return XF86XK_Search; |
| 601 | case FL_Back: |
| 602 | return XF86XK_Back; |
| 603 | case FL_Forward: |
| 604 | return XF86XK_Forward; |
| 605 | case FL_Stop: |
| 606 | return XF86XK_Stop; |
| 607 | case FL_Refresh: |
| 608 | return XF86XK_Refresh; |
| 609 | case FL_Sleep: |
| 610 | return XF86XK_Sleep; |
| 611 | case FL_Favorites: |
| 612 | return XF86XK_Favorites; |
| 613 | #endif |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 614 | case XK_ISO_Level3_Shift: |
| 615 | // FLTK tends to let this one leak through on X11... |
| 616 | return XK_ISO_Level3_Shift; |
Pierre Ossman | a75f8f8 | 2011-04-29 11:12:02 +0000 | [diff] [blame] | 617 | case XK_Multi_key: |
| 618 | // Same for this... |
| 619 | return XK_Multi_key; |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 620 | } |
| 621 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 622 | // Unknown special key? |
| 623 | if (keyText[0] == '\0') { |
| 624 | vlog.error(_("Unknown FLTK key code %d (0x%04x)"), keyCode, keyCode); |
| 625 | return XK_VoidSymbol; |
| 626 | } |
| 627 | |
| 628 | // Look up the symbol the key produces and translate that from Unicode |
| 629 | // to a X11 keysym. |
| 630 | if (fl_utf_nb_char((const unsigned char*)keyText, strlen(keyText)) != 1) { |
| 631 | vlog.error(_("Multiple characters given for key code %d (0x%04x): '%s'"), |
| 632 | keyCode, keyCode, keyText); |
| 633 | return XK_VoidSymbol; |
| 634 | } |
| 635 | |
| 636 | ucs = fl_utf8decode(keyText, NULL, NULL); |
| 637 | return ucs2keysym(ucs); |
| 638 | } |
| 639 | |
| 640 | |
Pierre Ossman | cd6ddef | 2011-05-20 12:05:20 +0000 | [diff] [blame] | 641 | void Viewport::handleKeyEvent(int keyCode, int origKeyCode, const char *keyText, bool down) |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 642 | { |
| 643 | rdr::U32 keySym; |
| 644 | |
| 645 | if (viewOnly) |
| 646 | return; |
| 647 | |
| 648 | // Because of the way keyboards work, we cannot expect to have the same |
| 649 | // symbol on release as when pressed. This breaks the VNC protocol however, |
| 650 | // so we need to keep track of what keysym a key _code_ generated on press |
| 651 | // and send the same on release. |
| 652 | if (!down) { |
| 653 | DownMap::iterator iter; |
| 654 | |
Pierre Ossman | cd6ddef | 2011-05-20 12:05:20 +0000 | [diff] [blame] | 655 | iter = downKeySym.find(origKeyCode); |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 656 | if (iter == downKeySym.end()) { |
Pierre Ossman | cd6ddef | 2011-05-20 12:05:20 +0000 | [diff] [blame] | 657 | vlog.error(_("Unexpected release of FLTK key code %d (0x%04x)"), |
| 658 | origKeyCode, origKeyCode); |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 659 | return; |
| 660 | } |
| 661 | |
Pierre Ossman | cd6ddef | 2011-05-20 12:05:20 +0000 | [diff] [blame] | 662 | vlog.debug("Key released: 0x%04x => 0x%04x", origKeyCode, iter->second); |
Pierre Ossman | 71f295a | 2011-05-19 14:55:12 +0000 | [diff] [blame] | 663 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 664 | cc->writer()->keyEvent(iter->second, false); |
| 665 | |
| 666 | downKeySym.erase(iter); |
| 667 | |
| 668 | return; |
| 669 | } |
| 670 | |
Pierre Ossman | cd6ddef | 2011-05-20 12:05:20 +0000 | [diff] [blame] | 671 | keySym = translateKeyEvent(keyCode, origKeyCode, keyText); |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 672 | if (keySym == XK_VoidSymbol) |
| 673 | return; |
| 674 | |
Pierre Ossman | cd6ddef | 2011-05-20 12:05:20 +0000 | [diff] [blame] | 675 | vlog.debug("Key pressed: 0x%04x (0x%04x) '%s' => 0x%04x", |
| 676 | origKeyCode, keyCode, keyText, keySym); |
Pierre Ossman | 71f295a | 2011-05-19 14:55:12 +0000 | [diff] [blame] | 677 | |
Pierre Ossman | cd6ddef | 2011-05-20 12:05:20 +0000 | [diff] [blame] | 678 | downKeySym[origKeyCode] = keySym; |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 679 | cc->writer()->keyEvent(keySym, down); |
| 680 | } |
Pierre Ossman | c7bfaac | 2011-04-29 11:08:11 +0000 | [diff] [blame] | 681 | |
| 682 | |
| 683 | void Viewport::initContextMenu() |
| 684 | { |
Pierre Ossman | 4e7271e | 2011-05-24 12:47:12 +0000 | [diff] [blame] | 685 | contextMenu->clear(); |
| 686 | |
Pierre Ossman | c7bfaac | 2011-04-29 11:08:11 +0000 | [diff] [blame] | 687 | contextMenu->add(_("Exit viewer"), 0, NULL, (void*)ID_EXIT, FL_MENU_DIVIDER); |
| 688 | |
Pierre Ossman | 4c613d3 | 2011-05-26 14:14:06 +0000 | [diff] [blame] | 689 | #ifdef HAVE_FLTK_FULLSCREEN |
| 690 | contextMenu->add(_("Full screen"), 0, NULL, (void*)ID_FULLSCREEN, FL_MENU_DIVIDER); |
| 691 | #endif |
| 692 | |
Pierre Ossman | c7bfaac | 2011-04-29 11:08:11 +0000 | [diff] [blame] | 693 | contextMenu->add(_("Ctrl"), 0, NULL, (void*)ID_CTRL, FL_MENU_TOGGLE); |
| 694 | contextMenu->add(_("Alt"), 0, NULL, (void*)ID_ALT, FL_MENU_TOGGLE); |
Pierre Ossman | 4e7271e | 2011-05-24 12:47:12 +0000 | [diff] [blame] | 695 | |
| 696 | if (menuKeyCode) { |
| 697 | char sendMenuKey[64]; |
| 698 | snprintf(sendMenuKey, 64, _("Send %s"), (const char *)menuKey); |
| 699 | contextMenu->add(sendMenuKey, 0, NULL, (void*)ID_MENUKEY, 0); |
| 700 | contextMenu->add("Secret shortcut menu key", menuKeyCode, NULL, (void*)ID_MENUKEY, FL_MENU_INVISIBLE); |
| 701 | } |
| 702 | |
Pierre Ossman | c7bfaac | 2011-04-29 11:08:11 +0000 | [diff] [blame] | 703 | contextMenu->add(_("Send Ctrl-Alt-Del"), 0, NULL, (void*)ID_CTRLALTDEL, FL_MENU_DIVIDER); |
| 704 | |
Pierre Ossman | d4c61ce | 2011-04-29 11:18:12 +0000 | [diff] [blame] | 705 | contextMenu->add(_("Refresh screen"), 0, NULL, (void*)ID_REFRESH, FL_MENU_DIVIDER); |
| 706 | |
Pierre Ossman | d463b57 | 2011-05-16 12:04:43 +0000 | [diff] [blame] | 707 | contextMenu->add(_("Options..."), 0, NULL, (void*)ID_OPTIONS, 0); |
Pierre Ossman | 2eb1d11 | 2011-05-16 12:18:08 +0000 | [diff] [blame] | 708 | contextMenu->add(_("Connection info..."), 0, NULL, (void*)ID_INFO, 0); |
Pierre Ossman | b885822 | 2011-04-29 11:51:38 +0000 | [diff] [blame] | 709 | contextMenu->add(_("About TigerVNC viewer..."), 0, NULL, (void*)ID_ABOUT, FL_MENU_DIVIDER); |
| 710 | |
Pierre Ossman | c7bfaac | 2011-04-29 11:08:11 +0000 | [diff] [blame] | 711 | contextMenu->add(_("Dismiss menu"), 0, NULL, (void*)ID_DISMISS, 0); |
| 712 | } |
| 713 | |
| 714 | |
| 715 | void Viewport::popupContextMenu() |
| 716 | { |
| 717 | const Fl_Menu_Item *m; |
Pierre Ossman | c628ba4 | 2011-05-23 12:21:21 +0000 | [diff] [blame] | 718 | char buffer[1024]; |
Pierre Ossman | c7bfaac | 2011-04-29 11:08:11 +0000 | [diff] [blame] | 719 | |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 720 | // FIXME: Hacky workaround for the fact that menus grab and ungrab the |
| 721 | // keyboard. Releasing focus here triggers some events on ungrab |
| 722 | // that DesktopWindow can catch and trigger some voodoo. |
| 723 | // See DesktopWindow::handle(). |
| 724 | if (window()->contains(Fl::focus())) |
| 725 | Fl::focus(NULL); |
| 726 | |
Pierre Ossman | b3ff437 | 2011-06-03 11:45:15 +0000 | [diff] [blame] | 727 | // Make sure the menu is reset to its initial state between goes or |
| 728 | // it will start up highlighting the previously selected entry. |
| 729 | contextMenu->value(-1); |
| 730 | |
Pierre Ossman | c7bfaac | 2011-04-29 11:08:11 +0000 | [diff] [blame] | 731 | m = contextMenu->popup(); |
| 732 | if (m == NULL) |
| 733 | return; |
| 734 | |
| 735 | switch (m->argument()) { |
| 736 | case ID_EXIT: |
| 737 | exit_vncviewer(); |
| 738 | break; |
Pierre Ossman | 4c613d3 | 2011-05-26 14:14:06 +0000 | [diff] [blame] | 739 | #ifdef HAVE_FLTK_FULLSCREEN |
| 740 | case ID_FULLSCREEN: |
| 741 | if (window()->fullscreen_active()) |
| 742 | window()->fullscreen_off(); |
| 743 | else |
| 744 | window()->fullscreen(); |
| 745 | break; |
| 746 | #endif |
Pierre Ossman | c7bfaac | 2011-04-29 11:08:11 +0000 | [diff] [blame] | 747 | case ID_CTRL: |
| 748 | if (!viewOnly) |
| 749 | cc->writer()->keyEvent(XK_Control_L, m->value()); |
| 750 | break; |
| 751 | case ID_ALT: |
| 752 | if (!viewOnly) |
| 753 | cc->writer()->keyEvent(XK_Alt_L, m->value()); |
| 754 | break; |
| 755 | case ID_MENUKEY: |
| 756 | if (!viewOnly) { |
Pierre Ossman | 4e7271e | 2011-05-24 12:47:12 +0000 | [diff] [blame] | 757 | handleKeyEvent(menuKeyCode, menuKeyCode, "", true); |
| 758 | handleKeyEvent(menuKeyCode, menuKeyCode, "", false); |
Pierre Ossman | c7bfaac | 2011-04-29 11:08:11 +0000 | [diff] [blame] | 759 | } |
| 760 | break; |
| 761 | case ID_CTRLALTDEL: |
| 762 | if (!viewOnly) { |
| 763 | cc->writer()->keyEvent(XK_Control_L, true); |
| 764 | cc->writer()->keyEvent(XK_Alt_L, true); |
| 765 | cc->writer()->keyEvent(XK_Delete, true); |
| 766 | cc->writer()->keyEvent(XK_Delete, false); |
| 767 | cc->writer()->keyEvent(XK_Alt_L, false); |
| 768 | cc->writer()->keyEvent(XK_Control_L, false); |
| 769 | } |
| 770 | break; |
Pierre Ossman | d4c61ce | 2011-04-29 11:18:12 +0000 | [diff] [blame] | 771 | case ID_REFRESH: |
| 772 | cc->refreshFramebuffer(); |
| 773 | break; |
Pierre Ossman | d463b57 | 2011-05-16 12:04:43 +0000 | [diff] [blame] | 774 | case ID_OPTIONS: |
| 775 | OptionsDialog::showDialog(); |
| 776 | break; |
Pierre Ossman | 2eb1d11 | 2011-05-16 12:18:08 +0000 | [diff] [blame] | 777 | case ID_INFO: |
Pierre Ossman | c628ba4 | 2011-05-23 12:21:21 +0000 | [diff] [blame] | 778 | if (fltk_escape(cc->connectionInfo(), buffer, sizeof(buffer)) < sizeof(buffer)) { |
| 779 | fl_message_title(_("VNC connection info")); |
| 780 | fl_message(buffer); |
| 781 | } |
Pierre Ossman | 2eb1d11 | 2011-05-16 12:18:08 +0000 | [diff] [blame] | 782 | break; |
Pierre Ossman | b885822 | 2011-04-29 11:51:38 +0000 | [diff] [blame] | 783 | case ID_ABOUT: |
| 784 | about_vncviewer(); |
| 785 | break; |
Pierre Ossman | c7bfaac | 2011-04-29 11:08:11 +0000 | [diff] [blame] | 786 | case ID_DISMISS: |
| 787 | // Don't need to do anything |
| 788 | break; |
| 789 | } |
| 790 | } |
Pierre Ossman | 4e7271e | 2011-05-24 12:47:12 +0000 | [diff] [blame] | 791 | |
| 792 | |
| 793 | void Viewport::setMenuKey() |
| 794 | { |
| 795 | const char *menuKeyStr; |
| 796 | |
| 797 | menuKeyCode = 0; |
| 798 | |
| 799 | menuKeyStr = menuKey; |
| 800 | if (menuKeyStr[0] == 'F') { |
| 801 | int num = atoi(menuKeyStr + 1); |
| 802 | if ((num >= 1) && (num <= 12)) |
| 803 | menuKeyCode = FL_F + num; |
| 804 | } |
| 805 | |
| 806 | // Need to repopulate the context menu as it contains references to |
| 807 | // the menu key |
| 808 | initContextMenu(); |
| 809 | } |
| 810 | |
| 811 | |
| 812 | void Viewport::handleOptions(void *data) |
| 813 | { |
| 814 | Viewport *self = (Viewport*)data; |
| 815 | |
| 816 | self->setMenuKey(); |
| 817 | } |