home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume8 / elk / part10 < prev    next >
Encoding:
Text File  |  1989-09-23  |  57.8 KB  |  1,870 lines

  1. Newsgroups: comp.sources.misc
  2. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  3. Subject: v08i058: Elk (Extension Language Toolkit) part 10 of 14
  4. Reply-To: net@tub.UUCP (Oliver Laumann)
  5.  
  6. Posting-number: Volume 8, Issue 58
  7. Submitted-by: net@tub.UUCP (Oliver Laumann)
  8. Archive-name: elk/part10
  9.  
  10. [Let this be a lesson to submitters:  this was submitted as uuencoded,
  11. compressed files.  I lost the source information while unpacking it; this
  12. is the best approximation I could come up with.  ++bsa]
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then unpack
  16. # it by saving it into a file and typing "sh file".  To overwrite existing
  17. # files, type "sh file -c".  You can also feed this as standard input via
  18. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  19. # will see the following message at the end:
  20. #        "End of archive 10 (of 14)."
  21. # Contents:  lib/xlib/Makefile lib/xlib/display.c lib/xlib/xlib.h
  22. #   lib/xlib/color.c lib/xlib/window.c lib/xlib/BUGS lib/xlib/event.c
  23. #   lib/xlib/gcontext.c lib/xlib/graphics.c lib/xaw lib/xaw/form.d
  24. #   lib/xaw/command.d
  25. # Wrapped by net@tub on Sun Sep 17 17:32:34 1989
  26. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  27. if test -f lib/xlib/Makefile -a "${1}" != "-c" ; then 
  28.   echo shar: Will not over-write existing file \"lib/xlib/Makefile\"
  29. else
  30. echo shar: Extracting \"lib/xlib/Makefile\" \(1062 characters\)
  31. sed "s/^X//" >lib/xlib/Makefile <<'END_OF_lib/xlib/Makefile'
  32. XH=    ../../src/config.h\
  33. X    ../../src/object.h\
  34. X    ../../src/extern.h\
  35. X    ../../src/macros.h\
  36. X    ../util/symbol.h\
  37. X    ../util/string.h\
  38. X    ../util/objects.h\
  39. X    xlib.h
  40. X
  41. XC=    color.c\
  42. X    colormap.c\
  43. X    cursor.c\
  44. X    display.c\
  45. X    error.c\
  46. X    event.c\
  47. X    font.c\
  48. X    gcontext.c\
  49. X    graphics.c\
  50. X    key.c\
  51. X    objects.c\
  52. X    pixel.c\
  53. X    pixmap.c\
  54. X    pointer.c\
  55. X    property.c\
  56. X    text.c\
  57. X    type.c\
  58. X    window.c\
  59. X    wm.c
  60. X
  61. XO=    color.o\
  62. X    colormap.o\
  63. X    cursor.o\
  64. X    display.o\
  65. X    error.o\
  66. X    event.o\
  67. X    font.o\
  68. X    gcontext.o\
  69. X    graphics.o\
  70. X    key.o\
  71. X    objects.o\
  72. X    pixel.o\
  73. X    pixmap.o\
  74. X    pointer.o\
  75. X    property.o\
  76. X    text.o\
  77. X    type.o\
  78. X    window.o\
  79. X    wm.o\
  80. X    ../util/symbol.o\
  81. X    ../util/objects.o
  82. X
  83. X../xlib.o:    $(O)
  84. X    ld -r -x $(O) -lX11; mv a.out ../xlib.o; chmod 644 ../xlib.o
  85. X
  86. Xcolor.o:    $(H)
  87. Xcolormap.o:    $(H)
  88. Xcursor.o:    $(H)
  89. Xdisplay.o:    $(H)
  90. Xerror.o:    $(H)
  91. Xevent.o:    $(H)
  92. Xfont.o:        $(H)
  93. Xgcontext.o:    $(H)
  94. Xgraphics.o:    $(H)
  95. Xkey.o:        $(H)
  96. Xobjects.o:    $(H)
  97. Xpixel.o:    $(H)
  98. Xpixmap.o:    $(H)
  99. Xpointer.o:    $(H)
  100. Xproperty.o:    $(H)
  101. Xtext.o:        $(H)
  102. Xtype.o:        $(H)
  103. Xwindow.o:    $(H)
  104. Xwm.o:        $(H)
  105. X
  106. Xlint:
  107. X    lint $(LINTFLAGS) -abxh $(C) | egrep -v '\?\?\?'
  108. X
  109. Xclean:
  110. X    rm -f *.o core a.out ../xlib.o
  111. END_OF_lib/xlib/Makefile
  112. if test 1062 -ne `wc -c <lib/xlib/Makefile`; then
  113.     echo shar: \"lib/xlib/Makefile\" unpacked with wrong size!
  114. fi
  115. # end of overwriting check
  116. fi
  117. if test -f lib/xlib/display.c -a "${1}" != "-c" ; then 
  118.   echo shar: Will not over-write existing file \"lib/xlib/display.c\"
  119. else
  120. echo shar: Extracting \"lib/xlib/display.c\" \(4805 characters\)
  121. sed "s/^X//" >lib/xlib/display.c <<'END_OF_lib/xlib/display.c'
  122. X#include "xlib.h"
  123. X
  124. XObject Sym_Pointer_Root;
  125. X
  126. Xstatic Display_Visit (dp, f) Object *dp; int (*f)(); {
  127. X    (*f)(&DISPLAY(*dp)->after);
  128. X}
  129. X
  130. XGeneric_Predicate (Display);
  131. X
  132. XGeneric_Equal (Display, DISPLAY, dpy);
  133. X
  134. Xstatic Display_Print (d, port, raw, depth, length) Object d, port; {
  135. X    Printf (port, "#[display %u %s]", (unsigned)DISPLAY(d)->dpy,
  136. X    DisplayString (DISPLAY(d)->dpy));
  137. X}
  138. X
  139. XObject Make_Display (finalize, dpy) Display *dpy; {
  140. X    char *p;
  141. X    Object d;
  142. X
  143. X    d = Find_Object (T_Display, (GENERIC)dpy, Match_X_Obj);
  144. X    if (Nullp (d)) {
  145. X    p = Get_Bytes (sizeof (struct S_Display));
  146. X    SET (d, T_Display, (struct S_Display *)p);
  147. X    DISPLAY(d)->dpy = dpy;
  148. X    DISPLAY(d)->free = 0;
  149. X    DISPLAY(d)->after = False;
  150. X    Register_Object (d, (GENERIC)dpy, finalize ? P_Close_Display :
  151. X        (PFO)0, 1);
  152. X    }
  153. X    return d;
  154. X}
  155. X
  156. Xstatic Object P_Open_Display (argc, argv) Object *argv; {
  157. X    register char *s;
  158. X    Object name;
  159. X    Display *dpy;
  160. X
  161. X    if (argc == 1) {
  162. X    name = argv[0];
  163. X    Make_C_String (name, s);
  164. X    if ((dpy = XOpenDisplay (s)) == 0)
  165. X        Primitive_Error ("cannot open display ~s", name);
  166. X    } else if ((dpy = XOpenDisplay ((char *)0)) == 0)
  167. X    Primitive_Error ("cannot open display");
  168. X    return Make_Display (1, dpy);
  169. X}
  170. X
  171. XObject P_Close_Display (d) Object d; {
  172. X    register struct S_Display *p;
  173. X
  174. X    Check_Type (d, T_Display);
  175. X    p = DISPLAY(d);
  176. X    if (!p->free) {
  177. X    Terminate_Group ((GENERIC)p->dpy);
  178. X    XCloseDisplay (p->dpy);
  179. X    }
  180. X    Deregister_Object (d);
  181. X    p->free = 1;
  182. X    return Void;
  183. X}
  184. X
  185. Xstatic Object P_Display_Root_Window (d) Object d; {
  186. X    Check_Type (d, T_Display);
  187. X    return Make_Window (0, DISPLAY(d)->dpy,
  188. X    DefaultRootWindow (DISPLAY(d)->dpy));
  189. X}
  190. X
  191. Xstatic Object P_Display_Colormap (d) Object d; {
  192. X    register Display *dpy;
  193. X
  194. X    Check_Type (d, T_Display);
  195. X    dpy = DISPLAY(d)->dpy;
  196. X    return Make_Colormap (0, dpy, DefaultColormap (dpy, DefaultScreen (dpy)));
  197. X}
  198. X
  199. Xstatic Object P_Display_Default_Gcontext (d) Object d; {
  200. X    register Display *dpy;
  201. X
  202. X    Check_Type (d, T_Display);
  203. X    dpy = DISPLAY(d)->dpy;
  204. X    return Make_Gc (0, dpy, DefaultGC (dpy, DefaultScreen (dpy)));
  205. X}
  206. X
  207. Xstatic Object P_Display_Width (d) Object d; {
  208. X    Check_Type (d, T_Display);
  209. X    return Make_Fixnum (DisplayWidth (DISPLAY(d)->dpy,
  210. X    DefaultScreen (DISPLAY(d)->dpy)));
  211. X}
  212. X
  213. Xstatic Object P_Display_Height (d) Object d; {
  214. X    Check_Type (d, T_Display);
  215. X    return Make_Fixnum (DisplayHeight (DISPLAY(d)->dpy,
  216. X    DefaultScreen (DISPLAY(d)->dpy)));
  217. X}
  218. X
  219. Xstatic Object P_Display_Flush_Output (d) Object d; {
  220. X    Check_Type (d, T_Display);
  221. X    XFlush (DISPLAY(d)->dpy);
  222. X    return Void;
  223. X}
  224. X
  225. Xstatic Object P_Display_Wait_Output (d, discard) Object d, discard; {
  226. X    Check_Type (d, T_Display);
  227. X    Check_Type (discard, T_Boolean);
  228. X    XSync (DISPLAY(d)->dpy, EQ(discard, True));
  229. X    return Void;
  230. X}
  231. X
  232. Xstatic Object P_Set_Input_Focus (d, win, revert_to, time) Object d, win,
  233. X    revert_to, time; {
  234. X    Window focus = PointerRoot;
  235. X
  236. X    Check_Type (d, T_Display);
  237. X    if (!EQ(win, Sym_Pointer_Root))
  238. X    focus = Get_Window (win);
  239. X    XSetInputFocus (DISPLAY(d)->dpy, focus, Symbols_To_Bits (revert_to, 0,
  240. X    Revert_Syms), Get_Time (time));
  241. X    return Void;
  242. X}
  243. X
  244. Xstatic Object P_Input_Focus (d) Object d; {
  245. X    Window win;
  246. X    int revert_to;
  247. X    Object ret, x;
  248. X    GC_Node;
  249. X
  250. X    Check_Type (d, T_Display);
  251. X    XGetInputFocus (DISPLAY(d)->dpy, &win, &revert_to);
  252. X    ret = Cons (Null, Null);
  253. X    GC_Link (ret);
  254. X    x = Make_Window (0, DISPLAY(d)->dpy, win);
  255. X    Car (ret) = x;
  256. X    x = Bits_To_Symbols ((unsigned long)revert_to, 0, Revert_Syms);
  257. X    Cdr (ret) = x;
  258. X    GC_Unlink;
  259. X    return ret;
  260. X}
  261. X
  262. Xinit_xlib_display () {
  263. X    Define_Symbol (&Sym_Pointer_Root, "pointer-root");
  264. X    T_Display = Define_Type (0, "display", NOFUNC, sizeof (struct S_Display),
  265. X    Display_Equal, Display_Equal, Display_Print, Display_Visit);
  266. X    Define_Primitive (P_Displayp,        "display?",        1, 1, EVAL);
  267. X    Define_Primitive (P_Open_Display,    "open-display",    0, 1, VARARGS);
  268. X    Define_Primitive (P_Close_Display,   "close-display",   1, 1, EVAL);
  269. X    Define_Primitive (P_Display_Root_Window,     "display-root-window",
  270. X                                1, 1, EVAL);
  271. X    Define_Primitive (P_Display_Colormap,        "display-colormap",
  272. X                                1, 1, EVAL);
  273. X    Define_Primitive (P_Display_Default_Gcontext,"display-default-gcontext",
  274. X                                1, 1, EVAL);
  275. X    Define_Primitive (P_Display_Width,   "display-width",   1, 1, EVAL);
  276. X    Define_Primitive (P_Display_Height,  "display-height",  1, 1, EVAL);
  277. X    Define_Primitive (P_Display_Flush_Output,    "display-flush-output",
  278. X                                1, 1, EVAL);
  279. X    Define_Primitive (P_Display_Wait_Output,     "display-wait-output",
  280. X                                2, 2, EVAL);
  281. X    Define_Primitive (P_Set_Input_Focus,  "set-input-focus",4, 4, EVAL);
  282. X    Define_Primitive (P_Input_Focus,      "input-focus",    1, 1, EVAL);
  283. X    P_Provide (Intern ("xlib.o"));
  284. X}
  285. END_OF_lib/xlib/display.c
  286. if test 4805 -ne `wc -c <lib/xlib/display.c`; then
  287.     echo shar: \"lib/xlib/display.c\" unpacked with wrong size!
  288. fi
  289. # end of overwriting check
  290. fi
  291. if test -f lib/xlib/xlib.h -a "${1}" != "-c" ; then 
  292.   echo shar: Will not over-write existing file \"lib/xlib/xlib.h\"
  293. else
  294. echo shar: Extracting \"lib/xlib/xlib.h\" \(6659 characters\)
  295. sed "s/^X//" >lib/xlib/xlib.h <<'END_OF_lib/xlib/xlib.h'
  296. X#include <X11/X.h>
  297. X#include <X11/Xlib.h>
  298. X#include <X11/Xutil.h>
  299. X#include <signal.h>
  300. X
  301. X#define X_True True
  302. X#undef True
  303. X#define X_False False
  304. X#undef False
  305. X
  306. X#include <scheme.h>
  307. X
  308. X#include "../util/symbol.h"
  309. X#include "../util/string.h"
  310. X#include "../util/objects.h"
  311. X
  312. Xint T_Display;
  313. Xint T_Gc;
  314. Xint T_Pixel;
  315. Xint T_Pixmap;
  316. Xint T_Window;
  317. Xint T_Font;
  318. Xint T_Colormap;
  319. Xint T_Color;
  320. Xint T_Cursor;
  321. Xint T_Atom;
  322. X
  323. X#define DISPLAY(x)   ((struct S_Display *)POINTER(x))
  324. X#define GCONTEXT(x)  ((struct S_Gc *)POINTER(x))
  325. X#define PIXEL(x)     ((struct S_Pixel *)POINTER(x))
  326. X#define PIXMAP(x)    ((struct S_Pixmap *)POINTER(x))
  327. X#define WINDOW(x)    ((struct S_Window *)POINTER(x))
  328. X#define FONT(x)      ((struct S_Font *)POINTER(x))
  329. X#define COLORMAP(x)  ((struct S_Colormap *)POINTER(x))
  330. X#define COLOR(x)     ((struct S_Color *)POINTER(x))
  331. X#define CURSOR(x)    ((struct S_Cursor *)POINTER(x))
  332. X#define ATOM(x)      ((struct S_Atom *)POINTER(x))
  333. X
  334. Xstruct S_Display {
  335. X    Object after;
  336. X    Display *dpy;
  337. X    char free;
  338. X};
  339. X
  340. Xstruct S_Gc {
  341. X    Object tag;
  342. X    GC gc;
  343. X    Display *dpy;
  344. X    char free;
  345. X};
  346. X
  347. Xstruct S_Pixel {
  348. X    Object tag;
  349. X    unsigned long pix;
  350. X};
  351. X
  352. Xstruct S_Pixmap {
  353. X    Object tag;
  354. X    Pixmap pm;
  355. X    Display *dpy;
  356. X    char free;
  357. X};
  358. X
  359. Xstruct S_Window {
  360. X    Object tag;
  361. X    Window win;
  362. X    Display *dpy;
  363. X    char free;
  364. X    char finalize;
  365. X};
  366. X
  367. Xstruct S_Font {
  368. X    Object name;
  369. X    Font id;
  370. X    XFontStruct *info;
  371. X    Display *dpy;
  372. X};
  373. X
  374. Xstruct S_Colormap {
  375. X    Object tag;
  376. X    Colormap cm;
  377. X    Display *dpy;
  378. X    char free;
  379. X};
  380. X
  381. Xstruct S_Color {
  382. X    Object tag;
  383. X    XColor c;
  384. X};
  385. X
  386. Xstruct S_Cursor {
  387. X    Object tag;
  388. X    Cursor cursor;
  389. X    Display *dpy;
  390. X    char free;
  391. X};
  392. X
  393. Xstruct S_Atom {
  394. X    Object tag;
  395. X    Atom atom;
  396. X};
  397. X
  398. Xextern unsigned long Encode_Event_Mask();
  399. Xextern unsigned long Get_Pixel();
  400. Xextern Pixmap Get_Pixmap();
  401. Xextern Font Get_Font();
  402. Xextern XColor *Get_Color();
  403. Xextern Colormap Get_Colormap();
  404. Xextern Cursor Get_Cursor();
  405. Xextern Window Get_Window();
  406. Xextern Drawable Get_Drawable();
  407. Xextern Object Get_Event_Args(), Make_Cursor(), Make_Pixmap();
  408. Xextern Object Make_Display(), Make_Window(), Make_Colormap(), Make_Atom();
  409. Xextern Object Make_Font(), Make_Pixel(), Make_Gc(), P_Destroy_Window();
  410. Xextern Object P_Close_Display(), P_Free_Gc(), P_Close_Font(), P_Free_Pixmap();
  411. Xextern Object P_Free_Colormap(), P_Free_Cursor();
  412. Xextern Time Get_Time();
  413. Xextern Match_X_Obj();
  414. X
  415. Xenum Type {
  416. X    T_NONE,
  417. X    T_INT, T_LONG, T_ULONG, T_PIXEL, T_PIXMAP, T_BOOL, T_FONT,
  418. X    T_COLORMAP, T_CURSOR, T_WINDOW, T_MASK, T_SYM, T_SHORT,
  419. X};
  420. X
  421. Xtypedef struct {
  422. X    char *slot;
  423. X    char *name;
  424. X    enum Type type;
  425. X    SYMDESCR *syms;
  426. X    int mask;
  427. X} RECORD;
  428. X
  429. Xtypedef struct {
  430. X    Window root;
  431. X    int x, y, width, height, border_width, depth;
  432. X} GEOMETRY;
  433. X
  434. Xextern XSetWindowAttributes SWA;
  435. Xextern XWindowChanges WC;
  436. Xextern XGCValues GCV;
  437. Xextern GEOMETRY GEO;
  438. Xextern XWindowAttributes WA;
  439. Xextern XFontStruct FI;
  440. Xextern XCharStruct CI;
  441. Xextern XWMHints WMH;
  442. Xextern XSizeHints SZH;
  443. Xextern XIconSize ISZ;
  444. X
  445. Xextern Set_Attr_Size, Conf_Size, GC_Size, Geometry_Size, Win_Attr_Size,
  446. X    Font_Info_Size, Char_Info_Size, Wm_Hints_Size, Size_Hints_Size,
  447. X    Icon_Size_Size;
  448. Xextern RECORD Set_Attr_Rec[], Conf_Rec[], GC_Rec[], Geometry_Rec[],
  449. X    Win_Attr_Rec[], Font_Info_Rec[], Char_Info_Rec[], Wm_Hints_Rec[],
  450. X    Size_Hints_Rec[], Icon_Size_Rec[];
  451. X
  452. Xextern unsigned long Vector_To_Record();
  453. Xextern Object Record_To_Vector();
  454. X
  455. Xextern SYMDESCR Func_Syms[], Bit_Grav_Syms[], Event_Syms[], Error_Syms[],
  456. X    Grav_Syms[], Backing_Store_Syms[], Class_Syms[], Stack_Mode_Syms[],
  457. X    Line_Style_Syms[], State_Syms[], Cap_Style_Syms[], Join_Style_Syms[],
  458. X    Map_State_Syms[], Fill_Style_Syms[], Fill_Rule_Syms[], Arc_Mode_Syms[],
  459. X    Subwin_Mode_Syms[], Button_Syms[], Cross_Mode_Syms[], Cross_Detail_Syms[],
  460. X    Focus_Detail_Syms[], Place_Syms[], Visibility_Syms[], Prop_Syms[],
  461. X    Mapping_Syms[], Direction_Syms[], Shape_Syms[], Propmode_Syms[],
  462. X    Grabstatus_Syms[], Allow_Events_Syms[], Revert_Syms[], Polyshape_Syms[],
  463. X    Initial_State_Syms[], Bitmapstatus_Syms[];
  464. X
  465. Xextern Object Sym_None, Sym_Now, Sym_Char_Info, Sym_Pointer_Root;
  466. X
  467. X
  468. X#ifdef __STDC__
  469. X#define conc(a,b) a##b
  470. X#define conc3(a,b,c) a##b##c
  471. X#else
  472. X#define ident(x) x
  473. X#define conc(a,b) ident(a)b
  474. X#define conc3(a,b,c) conc(conc(a,b),c)
  475. X#endif
  476. X
  477. X
  478. X/* Generic_Predicate (Pixmap) generates:
  479. X *
  480. X *    static Object P_Pixmapp (x) Object x; {
  481. X *        return TYPE(x) == T_Pixmap ? True : False;
  482. X *   }
  483. X */
  484. X#define Generic_Predicate(type) static Object conc3(P_,type,p) (x) Object x; {\
  485. X    return TYPE(x) == conc(T_,type) ? True : False;\
  486. X}
  487. X
  488. X/* Generic_Equal (Pixmap, PIXMAP, pm) generates:
  489. X *
  490. X *    static Pixmap_Equal (x, y) Object x, y; {
  491. X *        return PIXMAP(x)->pm == PIXMAP(y)->field
  492. X *            && !PIXMAP(x)->free && !PIXMAP(y)->free;
  493. X *    }
  494. X */
  495. X#define Generic_Equal(type,cast,field) static conc(type,_Equal) (x, y)\
  496. X    Object x, y; {\
  497. X    return cast(x)->field == cast(y)->field\
  498. X    && !cast(x)->free && !cast(y)->free;\
  499. X}
  500. X
  501. X/* Same as above, but doesn't check for ->free:
  502. X */
  503. X#define Generic_Simple_Equal(type,cast,field) static conc(type,_Equal) (x, y)\
  504. X    Object x, y; {\
  505. X    return cast(x)->field == cast(y)->field;\
  506. X}
  507. X
  508. X/* Same as above, but also checks ->dpy
  509. X */
  510. X#define Generic_Equal_Dpy(type,cast,field) static Object conc(type,_Equal)\
  511. X        (x, y)\
  512. X    Object x, y; {\
  513. X    return cast(x)->field == cast(y)->field && cast(x)->dpy == cast(y)->dpy\
  514. X    && !cast(x)->free && !cast(y)->free;\
  515. X}
  516. X
  517. X/* Generic_Print (Pixmap, "#[pixmap %u]", PIXMAP(x)->pm) generates:
  518. X *
  519. X *    static Pixmap_Print (x, port, raw, depth, len) Object x, port; {
  520. X *        Printf (port, "#[pixmap %u]", PIXMAP(x)->pm);
  521. X *    }
  522. X */
  523. X#define Generic_Print(type,fmt,how) static conc(type,_Print)\
  524. X    (x, port, raw, depth, len) Object x, port; {\
  525. X    Printf (port, fmt, (unsigned)how);\
  526. X}
  527. X
  528. X/* Generic_Define (Pixmap, "pixmap", "pixmap?") generates:
  529. X *
  530. X *    T_Pixmap = Define_Type (0, "pixmap", NOFUNC, sizeof (struct S_Pixmap),
  531. X *        Pixmap_Equal, Pixmap_Equal, Pixmap_Print, NOFUNC);
  532. X *    Define_Primitive (P_Pixmapp, "pixmap?", 1, 1, EVAL);
  533. X */
  534. X#define Generic_Define(type,name,pred) conc(T_,type) =\
  535. X    Define_Type (0, name, NOFUNC, sizeof (struct conc(S_,type)),\
  536. X    conc(type,_Equal), conc(type,_Equal), conc(type,_Print), NOFUNC);\
  537. X    Define_Primitive (conc3(P_,type,p), pred, 1, 1, EVAL);
  538. X
  539. X/* Generic_Get_Display (Pixmap, PIXMAP) generates:
  540. X *
  541. X *    static Object P_Pixmap_Display (x) Object x; {
  542. X *        Check_Type (x, T_Pixmap);
  543. X *        return Make_Display (PIXMAP(x)->dpy);
  544. X *    }
  545. X */
  546. X#define Generic_Get_Display(type,cast) static Object conc3(P_,type,_Display)\
  547. X    (x) Object x; {\
  548. X    Check_Type (x, conc(T_,type));\
  549. X    return Make_Display (0, cast(x)->dpy);\
  550. X}
  551. END_OF_lib/xlib/xlib.h
  552. if test 6659 -ne `wc -c <lib/xlib/xlib.h`; then
  553.     echo shar: \"lib/xlib/xlib.h\" unpacked with wrong size!
  554. fi
  555. # end of overwriting check
  556. fi
  557. if test -f lib/xlib/color.c -a "${1}" != "-c" ; then 
  558.   echo shar: Will not over-write existing file \"lib/xlib/color.c\"
  559. else
  560. echo shar: Extracting \"lib/xlib/color.c\" \(3568 characters\)
  561. sed "s/^X//" >lib/xlib/color.c <<'END_OF_lib/xlib/color.c'
  562. X#include "xlib.h"
  563. X
  564. XGeneric_Predicate (Color);
  565. X
  566. Xstatic Color_Equal (x, y) Object x, y; {
  567. X    register XColor *p = &COLOR(x)->c, *q = &COLOR(y)->c;
  568. X    return p->red == q->red && p->green == q->green && p->blue == q->blue;
  569. X}
  570. X
  571. XGeneric_Print (Color, "#[color %u]", POINTER(x));
  572. X
  573. XObject Make_Color (r, g, b) unsigned short r, g, b; {
  574. X    register char *p;
  575. X    Object c;
  576. X
  577. X    c = Find_Object (T_Color, (GENERIC)0, Match_X_Obj, r, g, b);
  578. X    if (Nullp (c)) {
  579. X    p = Get_Bytes (sizeof (struct S_Color));
  580. X    SET (c, T_Color, (struct S_Color *)p);
  581. X    COLOR(c)->tag = Null;
  582. X    COLOR(c)->c.red = r;
  583. X    COLOR(c)->c.green = g;
  584. X    COLOR(c)->c.blue = b;
  585. X    Register_Object (c, (GENERIC)0, (PFO)0, 0);
  586. X    }
  587. X    return c;
  588. X}
  589. X
  590. XXColor *Get_Color (c) Object c; {
  591. X    Check_Type (c, T_Color);
  592. X    return &COLOR(c)->c;
  593. X}
  594. X
  595. Xstatic unsigned short Get_RGB_Value (x) Object x; {
  596. X    double d;
  597. X
  598. X    d = Get_Double (x);
  599. X    if (d < 0.0 || d > 1.0)
  600. X    Primitive_Error ("bad RGB value: ~s", x);
  601. X    return (unsigned short)(d * 65535);
  602. X}
  603. X
  604. Xstatic Object P_Make_Color (r, g, b) Object r, g, b; {
  605. X    return Make_Color (Get_RGB_Value (r), Get_RGB_Value (g), Get_RGB_Value (b));
  606. X}
  607. X
  608. Xstatic Object P_Color_Rgb_Values (c) Object c; {
  609. X    Object ret, t, x;
  610. X    GC_Node3;
  611. X
  612. X    Check_Type (c, T_Color);
  613. X    ret = t = Null;
  614. X    GC_Link3 (c, ret, t);
  615. X    t = ret = P_Make_List (Make_Fixnum (3), Null);
  616. X    GC_Unlink;
  617. X    x = Make_Reduced_Flonum (COLOR(c)->c.red / 65535.0);
  618. X    Car (t) = x; t = Cdr (t);
  619. X    x = Make_Reduced_Flonum (COLOR(c)->c.green / 65535.0);
  620. X    Car (t) = x; t = Cdr (t);
  621. X    x = Make_Reduced_Flonum (COLOR(c)->c.blue / 65535.0);
  622. X    Car (t) = x;
  623. X    return ret;
  624. X}
  625. X
  626. Xstatic Object P_Query_Color (cmap, p) Object cmap, p; {
  627. X    XColor c;
  628. X    Colormap cm = Get_Colormap (cmap);
  629. X
  630. X    c.pixel = Get_Pixel (p);
  631. X    Disable_Interrupts;
  632. X    XQueryColor (COLORMAP(cmap)->dpy, cm, &c);
  633. X    Enable_Interrupts;
  634. X    return Make_Color (c.red, c.green, c.blue);
  635. X}
  636. X
  637. Xstatic Object P_Query_Colors (cmap, v) Object cmap, v; {
  638. X    Colormap cm = Get_Colormap (cmap);
  639. X    register i, n;
  640. X    Object ret;
  641. X    register XColor *p;
  642. X    GC_Node;
  643. X
  644. X    Check_Type (v, T_Vector);
  645. X    n = VECTOR(v)->size;
  646. X    p = (XColor *)alloca (n * sizeof (XColor));
  647. X    for (i = 0; i < n; i++)
  648. X    p[i].pixel = Get_Pixel (VECTOR(v)->data[i]);
  649. X    Disable_Interrupts;
  650. X    XQueryColors (COLORMAP(cmap)->dpy, cm, p, n);
  651. X    Enable_Interrupts;
  652. X    ret = Make_Vector (n, Null);
  653. X    GC_Link (ret);
  654. X    for (i = 0; i < n; i++, p++) {
  655. X    Object x = Make_Color (p->red, p->green, p->blue);
  656. X    VECTOR(ret)->data[i] = x;
  657. X    }
  658. X    GC_Unlink;
  659. X    return ret;
  660. X}
  661. X
  662. Xstatic Object P_Lookup_Color (cmap, name) Object cmap, name; {
  663. X    register char *s;
  664. X    XColor visual, exact;
  665. X    Colormap cm = Get_Colormap (cmap);
  666. X    Object ret, x;
  667. X    GC_Node;
  668. X
  669. X    Make_C_String (name, s);
  670. X    if (!XLookupColor (COLORMAP(cmap)->dpy, cm, s, &visual, &exact))
  671. X    Primitive_Error ("no such color: ~s", name);
  672. X    ret = Cons (Null, Null);
  673. X    GC_Link (ret);
  674. X    x = Make_Color (visual.red, visual.green, visual.blue);
  675. X    Car (ret) = x;
  676. X    x = Make_Color (exact.red, exact.green, exact.blue);
  677. X    Cdr (ret) = x;
  678. X    GC_Unlink;
  679. X    return ret;
  680. X}
  681. X
  682. Xinit_xlib_color () {
  683. X    Generic_Define (Color, "color", "color?");
  684. X    Define_Primitive (P_Make_Color,       "make-color",       3, 3, EVAL);
  685. X    Define_Primitive (P_Color_Rgb_Values, "color-rgb-values", 1, 1, EVAL);
  686. X    Define_Primitive (P_Query_Color,      "query-color",      2, 2, EVAL);
  687. X    Define_Primitive (P_Query_Colors,     "query-colors",     2, 2, EVAL);
  688. X    Define_Primitive (P_Lookup_Color,     "lookup-color",     2, 2, EVAL);
  689. X}
  690. END_OF_lib/xlib/color.c
  691. if test 3568 -ne `wc -c <lib/xlib/color.c`; then
  692.     echo shar: \"lib/xlib/color.c\" unpacked with wrong size!
  693. fi
  694. # end of overwriting check
  695. fi
  696. if test -f lib/xlib/window.c -a "${1}" != "-c" ; then 
  697.   echo shar: Will not over-write existing file \"lib/xlib/window.c\"
  698. else
  699. echo shar: Extracting \"lib/xlib/window.c\" \(7144 characters\)
  700. sed "s/^X//" >lib/xlib/window.c <<'END_OF_lib/xlib/window.c'
  701. X#include "xlib.h"
  702. X
  703. Xstatic Object Sym_Set_Attr, Sym_Get_Attr, Sym_Conf, Sym_Geo;
  704. X
  705. XGeneric_Predicate (Window);
  706. X
  707. XGeneric_Equal_Dpy (Window, WINDOW, win);
  708. X
  709. XGeneric_Print (Window, "#[window %u]", WINDOW(x)->win);
  710. X
  711. XGeneric_Get_Display (Window, WINDOW);
  712. X
  713. XObject Make_Window (finalize, dpy, win) Display *dpy; Window win; {
  714. X    register char *p;
  715. X    Object w;
  716. X
  717. X    if (win == None)
  718. X    return Sym_None;
  719. X    if (win == PointerRoot)
  720. X    return Sym_Pointer_Root;
  721. X    w = Find_Object (T_Window, (GENERIC)dpy, Match_X_Obj, win);
  722. X    if (Nullp (w)) {
  723. X    p = Get_Bytes (sizeof (struct S_Window));
  724. X    SET (w, T_Window, (struct S_Window *)p);
  725. X    WINDOW(w)->tag = Null;
  726. X    WINDOW(w)->win = win;
  727. X    WINDOW(w)->dpy = dpy;
  728. X    WINDOW(w)->free = 0;
  729. X    WINDOW(w)->finalize = finalize;
  730. X    Register_Object (w, (GENERIC)dpy, finalize ? P_Destroy_Window :
  731. X        (PFO)0, 0);
  732. X    }
  733. X    return w;
  734. X}
  735. X
  736. XWindow Get_Window (w) Object w; {
  737. X    if (EQ(w, Sym_None))
  738. X    return None;
  739. X    Check_Type (w, T_Window);
  740. X    return WINDOW(w)->win;
  741. X}
  742. X
  743. XDrawable Get_Drawable (d, dpyp) Object d; Display **dpyp; {
  744. X    if (TYPE(d) == T_Window) {
  745. X    *dpyp = WINDOW(d)->dpy;
  746. X    return (Drawable)WINDOW(d)->win;
  747. X    } else if (TYPE(d) == T_Pixmap) {
  748. X    *dpyp = PIXMAP(d)->dpy;
  749. X    return (Drawable)PIXMAP(d)->pm;
  750. X    }
  751. X    Wrong_Type_Combination (d, "drawable");
  752. X    /*NOTREACHED*/
  753. X}
  754. X
  755. Xstatic Object P_Create_Window (parent, x, y, width, height, border_width, attr)
  756. X    Object parent, x, y, width, height, border_width, attr; {
  757. X    unsigned long mask;
  758. X    Window win;
  759. X    
  760. X    Check_Type (parent, T_Window);
  761. X    mask = Vector_To_Record (attr, Set_Attr_Size, Sym_Set_Attr, Set_Attr_Rec);
  762. X    if ((win = XCreateWindow (WINDOW(parent)->dpy, WINDOW(parent)->win,
  763. X        Get_Integer (x), Get_Integer (y), Get_Integer (width),
  764. X        Get_Integer (height), Get_Integer (border_width),
  765. X        CopyFromParent, CopyFromParent, CopyFromParent, mask, &SWA)) == 0)
  766. X    Primitive_Error ("cannot create window");
  767. X    return Make_Window (1, WINDOW(parent)->dpy, win);
  768. X}
  769. X
  770. Xstatic Object P_Configure_Window (w, conf) Object w, conf; {
  771. X    unsigned mask;
  772. X
  773. X    Check_Type (w, T_Window);
  774. X    mask = Vector_To_Record (conf, Conf_Size, Sym_Conf, Conf_Rec);
  775. X    XConfigureWindow (WINDOW(w)->dpy, WINDOW(w)->win, mask, &WC);
  776. X    return Void;
  777. X}
  778. X
  779. Xstatic Object P_Change_Window_Attributes (w, attr) Object w, attr; {
  780. X    unsigned long mask;
  781. X
  782. X    Check_Type (w, T_Window);
  783. X    mask = Vector_To_Record (attr, Set_Attr_Size, Sym_Set_Attr, Set_Attr_Rec);
  784. X    XChangeWindowAttributes (WINDOW(w)->dpy, WINDOW(w)->win, mask, &SWA);
  785. X    return Void;
  786. X}
  787. X
  788. Xstatic Object P_Get_Window_Attributes (w) Object w; {
  789. X    Check_Type (w, T_Window);
  790. X    XGetWindowAttributes (WINDOW(w)->dpy, WINDOW(w)->win, &WA);
  791. X    return Record_To_Vector (Win_Attr_Rec, Win_Attr_Size, Sym_Get_Attr,
  792. X    WINDOW(w)->dpy, ~0L);
  793. X}
  794. X
  795. Xstatic Object P_Get_Geometry (d) Object d; {
  796. X    Display *dpy;
  797. X    Drawable dr = Get_Drawable (d, &dpy);
  798. X
  799. X    XGetGeometry (dpy, dr, &GEO.root, &GEO.x, &GEO.y, &GEO.width,
  800. X    &GEO.height, &GEO.border_width, &GEO.depth);
  801. X    return Record_To_Vector (Geometry_Rec, Geometry_Size, Sym_Geo, dpy, ~0L);
  802. X}
  803. X
  804. Xstatic Object P_Map_Window (w) Object w; {
  805. X    Check_Type (w, T_Window);
  806. X    XMapWindow (WINDOW(w)->dpy, WINDOW(w)->win);
  807. X    return Void;
  808. X}
  809. X
  810. Xstatic Object P_Unmap_Window (w) Object w; {
  811. X    Check_Type (w, T_Window);
  812. X    XUnmapWindow (WINDOW(w)->dpy, WINDOW(w)->win);
  813. X    return Void;
  814. X}
  815. X
  816. XObject P_Destroy_Window (w) Object w; {
  817. X    Check_Type (w, T_Window);
  818. X    if (!WINDOW(w)->free)
  819. X    XDestroyWindow (WINDOW(w)->dpy, WINDOW(w)->win);
  820. X    Deregister_Object (w);
  821. X    WINDOW(w)->free = 1;
  822. X    return Void;
  823. X}
  824. X
  825. Xstatic Object P_Destroy_Subwindows (w) Object w; {
  826. X    Check_Type (w, T_Window);
  827. X    XDestroySubwindows (WINDOW(w)->dpy, WINDOW(w)->win);
  828. X    return Void;
  829. X}
  830. X
  831. Xstatic Object P_Map_Subwindows (w) Object w; {
  832. X    Check_Type (w, T_Window);
  833. X    XMapSubwindows (WINDOW(w)->dpy, WINDOW(w)->win);
  834. X    return Void;
  835. X}
  836. X
  837. Xstatic Object P_Unmap_Subwindows (w) Object w; {
  838. X    Check_Type (w, T_Window);
  839. X    XUnmapSubwindows (WINDOW(w)->dpy, WINDOW(w)->win);
  840. X    return Void;
  841. X}
  842. X
  843. Xstatic Object P_Reparent_Window (w, parent, x, y) Object w, parent, x, y; {
  844. X    Check_Type (w, T_Window);
  845. X    Check_Type (parent, T_Window);
  846. X    XReparentWindow (WINDOW(w)->dpy, WINDOW(w)->win, WINDOW(parent)->win,
  847. X    Get_Integer (x), Get_Integer (y));
  848. X    return Void;
  849. X}
  850. X
  851. Xstatic Object P_Query_Tree (w) Object w; {
  852. X    Window root, parent, *children;
  853. X    Display *dpy;
  854. X    int i, n;
  855. X    Object v, ret;
  856. X    GC_Node2;
  857. X
  858. X    Check_Type (w, T_Window);
  859. X    dpy = WINDOW(w)->dpy;
  860. X    Disable_Interrupts;
  861. X    XQueryTree (dpy, WINDOW(w)->win, &root, &parent, &children, &n);
  862. X    Enable_Interrupts;
  863. X    v = ret = Null;
  864. X    GC_Link2 (v, ret);
  865. X    v = Make_Window (0, dpy, root);
  866. X    ret = Cons (v, Null);
  867. X    v = Make_Window (0, dpy, parent);
  868. X    ret = Cons (v, ret);
  869. X    v = Make_Vector (n, Null);
  870. X    for (i = 0; i < n; i++) {
  871. X    Object x = Make_Window (0, dpy, children[i]);
  872. X    VECTOR(v)->data[i] = x;
  873. X    }
  874. X    ret = Cons (v, ret);
  875. X    GC_Unlink;
  876. X    return ret;
  877. X}
  878. X
  879. Xstatic Object P_Translate_Coordinates (src, x, y, dst) Object src, x, y, dst; {
  880. X    int rx, ry;
  881. X    Window child;
  882. X    Object l, t, z;
  883. X    GC_Node3;
  884. X
  885. X    Check_Type (src, T_Window);
  886. X    Check_Type (dst, T_Window);
  887. X    if (!XTranslateCoordinates (WINDOW(src)->dpy, WINDOW(src)->win,
  888. X        WINDOW(dst)->win, Get_Integer (x), Get_Integer (y), &rx, &ry,
  889. X        &child))
  890. X    return False;
  891. X    l = t = P_Make_List (Make_Fixnum (3), Null);
  892. X    GC_Link3 (l, t, dst);
  893. X    Car (t) = Make_Fixnum (rx); t = Cdr (t);
  894. X    Car (t) = Make_Fixnum (ry), t = Cdr (t);
  895. X    z = Make_Window (0, WINDOW(dst)->dpy, child);
  896. X    Car (t) = z;
  897. X    GC_Unlink;
  898. X    return l;
  899. X}
  900. X
  901. Xinit_xlib_window () {
  902. X    Define_Symbol (&Sym_Set_Attr, "set-window-attributes");
  903. X    Define_Symbol (&Sym_Get_Attr, "get-window-attributes");
  904. X    Define_Symbol (&Sym_Conf, "window-configuration");
  905. X    Define_Symbol (&Sym_Geo, "geometry");
  906. X    Generic_Define (Window, "window", "window?");
  907. X    Define_Primitive (P_Window_Display,   "window-display",   1, 1, EVAL);
  908. X    Define_Primitive (P_Create_Window,    "create-window",    7, 7, EVAL);
  909. X    Define_Primitive (P_Configure_Window, "configure-window",
  910. X                                  2, 2, EVAL);
  911. X    Define_Primitive (P_Change_Window_Attributes, "change-window-attributes",
  912. X                                  2, 2, EVAL);
  913. X    Define_Primitive (P_Get_Window_Attributes, "get-window-attributes",
  914. X                                  1, 1, EVAL);
  915. X    Define_Primitive (P_Get_Geometry,     "get-geometry",     1, 1, EVAL);
  916. X    Define_Primitive (P_Map_Window,       "map-window",       1, 1, EVAL);
  917. X    Define_Primitive (P_Unmap_Window,     "unmap-window",     1, 1, EVAL);
  918. X    Define_Primitive (P_Destroy_Window,   "destroy-window",   1, 1, EVAL);
  919. X    Define_Primitive (P_Destroy_Subwindows, "destroy-subwindows",
  920. X                                  1, 1, EVAL);
  921. X    Define_Primitive (P_Map_Subwindows,   "map-subwindows",   1, 1, EVAL);
  922. X    Define_Primitive (P_Unmap_Subwindows, "unmap-subwindows", 1, 1, EVAL);
  923. X    Define_Primitive (P_Reparent_Window,  "reparent-window",  4, 4, EVAL);
  924. X    Define_Primitive (P_Query_Tree,       "query-tree",       1, 1, EVAL);
  925. X    Define_Primitive (P_Translate_Coordinates, "translate-coordinates",
  926. X                                  4, 4, EVAL);
  927. X}
  928. END_OF_lib/xlib/window.c
  929. if test 7144 -ne `wc -c <lib/xlib/window.c`; then
  930.     echo shar: \"lib/xlib/window.c\" unpacked with wrong size!
  931. fi
  932. # end of overwriting check
  933. fi
  934. if test -f lib/xlib/BUGS -a "${1}" != "-c" ; then 
  935.   echo shar: Will not over-write existing file \"lib/xlib/BUGS\"
  936. else
  937. echo shar: Extracting \"lib/xlib/BUGS\" \(737 characters\)
  938. sed "s/^X//" >lib/xlib/BUGS <<'END_OF_lib/xlib/BUGS'
  939. Xbackground-pixmap, border-pixmap can also be 'none or a symbol
  940. X
  941. Xset-gcontext-clip-rectangles! not implemented
  942. X
  943. XNeed a general keyword wrapper for
  944. X  1) functions like create-window that receive a vector
  945. X  2) functions with many arguments in general
  946. X
  947. XHigh-level interface for wm-hints/size-hints not implemented
  948. X
  949. Xx-io-errors should not be handled in Scheme (client must exit
  950. Xafter fatal error)
  951. X
  952. XP_Copy_Area, P_Copy_Plane:  initialization of dpy is broken
  953. X
  954. XP_Get_Property:  replace Make_Integer by Make_Unsigned?  Where else?
  955. X
  956. Xfont-name can return a symbol as well as a string
  957. X
  958. Xextents-attributes, max-char-attributes, and min-char-attributes
  959. Xare bogus and should be removed
  960. X
  961. Xthere is currently no support for different screens and visuals
  962. END_OF_lib/xlib/BUGS
  963. if test 737 -ne `wc -c <lib/xlib/BUGS`; then
  964.     echo shar: \"lib/xlib/BUGS\" unpacked with wrong size!
  965. fi
  966. # end of overwriting check
  967. fi
  968. if test -f lib/xlib/event.c -a "${1}" != "-c" ; then 
  969.   echo shar: Will not over-write existing file \"lib/xlib/event.c\"
  970. else
  971. echo shar: Extracting \"lib/xlib/event.c\" \(15403 characters\)
  972. sed "s/^X//" >lib/xlib/event.c <<'END_OF_lib/xlib/event.c'
  973. X#include "xlib.h"
  974. X
  975. X#define MAX_ARGS 14
  976. X
  977. Xstatic Object Sym_Else;
  978. Xstatic Object Argl, Argv;
  979. X
  980. Xstatic struct event_desc {
  981. X    char *name;
  982. X    int argc;
  983. X} Event_Table[] = {
  984. X    { "event-0",          1 },
  985. X    { "event-1",             1 },
  986. X    { "key-press",          12 },
  987. X    { "key-release",        12 },
  988. X    { "button-press",       12 },
  989. X    { "button-release",     12 },
  990. X    { "motion-notify",      12 },
  991. X    { "enter-notify",       14 },
  992. X    { "leave-notify",       14 },
  993. X    { "focus-in",            4 },
  994. X    { "focus-out",           4 },
  995. X    { "keymap-notify",       3 },
  996. X    { "expose",              7 },
  997. X    { "graphics-expose",     9 },
  998. X    { "no-expose",           4 },
  999. X    { "visibility-notify",   3 },
  1000. X    { "create-notify",       9 },
  1001. X    { "destroy-notify",      3 },
  1002. X    { "unmap-notify",        4 },
  1003. X    { "map-notify",          4 },
  1004. X    { "map-request",         3 },
  1005. X    { "reparent-notify",     7 },
  1006. X    { "configure-notify",   10 },
  1007. X    { "configure-request",  11 },
  1008. X    { "gravity-notify",      5 },
  1009. X    { "resize-request",      4 },
  1010. X    { "circulate-notify",    4 },
  1011. X    { "circulate-request",   4 },
  1012. X    { "property-notify",     5 },
  1013. X    { "selection-clear",     4 },
  1014. X    { "selection-request",   7 },
  1015. X    { "selection-notify",    6 },
  1016. X    { "colormap-notify",     5 },
  1017. X    { "client-message",      1 },
  1018. X    { "mapping-notify",      4 },
  1019. X    { 0,                     0 }
  1020. X};
  1021. X
  1022. X/* (handle-events display clause...)
  1023. X * clause = (event function) or ((event...) function) or (else function)
  1024. X * loops/blocks until a function returns x != #f, then returns x.
  1025. X */
  1026. X
  1027. Xstatic Object P_Handle_Events (argl) Object argl; {
  1028. X    Object disp, clause, func, ret, funcs[LASTEvent], args;
  1029. X    register i;
  1030. X    Display *dpy;
  1031. X    Window win = None;
  1032. X    XEvent e;
  1033. X    char *errmsg = "event occurs more than once";
  1034. X    GC_Node3; struct gcnode gcv;
  1035. X    TC_Prolog;
  1036. X
  1037. X    TC_Disable;
  1038. X    clause = args = Null;
  1039. X    GC_Link3 (argl, clause, args);
  1040. X    disp = Eval (Car (argl));
  1041. X    if (TYPE(disp) == T_Display) {
  1042. X    dpy = DISPLAY(disp)->dpy;
  1043. X    } else if (TYPE(disp) == T_Window) {
  1044. X    dpy = WINDOW(disp)->dpy;
  1045. X    win = WINDOW(disp)->win;
  1046. X    } else Wrong_Type_Combination (disp, "display or window");
  1047. X    for (i = 0; i < 32; i++)
  1048. X    funcs[i] = Null;
  1049. X    gcv.gclen = 1 + 32; gcv.gcobj = funcs; gcv.next = &gc3; GC_List = &gcv;
  1050. X    for (argl = Cdr (argl); !Nullp (argl); argl = Cdr (argl)) {
  1051. X    clause = Car (argl);
  1052. X    Check_List (clause);
  1053. X    if (Internal_Length (clause) != 2)
  1054. X        Primitive_Error ("badly formed event clause");
  1055. X    func = Eval (Car (Cdr (clause)));
  1056. X    Check_Procedure (func);
  1057. X    clause = Car (clause);
  1058. X    if (EQ(clause, Sym_Else)) {
  1059. X        for (i = 0; i < 32; i++)
  1060. X        if (Nullp (funcs[i])) funcs[i] = func;
  1061. X    } else {
  1062. X        if (TYPE(clause) == T_Pair) {
  1063. X        for (; !Nullp (clause); clause = Cdr (clause)) {
  1064. X            i = Encode_Event (Car (clause));
  1065. X            if (!Nullp (funcs[i]))
  1066. X            Primitive_Error (errmsg);
  1067. X            funcs[i] = func;
  1068. X        }
  1069. X        } else {
  1070. X        i = Encode_Event (clause);
  1071. X        if (!Nullp (funcs[i]))
  1072. X            Primitive_Error (errmsg);
  1073. X        funcs[i] = func;
  1074. X        }
  1075. X    }
  1076. X    }
  1077. X    ret = False;
  1078. X    while (!Truep (ret)) {
  1079. X    if (win == None)
  1080. X        XNextEvent (dpy, &e);
  1081. X    else
  1082. X        XWindowEvent (dpy, win, ~0L, &e);
  1083. X    if ((i = e.type) < LASTEvent && !Nullp (funcs[i])) {
  1084. X        args = Get_Event_Args (&e);
  1085. X        ret = Funcall (funcs[i], args, 0);
  1086. X        /*
  1087. X         * The argument vector is cleared to destroy all references
  1088. X         * to the arguments (so that a GC can throw away the objects):
  1089. X         */
  1090. X        Destroy_Event_Args (args);
  1091. X    }
  1092. X    }
  1093. X    GC_Unlink;
  1094. X    TC_Enable;
  1095. X    return ret;
  1096. X}
  1097. X
  1098. XObject Process_Event (ep, argl) XEvent *ep; Object argl; {
  1099. X    Object disp, clause, func, ret, funcs[LASTEvent], args;
  1100. X    register i;
  1101. X    Display *dpy;
  1102. X    Window win = None;
  1103. X    char *errmsg = "event occurs more than once";
  1104. X    GC_Node3; struct gcnode gcv;
  1105. X    TC_Prolog;
  1106. X
  1107. X    TC_Disable;
  1108. X    clause = args = Null;
  1109. X    GC_Link3 (argl, clause, args);
  1110. X    disp = Eval (Car (argl));
  1111. X    if (TYPE(disp) == T_Display) {
  1112. X    dpy = DISPLAY(disp)->dpy;
  1113. X    } else if (TYPE(disp) == T_Window) {
  1114. X    dpy = WINDOW(disp)->dpy;
  1115. X    win = WINDOW(disp)->win;
  1116. X    } else Wrong_Type_Combination (disp, "display or window");
  1117. X    for (i = 0; i < 32; i++)
  1118. X    funcs[i] = Null;
  1119. X    gcv.gclen = 1 + 32; gcv.gcobj = funcs; gcv.next = &gc3; GC_List = &gcv;
  1120. X    for (argl = Cdr (argl); !Nullp (argl); argl = Cdr (argl)) {
  1121. X    clause = Car (argl);
  1122. X    Check_List (clause);
  1123. X    if (Internal_Length (clause) != 2)
  1124. X        Primitive_Error ("badly formed event clause");
  1125. X    func = Eval (Car (Cdr (clause)));
  1126. X    Check_Procedure (func);
  1127. X    clause = Car (clause);
  1128. X    if (EQ(clause, Sym_Else)) {
  1129. X        for (i = 0; i < 32; i++)
  1130. X        if (Nullp (funcs[i])) funcs[i] = func;
  1131. X    } else {
  1132. X        if (TYPE(clause) == T_Pair) {
  1133. X        for (; !Nullp (clause); clause = Cdr (clause)) {
  1134. X            i = Encode_Event (Car (clause));
  1135. X            if (!Nullp (funcs[i]))
  1136. X            Primitive_Error (errmsg);
  1137. X            funcs[i] = func;
  1138. X        }
  1139. X        } else {
  1140. X        i = Encode_Event (clause);
  1141. X        if (!Nullp (funcs[i]))
  1142. X            Primitive_Error (errmsg);
  1143. X        funcs[i] = func;
  1144. X        }
  1145. X    }
  1146. X    }
  1147. X    ret = False;
  1148. X    if ((i = ep->type) < LASTEvent && !Nullp (funcs[i])) {
  1149. X    args = Get_Event_Args (ep);
  1150. X    ret = Funcall (funcs[i], args, 0);
  1151. X    /*
  1152. X     * The argument vector is cleared to destroy all references
  1153. X     * to the arguments (so that a GC can throw away the objects):
  1154. X     */
  1155. X    Destroy_Event_Args (args);
  1156. X    }
  1157. X    GC_Unlink;
  1158. X    TC_Enable;
  1159. X    return ret;
  1160. X}
  1161. X
  1162. Xstatic Object Get_Time_Arg (t) Time t; {
  1163. X    return t == CurrentTime ? Sym_Now : Make_Unsigned ((unsigned)t);
  1164. X}
  1165. X
  1166. XObject Get_Event_Args (ep) XEvent *ep; {
  1167. X    Object tmpargs[MAX_ARGS];
  1168. X    register e, i;
  1169. X    register Object *a, *vp;
  1170. X    struct gcnode gcv;
  1171. X    Object dummy;
  1172. X    GC_Node;
  1173. X
  1174. X    e = ep->type;
  1175. X    dummy = Null;
  1176. X    a = tmpargs;
  1177. X    for (i = 0; i < MAX_ARGS; i++)
  1178. X    a[i] = Null;
  1179. X    GC_Link (dummy);
  1180. X    gcv.gclen = 1 + MAX_ARGS; gcv.gcobj = a; gcv.next = &gc1; GC_List = &gcv;
  1181. X    switch (e) {
  1182. X    case KeyPress: case KeyRelease:
  1183. X    case ButtonPress: case ButtonRelease:
  1184. X    case MotionNotify:
  1185. X    case EnterNotify: case LeaveNotify: {
  1186. X    register XKeyEvent *p = (XKeyEvent *)ep;
  1187. X    a[1] = Make_Window (0, p->display, p->window);
  1188. X    a[2] = Make_Window (0, p->display, p->root);
  1189. X    a[3] = Make_Window (0, p->display, p->subwindow);
  1190. X    a[4] = Get_Time_Arg (p->time);
  1191. X    a[5] = Make_Fixnum (p->x);
  1192. X    a[6] = Make_Fixnum (p->y);
  1193. X    a[7] = Make_Fixnum (p->x_root);
  1194. X    a[8] = Make_Fixnum (p->y_root);
  1195. X    if (e == KeyPress || e == KeyRelease) {
  1196. X        a[9] = Bits_To_Symbols ((unsigned long)p->state, 1, State_Syms);
  1197. X        a[10] = Make_Fixnum (p->keycode);
  1198. X        a[11] = p->same_screen ? True : False;
  1199. X    } else if (e == ButtonPress || e == ButtonRelease) {
  1200. X        register XButtonEvent *q = (XButtonEvent *)ep;
  1201. X        a[9] = Bits_To_Symbols ((unsigned long)q->state, 1, State_Syms);
  1202. X        a[10] = Bits_To_Symbols ((unsigned long)q->button, 0, Button_Syms);
  1203. X        a[11] = q->same_screen ? True : False;
  1204. X    } else if (e == MotionNotify) {
  1205. X        register XMotionEvent *q = (XMotionEvent *)ep;
  1206. X        a[9] = Bits_To_Symbols ((unsigned long)q->state, 1, State_Syms);
  1207. X        a[10] = q->is_hint ? True : False;
  1208. X        a[11] = q->same_screen ? True : False;
  1209. X    } else {
  1210. X        register XCrossingEvent *q = (XCrossingEvent *)ep;
  1211. X        a[9] = Bits_To_Symbols ((unsigned long)q->mode, 0, Cross_Mode_Syms);
  1212. X        a[10] = Bits_To_Symbols ((unsigned long)q->detail, 0,
  1213. X        Cross_Detail_Syms);
  1214. X        a[11] = q->same_screen ? True : False;
  1215. X        a[12] = q->focus ? True : False;
  1216. X        a[13] = Bits_To_Symbols ((unsigned long)q->state, 1, Button_Syms);
  1217. X    }
  1218. X    } break;
  1219. X    case FocusIn: case FocusOut: {
  1220. X    register XFocusChangeEvent *p = (XFocusChangeEvent *)ep;
  1221. X    a[1] = Make_Window (0, p->display, p->window);
  1222. X    a[2] = Bits_To_Symbols ((unsigned long)p->mode, 0, Cross_Mode_Syms);
  1223. X    a[3] = Bits_To_Symbols ((unsigned long)p->detail, 0, Focus_Detail_Syms);
  1224. X    } break;
  1225. X    case KeymapNotify: {
  1226. X    register XKeymapEvent *p = (XKeymapEvent *)ep;
  1227. X    a[1] = Make_Window (0, p->display, p->window);
  1228. X    a[2] = Make_String (p->key_vector, 32);
  1229. X    } break;
  1230. X    case Expose: {
  1231. X    register XExposeEvent *p = (XExposeEvent *)ep;
  1232. X    a[1] = Make_Window (0, p->display, p->window);
  1233. X    a[2] = Make_Fixnum (p->x);
  1234. X    a[3] = Make_Fixnum (p->y);
  1235. X    a[4] = Make_Fixnum (p->width);
  1236. X    a[5] = Make_Fixnum (p->height);
  1237. X    a[6] = Make_Fixnum (p->count);
  1238. X    } break;
  1239. X    case GraphicsExpose: {
  1240. X    register XGraphicsExposeEvent *p = (XGraphicsExposeEvent *)ep;
  1241. X    a[1] = Make_Window (0, p->display, p->drawable);
  1242. X    a[2] = Make_Fixnum (p->x);
  1243. X    a[3] = Make_Fixnum (p->y);
  1244. X    a[4] = Make_Fixnum (p->width);
  1245. X    a[5] = Make_Fixnum (p->height);
  1246. X    a[6] = Make_Fixnum (p->count);
  1247. X    a[7] = Make_Fixnum (p->major_code);
  1248. X    a[8] = Make_Fixnum (p->minor_code);
  1249. X    } break;
  1250. X    case NoExpose: {
  1251. X    register XNoExposeEvent *p = (XNoExposeEvent *)ep;
  1252. X    a[1] = Make_Window (0, p->display, p->drawable);
  1253. X    a[2] = Make_Fixnum (p->major_code);
  1254. X    a[3] = Make_Fixnum (p->minor_code);
  1255. X    } break;
  1256. X    case VisibilityNotify: {
  1257. X    register XVisibilityEvent *p = (XVisibilityEvent *)ep;
  1258. X    a[1] = Make_Window (0, p->display, p->window);
  1259. X    a[2] = Bits_To_Symbols ((unsigned long)p->state, 0, Visibility_Syms);
  1260. X    } break;
  1261. X    case CreateNotify: {
  1262. X    register XCreateWindowEvent *p = (XCreateWindowEvent *)ep;
  1263. X    a[1] = Make_Window (0, p->display, p->parent);
  1264. X    a[2] = Make_Window (0, p->display, p->window);
  1265. X    a[3] = Make_Fixnum (p->x);
  1266. X    a[4] = Make_Fixnum (p->y);
  1267. X    a[5] = Make_Fixnum (p->width);
  1268. X    a[6] = Make_Fixnum (p->height);
  1269. X    a[7] = Make_Fixnum (p->border_width);
  1270. X    a[8] = p->override_redirect ? True : False;
  1271. X    } break;
  1272. X    case DestroyNotify: {
  1273. X    register XDestroyWindowEvent *p = (XDestroyWindowEvent *)ep;
  1274. X    a[1] = Make_Window (0, p->display, p->event);
  1275. X    a[2] = Make_Window (0, p->display, p->window);
  1276. X    } break;
  1277. X    case UnmapNotify: {
  1278. X    register XUnmapEvent *p = (XUnmapEvent *)ep;
  1279. X    a[1] = Make_Window (0, p->display, p->event);
  1280. X    a[2] = Make_Window (0, p->display, p->window);
  1281. X    a[3] = p->from_configure ? True : False;
  1282. X    } break;
  1283. X    case MapNotify: {
  1284. X    register XMapEvent *p = (XMapEvent *)ep;
  1285. X    a[1] = Make_Window (0, p->display, p->event);
  1286. X    a[2] = Make_Window (0, p->display, p->window);
  1287. X    a[3] = p->override_redirect ? True : False;
  1288. X    } break;
  1289. X    case MapRequest: {
  1290. X    register XMapRequestEvent *p = (XMapRequestEvent *)ep;
  1291. X    a[1] = Make_Window (0, p->display, p->parent);
  1292. X    a[2] = Make_Window (0, p->display, p->window);
  1293. X    } break;
  1294. X    case ReparentNotify: {
  1295. X    register XReparentEvent *p = (XReparentEvent *)ep;
  1296. X    a[1] = Make_Window (0, p->display, p->event);
  1297. X    a[2] = Make_Window (0, p->display, p->window);
  1298. X    a[3] = Make_Window (0, p->display, p->parent);
  1299. X    a[4] = Make_Fixnum (p->x);
  1300. X    a[5] = Make_Fixnum (p->y);
  1301. X    a[6] = p->override_redirect ? True : False;
  1302. X    } break;
  1303. X    case ConfigureNotify: {
  1304. X    register XConfigureEvent *p = (XConfigureEvent *)ep;
  1305. X    a[1] = Make_Window (0, p->display, p->event);
  1306. X    a[2] = Make_Window (0, p->display, p->window);
  1307. X    a[3] = Make_Fixnum (p->x);
  1308. X    a[4] = Make_Fixnum (p->y);
  1309. X    a[5] = Make_Fixnum (p->width);
  1310. X    a[6] = Make_Fixnum (p->height);
  1311. X    a[7] = Make_Fixnum (p->border_width);
  1312. X    a[8] = Make_Window (0, p->display, p->above);
  1313. X    a[9] = p->override_redirect ? True : False;
  1314. X    } break;
  1315. X    case ConfigureRequest: {
  1316. X    register XConfigureRequestEvent *p = (XConfigureRequestEvent *)ep;
  1317. X    a[1] = Make_Window (0, p->display, p->parent);
  1318. X    a[2] = Make_Window (0, p->display, p->window);
  1319. X    a[3] = Make_Fixnum (p->x);
  1320. X    a[4] = Make_Fixnum (p->y);
  1321. X    a[5] = Make_Fixnum (p->width);
  1322. X    a[6] = Make_Fixnum (p->height);
  1323. X    a[7] = Make_Fixnum (p->border_width);
  1324. X    a[8] = Make_Window (0, p->display, p->above);
  1325. X    a[9] = Bits_To_Symbols ((unsigned long)p->detail, 0, Stack_Mode_Syms);
  1326. X    a[10] = Make_Unsigned ((unsigned)p->value_mask);
  1327. X    } break;
  1328. X    case GravityNotify: {
  1329. X    register XGravityEvent *p = (XGravityEvent *)ep;
  1330. X    a[1] = Make_Window (0, p->display, p->event);
  1331. X    a[2] = Make_Window (0, p->display, p->window);
  1332. X    a[3] = Make_Fixnum (p->x);
  1333. X    a[4] = Make_Fixnum (p->y);
  1334. X    } break;
  1335. X    case ResizeRequest: {
  1336. X    register XResizeRequestEvent *p = (XResizeRequestEvent *)ep;
  1337. X    a[1] = Make_Window (0, p->display, p->window);
  1338. X    a[2] = Make_Fixnum (p->width);
  1339. X    a[3] = Make_Fixnum (p->height);
  1340. X    } break;
  1341. X    case CirculateNotify: {
  1342. X    register XCirculateEvent *p = (XCirculateEvent *)ep;
  1343. X    a[1] = Make_Window (0, p->display, p->event);
  1344. X    a[2] = Make_Window (0, p->display, p->window);
  1345. X    a[3] = Bits_To_Symbols ((unsigned long)p->place, 0, Place_Syms);
  1346. X    } break;
  1347. X    case CirculateRequest: {
  1348. X    register XCirculateRequestEvent *p = (XCirculateRequestEvent *)ep;
  1349. X    a[1] = Make_Window (0, p->display, p->parent);
  1350. X    a[2] = Make_Window (0, p->display, p->window);
  1351. X    a[3] = Bits_To_Symbols ((unsigned long)p->place, 0, Place_Syms);
  1352. X    } break;
  1353. X    case PropertyNotify: {
  1354. X    register XPropertyEvent *p = (XPropertyEvent *)ep;
  1355. X    a[1] = Make_Window (0, p->display, p->window);
  1356. X    a[2] = Make_Atom (p->atom);
  1357. X    a[3] = Get_Time_Arg (p->time);
  1358. X    a[4] = Bits_To_Symbols ((unsigned long)p->state, 0, Prop_Syms);
  1359. X    } break;
  1360. X    case SelectionClear: {
  1361. X    register XSelectionClearEvent *p = (XSelectionClearEvent *)ep;
  1362. X    a[1] = Make_Window (0, p->display, p->window);
  1363. X    a[2] = Make_Atom (p->selection);
  1364. X    a[3] = Get_Time_Arg (p->time);
  1365. X    } break;
  1366. X    case SelectionRequest: {
  1367. X    register XSelectionRequestEvent *p = (XSelectionRequestEvent *)ep;
  1368. X    a[1] = Make_Window (0, p->display, p->owner);
  1369. X    a[2] = Make_Window (0, p->display, p->requestor);
  1370. X    a[3] = Make_Atom (p->selection);
  1371. X    a[4] = Make_Atom (p->target);
  1372. X    a[5] = Make_Atom (p->property);
  1373. X    a[6] = Get_Time_Arg (p->time);
  1374. X    } break;
  1375. X    case SelectionNotify: {
  1376. X    register XSelectionEvent *p = (XSelectionEvent *)ep;
  1377. X    a[1] = Make_Window (0, p->display, p->requestor);
  1378. X    a[2] = Make_Atom (p->selection);
  1379. X    a[3] = Make_Atom (p->target);
  1380. X    a[4] = Make_Atom (p->property);
  1381. X    a[5] = Get_Time_Arg (p->time);
  1382. X    } break;
  1383. X    case ColormapNotify: {
  1384. X    register XColormapEvent *p = (XColormapEvent *)ep;
  1385. X    a[1] = Make_Window (0, p->display, p->window);
  1386. X    a[2] = Make_Colormap (0, p->display, p->colormap);
  1387. X    a[3] = p->new ? True : False;
  1388. X    a[4] = p->state == ColormapInstalled ? True : False;
  1389. X    } break;
  1390. X    case ClientMessage: {
  1391. X    } break;
  1392. X    case MappingNotify: {
  1393. X    register XMappingEvent *p = (XMappingEvent *)ep;
  1394. X    a[1] = Make_Window (0, p->display, p->window);
  1395. X    a[2] = Bits_To_Symbols ((unsigned long)p->request, 0, Mapping_Syms);
  1396. X    a[3] = Make_Fixnum (p->first_keycode);
  1397. X    a[4] = Make_Fixnum (p->count);
  1398. X    } break;
  1399. X    }
  1400. X    a[0] = Intern (Event_Table[e].name);
  1401. X    for (vp = VECTOR(Argv)->data, i = 0; i < Event_Table[e].argc; i++) {
  1402. X    if (i) vp++;
  1403. X    Car (*vp) = a[i];
  1404. X    Cdr (*vp) = vp[1];
  1405. X    }
  1406. X    Cdr (*vp) = Null;
  1407. X    GC_Unlink;
  1408. X    return Argl;
  1409. X}
  1410. X
  1411. XDestroy_Event_Args (args) Object args; {
  1412. X    Object t;
  1413. X
  1414. X    for (t = args; !Nullp (t); t = Cdr (t))
  1415. X    Car (t) = Null;
  1416. X}
  1417. X
  1418. XEncode_Event (e) Object e; {
  1419. X    Object s;
  1420. X    register char *p;
  1421. X    register struct event_desc *ep;
  1422. X    register n;
  1423. X
  1424. X    Check_Type (e, T_Symbol);
  1425. X    s = SYMBOL(e)->name;
  1426. X    p = STRING(s)->data;
  1427. X    n = STRING(s)->size;
  1428. X    for (ep = Event_Table; ep->name; ep++)
  1429. X    if (n && strncmp (ep->name, p, n) == 0) break;
  1430. X    if (ep->name == 0)
  1431. X    Primitive_Error ("no such event: ~s", e);
  1432. X    return ep-Event_Table;
  1433. X}
  1434. X
  1435. Xinit_xlib_event () {
  1436. X    Object t;
  1437. X    register i;
  1438. X
  1439. X    Argl = P_Make_List (Make_Fixnum (MAX_ARGS), Null);
  1440. X    Global_GC_Link (Argl);
  1441. X    Argv = Make_Vector (MAX_ARGS, Null);
  1442. X    Global_GC_Link (Argv);
  1443. X    for (i = 0, t = Argl; i < MAX_ARGS; i++, t = Cdr (t))
  1444. X    VECTOR(Argv)->data[i] = t;
  1445. X    Define_Symbol (&Sym_Else, "else");
  1446. X    Define_Primitive (P_Handle_Events,   "handle-events",     2, MANY, NOEVAL);
  1447. X}
  1448. END_OF_lib/xlib/event.c
  1449. if test 15403 -ne `wc -c <lib/xlib/event.c`; then
  1450.     echo shar: \"lib/xlib/event.c\" unpacked with wrong size!
  1451. fi
  1452. # end of overwriting check
  1453. fi
  1454. if test -f lib/xlib/gcontext.c -a "${1}" != "-c" ; then 
  1455.   echo shar: Will not over-write existing file \"lib/xlib/gcontext.c\"
  1456. else
  1457. echo shar: Extracting \"lib/xlib/gcontext.c\" \(2623 characters\)
  1458. sed "s/^X//" >lib/xlib/gcontext.c <<'END_OF_lib/xlib/gcontext.c'
  1459. X#include "xlib.h"
  1460. X
  1461. Xstatic Object Sym_Gc;
  1462. X
  1463. XGeneric_Predicate (Gc);
  1464. X
  1465. XGeneric_Equal_Dpy (Gc, GCONTEXT, gc);
  1466. X
  1467. XGeneric_Print (Gc, "#[gcontext %u]", GCONTEXT(x)->gc->gid);
  1468. X
  1469. XGeneric_Get_Display (Gc, GCONTEXT);
  1470. X
  1471. XObject Make_Gc (finalize, dpy, g) Display *dpy; GC g; {
  1472. X    register char *p;
  1473. X    Object gc;
  1474. X
  1475. X    gc = Find_Object (T_Gc, (GENERIC)dpy, Match_X_Obj, g);
  1476. X    if (Nullp (gc)) {
  1477. X    p = Get_Bytes (sizeof (struct S_Gc));
  1478. X    SET (gc, T_Gc, (struct S_Gc *)p);
  1479. X    GCONTEXT(gc)->tag = Null;
  1480. X    GCONTEXT(gc)->gc = g;
  1481. X    GCONTEXT(gc)->dpy = dpy;
  1482. X    GCONTEXT(gc)->free = 0;
  1483. X    Register_Object (gc, (GENERIC)gc, finalize ? P_Free_Gc :
  1484. X        (PFO)0, 0);
  1485. X    }
  1486. X    return gc;
  1487. X}
  1488. X
  1489. Xstatic Object P_Create_Gc (w, g) Object w, g; {
  1490. X    unsigned long mask;
  1491. X
  1492. X    Check_Type (w, T_Window);
  1493. X    mask = Vector_To_Record (g, GC_Size, Sym_Gc, GC_Rec);
  1494. X    return Make_Gc (1, WINDOW(w)->dpy,
  1495. X    XCreateGC (WINDOW(w)->dpy, WINDOW(w)->win, mask, &GCV));
  1496. X}
  1497. X
  1498. Xstatic Object P_Copy_Gc (gc, w) Object gc, w; {
  1499. X    GC dst;
  1500. X
  1501. X    Check_Type (gc, T_Gc);
  1502. X    Check_Type (w, T_Window);
  1503. X    dst = XCreateGC (WINDOW(w)->dpy, WINDOW(w)->win, 0L, &GCV);
  1504. X    XCopyGC (WINDOW(w)->dpy, GCONTEXT(gc)->gc, ~0L, dst);
  1505. X    return Make_Gc (1, WINDOW(w)->dpy, dst);
  1506. X}
  1507. X
  1508. Xstatic Object P_Change_Gc (gc, g) Object gc, g; {
  1509. X    unsigned long mask;
  1510. X
  1511. X    Check_Type (gc, T_Gc);
  1512. X    mask = Vector_To_Record (g, GC_Size, Sym_Gc, GC_Rec);
  1513. X    XChangeGC (GCONTEXT(gc)->dpy, GCONTEXT(gc)->gc, mask, &GCV);
  1514. X    return Void;
  1515. X}
  1516. X
  1517. XObject P_Free_Gc (g) Object g; {
  1518. X    Check_Type (g, T_Gc);
  1519. X    if (!GCONTEXT(g)->free)
  1520. X    XFreeGC (GCONTEXT(g)->dpy, GCONTEXT(g)->gc);
  1521. X    Deregister_Object (g);
  1522. X    GCONTEXT(g)->free = 1;
  1523. X    return Void;
  1524. X}
  1525. X
  1526. Xstatic Object P_Query_Best_Size (d, w, h, shape) Object d, w, h, shape; {
  1527. X    unsigned int rw, rh;
  1528. X
  1529. X    Check_Type (d, T_Display);
  1530. X    if (!XQueryBestSize (DISPLAY(d)->dpy, Symbols_To_Bits (shape, 0,
  1531. X        Shape_Syms), DefaultRootWindow (DISPLAY(d)->dpy),
  1532. X        Get_Integer (w), Get_Integer (h), &rw, &rh))
  1533. X    Primitive_Error ("cannot query best shape");
  1534. X    return Cons (Make_Fixnum (rw), Make_Fixnum (rh));
  1535. X}
  1536. X
  1537. Xinit_xlib_gcontext () {
  1538. X    Define_Symbol (&Sym_Gc, "gcontext");
  1539. X    Generic_Define (Gc, "gcontext", "gcontext?");
  1540. X    Define_Primitive (P_Gc_Display,      "gcontext-display", 1, 1, EVAL);
  1541. X    Define_Primitive (P_Create_Gc,       "create-gcontext",  2, 2, EVAL);
  1542. X    Define_Primitive (P_Copy_Gc,         "copy-gcontext",    2, 2, EVAL);
  1543. X    Define_Primitive (P_Change_Gc,       "change-gcontext",  2, 2, EVAL);
  1544. X    Define_Primitive (P_Free_Gc,         "free-gcontext",    1, 1, EVAL);
  1545. X    Define_Primitive (P_Query_Best_Size, "query-best-size",  4, 4, EVAL);
  1546. X}
  1547. END_OF_lib/xlib/gcontext.c
  1548. if test 2623 -ne `wc -c <lib/xlib/gcontext.c`; then
  1549.     echo shar: \"lib/xlib/gcontext.c\" unpacked with wrong size!
  1550. fi
  1551. # end of overwriting check
  1552. fi
  1553. if test -f lib/xlib/graphics.c -a "${1}" != "-c" ; then 
  1554.   echo shar: Will not over-write existing file \"lib/xlib/graphics.c\"
  1555. else
  1556. echo shar: Extracting \"lib/xlib/graphics.c\" \(8849 characters\)
  1557. sed "s/^X//" >lib/xlib/graphics.c <<'END_OF_lib/xlib/graphics.c'
  1558. X#include "xlib.h"
  1559. X
  1560. Xextern XDrawPoints(), XDrawLines(), XDrawRectangle(), XFillRectangle();
  1561. Xextern XDrawRectangles(), XFillRectangles(), XDrawArc(), XFillArc();
  1562. Xextern XDrawArcs(), XFillArcs(), XFillPolygon();
  1563. X
  1564. Xstatic Object P_Clear_Area (win, x, y, w, h, e) Object win, x, y, w, h, e; {
  1565. X    Check_Type (win, T_Window);
  1566. X    Check_Type (e, T_Boolean);
  1567. X    XClearArea (WINDOW(win)->dpy, WINDOW(win)->win, Get_Integer (x),
  1568. X    Get_Integer (y), Get_Integer (w), Get_Integer (h), EQ(e, True));
  1569. X    return Void;
  1570. X}
  1571. X
  1572. Xstatic Object P_Copy_Area (src, gc, sx, sy, w, h, dst, dx, dy) Object src, gc,
  1573. X    sx, sy, w, h, dst, dx, dy; {
  1574. X    Display *dpy;
  1575. X    Drawable ddst = Get_Drawable (dst, &dpy), dsrc = Get_Drawable (src, &dpy);
  1576. X
  1577. X    Check_Type (gc, T_Gc);
  1578. X    XCopyArea (dpy, dsrc, ddst, GCONTEXT(gc)->gc, Get_Integer (sx),
  1579. X    Get_Integer (sy), Get_Integer (w), Get_Integer (h),
  1580. X    Get_Integer (dx), Get_Integer (dy));
  1581. X    return Void;
  1582. X}
  1583. X
  1584. Xstatic Object P_Copy_Plane (src, gc, plane, sx, sy, w, h, dst, dx, dy)
  1585. X    Object src, gc, plane, sx, sy, w, h, dst, dx, dy; {
  1586. X    Display *dpy;
  1587. X    Drawable ddst = Get_Drawable (dst, &dpy), dsrc = Get_Drawable (src, &dpy);
  1588. X    register unsigned long p;
  1589. X
  1590. X    Check_Type (gc, T_Gc);
  1591. X    p = (unsigned long)Get_Integer (plane);
  1592. X    if (p & (p-1))
  1593. X    Primitive_Error ("invalid plane: ~s", plane);
  1594. X    XCopyPlane (dpy, dsrc, ddst, GCONTEXT(gc)->gc, Get_Integer (sx),
  1595. X    Get_Integer (sy), Get_Integer (w), Get_Integer (h),
  1596. X    Get_Integer (dx), Get_Integer (dy), p);
  1597. X    return Void;
  1598. X}
  1599. X
  1600. Xstatic Object P_Draw_Point (d, gc, x, y) Object d, gc, x, y; {
  1601. X    Display *dpy;
  1602. X    Drawable dr = Get_Drawable (d, &dpy);
  1603. X
  1604. X    Check_Type (gc, T_Gc);
  1605. X    XDrawPoint (dpy, dr, GCONTEXT(gc)->gc, Get_Integer (x), Get_Integer (y));
  1606. X    return Void;
  1607. X}
  1608. X
  1609. Xstatic Object Internal_Draw_Points (d, gc, v, relative, func, shape)
  1610. X    Object d, gc, v, relative, shape; int (*func)(); {
  1611. X    Display *dpy;
  1612. X    Drawable dr = Get_Drawable (d, &dpy);
  1613. X    register XPoint *p;
  1614. X    register i, n;
  1615. X    int rel, sh;
  1616. X
  1617. X    Check_Type (gc, T_Gc);
  1618. X    Check_Type (relative, T_Boolean);
  1619. X    rel = EQ(relative, True) ? CoordModePrevious : CoordModeOrigin;
  1620. X    if (func == XFillPolygon)
  1621. X    sh = Symbols_To_Bits (shape, 0, Polyshape_Syms);
  1622. X    n = VECTOR(v)->size;
  1623. X    p = (XPoint *)alloca (n * sizeof (XPoint));
  1624. X    for (i = 0; i < n; i++) {
  1625. X    Object point = VECTOR(v)->data[i];
  1626. X    Check_Type (point, T_Pair);
  1627. X    p[i].x = Get_Integer (Car (point));
  1628. X    p[i].y = Get_Integer (Cdr (point));
  1629. X    }
  1630. X    if (func == XFillPolygon)
  1631. X    XFillPolygon (dpy, dr, GCONTEXT(gc)->gc, p, n, sh, rel);
  1632. X    else
  1633. X    (*func)(dpy, dr, GCONTEXT(gc)->gc, p, n, rel);
  1634. X    return Void;
  1635. X}
  1636. X
  1637. Xstatic Object P_Draw_Points (d, gc, v, relative) Object d, gc, v, relative; {
  1638. X    return Internal_Draw_Points (d, gc, v, relative, XDrawPoints, Null);
  1639. X}
  1640. X
  1641. Xstatic Object P_Draw_Line (d, gc, x1, y1, x2, y2)
  1642. X    Object d, gc, x1, y1, x2, y2; {
  1643. X    Display *dpy;
  1644. X    Drawable dr = Get_Drawable (d, &dpy);
  1645. X
  1646. X    Check_Type (gc, T_Gc);
  1647. X    XDrawLine (dpy, dr, GCONTEXT(gc)->gc, Get_Integer (x1), Get_Integer (y1),
  1648. X    Get_Integer (x2), Get_Integer (y2));
  1649. X    return Void;
  1650. X}
  1651. X
  1652. Xstatic Object P_Draw_Lines (d, gc, v, relative) Object d, gc, v, relative; {
  1653. X    return Internal_Draw_Points (d, gc, v, relative, XDrawLines, Null);
  1654. X}
  1655. X
  1656. Xstatic Object P_Draw_Segments (d, gc, v) Object d, gc, v; {
  1657. X    Display *dpy;
  1658. X    Drawable dr = Get_Drawable (d, &dpy);
  1659. X    register XSegment *p;
  1660. X    register i, n;
  1661. X
  1662. X    Check_Type (gc, T_Gc);
  1663. X    n = VECTOR(v)->size;
  1664. X    p = (XSegment *)alloca (n * sizeof (XSegment));
  1665. X    for (i = 0; i < n; i++) {
  1666. X    Object seg = VECTOR(v)->data[i];
  1667. X    Check_Type (seg, T_Pair);
  1668. X    if (Internal_Length (seg) != 4)
  1669. X        Primitive_Error ("invalid segment: ~s", seg);
  1670. X    p[i].x1 = Get_Integer (Car (seg)); seg = Cdr (seg);
  1671. X    p[i].y1 = Get_Integer (Car (seg)); seg = Cdr (seg);
  1672. X    p[i].x2 = Get_Integer (Car (seg)); seg = Cdr (seg);
  1673. X    p[i].y2 = Get_Integer (Car (seg));
  1674. X    }
  1675. X    XDrawSegments (dpy, dr, GCONTEXT(gc)->gc, p, n);
  1676. X    return Void;
  1677. X}
  1678. X
  1679. Xstatic Object Internal_Draw_Rectangle (d, gc, x, y, w, h, func)
  1680. X    Object d, gc, x, y, w, h; int (*func)(); {
  1681. X    Display *dpy;
  1682. X    Drawable dr = Get_Drawable (d, &dpy);
  1683. X
  1684. X    Check_Type (gc, T_Gc);
  1685. X    (*func)(dpy, dr, GCONTEXT(gc)->gc, Get_Integer (x),
  1686. X    Get_Integer (y), Get_Integer (w), Get_Integer (h));
  1687. X    return Void;
  1688. X}
  1689. X
  1690. Xstatic Object P_Draw_Rectangle (d, gc, x, y, w, h) Object d, gc, x, y, w, h; {
  1691. X    return Internal_Draw_Rectangle (d, gc, x, y, w, h, XDrawRectangle);
  1692. X}
  1693. X
  1694. Xstatic Object P_Fill_Rectangle (d, gc, x, y, w, h) Object d, gc, x, y, w, h; {
  1695. X    return Internal_Draw_Rectangle (d, gc, x, y, w, h, XFillRectangle);
  1696. X}
  1697. X
  1698. Xstatic Object Internal_Draw_Rectangles (d, gc, v, func)
  1699. X    Object d, gc, v; int (*func)(); {
  1700. X    Display *dpy;
  1701. X    Drawable dr = Get_Drawable (d, &dpy);
  1702. X    register XRectangle *p;
  1703. X    register i, n;
  1704. X
  1705. X    Check_Type (gc, T_Gc);
  1706. X    n = VECTOR(v)->size;
  1707. X    p = (XRectangle *)alloca (n * sizeof (XRectangle));
  1708. X    for (i = 0; i < n; i++) {
  1709. X    Object rect = VECTOR(v)->data[i];
  1710. X    Check_Type (rect, T_Pair);
  1711. X    if (Internal_Length (rect) != 4)
  1712. X        Primitive_Error ("invalid rectangle: ~s", rect);
  1713. X    p[i].x = Get_Integer (Car (rect)); rect = Cdr (rect);
  1714. X    p[i].y = Get_Integer (Car (rect)); rect = Cdr (rect);
  1715. X    p[i].width = Get_Integer (Car (rect)); rect = Cdr (rect);
  1716. X    p[i].height = Get_Integer (Car (rect));
  1717. X    }
  1718. X    (*func)(dpy, dr, GCONTEXT(gc)->gc, p, n);
  1719. X    return Void;
  1720. X}
  1721. X
  1722. Xstatic Object P_Draw_Rectangles (d, gc, v) Object d, gc, v; {
  1723. X    return Internal_Draw_Rectangles (d, gc, v, XDrawRectangles);
  1724. X}
  1725. X
  1726. Xstatic Object P_Fill_Rectangles (d, gc, v) Object d, gc, v; {
  1727. X    return Internal_Draw_Rectangles (d, gc, v, XFillRectangles);
  1728. X}
  1729. X
  1730. Xstatic Object Internal_Draw_Arc (d, gc, x, y, w, h, a1, a2, func)
  1731. X    Object d, gc, x, y, w, h, a1, a2; int (*func)(); {
  1732. X    Display *dpy;
  1733. X    Drawable dr = Get_Drawable (d, &dpy);
  1734. X
  1735. X    Check_Type (gc, T_Gc);
  1736. X    (*func)(dpy, dr, GCONTEXT(gc)->gc, Get_Integer (x), Get_Integer (y),
  1737. X    Get_Integer (w), Get_Integer (h), Get_Integer (a1), Get_Integer (a2));
  1738. X    return Void;
  1739. X}
  1740. X
  1741. Xstatic Object P_Draw_Arc (d, gc, x, y, w, h, a1, a2)
  1742. X    Object d, gc, x, y, w, h, a1, a2; {
  1743. X    return Internal_Draw_Arc (d, gc, x, y, w, h, a1, a2, XDrawArc);
  1744. X}
  1745. X
  1746. Xstatic Object P_Fill_Arc (d, gc, x, y, w, h, a1, a2)
  1747. X    Object d, gc, x, y, w, h, a1, a2; {
  1748. X    return Internal_Draw_Arc (d, gc, x, y, w, h, a1, a2, XFillArc);
  1749. X}
  1750. X
  1751. Xstatic Object Internal_Draw_Arcs (d, gc, v, func) Object d, gc, v;
  1752. X    int (*func)(); {
  1753. X    Display *dpy;
  1754. X    Drawable dr = Get_Drawable (d, &dpy);
  1755. X    register XArc *p;
  1756. X    register i, n;
  1757. X
  1758. X    Check_Type (gc, T_Gc);
  1759. X    n = VECTOR(v)->size;
  1760. X    p = (XArc *)alloca (n * sizeof (XArc));
  1761. X    for (i = 0; i < n; i++) {
  1762. X    Object arc = VECTOR(v)->data[i];
  1763. X    Check_Type (arc, T_Pair);
  1764. X    if (Internal_Length (arc) != 6)
  1765. X        Primitive_Error ("invalid arc: ~s", arc);
  1766. X    p[i].x = Get_Integer (Car (arc)); arc = Cdr (arc);
  1767. X    p[i].y = Get_Integer (Car (arc)); arc = Cdr (arc);
  1768. X    p[i].width = Get_Integer (Car (arc)); arc = Cdr (arc);
  1769. X    p[i].height = Get_Integer (Car (arc)); arc = Cdr (arc);
  1770. X    p[i].angle1 = Get_Integer (Car (arc)); arc = Cdr (arc);
  1771. X    p[i].angle2 = Get_Integer (Car (arc));
  1772. X    }
  1773. X    (*func)(dpy, dr, GCONTEXT(gc)->gc, p, n);
  1774. X    return Void;
  1775. X}
  1776. X
  1777. Xstatic Object P_Draw_Arcs (d, gc, v) Object d, gc, v; {
  1778. X    return Internal_Draw_Arcs (d, gc, v, XDrawArcs);
  1779. X}
  1780. X
  1781. Xstatic Object P_Fill_Arcs (d, gc, v) Object d, gc, v; {
  1782. X    return Internal_Draw_Arcs (d, gc, v, XFillArcs);
  1783. X}
  1784. X
  1785. Xstatic Object P_Fill_Polygon (d, gc, v, relative, shape)
  1786. X    Object d, gc, v, relative, shape; {
  1787. X    return Internal_Draw_Points (d, gc, v, relative, XFillPolygon, shape);
  1788. X}
  1789. X
  1790. Xinit_xlib_graphics () {
  1791. X    Define_Primitive (P_Clear_Area,        "clear-area",       6, 6, EVAL);
  1792. X    Define_Primitive (P_Copy_Area,         "copy-area",        9, 9, EVAL);
  1793. X    Define_Primitive (P_Copy_Plane,        "copy-plane",      10,10, EVAL);
  1794. X    Define_Primitive (P_Draw_Point,        "draw-point",       4, 4, EVAL);
  1795. X    Define_Primitive (P_Draw_Points,       "draw-points",      4, 4, EVAL);
  1796. X    Define_Primitive (P_Draw_Line,         "draw-line",        6, 6, EVAL);
  1797. X    Define_Primitive (P_Draw_Lines,        "draw-lines",       4, 4, EVAL);
  1798. X    Define_Primitive (P_Draw_Segments,     "draw-segments",    3, 3, EVAL);
  1799. X    Define_Primitive (P_Draw_Rectangle,    "draw-rectangle",   6, 6, EVAL);
  1800. X    Define_Primitive (P_Fill_Rectangle,    "fill-rectangle",   6, 6, EVAL);
  1801. X    Define_Primitive (P_Draw_Rectangles,   "draw-rectangles",  3, 3, EVAL);
  1802. X    Define_Primitive (P_Fill_Rectangles,   "fill-rectangles",  3, 3, EVAL);
  1803. X    Define_Primitive (P_Draw_Arc,          "draw-arc",         8, 8, EVAL);
  1804. X    Define_Primitive (P_Fill_Arc,          "fill-arc",         8, 8, EVAL);
  1805. X    Define_Primitive (P_Draw_Arcs,         "draw-arcs",        3, 3, EVAL);
  1806. X    Define_Primitive (P_Fill_Arcs,         "fill-arcs",        3, 3, EVAL);
  1807. X    Define_Primitive (P_Fill_Polygon,      "fill-polygon",     5, 5, EVAL);
  1808. X}
  1809. END_OF_lib/xlib/graphics.c
  1810. if test 8849 -ne `wc -c <lib/xlib/graphics.c`; then
  1811.     echo shar: \"lib/xlib/graphics.c\" unpacked with wrong size!
  1812. fi
  1813. # end of overwriting check
  1814. fi
  1815. if test ! -d lib/xaw ; then
  1816.     echo shar: Creating directory \"lib/xaw\"
  1817.     mkdir lib/xaw
  1818. fi
  1819. if test -f lib/xaw/form.d -a "${1}" != "-c" ; then 
  1820.   echo shar: Will not over-write existing file \"lib/xaw/form.d\"
  1821. else
  1822. echo shar: Extracting \"lib/xaw/form.d\" \(100 characters\)
  1823. sed "s/^X//" >lib/xaw/form.d <<'END_OF_lib/xaw/form.d'
  1824. X;;; -*-Scheme-*-
  1825. X
  1826. X(define-widget-type 'form "Form.h")
  1827. X
  1828. X(define-widget-class 'form 'formWidgetClass)
  1829. END_OF_lib/xaw/form.d
  1830. if test 100 -ne `wc -c <lib/xaw/form.d`; then
  1831.     echo shar: \"lib/xaw/form.d\" unpacked with wrong size!
  1832. fi
  1833. # end of overwriting check
  1834. fi
  1835. if test -f lib/xaw/command.d -a "${1}" != "-c" ; then 
  1836.   echo shar: Will not over-write existing file \"lib/xaw/command.d\"
  1837. else
  1838. echo shar: Extracting \"lib/xaw/command.d\" \(153 characters\)
  1839. sed "s/^X//" >lib/xaw/command.d <<'END_OF_lib/xaw/command.d'
  1840. X;;; -*-Scheme-*-
  1841. X
  1842. X(define-widget-type 'command "Command.h")
  1843. X
  1844. X(define-widget-class 'command 'commandWidgetClass)
  1845. X
  1846. X(define-callback 'command 'callback #f)
  1847. END_OF_lib/xaw/command.d
  1848. if test 153 -ne `wc -c <lib/xaw/command.d`; then
  1849.     echo shar: \"lib/xaw/command.d\" unpacked with wrong size!
  1850. fi
  1851. # end of overwriting check
  1852. fi
  1853. echo shar: End of archive 10 \(of 14\).
  1854. cp /dev/null ark10isdone
  1855. MISSING=""
  1856. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ; do
  1857.     if test ! -f ark${I}isdone ; then
  1858.     MISSING="${MISSING} ${I}"
  1859.     fi
  1860. done
  1861. if test "${MISSING}" = "" ; then
  1862.     echo You have unpacked all 14 archives.
  1863.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1864. else
  1865.     echo You still need to unpack the following archives:
  1866.     echo "        " ${MISSING}
  1867. fi
  1868. ##  End of shell archive.
  1869. exit 0
  1870.