main.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <cstring>
  2. #include <cassert>
  3. #include <iostream>
  4. extern "C" {
  5. #include <xdo.h>
  6. }
  7. void search_windows_by_name(const xdo_t* xdo, const char* name_regex, Window** windowlist_ret, unsigned int* nwindows_ret) {
  8. xdo_search_t search;
  9. memset(&search, 0, sizeof(xdo_search_t));
  10. search.max_depth = -1;
  11. search.require = xdo_search::SEARCH_ALL;
  12. search.searchmask |= SEARCH_NAME;
  13. search.winname = name_regex;
  14. xdo_search_windows(xdo, &search, windowlist_ret, nwindows_ret);
  15. }
  16. void search_toontown_windows(const xdo_t* xdo, Window** windowlist_ret, unsigned int* nwindows_ret) {
  17. search_windows_by_name(xdo, "Toontown.*", windowlist_ret, nwindows_ret);
  18. }
  19. int main() {
  20. xdo_t* xdo = xdo_new(NULL);
  21. assert(xdo);
  22. Window* windows;
  23. unsigned int nwindows = 77;
  24. search_toontown_windows(xdo, &windows, &nwindows);
  25. std::cout << nwindows << std::endl;
  26. for(unsigned int i=0; i<nwindows; i++) {
  27. unsigned char* window_name = new unsigned char[255];
  28. int name_len, name_type;
  29. xdo_get_window_name(xdo, windows[i], &window_name, &name_len, &name_type);
  30. if(name_len > 0) {
  31. window_name[name_len] = '\0';
  32. std::cout << window_name << std::endl;
  33. }
  34. delete(window_name);
  35. }
  36. return 0;
  37. }