示例#1
0
/* convert the XPMIcons to XImage */
void GetXPM(void)
{
  static char **alt_xpm;
  XColor col;
  XWindowAttributes attributes;
  int ret;
  char tempc1[12],tempc2[12],tempc3[12];
  float colr,colg,colb;

  alt_xpm =ONLYSHAPE ? mask_xpm : back_xpm;

  /* for the colormap */
  XGetWindowAttributes(dpy,Root,&attributes);

  /* get user-defined color or validate the default */
  if (!XParseColor (dpy, attributes.colormap, LedColor, &col))
    {
      nocolor("parse",LedColor);
    }
  else
    {
      /* scale down the Xcolor values */
      colr = col.red   / 257;
      colg = col.green / 257;
      colb = col.blue  / 257;
      /* the brightest color */
      sprintf(tempc1, "S c #%.2x%.2x%.2x", (int)colr, (int)colg, (int)colb);
      back_xpm[47] = tempc1;

      /* make medium color */
      colr = (colr /100) *89;
      colg = (colg /100) *89;
      colb = (colb /100) *89;
      sprintf(tempc2, "R c #%.2x%.2x%.2x", (int)colr, (int)colg, (int)colb);
      back_xpm[46] = tempc2;

      /* make darkest color */
      colr = (colr /100) *89;
      colg = (colg /100) *89;
      colb = (colb /100) *89;
      sprintf(tempc3, "Q c #%.2x%.2x%.2x", (int)colr, (int)colg, (int)colb);
      back_xpm[45] = tempc3;
    }

  wmload.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions);
  ret = XpmCreatePixmapFromData(dpy, Root, alt_xpm, &wmload.pixmap,
				&wmload.mask, &wmload.attributes);
  if(ret != XpmSuccess)
    {fprintf(stderr, "%s\n", ERR_colorcells);exit(1);}

  visible.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions);
  ret = XpmCreatePixmapFromData(dpy, Root, back_xpm, &visible.pixmap,
				&visible.mask, &visible.attributes);
  if(ret != XpmSuccess)
    {fprintf(stderr, "%s\n", ERR_colorcells);exit(1);}

}
示例#2
0
SetupButtons()
{
  XWindowAttributes root_attr;
  XpmAttributes xpm_attributes;

  XGetWindowAttributes(dpy, Scr.Root, &root_attr);
  xpm_attributes.colormap = root_attr.colormap;
  xpm_attributes.closeness = 40000;
  xpm_attributes.valuemask =
      XpmSize | XpmReturnPixels | XpmColormap | XpmCloseness;

  if (XpmCreatePixmapFromData(dpy, Scr.Root, sysmenu_xpm,
			      &Scr.button_pixmap[0], &Scr.button_mask[0],
			      &xpm_attributes) != XpmSuccess) {
    fvwm_msg(ERR, "SetupButtons", "Can't make system menu button");
    return;
  }

  if (XpmCreatePixmapFromData(dpy, Scr.Root, close_xpm,
			      &Scr.button_pixmap[1], &Scr.button_mask[1],
			      &xpm_attributes) != XpmSuccess) {
    fvwm_msg(ERR, "SetupButtons", "Can't make close button");
    return;
  }

  if (XpmCreatePixmapFromData(dpy, Scr.Root, normalize_xpm,
			      &Scr.button_pixmap[2], &Scr.button_mask[2],
			      &xpm_attributes) != XpmSuccess) {
    fvwm_msg(ERR, "SetupButtons", "Can't make maximized-state button");
    return;
  }

  if (XpmCreatePixmapFromData(dpy, Scr.Root, maximize_xpm,
			      &Scr.button_pixmap[3], &Scr.button_mask[3],
			      &xpm_attributes) != XpmSuccess) {
    fvwm_msg(ERR, "SetupButtons", "Can't make maximize button");
    return;
  }

  if (XpmCreatePixmapFromData(dpy, Scr.Root, minimize_xpm,
			      &Scr.button_pixmap[5], &Scr.button_mask[5],
			      &xpm_attributes) != XpmSuccess) {
    fvwm_msg(ERR, "SetupButtons", "Can't make minimize button");
    return;
  }

  Scr.button_width = xpm_attributes.width + 3;
  Scr.button_height = xpm_attributes.height + 3;
}
示例#3
0
void CreateDock(int argc, char *argv[])    /* this part comes from http://www.linuxmag-france.org/ */
{
   Window root;
   XWMHints wmHints;
   XSizeHints sizeHints;
   XClassHint classHint;
   Pixmap pixmask;
   unsigned long p_blanc;
   unsigned long p_noir;
   unsigned int borderWidth = 2;
   char *wname = argv[0] ;

   dpy = XOpenDisplay(NULL) ;

   if(dpy == NULL)
	  {
	     fprintf(stderr, "Can't open display\n") ;
	     exit(1) ;
	  }

   root = RootWindow(dpy,screen);
   p_blanc = WhitePixel(dpy,screen) ;
   p_noir = BlackPixel(dpy,screen) ;
   gc = XDefaultGC(dpy,screen) ;
   XSetForeground(dpy, gc, p_noir);
   XSetBackground(dpy, gc,p_noir);

   sizeHints.x = 0 ;
   sizeHints.y = 0 ;
   sizeHints.width = 64 ;
   sizeHints.height = 64 ;

   win = XCreateSimpleWindow(dpy,root,sizeHints.x,sizeHints.y , sizeHints.width, sizeHints.height, borderWidth, p_noir,p_noir) ;
   iconWin = XCreateSimpleWindow(dpy,root,sizeHints.x,sizeHints.y,sizeHints.width, sizeHints.height, borderWidth, p_noir,p_noir ) ;

   sizeHints.flags = USSize | USPosition ;
   XSetWMNormalHints(dpy,win,&sizeHints) ;
   wmHints.initial_state = WithdrawnState ;
   wmHints.icon_window = iconWin ;
   wmHints.icon_x = sizeHints.x ;
   wmHints.icon_y = sizeHints.y ;
   wmHints.window_group = win ;
   wmHints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint ;
   XSetWMHints(dpy, win, &wmHints) ;
   classHint.res_name = wname ;
   classHint.res_class = wname ;

   XSetClassHint(dpy, win, &classHint) ;
   XSetCommand(dpy,win, argv, argc) ;

   pixmask = XCreateBitmapFromData(dpy,win,fond_bits, fond_width, fond_height) ;
   XShapeCombineMask(dpy,win,ShapeBounding,0,0,pixmask,ShapeSet) ;
   XShapeCombineMask(dpy,iconWin,ShapeBounding, 0, 0, pixmask, ShapeSet) ;
   XpmCreatePixmapFromData(dpy,root,wmAppKill_xpm, &XPM, NULL,NULL) ;

   XSelectInput(dpy,win, ExposureMask | ButtonPressMask) ;
   XSelectInput(dpy,iconWin, ExposureMask | ButtonPressMask) ;

   XMapWindow(dpy,win) ;
}
示例#4
0
static void GetXPM (XpmIcon * wmgen, char *pixmap_bytes[])
{

  XWindowAttributes attributes;
  int err;

  /* For the colormap */
  XGetWindowAttributes (display, Root, &attributes);

  wmgen->attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions);

  wmgen->attributes.closeness = 40000;
  wmgen->attributes.valuemask |= XpmCloseness;
  
  if (textColor)
  {
    colorSymbols[0].pixel = GetColor (textColor);
    wmgen->attributes.colorsymbols = colorSymbols;
    wmgen->attributes.numsymbols = 1;
    wmgen->attributes.valuemask |= XpmColorSymbols;
  }


  err = XpmCreatePixmapFromData (display, Root, pixmap_bytes, &(wmgen->pixmap),
				 &(wmgen->mask), &(wmgen->attributes));

  if (err != XpmSuccess)
    {
      fprintf (stderr, "Not enough free colorcells.\n");
      exit (1);
    }
}
示例#5
0
Pixmap XcodaCreatePixmapFromXpm(Widget parent,
				const char** data,
				int    type)
{
  Display        *dpy = XtDisplay(parent);
  Window         win = XDefaultRootWindow(dpy);
  Screen         *scr = XDefaultScreenOfDisplay(dpy);
  int            depth = DefaultDepthOfScreen(scr);
  Colormap       cmap = DefaultColormapOfScreen(scr);
  XpmAttributes  attr;
  unsigned int  valuemask = 0;
  int            err;

  /*unsigned int  pixmap_ret, pixmap_mask;*/
  Pixmap pixmap_ret, pixmap_mask;

  XpmColorSymbol col_symbol[1];
  Arg            arg[5];
  int            ac = 0;
  Pixel          parent_bg;

  if(type){ /* normal background for pixmap */
    XtSetArg (arg[ac], XmNbackground, &parent_bg); ac++;
    XtGetValues (parent, arg, ac);
    ac = 0;
  }
  else{  /* inverted or highlighted pixmap */
    XtSetArg (arg[ac], XmNforeground, &parent_bg); ac++;
    XtGetValues (parent, arg, ac);
    ac = 0;
  }    
  col_symbol[0].name = (char *)NULL;
  col_symbol[0].value = (char *)malloc((strlen("LightBlue")+1)*sizeof(char));
  strcpy(col_symbol[0].value,"LightBlue");
  col_symbol[0].pixel = parent_bg;
  
  attr.colormap = cmap;
  attr.depth = depth;
  attr.colorsymbols = col_symbol;
  attr.valuemask = valuemask;
  attr.numsymbols = 1;
  attr.closeness = 65536;
  
  attr.valuemask |= XpmReturnPixels;
  attr.valuemask |= XpmColormap;
  attr.valuemask |= XpmColorSymbols;
  attr.valuemask |= XpmDepth;
  attr.valuemask |= XpmCloseness;
  /*
  printf("Calling XpmCreatePixmapFromData ...\n");
  */
  err = XpmCreatePixmapFromData(dpy, win, (char **)data, &pixmap_ret, &pixmap_mask, &attr);
  
  free (col_symbol[0].value);
  if(err != XpmSuccess){
    pixmap_ret = 0;
  }

  return pixmap_ret;
}
示例#6
0
Pixmap CreatePPPOFFPixmap(void)
{
    int
        rc;

    XpmAttributes
        xpmatts;

    Pixmap
        mask,
        pix;

    mask=(Pixmap) NULL;
    xpmatts.closeness=65536;
    xpmatts.valuemask = XpmSize | XpmCloseness;

    rc=XpmCreatePixmapFromData(GetDisplay(),GetrootWindow(),
        pppoff_xpm,
        &pix,
        &mask,
        &xpmatts);

    if (mask != (Pixmap) NULL)
        XFreePixmap(GetDisplay(),mask);

    if (rc != XpmSuccess)
        return ((Pixmap) NULL);

    return(pix);
}
示例#7
0
void MpButton::AddIcon (const char *pxmap[], int align, bool bitmask)
{
  // remove possible previous icon
  DeleteIcon();

  // allocate pixmap
  int status = XpmCreatePixmapFromData(Mp.theDisplay, Win(), 
				       (char**) pxmap,
				       &pixmap, 
				       (bitmask) ? &mask : NULL, 
				       NULL); 
  if (status)      
    Mp.Warn("MpButton::AddIcon(XPM): Can't allocate icon pixmap");
  else {

    // parse size
    long w, h;
    char *endptr,*dummy;
    w = strtol(pxmap[0],&endptr,10);
    h = strtol(endptr,&dummy,10);

    // remember size
    icon_width  = short(w);
    icon_height = short(h);
    // remember alignment
    if (align & AlignLeft) 
      state |= icon_align_left;
    else if (align & AlignRight)
      state |= icon_align_right;
  }
}
示例#8
0
static void setup_window_hints_and_icon(Display* dpy, Window win, Window parent, const int maxsize) {
	XTextProperty	x_wname, x_iname;
	XSizeHints	hints;
	XWMHints	wmhints;
	char *w_name ="xjadeo";
	char *i_name ="xjadeo";

	/* default settings which allow arbitraray resizing of the window */
	hints.flags = PSize | PMaxSize | PMinSize;
	hints.min_width = 32;
	hints.min_height = 18;
	hints.max_width = maxsize;
	hints.max_height = maxsize;

	wmhints.input = True;
	XpmCreatePixmapFromData(dpy, parent, xjadeo8_xpm, &wmhints.icon_pixmap, &wmhints.icon_mask, NULL);
	wmhints.flags = InputHint | IconPixmapHint | IconMaskHint;

	if (XStringListToTextProperty (&w_name, 1, &x_wname) &&
			XStringListToTextProperty (&i_name, 1, &x_iname))
	{
		XSetWMProperties (dpy, win, &x_wname, &x_iname, NULL, 0, &hints, &wmhints, NULL);
		XFree (x_wname.value);
		XFree (x_iname.value);
	}
}
示例#9
0
int main(int argc, char **argv)
{
    XEvent   msg;
    XSetWindowAttributes xswa;
    XWMHints wmhints;
    Pixmap icon;
    const long evt_mask = ExposureMask | ButtonPressMask | ButtonReleaseMask | StructureNotifyMask | PointerMotionMask;

    dpy=XOpenDisplay(NULL);
    if (!dpy) {
        fprintf(stderr, "Could not open X11 display.\n");
        return 1;
        }

    scr = DefaultScreen(dpy);

    /* Create the main window and display it */
    wnd = XCreateSimpleWindow(dpy, RootWindow(dpy,scr), 0,0,400,400,0,
                              WhitePixel(dpy,scr), BlackPixel(dpy,scr));
    xswa.backing_store = Always;
    //  XChangeWindowAttributes(dpy, wnd, CWBackingStore, &xswa);

    if(!wnd){
        fprintf(stderr, "Window creation failed !\n");
        return 1;
        }

    XpmCreatePixmapFromData(dpy, wnd, mgldog_xpm, &icon, NULL, NULL);
    wmhints.icon_pixmap = icon;
    wmhints.flags = IconPixmapHint;
    XSetWMHints(dpy, wnd, &wmhints);

    /* Initialise the MGL */
    InitMGL();

    XSelectInput(dpy, wnd, evt_mask);
    XMapRaised(dpy,wnd);
    XStoreName(dpy,wnd,szAppName);
    XSync(dpy, false);


    MGL_bitBltCoord(winDC,memDC,0,0,sizex,sizey,0,0,MGL_REPLACE_MODE);
    /* Polling messages from event queue */
    for(;;) {
        XNextEvent(dpy, &msg);
        // XWindowEvent(dpy, wnd, evt_mask, &msg);
        ProcessEvent(wnd, &msg);
        }

    /* Clean up the MGL before exit */
    MGL_exit();
    XCloseDisplay(dpy);
    return 0;
}
示例#10
0
/****************************************************************************
 *
 * Looks for a color XPM icon file
 *
 ****************************************************************************/
