Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +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 | |
Peter Åstrand | c359f36 | 2011-08-23 12:04:46 +0000 | [diff] [blame] | 20 | #ifdef HAVE_CONFIG_H |
| 21 | #include <config.h> |
| 22 | #endif |
| 23 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 24 | #include <assert.h> |
| 25 | #include <stdio.h> |
| 26 | #include <string.h> |
| 27 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 28 | #include <rfb/LogWriter.h> |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 29 | #include <rfb/CMsgWriter.h> |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 30 | |
| 31 | #include "DesktopWindow.h" |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 32 | #include "OptionsDialog.h" |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 33 | #include "i18n.h" |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 34 | #include "parameters.h" |
Pierre Ossman | 39ceb50 | 2011-07-12 15:54:25 +0000 | [diff] [blame] | 35 | #include "vncviewer.h" |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 36 | #include "CConn.h" |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 37 | |
DRC | b65bb93 | 2011-06-24 03:17:00 +0000 | [diff] [blame] | 38 | #include <FL/Fl_Scroll.H> |
| 39 | #include <FL/x.H> |
| 40 | |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 41 | #ifdef WIN32 |
| 42 | #include "win32.h" |
| 43 | #endif |
| 44 | |
| 45 | #ifdef __APPLE__ |
| 46 | #include "cocoa.h" |
| 47 | #endif |
Pierre Ossman | 89f868a | 2011-04-11 11:59:31 +0000 | [diff] [blame] | 48 | |
Pierre Ossman | 1d867b6 | 2012-09-03 09:25:07 +0000 | [diff] [blame] | 49 | #define EDGE_SCROLL_SIZE 32 |
| 50 | #define EDGE_SCROLL_SPEED 20 |
| 51 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 52 | using namespace rfb; |
| 53 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 54 | static rfb::LogWriter vlog("DesktopWindow"); |
| 55 | |
| 56 | DesktopWindow::DesktopWindow(int w, int h, const char *name, |
| 57 | const rfb::PixelFormat& serverPF, |
| 58 | CConn* cc_) |
Pierre Ossman | 4c4b66f | 2012-08-23 14:53:36 +0000 | [diff] [blame] | 59 | : Fl_Window(w, h), cc(cc_), firstUpdate(true), |
| 60 | delayedFullscreen(false), delayedDesktopSize(false) |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 61 | { |
Pierre Ossman | 1d867b6 | 2012-09-03 09:25:07 +0000 | [diff] [blame] | 62 | scroll = new Fl_Scroll(0, 0, w, h); |
Pierre Ossman | 4ae229f | 2011-04-15 12:58:31 +0000 | [diff] [blame] | 63 | scroll->color(FL_BLACK); |
| 64 | |
| 65 | // Automatically adjust the scroll box to the window |
| 66 | resizable(scroll); |
| 67 | |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 68 | viewport = new Viewport(w, h, serverPF, cc); |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 69 | |
Pierre Ossman | 4ae229f | 2011-04-15 12:58:31 +0000 | [diff] [blame] | 70 | scroll->end(); |
| 71 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 72 | callback(handleClose, this); |
| 73 | |
| 74 | setName(name); |
| 75 | |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 76 | OptionsDialog::addCallback(handleOptions, this); |
| 77 | |
Pierre Ossman | a4f0f18 | 2011-06-14 13:36:57 +0000 | [diff] [blame] | 78 | // Hack. See below... |
| 79 | Fl::event_dispatch(&fltkHandle); |
| 80 | |
Peter Åstrand | c6cdc1f | 2012-08-29 07:14:31 +0000 | [diff] [blame] | 81 | // Support for -geometry option. Note that although we do support |
| 82 | // negative coordinates, we do not support -XOFF-YOFF (ie |
| 83 | // coordinates relative to the right edge / bottom edge) at this |
| 84 | // time. |
| 85 | int geom_x = 0, geom_y = 0; |
| 86 | if (geometry.hasBeenSet()) { |
| 87 | int matched; |
| 88 | matched = sscanf(geometry.getValueStr(), "+%d+%d", &geom_x, &geom_y); |
| 89 | if (matched == 2) { |
| 90 | force_position(1); |
| 91 | } else { |
| 92 | int geom_w, geom_h; |
| 93 | matched = sscanf(geometry.getValueStr(), "%dx%d+%d+%d", &geom_w, &geom_h, &geom_x, &geom_y); |
| 94 | switch (matched) { |
| 95 | case 4: |
| 96 | force_position(1); |
| 97 | /* fall through */ |
| 98 | case 2: |
| 99 | w = geom_w; |
| 100 | h = geom_h; |
| 101 | break; |
| 102 | default: |
| 103 | geom_x = geom_y = 0; |
| 104 | vlog.error("Invalid geometry specified!"); |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
Peter Åstrand | c6cdc1f | 2012-08-29 07:14:31 +0000 | [diff] [blame] | 109 | if (force_position()) { |
| 110 | resize(geom_x, geom_y, w, h); |
| 111 | } else { |
| 112 | size(w, h); |
| 113 | } |
| 114 | |
Pierre Ossman | 63ca58e | 2011-05-26 14:59:32 +0000 | [diff] [blame] | 115 | #ifdef HAVE_FLTK_FULLSCREEN |
Pierre Ossman | 4c4b66f | 2012-08-23 14:53:36 +0000 | [diff] [blame] | 116 | if (fullScreen) { |
| 117 | // Hack: Window managers seem to be rather crappy at respecting |
| 118 | // fullscreen hints on initial windows. So on X11 we'll have to |
| 119 | // wait until after we've been mapped. |
| 120 | #if defined(WIN32) || defined(__APPLE__) |
Pierre Ossman | aae3891 | 2012-07-13 11:22:55 +0000 | [diff] [blame] | 121 | fullscreen_on(); |
Pierre Ossman | 4c4b66f | 2012-08-23 14:53:36 +0000 | [diff] [blame] | 122 | #else |
| 123 | delayedFullscreen = true; |
| 124 | #endif |
Peter Åstrand | d62482e | 2011-08-02 08:33:27 +0000 | [diff] [blame] | 125 | } |
Peter Åstrand | c6cdc1f | 2012-08-29 07:14:31 +0000 | [diff] [blame] | 126 | #endif |
Pierre Ossman | 63ca58e | 2011-05-26 14:59:32 +0000 | [diff] [blame] | 127 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 128 | show(); |
Pierre Ossman | 3f6c4d0 | 2011-04-15 14:09:09 +0000 | [diff] [blame] | 129 | |
Peter Åstrand | 49b1157 | 2012-08-01 08:09:09 +0000 | [diff] [blame] | 130 | // Unfortunately, current FLTK does not allow us to set the |
| 131 | // maximized property before showing the window. See STR #2083 and |
| 132 | // STR #2178 |
| 133 | if (maximize) { |
| 134 | maximizeWindow(); |
| 135 | } |
| 136 | |
Pierre Ossman | 3f6c4d0 | 2011-04-15 14:09:09 +0000 | [diff] [blame] | 137 | // The window manager might give us an initial window size that is different |
| 138 | // than the one we requested, and in those cases we need to manually adjust |
| 139 | // the scroll widget for things to behave sanely. |
| 140 | if ((w != this->w()) || (h != this->h())) |
| 141 | scroll->size(this->w(), this->h()); |
Pierre Ossman | 4c4b66f | 2012-08-23 14:53:36 +0000 | [diff] [blame] | 142 | |
| 143 | #ifdef HAVE_FLTK_FULLSCREEN |
| 144 | if (delayedFullscreen) { |
| 145 | // Hack: Fullscreen requests may be ignored, so we need a timeout for |
| 146 | // when we should stop waiting. We also really need to wait for the |
| 147 | // resize, which can come after the fullscreen event. |
| 148 | Fl::add_timeout(0.5, handleFullscreenTimeout, this); |
| 149 | fullscreen_on(); |
| 150 | } |
| 151 | #endif |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | |
| 155 | DesktopWindow::~DesktopWindow() |
| 156 | { |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 157 | // Unregister all timeouts in case they get a change tro trigger |
| 158 | // again later when this object is already gone. |
| 159 | Fl::remove_timeout(handleGrab, this); |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 160 | Fl::remove_timeout(handleResizeTimeout, this); |
Pierre Ossman | 4c4b66f | 2012-08-23 14:53:36 +0000 | [diff] [blame] | 161 | Fl::remove_timeout(handleFullscreenTimeout, this); |
Pierre Ossman | 1d867b6 | 2012-09-03 09:25:07 +0000 | [diff] [blame] | 162 | Fl::remove_timeout(handleEdgeScroll, this); |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 163 | |
| 164 | OptionsDialog::removeCallback(handleOptions); |
| 165 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 166 | // FLTK automatically deletes all child widgets, so we shouldn't touch |
| 167 | // them ourselves here |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | |
| 171 | void DesktopWindow::setServerPF(const rfb::PixelFormat& pf) |
| 172 | { |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 173 | viewport->setServerPF(pf); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | |
| 177 | const rfb::PixelFormat &DesktopWindow::getPreferredPF() |
| 178 | { |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 179 | return viewport->getPreferredPF(); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 183 | void DesktopWindow::setName(const char *name) |
| 184 | { |
| 185 | CharArray windowNameStr; |
| 186 | windowNameStr.replaceBuf(new char[256]); |
| 187 | |
Pierre Ossman | 27820ba | 2011-09-30 12:54:24 +0000 | [diff] [blame] | 188 | snprintf(windowNameStr.buf, 256, "%.240s - TigerVNC", name); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 189 | |
| 190 | copy_label(windowNameStr.buf); |
| 191 | } |
| 192 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 193 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 194 | void DesktopWindow::setColourMapEntries(int firstColour, int nColours, |
| 195 | rdr::U16* rgbs) |
| 196 | { |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 197 | viewport->setColourMapEntries(firstColour, nColours, rgbs); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | |
| 201 | // Copy the areas of the framebuffer that have been changed (damaged) |
| 202 | // to the displayed window. |
| 203 | |
| 204 | void DesktopWindow::updateWindow() |
| 205 | { |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 206 | if (firstUpdate) { |
Pierre Ossman | 4c4b66f | 2012-08-23 14:53:36 +0000 | [diff] [blame] | 207 | if (cc->cp.supportsSetDesktopSize) { |
| 208 | // Hack: Wait until we're in the proper mode and position until |
| 209 | // resizing things, otherwise we might send the wrong thing. |
| 210 | if (delayedFullscreen) |
| 211 | delayedDesktopSize = true; |
| 212 | else |
| 213 | handleDesktopSize(); |
| 214 | } |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 215 | firstUpdate = false; |
| 216 | } |
| 217 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 218 | viewport->updateWindow(); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | |
Pierre Ossman | 6455d85 | 2011-06-01 09:33:00 +0000 | [diff] [blame] | 222 | void DesktopWindow::resizeFramebuffer(int new_w, int new_h) |
| 223 | { |
| 224 | if ((new_w == viewport->w()) && (new_h == viewport->h())) |
| 225 | return; |
| 226 | |
Pierre Ossman | 6455d85 | 2011-06-01 09:33:00 +0000 | [diff] [blame] | 227 | // If we're letting the viewport match the window perfectly, then |
| 228 | // keep things that way for the new size, otherwise just keep things |
| 229 | // like they are. |
Peter Åstrand | 1d03cbc | 2011-08-01 10:34:38 +0000 | [diff] [blame] | 230 | #ifdef HAVE_FLTK_FULLSCREEN |
| 231 | if (!fullscreen_active()) { |
| 232 | #endif |
Pierre Ossman | 29e4a16 | 2011-11-21 14:03:31 +0000 | [diff] [blame] | 233 | if ((w() == viewport->w()) && (h() == viewport->h())) |
| 234 | size(new_w, new_h); |
| 235 | else { |
| 236 | // Make sure the window isn't too big. We do this manually because |
| 237 | // we have to disable the window size restriction (and it isn't |
| 238 | // entirely trustworthy to begin with). |
Pierre Ossman | 6455d85 | 2011-06-01 09:33:00 +0000 | [diff] [blame] | 239 | if ((w() > new_w) || (h() > new_h)) |
| 240 | size(__rfbmin(w(), new_w), __rfbmin(h(), new_h)); |
Pierre Ossman | 29e4a16 | 2011-11-21 14:03:31 +0000 | [diff] [blame] | 241 | } |
Peter Åstrand | 1d03cbc | 2011-08-01 10:34:38 +0000 | [diff] [blame] | 242 | #ifdef HAVE_FLTK_FULLSCREEN |
| 243 | } |
| 244 | #endif |
Pierre Ossman | 6455d85 | 2011-06-01 09:33:00 +0000 | [diff] [blame] | 245 | |
| 246 | viewport->size(new_w, new_h); |
| 247 | |
| 248 | // We might not resize the main window, so we need to manually call this |
| 249 | // to make sure the viewport is centered. |
| 250 | repositionViewport(); |
| 251 | |
Pierre Ossman | 6455d85 | 2011-06-01 09:33:00 +0000 | [diff] [blame] | 252 | // repositionViewport() makes sure the scroll widget notices any changes |
| 253 | // in position, but it might be just the size that changes so we also |
| 254 | // need a poke here as well. |
| 255 | redraw(); |
| 256 | } |
| 257 | |
| 258 | |
Pierre Ossman | 835b4ef | 2011-06-08 17:02:36 +0000 | [diff] [blame] | 259 | void DesktopWindow::setCursor(int width, int height, const Point& hotspot, |
| 260 | void* data, void* mask) |
| 261 | { |
| 262 | viewport->setCursor(width, height, hotspot, data, mask); |
| 263 | } |
| 264 | |
| 265 | |
Pierre Ossman | 4ae229f | 2011-04-15 12:58:31 +0000 | [diff] [blame] | 266 | void DesktopWindow::resize(int x, int y, int w, int h) |
| 267 | { |
Pierre Ossman | 9f32e3c | 2012-08-23 14:40:52 +0000 | [diff] [blame] | 268 | bool resizing; |
| 269 | |
Pierre Ossman | 0e59346 | 2012-09-03 09:43:23 +0000 | [diff] [blame^] | 270 | #if ! (defined(WIN32) || defined(__APPLE__)) |
| 271 | // X11 window managers will treat a resize to cover the entire |
| 272 | // monitor as a request to go full screen. Make sure we avoid this. |
| 273 | // |
| 274 | // FIXME: If this is an external event then this code will get |
| 275 | // FLTK into a confused state about the window's position/size. |
| 276 | // Unfortunately FLTK doesn't offer an easy way to tell |
| 277 | // what kind of resize it is. Let's hope this corner case |
| 278 | // isn't too common... |
| 279 | #ifdef HAVE_FLTK_FULLSCREEN |
| 280 | if (!fullscreen_active()) |
| 281 | #endif |
| 282 | { |
| 283 | for (int i = 0;i < Fl::screen_count();i++) { |
| 284 | int sx, sy, sw, sh; |
| 285 | |
| 286 | Fl::screen_xywh(sx, sy, sw, sh, i); |
| 287 | |
| 288 | if ((sx == x) && (sy == y) && (sw == w) && (sh == h)) { |
| 289 | vlog.info("Adjusting window size to avoid accidental full screen request"); |
| 290 | // Assume a panel of some form and adjust the height |
| 291 | y += 20; |
| 292 | h -= 40; |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | #endif |
| 297 | |
Pierre Ossman | 9f32e3c | 2012-08-23 14:40:52 +0000 | [diff] [blame] | 298 | if ((this->w() != w) || (this->h() != h)) |
| 299 | resizing = true; |
| 300 | else |
| 301 | resizing = false; |
| 302 | |
Pierre Ossman | 4ae229f | 2011-04-15 12:58:31 +0000 | [diff] [blame] | 303 | Fl_Window::resize(x, y, w, h); |
Pierre Ossman | 6455d85 | 2011-06-01 09:33:00 +0000 | [diff] [blame] | 304 | |
Pierre Ossman | 9f32e3c | 2012-08-23 14:40:52 +0000 | [diff] [blame] | 305 | if (resizing) { |
| 306 | // Try to get the remote size to match our window size, provided |
| 307 | // the following conditions are true: |
| 308 | // |
| 309 | // a) The user has this feature turned on |
| 310 | // b) The server supports it |
| 311 | // c) We're not still waiting for a chance to handle DesktopSize |
Pierre Ossman | 4c4b66f | 2012-08-23 14:53:36 +0000 | [diff] [blame] | 312 | // d) We're not still waiting for startup fullscreen to kick in |
Pierre Ossman | 9f32e3c | 2012-08-23 14:40:52 +0000 | [diff] [blame] | 313 | // |
Pierre Ossman | 4c4b66f | 2012-08-23 14:53:36 +0000 | [diff] [blame] | 314 | if (not firstUpdate and not delayedFullscreen and |
| 315 | ::remoteResize and cc->cp.supportsSetDesktopSize) { |
Pierre Ossman | 9f32e3c | 2012-08-23 14:40:52 +0000 | [diff] [blame] | 316 | // We delay updating the remote desktop as we tend to get a flood |
| 317 | // of resize events as the user is dragging the window. |
| 318 | Fl::remove_timeout(handleResizeTimeout, this); |
| 319 | Fl::add_timeout(0.5, handleResizeTimeout, this); |
| 320 | } |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 321 | |
Pierre Ossman | 9f32e3c | 2012-08-23 14:40:52 +0000 | [diff] [blame] | 322 | // Deal with some scrolling corner cases |
| 323 | repositionViewport(); |
| 324 | } |
Pierre Ossman | 4ae229f | 2011-04-15 12:58:31 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 328 | int DesktopWindow::handle(int event) |
| 329 | { |
| 330 | switch (event) { |
| 331 | #ifdef HAVE_FLTK_FULLSCREEN |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 332 | case FL_FULLSCREEN: |
Pierre Ossman | 29e4a16 | 2011-11-21 14:03:31 +0000 | [diff] [blame] | 333 | fullScreen.setParam(fullscreen_active()); |
| 334 | |
Pierre Ossman | 1d867b6 | 2012-09-03 09:25:07 +0000 | [diff] [blame] | 335 | if (fullscreen_active()) |
| 336 | scroll->type(0); |
| 337 | else |
| 338 | scroll->type(Fl_Scroll::BOTH); |
| 339 | |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 340 | if (!fullscreenSystemKeys) |
| 341 | break; |
| 342 | |
| 343 | if (fullscreen_active()) |
| 344 | grabKeyboard(); |
| 345 | else |
| 346 | ungrabKeyboard(); |
| 347 | |
| 348 | break; |
Pierre Ossman | 1d867b6 | 2012-09-03 09:25:07 +0000 | [diff] [blame] | 349 | |
| 350 | case FL_ENTER: |
| 351 | case FL_LEAVE: |
| 352 | case FL_DRAG: |
| 353 | case FL_MOVE: |
| 354 | if (fullscreen_active()) { |
| 355 | if (((viewport->x() < 0) && (Fl::event_x() < EDGE_SCROLL_SIZE)) || |
| 356 | ((viewport->x() + viewport->w() > w()) && (Fl::event_x() > w() - EDGE_SCROLL_SIZE)) || |
| 357 | ((viewport->y() < 0) && (Fl::event_y() < EDGE_SCROLL_SIZE)) || |
| 358 | ((viewport->y() + viewport->h() > h()) && (Fl::event_y() > h() - EDGE_SCROLL_SIZE))) { |
| 359 | if (!Fl::has_timeout(handleEdgeScroll, this)) |
| 360 | Fl::add_timeout(0.1, handleEdgeScroll, this); |
| 361 | } |
| 362 | } |
| 363 | return 1; |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 364 | #endif |
Pierre Ossman | 1d867b6 | 2012-09-03 09:25:07 +0000 | [diff] [blame] | 365 | |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 366 | case FL_SHORTCUT: |
| 367 | // Sometimes the focus gets out of whack and we fall through to the |
| 368 | // shortcut dispatching. Try to make things sane again... |
| 369 | if (Fl::focus() == NULL) { |
| 370 | take_focus(); |
| 371 | Fl::handle(FL_KEYDOWN, this); |
| 372 | } |
| 373 | return 1; |
| 374 | } |
| 375 | |
| 376 | return Fl_Window::handle(event); |
| 377 | } |
| 378 | |
| 379 | |
Pierre Ossman | a4f0f18 | 2011-06-14 13:36:57 +0000 | [diff] [blame] | 380 | int DesktopWindow::fltkHandle(int event, Fl_Window *win) |
| 381 | { |
| 382 | int ret; |
| 383 | |
| 384 | ret = Fl::handle_(event, win); |
| 385 | |
| 386 | #ifdef HAVE_FLTK_FULLSCREEN |
| 387 | // This is hackish and the result of the dodgy focus handling in FLTK. |
| 388 | // The basic problem is that FLTK's view of focus and the system's tend |
| 389 | // to differ, and as a result we do not see all the FL_FOCUS events we |
| 390 | // need. Fortunately we can grab them here... |
| 391 | |
| 392 | DesktopWindow *dw = dynamic_cast<DesktopWindow*>(win); |
| 393 | |
| 394 | if (dw && fullscreenSystemKeys) { |
| 395 | switch (event) { |
| 396 | case FL_FOCUS: |
| 397 | // FIXME: We reassert the keyboard grabbing on focus as FLTK there are |
| 398 | // some issues we need to work around: |
| 399 | // a) Fl::grab(0) on X11 will release the keyboard grab for us. |
| 400 | // b) Gaining focus on the system level causes FLTK to switch |
| 401 | // window level on OS X. |
| 402 | if (dw->fullscreen_active()) |
| 403 | dw->grabKeyboard(); |
| 404 | break; |
| 405 | |
| 406 | case FL_UNFOCUS: |
| 407 | // FIXME: We need to relinquish control when the entire window loses |
| 408 | // focus as it is very tied to this specific window on some |
| 409 | // platforms and we want to be able to open subwindows. |
| 410 | dw->ungrabKeyboard(); |
| 411 | break; |
| 412 | } |
| 413 | } |
| 414 | #endif |
| 415 | |
| 416 | return ret; |
| 417 | } |
| 418 | |
| 419 | |
Pierre Ossman | aae3891 | 2012-07-13 11:22:55 +0000 | [diff] [blame] | 420 | void DesktopWindow::fullscreen_on() |
| 421 | { |
| 422 | #ifdef HAVE_FLTK_FULLSCREEN |
| 423 | #ifdef HAVE_FLTK_FULLSCREEN_SCREENS |
| 424 | if (not fullScreenAllMonitors) |
| 425 | fullscreen_screens(-1, -1, -1, -1); |
| 426 | else { |
| 427 | int top, bottom, left, right; |
| 428 | int top_y, bottom_y, left_x, right_x; |
| 429 | |
| 430 | int sx, sy, sw, sh; |
| 431 | |
| 432 | top = bottom = left = right = 0; |
| 433 | |
| 434 | Fl::screen_xywh(sx, sy, sw, sh, 0); |
| 435 | top_y = sy; |
| 436 | bottom_y = sy + sh; |
| 437 | left_x = sx; |
| 438 | right_x = sx + sw; |
| 439 | |
| 440 | for (int i = 1;i < Fl::screen_count();i++) { |
| 441 | Fl::screen_xywh(sx, sy, sw, sh, i); |
| 442 | if (sy < top_y) { |
| 443 | top = i; |
| 444 | top_y = sy; |
| 445 | } |
| 446 | if ((sy + sh) > bottom_y) { |
| 447 | bottom = i; |
| 448 | bottom_y = sy + sh; |
| 449 | } |
| 450 | if (sx < left_x) { |
| 451 | left = i; |
| 452 | left_x = sx; |
| 453 | } |
| 454 | if ((sx + sw) > right_x) { |
| 455 | right = i; |
| 456 | right_x = sx + sw; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | fullscreen_screens(top, bottom, left, right); |
| 461 | } |
| 462 | #endif // HAVE_FLTK_FULLSCREEN_SCREENS |
| 463 | |
| 464 | fullscreen(); |
| 465 | #endif // HAVE_FLTK_FULLSCREEN |
| 466 | } |
| 467 | |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 468 | void DesktopWindow::grabKeyboard() |
| 469 | { |
| 470 | // Grabbing the keyboard is fairly safe as FLTK reroutes events to the |
| 471 | // correct widget regardless of which low level window got the system |
| 472 | // event. |
| 473 | |
| 474 | // FIXME: Push this stuff into FLTK. |
| 475 | |
| 476 | #if defined(WIN32) |
| 477 | int ret; |
| 478 | |
| 479 | ret = win32_enable_lowlevel_keyboard(fl_xid(this)); |
| 480 | if (ret != 0) |
| 481 | vlog.error(_("Failure grabbing keyboard")); |
| 482 | #elif defined(__APPLE__) |
| 483 | int ret; |
| 484 | |
Pierre Ossman | 3d75911 | 2012-08-27 14:40:51 +0000 | [diff] [blame] | 485 | ret = cocoa_capture_display(this, |
| 486 | #ifdef HAVE_FLTK_FULLSCREEN_SCREENS |
| 487 | fullScreenAllMonitors |
| 488 | #else |
| 489 | false |
| 490 | #endif |
| 491 | ); |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 492 | if (ret != 0) |
| 493 | vlog.error(_("Failure grabbing keyboard")); |
| 494 | #else |
| 495 | int ret; |
| 496 | |
| 497 | ret = XGrabKeyboard(fl_display, fl_xid(this), True, |
Peter Åstrand | f52860b | 2011-07-18 07:42:16 +0000 | [diff] [blame] | 498 | GrabModeAsync, GrabModeAsync, CurrentTime); |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 499 | if (ret) { |
| 500 | if (ret == AlreadyGrabbed) { |
| 501 | // It seems like we can race with the WM in some cases. |
| 502 | // Try again in a bit. |
| 503 | if (!Fl::has_timeout(handleGrab, this)) |
| 504 | Fl::add_timeout(0.500, handleGrab, this); |
| 505 | } else { |
| 506 | vlog.error(_("Failure grabbing keyboard")); |
| 507 | } |
| 508 | } |
Pierre Ossman | 53fd544 | 2011-11-17 10:19:19 +0000 | [diff] [blame] | 509 | |
| 510 | // We also need to grab the pointer as some WMs like to grab buttons |
| 511 | // combined with modifies (e.g. Alt+Button0 in metacity). |
| 512 | ret = XGrabPointer(fl_display, fl_xid(this), True, |
| 513 | ButtonPressMask|ButtonReleaseMask| |
| 514 | ButtonMotionMask|PointerMotionMask, |
| 515 | GrabModeAsync, GrabModeAsync, |
| 516 | None, None, CurrentTime); |
| 517 | if (ret) |
| 518 | vlog.error(_("Failure grabbing mouse")); |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 519 | #endif |
| 520 | } |
| 521 | |
| 522 | |
| 523 | void DesktopWindow::ungrabKeyboard() |
| 524 | { |
| 525 | Fl::remove_timeout(handleGrab, this); |
| 526 | |
| 527 | #if defined(WIN32) |
| 528 | win32_disable_lowlevel_keyboard(fl_xid(this)); |
| 529 | #elif defined(__APPLE__) |
| 530 | cocoa_release_display(this); |
| 531 | #else |
| 532 | // FLTK has a grab so lets not mess with it |
| 533 | if (Fl::grab()) |
| 534 | return; |
| 535 | |
Pierre Ossman | 53fd544 | 2011-11-17 10:19:19 +0000 | [diff] [blame] | 536 | XUngrabPointer(fl_display, fl_event_time); |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 537 | XUngrabKeyboard(fl_display, fl_event_time); |
| 538 | #endif |
| 539 | } |
| 540 | |
| 541 | |
| 542 | void DesktopWindow::handleGrab(void *data) |
| 543 | { |
| 544 | DesktopWindow *self = (DesktopWindow*)data; |
| 545 | |
| 546 | assert(self); |
| 547 | |
| 548 | #ifdef HAVE_FLTK_FULLSCREEN |
| 549 | if (!fullscreenSystemKeys) |
| 550 | return; |
| 551 | if (!self->fullscreen_active()) |
| 552 | return; |
| 553 | |
| 554 | self->grabKeyboard(); |
| 555 | #endif |
| 556 | } |
| 557 | |
| 558 | |
Peter Åstrand | 49b1157 | 2012-08-01 08:09:09 +0000 | [diff] [blame] | 559 | #define _NET_WM_STATE_ADD 1 /* add/set property */ |
| 560 | void DesktopWindow::maximizeWindow() |
| 561 | { |
| 562 | #if defined(WIN32) |
| 563 | WINDOWPLACEMENT wp; |
| 564 | wp.length = sizeof(WINDOWPLACEMENT); |
| 565 | GetWindowPlacement(fl_xid(this), &wp); |
| 566 | wp.showCmd = SW_MAXIMIZE; |
| 567 | SetWindowPlacement(fl_xid(this), &wp); |
| 568 | #elif defined(__APPLE__) |
| 569 | /* OS X is somewhat strange and does not really have a concept of a |
| 570 | maximized window, so we can simply resize the window to the workarea */ |
| 571 | int X, Y, W, H; |
| 572 | Fl::screen_work_area(X, Y, W, H, this->x(), this->y()); |
| 573 | size(W, H); |
| 574 | #else |
| 575 | // X11 |
| 576 | fl_open_display(); |
| 577 | Atom net_wm_state = XInternAtom (fl_display, "_NET_WM_STATE", 0); |
| 578 | Atom net_wm_state_maximized_vert = XInternAtom (fl_display, "_NET_WM_STATE_MAXIMIZED_VERT", 0); |
| 579 | Atom net_wm_state_maximized_horz = XInternAtom (fl_display, "_NET_WM_STATE_MAXIMIZED_HORZ", 0); |
| 580 | |
| 581 | XEvent e; |
| 582 | e.xany.type = ClientMessage; |
| 583 | e.xany.window = fl_xid(this); |
| 584 | e.xclient.message_type = net_wm_state; |
| 585 | e.xclient.format = 32; |
| 586 | e.xclient.data.l[0] = _NET_WM_STATE_ADD; |
| 587 | e.xclient.data.l[1] = net_wm_state_maximized_vert; |
| 588 | e.xclient.data.l[2] = net_wm_state_maximized_horz; |
| 589 | e.xclient.data.l[3] = 0; |
| 590 | e.xclient.data.l[4] = 0; |
| 591 | XSendEvent(fl_display, RootWindow(fl_display, fl_screen), 0, SubstructureNotifyMask | SubstructureRedirectMask, &e); |
| 592 | #endif |
| 593 | } |
| 594 | |
| 595 | |
Pierre Ossman | 4c4b66f | 2012-08-23 14:53:36 +0000 | [diff] [blame] | 596 | void DesktopWindow::handleDesktopSize() |
| 597 | { |
| 598 | int width, height; |
| 599 | |
| 600 | if (sscanf(desktopSize.getValueStr(), "%dx%d", &width, &height) != 2) |
| 601 | return; |
| 602 | |
| 603 | remoteResize(width, height); |
| 604 | } |
| 605 | |
| 606 | |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 607 | void DesktopWindow::handleResizeTimeout(void *data) |
| 608 | { |
| 609 | DesktopWindow *self = (DesktopWindow *)data; |
| 610 | |
| 611 | assert(self); |
| 612 | |
Pierre Ossman | 4c4b66f | 2012-08-23 14:53:36 +0000 | [diff] [blame] | 613 | self->remoteResize(self->w(), self->h()); |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | |
Pierre Ossman | 4c4b66f | 2012-08-23 14:53:36 +0000 | [diff] [blame] | 617 | void DesktopWindow::remoteResize(int width, int height) |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 618 | { |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 619 | ScreenSet layout; |
Pierre Ossman | aae3891 | 2012-07-13 11:22:55 +0000 | [diff] [blame] | 620 | ScreenSet::iterator iter; |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 621 | |
Pierre Ossman | aae3891 | 2012-07-13 11:22:55 +0000 | [diff] [blame] | 622 | #ifdef HAVE_FLTK_FULLSCREEN |
Pierre Ossman | f44f6c0 | 2012-07-20 12:39:27 +0000 | [diff] [blame] | 623 | if (!fullscreen_active() || (width > w()) || (height > h())) { |
Pierre Ossman | aae3891 | 2012-07-13 11:22:55 +0000 | [diff] [blame] | 624 | #endif |
Pierre Ossman | f44f6c0 | 2012-07-20 12:39:27 +0000 | [diff] [blame] | 625 | // In windowed mode (or the framebuffer is so large that we need |
| 626 | // to scroll) we just report a single virtual screen that covers |
| 627 | // the entire framebuffer. |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 628 | |
Pierre Ossman | aae3891 | 2012-07-13 11:22:55 +0000 | [diff] [blame] | 629 | layout = cc->cp.screenLayout; |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 630 | |
Pierre Ossman | aae3891 | 2012-07-13 11:22:55 +0000 | [diff] [blame] | 631 | // Not sure why we have no screens, but adding a new one should be |
| 632 | // safe as there is nothing to conflict with... |
| 633 | if (layout.num_screens() == 0) |
| 634 | layout.add_screen(rfb::Screen()); |
| 635 | else if (layout.num_screens() != 1) { |
| 636 | // More than one screen. Remove all but the first (which we |
| 637 | // assume is the "primary"). |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 638 | |
Pierre Ossman | aae3891 | 2012-07-13 11:22:55 +0000 | [diff] [blame] | 639 | while (true) { |
| 640 | iter = layout.begin(); |
| 641 | ++iter; |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 642 | |
Pierre Ossman | aae3891 | 2012-07-13 11:22:55 +0000 | [diff] [blame] | 643 | if (iter == layout.end()) |
| 644 | break; |
| 645 | |
| 646 | layout.remove_screen(iter->id); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | // Resize the remaining single screen to the complete framebuffer |
| 651 | layout.begin()->dimensions.tl.x = 0; |
| 652 | layout.begin()->dimensions.tl.y = 0; |
| 653 | layout.begin()->dimensions.br.x = width; |
| 654 | layout.begin()->dimensions.br.y = height; |
| 655 | #ifdef HAVE_FLTK_FULLSCREEN |
| 656 | } else { |
| 657 | int i; |
| 658 | rdr::U32 id; |
| 659 | int sx, sy, sw, sh; |
Pierre Ossman | f44f6c0 | 2012-07-20 12:39:27 +0000 | [diff] [blame] | 660 | Rect viewport_rect, screen_rect; |
Pierre Ossman | aae3891 | 2012-07-13 11:22:55 +0000 | [diff] [blame] | 661 | |
| 662 | // In full screen we report all screens that are fully covered. |
| 663 | |
Pierre Ossman | f44f6c0 | 2012-07-20 12:39:27 +0000 | [diff] [blame] | 664 | viewport_rect.setXYWH(x() + (w() - width)/2, y() + (h() - height)/2, |
| 665 | width, height); |
Pierre Ossman | 93d2d92 | 2012-07-20 12:32:52 +0000 | [diff] [blame] | 666 | |
Pierre Ossman | aae3891 | 2012-07-13 11:22:55 +0000 | [diff] [blame] | 667 | // If we can find a matching screen in the existing set, we use |
| 668 | // that, otherwise we create a brand new screen. |
| 669 | // |
| 670 | // FIXME: We should really track screens better so we can handle |
| 671 | // a resized one. |
| 672 | // |
| 673 | for (i = 0;i < Fl::screen_count();i++) { |
| 674 | Fl::screen_xywh(sx, sy, sw, sh, i); |
| 675 | |
Pierre Ossman | 93d2d92 | 2012-07-20 12:32:52 +0000 | [diff] [blame] | 676 | // Check that the screen is fully inside the framebuffer |
| 677 | screen_rect.setXYWH(sx, sy, sw, sh); |
Pierre Ossman | f44f6c0 | 2012-07-20 12:39:27 +0000 | [diff] [blame] | 678 | if (!screen_rect.enclosed_by(viewport_rect)) |
Pierre Ossman | 93d2d92 | 2012-07-20 12:32:52 +0000 | [diff] [blame] | 679 | continue; |
| 680 | |
Pierre Ossman | f44f6c0 | 2012-07-20 12:39:27 +0000 | [diff] [blame] | 681 | // Adjust the coordinates so they are relative to our viewport |
| 682 | sx -= viewport_rect.tl.x; |
| 683 | sy -= viewport_rect.tl.y; |
| 684 | |
Pierre Ossman | aae3891 | 2012-07-13 11:22:55 +0000 | [diff] [blame] | 685 | // Look for perfectly matching existing screen... |
| 686 | for (iter = cc->cp.screenLayout.begin(); |
| 687 | iter != cc->cp.screenLayout.end(); ++iter) { |
| 688 | if ((iter->dimensions.tl.x == sx) && |
| 689 | (iter->dimensions.tl.y == sy) && |
| 690 | (iter->dimensions.width() == sw) && |
| 691 | (iter->dimensions.height() == sh)) |
| 692 | break; |
| 693 | } |
| 694 | |
| 695 | // Found it? |
| 696 | if (iter != cc->cp.screenLayout.end()) { |
| 697 | layout.add_screen(*iter); |
| 698 | continue; |
| 699 | } |
| 700 | |
| 701 | // Need to add a new one, which means we need to find an unused id |
| 702 | while (true) { |
| 703 | id = rand(); |
| 704 | for (iter = cc->cp.screenLayout.begin(); |
| 705 | iter != cc->cp.screenLayout.end(); ++iter) { |
| 706 | if (iter->id == id) |
| 707 | break; |
| 708 | } |
| 709 | |
| 710 | if (iter == cc->cp.screenLayout.end()) |
| 711 | break; |
| 712 | } |
| 713 | |
| 714 | layout.add_screen(rfb::Screen(id, sx, sy, sw, sh, 0)); |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 715 | } |
Pierre Ossman | 72b4adf | 2012-07-20 14:11:26 +0000 | [diff] [blame] | 716 | |
| 717 | // If the viewport doesn't match a physical screen, then we might |
| 718 | // end up with no screens in the layout. Add a fake one... |
| 719 | if (layout.num_screens() == 0) |
| 720 | layout.add_screen(rfb::Screen(0, 0, 0, width, height, 0)); |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 721 | } |
Pierre Ossman | aae3891 | 2012-07-13 11:22:55 +0000 | [diff] [blame] | 722 | #endif |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 723 | |
| 724 | // Do we actually change anything? |
| 725 | if ((width == cc->cp.width) && |
| 726 | (height == cc->cp.height) && |
| 727 | (layout == cc->cp.screenLayout)) |
| 728 | return; |
| 729 | |
Pierre Ossman | aae3891 | 2012-07-13 11:22:55 +0000 | [diff] [blame] | 730 | vlog.debug("Requesting framebuffer resize from %dx%d to %dx%d (%d screens)", |
| 731 | cc->cp.width, cc->cp.height, width, height, layout.num_screens()); |
| 732 | |
| 733 | if (!layout.validate(width, height)) { |
| 734 | vlog.error("Invalid screen layout computed for resize request!"); |
Pierre Ossman | aae3891 | 2012-07-13 11:22:55 +0000 | [diff] [blame] | 735 | return; |
| 736 | } |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 737 | |
| 738 | cc->writer()->writeSetDesktopSize(width, height, layout); |
| 739 | } |
| 740 | |
| 741 | |
Pierre Ossman | 6455d85 | 2011-06-01 09:33:00 +0000 | [diff] [blame] | 742 | void DesktopWindow::repositionViewport() |
| 743 | { |
| 744 | int new_x, new_y; |
| 745 | |
| 746 | // Deal with some scrolling corner cases: |
| 747 | // |
| 748 | // a) If the window is larger then the viewport, center the viewport. |
| 749 | // b) If the window is smaller than the viewport, make sure there is |
| 750 | // no wasted space on the sides. |
| 751 | // |
| 752 | // FIXME: Doesn't compensate for scroll widget size properly. |
| 753 | |
| 754 | new_x = viewport->x(); |
| 755 | new_y = viewport->y(); |
| 756 | |
| 757 | if (w() > viewport->w()) |
| 758 | new_x = (w() - viewport->w()) / 2; |
| 759 | else { |
| 760 | if (viewport->x() > 0) |
| 761 | new_x = 0; |
| 762 | else if (w() > (viewport->x() + viewport->w())) |
| 763 | new_x = w() - viewport->w(); |
| 764 | } |
| 765 | |
| 766 | // Same thing for y axis |
| 767 | if (h() > viewport->h()) |
| 768 | new_y = (h() - viewport->h()) / 2; |
| 769 | else { |
| 770 | if (viewport->y() > 0) |
| 771 | new_y = 0; |
| 772 | else if (h() > (viewport->y() + viewport->h())) |
| 773 | new_y = h() - viewport->h(); |
| 774 | } |
| 775 | |
| 776 | if ((new_x != viewport->x()) || (new_y != viewport->y())) { |
| 777 | viewport->position(new_x, new_y); |
| 778 | |
| 779 | // The scroll widget does not notice when you move around child widgets, |
| 780 | // so redraw everything to make sure things update. |
| 781 | redraw(); |
| 782 | } |
| 783 | } |
| 784 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 785 | void DesktopWindow::handleClose(Fl_Widget *wnd, void *data) |
| 786 | { |
| 787 | exit_vncviewer(); |
| 788 | } |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 789 | |
| 790 | |
| 791 | void DesktopWindow::handleOptions(void *data) |
| 792 | { |
| 793 | DesktopWindow *self = (DesktopWindow*)data; |
| 794 | |
| 795 | #ifdef HAVE_FLTK_FULLSCREEN |
| 796 | if (self->fullscreen_active() && fullscreenSystemKeys) |
| 797 | self->grabKeyboard(); |
| 798 | else |
| 799 | self->ungrabKeyboard(); |
Pierre Ossman | 9191164 | 2011-05-26 14:57:51 +0000 | [diff] [blame] | 800 | |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 801 | if (fullScreen && !self->fullscreen_active()) |
Pierre Ossman | aae3891 | 2012-07-13 11:22:55 +0000 | [diff] [blame] | 802 | self->fullscreen_on(); |
Pierre Ossman | ff47340 | 2012-07-04 11:27:47 +0000 | [diff] [blame] | 803 | else if (!fullScreen && self->fullscreen_active()) |
Pierre Ossman | 9191164 | 2011-05-26 14:57:51 +0000 | [diff] [blame] | 804 | self->fullscreen_off(); |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 805 | #endif |
| 806 | } |
Pierre Ossman | 4c4b66f | 2012-08-23 14:53:36 +0000 | [diff] [blame] | 807 | |
| 808 | void DesktopWindow::handleFullscreenTimeout(void *data) |
| 809 | { |
| 810 | DesktopWindow *self = (DesktopWindow *)data; |
| 811 | |
| 812 | assert(self); |
| 813 | |
| 814 | self->delayedFullscreen = false; |
| 815 | |
| 816 | if (self->delayedDesktopSize) { |
| 817 | self->handleDesktopSize(); |
| 818 | self->delayedDesktopSize = false; |
| 819 | } |
| 820 | } |
Pierre Ossman | 1d867b6 | 2012-09-03 09:25:07 +0000 | [diff] [blame] | 821 | |
| 822 | void DesktopWindow::handleEdgeScroll(void *data) |
| 823 | { |
| 824 | #ifdef HAVE_FLTK_FULLSCREEN |
| 825 | DesktopWindow *self = (DesktopWindow *)data; |
| 826 | |
| 827 | int mx, my; |
| 828 | int dx, dy; |
| 829 | |
| 830 | assert(self); |
| 831 | |
| 832 | if (!self->fullscreen_active()) |
| 833 | return; |
| 834 | |
| 835 | mx = Fl::event_x(); |
| 836 | my = Fl::event_y(); |
| 837 | |
| 838 | dx = dy = 0; |
| 839 | |
| 840 | // Clamp mouse position in case it is outside the window |
| 841 | if (mx < 0) |
| 842 | mx = 0; |
| 843 | if (mx > self->w()) |
| 844 | mx = self->w(); |
| 845 | if (my < 0) |
| 846 | my = 0; |
| 847 | if (my > self->h()) |
| 848 | my = self->h(); |
| 849 | |
| 850 | if ((self->viewport->x() < 0) && (mx < EDGE_SCROLL_SIZE)) |
| 851 | dx = EDGE_SCROLL_SPEED - EDGE_SCROLL_SPEED * mx / EDGE_SCROLL_SIZE; |
| 852 | if ((self->viewport->x() + self->viewport->w() > self->w()) && (mx > self->w() - EDGE_SCROLL_SIZE)) |
| 853 | dx = EDGE_SCROLL_SPEED * (self->w() - mx) / EDGE_SCROLL_SIZE - EDGE_SCROLL_SPEED; |
| 854 | if ((self->viewport->y() < 0) && (my < EDGE_SCROLL_SIZE)) |
| 855 | dy = EDGE_SCROLL_SPEED - EDGE_SCROLL_SPEED * my / EDGE_SCROLL_SIZE; |
| 856 | if ((self->viewport->y() + self->viewport->h() > self->h()) && (my > self->h() - EDGE_SCROLL_SIZE)) |
| 857 | dy = EDGE_SCROLL_SPEED * (self->h() - my) / EDGE_SCROLL_SIZE - EDGE_SCROLL_SPEED; |
| 858 | |
| 859 | if ((dx == 0) && (dy == 0)) |
| 860 | return; |
| 861 | |
| 862 | // Make sure we don't move the viewport too much |
| 863 | if (self->viewport->x() + dx > 0) |
| 864 | dx = -self->viewport->x(); |
| 865 | if (self->viewport->x() + dx + self->viewport->w() < self->w()) |
| 866 | dx = self->w() - (self->viewport->x() + self->viewport->w()); |
| 867 | if (self->viewport->y() + dy > 0) |
| 868 | dy = -self->viewport->y(); |
| 869 | if (self->viewport->y() + dy + self->viewport->h() < self->h()) |
| 870 | dy = self->h() - (self->viewport->y() + self->viewport->h()); |
| 871 | |
| 872 | self->scroll->scroll_to(self->scroll->xposition() - dx, self->scroll->yposition() - dy); |
| 873 | |
| 874 | Fl::repeat_timeout(0.1, handleEdgeScroll, data); |
| 875 | #endif |
| 876 | } |