You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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