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.4KB

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