scx/c/xlib/util.c

55 lines
1.9 KiB
C
Raw Normal View History

2001-05-08 10:21:00 -04:00
#include "xlib.h"
static s48_value P_Get_Default (d, program, option) s48_value d, program, option; {
2001-05-08 10:21:00 -04:00
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;
2001-05-08 10:21:00 -04:00
}
static s48_value P_Resource_Manager_String (d) s48_value d; {
2001-05-08 10:21:00 -04:00
register char *ret;
Check_Type (d, T_Display);
ret = XResourceManagerString (DISPLAY(d)->dpy);
return ret ? Make_String (ret, strlen (ret)) : S48_FALSE;
2001-05-08 10:21:00 -04:00
}
static s48_value P_Parse_Geometry (string) s48_value string; {
s48_value ret, t;
2001-05-08 10:21:00 -04:00
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);
2001-05-08 10:21:00 -04:00
return ret;
}
static s48_value P_Parse_Color (d, cmap, spec) s48_value d, cmap, spec; {
2001-05-08 10:21:00 -04:00
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;
2001-05-08 10:21:00 -04:00
}
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);
}