Exemplo n.º 1
0
WMenu *wAppMenuGet(WScreen * scr, Window window)
{
	XTextProperty text_prop;
	int count, i;
	char **slist;
	WMenu *menu;

	if (!XGetTextProperty(dpy, window, &text_prop, w_global.atom.wmaker.menu)) {
		return NULL;
	}
	if (!XTextPropertyToStringList(&text_prop, &slist, &count) || count < 1) {
		XFree(text_prop.value);
		return NULL;
	}
	XFree(text_prop.value);
	if (strcmp(slist[0], "WMMenu 0") != 0) {
		wwarning("appmenu: unknown version of WMMenu in window %lx: %s", window, slist[0]);
		XFreeStringList(slist);
		return NULL;
	}

	i = 1;
	menu = parseMenuCommand(scr, window, slist, count, &i);
	if (menu)
		menu->parent = NULL;

	XFreeStringList(slist);

	return menu;
}
Exemplo n.º 2
0
void UpdateIconName(UltimateContext *uc)
{
  XTextProperty prop;
  char **stringlist;
  int count;

  if(uc->title.iconname) free(uc->title.iconname);
  if(!XGetTextProperty(disp, uc->win, &prop, XA_WM_ICON_NAME)) {
    uc->title.iconname = NULL;
    return;
  }
  if(XTextPropertyToStringList(&prop, &stringlist, &count) && (count > 0)){
    uc->title.iconname = calloc(strlen(stringlist[0]) + 1, sizeof(char));
    if(uc->title.iconname) strcpy(uc->title.iconname, stringlist[0]);
    XFreeStringList(stringlist);
  } else uc->title.iconname = NULL;
  XFree(prop.value);

  DBG(fprintf(TheScreen.errout,"Window icon Name: %s\n",uc->title.iconname);)
}
Exemplo n.º 3
0
void WindowManagementPrivate::activeChanged(WId w)
{
    QString caption;
    QString appName;
    QRect rect;
    bool normal = true;

    // Fetch the window size and caption.
    if (w) {
        // Synchronize against the X display and set a null error handler.
        // This is to discard error messages if the window has gone away
        // between the time that we received the active changed message
        // and when we went looking for the window details.
        Display *dpy = QX11Info::display();
        XSync(dpy, False);
        XErrorHandler oldHandler = XSetErrorHandler(nullErrorHandler);

        // Get the window size information from XGetWindowAttributes,
        // and translate the client window's top-level position to root
        // co-ordinates using XTranslateCoordinates.
        XWindowAttributes attrs;
        int x, y;
        Window child;
        memset(&attrs, 0, sizeof(attrs));
        if (XGetWindowAttributes(dpy, (Window)w, &attrs) &&
            XTranslateCoordinates(dpy, (Window)w, attrs.root, 0, 0, &x, &y, &child)) {
            rect = QRect(x, y, attrs.width, attrs.height);
        } else {
            // Window has disappeared, so wait for next active window change.
            XSync(dpy, False);
            XSetErrorHandler(oldHandler);
            return;
        }

        // Read the window caption information.
        caption = readUtf8Property(dpy, w, netWmVisibleNameAtom, utf8StringAtom);
        if (caption.isEmpty())
            caption = readUtf8Property(dpy, w, netWmNameAtom, utf8StringAtom);
        if (caption.isEmpty()) {
            // Old-style X11 application.  Retrieve WM_NAME.
            XTextProperty textProp;
            if (XGetWMName(dpy, (Window)w, &textProp)) {
                char **list;
                int count;
                if (XTextPropertyToStringList(&textProp, &list, &count)) {
                    for (int index = 0; index < count; ++index)
                        caption += QString::fromLocal8Bit(list[index]);
                    XFreeStringList(list);
                }
            }
        }

        // Read the window type to determine if it is normal, dialog, or docked.
        Atom windowType = readAtomProperty(dpy, w, netWmWindowTypeAtom);
        Window transient = 0;
        XGetTransientForHint(dpy, (Window)w, &transient);
        if (windowType) {
            normal = (windowType == netWmWindowTypeNormalAtom);
        } else {
            // No window type, so if there is a transient-for hint,
            // it is probably a dialog, otherwise normal.
            normal = (transient != 0);
        }
        if (transient != 0 && !normal) {
            // If the window is transient, but not modal, then treat it as normal.
            if (!checkForAtomProperty(dpy, w, netWmState, netWmStateModal))
                normal = true;
        }

        // Get the class hint to determine the application's name.
        XClassHint classHint;
        if (XGetClassHint(dpy, (Window)w, &classHint)) {
            appName = QString::fromLatin1(classHint.res_name);
            XFree(classHint.res_name);
            XFree(classHint.res_class);
        }

        // Monitor the window for property changes and destroy notifications.
        if (!monitoredWindows.contains(w)) {
            monitoredWindows += w;
            if (!QWidget::find(w))  // Don't select on our own windows.
                XSelectInput(dpy, (Window)w, StructureNotifyMask | PropertyChangeMask);
        }

        // Sync again to flush errors and restore the original error handler.
        XSync(dpy, False);
        XSetErrorHandler(oldHandler);

        // If the caption is "_ignore_", we should ingore this window.
        // This is used by quicklauncher.
        if (caption == QLatin1String("_ignore_"))   // No tr
            return;
    }

    // Caption should only be emitted when a normal full-screen window
    // is made active.  Dialogs and docked apps shouldn't change it.
    if (normal) {
        if (appName != prevActive || caption != prevCaption || rect != prevRect) {
            prevActive = appName;
            prevCaption = caption;
            vs->setAttribute("Caption", caption);
            QString iconName;
            QContentId cid = QContent::execToContent(appName);
            if (cid != QContent::InvalidId) {
                QContent app(cid);
                iconName = QLatin1String(":icon/")+app.iconName();
            }
            vs->setAttribute("Icon", iconName);
            emit windowCaption(caption);
        }
    }

    // Advertise the change in active window.
    bool update = false;
    if (rect != prevRect) {
        prevRect = rect;
        vs->setAttribute("Rect", rect);
        update = true;
    }
    if (caption != prevCaption) {
        prevCaption = caption;
        vs->setAttribute("Title", caption);
        update = true;
    }
    if (update) {
        emit windowActive(caption, rect, w);
    }
}