Exemplo n.º 1
0
static ECursor     *
ECursorRealize(ECursor * ec)
{
   Pixmap              pmap, mask;
   int                 xh, yh;
   unsigned int        w, h, ww, hh;
   char               *img, msk[FILEPATH_LEN_MAX];

   if (ec->file)
     {
	img = ThemeFileFind(ec->file, FILE_TYPE_CURSOR);
	_EFREE(ec->file);	/* Ok or not - we never need file again */
	if (!img)
	   goto done;

	Esnprintf(msk, sizeof(msk), "%s.mask", img);
	pmap = 0;
	mask = 0;
	xh = 0;
	yh = 0;
	XReadBitmapFile(disp, WinGetXwin(VROOT), msk, &w, &h, &mask, &xh, &yh);
	XReadBitmapFile(disp, WinGetXwin(VROOT), img, &w, &h, &pmap, &xh, &yh);
	XQueryBestCursor(disp, WinGetXwin(VROOT), w, h, &ww, &hh);
	if ((w <= ww) && (h <= hh) && (pmap))
	  {
	     if (xh < 0 || xh >= (int)w)
		xh = (int)w / 2;
	     if (yh < 0 || yh >= (int)h)
		yh = (int)h / 2;
	     ec->cursor =
		ECreatePixmapCursor(pmap, mask, w, h, xh, yh, ec->fg, ec->bg);
	  }

	if (ec->cursor == NoXID)
	  {
	     Eprintf("*** Failed to create cursor \"%s\" from %s,%s\n",
		     ec->name, img, msk);
	  }

	if (pmap)
	   EFreePixmap(pmap);
	if (mask)
	   EFreePixmap(mask);
	Efree(img);
     }
   else
     {
	ec->cursor = (ec->native_id == 999) ?
	   None : XCreateFontCursor(disp, ec->native_id);
     }

 done:
   if (ec->cursor == NoXID)
     {
	ECursorDestroy(ec);
	ec = NULL;
     }

   return ec;
}
Exemplo n.º 2
0
void
pickPixmap(Display * display, Drawable drawable, char *name,
	   int default_width, int default_height, unsigned char *default_bits,
	   int *width, int *height, Pixmap * pixmap,
	   int *graphics_format)
{
	int         x_hot, y_hot;	/* dummy */

	if (name && *name) {
		if (readable(name)) {
			if (BitmapSuccess == XReadBitmapFile(display, drawable, name,
			     (unsigned int *) width, (unsigned int *) height,
						   pixmap, &x_hot, &y_hot)) {
				*graphics_format = IS_XBMFILE;
			}
			if (*graphics_format <= 0)
				(void) fprintf(stderr,
					    "\"%s\" not xbm format\n", name);
		} else {
			(void) fprintf(stderr,
				       "could not read file \"%s\"\n", name);
		}
	}
	if (*graphics_format <= 0) {
		*width = default_width;
		*height = default_height;
		*graphics_format = IS_XBM;
		*pixmap = XCreateBitmapFromData(display, drawable,
				     (char *) default_bits, *width, *height);
	}
}
Exemplo n.º 3
0
Arquivo: icons.c Projeto: att/uwin
/***************************************************************************
 *
 * Looks for a monochrome icon bitmap file
 *
 **************************************************************************/
