static Bool
titleinfoInitScreen (CompPlugin *p,
		     CompScreen *s)
{
    TitleinfoScreen *ts;

    TITLEINFO_DISPLAY (s->display);

    ts = malloc (sizeof (TitleinfoScreen));
    if (!ts)
	return FALSE;

    ts->windowPrivateIndex = allocateWindowPrivateIndex (s);
    if (ts->windowPrivateIndex < 0) 
    {
	free (ts);
	return FALSE;
    }

    s->base.privates[td->screenPrivateIndex].ptr = ts;

    WRAP (ts, s, addSupportedAtoms, titleinfoAddSupportedAtoms);

    return TRUE;
}
static void
titleinfoHandleEvent (CompDisplay *d,
		      XEvent      *event)
{
    TITLEINFO_DISPLAY (d);

    UNWRAP (td, d, handleEvent);
    (*d->handleEvent) (d, event);
    WRAP (td, d, handleEvent, titleinfoHandleEvent);

    if (event->type == PropertyNotify)
    {
	CompWindow *w;

	if (event->xproperty.atom == XA_WM_CLIENT_MACHINE)
	{
	    w = findWindowAtDisplay (d, event->xproperty.window);
	    if (w)
		titleinfoUpdateMachine (w);
	}
	else if (event->xproperty.atom == td->wmPidAtom)
	{
	    w = findWindowAtDisplay (d, event->xproperty.window);
	    if (w)
		titleinfoUpdatePid (w);
	}
	else if (event->xproperty.atom == d->wmNameAtom ||
		 event->xproperty.atom == XA_WM_NAME)
	{
	    w = findWindowAtDisplay (d, event->xproperty.window);
	    if (w)
		titleinfoUpdateTitle (w);
	}
    }
}
示例#3
0
static void
titleinfoUpdateVisibleName (CompWindow *w)
{
	CompDisplay *d = &display;
	char        *text = NULL, *machine = NULL;
	const char  *root = "", *title;

	TITLEINFO_DISPLAY (d);
	TITLEINFO_WINDOW (w);

	title = tw->title ? tw->title : "";

	const BananaValue *
	option_show_root = bananaGetOption (bananaIndex,
	                                    "show_root",
	                                    w->screen->screenNum);

	const BananaValue *
	option_show_remote_machine = bananaGetOption (bananaIndex,
	                                              "show_remote_machine",
	                                              w->screen->screenNum);

	if (option_show_root->b && tw->owner == 0)
		root = "ROOT: ";

	if (option_show_remote_machine->b && tw->remoteMachine)
	{
		char hostname[256];

		if (gethostname (hostname, 256) || strcmp (hostname, tw->remoteMachine))
			machine = tw->remoteMachine;
	}

	if (machine)
	{
#pragma GCC diagnostic ignored "-Wunused-variable"
		int retval = asprintf (&text, "%s%s (@%s)", root, title, machine);
	}
	else if (root[0])
	{
#pragma GCC diagnostic ignored "-Wunused-variable"
		int retval = asprintf (&text, "%s%s", root, title);
	}

	if (text)
	{
		XChangeProperty (d->display, w->id, td->visibleNameAtom,
		                 d->utf8StringAtom, 8, PropModeReplace,
		                 (unsigned char *) text, strlen (text));
		free (text);
	}
	else
	{
		XDeleteProperty (d->display, w->id, td->visibleNameAtom);
	}
}
示例#4
0
static void titleinfoFiniDisplay(CompPlugin * p, CompDisplay * d)
{
	TITLEINFO_DISPLAY(d);

	freeScreenPrivateIndex(d, td->screenPrivateIndex);

	UNWRAP(td, d, handleEvent);

	free(td);
}
示例#5
0
static void
titleinfoUpdatePid (CompWindow *w)
{
	CompDisplay   *d = &display;
	int pid = -1;
	Atom type;
	int result, format;
	unsigned long nItems, bytesAfter;
	unsigned char *propVal;

	TITLEINFO_DISPLAY (d);
	TITLEINFO_WINDOW (w);

	tw->owner = -1;

	result = XGetWindowProperty (d->display, w->id, td->wmPidAtom,
	                             0L, 1L, False, XA_CARDINAL, &type,
	                             &format, &nItems, &bytesAfter, &propVal);

	if (result == Success && propVal)
	{
		if (nItems)
		{
			unsigned long value;

			memcpy (&value, propVal, sizeof (unsigned long));
			pid = value;
		}

		XFree (propVal);
	}

	if (pid >= 0)
	{
		char path[512];
		struct stat fileStat;

		snprintf (path, 512, "/proc/%d", pid);
		if (!lstat (path, &fileStat))
			tw->owner = fileStat.st_uid;
	}

	const BananaValue *
	option_show_root = bananaGetOption (bananaIndex,
	                                    "show_root",
	                                    w->screen->screenNum);

	if (option_show_root->b)
		titleinfoUpdateVisibleName (w);
}
static void
titleinfoUpdateVisibleName (CompWindow *w)
{
    CompDisplay *d = w->screen->display;
    char        *text = NULL, *machine = NULL;
    const char  *root = "", *title;

    TITLEINFO_DISPLAY (d);
    TITLEINFO_WINDOW (w);

    title = tw->title ? tw->title : "";

    if (titleinfoGetShowRoot (w->screen) && tw->owner == 0)
	root = "ROOT: ";

    if (titleinfoGetShowRemoteMachine (w->screen) && tw->remoteMachine)
    {
	char hostname[256];

	if (gethostname (hostname, 256) || strcmp (hostname, tw->remoteMachine))
	    machine = tw->remoteMachine;
    }

    if (machine)
    {
	if (asprintf (&text, "%s%s (@%s)", root, title, machine) == -1)
		return;
	}
    else if (root[0])
    {
	if (asprintf (&text, "%s%s", root, title) == -1)
		return;
	}
    if (text)
    {
	XChangeProperty (d->display, w->id, td->visibleNameAtom,
			 d->utf8StringAtom, 8, PropModeReplace,
			 (unsigned char *) text, strlen (text));
	free (text);
    }
    else
    {
	XDeleteProperty (d->display, w->id, td->visibleNameAtom);
    }
}
示例#7
0
static unsigned int
titleinfoAddSupportedAtoms(CompScreen * s, Atom * atoms, unsigned int size)
{
	unsigned int count;

	TITLEINFO_DISPLAY(s->display);
	TITLEINFO_SCREEN(s);

	UNWRAP(ts, s, addSupportedAtoms);
	count = (*s->addSupportedAtoms) (s, atoms, size);
	WRAP(ts, s, addSupportedAtoms, titleinfoAddSupportedAtoms);

	if ((size - count) >= 2) {
		atoms[count++] = td->visibleNameAtom;
		atoms[count++] = td->wmPidAtom;
	}

	return count;
}