scx/c/xlib/display.c

244 lines
7.1 KiB
C
Raw Normal View History

2001-05-08 10:21:00 -04:00
#include "xlib.h"
#include "scheme48.h"
2001-05-08 10:21:00 -04:00
2001-05-21 11:33:32 -04:00
static s48_value display_record_type_binding = S48_FALSE;
2001-05-08 10:21:00 -04:00
2001-05-21 11:33:32 -04:00
// Open_Display(name) name should be a string or S48_FALSE (=> Null)
s48_value Open_Display (s48_value name) {
char* cname = (char*)0;
Display* dpy;
2001-05-21 11:33:32 -04:00
if (!S48_FALSE_P(name))
cname = s48_extract_string(name);
dpy = XOpenDisplay(cname);
return s48_enter_integer((long)dpy);
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
// 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 = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
XCloseDisplay(dpy);
return S48_UNSPECIFIC;
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
// The following procedure mainly wrap a corresponding XLib macro without
// underscores...
s48_value Display_Default_Root_Window(s48_value Xdisplay) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
Window wnd = DefaultRootWindow(dpy);
return ENTER_WINDOW(wnd);
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
s48_value Display_Default_Colormap(s48_value Xdisplay) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
Colormap cmp = DefaultColormap(dpy, DefaultScreen(dpy));
return ENTER_COLORMAP(cmp);
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
s48_value Display_Default_Gcontext(s48_value Xdisplay) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
GC gc = DefaultGC(dpy, DefaultScreen(dpy));
return ENTER_GC(gc);
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
s48_value Display_Default_Depth(s48_value Xdisplay) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
int depth = DefaultDepth(dpy, DefaultScreen(dpy));
return s48_enter_integer(depth);
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
s48_value Display_Default_Screen_Number(s48_value Xdisplay) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
return s48_enter_integer(DefaultScreen(dpy));
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
s48_value Display_Cells(s48_value Xdisplay, s48_value ScrNum) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
int num = (int)s48_extract_integer(ScrNum);
return s48_enter_integer(DisplayCells(dpy, num));
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
s48_value Display_Planes(s48_value Xdisplay, s48_value ScrNum) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
int num = (int)s48_extract_integer(ScrNum);
return s48_enter_integer(DisplayPlanes(dpy, num));
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
s48_value Display_String(s48_value Xdisplay) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
char* s = DisplayString(dpy);
return s48_enter_string(s);
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
s48_value Display_Vendor(s48_value Xdisplay) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
char* s = ServerVendor(dpy);
int i = VendorRelease(dpy);
return s48_cons( s48_enter_string(s),
s48_enter_integer(i) );
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
s48_value Display_Protocol_Version(s48_value Xdisplay) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
int maj = ProtocolVersion(dpy);
int min = ProtocolRevision(dpy);
return s48_cons( s48_enter_integer(maj),
s48_enter_integer(min) );
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
s48_value Display_Screen_Count(s48_value Xdisplay) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
int cnt = ScreenCount(dpy);
return s48_enter_integer(cnt);
2001-05-08 10:21:00 -04:00
}
s48_value Display_Image_Byte_Order(s48_value Xdisplay) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
return Bits_To_Symbols( (unsigned long)ImageByteOrder(dpy),
0, Byte_Order_Syms );
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
s48_value Display_Bitmap_Unit(s48_value Xdisplay) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
return s48_enter_integer(BitmapUnit(dpy));
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
s48_value Display_Bitmap_Bit_Order(s48_value Xdisplay) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
return Bits_To_Symbols( (unsigned long)BitmapBitOrder(dpy),
0, Byte_Order_Syms );
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
s48_value Display_Bitmap_Pad(s48_value Xdisplay) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
return s48_enter_integer(BitmapPad(dpy));
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
s48_value Display_Width(s48_value Xdisplay) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
return s48_enter_integer(DisplayWidth(dpy, DefaultScreen(dpy)));
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
s48_value Display_Height(s48_value Xdisplay) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
return s48_enter_integer(DisplayHeight(dpy, DefaultScreen(dpy)));
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
s48_value Display_Width_Mm (s48_value Xdisplay) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
return s48_enter_integer(DisplayWidthMM(dpy, DefaultScreen(dpy)));
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
s48_value Display_Height_Mm (s48_value Xdisplay) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
return s48_enter_integer(DisplayHeightMM(dpy, DefaultScreen(dpy)));
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
s48_value Display_Motion_Buffer_Size(s48_value Xdisplay) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
return s48_enter_integer(XDisplayMotionBufferSize(dpy));
2001-05-08 10:21:00 -04:00
}
s48_value Display_Flush_Output (s48_value Xdisplay) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
XFlush (dpy);
return S48_UNSPECIFIC;
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
s48_value Display_Wait_Output (s48_value Xdisplay, s48_value discard) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
XSync (dpy, !S48_FALSE_P(discard));
return S48_UNSPECIFIC;
2001-05-08 10:21:00 -04:00
}
s48_value No_Op (s48_value Xdisplay) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
XNoOp(dpy);
return S48_UNSPECIFIC;
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
s48_value List_Depths (s48_value Xdisplay, s48_value scr) {
S48_DECLARE_GC_PROTECT(1);
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
int i, num;
int* p;
s48_value ret;
S48_GC_PROTECT_1(ret);
2001-05-08 10:21:00 -04:00
2001-05-21 11:33:32 -04:00
p = XListDepths(dpy, s48_extract_integer(scr), &num);
if (!p)
ret = S48_FALSE;
else {
ret = s48_make_vector(num, S48_NULL);
2001-05-08 10:21:00 -04:00
for (i = 0; i < num; i++)
2001-05-21 11:33:32 -04:00
S48_VECTOR_SET(ret, i, s48_enter_integer(p[i]));
XFree((char *)p);
}
S48_GC_UNPROTECT();
2001-05-21 11:33:32 -04:00
return ret;
2001-05-08 10:21:00 -04:00
}
2001-05-21 11:33:32 -04:00
s48_value List_Pixmap_Formats (s48_value Xdisplay) {
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
S48_DECLARE_GC_PROTECT(2);
int num, i;
XPixmapFormatValues* p;
s48_value ret, t;
S48_GC_PROTECT_2(ret, t);
2001-05-08 10:21:00 -04:00
p = XListPixmapFormats(dpy, &num);
2001-05-21 11:33:32 -04:00
if (!p) ret = S48_FALSE;
else {
ret = s48_make_vector (num, S48_NULL);
2001-05-08 10:21:00 -04:00
for (i = 0; i < num; i++) {
2001-05-21 11:33:32 -04:00
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].scanline_pad),
2001-05-21 11:33:32 -04:00
S48_NULL)));
S48_VECTOR_SET(ret, i, t);
2001-05-08 10:21:00 -04:00
}
XFree ((char *)p);
2001-05-21 11:33:32 -04:00
}
S48_GC_UNPROTECT();
2001-05-21 11:33:32 -04:00
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_Bitmap_Pad);
2001-05-21 11:33:32 -04:00
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_Flush_Output);
2001-05-21 11:33:32 -04:00
S48_EXPORT_FUNCTION(Display_Wait_Output);
S48_EXPORT_FUNCTION(No_Op);
S48_EXPORT_FUNCTION(List_Depths);
S48_EXPORT_FUNCTION(List_Pixmap_Formats);
2001-05-08 10:21:00 -04:00
}