/** 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; }
void zwm_decor_init(void) { int i; XGlyphInfo info; cmap = DefaultColormap(dpy, scr); gc = XCreateGC(dpy, root, 0, NULL); memset(icons,0,64); xfont = XftFontOpenName (dpy, scr, "DejaVu Sans-9:bold"); if(!xfont)xfont = XftFontOpenXlfd(dpy, scr, config.font); ifont = XftFontOpenName (dpy, scr, "DejaVu Sans-16:bold"); if(!ifont)ifont = XftFontOpenXlfd(dpy, scr, config.icons); XftColorAllocValue(dpy, DefaultVisual(dpy, scr), cmap, &xcolor.color, &xcolor); config.xcolor_nborder = alloc_color(config.normal_border_color); config.xcolor_fborder = alloc_color(config.focus_border_color); config.xcolor_nbg = alloc_color(config.normal_bg_color); config.xcolor_fbg = alloc_color(config.focus_bg_color); config.xcolor_flbg = alloc_color(config.float_bg_color); config.xcolor_nshadow = alloc_color(config.normal_shadow_color); config.xcolor_fshadow = alloc_color(config.focus_shadow_color); config.xcolor_ntitle = alloc_color(config.normal_title_color); config.xcolor_ftitle = alloc_color(config.focus_title_color); config.xcolor_root = alloc_color(config.root_bg_color); get_status(icons, 64); XftTextExtentsUtf8(dpy, xfont, (FcChar8*)" [000] ", 7, &info); char_width = info.width; XftTextExtentsUtf8(dpy, xfont, (FcChar8*)icons, strlen(icons), &info); date_width = info.width; icons[0] = 0; for(i=0; i<32 && config.buttons[i].func; i++){ strcat(icons, config.buttons[i].c); config.button_count = i+1; } if(config.button_count){ XftTextExtentsUtf8(dpy, ifont, (FcChar8*)icons, strlen(icons), &info); config.button_width = info.width / config.button_count; config.icon_y = info.height + (config.title_height - info.height)/2 + 1; } config.title_y = config.title_height - xfont->descent - 2; }
void main (void) { Display *dsp = XOpenDisplay (0); if (dsp) { int scr = DefaultScreen (dsp); Window p = XCreateSimpleWindow (dsp, RootWindow (dsp, scr), 100, 100, 300, 100, 1, BlackPixel (dsp, scr), WhitePixel (dsp, scr)); XSelectInput (dsp, p, ExposureMask); XMapWindow (dsp, p); XftColor xft_color; XftColorAllocName (dsp, DefaultVisual (dsp, scr), DefaultColormap (dsp, scr), "tan", &xft_color); XftFont *font = XftFontOpenName (dsp, scr, "sans:bold:pixelsize=18"); XftDraw *draw = XftDrawCreate (dsp, p, DefaultVisual (dsp, scr), DefaultColormap (dsp, scr)); for (;;) { char *txt = "Lorem ipsum"; XEvent e; XNextEvent (dsp, &e); if (e.type == Expose) XftDrawString8 (draw, &xft_color, font, 20, 30, (XftChar8*)(txt), strlen(txt)); } } }
Fnt * drw_font_create(Display *dpy, int screen, const char *fontname) { Fnt *font; font = (Fnt *)calloc(1, sizeof(Fnt)); if(!font) return NULL; if(!(font->xfont = XftFontOpenName(dpy,screen,fontname)) && !(font->xfont = XftFontOpenName(dpy,screen,"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; }
struct gui_font * gui_font_load(const char *name, unsigned int size, int flags) { struct gui_font *result; XGlyphInfo extents; XftFont *xft_font; char *xft_font_desc; xft_font_desc = alloca(strlen(name) + 64); sprintf(xft_font_desc, "%s:pixelsize=%d", name, size); if(flags & GUI_FONT_BOLD) strcat(xft_font_desc, ":bold"); if(0 == (xft_font = XftFontOpenName(GUI_display, GUI_screenidx, xft_font_desc))) return 0; result = malloc(sizeof(*result)); result->xft_font = xft_font; XftTextExtentsUtf8(GUI_display, xft_font, (const unsigned char *) " ", 1, &extents); result->space_width = extents.xOff; return result; }
/*----------------------------------------------------------------------------*/ void VKLoadXResource() { VKLocaleInit(); VKLoadPalette(); if( !vk_font_name ) vk_font_name = strdup(screen_width<=800 ? VK_FONT_SMALL : VK_FONT_LARGE); if( !vk_font_name ) error("Error: not enough memory!"); #ifdef USE_XFT vk_font = XftFontOpenName(display, 0, vk_font_name); if( !vk_font ) vk_font = XftFontOpenXlfd(display, 0, vk_font_name); #else vk_font = XLoadQueryFont(display, vk_font_name); if( !vk_font ) vk_font = XLoadQueryFont(display, screen_width<=800 ? VK_FONT_SMALL : VK_FONT_LARGE); VKFontSetInit(); #endif if( !vk_font ) error("Cannot load font %s\n", vk_font_name); vk_hand = XCreateFontCursor(display, XC_hand2); vk_cursor = XCreateFontCursor(display, XC_left_ptr); vk_attrib.override_redirect = True; #ifdef USE_XFT vk_text_height = vk_font->height; vk_text_ascent = vk_font->ascent; #else { XFontSetExtents *fse = XExtentsOfFontSet(vk_fontset); vk_text_height = fse->max_logical_extent.height + 4; vk_text_ascent = vk_font->ascent + 3; } #endif }
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; }
static byte X11_LoadFont(CONST char * fontname, udat fontwidth, udat fontheight) { char * alloc_fontname = 0; byte loaded = tfalse; if (!fontname) fontname = alloc_fontname = X11_AutodetectFont(fontwidth, fontheight); #if HW_X_DRIVER == HW_X11 if ((fontname && (xsfont = XLoadQueryFont(xdisplay, fontname))) || (xsfont = XLoadQueryFont(xdisplay, fontname = "fixed"))) #elif HW_X_DRIVER == HW_XFT if (fontname && (xsfont = XftFontOpenName(xdisplay, DefaultScreen(xdisplay), fontname))) #endif { loaded = ttrue; #if HW_X_DRIVER == HW_X11 xwfont = xsfont->min_bounds.width; #elif HW_X_DRIVER == HW_XFT xwfont = xsfont->max_advance_width; #endif xwidth = xwfont * (unsigned)(HW->X = GetDisplayWidth()); xhfont = (xupfont = xsfont->ascent) + xsfont->descent; xheight = xhfont * (unsigned)(HW->Y = GetDisplayHeight()); printk(" selected %ux%u font `%."STR(TW_SMALLBUFF)"s'\n", (unsigned)xwfont, (unsigned)xhfont, fontname); } if (alloc_fontname) FreeMem(alloc_fontname); return loaded; }
/** Init the font */ static void init_font(void) { font = XftFontOpenName(dpy, SCREEN, conf.font); if(!font) { warnx("MWM Error: Cannot initialize font"); font = XftFontOpenName(dpy, SCREEN, "sans-10"); } /* Set font in _MWM_FONT for eventual status tools */ XChangeProperty(dpy, ROOT, net_atom[mwm_font], net_atom[utf8_string], 8, PropModeReplace, (uchar*)conf.font, strlen(conf.font)); return; }
// set an Xft font by name void textbox_font(textbox *tb, char *font, char *fg, char *bg) { if (tb->font) XftFontClose(display, tb->font); tb->font = XftFontOpenName(display, DefaultScreen(display), font); XftColorAllocName(display, DefaultVisual(display, DefaultScreen(display)), DefaultColormap(display, DefaultScreen(display)), fg, &tb->color_fg); XftColorAllocName(display, DefaultVisual(display, DefaultScreen(display)), DefaultColormap(display, DefaultScreen(display)), bg, &tb->color_bg); }
void win_init_font(const win_env_t *e, const char *fontstr) { if ((font = XftFontOpenName(e->dpy, e->scr, fontstr)) == NULL) error(EXIT_FAILURE, 0, "Error loading font '%s'", fontstr); fontheight = font->ascent + font->descent; FcPatternGetDouble(font->pattern, FC_SIZE, 0, &fontsize); barheight = fontheight + 2 * V_TEXT_PAD; }
/* helper function to correctly open Xft/core fonts by name #### Can't we use FcParseName here? #### Is this done so often that the logic needs to be hard-coded in C? Daniel Pittman sez: Older code tried to enforce that an XLFD font was not scaled, while this version just doesn't care. I think that is a better behavior, since if someone really wants a scaled font we should oblige them. Stephen sez: This whole function was ill-conceived, and I'm not sure it succeeds at any of the things it attempts to do. First, we should be using fontconfig directly. I'm not sure what Xft (or fontconfig) will try to do if passed an XLFD. As for scaled fonts, both options are equally bad. The problem is that the X server will often scale bitmap fonts willy-nilly; it's worth trying to avoid that, but I can't say whether that's worth overriding somebody who knows what they're doing. In any case, I think we should find out what Xft (fontconfig?) is able and willing to do with XLFDs, and probably move the logic to LISP. */ XftFont * xft_open_font_by_name (Display *dpy, char *name) { XftFont *res = NULL; /* if (!NILP (Fxft_xlfd_font_name_p (make_string (name, strlen (name))))) */ /* #### this is bogus but ... */ int count = 0; char *pos = name; /* extra parens shut up gcc */ while ((pos = strchr (pos, '-'))) { count++; pos++; } /* #### hard-coding DefaultScreen is evil! */ if (count == 14 /* fully-qualified XLFD */ || (count < 14 /* heuristic for wildcarded XLFD */ && count >= 5 && strchr (name, '*'))) res = XftFontOpenXlfd (dpy, DefaultScreen (dpy), name); else res = XftFontOpenName (dpy, DefaultScreen (dpy), name); /* Try for a generic monospace font #### Why? Menus don't need to line up in columns! */ if (!res) res = XftFontOpenName (dpy, DefaultScreen (dpy), "monospace"); /* Try for anything we can get */ if (!res) res = XftFontOpenName (dpy, DefaultScreen (dpy), ""); if (!res) { /* #### This is Just So Wrong ... ! */ /* sorry folks ... */ fprintf (stderr, "Unable to find any usable XFT font, even the defaults!\n"); abort (); return 0; } return res; }
JBoolean JXFontManager::GetNewFont ( const JCharacter* name, const JSize size, const JFontStyle& style, XFont* xfont ) const { JString xFontStr; #if ENABLE_TRUE_TYPE if (BuildTrueTypeFontName(name, size, style, &xFontStr)) { XftFont* xft = XftFontOpenName(*itsDisplay, itsDisplay->GetScreen(), xFontStr); if (xft != NULL) { xfont->type = kTrueType; xfont->xftrue = xft; return kJTrue; } } #endif const JCharacter* italicStr = kObliqueStr; // try oblique before italic const JCharacter* iso = "iso8859-1"; XFontStruct* xfs = NULL; while (1) { xFontStr = BuildStdFontName(name, size, style, italicStr, iso); xfs = XLoadQueryFont(*itsDisplay, xFontStr); if (xfs != NULL) { xfont->type = kStdType; xfont->xfstd = xfs; return kJTrue; } if (strcmp(italicStr, kObliqueStr) == 0 && style.italic) { italicStr = kItalicStr; } else if (iso[1] != '\0') { iso = "*"; } else { return kJFalse; // give up } } }
void setup_font(struct font *font, char *fontstr) { if(!(font->xfont = XftFontOpenName(dpy, screen, fontstr))) { err("WARNING: Could not setup font: '%s'. Falling back to 'fixed'\n", fontstr); if(!(font->xfont = XftFontOpenXlfd(dpy, screen, "fixed"))) die("ERROR: Could not setup font\n"); } font->h = font->xfont->ascent + font->xfont->descent; }
static int init() { XWindowAttributes wa; XSetWindowAttributes swa; XGCValues gcv; Window root; XConfigureEvent ce; d = XOpenDisplay(0); if (!d) die("cannot open display"); root = DefaultRootWindow(d); XGetWindowAttributes(d, root, &wa); visual = wa.visual; cmap = wa.colormap; screen = DefaultScreen(d); depth = DefaultDepth(d, screen); /* create the main window */ win = XCreateSimpleWindow(d, root, 0, 0, Width, Height, 0, 0, WhitePixel(d, screen)); swa.backing_store = WhenMapped; swa.bit_gravity = NorthWestGravity; XChangeWindowAttributes(d, win, CWBackingStore|CWBitGravity, &swa); XStoreName(d, win, "ED"); XSelectInput(d, win, StructureNotifyMask|ButtonPressMask|ButtonReleaseMask|Button1MotionMask|KeyPressMask|ExposureMask); /* simulate an initial resize and map the window */ ce.type = ConfigureNotify; ce.width = Width; ce.height = Height; XSendEvent(d, win, False, StructureNotifyMask, (XEvent *)&ce); XMapWindow(d, win); /* allocate font */ font = XftFontOpenName(d, screen, FONTNAME); if (!font) die("cannot open default font"); /* initialize gc */ gcv.foreground = WhitePixel(d, screen); gcv.graphics_exposures = False; gc = XCreateGC(d, win, GCForeground|GCGraphicsExposures, &gcv); /* initialize back buffer and Xft drawing context */ pbuf = XCreatePixmap(d, win, Width, Height, depth); xft = XftDrawCreate(d, pbuf, visual, cmap); /* set the action rectangle */ gui_x11.actionr.w = HMargin - 3; gui_x11.actionr.h = VMargin + font->height; return XConnectionNumber(d); }
XftFont *loadFont(const char *name, S32 size, Display *display) { XftFont *fontInfo = NULL; char* fontname = const_cast<char*>(name); if (dStrlen(fontname)==0) fontname = "arial"; else if (stristr(const_cast<char*>(name), "arial") != NULL) fontname = "arial"; else if (stristr(const_cast<char*>(name), "lucida console") != NULL) fontname = "lucida console"; char* weight = "medium"; char* slant = "roman"; // no slant if (stristr(const_cast<char*>(name), "bold") != NULL) weight = "bold"; if (stristr(const_cast<char*>(name), "italic") != NULL) slant = "italic"; int mSize = size - 2 - (int)((float)size * 0.1); char xfontName[512]; // We specify a lower DPI to get 'correct' looking fonts, if we go with the // native DPI the fonts are to big and don't fit the widgets. dSprintf(xfontName, 512, "%s-%d:%s:slant=%s:dpi=76", fontname, mSize, weight, slant); // Lets see if Xft can get a font for us. char xftname[1024]; fontInfo = XftFontOpenName(display, DefaultScreen(display), xfontName); // Cant find a suitabke font, default to a known font (6x10) if ( !fontInfo ) { dSprintf(xfontName, 512, "6x10-%d:%s:slant=%s:dpi=76", mSize, weight, slant); fontInfo = XftFontOpenName(display, DefaultScreen(display), xfontName); } XftNameUnparse(fontInfo->pattern, xftname, 1024); #ifdef DEBUG Con::printf("Font '%s %d' mapped to '%s'\n", name, size, xftname); #endif return fontInfo; }
WMFont* WMCreateFont(WMScreen *scrPtr, char *fontName) { WMFont *font; Display *display = scrPtr->display; char *fname, *ptr; /* This is for back-compat (to allow reading of old xlfd descriptions) */ if (fontName[0]=='-' && (ptr = strchr(fontName, ','))) { // warn for deprecation fname = wmalloc(ptr - fontName + 1); strncpy(fname, fontName, ptr - fontName); fname[ptr - fontName] = 0; } else { fname = wstrdup(fontName); } font = WMHashGet(scrPtr->fontCache, fname); if (font) { WMRetainFont(font); wfree(fname); return font; } font = wmalloc(sizeof(WMFont)); memset(font, 0, sizeof(WMFont)); font->screen = scrPtr; // remove printf("WMCreateFont: %s\n", fname); if (fname[0] == '-') { // Backward compat thing. Remove in a later version font->font = XftFontOpenXlfd(display, scrPtr->screen, fname); } else { font->font = XftFontOpenName(display, scrPtr->screen, fname); } if (!font->font) { wfree(font); wfree(fname); return NULL; } font->height = font->font->ascent+font->font->descent; font->y = font->font->ascent; font->refCount = 1; font->name = fname; assert(WMHashInsert(scrPtr->fontCache, font->name, font)==NULL); return font; }
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 }
void gui_init (void) { XGCValues gcv; XColor xcl; unsigned int i; #ifndef XFT char *fontname; #endif i = 0; do { xcl.red = cols[i].red; xcl.green = cols[i].green; xcl.blue = cols[i].blue; XAllocColor (dd, DefaultColormap (dd, scr_screen), &xcl); palette[i] = xcl.pixel; i++; } while (i < PALETTE_COUNT); #ifdef XFT xfs = XftFontOpenName (dd, scr_screen, XFT_FONT); #else fontname = FONT_NAME; do { xfs = XLoadQueryFont (dd, fontname); fontname = "fixed"; } while (!xfs); #endif gcv.graphics_exposures = False; #ifdef XFT text_y = xfs->ascent + ((WINHEIGHT - (xfs->ascent + xfs->descent)) / 2); fore_gc = XCreateGC (dd, root_win, GCGraphicsExposures, &gcv); #else text_y = xfs->ascent + ((WINHEIGHT - xfs->ascent) / 2); gcv.font = xfs->fid; fore_gc = XCreateGC (dd, root_win, GCFont | GCGraphicsExposures, &gcv); #endif #ifdef HAVE_XPM XpmCreatePixmapFromData (dd, root_win, icon_xpm, &generic_icon, &generic_mask, NULL); #else generic_icon = 0; #endif }
/* This function is an implementation detail. Library users should use * drw_font_create instead. */ static Fnt * drw_font_xcreate(Drw *drw, const char *fontname, FcPattern *fontpattern) { Fnt *font; if (!(fontname || fontpattern)) die("No font specified.\n"); if (!(font = (Fnt *)calloc(1, sizeof(Fnt)))) return NULL; if (fontname) { /* Using the pattern found at font->xfont->pattern does not yield same * the same substitution results as using the pattern returned by * FcNameParse; using the latter results in the desired fallback * behaviour whereas the former just results in * missing-character-rectangles being drawn, at least with some fonts. */ if (!(font->xfont = XftFontOpenName(drw->dpy, drw->screen, fontname)) || !(font->pattern = FcNameParse((FcChar8 *) fontname))) { if (font->xfont) { XftFontClose(drw->dpy, font->xfont); font->xfont = NULL; } fprintf(stderr, "error, cannot load font: '%s'\n", fontname); } } else if (fontpattern) { if (!(font->xfont = XftFontOpenPattern(drw->dpy, fontpattern))) { fprintf(stderr, "error, cannot load font pattern.\n"); } else { font->pattern = NULL; } } if (!font->xfont) { free(font); return NULL; } font->ascent = font->xfont->ascent; font->descent = font->xfont->descent; font->h = font->ascent + font->descent; font->dpy = drw->dpy; return font; }
static bool xft_load (Lisp_Font *f) { XftFont *xft_font; xft_font = XftFontOpenName (dpy, screen_num, rep_STR (f->name)); if (xft_font == 0) return FALSE; f->font = xft_font; f->ascent = xft_font->ascent; f->descent = xft_font->descent; return TRUE; }
static void Change_Font(Widget w, int n, char *s) { CtrlWidget cw = (CtrlWidget)w; CtrlPart *c = & cw->ctrl; Display *dpy = XtDisplay(w); clabel_t *cl = c->clabel+n; XftFont *font; TF(); TRACE(2,"%s",s); if( IsEmpty(s) ) s="Sans-12"; font = XftFontOpenName(dpy, DefaultScreen(dpy), s ); if(!font ) XtAppError(XtWidgetToApplicationContext(w), "CtrlWidget: unknown font" ); else { if( cl->font ) XftFontClose( dpy, cl->font); cl->font = font; } }
static XftFont* openFont (Widget widget, char *name) { char *fname = name; int screen = XScreenNumberOfScreen (XtScreen (widget)); int len = strlen (fname), i = len-1; XftFont *fn; /* Try to convert Gtk-syntax (Sans 9) to Xft syntax Sans-9. */ while (i > 0 && '0' <= fname[i] && fname[i] <= '9') --i; if (fname[i] == ' ') { fname = xstrdup (name); fname[i] = '-'; } fn = XftFontOpenName (XtDisplay (widget), screen, fname); if (fname != name) xfree (fname); return fn; }
static int _xft_Load(TextState * ts, const char *name) { XftFont *font; FontCtxXft *fdc; if (name[0] == '-') font = XftFontOpenXlfd(disp, Dpy.screen, name); else font = XftFontOpenName(disp, Dpy.screen, name); if (!font) return -1; #if 0 /* Debug */ { FT_Face ftf = XftLockFace(font); if (ftf == NULL) return -1; Eprintf("Font %s family_name=%s style_name=%s\n", name, ftf->family_name, ftf->style_name); XftUnlockFace(font); } #endif fdc = EMALLOC(FontCtxXft, 1); if (!fdc) return -1; fdc->font = font; ts->fdc = fdc; ts->need_utf8 = 1; ts->type = FONT_TYPE_XFT; ts->ops = &FontOps_xft; return 0; }
void* thread_pattern_gen(void *data){ Display *dp; Bool is_ntsc = (Bool)data; Window mw; /* One TopLevel Window & Two Child Windows */ GC gc, gc_rect1, gc_rect2, gc_string; XftFont *xft; XftDraw *xftdraw; XRenderColor xrcolor; XftColor xftcolor; XGCValues gv; XSetWindowAttributes xswa; struct timeval tv; /* 서버와 접속하기 그리고 변수들을 초기화 */ dp = XOpenDisplay ( NULL ); mw = XCreateSimpleWindow ( dp, DefaultRootWindow( dp ), 0, 0, 720, is_ntsc?480:576, 0, WhitePixel(dp,0), BlackPixel(dp,0) ); xswa.override_redirect = True; XChangeWindowAttributes ( dp, mw, CWOverrideRedirect, &xswa ); XMapWindow( dp, mw ); gv.foreground = UsrColorPixel( dp, "red" ); gv.background = UsrColorPixel( dp, "yello" ); gc = XCreateGC( dp, mw, GCForeground | GCBackground, &gv ); gv.foreground = UsrColorPixel( dp, "red" ); gv.background = UsrColorPixel( dp, "black" ); gc_rect1 = XCreateGC( dp, mw, GCForeground | GCBackground, &gv ); gv.foreground = UsrColorPixel( dp, "blue" ); gv.background = UsrColorPixel( dp, "black" ); gc_rect2 = XCreateGC( dp, mw, GCForeground | GCBackground, &gv ); gv.foreground = UsrColorPixel( dp, "white" ); gv.background = UsrColorPixel( dp, "black" ); gc_string = XCreateGC( dp, mw, GCForeground | GCBackground, &gv ); //xft = XftFontOpenName( dp, 0, "Bitstream Vera Sans Mono-50:bold" ); xft = XftFontOpenName( dp, 0, "Courier New-48:bold" ); if(!xft){ printf("font null\n"); return 0; } xftdraw = XftDrawCreate(dp, mw, DefaultVisual(dp, 0), DefaultColormap(dp, 0)); xrcolor.red = 65535; xrcolor.green = 65535; xrcolor.blue =65535; xrcolor.alpha = 65535; XftColorAllocValue(dp, DefaultVisual(dp, 0), DefaultColormap(dp, 0), &xrcolor, &xftcolor); int frame_rate = is_ntsc? 30:25; unsigned int div = is_ntsc? 33333: 40000; char line1[40]; char line2[40]; int line1_y = is_ntsc? (480/2)-30 : (576/2)-30; int line2_y = is_ntsc? (480/2)+30 : (576/2)+30; int rect1_y = is_ntsc? 480/4 : 576/4; int rect2_y = is_ntsc? (480/4)*3 : (576/4)*3; while(1){ if(kill_thread) break; int move; for( move = 0; move < frame_rate; move ++){ gettimeofday(&tv, NULL); struct tm *ptm = localtime(&(tv.tv_sec)); XFlush(dp); XClearWindow( dp, mw ); XFillRectangle ( dp, mw, gc_rect1, (move==0)? 0:(720/30)*move, rect1_y, 50, 10); XFillRectangle ( dp, mw, gc_rect2, (move==0)? 0:720-(720/30)*move, rect2_y, 50, 10); sprintf(line1," %04d/%02d/%02d ", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday); sprintf(line2,"%02d:%02d:%02d %02ld\'",ptm->tm_hour, ptm->tm_min, ptm->tm_sec, tv.tv_usec/div); XftDrawString8(xftdraw, &xftcolor, xft, 100, line1_y, (XftChar8 *)line1, 12); XftDrawString8(xftdraw, &xftcolor, xft, 100, line2_y, (XftChar8 *)line2, 12); usleep(div); } } printf("thread kill\n"); /* GC, 창 파괴 & 서버와의 접속 해제 */ XFreeGC( dp, gc ); XUnmapWindow( dp, mw ); XftDrawDestroy(xftdraw); XftColorFree(dp, DefaultVisual(dp, 0), DefaultColormap(dp, 0), &xftcolor); XDestroyWindow( dp, mw ); XCloseDisplay( dp ); return 0; }
DEFont *de_load_font(const char *fontname) { DEFont *fnt; const char *default_fontname=de_default_fontname(); #ifdef HAVE_X11_XFT XftFont *font=NULL; #endif #ifdef HAVE_X11_BMF XFontSet fontset=NULL; XFontStruct *fontstruct=NULL; #endif assert(fontname!=NULL); /* There shouldn't be that many fonts... */ for(fnt=fonts; fnt!=NULL; fnt=fnt->next){ if(strcmp(fnt->pattern, fontname)==0){ fnt->refcount++; return fnt; } } #ifdef HAVE_X11_XFT LOG(DEBUG, FONT, "Loading font %s via XFT", fontname); if(strncmp(fontname, "xft:", 4)==0){ font=XftFontOpenName(ioncore_g.dpy, DefaultScreen(ioncore_g.dpy), fontname+4); }else{ #ifdef HAVE_X11_BMF goto bitmap_font; #else font=XftFontOpenXlfd(ioncore_g.dpy, DefaultScreen(ioncore_g.dpy), fontname); #endif } if(font==NULL){ if(strcmp(fontname, default_fontname)!=0){ warn(TR("Could not load font \"%s\", trying \"%s\""), fontname, default_fontname); fnt=de_load_font(default_fontname); if(fnt==NULL) LOG(WARN, FONT, TR("Failed to load fallback font.")); return fnt; } return NULL; }else{ FcPatternPrint(font->pattern); } #endif /* HAVE_X11_XFT */ #ifdef HAVE_X11_BMF #ifdef HAVE_X11_XFT bitmap_font: #endif if(ioncore_g.use_mb && !(ioncore_g.enc_utf8 && iso10646_font(fontname))){ LOG(DEBUG, FONT, "Loading fontset %s", fontname); fontset=de_create_font_set(fontname); if(fontset!=NULL){ if(XContextDependentDrawing(fontset)){ warn(TR("Fontset for font pattern '%s' implements context " "dependent drawing, which is unsupported. Expect " "clutter."), fontname); } } }else{ LOG(DEBUG, FONT, "Loading fontstruct %s", fontname); fontstruct=XLoadQueryFont(ioncore_g.dpy, fontname); } if(fontstruct==NULL && fontset==NULL){ if(strcmp(fontname, default_fontname)!=0){ DEFont *fnt; LOG(WARN, FONT, TR("Could not load font \"%s\", trying \"%s\""), fontname, default_fontname); fnt=de_load_font(default_fontname); if(fnt==NULL) LOG(WARN, FONT, TR("Failed to load fallback font.")); return fnt; } return NULL; } #endif /* HAVE_X11_BMF */ fnt=ALLOC(DEFont); if(fnt==NULL) return NULL; #ifdef HAVE_X11_XFT fnt->font=font; #endif #ifdef HAVE_X11_BMF fnt->fontset=fontset; fnt->fontstruct=fontstruct; #endif fnt->pattern=scopy(fontname); fnt->next=NULL; fnt->prev=NULL; fnt->refcount=1; LINK_ITEM(fonts, fnt, next, prev); return fnt; }
int main(int argc, char *argv[]) { XEvent e; Atom type; XClassHint *h; XSetWindowAttributes wa; unsigned int desktop; struct pollfd pfd[1]; int nfds; char *fontstr = FONT; int running = 1; d = XOpenDisplay(NULL); if (d == NULL) { fprintf(stderr, "Cannot open display\n"); exit(1); } s = DefaultScreen(d); wa.override_redirect = 1; wa.background_pixmap = ParentRelative; wa.event_mask = ExposureMask | ButtonReleaseMask | ButtonPressMask; w = XCreateWindow(d, RootWindow(d, s), 0, BARPOS, BARWIDTH, BARHEIGHT, 0, DefaultDepth(d, s), CopyFromParent, DefaultVisual(d, s), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); h = XAllocClassHint(); h->res_name = "status"; h->res_class = "status"; XSetClassHint(d, w, h); XFree(h); XStoreName(d, w, "status"); type = XInternAtom(d, "_NET_WM_WINDOW_TYPE_DOCK", False); XChangeProperty(d, w, XInternAtom(d, "_NET_WM_WINDOW_TYPE", False), XInternAtom(d, "ATOM", False), 32, PropModeReplace, (unsigned char *)&type, 1); type = XInternAtom(d, "_NET_WM_STATE_ABOVE", False); XChangeProperty(d, w, XInternAtom(d, "_NET_WM_STATE", False), XInternAtom(d, "ATOM", False), 32, PropModeReplace, (unsigned char *)&type, 1); type = XInternAtom(d, "_NET_WM_STATE_STICKY", False); XChangeProperty(d, w, XInternAtom(d, "_NET_WM_STATE", False), XInternAtom(d, "ATOM", False), 32, PropModeAppend, (unsigned char *)&type, 1); desktop = 0xffffffff; XChangeProperty(d, w, XInternAtom(d, "_NET_WM_DESKTOP", False), XInternAtom(d, "CARDINAL", False), 32, PropModeReplace, (unsigned char *)&desktop, 1); xftd = XftDrawCreate(d, w, DefaultVisual(d, s), DefaultColormap(d, s)); XftColorAllocName(d, DefaultVisual(d, s), DefaultColormap(d, s), "white", &white); XftColorAllocName(d, DefaultVisual(d, s), DefaultColormap(d, s), "black", &black); XftColorAllocName(d, DefaultVisual(d, s), DefaultColormap(d, s), "red", &red); XftColorAllocName(d, DefaultVisual(d, s), DefaultColormap(d, s), "green", &green); xftfont = XftFontOpenXlfd(d, s, fontstr); if (!xftfont) xftfont = XftFontOpenName(d, s, fontstr); if (!xftfont) exit(1); XSelectInput(d, w, ExposureMask | ButtonPressMask | ButtonReleaseMask | Button1MotionMask); XSelectInput(d, RootWindow(d, s), PropertyChangeMask); XMapWindow(d, w); XFlush(d); pfd[0].fd = ConnectionNumber(d); pfd[0].events = POLLIN; while (running) { nfds = poll(pfd, 1, 1000); if (nfds == -1 || (pfd[0].revents & (POLLERR|POLLHUP|POLLNVAL))) break; if (nfds == 0) { redraw(); XFlush(d); continue; } while (XPending(d)) { XNextEvent(d, &e); if (e.type == PropertyNotify && e.xproperty.window == RootWindow(d, s) && e.xproperty.atom == XInternAtom(d, "_NET_CURRENT_DESKTOP", True)) { redraw(); } if (e.type == Expose) { XftDrawRect(xftd, &black, 0, 0, BARWIDTH, BARHEIGHT); redraw(); } if (e.type == ButtonPress) { /*running = 0; break;*/ redraw(); } } } XftColorFree(d, DefaultVisual(d, s), DefaultColormap(d, s), &white); XftColorFree(d, DefaultVisual(d, s), DefaultColormap(d, s), &black); XftFontClose(d, xftfont); XftDrawDestroy(xftd); XDestroyWindow(d, w); XCloseDisplay(d); return 0; }
void cfg_set_opt(char *key, char *value, int initial) { #ifdef USE_XFT XftFont *newxftfont; #endif XFontStruct *newfont; long i; if(strcmp(key, "resetkeys") == 0) keys_free(); if(!value) return; if(strcmp(key, "key") == 0) key_bind(value); if(strcmp(key, "exec") == 0 && initial) spawn(value); if(strcmp(key, "exec_onload") == 0) spawn(value); if(strcmp(key, "background") == 0) str_color(value, &bg); if(strcmp(key, "inactive_background") == 0) str_color(value, &ibg); if(strcmp(key, "foreground") == 0) str_color(value, &fg); if(strcmp(key, "inactive_foreground") == 0) str_color(value, &ifg); if(strcmp(key, "border_color") == 0) str_color(value, &bfg); if(strcmp(key, "inactive_border_color") == 0) str_color(value, &ibfg); if(strcmp(key, "font") == 0) { newfont = XLoadQueryFont(dpy, value); if(newfont) { if(font) XFreeFont(dpy, font); #ifdef USE_XFT if(xftfont) { XftFontClose(dpy, xftfont); xftfont = NULL; } #endif font = newfont; } #ifdef USE_XFT else { newxftfont = XftFontOpenName(dpy, screen, value); if(newxftfont) { if(xftfont) XftFontClose(dpy, xftfont); if(font) { XFreeFont(dpy, font); font = NULL; } xftfont = newxftfont; } } #endif } if(strcmp(key, "border_width") == 0) { i = strtol(value, NULL, 0); if(i >= 0) border_width = i; } if(strcmp(key, "border_spacing") == 0) { i = strtol(value, NULL, 0); if(i >= 0) border_spacing = i; } if(strcmp(key, "title_spacing") == 0) { i = strtol(value, NULL, 0); if(i >= 0) title_spacing = i; } if(strcmp(key, "button_spacing") == 0) { i = strtol(value, NULL, 0); if(i >= 0) button_spacing = i; } if(strcmp(key, "wlist_margin") == 0) { i = strtol(value, NULL, 0); if(i >= 0) wlist_margin = i; } if(strcmp(key, "wlist_maxwidth") == 0) { i = strtol(value, NULL, 0); if(i >= 0) wlist_maxwidth = i; } if(strcmp(key, "doubleclick_time") == 0) { i = strtol(value, NULL, 0); if(i > 0) doubleclick_time = i; } if(strcmp(key, "snap") == 0) snapat = strtol(value, NULL, 0); if(strcmp(key, "desktops") == 0) { i = strtol(value, NULL, 0); if(i > 0) dc = i; } if(strcmp(key, "ewmh_screen") == 0) { i = strtol(value, NULL, 0); if(i > 0) ewmh_screen = i; } if(strcmp(key, "button1") == 0) str_action(value, &button1); if(strcmp(key, "button2") == 0) str_action(value, &button2); if(strcmp(key, "button3") == 0) str_action(value, &button3); if(strcmp(key, "button4") == 0) str_action(value, &button4); if(strcmp(key, "button5") == 0) str_action(value, &button5); if(strcmp(key, "double1") == 0) str_action(value, &double1); if(strcmp(key, "double2") == 0) str_action(value, &double2); if(strcmp(key, "double3") == 0) str_action(value, &double3); if(strcmp(key, "double4") == 0) str_action(value, &double4); if(strcmp(key, "double5") == 0) str_action(value, &double5); if(strcmp(key, "root_button1") == 0) str_action(value, &root_button1); if(strcmp(key, "root_button2") == 0) str_action(value, &root_button2); if(strcmp(key, "root_button3") == 0) str_action(value, &root_button3); if(strcmp(key, "root_button4") == 0) str_action(value, &root_button4); if(strcmp(key, "root_button5") == 0) str_action(value, &root_button5); if(strcmp(key, "root_double1") == 0) str_action(value, &root_double1); if(strcmp(key, "root_double2") == 0) str_action(value, &root_double2); if(strcmp(key, "root_double3") == 0) str_action(value, &root_double3); if(strcmp(key, "root_double4") == 0) str_action(value, &root_double4); if(strcmp(key, "root_double5") == 0) str_action(value, &double5); if(strcmp(key, "click_focus") == 0) str_bool(value, &click_focus); if(strcmp(key, "click_raise") == 0) str_bool(value, &click_raise); if(strcmp(key, "focus_new") == 0) str_bool(value, &focus_new); if(strcmp(key, "fullscreen_stacking") == 0) str_fsstacking(value, &fullscreen_stacking); if(strcmp(key, "taskbar_ontop") == 0) str_bool(value, &taskbar_ontop); if(strcmp(key, "center_title") == 0) str_bool(value, ¢er_title); if(strcmp(key, "center_wlist_items") == 0) str_bool(value, ¢er_wlist_items); if(strcmp(key, "map_center") == 0) str_bool(value, &map_center); if(strcmp(key, "drag_warp") == 0) str_bool(value, &drag_warp); if(strcmp(key, "allow_focus_stealing") == 0) str_bool(value, &allow_focus_stealing); if(strcmp(key, "correct_center") == 0) str_bool(value, &correct_center); if(strcmp(key, "correct_center_unmanaged") == 0) str_bool(value, &correct_center_unmanaged); if(strcmp(key, "correct_center_separate") == 0) str_bool(value, &correct_center_separate); if(strcmp(key, "click_root") == 0) str_bool(value, &click_root); if(strcmp(key, "mouse_modifier") == 0) str_key(&value, &mousemodmask); if(strcmp(key, "no_snap_modifier") == 0) str_key(&value, &nosnapmodmask); if(strcmp(key, "ignore_modifier") == 0) { if(mod_ignore) { nmod_ignore = 0; free((void *) mod_ignore); mod_ignore = NULL; } while(value) { mod_ignore = (unsigned int *) _realloc((void *) mod_ignore, (nmod_ignore + nmod_ignore + 1) * sizeof(unsigned int)); skiprealloc: mod_ignore[nmod_ignore] = str_modifier(eat(&value, " \t")); if(mod_ignore[nmod_ignore] == None) goto skiprealloc; for(i = 0; i < nmod_ignore; i++) mod_ignore[nmod_ignore + 1 + i] = mod_ignore[i] | mod_ignore[nmod_ignore]; nmod_ignore += nmod_ignore + 1; } } if(strcmp(key, "buttons_left") == 0) str_buttons(value, &buttons_left, &nbuttons_left); if(strcmp(key, "buttons_right") == 0) str_buttons(value, &buttons_right, &nbuttons_right); }
Tooltip * tooltip_create(MainWin *mw, dlist *config) { Tooltip *tt; XSetWindowAttributes attr; const char *tmp; long int tmp_l; tt = (Tooltip *)malloc(sizeof(Tooltip)); if(! tt) return 0; tt->mainwin = mw; tt->window = None; tt->font = 0; tt->draw = 0; tt->text = 0; tt->color.pixel = tt->background.pixel = tt->border.pixel = tt->shadow.pixel = None; attr.override_redirect = True; attr.border_pixel = None; attr.background_pixel = None; attr.event_mask = ExposureMask; attr.colormap = mw->colormap; tt->window = XCreateWindow(mw->dpy, mw->root, 0, 0, 1, 1, 0, mw->depth, InputOutput, mw->visual, CWBorderPixel|CWBackPixel|CWOverrideRedirect|CWEventMask|CWColormap, &attr); if(tt->window == None) { fprintf(stderr, "WARNING: Couldn't create tooltip window.\n"); tooltip_destroy(tt); return 0; } tmp = config_get(config, "tooltip", "border", "#e0e0e0"); if(! XftColorAllocName(mw->dpy, mw->visual, mw->colormap, tmp, &tt->border)) { fprintf(stderr, "WARNING: Invalid color '%s'.\n", tmp); tooltip_destroy(tt); return 0; } tmp = config_get(config, "tooltip", "background", "#404040"); if(! XftColorAllocName(mw->dpy, mw->visual, mw->colormap, tmp, &tt->background)) { fprintf(stderr, "WARNING: Invalid color '%s'.\n", tmp); tooltip_destroy(tt); return 0; } tmp = config_get(config, "tooltip", "opacity", "128"); tmp_l = MIN(MAX(0, strtol(tmp, 0, 0) * 256), 65535); tt->background.color.alpha = tmp_l; tt->border.color.alpha = tmp_l; tmp = config_get(config, "tooltip", "text", "#e0e0e0"); if(! XftColorAllocName(mw->dpy, mw->visual, mw->colormap, tmp, &tt->color)) { fprintf(stderr, "WARNING: Couldn't allocate color '%s'.\n", tmp); tooltip_destroy(tt); return 0; } tmp = config_get(config, "tooltip", "textShadow", "black"); if(strcasecmp(tmp, "none") != 0) { if(! XftColorAllocName(mw->dpy, mw->visual, mw->colormap, tmp, &tt->shadow)) { fprintf(stderr, "WARNING: Couldn't allocate color '%s'.\n", tmp); tooltip_destroy(tt); return 0; } } tt->draw = XftDrawCreate(mw->dpy, tt->window, mw->visual, mw->colormap); if(! tt->draw) { fprintf(stderr, "WARNING: Couldn't create Xft draw surface.\n"); tooltip_destroy(tt); return 0; } tt->font = XftFontOpenName(mw->dpy, mw->screen, config_get(config, "tooltip", "font", "fixed-11:weight=bold")); if(! tt->font) { fprintf(stderr, "WARNING: Couldn't open Xft font.\n"); tooltip_destroy(tt); return 0; } tt->font_height = tt->font->ascent + tt->font->descent; return tt; }
PlatformFont::CharInfo &x86UNIXFont::getCharInfo(const UTF16 ch) const { Display *display = XOpenDisplay(getenv("DISPLAY")); if (!display ) AssertFatal(false, "createFont: cannot connect to X server"); static PlatformFont::CharInfo c; dMemset(&c, 0, sizeof(c)); c.bitmapIndex = 0; c.xOffset = 0; c.yOffset = 0; XftFont *fontInfo = XftFontOpenName(display, DefaultScreen(display), mFontName); if (!fontInfo) AssertFatal(false, "createFont: cannot load font"); int screen = DefaultScreen(display); // Create the pixmap to draw on. Drawable pixmap = XCreatePixmap(display, DefaultRootWindow(display), fontInfo->max_advance_width, fontInfo->height, DefaultDepth(display, screen)); // And the Xft wrapper around it. XftDraw *draw = XftDrawCreate(display, pixmap, DefaultVisual(display, screen), DefaultColormap(display, screen)); // Allocate some colors, we don't use XftColorAllocValue here as that // Don't appear to function correctly (or I'm using it wrong) As we only do // this twice per new un cached font it isn't that big of a penalty. (Each // call to XftColorAllocName involves a round trip to the X Server) XftColor black, white; XftColorAllocName(display, DefaultVisual(display, screen), DefaultColormap(display, screen), "black", &black); // White XftColorAllocName(display, DefaultVisual(display, screen), DefaultColormap(display, screen), "white", &white); XGlyphInfo charinfo; XftTextExtents16(display, fontInfo, &ch, 1, &charinfo); c.height = fontInfo->height; c.xOrigin = 0; c.yOrigin = fontInfo->ascent; c.xIncrement = charinfo.xOff; c.width = charinfo.xOff; // kick out early if the character is undrawable if( c.width == 0 || c.height == 0) return c; // allocate a greyscale bitmap and clear it. int bitmapDataSize = c.width * c.height; c.bitmapData = new U8[bitmapDataSize]; dMemset(c.bitmapData, 0, bitmapDataSize); XftDrawRect (draw, &black, 0, 0, fontInfo->max_advance_width, fontInfo->height); XftDrawString16 (draw, &white, fontInfo, 0, fontInfo->ascent, &ch, 1); // grab the pixmap image XImage *ximage = XGetImage(display, pixmap, 0, 0, charinfo.xOff, fontInfo->height, AllPlanes, XYPixmap); if (!ximage) AssertFatal(false, "cannot get x image"); int x, y; // grab each pixel and store it in the scratchPad for(y = 0; y < fontInfo->height; y++) { for(x = 0; x < charinfo.xOff; x++) c.bitmapData[y * charinfo.xOff + x] = static_cast<U8>(XGetPixel(ximage, x, y)); } XDestroyImage(ximage); XftColorFree(display, DefaultVisual(display, screen), DefaultColormap(display, screen), &black); XftColorFree(display, DefaultVisual(display, screen), DefaultColormap(display, screen), &white); XftDrawDestroy(draw); XFreePixmap(display, pixmap); XCloseDisplay(display); return c; }