void GetBitmapFile(struct icon_info *item)
{
  char *path = NULL;
  int HotX,HotY;

  path = findImageFile(item->icon_file, imagePath,R_OK);
  if(path == NULL)return;

  if(XReadBitmapFile (dpy, Root,path,(unsigned int *)&item->icon_w,
		      (unsigned int *)&item->icon_h,
		      &item->iconPixmap,
		      (int *)&HotX,
		      (int *)&HotY) != BitmapSuccess)
    {
      item->icon_w = 0;
      item->icon_h = 0;
    }
  else
      item->icon_depth = 1;

  item->icon_w = min(max_icon_width, item->icon_w);
  item->icon_h = min(max_icon_height, item->icon_h);
  item->icon_maskPixmap = None;
  free(path);
}
Exemplo n.º 4
0
static Object P_Read_Bitmap_File (Object d, Object fn) {
    Display *dpy;
    Drawable dr = Get_Drawable (d, &dpy);
    unsigned width, height;
    int r, xhot, yhot;
    Pixmap bitmap;
    Object t, ret, x;
    GC_Node2;

    Disable_Interrupts;
    r = XReadBitmapFile (dpy, dr, Get_Strsym (fn), &width, &height, &bitmap,
                         &xhot, &yhot);
    Enable_Interrupts;
    if (r != BitmapSuccess)
        return Bits_To_Symbols ((unsigned long)r, 0, Bitmapstatus_Syms);
    t = ret = P_Make_List (Make_Integer (5), Null);
    GC_Link2 (ret, t);
    x = Make_Pixmap (dpy, bitmap);
    Car (t) = x;
    t = Cdr (t);
    Car (t) = Make_Integer (width);
    t = Cdr (t);
    Car (t) = Make_Integer (height);
    t = Cdr (t);
    Car (t) = Make_Integer (xhot);
    t = Cdr (t);
    Car (t) = Make_Integer (yhot);
    GC_Unlink;
    return ret;
}
Exemplo n.º 5
0
void MSPixmap::create(MSDisplayServer *pServer_,const char *pName_,const char *bitmapFile_)
{
  Display *display=pServer_->display();
  Window window=pServer_->root();
  unsigned w,h;
  Pixmap bitmap;
  if (XReadBitmapFile(display,window,bitmapFile_,&w,&h,&bitmap,0,0)==BitmapSuccess)
   {
     _pData=new MSPixmapData(pServer_,pName_,bitmap,bitmap,w,h,1,0,0);
     addToHashTable(pName_,(void *)_pData);
     addReference();     
   }
  else
   {
     // Can't read bitmap file, create one with background color
     MSMessageLog::warningMessage("MSPixmap warning: Unable to create Pixmap from file `%s'\n",
				  bitmapFile_);
     char buf[255];
     unsigned long fg=pServer_->defaultForeground();
     unsigned long bg=pServer_->defaultBackground();
     int depth=DefaultDepthOfScreen(pServer_->screen());
     sprintf(buf,"Predefined_%s_%d_%d_%d_%d",MSPixmap::SolidBackgroundPixmap,fg,bg,depth,display);
     if(copyPixmapDataWithKey(buf)==MSFalse) 
       create(pServer_,MSPixmap::SolidBackgroundPixmap,fg,bg);
   }
}
Exemplo n.º 6
0
static pBitmapDirectory AddFile(
      Widget w,
      String file,
      String name,
      pBitmapDirectory bd) {
  int dummy;
  tBitmapEntry bitmap_entry;
  pBitmapDirectory entry;
  Window win = XRootWindowOfScreen(XtScreen(w));

  if(XReadBitmapFile(XtDisplay(w), win, file,
		     &bitmap_entry.width, &bitmap_entry.height,
		     &bitmap_entry.bitmap,
		     &dummy, &dummy) !=BitmapSuccess) 
    return bd; /* Ignore invalid bitmap files */
  if(!(entry = FindBitmap(name, bd))) {
    /* create new entry */
    entry = NEW(tBitmapDirectory);
    entry->next = bd;
    bd = entry;
  } /* else replace existent entry! */
  entry->bitmap_entry = bitmap_entry;
  entry->bitmap_entry.name = strdup(name);
  return bd;
}
Exemplo n.º 7
0
PyObject *
tkwin_ReadBitmapFile(TkWinObject * self, PyObject * args)
{
    Display	*display;
    Drawable	d;
    char *	arg1;
    unsigned int width, height;
    int hotspot_x, hotspot_y, error;
    Pixmap	bitmap;
    PyObject *pixmap, *tuple;

    if (!PyArg_ParseTuple(args, "s", &arg1))
	return NULL;

    display = Tk_Display(self->tkwin);
    d = RootWindowOfScreen(Tk_Screen(self->tkwin));
    error = XReadBitmapFile(display, d, arg1,
			    &width, &height, &bitmap,
			    &hotspot_x, &hotspot_y);
    /* Check error code, create a message to be returned as well as the error
     * code when the exception is raised.
     */
    tuple = NULL;
    switch (error)
    {
    case BitmapOpenFailed:
	PyErr_SetString(PyExc_IOError,
			"XReadBitMapFile - cannot open file");
	break;
    case BitmapFileInvalid:
	PyErr_SetString(PyExc_RuntimeError,
			"XReadBitMapFile - invalid bitmap data in file");
	break;
    case BitmapNoMemory:
	PyErr_SetString(PyExc_MemoryError,
			"XReadBitMapFile - no memory !!");
	break;
    case BitmapSuccess:
	/*
	 * Setup a tuple to be returned containing the info.
	 * returned from the call.
	 */
	pixmap = PaxPixmap_FromPixmap(display, bitmap, 1);
	if (pixmap != NULL)
	{
	    tuple = Py_BuildValue("(iiOii)", width, height, pixmap,
				  hotspot_x, hotspot_y);
	    Py_DECREF(pixmap);
	}
	break;
    default:
	PyErr_SetString(PyExc_SystemError,
			"XReadBitMapFile returned strange error");
	break;
    }

    return tuple;		/* will be NULL on error */
}
Exemplo n.º 8
0
Pixmap
FindBitmap(char *name, unsigned int *widthp, unsigned int *heightp)
{
  char *bigname;
  Pixmap pm;

  if (!name)
    return None;

  /*
   * Generate a full pathname if any special prefix characters (such as ~)
   * are used.  If the bigname is different from name, bigname will need to
   * be freed.
   */
  bigname = ExpandFilename(name);
  if (!bigname)
    return None;

  /*
   * look along bitmapFilePath resource same as toolkit clients
   */
  pm = XmuLocateBitmapFile(ScreenOfDisplay(dpy, Scr->screen), bigname, NULL, 0, (int *)widthp, (int *)heightp, &HotX, &HotY);
  if (pm == None && Scr->IconDirectory && bigname[0] != '/')
  {
    if (bigname != name)
      free(bigname);
    /*
     * Attempt to find icon in old IconDirectory (now obsolete)
     */
    bigname = (char *)malloc(strlen(name) + strlen(Scr->IconDirectory) + 2);
    if (!bigname)
    {
      fprintf(stderr, "%s:  unable to allocate memory for \"%s/%s\"\n", ProgramName, Scr->IconDirectory, name);
      return None;
    }
    (void)sprintf(bigname, "%s/%s", Scr->IconDirectory, name);
    if (XReadBitmapFile(dpy, Scr->Root, bigname, widthp, heightp, &pm, &HotX, &HotY) != BitmapSuccess)
    {
      pm = None;
    }
  }
  if (bigname != name)
    free(bigname);

#ifdef DEBUG
  if (pm == None)
  {
    fprintf(stderr, "%s:  unable to find bitmap \"%s\"\n", ProgramName, name);
  }
#endif

  return pm;
}
Exemplo n.º 9
0
// readBitmap(): Reads a specified bitmap into the pixmap slot specified by dest
void readBitmap( XInfo& xinfo, Pixmap* pixmaps, std::string fileName,
                 PixmapArray::Enum dest ) {
    Window rootWin = DefaultRootWindow( xinfo.display );
    unsigned int width, height;
    int x, y, rc;

    rc = XReadBitmapFile( xinfo.display, rootWin,
                          fileName.c_str(),
                          &width, &height,
                          &pixmaps[ dest ],
                          &x, &y );
    checkBitmapError( rc );
}
Exemplo n.º 10
0
FvwmPicture *LoadPicture(Display *dpy,Window Root,char *path, int color_limit)
{
  int l;
  FvwmPicture *p;
#ifdef XPM
  XpmAttributes xpm_attributes;
  int rc;
  XpmImage	my_image = {0};
#endif

  p=(FvwmPicture*)safemalloc(sizeof(FvwmPicture));
  p->count=1;
  p->name=path;
  p->next=NULL;

#ifdef XPM
  /* Try to load it as an X Pixmap first */
  xpm_attributes.colormap=PictureCMap;
  xpm_attributes.closeness=40000; /* Allow for "similar" colors */
  xpm_attributes.valuemask=
    XpmSize | XpmReturnPixels | XpmColormap | XpmCloseness;

  rc =XpmReadFileToXpmImage(path, &my_image, NULL);
  if (rc == XpmSuccess) {
    color_reduce_pixmap(&my_image, color_limit);
    rc = XpmCreatePixmapFromXpmImage(dpy, Root, &my_image,
                                     &p->picture,&p->mask,
                                     &xpm_attributes);
    if (rc == XpmSuccess) {
      p->width = my_image.width;
      p->height = my_image.height;
      XpmFreeXpmImage(&my_image);
      p->depth = DefaultDepthOfScreen(DefaultScreenOfDisplay(dpy));
      return p;
    }
    XpmFreeXpmImage(&my_image);
  }
#endif

  /* If no XPM support, or XPM loading failed, try bitmap */
  if(XReadBitmapFile(dpy,Root,path,&p->width,&p->height,&p->picture,&l,&l)
     == BitmapSuccess)
    {
      p->depth = 0;
      p->mask = None;
      return p;
    }

  free(p);
  return NULL;
}
Exemplo n.º 11
0
void MSPixmap::create(MSDisplayServer *pServer_,const char *pName_,
		      const char *bitmapFile_,unsigned long fg_,unsigned long bg_)
{
  Display *display=pServer_->display();
  Window window=pServer_->root();
  int depth=DefaultDepthOfScreen(pServer_->screen());
  unsigned w,h;
  Pixmap bitmap;
#ifdef MS_WINDOWS
  int res;
  if (bitmapFile_==0) res=MSXReadBitmapFromResource(display,window,_name,&w,&h,&bitmap);
  else res=MSXReadBitmapFromXbmFile(display,window,bitmapFile_,&w,&h,&bitmap,fg_,bg_,depth);
  if( res==BitmapSuccess)
  {
     _pData=new MSPixmapData(pServer_,pName_,bitmap,w,h,depth,fg_,bg_);

#else
  if (XReadBitmapFile(display,window,bitmapFile_,&w,&h,&bitmap,0,0)==BitmapSuccess)
   {
     Pixmap pixmap=XCreatePixmap(display,window,w,h,depth);
     GC gc=XCreateGC(display,window,0,0);
     XSetForeground(display,gc,fg_);
     XSetBackground(display,gc,bg_);
     XCopyPlane(display,bitmap,pixmap,gc,0,0,w,h,0,0,1);
     XFreeGC(display,gc);
     XFreePixmap(display,bitmap);
     _pData=new MSPixmapData(pServer_,pName_,pixmap,w,h,depth,fg_,bg_);
#endif
     addToHashTable(pName_,(void *)_pData);
     addReference();     
   }
  else
   {
     // Can't read bitmap file, create one with background color
     MSMessageLog::warningMessage("MSPixmap warning: Unable to create Pixmap from file %s\n",bitmapFile_);
     char buf[255];
     sprintf(buf,"Predefined_%s_%d_%d_%d_%d",MSPixmap::SolidBackgroundPixmap,fg_,bg_,depth,display);
     if(copyPixmapDataWithKey(buf)==MSFalse) 
       create(pServer_,MSPixmap::SolidBackgroundPixmap,fg_,bg_);
   }
}

void MSPixmap::create(MSDisplayServer *pServer_,const char *pName_,
		      int w_,int h_,unsigned long fg_,unsigned long bg_)
{
  int dep=DefaultDepthOfScreen(pServer_->screen());
  Pixmap p=XCreatePixmap(pServer_->display(),pServer_->root(),w_,h_,dep);
  create(pServer_,pName_,p,w_,h_,dep,fg_,bg_);
}
Exemplo n.º 12
0
Pixmap
wlp_xbm_from_file(Widget w, Display *dpy, char *name)
{
	Drawable d;
	Pixmap   b;
	unsigned width, height;
	int      hx, hy, status;

	if(w != NULL) {
		dpy = XtDisplay(w);
		d   = XtWindow(w);
	}
	else {
		d = RootWindow(dpy, DefaultScreen(dpy));
	}

	status = XReadBitmapFile(dpy, d, name, &width, &height, &b, &hx, &hy);
	return status == Success ? b : None;
}
Exemplo n.º 13
0
IconRec readIcon(Widget shell, char *name)
{
  Window win = DefaultRootWindow(dpy);
  Screen *scrn = XtScreen(shell);
  IconRec icon;
  char fullname[MAXPATHLEN];
  int x, y;
  XpmAttributes attr;
  static XpmColorSymbol none_color = { NULL, "None", (Pixel) 0 };

  none_color.pixel = winInfo.background;

  /* first search for xpm icons: */

  attr.valuemask = XpmReturnPixels | XpmColorSymbols | XpmCloseness;
  attr.colorsymbols = &none_color;
  attr.numsymbols = 1;
  attr.closeness = CLOSENESS;

  if (XpmReadFileToPixmap(dpy, win, searchPath(fullname, resources.pixmap_path, name), &icon.bm, &icon.mask, &attr) == XpmSuccess)
  {
      icon.width = attr.width;
      icon.height = attr.height;
      return icon;
  }

  icon.mask = None;

  /* now search along *bitmapPath: */

  if (XReadBitmapFile(dpy, win, searchPath(fullname, resources.bitmap_path, name), &attr.width, &attr.height, &icon.bm, &x, &y) == BitmapSuccess)
  {
      icon.width = attr.width;
      icon.height = attr.height;
  }

  /* finally search bitmap in standard locations (*bitmapFilePath): */

  else
      icon.bm = XmuLocateBitmapFile(scrn, name, NULL, 0, (int *)&icon.width, (int *)&icon.height, &x, &y);
  return icon;
}
Exemplo n.º 14
0
/*
 * iconGetBitmap
 *
 * Get a bitmap for the icon based on the path and name of the icon. 
 * If no bitmap file is found use a built-in default.
 */
static Pixmap
iconGetBitmap(
	Widget		widget,
	char		*iconPath,
	IconBitmapPart	iconPart,
	unsigned short	*returnWidth,
	unsigned short	*returnHeight)
{
	Display		*display = XtDisplayOfObject(widget);
	Window		window = DefaultRootWindow(display);
	int		status;
	int		xHot, yHot;
	Pixmap		bitmap;
	unsigned int	width, height;
	
	*returnWidth = *returnHeight = 0;

	if (iconPath != NULL) {

		status = XReadBitmapFile(display, window, iconPath,
			&width, &height, &bitmap, &xHot, &yHot);

		if (status == BitmapSuccess) {
			*returnWidth = (unsigned short) width;
			*returnHeight = (unsigned short) height;
		} else {
			printf(
			    "Unable to read icon from bitmap file \"%s\".\n"
			    "Using default icon bitmap.\n",
			    iconPath, NULL);
			bitmap = iconDefaultBitmap(display, window, iconPart,
				returnWidth, returnHeight);
		}
	} else {
		bitmap = iconDefaultBitmap(display, window, iconPart,
			returnWidth, returnHeight);
	}
	return bitmap;
}
Exemplo n.º 15
0
void* iupdrvImageLoad(const char* name, int type)
{
  if (type == IUPIMAGE_CURSOR)
  {
    Cursor cursor = 0;
    int id;
    if (iupStrToInt(name, &id))
      cursor = XCreateFontCursor(iupmot_display, id);
    return (void*)cursor;
  }
  else /* IUPIMAGE_IMAGE or IUPIMAGE_ICON */
  {
    Screen* screen = ScreenOfDisplay(iupmot_display, iupmot_screen);
  	Pixmap pixmap = XmGetPixmap(screen, (char*)name, BlackPixelOfScreen(screen), WhitePixelOfScreen(screen));
    if (pixmap == XmUNSPECIFIED_PIXMAP)
    {
	    unsigned int width, height;
	    int hotx, hoty;
      pixmap = 0;
    	XReadBitmapFile(iupmot_display, RootWindow(iupmot_display,iupmot_screen), name, &width, &height, &pixmap, &hotx, &hoty);
    }
  	return (void*)pixmap;
  }
}
Exemplo n.º 16
0
// Convert String to Bitmap
// A Bitmap will be read in as bitmap file -- 1 and 0 values remain unchanged.
static Boolean CvtStringToBitmap(Display *display, 
				 XrmValue *, Cardinal *, 
				 XrmValue *fromVal, XrmValue *toVal,
				 XtPointer *)
{
    // Fetch a drawable
    Window window = None;

#if 0
    if (*num_args >= 1)
    {
	// convert first arg into widget
	Widget w = *(Widget *) args[0].addr;
	if (XtIsRealized(w))
	    window = XtWindow(w);
    }
#endif

    if (window == None)
	window = DefaultRootWindow(display);

    // Locate file
    const string basename = str(fromVal, false);
    String filename = locateBitmap(display, basename.chars());
    if (filename == 0)
    {
	// Cannot find file -- check for predefined motif bitmaps
	for (Cardinal i = 0; i < XtNumber(bitmap_name_set); i++)
	{
	    if (basename == bitmap_name_set[i])
	    {
		Pixmap bitmap = XCreateBitmapFromData(display, window,
						      (char *)(bitmaps[i]),
						      16, 16);
		if (bitmap == None)
		    break;

		done(Pixmap, bitmap);
	    }
	}

	// Cannot find file and no predefined bitmap found
	XtDisplayStringConversionWarning(display, fromVal->addr, XtRBitmap);
	return False;
    }


    // create pixmap
    unsigned int width, height;
    Pixmap bitmap;
    int x_hot, y_hot;
    int success = XReadBitmapFile(display, window, filename, 
				  &width, &height, &bitmap, &x_hot, &y_hot);
    if (success != BitmapSuccess)
    {
	XtDisplayStringConversionWarning(display, fromVal->addr, XtRBitmap);
	XtFree(filename);
	return False;
    }

    done(Pixmap, bitmap);
}
Exemplo n.º 17
0
Arquivo: misc.c Projeto: morgant/mlvwm
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;
}
Exemplo n.º 18
0
void NxmCursor_createCursor ( int ref )
/************************************************************************
 * NxmCursor_createCursor						*
 *									*
 * This function creates the cursor for a specific reference index	*
 *									*
 * void NxmCursor_createCursor(ref)			                *
 *									*
 * Input parameters:							*
 *	ref           int	   reference # of cursor		*
 *									*
 * Output parameters:							*
 * Return parameters:							*
 *			NONE						*
 *									*
 **									*
 * Log:									*
 * H. Zeng/EAI          04/00   initial coding                          *
 * H. Zeng/EAI          05/00   added incorrect info. handling          *
 ***********************************************************************/
{
    int		   ii, x_hot, y_hot;
    int            cursor_id = IMPVAL, iret1, iret2;
    long int       no_use;
    unsigned int   width, height;       
    Pixmap         cursor_pixmap, mask_pixmap;
    XColor         fgcolr, bgcolr, ignore;
    char           cursor_name[20], pix_name[25], cursor_file[128]; 
    char           cursor_mask[128], cursor_color[10];
    char           bg_color[] = "black", *ptr;
    Status         status;
/*---------------------------------------------------------------------*/
/*
 * Find cursor type and cursor color according to the reference #.
 */
    strcpy(cursor_name, _currefTbl.currefs[ref].typ_name);
    strcpy(cursor_color, _currefTbl.currefs[ref].color);

    for(ii = 0; ii < _curtypTbl.ntyp; ii++) {
       if( strcmp(cursor_name,_curtypTbl.curtyps[ii].ext_name)==0 ) {
         strcpy(pix_name, _curtypTbl.curtyps[ii].int_name);
         cursor_id = _curtypTbl.curtyps[ii].id;
         break; 
       }
    }

/*
 * For garbage cursor_name
 */
    if(cursor_id == IMPVAL) {
      switch(ref) {
         case 0:
            cursor_id = 132;
            break;
         case 1:
            cursor_id = 34;
            break;
         case 2:
            cursor_id = 0;
            break;
         default:
            cursor_id = 132;
            break;
      }

    }

/*
 * Get foreground color and background color.
 */
    fgcolr.flags = DoRed | DoBlue | DoGreen;
    status = XAllocNamedColor (NXMdisplay, NXMcmap, cursor_color, 
                               &fgcolr, &ignore);

/*
 * For garbage cursor_color
 */
    if(status == 0) {
       XAllocNamedColor (NXMdisplay, NXMcmap, "white", 
                         &fgcolr, &ignore);
    }

    bgcolr.flags = DoRed | DoBlue | DoGreen;
    XAllocNamedColor (NXMdisplay, NXMcmap, bg_color, 
                      &bgcolr, &ignore);


/*
 * According to whether cursor_id is -1 or not, create 
 * pixmap cursor or standard cursor.
 */
    if( cursor_id != -1 ) {

/*
 * create standard cursor
 */
      if( _cursorRef[ref] != (Cursor)0 ) {
         XFreeCursor(NXMdisplay, _cursorRef[ref]);
      }

      _cursorRef[ref] = XCreateFontCursor(NXMdisplay, (Cardinal)cursor_id);

      XRecolorCursor (NXMdisplay, _cursorRef[ref], &fgcolr, &bgcolr);

    }
    else {

      strcat(pix_name, ".xbm");
      cfl_inqr (pix_name, ICON_DIR, &no_use, cursor_file, &iret1 ); 
      ptr = strstr(pix_name, ".xbm");
      sprintf (ptr, "_mask.xbm");
      cfl_inqr (pix_name, ICON_DIR, &no_use, cursor_mask, &iret2 ); 

      if( (iret1 != 0) || (iret2 != 0) ) {
  
/*
 * File not found !
 */
         fprintf(stderr, "\nPixmap file not found!\n");
         fprintf(stderr, "Please check the cursor type table.\n\n");
         switch(ref) {
	    case 0:
              cfl_inqr ("lg_arrow.xbm", ICON_DIR, &no_use, 
                        cursor_file, &iret1 );
              cfl_inqr ("lg_arrow_mask.xbm", ICON_DIR, &no_use, 
                        cursor_mask, &iret2 );
              break;
	    case 1:  
              cfl_inqr ("lg_cross.xbm", ICON_DIR, &no_use, 
                        cursor_file, &iret1 );
              cfl_inqr ("lg_cross_mask.xbm", ICON_DIR, &no_use, 
                        cursor_mask, &iret2 );
              break;
	    case 2:
              cfl_inqr ("lg_x.xbm", ICON_DIR, &no_use, 
                        cursor_file, &iret1 );
              cfl_inqr ("lg_x_mask.xbm", ICON_DIR, &no_use, 
                        cursor_mask, &iret2 );
              break;
	    default:
              cfl_inqr ("lg_arrow.xbm", ICON_DIR, &no_use, 
                        cursor_file, &iret1 );
              cfl_inqr ("lg_arrow_mask.xbm", ICON_DIR, &no_use, 
                        cursor_mask, &iret2 );
              break;

         }

      }  

      XReadBitmapFile(NXMdisplay, _bxmWin, cursor_mask,	
	              &width, &height, &mask_pixmap, 
		      &x_hot, &y_hot );

      XReadBitmapFile(NXMdisplay, _bxmWin, cursor_file,	
	              &width, &height, &cursor_pixmap, 
		      &x_hot, &y_hot );

      if( _cursorRef[ref] != (Cursor)0 ) {
         XFreeCursor(NXMdisplay, _cursorRef[ref]);
      }

      _cursorRef[ref] = XCreatePixmapCursor(NXMdisplay, cursor_pixmap, 
                                            mask_pixmap, &fgcolr, &bgcolr, 
                                            (Cardinal)x_hot, (Cardinal)y_hot );

      XFreePixmap(NXMdisplay, mask_pixmap);
      XFreePixmap(NXMdisplay, cursor_pixmap);

    }/* the end of else part */

}
Exemplo n.º 19
0
Arquivo: icon.c Projeto: guns/subtle
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;
} /* }}} */
Exemplo n.º 20
0
void XoInitCursor()
{
	Display	*disp,*XgDisplay();
	static Pixmap XoDefaultCursorPixmap;
	int screen = XDefaultScreen(XgDisplay());
	Colormap cmap = DefaultColormap(XgDisplay(),0);
	static char 	XoDefaultCursorFile[] = "genesis.bmp";
	static char 	XoDragCursorFile[] = "gendrag.bmp";
	char	*bmap_name,*FindFileOnPath();
	int		xhot,yhot;
	unsigned int wid,ht;

	disp = XgDisplay();
	bmap_name = FindFileOnPath(XoDefaultCursorFile);
	if (!bmap_name) {
		DefaultCursor = XCreateFontCursor(disp,0);
		return;
	}

	white.pixel = WhitePixel(disp,screen);
	white.red = white.green = white.blue = 65535;
	black.pixel = WhitePixel(disp,screen);
	black.red = black.green = black.blue = 0;

	if (XAllocColor(disp,cmap,&white) == 0) {
			fprintf(stderr,"Cannot allocate white color\n");
			return;
	}
	if (XAllocColor(disp,cmap,&black) == 0) {
			fprintf(stderr,"Cannot allocate black color\n");
			return;
	}

	if (XReadBitmapFile(
		disp,XDefaultRootWindow(disp),
		bmap_name,
		&wid,&ht,
		&XoDefaultCursorPixmap,
		&xhot,&yhot) != 0) {
		fprintf(stderr,"Cannot read bitmap file %s\n",
			bmap_name);
		DefaultCursor = XCreateFontCursor(disp,0);
		return;
	}

	DefaultCursor = XCreatePixmapCursor(disp,XoDefaultCursorPixmap,
		XoDefaultCursorPixmap,
		&black,&white,
		(xhot > 0) ? xhot : 0 ,(yhot > 0) ? yhot : 0 );

	bmap_name = FindFileOnPath(XoDragCursorFile);
	if (!bmap_name) {
		DragCursor = XCreateFontCursor(disp,1);
		return;
	}
	if (XReadBitmapFile(
		disp,XDefaultRootWindow(disp),
		bmap_name,
		&wid,&ht,
		&XoDragCursorPixmap,
		&xhot,&yhot) != 0) {
		fprintf(stderr,"Cannot read bitmap file %s\n",
			bmap_name);
		DragCursor = XCreateFontCursor(disp,1);
		return;
	}

	DragCursor = XCreatePixmapCursor(disp,XoDragCursorPixmap,
		XoDragCursorPixmap,
		&black,&white,
		(xhot > 0) ? xhot : 0 ,(yhot > 0) ? yhot : 0 );
}
Exemplo n.º 21
0
void
main(int argc, char* argv[])
{
  Display* display;		/* pointer to X Display structure.           */
  int screen_num;		/* number of screen to place the window on.  */
  Window win;			/* pointer to the newly created window.      */
  unsigned int display_width,
               display_height;	/* height and width of the X display.        */
  unsigned int width, height;	/* height and width for the new window.      */
  char *display_name = getenv("DISPLAY");  /* address of the X display.      */
  GC gc;			/* GC (graphics context) used for drawing    */
				/*  in our window.			     */

  /* open connection with the X server. */
  display = XOpenDisplay(display_name);
  if (display == NULL) {
    fprintf(stderr, "%s: cannot connect to X server '%s'\n",
            argv[0], display_name);
    exit(1);
  }

  /* get the geometry of the default screen for our display. */
  screen_num = DefaultScreen(display);
  display_width = DisplayWidth(display, screen_num);
  display_height = DisplayHeight(display, screen_num);

  /* make the new window occupy 1/9 of the screen's size. */
  width = (display_width / 3);
  height = (display_height / 3);
  printf("window width - '%d'; height - '%d'\n", width, height);

  /* create a simple window, as a direct child of the screen's   */
  /* root window. Use the screen's white color as the background */
  /* color of the window. Place the new window's top-left corner */
  /* at the given 'x,y' coordinates.                             */
  win = create_simple_window(display, width, height, 0, 0);

  /* allocate a new GC (graphics context) for drawing in the window. */
  gc = create_gc(display, win, 0);
  XSync(display, False);

  {
    /* this variable will contain the ID of the newly created pixmap.    */
    Pixmap bitmap;
    /* these variables will contain the dimensions of the loaded bitmap. */
    unsigned int bitmap_width, bitmap_height;
    /* these variables will contain the location of the hotspot of the   */
    /* loaded bitmap.                                                    */
    int hotspot_x, hotspot_y;

    /* load the bitmap found in the file "icon.bmp", create a pixmap     */
    /* containing its data in the server, and put its ID in the 'bitmap' */
    /* variable.                                                         */
    int rc = XReadBitmapFile(display, win,
                             "icon.bmp",
                             &bitmap_width, &bitmap_height,
                             &bitmap,
                             &hotspot_x, &hotspot_y);
    /* check for failure or success. */
    switch (rc) {
        case BitmapOpenFailed:
            fprintf(stderr, "XReadBitmapFile - could not open file 'icon.bmp'.\n");
	    exit(1);
            break;
        case BitmapFileInvalid:
            fprintf(stderr,
                    "XReadBitmapFile - file '%s' doesn't contain a valid bitmap.\n",
                    "icon.bmp");
	    exit(1);
            break;
        case BitmapNoMemory:
            fprintf(stderr, "XReadBitmapFile - not enough memory.\n");
	    exit(1);
            break;
    }

    /* start drawing the given pixmap on to our window. */
    {
      int i, j;

      for(i=0; i<6; i++) {
        for(j=0; j<6; j++) {
          XCopyPlane(display, bitmap, win, gc,
                    0, 0,
                    bitmap_width, bitmap_height,
                    j*bitmap_width, i*bitmap_height,
                    1);
	  XSync(display, False);
	  usleep(100000);
        }
      }
    }
  }

  /* flush all pending requests to the X server. */
  XFlush(display);

  /* make a delay for a short period. */
  sleep(4);

  /* close the connection to the X server. */
  XCloseDisplay(display);
}
Exemplo n.º 22
0
int main(int argc, char *argv[])
{
	Display* display;
	int screen_num;
	Window win;
	unsigned int display_width,
				 display_height;
	unsigned int win_width,
				 win_height;
	char *display_name = getenv("DISPLAY"); 

	/*用于绘制的图形环境*/
	GC gc;			

	/*不同xlib函数的返回值,应该就是一个整数*/
	/*int rc;*/
	Status rc;			
	Pixmap bitmap;
	unsigned int bitmap_width, bitmap_height;
	int hotspot_x, hotspot_y;
	int i,j;


	display = XOpenDisplay(display_name);
	if (display == NULL)
	{
		fprintf(stderr, "%s: cannot connect to X server '%s'\n",
				argv[0], display_name);
		exit(1);
	}

	/******窗口的创建******/
	screen_num = DefaultScreen(display);
	display_width = DisplayWidth(display, screen_num);
	display_height = DisplayHeight(display, screen_num);
	win_width = (display_width / 3);
	win_height = (display_height / 3);
	win = create_simple_window(display, win_width, win_height, 0, 0);

	/******图形上下文的创建******/
	/*图形上下文环境,提供绘图环境包含前景色背景色线风格等各种属性*/
	gc = create_gc(display, win);

	/*这个函数刷新所有的输出缓存直至所有事件被Xserver收到并处理。
	 *输入参数为False将会不会忽略所有排队事件,
	 如果为True则忽略所有事件包括该函数调用之前的排队事件。
	 * */
	XSync(display, False);

	/******在这里开始绘图******/

	/*使用当前路径的icon.bmp文件,不是windows的bmp,它是个数组,和xpm格式也不同*/
	rc = XReadBitmapFile(display, win,
			"icon.bmp",
			&bitmap_width, &bitmap_height,
			&bitmap,
			&hotspot_x, &hotspot_y);

	/*xpm格式的文件无法读取*/
	/*rc = XReadBitmapFile(display, win,
	  "home.xpm",
	  &bitmap_width, &bitmap_height,
	  &bitmap,
	  &hotspot_x, &hotspot_y);*/
	/*如果读取文件错误的出错处理*/
	switch (rc)
	{
		case BitmapOpenFailed:
			fprintf(stderr, "XReadBitmapFile - could not open file 'icon.bmp'.\n");
			exit(1);
			break;
		case BitmapFileInvalid:
			fprintf(stderr,
					"XReadBitmapFile - file '%s' doesn't contain a valid bitmap.\n",
					"icon.bmp");
			exit(1);
			break;
		case BitmapNoMemory:
			fprintf(stderr, "XReadBitmapFile - not enough memory.\n");
			exit(1);
			break;
	}

	/*不用上面的方法,用下面的方法获得图片也行,这需要把icon.bmp包含成为头文件
	 * 这里面的icon_bitmap_bits就是这个icon.bmp对应的表示图像的数组
	 * 另外宽度和高度这里设成20,如果不是这个数,那么绘制出来的可能乱了*/
	/*bitmap_width  = 20;
	bitmap_height = 20;
	bitmap = XCreateBitmapFromData(display,
			                       win,
			                       icon_bitmap_bits,
			                       bitmap_width,
			                       bitmap_height);
	if (!bitmap)
	{
		    fprintf(stderr, "XCreateBitmapFromData - error creating pixmap\n");
		    exit(1);
	}
	*/


	/*这里绘制了36个图标*/
	for(i=0; i<6; i++)
	{
		for(j=0; j<6; j++)
		{
			/*这里在指定的window上面绘制图片,各个参数如下:
			 * bitmap指定绘制的源(矩形)
			 * win指定绘制的目标(矩形)
			 * gc图形上下文环境,提供绘图环境包含前景色背景色线风格等各种属性
			 * (0,0)表示相对于源的左上角坐标
			 * (bitmap_width,bitmap_height)表示绘制的大小
			 * (j*bitmap_width,i*bitmap_height)表示相对于目标的左上角坐标
			 * 1和色深位相关,不太清楚。
			 * */
			XCopyPlane(display, bitmap, win, gc,
					0, 0,
					bitmap_width, bitmap_height,
					j*bitmap_width, i*bitmap_height,
					1);
			/*刷新输出缓存直至所有的到X的请求被收到并处理
			 *这里如果传入参数False就不会忽略事件队列中的事件了*/
			XSync(display, False);//如果没有这句话不会动态一个个的绘制
			usleep(100000);
		}
	}


	 /*把所有的请求通知给X server,我尝试过了,不用这一句也行,因为前面有XSync*/
	 /*XFlush函数刷新输出缓存,由于输出缓存通过调用XPending,XNextEvent,XWinEvents
	 *根据需要会被自动刷新,大多数客户程序是不用调用它的。
	 *服务端发起的事件可能被放到库事件队列中的.
	 * */
	XFlush(display);


	/******延迟5秒后释放资源,结束程序******/
	sleep(10);
	XCloseDisplay(display);

	return 0;
}
Exemplo n.º 23
0
	int main(int argc, char **argv)
	{
		int i;
		Display *display;
		int screen_num;
		Window win;			//窗口ID
		unsigned int width, height;	//窗口尺寸
		unsigned int border_width = 4;	//边界空白
		unsigned int display_width, display_height;//屏幕尺寸
		int count;
		XEvent report;			//X 事件
		GC gc;				//GC
		unsigned long valuemask = 0;
		XGCValues values;
		char *display_name = NULL;
		Colormap default_cmap;		//缺省颜色表
		Cursor cursor;			//光标
		Pixmap bitmap;			//光标的pixmap
		unsigned int bitmap_width, bitmap_height;
		int hotspot_x, hotspot_y;	//光标的热点位置
		int rc;				//返回值
		XColor cursor_fg, cursor_bg;	//光标的颜色

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

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

		//获得屏幕的宽度和高度
		display_width = DisplayWidth(display, screen_num);
		display_height = DisplayHeight(display, screen_num);
		default_cmap = DefaultColormap(display, screen_num);

		//指定所建立窗口的宽度和高度
		//width = display_width/2;
		//height = display_height/2;
		width = 600;
		height = 400;

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

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

		//读入位图
		rc = XReadBitmapFile(display, win,
                             "icon.xbm",		//位图文件名
                             &bitmap_width, &bitmap_height,//返回位图尺寸
                             &bitmap,			//位图图像
                             &hotspot_x, &hotspot_y);	//热点
		switch (rc) {
        		case BitmapOpenFailed:
				printf("Cannot open file icon.xbm\n");
				exit(1);
			case BitmapFileInvalid:
				printf("bitmap file is not valid.\n");
				exit(1);
			case BitmapNoMemory:
				printf("No enough memory.\n");
			exit(1);
		}

		//分配颜色
		rc = XAllocNamedColor(display, default_cmap, 
			"red", &cursor_fg, &cursor_fg);
		if (rc == 0) { 
			printf("Canot allocate color.\n");
			exit(1);
		}
		rc = XAllocNamedColor(display, default_cmap,
                            "white", &cursor_bg, &cursor_bg);
		if (rc == 0) {
			printf("Canot allocate color\n");
			exit(1);
		}

		//建立光标
		cursor = XCreatePixmapCursor(display, 
			bitmap, 	//光标形状
			bitmap,		//掩码形状
			&cursor_fg, 	//前景色
			&cursor_bg,	//背景色
			5, 4);		//热点位置, 靠近左上方



                //让 window 使用光标
                XDefineCursor(display, win, cursor);

		XSync(display, False);

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

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

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

			//曝光事件, 窗口应重绘
			case Expose:
				//取得最后一个曝光事件
				if (report.xexpose.count != 0) break;
				draw(display, win, gc);
				break;

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

			//鼠标点击或有按键, 释放资源则退出
			case ButtonPress:
			case KeyPress:
				XFreeGC(display, gc);
				XCloseDisplay(display);
				exit(1);
			default:
				
				break;
			}
		}
	}
