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.

x11helper.cpp 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include "x11helper.h"
  2. #include <X11/Xlib.h>
  3. #include <X11/Xutil.h>
  4. #include <X11/Xatom.h>
  5. #include <X11/Xresource.h>
  6. static char *get_property (Display *disp, Window win,
  7. Atom xa_prop_type, char *prop_name, unsigned long *size) {
  8. Atom xa_prop_name;
  9. Atom xa_ret_type;
  10. int ret_format;
  11. unsigned long ret_nitems;
  12. unsigned long ret_bytes_after;
  13. unsigned long tmp_size;
  14. unsigned char *ret_prop;
  15. char *ret;
  16. xa_prop_name = XInternAtom(disp, prop_name, False);
  17. if (XGetWindowProperty(disp, win, xa_prop_name, 0, 200 / 4, False,
  18. xa_prop_type, &xa_ret_type, &ret_format,
  19. &ret_nitems, &ret_bytes_after, &ret_prop) != Success) {
  20. return NULL;
  21. }
  22. if (xa_ret_type != xa_prop_type) {
  23. XFree(ret_prop);
  24. return NULL;
  25. }
  26. /* null terminate the result to make string handling easier */
  27. tmp_size = (ret_format / 8) * ret_nitems;
  28. /* Correct 64 Architecture implementation of 32 bit data */
  29. if(ret_format==32) tmp_size *= sizeof(long)/4;
  30. ret = (char*)malloc(tmp_size + 1);
  31. memcpy(ret, ret_prop, tmp_size);
  32. ret[tmp_size] = '\0';
  33. if (size) {
  34. *size = tmp_size;
  35. }
  36. XFree(ret_prop);
  37. return ret;
  38. }
  39. static Window *get_client_list (Display *disp, unsigned long *size) {
  40. Window *client_list;
  41. if ((client_list = (Window *)get_property(disp, DefaultRootWindow(disp),
  42. XA_WINDOW, (char*)"_NET_CLIENT_LIST", size)) == NULL) {
  43. if ((client_list = (Window *)get_property(disp, DefaultRootWindow(disp),
  44. XA_CARDINAL, (char*)"_WIN_CLIENT_LIST", size)) == NULL) {
  45. return NULL;
  46. }
  47. }
  48. return client_list;
  49. }
  50. QMap<WId, QString> X11Helper::getRootWindows()
  51. {
  52. QMap<WId, QString> windows;
  53. Display *dpy;
  54. Window *children;
  55. unsigned long noOfChildren;
  56. dpy = XOpenDisplay(NULL);
  57. if (!dpy) {
  58. return windows;
  59. }
  60. children = (Window*)get_client_list(dpy, &noOfChildren);
  61. if (!children) {
  62. return windows;
  63. }
  64. for (unsigned long i = 0; i < noOfChildren; ++i) {
  65. char* nameStr;
  66. XFetchName(dpy, children[i], &nameStr);
  67. QString name(nameStr);
  68. XFree(nameStr);
  69. if (!name.isEmpty()) {
  70. windows.insert(children[i], name);
  71. // if (name.startsWith("robin@gigi-lt1: /tmp")) {
  72. // qDebug() << name;
  73. // QWindow *window = QWindow::fromWinId(children[i]);
  74. // window->setFlags(Qt::FramelessWindowHint);
  75. // QWidget *widget = QWidget::createWindowContainer(window);
  76. // QEvent e(QEvent::EmbeddingControl);
  77. // QApplication::sendEvent(widget, &e);
  78. // widget->show();
  79. // QTimer* timer = new QTimer(widget);
  80. // QObject::connect(timer, SIGNAL(timeout()), widget, SLOT(update()));
  81. // timer->start(100);
  82. }
  83. }
  84. return windows;
  85. }