// filename: regular piece xpm data // num: ID for object instance // closeness: Color closeness for xpm library void Mahjong::ReadFile(Widget w, char *filename, int num, int closeness) { XpmAttributes attributes; int result; Pixmap mask; Colormap colormap = XDefaultColormapOfScreen(XtScreen(w)); GC gc; XGCValues gcv; if (rdata != 0 && data != rdata) { XFreePixmap(XtDisplay(w), rdata); XFreePixmap(XtDisplay(w), rdatag); } if (data != 0) { XFreePixmap(XtDisplay(w), data); XFreePixmap(XtDisplay(w), datag); } attributes.valuemask = XpmColormap | XpmSize | XpmCloseness; attributes.colormap = colormap; attributes.exactColors = False; attributes.closeness = closeness; id = num; result = XpmReadFileToPixmap(XtDisplay(w), XtWindow(w), filename, &data, &mask, &attributes); width = original_width = attributes.width; height = original_height = attributes.height; if (result != XpmSuccess && result != XpmColorError) { fprintf(stderr, "XpmReadFileToPixmap failed "); switch(result) { case XpmOpenFailed: fprintf(stderr, "(Cannot open xpm files)\n"); break; case XpmFileInvalid: fprintf(stderr, "(xpm file may be broken)\n"); break; case XpmNoMemory: fprintf(stderr, "(memory exhausted)\n"); break; case XpmColorFailed: fprintf(stderr, "(color allocation failed [closeness:%d])\n", closeness); break; default: fprintf(stderr, "(reason unknown)\n"); break; } fprintf(stderr, " %s\n", filename); exit(1); } else { attributes.valuemask = XpmColormap; gcv.foreground = WhitePixelOfScreen(XtScreen(w)); gc = XCreateGC(XtDisplay(w), XtWindow(w), GCForeground, &gcv); datag = MakeHalfBrightPixmap(data, gc); result = XpmSuccess; XFreeGC(XtDisplay(w), gc); } rdata = data; rdatag = datag; resized = 0; }
/* Konvertiere XPMIcons nach XImage */ void GetXPM(void) { XWindowAttributes attributes; int ret; /* for the colormap */ XGetWindowAttributes(dpy,Root,&attributes); /* ---------------------------------------------------------------- */ asclock.attributes.closeness = 40000; /* Allow for "similar" colors */ asclock.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions | XpmCloseness); if (clock_xpm_fn[0]) ret = XpmReadFileToPixmap(dpy, Root, clock_xpm_fn, &asclock.pixmap, &asclock.mask, &asclock.attributes); else ret = XpmCreatePixmapFromData(dpy, Root, clock_xpm, &asclock.pixmap, &asclock.mask, &asclock.attributes); if(ret != XpmSuccess) {nocolor("create asclock xpm", ERR_colorcells);exit(1);} /* ---------------------------------------------------------------- */ visible.attributes.closeness = 40000; /* Allow for "similar" colors */ visible.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions | XpmCloseness); if (clock_xpm_fn[0]) ret = XpmReadFileToPixmap(dpy, Root, clock_xpm_fn, &visible.pixmap, &visible.mask, &visible.attributes); else ret = XpmCreatePixmapFromData(dpy, Root, clock_xpm, &visible.pixmap, &visible.mask, &visible.attributes); if(ret != XpmSuccess) {nocolor("create visible xpm", ERR_colorcells);exit(1);} /* ---------------------------------------------------------------- */ if (led_visible) { led.attributes.closeness = 40000; /* Allow for "similar" colors */ led.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions | XpmCloseness); if(led_xpm_fn[0]) ret = XpmReadFileToPixmap(dpy, Root, led_xpm_fn, &led.pixmap, &led.mask, &led.attributes); else ret = XpmCreatePixmapFromData(dpy, Root, led_xpm, &led.pixmap, &led.mask, &led.attributes); if(ret != XpmSuccess) {nocolor("create led xpm", ERR_colorcells);exit(1);} if(led_elem_width==UNDEFINED) led_elem_width = led.attributes.width/15; if(led_elem_height==UNDEFINED) led_elem_height = led.attributes.height; } /* ---------------------------------------------------------------- */ if (month_visible) { month.attributes.closeness = 40000; /* Allow for "similar" colors */ month.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions | XpmCloseness); if( month_xpm_fn[0]) ret = XpmReadFileToPixmap(dpy, Root, month_xpm_fn, &month.pixmap, &month.mask, &month.attributes); else ret = XpmCreatePixmapFromData(dpy, Root, month_xpm, &month.pixmap, &month.mask, &month.attributes); if(ret != XpmSuccess) {nocolor("create month xpm", ERR_colorcells);exit(1);} if(month_elem_width==UNDEFINED) month_elem_width = month.attributes.width; if(month_elem_height==UNDEFINED) month_elem_height = month.attributes.height/12; } /* ---------------------------------------------------------------- */ if (day_visible) { date.attributes.closeness = 40000; /* Allow for "similar" colors */ date.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions | XpmCloseness); if (date_xpm_fn[0]) ret = XpmReadFileToPixmap(dpy, Root, date_xpm_fn, &date.pixmap, &date.mask, &date.attributes); else ret = XpmCreatePixmapFromData(dpy, Root, date_xpm, &date.pixmap, &date.mask, &date.attributes); if(ret != XpmSuccess) {nocolor("create date xpm", ERR_colorcells);exit(1);} if(day_elem_width==UNDEFINED) day_elem_width = date.attributes.width/10; if(day_elem_height==UNDEFINED) day_elem_height = date.attributes.height; } /* ---------------------------------------------------------------- */ if (week_visible) { weekday.attributes.closeness = 40000; /* Allow for "similar" colors */ weekday.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions | XpmCloseness); if(weekday_xpm_fn[0]) ret = XpmReadFileToPixmap(dpy, Root, weekday_xpm_fn, &weekday.pixmap, &weekday.mask, &weekday.attributes); else ret = XpmCreatePixmapFromData(dpy, Root, weekday_xpm, &weekday.pixmap, &weekday.mask, &weekday.attributes); if(ret != XpmSuccess) {nocolor("create weekday xpm", ERR_colorcells);exit(1);} if(week_elem_width==UNDEFINED) week_elem_width = weekday.attributes.width; if(week_elem_height==UNDEFINED) week_elem_height = weekday.attributes.height/7; } /* ---------------------------------------------------------------- */ if (beats_visible) { beats.attributes.closeness = 40000; /* Allow for "similar" colors */ beats.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions | XpmCloseness); if(beats_xpm_fn[0]) ret = XpmReadFileToPixmap(dpy, Root, beats_xpm_fn, &beats.pixmap, &beats.mask, &beats.attributes); else ret = XpmCreatePixmapFromData(dpy, Root, beats_xpm, &beats.pixmap, &beats.mask, &beats.attributes); if(ret != XpmSuccess) {nocolor("create beats xpm", ERR_colorcells);exit(1);} if(beats_elem_width==UNDEFINED) beats_elem_width = beats.attributes.width/12; if(beats_elem_height==UNDEFINED) beats_elem_height = beats.attributes.height; } }
VALUE subIconInit(int argc, VALUE *argv, VALUE self) { SubtlextIcon *i = NULL; Data_Get_Struct(self, SubtlextIcon, i); if(i) { VALUE data[3] = { Qnil }; rb_scan_args(argc, argv, "12", &data[0], &data[1], &data[2]); subSubtlextConnect(NULL); ///< Implicit open connection /* Find or create icon */ if(T_STRING == rb_type(data[0])) ///< Icon path { int hotx = 0, hoty = 0; char buf[100] = { 0 }; #ifdef HAVE_WORDEXP_H /* Expand tildes in path */ wordexp_t we; if(0 == wordexp(RSTRING_PTR(data[0]), &we, 0)) { snprintf(buf, sizeof(buf), "%s", we.we_wordv[0]); wordfree(&we); } else #endif /* HAVE_WORDEXP_H */ snprintf(buf, sizeof(buf), "%s", RSTRING_PTR(data[0])); /* Find file */ if(-1 == access(buf, R_OK)) { char *home = NULL; /* Combine paths */ if((home = getenv("XDG_DATA_HOME"))) { snprintf(buf, sizeof(buf), "%s/subtle/icons/%s", home, RSTRING_PTR(data[0])); } else { snprintf(buf, sizeof(buf), "%s/.local/share/subtle/icons/%s", getenv("HOME"), RSTRING_PTR(data[0])); } if(-1 == access(buf, R_OK)) rb_raise(rb_eStandardError, "Icon not found `%s'", RSTRING_PTR(data[0])); } /* Reading bitmap or pixmap icon file */ if(BitmapSuccess != XReadBitmapFile(display, DefaultRootWindow(display), buf, &i->width, &i->height, &i->pixmap, &hotx, &hoty)) { #ifdef HAVE_X11_XPM_H XpmAttributes attrs; /* We could define a color to use on transparent areas, but * this can be done on init only, so we just ignore it and * expect pixmaps to have no transparent areas at all */ /* Init attributes */ attrs.colormap = DefaultColormap(display, DefaultScreen(display)); attrs.depth = DefaultDepth(display, DefaultScreen(display)); attrs.visual = DefaultVisual(display, DefaultScreen(display)); attrs.valuemask = XpmColormap|XpmDepth|XpmVisual; if(XpmSuccess == XpmReadFileToPixmap(display, DefaultRootWindow(display), buf, &i->pixmap, NULL, &attrs)) { i->flags |= ICON_PIXMAP; i->width = attrs.width; i->height = attrs.height; } else #endif /* HAVE_X11_XPM_H */ { rb_raise(rb_eStandardError, "Malormed icon"); return Qnil; } } else i->flags |= ICON_BITMAP; } else if(FIXNUM_P(data[0]) && FIXNUM_P(data[1])) ///< Icon dimensions { int depth = 1; /* Create pixmap or bitmap */ if(Qtrue == data[2]) { i->flags |= ICON_PIXMAP; depth = XDefaultDepth(display, DefaultScreen(display)); } else i->flags |= ICON_BITMAP; /* Create empty pixmap */ i->width = FIX2INT(data[0]); i->height = FIX2INT(data[1]); i->pixmap = XCreatePixmap(display, DefaultRootWindow(display), i->width, i->height, depth); } else if(FIXNUM_P(data[0])) { XRectangle geom = { 0 }; i->flags |= (ICON_BITMAP|ICON_FOREIGN); i->pixmap = NUM2LONG(data[0]); subSharedPropertyGeometry(display, i->pixmap, &geom); i->width = geom.width; i->height = geom.height; } else rb_raise(rb_eArgError, "Unexpected value-types"); /* Update object */ rb_iv_set(i->instance, "@width", INT2FIX(i->width)); rb_iv_set(i->instance, "@height", INT2FIX(i->height)); rb_iv_set(i->instance, "@pixmap", LONG2NUM(i->pixmap)); XSync(display, False); ///< Sync all changes subSharedLogDebugSubtlext("new=icon, width=%03d, height=%03d\n", i->width, i->height); } return Qnil; } /* }}} */
int lockScreen(void) { XSetWindowAttributes attr, attr1, attr2; Pixmap shape, pic, lock, shp, bg_pic, bg_shp; int screen_number = 0; long win_mask = CWBackPixel | CWBorderPixel | CWOverrideRedirect; if (is_blocked()) return 0; set_blocked(1); x = 5; y = 35; (dsp) = XOpenDisplay(":0.0"); if ((dsp) == NULL) { write_log("Could not open Display 0:0\n"); return (-1); } dW = XDisplayWidth(dsp, screen_number); dH = XDisplayHeight(dsp, screen_number); root = XRootWindow(dsp, screen_number); /* If a extern XPM background file specified on the command line */ if (background_filename != NULL) { if (XpmReadFileToPixmap (dsp, root, background_filename, &bg_pic, &bg_shp, NULL) != XpmOpenFailed) win_mask = CWBackPixmap | CWBorderPixel | CWOverrideRedirect; } attr.background_pixel = 700; attr.background_pixmap = bg_pic; attr.border_pixel = 100; attr.override_redirect = True; (wnd1) = XCreateWindow(dsp, root, 0, 0, dW, dH, 0, CopyFromParent, CopyFromParent, CopyFromParent, win_mask, &attr); XMapRaised(dsp, wnd1); if (logo_filename != NULL) { XpmReadFileToPixmap(dsp, root, logo_filename, &pic, &shape, NULL); } attr1.background_pixmap = pic; logo = XCreateWindow(dsp, wnd1, dW - 150, 0, 150, 30, 0, CopyFromParent, CopyFromParent, CopyFromParent, CWBackPixmap, &attr1); XMapWindow(dsp, logo); logo2 = XCreateSimpleWindow(dsp, wnd1, 0, 0, dW - 150, 30, 0, 0, 300); XMapWindow(dsp, logo2); if (foreground_filename != NULL) { XpmReadFileToPixmap(dsp, root, foreground_filename, &lock, &shp, NULL); } attr2.background_pixmap = lock; wnd = XCreateWindow(dsp, wnd1, dW / 2 - 150, dH / 2 - 100, 300, 200, 0, CopyFromParent, CopyFromParent, CopyFromParent, CWBackPixmap, &attr2); //wnd = XCreateSimpleWindow(dsp, wnd1, x, y, 200, 200, 1, 0, 400); XMapWindow(dsp, wnd); XGrabPointer(dsp, wnd1, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); XGrabKeyboard(dsp, wnd1, False, GrabModeAsync, GrabModeAsync, CurrentTime); XSelectInput(dsp, wnd1, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ShiftMask | LockMask | ControlMask | Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask); write_log_fmt("locking screen\n"); return (0); }
// Pixmap caching utility void MotifUI::GetPixmaps(Widget w, char *name, Pixmap *pixmap, Pixmap *mask) { // Try to find pixmap in cache PixmapLookupList pixmaps = pixmap_table; int i; for (i = 0; i < n_pixmaps; i++, pixmaps++) if (!strcmp((**pixmaps).name, name)) { *pixmap = (**pixmaps).pixmap; if (mask) *mask = (**pixmaps).mask; return; } Pixmap _mask; char *s; SubstitutionRec subs[1]; char *bmPath; char *PIXMAP_DIR = "/usr/dt/appconfig/icons/%L/%B:" "/usr/dt/appconfig/icons/C/%B:" "/usr/include/X11/bitmaps/%B"; if (*name == '/') s = name; else { #ifdef NO_CDE if ((s = getenv("XBMLANGPATH")) && *s) #else if ((s = getenv("XMICONSEARCHPATH")) && *s) #endif { bmPath = new char [strlen(s) + strlen(PIXMAP_DIR) + 2]; sprintf(bmPath, "%s:%s", PIXMAP_DIR, s); } else bmPath = PIXMAP_DIR; subs[0].match = 'B'; subs[0].substitution = name; s = XtFindFile(bmPath, subs, XtNumber(subs), NULL); if (bmPath != PIXMAP_DIR) delete [] bmPath; } struct stat statbuf; if (!s || stat(s, &statbuf) < 0) { *pixmap = XmUNSPECIFIED_PIXMAP; if (mask) *mask = XmUNSPECIFIED_PIXMAP; return; } int len = strlen(s); if (!strcmp(s + len - 3, ".pm")) { XpmAttributes attributes; memset((char *)&attributes, 0, sizeof(XpmAttributes)); #ifdef NO_CDE XpmReadFileToPixmap(display, root, s, pixmap, &_mask, &attributes); #else _DtXpmReadFileToPixmap(display, root, s, pixmap, &_mask, &attributes); #endif if (_mask) FillBackground(w, *pixmap, _mask); #ifdef NO_CDE XpmFreeAttributes(&attributes); #else _DtXpmFreeAttributes(&attributes); #endif } else { if (UIClass() == MAIN_WINDOW) *pixmap = XmGetPixmapByDepth(XtScreen(w), s, white, black, depth); else *pixmap = XmGetPixmapByDepth(XtScreen(w), s, black, white, depth); char *s1 = new char [len + 3]; strcpy(s1, s); strcpy(s1 + len - 3, "_m.bm"); if (stat(s1, &statbuf) < 0) _mask = XmUNSPECIFIED_PIXMAP; else { _mask = XmGetPixmapByDepth(XtScreen(w), s1, white, black, 1); FillBackground(w, *pixmap, _mask); } delete [] s1; } if (mask) *mask = _mask; if (s != name) XtFree(s); // Add pixmap to table if (!(n_pixmaps % 8)) { pixmaps = new PixmapLookup [n_pixmaps + 8]; for (i = 0; i < n_pixmaps; i++) pixmaps[i] = pixmap_table[i]; for (i = n_pixmaps; i < n_pixmaps + 8; i++) pixmaps[i] = new PixmapLookupStruct; delete []pixmap_table; pixmap_table = pixmaps; } pixmap_table[n_pixmaps]->name = strdup(name); pixmap_table[n_pixmaps]->pixmap = *pixmap; pixmap_table[n_pixmaps]->mask = _mask; n_pixmaps++; }
/* EXTPROTO */ Pixmap rxvt_load_pixmap(rxvt_t *r, const char *file, long* pwidth, long* pheight) { char* f; int flen; #if defined(USE_JPEG) || defined(USE_PNG) long w = 0, h = 0; #endif XpmAttributes xpm_attr; Pixmap pixmap; UNSET_PIXMAP(pixmap); assert(file != NULL); if ((char) 0 == *file) { /* No file to load */ return None; } xpm_attr.closeness = 30000; xpm_attr.colormap = XCMAP; xpm_attr.visual = XVISUAL; xpm_attr.depth = XDEPTH; xpm_attr.valuemask = (XpmCloseness | XpmColormap | XpmVisual | XpmDepth | XpmSize | XpmReturnPixels); /* search environment variables here too */ if (NULL == (f = (char*) rxvt_File_find (file, ".xpm", r->h->rs[Rs_path])) #ifdef USE_JPEG && NULL == (f = (char*) rxvt_File_find (file, ".jpg", r->h->rs[Rs_path])) && NULL == (f = (char*) rxvt_File_find (file, ".jpeg", r->h->rs[Rs_path])) #endif #ifdef USE_PNG && NULL == (f = (char*) rxvt_File_find (file, ".png", r->h->rs[Rs_path])) #endif ) { char *p; /* semi-colon delimited */ if (NULL == (p = STRCHR(file, ';'))) p = STRCHR(file, '\0'); rxvt_msg (DBG_ERROR, DBG_PIXMAP, "couldn't load image file \"%.*s\"", (p - file), file); return None; } flen = STRLEN (f); #ifdef USE_JPEG if ((flen >= 4 && !STRNCASECMP (f+flen-4, ".jpg", 4)) || (flen >= 5 && !STRNCASECMP (f+flen-5, ".jpeg",5))) { GC gc = DefaultGC (r->Xdisplay, XSCREEN); if (!JpegReadFileToPixmap (r->Xdisplay, XROOT, gc, f, &pixmap, &w, &h)) { *pwidth = w; *pheight = h; } } else #endif #ifdef USE_PNG if (flen >= 4 && !STRNCASECMP (f+flen-4, ".png", 4)) { GC gc = DefaultGC (r->Xdisplay, XSCREEN); if (!PngReadFileToPixmap (r->Xdisplay, XROOT, gc, f, &pixmap, &w, &h)) { *pwidth = w; *pheight = h; } } else #endif #ifdef HAVE_LIBXPM if (!XpmReadFileToPixmap(r->Xdisplay, XROOT, f, &pixmap, NULL, &xpm_attr)) { *pwidth = xpm_attr.width; *pheight = xpm_attr.height; } #endif { /* empty to suppress compile error */ } rxvt_free(f); if (NOT_PIXMAP(pixmap)) { char *p; /* semi-colon delimited */ if ((p = STRCHR(file, ';')) == NULL) p = STRCHR(file, '\0'); rxvt_msg (DBG_ERROR, DBG_PIXMAP, "couldn't load image file \"%.*s\"", (p - file), file); } return (pixmap); }
JError JXImage::CreateFromXPM ( JXDisplay* display, const JCharacter* fileName, JXImage** image ) { #ifdef _J_HAS_XPM JXColormap* colormap = display->GetColormap(); Pixmap image_pixmap = None; Pixmap mask_pixmap = None; XpmAttributes attr; attr.valuemask = XpmVisual | XpmColormap | XpmDepth | XpmExactColors | XpmCloseness | XpmColorKey | XpmAllocCloseColors | XpmReturnAllocPixels; attr.visual = colormap->GetVisual(); attr.colormap = colormap->GetXColormap(); attr.depth = display->GetDepth(); attr.color_key = XPM_COLOR; attr.alloc_pixels = NULL; attr.nalloc_pixels = 0; attr.alloc_close_colors = kJTrue; // so we can free all resulting pixels attr.exactColors = 1; attr.closeness = 0; const int xpmErr = XpmReadFileToPixmap(*display, display->GetRootWindow(), const_cast<JCharacter*>(fileName), &image_pixmap, &mask_pixmap, &attr); if (xpmErr == XpmOpenFailed && JFileExists(fileName)) { return JAccessDenied(fileName); } else if (xpmErr == XpmOpenFailed) { return JDirEntryDoesNotExist(fileName); } else if (xpmErr == XpmFileInvalid) { return FileIsNotXPM(fileName); } else if (xpmErr == XpmNoMemory) { return JNoProcessMemory(); } else if (xpmErr == XpmColorFailed || xpmErr == XpmColorError) { if (image_pixmap != None) { XFreePixmap(*display, image_pixmap); } if (mask_pixmap != None) { XFreePixmap(*display, mask_pixmap); } if (attr.alloc_pixels != NULL) { XFreeColors(*display, attr.colormap, attr.alloc_pixels, attr.nalloc_pixels, 0); } XpmFreeAttributes(&attr); return TooManyColors(); } // create image and mask *image = new JXImage(display, image_pixmap); assert( *image != NULL ); XFreePixmap(*display, image_pixmap); if (mask_pixmap != None) { JXImageMask* mask = new JXImageMask(display, mask_pixmap); assert( mask != NULL ); (**image).SetMask(mask); XFreePixmap(*display, mask_pixmap); } // free pixels so X has usage count of 1 XFreeColors(*display, attr.colormap, attr.alloc_pixels, attr.nalloc_pixels, 0); // clean up XpmFreeAttributes(&attr); return JNoError(); #else return XPMNotAvailable(); #endif }
/* ARGSUSED */ static Boolean _XawCvtStringToPixmap(Display *dpy, XrmValuePtr args, Cardinal *nargs, XrmValuePtr from, XrmValuePtr to, XtPointer *data) { static Pixmap pixmap; Window win; XpmAttributes attr; XpmColorSymbol colors[1]; if (*nargs != 3) XtAppErrorMsg(XtDisplayToApplicationContext(dpy), "_XawCvtStringToPixmap", "wrongParameters", "XtToolkitError", "_XawCvtStringToPixmap needs screen, colormap, and background_pixel", (String *) NULL, (Cardinal *) NULL); if (strcmp(from->addr, "None") == 0) { pixmap = None; DONE(Pixmap, &pixmap); return (True); } if (strcmp(from->addr, "ParentRelative") == 0) { pixmap = ParentRelative; DONE(Pixmap, &pixmap); return (True); } win = RootWindowOfScreen(*((Screen **) args[0].addr)); attr.colormap = *((Colormap *) args[1].addr); attr.closeness = 32768; /* might help on 8-bpp displays? */ attr.valuemask = XpmColormap | XpmCloseness; colors[0].name = NULL; colors[0].value = "none"; colors[0].pixel = *((Pixel *) args[2].addr); attr.colorsymbols = colors; attr.numsymbols = 1; attr.valuemask |= XpmColorSymbols; if (XpmReadFileToPixmap(dpy, win, (String) from->addr, &pixmap, NULL, &attr) != XpmSuccess) { if ((pixmap = XmuLocateBitmapFile(*((Screen **) args[0].addr), (char *)from->addr, NULL, 0, NULL, NULL, NULL, NULL)) == None) { XtDisplayStringConversionWarning(dpy, (String) from->addr, XtRPixmap); return (False); } } if (to->addr == NULL) to->addr = (XtPointer) & pixmap; else { if (to->size < sizeof(Pixmap)) { to->size = sizeof(Pixmap); XtDisplayStringConversionWarning(dpy, (String) from->addr, XtRPixmap); return (False); } *((Pixmap *) to->addr) = pixmap; } to->size = sizeof(Pixmap); return (True); }
/* ARGSUSED */ static void Initialize ( Widget greq, Widget gnew, ArgList args, Cardinal *num_args) { LoginWidget w = (LoginWidget)gnew; XtGCMask valuemask, xvaluemask; XGCValues myXGCV; Arg position[2]; Position x, y; #ifdef USE_XINERAMA XineramaScreenInfo *screens; int s_num; #endif #ifdef XPM myXGCV.foreground = w->login.hipixel; myXGCV.background = w->core.background_pixel; valuemask = GCForeground | GCBackground; w->login.hiGC = XtGetGC(gnew, valuemask, &myXGCV); myXGCV.foreground = w->login.shdpixel; myXGCV.background = w->core.background_pixel; valuemask = GCForeground | GCBackground; w->login.shdGC = XtGetGC(gnew, valuemask, &myXGCV); #endif /* XPM */ myXGCV.foreground = w->login.textpixel; myXGCV.background = w->core.background_pixel; valuemask = GCForeground | GCBackground; if (w->login.font) { myXGCV.font = w->login.font->fid; valuemask |= GCFont; } w->login.textGC = XtGetGC(gnew, valuemask, &myXGCV); myXGCV.foreground = w->core.background_pixel; w->login.bgGC = XtGetGC(gnew, valuemask, &myXGCV); myXGCV.foreground = w->login.textpixel ^ w->core.background_pixel; myXGCV.function = GXxor; xvaluemask = valuemask | GCFunction; w->login.xorGC = XtGetGC (gnew, xvaluemask, &myXGCV); /* * Note that the second argument is a GCid -- QueryFont accepts a GCid and * returns the curently contained font. */ if (w->login.font == NULL) w->login.font = XQueryFont (XtDisplay (w), XGContextFromGC (XDefaultGCOfScreen (XtScreen (w)))); xvaluemask = valuemask; if (w->login.promptFont == NULL) w->login.promptFont = w->login.font; else xvaluemask |= GCFont; myXGCV.foreground = w->login.promptpixel; myXGCV.font = w->login.promptFont->fid; w->login.promptGC = XtGetGC (gnew, xvaluemask, &myXGCV); xvaluemask = valuemask; if (w->login.greetFont == NULL) w->login.greetFont = w->login.font; else xvaluemask |= GCFont; myXGCV.foreground = w->login.greetpixel; myXGCV.font = w->login.greetFont->fid; w->login.greetGC = XtGetGC (gnew, xvaluemask, &myXGCV); xvaluemask = valuemask; if (w->login.failFont == NULL) w->login.failFont = w->login.font; else xvaluemask |= GCFont; myXGCV.foreground = w->login.failpixel; myXGCV.font = w->login.failFont->fid; w->login.failGC = XtGetGC (gnew, xvaluemask, &myXGCV); #ifdef XPM w->login.logoValid = False; if (NULL != w->login.logoFileName) { XpmAttributes myAttributes = { 0 }; Window tmpWindow = { 0 }; struct stat myBuffer = { 0 }; unsigned int myPixmapDepth = 0; if (0 != stat(w->login.logoFileName, &myBuffer)) { LogError("Unable to stat() pixmap file %s\n", w->login.logoFileName); w->login.logoValid = False; goto SkipXpmLoad; } else myAttributes.valuemask |= XpmReturnPixels; myAttributes.valuemask |= XpmReturnExtensions; XpmReadFileToPixmap(XtDisplay(w), /* display */ RootWindowOfScreen(XtScreen(w)), /* window */ w->login.logoFileName, /* XPM filename */ &(w->login.logoPixmap), /* pixmap */ &(w->login.logoMask), /* pixmap mask */ &myAttributes); /* XPM attributes */ w->login.logoValid = True; XGetGeometry(XtDisplay(w), w->login.logoPixmap, &tmpWindow, &(w->login.logoX), &(w->login.logoY), &(w->login.logoWidth), &(w->login.logoHeight), &(w->login.logoBorderWidth), &myPixmapDepth); } else { w->login.logoX = 0; w->login.logoY = 0; w->login.logoWidth = 0; w->login.logoHeight = 0; w->login.logoBorderWidth = 0; } SkipXpmLoad: #endif /* XPM */ w->login.data.name[0] = '\0'; w->login.data.passwd[0] = '\0'; w->login.state = GET_NAME; w->login.cursor = 0; w->login.failUp = 0; if (w->core.width == 0) w->core.width = max (GREET_W(w), FAIL_W(w)) + PAD_X(w); if (w->core.height == 0) { int fy = FAIL_Y(w); int pady = PAD_Y(w); #ifndef XPM w->core.height = fy + pady; /* for stupid compilers */ #else /* w->core.height = fy + pady; * for stupid compilers */ w->core.height = max(fy + pady, (w->login.logoHeight + (2*w->login.logoPadding)) + pady); #endif /* XPM */ } #ifdef USE_XINERAMA if ( XineramaIsActive(XtDisplay(w)) && (screens = XineramaQueryScreens(XtDisplay(w), &s_num)) != NULL ) { if ((x = w->core.x) == -1) x = screens[0].x_org + (int)(screens[0].width - w->core.width) / 2; if ((y = w->core.y) == -1) y = screens[0].y_org + (int)(screens[0].height - w->core.height) / 3; XFree(screens); } else #endif { if ((x = w->core.x) == -1) x = (int)(XWidthOfScreen (XtScreen (w)) - w->core.width) / 2; if ((y = w->core.y) == -1) y = (int)(XHeightOfScreen (XtScreen (w)) - w->core.height) / 3; } XtSetArg (position[0], XtNx, x); XtSetArg (position[1], XtNy, y); XtSetValues (XtParent (w), position, (Cardinal) 2); }
static Boolean create_pixmap(Widget parent, int iconidx, Pixmap *sen, Pixmap *insen) { static Boolean first_time = True; static Window rootWindow; static XpmColorSymbol color[5] = { {"none", "none", 0}, {"iconColor1", NULL, 0}, {"bottomShadowColor", NULL, 0}, {"topShadowColor", NULL, 0}, {"selectColor", NULL, 0} }; static int screenNum; static Pixmap tools_map; static Pixmap tools_mask; static Pixmap shade_map; static Pixmap shade_mask; int status = 0; XpmAttributes attr; Pixmap map; Pixmap mask; static String pixmap_file_path = NULL; /* note: never free()d */ ASSERT(iconidx >= 0, "index must be positive"); if (first_time) { /* FIXME: We use a dummy window here to get the correct depth/visual for the pixmap creation (cant use globals.widgets.top_level since it's not realized yet and realizing it now would result in wrong dimensions) ... */ Widget dummy = XtVaAppCreateShell("xdvi", "Xdvi", transientShellWidgetClass, DISP, XtNdepth, G_depth, XtNvisual, G_visual, XtNcolormap, G_colormap, XtNmappedWhenManaged, False, NULL); XtRealizeWidget(dummy); /* note: doesn't pop it up */ rootWindow = XtWindow(dummy); screenNum = DefaultScreen(XtDisplay(globals.widgets.top_level)); ASSERT(rootWindow != 0, ""); XtVaGetValues(parent, XmNbackground, &color[BACKGROUND].pixel, XmNforeground, &color[FOREGROUND].pixel, XmNbottomShadowColor, &color[BOTTOM_SHADOW].pixel, XmNtopShadowColor, &color[TOP_SHADOW].pixel, XmNhighlightColor, &color[HIGHLIGHT].pixel, NULL); /* try to locate the XPM file with the toolbar pixmaps */ pixmap_file_path = XtResolvePathname(DISP, "pixmaps", resource.toolbar_pixmap_file, (String)NULL, /* suffix */ (String)NULL, /* use default path */ (Substitution)NULL, /* substitutions */ 0, /* number of substitutions */ (XtFilePredicate)NULL); /* return True iff file exists */ TRACE_GUI((stderr, "pixmap file search via XtResolvePathname: %s => %s", resource.toolbar_pixmap_file, pixmap_file_path ? (char*)pixmap_file_path : "<NULL>")); if (pixmap_file_path == NULL) { pixmap_file_path = (String)kpse_find_file(resource.toolbar_pixmap_file, kpse_program_text_format, 0); TRACE_GUI((stderr, "pixmap file search via kpse_find_file: %s => %s", resource.toolbar_pixmap_file, pixmap_file_path ? (char*)pixmap_file_path : "<NULL>")); if (pixmap_file_path == NULL) { TRACE_GUI((stderr, "No installed toolbar pixmap found, using built-in pixmap.")); } } } /* Setup the color subsititution table */ attr.valuemask = XpmColorSymbols | XpmCloseness | XpmColormap | XpmDepth | XpmVisual; attr.closeness = 65535; /* accuracy isn't crucial */ attr.colorsymbols = color; attr.numsymbols = XtNumber(color); attr.visual = G_visual; attr.colormap = G_colormap; attr.depth = G_depth; /* Create the "sensitive" pixmap */ if (!tools_map) { if (pixmap_file_path != NULL) { status = XpmReadFileToPixmap(XtDisplay(globals.widgets.top_level), rootWindow, pixmap_file_path, &tools_map, &tools_mask, &attr); } else { status = XpmCreatePixmapFromData(XtDisplay(globals.widgets.top_level), rootWindow, (char **)toolbar_xpm, &tools_map, &tools_mask, &attr); } } else status = XpmSuccess; map = tools_map; mask = tools_mask; if (status == XpmSuccess) { static Pixmap tmp_mask; static GC gc; if (first_time) { tmp_mask = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT, 1); gc = XCreateGC(XtDisplay(globals.widgets.top_level), tmp_mask, 0, NULL); } XCopyArea(XtDisplay(globals.widgets.top_level), mask, tmp_mask, gc, iconidx * PIXMAP_WIDTH, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0); mask = tmp_mask; } else { /* something went wrong */ popup_message(globals.widgets.top_level, MSG_ERR, "Something's wrong with your XPM file - " "try to load it into an image editor and fix the problem.", "Xpm error: %s - switching toolbar off.", XpmGetErrorString(status)); sen = insen = NULL; resource.expert_mode ^= XPRT_SHOW_TOOLBAR; return False; } XpmFreeAttributes(&attr); if (map != 0) { static GC back_gc, bots_gc; if (first_time) { XGCValues gcvalues; gcvalues.foreground = color[BACKGROUND].pixel; back_gc = XCreateGC(XtDisplay(globals.widgets.top_level), rootWindow, GCForeground, &gcvalues); gcvalues.foreground = color[BOTTOM_SHADOW].pixel; bots_gc = XCreateGC(XtDisplay(globals.widgets.top_level), rootWindow, GCForeground, &gcvalues); } /* Need to create new Pixmaps with the mask applied. */ XSetClipMask(XtDisplay(globals.widgets.top_level), bots_gc, mask); /* Create the "sensitive" pixmap. */ *sen = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT, G_depth); XFillRectangle(XtDisplay(globals.widgets.top_level), *sen, back_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT); if (iconidx != -1) XCopyArea(XtDisplay(globals.widgets.top_level), map, *sen, bots_gc, iconidx * PIXMAP_WIDTH, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0); else XCopyArea(XtDisplay(globals.widgets.top_level), map, *sen, bots_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0); if (iconidx == -1) XFreePixmap(XtDisplay(globals.widgets.top_level), map); /* Create the "insensitive" pixmap. */ if (insen != NULL) { Pixmap map; Pixmap mask; attr.valuemask = XpmColorSymbols | XpmCloseness | XpmColorKey | XpmColormap | XpmDepth | XpmVisual; attr.closeness = 65535; /* accuracy isn't crucial */ attr.colorsymbols = color; attr.numsymbols = XtNumber(color); attr.color_key = XPM_MONO; attr.visual = G_visual; attr.colormap = G_colormap; attr.depth = G_depth; if (!shade_map) { if (pixmap_file_path != NULL) { status = XpmReadFileToPixmap(XtDisplay(globals.widgets.top_level), rootWindow, pixmap_file_path, &shade_map, &shade_mask, &attr); } else { status = XpmCreatePixmapFromData(XtDisplay(globals.widgets.top_level), rootWindow, (char **)toolbar_xpm, &shade_map, &shade_mask, &attr); } } else status = XpmSuccess; map = shade_map; mask = shade_mask; if (status == XpmSuccess) { static Pixmap tmp_mask; static GC gc; if (first_time) { tmp_mask = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT, 1); gc = XCreateGC(XtDisplay(globals.widgets.top_level), tmp_mask, 0, NULL); } XCopyArea(XtDisplay(globals.widgets.top_level), mask, tmp_mask, gc, iconidx * PIXMAP_WIDTH, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0); mask = tmp_mask; } else { /* something went wrong */ popup_message(globals.widgets.top_level, MSG_ERR, "Something's wrong with your XPM file - " "try to load it into an image editor and fix the problem.", "Xpm error: %s - switching toolbar off.", XpmGetErrorString(status)); sen = insen = NULL; resource.expert_mode ^= XPRT_SHOW_TOOLBAR; return False; } if (mask != 0) { static GC tops_gc; if (first_time) { XGCValues gcvalues; gcvalues.foreground = color[TOP_SHADOW].pixel; tops_gc = XCreateGC(XtDisplay(globals.widgets.top_level), rootWindow, GCForeground, &gcvalues); } /* Need to create new Pixmaps with the mask applied. */ XSetClipMask(XtDisplay(globals.widgets.top_level), bots_gc, mask); XSetClipMask(XtDisplay(globals.widgets.top_level), tops_gc, mask); XSetClipOrigin(XtDisplay(globals.widgets.top_level), tops_gc, 1, 1); *insen = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT, G_depth); XFillRectangle(XtDisplay(globals.widgets.top_level), *insen, back_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT); XFillRectangle(XtDisplay(globals.widgets.top_level), *insen, tops_gc, 1, 1, PIXMAP_WIDTH - 1, PIXMAP_HEIGHT - 1); XFillRectangle(XtDisplay(globals.widgets.top_level), *insen, bots_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT); if (iconidx == -1) XFreePixmap(XtDisplay(globals.widgets.top_level), map); } XpmFreeAttributes(&attr); } } first_time = False; return True; }
char * parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { /* bitmaps */ unsigned int bm_w, bm_h; int bm_xh, bm_yh; /* rectangles, cirlcles*/ int rectw, recth, rectx, recty; /* positioning */ int n_posx, n_posy, set_posy=0; int px=0, py=0, opx=0; int i, next_pos=0, j=0, h=0, tw=0; /* buffer pos */ const char *linep=NULL; /* fonts */ int font_was_set=0; /* position */ int pos_is_fixed = 0; /* block alignment */ int block_align = -1; int block_width = -1; /* clickable area y tracking */ int max_y=-1; /* temp buffers */ char lbuf[MAX_LINE_LEN], *rbuf = NULL; /* parser state */ int t=-1, nobg=0; char *tval=NULL; /* X stuff */ long lastfg = dzen.norm[ColFG], lastbg = dzen.norm[ColBG]; Fnt *cur_fnt = NULL; #ifndef DZEN_XFT XGCValues gcv; #endif Drawable pm=0, bm; #ifdef DZEN_XPM int free_xpm_attrib = 0; Pixmap xpm_pm; XpmAttributes xpma; XpmColorSymbol xpms; #endif #ifdef DZEN_XFT XftDraw *xftd=NULL; XftColor xftc; char *xftcs; int xftcs_f=0; char *xftcs_bg; int xftcs_bgf=0; xftcs = (char *)dzen.fg; xftcs_bg = (char *)dzen.bg; #endif /* icon cache */ int ip; /* parse line and return the text without control commands */ if(nodraw) { rbuf = emalloc(MAX_LINE_LEN); rbuf[0] = '\0'; if( (lnr + dzen.slave_win.first_line_vis) >= dzen.slave_win.tcnt) line = NULL; else line = dzen.slave_win.tbuf[dzen.slave_win.first_line_vis+lnr]; } /* parse line and render text */ else { h = dzen.font.height; py = (dzen.line_height - h) / 2; xorig[LNR2WINDOW(lnr)] = 0; if(lnr != -1) { pm = XCreatePixmap(dzen.dpy, RootWindow(dzen.dpy, DefaultScreen(dzen.dpy)), dzen.slave_win.width, dzen.line_height, DefaultDepth(dzen.dpy, dzen.screen)); } else { pm = XCreatePixmap(dzen.dpy, RootWindow(dzen.dpy, DefaultScreen(dzen.dpy)), dzen.title_win.width, dzen.line_height, DefaultDepth(dzen.dpy, dzen.screen)); } #ifdef DZEN_XFT xftd = XftDrawCreate(dzen.dpy, pm, DefaultVisual(dzen.dpy, dzen.screen), DefaultColormap(dzen.dpy, dzen.screen)); #endif if(!reverse) { XSetForeground(dzen.dpy, dzen.tgc, dzen.norm[ColBG]); #ifdef DZEN_XPM xpms.pixel = dzen.norm[ColBG]; #endif #ifdef DZEN_XFT xftcs_bg = (char *)dzen.bg; xftcs_bgf = 0; #endif } else { XSetForeground(dzen.dpy, dzen.tgc, dzen.norm[ColFG]); #ifdef DZEN_XPM xpms.pixel = dzen.norm[ColFG]; #endif } XFillRectangle(dzen.dpy, pm, dzen.tgc, 0, 0, dzen.w, dzen.h); if(!reverse) { XSetForeground(dzen.dpy, dzen.tgc, dzen.norm[ColFG]); } else { XSetForeground(dzen.dpy, dzen.tgc, dzen.norm[ColBG]); } #ifdef DZEN_XPM xpms.name = NULL; xpms.value = (char *)"none"; xpma.colormap = DefaultColormap(dzen.dpy, dzen.screen); xpma.depth = DefaultDepth(dzen.dpy, dzen.screen); xpma.visual = DefaultVisual(dzen.dpy, dzen.screen); xpma.colorsymbols = &xpms; xpma.numsymbols = 1; xpma.valuemask = XpmColormap|XpmDepth|XpmVisual|XpmColorSymbols; #endif #ifndef DZEN_XFT if(!dzen.font.set){ gcv.font = dzen.font.xfont->fid; XChangeGC(dzen.dpy, dzen.tgc, GCFont, &gcv); } #endif cur_fnt = &dzen.font; if( lnr != -1 && (lnr + dzen.slave_win.first_line_vis >= dzen.slave_win.tcnt)) { XCopyArea(dzen.dpy, pm, dzen.slave_win.drawable[lnr], dzen.gc, 0, 0, px, dzen.line_height, xorig[LNR2WINDOW(lnr)], 0); XFreePixmap(dzen.dpy, pm); return NULL; } } linep = line; while(1) { if(*linep == ESC_CHAR || *linep == '\0') { lbuf[j] = '\0'; /* clear _lock_x at EOL so final width is correct */ if(*linep=='\0') pos_is_fixed=0; if(nodraw) { strcat(rbuf, lbuf); } else { if(t != -1 && tval) { switch(t) { case icon: if(MAX_ICON_CACHE && (ip=search_icon_cache(tval)) != -1) { int y; XCopyArea(dzen.dpy, icons[ip].p, pm, dzen.tgc, 0, 0, icons[ip].w, icons[ip].h, px, y=(set_posy ? py : (dzen.line_height >= (signed)icons[ip].h ? (dzen.line_height - icons[ip].h)/2 : 0))); px += !pos_is_fixed ? icons[ip].w : 0; max_y = MAX(max_y, y+icons[ip].h); } else { int y; if(XReadBitmapFile(dzen.dpy, pm, tval, &bm_w, &bm_h, &bm, &bm_xh, &bm_yh) == BitmapSuccess && (h/2 + px + (signed)bm_w < dzen.w)) { setcolor(&pm, px, bm_w, lastfg, lastbg, reverse, nobg); XCopyPlane(dzen.dpy, bm, pm, dzen.tgc, 0, 0, bm_w, bm_h, px, y=(set_posy ? py : (dzen.line_height >= (int)bm_h ? (dzen.line_height - (int)bm_h)/2 : 0)), 1); XFreePixmap(dzen.dpy, bm); px += !pos_is_fixed ? bm_w : 0; max_y = MAX(max_y, y+bm_h); } #ifdef DZEN_XPM else if(XpmReadFileToPixmap(dzen.dpy, dzen.title_win.win, tval, &xpm_pm, NULL, &xpma) == XpmSuccess) { setcolor(&pm, px, xpma.width, lastfg, lastbg, reverse, nobg); if(MAX_ICON_CACHE) cache_icon(tval, xpm_pm, xpma.width, xpma.height); XCopyArea(dzen.dpy, xpm_pm, pm, dzen.tgc, 0, 0, xpma.width, xpma.height, px, y=(set_posy ? py : (dzen.line_height >= (int)xpma.height ? (dzen.line_height - (int)xpma.height)/2 : 0))); px += !pos_is_fixed ? xpma.width : 0; max_y = MAX(max_y, y+xpma.height); /* freed by cache_icon() */ //XFreePixmap(dzen.dpy, xpm_pm); free_xpm_attrib = 1; } #endif } break; case rect: get_rect_vals(tval, &rectw, &recth, &rectx, &recty); recth = recth > dzen.line_height ? dzen.line_height : recth; if(set_posy) py += recty; recty = recty == 0 ? (dzen.line_height - recth)/2 : (dzen.line_height - recth)/2 + recty; px += !pos_is_fixed ? rectx : 0; setcolor(&pm, px, rectw, lastfg, lastbg, reverse, nobg); XFillRectangle(dzen.dpy, pm, dzen.tgc, px, set_posy ? py : ((int)recty < 0 ? dzen.line_height + recty : recty), rectw, recth); px += !pos_is_fixed ? rectw : 0; break; case recto: get_rect_vals(tval, &rectw, &recth, &rectx, &recty); if (!rectw) break; recth = recth > dzen.line_height ? dzen.line_height-2 : recth-1; if(set_posy) py += recty; recty = recty == 0 ? (dzen.line_height - recth)/2 : (dzen.line_height - recth)/2 + recty; px = (rectx == 0) ? px : rectx+px; /* prevent from stairs effect when rounding recty */ if (!((dzen.line_height - recth) % 2)) recty--; setcolor(&pm, px, rectw, lastfg, lastbg, reverse, nobg); XDrawRectangle(dzen.dpy, pm, dzen.tgc, px, set_posy ? py : ((int)recty<0 ? dzen.line_height + recty : recty), rectw-1, recth); px += !pos_is_fixed ? rectw : 0; break; case circle: rectx = get_circle_vals(tval, &rectw, &recth); setcolor(&pm, px, rectw, lastfg, lastbg, reverse, nobg); XFillArc(dzen.dpy, pm, dzen.tgc, px, set_posy ? py :(dzen.line_height - rectw)/2, rectw, rectw, 90*64, rectx>1?recth*64:64*360); px += !pos_is_fixed ? rectw : 0; break; case circleo: rectx = get_circle_vals(tval, &rectw, &recth); setcolor(&pm, px, rectw, lastfg, lastbg, reverse, nobg); XDrawArc(dzen.dpy, pm, dzen.tgc, px, set_posy ? py : (dzen.line_height - rectw)/2, rectw, rectw, 90*64, rectx>1?recth*64:64*360); px += !pos_is_fixed ? rectw : 0; break; case pos: if(tval[0]) { int r=0; r = get_pos_vals(tval, &n_posx, &n_posy); if( (r == 1 && !set_posy)) set_posy=0; else if (r == 5) { switch(n_posx) { case LOCK_X: pos_is_fixed = 1; break; case UNLOCK_X: pos_is_fixed = 0; break; case LEFT: px = 0; break; case RIGHT: px = dzen.w; break; case CENTER: px = dzen.w/2; break; case BOTTOM: set_posy = 1; py = dzen.line_height; break; case TOP: set_posy = 1; py = 0; break; } } else set_posy=1; if(r != 2) px = px+n_posx<0? 0 : px + n_posx; if(r != 1) py += n_posy; } else { set_posy = 0; py = (dzen.line_height - dzen.font.height) / 2; } break; case abspos: if(tval[0]) { int r=0; if( (r=get_pos_vals(tval, &n_posx, &n_posy)) == 1 && !set_posy) set_posy=0; else set_posy=1; n_posx = n_posx < 0 ? n_posx*-1 : n_posx; if(r != 2) px = n_posx; if(r != 1) py = n_posy; } else { set_posy = 0; py = (dzen.line_height - dzen.font.height) / 2; } break; case ibg: nobg = atoi(tval); break; case bg: lastbg = tval[0] ? (unsigned)getcolor(tval) : dzen.norm[ColBG]; #ifdef DZEN_XFT if(xftcs_bgf) free(xftcs_bg); if(tval[0]) { xftcs_bg = estrdup(tval); xftcs_bgf = 1; } else { xftcs_bg = (char *)dzen.bg; xftcs_bgf = 0; } #endif break; case fg: lastfg = tval[0] ? (unsigned)getcolor(tval) : dzen.norm[ColFG]; XSetForeground(dzen.dpy, dzen.tgc, lastfg); #ifdef DZEN_XFT if(tval[0]) { xftcs = estrdup(tval); xftcs_f = 1; } else { xftcs = (char *)dzen.fg; xftcs_f = 0; } #endif break; case fn: if(tval[0]) { #ifndef DZEN_XFT if(!strncmp(tval, "dfnt", 4)) { cur_fnt = &(dzen.fnpl[atoi(tval+4)]); if(!cur_fnt->set) { gcv.font = cur_fnt->xfont->fid; XChangeGC(dzen.dpy, dzen.tgc, GCFont, &gcv); } } else #endif setfont(tval); } else { cur_fnt = &dzen.font; #ifndef DZEN_XFT if(!cur_fnt->set){ gcv.font = cur_fnt->xfont->fid; XChangeGC(dzen.dpy, dzen.tgc, GCFont, &gcv); } #else setfont(dzen.fnt ? dzen.fnt : FONT); #endif } py = set_posy ? py : (dzen.line_height - cur_fnt->height) / 2; font_was_set = 1; break; case ca: { sens_w *w = &window_sens[LNR2WINDOW(lnr)]; if(tval[0]) { click_a *area = &((*w).sens_areas[(*w).sens_areas_cnt]); if((*w).sens_areas_cnt < MAX_CLICKABLE_AREAS) { get_sens_area(tval, &(*area).button, LNR2WINDOW(lnr)*MAX_CLICKABLE_AREAS+(*w).sens_areas_cnt); (*area).start_x = px; (*area).start_y = py; (*area).end_y = py; max_y = py; (*area).active = 0; if(lnr == -1) { (*area).win = dzen.title_win.win; } else { (*area).win = dzen.slave_win.line[lnr]; } (*w).sens_areas_cnt++; } } else { //find most recent unclosed area for(i = (*w).sens_areas_cnt - 1; i >= 0; i--) if(!(*w).sens_areas[i].active) break; if(i >= 0 && i < MAX_CLICKABLE_AREAS) { (*w).sens_areas[i].end_x = px; (*w).sens_areas[i].end_y = max_y; (*w).sens_areas[i].active = 1; } } } break; case ba: if(tval[0]) get_block_align_vals(tval, &block_align, &block_width); else block_align=block_width=-1; break; } free(tval); } /* check if text is longer than window's width */ tw = textnw(cur_fnt, lbuf, strlen(lbuf)); while((((tw + px) > (dzen.w)) || (block_align!=-1 && tw>block_width)) && j>=0) { lbuf[--j] = '\0'; tw = textnw(cur_fnt, lbuf, strlen(lbuf)); } opx = px; /* draw background for block */ if(block_align!=-1 && !nobg) { setcolor(&pm, px, rectw, lastbg, lastbg, 0, nobg); XFillRectangle(dzen.dpy, pm, dzen.tgc, px, 0, block_width, dzen.line_height); } if(block_align==ALIGNRIGHT) px += (block_width - tw); else if(block_align==ALIGNCENTER) px += (block_width/2) - (tw/2); if(!nobg) setcolor(&pm, px, tw, lastfg, lastbg, reverse, nobg); #ifndef DZEN_XFT if(cur_fnt->set) XmbDrawString(dzen.dpy, pm, cur_fnt->set, dzen.tgc, px, py + cur_fnt->ascent, lbuf, strlen(lbuf)); else XDrawString(dzen.dpy, pm, dzen.tgc, px, py+dzen.font.ascent, lbuf, strlen(lbuf)); #else if(reverse) { XftColorAllocName(dzen.dpy, DefaultVisual(dzen.dpy, dzen.screen), DefaultColormap(dzen.dpy, dzen.screen), xftcs_bg, &xftc); } else { XftColorAllocName(dzen.dpy, DefaultVisual(dzen.dpy, dzen.screen), DefaultColormap(dzen.dpy, dzen.screen), xftcs, &xftc); } XftDrawStringUtf8(xftd, &xftc, cur_fnt->xftfont, px, py + dzen.font.xftfont->ascent, (const FcChar8 *)lbuf, strlen(lbuf)); if(xftcs_f) { free(xftcs); xftcs_f = 0; } if(xftcs_bgf) { free(xftcs_bg); xftcs_bgf = 0; } #endif max_y = MAX(max_y, py+dzen.font.height); if(block_align==-1) { if(!pos_is_fixed || *linep =='\0') px += tw; } else { if(pos_is_fixed) px = opx; else px = opx+block_width; } block_align=block_width=-1; } if(*linep=='\0') break; j=0; t=-1; tval=NULL; next_pos = get_token(linep, &t, &tval); linep += next_pos; /* ^^ escapes */ if(next_pos == 0) lbuf[j++] = *linep++; } else lbuf[j++] = *linep; linep++; } if(!nodraw) { /* expand/shrink dynamically */ if(dzen.title_win.expand && lnr == -1){ i = px; switch(dzen.title_win.expand) { case left: /* grow left end */ otx = dzen.title_win.x_right_corner - i > dzen.title_win.x ? dzen.title_win.x_right_corner - i : dzen.title_win.x; XMoveResizeWindow(dzen.dpy, dzen.title_win.win, otx, dzen.title_win.y, px, dzen.line_height); break; case right: XResizeWindow(dzen.dpy, dzen.title_win.win, px, dzen.line_height); break; } } else { if(align == ALIGNLEFT) xorig[LNR2WINDOW(lnr)] = 0; if(align == ALIGNCENTER) { xorig[LNR2WINDOW(lnr)] = (lnr != -1) ? (dzen.slave_win.width - px)/2 : (dzen.title_win.width - px)/2; } else if(align == ALIGNRIGHT) { xorig[LNR2WINDOW(lnr)] = (lnr != -1) ? (dzen.slave_win.width - px) : (dzen.title_win.width - px); } } if(lnr != -1) { XCopyArea(dzen.dpy, pm, dzen.slave_win.drawable[lnr], dzen.gc, 0, 0, dzen.w, dzen.line_height, xorig[LNR2WINDOW(lnr)], 0); } else { XCopyArea(dzen.dpy, pm, dzen.title_win.drawable, dzen.gc, 0, 0, dzen.w, dzen.line_height, xorig[LNR2WINDOW(lnr)], 0); } XFreePixmap(dzen.dpy, pm); /* reset font to default */ if(font_was_set) setfont(dzen.fnt ? dzen.fnt : FONT); #ifdef DZEN_XPM if(free_xpm_attrib) { XFreeColors(dzen.dpy, xpma.colormap, xpma.pixels, xpma.npixels, xpma.depth); XpmFreeAttributes(&xpma); } #endif #ifdef DZEN_XFT XftDrawDestroy(xftd); #endif } return nodraw ? rbuf : NULL; }
short WPwcic( Window px_id, short x, short y, short bw, char *fnam, short cb, short cf, WPICON **outptr) /* Create WPICON. * * In: px_id = Parent window X-id. * x = X-position. * y = Y-position. * fnam = Pixmap file. * cb = Not used. * cf = Not used. * * Ut: *outptr = Ptr to a WPICON. * * Felkod: WP1212 = Can't load pixmap file %s * WP1292 = Can't malloc() * WP1712 = XPM error code = %s * * (C)microform ab 13/1/94 J. Kjellander * * 2007-06-17 Xpm, J.Kjellander * ********************************************************/ { char errbuf[V3STRLEN]; XSetWindowAttributes xwina; unsigned long xwinm; unsigned int dx,dy; int status; Window xwin_id; Pixmap icon_pixmap,icon_mask; XGCValues values; XpmAttributes attributes; WPICON *icoptr; /* ***Read the xpm-file and create a pixmap. Set attributes to XpmSize so ***that the size of the icon is returned. ***XpmColorError = 1 ***XpmSuccess = 0 ***XpmOpenFailed = -1 ***XpmFileInvalid = -2 ***XpmNoMemory = -3 ***XpmColorFailed = -4 */ attributes.valuemask = XpmSize; status = XpmReadFileToPixmap(xdisp,px_id,fnam,&icon_pixmap,&icon_mask,&attributes); if ( status != XpmSuccess ) { sprintf(errbuf,"%d",status); erpush("WP1712",errbuf); return(erpush("WP1212",fnam)); } dx = attributes.width; dy = attributes.height; /* ***Create the X window. */ xwina.background_pixel = WPgcol(cb); xwina.border_pixel = WPgcol(WP_BGND2); xwina.override_redirect = True; xwina.save_under = False; xwinm = ( CWBackPixel | CWBorderPixel | CWOverrideRedirect | CWSaveUnder ); if ( bw > 0 ) { dx += 2*bw + 2; dy += 2*bw + 2; } xwin_id = XCreateWindow(xdisp,px_id,x,y,dx,dy,bw, DefaultDepth(xdisp,xscr), InputOutput,CopyFromParent,xwinm,&xwina); /* ***Input events. */ if ( bw > 0 ) XSelectInput(xdisp,xwin_id,ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask); /* ***Create a WPICON. */ if ( (icoptr=(WPICON *)v3mall(sizeof(WPICON),"WPwcic")) == NULL ) return(erpush("WP1292",fnam)); icoptr->id.w_id = (wpw_id)NULL; icoptr->id.p_id = (wpw_id)NULL; icoptr->id.x_id = xwin_id; icoptr->geo.x = x; icoptr->geo.y = y; icoptr->geo.dx = (short)dx; icoptr->geo.dy = (short)dy; icoptr->geo.bw = bw; icoptr->pixmap = icon_pixmap; icoptr->mask = icon_mask; icoptr->tt_str[0] = '\0'; /* ***Set up a private GC for this icon. */ icoptr->gc = XCreateGC(xdisp,icoptr->id.x_id,0,&values); XSetClipMask(xdisp,icoptr->gc,icoptr->mask); *outptr = icoptr; /* ***The end. */ return(0); }
Icon *ReadIcon( char *fn, Icon *icon, Bool err ) { XWindowAttributes root_attr; XpmAttributes attr; int x, y, xhot, yhot; Pixmap bitmap; Icon *newicon; char *path; if( icon==NULL ) newicon = (Icon *)calloc( 1, sizeof(Icon) ); else newicon = icon; if((path = LookUpFiles( Scr.IconPath, fn, R_OK ))==NULL ){ if( err ) DrawErrMsgOnMenu( "Can't Find file ", fn ); return NULL; } XGetWindowAttributes(dpy,Scr.Root,&root_attr); attr.colormap = root_attr.colormap; attr.closeness = 40000; /* Allow for "similar" colors */ attr.valuemask = XpmSize | XpmReturnPixels | XpmColormap | XpmCloseness; if( XpmReadFileToPixmap( dpy, Scr.Root, path, &newicon->icon, &newicon->mask, &attr ) != XpmSuccess && XReadBitmapFile( dpy, Scr.Root, path, &newicon->width, &newicon->height, &bitmap, &xhot, &yhot) !=BitmapSuccess ){ if( err ) DrawErrMsgOnMenu( "Can't Read ICON ", fn ); if( icon==NULL ) free( newicon ); newicon = NULL; } else{ if( newicon->icon ){ newicon->width = attr.width; newicon->height = attr.height; newicon->kind = PIXMAP; } else{ newicon->icon = XCreatePixmap( dpy, Scr.Root, newicon->width, newicon->height, Scr.d_depth ); newicon->mask = XCreatePixmap( dpy, Scr.Root, newicon->width, newicon->height, Scr.d_depth ); XCopyPlane( dpy, bitmap, newicon->icon, Scr.BlackGC, 0, 0, newicon->width, newicon->height, 0, 0, 1 ); XCopyPlane( dpy, bitmap, newicon->mask, Scr.WhiteGC, 0, 0, newicon->width, newicon->height, 0, 0, 1 ); newicon->kind = BITMAP; XFreePixmap( dpy, bitmap ); } newicon->lighticon = XCreatePixmap( dpy, newicon->icon, newicon->width, newicon->height, Scr.d_depth ); XCopyArea( dpy, newicon->icon, newicon->lighticon, DefaultGC( dpy, Scr.screen ), 0, 0, attr.width, attr.height, 0, 0 ); for( y=0; y<newicon->height; y++ ) for( x=y%2; x<newicon->width; x+=2 ) XDrawPoint( dpy, newicon->lighticon, Scr.WhiteGC, x, y ); } if( path!=NULL ) free( path ); XpmFreeAttributes( &attr ); return newicon; }
/* * Set the pixmap. */ static void set_pixmap(XmEnhancedButtonWidget eb) { /* Configure defines XPMATTRIBUTES_TYPE as XpmAttributes or as * XpmAttributes_21, depending on what is in Xm/XpmP.h. */ XPMATTRIBUTES_TYPE attr; Pixmap sen_pix; Window root; static XpmColorSymbol color[8] = { {"none", "none", 0}, {"None", "none", 0}, {"background", NULL, 0}, {"foreground", NULL, 0}, {"bottomShadowColor", NULL, 0}, {"topShadowColor", NULL, 0}, {"highlightColor", NULL, 0}, {"armColor", NULL, 0} }; int scr; Display *dpy = XtDisplay(eb); int x; int y; unsigned int height, width, border, depth; int status = 0; Pixmap mask; Pixmap pix = None; Pixmap arm_pix = None; Pixmap ins_pix = None; Pixmap high_pix = None; char **data = (char **) eb->enhancedbutton.pixmap_data; char *fname = (char *) eb->enhancedbutton.pixmap_file; int shift; GC gc; /* Make sure there is a default value for the pixmap. */ if (!data) return; gc = XtGetGC((Widget)eb, (XtGCMask)0, NULL); scr = DefaultScreen(dpy); root = RootWindow(dpy, scr); eb->label.pixmap = None; eb->enhancedbutton.pixmap_depth = 0; eb->enhancedbutton.pixmap_width = 0; eb->enhancedbutton.pixmap_height = 0; eb->enhancedbutton.normal_pixmap = None; eb->enhancedbutton.armed_pixmap = None; eb->enhancedbutton.highlight_pixmap = None; eb->enhancedbutton.insensitive_pixmap = None; /* We use dynamic colors, get them now. */ motif_get_toolbar_colors( &eb->core.background_pixel, &eb->primitive.foreground, &eb->primitive.bottom_shadow_color, &eb->primitive.top_shadow_color, &eb->primitive.highlight_color); /* Setup color subsititution table. */ color[0].pixel = eb->core.background_pixel; color[1].pixel = eb->core.background_pixel; color[2].pixel = eb->core.background_pixel; color[3].pixel = eb->primitive.foreground; color[4].pixel = eb->core.background_pixel; color[5].pixel = eb->primitive.top_shadow_color; color[6].pixel = eb->primitive.highlight_color; color[7].pixel = eb->pushbutton.arm_color; /* Create the "sensitive" pixmap. */ attr.valuemask = XpmColorSymbols | XpmCloseness; attr.closeness = 65535; /* accuracy isn't crucial */ attr.colorsymbols = color; attr.numsymbols = XtNumber(color); if (fname) status = XpmReadFileToPixmap(dpy, root, fname, &pix, &mask, &attr); if (!fname || status != XpmSuccess) status = XpmCreatePixmapFromData(dpy, root, data, &pix, &mask, &attr); /* If something failed, we will fill in the default pixmap. */ if (status != XpmSuccess) status = XpmCreatePixmapFromData(dpy, root, blank_xpm, &pix, &mask, &attr); XpmFreeAttributes(&attr); XGetGeometry(dpy, pix, &root, &x, &y, &width, &height, &border, &depth); if (eb->enhancedbutton.label_location == (int)XmTOP || eb->enhancedbutton.label_location == (int)XmBOTTOM) shift = eb->primitive.shadow_thickness / 2; else shift = eb->primitive.shadow_thickness / 2; if (shift < 1) shift = 1; sen_pix = XCreatePixmap(dpy, root, width + shift, height + shift, depth); XSetForeground(dpy, gc, eb->core.background_pixel); XFillRectangle(dpy, sen_pix, gc, 0, 0, width + shift, height + shift); XSetClipMask(dpy, gc, mask); XSetClipOrigin(dpy, gc, shift, shift); XCopyArea(dpy, pix, sen_pix, gc, 0, 0, width, height, shift, shift); /* Create the "highlight" pixmap. */ color[4].pixel = eb->primitive.bottom_shadow_color; #ifdef XpmAllocColor /* SGI doesn't have it */ attr.valuemask = XpmColorSymbols | XpmCloseness | XpmAllocColor; attr.alloc_color = alloc_color; #else attr.valuemask = XpmColorSymbols | XpmCloseness; #endif attr.closeness = 65535; /* accuracy isn't crucial */ attr.colorsymbols = color; attr.numsymbols = XtNumber(color); status = XpmCreatePixmapFromData(dpy, root, data, &pix, NULL, &attr); XpmFreeAttributes(&attr); high_pix = XCreatePixmap(dpy, root, width + shift, height + shift, depth); #if 1 XSetForeground(dpy, gc, eb->core.background_pixel); #else XSetForeground(dpy, gc, eb->primitive.top_shadow_color); #endif XSetClipMask(dpy, gc, None); XFillRectangle(dpy, high_pix, gc, 0, 0, width + shift, height + shift); XSetClipMask(dpy, gc, mask); XSetClipOrigin(dpy, gc, 0, 0); XCopyArea(dpy, pix, high_pix, gc, 0, 0, width, height, 0, 0); arm_pix = XCreatePixmap(dpy, pix, width + shift, height + shift, depth); if (eb->pushbutton.fill_on_arm) XSetForeground(dpy, gc, eb->pushbutton.arm_color); else XSetForeground(dpy, gc, eb->core.background_pixel); XSetClipOrigin(dpy, gc, shift, shift); XSetClipMask(dpy, gc, None); XFillRectangle(dpy, arm_pix, gc, 0, 0, width + shift, height + shift); XSetClipMask(dpy, gc, mask); XSetClipOrigin(dpy, gc, 2 * shift, 2 * shift); XCopyArea(dpy, pix, arm_pix, gc, 0, 0, width, height, 2 * shift, 2 * shift); XFreePixmap(dpy, pix); XFreePixmap(dpy, mask); /* Create the "insensitive" pixmap. */ attr.valuemask = XpmColorSymbols | XpmCloseness | XpmColorKey; attr.closeness = 65535; /* accuracy isn't crucial */ attr.colorsymbols = color; attr.numsymbols = sizeof(color) / sizeof(color[0]); attr.color_key = XPM_MONO; status = XpmCreatePixmapFromData(dpy, root, data, &pix, &mask, &attr); /* Need to create new Pixmaps with the mask applied. */ ins_pix = XCreatePixmap(dpy, root, width + shift, height + shift, depth); XSetForeground(dpy, gc, eb->core.background_pixel); XSetClipOrigin(dpy, gc, 0, 0); XSetClipMask(dpy, gc, None); XFillRectangle(dpy, ins_pix, gc, 0, 0, width + shift, height + shift); XSetClipMask(dpy, gc, mask); XSetForeground(dpy, gc, eb->primitive.top_shadow_color); XSetClipOrigin(dpy, gc, 2 * shift, 2 * shift); XFillRectangle(dpy, ins_pix, gc, 2 * shift, 2 * shift, width, height); XSetForeground(dpy, gc, eb->primitive.bottom_shadow_color); XSetClipOrigin(dpy, gc, shift, shift); XFillRectangle(dpy, ins_pix, gc, 0, 0, width + shift, height + shift); XtReleaseGC((Widget) eb, gc); XpmFreeAttributes(&attr); eb->enhancedbutton.pixmap_depth = depth; eb->enhancedbutton.pixmap_width = width; eb->enhancedbutton.pixmap_height = height; eb->enhancedbutton.normal_pixmap = sen_pix; eb->enhancedbutton.highlight_pixmap = high_pix; eb->enhancedbutton.insensitive_pixmap = ins_pix; eb->enhancedbutton.armed_pixmap = arm_pix; eb->enhancedbutton.doing_setvalues = True; eb->enhancedbutton.doing_setvalues = False; XFreePixmap(dpy, pix); XFreePixmap(dpy, mask); }
/* * main */ int main(int argc, char *argv[]) { struct tm *gTime, *gmt; struct stat fi; XEvent event; Pixmap NewPixmap, NewShapeMask; XpmAttributes Attributes; Colormap cmap; int n, s, m, dt1, dt2, dt3, len; int Year, Month, Day; int Hours, Mins, Secs; int i, j, Width, Height, yoff, fd, Flag; long CurrentLocalTime; double UT, hour24(), jd(), CurrentJD, OldFileUT, FileUT; char command[1040], ImageName[256]; int havePixmap= 0; /* * Parse any command line arguments. */ ParseCMDLine(argc, argv); /* * Figure out what the name of the image xpm file should be... */ len = strlen(ImageURL); for (j = 0, i=0; i<len; ++i){ if (ImageURL[i] == '/') j = i; } strcpy(ImageName, ImageURL+j+1); sprintf(XpmFileName, "%s/.wmGrabImage/%s.xpm", getenv("HOME"), ImageName); sprintf(ImageFileName, "%s/.wmGrabImage/%s", getenv("HOME"), ImageName); openXwindow(argc, argv, wmGrabImage_master, wmGrabImage_mask_bits, wmGrabImage_mask_width, wmGrabImage_mask_height); cmap = DefaultColormap(display, DefaultScreen(display)); /* * Loop until we die */ n = 32000; s = 32000; m = 32000; dt1 = 32000; dt2 = 32000; dt3 = 32000; DblClkDelay = 32000; UpToDate = 0; FileUT = -999.0; Flag = 1; NewShapeMask = 0; Attributes.nalloc_pixels = 0; while(1) { /* * Keep track of # of seconds */ if (m > 100){ m = 0; ++dt1; ++dt2; ++dt3; } else { /* * Increment counter */ ++m; } /* * Double Click Delays * Keep track of click events. If Delay too long, set GotFirstClick's to False. */ if (DblClkDelay > 15) { DblClkDelay = 0; GotFirstClick1 = 0; GotDoubleClick1 = 0; GotFirstClick2 = 0; GotDoubleClick2 = 0; GotFirstClick3 = 0; GotDoubleClick3 = 0; } else { ++DblClkDelay; } /* * Process any pending X events. */ while(XPending(display)){ XNextEvent(display, &event); switch(event.type){ case Expose: RedrawWindow(); break; case ButtonPress: pressEvent(&event.xbutton); break; case ButtonRelease: break; } } /* * Draw window. */ if (ForceUpdate||Flag){ /* * Compute Current Julian Date */ CurrentLocalTime = time(CurrentTime); gTime = gmtime(&CurrentLocalTime); Year = gTime->tm_year+1900; Month = gTime->tm_mon+1; Day = gTime->tm_mday; Hours = gTime->tm_hour; Mins = gTime->tm_min; Secs = gTime->tm_sec; UT = (double)Hours + (double)Mins/60.0 + (double)Secs/3600.0; CurrentJD = jd(Year, Month, Day, UT); /* * Clear window. */ copyXPMArea(5, 69, 54, 54, 5, 5); if (havePixmap) { /* * free up the colors, if we alloc'd some before */ if (Attributes.nalloc_pixels > 0) XFreeColors(display, cmap, Attributes.alloc_pixels, Attributes.nalloc_pixels, 0); /* * Free last pixmap -- we dont need it anymore... * A ShapeMask is returned if the Pixmap had the color None used. * We could probably change Transparent to None to make use of this, but for now, * lets just ignore it... */ if ( NewShapeMask != 0 ) XFreePixmap(display, NewShapeMask); XFreePixmap(display, NewPixmap); XpmFreeAttributes(&Attributes); havePixmap= 0; } /* * Grab new pixmap. Accept a reasonable color match. */ Attributes.valuemask = XpmExactColors | XpmCloseness | XpmReturnAllocPixels; Attributes.exactColors = 0; Attributes.closeness = 40000; if (XpmReadFileToPixmap(display, Root, XpmFileName, &NewPixmap, &NewShapeMask, &Attributes) >= 0){ Height = Attributes.height; Width = Attributes.width; yoff = (CenterImage) ? (54 - Height)/2 : 0; XCopyArea(display, NewPixmap, wmgen.pixmap, NormalGC, 0, 0, Width, Height, 5, 5+yoff); Flag = 0; ForceUpdate = 0; havePixmap= 1; } /* * Make changes visible */ RedrawWindow(); } /* * Check xpm file status */ if (dt2 > 1){ dt2 = 0; if ( (fd = open(XpmFileName, O_RDONLY)) >= 0 ) { fstat(fd, &fi); close(fd); gmt = gmtime(&fi.st_mtime); OldFileUT = FileUT; FileUT = (double)gmt->tm_hour + (double)gmt->tm_min/60.0 + (double)gmt->tm_sec/3600.0; if (FileUT != OldFileUT) ForceUpdate = 1; } } /* * Check every 5 min if the values are not up to date... */ if (ForceUpdate2||(dt3 > UpdateDELAY)){ dt3 = 0; /* * Execute Perl script to grab the Latest METAR Report */ if (ConvertGeometry != NULL) sprintf(command, "GrabImage %s %s &", ImageURL, ConvertGeometry); else sprintf(command, "GrabImage %s &", ImageURL); system(command); ForceUpdate = 1; ForceUpdate2 = 0; } /* * Wait for next update */ usleep(DELAY); } }
int main ( int argc, char * * argv ) { int rc = -1; Display * pdisplay = NULL; /* "Window" is XID ID (unsigned long) */ Window hwindow = 0; Window hwindowButton = 0; GC hgc = 0; struct ParentInfo parentinfo; parentinfo.fGotChildStat = 0; do { Pixmap pixmap0; Pixmap pixmap1; XpmAttributes xpmattrs0; XpmAttributes xpmattrs1; XEvent xevent; int fLoop = 1; XWindowAttributes xattrs; pthread_t pthreadChild; pthread_t pthreadTimer; Atom atomHello; Atom atomTimer; Atom atomClose; static int x = 0; XInitThreads(); pthread_create(& pthreadChild, (void *) 0, doChild, NULL); pthread_create(& pthreadTimer, (void *) 0, doTimer, NULL); if (! (pdisplay = XOpenDisplay(NULL))) { break; } parentinfo.pdisplay = pdisplay; //fprintf(stderr, "d: %s\n", pdisplay->display_name); fprintf(stderr, "d: %s\n", DisplayString(pdisplay)); if (! (hwindow = XCreateSimpleWindow( pdisplay, // display DefaultRootWindow(pdisplay), // parent 0, // x 0, // y 100, // width 100, // height 0, // border_witdh getColor(pdisplay, "black"), // border getColor(pdisplay, "white") ))) { // background break; } parentinfo.hwindow = hwindow; XSelectInput(pdisplay, hwindow, ExposureMask | KeyPressMask); /* todo: magic number */ if (! (hwindowButton = XCreateSimpleWindow(pdisplay, hwindow, 10, 10, 60, 30, 3, getColor(pdisplay, "black"), getColor(pdisplay, "white" )))) { break; } XSelectInput(pdisplay, hwindowButton, ButtonPressMask | \ ButtonReleaseMask | ExposureMask ); if (! (hgc = XCreateGC(pdisplay, hwindow, 0, 0))) { break; } xpmattrs0.alloc_close_colors = True; xpmattrs0.closeness = 65535; xpmattrs0.valuemask = XpmAllocCloseColors | XpmCloseness; if (XpmCreatePixmapFromData(pdisplay, hwindow, test_xpm, & pixmap0, NULL, & xpmattrs0 ) != 0) { break; } /* http://www.fenix.ne.jp/~cdrtk/misc/xpm/advanced.html */ fprintf(stderr, "xpmattrs0 - width: %d, height: %d\n", xpmattrs0.width, xpmattrs0.height ); xpmattrs1.alloc_close_colors = True; xpmattrs1.closeness = 65535; xpmattrs1.valuemask = XpmAllocCloseColors | XpmCloseness; if ((XpmReadFileToPixmap(pdisplay, hwindow, "yahoo_logo.xpm", & pixmap1, NULL, & xpmattrs1 )) != 0) { break; } XMapWindow(pdisplay, hwindow); XMapSubwindows(pdisplay, hwindow); XResizeWindow(pdisplay, hwindow, (xpmattrs0.width > xpmattrs1.width)? xpmattrs0.width: xpmattrs1.width, xpmattrs0.height + xpmattrs1.height ); /* Window attributes are reflected after calling XFlush() */ XFlush(pdisplay); XGetWindowAttributes(pdisplay, hwindow, & xattrs); fprintf(stderr, "xattrs - x: %d, y: %d, width: %d, height: %d\n", xattrs.x, xattrs.y, xattrs.width, xattrs.height ); fprintf(stderr, "I'm your father\n"); pparentinfo_ = & parentinfo; atomHello = XInternAtom(pdisplay, "Hello", False); atomTimer = XInternAtom(pdisplay, "Timer", False); atomClose = XInternAtom(pdisplay, "WM_DELETE_WINDOW", False); while (fLoop) { XNextEvent(pdisplay, & xevent); switch (xevent.type) { /* todo: cliping */ /* http://homepage3.nifty.com/rio_i/lab/xlib/007expose.htm */ case (Expose): { /* Number of proceeding expose event. 0 means the last */ if (xevent.xexpose.count == 0) { XWindowAttributes xattrs; const char szButton[] = "BUTTON"; XGetWindowAttributes(pdisplay, hwindowButton, & xattrs ); /* todo: magic number */ XDrawString(pdisplay, hwindowButton, hgc, 10, xattrs.height / 2, szButton, strlen(szButton) ); XCopyArea(pdisplay, pixmap0, hwindow, hgc, 0, // x 0, // y xpmattrs0.width, // width xpmattrs0.height, // height 0, // dest x 0 ); // dest y XCopyArea(pdisplay, pixmap1, hwindow, hgc, 0, 0, xpmattrs1.width, xpmattrs1.height, 0, xpmattrs0.height ); } break; } case (MappingNotify): { //XRefreshKeyboardMapping(& xevent); break; } case (KeyPress): { char sz[256]; KeySym keysym; XComposeStatus xcomposestat; int n; n = XLookupString(& xevent.xkey, sz, sizeof (sz), & keysym, & xcomposestat ); if (n > 0) { sz[n] = '\0'; fprintf(stderr, "d: %d, %s\n", (int) keysym, sz); if (keysym == XK_space) { fLoop = 0; } } break; } case (ButtonRelease): { XWindowAttributes xattrs; XGetWindowAttributes(pdisplay, hwindowButton, & xattrs); if ( xevent.xbutton.window == hwindowButton && xattrs.x < xevent.xbutton.x && xattrs.y < xevent.xbutton.y && xevent.xbutton.x < xattrs.x + xattrs.width && xevent.xbutton.y < xattrs.y + xattrs.height ) { fLoop = 0; } break; } case (ClientMessage): { if (xevent.xclient.message_type == atomHello) { fprintf(stderr, "Got 0\n"); } else if (xevent.xclient.message_type == atomTimer) { XCopyArea(pdisplay, pixmap0, hwindow, hgc, 0, // x 0, // y xpmattrs0.width, // width xpmattrs0.height, // height x, // dest x 0 ); // dest y x -= 1; if (x < -300 ) { x = 1000; } //fprintf(stderr, "1"); } else if (xevent.xclient.message_type == atomClose) { fprintf(stderr, "XXXXX\n"); fLoop = 0; } break; } default: { break; } } } if (parentinfo.fGotChildStat) { rc = WEXITSTATUS(parentinfo.rc); } else { rc = 0; } } while (0); if (hgc) { XFreeGC(pdisplay, hgc); } if (hwindowButton) { XDestroyWindow(pdisplay, hwindowButton); } if (hwindow) { XDestroyWindow(pdisplay, hwindow); } if (pdisplay) { XCloseDisplay(pdisplay); } return (rc); }