24 #define stdin_fileno fileno(stdin)
30 typedef struct wl_EventClosure
57 static long xevent_mask[] = {
65 PointerMotionMask | PointerMotionHintMask | ButtonMotionMask |
66 Button1MotionMask | Button2MotionMask | Button3MotionMask |
67 Button4MotionMask | Button5MotionMask,
78 SubstructureNotifyMask,
79 SubstructureNotifyMask,
82 SubstructureRedirectMask,
83 SubstructureNotifyMask,
85 SubstructureRedirectMask,
89 SubstructureRedirectMask,
101 static char* xevent_name[] = {
145 #define DrawableGC(w)(GC)GetIntAttr(GetPsiAttr(w,"graphic_context"),"id")
146 #define WindowDisplayList(w) GetIntAttr(GetPsiAttr(w,"display_list"),"id")
149 #define DISP(X)(Display *)val[X]
150 #define DRAW(X)(Drawable)val[X]
151 #define WIND(X)(Window)val[X]
152 #define GCVAL(X)(GC)val[X]
153 #define FONT(X)(Font)val[X]
154 #define CMAP(X)(Colormap)val[X]
155 #define STRG(X) ((char *)val[X])
170 static int x_handle_error(Display *display,XErrorEvent *x_error)
173 XGetErrorText(display,x_error->error_code,msg,128);
188 static int x_handle_fatal_error(Display *display)
206 void bk_stack_add_int_attr(
ptr_psi_term t,
char *attrname,
long value)
320 bk_stack_add_int_attr(p,f,v);
333 long GetIntAttr(
ptr_psi_term psiTerm,
char *attributeName)
342 Errorline(
"in GetIntAttr: didn't find %s on %P\n",
375 Errorline(
"in GetPsiAttr: no attribute name on psi-term ?\n");
381 Errorline(
"in GetPsiAttr: no value on psi-term ?\n");
400 static void ResizePixmap(
ptr_psi_term psi_window,Display *display,Window window,
unsigned long width,
unsigned long height)
406 XWindowAttributes attr;
411 psiPixmap = GetPsiAttr(psi_window,
"pixmap");
414 if((pixmap = GetIntAttr(psiPixmap,
"id")) != 0)
417 XFreePixmap(display,pixmap);
420 psiPixmapGC = GetPsiAttr(psiPixmap,
"graphic_context");
423 pixmapGC=(GC)GetIntAttr(psiPixmapGC,
"id");
425 XFreeGC(display,pixmapGC);
427 bk_stack_add_int_attr(psiPixmap,
"id",(
long)
NULL);
428 bk_stack_add_int_attr(psiPixmapGC,
"id",(
long)
NULL);
432 XGetWindowAttributes(display,window,&attr);
433 if((pixmap = XCreatePixmap(display,window,
434 attr.width+1,attr.height+1,
437 bk_stack_add_int_attr(psiPixmap,
"id",(
long)pixmap);
438 gcvalues.cap_style = CapRound;
439 gcvalues.join_style = JoinRound;
440 pixmapGC = XCreateGC(display,pixmap,
441 GCJoinStyle|GCCapStyle,&gcvalues);
445 bk_stack_add_int_attr(psiPixmapGC,
"id",(
long)pixmapGC);
447 psiPixmapGC=NewPsi(xgc,
"id",(
long)pixmapGC);
448 bk_change_psi_attr(psiPixmap,
"graphic_context",psiPixmapGC);
463 static void FreeWindow(Display *display,
ptr_psi_term psi_window)
468 XFreeGC(display,DrawableGC(psi_window));
469 x_free_display_list((
ListHeader *)WindowDisplayList(psi_window));
471 psiPixmap = GetPsiAttr(psi_window,
"pixmap");
472 XFreeGC(display,DrawableGC(psiPixmap));
473 XFreePixmap(display,GetIntAttr(psiPixmap,
"id"));
485 long xcOpenConnection()
490 Display * connection;
500 if(strcmp(STRG(0),
""))
505 if(connection = XOpenDisplay(display))
507 psiConnection = NewPsi(xdisplay,
"id",(
long)connection);
514 Errorline(
"could not open connection in %P.\n",g);
529 long xcDefaultRootWindow()
543 psiRoot = NewPsi(xwindow,
"id",(
long)DefaultRootWindow(display));
560 static long GetConnectionAttribute(Display *display,
long attributeId,
long *attribute)
565 *attribute =(
unsigned long) ConnectionNumber(display);
569 *attribute = display->proto_major_version;
574 *attribute =(
unsigned long)(display->proto_minor_version);
578 *attribute =(
unsigned long) ServerVendor(display);
581 *attribute =(
unsigned long) ImageByteOrder(display);
584 *attribute =(
unsigned long) BitmapUnit(display);
587 *attribute =(
unsigned long) BitmapPad(display);
590 *attribute =(
unsigned long) BitmapBitOrder(display);
593 *attribute =(
unsigned long) VendorRelease(display);
597 *attribute =(
unsigned long)(display->qlen);
601 *attribute =(
unsigned long) LastKnownRequestProcessed(display);
605 *attribute =(
unsigned long)(display->request);
609 *attribute =(
unsigned long) DisplayString(display);
612 *attribute =(
unsigned long) DefaultScreen(display);
616 *attribute =(
unsigned long)(display->min_keycode);
621 *attribute =(
unsigned long)(display->max_keycode);
641 long xcGetConnectionAttribute()
653 if(GetConnectionAttribute(DISP(0),DRAW(1),&attr))
660 Errorline(
"could not get connection attribute in %P.\n",g);
677 static long GetScreenAttribute(Display *display,
long screen,
long attributeId,
long *attribute)
682 s = ScreenOfDisplay(display,screen);
686 *attribute =(
unsigned long) DisplayOfScreen(s);
689 *attribute =(
unsigned long) RootWindowOfScreen(s);
692 *attribute =(
unsigned long) WidthOfScreen(s);
695 *attribute =(
unsigned long) HeightOfScreen(s);
698 *attribute =(
unsigned long) WidthMMOfScreen(s);
701 *attribute =(
unsigned long) HeightMMOfScreen(s);
704 *attribute =(
unsigned long) DefaultDepthOfScreen(s);
707 *attribute =(
unsigned long) DefaultVisualOfScreen(s);
710 *attribute =(
unsigned long) DefaultGCOfScreen(s);
713 *attribute =(
unsigned long) DefaultColormapOfScreen(s);
716 *attribute =(
unsigned long) WhitePixelOfScreen(s);
719 *attribute =(
unsigned long) BlackPixelOfScreen(s);
722 *attribute =(
unsigned long) MaxCmapsOfScreen(s);
725 *attribute =(
unsigned long) MinCmapsOfScreen(s);
728 *attribute =(
unsigned long) DoesBackingStore(s);
731 *attribute =(
unsigned long) DoesSaveUnders(s);
734 *attribute =(
unsigned long) EventMaskOfScreen(s);
752 long xcGetScreenAttribute()
765 if(GetScreenAttribute(DISP(0),DRAW(1),val[2],&attr))
772 Errorline(
"could not get screen attribute in %P.\n",g);
787 long xcCloseConnection()
797 XCloseDisplay(DISP(0));
816 long xcCreateSimpleWindow()
823 XWindowChanges changes;
824 unsigned long changesMask;
825 XSetWindowAttributes attributes;
826 unsigned long attributesMask;
834 for(j = 0; j < 14; j++)
846 if(window = XCreateSimpleWindow(DISP(0),WIND(1),
854 bk_stack_add_int_attr(psiWindow,
"id",(
long)window);
857 life_icon = XCreateBitmapFromData(DISP(0),window,life_icon_bits,
858 life_icon_width,life_icon_height);
863 hints.width =val[4] ;
864 hints.height = val[5];
865 hints.flags = PPosition | PSize;
868 XSetStandardProperties(DISP(0),window,
875 changes.width =val[4] ;
876 changes.height = val[5];
877 changesMask = CWX | CWY | CWWidth | CWHeight;
879 XReconfigureWMWindow(DISP(0),window,DefaultScreen(display),
880 changesMask,&changes);
883 XSetWindowBackground(DISP(0),window,val[6]);
886 XMoveResizeWindow(DISP(0),window,
887 val[2],val[3],val[4],val[5]);
890 attributes.background_pixel = val[6];
891 attributes.backing_pixel = val[6];
892 attributesMask = CWBackingPixel|CWBackPixel;
893 XChangeWindowAttributes(DISP(0),window,
894 attributesMask,&attributes);
909 x_show_window(DISP(0),window);
913 gcvalues.cap_style = CapRound;
914 gcvalues.join_style = JoinRound;
915 gc = XCreateGC(DISP(0),window,GCJoinStyle|GCCapStyle,&gcvalues);
916 bk_change_psi_attr(psiWindow,
"graphic_context",
917 NewPsi(xgc,
"id",(
long)gc));
920 bk_change_psi_attr(psiWindow,
"display_list",
921 NewPsi(xdisplaylist,
"id",(
long)x_display_list()));
924 bk_change_psi_attr(psiWindow,
"pixmap",
925 NewPsi(xpixmap,
"id",(
long)
NULL));
926 ResizePixmap(psiWindow,DISP(0),window,val[4],val[5]);
933 Errorline(
"could not create a simple window in %P.\n",g);
957 long xcCreateWindow()
962 XWindowChanges changes;
963 unsigned long changesMask;
965 long j,permanent,
show;
969 for(j = 0; j < 13; j++)
977 if(window = XCreateWindow(DISP(0),WIND(1),
982 0,(XSetWindowAttributes *)
NULL))
988 changes.width =val[4] ;
989 changes.height = val[5];
990 changesMask = CWX | CWY | CWWidth | CWHeight;
991 XConfigureWindow(DISP(0),window,changesMask,&changes);
995 hints.width =val[4] ;
996 hints.height = val[5];
997 hints.flags = PPosition | PSize;
998 XSetNormalHints(DISP(0),window,&hints);
1010 x_show_window(DISP(0),window);
1013 gcvalues.cap_style = CapRound;
1014 gcvalues.join_style = JoinRound;
1015 gc = XCreateGC(DISP(0),window,GCJoinStyle|GCCapStyle,&gcvalues);
1016 bk_stack_add_int_attr(args[12],
"gc",gc);
1019 bk_stack_add_int_attr(args[12],
"display_list",
NULL);
1025 Errorline(
"could not create window in %P.\n",g);
1043 long xcSetStandardProperties()
1061 hints.width = val[6] ;
1062 hints.height = val[7];
1063 hints.flags = PPosition | PSize;
1065 XSetStandardProperties(DISP(0),WIND(1),
1066 (
char*)val[2],(
char*)val[3],
1071 ResizePixmap(args[1],(Display *)val[0],val[1],val[6],val[7]);
1087 long xcGetWindowGeometry()
1092 unsigned int w,h,bw,d;
1101 if(XGetGeometry(DISP(0),DRAW(1),
1102 &r,&x,&y,&w,&h,&bw,&d))
1112 Errorline(
"could not get the geometry in %P.\n",g);
1129 static long GetWindowAttribute(Display *display,
long window,
long attributeId,
long *attribute)
1131 XWindowAttributes windowAttributes;
1134 XGetWindowAttributes(display,window,&windowAttributes);
1138 *attribute = windowAttributes.x;
1141 *attribute = windowAttributes.y;
1144 *attribute = windowAttributes.width;
1147 *attribute = windowAttributes.height;
1150 *attribute = windowAttributes.border_width;
1153 *attribute = windowAttributes.depth;
1156 *attribute = windowAttributes.root;
1159 *attribute =(
unsigned long)windowAttributes.screen;
1162 *attribute =(
unsigned long)windowAttributes.visual;
1165 *attribute = windowAttributes.class;
1168 *attribute = windowAttributes.all_event_masks;
1171 *attribute = windowAttributes.bit_gravity;
1174 *attribute = windowAttributes.win_gravity;
1177 *attribute = windowAttributes.backing_store;
1180 *attribute = windowAttributes.backing_planes;
1183 *attribute = windowAttributes.backing_pixel;
1186 *attribute = windowAttributes.override_redirect;
1189 *attribute = windowAttributes.save_under;
1192 *attribute = windowAttributes.your_event_mask;
1195 *attribute = windowAttributes.do_not_propagate_mask;
1198 *attribute = windowAttributes.colormap;
1201 *attribute = windowAttributes.map_installed;
1204 *attribute = windowAttributes.map_state;
1221 long xcGetWindowAttribute()
1235 if(GetWindowAttribute(DISP(0),WIND(1),val[2],&attr))
1242 Errorline(
"could not get a window attribute in %P.\n",g);
1257 long xcSetWindowGeometry()
1269 XMoveResizeWindow(DISP(0),DRAW(1),
1270 val[2],val[3],val[4],val[5]);
1273 ResizePixmap(args[1],(Display *)val[0],val[1],val[4],val[5]);
1300 XMoveWindow(DISP(0),DRAW(1), val[2],val[3]);
1318 static long SetWindowAttribute(
ptr_psi_term psi_window,Display *display,Drawable window,
unsigned long attributeId,
unsigned long attribute)
1320 XSetWindowAttributes attributes;
1321 XWindowChanges changes;
1322 unsigned long attributesMask = 0;
1323 unsigned long changesMask = 0;
1324 long backgroundChange =
FALSE;
1325 long sizeChange =
FALSE;
1326 unsigned int width,height;
1334 changes.x = attribute;
1338 changes.y = attribute;
1342 changes.width = attribute;
1343 changesMask |= CWWidth;
1344 XGetGeometry(display,window,&r,&x,&y,&width,&height,&bw,&d);
1349 changes.height = attribute;
1350 changesMask |= CWHeight;
1351 XGetGeometry(display,window,&r,&x,&y,&width,&height,&bw,&d);
1356 changes.border_width = attribute;
1357 changesMask |= CWBorderWidth;
1360 attributes.bit_gravity = attribute;
1361 attributesMask |= CWBitGravity;
1364 attributes.win_gravity = attribute;
1365 attributesMask |= CWWinGravity;
1368 attributes.backing_store = attribute;
1369 attributesMask |= CWBackingStore;
1372 attributes.backing_planes = attribute;
1373 attributesMask |= CWBackingPlanes;
1376 attributes.backing_pixel = attribute;
1377 attributesMask |= CWBackingPixel;
1380 attributes.override_redirect = attribute;
1381 attributesMask |= CWOverrideRedirect;
1384 attributes.save_under = attribute;
1385 attributesMask |= CWSaveUnder;
1388 attributes.event_mask = attribute;
1389 attributesMask |= CWEventMask;
1392 attributes.do_not_propagate_mask = attribute;
1393 attributesMask |= CWDontPropagate;
1396 attributes.colormap = attribute;
1397 attributesMask |= CWColormap;
1400 changes.sibling = attribute;
1401 changesMask |= CWSibling;
1404 changes.stack_mode = attribute;
1405 changesMask |= CWStackMode;
1408 attributes.background_pixmap = attribute;
1409 attributesMask |= CWBackPixmap;
1412 attributes.background_pixel = attribute;
1413 attributesMask |= CWBackPixel;
1414 backgroundChange =
TRUE;
1417 attributes.backing_pixel = attribute;
1418 attributesMask |= CWBackingPixel;
1421 attributes.border_pixmap = attribute;
1422 attributesMask |= CWBorderPixmap;
1425 attributes.border_pixel = attribute;
1426 attributesMask |= CWBorderPixel;
1429 attributes.cursor = attribute;
1430 attributesMask |= CWCursor;
1438 XConfigureWindow(display,window,changesMask,&changes);
1441 XChangeWindowAttributes(display,window,attributesMask,&attributes);
1443 if(backgroundChange)
1444 XClearArea(display,window,0,0,0,0,True);
1447 ResizePixmap(psi_window,display,window,width,height);
1460 long xcSetWindowAttribute()
1472 if(SetWindowAttribute(args[1],(Display *)val[0],val[1],val[2],val[3]))
1479 Errorline(
"could not set window attribute in %P.\n",g);
1505 XMapWindow(DISP(0),WIND(1));
1522 long xcRaiseWindow()
1532 XRaiseWindow(DISP(0),WIND(1));
1549 long xcUnmapWindow()
1559 XUnmapWindow(DISP(0),WIND(1));
1577 long xcMapSubwindows()
1587 XMapSubwindows(DISP(0),WIND(1));
1604 long xcUnmapSubwindows()
1614 XUnmapSubwindows(DISP(0),WIND(1));
1633 long xcClearWindow()
1643 XClearWindow(DISP(0),WIND(1));
1646 x_free_display_list((
ListHeader *)WindowDisplayList(args[1]));
1661 long xcResizeWindowPixmap()
1674 ResizePixmap(args[1],(Display *)val[0],val[1],val[2],val[3]);
1689 long xcSelectInput()
1700 XSelectInput(DISP(0),WIND(1),val[2]);
1714 long xcRefreshWindow()
1726 psiPixmap = GetPsiAttr(args[1],
"pixmap");
1727 if((pixmap =(Pixmap) GetIntAttr(psiPixmap,
"id")) != 0)
1728 x_refresh_window((Display *)val[0],val[1],pixmap,
1729 DrawableGC(psiPixmap),
1732 x_refresh_window((Display *)val[0],val[1],val[1],
1733 DrawableGC(args[1]),
1749 long xcPostScriptWindow()
1760 success = x_postscript_window((Display *) val[0],val[1],(
ListHeader *)GetIntAttr(GetPsiAttr(args[1],
"display_list"),
"id"),(
char *)val[2]);
1773 long xcDestroyWindow()
1784 psi = GetPsiAttr(args[1],
"permanent");
1787 Errorline(
"cannot destroy a permanent window.\n");
1793 FreeWindow((Display *)val[0],args[1]);
1794 XDestroyWindow(DISP(0),WIND(1));
1823 if(gc = XCreateGC(DISP(0),WIND(1),0,&GCvalues))
1830 Errorline(
"could not create gc in %P.\n",g);
1846 static long GetGCAttribute(GC gc,
long attributeId,
long *attribute)
1852 *attribute = gc->values.function;
1855 *attribute = gc->values.plane_mask;
1858 *attribute = gc->values.foreground;
1861 *attribute = gc->values.background;
1864 *attribute = gc->values.line_width;
1867 *attribute = gc->values.line_style;
1870 *attribute = gc->values.cap_style;
1873 *attribute = gc->values.join_style;
1876 *attribute = gc->values.fill_style;
1879 *attribute = gc->values.fill_rule;
1882 *attribute = gc->values.tile;
1885 *attribute = gc->values.stipple;
1888 *attribute = gc->values.ts_x_origin;
1891 *attribute = gc->values.ts_y_origin;
1894 *attribute = gc->values.font;
1897 *attribute = gc->values.subwindow_mode;
1900 *attribute = gc->values.graphics_exposures;
1903 *attribute = gc->values.clip_x_origin;
1906 *attribute = gc->values.clip_y_origin;
1909 *attribute = gc->values.clip_mask;
1912 *attribute = gc->values.dash_offset;
1915 *attribute =(
unsigned char)(gc->values.dashes);
1918 *attribute = gc->values.arc_mode;
1921 *attribute = gc->rects;
1924 *attribute = gc->dashes;
1942 long xcGetGCAttribute()
1954 if(GetGCAttribute((GC)DISP(0),(
long)GCVAL(1),&attr))
1961 Errorline(
"could not get gc attribute in %P.\n",g);
1978 static long SetGCAttribute(Display *display,GC gc,
long attributeId,
long attribute)
1980 XGCValues attributes;
1981 unsigned long attributesMask = 0;
1986 attributes.function = attribute;
1987 attributesMask |= GCFunction;
1990 attributes.plane_mask = attribute;
1991 attributesMask |= GCPlaneMask;
1994 attributes.foreground = attribute;
1995 attributesMask |= GCForeground;
1998 attributes.background = attribute;
1999 attributesMask |= GCBackground;
2002 attributes.line_width = attribute;
2003 attributesMask |= GCLineWidth;
2006 attributes.line_style = attribute;
2007 attributesMask |= GCLineStyle;
2010 attributes.cap_style = attribute;
2011 attributesMask |= GCCapStyle;
2014 attributes.join_style = attribute;
2015 attributesMask |= GCJoinStyle;
2018 attributes.fill_style = attribute;
2019 attributesMask |= GCFillStyle;
2022 attributes.fill_rule = attribute;
2023 attributesMask |= GCFillRule;
2026 attributes.tile = attribute;
2027 attributesMask |= GCTile;
2030 attributes.stipple = attribute;
2031 attributesMask |= GCStipple;
2034 attributes.ts_x_origin = attribute;
2035 attributesMask |= GCTileStipXOrigin;
2038 attributes.ts_y_origin = attribute;
2039 attributesMask |= GCTileStipYOrigin;
2042 attributes.font = attribute;
2043 attributesMask |= GCFont;
2046 attributes.subwindow_mode = attribute;
2047 attributesMask |= GCSubwindowMode;
2050 attributes.graphics_exposures = attribute;
2051 attributesMask |= GCGraphicsExposures;
2054 attributes.clip_x_origin = attribute;
2055 attributesMask |= GCClipXOrigin;
2058 attributes.clip_y_origin = attribute;
2059 attributesMask |= GCClipYOrigin;
2062 attributes.clip_mask = attribute;
2063 attributesMask |= GCClipMask;
2066 attributes.dash_offset = attribute;
2067 attributesMask |= GCDashOffset;
2070 attributes.dashes =(char)(0xFF & attribute);
2071 attributesMask |= GCDashList;
2074 attributes.arc_mode = attribute;
2075 attributesMask |= GCArcMode;
2082 XChangeGC(display,gc,attributesMask,&attributes);
2094 long xcSetGCAttribute()
2107 if(SetGCAttribute((Display *)DISP(0),GCVAL(1),val[2],val[3]))
2111 Errorline(
"could not set gc attribute in %P.\n",g);
2136 XFreeGC(DISP(0),GCVAL(1));
2150 long xcRequestColor()
2162 color.red =(val[2]) << 8;
2163 color.green =(val[3]) << 8;
2164 color.blue =(val[4]) << 8;
2165 color.flags = DoRed|DoGreen|DoBlue;
2167 if(XAllocColor(DISP(0),CMAP(1),&color))
2174 Errorline(
"could not request a color in %P.\n",g);
2189 long xcRequestNamedColor()
2203 if(XAllocNamedColor(DISP(0),CMAP(1),STRG(2),&cell,&rgb))
2210 Errorline(
"could not request a named color in %P.\n",g);
2230 unsigned long pixel;
2238 XFreeColors(DISP(0),CMAP(1),&pixel,1,0);
2260 for(j = 0; j < 9; j++)
2266 gc = DrawableGC(args[1]);
2267 x_set_gc((Display *)val[0],gc,val[6],val[7],val[8],
xDefaultFont);
2269 XDrawLine(DISP(0),(Window) val[1],gc,
2270 val[2],val[3],val[4],val[5]);
2272 x_record_line((
ListHeader *)WindowDisplayList(args[1]),DRAW_LINE,
2273 val[2],val[3],val[4],val[5],
2274 val[6],val[7],val[8]);
2298 for(j = 0; j < 11; j++)
2304 gc = DrawableGC(args[1]);
2305 x_set_gc((Display *)val[0],gc,val[8],val[9],val[10],
xDefaultFont);
2307 XDrawArc(DISP(0),(Window) val[1],gc,
2308 val[2],val[3],val[4],val[5],
2311 x_record_arc((
ListHeader *)WindowDisplayList(args[1]),DRAW_ARC,
2312 val[2],val[3],val[4],val[5],
2313 val[6],val[7],val[8],val[9],val[10]);
2330 long xcDrawRectangle()
2337 for(j = 0; j < 9; j++)
2343 gc = DrawableGC(args[1]);
2344 x_set_gc((Display *)val[0],gc,val[6],val[7],val[8],
xDefaultFont);
2346 XDrawRectangle(DISP(0),(Window) val[1],gc,
2347 val[2],val[3],val[4],val[5]);
2349 x_record_rectangle((
ListHeader *)WindowDisplayList(args[1]),DRAW_RECTANGLE,
2350 val[2],val[3],val[4],val[5],
2351 val[6],val[7],val[8]);
2368 long xcFillRectangle()
2375 for(j = 0; j < 8; j++)
2381 gc = DrawableGC(args[1]);
2384 XFillRectangle(DISP(0),(Window) val[1],gc,
2385 val[2],val[3],val[4],val[5]);
2387 x_record_rectangle((
ListHeader *)WindowDisplayList(args[1]),FILL_RECTANGLE,
2388 val[2],val[3],val[4],val[5],
2414 for(j = 0; j < 10; j++)
2420 gc = DrawableGC(args[1]);
2423 XFillArc(DISP(0),(Window) val[1],gc,
2424 val[2],val[3],val[4],val[5],
2427 x_record_arc((
ListHeader *)WindowDisplayList(args[1]),FILL_ARC,
2428 val[2],val[3],val[4],val[5],
2429 val[6],val[7],val[8],val[9],
2445 long xcPointsAlloc()
2455 Points =(long) malloc((val [0]) * 2 *
sizeof(short));
2483 Points =(
short *) val [0];
2508 free((
void *)val [0]);
2523 long xcDrawPolygon()
2530 for(j = 0; j < 7; j++)
2536 gc = DrawableGC(args[1]);
2537 x_set_gc((Display *)val[0],gc,val[4],val[5],val[6],
xDefaultFont);
2539 XDrawLines(DISP(0),(Window) val[1],gc,
2540 (XPoint *)val[2],val[3],CoordModeOrigin);
2542 x_record_polygon((
ListHeader *)WindowDisplayList(args[1]),DRAW_POLYGON,
2543 (XPoint *)val[2],val[3],val[4],val[5],val[6]);
2558 long xcFillPolygon()
2565 for(j = 0; j < 6; j++)
2571 gc = DrawableGC(args[1]);
2574 XFillPolygon(DISP(0),(Window) val[1],gc,
2575 (XPoint *)val[2],val[3],
2576 Complex,CoordModeOrigin);
2578 x_record_polygon((
ListHeader *)WindowDisplayList(args[1]),FILL_POLYGON,
2579 (XPoint *)val[2],val[3],val[4],val[5],
2608 if(font=XLoadFont(DISP(0),STRG(1)))
2616 Errorline(
"could not load a font in %P.\n",g);
2641 XUnloadFont(DISP(0),FONT(1));
2664 for(j = 0; j < 8; j++)
2671 gc = DrawableGC(args[1]);
2674 XDrawString(DISP(0),(Window) val[1],gc,
2675 val[2],val[3],STRG(4),
2678 x_record_string((
ListHeader *)WindowDisplayList(args[1]),DRAW_STRING,
2699 long xcDrawImageString()
2706 for(j = 0; j < 8; j++)
2713 gc = DrawableGC(args[1]);
2716 XDrawImageString(DISP(0),WIND(1),gc,
2721 x_record_string((
ListHeader *)WindowDisplayList(args[1]),DRAW_IMAGE_STRING,
2741 long xcStringWidth()
2745 int direction,ascent,descent;
2746 XCharStruct overall;
2755 if(XQueryTextExtents(DISP(0),FONT(1),
2756 STRG(2),strlen(STRG(2)),
2757 &direction,&ascent,&descent,&overall))
2789 XSync(DISP(0),val[1]);
2813 bk_stack_add_int_attr(psiEvent,
"display",(
long)event->xany.display);
2814 bk_stack_add_int_attr(psiEvent,
"window",(
long)event->xany.window);
2816 switch(event->type) {
2820 bk_stack_add_int_attr(psiEvent,
"x",event->xkey.x);
2821 bk_stack_add_int_attr(psiEvent,
"y",event->xkey.y);
2822 bk_stack_add_int_attr(psiEvent,
"state",event->xkey.state);
2826 XLookupString((XKeyEvent*)event,buffer,
sizeof(buffer),&keysym,
NULL);
2827 bk_stack_add_int_attr(psiEvent,
"keycode",(
long)buffer[0]);
2828 if(keysym==XK_Return || keysym==XK_KP_Enter || keysym==XK_Linefeed)
2831 if(keysym == XK_BackSpace || keysym == XK_Delete)
2834 if(isascii(buffer[0]))
2838 bk_stack_add_int_attr(psiEvent,
"char",(
long)*str);
2844 bk_stack_add_int_attr(psiEvent,
"x",(
long)event->xbutton.x);
2845 bk_stack_add_int_attr(psiEvent,
"y",(
long)event->xbutton.y);
2846 bk_stack_add_int_attr(psiEvent,
"x_root",(
long)event->xbutton.x_root);
2847 bk_stack_add_int_attr(psiEvent,
"y_root",(
long)event->xbutton.y_root);
2848 bk_stack_add_int_attr(psiEvent,
"state",(
long)event->xbutton.state);
2849 bk_stack_add_int_attr(psiEvent,
"button",(
long)event->xbutton.button);
2854 bk_stack_add_int_attr(psiEvent,
"width",(
long)event->xexpose.width);
2855 bk_stack_add_int_attr(psiEvent,
"height",(
long)event->xexpose.height);
2865 bk_stack_add_int_attr(psiEvent,
"x",(
long)event->xbutton.x);
2866 bk_stack_add_int_attr(psiEvent,
"y",(
long)event->xbutton.y);
2867 bk_stack_add_int_attr(psiEvent,
"x_root",(
long)event->xbutton.x_root);
2868 bk_stack_add_int_attr(psiEvent,
"y_root",(
long)event->xbutton.y_root);
2871 case ConfigureNotify:
2873 bk_stack_add_int_attr(psiEvent,
"x",(
long)event->xconfigure.x);
2874 bk_stack_add_int_attr(psiEvent,
"y",(
long)event->xconfigure.y);
2875 bk_stack_add_int_attr(psiEvent,
"width",(
long)event->xconfigure.width);
2876 bk_stack_add_int_attr(psiEvent,
"height",(
long)event->xconfigure.height);
2877 bk_stack_add_int_attr(psiEvent,
"border_width",
2878 (
long)event->xconfigure.border_width);
2886 goto LeaveEnterCommon;
2892 bk_stack_add_int_attr(psiEvent,
"root", (
long) event->xcrossing.root);
2893 bk_stack_add_int_attr(psiEvent,
"subwindow",(
long)event->xcrossing.subwindow);
2895 bk_stack_add_int_attr(psiEvent,
"x",(
long)event->xcrossing.x);
2896 bk_stack_add_int_attr(psiEvent,
"y",(
long)event->xcrossing.y);
2898 bk_stack_add_int_attr(psiEvent,
"focus",(
long)event->xcrossing.focus);
2899 bk_stack_add_int_attr(psiEvent,
"state",(
long)event->xcrossing.state);
2906 bk_stack_add_int_attr(psiEvent,
"event_type",(
long)event->
type);
2925 return lst->type==
nil;
2940 if(lst->type==
alist) {
2948 Errorline(
"X event handling error in CDR(%P)\n",lst);
2966 if(lst->type==
alist) {
2974 Errorline(
"X event handling error in CAR(%P)\n",lst);
3018 while(!list_is_nil(lst))
3036 end=list_last_cdr(lst);
3053 long map_funct_over_list(
ptr_psi_term lst,
long(*proc)(),
long *closure)
3055 long notInterrupted=
TRUE;
3057 while(notInterrupted && !list_is_nil(lst)) {
3058 notInterrupted =(*proc)(lst,closure);
3062 return notInterrupted;
3075 long map_funct_over_cars(
ptr_psi_term lst,
long(*proc)(),
long *closure)
3078 int notInterrupted =
TRUE;
3080 while(notInterrupted && !list_is_nil(lst)) {
3085 notInterrupted=(*proc)(list_car(lst),closure);
3089 return notInterrupted;
3103 long still_there=
TRUE;
3106 while(!list_is_nil(lst) && still_there) {
3127 static long x_union_event(
ptr_psi_term psiEvent,EventClosure *closure)
3129 return !((Display *)GetIntAttr(psiEvent,
"display") == closure->display
3130 && (Window)GetIntAttr(psiEvent,
"window") == closure->window
3131 &&(GetIntAttr(psiEvent,
"mask") & closure->mask) != 0);
3150 EventClosure eventClosure;
3161 if(!xevent_existing) {
3164 eventClosure.display =DISP(0);
3165 eventClosure.window =WIND(1);
3166 eventClosure.mask = val[2];
3167 if(!map_funct_over_cars(xevent_list,x_union_event,(
long *)&eventClosure))
3168 warningline(
"you have coinciding event handlers on the same window");
3172 bk_stack_add_int_attr(eventElt,
"display",(
long)val[0]);
3173 bk_stack_add_int_attr(eventElt,
"window",(
long)val[1]);
3174 bk_stack_add_int_attr(eventElt,
"mask",(
long)val[2]);
3179 append_to_list(xevent_list,eventElt);
3190 psiEvent = GetPsiAttr(xevent_existing,
"event");
3192 xevent_existing =
NULL;
3212 static long x_flush_event(
ptr_psi_term eventElt,EventClosure *closure)
3216 psiEvent = list_car(eventElt);
3217 if ((Display *)GetIntAttr(psiEvent,
"display") == closure->display
3218 && (Window)GetIntAttr(psiEvent,
"window") ==closure->window
3219 && (GetIntAttr(psiEvent,
"mask") & closure->mask) != 0)
3225 list_remove_value(xevent_list,psiEvent);
3239 long xcFlushEvents()
3243 EventClosure eventClosure;
3251 eventClosure.display =DISP(0);
3252 eventClosure.window = val[1];
3253 eventClosure.mask = val[2];
3254 map_funct_over_list(xevent_list,x_flush_event,(
long *)&eventClosure);
3286 if(xcPsiEventToEvent(val[2],&event))
3288 XSendEvent((
GENERIC)DISP(0),WIND(1),False,?,&event);
3293 Errorline(
"%P is not an event in %P.\n",val[2],g);
3319 long xcQueryPointer()
3323 Window root_return,child_return;
3324 int root_x_return,root_y_return;
3325 int win_x_return,win_y_return;
3326 unsigned int mask_return;
3338 same_screen=XQueryPointer(DISP(0),
3340 &root_return, &child_return,
3341 &root_x_return,&root_y_return,
3342 &win_x_return, &win_y_return,
3371 void x_setup_builtins()
3377 XSetErrorHandler(x_handle_error);
3378 XSetIOErrorHandler(x_handle_fatal_error);
3493 static long WaitNextEvent(
long *ptreventflag)
3496 fd_set readfd,writefd,exceptfd;
3497 struct timeval timeout;
3498 long charflag =
FALSE,nbchar;
3501 *ptreventflag =
FALSE;
3510 timeout.tv_usec = 100000;
3512 nfds = select(32,&readfd,&writefd,&exceptfd,&timeout);
3522 Errorline(
"in select: interruption error.\n");
3535 *ptreventflag =
TRUE;
3547 Errorline(
"in select: keyboard error.\n");
3564 }
while(!(charflag || *ptreventflag));
3575 long x_read_stdin_or_event(
long *ptreventflag)
3579 *ptreventflag =
FALSE;
3600 c = WaitNextEvent(ptreventflag);
3604 if(
verbose) printf(
"<X event>");
3625 static long mask_match_type(
long mask,
long type)
3631 em=xevent_mask[type];
3632 if(!em ||(em & mask))
3652 if(beginSpan == endSpan)
3653 return list_car(beginSpan);
3655 if(mask_match_type(GetIntAttr(list_car(beginSpan),
"mask"),
3657 return list_car(beginSpan);
3659 return x_what_psi_event(list_cdr(beginSpan),
3682 psiEvent = x_what_psi_event(beginSpan,endSpan,eventType);
3685 bk_change_psi_attr(psiEvent,
"event",xcEventToPsiTerm(event));
3689 warningline(
"xevent_existing is non-null in x_build_existing_event");
3691 xevent_existing = psiEvent;
3698 list_remove_value(xevent_list,psiEvent);
3710 static long x_next_event_span(
ptr_psi_term eventElt,EventClosure *eventClosure)
3719 psiEvent = list_car(eventElt);
3720 display =(Display *)GetIntAttr(psiEvent,
"display");
3721 window =(Window)GetIntAttr(psiEvent,
"window");
3722 mask = GetIntAttr(psiEvent,
"mask");
3724 if(eventClosure->display ==
NULL) {
3726 eventClosure->display = display;
3727 eventClosure->window = window;
3728 eventClosure->mask = mask;
3729 eventClosure->beginSpan = eventElt;
3733 if(eventClosure->display == display && eventClosure->window == window) {
3735 eventClosure->mask |= mask;
3741 if(XCheckWindowEvent(eventClosure->display,eventClosure->window,
3742 eventClosure->mask,&event)
3749 if((event.type==Expose || event.type==GraphicsExpose)
3750 && event.xexpose.count!=0) {
3759 x_build_existing_event(&event,
3760 eventClosure->beginSpan,
3761 eventElt,event.
type);
3768 eventClosure->display = display;
3769 eventClosure->window = window;
3770 eventClosure->mask = mask;
3771 eventClosure->beginSpan = eventElt;
3784 long x_exist_event()
3786 XEvent event,exposeEvent;
3788 EventClosure eventClosure;
3796 if(list_is_nil(xevent_list)) {
3803 eventClosure.display =
NULL;
3804 if(!map_funct_over_list(xevent_list,x_next_event_span,(
long *)&eventClosure))
3813 if(XCheckWindowEvent(eventClosure.display,
3814 eventClosure.window,
3820 if(event.xany.window==eventClosure.window) {
3821 if(event.type == Expose)
3822 while(XCheckWindowEvent(eventClosure.display,
3823 eventClosure.window,
3829 x_build_existing_event(&event,
3830 eventClosure.beginSpan,
3831 list_last_cdr(xevent_list),
3849 void x_destroy_window(Display *display,Window window)
3856 XDestroyWindow(display,window);
3868 void x_show_window(Display *display,
long window)
3870 XMapWindow(display,window);
3882 void x_hide_window(Display *display,
long window)
3884 XUnmapWindow(display,window);
3898 void x_show_subwindow(Display *display,
long window)
3900 XMapSubwindows(display,window);
3912 void x_hide_subwindow(Display *display,
long window)
3914 XUnmapSubwindows(display,window);
3930 long xcQueryTextExtents()
3937 int direction,ascent,descent;
3956 XQueryTextExtents(DISP(0),
3969 val[6] =over.lbearing;
3970 val[7] =over.rbearing;
3972 val[9] =over.ascent;
3973 val[10]=over.descent;
3996 Errorline(
"X error in GoalFromPsiTerm: psiTerm is null\n");
4002 Errorline(
"X error in GoalFromPsiTerm: psiTerm has no residuating functions\n");
4008 Errorline(
"X error in GoalFromPsiTerm: psiTerm has more than one residuating function\n");
4014 Errorline(
"X error in GoalFromPsiTerm: psiTerm has no goal\n");
#define show_subwindow
To backtrack on show sub windows RM 8/12/92.
void new_built_in(ptr_module m, char *s, def_type t, long(*r)())
new_built_in
#define xDefaultLineWidth
ptr_definition alist
symbol in bi module
#define hide_subwindow
To backtrack on hide sub windows RM 8/12/92.
#define function_it
was enum (def_type) in extern.h now there is typedef ptr_definition
void get_two_args(ptr_node t, ptr_psi_term *a, ptr_psi_term *b)
get_two_args
void push_ptr_value(type_ptr t, GENERIC *p)
push_ptr_value
void interrupt()
INTERRUPT()
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
void show(long limit)
show
ptr_psi_term stack_cons(ptr_psi_term head, ptr_psi_term tail)
stack_cons
void residuate(ptr_psi_term t)
residuate
void exit_life(long nl_flag)
exit_life
ptr_definition integer
symbol in bi module
#define show_window
To backtrack on show window.
ptr_definition xdisplaylist
void push_goal(goals t, ptr_psi_term a, ptr_psi_term b, GENERIC c)
push_goal
#define def_ptr
values of type_ptr
ptr_node bk_stack_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
bk_stack_insert
ptr_definition xbutton_event
void push_ptr_value_global(type_ptr t, GENERIC *p)
push_ptr_value_global
#define predicate_it
was enum (def_type) in extern.h now there is typedef ptr_definition
long matches(ptr_definition t1, ptr_definition t2, long *smaller)
matches
#define destroy_window
To backtrack on window creation.
ptr_definition xexpose_event
struct wl_psi_term * ptr_psi_term
quotedStackCopy
#define REAL
Which C type to use to represent reals and integers in Wild_Life.
ptr_definition boolean
symbol in bi module
ptr_definition update_symbol(ptr_module module, char *symbol)
update_symbol
ptr_definition xmotion_event
#define begin_builtin(FUNCNAME, NBARGS, NBARGSIN, TYPES)
ptr_definition xmisc_event
void release_resid(ptr_psi_term t)
release_resid
ptr_definition real
symbol in bi module
#define hide_window
To backtrack on hide window.
void Errorline(char *format,...)
Errorline.
unsigned long * GENERIC
unsigned long *GENERIC
char * buffer
buffer used only in print.c - there is local with same name in xpred.c
ptr_node stack_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
stack_insert
void infoline(char *format,...)
infoline
char * heap_copy_string(char *s)
heap_copy_string
ptr_definition xkeyboard_event
int arg_c
set from argc in either life.c or lib.c
#define TRUE
Standard boolean.
#define FALSE
Standard boolean.
ptr_psi_term stack_psi_term(long stat)
stack_psi_term
ptr_definition nil
symbol in bi module
ptr_psi_term stack_nil()
stack_nil
ptr_definition xenter_event
void clean_undo_window(long disp, long wind)
clean_undo_window
#define unify
was enum (goal) – but must be long for error.c - now typedef
ptr_node find(long comp, char *keystr, ptr_node tree)
find
char * arg_v[ARGNN]
set from argv in either life.c or lib.c
void push_window(long type, long disp, long wind)
push_window
void raw_setup_builtins()
raw_setup_builtins
long unify_real_result(ptr_psi_term t, REAL v)
unify_real_result
ptr_definition xdestroy_event
ptr_definition xleave_event
void warningline(char *format,...)
warningline
ptr_definition xconfigure_event
ptr_psi_term xevent_existing
#define include_var_builtin(NBARGS)
ptr_module x_module
'ifdef X11' unnecessary
ptr_module set_current_module(ptr_module module)
set_current_module
ptr_definition quoted_string
symbol in bi module
ptr_goal GoalFromPsiTerm(ptr_psi_term psiTerm)
long i_check_out(ptr_psi_term t)
i_check_out
GENERIC heap_alloc(long s)
heap_alloc
#define psi_term_ptr
values of type_ptr
#define int_ptr
values of type_ptr