280 lines
8.6 KiB
C
280 lines
8.6 KiB
C
#include "xlib.h"
|
|
#include "scheme48.h"
|
|
#include <sys/time.h>
|
|
|
|
s48_value internal_after_function_binding = S48_FALSE;
|
|
|
|
// Open_Display(name) name should be a string or S48_FALSE (=> Null)
|
|
s48_value scx_Open_Display (s48_value name) {
|
|
char* cname = (char*)0;
|
|
if (!S48_FALSE_P(name))
|
|
cname = s48_extract_string(name);
|
|
|
|
return SCX_ENTER_DISPLAY(XOpenDisplay(cname));
|
|
}
|
|
|
|
// Close_Display( Xdisplay ) Xdisplay should be a pointer to the X-lib struct
|
|
// cast into a Scheme-Integer.
|
|
s48_value scx_Close_Display(s48_value Xdisplay) {
|
|
XCloseDisplay(SCX_EXTRACT_DISPLAY(Xdisplay));
|
|
return S48_UNSPECIFIC;
|
|
}
|
|
|
|
|
|
// After-Function routines
|
|
static X_After_Function(Display* d) {
|
|
s48_call_scheme(S48_SHARED_BINDING_REF(internal_after_function_binding),
|
|
1, SCX_ENTER_DISPLAY(d));
|
|
}
|
|
|
|
s48_value scx_Set_After_Function(s48_value Xdisplay, s48_value active) {
|
|
if (S48_FALSE_P(active))
|
|
(void)XSetAfterFunction(SCX_EXTRACT_DISPLAY(Xdisplay),
|
|
(int (*)())0);
|
|
else
|
|
(void)XSetAfterFunction(SCX_EXTRACT_DISPLAY(Xdisplay),
|
|
X_After_Function);
|
|
}
|
|
|
|
// This function returns the file destriptor of the message-channel.
|
|
s48_value scx_Display_Message_fd(s48_value Xdisplay) {
|
|
int fd = ConnectionNumber(SCX_EXTRACT_DISPLAY(Xdisplay));
|
|
/* struct timeval timeout;
|
|
fd_set fdset;
|
|
|
|
FD_ZERO(&fdset);
|
|
FD_SET(fd, &fdset);
|
|
timeout.tv_sec = 20; // 20 seconds
|
|
timeout.tv_usec = 0;
|
|
|
|
if (select(1, &fdset, NULL, NULL, &timeout) != 0)
|
|
return S48_TRUE;
|
|
else
|
|
return S48_FALSE;
|
|
*/
|
|
return s48_enter_integer(fd);
|
|
}
|
|
|
|
// The following procedure mainly wrap a corresponding XLib macro without
|
|
// underscores...
|
|
s48_value scx_Display_Default_Root_Window(s48_value Xdisplay) {
|
|
Window wnd = DefaultRootWindow(SCX_EXTRACT_DISPLAY(Xdisplay));
|
|
return SCX_ENTER_WINDOW(wnd);
|
|
}
|
|
|
|
s48_value scx_Display_Default_Colormap(s48_value Xdisplay) {
|
|
Display* dpy = SCX_EXTRACT_DISPLAY(Xdisplay);
|
|
Colormap cmp = DefaultColormap(dpy, DefaultScreen(dpy));
|
|
return SCX_ENTER_COLORMAP(cmp);
|
|
}
|
|
|
|
s48_value scx_Display_Default_Gcontext(s48_value Xdisplay) {
|
|
Display* dpy = SCX_EXTRACT_DISPLAY(Xdisplay);
|
|
GC gc = DefaultGC(dpy, DefaultScreen(dpy));
|
|
return SCX_ENTER_GCONTEXT(gc);
|
|
}
|
|
|
|
s48_value scx_Display_Default_Depth(s48_value Xdisplay) {
|
|
Display* dpy = SCX_EXTRACT_DISPLAY(Xdisplay);
|
|
int depth = DefaultDepth(dpy, DefaultScreen(dpy));
|
|
return s48_enter_integer(depth);
|
|
}
|
|
|
|
s48_value scx_Display_Default_Screen_Number(s48_value Xdisplay) {
|
|
return s48_enter_integer(DefaultScreen(SCX_EXTRACT_DISPLAY(Xdisplay)));
|
|
}
|
|
|
|
s48_value scx_Display_Default_Visual(s48_value Xdisplay, s48_value scrnum) {
|
|
return SCX_ENTER_VISUAL( DefaultVisual( SCX_EXTRACT_DISPLAY(Xdisplay),
|
|
s48_extract_integer(scrnum) ));
|
|
}
|
|
|
|
s48_value scx_Display_Cells(s48_value Xdisplay, s48_value ScrNum) {
|
|
int num = (int)s48_extract_integer(ScrNum);
|
|
return s48_enter_integer(DisplayCells(SCX_EXTRACT_DISPLAY(Xdisplay), num));
|
|
}
|
|
|
|
s48_value scx_Display_Planes(s48_value Xdisplay, s48_value ScrNum) {
|
|
int num = (int)s48_extract_integer(ScrNum);
|
|
return s48_enter_integer(DisplayPlanes(SCX_EXTRACT_DISPLAY(Xdisplay), num));
|
|
}
|
|
|
|
s48_value scx_Display_String(s48_value Xdisplay) {
|
|
char* s = DisplayString(SCX_EXTRACT_DISPLAY(Xdisplay));
|
|
return s48_enter_string(s);
|
|
}
|
|
|
|
s48_value scx_Display_Vendor(s48_value Xdisplay) {
|
|
Display* dpy = SCX_EXTRACT_DISPLAY(Xdisplay);
|
|
char* s = ServerVendor(dpy);
|
|
int i = VendorRelease(dpy);
|
|
return s48_cons( s48_enter_string(s),
|
|
s48_enter_integer(i) );
|
|
}
|
|
|
|
s48_value scx_Display_Protocol_Version(s48_value Xdisplay) {
|
|
Display* dpy = SCX_EXTRACT_DISPLAY(Xdisplay);
|
|
int maj = ProtocolVersion(dpy);
|
|
int min = ProtocolRevision(dpy);
|
|
return s48_cons( s48_enter_integer(maj),
|
|
s48_enter_integer(min) );
|
|
}
|
|
|
|
s48_value scx_Display_Screen_Count(s48_value Xdisplay) {
|
|
int cnt = ScreenCount(SCX_EXTRACT_DISPLAY(Xdisplay));
|
|
return s48_enter_integer(cnt);
|
|
}
|
|
|
|
|
|
s48_value scx_Display_Image_Byte_Order(s48_value Xdisplay) {
|
|
Display* dpy = SCX_EXTRACT_DISPLAY(Xdisplay);
|
|
return Bits_To_Symbols( (unsigned long)ImageByteOrder(dpy),
|
|
Byte_Order_Syms );
|
|
}
|
|
|
|
s48_value scx_Display_Bitmap_Unit(s48_value Xdisplay) {
|
|
int bu = BitmapUnit(SCX_EXTRACT_DISPLAY(Xdisplay));
|
|
return s48_enter_integer(bu);
|
|
}
|
|
|
|
s48_value scx_Display_Bitmap_Bit_Order(s48_value Xdisplay) {
|
|
Display* dpy = SCX_EXTRACT_DISPLAY(Xdisplay);
|
|
return Bits_To_Symbols( (unsigned long)BitmapBitOrder(dpy),
|
|
Byte_Order_Syms );
|
|
}
|
|
|
|
s48_value scx_Display_Bitmap_Pad(s48_value Xdisplay) {
|
|
int bp = BitmapPad(SCX_EXTRACT_DISPLAY(Xdisplay));
|
|
return s48_enter_integer(bp);
|
|
}
|
|
|
|
s48_value scx_Display_Width(s48_value Xdisplay) {
|
|
Display* dpy = SCX_EXTRACT_DISPLAY(Xdisplay);
|
|
return s48_enter_integer(DisplayWidth(dpy, DefaultScreen(dpy)));
|
|
}
|
|
|
|
s48_value scx_Display_Height(s48_value Xdisplay) {
|
|
Display* dpy = SCX_EXTRACT_DISPLAY(Xdisplay);
|
|
return s48_enter_integer(DisplayHeight(dpy, DefaultScreen(dpy)));
|
|
}
|
|
|
|
s48_value scx_Display_Width_Mm (s48_value Xdisplay) {
|
|
Display* dpy = SCX_EXTRACT_DISPLAY(Xdisplay);
|
|
return s48_enter_integer(DisplayWidthMM(dpy, DefaultScreen(dpy)));
|
|
}
|
|
|
|
s48_value scx_Display_Height_Mm (s48_value Xdisplay) {
|
|
Display* dpy = SCX_EXTRACT_DISPLAY(Xdisplay);
|
|
return s48_enter_integer(DisplayHeightMM(dpy, DefaultScreen(dpy)));
|
|
}
|
|
|
|
s48_value scx_Display_Motion_Buffer_Size(s48_value Xdisplay) {
|
|
int mbs = XDisplayMotionBufferSize(SCX_EXTRACT_DISPLAY(Xdisplay));
|
|
return s48_enter_integer(mbs);
|
|
}
|
|
|
|
s48_value scx_Display_Flush_Output (s48_value Xdisplay) {
|
|
XFlush (SCX_EXTRACT_DISPLAY(Xdisplay));
|
|
return S48_UNSPECIFIC;
|
|
}
|
|
|
|
s48_value scx_Display_Wait_Output (s48_value Xdisplay, s48_value discard) {
|
|
XSync (SCX_EXTRACT_DISPLAY(Xdisplay), !S48_FALSE_P(discard));
|
|
return S48_UNSPECIFIC;
|
|
}
|
|
|
|
s48_value scx_No_Op (s48_value Xdisplay) {
|
|
XNoOp(SCX_EXTRACT_DISPLAY(Xdisplay));
|
|
return S48_UNSPECIFIC;
|
|
}
|
|
|
|
s48_value scx_List_Depths (s48_value Xdisplay, s48_value scr) {
|
|
int i, num;
|
|
int* p;
|
|
s48_value ret = S48_FALSE;
|
|
S48_DECLARE_GC_PROTECT(1);
|
|
|
|
p = XListDepths(SCX_EXTRACT_DISPLAY(Xdisplay),
|
|
s48_extract_integer(scr), &num);
|
|
if (p) {
|
|
S48_GC_PROTECT_1(ret);
|
|
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 scx_List_Pixmap_Formats (s48_value Xdisplay) {
|
|
int num, i;
|
|
XPixmapFormatValues* p;
|
|
s48_value ret = S48_FALSE, t = S48_FALSE;
|
|
S48_DECLARE_GC_PROTECT(2);
|
|
|
|
p = XListPixmapFormats(SCX_EXTRACT_DISPLAY(Xdisplay), &num);
|
|
|
|
if (p) {
|
|
S48_GC_PROTECT_2(ret, t);
|
|
ret = s48_make_vector (num, S48_FALSE);
|
|
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].scanline_pad),
|
|
S48_NULL)));
|
|
S48_VECTOR_SET(ret, i, t);
|
|
}
|
|
XFree ((char *)p);
|
|
}
|
|
|
|
S48_GC_UNPROTECT();
|
|
return ret;
|
|
}
|
|
|
|
s48_value scx_Display_Select_Input(s48_value Xdisplay, s48_value Xwindow,
|
|
s48_value event_mask) {
|
|
XSelectInput(SCX_EXTRACT_DISPLAY(Xdisplay),
|
|
SCX_EXTRACT_WINDOW(Xwindow),
|
|
Symbols_To_Bits(event_mask, Event_Mask_Syms));
|
|
}
|
|
|
|
void scx_init_display(void) {
|
|
S48_GC_PROTECT_GLOBAL(internal_after_function_binding);
|
|
internal_after_function_binding =
|
|
s48_get_imported_binding("internal-after-function");
|
|
|
|
S48_EXPORT_FUNCTION(scx_Set_After_Function);
|
|
S48_EXPORT_FUNCTION(scx_Open_Display);
|
|
S48_EXPORT_FUNCTION(scx_Close_Display);
|
|
S48_EXPORT_FUNCTION(scx_Display_Message_fd);
|
|
S48_EXPORT_FUNCTION(scx_Display_Default_Root_Window);
|
|
S48_EXPORT_FUNCTION(scx_Display_Default_Colormap);
|
|
S48_EXPORT_FUNCTION(scx_Display_Default_Gcontext);
|
|
S48_EXPORT_FUNCTION(scx_Display_Default_Depth);
|
|
S48_EXPORT_FUNCTION(scx_Display_Default_Screen_Number);
|
|
S48_EXPORT_FUNCTION(scx_Display_Default_Visual);
|
|
S48_EXPORT_FUNCTION(scx_Display_Cells);
|
|
S48_EXPORT_FUNCTION(scx_Display_Planes);
|
|
S48_EXPORT_FUNCTION(scx_Display_String);
|
|
S48_EXPORT_FUNCTION(scx_Display_Vendor);
|
|
S48_EXPORT_FUNCTION(scx_Display_Protocol_Version);
|
|
S48_EXPORT_FUNCTION(scx_Display_Screen_Count);
|
|
S48_EXPORT_FUNCTION(scx_Display_Image_Byte_Order);
|
|
S48_EXPORT_FUNCTION(scx_Display_Bitmap_Unit);
|
|
S48_EXPORT_FUNCTION(scx_Display_Bitmap_Bit_Order);
|
|
S48_EXPORT_FUNCTION(scx_Display_Bitmap_Pad);
|
|
S48_EXPORT_FUNCTION(scx_Display_Width);
|
|
S48_EXPORT_FUNCTION(scx_Display_Height);
|
|
S48_EXPORT_FUNCTION(scx_Display_Width_Mm);
|
|
S48_EXPORT_FUNCTION(scx_Display_Height_Mm);
|
|
S48_EXPORT_FUNCTION(scx_Display_Motion_Buffer_Size);
|
|
S48_EXPORT_FUNCTION(scx_Display_Flush_Output);
|
|
S48_EXPORT_FUNCTION(scx_Display_Wait_Output);
|
|
S48_EXPORT_FUNCTION(scx_No_Op);
|
|
S48_EXPORT_FUNCTION(scx_List_Depths);
|
|
S48_EXPORT_FUNCTION(scx_List_Pixmap_Formats);
|
|
S48_EXPORT_FUNCTION(scx_Display_Select_Input);
|
|
}
|