Exemplo n.º 24
0
static int bgi_0to2(char * window_name,char * icon_file)
{
	unsigned int    depth;
	XSizeHints	size_hints;
	char		*dsp_name = NULL;
	Pixmap icon_pixmap;
	XSetWindowAttributes setwinattr;   
	if((display = XOpenDisplay (dsp_name))==NULL) return -3;

	screen=DefaultScreen(display);
	cmap=DefaultColormap(display,screen);
	depth=DefaultDepth(display,screen);
	if((bgi_font=XLoadQueryFont(display,BGI_DEFAULT_FONT))==NULL)
	{
	   fprintf(stderr,"Warning Graphical font not found : %s\n",BGI_DEFAULT_FONT);
	   fprintf(stderr,"Font  \"fixed\" is used instead\n");
	   if((bgi_font=XLoadQueryFont(display,"fixed"))==NULL)
	   { fprintf(stderr,"Font \"fixed\" not found too. Program terminated\n");  
	     X_IO_Error_H(NULL);
	   }
	}

	if((text_font=XLoadQueryFont(display, BGI_TEXT_FONT))==NULL)
	{ 
	   fprintf(stderr,"Text font not found : %s\n",BGI_TEXT_FONT);
	   fprintf(stderr,"Font  \"fixed\" is used instead\n");
	   text_font=XLoadQueryFont(display,"fixed");
	}
	xw_fn_w=text_font->max_bounds.width;
	xw_fn_h=text_font->ascent+text_font->descent;
	isProportional=(xw_fn_w!=text_font->min_bounds.width);
	if (isProportional)
	{ 
	   fprintf(stderr, "\n Warning: Text font is proportional\n");
	}
	bgi_maxx=text_font->max_bounds.width*CRT_X-1;
	bgi_maxy=(text_font->ascent+text_font->descent)*CRT_Y-1;
	if(bgi_maxcolor && depth >= 3 )
	{
            bgi_maxcolor= (1 << depth)-1;
            if(bgi_maxcolor>15) bgi_maxcolor=15;
        }
	else  bgi_maxcolor=0;
	win=XCreateWindow(	display,
	    RootWindow(display,screen),
	    0,
	    0,
	    bgi_maxx+1,
	    bgi_maxy+1,
	    3,
	    depth,
	    InputOutput,
	    CopyFromParent,
	    0,
	    &setwinattr);

        {  int hx,hy;
           unsigned w,h;     
           if(XReadBitmapFile(display,win,icon_file,&w,&h,&icon_pixmap,&hx,&hy) 
              !=BitmapSuccess)icon_pixmap=None;
        }    
	size_hints.flags=PSize|PMinSize;
	size_hints.width=bgi_maxx+1;
	size_hints.height=bgi_maxy+1;
	size_hints.min_width=bgi_maxx+1;
	size_hints.min_height=bgi_maxy+1;
	XSetStandardProperties(	display,
	    win,
	    window_name,
	    window_name,
	    icon_pixmap,
	    NULL,
	    0,
	    &size_hints);
	XSelectInput( display,
	    win,
	    ExposureMask|
	    KeyPressMask|
	    StructureNotifyMask|
	    ButtonPressMask|
	    ButtonReleaseMask);

	XSetErrorHandler(X_Error_H);
	XSetIOErrorHandler(X_IO_Error_H);


	{  unsigned long valuemask = 0;
	   XGCValues values;
	   XEvent report;
	   gc=XCreateGC(display,win,valuemask,&values);
           XMapWindow(display,win);
           XMaskEvent(display,ExposureMask,&report) ;
        }

	XSetFont(display,gc,text_font->fid);
	XSetForeground(display,gc,BlackPixel(display,screen));  
        xw_graphic=0;          
        setallpalette();	
	XFillRectangle(display,win,gc,0,0,bgi_maxx+1,bgi_maxy+1);
	return 0;	
}
Exemplo n.º 25
0
Arquivo: icons.c Projeto: att/uwin
Bool GetBackPixmap(void)
{
#ifdef XPM
  XpmAttributes xpm_attributes;
  XpmImage my_image;
  Pixmap maskPixmap;
  int rc;
#endif
  char *path = NULL;
  Pixmap tmp_bitmap;
  int x, y, w=0, h=0;

  if (IconwinPixmapFile == NULL)
    return False;

  if ((path = findImageFile(IconwinPixmapFile, imagePath,R_OK)) != NULL){
    if (XReadBitmapFile(dpy, main_win ,path,(unsigned int *)&w,
			(unsigned int *)&h, &tmp_bitmap,
			(int *)&x, (int *)&y)!= BitmapSuccess)
      w = h = 0;
    else{
      IconwinPixmap = XCreatePixmap(dpy, main_win, w, h, Pdepth);
      XCopyPlane(dpy, tmp_bitmap, IconwinPixmap, NormalGC, 0, 0, w, h,
		 0, 0, 1);
      XFreePixmap(dpy, tmp_bitmap);
    }
    free(path);
  }

#ifdef XPM
  if ( w == 0 && h == 0 && (path = findImageFile(IconwinPixmapFile,
						imagePath,R_OK)) != NULL)
    {
      rc = XpmReadFileToXpmImage(path, &my_image, NULL);
      if (rc != XpmSuccess) {
        fprintf(stderr, "Problem reading pixmap %s, rc %d\n", path, rc);
        free(path);
        return False;
      }
      color_reduce_pixmap(&my_image,save_color_limit);
      xpm_attributes.visual = Pvisual;
      xpm_attributes.colormap = Pcmap;
      xpm_attributes.depth = Pdepth;
      xpm_attributes.closeness = 40000;    /* same closeness used elsewhere */
      xpm_attributes.valuemask =
	XpmVisual | XpmColormap | XpmDepth | XpmCloseness | XpmReturnPixels;
      rc = XpmCreatePixmapFromXpmImage(dpy, main_win, &my_image,
                                       &IconwinPixmap,
                                       &maskPixmap,
                                       &xpm_attributes);
      if (rc != XpmSuccess) {
        fprintf(stderr, "Problem creating pixmap from image, rc %d\n", rc);
        free(path);
        return False;
      }
      w = my_image.width;
      h = my_image.height;
      free(path);
    }
#endif
  if (w != 0 && h != 0)
    return True;
  return False;
}
Exemplo n.º 26
0
int main(int argc, char* argv[])
{
  Display* display;		/* pointer to X Display structure.           */
  int screen_num;		/* number of screen to place the window on.  */
  Window win;			/* pointer to the newly created window.      */
  unsigned int display_width,
               display_height;	/* height and width of the X display.        */
  unsigned int width, height;	/* height and width for the new window.      */
  char *display_name = getenv("DISPLAY");  /* address of the X display.      */
  GC gc;			/* GC (graphics context) used for drawing    */
				/*  in our window.			     */
  Cursor font_cursor,		/* handles for the cursors we will create.   */
         icon_cursor;

  /* open connection with the X server. */
  display = XOpenDisplay(display_name);
  if (display == NULL) {
    fprintf(stderr, "%s: cannot connect to X server '%s'\n",
            argv[0], display_name);
    exit(1);
  }

  /* get the geometry of the default screen for our display. */
  screen_num = DefaultScreen(display);
  display_width = DisplayWidth(display, screen_num);
  display_height = DisplayHeight(display, screen_num);

  /* make the new window occupy 1/9 of the screen's size. */
  width = (display_width / 3);
  height = (display_height / 3);
  printf("window width - '%d'; height - '%d'\n", width, height);

  /* create a simple window, as a direct child of the screen's   */
  /* root window. Use the screen's white color as the background */
  /* color of the window. Place the new window's top-left corner */
  /* at the given 'x,y' coordinates.                             */
  win = create_simple_window(display, width, height, 0, 0);

  /* allocate a new GC (graphics context) for drawing in the window. */
  gc = create_gc(display, win, 0);
  XSync(display, False);

  /* play with cursors... */
  {
    /* this variable will contain the ID of the newly created pixmap.    */
    Pixmap bitmap;
    /* these variables will contain the dimensions of the loaded bitmap. */
    unsigned int bitmap_width, bitmap_height;
    /* these variables will contain the location of the hotspot of the   */
    /* loaded bitmap.                                                    */
    int hotspot_x, hotspot_y;

    /* load the bitmap found in the file "icon.bmp", create a pixmap     */
    /* containing its data in the server, and put its ID in the 'bitmap' */
    /* variable.                                                         */
    int rc = XReadBitmapFile(display, win,
                             "icon.bmp",
                             &bitmap_width, &bitmap_height,
                             &bitmap,
                             &hotspot_x, &hotspot_y);
    /* check for failure or success. */
    switch (rc) {
        case BitmapOpenFailed:
            fprintf(stderr, "XReadBitmapFile - could not open file 'icon.bmp'.\n");
	    exit(1);
            break;
        case BitmapFileInvalid:
            fprintf(stderr,
                    "XReadBitmapFile - file '%s' doesn't contain a valid bitmap.\n",
                    "icon.bmp");
	    exit(1);
            break;
        case BitmapNoMemory:
            fprintf(stderr, "XReadBitmapFile - not enough memory.\n");
	    exit(1);
            break;
    }

    /* create a 'watch' cursor. */
    font_cursor = XCreateFontCursor(display, XC_watch);
    /* attach this cursor to our window. */
    XDefineCursor(display, win, font_cursor);
    XSync(display, False);

    /* make a short delay. */
    sleep(3);

    /* detach this cursor from our window. */
    XUndefineCursor(display, win);

    /* create a 'box' cursor. */
    font_cursor = XCreateFontCursor(display, XC_box_spiral);
    /* attach this cursor to our window. */
    XDefineCursor(display, win, font_cursor);
    XSync(display, False);

    /* make a short delay. */
    sleep(3);

    /* detach this cursor from our window. */
    XUndefineCursor(display, win);

    /* create a cursor out of our icon's pixmap. */
    {
      /* first, define forground and background colors for the cursor. */
      XColor cursor_fg, cursor_bg;

      /* access the default color map of our screen. */
      Colormap screen_colormap =
			DefaultColormap(display, DefaultScreen(display));

      /* allocate black and while colors. */
      Status rc = XAllocNamedColor(display,
                                   screen_colormap,
                                   "black",
                                   &cursor_fg,
                                   &cursor_fg);
      if (rc == 0) {
          fprintf(stderr, "XAllocNamedColor - canot allocate 'black' !\n");
          exit(1);
      }
      rc = XAllocNamedColor(display,
                            screen_colormap,
                            "white",
                            &cursor_bg,
                            &cursor_bg);
      if (rc == 0) {
          fprintf(stderr, "XAllocNamedColor - canot allocate 'white' !\n");
          exit(1);
      }

      /* finally, generate the cursor. make the 'hot spot' be close to the */
      /* top-left corner of the cursor - location (x=5, y=4). */
      icon_cursor = XCreatePixmapCursor(display, bitmap, bitmap,
				        &cursor_fg, &cursor_bg,
                                        5, 4);
    }

    /* attach the icon cursor to our window. */
    XDefineCursor(display, win, icon_cursor);
    XSync(display, False);

    /* make a short delay. */
    sleep(4);

    /* detach this cursor from our window. */
    XUndefineCursor(display, win);

    /* finally, free our icon pixmap. */
    XFreePixmap(display, bitmap);
  }

  /* flush all pending requests to the X server. */
  XFlush(display);

  /* make a delay for a short period. */
  sleep(4);

  /* close the connection to the X server. */
  XCloseDisplay(display);
  return(0);
}
Exemplo n.º 27
0
/*
 * Almost the same as XmGetPixmap() above, but this time the programmer can
 * even control the depth of the pixmap she/he wants.
 */