void GetXPMData(char **data)
{
  view.attributes.valuemask = XpmReturnPixels| XpmCloseness | XpmExtensions;
  view.attributes.closeness = 40000 /* Allow for "similar" colors */;
  if(XpmCreatePixmapFromData(dpy, Root, data,
                             &view.pixmap, &view.mask,
                             &view.attributes)!=XpmSuccess)
  {
    fprintf(stderr,"FvwmBanner: ERROR couldn't convert data to pixmap\n");
    exit(1);
  }
}
示例#11
0
void ReadIcon(char *pixData[], int iconNr)
{
    int r;

	if ((r=XpmCreatePixmapFromData(xDisplay, XtWindow(outputField[0][nColorIcon]),
				       pixData,
				       &(icons[iconNr]),
				       NULL, NULL /*&attr*/)) != 0) {
	  fprintf(stderr, _("Error %d loading icon image\n"), r);
	  exit(1);
	}
}
示例#12
0
static void
set_ctt_window_shape_and_background(Display *dpy, Window ctt_window,
				    unsigned long ctt_attribute_mask,
				    XSetWindowAttributes *ctt_attributes) {
  Pixmap ctt_xpm, ctt_shape;
  XpmCreatePixmapFromData(dpy, ctt_window, atcttxpm, &ctt_xpm, &ctt_shape,
			  NULL /* Attributes; IIRC, we don't need this. */);
  ctt_attribute_mask |= CWBackPixmap;
  ctt_attributes->background_pixmap = ctt_xpm;
  XChangeWindowAttributes(dpy, ctt_window, ctt_attribute_mask, ctt_attributes);
  XShapeCombineMask(dpy, ctt_window, ShapeBounding, 0, 0, ctt_shape, ShapeSet);
}
示例#13
0
static void DrawTray(winlist_t *win)
{
    XpmAttributes attributes;
    Pixmap tray, mask, shapemask;
    GC shapegc, traygc;
    attributes.valuemask = 0;
    XpmCreatePixmapFromData(gui->display, win->window,
			oxim_tray, &tray, &mask, &attributes);

    tray_w = attributes.width;
    tray_h = attributes.height;

    shapemask = XCreatePixmap(gui->display, win->window,
			win->width , win->height , 1);

    traygc = XCreateGC(gui->display, tray, 0, 0);
    shapegc = XCreateGC(gui->display, shapemask, 0, 0);

    XFillRectangle(gui->display, shapemask, shapegc, 0, 0,
		win->width, win->height);

    int sw = (win->width - tray_w) / 2;
    int sh = (win->height - tray_h) / 2;
    int new_x = (sw > 0) ? sw : 0;
    int new_y = (sh > 0) ? sh : 0;

    if (mask)
    {
	XCopyArea(gui->display, mask, shapemask, shapegc, 0, 0,
		tray_w, tray_h, new_x, new_y);
	XFreePixmap(gui->display, mask);
    }
    else
    {
	XSetForeground(gui->display, shapegc, 1);
	XFillRectangle(gui->display, shapemask, shapegc, new_x, new_y,
		tray_w, tray_h);
    }

    XShapeCombineMask(gui->display, win->window, ShapeBounding,
		0, 0, shapemask, ShapeSet);
/*    XShapeCombineMask(gui->display, win->window, ShapeClip,
		0, 0, shapemask, ShapeSet);*/
    XCopyArea(gui->display, tray, win->window, traygc, 0, 0,
		win->width, win->height, new_x, new_y);

    XpmFreeAttributes(&attributes);
    XFreePixmap(gui->display, tray);
    XFreePixmap(gui->display, shapemask);
    XFreeGC(gui->display, shapegc);
    XFreeGC(gui->display, traygc);    
}
示例#14
0
void UserInterface::loadAppIcon()
{
    fl_open_display(); // needed if display has not been previously opened

    Pixmap p, mask;
    XpmCreatePixmapFromData(fl_display, DefaultRootWindow(fl_display),
                                     (char**)icon_xpm, &p, &mask, NULL);

//    Pixmap p = XCreateBitmapFromData(fl_display, DefaultRootWindow(fl_display),
//                                     (char const *)icon_bits, icon_width, icon_height);

    mainWindow_->icon((const void *)p);
}
示例#15
0
void
gui_init (void)
{
	XGCValues gcv;
	XColor xcl;
	unsigned int i;
#ifndef XFT
	char *fontname;
#endif

	i = 0;
	do
	{
		xcl.red = cols[i].red;
		xcl.green = cols[i].green;
		xcl.blue = cols[i].blue;
		XAllocColor (dd, DefaultColormap (dd, scr_screen), &xcl);
		palette[i] = xcl.pixel;
		i++;
	}
	while (i < PALETTE_COUNT);

#ifdef XFT
	xfs = XftFontOpenName (dd, scr_screen, XFT_FONT);
#else
	fontname = FONT_NAME;
	do
	{
		xfs = XLoadQueryFont (dd, fontname);
		fontname = "fixed";
	}
	while (!xfs);
#endif

	gcv.graphics_exposures = False;
#ifdef XFT
	text_y = xfs->ascent + ((WINHEIGHT - (xfs->ascent + xfs->descent)) / 2);
	fore_gc = XCreateGC (dd, root_win, GCGraphicsExposures, &gcv);
#else
	text_y = xfs->ascent + ((WINHEIGHT - xfs->ascent) / 2);
	gcv.font = xfs->fid;
	fore_gc = XCreateGC (dd, root_win, GCFont | GCGraphicsExposures, &gcv);
#endif

#ifdef HAVE_XPM
	XpmCreatePixmapFromData (dd, root_win, icon_xpm, &generic_icon,
									 &generic_mask, NULL);
#else
	generic_icon = 0;
#endif
}
示例#16
0
void gu_setFavicon(Fl_Window *w) {
#if defined(__linux__)
	fl_open_display();
	Pixmap p, mask;
	XpmCreatePixmapFromData(
		fl_display,
		DefaultRootWindow(fl_display),
		(char **)giada_icon,
		&p,
		&mask,
		NULL);
	w->icon((char *)p);
#elif defined(_WIN32)
	w->icon((char *)LoadIcon(fl_display, MAKEINTRESOURCE(IDI_ICON1)));
#endif
}
示例#17
0
TPixmap::TPixmap(const char** xpmData)
	:	fPixmap(0),
		fMask(0)
{
	XpmAttributes	attributes;
	attributes.valuemask = XpmCloseness;
	attributes.closeness = 40000;
	
   int result = XpmCreatePixmapFromData(gApplication->GetDisplay(), gApplication->GetRootWindow(),
   									(char **)xpmData, &fPixmap, &fMask, &attributes);
   	ASSERT(result == 0);
   	
   	// Fill out TDrawable values
   	fBounds.right = attributes.width;
   	fBounds.bottom = attributes.height;
   	fDepth = 0;	// fix me
}
示例#18
0
static void DrawTrayExtend(winlist_t *win)
{
    Pixmap tray, dummy;
    XpmAttributes attr;
    attr.valuemask = 0;
    XpmCreatePixmapFromData(gui->display, win->window,
			oxim_tray, &tray, &dummy, &attr);

    int tray_w = attr.width;
    int tray_h = attr.height;
    int w = win->width;
    int h = win->height;
    int x=0, y=0;
    int offset_y = h/2 - tray_h/2;
    
    Picture trayw, mask, icon;
    
    XWindowAttributes attrs;

    XGetWindowAttributes( gui->display, win->window , &attrs );
    XRenderPictFormat*  format = XRenderFindVisualFormat( gui->display, attrs.visual );

    XRenderPictFormat *pformat = XRenderFindStandardFormat( gui->display, PictStandardA1 );
    XRenderPictFormat *pformat2 = XRenderFindStandardFormat( gui->display, PictStandardRGB24 );

    XRenderPictureAttributes pattrs;

    trayw = XRenderCreatePicture(gui->display, win->window,
	    format, 0, NULL);

    mask = XRenderCreatePicture(gui->display, icon_mask,
	    pformat, 0, NULL);

    pattrs.alpha_map = mask;
    icon = XRenderCreatePicture(gui->display, picon,
	    pformat2, CPAlphaMap, &pattrs);

    XRenderComposite(gui->display, PictOpOver, icon, None, trayw, 
	    x,y-offset_y , x,y,x,y,w,h);
    XRenderFreePicture(gui->display,trayw);
    XRenderFreePicture(gui->display,mask);
    XRenderFreePicture(gui->display,icon);
    XFreePixmap(gui->display,tray);
    if(dummy)
	XFreePixmap(gui->display,dummy);
}
示例#19
0
static void GetXPM(XpmIcon *wmgen, char *pixmap_bytes[]) {

	XWindowAttributes	attributes;
	int					err;

	/* For the colormap */
	XGetWindowAttributes(display, Root, &attributes);

	wmgen->attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions);

	err = XpmCreatePixmapFromData(display, Root, pixmap_bytes, &(wmgen->pixmap),
					&(wmgen->mask), &(wmgen->attributes));

	if (err != XpmSuccess) {
		fprintf(stderr, "Not enough free colorcells.\n");
		exit(1);
	}
}
示例#20
0
文件: dockapp.c 项目: yogsothoth/wmmp
Bool
dockapp_xpm2pixmap(char **data, Pixmap *pixmap, Pixmap *mask,
		   XpmColorSymbol * colorSymbol, unsigned int nsymbols)
{
    XpmAttributes xpmAttr;
    xpmAttr.valuemask = XpmCloseness;
    xpmAttr.closeness = 40000;

    if (nsymbols) {
	xpmAttr.colorsymbols = colorSymbol;
	xpmAttr.numsymbols = nsymbols;
	xpmAttr.valuemask |= XpmColorSymbols;
    }

    if (XpmCreatePixmapFromData(display, icon_window, data, pixmap, mask, &xpmAttr) != 0)
	return False;

    return True;
}
示例#21
0
Bool ProcessTrayIcon(char** data, XImage** image, Pixmap* pixmapshape, Pixmap* pixmap)
{
	XImage* dummy = NULL;
	XpmAttributes attr;
	attr.valuemask = XpmColormap | XpmDepth | XpmCloseness;
	attr.colormap = DefaultColormap(dpy, iScreen);
	attr.depth = DefaultDepth(dpy, iScreen);
	attr.closeness = 40000;
	attr.exactColors = False;
	if (XpmCreateImageFromData(dpy, data, image, &dummy, &attr))
		return False;
	if (XpmCreatePixmapFromData(dpy, tray.window,data, pixmap,
				pixmapshape, &attr))
		return False;
	if (dummy)
		XDestroyImage(dummy);

	return True;
}
示例#22
0
static void set_initial_icon(Display *x11display, Window window)
{
#ifdef ALLEGRO_XWINDOWS_WITH_XPM
   XWMHints *wm_hints;

   if (x11_xpm == NULL)
      return;

   wm_hints = XAllocWMHints();

   wm_hints->flags |= IconPixmapHint | IconMaskHint;
   XpmCreatePixmapFromData(x11display, window, x11_xpm,
      &wm_hints->icon_pixmap, &wm_hints->icon_mask, NULL);

   XSetWMHints(x11display, window, wm_hints);
   XFree(wm_hints);
#else
   (void)x11display;
   (void)window;
#endif
}
示例#23
0
static void
CreateIconFromXpmData( char *pixmap_data[] )
{
  int status;

  dockapp.xpm_icon.attributes.valuemask |=
    ( XpmReturnPixels | XpmReturnExtensions );

  /* Using the XPM library to read XPM data from the array in the included XPM
     file. The 'shapemask' Pixmap variable is set to an additional 1-bit deep
     pixmap that can then be used as a shape mask for the XShapeCombineMask()
     function. */
  status = XpmCreatePixmapFromData( dockapp.display, dockapp.root_win,
				    pixmap_data, &dockapp.xpm_icon.image,
				    &dockapp.xpm_icon.shapemask,
				    &dockapp.xpm_icon.attributes );
  if( status != XpmSuccess ) {
    fprintf( stderr, "%s: XpmCreatePixmapFromData() failed\n", PACKAGE );
    ErrorLocation( __FILE__, __LINE__ );
    exit( EXIT_FAILURE );
  }
}
示例#24
0
void readBitmaps(void)
{
  int i, scrn;
  Colormap cmp;
  Window win;
  XColor black, white;
  XpmAttributes xpm_attr;
  static XpmColorSymbol none_color = { NULL, "None", (Pixel)0 };
  IconRec cursor;

  win = DefaultRootWindow(dpy);
  scrn = DefaultScreen(dpy);
  cmp = DefaultColormap(dpy, scrn);

  black.pixel = BlackPixel(dpy, scrn);
  XQueryColor(dpy, cmp, &black);
  white.pixel = WhitePixel(dpy, scrn);
  XQueryColor(dpy, cmp, &white);

  icons = (IconRec *) XtMalloc(END_BM * sizeof(IconRec));

  /* create the hardcoded cursor */

  cursor.bm = XCreateBitmapFromData(dpy, win, bitmaps[0].bits, bitmaps[0].width, bitmaps[0].height);
  cursor.mask = XCreateBitmapFromData(dpy, win, bitmaps[1].bits, bitmaps[1].width, bitmaps[1].height);
  cur = XCreatePixmapCursor(dpy, cursor.bm, cursor.mask, &black, &white, 16, 16);

  xpm_attr.valuemask = XpmReturnPixels | XpmColorSymbols | XpmCloseness;
  xpm_attr.colorsymbols = &none_color;
  xpm_attr.numsymbols = 1;
  xpm_attr.closeness = CLOSENESS;
  none_color.pixel = winInfo.background;
  for (i=0; i<END_BM; i++)
  {
      XpmCreatePixmapFromData(dpy, win, pixmaps[i], &icons[i].bm, &icons[i].mask, &xpm_attr);
      icons[i].width = xpm_attr.width;
      icons[i].height = xpm_attr.height;
  }
}
示例#25
0
文件: x11wm.c 项目: mohaslan/libwm
struct wm_window* create_parent_window(struct wm_window *child) {
	GC gc;
	XGCValues values;
	struct wm_window *parent_win = (struct wm_window *)malloc(sizeof(struct wm_window));
	XColor bg_color;
	bg_color.red = 0 * 256;
	bg_color.green = 100 * 256;
	bg_color.blue = 150 * 256;
	XAllocColor(wm.display, DefaultColormap(wm.display, wm.screen), &bg_color);
	parent_win->win = XCreateSimpleWindow(wm.display, DefaultRootWindow(wm.display), 0, 0, 600, 600, 0, bg_color.pixel, bg_color.pixel);
	wm_window_resize(&wm, child, 590, 570);

