blob: f568b21146ffc127ba2ccdba74ade7632eca56cc [file] [log] [blame]
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00001/* Copyright (C) 2002-2003 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
28using namespace rfb;
29using namespace rfb::win32;
30
31static LogWriter vlog("WMPoller");
32
33BoolParameter rfb::win32::WMPoller::poll_console_windows("PollConsoleWindows",
34 "Server should poll console windows for updates", true);
35
36// -=- WMPoller class
37
38rfb::win32::WMPoller::WMPoller() : clipper(0) {
39}
40
41rfb::win32::WMPoller::~WMPoller() {
42 if (clipper) delete clipper;
43}
44
45bool
46rfb::win32::WMPoller::processEvent() {
47 PollInfo info;
48 if (clipper && poll_console_windows) {
49 ::EnumWindows(WMPoller::enumWindowProc, (LPARAM) &info);
50 clipper->add_changed(info.poll_include);
51 }
52 return false;
53}
54
55bool
56rfb::win32::WMPoller::setClipRect(const Rect& r) {
57 clip_region = r;
58 if (clipper) clipper->set_clip_region(clip_region);
59 return true;
60}
61
62bool
63rfb::win32::WMPoller::setUpdateTracker(UpdateTracker* ut) {
64 if (clipper) delete clipper;
65 clipper = new ClippedUpdateTracker(*ut);
66 clipper->set_clip_region(clip_region);
67 return true;
68}
69
70bool
71rfb::win32::WMPoller::checkPollWindow(HWND w) {
72 TCHAR buffer[128];
73 if (!GetClassName(w, buffer, 128))
74 throw rdr::SystemException("unable to get window class:%u", GetLastError());
75 if ((_tcscmp(buffer, _T("tty")) != 0) &&
76 (_tcscmp(buffer, _T("ConsoleWindowClass")) != 0)) {
77 return false;
78 }
79 return true;
80}
81
82void
83rfb::win32::WMPoller::pollWindow(HWND w, PollInfo* i) {
84 RECT r;
85 if (IsWindowVisible(w) && GetWindowRect(w, &r)) {
86 if (IsRectEmpty(&r)) return;
87 Region wrgn(Rect(r.left, r.top, r.right, r.bottom));
88 if (checkPollWindow(w)) {
89 wrgn.assign_subtract(i->poll_exclude);
90 i->poll_include.assign_union(wrgn);
91 } else {
92 i->poll_exclude.assign_union(wrgn);
93 }
94 }
95}
96
97BOOL CALLBACK
98rfb::win32::WMPoller::enumWindowProc(HWND w, LPARAM lp) {
99 pollWindow(w, (PollInfo*)lp);
100 return TRUE;
101}