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];
}
Example #2
0
File: wmfs.c Project: 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);
}
Example #3
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;
}
Example #4
0
File: init.c Project: pierreN/wmfs
/** 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;
}
XFontSet YsSystemFontCache::InternalData::MakeFontSet(int height)
{
	if(NULL!=dsp)
	{
		const char *fontNameFmt=
			"-*-*-*-*-*-*-%d-*-*-*-*-*-iso8859-1,"
			"-*-*-*-*-*-*-%d-*-*-*-*-*-iso8859-2,"
			"-*-*-*-*-*-*-%d-*-*-*-*-*-iso8859-4,"
			"-*-*-*-*-*-*-%d-*-*-*-*-*-iso8859-5,"
			"-*-*-*-*-*-*-%d-*-*-*-*-*-iso8859-6,"
			"-*-*-*-*-*-*-%d-*-*-*-*-*-iso8859-7,"
			"-*-*-*-*-*-*-%d-*-*-*-*-*-iso8859-8,"
			"-*-*-*-*-*-*-%d-*-*-*-*-*-iso8859-9,"
			"-*-*-*-*-*-*-%d-*-*-*-*-*-iso8859-15,"
			"-*-*-*-*-*-*-%d-*-*-*-*-*-iso10646-1";
		char fontNameBuf[1024];
		snprintf(fontNameBuf,1023,fontNameFmt,
				 height,
				 height,
				 height,
				 height,
				 height,
				 height,
				 height,
				 height,
				 height,
				 height);
		fontNameBuf[1023]=0;
		
		int missSetCount;
		char *defStr,**missSet;
		return XCreateFontSet(dsp,fontNameBuf,&missSet,&missSetCount,&defStr);
	}
	return NULL;
}
Example #6
0
static void
Realize(Widget aw, XtValueMask * value_mask, XSetWindowAttributes * attributes)
{
	XltFontChooserWidget	fc = (XltFontChooserWidget) aw;
	char			*f = XtMalloc(256), **list;
	int			i, j, nfonts;

#define	superclass	(&xmMessageBoxClassRec)
  (*superclass->core_class.realize) (aw, value_mask, attributes);
#undef	superclass

	if (! FC_ShowDemo(fc))
		return;

/* Show the right font initially */
	f[0] = '\0';
	for (j=0; j<14; j++) {
		strcat(f, "-");
		strcat(f, FC_Setting(fc)[j]);
	}

	if (FC_FontName(fc))
		XtFree(FC_FontName(fc));
	FC_FontName(fc) = f;

/* How many fonts ? */
	list = XListFonts(XtDisplay(fc), f, 4096, &nfonts);
	for (i=0; i<nfonts; i++)
		EnableMenu(aw, list[i]);
	XFreeFontNames(list);

	if (FC_DemoWidget(fc)) {
		XmFontList      fl;
		XmFontListEntry fle;
		XFontSet        fs;
		char            m1[2][80], **missing = (char **)&m1[0][0];
		char            m2[80], *def = &m2[0];
		int             nmissing = 0;

		fs = XCreateFontSet(XtDisplay(fc), f, &missing, &nmissing, &def);

		if (fs != NULL) {
                	fle = XmFontListEntryCreate(XmFONTLIST_DEFAULT_TAG,
			         XmFONT_IS_FONTSET, (XtPointer)fs);
                	fl = XmFontListAppendEntry(NULL, fle);

			XtVaSetValues(FC_DemoWidget(fc), XmNfontList, fl, NULL);

			XmFontListEntryFree(&fle);
			XmFontListFree(fl);
#if 0
			/* Freeing the font set produces nice little core dumps */
			XFreeFontSet(XtDisplay(fc), fs);	/* FIX ME leak ?? */
#endif
        	}

	}

	ShowCount(aw, nfonts);
}
Example #7
0
File: window.c Project: hirkmt/sxiv
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;
}
Example #8
0
File: draw.c Project: Yomin/dmenu
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;
}
Example #9
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;
}
Example #10
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;
}
Example #11
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;
}
Example #12
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;
}
Example #13
0
File: draw.c Project: 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
}
Example #14
0
XFontSet
getFontSet(Display * display)
{
	char **miss, *def;
	int n_miss;
	XFontSet fs;

	fs = XCreateFontSet(display,
			    DEF_MESSAGEFONTSET,
			    &miss, &n_miss, &def);
	return fs;
}
Example #15
0
File: terma.c Project: halhen/terma
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);
    }
}
Example #16
0
/*----------------------------------------------------------------------------*/
void VKFontSetInit()
{
	int missing_count;
	char **missing_list;
	char *def_string;
	char *backup = NULL;

	vk_fontset = XCreateFontSet(display, vk_font_name, &missing_list,
								&missing_count, &def_string);
	if( !vk_fontset ) {
		char *p = strchr(vk_font_name, ':');
		if( p ) {
			TRACE("It seems XFT font name,"
				" strip extended info and try to reload fontset.\n");
			backup = vk_font_name;
			vk_font_name = strdup(VKXftFont2XFont(vk_font_name));
		}
		else {
			TRACE("Unknown fontname style.\n"
				"Try to load fontset with default font.\n");
			VKUseDefaultFont();
		}
		vk_fontset = XCreateFontSet(display, vk_font_name, &missing_list,
									&missing_count, &def_string);
	}
	if( !vk_fontset ) {
		if( backup ) {
			VKUseDefaultFont();
			vk_fontset = XCreateFontSet(display, vk_font_name, &missing_list,
									&missing_count, &def_string);
		}
		if( !vk_fontset ) error("Error: cannot load font set.\n");
	}
	if( backup ) {
		free(vk_font_name);
		vk_font_name = backup;
	}
}
Example #17
0
XFontSet getFont(Display *dpy, XrmDatabase db, char *name,
		char *cl, char *def){
	XrmValue v;
	char * type;
	XFontSet font = NULL;
	int nmissing;
	char **missing;
	char *def_string;

	if (XrmGetResource(db, name, cl, &type, &v)){
		if (v.addr)
			font = XCreateFontSet(dpy, v.addr, &missing, &nmissing, &def_string);
	}
	if (!font) {
		if (v.addr)
		fprintf(stderr, "unable to load preferred font: %s using fixed\n", v.addr);
		else 
		fprintf(stderr, "couldn't figure out preferred font\n");
		font = XCreateFontSet(dpy, def, &missing, &nmissing, &def_string);
	}
	XFreeStringList(missing);
	return font;
}
Example #18
0
void
initfont(const char *fontstr)
{
    char *def, **missing;
    int i, n;

    missing = NULL;
    if(dc.font.set)
        XFreeFontSet(dpy, dc.font.set);
    dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
    if(missing) {
        while(n--) {
            fprintf(stderr, "thingmenu: missing fontset: %s\n",
                    missing[n]);
        }
        XFreeStringList(missing);
    }
    if(dc.font.set) {
        XFontStruct **xfonts;
        char **font_names;
        dc.font.ascent = dc.font.descent = 0;
        n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
        for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
            dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent);
            dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent);
            xfonts++;
        }
    }
    else {
        if(dc.font.xfont)
            XFreeFont(dpy, dc.font.xfont);
        dc.font.xfont = NULL;
        if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))
                && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed")))
            die("error, 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;
}
Example #19
0
static void font_x11_sel_font(int type, int size) {
	XFontStruct **font_structs;
	char        **font_names;
	int         i, num_fonts;
	FontTable   *tbl;
	
	if (NULL == (tbl = font_lookup(size, type))) {
		char  name[256];
		char **miss, *def;
		int    n_miss;
		XFontSet fs;
	
		if (type > 3) type = FONT_GOTHIC;
		
		/* set size */
		g_snprintf(name, sizeof(name), this->name[type], size, size);
		
		fs = XCreateFontSet(x11_display, name, &miss, &n_miss, &def);
		if (n_miss > 0) {
			for (i = 0; i < n_miss; i++) {
				WARNING("can't load font %s\n", miss[i]);
			}
			XFreeStringList(miss);
			SYSERROR("Font Load failed\n");
		}
		font_insert(size, type, fs);
		fontset = fs;
	} else {
		fontset = tbl->id;
	}
	
	/* 最大のフォントの高さの取得 */
	num_fonts = XFontsOfFontSet(fontset, &font_structs, &font_names);
	font_ascent = font_descent = 0;
	for (i = 0; i < num_fonts; i++) {
		font_ascent  = max(font_ascent, font_structs[i]->ascent);
		font_descent = max(font_descent, font_structs[i]->descent);
	}
}
Example #20
0
static void
x_preload(const char *fontstr, int p) {
	char *def, **missing;
	int i, n;

	missing = NULL;

	dzen.fnpl[p].set = XCreateFontSet(dzen.dpy, fontstr, &missing, &n, &def);
	if(missing)
		XFreeStringList(missing);

	if(dzen.fnpl[p].set) {
		XFontSetExtents *font_extents;
		XFontStruct **xfonts;
		char **font_names;
		dzen.fnpl[p].ascent = dzen.fnpl[p].descent = 0;
		font_extents = XExtentsOfFontSet(dzen.fnpl[p].set);
		n = XFontsOfFontSet(dzen.fnpl[p].set, &xfonts, &font_names);
		for(i = 0, dzen.fnpl[p].ascent = 0, dzen.fnpl[p].descent = 0; i < n; i++) {
			if(dzen.fnpl[p].ascent < (*xfonts)->ascent)
				dzen.fnpl[p].ascent = (*xfonts)->ascent;
			if(dzen.fnpl[p].descent < (*xfonts)->descent)
				dzen.fnpl[p].descent = (*xfonts)->descent;
			xfonts++;
		}
	}
	else {
		if(dzen.fnpl[p].xfont)
			XFreeFont(dzen.dpy, dzen.fnpl[p].xfont);
		dzen.fnpl[p].xfont = NULL;
		if(!(dzen.fnpl[p].xfont = XLoadQueryFont(dzen.dpy, fontstr)))
			eprint("dzen: error, cannot load font: '%s'\n", fontstr);
		dzen.fnpl[p].ascent = dzen.fnpl[p].xfont->ascent;
		dzen.fnpl[p].descent = dzen.fnpl[p].xfont->descent;
	}
	dzen.fnpl[p].height = dzen.fnpl[p].ascent + dzen.fnpl[p].descent;
}
Example #21
0
Fnt *
draw_font_create(Draw *draw, const char *fontname) {
	Fnt *font;
	char *def, **missing;
	int n;

	if(!draw)
		return NULL;
	font = (Fnt *)calloc(1, sizeof(Fnt));
	font->set = XCreateFontSet(draw->dpy, fontname, &missing, &n, &def);
	if(missing) {
		while(n--)
			fprintf(stderr, "draw: 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(draw->dpy, fontname))
		&& !(font->xfont = XLoadQueryFont(draw->dpy, "fixed")))
			die("error, cannot load font: '%s'\n", fontname);
		font->ascent = font->xfont->ascent;
		font->descent = font->xfont->descent;
	}
	font->h = font->ascent + font->descent;
	return font;
}
Example #22
0
static void
OpenIM(
    TkDisplay *dispPtr)		/* Tk's structure for the display. */
{
    int i;
    XIMStyles *stylePtr;
    XIMStyle bestStyle = 0;

    if (XSetLocaleModifiers("") == NULL) {
	return;
    }

    dispPtr->inputMethod = XOpenIM(dispPtr->display, NULL, NULL, NULL);
    if (dispPtr->inputMethod == NULL) {
	return;
    }

    if ((XGetIMValues(dispPtr->inputMethod, XNQueryInputStyle, &stylePtr,
	    NULL) != NULL) || (stylePtr == NULL)) {
	goto error;
    }

    /*
     * Select the best input style supported by both the IM and Tk.
     */
    for (i = 0; i < stylePtr->count_styles; i++) {
	XIMStyle thisStyle = stylePtr->supported_styles[i];
	if (thisStyle == (XIMPreeditPosition | XIMStatusNothing)) {
	    bestStyle = thisStyle;
	    break;
	} else if (thisStyle == (XIMPreeditNothing | XIMStatusNothing)) {
	    bestStyle = thisStyle;
	}
    }
    XFree(stylePtr);
    if (bestStyle == 0) {
	goto error;
    }

    dispPtr->inputStyle = bestStyle;

    /*
     * Create an XFontSet for preedit area.
     */
    if (dispPtr->inputStyle & XIMPreeditPosition) {
	char **missing_list;
	int missing_count;
	char *def_string;

	dispPtr->inputXfs = XCreateFontSet(dispPtr->display,
		"-*-*-*-R-Normal--14-130-75-75-*-*",
		&missing_list, &missing_count, &def_string);
	if (missing_count > 0) {
	    XFreeStringList(missing_list);
	}
    }

    return;

error:
    if (dispPtr->inputMethod) {
	XCloseIM(dispPtr->inputMethod);
	dispPtr->inputMethod = NULL;
    }
}
Example #23
0
/*
 * Try to open a XIM with the current modifiers, then see if we can
 * open a suitable preedit type
 */
