Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +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 | // -=- WMPoller.cxx |
| 20 | |
| 21 | #include <rfb_win32/WMPoller.h> |
| 22 | #include <rfb/Exception.h> |
| 23 | #include <rfb/LogWriter.h> |
| 24 | #include <rfb/Configuration.h> |
| 25 | |
| 26 | #include <tchar.h> |
| 27 | |
| 28 | using namespace rfb; |
| 29 | using namespace rfb::win32; |
| 30 | |
| 31 | static LogWriter vlog("WMPoller"); |
| 32 | |
| 33 | BoolParameter rfb::win32::WMPoller::poll_console_windows("PollConsoleWindows", |
| 34 | "Server should poll console windows for updates", true); |
| 35 | |
| 36 | // -=- WMPoller class |
| 37 | |
| 38 | bool |
| 39 | rfb::win32::WMPoller::processEvent() { |
| 40 | PollInfo info; |
| 41 | if (poll_console_windows && ut) { |
| 42 | ::EnumWindows(WMPoller::enumWindowProc, (LPARAM) &info); |
| 43 | ut->add_changed(info.poll_include); |
| 44 | } |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | bool |
| 49 | rfb::win32::WMPoller::setUpdateTracker(UpdateTracker* ut_) { |
| 50 | ut = ut_; |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | bool |
| 55 | rfb::win32::WMPoller::checkPollWindow(HWND w) { |
| 56 | TCHAR buffer[128]; |
| 57 | if (!GetClassName(w, buffer, 128)) |
| 58 | throw rdr::SystemException("unable to get window class:%u", GetLastError()); |
| 59 | if ((_tcscmp(buffer, _T("tty")) != 0) && |
| 60 | (_tcscmp(buffer, _T("ConsoleWindowClass")) != 0)) { |
| 61 | return false; |
| 62 | } |
| 63 | return true; |
| 64 | } |
| 65 | |
| 66 | void |
| 67 | rfb::win32::WMPoller::pollWindow(HWND w, PollInfo* i) { |
| 68 | RECT r; |
| 69 | if (IsWindowVisible(w) && GetWindowRect(w, &r)) { |
| 70 | if (IsRectEmpty(&r)) return; |
| 71 | Region wrgn(Rect(r.left, r.top, r.right, r.bottom)); |
| 72 | if (checkPollWindow(w)) { |
| 73 | wrgn.assign_subtract(i->poll_exclude); |
| 74 | i->poll_include.assign_union(wrgn); |
| 75 | } else { |
| 76 | i->poll_exclude.assign_union(wrgn); |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | BOOL CALLBACK |
| 82 | rfb::win32::WMPoller::enumWindowProc(HWND w, LPARAM lp) { |
| 83 | pollWindow(w, (PollInfo*)lp); |
| 84 | return TRUE; |
| 85 | } |