extern Pixmap
XmGetPixmapByDepth(Screen *screen, char *image_name, Pixel foreground, Pixel background, int depth)
{
    LTPixmapDescRec PixmapDesc;
    LTPixmapDesc PixmapValue;
    LTImageValue ImageDesc;

    int image_depth;

    char *pathname_to_pixmap;
    unsigned int bitmap_width, bitmap_height;
    int x_hot, y_hot;
    XImage *image;
    Pixmap new_pix, tmp, mask;
    GC gc;
    XGCValues values;
#ifdef NONSTANDARD_CONVERTERS
    XpmColorSymbol xpm_colour_symbols[3];
    XpmAttributes xpm_attrib;
#endif /* NONSTANDARD_CONVERTERS */

    values.foreground = foreground;
    values.background = background;

    if (PixmapCache == NULL)
    {
	LTSetupPixmapCache();
    }

    if (image_name == NULL)
    {
	return XmUNSPECIFIED_PIXMAP;
    }

    /*
     * First, we check the pixmap cache to see if such a pixmap is already
     * there. Therefore we fill in a pixmap description but only use the
     * first set of fields in the description structure. The second set will
     * contain information about the pixmap, if a pixmap, as described by the
     * first set, is already in the cache.
     */
    PixmapDesc.image_name = image_name;
    PixmapDesc.screen = screen;
    PixmapDesc.foreground = foreground;
    PixmapDesc.background = background;
    PixmapDesc.depth = depth;

    if (_LTHashTableLookupItem(PixmapCache, (LTHashItemID) & PixmapDesc,
			      (LTHashItemValue *) & PixmapValue))
    {
	/*
	 * There's a pixmap in the cache so we use it and increment its
	 * reference count.
	 */
	(PixmapValue->ref_count)++;

#if 0
	DEBUGOUT(_LtDebug0(__FILE__, NULL,
		"XmGetPixmapByDepth(scr %p, %s, dpy %p, fg %p, bg %p, d %d) -> %p, refcnt %d\n",
		screen, image_name, DisplayOfScreen(screen), foreground, background, depth,
		PixmapValue->pixmap, PixmapValue->ref_count));
#endif
	return PixmapValue->pixmap;
    }

    /*
     * Okay, we had no luck. Now check the image cache.
     */
    ImageDesc = LTGetImageFromCache(image_name);

    if (ImageDesc != NULL)
    {
	/*
	 * A match from the image cache. Now create the pixmap, add it to
	 * the cache, and return it.
	 */
	image = ImageDesc->image;

	if (image->format == XYBitmap)
	{
	    image_depth = 1;
	}
	else
	{
	    image_depth = image->depth;
	}

	/* create the pixmap */
	new_pix = _XmAllocScratchPixmap((XmScreen)XmGetXmScreen(screen),
					depth, image->width, image->height);

	tmp = _XmAllocScratchPixmap((XmScreen)XmGetXmScreen(screen),
				    depth, image->width, image->height);

	gc = XCreateGC(DisplayOfScreen(screen), tmp, 0, NULL);

	/* move the image information into a temporary pixmap */
	XPutImage(DisplayOfScreen(screen),
		  tmp,
		  gc,
		  image,
		  0, 0,
		  0, 0,
		  image->width, image->height);

	XFreeGC(DisplayOfScreen(screen), gc);

	values.foreground = background;
	values.background = foreground;

	gc = XCreateGC(DisplayOfScreen(screen), new_pix,
		       GCForeground | GCBackground, &values);

	if (image_depth == 1)
	{
	    XCopyPlane(DisplayOfScreen(screen),
		       tmp,
		       new_pix,
		       gc,
		       0, 0,
		       image->width, image->height,
		       0, 0,
		       1);
	}
	else
	{
	    XCopyArea(DisplayOfScreen(screen),
		      tmp,
		      new_pix,
		      gc,
		      0, 0,
		      image->width, image->height,
		      0, 0);
	}

	XFreeGC(DisplayOfScreen(screen), gc);

	/* add the pixmap to the cache */
	_LTAddPixmapToCache(image_name, new_pix, screen,
			   foreground, background, depth,
			   image->width, image->height,
			   ImageDesc->hot_x, ImageDesc->hot_y);

DEBUGOUT(_LtDebug0(__FILE__, NULL,
"XmGetPixmapByDepth(scr %p, %s, dpy %p, fg %p, bg %p, d %d) -> %p new\n",
screen, image_name, DisplayOfScreen(screen), foreground, background, depth,
new_pix));
	return new_pix;
    }

    /* since it wasn't in either cache, we search for the file */
    /* make sure the search path is there */
    if (!_search_path)
    {
	_LTCreateSearchPath();
    }

    if (image_name[0] == '/')	/* an absolute pathname */
    {
	pathname_to_pixmap = XtNewString(image_name);
    }
    else
    {
	SubstitutionRec subs[1];

	subs[0].match = 'B';
	subs[0].substitution = XtNewString(image_name);

	pathname_to_pixmap = XtResolvePathname(DisplayOfScreen(screen),
					       "bitmaps",
					       NULL,
					       NULL,
					       _search_path,
					       subs,
					       1,
					       NULL);
	XtFree(subs[0].substitution);
    }

    /* this breaks if X isn't where it's supposed to be. Don't dump core,
     * just return */
    if (pathname_to_pixmap == NULL || strlen(pathname_to_pixmap) == 0)
    {
	return XmUNSPECIFIED_PIXMAP;
    }

    DEBUGOUT(_LtDebug(__FILE__, NULL,
		      "pathname found is %s\n", pathname_to_pixmap));


    /* 
     * For 1.2 converting XPMs to pixmaps is an extension (standard
     * Motif dosen't read XPMs until version 2) so only do it if
     * NONSTANDARD_CONVERTERS is defined
     */
#ifdef NONSTANDARD_CONVERTERS
    /* Try for an XPM file, then a bitmap */
    /* Set up symbolic names for foreground & background colours */
    xpm_colour_symbols[0].name = "background";
    xpm_colour_symbols[0].value = 0;
    xpm_colour_symbols[0].pixel = background ;
    xpm_colour_symbols[1].name = "foreground";
    xpm_colour_symbols[1].value = 0;
    xpm_colour_symbols[1].pixel = foreground ;    
    xpm_colour_symbols[2].name = NULL;
    xpm_colour_symbols[2].value = "None";
    xpm_colour_symbols[2].pixel = background ;

    xpm_attrib.colorsymbols = xpm_colour_symbols;
    xpm_attrib.numsymbols = XtNumber(xpm_colour_symbols);
    xpm_attrib.depth = depth;
    xpm_attrib.closeness = 40000;
    xpm_attrib.valuemask = ( XpmSize | XpmReturnPixels | XpmColorSymbols
			     | XpmCloseness | XpmDepth );

    if (XpmReadFileToPixmap(DisplayOfScreen(screen),
                               RootWindowOfScreen(screen),
                               pathname_to_pixmap,
			       &new_pix, &mask,
			       &xpm_attrib) == XpmSuccess)
    {
	/* add the pixmap to the cache */
	_LTAddPixmapToCache(image_name, new_pix, screen,
			   foreground, background, depth,
			   xpm_attrib.width, xpm_attrib.height,
			   xpm_attrib.x_hotspot, xpm_attrib.y_hotspot);
    }
	else
#endif /* NONSTANDARD_CONVERTERS */

    if (XReadBitmapFile(DisplayOfScreen(screen),
			RootWindowOfScreen(screen),
			pathname_to_pixmap,
			&bitmap_width, &bitmap_height,
			&tmp, &x_hot, &y_hot) == BitmapSuccess)
    {
	new_pix = _XmAllocScratchPixmap((XmScreen)XmGetXmScreen(screen),
					depth, bitmap_width, bitmap_height);

	gc = XCreateGC(DisplayOfScreen(screen), new_pix,
		       GCForeground | GCBackground, &values);

	XCopyPlane(DisplayOfScreen(screen),
		   tmp,
		   new_pix,
		   gc,
		   0, 0,
		   bitmap_width, bitmap_height,
		   0, 0,
		   1);

	XFreeGC(DisplayOfScreen(screen), gc);

	/* add the pixmap to the cache */
	_LTAddPixmapToCache(image_name, new_pix, screen,
			   foreground, background, depth,
			   bitmap_width, bitmap_height,
			   0, 0 /* FIX ME! hot_x, hot_y! */ );

    }
    else
    {
	_XmWarning(NULL, "Couldn't load the pixmap %s.\n", pathname_to_pixmap);
	new_pix = XmUNSPECIFIED_PIXMAP;
    }

    XtFree(pathname_to_pixmap);
DEBUGOUT(_LtDebug0(__FILE__, NULL,
"XmGetPixmapByDepth(scr %p, %s, dpy %p, fg %p, bg %p, d %d) -> %p new2\n",
screen, image_name, DisplayOfScreen(screen), foreground, background, depth,
new_pix));
    return new_pix;
}
Exemplo n.º 28
0
Arquivo: draw.c Projeto: dylex/dzen
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;
}