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.

WMPoller.cxx 2.3KB

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