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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #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. bool
  31. rfb::win32::WMPoller::processEvent() {
  32. PollInfo info;
  33. if (poll_console_windows && ut) {
  34. ::EnumWindows(WMPoller::enumWindowProc, (LPARAM) &info);
  35. ut->add_changed(info.poll_include);
  36. }
  37. return false;
  38. }
  39. bool
  40. rfb::win32::WMPoller::setUpdateTracker(UpdateTracker* ut_) {
  41. ut = ut_;
  42. return true;
  43. }
  44. bool
  45. rfb::win32::WMPoller::checkPollWindow(HWND w) {
  46. TCHAR buffer[128];
  47. if (!GetClassName(w, buffer, 128))
  48. throw rdr::SystemException("unable to get window class:%u", GetLastError());
  49. if ((_tcscmp(buffer, _T("tty")) != 0) &&
  50. (_tcscmp(buffer, _T("ConsoleWindowClass")) != 0)) {
  51. return false;
  52. }
  53. return true;
  54. }
  55. void
  56. rfb::win32::WMPoller::pollWindow(HWND w, PollInfo* i) {
  57. RECT r;
  58. if (IsWindowVisible(w) && GetWindowRect(w, &r)) {
  59. if (IsRectEmpty(&r)) return;
  60. Region wrgn(Rect(r.left, r.top, r.right, r.bottom));
  61. if (checkPollWindow(w)) {
  62. wrgn.assign_subtract(i->poll_exclude);
  63. i->poll_include.assign_union(wrgn);
  64. } else {
  65. i->poll_exclude.assign_union(wrgn);
  66. }
  67. }
  68. }
  69. BOOL CALLBACK
  70. rfb::win32::WMPoller::enumWindowProc(HWND w, LPARAM lp) {
  71. pollWindow(w, (PollInfo*)lp);
  72. return TRUE;
  73. }