コード例 #1
0
ファイル: mainwin.c プロジェクト: jameswthorne/skippy
void
mainwin_destroy(MainWin *mw)
{
	if(mw->tooltip)
		tooltip_destroy(mw->tooltip);
	
	if(! mw->no_free_color)
		XFreeColors(mw->dpy, mw->colormap, mw->pixels, 2, 0);
	else {
		if(! (mw->no_free_color & 1))
			XFreeColors(mw->dpy, mw->colormap, &BORDER_COLOR(mw), 1, 0);
		if(! (mw->no_free_color & 2))
			XFreeColors(mw->dpy, mw->colormap, &HIGHLIGHT_COLOR(mw), 1, 0);
	}
	
	if(mw->cm_highlight)
	{
		imlib_context_set_color_modifier(mw->cm_highlight);
		imlib_free_color_modifier();
	}
	
	if(mw->cm_normal)
	{
		imlib_context_set_color_modifier(mw->cm_normal);
		imlib_free_color_modifier();
	}
	
	if(mw->background)
	{
		imlib_context_set_image(mw->background);
		imlib_free_image();
	}
	
	if(mw->bg_pixmap != None)
		imlib_free_pixmap_and_mask(mw->bg_pixmap);
	
	XDestroyWindow(mw->dpy, mw->window);
	
#ifdef XINERAMA
	if(mw->xin_info)
		XFree(mw->xin_info);
#endif /* XINERAMA */
	
	free(mw);
}
コード例 #2
0
ファイル: tooltip.c プロジェクト: mozeq/skippy-xd
Tooltip *
tooltip_create(MainWin *mw, dlist *config)
{
	Tooltip *tt;
	XSetWindowAttributes attr;
	const char *tmp;
	long int tmp_l;
	
	tt = (Tooltip *)malloc(sizeof(Tooltip));
	if(! tt)
		return 0;
	
	tt->mainwin = mw;
	tt->window = None;
	tt->font = 0;
	tt->draw = 0;
	tt->text = 0;
	tt->color.pixel = tt->background.pixel = tt->border.pixel = tt->shadow.pixel = None;
	
	attr.override_redirect = True;
	attr.border_pixel = None;
	attr.background_pixel = None;
	attr.event_mask = ExposureMask;
	attr.colormap = mw->colormap;
	
	tt->window = XCreateWindow(mw->dpy, mw->root,
	                           0, 0, 1, 1, 0,
	                           mw->depth, InputOutput, mw->visual,
	                           CWBorderPixel|CWBackPixel|CWOverrideRedirect|CWEventMask|CWColormap,
	                           &attr);
	if(tt->window == None)
	{
		fprintf(stderr, "WARNING: Couldn't create tooltip window.\n");
		tooltip_destroy(tt);
		return 0;
	}
	
	tmp = config_get(config, "tooltip", "border", "#e0e0e0");
	if(! XftColorAllocName(mw->dpy, mw->visual, mw->colormap, tmp, &tt->border))
	{
		fprintf(stderr, "WARNING: Invalid color '%s'.\n", tmp);
		tooltip_destroy(tt);
		return 0;
	}
	
	tmp = config_get(config, "tooltip", "background", "#404040");
	if(! XftColorAllocName(mw->dpy, mw->visual, mw->colormap, tmp, &tt->background))
	{
		fprintf(stderr, "WARNING: Invalid color '%s'.\n", tmp);
		tooltip_destroy(tt);
		return 0;
	}
	
	tmp = config_get(config, "tooltip", "opacity", "128");
	tmp_l = MIN(MAX(0, strtol(tmp, 0, 0) * 256), 65535);
	tt->background.color.alpha = tmp_l;
	tt->border.color.alpha = tmp_l;
	
	tmp = config_get(config, "tooltip", "text", "#e0e0e0");
	if(! XftColorAllocName(mw->dpy, mw->visual, mw->colormap, tmp, &tt->color))
	{
		fprintf(stderr, "WARNING: Couldn't allocate color '%s'.\n", tmp);
		tooltip_destroy(tt);
		return 0;
	}
	
	tmp = config_get(config, "tooltip", "textShadow", "black");
	if(strcasecmp(tmp, "none") != 0)
	{
		if(! XftColorAllocName(mw->dpy, mw->visual, mw->colormap, tmp, &tt->shadow))
		{
			fprintf(stderr, "WARNING: Couldn't allocate color '%s'.\n", tmp);
			tooltip_destroy(tt);
			return 0;
		}
	}
	
	tt->draw = XftDrawCreate(mw->dpy, tt->window, mw->visual, mw->colormap);
	if(! tt->draw)
	{
		fprintf(stderr, "WARNING: Couldn't create Xft draw surface.\n");
		tooltip_destroy(tt);
		return 0;
	}
	
	tt->font = XftFontOpenName(mw->dpy, mw->screen, config_get(config, "tooltip", "font", "fixed-11:weight=bold"));
	if(! tt->font)
	{
		fprintf(stderr, "WARNING: Couldn't open Xft font.\n");
		tooltip_destroy(tt);
		return 0;
	}
	
	tt->font_height = tt->font->ascent + tt->font->descent;
	
	return tt;
}