Beispiel #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;
}
Beispiel #2
0
// Thanks zcodes!
char *get_window_name(Window win)
{
    XTextProperty text_property;
    Status status = XGetWMName(server.display, win, &text_property);
    if (!status || !text_property.value || !text_property.nitems) {
        return strdup("");
    }

    char **name_list;
    int count;
    status = Xutf8TextPropertyToTextList(server.display, &text_property, &name_list, &count);
    if (status < Success || !count) {
        XFree(text_property.value);
        return strdup("");
    }

    if (!name_list[0]) {
        XFreeStringList(name_list);
        XFree(text_property.value);
        return strdup("");
    }

    char *result = strdup(name_list[0]);
    XFreeStringList(name_list);
    XFree(text_property.value);
    return result;
}
static XFontSet getFontSet(const QFont &f)
{
    int i = 0;
    if (f.italic())
        i |= 1;
    if (f.bold())
        i |= 2;

    if (f.pointSize() > 20)
        i += 4;

    if (!fontsetCache[i]) {
        Display* dpy = X11->display;
        int missCount;
        char** missList;
        fontsetCache[i] = XCreateFontSet(dpy, fontsetnames[i], &missList, &missCount, 0);
        if(missCount > 0)
            XFreeStringList(missList);
        if (!fontsetCache[i]) {
            fontsetCache[i] = XCreateFontSet(dpy, "-*-fixed-*-*-*-*-16-*", &missList, &missCount, 0);
            if(missCount > 0)
                XFreeStringList(missList);
            if (!fontsetCache[i])
                fontsetCache[i] = (XFontSet)-1;
        }
    }
    return (fontsetCache[i] == (XFontSet)-1) ? 0 : fontsetCache[i];
}
Beispiel #4
0
static XFontSet
x_create_fontset (char *xlfd, char ***missing,
		   int *nmissing, char **def_string)
{
    XFontSet fs = XCreateFontSet (dpy, xlfd, missing, nmissing, def_string);

    if (fs != 0 && *nmissing == 0)
	return fs;

    /* for non-iso8859-1 language and iso8859-1 specification
       (this fontset is only for pattern analysis) */

    if (fs == 0)
    {
	char *old_locale, *tem;

	if (*nmissing != 0)
	    XFreeStringList (*missing);

	/* Save the old LC_CTYPE locale.. */
	tem = setlocale (LC_CTYPE, 0);
	if (tem != 0)
	{
	    old_locale = alloca (strlen (tem) + 1);
	    strcpy (old_locale, tem);

	    /* ..then create the fontset in the default locale.. */
	    setlocale (LC_CTYPE, "C");
	}
	else
	    old_locale = 0;

	fs = XCreateFontSet (dpy, xlfd, missing, nmissing, def_string);

	/* ..then restore the original locale */
	if (old_locale != 0)
	    setlocale (LC_CTYPE, old_locale);
    }

    /* make XLFD font name for pattern analysis */
    if (fs != 0)
    {
	XFontStruct **fontstructs;
	char **fontnames;
	if (XFontsOfFontSet (fs, &fontstructs, &fontnames) > 0)
	    xlfd = fontnames[0];
    }

    xlfd = generalize_xlfd (xlfd);

    if (*nmissing != 0)
	XFreeStringList (*missing);
    if (fs != 0)
	XFreeFontSet (dpy, fs);

    fs = XCreateFontSet (dpy, xlfd, missing, nmissing, def_string);

    free (xlfd);
    return fs;
}
Beispiel #5
0
/**
 * Get the WM_COMMAND property for @a win.
 *
 * Return the command of a window. String must be free'd when done with.
 *
 * @param win  The window.
 * @param argc Number of arguments.
 * @param argv Arguments.
 */
