123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #include "x11helper.h"
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
- #include <X11/Xatom.h>
- #include <X11/Xresource.h>
-
- static char *get_property (Display *disp, Window win,
- Atom xa_prop_type, char *prop_name, unsigned long *size) {
- Atom xa_prop_name;
- Atom xa_ret_type;
- int ret_format;
- unsigned long ret_nitems;
- unsigned long ret_bytes_after;
- unsigned long tmp_size;
- unsigned char *ret_prop;
- char *ret;
-
- xa_prop_name = XInternAtom(disp, prop_name, False);
-
- if (XGetWindowProperty(disp, win, xa_prop_name, 0, 200 / 4, False,
- xa_prop_type, &xa_ret_type, &ret_format,
- &ret_nitems, &ret_bytes_after, &ret_prop) != Success) {
- return NULL;
- }
-
- if (xa_ret_type != xa_prop_type) {
- XFree(ret_prop);
- return NULL;
- }
-
- /* null terminate the result to make string handling easier */
- tmp_size = (ret_format / 8) * ret_nitems;
- /* Correct 64 Architecture implementation of 32 bit data */
- if(ret_format==32) tmp_size *= sizeof(long)/4;
- ret = (char*)malloc(tmp_size + 1);
- memcpy(ret, ret_prop, tmp_size);
- ret[tmp_size] = '\0';
-
- if (size) {
- *size = tmp_size;
- }
-
- XFree(ret_prop);
- return ret;
- }
-
- static Window *get_client_list (Display *disp, unsigned long *size) {
- Window *client_list;
-
- if ((client_list = (Window *)get_property(disp, DefaultRootWindow(disp),
- XA_WINDOW, (char*)"_NET_CLIENT_LIST", size)) == NULL) {
- if ((client_list = (Window *)get_property(disp, DefaultRootWindow(disp),
- XA_CARDINAL, (char*)"_WIN_CLIENT_LIST", size)) == NULL) {
- return NULL;
- }
- }
-
- return client_list;
- }
-
- QMap<WId, QString> X11Helper::getRootWindows()
- {
- QMap<WId, QString> windows;
- Display *dpy;
- Window *children;
- unsigned long noOfChildren;
-
- dpy = XOpenDisplay(NULL);
- if (!dpy) {
- return windows;
- }
-
- children = (Window*)get_client_list(dpy, &noOfChildren);
- if (!children) {
- return windows;
- }
- for (unsigned long i = 0; i < noOfChildren; ++i) {
- char* nameStr;
- XFetchName(dpy, children[i], &nameStr);
- QString name(nameStr);
- XFree(nameStr);
- if (!name.isEmpty()) {
- windows.insert(children[i], name);
- // if (name.startsWith("robin@gigi-lt1: /tmp")) {
- // qDebug() << name;
- // QWindow *window = QWindow::fromWinId(children[i]);
- // window->setFlags(Qt::FramelessWindowHint);
-
- // QWidget *widget = QWidget::createWindowContainer(window);
- // QEvent e(QEvent::EmbeddingControl);
- // QApplication::sendEvent(widget, &e);
- // widget->show();
- // QTimer* timer = new QTimer(widget);
- // QObject::connect(timer, SIGNAL(timeout()), widget, SLOT(update()));
- // timer->start(100);
- }
- }
- return windows;
- }
|