scx/c/xlib/visual.c

98 lines
3.1 KiB
C
Raw Normal View History

#include "xlib.h"
s48_value Enter_Visual_And_Visual_Info(XVisualInfo* vi) {
s48_value t = s48_make_vector(10, S48_FALSE);
S48_DECLARE_GC_PROTECT(1);
S48_GC_PROTECT_1(t);
S48_VECTOR_SET(t, 0, s48_enter_integer(vi->visualid));
S48_VECTOR_SET(t, 1, s48_enter_fixnum(vi->screen));
S48_VECTOR_SET(t, 2, s48_enter_fixnum(vi->depth));
S48_VECTOR_SET(t, 3, s48_enter_integer(vi->class));
S48_VECTOR_SET(t, 4, s48_enter_integer(vi->red_mask));
S48_VECTOR_SET(t, 5, s48_enter_integer(vi->green_mask));
S48_VECTOR_SET(t, 6, s48_enter_integer(vi->blue_mask));
S48_VECTOR_SET(t, 7, s48_enter_integer(vi->colormap_size));
S48_VECTOR_SET(t, 8, s48_enter_fixnum(vi->bits_per_rgb));
t = s48_cons(s48_enter_integer(VisualAllMask), t);
t = s48_cons(SCX_ENTER_VISUAL(vi->visual), t);
S48_GC_UNPROTECT();
return t;
}
unsigned long Extract_Visual_Info(s48_value vi, XVisualInfo* VI) {
unsigned long mask = s48_extract_integer(S48_CAR(vi));
s48_value v = S48_CDR(vi);
if (mask & VisualIDMask)
VI->visualid = s48_extract_integer(S48_VECTOR_REF(v, 0));
if (mask & VisualScreenMask)
VI->screen = s48_extract_integer(S48_VECTOR_REF(v, 1));
if (mask & VisualDepthMask)
VI->depth = s48_extract_integer(S48_VECTOR_REF(v, 2));
if (mask & VisualClassMask)
VI->class = s48_extract_integer(S48_VECTOR_REF(v, 3));
if (mask & VisualRedMaskMask)
VI->red_mask = s48_extract_integer(S48_VECTOR_REF(v, 4));
if (mask & VisualGreenMaskMask)
VI->green_mask = s48_extract_integer(S48_VECTOR_REF(v, 5));
if (mask & VisualBlueMaskMask)
VI->blue_mask = s48_extract_integer(S48_VECTOR_REF(v, 6));
if (mask & VisualColormapSizeMask)
VI->colormap_size = s48_extract_integer(S48_VECTOR_REF(v, 7));
if (mask & VisualBitsPerRGBMask)
VI->bits_per_rgb = s48_extract_integer(S48_VECTOR_REF(v, 8));
return mask;
}
s48_value scx_Get_Visual_Info(s48_value Xdisplay, s48_value v) {
XVisualInfo template;
XVisualInfo* visualList;
int visualsMatch, i;
long mask = VisualNoMask;
s48_value res = S48_FALSE;
S48_DECLARE_GC_PROTECT(1);
mask = Extract_Visual_Info(v, &template);
visualList = XGetVisualInfo( SCX_EXTRACT_DISPLAY(Xdisplay),
mask, &template, &visualsMatch);
res = s48_make_vector(visualsMatch, S48_FALSE);
S48_GC_PROTECT_1(res);
for (i=0; i<visualsMatch; i++)
S48_VECTOR_SET(res, i, Enter_Visual_And_Visual_Info(&visualList[i]));
S48_GC_UNPROTECT();
return res;
}
s48_value scx_Visual_ID(s48_value Xvisual) {
return s48_enter_integer(XVisualIDFromVisual(SCX_EXTRACT_VISUAL(Xvisual)));
}
s48_value scx_Match_Visual_Info(s48_value Xdisplay, s48_value scrnum,
s48_value depth, s48_value class) {
XVisualInfo r;
if (XMatchVisualInfo(SCX_EXTRACT_DISPLAY(Xdisplay),
s48_extract_integer(scrnum),
s48_extract_integer(depth),
s48_extract_integer(class),
&r))
return Enter_Visual_And_Visual_Info(&r);
else
return S48_FALSE;
}
void scx_init_visual(void) {
S48_EXPORT_FUNCTION(scx_Get_Visual_Info);
S48_EXPORT_FUNCTION(scx_Visual_ID);
S48_EXPORT_FUNCTION(scx_Match_Visual_Info);
}