Constantin Kaplinsky | 0a1eca1 | 2006-04-16 07:28:14 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
| 2 | * |
| 3 | * This is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This software is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this software; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 16 | * USA. |
| 17 | */ |
| 18 | |
| 19 | // -=- SDisplayCoreWMHooks.cxx |
| 20 | |
| 21 | #include <rfb_win32/SDisplayCoreWMHooks.h> |
| 22 | #include <rfb/LogWriter.h> |
| 23 | |
| 24 | using namespace rfb; |
| 25 | using namespace rfb::win32; |
| 26 | |
| 27 | static LogWriter vlog("SDisplayCoreWMHooks"); |
| 28 | |
| 29 | const int SDisplayCoreWMHooks::cursorTimerId = 2; |
| 30 | const int SDisplayCoreWMHooks::consolePollTimerId = 3; |
| 31 | |
| 32 | |
| 33 | SDisplayCoreWMHooks::SDisplayCoreWMHooks(SDisplay* d, UpdateTracker* ut) |
| 34 | : SDisplayCorePolling(d, ut, 5000), |
| 35 | cursorTimer(getHandle(), cursorTimerId), |
| 36 | consolePollTimer(getHandle(), consolePollTimerId), |
| 37 | pollConsoles(false) { |
| 38 | if (!hooks.setEvent(display->getUpdateEvent())) |
| 39 | throw rdr::Exception("hook subsystem failed to initialise"); |
| 40 | poller.setUpdateTracker(updateTracker); |
| 41 | cursorTimer.start(20); |
| 42 | consolePollTimer.start(200); |
| 43 | } |
| 44 | |
| 45 | SDisplayCoreWMHooks::~SDisplayCoreWMHooks() { |
| 46 | } |
| 47 | |
| 48 | LRESULT SDisplayCoreWMHooks::processMessage(UINT msg, WPARAM wParam, LPARAM lParam) { |
| 49 | if (msg == WM_TIMER) { |
| 50 | if (wParam == cursorTimerId) { |
| 51 | SetEvent(display->getUpdateEvent()); |
| 52 | return 0; |
| 53 | } else if (wParam == consolePollTimerId) { |
| 54 | pollConsoles = true; |
| 55 | SetEvent(display->getUpdateEvent()); |
| 56 | return 0; |
| 57 | } |
| 58 | } |
| 59 | return SDisplayCorePolling::processMessage(msg, wParam, lParam); |
| 60 | } |
| 61 | |
| 62 | void SDisplayCoreWMHooks::flushUpdates() { |
| 63 | // Poll any visible console windows |
| 64 | if (pollConsoles) { |
| 65 | pollConsoles = false; |
| 66 | poller.processEvent(); |
| 67 | } |
| 68 | |
| 69 | // Check for updates from the hooks |
| 70 | hooks.getUpdates(updateTracker); |
| 71 | |
| 72 | // Check for updates from the polling Core |
| 73 | SDisplayCorePolling::flushUpdates(); |
| 74 | } |