	int w, h;
	w = 100 + rand()%screen_width - (child->width + 20);
	h = 100 + rand()%screen_height - (child->height + 20);
	w = w >= 0 ? w : 0;
	h = h >= 0 ? h : 0;
	printf("::: %d %d\n", w, h);
	wm_window_move(&wm, parent_win, w, h);
	wm_window_show(&wm, parent_win);

   	gc = XCreateGC(wm.display, parent_win->win, None, &values);
	XSetLineAttributes(wm.display, gc,  2, LineSolid, CapButt, JoinRound);
	XDrawString(wm.display, parent_win->win, gc, 20, 20, child->title, strlen(child->title));

	Pixmap exit_icon, mask;
	XpmAttributes xpm_attr;
	XpmCreatePixmapFromData(wm.display, parent_win->win, exit_icon_xpm, &exit_icon, &mask, &xpm_attr);
	GC gc2;
	XGCValues values2;
       	gc2 = XCreateGC(wm.display, parent_win->win, None, &values2);
	XSetClipMask(wm.display, gc2, mask);
	// XcopyArea() server-side should be faster than XPutImage() client-side 
	XSetClipOrigin(wm.display, gc2, 600-xpm_attr.width, 0);
	XCopyArea(wm.display, exit_icon, parent_win->win, gc2, 0, 0, xpm_attr.width, xpm_attr.height, 600-xpm_attr.width, 0);