EAPI void
ecore_x_icccm_command_get(Ecore_X_Window win,
                          int *argc,
                          char ***argv)
{
   int i, c;
   char **v;
   Eina_Bool success;

   if (argc)
     *argc = 0;

   if (argv)
     *argv = NULL;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   success = XGetCommand(_ecore_x_disp, win, &v, &c);
   if (_ecore_xlib_sync) ecore_x_sync();
   if (!success) return;

   if (c < 1)
     {
        if (v)
          XFreeStringList(v);

        return;
     }

   if (argc)
     *argc = c;

   if (argv)
     {
        (*argv) = malloc(c * sizeof(char *));
        if (!*argv)
          {
             XFreeStringList(v);
             if (argc)
               *argc = 0;

             return;
          }

        for (i = 0; i < c; i++)
          {
             if (v[i])
               (*argv)[i] = strdup(v[i]);
             else
               (*argv)[i] = strdup("");
          }
     }

   XFreeStringList(v);
}
Beispiel #6
0
int
xu_getstrprop(Window win, Atom atm, char **text) {
	XTextProperty	 prop;
	char		**list;
	int		 nitems = 0;

	*text = NULL;

	XGetTextProperty(X_Dpy, win, &prop, atm);
	if (!prop.nitems)
		return (0);

	if (Xutf8TextPropertyToTextList(X_Dpy, &prop, &list,
	    &nitems) == Success && nitems > 0 && *list) {
		if (nitems > 1) {
			XTextProperty    prop2;
			if (Xutf8TextListToTextProperty(X_Dpy, list, nitems,
			    XUTF8StringStyle, &prop2) == Success) {
				*text = xstrdup((const char *)prop2.value);
				XFree(prop2.value);
			}
		} else {
			*text = xstrdup(*list);
		}
		XFreeStringList(list);
	}

	XFree(prop.value);

	return (nitems);
}
Beispiel #7
0
void
updatetitle(Client *c) {
    char **list = NULL;
    int n;
    XTextProperty name;

    name.nitems = 0;
    c->name[0] = 0;
    XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
    if(!name.nitems)
        XGetWMName(dpy, c->win, &name);
    if(!name.nitems)
        return;
    if(name.encoding == XA_STRING)
        strncpy(c->name, (char *)name.value, sizeof c->name);
    else {
        if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
                && n > 0 && *list)
        {
            strncpy(c->name, *list, sizeof c->name);
            XFreeStringList(list);
        }
    }
    XFree(name.value);
}
Beispiel #8
0
Datei: wmfs.c Projekt: Engil/wmfs
void
wmfs_init_font(char *font, struct theme *t)
{
     XFontStruct **xfs = NULL;
     char **misschar, **names, *defstring;
     int d;

     if(!(t->font.fontset = XCreateFontSet(W->dpy, font, &misschar, &d, &defstring)))
     {
          warnxl("Can't load font '%s'", font);
          t->font.fontset = XCreateFontSet(W->dpy, "fixed", &misschar, &d, &defstring);
     }

     XExtentsOfFontSet(t->font.fontset);
     XFontsOfFontSet(t->font.fontset, &xfs, &names);

     t->font.as    = xfs[0]->max_bounds.ascent;
     t->font.de    = xfs[0]->max_bounds.descent;
     t->font.width = xfs[0]->max_bounds.width;

     t->font.height = t->font.as + t->font.de;

     if(misschar)
          XFreeStringList(misschar);
}
Beispiel #9
0
VALUE
subViewSingCurrent(VALUE self)
{
  int nnames = 0;
  char **names = NULL;
  unsigned long *cur_view = NULL;
  VALUE view = Qnil;

  subSubtlextConnect(NULL); ///< Implicit open connection

  /* Fetch data */
  names    = subSharedPropertyGetStrings(display, DefaultRootWindow(display),
    XInternAtom(display, "_NET_DESKTOP_NAMES", False), &nnames);
  cur_view = (unsigned long *)subSharedPropertyGet(display,
    DefaultRootWindow(display), XA_CARDINAL,
    XInternAtom(display, "_NET_CURRENT_DESKTOP", False), NULL);

  /* Check results */
  if(names && cur_view)
    {
      /* Create instance */
      view = subViewInstantiate(names[*cur_view]);
      rb_iv_set(view, "@id",  INT2FIX(*cur_view));
    }

  if(names)    XFreeStringList(names);
  if(cur_view) free(cur_view);

  return view;
} /* }}} */
Beispiel #10
0
VALUE
subSubletSingAll(VALUE self)
{
  int i, nsublets = 0;
  char **sublets = NULL;
  VALUE meth = Qnil, klass = Qnil, array = Qnil;

  subSubtlextConnect(NULL); ///< Implicit open connection

  /* Fetch data */
  meth   = rb_intern("new");
  klass  = rb_const_get(mod, rb_intern("Sublet"));
  array  = rb_ary_new();

  /* Check results */
  if((sublets = subSharedPropertyGetStrings(display,
      DefaultRootWindow(display), XInternAtom(display, "SUBTLE_SUBLET_LIST",
      False), &nsublets)))
    {
      for(i = 0; i < nsublets; i++)
        {
          VALUE s = rb_funcall(klass, meth, 1, rb_str_new2(sublets[i]));

          rb_iv_set(s, "@id", INT2FIX(i));
          rb_ary_push(array, s);
        }

      XFreeStringList(sublets);
    }

  return array;
} /* }}} */
Beispiel #11
0
// retrieve a text property from a window
// technically we could use window_get_prop(), but this is better for character set support
char* window_get_text_prop ( Display *display, Window w, Atom atom )
{
    XTextProperty prop;
    char          *res   = NULL;
    char          **list = NULL;
    int           count;

    if ( XGetTextProperty ( display, w, &prop, atom ) && prop.value && prop.nitems ) {
        if ( prop.encoding == XA_STRING ) {
            size_t l = strlen ( ( char *) prop.value ) + 1;
            res = g_malloc ( l );
            // make clang-check happy.
            if ( res ) {
                g_strlcpy ( res, ( char * ) prop.value, l );
            }
        }
        else if ( Xutf8TextPropertyToTextList ( display, &prop, &list, &count ) >= Success && count > 0 && *list ) {
            size_t l = strlen ( *list ) + 1;
            res = g_malloc ( l );
            // make clang-check happy.
            if ( res ) {
                g_strlcpy ( res, *list, l );
            }
            XFreeStringList ( list );
        }
    }

    if ( prop.value ) {
        XFree ( prop.value );
    }

    return res;
}
Beispiel #12
0
/* XFetchName Wrapper */
Bool wFetchName(Display *dpy, Window win, char **winname)
{
	XTextProperty text_prop;
	char **list;
	int num;

	if (XGetWMName(dpy, win, &text_prop)) {
		if (text_prop.value && text_prop.nitems > 0) {
			if (text_prop.encoding == XA_STRING) {
				*winname = wstrdup((char *)text_prop.value);
				XFree(text_prop.value);
			} else {
				text_prop.nitems = strlen((char *)text_prop.value);
				if (XmbTextPropertyToTextList(dpy, &text_prop, &list, &num) >=
				    Success && num > 0 && *list) {
					XFree(text_prop.value);
					*winname = wstrdup(*list);
					XFreeStringList(list);
				} else {
					*winname = wstrdup((char *)text_prop.value);
					XFree(text_prop.value);
				}
			}
		} else {
			/* the title is set, but it was set to none */
			*winname = wstrdup("");
		}
		return True;
	} else {
		/* the hint is probably not set */
		*winname = NULL;

		return False;
	}
}
	std::string getWindowName(Window win)
	{
		Atom netWmName = XInternAtom(disp(), "_NET_WM_NAME", false);
		int n;
		char **list = 0;
		XTextProperty tp;
		std::string res = "unknown";

		XGetTextProperty(disp(), win, &tp, netWmName);

		if (!tp.nitems)
			XGetWMName(disp(), win, &tp);

		if (!tp.nitems)
			return "error";

		if (tp.encoding == XA_STRING) {
			res = (char*)tp.value;
		} else {
			int ret = XmbTextPropertyToTextList(disp(), &tp, &list,
					&n);

			if (ret >= Success && n > 0 && *list) {
				res = *list;
				XFreeStringList(list);
			}
		}

		XFree(tp.value);

		return res;
	}
