scx/c/xlib/display.c

243 lines
7.4 KiB
C
Raw Normal View History

2001-05-08 10:21:00 -04:00
#include "xlib.h"
#include "scheme48.h"
2001-07-09 09:39:59 -04:00
#include <sys/time.h>
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 scx_Open_Display (s48_value name) {
2001-05-21 11:33:32 -04:00
char* cname = (char*)0;
if (!S48_FALSE_P(name))
cname = s48_extract_string(name);
return SCX_ENTER_DISPLAY(XOpenDisplay(cname));
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 scx_Close_Display(s48_value Xdisplay) {
XCloseDisplay(SCX_EXTRACT_DISPLAY(Xdisplay));
2001-05-21 11:33:32 -04:00
return S48_UNSPECIFIC;
2001-05-08 10:21:00 -04:00
}
// 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));
2001-07-09 09:39:59 -04:00
/* 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);
}
2001-05-21 11:33:32 -04:00
// 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);
2001-05-08 10:21:00 -04:00
}
s48_value scx_Display_Default_Colormap(s48_value Xdisplay) {
Display* dpy = SCX_EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
Colormap cmp = DefaultColormap(dpy, DefaultScreen(dpy));
return SCX_ENTER_COLORMAP(cmp);
2001-05-08 10:21:00 -04:00
}
s48_value scx_Display_Default_Gcontext(s48_value Xdisplay) {
Display* dpy = SCX_EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
GC gc = DefaultGC(dpy, DefaultScreen(dpy));
return SCX_ENTER_GCONTEXT(gc);
2001-05-08 10:21:00 -04:00
}
s48_value scx_Display_Default_Depth(s48_value Xdisplay) {
Display* dpy = SCX_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
}
s48_value scx_Display_Default_Screen_Number(s48_value Xdisplay) {
return s48_enter_integer(DefaultScreen(SCX_EXTRACT_DISPLAY(Xdisplay)));
2001-05-08 10:21:00 -04:00
}
s48_value scx_Display_Cells(s48_value Xdisplay, s48_value ScrNum) {
2001-05-21 11:33:32 -04:00
int num = (int)s48_extract_integer(ScrNum);
return s48_enter_integer(DisplayCells(SCX_EXTRACT_DISPLAY(Xdisplay), num));
2001-05-08 10:21:00 -04:00
}
s48_value scx_Display_Planes(s48_value Xdisplay, s48_value ScrNum) {
2001-05-21 11:33:32 -04:00
int num = (int)s48_extract_integer(ScrNum);
return s48_enter_integer(DisplayPlanes(SCX_EXTRACT_DISPLAY(Xdisplay), num));
2001-05-08 10:21:00 -04:00
}
s48_value scx_Display_String(s48_value Xdisplay) {
char* s = DisplayString(SCX_EXTRACT_DISPLAY(Xdisplay));
2001-05-21 11:33:32 -04:00
return s48_enter_string(s);
2001-05-08 10:21:00 -04:00
}
s48_value scx_Display_Vendor(s48_value Xdisplay) {
Display* dpy = SCX_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
}
s48_value scx_Display_Protocol_Version(s48_value Xdisplay) {
Display* dpy = SCX_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
}
s48_value scx_Display_Screen_Count(s48_value Xdisplay) {
int cnt = ScreenCount(SCX_EXTRACT_DISPLAY(Xdisplay));
2001-05-21 11:33:32 -04:00
return s48_enter_integer(cnt);
2001-05-08 10:21:00 -04:00
}
s48_value scx_Display_Image_Byte_Order(s48_value Xdisplay) {
Display* dpy = SCX_EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
return Bits_To_Symbols( (unsigned long)ImageByteOrder(dpy),
2001-07-30 10:13:03 -04:00
Byte_Order_Syms );
2001-05-08 10:21:00 -04:00
}
s48_value scx_Display_Bitmap_Unit(s48_value Xdisplay) {
int bu = BitmapUnit(SCX_EXTRACT_DISPLAY(Xdisplay));
return s48_enter_integer(bu);
2001-05-08 10:21:00 -04:00
}
s48_value scx_Display_Bitmap_Bit_Order(s48_value Xdisplay) {
Display* dpy = SCX_EXTRACT_DISPLAY(Xdisplay);
2001-05-21 11:33:32 -04:00
return Bits_To_Symbols( (unsigned long)BitmapBitOrder(dpy),
2001-07-30 10:13:03 -04:00
Byte_Order_Syms );
2001-05-08 10:21:00 -04:00
}
s48_value scx_Display_Bitmap_Pad(s48_value Xdisplay) {
int bp = BitmapPad(SCX_EXTRACT_DISPLAY(Xdisplay));
return s48_enter_integer(bp);
2001-05-08 10:21:00 -04:00
}
s48_value scx_Display_Width(s48_value Xdisplay) {
Display* dpy = SCX_EXTRACT_DISPLAY(Xdisplay);
return s48_enter_integer(DisplayWidth(dpy, DefaultScreen(dpy)));
2001-05-08 10:21:00 -04:00
}
s48_value scx_Display_Height(s48_value Xdisplay) {
Display* dpy = SCX_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
}
s48_value scx_Display_Width_Mm (s48_value Xdisplay) {
Display* dpy = SCX_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
}
s48_value scx_Display_Height_Mm (s48_value Xdisplay) {
Display* dpy = SCX_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
}
s48_value scx_Display_Motion_Buffer_Size(s48_value Xdisplay) {
int mbs = XDisplayMotionBufferSize(SCX_EXTRACT_DISPLAY(Xdisplay));
return s48_enter_integer(mbs);
2001-05-08 10:21:00 -04:00
}
s48_value scx_Display_Flush_Output (s48_value Xdisplay) {
XFlush (SCX_EXTRACT_DISPLAY(Xdisplay));
2001-05-21 11:33:32 -04:00
return S48_UNSPECIFIC;
2001-05-08 10:21:00 -04:00
}
s48_value scx_Display_Wait_Output (s48_value Xdisplay, s48_value discard) {
XSync (SCX_EXTRACT_DISPLAY(Xdisplay), !S48_FALSE_P(discard));
2001-05-21 11:33:32 -04:00
return S48_UNSPECIFIC;
2001-05-08 10:21:00 -04:00
}
s48_value scx_No_Op (s48_value Xdisplay) {
XNoOp(SCX_EXTRACT_DISPLAY(Xdisplay));
2001-05-21 11:33:32 -04:00
return S48_UNSPECIFIC;
2001-05-08 10:21:00 -04:00
}
s48_value scx_List_Depths (s48_value Xdisplay, s48_value scr) {
2001-05-21 11:33:32 -04:00
int i, num;
int* p;
s48_value ret = S48_FALSE;
S48_DECLARE_GC_PROTECT(1);
2001-05-08 10:21:00 -04:00
p = XListDepths(SCX_EXTRACT_DISPLAY(Xdisplay),
s48_extract_integer(scr), &num);
if (p) {
S48_GC_PROTECT_1(ret);
2001-05-21 11:33:32 -04:00
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
}
s48_value scx_List_Pixmap_Formats (s48_value Xdisplay) {
2001-05-21 11:33:32 -04:00
int num, i;
XPixmapFormatValues* p;
s48_value ret = S48_FALSE, t = S48_FALSE;
S48_DECLARE_GC_PROTECT(2);
2001-05-08 10:21:00 -04:00
p = XListPixmapFormats(SCX_EXTRACT_DISPLAY(Xdisplay), &num);
2001-05-21 11:33:32 -04:00
if (p) {
S48_GC_PROTECT_2(ret, t);
ret = s48_make_vector (num, S48_FALSE);
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 scx_init_display(void) {
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_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);
2001-05-08 10:21:00 -04:00
}