bool
rxvt_term::IM_get_IC (const char *modifiers)
{
  int i, j, found;
  XIM xim;
  XPoint spot;
  XRectangle rect, status_rect, needed_rect;
  unsigned long fg, bg;
  const char *p;
  char **s;
  XIMStyles *xim_styles;
#ifdef ENABLE_XIM_ONTHESPOT
  XIMCallback xcb[4];
#endif

  set_environ (envv);

  if (! ((p = XSetLocaleModifiers (modifiers)) && *p))
    return false;

  input_method = display->get_xim (locale, modifiers);
  if (input_method == NULL)
    return false;

  xim = input_method->xim;
  spot.x = spot.y = -1;

  xim_styles = NULL;
  if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL)
      || !xim_styles || !xim_styles->count_styles)
    {
      im_destroy ();
      return false;
    }

  const char *pet[] = { rs[Rs_preeditType], "OverTheSpot,OffTheSpot,Root,None" };

  for (int pi = 0; pi < 2; pi++)
    {
      p = pet[pi];

      if (!p)
        continue;

      s = rxvt_splitcommastring (p);

      for (i = found = 0; !found && s[i]; i++)
        {
          if (!strcmp (s[i], "OverTheSpot"))
            input_style = XIMPreeditPosition | XIMStatusNothing;
          else if (!strcmp (s[i], "OffTheSpot"))
            input_style = XIMPreeditArea | XIMStatusArea;
          else if (!strcmp (s[i], "Root"))
            input_style = XIMPreeditNothing | XIMStatusNothing;
          else if (!strcmp (s[i], "None"))
            input_style = XIMPreeditNone | XIMStatusNone;
#ifdef ENABLE_XIM_ONTHESPOT
          else if (SHOULD_INVOKE (HOOK_XIM_PREEDIT_START) && !strcmp (s[i], "OnTheSpot"))
            input_style = XIMPreeditCallbacks | XIMStatusNothing;
#endif
          else
            input_style = XIMPreeditNothing | XIMStatusNothing;

          for (j = 0; j < xim_styles->count_styles; j++)
            if (input_style == xim_styles->supported_styles[j])
              {
                rxvt_freecommastring (s);

                found = 1;
                goto foundpet;
              }

        }

      rxvt_freecommastring (s);
    }