Beispiel #14
0
Bool
loadfont(DC *dc, const char *fontstr) {
	char *def, **missing, **names;
	int i, n;
	XFontStruct **xfonts;

	if(!*fontstr)
		return False;
	if((dc->font.set = XCreateFontSet(dc->dpy, fontstr, &missing, &n, &def))) {
		n = XFontsOfFontSet(dc->font.set, &xfonts, &names);
		for(i = 0; i < n; i++) {
			dc->font.ascent  = MAX(dc->font.ascent,  xfonts[i]->ascent);
			dc->font.descent = MAX(dc->font.descent, xfonts[i]->descent);
			dc->font.width   = MAX(dc->font.width,   xfonts[i]->max_bounds.width);
		}
	}
	else if((dc->font.xfont = XLoadQueryFont(dc->dpy, fontstr))) {
		dc->font.ascent  = dc->font.xfont->ascent;
		dc->font.descent = dc->font.xfont->descent;
		dc->font.width   = dc->font.xfont->max_bounds.width;
	}
	if(missing)
		XFreeStringList(missing);
	return dc->font.set || dc->font.xfont;
}
/*
getWinTitle:
   This function gets the window title for a given Window handle.

Input:
   dsp: The current XDisplay.
   win: The window handle that you want the title for.

Output:
   Returns a char* containing the window's title.
 
*/
char *getWinTitle(Display *dsp, Window win) {
   Status status;
   XTextProperty prop;
   char *err = "";
   char **list = NULL;
   int count;
   int ret;

   status = XGetWMName(dsp, win, &prop);
   ret = XmbTextPropertyToTextList(dsp, &prop, &list, &count);
   if (ret == Success || ret > 0 && list != NULL) {
      int i = 0;
      
      for (i = 0; i < count; i++) {
         if (list[i] == NULL) {
            err = "null";
         } else {
            err = (char*)malloc(strlen(list[i])+1);
            err = strcpy(err, list[i]);
         }
      }

      if (list != NULL) {
         XFreeStringList(list);
      }
   } 

   return err;
}
Beispiel #16
0
void win_init_font(Display *dpy, const char *fontstr)
{
	int n;
	char *def, **missing;

	font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
	if (missing)
		XFreeStringList(missing);
	if (font.set) {
		XFontStruct **xfonts;
		char **font_names;

		font.ascent = font.descent = 0;
		XExtentsOfFontSet(font.set);
		n = XFontsOfFontSet(font.set, &xfonts, &font_names);
		while (n--) {
			font.ascent  = MAX(font.ascent, (*xfonts)->ascent);
			font.descent = MAX(font.descent,(*xfonts)->descent);
			xfonts++;
		}
	} else {
		if ((font.xfont = XLoadQueryFont(dpy, fontstr)) == NULL &&
		    (font.xfont = XLoadQueryFont(dpy, "fixed")) == NULL)
		{
			die("could not load font: %s", fontstr);
		}
		font.ascent  = font.xfont->ascent;
		font.descent = font.xfont->descent;
	}
	fontheight = font.ascent + font.descent;
	barheight = fontheight + 2 * V_TEXT_PAD;
}
Beispiel #17
0
static bool register_cm(Display* dpy)
{
	Window w;
	Atom a;
	a = XInternAtom (dpy, "_NET_WM_CM_S0", False);
	w = XGetSelectionOwner (dpy, a);
	if (w != None)
	{
		XTextProperty tp;
		char **strs;
		int count;
		Atom winNameAtom = XInternAtom (dpy, "_NET_WM_NAME", False);
		if (!XGetTextProperty (dpy, w, &tp, winNameAtom) && !XGetTextProperty (dpy, w, &tp, XA_WM_NAME))
		{
			fprintf (stderr, "Another composite manager is already running (0x%lx)\n", (unsigned long) w);
			return false;
		}
		if (XmbTextPropertyToTextList (dpy, &tp, &strs, &count) == Success)
		{
			fprintf (stderr, "Another composite manager is already running (%s)\n", strs[0]);
			XFreeStringList (strs);
		}
		XFree (tp.value);
		return false;
	}
	w = XCreateSimpleWindow (dpy, RootWindow (dpy, 0), 0, 0, 1, 1, 0, None, None);
	Xutf8SetWMProperties (dpy, w, "xcompmgr", "xcompmgr", NULL, 0, NULL, NULL, NULL);
	XSetSelectionOwner (dpy, a, w, 0);
	return true;
}
Beispiel #18
0
void initfont(const char *fontstr)
{
	char *def, **missing;
	int n;

	dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
	if (missing)
		XFreeStringList(missing);
	if (dc.font.set) {
		char **font_names;
		XFontStruct **xfonts;

		dc.font.ascent = dc.font.descent = 0;
		n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
		while (n--) {
			dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent);
			dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent);
			xfonts++;
		}
	} else {
		if (!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))
				&& !(dc.font.xfont = XLoadQueryFont(dpy, "fixed")))
			die("cannot load font '%s'\n", fontstr);
		dc.font.ascent = dc.font.xfont->ascent;
		dc.font.descent = dc.font.xfont->descent;
	}
	dc.font.height = dc.font.ascent + dc.font.descent;
}
Beispiel #19
0
void
initfont(DC *dc, const char *fontstr) {
	char *def, **missing, **names;
	int i, n;
	XFontStruct **xfonts;

	missing = NULL;
	if((dc->font.xfont = XLoadQueryFont(dc->dpy, fontstr))) {
		dc->font.ascent = dc->font.xfont->ascent;
		dc->font.descent = dc->font.xfont->descent;
		dc->font.width   = dc->font.xfont->max_bounds.width;
	} else if((dc->font.set = XCreateFontSet(dc->dpy, fontstr,
                                           &missing, &n, &def))) {
		n = XFontsOfFontSet(dc->font.set, &xfonts, &names);
		for(i = 0; i < n; i++) {
			dc->font.ascent  = MAX(dc->font.ascent,  xfonts[i]->ascent);
			dc->font.descent = MAX(dc->font.descent, xfonts[i]->descent);
			dc->font.width   = MAX(dc->font.width,   xfonts[i]->max_bounds.width);
		}
	} else if((dc->font.xft_font = XftFontOpenName(dc->dpy,
                                                 DefaultScreen(dc->dpy),
                                                 fontstr))) {
		dc->font.ascent = dc->font.xft_font->ascent;
		dc->font.descent = dc->font.xft_font->descent;
		dc->font.width = dc->font.xft_font->max_advance_width;
	} else {
		eprintf("cannot load font '%s'\n", fontstr);
	}
	if(missing)
		XFreeStringList(missing);
	dc->font.height = dc->font.ascent + dc->font.descent;
	return;
}
Beispiel #20
0
XFontSet de_create_font_in_current_locale(const char *fontname)
{
    XFontSet fs;
    char **missing=NULL, *def="-";
    int nmissing=0;
    
    LOG(DEBUG, FONT, "Creating fontset for: %s", fontname);
    
    fs=XCreateFontSet(ioncore_g.dpy, fontname, &missing, &nmissing, &def);

    if(fs){
        if(nmissing==0)
            LOG(DEBUG, FONT, "Found a font without missing charsets for %s, returning it.", fontname);
        else {
            int i;
            LOG(INFO, FONT, "Found a font with %d missing charsets for %s:", nmissing, fontname);
            for(i=0;i<nmissing;i++)
                LOG(DEBUG, FONT, "* %s", missing[i]);
        }
    }else{
        LOG(WARN, FONT, "Found no font for %s.", fontname);
    }

    if(missing!=NULL)
        XFreeStringList(missing);

    return fs;
}
Beispiel #21
0
static XFont*
font_create(Display *dpy, const char *name)
{
    int n;
    char *def, **missing;
    XFont *font = (XFont*)xcalloc(1, sizeof(XFont));
    font->set = XCreateFontSet(dpy, name, &missing, &n, &def);
    if(missing) {
        while(n--)
            fprintf(stderr, "missing fontset: %s\n", missing[n]);
        XFreeStringList(missing);
    }

    if(font->set) {
        XFontStruct **xfonts;
        char **font_names;
        XExtentsOfFontSet(font->set);
        n = XFontsOfFontSet(font->set, &xfonts, &font_names);
        while(n--) {
            font->ascent = MAX(font->ascent, (*xfonts)->ascent);
            font->descent = MAX(font->descent,(*xfonts)->descent);
            xfonts++;
        }
    } else {
        if(!(font->xfont = XLoadQueryFont(dpy, name))
        && !(font->xfont = XLoadQueryFont(dpy, "fixed")))
            die("error, cannot load font: '%s'\n", name);
        font->ascent = font->xfont->ascent;
        font->descent = font->xfont->descent;
    }
    font->height = font->ascent + font->descent;
    return font;
}
Beispiel #22
0
char *ICCCM::get_title(Frame *f)
{
    XTextProperty xtp;
    char *title = 0;

    if(XGetWMName(fl_display, f->window(), &xtp))
    {
        if(xtp.encoding == XA_STRING) {
            title = strdup((const char*)xtp.value);
        } else {
#if HAVE_X11_UTF_TEXT_PROP
            int items;
            char **list=0;
            Status s;
            s = Xutf8TextPropertyToTextList(fl_display, &xtp, &list, &items);
            if((s == Success) && (items > 0)) {
                title = strdup((const char *)*list);
            } else
                title = strdup((const char *)xtp.value);
            if(list) XFreeStringList(list);
#else
            title = strdup((const char*)xtp.value);
#endif
        }
        XFree(xtp.value);
    }
    return title;
}
	std::string getWindowCommand(Window win)
	{
		Atom xi = XInternAtom(disp(), "WM_COMMAND", false);
		int n;
		char **list = 0;
		XTextProperty tp;
		std::string res = "error";

		XGetTextProperty(disp(), win, &tp, xi);

		if (!tp.nitems)
			return std::string();

		if (tp.encoding == XA_STRING) {
			res = (char*)tp.value;
		} else {
			int ret = XmbTextPropertyToTextList(disp(), &tp, &list,
					&n);
			if (ret >= Success && n > 0 && *list) {
				res = *list;
				XFreeStringList(list);
			}
		}

		XFree(tp.value);

		return res;
	}
