scx/c/xlib/display.c

243 lines
7.4 KiB
C

#include "xlib.h"
static s48_value display_record_type_binding = S48_FALSE;
// Open_Display(name) name should be a string or S48_FALSE (=> Null)
s48_value Open_Display (s48_value name) {
char* cname = (char*)0;
int res;
if (!S48_FALSE_P(name))
cname = s48_extract_string(name);
res = XOpenDisplay(cname);
return s48_enter_fixnum(res);
}
// Close_Display( Xdisplay ) Xdisplay should be a pointer to the X-lib struct
// cast into a Scheme-Integer.
s48_value Close_Display(s48_value Xdisplay) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
XCloseDisplay(dpy);
return S48_UNSPECIFIC;
}
// The following procedure mainly wrap a corresponding XLib macro without
// underscores...
s48_value Display_Default_Root_Window(s48_value Xdisplay) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
Window wnd = DefaultRootWindow(dpy);
return s48_enter_integer((long)wnd);
}
s48_value Display_Default_Colormap(s48_value Xdisplay) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
Colormap cmp = DefaultColormap(dpy, DefaultScreen(dpy));
return s48_enter_integer((long)cmp);
}
s48_value Display_Default_Gcontext(s48_value Xdisplay) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
GC gc = DefaultGC(dpy, DefaultScreen(dpy));
return s48_enter_integer((long)gc);
}
s48_value Display_Default_Depth(s48_value Xdisplay) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
int depth = DefaultDepth(dpy, DefaultScreen(dpy));
return s48_enter_integer(depth);
}
s48_value Display_Default_Screen_Number(s48_value Xdisplay) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
return s48_enter_integer(DefaultScreen(dpy));
}
s48_value Display_Cells(s48_value Xdisplay, s48_value ScrNum) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
int num = (int)s48_extract_integer(ScrNum);
return s48_enter_integer(DisplayCells(dpy, num));
}
s48_value Display_Planes(s48_value Xdisplay, s48_value ScrNum) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
int num = (int)s48_extract_integer(ScrNum);
return s48_enter_integer(DisplayPlanes(dpy, num));
}
s48_value Display_String(s48_value Xdisplay) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
char* s = DisplayString(dpy);
return s48_enter_string(s);
}
s48_value Display_Vendor(s48_value Xdisplay) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
char* s = ServerVendor(dpy);
int i = VendorRelease(dpy);
return s48_cons( s48_enter_string(s),
s48_enter_integer(i) );
}
s48_value Display_Protocol_Version(s48_value Xdisplay) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
int maj = ProtocolVersion(dpy);
int min = ProtocolRevision(dpy);
return s48_cons( s48_enter_integer(maj),
s48_enter_integer(min) );
}
s48_value Display_Screen_Count(s48_value Xdisplay) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
int cnt = ScreenCount(dpy);
return s48_enter_integer(cnt);
}
s48_value Display_Image_Byte_Order(s48_value d) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
return Bits_To_Symbols( (unsigned long)ImageByteOrder(dpy),
0, Byte_Order_Syms );
}
s48_value Display_Bitmap_Unit(s48_value Xdisplay) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
return s48_enter_integer(BitmapUnit(dpy));
}
s48_value Display_Bitmap_Bit_Order(s48_value Xdisplay) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
return Bits_To_Symbols( (unsigned long)BitmapBitOrder(dpy),
0, Byte_Order_Syms );
}
s48_value Display_Bitmap_Pad(s48_value Xdisplay) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
return s48_enter_integer(BitmapPad(dpy));
}
s48_value Display_Width(s48_value Xdisplay) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
return s48_enter_integer(DisplayWidth(dpy), DefaultScreen(dpy));
}
s48_value Display_Height(s48_value Xdisplay) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
return s48_enter_integer(DisplayHeight(dpy, DefaultScreen(dpy)));
}
s48_value Display_Width_Mm (s48_value Xdisplay) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
return s48_enter_integer(DisplayWidthMM(dpy, DefaultScreen(dpy)));
}
s48_value Display_Height_Mm (s48_value Xdisplay) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
return s48_enter_integer(DisplayHeightMM(dpy, DefaultScreen(dpy)));
}
s48_value Display_Motion_Buffer_Size(s48_value Xdisplay) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
return s48_enter_integer(XDisplayMotionBufferSize(dpy));
}
s48_value Display_Flush_Output (s48_value Xdisplay); {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
XFlush (dpy);
return S48_UNSPECIFIC;
}
s48_value Display_Wait_Output (s48_value Xdisplay, s48_value discard) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
XSync (dpy, !S48_FALSE_P(discard));
return S48_UNSPECIFIC;
}
s48_value P_No_Op (s48_value Xdisplay) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
XNoOp(dpy);
return S48_UNSPECIFIC;
}
s48_value List_Depths (s48_value Xdisplay, s48_value scr) {
S48_DECLARE_GC_PROTECT(1);
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
int i, num;
int* p;
s48_value ret;
S48_GC_PROTECT_1(ret);
p = XListDepths(dpy, s48_extract_integer(scr), &num);
if (!p)
ret = S48_FALSE;
else {
ret = s48_make_vector(num, S48_NULL);
for (i = 0; i < num; i++)
S48_VECTOR_SET(ret, i, s48_enter_integer(p[i]));
XFree((char *)p);
}
S48_GC_UNPROTECT;
return ret;
}
s48_value List_Pixmap_Formats (s48_value Xdisplay) {
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
S48_DECLARE_GC_PROTECT(2);
int num, i;
XPixmapFormatValues* p;
s48_value ret, t;
S48_GC_PROTECT_2(ret, t);
p = XListPixmapFormats(dpy, %num);
if (!p) ret = S48_FALSE;
else {
ret = s48_make_vector (num, S48_NULL);
for (i = 0; i < num; i++) {
t = s48_cons(s48_enter_integer(p[i].depth),
s48_cons(s48_enter_integer(p[i].bits_per_pixel),
s48_cons(s48_enter_integer(p[i].pad),
S48_NULL)));
S48_VECTOR_SET(ret, i, t);
}
XFree ((char *)p);
}
S48_GC_UNPROTECT;
return ret;
}
void s48_init_display(void) {
S48_GC_PROTECT_GLOBAL(display_record_type_binding);
display_record_type_binding = s48_get_imported_binding("display-record-type");
S48_EXPORT_FUNCTION(Open_Display);
S48_EXPORT_FUNCTION(Close_Display);
S48_EXPORT_FUNCTION(Display_Default_Root_Window);
S48_EXPORT_FUNCTION(Display_Default_Colormap);
S48_EXPORT_FUNCTION(Display_Default_Gcontext);
S48_EXPORT_FUNCTION(Display_Default_Depth);
S48_EXPORT_FUNCTION(Display_Default_Screen_Number);
S48_EXPORT_FUNCTION(Display_Cells);
S48_EXPORT_FUNCTION(Display_Planes);
S48_EXPORT_FUNCTION(Display_String);
S48_EXPORT_FUNCTION(Display_Vendor);
S48_EXPORT_FUNCTION(Display_Protocol_Version);
S48_EXPORT_FUNCTION(Display_Screen_Count);
S48_EXPORT_FUNCTION(Display_Image_Byte_Order);
S48_EXPORT_FUNCTION(Display_Bitmap_Unit);
S48_EXPORT_FUNCTION(Display_Bitmap_Bit_Order);
S48_EXPORT_FUNCTION(Display_Display_Bitmap_Pad);
S48_EXPORT_FUNCTION(Display_Width);
S48_EXPORT_FUNCTION(Display_Height);
S48_EXPORT_FUNCTION(Display_Width_Mm);
S48_EXPORT_FUNCTION(Display_Height_Mm);
S48_EXPORT_FUNCTION(Display_Motion_Buffer_Size);
S48_EXPORT_FUNCTION(Display_Flushed_Output);
S48_EXPORT_FUNCTION(Display_Wait_Output);
S48_EXPORT_FUNCTION(No_Op);
S48_EXPORT_FUNCTION(List_Depths);
S48_EXPORT_FUNCTION(List_Pixmap_Formats);
}