foundpet:

  XFree (xim_styles);

  if (!found)
    {
      im_destroy ();
      return false;
    }

  XFontSet fs = 0;
  XVaNestedList preedit_attr = 0, status_attr = 0;

  if (input_style & (XIMPreeditPosition | XIMPreeditArea))
    {
      // fake us a font-set, please
      char **missing_charset_list;
      int missing_charset_count;
      char *def_string;
      char pat[512];

      sprintf (pat,
               "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
               "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
               "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
               "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
               "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
               "*",
               fheight,
               fheight + 1, fheight - 1,
               fheight - 2, fheight + 2);

      fs = XCreateFontSet (dpy, rs[Rs_imFont] ? rs[Rs_imFont] : pat,
                           &missing_charset_list, &missing_charset_count, &def_string);

      if (missing_charset_list)
        XFreeStringList (missing_charset_list);

      if (!fs)
        {
          input_style &= ~(XIMPreeditPosition | XIMPreeditArea);
          rxvt_warn ("unable to create fontset for input method, try \"-pt Root\". Continuing.\n");
        }
    }

  if (input_style & XIMPreeditPosition)
    {
      im_set_size (rect);
      im_set_position (spot);
      im_set_color (fg, bg);

      preedit_attr = XVaCreateNestedList (0,
                                          XNForeground, fg,
                                          XNBackground, bg,
                                          XNArea, &rect,
                                          XNSpotLocation, &spot,
                                          XNFontSet, fs,
                                          NULL);
    }
  else if (input_style & XIMPreeditArea)
    {
      im_set_color (fg, bg);

      /*
       * The necessary width of preedit area is unknown
       * until create input context.
       */
      needed_rect.width = 0;
      im_set_preedit_area (rect, status_rect, needed_rect);

      preedit_attr = XVaCreateNestedList (0,
                                          XNForeground, fg,
                                          XNBackground, bg,
                                          XNArea, &rect,
                                          XNFontSet, fs,
                                          NULL);
      status_attr = XVaCreateNestedList (0,
                                         XNForeground, fg,
                                         XNBackground, bg,
                                         XNArea, &status_rect,
                                         XNFontSet, fs,
                                         NULL);
    }
#if ENABLE_XIM_ONTHESPOT
  else if (input_style & XIMPreeditCallbacks)
    {
      im_set_position (spot);

      xcb[0].client_data = (XPointer)this; xcb[0].callback = (XIMProc)xim_preedit_start;
      xcb[1].client_data = (XPointer)this; xcb[1].callback = (XIMProc)xim_preedit_done;
      xcb[2].client_data = (XPointer)this; xcb[2].callback = (XIMProc)xim_preedit_draw;
# if 0
      xcb[3].client_data = (XPointer)this; xcb[3].callback = (XIMProc)xim_preedit_caret;
# endif

      preedit_attr = XVaCreateNestedList (0,
                                          XNSpotLocation, &spot,
                                          XNPreeditStartCallback, &xcb[0],
                                          XNPreeditDoneCallback , &xcb[1],
                                          XNPreeditDrawCallback , &xcb[2],
# if 0
                                          XNPreeditCaretCallback, &xcb[3],
# endif
                                          NULL);
    }
#endif

  Input_Context = XCreateIC (xim,
                             XNInputStyle, input_style,
                             XNClientWindow, vt,
                             XNFocusWindow, parent[0],
                             preedit_attr ? XNPreeditAttributes : NULL,
                             preedit_attr,
                             status_attr ? XNStatusAttributes : NULL,
                             status_attr, NULL);

  if (preedit_attr) XFree (preedit_attr);
  if (status_attr)  XFree (status_attr);
  if (fs)           XFreeFontSet (dpy, fs);

  if (Input_Context == NULL)
    {
      rxvt_warn ("failed to create input context, continuing without XIM.\n");
      im_destroy ();
      return false;
    }

#if 0
  // unfortunately, only the focus window is used by XIM, hard to fix
  if (!XGetICValues (Input_Context, XNFilterEvents, &vt_emask_xim, NULL))
    vt_select_input ();