Beispiel #24
0
/*ARGSUSED*/
static Boolean
XawCvtCompoundTextToString(Display *dpy, XrmValuePtr args, Cardinal *num_args,
			   XrmValue *fromVal, XrmValue *toVal,
			   XtPointer *cvt_data)
{
    XTextProperty prop;
    char **list;
    int count;
    static char *mbs = NULL;
    int len;

    prop.value = (unsigned char *)fromVal->addr;
    prop.encoding = XA_COMPOUND_TEXT(dpy);
    prop.format = 8;
    prop.nitems = fromVal->size;

    if(XmbTextPropertyToTextList(dpy, &prop, &list, &count) < Success) {
	XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
	"converter", "XmbTextPropertyToTextList", "XawError",
	"conversion from CT to MB failed.", NULL, 0);
	return False;
    }
    len = strlen(*list);
    toVal->size = len;
    mbs = XtRealloc(mbs, len + 1); /* keep buffer because no one call free :( */
    strcpy(mbs, *list);
    XFreeStringList(list);
    toVal->addr = (XtPointer)mbs;
    return True;
}
static void
GetWindowName (Display *pDisplay, Window iWin, char **ppName)
{
  int			nResult, nNum;
  char			**ppList;
  XTextProperty		xtpName;
  
#if CYGMULTIWINDOW_DEBUG
  ErrorF ("GetWindowName\n");
#endif

  /* Intialize ppName to NULL */
  *ppName = NULL;

  /* Try to get --- */
  nResult = XGetWMName (pDisplay, iWin, &xtpName);
  if (!nResult || !xtpName.value || !xtpName.nitems)
    {
      ErrorF ("GetWindowName - XGetWMName failed.  No name.\n");
      return;
    }
  
  /* */
  if (xtpName.encoding == XA_STRING)
    {
      /* */
      if (xtpName.value)
	{
	  *ppName = strdup ((char*)xtpName.value);
	  XFree (xtpName.value);
	}

#if CYGMULTIWINDOW_DEBUG
      ErrorF ("XA_STRING %s\n", *ppName);
#endif
    }
  else
    {
      XmbTextPropertyToTextList (pDisplay, &xtpName, &ppList, &nNum);

      /* */
      if (nNum && *ppList)
	{
	  XFree (xtpName.value);
	  *ppName = strdup (*ppList);
	  XFreeStringList (ppList);
	}

#if CYGMULTIWINDOW_DEBUG
      ErrorF ("%s %s\n", XGetAtomName (pDisplay, xtpName.encoding), *ppName);
#endif
    }


#if CYGMULTIWINDOW_DEBUG
  ErrorF ("-GetWindowName\n");
#endif
}
Beispiel #26
0
/**
 * Get a window icon name.
 * @param win The window
 * @return The windows icon name string
 *
 * Return the icon name of a window. String must be free'd when done with.
 */
