ltk

Socket-based GUI for X11 (WIP)
git clone git://lumidify.org/ltk.git (fast, but not encrypted)
git clone https://lumidify.org/git/ltk.git (encrypted, but very slow)
Log | Files | Refs | README | LICENSE

color.c (1745B)


      1 /*
      2  * Copyright (c) 2021 lumidify <nobody@lumidify.org>
      3  *
      4  * Permission to use, copy, modify, and/or distribute this software for any
      5  * purpose with or without fee is hereby granted, provided that the above
      6  * copyright notice and this permission notice appear in all copies.
      7  *
      8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
      9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     15  */
     16 
     17 #include <stdarg.h>
     18 #include <X11/Xlib.h>
     19 #include <X11/Xutil.h>
     20 
     21 #include "util.h"
     22 #include "color.h"
     23 #include "compat.h"
     24 
     25 /* FIXME: avoid initializing part of the struct and then error returning */
     26 /* FIXME: better error codes */
     27 /* FIXME: I think xcolor is unneeded when xft is enabled */
     28 int
     29 ltk_color_create(Display *dpy, Visual *vis, Colormap cm, const char *hex, ltk_color *col) {
     30 	if (!XParseColor(dpy, cm, hex, &col->xcolor))
     31 		return 1;
     32 	if (!XAllocColor(dpy, cm, &col->xcolor))
     33 		return 1;
     34 	/* FIXME: replace with XftColorAllocValue */
     35 	#if USE_XFT == 1
     36 	if (!XftColorAllocName(dpy, vis, cm, hex, &col->xftcolor))
     37 		return 1;
     38 	#else
     39 	(void)vis;
     40 	#endif
     41 	return 0;
     42 }
     43 
     44 void
     45 ltk_color_destroy(Display *dpy, Visual *vis, Colormap cm, ltk_color *col) {
     46 	/* FIXME: what should the 'planes' argument be? */
     47 	XFreeColors(dpy, cm, &col->xcolor.pixel, 1, 0);
     48 	#if USE_XFT == 1
     49 	XftColorFree(dpy, vis, cm, &col->xftcolor);
     50 	#else
     51 	(void)vis;
     52 	#endif
     53 }