#endif

  IMSetPosition ();

  return true;
}
Example #24
0
static void
ShowAlert(const char *title,
	  const char *ignore, const char *restart, const char *quit,
	  const char *fmt, va_list args)
{
   char                text[4096], buf1[64], buf2[64], buf3[64];
   Window              win, b1 = 0, b2 = 0, b3 = 0, root;
   Display            *dd;
   int                 wid, hih, w, h, i, k, mask;
   XGCValues           gcv;
   GC                  gc;
   unsigned int        len;
   XEvent              ev;
   XSetWindowAttributes att;
   XRectangle          rect1, rect2;
   char                colorful;
   unsigned long       cols[5];
   XColor              xcl;
   Colormap            cmap;
   int                 cnum, fh, x, y, ww, hh, bw, bh;
   char               *str1, *str2, *str3, *p;
   KeyCode             keycode;
   int                 button;
   char              **missing_charset_list_return, *def_string_return;
   int                 missing_charset_count_return;
   XFontStruct       **font_struct_list_return;
   char              **font_name_list_return;

#if 0
   /* Don't play sound here (maybe if not forked/in signal handler - later) */
   SoundPlay(SOUND_ALERT);
#endif

   if (!fmt)
      return;

   Evsnprintf(text, sizeof(text), fmt, args);

   /*
    * We may get here from obscure places like an X-error or signal handler
    * and things seem to work properly only if we do a new XOpenDisplay().
    */
   dd = XOpenDisplay(NULL);
   if (!dd)
     {
	fprintf(stderr, "%s\n", text);
	fflush(stderr);
	return;
     }

   button = 0;

   if (!title)
      title = _("Enlightenment Error");
   str1 = AlertButtonText(1, buf1, sizeof(buf1), ignore);
   str2 = AlertButtonText(2, buf2, sizeof(buf2), restart);
   str3 = AlertButtonText(3, buf3, sizeof(buf3), quit);

   cnum = 0;
   colorful = 0;
   cols[0] = cols[1] = cols[2] = cols[3] = cols[4] = 0;
   cmap = DefaultColormap(dd, DefaultScreen(dd));
   if (DefaultDepth(dd, DefaultScreen(dd)) > 4)
     {
	ExSetColor(&xcl, 220, 220, 220);
	if (!XAllocColor(dd, cmap, &xcl))
	   goto CN;
	cols[cnum++] = xcl.pixel;
	ExSetColor(&xcl, 160, 160, 160);
	if (!XAllocColor(dd, cmap, &xcl))
	   goto CN;
	cols[cnum++] = xcl.pixel;
	ExSetColor(&xcl, 100, 100, 100);
	if (!XAllocColor(dd, cmap, &xcl))
	   goto CN;
	cols[cnum++] = xcl.pixel;
	ExSetColor(&xcl, 0, 0, 0);
	if (!XAllocColor(dd, cmap, &xcl))
	   goto CN;
	cols[cnum++] = xcl.pixel;
	ExSetColor(&xcl, 255, 255, 255);
	if (!XAllocColor(dd, cmap, &xcl))
	   goto CN;
	cols[cnum++] = xcl.pixel;
	colorful = 1;
     }
 CN:

   if (colorful)
      att.background_pixel = cols[1];
   else
      att.background_pixel = BlackPixel(dd, DefaultScreen(dd));
   if (colorful)
      att.border_pixel = cols[3];
   else
      att.border_pixel = WhitePixel(dd, DefaultScreen(dd));
   att.backing_store = Always;
   att.save_under = True;
   att.override_redirect = True;
   mask = CWBackPixel | CWBorderPixel | CWOverrideRedirect | CWSaveUnder |
      CWBackingStore;

#if USE_COMPOSITE_OVERLAY_WINDOW
   /*
    * Intended workings:
    * Composite extension not enabled (or COW not available?)
    * - fall back to root
    * Composite extension enabled
    * - use COW whether or not compositing is enabled, window mode too
    */
   root = XCompositeGetOverlayWindow(dd, DefaultRootWindow(dd));
   if (root == None)
#endif
     {
	root = DefaultRootWindow(dd);
     }
   win = XCreateWindow(dd, root, -100, -100, 1, 1, 0,
		       CopyFromParent, InputOutput, CopyFromParent, mask, &att);

   gc = XCreateGC(dd, win, 0, &gcv);
   if (colorful)
      XSetForeground(dd, gc, cols[3]);
   else
      XSetForeground(dd, gc, att.border_pixel);

   xfs = XCreateFontSet(dd, "fixed",
			&missing_charset_list_return,
			&missing_charset_count_return, &def_string_return);
   if (!xfs)
      goto done;

   if (missing_charset_list_return)
      XFreeStringList(missing_charset_list_return);

   k = XFontsOfFontSet(xfs, &font_struct_list_return, &font_name_list_return);
   fh = 0;
   for (i = 0; i < k; i++)
     {
	h = font_struct_list_return[i]->ascent +
	   font_struct_list_return[i]->descent;
	if (fh < h)
	   fh = h;
     }

   XSelectInput(dd, win, ExposureMask);
   XMapWindow(dd, win);

   XGrabServer(dd);

   XGrabPointer(dd, win, False, ButtonPressMask | ButtonReleaseMask,
		GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
   XGrabKeyboard(dd, win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
   XSetInputFocus(dd, win, RevertToPointerRoot, CurrentTime);

   XSync(dd, False);

   wid = DisplayWidth(dd, DefaultScreen(dd));
   hih = DisplayHeight(dd, DefaultScreen(dd));
   ww = (wid >= 600) ? 600 : (wid / 40) * 40;
   hh = (hih >= 440) ? 440 : (hih / 40) * 40;

   for (i = 40; i < ww; i += 40)
     {
	w = i;
	h = (i * hh) / ww;
	x = (wid - w) >> 1;
	y = (hih - h) >> 1;
	XMoveResizeWindow(dd, win, x, y, w, h);
	DRAW_BOX_OUT(dd, gc, win, 0, 0, w, h);
	XSync(dd, False);
	SleepUs(20000);
     }
   x = (wid - ww) >> 1;
   y = (hih - hh) >> 1;
   XMoveResizeWindow(dd, win, x, y, ww, hh);
   XSync(dd, False);

   bw = 0;
   if (str1)
     {
	ExTextExtents(xfs, str1, strlen(str1), &rect1, &rect2);
	bw = (rect2.width > bw) ? rect2.width : bw;
     }
   if (str2)
     {
	ExTextExtents(xfs, str2, strlen(str2), &rect1, &rect2);
	bw = (rect2.width > bw) ? rect2.width : bw;
     }
   if (str3)
     {
	ExTextExtents(xfs, str3, strlen(str3), &rect1, &rect2);
	bw = (rect2.width > bw) ? rect2.width : bw;
     }
   bw += 20;
   bh = fh + 10;

#define BX(i) (5 + (((ww - bw - 10) * (i)) / 2))
#define BY    (hh - bh - 5)

   if (str1)
     {
	b1 = XCreateWindow(dd, win, BX(0), BY, bw, bh, 0, CopyFromParent,
			   InputOutput, CopyFromParent, mask, &att);
	XMapWindow(dd, b1);
     }
   if (str2)
     {
	b2 = XCreateWindow(dd, win, BX(1), BY, bw, bh, 0, CopyFromParent,
			   InputOutput, CopyFromParent, mask, &att);
	XMapWindow(dd, b2);
     }
   if (str3)
     {
	b3 = XCreateWindow(dd, win, BX(2), BY, bw, bh, 0, CopyFromParent,
			   InputOutput, CopyFromParent, mask, &att);
	XMapWindow(dd, b3);
     }
   XSync(dd, False);

   button = 0;
   for (; button == 0;)
     {
	XNextEvent(dd, &ev);
	switch (ev.type)
	  {
	  case KeyPress:
	     keycode = XKeysymToKeycode(dd, XK_F1);
	     if (keycode == ev.xkey.keycode)
	       {
		  DRAW_BOX_IN(dd, gc, b1, 0, 0, bw, bh);
		  XSync(dd, False);
		  SleepUs(500000);
		  DRAW_BOX_OUT(dd, gc, b1, 0, 0, bw, bh);
		  button = 1;
		  goto do_sync;
	       }
	     keycode = XKeysymToKeycode(dd, XK_F2);
	     if (keycode == ev.xkey.keycode)
	       {
		  DRAW_BOX_IN(dd, gc, b2, 0, 0, bw, bh);
		  XSync(dd, False);
		  SleepUs(500000);
		  DRAW_BOX_OUT(dd, gc, b2, 0, 0, bw, bh);
		  button = 2;
		  goto do_sync;
	       }
	     keycode = XKeysymToKeycode(dd, XK_F3);
	     if (keycode == ev.xkey.keycode)
	       {
		  DRAW_BOX_IN(dd, gc, b3, 0, 0, bw, bh);
		  XSync(dd, False);
		  SleepUs(500000);
		  DRAW_BOX_OUT(dd, gc, b3, 0, 0, bw, bh);
		  button = 3;
		  goto do_sync;
	       }
	     break;

	  case ButtonPress:
	     if (!(ev.xbutton.y >= BY && ev.xbutton.y < BY + bh))
		break;

	     x = BX(0);
	     if (b1 && ev.xbutton.x >= x && ev.xbutton.x < x + bw)
	       {
		  DRAW_BOX_IN(dd, gc, b1, 0, 0, bw, bh);
		  goto do_sync;
	       }
	     x = BX(1);
	     if (b2 && ev.xbutton.x >= x && ev.xbutton.x < x + bw)
	       {
		  DRAW_BOX_IN(dd, gc, b2, 0, 0, bw, bh);
		  goto do_sync;
	       }
	     x = BX(2);
	     if (b3 && ev.xbutton.x >= x && ev.xbutton.x < x + bw)
	       {
		  DRAW_BOX_IN(dd, gc, b3, 0, 0, bw, bh);
		  goto do_sync;
	       }
	     break;

	  case ButtonRelease:
	     if (!(ev.xbutton.y >= BY && ev.xbutton.y < BY + bh))
		break;

	     x = BX(0);
	     if (b1 && ev.xbutton.x >= x && ev.xbutton.x < x + bw)
	       {
		  DRAW_BOX_OUT(dd, gc, b1, 0, 0, bw, bh);
		  button = 1;
		  goto do_sync;
	       }
	     x = BX(1);
	     if (b2 && ev.xbutton.x >= x && ev.xbutton.x < x + bw)
	       {
		  DRAW_BOX_OUT(dd, gc, b2, 0, 0, bw, bh);
		  button = 2;
		  goto do_sync;
	       }
	     x = BX(2);
	     if (b3 && ev.xbutton.x >= x && ev.xbutton.x < x + bw)
	       {
		  DRAW_BOX_OUT(dd, gc, b3, 0, 0, bw, bh);
		  button = 3;
		  goto do_sync;
	       }
	     break;

	  case Expose:
	     /* Flush all other Expose events */
	     while (XCheckTypedWindowEvent(dd, ev.xexpose.window, Expose, &ev))
		;

	     ExTextExtents(xfs, title, strlen(title), &rect1, &rect2);
	     w = rect2.width;

	     DRAW_HEADER(dd, gc, win, (ww - w) / 2, 5 - rect2.y, title);
	     DRAW_BOX_OUT(dd, gc, win, 0, 0, ww, bh);
	     DRAW_BOX_OUT(dd, gc, win, 0, bh - 1, ww, hh - fh - fh - 30 + 2);
	     DRAW_BOX_OUT(dd, gc, win, 0, hh - fh - 20, ww, fh + 20);
	     k = bh;
	     for (p = text;; p += len + 1)
	       {
		  len = strcspn(p, "\n");
		  DRAW_STRING(dd, gc, win, 6, 6 + k + fh, p, len);
		  k += fh + 2;
		  if (p[len] == '\0')
		     break;
	       }
	     if (str1)
	       {
		  ExTextExtents(xfs, str1, strlen(str1), &rect1, &rect2);
		  w = rect2.width;
		  DRAW_HEADER(dd, gc, b1, (bw - w) / 2, 5 - rect2.y, str1);
		  DRAW_BOX_OUT(dd, gc, b1, 0, 0, bw, bh);
		  DRAW_THIN_BOX_IN(dd, gc, win,
				   BX(0) - 2, BY - 2, bw + 4, bh + 4);
	       }
	     if (str2)
	       {
		  ExTextExtents(xfs, str2, strlen(str2), &rect1, &rect2);
		  w = rect2.width;
		  DRAW_HEADER(dd, gc, b2, (bw - w) / 2, 5 - rect2.y, str2);
		  DRAW_BOX_OUT(dd, gc, b2, 0, 0, bw, bh);
		  DRAW_THIN_BOX_IN(dd, gc, win,
				   BX(1) - 2, BY - 2, bw + 4, bh + 4);
	       }
	     if (str3)
	       {
		  ExTextExtents(xfs, str3, strlen(str3), &rect1, &rect2);
		  w = rect2.width;
		  DRAW_HEADER(dd, gc, b3, (bw - w) / 2, 5 - rect2.y, str3);
		  DRAW_BOX_OUT(dd, gc, b3, 0, 0, bw, bh);
		  DRAW_THIN_BOX_IN(dd, gc, win,
				   BX(2) - 2, BY - 2, bw + 4, bh + 4);
	       }
	   do_sync:
	     XSync(dd, False);
	     break;

	  default:
	     break;
	  }
     }

   XFreeFontSet(dd, xfs);
 done:
   XUngrabServer(dd);
   XDestroyWindow(dd, win);
   XFreeGC(dd, gc);
   if (cnum > 0)
      XFreeColors(dd, cmap, cols, cnum, 0);
   XCloseDisplay(dd);

   switch (button)
     {
     default:
     case 1:
	break;
     case 2:
	SessionExit(EEXIT_RESTART, NULL);
	break;
     case 3:
	SessionExit(EEXIT_EXIT, NULL);
	break;
     }
}
Example #25
0
	int main(int argc, char **argv)
	{
		Display *display;
		int screen_num;
		Window win;			//窗口ID
		unsigned int width, height;	//窗口尺寸
		unsigned int border_width = 4;	//边界空白
		unsigned int display_width, display_height;//屏幕尺寸
		XEvent report;
		GC gc;
		unsigned long valuemask = 0;
		XGCValues values;
		char *display_name = NULL;
		Atom          protocols;

		//edit
		int           len = 127;
		unsigned char string[128], s_tab[ROW][127];
		KeySym        keysym;
		int           row = 0, col = 0;
		int           i, count = 0;
		Status        status;
		//字体集
		XFontSet fontset;
		char **missing_charsets;
		int num_missing_charsets;
		char *default_string;
		XFontSetExtents *fs_ext;
		int dec;    

		//XIM
		XIM im;
		XIC ic;
		//overspot
		XRectangle    spot, s_rect;
		XVaNestedList preedit_attr, status_attr;

		//设置locale	
		if((setlocale(LC_ALL, "")) == NULL){
			printf("cannot set locale\n");
			exit(1);
		}

		//判断X是否支持locale
		if(!XSupportsLocale()){
			printf("X does not support current locale\n");
			exit(1);
		}

		//设置locale修饰
		if(XSetLocaleModifiers(NULL)){
			printf("Cannot set locale modifiers\n");
			exit(1);
		}
	
		// 和X 服务器连接
		if ( (display=XOpenDisplay(display_name)) == NULL )
		{
			printf("Cannot connect to X server %s\n", 
					XDisplayName(display_name));
			exit(-1);
		}

		//获得缺省的 screen_num
		screen_num = DefaultScreen(display);

		//获得屏幕的宽度和高度
		display_width = DisplayWidth(display, screen_num);
		display_height = DisplayHeight(display, screen_num);
	
		//建立字体集
		fontset = XCreateFontSet(display, 
			"8x16,-*-song-medium-r-normal--16-*-*-*-*-*-gb2312.1980-0",
			&missing_charsets, &num_missing_charsets,
			&default_string);

		if(num_missing_charsets > 0){
			int i;
			printf("Following charsets are missing:\n");
			for(i=0; i<num_missing_charsets; i++){
				printf("Missing %d: %s\n", 
					i, missing_charsets[i]);
			}
			printf("\nDefault string:%s\n", default_string);
			XFreeStringList(missing_charsets);
		}
		//字体的Extents
		fs_ext = XExtentsOfFontSet(fontset);
		dec = fs_ext->max_logical_extent.height 
			+ fs_ext->max_logical_extent.y;

		width  = W_WIDTH;
		height = W_HEIGHT + dec;

	
		//建立窗口
		win = XCreateSimpleWindow(display, 	//display
			RootWindow(display,screen_num), //父窗口
			0, 0, width, height, 		//位置和大小
			border_width, 			//边界宽度
			BlackPixel(display,screen_num), //前景色
			WhitePixel(display,screen_num));//背景色
	
		//选择窗口感兴趣的事件掩码
		XSelectInput(display, win, 
			ExposureMask | KeyPressMask | 
			ButtonPressMask | StructureNotifyMask);

		//建立GC
		gc = XCreateGC(display, win, valuemask, &values);

		protocols = XInternAtom(display, "WM_DELETE_WINDOW", True);
		XSetWMProtocols(display, win, &protocols, 1);

		//显示窗口
		XMapWindow(display, win);

		//联接输入服务器
		if((im = XOpenIM(display, NULL, NULL, NULL)) == NULL){
			printf("Error : XOpenIM !\n");
			exit(1);
		}

		//设置输入服务器的位置
		spot.x = F_SIZE / 2 * col;
		spot.y = F_SIZE * (row + 1) - dec; 
		preedit_attr = XVaCreateNestedList(0,
			XNSpotLocation, &spot,
			XNFontSet, fontset, 
			NULL);
		s_rect.x = 0;
		s_rect.y = F_SIZE * ROW + dec + 2;
		s_rect.width = W_WIDTH;
		s_rect.height = F_SIZE;
		status_attr = XVaCreateNestedList(0,
			XNArea, &s_rect,
			XNFontSet, fontset,
			NULL);
		//建立IC
		if((ic = XCreateIC(im, 
			XNInputStyle, XIMPreeditPosition | XIMStatusNothing,
			XNClientWindow, win, 
			XNPreeditAttributes, preedit_attr,
			XNStatusAttributes, status_attr, NULL)) == NULL){
			printf("Error : XCreateIC() ! \n");
			XCloseIM(im);
			exit(0);
		}
		//释放内存
		XFree(preedit_attr);
		XFree(status_attr);


		//写屏缓冲区初始化
		for(i = 0; i < ROW; i++)s_tab[i][0] = 0;

		//进入事件循环
		while (1)  {

			//取得队列中的事件
			XNextEvent(display, &report);

			//过滤事件
			if(XFilterEvent(&report, None) == True) continue;
			switch  (report.type) {

			//聚焦发声变化
			case FocusIn:
				XSetICFocus(ic); 
				break;
			case FocusOut:
				XUnsetICFocus(ic);
				break;

			//曝光事件, 窗口应重绘
			case Expose:
				//取得最后一个曝光事件
				if (report.xexpose.count != 0) break;
				for ( i=0; i < ROW; i++)
					XmbDrawString(display, win, fontset,gc, 
					0, F_SIZE * (i +1), 
					s_tab[i], strlen(s_tab[i]));
				break;

			//窗口尺寸改变, 重新取得窗口的宽度和高度
			case ConfigureNotify:
				width = report.xconfigure.width;
				height = report.xconfigure.height;
				break;

			//鼠标点击或有按键, 释放资源则退出
			case KeyPress:
				count = XmbLookupString(ic, 
					(XKeyPressedEvent *) &report,
					string, len, &keysym, &status);
				string[count] = 0;
				if (status == XLookupBoth&&keysym == XK_Return){
					row = (++row) % ROW;
					col = 0;
					s_tab[row][0] = 0;
					XClearArea(display, win, 
						0, F_SIZE * row + dec,
						W_WIDTH, F_SIZE, False);
				} else if (status = XLookupChars 
					|| status == XLookupBoth){
					XmbDrawString(display, win, fontset, gc,
					F_SIZE / 2 * col, F_SIZE * (row + 1),
					string, count);
					for (i = 0; i < count && col < len && 
						string[i]; i++, col++)
						s_tab[row][col] = string[i];
						s_tab[row][col] = 0;
				}
				//更新输入服务器位置
				spot.x = F_SIZE / 2 * col;
				spot.y = F_SIZE * (row + 1);
				preedit_attr = XVaCreateNestedList(0,
					XNSpotLocation, &spot,
					NULL);
				XSetICValues(ic, 
					XNPreeditAttributes, preedit_attr, 
					NULL);
				XFree(preedit_attr);
				break;
			case ClientMessage:
				if (report.xclient.data.l[0] == protocols) {
					XDestroyIC(ic);
					XCloseIM(im);
					XDestroyWindow(display, win);
					XCloseDisplay(display);
					exit(0);
				}
				break;
			default:
				break;
			}
		}
	}
Example #26
0
int xtwitter_x_init()
{
    Window root;
    int screen;
    int root_x, root_y;
    unsigned int root_width, root_height, root_border, root_depth;
    int missing_count;
    char** missing_list;
    char* def_string;

    XInitThreads();

    if(!setlocale(LC_CTYPE, "")){
        fprintf(stderr, "error: setlocale()\n");
        return -1;
    }
    if (!XSupportsLocale()){
        fprintf(stderr, "error: XSupportsLocale()\n");
        return -1;
    }
    display = XOpenDisplay(NULL);
    if(!display){
        fprintf(stderr, "Can't open display\n");
        return -1;
    }
    root = DefaultRootWindow(display);
    screen = DefaultScreen(display);
    color_white= WhitePixel(display, screen);
    color_black= BlackPixel(display, screen);

    XGetGeometry(display, RootWindow(display, 0), &root,
                 &root_x, &root_y, &root_width, &root_height,
                 &root_border, &root_depth);

    text_fonts = XCreateFontSet(display, "-*-*-medium-r-normal--12-*-*-*", 
                                &missing_list, &missing_count, &def_string);

    if(!text_fonts){
        printf( "error: XCreateFontSet\n" );
        return 1;
    }
    if(!missing_list){
        XFreeStringList(missing_list);
    }

    user_fonts = XCreateFontSet(display, "-*-*-medium-r-normal--12-*-*-*", 
                                &missing_list, &missing_count, &def_string);
    if(!user_fonts){
        printf( "error: XCreateFontSet\n" );
        return 1;
    }
    if(!missing_list){
        XFreeStringList(missing_list);
    }

    window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0,
                                 XTWITTER_WINDOW_WIDTH, XTWITTER_WINDOW_HEIGHT,
                                 1, color_black, color_white);

    atom_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(display, window, &atom_delete_window, 1);

    gc = XCreateGC(display, window, 0, NULL);
    XSetBackground(display, gc, color_white);
    XSetForeground(display, gc, color_black);

	imlib_context_set_display(display);
	imlib_context_set_visual(DefaultVisual(display, 0));
	imlib_context_set_colormap(DefaultColormap(display, 0));

    pixmap = XCreatePixmap(display, window,
                           XTWITTER_WINDOW_WIDTH, XTWITTER_WINDOW_HEIGHT,
                           DefaultDepth(display, screen));

    // control under window manager
    XSetWindowAttributes attr;
    attr.override_redirect = False;
    XChangeWindowAttributes(display, window, CWOverrideRedirect, &attr);

    // set title bar
    XTextProperty  prop;
    prop.value    = (unsigned char *)PACKAGE;
    prop.encoding = XA_STRING;
    prop.format = 8;
    prop.nitems = strlen(PACKAGE);
    XSetWMName(display, window, &prop);

    // fill pixmap by white
    XSetForeground(display, gc, color_white);
    XSetBackground(display, gc, color_black);
    XFillRectangle(display, pixmap, gc,
                   0, 0, XTWITTER_WINDOW_WIDTH, XTWITTER_WINDOW_HEIGHT);

    XMapWindow(display, window);
    XFlush(display);
    return 0;
}
Example #27
0
/**************************************************************************
  Entry point for GUI specific portion. Called from client_main()
**************************************************************************/
void ui_main(int argc, char *argv[])
{
  int i;
  struct sprite *icon; 

  parse_options(argc, argv);

  /* include later - pain to see the warning at every run */
  XtSetLanguageProc(NULL, NULL, NULL);
  
  toplevel = XtVaAppInitialize(
	       &app_context,               /* Application context */
	       "Freeciv",                  /* application class name */
#ifdef UNUSED
	       cmd_options, XtNumber(cmd_options),
#else
	       NULL, 0,
#endif
	                                   /* command line option list */
	       &argc, argv,                /* command line args */
	       &fallback_resources[1],     /* for missing app-defaults file */
	       XtNallowShellResize, True,
	       NULL);              

  XtGetApplicationResources(toplevel, &appResources, resources,
                            XtNumber(resources), NULL, 0);

/*  XSynchronize(display, 1); 
  XSetErrorHandler(myerr);*/

  if(appResources.version==NULL)  {
    freelog(LOG_FATAL, _("No version number in resources."));
    freelog(LOG_FATAL, _("You probably have an old (circa V1.0)"
			 " Freeciv resource file somewhere."));
    exit(EXIT_FAILURE);
  }

  /* TODO: Use capabilities here instead of version numbers */
  if (0 != strncmp(appResources.version, VERSION_STRING,
		   strlen(appResources.version))) {
    freelog(LOG_FATAL, _("Game version does not match Resource version."));
    freelog(LOG_FATAL, _("Game version: %s - Resource version: %s"), 
	    VERSION_STRING, appResources.version);
    freelog(LOG_FATAL, _("You might have an old Freeciv resourcefile"
			 " in /usr/lib/X11/app-defaults"));
    exit(EXIT_FAILURE);
  }
  
  if(!appResources.gotAppDefFile) {
    freelog(LOG_NORMAL, _("Using fallback resources - which is OK"));
  }

  display = XtDisplay(toplevel);
  screen_number=XScreenNumberOfScreen(XtScreen(toplevel));
  display_depth=DefaultDepth(display, screen_number);
  root_window=DefaultRootWindow(display);

  display_color_type=get_visual(); 
  
  if(display_color_type!=COLOR_DISPLAY) {
    freelog(LOG_FATAL, _("Only color displays are supported for now..."));
    /*    exit(EXIT_FAILURE); */
  }

  {
    XGCValues values;
    char **missing_charset_list_return;
    int missing_charset_count_return;
    char *def_string_return;
    char *city_names_font, *city_productions_font_name;

    values.graphics_exposures = False;
    civ_gc = XCreateGC(display, root_window, GCGraphicsExposures, &values);

    city_names_font = mystrdup("-*-*-*-*-*-*-14-*");

    city_productions_font_name = mystrdup("-*-*-*-*-*-*-14-*");

    main_font_set = XCreateFontSet(display, city_names_font,
	&missing_charset_list_return,
	&missing_charset_count_return,
	&def_string_return);
    if (!main_font_set) {
      freelog(LOG_FATAL, _("Unable to open fontset: %s"),
	      city_names_font);
      freelog(LOG_FATAL,
	      _("Doing 'xset fp rehash' may temporarily solve a problem."));
      exit(EXIT_FAILURE);
    }
    for (i = 0; i < missing_charset_count_return; i++) {
      freelog(LOG_ERROR, _("Font for charset %s is lacking"),
	      missing_charset_list_return[i]);
    }
    values.foreground = get_color(tileset, COLOR_MAPVIEW_CITYTEXT)->color.pixel;
    values.background = get_color(tileset, COLOR_MAPVIEW_UNKNOWN)->color.pixel;
    font_gc= XCreateGC(display, root_window, 
		       GCForeground|GCBackground|GCGraphicsExposures, 
		       &values);

    prod_font_set = XCreateFontSet(display, city_productions_font_name,
	&missing_charset_list_return,
	&missing_charset_count_return,
	&def_string_return);
    if (!prod_font_set) {
      freelog(LOG_FATAL, _("Unable to open fontset: %s"),
	      city_productions_font_name);
      freelog(LOG_FATAL,
	      _("Doing 'xset fp rehash' may temporarily solve a problem."));
      exit(EXIT_FAILURE);
    }
    for (i = 0; i < missing_charset_count_return; i++) {
      freelog(LOG_ERROR, _("Font for charset %s is lacking"),
	      missing_charset_list_return[i]);
    }
    values.foreground = get_color(tileset, COLOR_MAPVIEW_CITYTEXT)->color.pixel;
    values.background = get_color(tileset, COLOR_MAPVIEW_UNKNOWN)->color.pixel;
    prod_font_gc= XCreateGC(display, root_window,
			    GCForeground|GCBackground|GCGraphicsExposures,
			    &values);

    values.line_width = BORDER_WIDTH;
    values.line_style = LineOnOffDash;
    values.cap_style = CapNotLast;
    values.join_style = JoinMiter;
    values.fill_style = FillSolid;
    border_line_gc = XCreateGC(display, root_window,
			       GCGraphicsExposures|GCLineWidth|GCLineStyle
			       |GCCapStyle|GCJoinStyle|GCFillStyle, &values);

    values.foreground = 0;
    values.background = 0;
    fill_bg_gc= XCreateGC(display, root_window, 
			  GCForeground|GCBackground|GCGraphicsExposures,
			  &values);

    values.fill_style=FillStippled;
    fill_tile_gc= XCreateGC(display, root_window, 
    			    GCForeground|GCBackground|GCFillStyle|GCGraphicsExposures,
			    &values);
  }

  {
    char d1[]={0x03,0x0c,0x03,0x0c};
    char d2[]={0x08,0x02,0x08,0x02};
    gray50 = XCreateBitmapFromData(display, root_window, d1, 4, 4);
    gray25 = XCreateBitmapFromData(display, root_window, d2, 4, 4);
  }
  
  /* 135 below is rough value (could be more intelligent) --dwp */
  num_units_below = 135 / tileset_full_tile_width(tileset);
  num_units_below = MIN(num_units_below,MAX_NUM_UNITS_BELOW);
  num_units_below = MAX(num_units_below,1);
  
  /* do setup_widgets before loading the rest of graphics to ensure that
     setup_widgets() has enough colors available:  (on 256-colour systems)
  */
  setup_widgets();
  tileset_init(tileset);
  tileset_load_tiles(tileset);
  load_intro_gfx();
  load_cursors();

  /* FIXME: what about the mask? */
  icon = get_icon_sprite(tileset, ICON_FREECIV);
  XtVaSetValues(toplevel, XtNiconPixmap, icon->pixmap, NULL);

  XtSetKeyboardFocus(bottom_form, inputline_text);
  XtSetKeyboardFocus(below_menu_form, map_canvas);

  InitializeActions(app_context);

  /* Do this outside setup_widgets() so after tiles are loaded */
  fill_econ_label_pixmaps();
		
  XtAddCallback(map_horizontal_scrollbar, XtNjumpProc, 
		scrollbar_jump_callback, NULL);
  XtAddCallback(map_vertical_scrollbar, XtNjumpProc, 
		scrollbar_jump_callback, NULL);
  XtAddCallback(map_horizontal_scrollbar, XtNscrollProc, 
		scrollbar_scroll_callback, NULL);
  XtAddCallback(map_vertical_scrollbar, XtNscrollProc, 
		scrollbar_scroll_callback, NULL);
  XtAddCallback(turn_done_button, XtNcallback, end_turn_callback, NULL);

  XtAppAddWorkProc(app_context, toplevel_work_proc, NULL);

  XtRealizeWidget(toplevel);

  x_interval_id = XtAppAddTimeOut(app_context, TIMER_INTERVAL,
				  timer_callback, NULL);

  init_mapcanvas_and_overview();

  fill_unit_below_pixmaps();

  set_indicator_icons(client_research_sprite(),
		      client_warming_sprite(),
		      client_cooling_sprite(),
		      client_government_sprite());

  wm_delete_window = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW", 0);
  XSetWMProtocols(display, XtWindow(toplevel), &wm_delete_window, 1);
  XtOverrideTranslations(toplevel,
    XtParseTranslationTable ("<Message>WM_PROTOCOLS: msg-quit-freeciv()"));

  XtSetSensitive(toplevel, FALSE);

  XtAppMainLoop(app_context);
}
Example #28
0
int main(int argc, char *argv[])
{
	XGCValues xgcv;
	memset( &xgcv, 0, sizeof( xgcv ) );
	xgcv.graphics_exposures = False;

	system( "killall -o 1s boxer" );
	if( argc != 5 )
	{
		fprintf( stderr, "Error: expects four parameters ./boxer [x] [y] [w] [h]\n" );
		return -1;
	}

	x = atoi( argv[1] );
	y = atoi( argv[2] );
	w = atoi( argv[3] );
	h = atoi( argv[4] );

	int event_basep, error_basep, a, b;
	int xinerama_screen;
	XineramaScreenInfo *screeninfo = NULL;

	if (setlocale(LC_ALL, "") == NULL || !XSupportsLocale())
		fprintf(stderr, "Locale not available, expect problems with fonts.\n");

	char * dpy = getenv("DISPLAY");

	Display * display = XOpenDisplay(dpy);
	if (!display) {
		fprintf( stderr, "Error: Cannot open display.\n" );
		return -1;
	}
	int screen = XDefaultScreen(display);

	if (!XShapeQueryExtension(display, &event_basep, &error_basep))
	{
    		fprintf( stderr, "X-Server does not support shape extension" );
		return -1;
	}

 	Visual * visual = DefaultVisual(display, screen);
	depth = DefaultDepth(display, screen);

	if (XineramaQueryExtension(display, &a, &b ) &&
		(screeninfo = XineramaQueryScreens(display, &screens)) &&
		XineramaIsActive(display) && xinerama_screen >= 0 &&
		xinerama_screen < screens ) {
		width = screeninfo[xinerama_screen].width;
		height = screeninfo[xinerama_screen].height;
		xpos = screeninfo[xinerama_screen].x_org;
	} else
	{
		width = XDisplayWidth(display, screen);
		height = XDisplayHeight(display, screen);
		xpos = 0;
	}
	if (screeninfo)
	XFree(screeninfo);


	XSetWindowAttributes setwinattr;
	setwinattr.override_redirect = 1;

	window = XCreateWindow(display, XRootWindow(display, screen),
		0, 0, width, height,
		0, depth, CopyFromParent, visual, CWOverrideRedirect, &setwinattr);

	XSelectInput(display, window, ExposureMask);

	//printf( "Window: %p (%d x %d @ %d)\n", window, width, height, depth );
	XStoreName(display, window, "xzbar");

	int mask_bitmap  = XCreatePixmap(display, window, width, height, 1);

	int line_bitmap = XCreatePixmap(display, window, width, height, depth);

	gc = XCreateGC(display, window, GCGraphicsExposures, &xgcv);
	mask_gc = XCreateGC( display, mask_bitmap, GCGraphicsExposures, &xgcv);
	mask_gc_back = XCreateGC( display, mask_bitmap, GCGraphicsExposures, &xgcv);

	XSetBackground(display, gc, WhitePixel(display, screen));

	XSetForeground(display, mask_gc_back, BlackPixel(display, screen));
	XSetBackground(display, mask_gc_back, WhitePixel(display, screen));

	XSetForeground(display, mask_gc, WhitePixel(display, screen));
	XSetBackground(display, mask_gc, BlackPixel(display, screen));

	stay_on_top( display, window );


	XMapRaised(display, window);

	char **missing;
	int nmissing;
	char *defstr;
	_XOC * fontset = XCreateFontSet( display, default_font, &missing, &nmissing, &defstr);

	while(1)
	{
		XEvent e;
		int i;

		XSetForeground(display, gc, 0);
		XFillRectangle(display, mask_bitmap, mask_gc_back, 0, 0, width, height);
		XSetForeground(display, gc, 0xFF00FF);

/*
		for (i = 0; i < 100; i++ ) {
			XRectangle t;
			t.x = rand()%1000;
			t.y = 100;
			t.width = 5;
			t.height = 20;
			XFillRectangles(display, mask_bitmap, mask_gc, &t, 1);
			XFillRectangles(display, line_bitmap, gc, &t, 1);
		}
*/

/*
		XRectangle t;
		t.x = x;
		t.y = y;
		t.width = w;
		t.height = h;
*/
		int addx = x + w;
		int addy = y + h;
		int ox = x;
		int oy = y;

		if( ox > 0 )
			XDrawLine( display, mask_bitmap, mask_gc, ox, addy, ox, oy );
		else
			ox = 0;

		if( oy > 0 )
			XDrawLine( display, mask_bitmap, mask_gc, ox, oy, addx, oy );
		else
			oy = 0;

		XDrawLine( display, mask_bitmap, mask_gc, addx, oy, addx, addy );
		XDrawLine( display, mask_bitmap, mask_gc, addx, addy, ox, addy );

		if( ox > 0 )
			XDrawLine( display, line_bitmap, gc, ox, addy, ox, oy );
		else
			ox = 0;

		if( oy > 0 )
			XDrawLine( display, line_bitmap, gc, ox, oy, addx, oy );
		else
			oy = 0;
	

		XDrawLine( display, line_bitmap, gc, addx, oy, addx, addy );
		XDrawLine( display, line_bitmap, gc, addx, addy, ox, addx );

	//	XDrawRectangles(display, mask_bitmap, mask_gc, &t, 1);
	//	XDrawRectangles(display, line_bitmap, gc, &t, 1);


		//Combine the mask again.
		XShapeCombineMask(display, window, ShapeBounding, 0, 0, mask_bitmap, ShapeSet);

//		XNextEvent(display, &e);

//		if (e.type == Expose) {
			//printf( "Expose\n" );
			XCopyArea(display, line_bitmap, window, gc, 0, 0, width, height, 0, 0);
//		}

		XFlush(display);
		usleep(100000);
	}
}
Example #29
0
static void
FCFilter(Widget w, XtPointer client, XtPointer call)
{
	int				i = (int)client, j, nfonts;
	Widget				fc, b, demo;
	char				*f = XtMalloc(256), **list;
	XmRowColumnCallbackStruct	*cbs = (XmRowColumnCallbackStruct *)call;

/* Figure out who we are and who called us */
#if 0
	for (fc = w; fc && ! XltIsFontChooser(fc); fc = XtParent(fc)) ;
	if (fc == NULL) {
		/* Probably in a tearoff */
		abort();
	}
#endif

	b = cbs->widget;		/* This widget invoked us */
	XtVaGetValues(b, XmNuserData, &fc, NULL);

	demo = FC_DemoWidget(fc);

/* Store the setting */
	if (FC_Setting(fc)[i] != NULL)
		XtFree(FC_Setting(fc)[i]);

	FC_Setting(fc)[i] = XtNewString(XtName(b));

	f[0] = '\0';
	for (j=0; j<14; j++) {
		strcat(f, "-");
		strcat(f, FC_Setting(fc)[j]);
	}

	if (FC_FontName(fc))
		XtFree(FC_FontName(fc));
	FC_FontName(fc) = f;

/* How many fonts ? */
	DisableAllMenus(fc, i);
	list = XListFonts(XtDisplay(fc), f, 4096, &nfonts);
	for (i=0; i<nfonts; i++)
		EnableMenu(fc, list[i]);
	XFreeFontNames(list);

/* Change the display */
	if (FC_ShowDemo(fc)) {
	    if (demo) {
		XmFontList      fl;
		XmFontListEntry fle;
		XFontSet        fs;
		char            m1[2][80], **missing = (char **)&m1[0][0];
		char            m2[80], *def = &m2[0];
		int             nmissing = 0;

		fs = XCreateFontSet(XtDisplay(fc), f, &missing, &nmissing, &def);

		if (fs != NULL) {
                	fle = XmFontListEntryCreate(XmFONTLIST_DEFAULT_TAG,
			         XmFONT_IS_FONTSET, (XtPointer)fs);
                	fl = XmFontListAppendEntry(NULL, fle);

			XtVaSetValues(demo, XmNfontList, fl, NULL);

			XmFontListEntryFree(&fle);
			XmFontListFree(fl);
#if 0
			/* Freeing the font set produces nice little core dumps */
			XFreeFontSet(XtDisplay(fc), fs);	/* FIX ME leak ?? */
#endif
        	}
	    }

	    ShowCount(fc, nfonts);
	}
}
Example #30
0
/***********************************************************************
 *           X11DRV Ime creation
 *
 * Should always be called with the x11 lock held
 */
static BOOL open_xim( Display *display )
{
    struct x11drv_thread_data *thread_data = x11drv_thread_data();
    XIMStyle ximStyleCallback, ximStyleNone;
    XIMStyles *ximStyles = NULL;
    INT i;
    XIM xim;
    XIMCallback destroy;

    xim = XOpenIM(display, NULL, NULL, NULL);
    if (xim == NULL)
    {
        WARN("Could not open input method.\n");
        return FALSE;
    }

    destroy.client_data = NULL;
    destroy.callback = X11DRV_DestroyIM;
    if (XSetIMValues(xim, XNDestroyCallback, &destroy, NULL))
    {
        WARN("Could not set destroy callback.\n");
    }

    TRACE("xim = %p\n", xim);
    TRACE("X display of IM = %p\n", XDisplayOfIM(xim));
    TRACE("Using %s locale of Input Method\n", XLocaleOfIM(xim));

    XGetIMValues(xim, XNQueryInputStyle, &ximStyles, NULL);
    if (ximStyles == 0)
    {
        WARN("Could not find supported input style.\n");
        XCloseIM(xim);
        return FALSE;
    }
    else
    {
        TRACE("ximStyles->count_styles = %d\n", ximStyles->count_styles);

        ximStyleRoot = 0;
        ximStyleNone = 0;
        ximStyleCallback = 0;

        for (i = 0; i < ximStyles->count_styles; ++i)
        {
            int style = ximStyles->supported_styles[i];
            TRACE("ximStyles[%d] = %s%s%s%s%s\n", i,
                        (style&XIMPreeditArea)?"XIMPreeditArea ":"",
                        (style&XIMPreeditCallbacks)?"XIMPreeditCallbacks ":"",
                        (style&XIMPreeditPosition)?"XIMPreeditPosition ":"",
                        (style&XIMPreeditNothing)?"XIMPreeditNothing ":"",
                        (style&XIMPreeditNone)?"XIMPreeditNone ":"");
            if (!ximStyle && (ximStyles->supported_styles[i] ==
                                ximStyleRequest))
            {
                ximStyle = ximStyleRequest;
                TRACE("Setting Style: ximStyle = ximStyleRequest\n");
            }
            else if (!ximStyleRoot &&(ximStyles->supported_styles[i] ==
                     STYLE_ROOT))
            {
                ximStyleRoot = STYLE_ROOT;
                TRACE("Setting Style: ximStyleRoot = STYLE_ROOT\n");
            }
            else if (!ximStyleCallback &&(ximStyles->supported_styles[i] ==
                     STYLE_CALLBACK))
            {
                ximStyleCallback = STYLE_CALLBACK;
                TRACE("Setting Style: ximStyleCallback = STYLE_CALLBACK\n");
            }
            else if (!ximStyleNone && (ximStyles->supported_styles[i] ==
                     STYLE_NONE))
            {
                TRACE("Setting Style: ximStyleNone = STYLE_NONE\n");
                ximStyleNone = STYLE_NONE;
            }
        }
        XFree(ximStyles);

        if (ximStyle == 0)
            ximStyle = ximStyleRoot;

        if (ximStyle == 0)
            ximStyle = ximStyleNone;

        if (ximStyleCallback == 0)
        {
            TRACE("No callback style avalable\n");
            ximStyleCallback = ximStyle;
        }

    }

    thread_data->xim = xim;

    if ((ximStyle & (XIMPreeditNothing | XIMPreeditNone)) == 0 ||
        (ximStyle & (XIMStatusNothing | XIMStatusNone)) == 0)
    {
        char **list;
        int count;
        thread_data->font_set = XCreateFontSet(display, "fixed",
                          &list, &count, NULL);
        TRACE("ximFontSet = %p\n", thread_data->font_set);
        TRACE("list = %p, count = %d\n", list, count);
        if (list != NULL)
        {
            int i;
            for (i = 0; i < count; ++i)
                TRACE("list[%d] = %s\n", i, list[i]);
            XFreeStringList(list);
        }
    }
    else
        thread_data->font_set = NULL;

    wine_tsx11_unlock();
    IME_UpdateAssociation(NULL);
    wine_tsx11_lock();
    return TRUE;
}