scx/c/xlib/util.c

55 lines
1.9 KiB
C

#include "xlib.h"
static s48_value P_Get_Default (d, program, option) s48_value d, program, option; {
register char *ret;
Check_Type (d, T_Display);
if (ret = XGetDefault (DISPLAY(d)->dpy, Get_Strsym (program),
Get_Strsym (option)))
return Make_String (ret, strlen (ret));
return S48_FALSE;
}
static s48_value P_Resource_Manager_String (d) s48_value d; {
register char *ret;
Check_Type (d, T_Display);
ret = XResourceManagerString (DISPLAY(d)->dpy);
return ret ? Make_String (ret, strlen (ret)) : S48_FALSE;
}
static s48_value P_Parse_Geometry (string) s48_value string; {
s48_value ret, t;
register mask;
int x, y;
unsigned w, h;
mask = XParseGeometry (Get_Strsym (string), &x, &y, &w, &h);
t = ret = P_Make_List (s48_enter_integer (6), S48_FALSE);
if (mask & XNegative) S48_CAR (t) = S48_TRUE; t = S48_CDR (t);
if (mask & YNegative) S48_CAR (t) = S48_TRUE; t = S48_CDR (t);
if (mask & XValue) S48_CAR (t) = s48_enter_integer (x); t = S48_CDR (t);
if (mask & YValue) S48_CAR (t) = s48_enter_integer (y); t = S48_CDR (t);
if (mask & WidthValue) S48_CAR (t) = s48_enter_integer (w); t = S48_CDR (t);
if (mask & HeightValue) S48_CAR (t) = s48_enter_integer (h);
return ret;
}
static s48_value P_Parse_Color (d, cmap, spec) s48_value d, cmap, spec; {
XColor ret;
Check_Type (d, T_Display);
if (XParseColor (DISPLAY(d)->dpy, Get_Colormap (cmap), Get_Strsym (spec),
&ret))
return Make_Color (ret.red, ret.green, ret.blue);
return S48_FALSE;
}
elk_init_xlib_util () {
Define_Primitive (P_Get_Default, "get-default", 3, 3, EVAL);
Define_Primitive (P_Resource_Manager_String,
"resource-manager-string", 1, 1, EVAL);
Define_Primitive (P_Parse_Geometry, "parse-geometry", 1, 1, EVAL);
Define_Primitive (P_Parse_Color, "parse-color", 3, 3, EVAL);
}