22 #define stdin_fileno fileno(stdin)
28 typedef struct wl_EventClosure
56 static long xevent_mask[] = {
64 PointerMotionMask | PointerMotionHintMask | ButtonMotionMask |
65 Button1MotionMask | Button2MotionMask | Button3MotionMask |
66 Button4MotionMask | Button5MotionMask,
77 SubstructureNotifyMask,
78 SubstructureNotifyMask,
81 SubstructureRedirectMask,
82 SubstructureNotifyMask,
84 SubstructureRedirectMask,
88 SubstructureRedirectMask,
100 static char* xevent_name[] = {
144 #define DrawableGC(w)(GC)GetIntAttr(GetPsiAttr(w,"graphic_context"),"id")
145 #define WindowDisplayList(w) GetIntAttr(GetPsiAttr(w,"display_list"),"id")
148 #define DISP(X)(Display *)val[X]
149 #define DRAW(X)(Drawable)val[X]
150 #define WIND(X)(Window)val[X]
151 #define GCVAL(X)(GC)val[X]
152 #define FONT(X)(Font)val[X]
153 #define CMAP(X)(Colormap)val[X]
154 #define STRG(X) ((char *)val[X])
163 static int x_handle_error(display,x_error)
165 XErrorEvent *x_error;
168 XGetErrorText(display,x_error->error_code,msg,128);
178 static int x_handle_fatal_error(display)
189 void bk_stack_add_int_attr(t,attrname,value)
220 void bk_change_psi_attr(t,attrname,value)
253 long unify_int_result(t,v)
264 *(
REAL *) t->value_3 = v;
301 bk_stack_add_int_attr(p,f,v);
310 long GetIntAttr(psiTerm,attributeName)
320 nodeAttr=
find(
FEATCMP,attributeName,psiTerm->attr_list);
322 Errorline(
"in GetIntAttr: didn't find %s on %P\n",
353 if((nodeAttr =
find(
FEATCMP,attributeName,psiTerm->attr_list)) ==
NULL)
355 Errorline(
"in GetPsiAttr: no attribute name on psi-term ?\n");
361 Errorline(
"in GetPsiAttr: no value on psi-term ?\n");
372 static void ResizePixmap(psi_window,display,window,width,height)
377 unsigned long width,height;
383 XWindowAttributes attr;
388 psiPixmap = GetPsiAttr(psi_window,
"pixmap");
391 if((pixmap = GetIntAttr(psiPixmap,
"id")) != 0)
394 XFreePixmap(display,pixmap);
397 psiPixmapGC = GetPsiAttr(psiPixmap,
"graphic_context");
400 pixmapGC=(GC)GetIntAttr(psiPixmapGC,
"id");
402 XFreeGC(display,pixmapGC);
404 bk_stack_add_int_attr(psiPixmap,
"id",(
long)
NULL);
405 bk_stack_add_int_attr(psiPixmapGC,
"id",(
long)
NULL);
409 XGetWindowAttributes(display,window,&attr);
410 if((pixmap = XCreatePixmap(display,window,
411 attr.width+1,attr.height+1,
414 bk_stack_add_int_attr(psiPixmap,
"id",pixmap);
415 gcvalues.cap_style = CapRound;
416 gcvalues.join_style = JoinRound;
417 pixmapGC = XCreateGC(display,pixmap,
418 GCJoinStyle|GCCapStyle,&gcvalues);
422 bk_stack_add_int_attr(psiPixmapGC,
"id",(
long)pixmapGC);
424 psiPixmapGC=NewPsi(xgc,
"id",pixmapGC);
425 bk_change_psi_attr(psiPixmap,
"graphic_context",psiPixmapGC);
435 static void FreeWindow(display,psi_window)
444 XFreeGC(display,DrawableGC(psi_window));
445 x_free_display_list((
ListHeader *)WindowDisplayList(psi_window));
447 psiPixmap = GetPsiAttr(psi_window,
"pixmap");
448 XFreeGC(display,DrawableGC(psiPixmap));
449 XFreePixmap(display,GetIntAttr(psiPixmap,
"id"));
462 long xcOpenConnection()
468 Display * connection;
478 if(strcmp(STRG(0),
""))
483 if(connection = XOpenDisplay(display))
485 psiConnection = NewPsi(xdisplay,
"id",connection);
492 Errorline(
"could not open connection in %P.\n",g);
509 long xcDefaultRootWindow()
525 psiRoot = NewPsi(xwindow,
"id",DefaultRootWindow(display));
538 static long GetConnectionAttribute(display,attributeId,attribute)
541 long attributeId,*attribute;
547 *attribute =(
unsigned long) ConnectionNumber(display);
551 *attribute = display->proto_major_version;
556 *attribute =(
unsigned long)(display->proto_minor_version);
560 *attribute =(
unsigned long) ServerVendor(display);
563 *attribute =(
unsigned long) ImageByteOrder(display);
566 *attribute =(
unsigned long) BitmapUnit(display);
569 *attribute =(
unsigned long) BitmapPad(display);
572 *attribute =(
unsigned long) BitmapBitOrder(display);
575 *attribute =(
unsigned long) VendorRelease(display);
579 *attribute =(
unsigned long)(display->qlen);
583 *attribute =(
unsigned long) LastKnownRequestProcessed(display);
587 *attribute =(
unsigned long)(display->request);
591 *attribute =(
unsigned long) DisplayString(display);
594 *attribute =(
unsigned long) DefaultScreen(display);
598 *attribute =(
unsigned long)(display->min_keycode);
603 *attribute =(
unsigned long)(display->max_keycode);
615 long xcQueryTextExtents();
627 long xcGetConnectionAttribute()
641 if(GetConnectionAttribute(DISP(0),DRAW(1),&attr))
648 Errorline(
"could not get connection attribute in %P.\n",g);
659 static long GetScreenAttribute(display,screen,attributeId,attribute)
662 long screen,attributeId,*attribute;
668 s = ScreenOfDisplay(display,screen);
672 *attribute =(
unsigned long) DisplayOfScreen(s);
675 *attribute =(
unsigned long) RootWindowOfScreen(s);
678 *attribute =(
unsigned long) WidthOfScreen(s);
681 *attribute =(
unsigned long) HeightOfScreen(s);
684 *attribute =(
unsigned long) WidthMMOfScreen(s);
687 *attribute =(
unsigned long) HeightMMOfScreen(s);
690 *attribute =(
unsigned long) DefaultDepthOfScreen(s);
693 *attribute =(
unsigned long) DefaultVisualOfScreen(s);
696 *attribute =(
unsigned long) DefaultGCOfScreen(s);
699 *attribute =(
unsigned long) DefaultColormapOfScreen(s);
702 *attribute =(
unsigned long) WhitePixelOfScreen(s);
705 *attribute =(
unsigned long) BlackPixelOfScreen(s);
708 *attribute =(
unsigned long) MaxCmapsOfScreen(s);
711 *attribute =(
unsigned long) MinCmapsOfScreen(s);
714 *attribute =(
unsigned long) DoesBackingStore(s);
717 *attribute =(
unsigned long) DoesSaveUnders(s);
720 *attribute =(
unsigned long) EventMaskOfScreen(s);
740 long xcGetScreenAttribute()
755 if(GetScreenAttribute(DISP(0),DRAW(1),val[2],&attr))
762 Errorline(
"could not get screen attribute in %P.\n",g);
779 long xcCloseConnection()
790 XCloseDisplay(DISP(0));
810 long xcCreateSimpleWindow()
818 XWindowChanges changes;
819 unsigned long changesMask;
820 XSetWindowAttributes attributes;
821 unsigned long attributesMask;
830 for(j = 0; j < 14; j++)
842 if(window = XCreateSimpleWindow(DISP(0),WIND(1),
850 bk_stack_add_int_attr(psiWindow,
"id",window);
853 life_icon = XCreateBitmapFromData(DISP(0),window,life_icon_bits,
854 life_icon_width,life_icon_height);
859 hints.width =val[4] ;
860 hints.height = val[5];
861 hints.flags = PPosition | PSize;
864 XSetStandardProperties(DISP(0),window,
871 changes.width =val[4] ;
872 changes.height = val[5];
873 changesMask = CWX | CWY | CWWidth | CWHeight;
875 XReconfigureWMWindow(DISP(0),window,DefaultScreen(display),
876 changesMask,&changes);
879 XSetWindowBackground(DISP(0),window,val[6]);
882 XMoveResizeWindow(DISP(0),window,
883 val[2],val[3],val[4],val[5]);
886 attributes.background_pixel = val[6];
887 attributes.backing_pixel = val[6];
888 attributesMask = CWBackingPixel|CWBackPixel;
889 XChangeWindowAttributes(DISP(0),window,
890 attributesMask,&attributes);
905 x_show_window(DISP(0),window);
909 gcvalues.cap_style = CapRound;
910 gcvalues.join_style = JoinRound;
911 gc = XCreateGC(DISP(0),window,GCJoinStyle|GCCapStyle,&gcvalues);
912 bk_change_psi_attr(psiWindow,
"graphic_context",
913 NewPsi(xgc,
"id",gc));
916 bk_change_psi_attr(psiWindow,
"display_list",
917 NewPsi(xdisplaylist,
"id",x_display_list()));
920 bk_change_psi_attr(psiWindow,
"pixmap",
921 NewPsi(xpixmap,
"id",
NULL));
922 ResizePixmap(psiWindow,DISP(0),window,val[4],val[5]);
929 Errorline(
"could not create a simple window in %P.\n",g);
940 xcCreateWindow is not used anymore since we use xcCreateSimpleWindow.
941 I just keep
this code in
case - jch - Thu Aug 6 16:11:23 MET DST 1992
953 long xcCreateWindow()
959 XWindowChanges changes;
960 unsigned long changesMask;
962 long j,permanent,
show;
967 for(j = 0; j < 13; j++)
975 if(window = XCreateWindow(DISP(0),WIND(1),
980 0,(XSetWindowAttributes *)
NULL))
986 changes.width =val[4] ;
987 changes.height = val[5];
988 changesMask = CWX | CWY | CWWidth | CWHeight;
989 XConfigureWindow(DISP(0),window,changesMask,&changes);
993 hints.width =val[4] ;
994 hints.height = val[5];
995 hints.flags = PPosition | PSize;
996 XSetNormalHints(DISP(0),window,&hints);
1008 x_show_window(DISP(0),window);
1011 gcvalues.cap_style = CapRound;
1012 gcvalues.join_style = JoinRound;
1013 gc = XCreateGC(DISP(0),window,GCJoinStyle|GCCapStyle,&gcvalues);
1014 bk_stack_add_int_attr(args[12],
"gc",gc);
1017 bk_stack_add_int_attr(args[12],
"display_list",
NULL);
1023 Errorline(
"could not create window in %P.\n",g);
1041 long xcSetStandardProperties()
1059 hints.width = val[6] ;
1060 hints.height = val[7];
1061 hints.flags = PPosition | PSize;
1063 XSetStandardProperties(DISP(0),WIND(1),
1064 (
char*)val[2],(
char*)val[3],
1069 ResizePixmap(args[1],val[0],val[1],val[6],val[7]);
1088 long xcGetWindowGeometry()
1094 unsigned int w,h,bw,d;
1104 if(XGetGeometry(DISP(0),DRAW(1),
1105 &r,&x,&y,&w,&h,&bw,&d))
1115 Errorline(
"could not get the geometry in %P.\n",g);
1126 static long GetWindowAttribute(display,window,attributeId,attribute)
1128 Display *display;
long window,attributeId,*attribute;
1130 XWindowAttributes windowAttributes;
1133 XGetWindowAttributes(display,window,&windowAttributes);
1137 *attribute = windowAttributes.x;
1140 *attribute = windowAttributes.y;
1143 *attribute = windowAttributes.width;
1146 *attribute = windowAttributes.height;
1149 *attribute = windowAttributes.border_width;
1152 *attribute = windowAttributes.depth;
1155 *attribute = windowAttributes.root;
1158 *attribute =(
unsigned long)windowAttributes.screen;
1161 *attribute =(
unsigned long)windowAttributes.visual;
1164 *attribute = windowAttributes.class;
1167 *attribute = windowAttributes.all_event_masks;
1170 *attribute = windowAttributes.bit_gravity;
1173 *attribute = windowAttributes.win_gravity;
1176 *attribute = windowAttributes.backing_store;
1179 *attribute = windowAttributes.backing_planes;
1182 *attribute = windowAttributes.backing_pixel;
1185 *attribute = windowAttributes.override_redirect;
1188 *attribute = windowAttributes.save_under;
1191 *attribute = windowAttributes.your_event_mask;
1194 *attribute = windowAttributes.do_not_propagate_mask;
1197 *attribute = windowAttributes.colormap;
1200 *attribute = windowAttributes.map_installed;
1203 *attribute = windowAttributes.map_state;
1222 long xcGetWindowAttribute()
1237 if(GetWindowAttribute(DISP(0),WIND(1),val[2],&attr))
1244 Errorline(
"could not get a window attribute in %P.\n",g);
1261 long xcSetWindowGeometry()
1275 XMoveResizeWindow(DISP(0),DRAW(1),
1276 val[2],val[3],val[4],val[5]);
1279 ResizePixmap(args[1],val[0],val[1],val[4],val[5]);
1311 XMoveWindow(DISP(0),DRAW(1), val[2],val[3]);
1323 static long SetWindowAttribute(psi_window,display,window,attributeId,attribute)
1328 unsigned long attributeId,attribute;
1331 XSetWindowAttributes attributes;
1332 XWindowChanges changes;
1333 unsigned long attributesMask = 0;
1334 unsigned long changesMask = 0;
1335 long backgroundChange =
FALSE;
1336 long sizeChange =
FALSE;
1337 unsigned int width,height;
1345 changes.x = attribute;
1349 changes.y = attribute;
1353 changes.width = attribute;
1354 changesMask |= CWWidth;
1355 XGetGeometry(display,window,&r,&x,&y,&width,&height,&bw,&d);
1360 changes.height = attribute;
1361 changesMask |= CWHeight;
1362 XGetGeometry(display,window,&r,&x,&y,&width,&height,&bw,&d);
1367 changes.border_width = attribute;
1368 changesMask |= CWBorderWidth;
1371 attributes.bit_gravity = attribute;
1372 attributesMask |= CWBitGravity;
1375 attributes.win_gravity = attribute;
1376 attributesMask |= CWWinGravity;
1379 attributes.backing_store = attribute;
1380 attributesMask |= CWBackingStore;
1383 attributes.backing_planes = attribute;
1384 attributesMask |= CWBackingPlanes;
1387 attributes.backing_pixel = attribute;
1388 attributesMask |= CWBackingPixel;
1391 attributes.override_redirect = attribute;
1392 attributesMask |= CWOverrideRedirect;
1395 attributes.save_under = attribute;
1396 attributesMask |= CWSaveUnder;
1399 attributes.event_mask = attribute;
1400 attributesMask |= CWEventMask;
1403 attributes.do_not_propagate_mask = attribute;
1404 attributesMask |= CWDontPropagate;
1407 attributes.colormap = attribute;
1408 attributesMask |= CWColormap;
1411 changes.sibling = attribute;
1412 changesMask |= CWSibling;
1415 changes.stack_mode = attribute;
1416 changesMask |= CWStackMode;
1419 attributes.background_pixmap = attribute;
1420 attributesMask |= CWBackPixmap;
1423 attributes.background_pixel = attribute;
1424 attributesMask |= CWBackPixel;
1425 backgroundChange =
TRUE;
1428 attributes.backing_pixel = attribute;
1429 attributesMask |= CWBackingPixel;
1432 attributes.border_pixmap = attribute;
1433 attributesMask |= CWBorderPixmap;
1436 attributes.border_pixel = attribute;
1437 attributesMask |= CWBorderPixel;
1440 attributes.cursor = attribute;
1441 attributesMask |= CWCursor;
1449 XConfigureWindow(display,window,changesMask,&changes);
1452 XChangeWindowAttributes(display,window,attributesMask,&attributes);
1454 if(backgroundChange)
1455 XClearArea(display,window,0,0,0,0,True);
1458 ResizePixmap(psi_window,display,window,width,height);
1473 long xcSetWindowAttribute()
1487 if(SetWindowAttribute(args[1],val[0],val[1],val[2],val[3]))
1494 Errorline(
"could not set window attribute in %P.\n",g);
1524 XMapWindow(DISP(0),WIND(1));
1544 long xcRaiseWindow()
1556 XRaiseWindow(DISP(0),WIND(1));
1576 long xcUnmapWindow()
1588 XUnmapWindow(DISP(0),WIND(1));
1614 long xcMapSubwindows()
1626 XMapSubwindows(DISP(0),WIND(1));
1646 long xcUnmapSubwindows()
1658 XUnmapSubwindows(DISP(0),WIND(1));
1683 long xcClearWindow()
1695 XClearWindow(DISP(0),WIND(1));
1698 x_free_display_list((
ListHeader *)WindowDisplayList(args[1]));
1716 long xcResizeWindowPixmap()
1731 ResizePixmap(args[1],val[0],val[1],val[2],val[3]);
1749 long xcSelectInput()
1762 XSelectInput(DISP(0),WIND(1),val[2]);
1780 long xcRefreshWindow()
1794 psiPixmap = GetPsiAttr(args[1],
"pixmap");
1795 if((pixmap =(Pixmap) GetIntAttr(psiPixmap,
"id")) != 0)
1796 x_refresh_window((Display *)val[0],val[1],pixmap,
1797 DrawableGC(psiPixmap),
1800 x_refresh_window((Display *)val[0],val[1],val[1],
1801 DrawableGC(args[1]),
1821 long xcPostScriptWindow()
1834 success = x_postscript_window((Display *) val[0],val[1],(
ListHeader *)GetIntAttr(GetPsiAttr(args[1],
"display_list"),
"id"),(
char *)val[2]);
1851 long xcDestroyWindow()
1863 psi = GetPsiAttr(args[1],
"permanent");
1866 Errorline(
"cannot destroy a permanent window.\n");
1872 FreeWindow(val[0],args[1]);
1873 XDestroyWindow(DISP(0),WIND(1));
1908 if(gc = XCreateGC(DISP(0),WIND(1),0,&GCvalues))
1915 Errorline(
"could not create gc in %P.\n",g);
1927 static long GetGCAttribute(gc,attributeId,attribute)
1930 long attributeId,*attribute;
1937 *attribute = gc->values.function;
1940 *attribute = gc->values.plane_mask;
1943 *attribute = gc->values.foreground;
1946 *attribute = gc->values.background;
1949 *attribute = gc->values.line_width;
1952 *attribute = gc->values.line_style;
1955 *attribute = gc->values.cap_style;
1958 *attribute = gc->values.join_style;
1961 *attribute = gc->values.fill_style;
1964 *attribute = gc->values.fill_rule;
1967 *attribute = gc->values.tile;
1970 *attribute = gc->values.stipple;
1973 *attribute = gc->values.ts_x_origin;
1976 *attribute = gc->values.ts_y_origin;
1979 *attribute = gc->values.font;
1982 *attribute = gc->values.subwindow_mode;
1985 *attribute = gc->values.graphics_exposures;
1988 *attribute = gc->values.clip_x_origin;
1991 *attribute = gc->values.clip_y_origin;
1994 *attribute = gc->values.clip_mask;
1997 *attribute = gc->values.dash_offset;
2000 *attribute =(
unsigned char)(gc->values.dashes);
2003 *attribute = gc->values.arc_mode;
2006 *attribute = gc->rects;
2009 *attribute = gc->dashes;
2029 long xcGetGCAttribute()
2043 if(GetGCAttribute((
long)DISP(0),GCVAL(1),&attr))
2050 Errorline(
"could not get gc attribute in %P.\n",g);
2062 static long SetGCAttribute(display,gc,attributeId,attribute)
2066 long attributeId,attribute;
2069 XGCValues attributes;
2070 unsigned long attributesMask = 0;
2076 attributes.function = attribute;
2077 attributesMask |= GCFunction;
2080 attributes.plane_mask = attribute;
2081 attributesMask |= GCPlaneMask;
2084 attributes.foreground = attribute;
2085 attributesMask |= GCForeground;
2088 attributes.background = attribute;
2089 attributesMask |= GCBackground;
2092 attributes.line_width = attribute;
2093 attributesMask |= GCLineWidth;
2096 attributes.line_style = attribute;
2097 attributesMask |= GCLineStyle;
2100 attributes.cap_style = attribute;
2101 attributesMask |= GCCapStyle;
2104 attributes.join_style = attribute;
2105 attributesMask |= GCJoinStyle;
2108 attributes.fill_style = attribute;
2109 attributesMask |= GCFillStyle;
2112 attributes.fill_rule = attribute;
2113 attributesMask |= GCFillRule;
2116 attributes.tile = attribute;
2117 attributesMask |= GCTile;
2120 attributes.stipple = attribute;
2121 attributesMask |= GCStipple;
2124 attributes.ts_x_origin = attribute;
2125 attributesMask |= GCTileStipXOrigin;
2128 attributes.ts_y_origin = attribute;
2129 attributesMask |= GCTileStipYOrigin;
2132 attributes.font = attribute;
2133 attributesMask |= GCFont;
2136 attributes.subwindow_mode = attribute;
2137 attributesMask |= GCSubwindowMode;
2140 attributes.graphics_exposures = attribute;
2141 attributesMask |= GCGraphicsExposures;
2144 attributes.clip_x_origin = attribute;
2145 attributesMask |= GCClipXOrigin;
2148 attributes.clip_y_origin = attribute;
2149 attributesMask |= GCClipYOrigin;
2152 attributes.clip_mask = attribute;
2153 attributesMask |= GCClipMask;
2156 attributes.dash_offset = attribute;
2157 attributesMask |= GCDashOffset;
2160 attributes.dashes =(char)(0xFF & attribute);
2161 attributesMask |= GCDashList;
2164 attributes.arc_mode = attribute;
2165 attributesMask |= GCArcMode;
2172 XChangeGC(display,gc,attributesMask,&attributes);
2186 long xcSetGCAttribute()
2200 if(SetGCAttribute((
long)DISP(0),GCVAL(1),val[2],val[3]))
2204 Errorline(
"could not set gc attribute in %P.\n",g);
2234 XFreeGC(DISP(0),GCVAL(1));
2249 long xcRequestColor()
2263 color.red =(val[2]) << 8;
2264 color.green =(val[3]) << 8;
2265 color.blue =(val[4]) << 8;
2266 color.flags = DoRed|DoGreen|DoBlue;
2268 if(XAllocColor(DISP(0),CMAP(1),&color))
2275 Errorline(
"could not request a color in %P.\n",g);
2292 long xcRequestNamedColor()
2307 if(XAllocNamedColor(DISP(0),CMAP(1),STRG(2),&cell,&rgb))
2314 Errorline(
"could not request a named color in %P.\n",g);
2337 unsigned long pixel;
2346 XFreeColors(DISP(0),CMAP(1),&pixel,1,0);
2372 for(j = 0; j < 9; j++)
2378 gc = DrawableGC(args[1]);
2379 x_set_gc((Display *)val[0],gc,val[6],val[7],val[8],
xDefaultFont);
2381 XDrawLine(DISP(0),(Window) val[1],gc,
2382 val[2],val[3],val[4],val[5]);
2384 x_record_line((
ListHeader *)WindowDisplayList(args[1]),DRAW_LINE,
2385 val[2],val[3],val[4],val[5],
2386 val[6],val[7],val[8]);
2413 for(j = 0; j < 11; j++)
2419 gc = DrawableGC(args[1]);
2420 x_set_gc((Display *)val[0],gc,val[8],val[9],val[10],
xDefaultFont);
2422 XDrawArc(DISP(0),(Window) val[1],gc,
2423 val[2],val[3],val[4],val[5],
2426 x_record_arc((
ListHeader *)WindowDisplayList(args[1]),DRAW_ARC,
2427 val[2],val[3],val[4],val[5],
2428 val[6],val[7],val[8],val[9],val[10]);
2447 long xcDrawRectangle()
2456 for(j = 0; j < 9; j++)
2462 gc = DrawableGC(args[1]);
2463 x_set_gc((Display *)val[0],gc,val[6],val[7],val[8],
xDefaultFont);
2465 XDrawRectangle(DISP(0),(Window) val[1],gc,
2466 val[2],val[3],val[4],val[5]);
2468 x_record_rectangle((
ListHeader *)WindowDisplayList(args[1]),DRAW_RECTANGLE,
2469 val[2],val[3],val[4],val[5],
2470 val[6],val[7],val[8]);
2489 long xcFillRectangle()
2498 for(j = 0; j < 8; j++)
2504 gc = DrawableGC(args[1]);
2507 XFillRectangle(DISP(0),(Window) val[1],gc,
2508 val[2],val[3],val[4],val[5]);
2510 x_record_rectangle((
ListHeader *)WindowDisplayList(args[1]),FILL_RECTANGLE,
2511 val[2],val[3],val[4],val[5],
2540 for(j = 0; j < 10; j++)
2546 gc = DrawableGC(args[1]);
2549 XFillArc(DISP(0),(Window) val[1],gc,
2550 val[2],val[3],val[4],val[5],
2553 x_record_arc((
ListHeader *)WindowDisplayList(args[1]),FILL_ARC,
2554 val[2],val[3],val[4],val[5],
2555 val[6],val[7],val[8],val[9],
2573 long xcPointsAlloc()
2585 Points =(long) malloc((val [0]) * 2 *
sizeof(short));
2615 Points =(
short *) val [0];
2643 free((
void *)val [0]);
2660 long xcDrawPolygon()
2669 for(j = 0; j < 7; j++)
2675 gc = DrawableGC(args[1]);
2676 x_set_gc((Display *)val[0],gc,val[4],val[5],val[6],
xDefaultFont);
2678 XDrawLines(DISP(0),(Window) val[1],gc,
2679 (XPoint *)val[2],val[3],CoordModeOrigin);
2681 x_record_polygon((
ListHeader *)WindowDisplayList(args[1]),DRAW_POLYGON,
2682 (XPoint *)val[2],val[3],val[4],val[5],val[6]);
2700 long xcFillPolygon()
2709 for(j = 0; j < 6; j++)
2715 gc = DrawableGC(args[1]);
2718 XFillPolygon(DISP(0),(Window) val[1],gc,
2719 (XPoint *)val[2],val[3],
2720 Complex,CoordModeOrigin);
2722 x_record_polygon((
ListHeader *)WindowDisplayList(args[1]),FILL_POLYGON,
2723 (XPoint *)val[2],val[3],val[4],val[5],
2756 if(font=XLoadFont(DISP(0),STRG(1)))
2764 Errorline(
"could not load a font in %P.\n",g);
2794 XUnloadFont(DISP(0),FONT(1));
2821 for(j = 0; j < 8; j++)
2828 gc = DrawableGC(args[1]);
2831 XDrawString(DISP(0),(Window) val[1],gc,
2832 val[2],val[3],STRG(4),
2835 x_record_string((
ListHeader *)WindowDisplayList(args[1]),DRAW_STRING,
2858 long xcDrawImageString()
2866 for(j = 0; j < 8; j++)
2873 gc = DrawableGC(args[1]);
2876 XDrawImageString(DISP(0),WIND(1),gc,
2881 x_record_string((
ListHeader *)WindowDisplayList(args[1]),DRAW_IMAGE_STRING,
2904 long xcStringWidth()
2908 int direction,ascent,descent;
2909 XCharStruct overall;
2918 if(XQueryTextExtents(DISP(0),FONT(1),
2919 STRG(2),strlen(STRG(2)),
2920 &direction,&ascent,&descent,&overall))
2956 XSync(DISP(0),val[1]);
2981 bk_stack_add_int_attr(psiEvent,
"display",(
long)event->xany.display);
2982 bk_stack_add_int_attr(psiEvent,
"window",event->xany.window);
2984 switch(event->type) {
2988 bk_stack_add_int_attr(psiEvent,
"x",event->xkey.x);
2989 bk_stack_add_int_attr(psiEvent,
"y",event->xkey.y);
2990 bk_stack_add_int_attr(psiEvent,
"state",event->xkey.state);
2994 XLookupString((XKeyEvent*)event,buffer,
sizeof(buffer),&keysym,
NULL);
2995 bk_stack_add_int_attr(psiEvent,
"keycode",buffer[0]);
2996 if(keysym==XK_Return || keysym==XK_KP_Enter || keysym==XK_Linefeed)
2999 if(keysym == XK_BackSpace || keysym == XK_Delete)
3002 if(isascii(buffer[0]))
3006 bk_stack_add_int_attr(psiEvent,
"char",*str);
3012 bk_stack_add_int_attr(psiEvent,
"x",event->xbutton.x);
3013 bk_stack_add_int_attr(psiEvent,
"y",event->xbutton.y);
3014 bk_stack_add_int_attr(psiEvent,
"x_root",event->xbutton.x_root);
3015 bk_stack_add_int_attr(psiEvent,
"y_root",event->xbutton.y_root);
3016 bk_stack_add_int_attr(psiEvent,
"state",event->xbutton.state);
3017 bk_stack_add_int_attr(psiEvent,
"button",event->xbutton.button);
3022 bk_stack_add_int_attr(psiEvent,
"width",event->xexpose.width);
3023 bk_stack_add_int_attr(psiEvent,
"height",event->xexpose.height);
3033 bk_stack_add_int_attr(psiEvent,
"x",event->xbutton.x);
3034 bk_stack_add_int_attr(psiEvent,
"y",event->xbutton.y);
3035 bk_stack_add_int_attr(psiEvent,
"x_root",event->xbutton.x_root);
3036 bk_stack_add_int_attr(psiEvent,
"y_root",event->xbutton.y_root);
3039 case ConfigureNotify:
3041 bk_stack_add_int_attr(psiEvent,
"x",event->xconfigure.x);
3042 bk_stack_add_int_attr(psiEvent,
"y",event->xconfigure.y);
3043 bk_stack_add_int_attr(psiEvent,
"width",event->xconfigure.width);
3044 bk_stack_add_int_attr(psiEvent,
"height",event->xconfigure.height);
3045 bk_stack_add_int_attr(psiEvent,
"border_width",
3046 event->xconfigure.border_width);
3054 goto LeaveEnterCommon;
3060 bk_stack_add_int_attr(psiEvent,
"root", event->xcrossing.root);
3061 bk_stack_add_int_attr(psiEvent,
"subwindow",event->xcrossing.subwindow);
3063 bk_stack_add_int_attr(psiEvent,
"x",event->xcrossing.x);
3064 bk_stack_add_int_attr(psiEvent,
"y",event->xcrossing.y);
3066 bk_stack_add_int_attr(psiEvent,
"focus",event->xcrossing.focus);
3067 bk_stack_add_int_attr(psiEvent,
"state",event->xcrossing.state);
3074 bk_stack_add_int_attr(psiEvent,
"event_type",event->
type);
3091 long list_is_nil(lst)
3097 return lst->type==
nil;
3112 if(lst->type==
alist) {
3120 Errorline(
"X event handling error in CDR(%P)\n",lst);
3136 if(lst->type==
alist) {
3144 Errorline(
"X event handling error in CAR(%P)\n",lst);
3151 void list_set_car(lst,value)
3162 void list_set_cdr(lst,value)
3178 while(!list_is_nil(lst))
3193 end=list_last_cdr(lst);
3202 long map_funct_over_list(lst,proc,closure)
3207 long notInterrupted=
TRUE;
3209 while(notInterrupted && !list_is_nil(lst)) {
3210 notInterrupted =(*proc)(lst,closure);
3214 return notInterrupted;
3220 long map_funct_over_cars(lst,proc,closure)
3226 int notInterrupted =
TRUE;
3228 while(notInterrupted && !list_is_nil(lst)) {
3233 notInterrupted=(*proc)(list_car(lst),closure);
3237 return notInterrupted;
3243 void list_remove_value(lst,value)
3249 long still_there=
TRUE;
3252 while(!list_is_nil(lst) && still_there) {
3270 static long x_union_event(psiEvent,closure)
3273 EventClosure *closure;
3276 return !((Display *)GetIntAttr(psiEvent,
"display") == closure->display
3277 && (Window)GetIntAttr(psiEvent,
"window") == closure->window
3278 &&(GetIntAttr(psiEvent,
"mask") & closure->mask) != 0);
3303 EventClosure eventClosure;
3315 if(!xevent_existing) {
3318 eventClosure.display =DISP(0);
3319 eventClosure.window =WIND(1);
3320 eventClosure.mask = val[2];
3321 if(!map_funct_over_cars(xevent_list,x_union_event,(
long *)&eventClosure))
3322 warningline(
"you have coinciding event handlers on the same window");
3326 bk_stack_add_int_attr(eventElt,
"display",val[0]);
3327 bk_stack_add_int_attr(eventElt,
"window",val[1]);
3328 bk_stack_add_int_attr(eventElt,
"mask",val[2]);
3333 append_to_list(xevent_list,eventElt);
3344 psiEvent = GetPsiAttr(xevent_existing,
"event");
3346 xevent_existing =
NULL;
3363 static long x_flush_event(eventElt,closure)
3365 EventClosure *closure;
3370 psiEvent = list_car(eventElt);
3371 if ((Display *)GetIntAttr(psiEvent,
"display") == closure->display
3372 && (Window)GetIntAttr(psiEvent,
"window") ==closure->window
3373 && (GetIntAttr(psiEvent,
"mask") & closure->mask) != 0)
3379 list_remove_value(xevent_list,psiEvent);
3395 long xcFlushEvents()
3400 EventClosure eventClosure;
3409 eventClosure.display =DISP(0);
3410 eventClosure.window = val[1];
3411 eventClosure.mask = val[2];
3412 map_funct_over_list(xevent_list,x_flush_event,(
long *)&eventClosure);
3447 if(xcPsiEventToEvent(val[2],&event))
3449 XSendEvent((
long)DISP(0),WIND(1),False,?,&event);
3454 Errorline(
"%P is not an event in %P.\n",val[2],g);
3480 long xcQueryPointer()
3485 Window root_return,child_return;
3486 int root_x_return,root_y_return;
3487 int win_x_return,win_y_return;
3488 unsigned int mask_return;
3502 same_screen=XQueryPointer(DISP(0),
3504 &root_return, &child_return,
3505 &root_x_return,&root_y_return,
3506 &win_x_return, &win_y_return,
3538 void x_setup_builtins()
3545 XSetErrorHandler(x_handle_error);
3546 XSetIOErrorHandler(x_handle_fatal_error);
3659 static long WaitNextEvent(ptreventflag)
3663 fd_set readfd,writefd,exceptfd;
3664 struct timeval timeout;
3665 long charflag =
FALSE,nbchar;
3669 *ptreventflag =
FALSE;
3678 timeout.tv_usec = 100000;
3680 nfds = select(32,&readfd,&writefd,&exceptfd,&timeout);
3690 Errorline(
"in select: interruption error.\n");
3703 *ptreventflag =
TRUE;
3715 Errorline(
"in select: keyboard error.\n");
3732 }
while(!(charflag || *ptreventflag));
3740 long x_read_stdin_or_event(ptreventflag)
3746 *ptreventflag =
FALSE;
3767 c = WaitNextEvent(ptreventflag);
3771 if(
verbose) printf(
"<X event>");
3788 static long mask_match_type(mask,type)
3795 em=xevent_mask[type];
3796 if(!em ||(em & mask))
3810 static ptr_psi_term x_what_psi_event(beginSpan,endSpan,eventType)
3814 if(beginSpan == endSpan)
3815 return list_car(beginSpan);
3817 if(mask_match_type(GetIntAttr(list_car(beginSpan),
"mask"),
3819 return list_car(beginSpan);
3821 return x_what_psi_event(list_cdr(beginSpan),
3831 static void x_build_existing_event(event,beginSpan,endSpan,eventType)
3843 psiEvent = x_what_psi_event(beginSpan,endSpan,eventType);
3846 bk_change_psi_attr(psiEvent,
"event",xcEventToPsiTerm(event));
3850 warningline(
"xevent_existing is non-null in x_build_existing_event");
3852 xevent_existing = psiEvent;
3859 list_remove_value(xevent_list,psiEvent);
3868 static long x_next_event_span(eventElt,eventClosure)
3870 EventClosure *eventClosure;
3879 psiEvent = list_car(eventElt);
3880 display =(Display *)GetIntAttr(psiEvent,
"display");
3881 window =(Window)GetIntAttr(psiEvent,
"window");
3882 mask = GetIntAttr(psiEvent,
"mask");
3884 if(eventClosure->display ==
NULL) {
3886 eventClosure->display = display;
3887 eventClosure->window = window;
3888 eventClosure->mask = mask;
3889 eventClosure->beginSpan = eventElt;
3893 if(eventClosure->display == display && eventClosure->window == window) {
3895 eventClosure->mask |= mask;
3901 if(XCheckWindowEvent(eventClosure->display,eventClosure->window,
3902 eventClosure->mask,&event)
3909 if((event.type==Expose || event.type==GraphicsExpose)
3910 && event.xexpose.count!=0) {
3919 x_build_existing_event(&event,
3920 eventClosure->beginSpan,
3921 eventElt,event.type);
3928 eventClosure->display = display;
3929 eventClosure->window = window;
3930 eventClosure->mask = mask;
3931 eventClosure->beginSpan = eventElt;
3943 long x_exist_event()
3945 XEvent event,exposeEvent;
3947 EventClosure eventClosure;
3955 if(list_is_nil(xevent_list)) {
3962 eventClosure.display =
NULL;
3963 if(!map_funct_over_list(xevent_list,x_next_event_span,(
long *)&eventClosure))
3972 if(XCheckWindowEvent(eventClosure.display,
3973 eventClosure.window,
3979 if(event.xany.window==eventClosure.window) {
3980 if(event.type == Expose)
3981 while(XCheckWindowEvent(eventClosure.display,
3982 eventClosure.window,
3988 x_build_existing_event(&event,
3989 eventClosure.beginSpan,
3990 list_last_cdr(xevent_list),
4004 void x_destroy_window(display,window)
4015 XDestroyWindow(display,window);
4023 void x_show_window(display,window)
4025 Display *display;
long window;
4028 XMapWindow(display,window);
4036 void x_hide_window(display,window)
4038 Display *display;
long window;
4041 XUnmapWindow(display,window);
4051 void x_show_subwindow(display,window)
4053 Display *display;
long window;
4056 XMapSubwindows(display,window);
4064 void x_hide_subwindow(display,window)
4066 Display *display;
long window;
4069 XUnmapSubwindows(display,window);
4086 long xcQueryTextExtents()
4094 int direction,ascent,descent;
4113 XQueryTextExtents(DISP(0),
4126 val[6] =over.lbearing;
4127 val[7] =over.rbearing;
4129 val[9] =over.ascent;
4130 val[10]=over.descent;
4154 Errorline(
"X error in GoalFromPsiTerm: psiTerm is null\n");
4158 if((resid = psiTerm->resid) ==
NULL)
4160 Errorline(
"X error in GoalFromPsiTerm: psiTerm has no residuating functions\n");
4166 Errorline(
"X error in GoalFromPsiTerm: psiTerm has more than one residuating function\n");
4172 Errorline(
"X error in GoalFromPsiTerm: psiTerm has no goal\n");
void new_built_in(ptr_module m, char *s, def_type t, long(*r)())
new_built_in
#define xDefaultLineWidth
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()
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 xdisplaylist
void push_goal(goals t, ptr_psi_term a, ptr_psi_term b, GENERIC c)
push_goal
ptr_node bk_stack_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
ptr_definition xbutton_event
void push_ptr_value_global(type_ptr t, GENERIC *p)
push_ptr_value_global
long matches(ptr_definition t1, ptr_definition t2, long *smaller)
ptr_definition xexpose_event
ptr_definition update_symbol(ptr_module module, char *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
void Errorline(char *format,...)
char * heap_copy_string(char *s)
ptr_node stack_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
void infoline(char *format,...)
ptr_definition xkeyboard_event
ptr_definition quoted_string
ptr_psi_term stack_psi_term(long stat)
stack_psi_term
ptr_psi_term stack_nil()
stack_nil
ptr_definition xenter_event
void clean_undo_window(long disp, long wind)
clean_undo_window
ptr_node find(long comp, char *keystr, ptr_node tree)
void push_window(long type, long disp, long wind)
push_window
struct wl_psi_term * ptr_psi_term
void 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,...)
ptr_definition xconfigure_event
ptr_psi_term xevent_existing
#define include_var_builtin(NBARGS)
ptr_module set_current_module(ptr_module 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