EAPI char *
ecore_x_icccm_icon_name_get(Ecore_X_Window win)
{
   XTextProperty xprop;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   xprop.value = NULL;
   if (XGetWMIconName(_ecore_x_disp, win, &xprop) >= Success)
     {
        if (_ecore_xlib_sync) ecore_x_sync();
        if (xprop.value)
          {
             char **list = NULL;
             char *t = NULL;
             int num = 0;
             int ret;

             if (xprop.encoding == ECORE_X_ATOM_UTF8_STRING)
               t = strdup((char *)xprop.value);
             else
               {
                  /* convert to utf8 */
#ifdef X_HAVE_UTF8_STRING
                  ret = Xutf8TextPropertyToTextList(_ecore_x_disp, &xprop,
                                                    &list, &num);
#else /* ifdef X_HAVE_UTF8_STRING */
                  ret = XmbTextPropertyToTextList(_ecore_x_disp, &xprop,
                                                  &list, &num);
#endif /* ifdef X_HAVE_UTF8_STRING */
                  if (_ecore_xlib_sync) ecore_x_sync();

                  if ((ret == XLocaleNotSupported) ||
                      (ret == XNoMemory) || (ret == XConverterNotFound))
                    t = strdup((char *)xprop.value);
                  else if (ret >= Success)
                    {
                       if ((num >= 1) && (list))
                         t = strdup(list[0]);

                       if (list)
                         XFreeStringList(list);
                    }
               }

             if (xprop.value)
               XFree(xprop.value);

             return t;
          }
     }
   else
     {
        if (_ecore_xlib_sync) ecore_x_sync();
     }

   return NULL;
}
Beispiel #27
0
void query(Display *xdpy, int window, int level) {
  int i, j;
  Window *children, dummy;
  unsigned int nchildren;

  if (!XQueryTree(xdpy, window, &dummy, &dummy, &children, &nchildren))
    return;

  for (i = 0; i < nchildren; i++) {
    Window w = children[i];
    XWindowAttributes attr;
    XTextProperty tp;
    XClassHint classhint;
    char *name;

    XGetWindowAttributes(xdpy, w, &attr);
    XGetWMName(xdpy, w, &tp);

    if (tp.nitems > 0) {
      indent(level - 1);
      printf("+ %d (%dx%d@%d,%d) [%s]\n", w, 
             attr.x, attr.y, attr.width, attr.height,
             (attr.map_state == IsViewable ? "Visible" : "Hidden"));

      int count = 0;
      char **list = NULL;
      int ret;
      ret = XmbTextPropertyToTextList(xdpy, &tp, &list, &count);
      indent(level);
      for (j = 0; j < count; j++)
        printf("%s", list[j]);
      XFreeStringList(list);
    } else {
      //printf("(!) %s\n", tp.value);
      query(xdpy, w, level);
      continue;
    }

    if (XGetClassHint(xdpy, w, &classhint)) {
      printf("\n");
      indent(level);
      if (classhint.res_name) {
        printf("\"%s\" ", classhint.res_name);
        XFree(classhint.res_name);
      }
      if (classhint.res_class) {
        printf("\"%s\" ", classhint.res_class);
        XFree(classhint.res_class);
      }
    }
    printf("\n");

    query(xdpy, w, level+1);
  }

}
Beispiel #28
0
/** Init the font
*/
static void
init_font(void)
{
#ifdef HAVE_XFT
     if(conf.use_xft)
     {
          if(!(font.font = XftFontOpenName(dpy, SCREEN, conf.font)))
          {
               warnx("WMFS Error: Cannot initialize Xft font");
               font.font = XftFontOpenName(dpy, SCREEN, "sans-10");
          }

          font.de     = font.font->descent;
          font.as     = font.font->ascent;
          font.height = font.font->height;
     }
     else
#endif /* HAVE_XFT */
     {
          char **misschar, **names, *defstring;
          int d;
          XFontStruct **xfs = NULL;

          /* locale support */
          setlocale(LC_CTYPE, "");

          if(!conf.font)
               conf.font = xstrdup("fixed");

          /* Using Font Set */
          if(!(font.fontset = XCreateFontSet(dpy, conf.font, &misschar, &d, &defstring)))
          {
               warnx("Can't load font '%s'", conf.font);
               font.fontset = XCreateFontSet(dpy, "fixed", &misschar, &d, &defstring);
          }

          XExtentsOfFontSet(font.fontset);
          XFontsOfFontSet(font.fontset, &xfs, &names);

          font.as    = xfs[0]->max_bounds.ascent;
          font.de    = xfs[0]->max_bounds.descent;
          font.width = xfs[0]->max_bounds.width;

          font.height = font.as + font.de;

          if(misschar)
               XFreeStringList(misschar);
     }

     /* Set font in _WMFS_FONT for eventual status tools */
     XChangeProperty(dpy, ROOT, net_atom[wmfs_font], net_atom[utf8_string], 8,
                    PropModeReplace, (uchar*)conf.font, strlen(conf.font));

     return;
}
Beispiel #29
0
Datei: draw.c Projekt: dylex/dzen
void
setfont(const char *fontstr) {
#ifndef DZEN_XFT
	char *def, **missing;
	int i, n;

	missing = NULL;
	if(dzen.font.set)
		XFreeFontSet(dzen.dpy, dzen.font.set);

	dzen.font.set = XCreateFontSet(dzen.dpy, fontstr, &missing, &n, &def);
	if(missing)
		XFreeStringList(missing);

	if(dzen.font.set) {
		XFontSetExtents *font_extents;
		XFontStruct **xfonts;
		char **font_names;
		dzen.font.ascent = dzen.font.descent = 0;
		font_extents = XExtentsOfFontSet(dzen.font.set);
		n = XFontsOfFontSet(dzen.font.set, &xfonts, &font_names);
		for(i = 0, dzen.font.ascent = 0, dzen.font.descent = 0; i < n; i++) {
			if(dzen.font.ascent < (*xfonts)->ascent)
				dzen.font.ascent = (*xfonts)->ascent;
			if(dzen.font.descent < (*xfonts)->descent)
				dzen.font.descent = (*xfonts)->descent;
			xfonts++;
		}
	}
	else {
		if(dzen.font.xfont)
			XFreeFont(dzen.dpy, dzen.font.xfont);
		dzen.font.xfont = NULL;
		if(!(dzen.font.xfont = XLoadQueryFont(dzen.dpy, fontstr)))
			eprint("dzen: error, cannot load font: '%s'\n", fontstr);
		dzen.font.ascent = dzen.font.xfont->ascent;
		dzen.font.descent = dzen.font.xfont->descent;
	}
	dzen.font.height = dzen.font.ascent + dzen.font.descent;
#else
        if(dzen.font.xftfont)
           XftFontClose(dzen.dpy, dzen.font.xftfont);
	dzen.font.xftfont = XftFontOpenXlfd(dzen.dpy, dzen.screen, fontstr);
	if(!dzen.font.xftfont)
	   dzen.font.xftfont = XftFontOpenName(dzen.dpy, dzen.screen, fontstr);
	if(!dzen.font.xftfont)
	   eprint("error, cannot load font: '%s'\n", fontstr);
	dzen.font.extents = malloc(sizeof(XGlyphInfo));
	XftTextExtentsUtf8(dzen.dpy, dzen.font.xftfont, (unsigned const char *) fontstr, strlen(fontstr), dzen.font.extents);
	dzen.font.height = dzen.font.xftfont->ascent + dzen.font.xftfont->descent;
	dzen.font.width = (dzen.font.extents->width)/strlen(fontstr);
#endif
}
Beispiel #30
0
void
x_init_font()
{
    int i, n;
    char *def, **missing;
    XFontStruct **xfonts;
    char **font_names;

    X.font = XCreateFontSet(X.dpy,
                            config.font,
                            &missing,
                            &n,
                            &def);
    if (missing) {
        while (n--) {
            debug("Missing font: %s", missing[n]);
        }
        XFreeStringList(missing);
    }

    X.bold_font = XCreateFontSet(X.dpy,
                                 config.bold_font,
                                 &missing,
                                 &n,
                                 &def);
    if (missing) {
        while (n--) {
            debug("Missing font: %s", missing[n]);
        }
        XFreeStringList(missing);
    }

    n = XFontsOfFontSet(X.font, &xfonts, &font_names);
    for (i = 0; i < n; i++) {
        X.glyph_ascent  = max(X.glyph_ascent,  xfonts[i]->ascent);
        X.glyph_descent = max(X.glyph_descent, xfonts[i]->descent);
        X.glyph_height  = X.glyph_ascent + X.glyph_descent;
        X.glyph_width   = max(X.glyph_width,   xfonts[i]->max_bounds.width);
    }
}