#include "xlib.h" unsigned long Attribs_To_XSetWindowAttributes(s48_value attribs, XSetWindowAttributes* Xattrs) { unsigned long mask = s48_extract_integer(S48_CAR(attribs)); s48_value v = S48_CDR(attribs); if (mask & CWBackPixmap) Xattrs->background_pixmap = SCX_EXTRACT_PIXMAP(S48_VECTOR_REF(v, 0)); if (mask & CWBackPixel) Xattrs->background_pixel = s48_extract_integer(S48_VECTOR_REF(v, 1)); if (mask & CWBorderPixmap) Xattrs->border_pixmap = SCX_EXTRACT_PIXMAP(S48_VECTOR_REF(v, 2)); if (mask & CWBorderPixel) Xattrs->border_pixel = s48_extract_integer(S48_VECTOR_REF(v, 3)); if (mask & CWBitGravity) Xattrs->bit_gravity = s48_extract_integer(S48_VECTOR_REF(v, 4)); if (mask & CWWinGravity) Xattrs->win_gravity = s48_extract_integer(S48_VECTOR_REF(v, 5)); if (mask & CWBackingStore) Xattrs->backing_store = s48_extract_integer(S48_VECTOR_REF(v, 6)); if (mask & CWBackingPlanes) Xattrs->backing_planes = s48_extract_integer(S48_VECTOR_REF(v, 7)); if (mask & CWBackingPixel) Xattrs->backing_pixel = s48_extract_integer(S48_VECTOR_REF(v, 8)); if (mask & CWOverrideRedirect) Xattrs->override_redirect = s48_extract_integer(S48_VECTOR_REF(v, 9)); if (mask & CWSaveUnder) Xattrs->save_under = s48_extract_integer(S48_VECTOR_REF(v, 10)); if (mask & CWEventMask) Xattrs->event_mask = s48_extract_integer(S48_VECTOR_REF(v, 11)); if (mask & CWDontPropagate) Xattrs->do_not_propagate_mask = s48_extract_integer(S48_VECTOR_REF(v, 12)); if (mask & CWColormap) Xattrs->colormap = SCX_EXTRACT_COLORMAP(S48_VECTOR_REF(v, 13)); if (mask & CWCursor) Xattrs->cursor = SCX_EXTRACT_CURSOR(S48_VECTOR_REF(v, 14)); return mask; } s48_value scx_Create_Window (s48_value Xdisplay, s48_value Xparent, s48_value x, s48_value y, s48_value width, s48_value height, s48_value border_width, s48_value depth, s48_value class, s48_value Xvisual, s48_value attribs) { Window win; XSetWindowAttributes Xattrs; unsigned long mask = Attribs_To_XSetWindowAttributes( attribs, &Xattrs ); int dep = S48_FALSE_P(depth) ? CopyFromParent : s48_extract_integer(depth); int cla = 0; Visual* vis = S48_FALSE_P(Xvisual) ? CopyFromParent : SCX_EXTRACT_VISUAL(Xvisual); switch (s48_extract_integer(class)) { case 0: cla = InputOutput; case 1: cla = InputOnly; case 2: cla = CopyFromParent; } win = XCreateWindow( SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_WINDOW(Xparent), (int)s48_extract_integer(x), (int)s48_extract_integer(y), (int)s48_extract_integer (width), (int)s48_extract_integer (height), (int)s48_extract_integer (border_width), dep, cla, vis, mask,&Xattrs ); return SCX_ENTER_WINDOW(win); } s48_value scx_Destroy_Window (s48_value Xdisplay, s48_value Xwindow) { XDestroyWindow (SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_WINDOW(Xwindow)); return S48_UNSPECIFIC; } s48_value scx_Change_Window_Attributes(s48_value Xwindow, s48_value Xdisplay, s48_value attribs) { XSetWindowAttributes Xattrs; unsigned long mask = Attribs_To_XSetWindowAttributes( attribs, &Xattrs ); XChangeWindowAttributes(SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_WINDOW(Xwindow), mask, &Xattrs); return S48_UNSPECIFIC; } s48_value scx_Get_Window_Attributes(s48_value Xdisplay, s48_value Xwindow) { XWindowAttributes WA; S48_DECLARE_GC_PROTECT(1); s48_value res = S48_NULL; if (!XGetWindowAttributes(SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_WINDOW(Xwindow), &WA)) res = S48_FALSE; else { S48_GC_PROTECT_1(res); res = s48_make_vector(23, S48_FALSE); S48_VECTOR_SET(res, 0, s48_enter_fixnum(WA.x)); S48_VECTOR_SET(res, 1, s48_enter_fixnum(WA.y)); S48_VECTOR_SET(res, 2, s48_enter_fixnum(WA.width)); S48_VECTOR_SET(res, 3, s48_enter_fixnum(WA.height)); S48_VECTOR_SET(res, 4, s48_enter_fixnum(WA.border_width)); S48_VECTOR_SET(res, 5, s48_enter_fixnum(WA.depth)); S48_VECTOR_SET(res, 6, SCX_ENTER_VISUAL(WA.visual)); S48_VECTOR_SET(res, 7, SCX_ENTER_WINDOW(WA.root)); S48_VECTOR_SET(res, 8, s48_enter_integer(WA.class)); S48_VECTOR_SET(res, 9, s48_enter_integer(WA.bit_gravity)); S48_VECTOR_SET(res, 10, s48_enter_integer(WA.win_gravity)); S48_VECTOR_SET(res, 11, s48_enter_integer(WA.backing_store)); S48_VECTOR_SET(res, 12, s48_enter_integer(WA.backing_planes)); S48_VECTOR_SET(res, 13, SCX_ENTER_PIXEL(WA.backing_pixel)); S48_VECTOR_SET(res, 14, s48_enter_fixnum(WA.save_under)); S48_VECTOR_SET(res, 15, SCX_ENTER_COLORMAP(WA.colormap)); S48_VECTOR_SET(res, 16, s48_enter_fixnum(WA.map_installed)); S48_VECTOR_SET(res, 17, s48_enter_integer(WA.map_state)); S48_VECTOR_SET(res, 18, s48_enter_integer(WA.all_event_masks)); S48_VECTOR_SET(res, 19, s48_enter_integer(WA.your_event_mask)); S48_VECTOR_SET(res, 20, s48_enter_integer(WA.do_not_propagate_mask)); S48_VECTOR_SET(res, 21, s48_enter_fixnum(WA.override_redirect)); S48_VECTOR_SET(res, 22, S48_FALSE); //S48_VECTOR_SET(res, 22, s48_enter_fixnum((long)WA.screen)); // WA.screen not yet supported res = s48_cons(s48_enter_integer((1L<<23) - 1), res); S48_GC_UNPROTECT(); } return res; } s48_value Changes_To_XWindowChanges(s48_value changes, XWindowChanges* WC) { unsigned long mask = s48_extract_integer(S48_CAR(changes)); s48_value v = S48_CDR(changes); if (mask & CWX) WC->x = s48_extract_integer(S48_VECTOR_REF(v, 0)); if (mask & CWY) WC->y = s48_extract_integer(S48_VECTOR_REF(v, 1)); if (mask & CWWidth) WC->width = s48_extract_integer(S48_VECTOR_REF(v, 2)); if (mask & CWHeight) WC->height = s48_extract_integer(S48_VECTOR_REF(v, 3)); if (mask & CWBorderWidth) WC->border_width = s48_extract_integer(S48_VECTOR_REF(v, 4)); if (mask & CWSibling) WC->sibling = SCX_EXTRACT_WINDOW(S48_VECTOR_REF(v, 5)); if (mask & CWStackMode) WC->stack_mode = s48_extract_integer(S48_VECTOR_REF(v, 6)); return mask; } s48_value scx_Configure_Window (s48_value Xwindow, s48_value Xdisplay, s48_value changes) { XWindowChanges WC; unsigned long mask = Changes_To_XWindowChanges(changes, &WC); XConfigureWindow (SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_WINDOW(Xwindow), mask, &WC); return S48_UNSPECIFIC; } s48_value scx_Map_Window(s48_value Xwindow, s48_value Xdisplay) { XMapWindow(SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_WINDOW(Xwindow)); return S48_UNSPECIFIC; } s48_value scx_Unmap_Window(s48_value Xwindow, s48_value Xdisplay) { XUnmapWindow(SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_WINDOW(Xwindow)); return S48_UNSPECIFIC; } s48_value scx_Destroy_Subwindows (s48_value Xwindow, s48_value Xdisplay) { XDestroySubwindows(SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_WINDOW(Xwindow)); return S48_UNSPECIFIC; } s48_value scx_Map_Subwindows (s48_value Xwindow, s48_value Xdisplay) { XMapSubwindows(SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_WINDOW(Xwindow)); return S48_UNSPECIFIC; } s48_value scx_Unmap_Subwindows (s48_value Xwindow, s48_value Xdisplay) { XUnmapSubwindows(SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_WINDOW(Xwindow)); return S48_UNSPECIFIC; } s48_value scx_Circulate_Subwindows(s48_value Xwindow, s48_value Xdisplay, s48_value dir) { XCirculateSubwindows(SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_WINDOW(Xwindow), S48_FALSE_P(dir) ? RaiseLowest : LowerHighest); return S48_UNSPECIFIC; } s48_value scx_Query_Tree (s48_value Xwindow, s48_value Xdisplay) { Window root, parent, *children; int i; unsigned n; s48_value v = S48_FALSE, ret = S48_FALSE; S48_DECLARE_GC_PROTECT(2); if (! XQueryTree (SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_WINDOW(Xwindow), &root, &parent, &children, &n)) return S48_FALSE; ret = s48_make_vector(3, S48_FALSE); v = S48_FALSE; S48_GC_PROTECT_2 (v, ret); // vector of child-windows v = s48_make_vector (n, S48_FALSE); for (i = 0; i < n; i++) { S48_VECTOR_SET(v, i, SCX_ENTER_WINDOW(children[i])); } if (children != NULL) XFree(children); S48_VECTOR_SET(ret, 0, SCX_ENTER_WINDOW(root)); S48_VECTOR_SET(ret, 1, SCX_ENTER_WINDOW(parent)); S48_VECTOR_SET(ret, 2, v); S48_GC_UNPROTECT(); return ret; } s48_value scx_Translate_Coordinates (s48_value Xdisplay, s48_value srcXwindow, s48_value x, s48_value y, s48_value dstXwindow) { int rx, ry; Window child; s48_value v = S48_FALSE; S48_DECLARE_GC_PROTECT(1); if (!XTranslateCoordinates (SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_WINDOW(srcXwindow), SCX_EXTRACT_WINDOW(dstXwindow), (int)s48_extract_integer (x), (int)s48_extract_integer (y), &rx, &ry, &child)) return S48_FALSE; S48_GC_PROTECT_1 (v); v = s48_make_vector(3, S48_FALSE); S48_VECTOR_SET(v, 0, s48_enter_fixnum(rx)); S48_VECTOR_SET(v, 1, s48_enter_fixnum(ry)); S48_VECTOR_SET(v, 2, SCX_ENTER_WINDOW(child)); S48_GC_UNPROTECT(); return v; } s48_value scx_Query_Pointer (s48_value Xdisplay, s48_value Xwindow) { s48_value v = S48_FALSE; Bool ret; Window root, child; int r_x, r_y, x, y; unsigned int mask; S48_DECLARE_GC_PROTECT(1); ret = XQueryPointer (SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_WINDOW(Xwindow), &root, &child, &r_x, &r_y, &x, &y, &mask); v = s48_make_vector(8, S48_FALSE); S48_GC_PROTECT_1(v); S48_VECTOR_SET(v, 0, s48_enter_fixnum(x)); S48_VECTOR_SET(v, 1, s48_enter_fixnum(y)); S48_VECTOR_SET(v, 2, ret ? S48_TRUE : S48_FALSE); S48_VECTOR_SET(v, 3, SCX_ENTER_WINDOW(root)); S48_VECTOR_SET(v, 4, s48_enter_fixnum(r_x)); S48_VECTOR_SET(v, 5, s48_enter_fixnum(r_y)); S48_VECTOR_SET(v, 6, SCX_ENTER_WINDOW(child)); S48_VECTOR_SET(v, 7, s48_enter_integer((unsigned long)mask)); S48_GC_UNPROTECT(); return v; } s48_value scx_Get_Geometry(s48_value Xdisplay, s48_value Xdrawable) { s48_value v = S48_FALSE; Window root; int x, y; unsigned int width, height, border_width, depth; S48_DECLARE_GC_PROTECT(1); XGetGeometry(SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_DRAWABLE(Xdrawable), &root, &x, &y, &width, &height, &border_width, &depth); v = s48_make_vector(7, S48_FALSE); S48_GC_PROTECT_1(v); S48_VECTOR_SET(v, 0, SCX_ENTER_WINDOW(root)); S48_VECTOR_SET(v, 1, s48_enter_fixnum(x)); S48_VECTOR_SET(v, 2, s48_enter_fixnum(y)); S48_VECTOR_SET(v, 3, s48_enter_fixnum(width)); S48_VECTOR_SET(v, 4, s48_enter_fixnum(height)); S48_VECTOR_SET(v, 5, s48_enter_fixnum(border_width)); S48_VECTOR_SET(v, 6, s48_enter_fixnum(depth)); S48_GC_UNPROTECT(); return v; } void scx_init_window(void) { S48_EXPORT_FUNCTION(scx_Create_Window); S48_EXPORT_FUNCTION(scx_Destroy_Window); S48_EXPORT_FUNCTION(scx_Change_Window_Attributes); S48_EXPORT_FUNCTION(scx_Get_Window_Attributes); S48_EXPORT_FUNCTION(scx_Configure_Window); S48_EXPORT_FUNCTION(scx_Map_Window); S48_EXPORT_FUNCTION(scx_Unmap_Window); S48_EXPORT_FUNCTION(scx_Destroy_Subwindows); S48_EXPORT_FUNCTION(scx_Map_Subwindows); S48_EXPORT_FUNCTION(scx_Unmap_Subwindows); S48_EXPORT_FUNCTION(scx_Circulate_Subwindows); S48_EXPORT_FUNCTION(scx_Query_Tree); S48_EXPORT_FUNCTION(scx_Translate_Coordinates); S48_EXPORT_FUNCTION(scx_Query_Pointer); S48_EXPORT_FUNCTION(scx_Get_Geometry); }