	return parent_win;
}
示例#26
0
static void set_titlebar_icon(Fl_Window* ww) {
#ifdef HAVE_LIBXPM
	/* it can be safely casted to our Window class */
	Window* win = (Window*)ww;

	if(!win->window_icon())
		return;

	Pixmap pix, mask;
	XpmCreatePixmapFromData(fl_display, DefaultRootWindow(fl_display), (char**)win->window_icon(), &pix, &mask, NULL);

	XWMHints* hints = XGetWMHints(fl_display, fl_xid(win));
	if(!hints)
		return;

	hints->icon_pixmap = pix;
	hints->icon_mask = mask;
	hints->flags |= IconPixmapHint | IconMaskHint;

	XSetWMHints(fl_display, fl_xid(win), hints);
	XFree(hints);
#endif
}
示例#27
0
文件: xdata.cpp 项目: toppk/xevil
Boolean Xvars::load_pixmap(Drawable* pixmap,Drawable* mask,
                           int dpyNum,char** xpmBits,Boolean fullSize) {
  // Just load XPM as is.
  if (fullSize) {
    XpmAttributes attr;
    attr.valuemask = XpmCloseness;
    attr.closeness = XPM_CLOSENESS;
    attr.alloc_close_colors = True;

    int val = 
      XpmCreatePixmapFromData(dpy[dpyNum],root[dpyNum],
                              xpmBits,
                              pixmap,mask,
                              &attr);
    XpmFreeAttributes(&attr);

    Boolean ret = (val == XpmSuccess);
    if (!*pixmap || (mask && !*mask)) {
      ret = False;
    }

    return ret; 
  }


  //// Load image and mask into memory, reduce them and put them up to the
  //// display server as a new pixmap and mask

  XImage* srcImage;
  XImage* srcMask;
  Size srcSize;

  // Load in src image from supplied data.
  XpmAttributes attr;
  attr.valuemask = XpmReturnPixels | XpmCloseness;
  attr.closeness = XPM_CLOSENESS;
  attr.alloc_close_colors = True;

  // Perhaps should use XpmReturnAllocPixels, neither gives the transparent 
  // value.
  int val = 
    XpmCreateImageFromData(dpy[dpyNum],
                           xpmBits,
                           &srcImage,(mask ? &srcMask : (XImage**)NULL),
                           &attr);
  srcSize.width = attr.width;
  srcSize.height = attr.height;
  if (val != XpmSuccess) {
    XpmFreeAttributes(&attr);
    return False;
  }
  // Must be even size.
  assert((srcSize.width % 2 == 0) && 
         (srcSize.height % 2 == 0));
  int depth = srcImage->depth;
  int bitmap_pad = srcImage->bitmap_pad;

  // Size of reduced, destination image.
  Size destSize;
  destSize.set(srcSize.width / 2,srcSize.height / 2);
  
  // Create image for dest data.
  char* destData = 
    new_bytes_for_image(destSize,depth,bitmap_pad);
  XImage *destImage = 
    XCreateImage(dpy[dpyNum],visual[dpyNum],depth,ZPixmap,0,
                 destData,destSize.width,destSize.height,
                 bitmap_pad,0);
  assert(destImage);

  // Create dest mask if needed.
  XImage *destMask;
  if (mask) {
    assert(srcMask->depth == 1);
    char* destMaskData = 
      new_bytes_for_image(destSize,1,bitmap_pad);
    destMask = 
      XCreateImage(dpy[dpyNum],visual[dpyNum],1,ZPixmap,0,
                   destMaskData,destSize.width,destSize.height,
                   bitmap_pad,0);
    assert(destMask);
  }
    
  // Do the pixel reduction.
  //  unstretch_image(dpyNum,destImage,srcImage,attr.pixels,attr.npixels);
  unstretch_image(dpyNum,destImage,srcImage,
                  attr.pixels,attr.npixels);
  if (mask) {
    unstretch_image(dpyNum,destMask,srcMask,NULL,0);
  }

  // Kill src image and mask.
  XpmFreeAttributes(&attr);
  XDestroyImage(srcImage);  
  if (mask) {
    XDestroyImage(srcMask);
  }
      
  // Create dest pixmap and mask
  *pixmap = XCreatePixmap(dpy[dpyNum],root[dpyNum],
                          destSize.width,destSize.height,
                          depth);
  if (!*pixmap) {
    // Should do more cleanup.
    return False;
  }
  if (mask) {
    *mask = XCreatePixmap(dpy[dpyNum],root[dpyNum],
                          destSize.width,destSize.height,
                          1);
    if (!*mask) {
      // Should do more cleanup.
      return False;
    }
  }

  // Put dest image and mask up to the display server.
  put_image(dpyNum,*pixmap,destImage,destSize);
  if (mask) {
    put_image(dpyNum,*mask,destMask,destSize);
  }

  // Kill dest image and mask
  destroy_image(destImage);
  if (mask) {
    destroy_image(destMask);
  }
  return True;
}
示例#28
0
文件: button.cpp 项目: ALLPix/SoXt
Pixmap
createPixmapFromXpm(Widget widget, const char ** xpm)
{
  Pixmap pixels = 0;
  Widget shell = widget;
  while (! XtIsShell(shell) && shell != (Widget) NULL) {
    shell = XtParent(shell);
  }
  assert(shell != (Widget) NULL);
  fprintf(stderr, "shell: %p\n", shell);
  Display * display = XtDisplay(shell);

  XpmAttributes attrs;
  attrs.visual = NULL;
  attrs.colormap = 0;
  attrs.depth = 0;
  attrs.valuemask = XpmVisual | XpmColormap | XpmDepth;

  XtVaGetValues(shell, XmNcolormap, &attrs.colormap, NULL);
  XtVaGetValues(shell, XmNdepth, &attrs.depth, NULL);
  XtVaGetValues(shell, XmNvisual, &attrs.visual, NULL);
  if ( attrs.visual == NULL ) {
    fprintf(stderr, "attrs.visual for shell was NULL - using default\n");
    attrs.visual = DefaultVisual(display, DefaultScreen(display));
    attrs.depth = DefaultDepth(display, DefaultScreen(display));
    attrs.colormap = DefaultColormap(display, DefaultScreen(display));
  }

  /* I'm questioning the use of the root Window here... */
  /* An alternative approach could maybe be to set it up once the window was
   * created (so we can use the actual window in question) through the use
   * of XtAddCallback()? */

  Drawable draw = RootWindow(display, DefaultScreen(display));
  Pixmap stencil = 0;

  // FIXME: that cast is pretty nasty -- get rid of it. 20020319 mortene.
  int error = XpmCreatePixmapFromData(display, draw, (char **)xpm, &pixels, &stencil, &attrs);

  if (error != XpmSuccess) {
    fprintf(stderr, "XpmCreatePixmapFromData() failed: %d", error);
    return (Pixmap) 0;
  }

  if (stencil) {
    Pixel bg;
    XtVaGetValues(widget, XmNbackground, &bg, NULL);

    XImage * pixmap = XGetImage(display, pixels, 0, 0, attrs.width, attrs.height,
                                0xffffffff, ZPixmap);
    XImage * mask = XGetImage(display, stencil, 0, 0, attrs.width, attrs.height,
                              0xffffffff, ZPixmap);
    assert(pixmap != NULL && mask != NULL);

    for (unsigned int x = 0; x < attrs.width; x++) {
      for (unsigned int y = 0; y < attrs.height; y++) {
        Pixel pixel = XGetPixel(mask, x, y);
        Bool usebg = (pixel == 0);
        if (usebg) { // background must be set in image
          XPutPixel(pixmap, x, y, bg);
        }
      }
    }

    GC temp = XCreateGC(display, pixels, 0, NULL);
    XPutImage(display, pixels, temp, pixmap,
              0, 0, 0, 0, attrs.width, attrs.height);
    XFreeGC(display, temp);

    XDestroyImage(pixmap);
    XDestroyImage(mask);
  }
  return pixels;
}
示例#29
0
文件: init.c 项目: norayr/wmlaptop
void init_image ()
{
	char *xbm = wmlaptop_mask_bits;
	char ** xpm;
	int sx = wmlaptop_mask_width;
	int sy = wmlaptop_mask_height;
	
	XWindowAttributes      attributes;
	int                    err;
	
	int i,j,k;
	int width, height, numcol, depth;
    int zero=0;
    int bcount;
    int curpixel;
	unsigned char bwrite;


	/* use the command line arg selected pixmap */
	usePixmap( args_skin );
	xpm = XPM_NAME;
	
	sscanf(*xpm, "%d %d %d %d", &width, &height, &numcol, &depth);


    for (k=0; k!=depth; k++)
    {
        zero <<=8;
        zero |= xpm[1][k];
    }
        
	for (i=numcol+1; i < numcol+sy+1; i++)
	{
		bcount = 0;
		bwrite = 0;
		for (j=0; j<sx*depth; j+=depth)
		{
            bwrite >>= 1;

            curpixel=0;
            for (k=0; k!=depth; k++)
            {
                curpixel <<=8;
                curpixel |= xpm[i][j+k];
            }
                
            if ( curpixel != zero )
            {
				bwrite += 128;
			}
			bcount++;
			if (bcount == 8)
			{
				*xbm = bwrite;
				xbm++;
				bcount = 0;
				bwrite = 0;
			}
		}
	}
	
	/* For the colormap */
	XGetWindowAttributes(display, Root, &attributes);
	
	wmgen.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions);
	
	err = XpmCreatePixmapFromData(display, Root, XPM_NAME, &(wmgen.pixmap), &(wmgen.mask), &(wmgen.attributes));
	
	if (err != XpmSuccess)
	{
		fprintf(stderr, "Not enough free colorcells.\n");
		free_and_exit( ERROR );
	}
	
}
示例#30
0
/*
    建立 Tray 
*/
void gui_tray_init(void)
{
    winlist_t *win = NULL;

    if (gui->tray_win)
    {
	//return;
	win = gui->tray_win;
    }
    else
    {
#if 0
	//manager_window = XGetSelectionOwner(gui->display, selection_atom);
	manager_window = ManagerWindow(gui->display, gui->screen);

	if (manager_window != None)
	{
	    Atom visual_atom = XInternAtom(gui->display, "_NET_SYSTEM_TRAY_VISUAL", False);

	    Atom type;
	    int format;
	    union {
		    unsigned long *prop;
		    unsigned char *prop_ch;
	    } prop = { NULL };
	    unsigned long nitems;
	    unsigned long bytes_after;
	    int result;

	    type = None;
	    result = XGetWindowProperty (gui->display,
					manager_window,
					visual_atom,
					0, sizeof(long), False,
					XA_VISUALID,
					&type, &format, &nitems,
					&bytes_after, &(prop.prop_ch));

	    Visual *default_xvisual;
	    
	    if (result == 0 &&
		type == XA_VISUALID && nitems == 1 && format == 32)
		{
		    VisualID visual_id = prop.prop[0];
		    visual = x11_screen_lookup_visual (visual_id);
		}
	}
#endif
#if 1
/*        Atom actual_type;
        int actual_format;
        unsigned long nitems, bytes_remaining;
        unsigned char *data = 0;
        int result = XGetWindowProperty(gui->display, manager_window, visual_atom, 0, 1,
                                        False, XA_VISUALID, &actual_type,
                                        &actual_format, &nitems, &bytes_remaining, &data);
        VisualID vid = 0;
        if (result == Success && data && actual_type == XA_VISUALID && actual_format == 32 &&
                nitems == 1 && bytes_remaining == 0)
            vid = *(VisualID*)data;
        if (data)
            XFree(data);
        if (vid == 0)
            return;
*/
        uint mask = VisualScreenMask;
        XVisualInfo *vi, rvi;
        int count=0, i;
        //rvi.visualid = vid;
	rvi.screen = gui->screen;
        vi = XGetVisualInfo(gui->display, mask, &rvi, &count);
	for(i=0; i<count; i++)
	{
	      if (vi[i].depth == 32 &&
		  (vi[i].red_mask   == 0xff0000 &&
		   vi[i].green_mask == 0x00ff00 &&
		   vi[i].blue_mask  == 0x0000ff))
		{
			//printf("rgba_visual=%d\n", vi[i].visual->visualid);
			visual = &vi[i];
			break;
		}
	}
        /*if (vi) {
            //visual = vi[0];
	    visual = &vi[0];
	    //return;
            //XFree((char*)vi);
        }*/
#endif

	if(visual && visual->visual)
	    win = gui_new_win_tray((XVisualInfo*)visual);
	else
	    win = gui_new_win();
    }

    /* Tray 不需要邊框 */
    XSetWindowBorderWidth(gui->display, win->window, 0);

    XSetWindowAttributes win_attr;
    win_attr.override_redirect = True;
    XChangeWindowAttributes(gui->display, win->window,
			CWOverrideRedirect, &win_attr);

    Pixmap tray, mask;
    XpmAttributes attributes;
    attributes.valuemask = 0;

    if (!ProcessTrayIcon(gui->display, win->window, oxim_tray, &icon, &icon_mask,
				&picon)) 
    {
	//fprintf(stderr, "failed to get inactive icon image\n");
	return;
    }
#if 1
    if(visual && visual->visual)
    {
	/* GCs for copy and drawing on mask */
	XGCValues gv;
	gv.foreground = BlackPixel(gui->display, gui->screen);
	gv.background = BlackPixel(gui->display, gui->screen);
	//GC gc = XCreateGC(gui->display, win->window, GCBackground|GCForeground, &gv);
	GC gc = XCreateGC(gui->display, aw, GCBackground|GCForeground, &gv);

	XSetClipMask(gui->display, gc, icon_mask);
    }
#endif
    XpmCreatePixmapFromData(gui->display, win->window,
		oxim_tray, &tray, &mask, &attributes);
    tray_w = attributes.width;
    tray_h = attributes.height;

    win->width  = tray_w;
    win->height = tray_h;

    XpmFreeAttributes(&attributes);
    XFreePixmap(gui->display, tray);
    if (mask)
    {
	XFreePixmap(gui->display, mask);
    }
    win->pos_x = 0;
    win->pos_y = 0;

    win->win_draw_func = NULL;
    win->win_event_func = gui_focus_event;

    XSizeHints *size_hints = XAllocSizeHints();
    size_hints->flags = PMinSize | PMaxSize;
    size_hints->min_width = win->width;
    size_hints->min_height = win->height;
    size_hints->max_width = win->width;
    size_hints->max_height = win->height;
    XSetWMNormalHints(gui->display, win->window, size_hints);
    XFree(size_hints);

    Atom xembed_info = XInternAtom(gui->display, "_XEMBED_INFO", False);
    unsigned int mapping[2];
    mapping[0] = 0; /* ver 0 */
    mapping[1] = 1; /* request mapping */
    XChangeProperty(gui->display, win->window, xembed_info, xembed_info,
			32, PropModeReplace, (unsigned char *)mapping, 2);
    gui->tray_win = win;
}