PageRenderTime 104ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/clx/new-clx/clx.f

https://github.com/ynd/clisp-branch--ynd-devel
FORTRAN Legacy | 8276 lines | 7155 code | 885 blank | 236 comment | 487 complexity | eebc37146486bb3f5d8a83c02c77d45a MD5 | raw file
Possible License(s): LGPL-2.0, GPL-2.0, BSD-3-Clause
  1. /* -*- C -*- vim:filetype=c
  2. Copyright (c) 1996-1999 by Gilbert Baumann, distributed under GPL
  3. Bruno Haible 1998-2000
  4. Sam Steingold 2001-2008
  5. ----------------------------------------------------------------------------
  6. Title: C implementation of CLX utilizing the Xlib
  7. Created: Sat Dec 2 18:04:51 1995
  8. Author: Gilbert Baumann <unk6@rz.uni-karlsruhe.de>
  9. Copying: (c) copyright 1996 by Gilbert Baumann distributed under GPL.
  10. ----------------------------------------------------------------------------
  11. Revision 1.24 1999-10-17 bruno
  12. - Use allocate_bit_vector in place of allocate_byte_vector. Remove ->data
  13. indirection.
  14. Revision 1.23 1999-10-11 gilbert
  15. - get_font_info_and_display: XGetAtomNames is a new X11R6 addition, use
  16. XGetAtomName instead.
  17. Revision 1.22 1999-06-06 bruno
  18. - get_font_info_and_display now optionally returns the Lisp font.
  19. It also fills in the font's encoding.
  20. - New function to_XChar2b, used to convert a character sequence to a font
  21. index sequence. Works for linear non-iso8859-1 fonts (unlike Motif!).
  22. Still needs work for chinese or japanese fonts.
  23. Revision 1.21 1999-05-30 bruno
  24. - Add missing begin_callback() in `xlib_io_error_handler'.
  25. - Save subr_self during some calls in xlib:change-property.
  26. - Fix some obvious typos in `font_char_info'.
  27. - Call XFree() when done with the result of XGetAtomName().
  28. - Improved error handling in `get_font_info_and_display'.
  29. Revision 1.20 1999-04-04 bruno
  30. - Modifications for UNICODE.
  31. Revision 1.19 1998-10-19 bruno
  32. - Use the macro `nonreturning_function', not `nonreturning'.
  33. Revision 1.18 1997-06-22 bruno
  34. - replace first preprocessing with CCMP2C; then only comments need to be
  35. stripped before e2d can be applied.
  36. - compilation in WIDE mode works now (use `eq', not `==' to compare objects)
  37. - fixed buggy ESLOT4 macro (make_xatom wants a `Display*', not an `object')
  38. - DYNAMIC_ARRAY has 3 arguments since 1996-07-22
  39. - allocate_byte_array is now exported from array.d
  40. - typos and spaces here and there
  41. Revision 1.18 1997/06/12 00:23:35 gilbert
  42. - nothing special
  43. Revision 1.17 1997/06/02 16:19:27 gilbert
  44. - Lots of minor tweeks here and there
  45. - First attempt to get the IMAGE implementation right
  46. - Found memory leak in font handling code
  47. - fixed bug in xpm::read-pixmap-from-file occured when shape-mask-p = t
  48. - (xlib:open-display "localhost") works now
  49. Revision 1.16 1996/10/11 14:18:03 gilbert
  50. - Some tweakings to get it smoother compiled under 07-22
  51. Revision 1.15 1996/10/11 10:15:52 gilbert
  52. - removed all GETTEXTs because it does not compile on 07-22
  53. - error hander now calls the Lisp error handler
  54. - fixed invokation of DYNAMIC_ARRAY
  55. - removed all 'reg?' decls
  56. - lots of bug fixes
  57. - changed outlook of xlib:%restore-gcontext-components.
  58. - the clip mask and the dash list are now retrievable from a gcontext
  59. So the gcontext chapter should be complete now. [sans cache-p]
  60. Revision 1.14 1996/10/09 09:03:42 gilbert
  61. - lots of bug fixes
  62. - changed outlook of xlib:%restore-gcontext-components.
  63. - the clip mask and the dash list are now retrievable from a gcontext
  64. So the gcontext chapter should be complete now. [sans cache-p]
  65. Revision 1.13 1996/10/05 01:00:50 gilbert
  66. - begin_call / end_call should be finally added everwhere..
  67. - fixed some serve bugs in XLIB:CHANGE-PROPERTY.
  68. - providing {WINDOW,PIXMAP,DRAWABLE,FONT,COLORMAP}-LOOKUP
  69. Revision 1.12 1996/10/04 03:14:53 gilbert
  70. - Introduced new macro 'STANDARD_XID_OBJECT_LOOK'.
  71. - The {WINDOW,PIXMAP,DRAWABLE,FONT,COLORMAP}-{DISPLAY,PLIST,PLIST-SETTER,ID}
  72. functions now do proper type checking.
  73. The corresponding xx-EQUAL functions are based on the XID alone.
  74. Same needs to be done for PTR objects.
  75. - The silly (and ineffient) 'general_p' function vanished.
  76. Revision 1.11 1996/10/03 03:37:12 gilbert
  77. - all invocations of "TheFpointer()->fp_pointer"
  78. are now guarded by "fp_validp".
  79. Revision 1.10 1996/10/03 02:45:00 gilbert
  80. - made the get_[su]int?? functions do type checking
  81. - Got rid of get_string and get_stringable.
  82. Revision 1.9 1996/10/02 10:39:45 gilbert
  83. - eliminated get_xatom_name due to GC vulnerability.
  84. - got rid of most get_string due to the same reason
  85. - as always some begin/end_calls added.
  86. Revision 1.8 1996/09/28 21:59:02 gilbert
  87. - Only lots of code movements to gather stuff which belongs together
  88. also to appear together for better maintainability.
  89. Revision 1.7 1996/09/28 20:52:24 gilbert
  90. - Redone the invoke stuff, because
  91. YOU HAVE TO SAVE YOUR FILE BEFORE YOU CHECK IT IN!
  92. [Emacs does not check this 8-{ Realy angry! $%^#@#%$@ ]
  93. Revision 1.6 1996/09/28 20:41:23 gilbert
  94. - added type checking to get_{xid,ptr}_object
  95. - got rid of display_of all now done with the get_foo_and_display
  96. functions, so get_font_info is now called get_font_info_and_display.
  97. - also get rid of the 'invoke' function, it was considered too
  98. unportable.
  99. Revision 1.5 1996/09/28 01:45:06 gilbert
  100. Converted all enum definitions into the DEF_ENUM macro for code size.
  101. Revision 1.4 1996/09/27 12:48:33 gilbert
  102. Cleaned up event disassembling code
  103. Revision 1.3 1996/08/02 10:51:40 gilbert
  104. Only for Bruno.
  105. Revision 1.2 1996/07/27 02:25:31 gilbert
  106. *** empty log message ***
  107. Revision 1.1 1996/07/08 15:47:43 gilbert
  108. Initial revision
  109. ^^^ That is not true! Coding this started actually in Dec 1995.
  110. (Just around a couple of days befor chrismas?)
  111. */
  112. /* --- TODO ---
  113. - fake the REPORT-ASYNCHRONOUS-ERRORS slot on displays.
  114. - Garnet seems to loose exposure events from time to time, I do not know
  115. if it is my fault or a garnet bug? This thing is hard to trace, since
  116. it seems to depend on how fast the window gets mapped, or how fast the
  117. garnet code is!
  118. - the get_XXX functions *all* should do type checking
  119. - Most uses of 'fixnum' are wrong, since the actual type is somewhat more
  120. precise known. fixnums are only correct as indexes into sequences and
  121. such!
  122. -------
  123. When passing #<XLIB:GCONTEXT #x00000160> to FONT-ASCENT it says:
  124. "Error: XLIB:FONT-ASCENT: NIL is not of type XLIB:FONT"
  125. Why is two way wrong:
  126. a. A gcontext should be ok where a font is
  127. b. Why is dumped NIL and not the gcontext?
  128. O.k. this was due to the fact that the font was actually never set.
  129. fix that!
  130. (Maybe we just pass the gcontext down to Xlib, since Xlib is supposed
  131. to do the same here.)
  132. -------
  133. When a display is closed the host name and such sould not
  134. be available any longer
  135. -------
  136. - there should be a function called closed-p, which checks wether an given
  137. xid or ptr object is closed or not. When re-incarnating CLISP all CLX
  138. objects should get closed. get_xxx functions should check on that. But
  139. there a some nasty problems:
  140. a.) when I setup the XFree... request it is not yet at the server
  141. b.) There may be additional references in the servers queque.
  142. Maybe I open a pseudo window, just for sneeking for destruction events?
  143. - XLIB:TEXT-EXTENTS and XLIB:TEXT-WIDTH needs fixing for non simple
  144. string arguments.
  145. - Garnet accidentally used :on/:off for save under values
  146. [But only sometimes]
  147. - Scan for all funcalls and save subr_self prior to call.
  148. - Is it right that we make the list of displays public?
  149. - we should rethink a bit more the font handling stuff, because several
  150. situations could arise:
  151. . A font may not have an fid, this implies, that the font could not be
  152. hashed, furthermore we should init a finializer to discard also the
  153. fontinfo when the font object becomes inaccessible.
  154. . A font may come without per-character information.
  155. (But only when it has a 0 font id, hence a pseudo font)
  156. . If we open a pseudo font, we should then enter it into the hash table.
  157. . ensure that the font-name slot has some valid value.
  158. (It is even not guaranteed to be available.)
  159. - go thru' the whole source and find all error messages and check that they
  160. are given right. [error wants its arguments backwards!]
  161. - since some make_xxx functions use value1, I should generally push the
  162. return values onto the stack before actually returning.
  163. - since somebody could now create classes on top of window, check the xid we
  164. want to read, if it is unbound emit some reasonable error message. [If it
  165. is unbound the slot-value function returns an error on its own already.]
  166. - What about the plist slot? (Should we bind it to a useful value?)
  167. - maybe we make the clos-instance representation optional? Since it eats
  168. some speed. (Fetching a slot value is not the fastest operation.)
  169. - several X11 functions, which return lists may actually pass NULL as the
  170. empty sequence?!
  171. - some of the enumerating functions (list XListDepths etc) do not set the
  172. count_return on failure, so set it yourself to 0 before you make the call,
  173. so that we do not run into difficulties.
  174. - Maybe we dont put all those symbols in the XLIB package to be able to
  175. include the MIT-CLX also. (Generally CLISP lacks some of the nice package
  176. features Symbolics Common LISP provided. There were also anonymous or
  177. invisible packages.)
  178. - errors should be reported in a much more meaningful way.
  179. - the big export list in clx.lisp seems to export some superfluous symbols.
  180. - put also ptr objects into the hashtable.
  181. Is there any way to get 'em anyhow back?
  182. - the xlib:free-xxx routines should remove that object from the hashtable.
  183. (or shouldn`t they?) What does the Xserver with free`ed objects?
  184. And also they might be still alive, if some other application uses it.
  185. [Well simply take a look at the MIT code.] [What about GC?!]
  186. - should DISPLAY be a class? What with VISUAL-INFO, COLOR an so on ...
  187. - We should really make DISPLAY-AFTER-FUNCTION to live.
  188. The is also a XAfterFunction or something like that on the C side of life.
  189. - What exactly is a drawable? a type? a class?
  190. - We should insert a lot more type checks?
  191. - Since type checks are rather expensive think about listening to SAFTY and
  192. SPEED ...
  193. */
  194. /* --- DONE ----
  195. - some functions emit errors saying #xDDD using decimal notation!
  196. - upon disconnection we simply get a broken pipe message and exit
  197. [This is not the disired way, since we want to handle such an error.]
  198. - with-gcontext !!!
  199. - rename the 'font-name' slot of font to 'name'.
  200. - take a look at the CLUE code, what it does with the :xxx option to
  201. create-xxx functions?!
  202. - DISPLAY-AFTER-FUNCTION setter is needed.
  203. - make display/window/pixmap clos-instances (see the CLUE patches for that)
  204. - put xids into the hashtable and do not build the object new on each
  205. request.
  206. - plists (partly done)
  207. - get_visual
  208. - how to proceed with visuals? In CLX a visual is just a card29 in CLX it is
  209. a pointer to a structure.
  210. - Together with the CLX implementation should go a wholine implementation.
  211. (partly there)
  212. */
  213. /* --- NOTE ---
  214. This package is not actually optimized for speed, since my intent and BTW
  215. the overall intent of CLISP is to make the whole beast small.
  216. (Actually you gain speed due to reduced paging).
  217. Also this code is at some places BFI!
  218. The general idea behind writing this bunch of code, is to provide a CLX
  219. implementation for CLISP, which is feasible of both speed and space. I
  220. actually use the libX library, because if you want to do graphics on your
  221. machine, you will already have it in memory, so it adds no extra cost. [One
  222. disadvantage is that I am forced in some places to go into the internals of
  223. the libX, since the CLX specification is more powerful at some places than
  224. the libX implementation. This add another source of in-portability of CLISP,
  225. so *please*, if you encounter compilation problems mail me,
  226. so I could adjust the code ...]
  227. CLX adds on my machines another ~700k of memory needs for CLISP, but this
  228. implementation add only 70k [*I* know that I am telling lies here, since the
  229. libX11 itself has a size of ~500k; But as long as I have no pure LISP OS but
  230. need the UNIX to boot it ...] and a great bunch of speed.
  231. Also having this implemenation should gain a big plus against GCL. (IMHO
  232. gcl is very bad code compared to CLISP! [gcl is actually akcl]) flame,flame.
  233. BTW It should be fun to write the graph.d routines on top of CLX!
  234. */
  235. /* --- FUTURE ---
  236. Xpm Support?
  237. We should also include support for the xpm library to have a nice access to
  238. .xpm files, which is hardly needed, since I do not want to duplicate this
  239. non-trivial code in Lisp. But we have to think about a Lisp representation
  240. for pixmaps. I could also imagine a `defpixmap` macro. Just another
  241. question is if we want to put the xpm routines into another package. (called
  242. `x-pixmap` or just 'xpm'). I want also to write some documentation for the
  243. then Lisp xpm routines. But since the xpm library seems to be a changing
  244. thing it is also a question, how we cope with them.
  245. Incorporation into the FFI?
  246. Since we use could convert now a WINDOW object into a libX11 Window object,
  247. it may be worth offer this also to the FFI. When I finished this work I
  248. should take a look at the FFI.
  249. */
  250. /* --- IMPLEMENTATION NOTES ---------------------------------------------------
  251. The following types are only XID`s:
  252. window, drawable, font, pixmap, cursor, colormap, GContext, keysym
  253. No XID, but data-structures:
  254. color, display, screen, GC
  255. First I define some data types by providing get_xxx, make_xxx and xxx_p
  256. functions. Note that this set is not complete, since not all functions are
  257. actually needed. The consistent name is crucial, since some macros I define
  258. later take a "type" argument, which is concatenated with 'make_' or 'get_'.
  259. This is done to make this file more dense; (Thus save me a lot of redundant
  260. typing.)
  261. type | dpy? | XID-P | hashed-p | Note
  262. ----------+------+-------+----------+------------------------------
  263. GCONTEXT | T | NIL | NIL | Is really a pointer
  264. WINDOW | T | T | T |
  265. PIXMAP | T | T | T |
  266. CURSOR | T | T | T |
  267. COLORMAP | T | T | T |
  268. FONT | T | T/NIL | T/NIL |
  269. SCREEN | T | NIL | (should | Could also been represented as index?
  270. | | | be) |
  271. DISPLAY | NIL | NIL | NIL |
  272. Class Hierarchy
  273. --------------------
  274. xlib-object --+--> xid-object --+--> DRAWABLE -+--> WINDOW
  275. | | +--> PIXMAP
  276. | |--> CURSOR
  277. | +--> COLORMAP
  278. | +--> FONT
  279. |
  280. +--> ptr-object --+--> GCONTEXT
  281. |
  282. +--> DISPLAY
  283. Just in case you prefer a textual representation:
  284. (defclass xlib-object () (plist display))
  285. (defclass xid-object (xlib-object) (xid))
  286. (defclass ptr-object (xlib-object) (ptr))
  287. (defclass drawable (xid-object) ())
  288. (defclass window (drawable) ())
  289. (defclass pixmap (drawable) ())
  290. (defclass cursor (xid-object) ())
  291. (defclass colormap (xid-object) ())
  292. (defclass gcontext (ptr-object) ())
  293. (defclass display (ptr-object) ())
  294. (defclass font (xid-object) (font-info name))
  295. */
  296. /* -- NOTE --
  297. For further for grepability I use the following tags in comments:
  298. XXX - really bad and a major risk to safety/usability.
  299. FIXME - just fix me, something that ought to be done
  300. before next release.
  301. TODO - something, which should be done and is already
  302. considered useful.
  303. FUTURE - something which is just an idea and it is not yet
  304. decided, if I ever implement it; It may also later
  305. be considered silly.
  306. I welcome discussion about those items.
  307. OK - the opposite of XXX. Functions which are
  308. considered to be totally finished and
  309. had undergone a test are marked with this.
  310. UNDEFINED - this is thought for undefined functions at whole
  311. NOTIMPLEMENTED - is thought for not implemented features
  312. in an partly defined function.
  313. */
  314. /* enough bla bla, let's start coding, we have a long long way before us ...*/
  315. #include "clisp.h"
  316. #include <X11/Xlib.h>
  317. #include <X11/Xutil.h> /* XGetVisualInfo */
  318. #include <X11/Xcms.h> /* forXcmsCCCOfColormap() & XcmsVisualOfCCC() */
  319. #include <X11/Xauth.h>
  320. /* #include <X11/Xresource.h> */
  321. #include <stdio.h> /* sprintf() */
  322. #include <string.h> /* memcpy(), strchr(), strcpy() */
  323. #include "config.h"
  324. #if defined(TIME_WITH_SYS_TIME)
  325. # include <sys/time.h>
  326. # include <time.h>
  327. #else
  328. # if defined(HAVE_SYS_TIME_H)
  329. # include <sys/time.h>
  330. # elif defined(HAVE_TIME_H)
  331. # include <time.h>
  332. # endif
  333. #endif
  334. #if defined(HAVE_SYS_SOCKET_H)
  335. # include <sys/socket.h>
  336. #endif
  337. #if defined(HAVE_NETDB_H)
  338. # include <netdb.h>
  339. #endif
  340. #if defined(HAVE_NETINET_IN_H)
  341. # include <netinet/in.h>
  342. #endif
  343. ##if WANT_XSHAPE
  344. /* must include this before DEFMODULE so that DEFCHECKER will work */
  345. #include <X11/extensions/shape.h>
  346. ##endif
  347. #define DEBUG_CLX 0
  348. #ifndef FOREIGN
  349. #error FOREIGN is not defined.
  350. #error CLX needs a CLISP built with the foreign pointer datatype support.
  351. #error Go into the main CLISP makefile and add a -DFOREIGN=void*
  352. #error to CFLAGS make variable and rebuild CLISP before coming back here.
  353. #endif
  354. DEFMODULE(clx,"XLIB")
  355. /* ... But first we provide some prototypes for functions, which maybe worth
  356. included in libX11 and are defined at the end of this file. */
  357. /* might also been called XVisualIDFromVisual**(-1) : */
  358. static Visual *XVisualIDToVisual (Display *dpy, VisualID vid);
  359. /* Find the screen index from a Screen* : */
  360. static int XScreenNo (Display *dpy, Screen *screen);
  361. /* our own forward declaration */
  362. static Display *pop_display (void);
  363. static inline Display *get_display (object dpy)
  364. { pushSTACK(dpy); return pop_display(); }
  365. /* Some fix-ups: */
  366. #define NOTIMPLEMENTED NOTREACHED
  367. #define UNDEFINED NOTIMPLEMENTED
  368. /* debug */
  369. #if DEBUG_CLX
  370. #define dprintf(x) do{ printf x; fflush(stdout); }while(0)
  371. #else
  372. #define dprintf(x) do{}while(0)
  373. #endif
  374. /* it is not clear whether we can rely on `writing_to_subprocess' or
  375. must actually disable SIGPIPE - see src/spvw_sigpipe.d */
  376. #define RELY_ON_WRITING_TO_SUBPROCESS
  377. #if defined(RELY_ON_WRITING_TO_SUBPROCESS)
  378. /* including <signal.h> just for the sake of SIGPIPE
  379. (which is always there anyway) is a total waste */
  380. # if defined(HAVE_SIGNALS) /* && defined(SIGPIPE) */
  381. extern
  382. # endif
  383. bool writing_to_subprocess;
  384. # define begin_x_call() writing_to_subprocess=true;begin_call()
  385. # define end_x_call() end_call();writing_to_subprocess=false
  386. #else
  387. # define begin_x_call() begin_call()
  388. # define end_x_call() end_call()
  389. extern void disable_sigpipe(void);
  390. #endif
  391. #define X_CALL(f) do{ begin_x_call(); f; end_x_call(); }while(0)
  392. /* -------------------------------------------------------------------------
  393. * General purpose utilities
  394. * ------------------------------------------------------------------------- */
  395. /* sugar for funcall (used in macros, so not a macro) */
  396. static inline object funcall1 (object fun, object arg)
  397. { pushSTACK(arg); funcall(fun,1); return value1; }
  398. nonreturning_function(static,my_type_error,(object type, object datum))
  399. {
  400. pushSTACK(datum); /* TYPE-ERROR slot DATUM */
  401. pushSTACK(type); /* TYPE-ERROR slot TYPE */
  402. pushSTACK(type); pushSTACK(datum); pushSTACK(TheSubr(subr_self)->name);
  403. error (type_error, ("~S: ~S is not of type ~S"));
  404. }
  405. nonreturning_function (static, error_closed_display,
  406. (object caller, object dpy)) {
  407. pushSTACK(`XLIB::CLOSED-DISPLAY`);
  408. pushSTACK(`:DISPLAY`); pushSTACK(dpy);
  409. pushSTACK(`:CALLER`); pushSTACK(caller);
  410. funcall(L(error),5);
  411. abort(); /* ERROR does not return: avoid a compiler warning */
  412. }
  413. /* with_stringable_0 is much like with_string_0, but a symbol is also
  414. allowed as argument. This macro does type checking and may raise an error. */
  415. #define with_stringable_0_tc(obj, encoding, cvar, body) \
  416. do { \
  417. object wsa0_temp = \
  418. (symbolp(obj) ? (object)Symbol_name (obj) : (object)(obj)); \
  419. if (stringp (wsa0_temp)) { \
  420. with_string_0 (wsa0_temp, encoding, cvar, body); \
  421. } else my_type_error(`(OR STRING SYMBOL)`,obj); \
  422. } while(0)
  423. /* -----------------------------------------------------------------------
  424. * Integer data types
  425. * ----------------------------------------------------------------------- */
  426. /* Huh?! These functions do not check the type?! */
  427. #define make_uint8(i) uint8_to_I (i)
  428. #define make_uint16(i) uint16_to_I (i)
  429. #define make_uint29(ul) UL_to_I (ul)
  430. #define make_uint32(ul) UL_to_I (ul)
  431. #define make_sint8(i) sint8_to_I (i)
  432. #define make_sint16(i) sint16_to_I (i)
  433. #define make_sint32(i) L_to_I (i)
  434. #define get_bool(obj) (!nullp(obj))
  435. #define make_bool(b) ((b)?(T):(NIL))
  436. #define pixel_p(obj) integerp (obj)
  437. #define get_pixel(obj) get_uint32(obj)
  438. #define make_pixel(obj) make_uint32(obj)
  439. #define get_fixnum(obj) fixnum_to_V (obj) /* WARNING: obj should be a variable (evaluated multiple), and no range check is performed */
  440. #if 0
  441. #define get_uint8(obj) I_to_uint8(obj)
  442. #define get_uint16(obj) I_to_uint16(obj)
  443. #define get_uint29(obj) I_to_UL (obj)
  444. #define get_uint32(obj) I_to_UL (obj)
  445. #define get_sint8(obj) I_to_sint8(obj)
  446. #define get_sint16(obj) I_to_sint16(obj)
  447. #define get_sint32(obj) I_to_sint32(obj)
  448. #else
  449. #define uint29_p uint32_p /* XXX the actual type checking code is just too weird! */
  450. #define I_to_uint29 I_to_UL /* XXX ditto */
  451. #define DEFINE_INTEGER_GETTER(type, lspnam) \
  452. static inline type get_##type (object obj) { \
  453. if (type##_p (obj)) \
  454. return I_to_##type (obj); \
  455. else my_type_error(lspnam,obj); \
  456. } \
  457. static inline type get_##type##_0 (object obj) { \
  458. return missingp(obj) ? 0 : get_##type(obj); \
  459. }
  460. DEFINE_INTEGER_GETTER (uint8, `XLIB::CARD8`)
  461. DEFINE_INTEGER_GETTER (uint16, `XLIB::CARD16`)
  462. DEFINE_INTEGER_GETTER (uint29, `XLIB::CARD29`)
  463. DEFINE_INTEGER_GETTER (uint32, `XLIB::CARD32`)
  464. DEFINE_INTEGER_GETTER (sint8, `XLIB::INT8`)
  465. DEFINE_INTEGER_GETTER (sint16, `XLIB::INT16`)
  466. DEFINE_INTEGER_GETTER (sint32, `XLIB::INT32`)
  467. #endif
  468. static uint32 get_aint32 (object obj)
  469. { /* This is special routine, which accepts either an uint32 or a sint32.
  470. However returned is an uint32.
  471. Used by XLIB:CHANGE-PROPERTY */
  472. if (uint32_p (obj))
  473. return I_to_uint32 (obj);
  474. if (sint32_p (obj))
  475. return (uint32)I_to_sint32 (obj);
  476. else my_type_error(`(OR XLIB::INT32 XLIB::CARD32)`,obj);
  477. }
  478. /* -----------------------------------------------------------------------
  479. * Displays
  480. * ----------------------------------------------------------------------- */
  481. /* Objects of type DISPLAY are currently represented as structure; here are the
  482. slots: The actual defstruct definition in clx.lisp must match. There is a
  483. warning in the code. */
  484. enum {
  485. slot_DISPLAY_FOREIGN_POINTER=1,
  486. slot_DISPLAY_HASH_TABLE,
  487. slot_DISPLAY_PLIST,
  488. slot_DISPLAY_AFTER_FUNCTION,
  489. slot_DISPLAY_ERROR_HANDLER,
  490. slot_DISPLAY_DISPLAY,
  491. display_structure_size
  492. };
  493. /* The display contains a hash table. All XID objects are entered there, so
  494. that two XID objects, with equal XID are actually eq. */
  495. static object make_display (Display *dpy, int display_number)
  496. { /* Given the C representation of a display create the Lisp one and
  497. initialize it. The newly created display is added to XLIB:*DISPLAYS*. */
  498. pushSTACK(`(XLIB::DISPLAY)`); pushSTACK(fixnum(display_structure_size));
  499. funcall(L(make_structure),2); pushSTACK(value1);
  500. TheStructure(STACK_0)->recdata[slot_DISPLAY_FOREIGN_POINTER]
  501. = allocate_fpointer (dpy);
  502. #if oint_data_len<29
  503. pushSTACK(S(Ktest)); pushSTACK(S(stablehash_equal)); /* key is a cons */
  504. #else
  505. pushSTACK(S(Ktest)); pushSTACK(S(stablehash_eq)); /* key is a fixnum */
  506. #endif
  507. funcall (L(make_hash_table), 2);
  508. TheStructure(STACK_0)->recdata[slot_DISPLAY_HASH_TABLE] = value1;
  509. TheStructure(STACK_0)->recdata[slot_DISPLAY_PLIST] = NIL;
  510. TheStructure(STACK_0)->recdata[slot_DISPLAY_AFTER_FUNCTION] = NIL;
  511. TheStructure(STACK_0)->recdata[slot_DISPLAY_ERROR_HANDLER] = NIL;
  512. TheStructure(STACK_0)->recdata[slot_DISPLAY_DISPLAY] =
  513. make_uint8 (display_number);
  514. /* Now enter the display into the list of all displays: */
  515. pushSTACK(STACK_0);
  516. pushSTACK(Symbol_value(`XLIB::*DISPLAYS*`));
  517. funcall (L(cons), 2);
  518. Symbol_value(`XLIB::*DISPLAYS*`) = value1;
  519. return value1 = popSTACK();
  520. }
  521. static object find_display (Display *display)
  522. { /* Searched the XLIB:*DISPLAY* variable for `display',
  523. return NIL, if display was not found.
  524. Used by the error handler, the only callback code here. */
  525. pushSTACK(Symbol_value (`XLIB::*DISPLAYS*`));
  526. for (;consp (STACK_0); STACK_0 = Cdr (STACK_0)) {
  527. if (get_display(Car(STACK_0)) == display)
  528. return Car(popSTACK());
  529. }
  530. skipSTACK(1);
  531. return NIL;
  532. }
  533. static Bool ensure_living_display (gcv_object_t *objf)
  534. { /* ensures that the object pointed to by 'objf' is really a display.
  535. Also the display must be 'alive', meaning that it does not contain
  536. a fptr from an previous incarnation of CLISP.
  537. If all that does not hold an error is signaled.
  538. Finally, returns an indicator of whether the display has been closed.
  539. 'objf' should point into the stack due to GC. */
  540. if (typep_classname (*objf, `XLIB::DISPLAY`)) { /* Is it a display at all? */
  541. object fptr = TheStructure(*objf)->recdata[slot_DISPLAY_FOREIGN_POINTER];
  542. return (fpointerp(fptr) && fp_validp(TheFpointer(fptr))
  543. && (TheFpointer(fptr)->fp_pointer != NULL));
  544. }
  545. /* Fall through -- raise type error */
  546. my_type_error(`XLIB::DISPLAY`,*(objf));
  547. }
  548. DEFUN(XLIB:CLOSED-DISPLAY-P, display)
  549. {
  550. VALUES_IF(!ensure_living_display(&STACK_0));
  551. skipSTACK(1);
  552. }
  553. /* display_hash_table -- return the hashtable of a display object
  554. > the display object
  555. < its hash table
  556. This function is somewhat silly, since it introduces double type checking! */
  557. static object display_hash_table (object dpy)
  558. {
  559. pushSTACK(dpy);
  560. if (!ensure_living_display(&(STACK_0)))
  561. error_closed_display(TheSubr(subr_self)->name,STACK_0);
  562. return TheStructure (popSTACK())->recdata[slot_DISPLAY_HASH_TABLE];
  563. }
  564. /* pop_display --- return the C Display* of an display object
  565. > STACK_0: the Lisp DISPLAY object */
  566. static Display *pop_display (void)
  567. {
  568. if (!ensure_living_display(&(STACK_0)))
  569. error_closed_display(TheSubr(subr_self)->name,STACK_0);
  570. STACK_0 = TheStructure (STACK_0)->recdata[slot_DISPLAY_FOREIGN_POINTER];
  571. return (Display*) TheFpointer(popSTACK())->fp_pointer;
  572. }
  573. /* -----------------------------------------------------------------------
  574. * PTR and XID objects
  575. * ----------------------------------------------------------------------- */
  576. /* First the ptr ones.
  577. ptr_objs are screens and gcontexts, these objects are not hashed.
  578. (which is a bad idea btw). But on the other hand for gcontexts it is
  579. not too bad, since you get `em only once.
  580. Another story are the screen, these could be cached. Or we do not give the
  581. actual screen structure, but pass simply the index? */
  582. static object make_ptr_obj (object type, object dpy, void *ptr)
  583. { /* (make-instance type :display dpy :ptr ptr) */
  584. pushSTACK(type);
  585. pushSTACK(`:DISPLAY`); pushSTACK(dpy);
  586. pushSTACK(`:PTR`); pushSTACK(allocate_fpointer (ptr));
  587. funcall(S(make_instance),5);
  588. return value1;
  589. }
  590. /* return the fp_pointer of the foreign slot
  591. value1 is set the slot value
  592. can trigger GC */
  593. static void* foreign_slot (object obj, object slot) {
  594. pushSTACK(obj); pushSTACK(slot); funcall(L(slot_value), 2);
  595. return TheFpointer(value1 = check_fpointer(value1,false))->fp_pointer;
  596. }
  597. static void *get_ptr_object_and_display (object type, object obj,
  598. Display **dpyf)
  599. { /* 'obj' is the lisp object, whose C representation is returned.
  600. When 'dpyf' is non-0, the display of 'obj' is also returned and it is
  601. ensured that it lives. [Otherwise an error is signaled.]
  602. If 'obj' is not of type 'type', a symbol naming the desired class,
  603. an error is issued.
  604. Hence this function ensures, that a proper object is returned, or nothing. */
  605. pushSTACK(type);
  606. pushSTACK(obj);
  607. if (typep_classname (STACK_0, STACK_1)) {
  608. if (dpyf) { /* do we want the display? */
  609. pushSTACK(STACK_0); pushSTACK(`XLIB::DISPLAY`);
  610. funcall(L(slot_value), 2); pushSTACK(value1);
  611. *dpyf = pop_display ();
  612. }
  613. { void * ret = foreign_slot(STACK_0/* 'obj' */,`XLIB::PTR`);
  614. skipSTACK(2); /* clean up */
  615. return ret;
  616. }
  617. } else my_type_error(STACK_1/*type*/,STACK_0/*obj*/);
  618. }
  619. /* Now the XID objects */
  620. static object make_xid_obj_low (gcv_object_t *prealloc, gcv_object_t *type,
  621. gcv_object_t *dpy, XID xid)
  622. {
  623. if (nullp (*prealloc)) {
  624. /* (make-instance type :display dpy :id xid) */
  625. pushSTACK(*type);
  626. pushSTACK(`:DISPLAY`); pushSTACK(*dpy);
  627. pushSTACK(`:ID`); pushSTACK(make_uint29 (xid));
  628. funcall(S(make_instance),5);
  629. return value1;
  630. } else {
  631. /* TODO: We should check the type of the preallocated object?!
  632. [Is is a bug or a feature?] */
  633. pushSTACK(*prealloc);
  634. pushSTACK(`XLIB::DISPLAY`);
  635. pushSTACK(*dpy);
  636. funcall (L(set_slot_value), 3);
  637. pushSTACK(*prealloc);
  638. pushSTACK(`XLIB::ID`);
  639. pushSTACK(make_uint29 (xid));
  640. funcall (L(set_slot_value), 3);
  641. return *prealloc;
  642. }
  643. }
  644. #if oint_data_len<29
  645. DEFVAR(xlib_a_cons,allocate_cons());
  646. /* return the XID object for lookup (old) */
  647. static inline object XID_to_object_old (XID xid) {
  648. Car (O(xlib_a_cons)) = make_uint16 (xid & 0xFFFF); /* lower halfword */
  649. Cdr (O(xlib_a_cons)) = make_uint16 (xid >> 16); /* upper halfword */
  650. return O(xlib_a_cons);
  651. }
  652. /* return the XID object for creation (new) */
  653. static inline object XID_to_object_new (XID xid) {
  654. pushSTACK(make_uint16 (xid & 0xFFFF)); /* lower halfword */
  655. pushSTACK(make_uint16 (xid >> 16)); /* upper halfword */
  656. funcall(L(cons),2); /* cons them */
  657. return value1;
  658. }
  659. #else
  660. #define XID_to_object_old(xid) fixnum(xid)
  661. #define XID_to_object_new(xid) fixnum(xid)
  662. #endif
  663. /* find the resource in the display hash table
  664. < display object, XID number
  665. > returns dpy->hash-table if NOT found
  666. nullobj if found, in which case the object found is in value1 */
  667. static object lookup_xid (object dpy, XID xid) {
  668. if (xid == 0) { /* This is trivial, but is it also right?! */
  669. VALUES1(NIL);
  670. return nullobj;
  671. } else {
  672. object ht = display_hash_table(dpy);
  673. value1 = gethash(XID_to_object_old(xid),ht,false); /* look it up */
  674. if (!eq(value1,nullobj)) { /* something found? */
  675. mv_count = 1; /* simply return what we found */
  676. return nullobj;
  677. } else
  678. return ht; /* return the hash-table */
  679. }
  680. }
  681. /* set the ID to map to RESOURCE on display
  682. < display hash-table object, XID number, resource object
  683. can trigger GC */
  684. static void set_resource_id (gcv_object_t *ht, XID xid,
  685. gcv_object_t *resource) {
  686. value1 = XID_to_object_new(xid);
  687. pushSTACK(value1); /* key for puthash */
  688. pushSTACK(*ht); /* hashtable */
  689. pushSTACK(*resource); /* value */
  690. funcall (L(puthash), 3); /* put it into the hashtable */
  691. }
  692. /* delete the resource ID from the display
  693. < display hash-table object, XID number */
  694. static Values delete_resource_id (gcv_object_t *ht, XID xid) {
  695. pushSTACK(XID_to_object_old(xid)); pushSTACK(*ht); funcall(L(remhash),2);
  696. }
  697. static object make_xid_obj_2 (object type, object dpy, XID xid,
  698. object prealloc)
  699. { /* NOTE: - This code is not reentrant :-( But hence it saves consing
  700. - may be we want to check the most significant 3 bits in xid, since
  701. GC inquiry functions return those values, if slot has an unknown
  702. value.
  703. - We could add even more safty here
  704. 1. bark if lookup succeed and prealloc was specified.
  705. [But this situation should not be able to occurr, since a
  706. prealloc is only given upon creation requests.] However MIT-CLX
  707. does this check and raises a hash-error, if something is not
  708. o.k. with the hash table. [But only if you set a debug flag
  709. somewhere].
  710. 2. If lookup succeeds we could also check the type.
  711. 3. We should check the type of the preallocated object?!
  712. [Compare to make_ptr_obj] */
  713. object ht = lookup_xid(dpy,xid);
  714. if (!eq(ht,nullobj)) { /* allocate and enter object into the hashtable */
  715. pushSTACK(prealloc); /* save is save */
  716. pushSTACK(type); /* ditto */
  717. pushSTACK(dpy); /* ditto */
  718. pushSTACK(ht); /* hashtable */
  719. pushSTACK(make_xid_obj_low (&STACK_3, &STACK_2, &STACK_1, xid));
  720. set_resource_id(&STACK_1,xid,&STACK_0); /* enter it into the hashtable */
  721. VALUES1(popSTACK()); /* return freshly allocated structure */
  722. skipSTACK(4); /* remove saved prealloc, type, dpy, ht */
  723. }
  724. return value1;
  725. }
  726. static XID get_xid_object_and_display (object type, object obj, Display **dpyf)
  727. {
  728. pushSTACK(type);
  729. pushSTACK(obj);
  730. if (typep_classname (STACK_0, STACK_1)) {
  731. if (dpyf) { /* do we want the display? */
  732. pushSTACK(STACK_0); pushSTACK(`XLIB::DISPLAY`);
  733. funcall(L(slot_value), 2); pushSTACK(value1);
  734. *dpyf = pop_display();
  735. }
  736. pushSTACK(STACK_0); /* obj already on stack */ pushSTACK(`XLIB::ID`);
  737. funcall(L(slot_value), 2);
  738. ASSERT(integerp (value1)); /* FIXME */
  739. skipSTACK(2); /* clean up */
  740. return (XID)(get_uint29 (value1)); /* all done */
  741. } else my_type_error(STACK_1/*type*/,STACK_0/*obj*/);
  742. }
  743. static object get_display_obj_tc (object type, object obj)
  744. {
  745. if (typep_classname (obj, type)) {
  746. pushSTACK(obj); pushSTACK(`XLIB::DISPLAY`);
  747. funcall(L(slot_value), 2); return value1;
  748. } else my_type_error(type,obj);
  749. }
  750. static object get_display_obj (object obj)
  751. { /* XXX type checking [Well on the other hand is it really necessary?]
  752. I want to use the combined function above. */
  753. pushSTACK(obj); pushSTACK(`XLIB::DISPLAY`);
  754. funcall(L(slot_value), 2); return value1;
  755. }
  756. /* -----------------------------------------------------------------------
  757. * Specializied getters/makers/predicates
  758. * ----------------------------------------------------------------------- */
  759. /* Simple Getters */
  760. #define get_xid_object(type,obj) get_xid_object_and_display(type,obj,0)
  761. #define get_ptr_object(type,obj) get_ptr_object_and_display(type,obj,0)
  762. #define get_gcontext(obj) ((GC) get_ptr_object (`XLIB::GCONTEXT`, obj))
  763. #define get_screen(obj) ((Screen*) get_ptr_object (`XLIB::SCREEN`, obj))
  764. #define get_image(obj) ((XImage*) get_ptr_object (`XLIB::IMAGE`, obj))
  765. #define get_window(obj) ((Window) get_xid_object (`XLIB::WINDOW`, obj))
  766. #define get_pixmap(obj) ((Pixmap) get_xid_object (`XLIB::PIXMAP`, obj))
  767. #define get_cursor(obj) ((Cursor) get_xid_object (`XLIB::CURSOR`, obj))
  768. #define get_colormap(obj) ((Colormap)get_xid_object (`XLIB::COLORMAP`, obj))
  769. #define get_drawable(obj) ((Drawable)get_xid_object (`XLIB::DRAWABLE`, obj))
  770. /* Combined getters */
  771. #define get_drawable_and_display(obj, dpyf) ((Drawable)get_xid_object_and_display (`XLIB::DRAWABLE`, obj, dpyf))
  772. #define get_window_and_display(obj, dpyf) ((Window) get_xid_object_and_display (`XLIB::WINDOW`, obj, dpyf))
  773. #define get_pixmap_and_display(obj, dpyf) ((Pixmap) get_xid_object_and_display (`XLIB::PIXMAP`, obj, dpyf))
  774. #define get_cursor_and_display(obj, dpyf) ((Cursor) get_xid_object_and_display (`XLIB::CURSOR`, obj, dpyf))
  775. #define get_colormap_and_display(obj, dpyf) ((Colormap)get_xid_object_and_display (`XLIB::COLORMAP`, obj, dpyf))
  776. #define get_gcontext_and_display(obj,dpyf) ((GC) get_ptr_object_and_display (`XLIB::GCONTEXT`, obj, dpyf))
  777. #define get_screen_and_display(obj,dpyf) ((Screen*) get_ptr_object_and_display (`XLIB::SCREEN`, obj, dpyf))
  778. #define get_font_and_display(obj, dpyf) ((Font) get_xid_object_and_display (`XLIB::FONT`, obj, dpyf))
  779. /* Predicates */
  780. #define drawable_p(obj) (typep_classname (obj, `XLIB::DRAWABLE`))
  781. #define window_p(obj) (typep_classname (obj, `XLIB::WINDOW`))
  782. #define pixmap_p(obj) (typep_classname (obj, `XLIB::PIXMAP`))
  783. #define cursor_p(obj) (typep_classname (obj, `XLIB::CURSOR`))
  784. #define colormap_p(obj) (typep_classname (obj, `XLIB::COLORMAP`))
  785. #define font_p(obj) (typep_classname (obj, `XLIB::FONT`))
  786. #define gcontext_p(obj) (typep_classname (obj, `XLIB::GCONTEXT`))
  787. #define screen_p(obj) (typep_classname (obj, `XLIB::SCREEN`))
  788. #define display_p(obj) (typep_classname (obj, `XLIB::DISPLAY`))
  789. #define color_p(obj) (typep_classname (obj, `XLIB::COLOR`))
  790. /* Simple Makers */
  791. #define make_xid_obj(a,b,c) make_xid_obj_2(a,b,c,NIL)
  792. #define make_window(dpy,win) (make_window_2(dpy,win,NIL))
  793. #define make_pixmap(dpy,pix) (make_pixmap_2(dpy,pix,NIL))
  794. #define make_drawable(dpy,da) (make_window (dpy, da))
  795. #define make_cursor(dpy,cur) (make_xid_obj (`XLIB::CURSOR`, dpy, cur))
  796. #define make_colormap(dpy,cm) (make_xid_obj (`XLIB::COLORMAP`, dpy, cm))
  797. #define make_gcontext(dpy,gc) (make_ptr_obj (`XLIB::GCONTEXT`, dpy, gc))
  798. #define make_screen(dpy, srcn) (make_ptr_obj (`XLIB::SCREEN`, dpy, srcn))
  799. /* Makers with prealloc */
  800. #define make_window_2(dpy, win, prealloc) (make_xid_obj_2 (`XLIB::WINDOW`, dpy, win, prealloc))
  801. #define make_pixmap_2(dpy, pm, prealloc) (make_xid_obj_2 (`XLIB::PIXMAP`, dpy, pm, prealloc))
  802. static object make_font (object dpy, Font fn, object name)
  803. { /* This looks much more like assembler, doesn't it? */
  804. pushSTACK(name); /* save the name */
  805. pushSTACK(make_xid_obj (`XLIB::FONT`, dpy, fn)); /* make the xid-object and save it */
  806. /* fetch old FONT-INFO slot */
  807. pushSTACK(STACK_0); /* xid-object */
  808. pushSTACK(`XLIB::FONT-INFO`); /* slot */
  809. funcall(L(slot_value), 2); /* (slot-value new-xid-object `font-info) */
  810. /* do not overwrite any already fetched font info */
  811. if (!fpointerp (value1)) { /* allocate a new fpointer */
  812. pushSTACK(STACK_0); /* the new xid-object */
  813. pushSTACK(`XLIB::FONT-INFO`); /* the slot */
  814. pushSTACK(allocate_fpointer (NULL)); /* new value */
  815. funcall (L(set_slot_value), 3); /* update the :font-info slot */
  816. }
  817. if (!nullp (STACK_1)) { /* name */
  818. pushSTACK(STACK_0); /* the new xid-object */
  819. pushSTACK(`XLIB::NAME`); /* the :name slot */
  820. pushSTACK(STACK_3); /* [name] new value */
  821. funcall (L(set_slot_value), 3); /* update the :name slot */
  822. }
  823. value1 = STACK_0; /* return value = new xid-object */
  824. skipSTACK(2); /* clean up */
  825. return value1;
  826. }
  827. static Font get_font (object obj);
  828. static XFontStruct *get_font_info_and_display (object obj, object* fontf,
  829. Display **dpyf)
  830. { /* Fetches the font information from a font, if it isn't there
  831. already, query the server for it.
  832. Further more if a gcontext is passed in, fetch its font slot instead.
  833. Does type checking and raises error if unappropriate object passed in.
  834. If 'fontf' is non-0, also the font as a Lisp object is returned.
  835. If 'dpyf' is non-0, also the display of the font is returned and it is
  836. ensured that the display actually lives. */
  837. XFontStruct *info;
  838. Display *dpy;
  839. Font font;
  840. if (gcontext_p (obj)) {
  841. /* In all places where a font object is required, a gcontext should
  842. be accepted too, so fetch the font slot and go on ... */
  843. pushSTACK(obj); pushSTACK(NIL);
  844. funcall(``XLIB:GCONTEXT-FONT``,2);
  845. obj = value1; /* Now we have the font [or nothing] */
  846. }
  847. if (!font_p (obj)) my_type_error(`XLIB::FONT`,obj);
  848. pushSTACK(obj); /* save */
  849. info = (XFontStruct*) foreign_slot(obj,`XLIB::FONT-INFO`);
  850. if (!info) {
  851. /* We have no font information already, so go and ask the server for it. */
  852. pushSTACK(value1); /* but first save what we found. */
  853. font = get_font_and_display (STACK_1, &dpy);
  854. X_CALL(info = XQueryFont (dpy, font));
  855. if (!info) {
  856. pushSTACK(STACK_1); pushSTACK(TheSubr (subr_self)->name);
  857. error(error_condition,"~S: Font ~S does not exist");
  858. }
  859. if (dpyf) *dpyf = dpy;
  860. /* Store it in the foreign pointer
  861. (foreign_slot ensures that STACK_0 is a foreign pointer) */
  862. TheFpointer(STACK_0)->fp_pointer = info;
  863. skipSTACK(1);
  864. # ifdef UNICODE
  865. { /* Determine the font's encoding, so we can correctly convert
  866. characters to indices.
  867. Call (XLIB:FONT-PROPERTY font "CHARSET_REGISTRY")
  868. and (XLIB:FONT-PROPERTY font "CHARSET_ENCODING")
  869. and translate the resulting pairs to CLISP encodings. */
  870. Atom xatom;
  871. unsigned long rgstry;
  872. unsigned long encdng;
  873. begin_x_call();
  874. xatom = XInternAtom (dpy, "CHARSET_REGISTRY", 0);
  875. if (XGetFontProperty (info, xatom, &rgstry)) {
  876. xatom = XInternAtom (dpy, "CHARSET_ENCODING", 0);
  877. if (XGetFontProperty (info, xatom, &encdng)) {
  878. Atom xatoms[2];
  879. char* names[2];
  880. int status;
  881. xatoms[0] = rgstry;
  882. xatoms[1] = encdng;
  883. names[0] = NULL;
  884. names[1] = NULL;
  885. # if !defined(HAVE_XGETATOMNAMES)
  886. names[0] = XGetAtomName (dpy, xatoms[0]);
  887. names[1] = XGetAtomName (dpy, xatoms[1]);
  888. status = names[0] && names[1];
  889. # else
  890. status = XGetAtomNames (dpy, xatoms, 2, names); /* X11R6 */
  891. # endif
  892. if (status) {
  893. /* this encoding canonicalization was requested by
  894. Pascal J.Bourguignon <pjb@informatimago.com>
  895. in <http://article.gmane.org/gmane.lisp.clisp.general:7794> */
  896. char* whole = (char*) alloca(strlen(names[0])+strlen(names[1])+3);
  897. if (!strncasecmp(names[0],"iso",3) && names[0][3] != '-') {
  898. strcpy(whole,"ISO-");
  899. strcat(whole,names[0]+3);
  900. } else strcpy(whole,names[0]);
  901. strcat(whole,"-");
  902. strcat(whole,names[1]);
  903. end_x_call();
  904. pushSTACK(S(Kcharset));
  905. pushSTACK(asciz_to_string(whole,GLO(misc_encoding)));
  906. pushSTACK(S(Koutput_error_action));
  907. pushSTACK(fixnum(info->default_char));
  908. funcall(L(make_encoding),4);
  909. pushSTACK(STACK_0); /* obj */
  910. pushSTACK(`XLIB::ENCODING`);
  911. pushSTACK(value1);
  912. funcall(L(set_slot_value),3);
  913. begin_x_call();
  914. }
  915. if (names[0])
  916. XFree (names[0]);
  917. if (names[1])
  918. XFree (names[1]);
  919. }
  920. }
  921. end_x_call();
  922. }
  923. # endif
  924. } else if (dpyf) /* caller wants the display, so get it! */
  925. unused get_font_and_display (STACK_0, dpyf);
  926. if (fontf) *fontf = STACK_0;
  927. skipSTACK(1);
  928. return info; /* all done */
  929. }
  930. static object get_font_name (object obj)
  931. {
  932. pushSTACK(obj); /* the instance */
  933. pushSTACK(`XLIB::NAME`); /* slot */
  934. funcall(L(slot_value), 2); /* lookup the slot */
  935. return value1;
  936. }
  937. #define ENSURE_TYPE(datum,booli,type) if (!booli) my_type_error(type,datum)
  938. static object get_slot (object obj, object slot)
  939. { /* like gethash(): return nullobj on unbound slot and slot value otherwise */
  940. pushSTACK(obj); pushSTACK(slot); /* save for SLOT-VALUE */
  941. pushSTACK(obj); pushSTACK(slot); funcall(L(slot_boundp),2);
  942. if (nullp(value1)) { skipSTACK(2); return nullobj; }
  943. funcall(L(slot_value),2); return value1;
  944. }
  945. static Font get_font (object self)
  946. { /* Does type-checking. */
  947. object font_id;
  948. pushSTACK(self); /* save */
  949. ENSURE_TYPE (STACK_0, font_p(STACK_0), `XLIB::FONT`);
  950. font_id = get_slot(STACK_0,`XLIB::ID`);
  951. if (!eq(font_id,nullobj)) { /* We have already a fid, so return it. */
  952. skipSTACK(1); /* clean up */
  953. ASSERT(integerp(font_id));
  954. return (XID)(get_uint29(font_id));
  955. } else { /* No font id => lookup the name & open that font */
  956. object name = get_font_name(STACK_0/*self*/);
  957. if (boundp(name)) { /* Ok there is a name ... so try to open the font */
  958. Font font; Display *dpy = get_display(STACK_0);
  959. with_string_0 (name, GLO(misc_encoding), namez, { /* XXX */
  960. X_CALL(font = XLoadFont(dpy,namez));
  961. });
  962. if (font) { /* Hurra! We got a font id, so enter it */
  963. pushSTACK(`XLIB::ID`); pushSTACK(make_uint29(font));
  964. funcall(L(set_slot_value),3);
  965. /* XXX -- We should enter it also into the hash table! */
  966. return font; /* all done */
  967. } else { /* We could not open the font, so emit an error message */
  968. pushSTACK(TheSubr(subr_self)->name); /* function name */
  969. error(error_condition,"~S: Cannot open pseudo font ~S");
  970. }
  971. } else { /* We have no name, tell that the luser. */
  972. pushSTACK(TheSubr(subr_self)->name); /* function name */
  973. error(error_condition,"~S: Cannot open pseudo font ~S, since it has no name associated with it.");
  974. }
  975. }
  976. }
  977. static Atom get_xatom_general (Display *dpy, object obj, int internp)
  978. { /* Converts a symbol or a string to an xatom. If 'obj' is no symbol
  979. nor a string, an error is raised. if 'internp' is non-0 the atom
  980. is interned on the server. */
  981. Atom xatom;
  982. with_stringable_0_tc (obj, GLO(misc_encoding), atom_name, {
  983. X_CALL(xatom = XInternAtom (dpy, atom_name, !internp));
  984. });
  985. return xatom;
  986. }
  987. #define get_xatom(dpy,obj) get_xatom_general (dpy, obj, 1) /* interning version */
  988. #define get_xatom_nointern(dpy,obj) get_xatom_general (dpy, obj, 0) /* non-interning version */
  989. static object make_visual (Visual *visual)
  990. {
  991. XID id;
  992. X_CALL(id = XVisualIDFromVisual (visual));
  993. return make_uint29 (id);
  994. }
  995. static Visual *get_visual (Display *dpy, object vid)
  996. {
  997. /* no begin/end_call here XVisualIDToVisual is defined by us. */
  998. return XVisualIDToVisual (dpy, get_uint29 (vid));
  999. }
  1000. /* -----------------------------------------------------------------------
  1001. * Lots of enums
  1002. * ----------------------------------------------------------------------- */
  1003. DEFCHECKER(get_map_state,default=,UNMAPPED=IsUnmapped \
  1004. UNVIEWABLE=IsUnviewable VIEWABLE=IsViewable)
  1005. #define make_map_state get_map_state_reverse
  1006. DEFCHECKER(get_shape,default=,COMPLEX=Complex CONVEX=Convex \
  1007. NON-CONVEX=Nonconvex)
  1008. DEFCHECKER(get_W_class,default=,:COPY=CopyFromParent INPUT-OUTPUT=InputOutput \
  1009. INPUT-ONLY=InputOnly)
  1010. #define make_W_class get_W_class_reverse
  1011. DEFCHECKER(get_stack_mode,default=,ABOVE=Above BELOW=Below TOP-IF=TopIf \
  1012. BOTTOM-IF=BottomIf OPPOSITE=Opposite)
  1013. #define make_stack_mode get_stack_mode_reverse
  1014. DEFCHECKER(get_arc_mode,default=,CHORD=ArcChord PIE-SLICE=ArcPieSlice)
  1015. #define make_arc_mode get_arc_mode_reverse
  1016. DEFCHECKER(get_line_style,default=,SOLID=LineSolid DASH=LineOnOffDash \
  1017. DOUBLE-DASH=LineDoubleDash)
  1018. #define make_line_style get_line_style_reverse
  1019. DEFCHECKER(get_cap_style,default=,NOT-LAST=CapNotLast BUTT=CapButt \
  1020. ROUND=CapRound PROJECTING=CapProjecting)
  1021. #define make_cap_style get_cap_style_reverse
  1022. DEFCHECKER(get_join_style,default=, \
  1023. MITER=JoinMiter ROUND=JoinRound BEVEL=JoinBevel)
  1024. #define make_join_style get_join_style_reverse
  1025. DEFCHECKER(get_fill_style,default=,SOLID=FillSolid TILED=FillTiled \
  1026. STIPPLED=FillStippled OPAQUE-STIPPLED=FillOpaqueStippled)
  1027. #define make_fill_style get_fill_style_reverse
  1028. DEFCHECKER(get_fill_rule,default=, EVEN-ODD=EvenOddRule WINDING=WindingRule)
  1029. #define make_fill_rule get_fill_rule_reverse
  1030. DEFCHECKER(get_subwindow_mode,default=, \
  1031. CLIP-BY-CHILDREN=ClipByChildren INCLUDE-INFERIORS=IncludeInferiors)
  1032. #define make_subwindow_mode get_subwindow_mode_reverse
  1033. DEFCHECKER(get_gravity,default=,FORGET=ForgetGravity \
  1034. NORTH-WEST=NorthWestGravity NORTH=NorthGravity \
  1035. NORTH-EAST=NorthEastGravity WEST=WestGravity CENTER=CenterGravity \
  1036. EAST=EastGravity SOUTH-WEST=SouthWestGravity SOUTH=SouthGravity \
  1037. SOUTH-EAST=SouthEastGravity STATIC=StaticGravity)
  1038. #define make_gravity get_gravity_reverse
  1039. /* NIM: the :static gravity is not mentioned in the CLX manual. */
  1040. DEFCHECKER(get_visibility_state,default=, UNOBSCURED=VisibilityUnobscured \
  1041. PARTLY-OBSCURED=VisibilityPartiallyObscured \
  1042. FULLY-OBSCURED=VisibilityFullyObscured)
  1043. #define make_visibility_state get_visibility_state_reverse
  1044. DEFCHECKER(get_top_or_bottom,default=,TOP=PlaceOnTop BOTTOM=PlaceOnBottom)
  1045. #define make_top_or_bottom get_top_or_bottom_reverse
  1046. DEFCHECKER(get_new_value_or_deleted,default=, \
  1047. NEW-VALUE=PropertyNewValue DELETED=PropertyDelete)
  1048. #define make_new_value_or_deleted get_new_value_or_deleted_reverse
  1049. DEFCHECKER(get_ordering,default=Unsorted, UNSORTED=Unsorted Y-SORTED=YSorted \
  1050. YX-SORTED=YXSorted YX-BANDED=YXBanded)
  1051. DEFCHECKER(get_mapping_request,default=, MODIFIER=MappingModifier \
  1052. KEYBOARD=MappingKeyboard POINTER=MappingPointer)
  1053. #define make_mapping_request get_mapping_request_reverse
  1054. DEFCHECKER(get_crossing_mode,default=, :NORMAL=NotifyNormal GRAB=NotifyGrab \
  1055. UNGRAB=NotifyUngrab WHILE-GRABBED=NotifyWhileGrabbed)
  1056. #define make_crossing_mode get_crossing_mode_reverse
  1057. /* NIM: :while-grabbed */
  1058. DEFCHECKER(get_crossing_kind,default=, ANCESTOR=NotifyAncestor \
  1059. VIRTUAL=NotifyVirtual INFERIOR=NotifyInferior \
  1060. NONLINEAR=NotifyNonlinear NONLINEAR-VIRTUAL=NotifyNonlinearVirtual \
  1061. POINTER=NotifyPointer POINTER-ROOT=NotifyPointerRoot \
  1062. NONE=NotifyDetailNone)
  1063. #define make_crossing_kind get_crossing_kind_reverse
  1064. /* NIM: :pointer, :pointer-root, :none */
  1065. DEFCHECKER(get_focus_mode,default=,:NORMAL=NotifyNormal GRAB=NotifyGrab \
  1066. UNGRAB=NotifyUngrab WHILE-GRABBED=NotifyWhileGrabbed)
  1067. #define make_focus_mode get_focus_mode_reverse
  1068. /* This seems to be the same as crossing_mode, but added the
  1069. :while-grabbed in CLXM Have to justify that by looking into the
  1070. source. I was complaining 'Strange -- the CLX manual says also
  1071. somthing about :while-grabbed!' Maybe libX and CLX differ here? */
  1072. DEFCHECKER(get_focus_detail,default=,ANCESTOR=NotifyAncestor \
  1073. VIRTUAL=NotifyVirtual INFERIOR=NotifyInferior \
  1074. NONLINEAR=NotifyNonlinear NONLINEAR-VIRTUAL=NotifyNonlinearVirtual \
  1075. POINTER=NotifyPointer POINTER-ROOT=NotifyPointerRoot \
  1076. NONE=NotifyDetailNone)
  1077. #define make_focus_detail get_focus_detail_reverse
  1078. /* This seems also to be the same as crossing_kind! */
  1079. DEFCHECKER(get_V_class,default=,STATIC-GRAY=StaticGray GRAY-SCALE=GrayScale \
  1080. STATIC-COLOR=StaticColor PSEUDO-COLOR=PseudoColor \
  1081. TRUE-COLOR=TrueColor DIRECT-COLOR=DirectColor)
  1082. #define make_V_class get_V_class_reverse
  1083. DEFCHECKER(get_backing_store,default=,\
  1084. NOT-USEFUL=NotUseful WHEN-MAPPED=WhenMapped ALWAYS=Always)
  1085. #define make_backing_store get_backing_store_reverse
  1086. DEFCHECKER(get_switch,default=, OFF=LedModeOff ON=LedModeOn)
  1087. #define make_switch get_switch_reverse
  1088. DEFCHECKER(get_close_down_mode,default=, DESTROY=DestroyAll \
  1089. RETAIN-PERMANENT=RetainPermanent RETAIN-TEMPORARY=RetainTemporary)
  1090. DEFCHECKER(get_draw_direction,default=, \
  1091. LEFT-TO-RIGHT=FontLeftToRight RIGHT-TO-LEFT=FontRightToLeft)
  1092. #define make_draw_direction get_draw_direction_reverse
  1093. static Bool get_generic_switch (object o)
  1094. { return ! (eq (o, `:NO`) || eq (o, `:OFF`) || nullp (o)); }
  1095. #define make_generic_switch make_bool
  1096. #define BOOLEEQ(obj,bo) (eq (obj,bo) || eq (obj, Symbol_value (bo)))
  1097. static object make_gc_function (int i)
  1098. { /* This Symbol_value thing here is somewhat silly */
  1099. switch (i) {
  1100. case GXclear: return Symbol_value (`BOOLE-CLR`); /* 0 */
  1101. case GXand: return Symbol_value (`BOOLE-AND`); /* src AND dst */
  1102. case GXandReverse: return Symbol_value (`BOOLE-ANDC2`); /* src AND NOT dst */
  1103. case GXcopy: return Symbol_value (`BOOLE-1`); /* src */
  1104. case GXandInverted: return Symbol_value (`BOOLE-ANDC1`); /* (NOT src) AND dst */
  1105. case GXnoop: return Symbol_value (`BOOLE-2`); /* dst */
  1106. case GXxor: return Symbol_value (`BOOLE-XOR`); /* src XOR dst */
  1107. case GXor: return Symbol_value (`BOOLE-IOR`); /* src OR dst */
  1108. case GXnor: return Symbol_value (`BOOLE-NOR`); /* (NOT src) AND (NOT dst) */
  1109. case GXequiv: return Symbol_value (`BOOLE-EQV`); /* (NOT src) XOR dst */
  1110. case GXinvert: return Symbol_value (`BOOLE-C2`); /* NOT dst */
  1111. case GXorReverse: return Symbol_value (`BOOLE-ORC2`); /* src OR (NOT dst) */
  1112. case GXcopyInverted: return Symbol_value (`BOOLE-C1`); /* NOT src */
  1113. case GXorInverted: return Symbol_value (`BOOLE-ORC1`); /* (NOT src) OR dst */
  1114. case GXnand: return Symbol_value (`BOOLE-NAND`); /* (NOT src) OR (NOT dst) */
  1115. case GXset: return Symbol_value (`BOOLE-SET`); /* 1 */
  1116. default:
  1117. my_type_error(`XLIB::GC-FUNCTION`,fixnum(i));
  1118. }
  1119. }
  1120. static int get_gc_function (object obj)
  1121. { /* I hope this translations are right -- could somebody please verify?! */
  1122. if (BOOLEEQ (obj, `BOOLE-CLR`)) return GXclear; /* 0 */
  1123. if (BOOLEEQ (obj, `BOOLE-AND`)) return GXand; /* src AND dst */
  1124. if (BOOLEEQ (obj, `BOOLE-ANDC2`)) return GXandReverse; /* src AND NOT dst */
  1125. if (BOOLEEQ (obj, `BOOLE-1`)) return GXcopy; /* src */
  1126. if (BOOLEEQ (obj, `BOOLE-ANDC1`)) return GXandInverted; /* (NOT src) AND dst */
  1127. if (BOOLEEQ (obj, `BOOLE-2`)) return GXnoop; /* dst */
  1128. if (BOOLEEQ (obj, `BOOLE-XOR`)) return GXxor; /* src XOR dst */
  1129. if (BOOLEEQ (obj, `BOOLE-IOR`)) return GXor; /* src OR dst */
  1130. if (BOOLEEQ (obj, `BOOLE-NOR`)) return GXnor; /* (NOT src) AND (NOT dst) */
  1131. if (BOOLEEQ (obj, `BOOLE-EQV`)) return GXequiv; /* (NOT src) XOR dst */
  1132. if (BOOLEEQ (obj, `BOOLE-C2`)) return GXinvert; /* NOT dst */
  1133. if (BOOLEEQ (obj, `BOOLE-ORC2`)) return GXorReverse; /* src OR (NOT dst) */
  1134. if (BOOLEEQ (obj, `BOOLE-C1`)) return GXcopyInverted; /* NOT src */
  1135. if (BOOLEEQ (obj, `BOOLE-ORC1`)) return GXorInverted; /* (NOT src) OR dst */
  1136. if (BOOLEEQ (obj, `BOOLE-NAND`)) return GXnand; /* (NOT src) OR (NOT dst) */
  1137. if (BOOLEEQ (obj, `BOOLE-SET`)) return GXset; /* 1 */
  1138. my_type_error(`XLIB::GC-FUNCTION`,obj);
  1139. /* Garnet seem to run in that ...
  1140. ... not any longer
  1141. return GXcopy; */
  1142. }
  1143. DEFCHECKER(get_gcontext_key,type=unsigned long,default=, ARC-MODE=GCArcMode \
  1144. BACKGROUND=GCBackground CAP-STYLE=GCCapStyle \
  1145. CLIP-MASK=GCClipMask \
  1146. CLIP-X=GCClipXOrigin CLIP-Y=GCClipYOrigin \
  1147. DASH-OFFSET=GCDashOffset DASHES=GCDashList \
  1148. EXPOSURES=GCGraphicsExposures \
  1149. FILL-RULE=GCFillRule FILL-STYLE=GCFillStyle \
  1150. FONT=GCFont \
  1151. FOREGROUND=GCForeground \
  1152. FUNCTION=GCFunction \
  1153. JOIN-STYLE=GCJoinStyle LINE-STYLE=GCLineStyle \
  1154. LINE-WIDTH=GCLineWidth PLANE-MASK=GCPlaneMask \
  1155. STIPPLE=GCStipple \
  1156. SUBWINDOW-MODE=GCSubwindowMode \
  1157. TILE=GCTile \
  1158. TS-X=GCTileStipXOrigin TS-Y=GCTileStipXOrigin)
  1159. /* -----------------------------------------------------------------------
  1160. * Masks
  1161. * ----------------------------------------------------------------------- */
  1162. DEFCHECKER(check_modifier, default=, bitmasks=both, type=unsigned int, \
  1163. SHIFT=ShiftMask LOCK=LockMask CONTROL=ControlMask \
  1164. MOD-1=Mod1Mask MOD-2=Mod2Mask MOD-3=Mod3Mask MOD-4=Mod4Mask \
  1165. MOD-5=Mod5Mask BUTTON-1=Button1Mask BUTTON-2=Button2Mask \
  1166. BUTTON-3=Button3Mask BUTTON-4=Button4Mask BUTTON-5=Button5Mask)
  1167. static unsigned int get_modifier_mask (object obj)
  1168. {
  1169. if (!boundp(obj)) return 0;
  1170. if (eq (obj, `:ANY`)) return AnyModifier;
  1171. if (integerp (obj)) return get_uint16 (obj);
  1172. if (listp(obj)) return check_modifier_from_list(obj);
  1173. my_type_error(`(OR (EQL :ANY) XLIB::CARD16 LIST)`,obj);
  1174. }
  1175. DEFCHECKER(check_event_mask,default=, bitmasks=both, type=unsigned long, \
  1176. KEY-PRESS=KeyPressMask \
  1177. KEY-RELEASE=KeyReleaseMask \
  1178. BUTTON-PRESS=ButtonPressMask \
  1179. BUTTON-RELEASE=ButtonReleaseMask \
  1180. ENTER-WINDOW=EnterWindowMask \
  1181. LEAVE-WINDOW=LeaveWindowMask \
  1182. POINTER-MOTION=PointerMotionMask \
  1183. POINTER-MOTION-HINT=PointerMotionHintMask \
  1184. BUTTON-1-MOTION=Button1MotionMask \
  1185. BUTTON-2-MOTION=Button2MotionMask \
  1186. BUTTON-3-MOTION=Button3MotionMask \
  1187. BUTTON-4-MOTION=Button4MotionMask \
  1188. BUTTON-5-MOTION=Button5MotionMask \
  1189. BUTTON-MOTION=ButtonMotionMask \
  1190. KEYMAP-STATE=KeymapStateMask \
  1191. EXPOSURE=ExposureMask \
  1192. VISIBILITY-CHANGE=VisibilityChangeMask \
  1193. STRUCTURE-NOTIFY=StructureNotifyMask \
  1194. RESIZE-REDIRECT=ResizeRedirectMask \
  1195. SUBSTRUCTURE-NOTIFY=SubstructureNotifyMask \
  1196. SUBSTRUCTURE-REDIRECT=SubstructureRedirectMask \
  1197. FOCUS-CHANGE=FocusChangeMask PROPERTY-CHANGE=PropertyChangeMask \
  1198. COLORMAP-CHANGE=ColormapChangeMask \
  1199. OWNER-GRAB-BUTTON=OwnerGrabButtonMask)
  1200. static unsigned long get_event_mask (object obj)
  1201. { /* get_event_mask could handle a numerical and symbolic
  1202. representation of an event mask */
  1203. if (uint32_p (obj)) return get_uint32 (obj);
  1204. if (listp (obj)) return check_event_mask_from_list(obj);
  1205. my_type_error(`(OR XLIB::CARD32 LIST)`,obj);
  1206. }
  1207. static object make_event_mask (unsigned long mask)
  1208. { return make_uint32 (mask); }
  1209. /* -----------------------------------------------------------------------
  1210. * Various other types
  1211. * ----------------------------------------------------------------------- */
  1212. static object make_xatom (Display *dpy, Atom atom)
  1213. {
  1214. char *atom_name;
  1215. X_CALL(atom_name = XGetAtomName (dpy, atom));
  1216. if (atom_name == NULL) return NIL;
  1217. else {
  1218. object kwd = intern_keyword(asciz_to_string(atom_name,GLO(misc_encoding)));
  1219. X_CALL(XFree(atom_name));
  1220. return kwd;
  1221. }
  1222. }
  1223. static Time get_timestamp (object obj)
  1224. { return missingp(obj) ? CurrentTime : get_uint32 (obj); }
  1225. static sint32 get_angle (object ang)
  1226. { /* translates the CLX angle representation in radian to X represent
  1227. in sixty-fourth of degree: (round (* (/ ang pi) (* 180 64))) */
  1228. pushSTACK(ang);
  1229. pushSTACK(GLO(FF_pi));
  1230. funcall (L(slash), 2);
  1231. pushSTACK(value1);
  1232. pushSTACK(fixnum(180*64));
  1233. funcall (L(star), 2);
  1234. return get_sint32(funcall1(L(round),value1));
  1235. }
  1236. static object make_fill_bit_vector (char *data, int len)
  1237. {
  1238. object ret = allocate_bit_vector (Atype_Bit, len * 8);
  1239. X_CALL(memcpy (TheSbvector(ret)->data, data, len));
  1240. return ret;
  1241. }
  1242. static object make_key_vector (char key_vector[32])
  1243. { return make_fill_bit_vector(key_vector,32); }
  1244. #define check_bitvec_256(obj) \
  1245. if (!(simple_bit_vector_p (Atype_Bit, obj) \
  1246. && Sbvector_length (obj) == 256)) \
  1247. my_type_error(`(SIMPLE-BIT-VECTOR 256)`,STACK_0)
  1248. static void get_key_vector (object obj, char key_vector [32])
  1249. {
  1250. check_bitvec_256(obj);
  1251. X_CALL(memcpy (key_vector, TheSbvector(obj)->data, 32));
  1252. }
  1253. static object make_client_message_format (int format)
  1254. {
  1255. switch (format) {
  1256. case 32: case 16: case 8: return make_uint32 (format);
  1257. default: my_type_error (`(MEMBER 8 16 32)`, make_uint32 (format));
  1258. }
  1259. }
  1260. static int get_client_message_format (object obj)
  1261. {
  1262. int format = get_uint32 (obj);
  1263. switch (format) {
  1264. case 32: case 16: case 8: return format;
  1265. default: my_type_error (`(MEMBER 8 16 32)`, obj);
  1266. }
  1267. }
  1268. static object make_client_message_data (XClientMessageEvent *xclient)
  1269. {
  1270. int i;
  1271. int cnt = 0;
  1272. switch (xclient->format) {
  1273. case 8:
  1274. for (i=0; i<20; i++)
  1275. pushSTACK (make_uint8 (xclient->data.b[i]));
  1276. cnt = 20;
  1277. break;
  1278. case 16:
  1279. for (i=0; i<10; i++)
  1280. pushSTACK (make_uint16 (xclient->data.s[i]));
  1281. cnt = 10;
  1282. break;
  1283. case 32:
  1284. for (i=0; i<5; i++)
  1285. pushSTACK (make_uint32 (xclient->data.l[i]));
  1286. cnt = 5;
  1287. break;
  1288. default:
  1289. my_type_error (`(MEMBER 8 16 32)`, make_uint32 (xclient->format));
  1290. }
  1291. return listof (cnt);
  1292. }
  1293. static void get_client_message_data (XClientMessageEvent *event, uint32 format,
  1294. object data)
  1295. {
  1296. int i;
  1297. if (consp (data)) {
  1298. switch (format) {
  1299. case 8:
  1300. for (i=0; i<20; i++) {
  1301. if (nullp (data)) {
  1302. event->data.b[i] = 0;
  1303. } else {
  1304. event->data.b[i] = get_uint8 (Car(data));
  1305. data = Cdr(data);
  1306. }
  1307. }
  1308. break;
  1309. case 16:
  1310. for (i=0; i<10; i++) {
  1311. if (nullp (data)) {
  1312. event->data.s[i] = 0;
  1313. } else {
  1314. event->data.s[i] = get_uint16 (Car(data));
  1315. data = Cdr(data);
  1316. }
  1317. }
  1318. break;
  1319. case 32:
  1320. for (i=0; i<5; i++) {
  1321. if (nullp (data)) {
  1322. event->data.l[i] = 0;
  1323. } else {
  1324. event->data.l[i] = get_uint32 (Car(data));
  1325. data = Cdr(data);
  1326. }
  1327. }
  1328. break;
  1329. default:
  1330. my_type_error (`(MEMBER 8 16 32)`, make_uint32 (format));
  1331. }
  1332. }
  1333. else
  1334. my_type_error (S(cons), data);
  1335. }
  1336. static object make_visual_info (Visual *vis)
  1337. {
  1338. pushSTACK(`(XLIB::VISUAL-INFO)`); pushSTACK(fixnum(8));
  1339. funcall(L(make_structure),2); pushSTACK(value1);
  1340. TheStructure(STACK_0)->recdata[1] = make_uint29 (vis->visualid); /* id */
  1341. #ifdef __cplusplus
  1342. TheStructure(STACK_0)->recdata[2] = make_V_class (vis->c_class); /* class */
  1343. #else
  1344. TheStructure(STACK_0)->recdata[2] = make_V_class (vis->class); /* class */
  1345. #endif
  1346. TheStructure(STACK_0)->recdata[3] = make_pixel (vis->red_mask); /* red-mask */
  1347. TheStructure(STACK_0)->recdata[4] = make_pixel (vis->green_mask); /* green-mask */
  1348. TheStructure(STACK_0)->recdata[5] = make_pixel (vis->blue_mask); /* blue-mask */
  1349. TheStructure(STACK_0)->recdata[6] = make_uint8 (vis->bits_per_rgb); /* bits-per-rgb */
  1350. TheStructure(STACK_0)->recdata[7] = make_uint16 (vis->map_entries); /* colormap-entries */
  1351. return popSTACK();
  1352. }
  1353. static object make_rgb_val (unsigned short value)
  1354. { /* calculate (/ value 65535.0)
  1355. FIXME -- should find more clever way to do this ... */
  1356. pushSTACK(fixnum(value));
  1357. pushSTACK(fixnum(65535));
  1358. funcall (L(slash), 2);
  1359. return value1;
  1360. }
  1361. static unsigned short get_rgb_val (object value)
  1362. { /* calculate (round (* value 65535))
  1363. FIXME -- should really find more clever way to do this ...
  1364. -- maybe we check the actual type here?! */
  1365. pushSTACK(value);
  1366. pushSTACK(fixnum(0xFFFF));
  1367. funcall (L(star), 2);
  1368. return get_uint16(funcall1(L(round),value1));
  1369. }
  1370. static void get_color (Display *dpy, object color, XColor *result)
  1371. {
  1372. pushSTACK(color);
  1373. ENSURE_TYPE (STACK_0, color_p (STACK_0), `XLIB::COLOR`);
  1374. result->pixel = 0;
  1375. result->flags = -1; /* Well set all flags .. just in case; */
  1376. /* in the .h files is something like do_{red,green,blue} ?! */
  1377. result->red = get_rgb_val (TheStructure (STACK_0)->recdata[1]);
  1378. result->green = get_rgb_val (TheStructure (STACK_0)->recdata[2]);
  1379. result->blue = get_rgb_val (TheStructure (STACK_0)->recdata[3]);
  1380. skipSTACK(1);
  1381. }
  1382. static object make_color (XColor *color)
  1383. {
  1384. pushSTACK(`(XLIB::COLOR)`); pushSTACK(fixnum(4));
  1385. funcall(L(make_structure),2); pushSTACK(value1);
  1386. TheStructure(STACK_0)->recdata[1] = make_rgb_val (color->red); /* red */
  1387. TheStructure(STACK_0)->recdata[2] = make_rgb_val (color->green); /* green */
  1388. TheStructure(STACK_0)->recdata[3] = make_rgb_val (color->blue); /* blue */
  1389. return popSTACK();
  1390. }
  1391. /* general_plist_reader (type) -- used by the various xxx-plist functions
  1392. > type the type the argument should have
  1393. > STACK_0 the object in question */
  1394. static void general_plist_reader (object type)
  1395. { /* the XLIB object in question is already on the stack */
  1396. if (typep_classname (STACK_0, type)) {
  1397. pushSTACK(`XLIB::PLIST`);
  1398. funcall(L(slot_value), 2);
  1399. } else my_type_error(type,STACK_0);
  1400. }
  1401. /* general_plist_writer (type) -- used by the various xxx-plist functions
  1402. > type the type the argument should have
  1403. > STACK_1 the object in question
  1404. > STACK_0 the new value for plist */
  1405. static void general_plist_writer (object type)
  1406. { /* the XLIB object and the new value are already on the stack */
  1407. if (typep_classname (STACK_1, type)) {
  1408. object new_value = popSTACK();
  1409. pushSTACK(`XLIB::PLIST`); /* the slot */
  1410. pushSTACK(new_value); /* new value */
  1411. funcall (L(set_slot_value), 3);
  1412. } else my_type_error(type,STACK_0);
  1413. }
  1414. static void general_lookup (object type)
  1415. {
  1416. XID xid = get_uint29 (STACK_0);
  1417. if (!ensure_living_display (&(STACK_1)))
  1418. error_closed_display(TheSubr(subr_self)->name,STACK_1);
  1419. VALUES1(make_xid_obj_2 (type, STACK_1, xid, NIL));
  1420. skipSTACK(2);
  1421. }
  1422. /* in STANDARD_XID_OBJECT_LOOK & STANDARD_PTR_OBJECT_LOOK the L argument
  1423. is just the upcase of c, CPP cannot do that and we will defer resolving
  1424. this until util/ccmp2c.c is merged into util/modprep.lisp */
  1425. /* Defines xxx-{DISPLAY,PLIST,SET-PLIST,P,EQUAL,ID}
  1426. and LOOKUP-xxx for xid objects */
  1427. ##define STANDARD_XID_OBJECT_LOOK(L,c) \
  1428. DEFUN(XLIB:##L##-DISPLAY,xxx) \
  1429. { VALUES1(get_display_obj_tc(`XLIB::##L`, popSTACK())); } \
  1430. DEFUN(XLIB:##L##-PLIST,xxx) \
  1431. { general_plist_reader (`XLIB::##L`); } \
  1432. DEFUN(XLIB:SET-##L##-PLIST,xxx plist) \
  1433. { general_plist_writer (`XLIB::##L`); } \
  1434. DEFUN(XLIB:##L##-P,xxx) \
  1435. { VALUES_IF(c##_p (popSTACK())); } \
  1436. DEFUN(XLIB:##L##-ID,xxx) \
  1437. { VALUES1(make_uint29((XID)get_##c (popSTACK()))); } \
  1438. DEFUN(XLIB:##L##-EQUAL,xxx yyy) \
  1439. { VALUES_IF(get_##c (popSTACK()) == get_##c (popSTACK())); } \
  1440. DEFUN(XLIB:LOOKUP-##L,display xxx) \
  1441. { general_lookup (`XLIB::##L##`); }
  1442. /* Defines xxx-{DISPLAY,PLIST,SET-PLIST,P,EQUAL}
  1443. However xxx-ID and LOOKUP-xxx are not defined, since the way to
  1444. get the xid and looking it up differs between ptr objects */
  1445. ##define STANDARD_PTR_OBJECT_LOOK(L,c) \
  1446. DEFUN(XLIB:##L##-DISPLAY,display) \
  1447. { VALUES1(get_display_obj_tc(`XLIB::##L`, popSTACK())); } \
  1448. DEFUN(XLIB:##L##-PLIST,xxx) \
  1449. { general_plist_reader (`XLIB::##L`); } \
  1450. DEFUN(XLIB:SET-##L##-PLIST,xxx plist) \
  1451. { general_plist_writer (`XLIB::##L`); } \
  1452. DEFUN(XLIB:##L##-P,xxx) \
  1453. { VALUES_IF(c##_p (popSTACK())); } \
  1454. DEFUN(XLIB:##L##-EQUAL,xxx yyy) \
  1455. { VALUES_IF(get_##c (popSTACK()) == get_##c (popSTACK())); }
  1456. /* -----------------------------------------------------------------------
  1457. * Chapter 1 Data Types
  1458. * ----------------------------------------------------------------------- */
  1459. STANDARD_XID_OBJECT_LOOK(WINDOW,window)
  1460. STANDARD_XID_OBJECT_LOOK(PIXMAP,pixmap)
  1461. STANDARD_XID_OBJECT_LOOK(DRAWABLE,drawable)
  1462. STANDARD_XID_OBJECT_LOOK(FONT,font)
  1463. STANDARD_XID_OBJECT_LOOK(COLORMAP,colormap)
  1464. STANDARD_XID_OBJECT_LOOK(CURSOR,cursor)
  1465. STANDARD_PTR_OBJECT_LOOK(GCONTEXT,gcontext)
  1466. DEFUN(XLIB:MAKE-EVENT-KEYS, event)
  1467. { VALUES1(check_event_mask_to_list(get_uint32(popSTACK()))); }
  1468. DEFUN(XLIB:MAKE-EVENT-MASK,&rest keys)
  1469. {
  1470. unsigned long mask = 0;
  1471. while (argcount--) mask |= check_event_mask(popSTACK());
  1472. VALUES1(make_uint32(mask));
  1473. }
  1474. DEFUN(XLIB:MAKE-STATE-KEYS, event)
  1475. { VALUES1(check_modifier_to_list(get_uint16(popSTACK()))); }
  1476. DEFUN(XLIB:MAKE-STATE-MASK, &rest args)
  1477. {
  1478. unsigned int mask = 0;
  1479. while (argcount--) mask |= check_modifier(popSTACK());
  1480. VALUES1(make_uint16(mask));
  1481. }
  1482. /* -----------------------------------------------------------------------
  1483. * Chapter 2 Displays
  1484. * ----------------------------------------------------------------------- */
  1485. int xlib_error_handler (Display*, XErrorEvent*);
  1486. int xlib_io_error_handler (Display*);
  1487. static Display *x_open_display (char* display_name, int display_number) {
  1488. Display *dpy;
  1489. /* On one hand fetching the DISPLAY variable if in doubt is a nice
  1490. feature -- on the other hand does it conform to the CLX documentation? */
  1491. if (!display_name)
  1492. X_CALL(display_name = getenv ("DISPLAY"));
  1493. if (!display_name) { /* Which display should we open?! */
  1494. pushSTACK(TheSubr(subr_self)->name); /* function name */
  1495. error(error_condition,("~S: Do not know which display to open."));
  1496. }
  1497. {
  1498. int len = asciz_length (display_name);
  1499. DYNAMIC_ARRAY (cname, char, len + 5);
  1500. begin_x_call();
  1501. /* install the error handlers before XOpenDisplay to catch errors there */
  1502. XSetErrorHandler (xlib_error_handler);
  1503. XSetIOErrorHandler (xlib_io_error_handler);
  1504. if (strchr(display_name,':'))
  1505. strcpy(cname, display_name);
  1506. else
  1507. sprintf(cname, "%s:%d",display_name,display_number);
  1508. dpy = XOpenDisplay (cname);
  1509. end_x_call();
  1510. if (!dpy) {
  1511. pushSTACK(asciz_to_string(cname,GLO(misc_encoding))); /* display name */
  1512. pushSTACK(TheSubr(subr_self)->name); /* function name */
  1513. error(error_condition,("~S: Cannot open display ~S.")); /* raise error */
  1514. }
  1515. FREE_DYNAMIC_ARRAY (cname);
  1516. }
  1517. return dpy;
  1518. }
  1519. DEFUN(XLIB:OPEN-DISPLAY, &rest args)
  1520. { /* (XLIB:OPEN-DISPLAY host &key :display &allow-other-keys) */
  1521. int display_number = 0; /* the display number */
  1522. Display *dpy;
  1523. gcv_object_t *display_arg = NULL;
  1524. if (argcount % 2 != 1) error_key_odd(argcount,TheSubr(subr_self)->name);
  1525. if (argcount > 0) {
  1526. pushSTACK(STACK_(argcount-1)); /* the first argument */
  1527. if (!nullp(STACK_0) && !stringp(STACK_0))
  1528. my_type_error(`(OR NULL STRING)`,STACK_0);
  1529. else display_arg = &STACK_(argcount);
  1530. skipSTACK(1);
  1531. }
  1532. { /* Fetch an optional :DISPLAY argument */
  1533. uintC i;
  1534. for (i = 1; i < argcount ; i += 2)
  1535. if (eq (STACK_(i), `:DISPLAY`)) {
  1536. /* keyword found; value is in STACK_(i-1) */
  1537. display_number = get_uint8 (STACK_(i-1));
  1538. break;
  1539. }
  1540. }
  1541. if (display_arg) {
  1542. with_string_0(*display_arg,GLO(misc_encoding),displayz,
  1543. { dpy = x_open_display(displayz,display_number); });
  1544. } else dpy = x_open_display(NULL,display_number);
  1545. VALUES1(make_display(dpy, display_number));
  1546. skipSTACK(argcount);
  1547. }
  1548. static Xauth * my_xau_get_auth_by_name (char *dpy_name) {
  1549. char *s = dpy_name;
  1550. int len = strlen(dpy_name);
  1551. while (*s && *s != ':') s++;
  1552. if (*s == ':') {
  1553. int addr_len = s-dpy_name;
  1554. return XauGetAuthByAddr(AF_INET,addr_len,dpy_name,
  1555. len-addr_len-1,s+1,len,dpy_name);
  1556. } else return XauGetAuthByAddr(AF_INET,0,"",len,dpy_name,len,dpy_name);
  1557. }
  1558. DEFUN(XLIB:DISPLAY-AUTHORIZATION, display) /* OK */
  1559. {
  1560. Display *dpy = pop_display ();
  1561. Xauth *auth;
  1562. X_CALL(auth = my_xau_get_auth_by_name(DisplayString(dpy)));
  1563. if (auth) {
  1564. pushSTACK(fixnum(auth->family));
  1565. # define PUSH(n) pushSTACK(n_char_to_string(auth->n,auth->n##_length, \
  1566. GLO(misc_encoding)))
  1567. PUSH(address); PUSH(number); PUSH(name); PUSH(data);
  1568. # undef PUSH
  1569. STACK_to_mv(5);
  1570. X_CALL(XauDisposeAuth(auth));
  1571. } else VALUES0;
  1572. }
  1573. DEFUN(XLIB:DISPLAY-AUTHORIZATION-DATA, display) /* OK */
  1574. {
  1575. Display *dpy = pop_display ();
  1576. Xauth *auth;
  1577. X_CALL(auth = my_xau_get_auth_by_name(DisplayString(dpy)));
  1578. if (auth) {
  1579. VALUES1(n_char_to_string(auth->data,auth->data_length,GLO(misc_encoding)));
  1580. X_CALL(XauDisposeAuth(auth));
  1581. } else VALUES1(`""`);
  1582. }
  1583. DEFUN(XLIB:DISPLAY-AUTHORIZATION-NAME, display) /* OK */
  1584. {
  1585. Display *dpy = pop_display ();
  1586. Xauth *auth;
  1587. X_CALL(auth = my_xau_get_auth_by_name(DisplayString(dpy)));
  1588. if (auth) {
  1589. VALUES1(n_char_to_string(auth->name,auth->name_length,GLO(misc_encoding)));
  1590. X_CALL(XauDisposeAuth(auth));
  1591. } else VALUES1(`""`);
  1592. }
  1593. DEFUN(XLIB:DISPLAY-BITMAP-FORMAT, display) /* OK */
  1594. {
  1595. Display *dpy = pop_display ();
  1596. pushSTACK(`(XLIB::BITMAP-FORMAT)`); pushSTACK(fixnum(4));
  1597. funcall(L(make_structure),2); pushSTACK(value1);
  1598. TheStructure (STACK_0)->recdata[1] = fixnum(BitmapUnit(dpy)); /* unit slot */
  1599. TheStructure (STACK_0)->recdata[2] = fixnum(BitmapPad (dpy)); /* pad slot */
  1600. TheStructure (STACK_0)->recdata[3] =
  1601. (BitmapBitOrder (dpy) == LSBFirst ? T : NIL); /* lsb-first-p slot */
  1602. VALUES1(popSTACK());
  1603. }
  1604. DEFUN(XLIB:NO-OPERATION, display) {
  1605. Display *dpy = pop_display ();
  1606. int ret;
  1607. X_CALL(ret = XNoOp(dpy));
  1608. VALUES1(sint_to_I(ret));
  1609. }
  1610. DEFUN(XLIB:DISPLAY-BYTE-ORDER, display) /* OK */
  1611. {
  1612. skipSTACK(1);
  1613. /* To my knowlegde the libX11 opens the display in the local byte sex ... */
  1614. VALUES1((BIG_ENDIAN_P) ? `:MSBFIRST` : `:LSBFIRST`);
  1615. }
  1616. DEFUN(XLIB:DISPLAY-DISPLAY, display) { /* OK */
  1617. ensure_living_display (&(STACK_0));
  1618. VALUES1(TheStructure (STACK_0)->recdata[slot_DISPLAY_DISPLAY]);
  1619. skipSTACK(1);
  1620. }
  1621. DEFUN(XLIB:DISPLAY-ERROR-HANDLER, display) /* OK */
  1622. {
  1623. ensure_living_display (&(STACK_0));
  1624. VALUES1(TheStructure (STACK_0)->recdata[slot_DISPLAY_ERROR_HANDLER]);
  1625. skipSTACK(1);
  1626. }
  1627. DEFUN(XLIB:SET-DISPLAY-ERROR-HANDLER, display handler) /* OK */
  1628. {
  1629. ensure_living_display (&(STACK_1));
  1630. VALUES1(TheStructure(STACK_1)->recdata[slot_DISPLAY_ERROR_HANDLER]=STACK_0);
  1631. skipSTACK(2);
  1632. }
  1633. DEFUN(XLIB:DISPLAY-IMAGE-LSB-FIRST-P, display) /* OK */
  1634. {
  1635. VALUES_IF(ImageByteOrder (pop_display ()) == LSBFirst);
  1636. }
  1637. DEFUN(XLIB:DISPLAY-KEYCODE-RANGE, display) /* OK */
  1638. {
  1639. int max_kc, min_kc;
  1640. Display *dpy = pop_display ();
  1641. X_CALL(XDisplayKeycodes (dpy, &min_kc, &max_kc));
  1642. VALUES2(fixnum(min_kc),fixnum(max_kc));
  1643. }
  1644. DEFUN(XLIB:DISPLAY-MAX-KEYCODE, display) /* OK */
  1645. {
  1646. funcall(``XLIB:DISPLAY-KEYCODE-RANGE``,1);
  1647. value1 = value2; mv_count = 1;
  1648. }
  1649. DEFUN(XLIB:DISPLAY-MIN-KEYCODE, display) /* OK */
  1650. {
  1651. funcall(``XLIB:DISPLAY-KEYCODE-RANGE``,1);
  1652. mv_count = 1;
  1653. }
  1654. DEFUN(XLIB:DISPLAY-MAX-REQUEST-LENGTH, display) /* OK */
  1655. {
  1656. Display *dpy = pop_display ();
  1657. long n;
  1658. X_CALL(n = XMaxRequestSize (dpy));
  1659. VALUES1(make_uint32(n));
  1660. }
  1661. DEFUN(XLIB::DISPLAY-EXTENDED-MAX-REQUEST-LENGTH, display) {
  1662. Display *dpy = pop_display ();
  1663. long n;
  1664. X_CALL(n = XExtendedMaxRequestSize (dpy));
  1665. VALUES1(make_uint32(n));
  1666. }
  1667. DEFUN(XLIB::DISPLAY-RESOURCE-MANAGER-STRING, display) {
  1668. Display *dpy = pop_display ();
  1669. char *s;
  1670. X_CALL(s = XResourceManagerString (dpy));
  1671. VALUES1(safe_to_string(s));
  1672. }
  1673. DEFUN(XLIB:DISPLAY-MOTION-BUFFER-SIZE, display) /* OK */
  1674. {
  1675. Display *dpy = pop_display ();
  1676. unsigned long n;
  1677. X_CALL(n = XDisplayMotionBufferSize (dpy));
  1678. VALUES1(make_uint32(n)); /* remeber pop_display pops */
  1679. }
  1680. DEFUN(XLIB:DISPLAY-P, display) /* OK */
  1681. { VALUES_IF(display_p (popSTACK())); }
  1682. DEFUN(XLIB:DISPLAY-PIXMAP-FORMATS, display) /* OK */
  1683. {
  1684. int cnt = 0;
  1685. int i;
  1686. Display *dpy = pop_display ();
  1687. XPixmapFormatValues *formats;
  1688. X_CALL(formats = XListPixmapFormats (dpy, &cnt));
  1689. for (i = 0; i < cnt; i++) {
  1690. pushSTACK(`(XLIB::PIXMAP-FORMAT)`); pushSTACK(fixnum(4));
  1691. funcall(L(make_structure),2); pushSTACK(value1);
  1692. TheStructure(STACK_0)->recdata[1] = fixnum(formats[i].depth);
  1693. TheStructure(STACK_0)->recdata[2] = fixnum(formats[i].bits_per_pixel);
  1694. TheStructure(STACK_0)->recdata[3] = fixnum(formats[i].scanline_pad);
  1695. }
  1696. if (formats)
  1697. X_CALL(XFree (formats));
  1698. VALUES1(listof(cnt));
  1699. }
  1700. DEFUN(XLIB:DISPLAY-PROTOCOL-MAJOR-VERSION, display) /* OK */
  1701. { VALUES1(fixnum(ProtocolVersion (pop_display()))); }
  1702. DEFUN(XLIB:DISPLAY-PROTOCOL-MINOR-VERSION, display) /* OK */
  1703. { VALUES1(fixnum(ProtocolRevision(pop_display()))); }
  1704. DEFUN(XLIB:DISPLAY-PROTOCOL-VERSION, display) /* OK */
  1705. {
  1706. Display *dpy = pop_display ();
  1707. VALUES2(fixnum(ProtocolVersion(dpy)),
  1708. fixnum(ProtocolRevision(dpy)));
  1709. }
  1710. static XID display_resource_base (Display *dpy);
  1711. DEFUN(XLIB:DISPLAY-RESOURCE-ID-BASE, display)
  1712. {
  1713. Display *dpy = pop_display();
  1714. VALUES1(make_uint29(display_resource_base(dpy)));
  1715. }
  1716. static XID display_resource_mask (Display *dpy);
  1717. DEFUN(XLIB:DISPLAY-RESOURCE-ID-MASK, display)
  1718. {
  1719. Display *dpy = pop_display();
  1720. VALUES1(make_uint29(display_resource_mask(dpy)));
  1721. }
  1722. DEFUN(XLIB:DISPLAY-ROOTS, display) /* OK */
  1723. {
  1724. Display *dpy;
  1725. int i;
  1726. int cnt;
  1727. pushSTACK(STACK_0);
  1728. dpy = pop_display (); /* retrieve display pointer */
  1729. cnt = ScreenCount (dpy); /* number of screens */
  1730. for (i = 0; i < cnt; i++) /* thru all screens */
  1731. pushSTACK(make_screen (STACK_(i), ScreenOfDisplay (dpy, i)));
  1732. VALUES1(listof(cnt)); /* cons`em together */
  1733. skipSTACK(1); /* cleanup and all done */
  1734. }
  1735. DEFUN(XLIB:DISPLAY-VENDOR, display) /* OK */
  1736. {
  1737. Display *dpy = pop_display ();
  1738. char *s = ServerVendor (dpy);
  1739. pushSTACK(safe_to_string(s));
  1740. pushSTACK(make_uint32 (VendorRelease (dpy)));
  1741. value2 = popSTACK();
  1742. value1 = popSTACK();
  1743. mv_count = 2;
  1744. }
  1745. DEFUN(XLIB:DISPLAY-VENDOR-NAME, display) /* OK */
  1746. { funcall(``XLIB:DISPLAY-VENDOR``,1); }
  1747. DEFUN(XLIB:DISPLAY-RELEASE-NUMBER, display) /* OK */
  1748. {
  1749. funcall(``XLIB:DISPLAY-VENDOR``,1);
  1750. value1 = value2; mv_count = 1;
  1751. }
  1752. DEFUN(XLIB::%DISPLAY-XID, display)
  1753. {
  1754. Display *dpy = pop_display ();
  1755. XID xid; X_CALL(xid = XAllocID(dpy));
  1756. VALUES1(make_uint29(xid));
  1757. }
  1758. DEFUN(XLIB:DISPLAY-XID, display)
  1759. { /* This functions returns a function to allocate new resource id's */
  1760. pop_display();
  1761. VALUES1(``XLIB::%DISPLAY-XID``);
  1762. }
  1763. DEFUN(XLIB::LOOKUP-RESOURCE-ID, display id) { /* used by RGB-COLORMAPS */
  1764. XID resource_id = get_uint29(popSTACK());
  1765. object ht = lookup_xid(popSTACK(),resource_id); /* set value1 if found */
  1766. if (!eq(ht,nullobj)) VALUES1(NIL); /* not found */
  1767. }
  1768. DEFUN(XLIB::SAVE-ID, display id resource) { /* used by CLUE */
  1769. XID resource_id = get_uint29(STACK_1);
  1770. STACK_2 = display_hash_table(STACK_2);
  1771. set_resource_id(&STACK_2,resource_id,&STACK_0);
  1772. VALUES1(STACK_0);
  1773. skipSTACK(3);
  1774. }
  1775. DEFUN(XLIB::DEALLOCATE-RESOURCE-ID, display id type) { /* used by CLUE */
  1776. XID resource_id = get_uint29(STACK_1);
  1777. STACK_2 = display_hash_table(STACK_2);
  1778. delete_resource_id(&STACK_2,resource_id); /* sets values */
  1779. skipSTACK(3);
  1780. }
  1781. DEFUN(XLIB::SET-GCONTEXT-DISPLAY, display gcontext) { /* used by CLUE */
  1782. Display *dpy_orig;
  1783. GC gcon = get_gcontext_and_display(STACK_0,&dpy_orig);
  1784. Display *dpy_new = get_display(STACK_1);
  1785. if (dpy_orig != dpy_new) {
  1786. pushSTACK(allocate_fpointer(dpy_orig));
  1787. pushSTACK(allocate_fpointer(dpy_new));
  1788. pushSTACK(STACK_3)/*gc*/; pushSTACK(STACK_3)/* dpy */;
  1789. pushSTACK(TheSubr(subr_self)->name);
  1790. error(error_condition,"~S: cannot change dpy of ~S to ~S (~S is not ~S)");
  1791. }
  1792. pushSTACK(STACK_0); /* GC */
  1793. pushSTACK(`XLIB::DISPLAY`); /* slot */
  1794. pushSTACK(STACK_3); /* dpy */
  1795. funcall(L(set_slot_value),3);
  1796. skipSTACK(2);
  1797. }
  1798. DEFUN(XLIB:DISPLAY-AFTER-FUNCTION, display) /* OK */
  1799. {
  1800. ensure_living_display (&(STACK_0));
  1801. VALUES1(TheStructure (STACK_0)->recdata[slot_DISPLAY_AFTER_FUNCTION]);
  1802. skipSTACK(1);
  1803. }
  1804. int xlib_after_function (Display *display);
  1805. DEFUN(XLIB:SET-DISPLAY-AFTER-FUNCTION, display after-function) /* OK */
  1806. { /* TODO - check for function type [Not very important since the
  1807. xlib_after_function should get this error.] */
  1808. object display = STACK_1;
  1809. Display *dpy = get_display(display);
  1810. TheStructure (display)->recdata[slot_DISPLAY_AFTER_FUNCTION] = STACK_0;
  1811. if (nullp (STACK_0)) {
  1812. X_CALL(XSetAfterFunction (dpy, NULL)); /* Q: Is that right?! */
  1813. } else {
  1814. X_CALL(XSetAfterFunction (dpy, xlib_after_function));
  1815. }
  1816. VALUES1(STACK_0);
  1817. skipSTACK(2);
  1818. }
  1819. DEFUN(XLIB:DISPLAY-FORCE-OUTPUT, display) /* OK */
  1820. {
  1821. Display *dpy = pop_display ();
  1822. X_CALL(XFlush(dpy));
  1823. VALUES1(NIL);
  1824. }
  1825. DEFUN(XLIB:DISPLAY-FINISH-OUTPUT, display) /* OK */
  1826. {
  1827. Display *dpy = pop_display ();
  1828. X_CALL(XSync (dpy, 0));
  1829. VALUES1(NIL);
  1830. }
  1831. DEFUN(XLIB:CLOSE-DISPLAY, display &key :ABORT) /* OK */
  1832. { /* We can do nothing meaningful with the :abort option ... or could we? */
  1833. /* if abort is NIL sync with display and remove the display from the
  1834. xlib::*displays* list. Destroy the hash table and to make sure that
  1835. not one single reference to an X object hinders all other from being
  1836. garbage collected [syncing is for fetching the errors now]
  1837. if abort is non-NIL do sync too, but do not report errors, which
  1838. could occur. */
  1839. Display *dpy;
  1840. skipSTACK(1); /* the :abort option */
  1841. dpy = get_display(STACK_0);
  1842. X_CALL(XCloseDisplay (dpy));
  1843. /* Now remove the display from the XLIB:*DISPLAYS* variable
  1844. FIXME we should cdr-down the hash table and mark all clx object known
  1845. as dead. */
  1846. Symbol_value(`XLIB::*DISPLAYS*`) =
  1847. deleteq(Symbol_value(`XLIB::*DISPLAYS*`),STACK_0);
  1848. /* mark the display as closed */
  1849. TheFpointer(TheStructure(STACK_0)->recdata[slot_DISPLAY_FOREIGN_POINTER])
  1850. ->fp_pointer = NULL;
  1851. VALUES1(popSTACK());
  1852. }
  1853. DEFUN(XLIB:DISPLAY-PLIST, display) /* OK */
  1854. {
  1855. ensure_living_display (&(STACK_0));
  1856. VALUES1(TheStructure (STACK_0)->recdata[slot_DISPLAY_PLIST]);
  1857. skipSTACK(1);
  1858. }
  1859. DEFUN(XLIB:SET-DISPLAY-PLIST, display plist) /* OK */
  1860. {
  1861. ensure_living_display (&(STACK_1));
  1862. VALUES1(TheStructure (STACK_1)->recdata[slot_DISPLAY_PLIST] = STACK_0);
  1863. skipSTACK(2);
  1864. }
  1865. DEFUN(XLIB:DISPLAY-DEFAULT-SCREEN, display) /* NIM / OK */
  1866. {
  1867. Display *dpy = get_display(STACK_0);
  1868. VALUES1(make_screen(STACK_0,DefaultScreenOfDisplay(dpy)));
  1869. skipSTACK(1);
  1870. }
  1871. DEFUN(XLIB::SET-DISPLAY-DEFAULT-SCREEN, display screen)
  1872. { /* accept integer (index) as well as object as screen */
  1873. Display *dpy = get_display(STACK_1);
  1874. int ns = ScreenCount(dpy), s=-1;
  1875. if (posfixnump(STACK_0)) { /* index */
  1876. s = fixnum_to_V(STACK_0);
  1877. if (s < 0 || s >= ns) {
  1878. pushSTACK(fixnum(s)); pushSTACK(fixnum(ns));
  1879. pushSTACK(TheSubr(subr_self)->name);
  1880. error(error_condition,"~S: ~S out of range [0;~S)");
  1881. }
  1882. } else {
  1883. Display *dpy1;
  1884. Screen *scr = get_screen_and_display (STACK_0, &dpy1);
  1885. if (dpy != dpy1) {
  1886. pushSTACK(STACK_1); /*dpy*/
  1887. pushSTACK(find_display(dpy1));
  1888. pushSTACK(STACK_2); /*scr*/
  1889. pushSTACK(TheSubr(subr_self)->name);
  1890. error(error_condition,"~S: ~S belongs to ~S, not to ~S");
  1891. }
  1892. s = XScreenNo(dpy,scr);
  1893. if (s == -1) {
  1894. pushSTACK(STACK_1); /*dpy*/
  1895. pushSTACK(STACK_1); /*scr*/
  1896. pushSTACK(TheSubr(subr_self)->name);
  1897. error(error_condition,"~S: ~S is not found in ~S");
  1898. }
  1899. }
  1900. DefaultScreen(dpy) = s;
  1901. VALUES1(fixnum(s));
  1902. skipSTACK(2);
  1903. }
  1904. DEFUN(XLIB:DISPLAY-NSCREENS, display) /* NIM */
  1905. { VALUES1(fixnum(ScreenCount(pop_display()))); }
  1906. DEFUN(XLIB:DISPLAY-INVOKE-AFTER-FUNCTION, display)
  1907. { /* XXX This function does not work at all -- it pushes the hash table
  1908. instead of the after function, but why? This one seems simply to
  1909. be a a hook to call the after_function
  1910. (funcall (display-after-function dpy) dpy) */
  1911. pushSTACK(STACK_0);
  1912. funcall(`XLIB::DISPLAY-AFTER-FUNCTION`,1);
  1913. funcall(value1,1);
  1914. }
  1915. DEFUN(XLIB:DISPLAY-HOST, display)
  1916. {
  1917. char *name = DisplayString (pop_display ());
  1918. char *s;
  1919. /* Hunt the ':' */
  1920. for (s = name; *s && *s!=':'; s++)
  1921. continue;
  1922. VALUES1(s == name ? ascii_to_string("localhost")
  1923. : n_char_to_string(name, s - name, GLO(misc_encoding)));
  1924. }
  1925. DEFUN(XLIB:DISPLAY-REPORT-ASYNCHRONOUS-ERRORS, display)
  1926. { /* This function is not actually specified in the CLX refman, but the
  1927. source code says something about it:
  1928. (def-clx-class (display (:include buffer) ..)
  1929. :
  1930. (report-asynchronous-errors ; When to report asynchronous errors
  1931. `(:immediately) :type list) ; The keywords that can be on this list
  1932. : ; are :IMMEDIATELY, :BEFORE-EVENT-HANDLING,
  1933. ) ; and :AFTER-FINISH-OUTPUT
  1934. */
  1935. skipSTACK(1);
  1936. VALUES1(`(:IMMEDIATELY)`); /* Well, em ... fake it! */
  1937. }
  1938. DEFUN(XLIB:SET-DISPLAY-REPORT-ASYNCHRONOUS-ERRORS, display value)
  1939. {
  1940. VALUES1(STACK_0);
  1941. skipSTACK(2);
  1942. }
  1943. DEFUN(XLIB:DISPLAY-TRACE, &rest args)
  1944. { /* I do not think I will support this function, since
  1945. - tracing seems not to be possible using the libX11
  1946. - It may even not be wanted by anybody...?!
  1947. BTW in the source of MIT-CLX (trace.lisp) I found a mark
  1948. that display-trace is an obsolete name. */
  1949. UNDEFINED;
  1950. }
  1951. /* -----------------------------------------------------------------------
  1952. * Chapter 3 Screens
  1953. * ----------------------------------------------------------------------- */
  1954. ##define DEF_SCREEN_PROP(lspnam, typ, cnam) \
  1955. DEFUN(lspnam, screen) { \
  1956. VALUES1(make_##typ(cnam(get_screen(popSTACK())))); \
  1957. }
  1958. DEF_SCREEN_PROP(XLIB:SCREEN-BLACK-PIXEL, uint32, BlackPixelOfScreen)
  1959. DEF_SCREEN_PROP(XLIB:SCREEN-WHITE-PIXEL, uint32, WhitePixelOfScreen)
  1960. DEF_SCREEN_PROP(XLIB:SCREEN-EVENT-MASK-AT-OPEN, uint32, EventMaskOfScreen)
  1961. DEF_SCREEN_PROP(XLIB:SCREEN-HEIGHT, sint16, HeightOfScreen)
  1962. DEF_SCREEN_PROP(XLIB:SCREEN-HEIGHT-IN-MILLIMETERS,sint16, HeightMMOfScreen)
  1963. DEF_SCREEN_PROP(XLIB:SCREEN-WIDTH, sint16, WidthOfScreen)
  1964. DEF_SCREEN_PROP(XLIB:SCREEN-WIDTH-IN-MILLIMETERS, sint16, WidthMMOfScreen)
  1965. DEF_SCREEN_PROP(XLIB:SCREEN-MAX-INSTALLED-MAPS, uint16, MaxCmapsOfScreen)
  1966. DEF_SCREEN_PROP(XLIB:SCREEN-MIN-INSTALLED-MAPS, uint16, MinCmapsOfScreen)
  1967. DEF_SCREEN_PROP(XLIB:SCREEN-ROOT-DEPTH, uint16, DefaultDepthOfScreen)
  1968. DEF_SCREEN_PROP(XLIB:SCREEN-ROOT-VISUAL, visual,DefaultVisualOfScreen)
  1969. DEF_SCREEN_PROP(XLIB:SCREEN-ROOT-VISUAL-INFO, visual_info,DefaultVisualOfScreen) /* NIM */
  1970. DEF_SCREEN_PROP(XLIB:SCREEN-SAVE-UNDERS-P, bool, DoesSaveUnders)
  1971. DEFUN(XLIB:SCREEN-BACKING-STORES, screen) /* OK */
  1972. {
  1973. int a = DoesBackingStore (get_screen (popSTACK()));
  1974. VALUES1((a == NotUseful) ? `:NEVER` : /* Why :NEVER but not :NOT-USEFUL?! */
  1975. (a == WhenMapped) ? `:WHEN-MAPPED` :
  1976. `:ALWAYS`);
  1977. }
  1978. DEFUN(XLIB:SCREEN-DEFAULT-COLORMAP, screen) /* OK */
  1979. {
  1980. VALUES1(make_colormap(get_display_obj(STACK_0),
  1981. DefaultColormapOfScreen(get_screen(STACK_0))));
  1982. skipSTACK(1);
  1983. }
  1984. DEFUN(XLIB:SCREEN-DEPTHS, screen)
  1985. {
  1986. Display *dpy;
  1987. Screen *scr = get_screen_and_display (STACK_0, &dpy);
  1988. int *depths;
  1989. int ndepths = 0;
  1990. int i;
  1991. int screen_number = XScreenNo(dpy,scr);
  1992. ASSERT(screen_number >= 0); /* we know that scr belongs to dpy */
  1993. X_CALL(depths = XListDepths (dpy, screen_number, &ndepths));
  1994. for (i = 0; i < ndepths; i++) {
  1995. XVisualInfo templeight, *visual_infos;
  1996. int n_visual_infos, j;
  1997. pushSTACK(make_uint8 (depths[i]));
  1998. /* Now enumerate the visual infos ... */
  1999. templeight.depth = depths[i];
  2000. n_visual_infos = 0;
  2001. X_CALL(visual_infos = XGetVisualInfo (dpy, VisualDepthMask, &templeight,
  2002. &n_visual_infos));
  2003. if (visual_infos) {
  2004. for (j = 0; j < n_visual_infos; j++)
  2005. pushSTACK(make_visual_info (visual_infos[j].visual));
  2006. X_CALL(XFree (visual_infos));
  2007. }
  2008. value1 = listof(n_visual_infos+1); /* cons `em up */
  2009. pushSTACK(value1);
  2010. }
  2011. /* Final cons */
  2012. VALUES1(listof(ndepths));
  2013. if (depths)
  2014. X_CALL(XFree (depths));
  2015. skipSTACK(1); /* all done */
  2016. }
  2017. DEFUN(XLIB:SCREEN-P, screen) /* OK */
  2018. {
  2019. VALUES_IF(screen_p (popSTACK()));
  2020. }
  2021. DEFUN(XLIB:SCREEN-PLIST, screen) /* OK */
  2022. {
  2023. general_plist_reader (`XLIB::SCREEN`);
  2024. }
  2025. DEFUN(XLIB:SET-SCREEN-PLIST, screen plist) /* OK */
  2026. {
  2027. general_plist_writer (`XLIB::SCREEN`);
  2028. }
  2029. DEFUN(XLIB:SCREEN-ROOT, screen) /* OK */
  2030. {
  2031. VALUES1(make_window(get_display_obj(STACK_0),
  2032. RootWindowOfScreen(get_screen(STACK_0))));
  2033. skipSTACK(1);
  2034. }
  2035. DEFUN(XLIB::SCREEN-RESOURCE-STRING, screen) {
  2036. Screen *screen = get_screen(popSTACK());
  2037. char *s;
  2038. X_CALL(s = XScreenResourceString(screen));
  2039. VALUES1(safe_to_string(s));
  2040. }
  2041. DEFUN(XLIB:VISUAL-INFO, display visual-id) /* NIM / OK */
  2042. {
  2043. VisualID vid;
  2044. Display *dpy = get_display(STACK_1);
  2045. Visual *visual;
  2046. vid = get_uint29 (STACK_0);
  2047. visual = XVisualIDToVisual (dpy, vid);
  2048. if (visual) {
  2049. VALUES1(make_visual_info (visual));
  2050. skipSTACK(2);
  2051. } else {
  2052. pushSTACK(STACK_1); /* display argument */
  2053. pushSTACK(STACK_1); /* visual id argument */
  2054. error(error_condition,"Visual info not found for id #~S in display ~S.");
  2055. }
  2056. }
  2057. /* After all, no SCREEN-EQUAL ? */
  2058. /* -----------------------------------------------------------------------
  2059. * Chapter 4 Windows and Pixmaps
  2060. * ----------------------------------------------------------------------- */
  2061. nonreturning_function(static, error_required_keywords, (object list)) {
  2062. pushSTACK(list); pushSTACK(TheSubr(subr_self)->name);
  2063. error(error_condition,"~S: At least ~S must be specified");
  2064. }
  2065. /* 4.1 Drawables */
  2066. /* 4.2 Creating Windows - 23 keys! */
  2067. DEFUN(XLIB:CREATE-WINDOW, &key WINDOW PARENT X Y WIDTH HEIGHT \
  2068. DEPTH BORDER-WIDTH CLASS VISUAL BACKGROUND BORDER BIT-GRAVITY GRAVITY \
  2069. BACKING-STORE BACKING-PLANES BACKING-PIXEL SAVE-UNDER EVENT-MASK \
  2070. DO-NOT-PROPAGATE-MASK OVERRIDE-REDIRECT COLORMAP CURSOR)
  2071. {
  2072. XSetWindowAttributes attr;
  2073. unsigned long valuemask = 0;
  2074. Visual *visual = CopyFromParent;
  2075. int c_class = CopyFromParent;
  2076. int border_width = 0;
  2077. int depth = CopyFromParent;
  2078. Window parent;
  2079. int x,y,width,height;
  2080. Display *dpy;
  2081. Window win;
  2082. #define SLOT(ofs, type, cslot, mask)\
  2083. if (!missingp(STACK_(ofs))) { attr.cslot = get_##type(STACK_(ofs)); valuemask |= mask; }
  2084. #if 0
  2085. SLOT ( 0, cursor, cursor, CWCursor);
  2086. SLOT ( 1, colormap, colormap, CWColormap);
  2087. SLOT ( 2, switch, override_redirect, CWOverrideRedirect);
  2088. SLOT ( 3, uint32, do_not_propagate_mask, CWDontPropagate);
  2089. SLOT ( 4, event_mask, event_mask, CWEventMask);
  2090. SLOT ( 5, switch, save_under, CWSaveUnder);
  2091. SLOT ( 6, uint32, backing_pixel, CWBackingPixel);
  2092. SLOT ( 7, uint32, backing_planes, CWBackingPlanes);
  2093. #endif
  2094. if (!missingp(STACK_0))
  2095. { attr.cursor = get_cursor(STACK_0); valuemask |= CWCursor; }
  2096. if (!missingp(STACK_1))
  2097. { attr.colormap = get_colormap (STACK_1); valuemask |= CWColormap; }
  2098. if (!missingp(STACK_2)) { attr.override_redirect = get_switch (STACK_2); valuemask |= CWOverrideRedirect; }
  2099. if (!missingp(STACK_3)) { attr.do_not_propagate_mask = get_uint32 (STACK_3); valuemask |= CWDontPropagate; }
  2100. if (!missingp(STACK_4)) { attr.event_mask = get_event_mask (STACK_4); valuemask |= CWEventMask; }
  2101. if (!missingp(STACK_5)) { attr.save_under = get_generic_switch (STACK_5); valuemask |= CWSaveUnder; }
  2102. if (!missingp(STACK_6)) { attr.backing_pixel = get_uint32 (STACK_6); valuemask |= CWBackingPixel; }
  2103. if (!missingp(STACK_7)) { attr.backing_planes = get_uint32 (STACK_7); valuemask |= CWBackingPlanes; }
  2104. if (!missingp(STACK_8)) { attr.backing_store = get_backing_store (STACK_8); valuemask |= CWBackingStore; }
  2105. if (!missingp(STACK_9)) { attr.win_gravity = get_gravity (STACK_9); valuemask |= CWWinGravity; }
  2106. if (!missingp(STACK_10)) { attr.bit_gravity = get_gravity (STACK_10); valuemask |= CWBitGravity; }
  2107. if (!missingp(STACK_(11))) { /* :border */
  2108. if (eq(STACK_(11),S(Kcopy))) {
  2109. attr.border_pixmap = CopyFromParent;
  2110. valuemask |= CWBorderPixmap;
  2111. } else if (pixmap_p (STACK_(11))) {
  2112. attr.border_pixmap = get_pixmap (STACK_(11));
  2113. valuemask |= CWBorderPixmap;
  2114. } else {
  2115. attr.border_pixel = get_uint32 (STACK_(11));
  2116. valuemask |= CWBorderPixel;
  2117. }
  2118. }
  2119. if (!missingp(STACK_(12))) { /* :background */
  2120. if (eq(STACK_(12), `:NONE`)) {
  2121. attr.background_pixmap = None;
  2122. valuemask |= CWBackPixmap;
  2123. } else if (eq(STACK_(12), `:PARENT-RELATIVE`)) {
  2124. attr.background_pixmap = ParentRelative;
  2125. valuemask |= CWBackPixmap;
  2126. } else if (pixmap_p (STACK_(12))) {
  2127. attr.background_pixmap = get_pixmap (STACK_(12));
  2128. valuemask |= CWBackPixmap;
  2129. } else {
  2130. attr.background_pixel = get_pixel (STACK_(12));
  2131. valuemask |= CWBackPixel;
  2132. }
  2133. }
  2134. if (!missingp(STACK_(14))) /* :class */
  2135. c_class = get_W_class (STACK_(14));
  2136. if (!missingp(STACK_(15))) /* :border-width */
  2137. border_width = get_uint16 (STACK_(15));
  2138. if (!missingp(STACK_(16))) /* :depth */
  2139. depth = get_uint16 (STACK_(16));
  2140. if (!missingp(STACK_(17))) /* :height */ /* C */
  2141. height = get_uint16 (STACK_(17));
  2142. else
  2143. goto required;
  2144. if (!missingp(STACK_(18))) /* :width */ /* C */
  2145. width = get_uint16 (STACK_(18));
  2146. else
  2147. goto required;
  2148. if (!missingp(STACK_(19))) /* :y */ /* C */
  2149. y = get_sint16 (STACK_(19));
  2150. else
  2151. goto required;
  2152. if (!missingp(STACK_(20))) /* :x */ /* C */
  2153. x = get_sint16 (STACK_(20));
  2154. else
  2155. goto required;
  2156. if (!missingp(STACK_(21))) { /* :parent */ /* C */
  2157. parent = get_window_and_display (STACK_(21), &dpy);
  2158. pushSTACK(get_display_obj (STACK_(21)));
  2159. } else
  2160. goto required;
  2161. if (!missingp(STACK_(13+1))) /* :visual */
  2162. visual = get_visual (dpy, STACK_(13+1));
  2163. if (!missingp(STACK_(23))) /* :window */ /* C */
  2164. pushSTACK(STACK_(23));
  2165. else
  2166. pushSTACK(NIL);
  2167. #undef SLOT
  2168. X_CALL(win = XCreateWindow (dpy, parent, x,y, width,height, border_width,
  2169. depth, c_class, visual, valuemask, &attr));
  2170. VALUES1(make_window_2 (STACK_1, win, STACK_0));
  2171. skipSTACK(23 + 2);
  2172. return;
  2173. required:
  2174. error_required_keywords(`(:X :Y :WIDTH :HEIGHT :PARENT)`);
  2175. }
  2176. ##define DEF_DRAWABLE_GEOM_GETTER(type, lspnam, attr) \
  2177. DEFUN(XLIB:DRAWABLE-##lspnam, window) { \
  2178. Window root; \
  2179. int x, y; \
  2180. unsigned int width, height; \
  2181. unsigned int border_width; \
  2182. unsigned int depth; \
  2183. Display *dpy; \
  2184. Drawable da = get_drawable_and_display (STACK_0, &dpy); \
  2185. X_CALL(XGetGeometry (dpy, da, \
  2186. &root, &x, &y, &width, &height, \
  2187. &border_width, &depth)); \
  2188. VALUES1(make_##type(attr)); \
  2189. skipSTACK(1); \
  2190. }
  2191. ##define DEF_SET_DRAWABLE_GEOM(type, lspnam, attr, mask) \
  2192. DEFUN(XLIB:SET-DRAWABLE-##lspnam##, window param) { \
  2193. XWindowChanges values; \
  2194. Window win; \
  2195. Display *dpy; \
  2196. /* Why window here vvvv and not drawable? */ \
  2197. win = get_window_and_display (STACK_1, &dpy); \
  2198. values.attr = get_##type (STACK_0); \
  2199. X_CALL(XConfigureWindow (dpy, win, mask, &values)); \
  2200. VALUES1(STACK_0); \
  2201. skipSTACK(2); \
  2202. }
  2203. ##define DEF_DRAWABLE_GEOM(type, lspnam, attr, mask) \
  2204. DEF_DRAWABLE_GEOM_GETTER (type, lspnam, attr) \
  2205. DEF_SET_DRAWABLE_GEOM (type, lspnam, attr, mask)
  2206. DEF_DRAWABLE_GEOM (uint16, BORDER-WIDTH, border_width, CWBorderWidth) /* OK */
  2207. DEF_DRAWABLE_GEOM_GETTER (uint8, DEPTH, depth) /* OK */
  2208. DEF_DRAWABLE_GEOM (uint16, HEIGHT, height, CWHeight) /* OK */
  2209. DEF_DRAWABLE_GEOM (uint16, WIDTH, width, CWWidth) /* OK */
  2210. DEF_DRAWABLE_GEOM (sint16, X, x, CWX) /* OK */
  2211. DEF_DRAWABLE_GEOM (sint16, Y, y, CWY) /* OK */
  2212. DEFUN(XLIB:WINDOW-ALL-EVENT-MASKS, window)
  2213. {
  2214. XWindowAttributes attr;
  2215. Display *dpy;
  2216. Window win = get_xid_object_and_display (`XLIB::WINDOW`, STACK_0, &dpy);
  2217. X_CALL(XGetWindowAttributes (dpy, win, &attr));
  2218. VALUES1(make_event_mask (attr.all_event_masks));
  2219. skipSTACK(1);
  2220. }
  2221. DEFUN(XLIB:SET-WINDOW-BACKGROUND, window background) /*OK*/
  2222. {
  2223. XSetWindowAttributes attr;
  2224. unsigned long valuemask = 0;
  2225. if (eq (STACK_0, `:NONE`)) {
  2226. attr.background_pixmap = None; valuemask |= CWBackPixmap;
  2227. } else if (eq (STACK_0, `:PARENT-RELATIVE`)) {
  2228. attr.background_pixmap = ParentRelative; valuemask |= CWBackPixmap;
  2229. } else if (pixmap_p (STACK_0)) {
  2230. attr.background_pixmap = get_pixmap (STACK_0); valuemask |= CWBackPixmap;
  2231. } else if (pixel_p (STACK_0)) {
  2232. attr.background_pixel = get_pixel (STACK_0); valuemask |= CWBackPixel;
  2233. } else my_type_error(`(OR XLIB::PIXMAP XLIB::PIXEL (EQL :NONE) (EQL :PARENT-RELATIVE))`,STACK_0);
  2234. {
  2235. Display *dpy;
  2236. Window win = get_xid_object_and_display (`XLIB::WINDOW`, STACK_1, &dpy);
  2237. X_CALL(XChangeWindowAttributes (dpy, win, valuemask, &attr));
  2238. }
  2239. VALUES1(STACK_0);
  2240. skipSTACK(2);
  2241. }
  2242. ##define DEF_WIN_ATTR_READER(lspnam,typ,slotget) \
  2243. DEFUN(XLIB:WINDOW-##lspnam, window) { \
  2244. XWindowAttributes attr; \
  2245. Display *dpy; \
  2246. Window win = get_xid_object_and_display (`XLIB::WINDOW`, STACK_0, &dpy); \
  2247. X_CALL(XGetWindowAttributes (dpy, win, &attr)); \
  2248. VALUES1(make_##typ (attr.slotget)); \
  2249. skipSTACK(1); \
  2250. }
  2251. ##define DEF_WIN_ATTR_READER_2(lspnam,typ,slotget) \
  2252. DEFUN(XLIB:WINDOW-##lspnam, window) { \
  2253. XWindowAttributes attr; \
  2254. Display *dpy; \
  2255. Window win = get_window_and_display (STACK_0, &dpy); \
  2256. X_CALL(XGetWindowAttributes (dpy, win, &attr)); \
  2257. VALUES1(make_##typ (get_display_obj (STACK_0),attr.slotget)); \
  2258. skipSTACK(1); \
  2259. }
  2260. ##define DEF_WIN_ATTR_WRITER(lspnam,typ,slotset,msk) \
  2261. DEFUN(XLIB:SET-WINDOW-##lspnam##, window attr) { \
  2262. XSetWindowAttributes attr; \
  2263. Display *dpy; \
  2264. Window win = get_window_and_display (STACK_1, &dpy); \
  2265. attr.slotset = get_##typ (STACK_0); \
  2266. X_CALL(XChangeWindowAttributes (dpy, win, msk, &attr)); \
  2267. VALUES1(STACK_0); \
  2268. skipSTACK(2); \
  2269. }
  2270. ##define DEF_WIN_ATTR(lspnam, typ, slotget, slotset, msk) \
  2271. DEF_WIN_ATTR_READER(lspnam, typ, slotget) \
  2272. DEF_WIN_ATTR_WRITER(lspnam, typ, slotset, msk)
  2273. ##define DEF_WIN_ATTR_2(lspnam, typ, slotget, slotset, msk) \
  2274. DEF_WIN_ATTR_READER_2(lspnam, typ, slotget) \
  2275. DEF_WIN_ATTR_WRITER(lspnam, typ, slotset, msk)
  2276. DEF_WIN_ATTR (BACKING-PIXEL, uint32, backing_pixel, backing_pixel, CWBackingPixel)
  2277. DEF_WIN_ATTR (BACKING-PLANES, uint32, backing_planes, backing_planes, CWBackingPlanes)
  2278. DEF_WIN_ATTR (BIT-GRAVITY, gravity, bit_gravity, bit_gravity, CWBitGravity)
  2279. DEF_WIN_ATTR (GRAVITY, gravity, win_gravity, win_gravity, CWWinGravity)
  2280. DEF_WIN_ATTR (EVENT-MASK, event_mask, your_event_mask, event_mask, CWEventMask)
  2281. DEF_WIN_ATTR (OVERRIDE-REDIRECT, switch, override_redirect, override_redirect, CWOverrideRedirect)
  2282. DEF_WIN_ATTR (BACKING-STORE, backing_store, backing_store, backing_store, CWBackingStore)
  2283. DEF_WIN_ATTR (DO-NOT-PROPAGATE-MASK, event_mask, do_not_propagate_mask, do_not_propagate_mask, CWDontPropagate)
  2284. DEF_WIN_ATTR (SAVE-UNDER, generic_switch, save_under, save_under, CWSaveUnder)
  2285. DEF_WIN_ATTR_2 (COLORMAP, colormap, colormap, colormap, CWColormap)
  2286. DEF_WIN_ATTR_WRITER (CURSOR, cursor, cursor, CWCursor)
  2287. DEF_WIN_ATTR_READER (MAP-STATE, map_state, map_state)
  2288. #ifdef __cplusplus
  2289. DEF_WIN_ATTR_READER (CLASS, W_class, c_class)
  2290. #else
  2291. DEF_WIN_ATTR_READER (CLASS, W_class, class)
  2292. #endif
  2293. DEF_WIN_ATTR_READER (COLORMAP-INSTALLED-P, bool, map_installed)
  2294. DEF_WIN_ATTR_READER (VISUAL, visual, visual)
  2295. DEF_WIN_ATTR_READER (VISUAL-INFO, visual_info, visual)/* NIM */
  2296. DEFUN(XLIB:WINDOW-CURSOR, window)
  2297. {
  2298. pushSTACK(`XLIB::WINDOW-CURSOR`);
  2299. error(error_condition,"~S can only be set");
  2300. }
  2301. DEFUN(XLIB:SET-WINDOW-BORDER, arg1 arg2)
  2302. {
  2303. Display *dpy;
  2304. Window win = get_window_and_display (STACK_1, &dpy);
  2305. XSetWindowAttributes attr;
  2306. unsigned long value_mask = 0;
  2307. if (eq (STACK_0,S(Kcopy))) {
  2308. attr.border_pixmap = CopyFromParent; value_mask = CWBorderPixmap;
  2309. } else if (pixmap_p (STACK_0)) {
  2310. attr.border_pixmap = get_pixmap (STACK_0); value_mask = CWBorderPixmap;
  2311. } else if (pixel_p (STACK_0)) {
  2312. attr.border_pixel = get_pixel (STACK_0); value_mask = CWBorderPixel;
  2313. } else my_type_error(`(OR XLIB::PIXMAP XLIB::PIXEL (EQL :COPY))`,STACK_0);
  2314. X_CALL(XChangeWindowAttributes (dpy, win, value_mask, &attr));
  2315. VALUES1(STACK_0);
  2316. skipSTACK(2); /* all done */
  2317. }
  2318. /* (setf (XLIB:SET-WINDOW-PRIORITY window &optional sibling) mode) */
  2319. DEFUN(XLIB:SET-WINDOW-PRIORITY, mode window &optional sibling)
  2320. {
  2321. XWindowChanges changes;
  2322. unsigned int value_mask = 0;
  2323. Display *dpy;
  2324. Window win = get_window_and_display (STACK_1, &dpy);
  2325. if (!missingp(STACK_0)) {
  2326. changes.sibling = get_window (STACK_0); value_mask |= CWSibling;
  2327. }
  2328. changes.stack_mode = get_stack_mode (STACK_2); value_mask |= CWStackMode;
  2329. X_CALL(XConfigureWindow (dpy, win, value_mask, &changes));
  2330. VALUES1(STACK_2);
  2331. skipSTACK(3); /* all done */
  2332. }
  2333. /* 4.4 Stacking Order */
  2334. DEFUN(XLIB:CIRCULATE-WINDOW-DOWN, window)
  2335. {
  2336. Display *dpy;
  2337. Window win = get_window_and_display (STACK_0, &dpy);
  2338. X_CALL(XCirculateSubwindowsDown (dpy, win));
  2339. VALUES1(popSTACK());
  2340. }
  2341. DEFUN(XLIB:CIRCULATE-WINDOW-UP, window)
  2342. {
  2343. Display *dpy;
  2344. Window win = get_window_and_display (STACK_0, &dpy);
  2345. X_CALL(XCirculateSubwindowsUp (dpy, win));
  2346. VALUES1(popSTACK());
  2347. }
  2348. /* 4.5 Window Hierachy */
  2349. DEFUN(XLIB:DRAWABLE-ROOT, window)
  2350. {
  2351. Window root;
  2352. Drawable da;
  2353. Display *dpy;
  2354. int x, y;
  2355. unsigned int width, height, border_width, depth;
  2356. da = get_drawable_and_display (STACK_0, &dpy);
  2357. X_CALL(XGetGeometry (dpy, da, &root, &x, &y, &width, &height,
  2358. &border_width, &depth));
  2359. VALUES1(make_window (get_display_obj (STACK_0), root));
  2360. skipSTACK(1);
  2361. }
  2362. /* can trigger GC */
  2363. static object coerce_result_type (unsigned int stack_count,
  2364. gcv_object_t *result_type)
  2365. { /* there are stack_count objects on the STACK, which will be removed
  2366. and collected into a sequence of type *result_type */
  2367. if (eq(*result_type,S(list)) || missingp(*result_type))
  2368. return listof(stack_count);
  2369. else {
  2370. object vec = vectorof(stack_count);
  2371. if (!eq(*result_type,S(vector))) {
  2372. pushSTACK(vec); pushSTACK(*result_type);
  2373. funcall(L(coerce),2);
  2374. return value1;
  2375. } else return vec;
  2376. }
  2377. }
  2378. DEFUN(XLIB:QUERY-TREE, window &key RESULT-TYPE)
  2379. {
  2380. Window win;
  2381. Display *dpy;
  2382. gcv_object_t *dpy_objf, *res_type = &STACK_0;
  2383. Window root;
  2384. Window parent;
  2385. Window *childs;
  2386. unsigned int nchilds, i;
  2387. int status;
  2388. win = get_window_and_display (STACK_1, &dpy);
  2389. pushSTACK(get_display_obj (STACK_1));
  2390. dpy_objf = &(STACK_0);
  2391. X_CALL(status = XQueryTree(dpy,win,&root,&parent,&childs,&nchilds));
  2392. if (status) {
  2393. /* Now push all childrens */
  2394. for (i = 0; i < nchilds; i++)
  2395. pushSTACK(make_window (*dpy_objf, childs[i]));
  2396. if (childs) X_CALL(XFree(childs));
  2397. /* Now cons 'em together */
  2398. value1 = coerce_result_type(nchilds,res_type);
  2399. pushSTACK(value1);
  2400. pushSTACK(make_window (*dpy_objf, parent));
  2401. pushSTACK(make_window (*dpy_objf, root));
  2402. value3 = popSTACK();
  2403. value2 = popSTACK();
  2404. value1 = popSTACK();
  2405. mv_count = 3;
  2406. } else {
  2407. VALUES1(NIL);
  2408. }
  2409. skipSTACK(3);
  2410. }
  2411. DEFUN(XLIB:REPARENT-WINDOW, window1 window2 x y)
  2412. {
  2413. Display *dpy;
  2414. Window win = get_window_and_display (STACK_3, &dpy);
  2415. Window win2 = get_window (STACK_2);
  2416. int x = get_sint16 (STACK_1);
  2417. int y = get_sint16 (STACK_0);
  2418. X_CALL(XReparentWindow (dpy, win, win2, x, y));
  2419. skipSTACK(4);
  2420. value1= NIL; mv_count = 1;
  2421. }
  2422. DEFUN(XLIB:TRANSLATE-COORDINATES, src src-x src-y dst)
  2423. {
  2424. int x,y;
  2425. Window child;
  2426. Window src, dest;
  2427. int src_x, src_y;
  2428. Display *dpy;
  2429. int r;
  2430. src = get_xid_object_and_display (`XLIB::WINDOW`, STACK_3, &dpy);
  2431. dest = get_window (STACK_0);
  2432. src_x = get_sint16 (STACK_2);
  2433. src_y = get_sint16 (STACK_1);
  2434. X_CALL(r = XTranslateCoordinates (dpy, src, dest, src_x, src_y,
  2435. &x, &y, &child));
  2436. if (r) {
  2437. pushSTACK(make_sint16 (x));
  2438. pushSTACK(make_sint16 (y));
  2439. pushSTACK(make_window (get_display_obj (STACK_5), child));
  2440. value3 = popSTACK();
  2441. value2 = popSTACK();
  2442. value1 = popSTACK();
  2443. mv_count = 3;
  2444. } else
  2445. VALUES3(NIL,NIL,NIL);
  2446. skipSTACK(4);
  2447. }
  2448. /* 4.6 Mapping Windows */
  2449. DEFUN(XLIB:MAP-WINDOW, window)
  2450. {
  2451. Display *dpy;
  2452. Window win = get_window_and_display (STACK_0, &dpy);
  2453. X_CALL(XMapWindow (dpy, win));
  2454. skipSTACK(1);
  2455. VALUES1(NIL);
  2456. }
  2457. DEFUN(XLIB:MAP-SUBWINDOWS, window)
  2458. {
  2459. Display *dpy;
  2460. Window win = get_window_and_display (STACK_0, &dpy);
  2461. X_CALL(XMapSubwindows (dpy, win));
  2462. skipSTACK(1);
  2463. VALUES1(NIL);
  2464. }
  2465. DEFUN(XLIB:UNMAP-WINDOW, window)
  2466. {
  2467. Display *dpy;
  2468. Window win = get_window_and_display (STACK_0, &dpy);
  2469. X_CALL(XUnmapWindow (dpy, win));
  2470. skipSTACK(1);
  2471. VALUES1(NIL);
  2472. }
  2473. DEFUN(XLIB:UNMAP-SUBWINDOWS, window)
  2474. {
  2475. Display *dpy;
  2476. Window win = get_window_and_display (STACK_0, &dpy);
  2477. X_CALL(XUnmapSubwindows (dpy, win));
  2478. skipSTACK(1);
  2479. VALUES1(NIL);
  2480. }
  2481. /* 4.7 Destroying Windows */
  2482. DEFUN(XLIB:DESTROY-WINDOW, window)
  2483. {
  2484. Display *dpy;
  2485. Window win = get_window_and_display (STACK_0, &dpy);
  2486. X_CALL(XDestroyWindow (dpy, win));
  2487. skipSTACK(1);
  2488. VALUES1(NIL);
  2489. }
  2490. DEFUN(XLIB:DESTROY-SUBWINDOWS, window)
  2491. {
  2492. Display *dpy;
  2493. Window win = get_window_and_display (STACK_0, &dpy);
  2494. X_CALL(XDestroySubwindows (dpy, win));
  2495. skipSTACK(1);
  2496. VALUES1(NIL);
  2497. }
  2498. /* 4.8 Pixmaps */
  2499. DEFUN(XLIB:CREATE-PIXMAP, &key PIXMAP WIDTH HEIGHT DEPTH DRAWABLE)
  2500. {
  2501. Display *dpy;
  2502. Drawable da;
  2503. Pixmap pm;
  2504. int width,height,depth;
  2505. if (!boundp(STACK_0) || !boundp(STACK_1) ||
  2506. !boundp(STACK_2) || !boundp(STACK_3))
  2507. NOTIMPLEMENTED;
  2508. da = get_drawable_and_display (STACK_0, &dpy);
  2509. width = get_uint16 (STACK_3); /* actually uint15! */
  2510. height = get_uint16 (STACK_2);
  2511. depth = get_uint16 (STACK_1);
  2512. X_CALL(pm = XCreatePixmap (dpy, da, width, height, depth));
  2513. VALUES1(make_pixmap_2(get_display_obj(STACK_0),pm,
  2514. (!missingp(STACK_4) ? (object)STACK_4 : NIL)));
  2515. skipSTACK(5);
  2516. return;
  2517. }
  2518. DEFUN(XLIB:FREE-PIXMAP, pixmap)
  2519. {
  2520. Display *dpy;
  2521. Pixmap pix = get_pixmap_and_display (STACK_0, &dpy);
  2522. X_CALL(XFreePixmap (dpy, pix));
  2523. skipSTACK(1);
  2524. VALUES1(NIL);
  2525. }
  2526. /* -----------------------------------------------------------------------
  2527. * Chapter 5 Graphics Contexts
  2528. * ----------------------------------------------------------------------- */
  2529. /* Since libX does not allow to retrieve the clip-mask or the dashes list any
  2530. how, we save the clip-mask and dashes-list in the gcontext instance extra.
  2531. DASHES-LIST is stored in the additional slot xlib::%dashes and is
  2532. represented as a single uint8 or as a simple vector of uint8's.
  2533. (This allowes us to pass the vector directly into the C routine if
  2534. needed.) However this value could be NIL, then the C rep is suffient.
  2535. FLAME -- I find me always fixing the flaws of the narrow-minded C people,
  2536. not capable of defining any clean and consistent interface. Even worse,
  2537. yesterday I spend a couple of hours of debugging just to recognize, that the
  2538. malloc implmentation of the default Linux libc (version 5.3.9 and up [Yes,
  2539. 5.4.7 is even worse]!) is now broken, it messed up *my* memory. (I
  2540. considered it all the time working). I have the strange feeling that the
  2541. more popular Linux becomes the more broken it gets. I want the old days
  2542. back, where only a couple of people messed around with Linux, knowing what
  2543. they do.
  2544. [Ya, back to the 0.96 days (or was it 0.98?), I had only 8MB ram (and ~80MB
  2545. hd) and it was just smooth flying under X; The feeling you get when driving
  2546. an empty 'Autobahn' with a capable car at moderate speed, just smooth,
  2547. effient and relaxing].
  2548. Also the manual says (somewhat foggy):
  2549. Changing the dash-offset or dash-list overrides any previous XSetDashes
  2550. request on the context. The order in which components ... and bla bla
  2551. Maybe have also to save the dash-offset? */
  2552. /* 5.2 Creating Graphics Contexts -- 26 keys*/
  2553. DEFUN(XLIB:CREATE-GCONTEXT, &key DRAWABLE FUNCTION PLANE-MASK FOREGROUND \
  2554. BACKGROUND LINE-WIDTH LINE-STYLE CAP-STYLE JOIN-STYLE FILL-STYLE \
  2555. FILL-RULE ARC-MODE TILE STIPPLE TS-X TS-Y FONT SUBWINDOW-MODE \
  2556. EXPOSURES CLIP-X CLIP-Y CLIP-MASK CLIP-ORDERING DASH-OFFSET DASHES \
  2557. CACHE-P)
  2558. { /* the keyword list must be in sync with
  2559. (defconstant *GCONTEXT-COMPONENTS* ...) in clx.lisp */
  2560. XGCValues values;
  2561. unsigned long valuemask = 0;
  2562. int non_trivial_clip_mask_p = 0; /* whether user specified a rect-seq */
  2563. int non_trivial_dashes_p = 0; /* whether user specified a sequence as :dashes argument */
  2564. #define SLOT(ofs, type, slot, mask) \
  2565. if (!missingp(STACK_(ofs))) \
  2566. { values.slot = get_##type (STACK_(ofs)); valuemask |= mask; }
  2567. /* missing: 0=cache-p */
  2568. SLOT (24, gc_function, function, GCFunction);
  2569. SLOT (23, uint32, plane_mask, GCPlaneMask);
  2570. SLOT (22, pixel, foreground, GCForeground);
  2571. SLOT (21, pixel, background, GCBackground);
  2572. SLOT (20, sint16, line_width, GCLineWidth);
  2573. SLOT (19, line_style, line_style, GCLineStyle);
  2574. SLOT (18, cap_style, cap_style, GCCapStyle);
  2575. SLOT (17, join_style, join_style, GCJoinStyle);
  2576. SLOT (16, fill_style, fill_style, GCFillStyle);
  2577. SLOT (15, fill_rule, fill_rule, GCFillRule);
  2578. SLOT (14, arc_mode, arc_mode, GCArcMode);
  2579. SLOT (13, pixmap, tile, GCTile);
  2580. SLOT (12, pixmap, stipple, GCStipple);
  2581. SLOT (11, sint16, ts_x_origin, GCTileStipXOrigin);
  2582. SLOT (10, sint16, ts_y_origin, GCTileStipYOrigin);
  2583. SLOT ( 9, font, font, GCFont);
  2584. SLOT ( 8, subwindow_mode, subwindow_mode, GCSubwindowMode);
  2585. SLOT ( 7, bool, graphics_exposures, GCGraphicsExposures);
  2586. SLOT ( 6, sint16, clip_x_origin, GCClipXOrigin);
  2587. SLOT ( 5, sint16, clip_y_origin, GCClipYOrigin);
  2588. SLOT ( 4, pixmap, clip_mask, GCClipMask);
  2589. SLOT ( 2, sint16, dash_offset, GCDashOffset);
  2590. #undef SLOT
  2591. /* Handle the :clip-mask argument, :clipordering is only used if
  2592. :clip-mask is a rect-seq. */
  2593. if (boundp(STACK_4)) { /* :clip-mask */
  2594. if (pixmap_p (STACK_4)) {
  2595. values.clip_mask = get_pixmap (STACK_4); valuemask |= GCClipMask;
  2596. } else if (eq (STACK_4, `:NONE`) || eq (STACK_4, NIL)) {
  2597. values.clip_mask = None; valuemask |= GCClipMask;
  2598. } else
  2599. non_trivial_clip_mask_p = 1;
  2600. }
  2601. /* Now handle the :dashes argument, same procedure as above. */
  2602. if (boundp(STACK_1)) {
  2603. if (uint8_p (STACK_1)) { /* simple argument */
  2604. values.dashes = get_uint8 (STACK_1); valuemask |= GCDashList;
  2605. } else
  2606. non_trivial_dashes_p = 1;
  2607. }
  2608. if (!missingp(STACK_(25))) { /* :drawable */
  2609. Display *dpy;
  2610. Drawable da = get_drawable_and_display (STACK_(25), &dpy);
  2611. GC gcon;
  2612. X_CALL(gcon = XCreateGC (dpy, da, valuemask, &values));
  2613. VALUES1(make_gcontext (get_display_obj(STACK_(25)), gcon));
  2614. if (non_trivial_clip_mask_p) {
  2615. /* User specified a clip mask, which is a rect-seq.
  2616. Use the (SETF GCONTEXT-CLIP-MASK) function to set it up. */
  2617. pushSTACK(value1); /* save gcontext */
  2618. pushSTACK(STACK_5); /* the :clip-mask argument */
  2619. pushSTACK(STACK_1); /* the gcontext again */
  2620. pushSTACK(STACK_6); /* the :clip-ordering argument */
  2621. funcall(``XLIB:SET-GCONTEXT-CLIP-MASK``,3);
  2622. value1 = popSTACK(); /* restore gcontext */
  2623. }
  2624. if (non_trivial_dashes_p) {
  2625. /* Same procedure as above */
  2626. pushSTACK(value1); /* save gcontext */
  2627. pushSTACK(STACK_2); /* the :dashes argument */
  2628. pushSTACK(STACK_1); /* gcontext again */
  2629. funcall(``XLIB:SET-GCONTEXT-DASHES``,2);
  2630. value1 = popSTACK(); /* restore gcontext */
  2631. }
  2632. } else {
  2633. pushSTACK(TheSubr (subr_self)->name);
  2634. error(error_condition,"~S: At least :DRAWABLE should be specifed.");
  2635. }
  2636. skipSTACK(26);
  2637. }
  2638. /* 5.3 Graphics Context Attributes */
  2639. /* XGetGCValues (3x11) says:
  2640. [...]
  2641. Also note that an invalid resource ID (with one or more of the three
  2642. most-significant bits set to one) will be returned for GCFont, GCTile, and
  2643. GCStipple if the component has never been explicitly set by the client.
  2644. [...]
  2645. FIXME: What about 64bit (or probably 36bit) architectures?
  2646. [I have to look into the source code of libX, but I am afraid,
  2647. that they think every machine is 32bit] */
  2648. #define invalid_xid_p(xid) ((xid) & 0xE0000000)
  2649. ##define DEF_GCONTEXT_SLOT_GETTER(lspnam, type, slot, mask) \
  2650. DEFUN(XLIB:GCONTEXT-##lspnam, context) { \
  2651. XGCValues values; \
  2652. Display *dpy; \
  2653. GC gcon = get_gcontext_and_display (STACK_0, &dpy); \
  2654. X_CALL(XGetGCValues (dpy, gcon, mask, &values)); \
  2655. VALUES1(make_##type (values.slot)); \
  2656. skipSTACK(1); \
  2657. }
  2658. ##define DEF_GCONTEXT_SLOT_GETTER2(lspnam, type, slot, mask) \
  2659. DEFUN(XLIB:GCONTEXT-##lspnam, context) { \
  2660. XGCValues values; \
  2661. Display *dpy; \
  2662. GC gc = get_gcontext_and_display (STACK_0, &dpy); \
  2663. X_CALL(XGetGCValues(dpy,gc,mask,&values)); \
  2664. VALUES1(invalid_xid_p (values.slot) ? NIL \
  2665. : make_##type (get_display_obj (STACK_0), values.slot)); \
  2666. skipSTACK(1); \
  2667. }
  2668. ##define DEF_SET_GCONTEXT_SLOT(lspnam, type, slot, mask) \
  2669. DEFUN(XLIB:SET-GCONTEXT-##lspnam##, context val) { \
  2670. XGCValues values; \
  2671. Display *dpy; \
  2672. GC gcon = get_gcontext_and_display (STACK_1, &dpy); \
  2673. values.slot = get_##type (STACK_0); \
  2674. X_CALL(XChangeGC (dpy, gcon, mask, &values)); \
  2675. VALUES1(STACK_0); \
  2676. skipSTACK(2); \
  2677. }
  2678. ##define DEF_GCONTEXT_SLOT(lspnam, type, slot, mask) \
  2679. DEF_GCONTEXT_SLOT_GETTER (lspnam, type, slot, mask) \
  2680. DEF_SET_GCONTEXT_SLOT (lspnam, type, slot, mask)
  2681. ##define DEF_GCONTEXT_SLOT2(lspnam, type, slot, mask) \
  2682. DEF_GCONTEXT_SLOT_GETTER2 (lspnam, type, slot, mask) \
  2683. DEF_SET_GCONTEXT_SLOT (lspnam, type, slot, mask)
  2684. /*--------------------------------------------------------------------------
  2685. lisp name type C slot mask
  2686. ---------------------------------------------------------------------------*/
  2687. DEF_GCONTEXT_SLOT(ARC-MODE, arc_mode, arc_mode, GCArcMode)
  2688. DEF_GCONTEXT_SLOT(BACKGROUND, pixel, background, GCBackground)
  2689. DEF_GCONTEXT_SLOT(CAP-STYLE, cap_style, cap_style, GCCapStyle)
  2690. DEF_GCONTEXT_SLOT(CLIP-X, sint16, clip_x_origin, GCClipXOrigin)
  2691. DEF_GCONTEXT_SLOT(CLIP-Y, sint16, clip_y_origin, GCClipYOrigin)
  2692. DEF_GCONTEXT_SLOT(DASH-OFFSET, uint16, dash_offset, GCDashOffset)
  2693. DEF_GCONTEXT_SLOT(EXPOSURES, bool, graphics_exposures,GCGraphicsExposures)
  2694. DEF_GCONTEXT_SLOT(FILL-RULE, fill_rule, fill_rule, GCFillRule)
  2695. DEF_GCONTEXT_SLOT(FILL-STYLE, fill_style, fill_style, GCFillStyle)
  2696. DEF_GCONTEXT_SLOT(FOREGROUND, pixel, foreground, GCForeground)
  2697. DEF_GCONTEXT_SLOT(FUNCTION, gc_function, function, GCFunction)
  2698. DEF_GCONTEXT_SLOT(JOIN-STYLE, join_style, join_style, GCJoinStyle)
  2699. DEF_GCONTEXT_SLOT(LINE-STYLE, line_style, line_style, GCLineStyle)
  2700. DEF_GCONTEXT_SLOT(LINE-WIDTH, sint16, line_width, GCLineWidth)
  2701. DEF_GCONTEXT_SLOT(PLANE-MASK, uint32, plane_mask, GCPlaneMask)
  2702. DEF_GCONTEXT_SLOT(SUBWINDOW-MODE,subwindow_mode,subwindow_mode,GCSubwindowMode)
  2703. DEF_GCONTEXT_SLOT(TS-X, sint16, ts_x_origin, GCTileStipXOrigin)
  2704. DEF_GCONTEXT_SLOT(TS-Y, sint16, ts_y_origin, GCTileStipYOrigin)
  2705. DEF_GCONTEXT_SLOT2(STIPPLE, pixmap, stipple, GCStipple)
  2706. DEF_GCONTEXT_SLOT2(TILE, pixmap, tile, GCTile)
  2707. /* What about getting clip-mask?! */
  2708. DEFUN(XLIB:GCONTEXT-CACHE-P, context)
  2709. {
  2710. Display *dpy;
  2711. unused get_gcontext_and_display (STACK_0, &dpy);
  2712. /* libX seems to cache all GCs */
  2713. VALUES1(T);
  2714. skipSTACK(1);
  2715. }
  2716. DEFUN(XLIB:SET-GCONTEXT-CACHE-P, arg1 arg2)
  2717. {
  2718. Display *dpy;
  2719. unused get_gcontext_and_display (STACK_1, &dpy);
  2720. if (nullp(STACK_0)) {
  2721. pushSTACK(TheSubr (subr_self)->name);
  2722. error(error_condition,"~S: This CLX implemenation does not allow uncached graphics contexts.");
  2723. }
  2724. VALUES1(STACK_0);
  2725. skipSTACK(2);
  2726. }
  2727. /* xlib:gcontext-dashes gcontext */
  2728. DEFUN(XLIB:GCONTEXT-DASHES, context)
  2729. {
  2730. unused get_gcontext_and_display (STACK_0, 0); /* only type checking here */
  2731. /* Now see if there is a %dashes slot? */
  2732. get_slot(STACK_0,`XLIB::%DASHES`);
  2733. if (eq(value1,nullobj))
  2734. /* Slot unbound --> oops, not set, so return default value */
  2735. value1 = make_uint8(0); /* FIXME: right? */
  2736. /* mv_count = 1; - done by get_slot() */
  2737. /* Simply return what is there. Or better copy it? Well, if the luser
  2738. fools around with what he has found, he shoot only himself in the
  2739. foot, not me. So we need not copy here. */
  2740. skipSTACK(1);
  2741. }
  2742. DEFUN(XLIB::SET-GCONTEXT-DASHES, gcontext dashes)
  2743. { /* (setf (xlib:gcontext-dashes gcontext) dashes) */
  2744. XGCValues values;
  2745. Display *dpy;
  2746. GC gcon = get_gcontext_and_display (STACK_1, &dpy);
  2747. if (uint8_p (STACK_0)) {
  2748. values.dashes = get_uint8 (STACK_0);
  2749. X_CALL(XChangeGC (dpy, gcon, GCDashList, &values));
  2750. /* Now set the %dashes slot. */
  2751. pushSTACK(STACK_1); /* The instance, hence the gcontext */
  2752. pushSTACK(`XLIB::%DASHES`); /* slot */
  2753. pushSTACK(make_uint8 ((uint8)values.dashes)); /* value */
  2754. funcall (L(set_slot_value), 3);
  2755. } else { /* Now STACK_0 is required to be a non-empty sequence */
  2756. uintC n = get_fixnum(funcall1(L(length),STACK_0));
  2757. if (n < 1) {
  2758. pushSTACK(TheSubr(subr_self)->name);
  2759. error(error_condition,"~S: The dash list should be non-empty.");
  2760. }
  2761. /* FIXME: For efficiency reasons, we should look
  2762. if user gave already a byte vector.
  2763. [probably via with-gcontext]. */
  2764. /* Allocate a simple vector of uint8's: */
  2765. pushSTACK(allocate_bit_vector (/* eltype: */ Atype_8Bit, /* len: */ n));
  2766. /* Copy the values from the dash-list argument into the
  2767. newly created byte-vector representation */
  2768. pushSTACK(STACK_0); pushSTACK(STACK_2); funcall(L(replace),2);
  2769. /* The XSetDashes routine requires also the dash_offset,
  2770. so retrieve it first. */
  2771. begin_x_call();
  2772. XGetGCValues (dpy, gcon, GCDashOffset, &values);
  2773. XSetDashes (dpy, gcon, values.dash_offset,
  2774. (char*)(TheSbvector(STACK_1)->data), n);
  2775. end_x_call();
  2776. /* Now install the byte-vector into the %dashes slot: */
  2777. pushSTACK(STACK_2); /* The instance, hence the gcontext */
  2778. pushSTACK(`XLIB::%DASHES`); /* slot */
  2779. pushSTACK(STACK_2); /* value, the byte-vector */
  2780. funcall (L(set_slot_value), 3);
  2781. skipSTACK(1); /* clean up; pop the byte-vector */
  2782. }
  2783. VALUES1(STACK_0);
  2784. skipSTACK(2);
  2785. }
  2786. DEFUN(XLIB:GCONTEXT-CLIP-MASK, context)
  2787. {
  2788. unused get_gcontext_and_display (STACK_0, 0); /* only type checking here */
  2789. get_slot(STACK_0,`XLIB::%CLIP-MASK`);
  2790. if (eq(value1,nullobj)) value1 = `:NONE`;
  2791. skipSTACK(1);
  2792. /* mv_count = 1; - done by get_slot() */
  2793. }
  2794. /* convert Lisp FOO-SEQ to a C vector */
  2795. static int get_seq_len (gcv_object_t *seq, gcv_object_t *type, int size) {
  2796. int num = get_uint32(funcall1(L(length),*seq));
  2797. if (num % size) {
  2798. pushSTACK(fixnum(size)); pushSTACK(fixnum(num)); pushSTACK(*type);
  2799. pushSTACK(TheSubr(subr_self)->name);
  2800. error(error_condition,"~S: Argument is not a proper ~S; length of sequence, ~S, is not a multiple of ~S.");
  2801. }
  2802. return num/size;
  2803. }
  2804. struct seq_generic { void *seq; int slot; };
  2805. static void set_seq (gcv_object_t *l_seq, void *c_seq,
  2806. map_sequence_function_t mapper) {
  2807. struct seq_generic seq;
  2808. seq.seq = c_seq; seq.slot = 0;
  2809. map_sequence(*l_seq,mapper,(void*)&seq);
  2810. }
  2811. /* convert Lisp RECT-SEQ to a C vector */
  2812. struct seq_rectangle { XRectangle *rectangle; int slot; };
  2813. void coerce_into_rectangle (void *arg, object element);
  2814. void coerce_into_rectangle (void *arg, object element) {
  2815. struct seq_rectangle *rec = (struct seq_rectangle *)arg;
  2816. switch (rec->slot) {
  2817. case 0: rec->rectangle->x = get_sint16(element);
  2818. rec->slot = 1; break;
  2819. case 1: rec->rectangle->y = get_sint16(element);
  2820. rec->slot = 2; break;
  2821. case 2: rec->rectangle->width = get_uint16(element);
  2822. rec->slot = 3; break;
  2823. case 3: rec->rectangle->height = get_uint16(element);
  2824. rec->slot = 0; rec->rectangle++; break;
  2825. }
  2826. }
  2827. DEFUN(XLIB:SET-GCONTEXT-CLIP-MASK, clip-mask gcontext &optional ordering)
  2828. { /* (SETF (XLIB:GCONTEXT-CLIP-MASK gcontext &optional ordering) clip-mask) */
  2829. Display *dpy;
  2830. GC gcontext = get_gcontext_and_display (STACK_1, &dpy);
  2831. if (eq (STACK_2, `:NONE`) || eq (STACK_2, NIL)) {
  2832. X_CALL(XSetClipMask (dpy, gcontext, None));
  2833. } else if (pixmap_p (STACK_2)) {
  2834. Pixmap pixmap = get_pixmap (STACK_2);
  2835. X_CALL(XSetClipMask (dpy, gcontext, pixmap));
  2836. } else {
  2837. /* FIXME: We could use a more effient representation for the clip-mask
  2838. in the gcontext.
  2839. We should think about the portability of using a halfword-vector
  2840. and then beam the data directly into the rectangles vector. */
  2841. int ordering = get_ordering(STACK_0);
  2842. int n = get_seq_len(&STACK_2,&`XLIB::RECT-SEQ`,4);
  2843. DYNAMIC_ARRAY (rectangles, XRectangle, n);
  2844. set_seq(&STACK_2,rectangles,coerce_into_rectangle);
  2845. {
  2846. XGCValues values;
  2847. begin_x_call();
  2848. XGetGCValues (dpy, gcontext, GCClipXOrigin|GCClipYOrigin, &values);
  2849. XSetClipRectangles (dpy, gcontext, values.clip_x_origin,
  2850. values.clip_y_origin, rectangles, n, ordering);
  2851. end_x_call();
  2852. }
  2853. /* ok. now copy the value given by user, so if he messes around with
  2854. what he gave as argument, it will not affect the saved value. */
  2855. STACK_2 = funcall1(L(copy_seq),STACK_2);
  2856. FREE_DYNAMIC_ARRAY (rectangles);
  2857. }
  2858. /* Now save the value just set in the %clip-mask slot. */
  2859. pushSTACK(STACK_1); /* The instance, hence the gcontext */
  2860. pushSTACK(`XLIB::%CLIP-MASK`); /* slot */
  2861. pushSTACK(STACK_4); /* value */
  2862. funcall (L(set_slot_value), 3);
  2863. VALUES1(STACK_2);
  2864. skipSTACK(3);
  2865. }
  2866. DEFUN(XLIB:GCONTEXT-FONT, context &optional pseudo-p)
  2867. {
  2868. Display *dpy;
  2869. GC gc;
  2870. int pseudo_font_p;
  2871. XGCValues values;
  2872. pseudo_font_p = !missingp(STACK_0);
  2873. if (pseudo_font_p) NOTIMPLEMENTED;
  2874. gc = get_gcontext_and_display (STACK_1, &dpy);
  2875. X_CALL(XGetGCValues (dpy, gc, GCFont, &values));
  2876. VALUES1(invalid_xid_p (values.font) ? NIL
  2877. : make_font (get_display_obj (STACK_1), values.font, NIL));
  2878. skipSTACK(2);
  2879. }
  2880. DEFUN(XLIB:SET-GCONTEXT-FONT, font context &optional pseudo-p)
  2881. {
  2882. int pseudo_font_p;
  2883. XGCValues values;
  2884. Display *dpy;
  2885. GC gc = get_gcontext_and_display (STACK_1, &dpy);
  2886. pseudo_font_p = !missingp(STACK_0);
  2887. if (pseudo_font_p) NOTIMPLEMENTED;
  2888. values.font = get_font (STACK_2);
  2889. X_CALL(XChangeGC (dpy, gc, GCFont, &values));
  2890. VALUES1(STACK_2);
  2891. skipSTACK(3);
  2892. }
  2893. /* Standard clx objects look: */
  2894. DEFUN(XLIB:GCONTEXT-ID, context)
  2895. {
  2896. GContext context;
  2897. GC gc = get_gcontext (popSTACK());
  2898. X_CALL(context = XGContextFromGC(gc));
  2899. VALUES1(make_uint32(context));
  2900. }
  2901. static void query_best_X (Status (*query) (Display*, Drawable,
  2902. unsigned int, unsigned int,
  2903. unsigned int *, unsigned int *))
  2904. {
  2905. unsigned int width, height, x, y;
  2906. Display *dpy;
  2907. Drawable da = get_drawable_and_display (STACK_0, &dpy);
  2908. x = get_uint16 (STACK_2);
  2909. y = get_uint16 (STACK_1);
  2910. X_CALL(query (dpy, da, x, y, &width, &height));
  2911. pushSTACK(make_uint16 (height));
  2912. pushSTACK(make_uint16 (width));
  2913. VALUES2(STACK_0,STACK_1);
  2914. skipSTACK(5);
  2915. }
  2916. DEFUN(XLIB:QUERY-BEST-STIPPLE, arg1 arg2 arg3)
  2917. {
  2918. query_best_X (XQueryBestStipple);
  2919. }
  2920. DEFUN(XLIB:QUERY-BEST-TILE, arg1 arg2 arg3)
  2921. {
  2922. query_best_X (XQueryBestTile);
  2923. }
  2924. /* 5.3 Copying Graphics Contexts */
  2925. DEFUN(XLIB:COPY-GCONTEXT, arg1 arg2)
  2926. {
  2927. Display *dpy;
  2928. GC gcon1 = get_gcontext_and_display (STACK_1, &dpy);
  2929. GC gcon2 = get_gcontext (STACK_0);
  2930. X_CALL(XCopyGC (dpy, gcon1, 0x7FFFFFUL, gcon2));
  2931. VALUES0;
  2932. skipSTACK(2);
  2933. }
  2934. DEFUN(XLIB:COPY-GCONTEXT-COMPONENTS, gc1 gc2 &rest rest)
  2935. {
  2936. unsigned i;
  2937. unsigned long mask = 0;
  2938. GC gcon1, gcon2;
  2939. Display *dpy;
  2940. for (i = 0; i < argcount-2; i++) {
  2941. mask |= get_gcontext_key (STACK_0);
  2942. skipSTACK(1);
  2943. }
  2944. gcon1 = get_gcontext_and_display (STACK_0, &dpy);
  2945. gcon2 = get_gcontext (STACK_1);
  2946. X_CALL(XCopyGC (dpy, gcon2, mask, gcon1));
  2947. VALUES0;
  2948. skipSTACK(2);
  2949. }
  2950. /* 5.4 Destroying Graphics Contexts */
  2951. DEFUN(XLIB:FREE-GCONTEXT, context)
  2952. {
  2953. Display *dpy;
  2954. GC gcon = get_gcontext_and_display (STACK_0, &dpy);
  2955. X_CALL(XFreeGC (dpy, gcon));
  2956. skipSTACK(1);
  2957. VALUES1(NIL);
  2958. }
  2959. /* 5.5 Graphics Context Cache */
  2960. DEFUN(XLIB:FORCE-GCONTEXT-CHANGES, context)
  2961. {
  2962. Display *dpy;
  2963. GC gcon = get_gcontext_and_display (STACK_0, &dpy);
  2964. X_CALL(XFlushGC(dpy,gcon)); /* This function is actually undocumented */
  2965. skipSTACK(1);
  2966. VALUES1(NIL);
  2967. }
  2968. /* ----------------------------------------------------------------------------
  2969. WITH-GCONTEXT
  2970. Method: with-gcontext should 'bind' some gcontext slots, so we have to save
  2971. them and restore them after exiting the body (probably within an
  2972. unwind-protect). The core of the with-gcontext macro looks like this:
  2973. (let ((saved (%save-gcontext-compoments gcon mask)))
  2974. (unwind-protect
  2975. ,body
  2976. (%restore-gcontext-compoments gcon saved)))
  2977. %save-g.-c. and %restore-g.-c. work by putting the XGCValues structure into
  2978. a bitvector. Plain and simple.
  2979. clip-mask and the dashes-list are to be saved and restored by the Lisp code.
  2980. Another method would be copy the gcontext and modify the fptr. This would
  2981. then also work with dash-list and clip-mask on gcontexts modified by some C
  2982. code. [I plan to incooperate other C libs here.] */
  2983. DEFUN(XLIB:%GCONTEXT-KEY->MASK, key)
  2984. { /* Finds the libX mask bit for given symbolic representation of the slot */
  2985. VALUES1(make_uint32 (get_gcontext_key (popSTACK())));
  2986. }
  2987. /* data structure in which the values survive. */
  2988. typedef struct {
  2989. uint32 mask; /* values mask, specifies which values where saved */
  2990. XGCValues values; /* the values itself in native C rep. */
  2991. } saved_gcontext_values;
  2992. /* Returns the gcontext components selected by 'components', a mask32, and
  2993. returns them in some compact object, which should be considered opaque. */
  2994. DEFUN(XLIB:%SAVE-GCONTEXT-COMPONENTS, gcontext components)
  2995. {
  2996. saved_gcontext_values values;
  2997. Display *dpy;
  2998. GC gcontext = get_gcontext_and_display (STACK_1, &dpy);
  2999. values.mask = get_uint32 (STACK_0);
  3000. if (values.mask & GCDashList) {
  3001. /* the dash list itself is saved by Lisp code, but we take care of
  3002. the dash offset. */
  3003. values.mask |= GCDashOffset;
  3004. values.mask &= ~GCDashList; /* do not make any nonsense here. */
  3005. }
  3006. if (values.mask & GCClipMask) {
  3007. /* same story as above. */
  3008. values.mask |= GCClipXOrigin|GCClipYOrigin;
  3009. values.mask &= ~GCClipMask;
  3010. }
  3011. X_CALL(XGetGCValues (dpy, gcontext, values.mask, &values.values));
  3012. /* TODO: What to do on failure of XGetGCValues? */
  3013. /* Allocate a new bit vector, which should hold the requested components */
  3014. VALUES1(make_fill_bit_vector((char*)&values, sizeof(values)));
  3015. skipSTACK(2);
  3016. }
  3017. /* Counterpart of xlib:%save-gcontext-components: Installs the saved values.
  3018. Note that the components mask is not needed, since it is saved together
  3019. with the values to avoid malformed restores. */
  3020. DEFUN(XLIB:%RESTORE-GCONTEXT-COMPONENTS, gcontext values)
  3021. {
  3022. saved_gcontext_values values;
  3023. Display *dpy;
  3024. GC gcontext = get_gcontext_and_display (STACK_1, &dpy);
  3025. X_CALL(memcpy (&values, TheSbvector (STACK_0)->data, sizeof (values)));
  3026. /* do not attempt to restore invalid resource ids
  3027. Probably we want to reinvalidate them, but that seems not to be possible. */
  3028. if (invalid_xid_p (values.values.font)) values.mask&=~GCFont;
  3029. if (invalid_xid_p (values.values.tile)) values.mask&=~GCTile;
  3030. if (invalid_xid_p (values.values.stipple)) values.mask&=~GCStipple;
  3031. X_CALL(XChangeGC (dpy, gcontext, values.mask, &values.values));
  3032. skipSTACK(2);
  3033. VALUES1(NIL);
  3034. }
  3035. /* -----------------------------------------------------------------------
  3036. * Chapter 6 Graphics Operations
  3037. * ----------------------------------------------------------------------- */
  3038. /* 6.2 Area and Plane Operations */
  3039. DEFUN(XLIB:CLEAR-AREA, drawable &key X Y WIDTH HEIGHT EXPOSURES-P)
  3040. {
  3041. Display *dpy;
  3042. Window win = get_drawable_and_display (STACK_5, &dpy);
  3043. int x = get_sint16_0 (STACK_4);
  3044. int y = get_sint16_0 (STACK_3);
  3045. int w = get_uint16_0 (STACK_2);
  3046. int h = get_uint16_0 (STACK_1);
  3047. int exposures_p = !missingp(STACK_0);
  3048. X_CALL(XClearArea (dpy, win, x,y,w,h, exposures_p));
  3049. skipSTACK(6);
  3050. VALUES0;
  3051. }
  3052. DEFUN(XLIB:COPY-AREA, source gcontext source-x source-y width height \
  3053. destination destination-x destination-y)
  3054. {
  3055. int dest_y = get_sint16 (popSTACK());
  3056. int dest_x = get_sint16 (popSTACK());
  3057. Drawable dest = get_drawable (popSTACK());
  3058. int height = get_sint16 (popSTACK());
  3059. int width = get_sint16 (popSTACK());
  3060. int src_y = get_sint16 (popSTACK());
  3061. int src_x = get_sint16 (popSTACK());
  3062. GC gc = get_gcontext (popSTACK());
  3063. Display *dpy;
  3064. Drawable src = get_drawable_and_display (popSTACK(), &dpy);
  3065. X_CALL(XCopyArea (dpy, src, dest, gc, src_x, src_y, width, height,
  3066. dest_x, dest_y));
  3067. VALUES1(NIL);
  3068. }
  3069. DEFUN(XLIB:COPY-PLANE, source gcontext plane source-x source-y width height \
  3070. destination destination-x destination-y)
  3071. { /* WAS: invoke (XCopyPlane, 10, 'v', "D1dgiiiiidii"); */
  3072. int dest_y = get_sint16 (STACK_0);
  3073. int dest_x = get_sint16 (STACK_1);
  3074. Drawable dest = get_drawable (STACK_2);
  3075. int height = get_sint16 (STACK_3);
  3076. int width = get_sint16 (STACK_4);
  3077. int src_y = get_sint16 (STACK_5);
  3078. int src_x = get_sint16 (STACK_6);
  3079. unsigned long plane = get_uint32 (STACK_7);
  3080. GC gc = get_gcontext (STACK_8);
  3081. Display *dpy;
  3082. Drawable src = get_drawable_and_display (STACK_9, &dpy);
  3083. X_CALL(XCopyPlane (dpy, src, dest, gc, src_x, src_y, width, height,
  3084. dest_x, dest_y, plane));
  3085. skipSTACK(10);
  3086. VALUES1(NIL);
  3087. }
  3088. /* 6.3 Drawing Points */
  3089. DEFUN(XLIB:DRAW-POINT, drawable gcontext x y)
  3090. { /* WAS: invoke (XDrawPoint, 4, "D1dgii"); */
  3091. int y = get_sint16 (popSTACK());
  3092. int x = get_sint16 (popSTACK());
  3093. GC gc = get_gcontext (popSTACK());
  3094. Display *dpy;
  3095. Drawable da = get_drawable_and_display (popSTACK(), &dpy);
  3096. X_CALL(XDrawPoint (dpy, da, gc, x, y));
  3097. VALUES1(NIL);
  3098. }
  3099. /* convert Lisp POINT-SEQ to a C vector */
  3100. struct seq_point { XPoint *point; int slot; };
  3101. void coerce_into_point (void *arg, object element);
  3102. void coerce_into_point (void *arg, object element) {
  3103. struct seq_point *rec = (struct seq_point *)arg;
  3104. sint16 val = get_sint16(element);
  3105. switch (rec->slot) {
  3106. case 0: rec->point->x = val;
  3107. rec->slot = 1; break;
  3108. case 1: rec->point->y = val;
  3109. rec->slot = 0; rec->point++; break;
  3110. }
  3111. }
  3112. DEFUN(XLIB:DRAW-POINTS, drawable gcontext points &optional relative-p)
  3113. {
  3114. Display *dpy;
  3115. Drawable da = get_drawable_and_display (STACK_3, &dpy);
  3116. GC gc = get_gcontext (STACK_2);
  3117. int relative_p = !missingp(STACK_0);
  3118. int npts = get_seq_len(&STACK_1,&`XLIB::POINT-SEQ`,2);
  3119. DYNAMIC_ARRAY (pts, XPoint, npts);
  3120. set_seq(&STACK_1,pts,coerce_into_point);
  3121. X_CALL(XDrawPoints (dpy, da, gc, pts, npts,
  3122. relative_p ? CoordModePrevious : CoordModeOrigin));
  3123. FREE_DYNAMIC_ARRAY (pts);
  3124. VALUES1(NIL);
  3125. skipSTACK(4);
  3126. }
  3127. /* 6.4 Drawing Lines */
  3128. DEFUN(XLIB:DRAW-LINE, drawable gcontext x0 y0 x1 y1 &optional relative-p)
  3129. {
  3130. int relative_p, x1,y1,x2,y2;
  3131. GC gc;
  3132. Drawable da;
  3133. Display *dpy;
  3134. relative_p = !missingp(STACK_0);
  3135. x1 = get_sint16 (STACK_4); y1 = get_sint16 (STACK_3);
  3136. x2 = get_sint16 (STACK_2); y2 = get_sint16 (STACK_1);
  3137. if (relative_p) { x2 += x1; y2 += y1; }
  3138. da = get_drawable_and_display (STACK_6, &dpy);
  3139. gc = get_gcontext (STACK_5);
  3140. X_CALL(XDrawLine (dpy, da, gc, x1, y1, x2, y2));
  3141. skipSTACK(7);
  3142. VALUES1(NIL);
  3143. }
  3144. /* DEUTSCH Kuerzester Mathematikerwitz: epsilon kleiner null.
  3145. ENGLISH Shortest mathematician's joke: epsilon less than zero. */
  3146. /* XLIB:DRAW-LINES [5]drawable [4]gcontext [3]points &key [2]:relative-p
  3147. [1]:fill-p [0](:shape :complex) */
  3148. DEFUN(XLIB:DRAW-LINES, drawable gcontext points &key RELATIVE-P FILL-P SHAPE)
  3149. {
  3150. Display *dpy;
  3151. Drawable da = get_drawable_and_display (STACK_5, &dpy);
  3152. GC gc = get_gcontext (STACK_4);
  3153. int relative_p = !missingp(STACK_2);
  3154. int fill_p = !missingp(STACK_1);
  3155. int shape = (boundp(STACK_0) ? get_shape(STACK_0) : Complex);
  3156. int npoints = get_seq_len(&STACK_3,&`XLIB::POINT-SEQ`,2);
  3157. DYNAMIC_ARRAY (points, XPoint, npoints);
  3158. set_seq(&STACK_3,points,coerce_into_point);
  3159. begin_x_call();
  3160. if (fill_p)
  3161. XFillPolygon (dpy, da, gc, points, npoints, shape,
  3162. relative_p ? CoordModePrevious : CoordModeOrigin);
  3163. else
  3164. XDrawLines (dpy, da, gc, points, npoints,
  3165. relative_p ? CoordModePrevious : CoordModeOrigin);
  3166. end_x_call();
  3167. FREE_DYNAMIC_ARRAY (points);
  3168. VALUES1(NIL);
  3169. skipSTACK(6);
  3170. }
  3171. /* convert Lisp SEG-SEQ to a C vector */
  3172. struct seq_segment { XSegment *segment; int slot; };
  3173. void coerce_into_segment (void *arg, object element);
  3174. void coerce_into_segment (void *arg, object element) {
  3175. struct seq_segment *rec = (struct seq_segment *)arg;
  3176. sint16 val = get_sint16(element);
  3177. switch (rec->slot) {
  3178. case 0: rec->segment->x1 = val;
  3179. rec->slot = 1; break;
  3180. case 1: rec->segment->y1 = val;
  3181. rec->slot = 2; break;
  3182. case 2: rec->segment->x2 = val;
  3183. rec->slot = 3; break;
  3184. case 3: rec->segment->y2 = val;
  3185. rec->slot = 0; rec->segment++; break;
  3186. }
  3187. }
  3188. DEFUN(XLIB:DRAW-SEGMENTS, drawable gcontext segments)
  3189. {
  3190. Display *dpy;
  3191. Drawable da = get_drawable_and_display (STACK_2, &dpy);
  3192. GC gc = get_gcontext (STACK_1);
  3193. int nsegments = get_seq_len(&STACK_0,&`XLIB::SEG-SEQ`,4);
  3194. DYNAMIC_ARRAY (segments, XSegment, nsegments);
  3195. set_seq(&STACK_0,segments,coerce_into_segment);
  3196. X_CALL(XDrawSegments (dpy, da, gc, segments, nsegments));
  3197. FREE_DYNAMIC_ARRAY (segments);
  3198. VALUES1(NIL);
  3199. skipSTACK(3);
  3200. }
  3201. /* 6.5 Drawing Rectangles */
  3202. DEFUN(XLIB:DRAW-RECTANGLE, drawable gcontext x y width height &optional fill-p)
  3203. {
  3204. Display *dpy;
  3205. int fill_p = !missingp(STACK_0);
  3206. int x = get_sint16 (STACK_4);
  3207. int y = get_sint16 (STACK_3);
  3208. int w = get_sint16 (STACK_2);
  3209. int h = get_sint16 (STACK_1);
  3210. GC gcon = get_gcontext (STACK_5);
  3211. Drawable da = get_drawable_and_display (STACK_6, &dpy);
  3212. X_CALL((fill_p ? XFillRectangle : XDrawRectangle) (dpy,da,gcon,x,y,w,h));
  3213. skipSTACK(7);
  3214. VALUES1(NIL);
  3215. }
  3216. DEFUN(XLIB:DRAW-RECTANGLES, drawable gcontext rectangles &optional fill-p)
  3217. {
  3218. Display *dpy;
  3219. Drawable da = get_drawable_and_display (STACK_3, &dpy);
  3220. GC gc = get_gcontext (STACK_2);
  3221. int fill_p = missingp(STACK_0);
  3222. int nrectangles = get_seq_len(&STACK_1,&`XLIB::RECT-SEQ`,4);
  3223. DYNAMIC_ARRAY (rectangles, XRectangle, nrectangles);
  3224. set_seq(&STACK_1,rectangles,coerce_into_rectangle);
  3225. X_CALL((fill_p ? XFillRectangles : XDrawRectangles)
  3226. (dpy, da, gc, rectangles, nrectangles));
  3227. FREE_DYNAMIC_ARRAY (rectangles);
  3228. VALUES1(NIL);
  3229. skipSTACK(4);
  3230. }
  3231. /* 6.6 Drawing Arcs */
  3232. /* XLIB:DRAW-ARC drawable gcontext x y width height angle1 angle2
  3233. &optional fill-p */
  3234. DEFUN(XLIB:DRAW-ARC, &rest args)
  3235. {
  3236. int fill_p, x,y,w,h, ang1, ang2;
  3237. GC gcon;
  3238. Display *dpy;
  3239. Drawable da;
  3240. ASSERT ((argcount >= 8) && (argcount <= 9));
  3241. fill_p = (argcount == 9) ? (!nullp (popSTACK())) : 0;
  3242. x = get_sint16 (STACK_5); y = get_sint16 (STACK_4);
  3243. w = get_sint16 (STACK_3); h = get_sint16 (STACK_2);
  3244. ang1 = get_angle (STACK_1); ang2 = get_angle (STACK_0);
  3245. gcon = get_gcontext (STACK_6);
  3246. da = get_drawable_and_display (STACK_7, &dpy);
  3247. X_CALL((fill_p ? XFillArc : XDrawArc) (dpy, da, gcon, x, y, w, h,
  3248. ang1, ang2));
  3249. skipSTACK(8);
  3250. VALUES0;
  3251. }
  3252. /* convert Lisp ARC-SEQ to a C vector */
  3253. struct seq_arc { XArc *arc; int slot; };
  3254. void coerce_into_arc (void *arg, object element);
  3255. void coerce_into_arc (void *arg, object element) {
  3256. struct seq_arc *rec = (struct seq_arc *)arg;
  3257. switch (rec->slot) {
  3258. case 0: rec->arc->x = get_sint16(element);
  3259. rec->slot = 1; break;
  3260. case 1: rec->arc->y = get_sint16(element);
  3261. rec->slot = 2; break;
  3262. case 2: rec->arc->width = get_uint16(element);
  3263. rec->slot = 3; break;
  3264. case 3: rec->arc->height = get_uint16(element);
  3265. rec->slot = 4; break;
  3266. case 4: rec->arc->angle1 = get_angle(element);
  3267. rec->slot = 5; break;
  3268. case 5: rec->arc->angle2 = get_angle(element);
  3269. rec->slot = 0; rec->arc++; break;
  3270. }
  3271. }
  3272. DEFUN(XLIB:DRAW-ARCS, drawable gcontext arcs &optional fill-p)
  3273. { /* arcs = ((x y width height angle1 angle2) ...) */
  3274. Display *dpy;
  3275. Drawable da = get_drawable_and_display (STACK_3, &dpy);
  3276. GC gc = get_gcontext (STACK_2);
  3277. int fill_p = missingp(STACK_0);
  3278. int narcs = get_seq_len(&STACK_1,&`XLIB::ARC-SEQ`,6);
  3279. DYNAMIC_ARRAY (arcs, XArc, narcs);
  3280. set_seq(&STACK_1,arcs,coerce_into_arc);
  3281. X_CALL((fill_p ? XFillArcs : XDrawArcs) (dpy, da, gc, arcs, narcs));
  3282. FREE_DYNAMIC_ARRAY (arcs);
  3283. VALUES1(NIL);
  3284. skipSTACK(4);
  3285. }
  3286. /* 6.7 Drawing Text */
  3287. /* Conversion from chart array to XChar2b array.
  3288. Returns 1 if a char array was generated, or 2 if a XChar2b array was
  3289. generated. */
  3290. static int to_XChar2b (object font, XFontStruct* font_info, const chart* src,
  3291. XChar2b* dst, unsigned int count)
  3292. {
  3293. object encoding;
  3294. pushSTACK(font); pushSTACK(`XLIB::ENCODING`);
  3295. funcall(L(slot_value), 2); encoding = value1;
  3296. if (font_info->min_byte1 == 0 && font_info->max_byte1 == 0) {
  3297. /* Linear addressing */
  3298. if (!nullp(encoding)/*&& TheEncoding(encoding)->max_bytes_per_char==1*/) {
  3299. /* Special hack: use the font's encoding */
  3300. if (count > 0) {
  3301. cstombs(encoding,src,count,(uintB*)dst,count);
  3302. return 1;
  3303. }
  3304. } else
  3305. while (count > 0) {
  3306. unsigned int c = as_cint(*src);
  3307. if (c >= font_info->min_char_or_byte2 &&
  3308. c <= font_info->max_char_or_byte2)
  3309. dst->byte2 = c;
  3310. else
  3311. dst->byte2 = font_info->default_char;
  3312. dst->byte1 = 0;
  3313. src++; dst++; count--;
  3314. }
  3315. } else { /* Matrix addressing */
  3316. unsigned int d = font_info->max_char_or_byte2 - font_info->min_char_or_byte2 + 1;
  3317. while (count > 0) {
  3318. unsigned int c = as_cint(*src);
  3319. dst->byte1 = (c/d) + font_info->min_byte1;
  3320. dst->byte2 = (c%d) + font_info->min_char_or_byte2;
  3321. src++; dst++; count--;
  3322. }
  3323. }
  3324. return 2;
  3325. }
  3326. static void general_draw_text (int image_p)
  3327. { /* General text drawing routine to not to have to duplicate code for
  3328. DRAW-GLYPHS and DRAW-IMAGE-GLYPHS. */
  3329. /* First of all fetch the arguments */
  3330. #if 0
  3331. int size = 0; /* 8 or 16, 0="have to look into the font" */
  3332. STACK_9= drawable;
  3333. STACK_8= gcontext;
  3334. STACK_7= x;
  3335. STACK_6= y;
  3336. STACK_5= sequence;
  3337. STACK_4= start;
  3338. STACK_3= end;
  3339. STACK_2= translate;
  3340. if (boundp(STACK_1))
  3341. width = get_sint16 (STACK_1);
  3342. else
  3343. width = 17; /* Does not mater we ignore this value either way round. */
  3344. if (boundp(STACK_0) && !eq (STACK_0, S(Kdefault))) {
  3345. if (eq (STACK_0, fixnum(8))) size = 8;
  3346. else if (eq (STACK_0, fixnum(16))) size = 16;
  3347. else my_type_error(`(MEMBER 8 16 :DEFAULT)`,STACK_0);
  3348. }
  3349. /* invoke the translation function:
  3350. XLIB:TRANSLATE-DEFAULT src src-start src-end font dst dst-start */
  3351. pushSTACK(source);
  3352. pushSTACK(fixnum(start));
  3353. pushSTACK(fixnum(end));
  3354. pushSTACK(*font);
  3355. pushSTACK(*dest);
  3356. pushSTACK(fixnum(dest_start));
  3357. funcall (*translate, 6);
  3358. /* Now: value1 = first-not-done
  3359. value2 = NIL or
  3360. a new font or
  3361. a delta
  3362. value3 = NIL or
  3363. current width */
  3364. new_start = get_fixnum(value1);
  3365. textitem.nchars = new_start - start;
  3366. if (textitem.nchars <= 0) {
  3367. /* This should be an error */
  3368. }
  3369. if (size == 8) {
  3370. textitem.chars = (ptr into destination);
  3371. } else {
  3372. /* If we are on a litte-endian machine, we have to convert it ... */
  3373. textitem.chars = (copy the appropriate portion);
  3374. /* Or we do it at the end of the journey... */
  3375. /* .. otherwise just drop the pointer in: */
  3376. textitem.chars = (ptr into destination);
  3377. }
  3378. textitem.delta = 0; /* default value for delta */
  3379. textitem.font = None; /* default value for font */
  3380. if (mv_count >= 2 && !nullp (value2)) {
  3381. if (font_p (value2)) textitem.font = value2;
  3382. if (sint16_p (value2)) textitem.delta = get_fixnum(value2);
  3383. /* type-error-p? */
  3384. }
  3385. if (mv_count >= 3 && !nullp (value3)) {
  3386. /* Currently ignored ... */
  3387. }
  3388. #else
  3389. Display *dpy;
  3390. Drawable da = get_drawable_and_display (STACK_9, &dpy);
  3391. GC gcon = get_gcontext (STACK_8);
  3392. int x = get_sint16 (STACK_7);
  3393. int y = get_sint16 (STACK_6);
  3394. STACK_5 = check_string(STACK_5);
  3395. {
  3396. object font;
  3397. XFontStruct* font_info = get_font_info_and_display(STACK_8,&font,NULL);
  3398. uintL len, offset;
  3399. object s_string = unpack_string_ro(STACK_5,&len,&offset);
  3400. const chart* charptr;
  3401. unpack_sstring_alloca(s_string,len,offset,charptr=);
  3402. { DYNAMIC_ARRAY(str,XChar2b,len);
  3403. if (to_XChar2b(font,font_info,charptr,str,len) == 1)
  3404. X_CALL((image_p ? XDrawImageString : XDrawString)
  3405. (dpy, da, gcon, x, y, (char*)str, len));
  3406. else
  3407. X_CALL((image_p ? XDrawImageString16 : XDrawString16)
  3408. (dpy, da, gcon, x, y, str, len));
  3409. FREE_DYNAMIC_ARRAY(str);
  3410. }
  3411. }
  3412. VALUES0;
  3413. skipSTACK(10);
  3414. #endif
  3415. }
  3416. /* XLIB:DRAW-GLYPH drawable[6] gcontext[5] x[4] y[3] element[2]
  3417. &key :translate[1] :width[0] */
  3418. DEFUN(XLIB:DRAW-GLYPH, drawable gcontext x y element \
  3419. &key TRANSLATE WIDTH :SIZE)
  3420. {
  3421. NOTIMPLEMENTED;
  3422. }
  3423. /* XLIB:DRAW-GLPYHS drawable[9] gcontext[8] x[7] y[6] sequence[5]
  3424. &key (:start 0)[4] :end[3]
  3425. (:translate #'translate-default)[2] :width[1] (:size :default)[0] */
  3426. DEFUN(XLIB:DRAW-GLYPHS, drawable gcontext x y sequence \
  3427. &key :START :END TRANSLATE WIDTH :SIZE)
  3428. {
  3429. general_draw_text (0);
  3430. }
  3431. DEFUN(XLIB:DRAW-IMAGE-GLYPH, drawable gcontext x y element \
  3432. &key TRANSLATE WIDTH :SIZE)
  3433. {UNDEFINED;}
  3434. /* XLIB:DRAW-IMAGE-GLPYHS drawable gcontext x y sequence &key (:start 0) :end
  3435. (:translate #'translate-default) :width (:size :default) */
  3436. DEFUN(XLIB:DRAW-IMAGE-GLYPHS, drawable gcontext x y sequence \
  3437. &key :START :END TRANSLATE WIDTH :SIZE)
  3438. {
  3439. general_draw_text(1);
  3440. }
  3441. /* XLIB:TRANSLATE-DEFAULT src src-start src-end font dst dst-start
  3442. This function is not actually specified in the manual, so I include here the
  3443. Lisp code from MIT-CLX for reference:
  3444. (DEFUN(translate-default (src src-start src-end font dst dst-start)
  3445. ;; dst is guaranteed to have room for (- src-end src-start) integer elements,
  3446. ;; starting at dst-start; whether dst holds 8-bit or 16-bit elements depends
  3447. ;; on context. font is the current font, if known. The function should
  3448. ;; translate as many elements of src as possible into indexes in the current
  3449. ;; font, and store them into dst.
  3450. ;;
  3451. ;; The first return value should be the src index of the first untranslated
  3452. ;; element. If no further elements need to be translated, the second return
  3453. ;; value should be nil. If a horizontal motion is required before further
  3454. ;; translation, the second return value should be the delta in x coordinate.
  3455. ;; If a font change is required for further translation, the second return
  3456. ;; value should be the new font. If known, the pixel width of the translated
  3457. ;; text can be returned as the third value; this can allow for appending of
  3458. ;; subsequent output to the same protocol request, if no overall width has
  3459. ;; been specified at the higher level.
  3460. ;; (returns values: ending-index
  3461. ;; (OR null horizontal-motion font)
  3462. ;; (OR null translated-width))
  3463. (declare (type sequence src)
  3464. (type array-index src-start src-end dst-start)
  3465. (type (or null font) font)
  3466. (type vector dst)
  3467. (inline graphic-char-p))
  3468. (declare (values integer (or null integer font) (or null integer)))
  3469. font;;not used
  3470. (if (stringp src)
  3471. (do ((i src-start (index+ i 1))
  3472. (j dst-start (index+ j 1))
  3473. (char))
  3474. ((index>= i src-end)
  3475. i)
  3476. (declare (type array-index i j))
  3477. (if (graphic-char-p (setq char (char src i)))
  3478. (setf (aref dst j) (char->card8 char))
  3479. (return i)))
  3480. (do ((i src-start (index+ i 1))
  3481. (j dst-start (index+ j 1))
  3482. (elt))
  3483. ((index>= i src-end)
  3484. i)
  3485. (declare (type array-index i j))
  3486. (setq elt (elt src i))
  3487. (cond ((and (characterp elt) (graphic-char-p elt))
  3488. (setf (aref dst j) (char->card8 elt)))
  3489. ((integerp elt)
  3490. (setf (aref dst j) elt))
  3491. (t
  3492. (return i))))))
  3493. */
  3494. DEFUN(XLIB:TRANSLATE-DEFAULT, a1 a2 a3 a4 a5 a6) /* NIM */
  3495. {UNDEFINED;}
  3496. /* Together with the above function go the two below listed functions:
  3497. (Which are indeed trivial, since we are on an ASCII system).
  3498. [We could move it to the Lisp side?] */
  3499. DEFUN(XLIB:CARD8->CHAR, code) { funcall (L(code_char), 1); }
  3500. DEFUN(XLIB:CHAR->CARD8, char) { funcall (L(char_code), 1); }
  3501. /* -----------------------------------------------------------------------
  3502. * Chapter 7 Images
  3503. * ----------------------------------------------------------------------- */
  3504. /* Note: As you will probably see within a second, this code is still in
  3505. development.
  3506. ==== There are still not all image formats supported. But the code
  3507. should be safe (Thus bailing out, when ever some format comes in,
  3508. which is not fully understood.)
  3509. If you have urgent need for some particular format please mail me, I'll
  3510. see that I could implement it then. Unfortunately it is not possible
  3511. for me to test this code fully, since I do not have an X server, which
  3512. could understand all the possible formats. */
  3513. DEFCHECKER(get_image_format,default=, \
  3514. BITMAP=XYBitmap XY-PIXMAP=XYPixmap Z-PIXMAP=ZPixmap)
  3515. static uint16 get_image_width (void)
  3516. {
  3517. funcall (`XLIB::IMAGE-WIDTH`, 1);
  3518. return get_uint16 (value1);
  3519. }
  3520. static uint16 get_image_height (void)
  3521. {
  3522. funcall (`XLIB::IMAGE-HEIGHT`, 1);
  3523. return get_uint16 (value1);
  3524. }
  3525. static uint16 get_image_depth (void)
  3526. {
  3527. funcall (`XLIB::IMAGE-DEPTH`, 1);
  3528. return get_uint16 (value1);
  3529. }
  3530. static void ensure_valid_put_image_args (int src_x, int src_y, int w, int h,
  3531. int width, int height)
  3532. { /* ensure that the src_{x,y} and w, h arguments are valid,
  3533. signals error if not. */
  3534. /* I find it much easier to express the valid precondition instead of
  3535. the error condition; */
  3536. if (src_x >= 0 && (src_x + w) <= width &&
  3537. src_y >= 0 && (src_y + h) <= height) {
  3538. /* everything o.k. */
  3539. return;
  3540. } else {
  3541. /* TODO: Be more verbose here. */
  3542. error(error_condition,":SRC-X, :SRC-Y, :WIDTH, :HEIGHT are bad");
  3543. }
  3544. }
  3545. /* call XPutImage + XDestroyImage */
  3546. static void image_put_and_destroy (Display* dpy, Drawable drawable, GC gcontext,
  3547. XImage* im, int src_x, int src_y,
  3548. int x, int y, unsigned int w, unsigned int h)
  3549. {
  3550. begin_x_call();
  3551. XPutImage (dpy, drawable, gcontext, im, src_x, src_y, x,y,w,h);
  3552. XDestroyImage (im); /* Note: XDestroyImage frees im->data for us */
  3553. end_x_call();
  3554. dprintf (("\nXPutImage (.., src_x=%d, src_y=%d, x=%d,y=%d,w=%d,h=%d);",
  3555. src_x, src_y, x,y,w,h));
  3556. }
  3557. /* allocate memory and create the image */
  3558. static XImage* create_image (Display *dpy, unsigned int depth, int bitmap_p,
  3559. unsigned int width, unsigned int height,
  3560. int bytes_per_line) {
  3561. /* Allocate memory */
  3562. char *data = (char*) my_malloc (bytes_per_line * height);
  3563. XImage *im;
  3564. /* Actually create the image */
  3565. X_CALL(im = XCreateImage (dpy, 0, depth,
  3566. (bitmap_p && (depth == 1)) ? XYBitmap : ZPixmap, 0,
  3567. data, width, height, 32, bytes_per_line));
  3568. if (im == 0) {
  3569. free (data);
  3570. pushSTACK(TheSubr(subr_self)->name);
  3571. error(error_condition,"~S: XCreateImage call failed.");
  3572. }
  3573. dprintf (("im.bytes_per_line = %d (vs. %d)",
  3574. im->bytes_per_line, bytes_per_line));
  3575. return im;
  3576. }
  3577. static void handle_image_z (int src_x, int src_y, int x, int y, int w, int h,
  3578. GC gcontext, Drawable drawable,
  3579. int bitmap_p, Display *dpy)
  3580. { /* STACK_0 = the image object; cleans up stack after return
  3581. Handles images in the Z-format. This functions should be considered local to
  3582. xlib:put-image. */
  3583. int width;
  3584. int height;
  3585. int depth;
  3586. int bytes_per_line;
  3587. int ix, iy;
  3588. unsigned long v;
  3589. XImage *im;
  3590. /* First fetch the actual image geometry */
  3591. pushSTACK(STACK_0); width = get_image_width ();
  3592. pushSTACK(STACK_0); height = get_image_height ();
  3593. pushSTACK(STACK_0); depth = get_image_depth ();
  3594. /* Now ensure that src_x ... h are valid */
  3595. ensure_valid_put_image_args (src_x, src_y, w, h, width, height);
  3596. /* Calculate the bytes_per_line field */
  3597. switch (depth) {
  3598. case 1: bytes_per_line = ((width+31)/32)*4; break;
  3599. case 8: bytes_per_line = ((width+3)/4)*4; break;
  3600. default:
  3601. pushSTACK(sfixnum(depth));
  3602. pushSTACK(TheSubr(subr_self)->name);
  3603. error(error_condition,"~S: depth=~S is not supported");
  3604. }
  3605. /* Actually create the image */
  3606. im = create_image (dpy, depth, bitmap_p, width, height, bytes_per_line);
  3607. /* fetch the pixarray */
  3608. pushSTACK(STACK_0);
  3609. funcall (`XLIB::IMAGE-Z-PIXARRAY`, 1);
  3610. pushSTACK(value1);
  3611. /* Now the silly loop
  3612. This loop is anything but efficient.
  3613. On the other hand it works reliabably.
  3614. -- That is more important to me than speed. */
  3615. for (iy = 0; iy < height; iy++)
  3616. for (ix = 0; ix < width; ix++) {
  3617. pushSTACK(STACK_0);
  3618. pushSTACK(fixnum(iy));
  3619. pushSTACK(fixnum(ix));
  3620. funcall (L(aref), 3);
  3621. v = get_uint32 (value1);
  3622. X_CALL(XPutPixel (im, ix, iy, v));
  3623. }
  3624. skipSTACK(1); /* pixarray */
  3625. image_put_and_destroy (dpy, drawable, gcontext, im, src_x, src_y, x,y,w,h);
  3626. skipSTACK(1); /* clean up */
  3627. }
  3628. #if DEBUG_CLX
  3629. /* from Barry Fishman <barry_fishman@att.net>
  3630. http://article.gmane.org/gmane.lisp.clisp.general/7587
  3631. This presumes little-endian bitmaps */
  3632. void dump_image (XImage *image)
  3633. { /* test function to print the contents of the bitmap */
  3634. int x, y;
  3635. int height = image->height;
  3636. int width = image->width;
  3637. int line_len = image->bytes_per_line;
  3638. printf("\n;; Image (%s) %dx%dx%d, bpl= %d, pad= %d:\n",
  3639. ((char*[]){"bitmap","xy-pixmap","z-pixmap"})[image->format],
  3640. width,height,image->depth,line_len,image->bitmap_pad);
  3641. for (y = 0; y < height; y++) {
  3642. char * row = image->data + y * line_len;
  3643. printf(";|");
  3644. for (x = 0; x < width; x++)
  3645. printf( (row[x / 8] & (1 << (x % 8))) ? "*" : " ");
  3646. printf("|\n");
  3647. }
  3648. fflush(stdout);
  3649. }
  3650. #define DUMP_IMAGE(im) dump_image(im)
  3651. #else
  3652. #define DUMP_IMAGE(im)
  3653. #endif
  3654. /* make sure to call DISPLAY-FORCE-OUTPUT after this function! */
  3655. DEFUN(XLIB:PUT-IMAGE, drawable gcontext image \
  3656. &key SRC-X SRC-Y X Y WIDTH HEIGHT BITMAP-P)
  3657. { /* This is a *VERY* silly implementation.
  3658. XXX see that the keyword arguments are actually given */
  3659. Display *dpy;
  3660. int src_x = get_sint32_0(STACK_6);
  3661. int src_y = get_sint32_0(STACK_5);
  3662. int x = get_sint32 (STACK_4);
  3663. int y = get_sint32 (STACK_3);
  3664. int w = get_sint32 (STACK_2);
  3665. int h = get_sint32 (STACK_1);
  3666. GC gcontext = get_gcontext (STACK_8);
  3667. Drawable drawable = get_drawable_and_display (STACK_9, &dpy);
  3668. int bitmap_p = get_bool (STACK_0);
  3669. /* There seem to be three kinds of images passed in:
  3670. IMAGE-X, IMAGE-XY, IMAGE-Z */
  3671. /* First see if it is an IMAGE-X? */
  3672. pushSTACK(STACK_7); funcall (`XLIB::IMAGE-X-P`, 1);
  3673. if (!nullp (value1)) {
  3674. # if 0
  3675. pushSTACK(STACK_7);
  3676. handle_image_x (src_x, src_y, x, y, w, h, gcontext, drawable, bitmap_p, dpy);
  3677. # endif
  3678. /* image-x stuff
  3679. It seems that images of type image-x are already in the format
  3680. needed by XPutImage. */
  3681. XImage im;
  3682. /* Now fill in the XImage structure from the slots */
  3683. im.depth = get_uint8(funcall1(`XLIB::IMAGE-DEPTH`,STACK_7));
  3684. im.width = get_uint16(funcall1(`XLIB::IMAGE-WIDTH`,STACK_7));
  3685. im.height = get_uint16(funcall1(`XLIB::IMAGE-HEIGHT`,STACK_7));
  3686. im.format = get_image_format(funcall1(`XLIB::IMAGE-X-FORMAT`,STACK_7));
  3687. im.bytes_per_line = get_uint16(funcall1(`XLIB::IMAGE-X-BYTES-PER-LINE`,STACK_7));
  3688. im.bitmap_pad = get_uint8(funcall1(`XLIB::IMAGE-X-PAD`,STACK_7));
  3689. im.bits_per_pixel = get_uint8(funcall1(`XLIB::IMAGE-X-BITS-PER-PIXEL`,
  3690. STACK_7));
  3691. im.bitmap_bit_order = nullp(funcall1(`XLIB::IMAGE-X-BIT-LSB-FIRST-P`,
  3692. STACK_7)) ? MSBFirst : LSBFirst;
  3693. im.byte_order = nullp(funcall1(`XLIB::IMAGE-X-BYTE-LSB-FIRST-P`,
  3694. STACK_7)) ? MSBFirst : LSBFirst;
  3695. im.bitmap_unit = get_uint8(funcall1(`XLIB::IMAGE-X-UNIT`,STACK_7));
  3696. im.xoffset = get_uint8(funcall1(`XLIB::IMAGE-X-LEFT-PAD`,STACK_7));
  3697. if (bitmap_p && im.depth == 1)
  3698. im.format = XYBitmap;
  3699. /* Now fetch data - it *must* be a vector of card8 */
  3700. pushSTACK(STACK_7); funcall (`XLIB::IMAGE-X-DATA`, 1);
  3701. if (simple_bit_vector_p (Atype_8Bit, value1)) {
  3702. im.data = (char*)(TheSbvector(value1)->data);
  3703. } else {
  3704. pushSTACK(`(ARRAY XLIB::CARD8 (*))`);
  3705. pushSTACK(STACK_8);
  3706. pushSTACK(TheSubr (subr_self)->name);
  3707. error(error_condition,"~S: Slot :DATA of IMAGE-X ~S is not of type ~S.");
  3708. }
  3709. dprintf(("\n;; put-image: IMAGE-X -> %dx%d+%d+%d",w,h,x,y));
  3710. DUMP_IMAGE(&im);
  3711. X_CALL(XPutImage(dpy,drawable,gcontext,&im,src_x,src_y,x,y,w,h));
  3712. goto raus;
  3713. } else {
  3714. /* handle_image_z (src_x, src_y, x, y, w, h, gcontext, drawable,
  3715. bitmap_p, dpy); image-z or image-xy stuff */
  3716. XImage *im;
  3717. int width, height, depth;
  3718. unsigned long fg,bg;
  3719. width = get_sint32(funcall1(`XLIB::IMAGE-WIDTH`,STACK_7));
  3720. height = get_sint32(funcall1(`XLIB::IMAGE-HEIGHT`,STACK_7));
  3721. depth = get_sint32(funcall1(`XLIB::IMAGE-DEPTH`,STACK_7));
  3722. {
  3723. XGCValues vals;
  3724. X_CALL(XGetGCValues(dpy,gcontext,GCForeground|GCBackground,&vals));
  3725. fg = vals.foreground;
  3726. bg = vals.background;
  3727. dprintf (("\n;; put-image: IMAGE-XY %dx%dx%d", width,height,depth));
  3728. dprintf ((", fg=%.8x, bg=%.8x", fg,bg));
  3729. }
  3730. {
  3731. int bytes_per_line;
  3732. int ix, iy;
  3733. unsigned long v;
  3734. switch (depth) {
  3735. case 1: bytes_per_line = ((width+31)/32)*4; break;
  3736. case 8: bytes_per_line = ((width+3)/4)*4; break;
  3737. default:
  3738. goto fake;
  3739. }
  3740. im = create_image(dpy,depth,bitmap_p,width,height,bytes_per_line);
  3741. pushSTACK(STACK_7); funcall(`XLIB::IMAGE-XY-P`,1);
  3742. if (!nullp (value1)) {
  3743. pushSTACK(STACK_7); funcall(`XLIB::IMAGE-XY-BITMAP-LIST`,1);
  3744. pushSTACK(value1); funcall (L(car), 1);
  3745. pushSTACK(value1);
  3746. } else {
  3747. pushSTACK(STACK_7); funcall(`XLIB::IMAGE-Z-PIXARRAY`,1);
  3748. pushSTACK(value1);
  3749. }
  3750. dprintf (("\n;im = %.8x",im));
  3751. for (ix = 0; ix < width; ix++)
  3752. for (iy = 0; iy < height; iy++) {
  3753. pushSTACK(STACK_0);
  3754. pushSTACK(fixnum(iy));
  3755. pushSTACK(fixnum(ix));
  3756. funcall (L(aref), 3);
  3757. v = get_uint32 (value1);
  3758. X_CALL(XPutPixel (im, ix, iy, v));
  3759. }
  3760. skipSTACK(1);
  3761. image_put_and_destroy (dpy,drawable,gcontext,im,src_x,src_y,x,y,w,h);
  3762. }
  3763. goto raus;
  3764. }
  3765. fake:
  3766. dprintf ((" --- FAKED"));
  3767. raus:
  3768. skipSTACK(10);
  3769. }
  3770. /* -----------------------------------------------------------------------
  3771. * Chapter 8 Fonts and Characters
  3772. * ----------------------------------------------------------------------- */
  3773. /* 8.2 Opening Fonts */
  3774. DEFUN(XLIB:OPEN-FONT, display font)
  3775. {
  3776. Display *dpy = get_display(STACK_1);
  3777. Font font;
  3778. /* XXX Maybe a symbol should be o.k. here too? */
  3779. with_string_0 (check_string(STACK_0), GLO(misc_encoding), font_name, {
  3780. X_CALL(font = XLoadFont (dpy, font_name)); /* Load the font */
  3781. });
  3782. /* make up the LISP representation: */
  3783. VALUES1(make_font (STACK_1, font, STACK_0));
  3784. skipSTACK(2);
  3785. }
  3786. /* BTW: Mathematics and alcohol don`t mix -- Don't drink and derive.
  3787. [Found on somebody's signature]
  3788. Put here, because I dislike alcohol. (Err, sometimes ..) */
  3789. DEFUN(XLIB:CLOSE-FONT, font)
  3790. { /* FIXME: The manual says something about that fonts are reference
  3791. counted..? */
  3792. Display *dpy;
  3793. Font font = get_font_and_display (STACK_0, &dpy);
  3794. X_CALL(XUnloadFont (dpy, font));
  3795. funcall(``XLIB:DISCARD-FONT-INFO``,1);
  3796. }
  3797. DEFUN(XLIB:DISCARD-FONT-INFO, font)
  3798. {
  3799. XFontStruct *info = (XFontStruct*) foreign_slot(STACK_0,`XLIB::FONT-INFO`);
  3800. TheFpointer(value1)->fp_pointer = NULL; /* No longer valid */
  3801. if (info) X_CALL(XFreeFontInfo (NULL, info, 1));
  3802. skipSTACK(1);
  3803. VALUES1(NIL);
  3804. }
  3805. /* 8.3 Listing Fonts */
  3806. DEFUN(XLIB:FONT-PATH, display &key RESULT-TYPE) /* [OK] */
  3807. {
  3808. Display *dpy = get_display(STACK_1);
  3809. int npathen, i;
  3810. char **pathen;
  3811. gcv_object_t *res_type = &STACK_0;
  3812. X_CALL(pathen = XGetFontPath (dpy, &npathen));
  3813. for (i = 0; i < npathen; i++)
  3814. pushSTACK(asciz_to_string (pathen[i], GLO(misc_encoding)));
  3815. VALUES1(coerce_result_type(npathen,res_type));
  3816. X_CALL(if (pathen) XFreeFontPath (pathen));
  3817. skipSTACK(2); /* all done */
  3818. }
  3819. /* convert a Lisp sequence of pathnames to a C vector */
  3820. struct seq_path { char **path; };
  3821. void coerce_into_path (void *arg, object element);
  3822. void coerce_into_path (void *arg, object element) {
  3823. struct seq_path *rec = (struct seq_path *)arg;
  3824. if (stringp(element)) { coerce_into_path_string:
  3825. with_string_0 (element, GLO(pathname_encoding), frob, {
  3826. uintL j = frob_bytelen+1;
  3827. char *path = (char*)my_malloc(j);
  3828. while (j--) path[j] = frob[j];
  3829. *(rec->path++) = path;
  3830. });
  3831. } else {
  3832. element = physical_namestring(element);
  3833. goto coerce_into_path_string;
  3834. }
  3835. }
  3836. /* (SETF (XLIB:FONT-PATH display) new-path)
  3837. == (XLIB:SET-FONT-PATH display new-path)
  3838. NOTE - The CLX manual says that pathnames are also o.k. as arguments.
  3839. But I consider it dirty, since the X server may live on an
  3840. entirely different architecture than the client. */
  3841. DEFUN(XLIB:SET-FONT-PATH, display new-path)
  3842. {
  3843. Display *dpy = get_display(STACK_1);
  3844. int npathen = get_uint32(funcall1(L(length),STACK_0)) , i;
  3845. struct seq_path sp;
  3846. DYNAMIC_ARRAY (pathen, char*, npathen);
  3847. sp.path = pathen;
  3848. map_sequence(STACK_0,coerce_into_path,(void*)&sp);
  3849. begin_x_call();
  3850. XSetFontPath (dpy, pathen, npathen);
  3851. for (i = 0; i < npathen; i++) free (pathen [i]);
  3852. end_x_call();
  3853. FREE_DYNAMIC_ARRAY (pathen);
  3854. VALUES1(STACK_0);
  3855. skipSTACK(2);
  3856. }
  3857. /* XLIB:LIST-FONT-NAMES display pattern &key (:max-fonts 65535)
  3858. (:result-type 'list)
  3859. -> sequence of string. */
  3860. DEFUN(XLIB:LIST-FONT-NAMES, display pattern &key MAX-FONTS RESULT-TYPE)
  3861. { /* OK */
  3862. Display *dpy = get_display(STACK_3);
  3863. int max_fonts = check_uint_defaulted(STACK_1, 65535);
  3864. int count = 0, i;
  3865. char **names;
  3866. gcv_object_t *res_type = &STACK_0;
  3867. with_string_0 (check_string(STACK_2), GLO(misc_encoding), pattern, {
  3868. X_CALL(names = XListFonts (dpy, pattern, max_fonts, &count));
  3869. });
  3870. if (count) {
  3871. for (i = 0; i < count; i++)
  3872. pushSTACK(asciz_to_string (names[i], GLO(misc_encoding)));
  3873. X_CALL(XFreeFontNames (names));
  3874. }
  3875. VALUES1(coerce_result_type(count,res_type));
  3876. skipSTACK(4);
  3877. }
  3878. /* XLIB:LIST-FONTS display pattern &key (:max-fonts 65535)
  3879. (:result-type 'list)
  3880. returns a sequence of pseudo fonts. */
  3881. DEFUN(XLIB:LIST-FONTS, display pattern &key MAX-FONTS RESULT-TYPE)
  3882. {
  3883. Display *dpy = get_display(STACK_3);
  3884. gcv_object_t *dpyf = &(STACK_3);
  3885. int max_fonts = check_uint_defaulted(STACK_1, 65535);
  3886. int count = 0, i;
  3887. char **names;
  3888. gcv_object_t *res_type = &STACK_0;
  3889. with_string_0 (check_string(STACK_2), GLO(misc_encoding), pattern, {
  3890. /* we could use XListFontsWithInfo instead, but this would make
  3891. memory management impossible because the XFontStruct block
  3892. has to be released by XFreeFontInfo en mass and not piecewise */
  3893. X_CALL(names = XListFonts (dpy, pattern, max_fonts, &count));
  3894. });
  3895. if (count) {
  3896. for (i = 0; i < count; i++) {
  3897. Font fn;
  3898. X_CALL(fn = XLoadFont(dpy,names[i]));
  3899. pushSTACK(make_font(*dpyf,fn,asciz_to_string(names[i],
  3900. GLO(misc_encoding))));
  3901. }
  3902. X_CALL(XFreeFontNames (names));
  3903. }
  3904. VALUES1(coerce_result_type(count,res_type));
  3905. skipSTACK(4);
  3906. }
  3907. /* 8.4 Font Attributes */
  3908. ##define DEF_FONT_ATTR(lspnam, type, cnam) \
  3909. DEFUN(XLIB:##lspnam, font) { \
  3910. XFontStruct *info = get_font_info_and_display(STACK_0,NULL,NULL); \
  3911. VALUES1(make_##type(info->cnam)); \
  3912. skipSTACK(1); \
  3913. }
  3914. /* ------------------------------------------------------------------------
  3915. * lisp name type C slot
  3916. * ------------------------------------------------------------------------ */
  3917. DEF_FONT_ATTR(FONT-ALL-CHARS-EXIST-P,bool, all_chars_exist)
  3918. DEF_FONT_ATTR(FONT-ASCENT, sint16, ascent)
  3919. DEF_FONT_ATTR(FONT-DEFAULT-CHAR, uint16, default_char)
  3920. DEF_FONT_ATTR(FONT-DESCENT, sint16, descent)
  3921. DEF_FONT_ATTR(FONT-DIRECTION, draw_direction,direction)
  3922. DEF_FONT_ATTR(FONT-MAX-BYTE1, uint8, max_byte1)
  3923. DEF_FONT_ATTR(FONT-MAX-BYTE2, uint8, max_char_or_byte2)/* XXX */
  3924. DEF_FONT_ATTR(FONT-MAX-CHAR, uint16, max_char_or_byte2)
  3925. DEF_FONT_ATTR(FONT-MIN-BYTE1, uint8, min_byte1)
  3926. DEF_FONT_ATTR(FONT-MIN-BYTE2, uint8, min_char_or_byte2)/* XXX */
  3927. DEF_FONT_ATTR(FONT-MIN-CHAR, uint16, min_char_or_byte2)
  3928. DEF_FONT_ATTR(MAX-CHAR-ASCENT, sint16, max_bounds.ascent)
  3929. DEF_FONT_ATTR(MAX-CHAR-ATTRIBUTES, uint16, max_bounds.attributes)
  3930. DEF_FONT_ATTR(MAX-CHAR-DESCENT, sint16, max_bounds.descent)
  3931. DEF_FONT_ATTR(MAX-CHAR-LEFT-BEARING, sint16, max_bounds.lbearing)
  3932. DEF_FONT_ATTR(MAX-CHAR-RIGHT-BEARING,sint16, max_bounds.rbearing)
  3933. DEF_FONT_ATTR(MAX-CHAR-WIDTH, sint16, max_bounds.width)
  3934. DEF_FONT_ATTR(MIN-CHAR-ASCENT, sint16, min_bounds.ascent)
  3935. DEF_FONT_ATTR(MIN-CHAR-ATTRIBUTES, uint16, min_bounds.attributes)
  3936. DEF_FONT_ATTR(MIN-CHAR-DESCENT, sint16, min_bounds.descent)
  3937. DEF_FONT_ATTR(MIN-CHAR-LEFT-BEARING, sint16, min_bounds.lbearing)
  3938. DEF_FONT_ATTR(MIN-CHAR-RIGHT-BEARING,sint16, min_bounds.rbearing)
  3939. DEF_FONT_ATTR(MIN-CHAR-WIDTH, sint16, min_bounds.width)
  3940. /* -------------------------------------------------------------------- */
  3941. DEFUN(XLIB:FONT-NAME, font)
  3942. {
  3943. VALUES1(get_font_name(popSTACK()));
  3944. }
  3945. DEFUN(XLIB:FONT-PROPERTIES, font)
  3946. {
  3947. Display *dpy;
  3948. XFontStruct *font_struct = get_font_info_and_display (STACK_0, NULL, &dpy);
  3949. int i;
  3950. for (i = 0; i < font_struct->n_properties; i++) {
  3951. pushSTACK(make_xatom(dpy, font_struct->properties[i].name));
  3952. pushSTACK(make_uint32 (font_struct->properties[i].card32));
  3953. }
  3954. VALUES1(listof(2 * font_struct->n_properties));
  3955. skipSTACK(1); /* all done */
  3956. }
  3957. DEFUN(XLIB:FONT-PROPERTY, font name)
  3958. {
  3959. Display *dpy;
  3960. XFontStruct *font_struct = get_font_info_and_display (STACK_1, NULL, &dpy);
  3961. Atom atom = get_xatom (dpy, STACK_0);
  3962. unsigned long value, status;
  3963. X_CALL(status = XGetFontProperty (font_struct, atom, &value));
  3964. VALUES1(status ? make_uint32 (value) : NIL);
  3965. skipSTACK(2);
  3966. }
  3967. /* 8.5 Character Attributes */
  3968. static XCharStruct *font_char_info (XFontStruct *fs, unsigned int index)
  3969. {
  3970. /* from XLoadFont(3X11):
  3971. *
  3972. * If the min_byte1 and max_byte1 members are both zero,
  3973. * min_char_or_byte2 specifies the linear character index corresponding
  3974. * to the first element of the per_char array, and max_char_or_byte2
  3975. * specifies the linear character index of the last element.
  3976. * If either min_byte1 or max_byte1 are nonzero, both min_char_or_byte2
  3977. * and max_char_or_byte2 are less than 256, and the 2-byte character
  3978. * index values corresponding to the per_char array element N (counting
  3979. * from 0) are:
  3980. *
  3981. * byte1 = N/D + min_byte1
  3982. * byte2 = N\D + min_char_or_byte2
  3983. *
  3984. * where:
  3985. *
  3986. * D = max_char_or_byte2 - min_char_or_byte2 + 1
  3987. * / = integer division
  3988. * \ = integer modulus
  3989. */
  3990. if (fs->min_byte1 == 0 && fs->max_byte1 == 0) { /* Linear indexing ... */
  3991. if (index >= fs->min_char_or_byte2 && index <= fs->max_char_or_byte2)
  3992. return fs->per_char ? fs->per_char+(index-fs->min_char_or_byte2)
  3993. : &(fs->min_bounds);
  3994. } else { /* Nonlinear indexing .. */
  3995. unsigned char byte1 = (index >> 8) &0xFF; /* Is this right?! */
  3996. unsigned char byte2 = index & 0xFF;
  3997. unsigned int d = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1;
  3998. if (byte1 >= fs->min_byte1 && byte1 <= fs->max_byte1 &&
  3999. byte2 >= fs->min_char_or_byte2 && byte2 <= fs->max_char_or_byte2) {
  4000. index = (byte1 - fs->min_byte1)*d + (byte2 - fs->min_char_or_byte2);
  4001. return fs->per_char ? fs->per_char+index : &(fs->min_bounds);
  4002. }
  4003. }
  4004. /* BTW these two cases could be handled in one, but I leave it here
  4005. for clarity. */
  4006. /* fall thru' */
  4007. return NULL;
  4008. }
  4009. ##define DEF_CHAR_ATTR(lspnam, type, cnam) \
  4010. DEFUN(lspnam, font code) { \
  4011. XFontStruct *font_info = get_font_info_and_display(STACK_1,NULL,NULL);\
  4012. unsigned int index = get_uint16 (STACK_0); \
  4013. XCharStruct *char_info = font_char_info (font_info, index); \
  4014. if (char_info) \
  4015. if (char_info->lbearing == 0 && \
  4016. char_info->rbearing == 0 && \
  4017. char_info->width == 0 && \
  4018. char_info->attributes == 0 && \
  4019. char_info->ascent == 0 && \
  4020. char_info->descent == 0) \
  4021. value1 = NIL; \
  4022. else \
  4023. value1 = make_##type (char_info->cnam); \
  4024. else \
  4025. value1 = NIL; \
  4026. mv_count = 1; \
  4027. skipSTACK(2); \
  4028. }
  4029. DEF_CHAR_ATTR(XLIB:CHAR-LEFT-BEARING, sint16, lbearing)
  4030. DEF_CHAR_ATTR(XLIB:CHAR-RIGHT-BEARING, sint16, rbearing)
  4031. DEF_CHAR_ATTR(XLIB:CHAR-WIDTH, sint16, width)
  4032. DEF_CHAR_ATTR(XLIB:CHAR-ATTRIBUTES, sint16, attributes)
  4033. DEF_CHAR_ATTR(XLIB:CHAR-ASCENT, sint16, ascent)
  4034. DEF_CHAR_ATTR(XLIB:CHAR-DESCENT, sint16, descent)
  4035. /* 8.6 Querying Text Size */
  4036. DEFUN(XLIB:TEXT-EXTENTS, font obj &key :START :END TRANSLATE)
  4037. { /* FIXME: Could font be a graphics context?!
  4038. -- yes! This is handled by get_font_info_and_display already */
  4039. object font;
  4040. XFontStruct *font_info = get_font_info_and_display (STACK_4, &font, NULL);
  4041. int start = get_uint16_0 (STACK_2);
  4042. int dir;
  4043. int font_ascent, font_descent;
  4044. XCharStruct overall;
  4045. uintL len, offset;
  4046. object s_string = unpack_string_ro(STACK_3=check_string(STACK_3),
  4047. &len,&offset);
  4048. const chart* charptr;
  4049. int end = missingp(STACK_1) ? len : get_uint16(STACK_1);
  4050. /* START/END handling should be done via test_string_limits_ro ... */
  4051. if (end > len) end = len;
  4052. if (start > end) start = end;
  4053. unpack_sstring_alloca(s_string,end-start,start+offset,charptr=);
  4054. { DYNAMIC_ARRAY(str,XChar2b,end-start);
  4055. if (to_XChar2b(font,font_info,charptr,str,end-start) == 1)
  4056. X_CALL(XTextExtents (font_info, (char*)str, end-start, &dir,
  4057. &font_ascent, &font_descent, &overall));
  4058. else
  4059. X_CALL(XTextExtents16 (font_info, str, end-start, &dir,
  4060. &font_ascent, &font_descent, &overall));
  4061. FREE_DYNAMIC_ARRAY(str);
  4062. }
  4063. pushSTACK(make_sint32(overall.width)); /* width */
  4064. pushSTACK(make_sint16(overall.ascent)); /* ascent */
  4065. pushSTACK(make_sint16(overall.descent)); /* descent */
  4066. pushSTACK(make_sint16(overall.lbearing)); /* left */
  4067. pushSTACK(make_sint16(overall.rbearing)); /* right */
  4068. pushSTACK(make_sint16(font_ascent)); /* font-ascent */
  4069. pushSTACK(make_sint16(font_descent)); /* font-descent */
  4070. pushSTACK(make_draw_direction (dir)); /* direction */
  4071. pushSTACK(NIL); /* first-not-done */
  4072. value9 = popSTACK();
  4073. value8 = popSTACK();
  4074. value7 = popSTACK();
  4075. value6 = popSTACK();
  4076. value5 = popSTACK();
  4077. value4 = popSTACK();
  4078. value3 = popSTACK();
  4079. value2 = popSTACK();
  4080. value1 = popSTACK();
  4081. mv_count = 9;
  4082. skipSTACK(5);
  4083. }
  4084. /* -> width - Type int32
  4085. -> first-not-done - Type array-index or null. */
  4086. DEFUN(XLIB:TEXT-WIDTH, font sequence &key :START :END TRANSLATE)
  4087. {
  4088. object font;
  4089. XFontStruct *font_info = get_font_info_and_display (STACK_4, &font, NULL);
  4090. if (stringp(STACK_3)) {
  4091. int start = get_uint16_0 (STACK_2);
  4092. int w;
  4093. uintL len, offset;
  4094. object s_string = unpack_string_ro(STACK_3,&len,&offset);
  4095. const chart* charptr;
  4096. int end = missingp(STACK_1) ? len : get_uint16(STACK_1);
  4097. /* START/END handling should be done via test_string_limits_ro ... */
  4098. if (end > len) end = len;
  4099. if (start > end) start = end;
  4100. unpack_sstring_alloca(s_string,end-start,start+offset,charptr=);
  4101. { DYNAMIC_ARRAY(str,XChar2b,end-start);
  4102. if (to_XChar2b(font,font_info,charptr,str,end-start) == 1)
  4103. X_CALL(w = XTextWidth (font_info, (char*)str, end-start));
  4104. else
  4105. X_CALL(w = XTextWidth16 (font_info, str, end-start));
  4106. FREE_DYNAMIC_ARRAY(str);
  4107. }
  4108. VALUES2(make_sint32 (w),NIL);
  4109. } else if (listp (STACK_3)) {
  4110. /* Now the generic case for lists
  4111. XXX -- Fix this also above
  4112. XXX This is faked, isn't it. */
  4113. VALUES2(make_sint32(0),NIL);
  4114. } else if (vectorp (STACK_3)) {
  4115. /* Generic case for vectors.
  4116. XXX faked. */
  4117. int start = get_uint16_0 (STACK_2);
  4118. int end = missingp(STACK_1) ? vector_length (STACK_3) : get_uint16 (STACK_1);
  4119. VALUES2(make_sint32(0),NIL);
  4120. } else
  4121. my_type_error(S(sequence),STACK_3);
  4122. skipSTACK(5);
  4123. }
  4124. /* -----------------------------------------------------------------------
  4125. * Chapter 9 Colors
  4126. * ----------------------------------------------------------------------- */
  4127. /* 9.2 Color Functions
  4128. These functions moved to LISP.
  4129. MAKE-COLOR COLOR-BLUE COLOR-GREEN COLOR-P COLOR-RED COLOR-RGB
  4130. */
  4131. /* 9.3 Colormap Functions */
  4132. DEFUN(XLIB:CREATE-COLORMAP, visual colormap &optional alloc-p)
  4133. {
  4134. int alloc_p = !missingp(STACK_0);
  4135. Display *dpy;
  4136. Window win = get_window_and_display (STACK_1, &dpy);
  4137. Visual *vis = get_visual (dpy, STACK_2);
  4138. Colormap map;
  4139. X_CALL(map = XCreateColormap (dpy, win, vis, alloc_p));
  4140. VALUES1(make_colormap (get_display_obj (STACK_1), map));
  4141. skipSTACK(3);
  4142. }
  4143. DEFUN(XLIB:COPY-COLORMAP-AND-FREE, colormap)
  4144. {
  4145. Display *dpy;
  4146. Colormap cm = get_colormap_and_display (STACK_0, &dpy);
  4147. Colormap cm2;
  4148. X_CALL(cm2 = XCopyColormapAndFree (dpy, cm));
  4149. VALUES1(make_colormap (get_display_obj (STACK_0), cm2));
  4150. skipSTACK(1);
  4151. }
  4152. DEFUN(XLIB:FREE-COLORMAP, colormap)
  4153. {
  4154. Display *dpy;
  4155. Colormap cm = get_colormap_and_display (popSTACK(), &dpy);
  4156. X_CALL(XFreeColormap (dpy, cm));
  4157. VALUES1(NIL);
  4158. }
  4159. DEFUN(XLIB:INSTALL-COLORMAP, colormap)
  4160. {
  4161. Display *dpy;
  4162. Colormap cm = get_colormap_and_display (popSTACK(), &dpy);
  4163. X_CALL(XInstallColormap (dpy, cm));
  4164. VALUES1(NIL);
  4165. }
  4166. DEFUN(XLIB:INSTALLED-COLORMAPS, window &key RESULT-TYPE)
  4167. {
  4168. Display *dpy;
  4169. Window win = get_window_and_display (STACK_1, &dpy);
  4170. gcv_object_t *dpy_objf = &(STACK_1);
  4171. int num_cms = 0; /* paranoia */
  4172. int i;
  4173. Colormap *cms;
  4174. gcv_object_t *res_type = &STACK_0;
  4175. X_CALL(cms = XListInstalledColormaps (dpy, win, &num_cms));
  4176. /* Now push all colormaps ... */
  4177. for (i = 0; i < num_cms; i++)
  4178. pushSTACK(make_colormap (*dpy_objf, cms[i]));
  4179. if (cms) X_CALL(XFree (cms));
  4180. /* Now cons 'em together */
  4181. VALUES1(coerce_result_type(num_cms,res_type));
  4182. skipSTACK(2); /* all done */
  4183. }
  4184. DEFUN(XLIB:UNINSTALL-COLORMAP, colormap)
  4185. {
  4186. Display *dpy;
  4187. Colormap cm = get_colormap_and_display (popSTACK(), &dpy);
  4188. X_CALL(XUninstallColormap (dpy, cm));
  4189. VALUES1(NIL);
  4190. }
  4191. /*
  4192. xlib:colormap-visual-info colormap
  4193. returns the visual-info corresponding to a colormap
  4194. NIM
  4195. */
  4196. DEFUN(XLIB:COLORMAP-VISUAL-INFO, colormap)
  4197. {
  4198. Display *dpy;
  4199. Colormap cm = get_colormap_and_display (STACK_0, &dpy);
  4200. Visual *vis;
  4201. begin_x_call();
  4202. {
  4203. XcmsCCC ccc = XcmsCCCOfColormap (dpy, cm);
  4204. vis = ccc ? XcmsVisualOfCCC (ccc) : 0;
  4205. /* FIXME: Should we free the XcmsCCC? are they hashed or what? */
  4206. }
  4207. end_x_call();
  4208. VALUES1(vis ? make_visual_info (vis) : NIL);
  4209. skipSTACK(1);
  4210. }
  4211. nonreturning_function(static, error_no_such_color,
  4212. (object display, object color)) {
  4213. pushSTACK(display); /* get_display_obj() can trigger GC! */
  4214. pushSTACK(color); /* color argument */
  4215. pushSTACK(TheSubr(subr_self)->name);
  4216. STACK_2 = get_display_obj(STACK_2); /* display argument */
  4217. error(error_condition,"~S: Color ~S is unknown to display ~S.");
  4218. }
  4219. DEFUN(XLIB:ALLOC-COLOR, arg1 arg2)
  4220. {
  4221. Display *dpy;
  4222. Colormap cm = get_colormap_and_display (STACK_1, &dpy);
  4223. XColor color;
  4224. int status;
  4225. if (stringp (STACK_0) || symbolp (STACK_0)) {
  4226. XColor exact_color;
  4227. with_stringable_0_tc (STACK_0, GLO(misc_encoding), name, {
  4228. X_CALL(status = XAllocNamedColor(dpy,cm,name,&color,&exact_color));
  4229. if (status) {
  4230. pushSTACK(make_pixel (color.pixel)); /* pixel */
  4231. pushSTACK(make_color (&color)); /* screen color */
  4232. value3 = make_color (&exact_color); /* exact color */
  4233. value2 = popSTACK();
  4234. value1 = popSTACK();
  4235. mv_count = 3;
  4236. } else
  4237. goto failed;
  4238. });
  4239. } else if (color_p (STACK_0)) {
  4240. get_color (dpy, STACK_0, &color);
  4241. X_CALL(status = XAllocColor(dpy,cm,&color));
  4242. if (status) {
  4243. pushSTACK(make_pixel(color.pixel)); /* pixel */
  4244. value2 = make_color(&color); /* screen color */
  4245. value3 = STACK_1; /* exact color (what the luser gave) */
  4246. value1 = popSTACK();
  4247. mv_count = 3;
  4248. } else
  4249. goto failed;
  4250. } else my_type_error(`(OR STRING SYMBOL XLIB::COLOR)`,STACK_0);
  4251. skipSTACK(2);
  4252. return;
  4253. failed: /* I have to see what the MIT-CLX implementation does here ... */
  4254. error_no_such_color(STACK_1,STACK_0);
  4255. }
  4256. /* XLIB:ALLOC-COLOR-CELLS colormap colors &key (:planes 0) :contiguous-p
  4257. (:result-type 'list)
  4258. returns
  4259. pixels, masks -- Type sequence of pixels */
  4260. DEFUN(XLIB:ALLOC-COLOR-CELLS, colormap colors \
  4261. &key PLANES CONTIGUOUS-P RESULT-TYPE)
  4262. {
  4263. Display *dpy;
  4264. Colormap cm = get_colormap_and_display (STACK_4, &dpy);
  4265. unsigned int npixels = get_uint32 (STACK_3);
  4266. unsigned int nplanes = get_uint32_0(STACK_2);
  4267. Bool contiguous_p = !missingp(STACK_1);
  4268. gcv_object_t *res_type = &STACK_0;
  4269. int status;
  4270. /* FIXME -- we should introduce some checks here, since if the luser gave
  4271. nonsense arguments, we might run into real problems. */
  4272. {
  4273. DYNAMIC_ARRAY (plane_masks, unsigned long, nplanes);
  4274. {
  4275. DYNAMIC_ARRAY (pixels, unsigned long, npixels);
  4276. X_CALL(status = XAllocColorCells(dpy,cm,contiguous_p,plane_masks,
  4277. nplanes,pixels,npixels));
  4278. if (status) {
  4279. unsigned i;
  4280. for (i = 0; i < nplanes; i++)
  4281. pushSTACK(make_uint32 (plane_masks [i]));
  4282. value1 = coerce_result_type(nplanes,res_type);
  4283. pushSTACK(value1);
  4284. for (i = 0; i < npixels; i++)
  4285. pushSTACK(make_uint32 (pixels [i]));
  4286. VALUES2(coerce_result_type(npixels,res_type),popSTACK());
  4287. } else
  4288. /* Q: Should we raise a x-error-sonstwas condition here? */
  4289. VALUES1(NIL);
  4290. FREE_DYNAMIC_ARRAY (pixels);
  4291. }
  4292. FREE_DYNAMIC_ARRAY (plane_masks);
  4293. }
  4294. skipSTACK(5);
  4295. }
  4296. /* XLIB:ALLOC-COLOR-PLANES colormap colors &key (:reds 0) (:greens 0)
  4297. (:blues 0) :contiguous-p (:result-type 'list)
  4298. returns: pixels -- Type sequence of pixels
  4299. red-mask, green-mask, blue-mask -- Type pixel. */
  4300. DEFUN(XLIB:ALLOC-COLOR-PLANES, colormap colors \
  4301. &key REDS GREENS BLUES CONTIGUOUS-P RESULT-TYPE)
  4302. {
  4303. Display *dpy;
  4304. Colormap cm = get_colormap_and_display (STACK_6, &dpy);
  4305. unsigned int ncolors = get_uint32 (STACK_5);
  4306. unsigned int nreds = get_uint32_0(STACK_4);
  4307. unsigned int ngreens = get_uint32_0(STACK_3);
  4308. unsigned int nblues = get_uint32_0(STACK_2);
  4309. Bool contiguous_p = !missingp(STACK_1);
  4310. unsigned long red_mask, green_mask, blue_mask;
  4311. gcv_object_t *res_type = &STACK_0;
  4312. {
  4313. int status;
  4314. DYNAMIC_ARRAY (pixels, unsigned long, ncolors);
  4315. X_CALL(status = XAllocColorPlanes(dpy,cm,contiguous_p,pixels,ncolors,
  4316. nreds,ngreens,nblues,
  4317. &red_mask,&green_mask,&blue_mask));
  4318. if (status) {
  4319. uintC i;
  4320. for (i = 0; i < ncolors; i++)
  4321. pushSTACK(make_uint32 (pixels [i]));
  4322. value1 = coerce_result_type(ncolors,res_type);
  4323. pushSTACK(value1);
  4324. pushSTACK(make_uint32 (red_mask));
  4325. pushSTACK(make_uint32 (green_mask));
  4326. pushSTACK(make_uint32 (blue_mask));
  4327. value1 = STACK_3;
  4328. value2 = STACK_2;
  4329. value3 = STACK_1;
  4330. value4 = STACK_0;
  4331. mv_count = 4;
  4332. skipSTACK(4);
  4333. } else
  4334. VALUES1(NIL);
  4335. FREE_DYNAMIC_ARRAY (pixels);
  4336. }
  4337. skipSTACK(7);
  4338. }
  4339. /* convert a Lisp sequence of pixels to a C vector */
  4340. struct seq_pixel { unsigned long* pixel; };
  4341. void coerce_into_pixel (void *arg, object element);
  4342. void coerce_into_pixel (void *arg, object element)
  4343. { *(((struct seq_pixel *)arg)->pixel++) = get_pixel(element); }
  4344. DEFUN(XLIB:FREE-COLORS, colormap pixels &optional plane-mask)
  4345. {
  4346. Display *dpy;
  4347. Colormap cm = get_colormap_and_display (STACK_2, &dpy);
  4348. unsigned long plane_mask = (boundp(STACK_0) ? get_pixel (STACK_0) : 0);
  4349. unsigned int npixels = get_uint32(funcall1(L(length),STACK_1));
  4350. struct seq_pixel sp;
  4351. DYNAMIC_ARRAY (pixels, unsigned long, npixels);
  4352. sp.pixel = pixels;
  4353. map_sequence(STACK_1,coerce_into_pixel,(void*)&sp);
  4354. X_CALL(XFreeColors (dpy, cm, pixels, npixels, plane_mask));
  4355. FREE_DYNAMIC_ARRAY (pixels);
  4356. VALUES1(NIL);
  4357. skipSTACK(3);
  4358. }
  4359. DEFUN(XLIB:LOOKUP-COLOR, colormap name) /* [OK] */
  4360. {
  4361. Display *dpy;
  4362. Colormap cm = get_colormap_and_display (STACK_1, &dpy);
  4363. XColor exact_color, screen_color;
  4364. int status;
  4365. with_stringable_0_tc (STACK_0, GLO(misc_encoding), name, {
  4366. X_CALL(status = XLookupColor(dpy,cm,name,&exact_color,&screen_color));
  4367. if (status) {
  4368. pushSTACK(make_color (&screen_color));
  4369. value2 = make_color (&exact_color);
  4370. value1 = popSTACK();
  4371. mv_count = 2;
  4372. } else
  4373. error_no_such_color(STACK_1,STACK_0);
  4374. });
  4375. skipSTACK(2);
  4376. }
  4377. /* convert a Lisp sequence of pixels to a C vector of colors at them */
  4378. void coerce_into_color (void *arg, object element);
  4379. void coerce_into_color (void *arg, object element) {
  4380. ((XColor*)arg)->pixel = get_pixel(element);
  4381. }
  4382. DEFUN(XLIB:QUERY-COLORS, colormap pixels &key RESULT-TYPE)
  4383. { /* returns: colors -- Type sequence of color. */
  4384. Display *dpy;
  4385. Colormap cm = get_colormap_and_display (STACK_2, &dpy);
  4386. gcv_object_t *res_type = &STACK_0;
  4387. int ncolors = get_uint32(funcall1(L(length),STACK_1)), i;
  4388. DYNAMIC_ARRAY (colors, XColor, ncolors);
  4389. map_sequence(STACK_1,coerce_into_color,(void*)colors);
  4390. X_CALL(XQueryColors (dpy, cm, colors, ncolors));
  4391. /* FIXME - find what to do with the DoRed, DoGreen, and DoBlue flags?! */
  4392. for (i = 0; i < ncolors; i++)
  4393. pushSTACK(make_color (&(colors[i])));
  4394. VALUES1(coerce_result_type(ncolors,res_type));
  4395. FREE_DYNAMIC_ARRAY (colors);
  4396. skipSTACK(3); /* all done */
  4397. }
  4398. DEFFLAGSET(xlib_rgb, DoRed DoGreen DoBlue)
  4399. /* XLIB:STORE-COLOR colormap pixel color
  4400. &key (:red-p t) (:green-p t) (:blue-p t) */
  4401. DEFUN(XLIB:STORE-COLOR, colormap pixel color &key RED-P GREEN-P BLUE-P)
  4402. {
  4403. char flags = xlib_rgb();
  4404. Display *dpy;
  4405. Colormap cm = get_colormap_and_display (STACK_2, &dpy);
  4406. XColor color;
  4407. get_color (dpy, STACK_0, &color);
  4408. color.pixel = get_uint32 (STACK_1);
  4409. color.flags = flags;
  4410. X_CALL(XStoreColor (dpy, cm, &color));
  4411. VALUES0;
  4412. skipSTACK(3);
  4413. }
  4414. /* convert a Lisp sequence of (pixel color) to a C vector of colors */
  4415. struct seq_pixel_color { Display *dpy; XColor* color; int slot; char flags; };
  4416. void coerce_into_pixel_color (void *arg, object element);
  4417. void coerce_into_pixel_color (void *arg, object element) {
  4418. struct seq_pixel_color *spc = (struct seq_pixel_color *)arg;
  4419. switch (spc->slot) {
  4420. case 0:
  4421. spc->color->pixel = get_pixel(element);
  4422. spc->color->flags = spc->flags;
  4423. spc->slot = 1; break;
  4424. case 1:
  4425. get_color(spc->dpy,element,spc->color++);
  4426. spc->slot = 0; break;
  4427. }
  4428. }
  4429. /* XLIB:STORE-COLORS colormap pixel-colors
  4430. &key (:red-p t) (:green-p t) (:blue-p t) */
  4431. DEFUN(XLIB:STORE-COLORS, colormap pixel-colors &key RED-P GREEN-P BLUE-P)
  4432. {
  4433. char flags = xlib_rgb();
  4434. Display *dpy;
  4435. Colormap cm = get_colormap_and_display (STACK_1, &dpy);
  4436. int ncolors = get_seq_len(&STACK_0,&`XLIB::PIXEL-COLORS-SEQ`,2);
  4437. struct seq_pixel_color spc;
  4438. DYNAMIC_ARRAY (colors, XColor, ncolors);
  4439. spc.dpy = dpy; spc.color = colors; spc.slot = 0; spc.flags = flags;
  4440. map_sequence(STACK_0,coerce_into_pixel_color,(void*)&spc);
  4441. X_CALL(XStoreColors (dpy, cm, colors, ncolors));
  4442. FREE_DYNAMIC_ARRAY (colors);
  4443. VALUES1(NIL);
  4444. skipSTACK(2);
  4445. }
  4446. /* -----------------------------------------------------------------------
  4447. * Chapter 10 Cursors
  4448. * ----------------------------------------------------------------------- */
  4449. /* 10.2 Creating Cursors */
  4450. /* XLIB:CREATE-CURSOR &key [5]:source [4]:mask [3]:x [2]:y
  4451. [1]:foreground [0]:background
  4452. FIXME: May also here are color names legal?! */
  4453. DEFUN(XLIB:CREATE-CURSOR, &key SOURCE MASK X Y FOREGROUND BACKGROUND)
  4454. {
  4455. Display *dpy;
  4456. Pixmap source;
  4457. Pixmap mask = None;
  4458. XColor foreground;
  4459. XColor background;
  4460. unsigned int x, y;
  4461. Cursor cursor;
  4462. if (boundp(STACK_5))
  4463. source = get_pixmap_and_display (STACK_5, &dpy);
  4464. else
  4465. goto required;
  4466. if (boundp(STACK_4))
  4467. mask = get_pixmap (STACK_4);
  4468. if (boundp(STACK_3))
  4469. x = get_sint16 (STACK_3);
  4470. else
  4471. goto required;
  4472. if (boundp(STACK_2))
  4473. y = get_sint16 (STACK_2);
  4474. else
  4475. goto required;
  4476. if (boundp(STACK_1))
  4477. get_color (dpy, STACK_1, &foreground);
  4478. else
  4479. goto required;
  4480. if (boundp(STACK_0))
  4481. get_color (dpy, STACK_0, &background);
  4482. else
  4483. goto required;
  4484. X_CALL(cursor = XCreatePixmapCursor (dpy, source, mask, &foreground,
  4485. &background, x, y));
  4486. VALUES1(make_cursor (get_display_obj (STACK_5),cursor));
  4487. skipSTACK(6); /* All done */
  4488. return;
  4489. required:
  4490. error_required_keywords(`(:SOURCE :X :Y :FOREGROUND :BACKGROUND)`);
  4491. }
  4492. /* XLIB:CREATE-GLYPH-CURSOR &key [5]:source-font [4]:source-char
  4493. [3]:mask-font [2](:mask-char 0) [1]:foreground [0]:background */
  4494. DEFUN(XLIB:CREATE-GLYPH-CURSOR, &key SOURCE-FONT SOURCE-CHAR MASK-FONT \
  4495. MASK-CHAR FOREGROUND BACKGROUND)
  4496. {
  4497. Display *dpy;
  4498. Font source_font;
  4499. unsigned int source_char;
  4500. Font mask_font = None;
  4501. unsigned int mask_char = 0;
  4502. XColor foreground;
  4503. XColor background;
  4504. Cursor cursor;
  4505. if (boundp(STACK_5)) /* :source-font */
  4506. source_font = get_font_and_display (STACK_5, &dpy);
  4507. else
  4508. goto required;
  4509. if (boundp(STACK_4)) /* :source-char */
  4510. source_char = get_uint16 (STACK_4);
  4511. else
  4512. goto required;
  4513. if (boundp(STACK_3)) /* :mask-font */
  4514. mask_font = get_font (STACK_3);
  4515. if (boundp(STACK_2)) /* :mask-char */
  4516. mask_char = get_uint16 (STACK_2);
  4517. if (boundp(STACK_1)) /* :foreground */
  4518. get_color (dpy, STACK_1, &foreground);
  4519. else
  4520. goto required;
  4521. if (boundp(STACK_0)) /* :background */
  4522. get_color (dpy, STACK_0, &background);
  4523. else
  4524. goto required;
  4525. X_CALL(cursor = XCreateGlyphCursor (dpy, source_font, mask_font, source_char,
  4526. mask_char, &foreground, &background));
  4527. VALUES1(make_cursor (get_display_obj (STACK_5),cursor));
  4528. skipSTACK(6); /* All done */
  4529. return;
  4530. required:
  4531. error_required_keywords(`(:SOURCE-FONT :SOURCE-CHAR :FOREGROUND :BACKGROUND)`);
  4532. }
  4533. DEFUN(XLIB:FREE-CURSOR, cursor)
  4534. {
  4535. Display *dpy;
  4536. Cursor cur = get_cursor_and_display (STACK_0, &dpy);
  4537. X_CALL(XFreeCursor (dpy, cur));
  4538. skipSTACK(1);
  4539. VALUES1(NIL);
  4540. }
  4541. /* 10.3 Cursor Functions */
  4542. DEFUN(XLIB:QUERY-BEST-CURSOR, arg1 arg2 arg3)
  4543. {
  4544. query_best_X (XQueryBestCursor);
  4545. }
  4546. /* XLIB:RECOLOR-CURSOR cursor foreground background
  4547. FIXME? Are color names also OK here? */
  4548. DEFUN(XLIB:RECOLOR-CURSOR, arg1 arg2 arg3)
  4549. {
  4550. Display *dpy;
  4551. Cursor cursor = get_cursor_and_display (STACK_2, &dpy);
  4552. XColor foreground,background;
  4553. get_color (dpy, STACK_1, &foreground);
  4554. get_color (dpy, STACK_1, &background);
  4555. X_CALL(XRecolorCursor (dpy, cursor, &foreground, &background));
  4556. VALUES1(NIL);
  4557. skipSTACK(3); /* all done */
  4558. }
  4559. /* 10.4 Cursor Attributes */
  4560. /* -----------------------------------------------------------------------
  4561. * Chapter 11 Atoms, Properties and Selections
  4562. * ----------------------------------------------------------------------- */
  4563. /* 11.1 Atoms */
  4564. DEFUN(XLIB:ATOM-NAME, display atom) /* OK */
  4565. {
  4566. Atom atom = get_uint29 (popSTACK());
  4567. Display *dpy = pop_display ();
  4568. VALUES1(make_xatom(dpy,atom));
  4569. }
  4570. DEFUN(XLIB:FIND-ATOM, display atom) /* OK */
  4571. {
  4572. Display *dpy = get_display(STACK_1);
  4573. Atom atom = get_xatom_nointern (dpy, STACK_0);
  4574. skipSTACK(2);
  4575. VALUES1((atom != None) ? make_uint32 (atom) : NIL);
  4576. }
  4577. DEFUN(XLIB:INTERN-ATOM, display atom) /* OK */
  4578. {
  4579. Display *dpy = get_display(STACK_1);
  4580. Atom atom = get_xatom (dpy, STACK_0);
  4581. skipSTACK(2);
  4582. VALUES1((atom != None) ? make_uint32 (atom) : NIL);
  4583. }
  4584. /* 11.2 Properties */
  4585. /* convert a Lisp sequence of (pixel color) to a C vector of colors */
  4586. struct seq_map { gcv_object_t *transform; unsigned char *data; int format; };
  4587. void coerce_into_map (void *arg, object element);
  4588. void coerce_into_map (void *arg, object element) {
  4589. struct seq_map *sm = (struct seq_map *)arg;
  4590. if (!missingp(*(sm->transform))) { /* call the transform function */
  4591. pushSTACK(element); funcall(*(sm->transform),1); element = value1;
  4592. }
  4593. switch (sm->format) {
  4594. case 8: *((uint8*)(sm->data)) = get_uint8(element); sm->data++; break;
  4595. case 16: *((uint16*)(sm->data)) = get_uint16(element); sm->data+=2; break;
  4596. case 32: *((uint32*)(sm->data)) = get_aint32(element); sm->data+=4; break;
  4597. /* NOTE: I am using aint32, here not knowing if that is correct,
  4598. the manual does not specify of which type the property data
  4599. should be. [aint16, aint8 also?]. */
  4600. default:
  4601. NOTREACHED;
  4602. }
  4603. }
  4604. DEFCHECKER(check_propmode,default=PropModeReplace, REPLACE=PropModeReplace \
  4605. PREPEND=PropModePrepend :APPEND=PropModeAppend)
  4606. /* XLIB:CHANGE-PROPERTY window property data type format
  4607. &key (:mode :replace) (:start 0) :end :transform */
  4608. DEFUN(XLIB:CHANGE-PROPERTY, window property data type format \
  4609. &key MODE :START :END TRANSFORM)
  4610. {
  4611. Display *dpy;
  4612. Window win = get_window_and_display (STACK_8, &dpy);
  4613. Atom property = get_xatom (dpy, STACK_7);
  4614. Atom type = get_xatom (dpy, STACK_5);
  4615. int format = get_client_message_format (STACK_4);
  4616. int mode = check_propmode(STACK_3);
  4617. int start = get_uint32_0 (STACK_2);
  4618. int end;
  4619. int len;
  4620. if (missingp(STACK_1)) /* data argument */
  4621. end = get_uint32(funcall1(L(length),STACK_6));
  4622. else
  4623. end = get_uint32 (STACK_1);
  4624. len = (end-start) * (format/8);
  4625. if (len < 0) {
  4626. pushSTACK(make_sint32 (len));
  4627. pushSTACK(TheSubr (subr_self)->name);
  4628. error(error_condition,
  4629. "~S: How bogus! The effective length (~S) is negative.");
  4630. }
  4631. {
  4632. struct seq_map sm;
  4633. DYNAMIC_ARRAY (data, unsigned char, len ? len : 1);
  4634. sm.transform = &STACK_0; sm.data = data; sm.format = format;
  4635. map_sequence(STACK_6,coerce_into_map,(void*)&sm);
  4636. X_CALL(XChangeProperty (dpy, win, property, type, format, mode, data,
  4637. (end-start)));
  4638. FREE_DYNAMIC_ARRAY (data);
  4639. }
  4640. VALUES1(NIL);
  4641. skipSTACK(9);
  4642. }
  4643. DEFUN(XLIB:DELETE-PROPERTY, arg1 arg2) /* OK */
  4644. {
  4645. Display *dpy;
  4646. Window win = get_window_and_display (STACK_1, &dpy);
  4647. Atom atom = get_xatom_nointern (dpy, STACK_0);
  4648. if (atom != None)
  4649. X_CALL(XDeleteProperty (dpy, win, atom));
  4650. VALUES1(NIL);
  4651. skipSTACK(2); /* all done */
  4652. }
  4653. /* XLIB:GET-PROPERTY window property
  4654. &key :type (:start 0) :end :delete-p (:result-type 'list) :transform
  4655. returns: data -- Type sequence
  4656. type -- Type xatom
  4657. format -- Type (member 8 16 32)
  4658. bytes-after -- Type card32 */
  4659. DEFUN(XLIB:GET-PROPERTY,window property \
  4660. &key :TYPE :START :END DELETE-P RESULT-TYPE TRANSFORM) /* OK */
  4661. {
  4662. /* input: */
  4663. Display *display;
  4664. Window w;
  4665. Atom property;
  4666. long long_offset, long_length;
  4667. Bool delete_p;
  4668. Atom req_type;
  4669. /* output: */
  4670. Atom actual_type_return;
  4671. int actual_format_return;
  4672. unsigned long nitems_return;
  4673. unsigned long bytes_after_return;
  4674. unsigned char *prop_return = NULL;
  4675. Status r;
  4676. w = get_xid_object_and_display (`XLIB::WINDOW`, STACK_7, &display);
  4677. property = get_xatom (display, STACK_6);
  4678. /* How is :start/:end counted?
  4679. CLX counts the same way libX counts [This should be documented.] */
  4680. long_offset = get_uint32_0 (STACK_4);
  4681. long_length = (missingp(STACK_3) ? 0x7FFFFFFF : (get_uint32(STACK_3) - long_offset));
  4682. delete_p = (missingp(STACK_2) ? 0 : 1);
  4683. req_type = (missingp(STACK_5) ? AnyPropertyType : get_xatom (display, STACK_5));
  4684. X_CALL(r = XGetWindowProperty (display, w, property,long_offset,long_length,
  4685. delete_p, req_type,
  4686. &actual_type_return, &actual_format_return,
  4687. &nitems_return, &bytes_after_return,
  4688. &prop_return));
  4689. if (r != Success || actual_type_return == None) {
  4690. pushSTACK(NIL);
  4691. pushSTACK(NIL);
  4692. pushSTACK(fixnum(0));
  4693. pushSTACK(fixnum(0));
  4694. } else {
  4695. if (req_type != AnyPropertyType && actual_type_return != req_type) {
  4696. pushSTACK(NIL);
  4697. } else {
  4698. uintC i;
  4699. gcv_object_t *transform_f = &(STACK_0);
  4700. gcv_object_t *result_type_f = &(STACK_1);
  4701. for (i = 0; i < nitems_return; i++) {
  4702. if (boundp(*transform_f))
  4703. pushSTACK(*transform_f); /* transform function .. */
  4704. switch (actual_format_return) {
  4705. case 8: pushSTACK(make_uint8 (prop_return[i])); break;
  4706. case 16: pushSTACK(make_uint16 (((unsigned short*)prop_return)[i])); break;
  4707. case 32: pushSTACK(make_uint32 (((unsigned long*) prop_return)[i])); break;
  4708. default:
  4709. NOTREACHED;
  4710. }
  4711. if (boundp(*transform_f)) {
  4712. funcall (L(funcall), 2); /* apply the transform function */
  4713. pushSTACK(value1);
  4714. }
  4715. }
  4716. value1 = coerce_result_type(nitems_return,result_type_f);
  4717. pushSTACK(value1);
  4718. }
  4719. if (prop_return)
  4720. X_CALL(XFree (prop_return));
  4721. pushSTACK(make_xatom(display, actual_type_return));
  4722. pushSTACK(make_uint8 (actual_format_return));
  4723. pushSTACK(make_uint32 (bytes_after_return));
  4724. }
  4725. value4 = popSTACK();
  4726. value3 = popSTACK();
  4727. value2 = popSTACK();
  4728. value1 = popSTACK();
  4729. mv_count = 4;
  4730. skipSTACK(8);
  4731. }
  4732. DEFUN(XLIB:LIST-PROPERTIES, window &key RESULT-TYPE) /* OK */
  4733. {
  4734. int num_props, i;
  4735. gcv_object_t *res_type = &STACK_0;
  4736. Display *dpy;
  4737. Window win = get_window_and_display (STACK_1, &dpy);
  4738. Atom *props;
  4739. X_CALL(props = XListProperties (dpy, win, &num_props));
  4740. /* Now push all properties ... */
  4741. for (i = 0; i < num_props; i++)
  4742. pushSTACK(make_xatom(dpy, props[i]));
  4743. if (props) X_CALL(XFree (props));
  4744. VALUES1(coerce_result_type(num_props,res_type));
  4745. skipSTACK(2); /* all done */
  4746. }
  4747. /* convert a Lisp sequence of X Atoms to a C vector */
  4748. struct seq_xatom { Display *dpy; Atom* atom; };
  4749. void coerce_into_xatom (void *arg, object element);
  4750. void coerce_into_xatom (void *arg, object element) {
  4751. struct seq_xatom *sa = (struct seq_xatom *)arg;
  4752. *(sa->atom++) = get_xatom(sa->dpy,element);
  4753. }
  4754. DEFUN(XLIB:ROTATE-PROPERTIES, window properties &optional delta)
  4755. { /* XLIB:ROTATE-PROPERTIES window properties &optional (delta 1) */
  4756. Display *dpy;
  4757. Window win = get_window_and_display (STACK_2, &dpy);
  4758. int delta = (boundp(STACK_0) ? get_sint32 (STACK_0) : 1);
  4759. int num_props = get_uint32(funcall1(L(length),STACK_1));
  4760. struct seq_xatom sa;
  4761. DYNAMIC_ARRAY (props, Atom, num_props);
  4762. sa.dpy = dpy; sa.atom = props;
  4763. map_sequence(STACK_1,coerce_into_xatom,(void*)&sa);
  4764. X_CALL(XRotateWindowProperties (dpy, win, props, num_props, delta));
  4765. FREE_DYNAMIC_ARRAY (props);
  4766. VALUES1(NIL);
  4767. skipSTACK(3); /* all done */
  4768. }
  4769. /* 11.3 Selections */
  4770. DEFUN(XLIB:CONVERT-SELECTION, selection type requestor &optional property time)
  4771. {
  4772. Display *dpy;
  4773. Window requestor = get_window_and_display (STACK_2, &dpy);
  4774. Atom target = get_xatom (dpy, STACK_3);
  4775. Atom selection = get_xatom (dpy, STACK_4);
  4776. Atom property = missingp(STACK_1) ? None : get_xatom (dpy, STACK_1);
  4777. Time time = get_timestamp (STACK_0);
  4778. X_CALL(XConvertSelection (dpy, selection, target, property,requestor,time));
  4779. VALUES1(NIL);
  4780. skipSTACK(5); /* all done */
  4781. }
  4782. DEFUN(XLIB:SELECTION-OWNER, display selection)
  4783. {
  4784. Display *dpy = get_display(STACK_1);
  4785. Atom selection = get_xatom (dpy, STACK_0);
  4786. Window owner;
  4787. X_CALL(owner = XGetSelectionOwner (dpy, selection));
  4788. VALUES1(make_window (STACK_1, owner));
  4789. skipSTACK(2);
  4790. }
  4791. /* (SETF (XLIB:SELECTION-OWNER display selection &optional time) owner)
  4792. == (XLIB:SET-SELECTION-OWNER display selection owner &optional time) */
  4793. DEFUN(XLIB:SET-SELECTION-OWNER, display selection owner &optional time)
  4794. {
  4795. Display *dpy = get_display(STACK_3);
  4796. Atom selection = get_xatom (dpy, STACK_2);
  4797. Window owner = get_window (STACK_1);
  4798. Time time = get_timestamp (STACK_0);
  4799. X_CALL(XSetSelectionOwner (dpy, selection, owner, time));
  4800. VALUES1(STACK_1);
  4801. skipSTACK(4);
  4802. }
  4803. /* -----------------------------------------------------------------------
  4804. * Chapter 12 Events and Input
  4805. * ----------------------------------------------------------------------- */
  4806. /* 12.3 Processing Events */
  4807. /*
  4808. First of all, we have to enter all the nasty events, together with all its
  4809. slots, type information, etc. It is up to the two different functions for
  4810. assembling and disassembling event to provide the right macro definitions for
  4811. DEF_EVENT, ESLOT, and ESLOT2; [I want to do it only *ONCE*, so this klugde.]
  4812. DEF_EVENT ( <lisp event key>, <C name of event key>, <C type of struct>, <C name of struct in XEvent> )
  4813. -- start defining an event.
  4814. ESLOT ( <lisp slot name>, <type>, <C slot> )
  4815. -- define a slot
  4816. ESLOT2 ( <lisp slot name>, <type>, <C slot> )
  4817. -- same as ESLOT, but for objects, which needs the display.
  4818. ESLOT3 is just for the key_vector, since you cannot assign arrays in C
  4819. usually, but must pass a pointer.
  4820. ESLOT4 is just used for the atom slot, since get_xatom requires an display
  4821. argument
  4822. ESLOT5 is just for client-message's data slot.
  4823. (If your preprocessor or your compiler can't eat this, hmm... get a new one.)
  4824. */
  4825. #define COMMON_INPUT_EVENT \
  4826. ESLOT2(`:WINDOW`, window, window) \
  4827. ESLOT2(`:EVENT-WINDOW`, window, window) \
  4828. ESLOT2(`:CHILD`, window, subwindow) \
  4829. ESLOT2(`:ROOT`, window, root) \
  4830. ESLOT (`:X`, sint16, x) \
  4831. ESLOT (`:Y`, sint16, y) \
  4832. ESLOT (`:ROOT-X`, sint16, x_root) \
  4833. ESLOT (`:ROOT-Y`, sint16, y_root) \
  4834. ESLOT (`:STATE`, uint16, state) \
  4835. ESLOT (`:TIME`, uint32, time) \
  4836. ESLOT (`:SAME-SCREEN-P`, bool, same_screen)
  4837. #define ALL_EVENT_DEFS \
  4838. DEF_EVENT (`:KEY-PRESS`, KeyPress, XKeyPressedEvent, xkey) \
  4839. ESLOT (S(Kcode), uint8, keycode) \
  4840. COMMON_INPUT_EVENT \
  4841. \
  4842. DEF_EVENT (`:KEY-RELEASE`, KeyRelease, XKeyReleasedEvent, xkey) \
  4843. ESLOT (S(Kcode), uint8, keycode) \
  4844. COMMON_INPUT_EVENT \
  4845. \
  4846. DEF_EVENT (`:BUTTON-PRESS`, ButtonPress, XButtonPressedEvent, xbutton) \
  4847. ESLOT (S(Kcode), uint8, button) \
  4848. COMMON_INPUT_EVENT \
  4849. \
  4850. DEF_EVENT (`:BUTTON-RELEASE`, ButtonRelease, XButtonReleasedEvent, xbutton) \
  4851. ESLOT (S(Kcode), uint8, button) \
  4852. COMMON_INPUT_EVENT \
  4853. \
  4854. DEF_EVENT (`:MOTION-NOTIFY`, MotionNotify, XMotionEvent, xmotion) \
  4855. ESLOT (`:HINT-P`, bool, is_hint) \
  4856. COMMON_INPUT_EVENT \
  4857. \
  4858. DEF_EVENT (`:ENTER-NOTIFY`, EnterNotify, XEnterWindowEvent, xcrossing) \
  4859. ESLOT (`:MODE`, crossing_mode, mode) \
  4860. ESLOT (`:KIND`, crossing_kind, detail) \
  4861. ESLOT (`:FOCUS-P`, bool, focus) \
  4862. COMMON_INPUT_EVENT \
  4863. \
  4864. DEF_EVENT (`:LEAVE-NOTIFY`, LeaveNotify, XLeaveWindowEvent, xcrossing) \
  4865. ESLOT (`:MODE`, crossing_mode, mode) \
  4866. ESLOT (`:KIND`, crossing_kind, detail) \
  4867. ESLOT (`:FOCUS-P`, bool, focus) \
  4868. COMMON_INPUT_EVENT \
  4869. \
  4870. DEF_EVENT (`:FOCUS-IN`, FocusIn, XFocusChangeEvent, xfocus) \
  4871. ESLOT2(`:WINDOW`, window, window) \
  4872. ESLOT2(`:EVENT-WINDOW`, window, window) \
  4873. ESLOT (`:MODE`, focus_mode, mode) \
  4874. ESLOT (`:KIND`, focus_detail, detail) \
  4875. \
  4876. DEF_EVENT (`:FOCUS-OUT`, FocusOut, XFocusChangeEvent, xfocus) \
  4877. ESLOT2(`:WINDOW`, window, window) \
  4878. ESLOT2(`:EVENT-WINDOW`, window, window) \
  4879. ESLOT (`:MODE`, focus_mode, mode) \
  4880. ESLOT (`:KIND`, focus_detail, detail) \
  4881. \
  4882. DEF_EVENT (`:EXPOSURE`, Expose, XExposeEvent, xexpose) \
  4883. ESLOT2(`:WINDOW`, window, window) \
  4884. ESLOT2(`:EVENT-WINDOW`, window, window) \
  4885. ESLOT (`:X`, uint16, x) \
  4886. ESLOT (`:Y`, uint16, y) \
  4887. ESLOT (`:WIDTH`, uint16, width) \
  4888. ESLOT (`:HEIGHT`, uint16, height) \
  4889. ESLOT (S(Kcount), uint16, count) \
  4890. \
  4891. DEF_EVENT (`:GRAPHICS-EXPOSURE`, GraphicsExpose, XGraphicsExposeEvent, xgraphicsexpose) \
  4892. ESLOT2(`:DRAWABLE`, drawable, drawable) \
  4893. ESLOT2(`:EVENT-WINDOW`, drawable, drawable) \
  4894. ESLOT (`:X`, uint16, x) \
  4895. ESLOT (`:Y`, uint16, y) \
  4896. ESLOT (`:WIDTH`, uint16, width) \
  4897. ESLOT (`:HEIGHT`, uint16, height) \
  4898. ESLOT (S(Kcount), uint16, count) \
  4899. ESLOT (`:MAJOR`, uint8, major_code) \
  4900. ESLOT (`:MINOR`, uint16, minor_code) \
  4901. \
  4902. DEF_EVENT (`:KEYMAP-NOTIFY`, KeymapNotify, XKeymapEvent, xkeymap) \
  4903. ESLOT3(`:KEYMAP`, key_vector, key_vector) \
  4904. \
  4905. DEF_EVENT (`:MAPPING-NOTIFY`, MappingNotify, XMappingEvent, xmapping) \
  4906. ESLOT (S(Kcount), uint8, count) \
  4907. ESLOT (S(Kstart), uint8, first_keycode) \
  4908. ESLOT (`:REQUEST`, mapping_request, request) \
  4909. \
  4910. DEF_EVENT (`:NO-EXPOSURE`, NoExpose, XNoExposeEvent, xnoexpose) \
  4911. ESLOT2(`:DRAWABLE`, drawable, drawable) \
  4912. ESLOT2(`:EVENT-WINDOW`, drawable, drawable) \
  4913. ESLOT (`:MAJOR`, uint8, major_code) \
  4914. ESLOT (`:MINOR`, uint16, minor_code) \
  4915. \
  4916. DEF_EVENT (`:CIRCULATE-NOTIFY`, CirculateNotify, XCirculateEvent, xcirculate) \
  4917. ESLOT2(`:WINDOW`, window, window) \
  4918. ESLOT2(`:EVENT-WINDOW`, window, event) \
  4919. ESLOT (`:PLACE`, top_or_bottom, place) \
  4920. \
  4921. DEF_EVENT (`:CONFIGURE-NOTIFY`, ConfigureNotify, XConfigureEvent, xconfigure) \
  4922. ESLOT2(`:WINDOW`, window, window) \
  4923. ESLOT2(`:EVENT-WINDOW`, window, event) \
  4924. ESLOT (`:X`, sint16, x) \
  4925. ESLOT (`:Y`, sint16, y) \
  4926. ESLOT (`:WIDTH`, uint16, width) \
  4927. ESLOT (`:HEIGHT`, uint16, height) \
  4928. ESLOT (`:BORDER-WIDTH`, uint16, border_width) \
  4929. ESLOT2(`:ABOVE-SIBLING`, window, above) \
  4930. ESLOT (`:OVERRIDE-REDIRECT-P`,bool, override_redirect) \
  4931. \
  4932. DEF_EVENT (`:CREATE-NOTIFY`, CreateNotify, XCreateWindowEvent, xcreatewindow) \
  4933. ESLOT2(`:PARENT`, window, parent) \
  4934. ESLOT2(`:EVENT-WINDOW`, window, parent) \
  4935. ESLOT2(`:WINDOW`, window, window) \
  4936. ESLOT (`:X`, sint16, x) \
  4937. ESLOT (`:Y`, sint16, y) \
  4938. ESLOT (`:WIDTH`, uint16, width) \
  4939. ESLOT (`:HEIGHT`, uint16, height) \
  4940. ESLOT (`:BORDER-WIDTH`, uint16, border_width) \
  4941. \
  4942. DEF_EVENT (`:DESTROY-NOTIFY`, DestroyNotify, XDestroyWindowEvent, xdestroywindow) \
  4943. ESLOT2(`:WINDOW`, window, window) \
  4944. ESLOT2(`:EVENT-WINDOW`, window, event) \
  4945. \
  4946. DEF_EVENT (`:GRAVITY-NOTIFY`, GravityNotify, XGravityEvent, xgravity) \
  4947. ESLOT2(`:WINDOW`, window, window) \
  4948. ESLOT2(`:EVENT-WINDOW`, window, event) \
  4949. ESLOT (`:X`, sint16, x) \
  4950. ESLOT (`:Y`, sint16, y) \
  4951. \
  4952. DEF_EVENT (`:MAP-NOTIFY`, MapNotify, XMapEvent, xmap) \
  4953. ESLOT2(`:WINDOW`, window, window) \
  4954. ESLOT2(`:EVENT-WINDOW`, window, event) \
  4955. ESLOT (`:OVERRIDE-REDIRECT-P`,bool, override_redirect) \
  4956. \
  4957. DEF_EVENT (`:REPARENT-NOTIFY`, ReparentNotify, XReparentEvent, xreparent) \
  4958. ESLOT2(`:WINDOW`, window, window) \
  4959. ESLOT2(`:EVENT-WINDOW`, window, event) \
  4960. ESLOT2(`:PARENT`, window, parent) \
  4961. ESLOT (`:X`, sint16, x) \
  4962. ESLOT (`:Y`, sint16, y) \
  4963. ESLOT (`:OVERRIDE-REDIRECT-P`,bool, override_redirect) \
  4964. \
  4965. DEF_EVENT (`:UNMAP-NOTIFY`, UnmapNotify, XUnmapEvent, xunmap) \
  4966. ESLOT2(`:WINDOW`, window, window) \
  4967. ESLOT2(`:EVENT-WINDOW`, window, event) \
  4968. ESLOT (`:CONFIGURE-P`, bool, from_configure) \
  4969. \
  4970. DEF_EVENT (`:VISIBILITY-NOTIFY`, VisibilityNotify, XVisibilityEvent, xvisibility) \
  4971. ESLOT2(`:WINDOW`, window, window) \
  4972. ESLOT2(`:EVENT-WINDOW`, window, window) \
  4973. ESLOT (`:STATE`, visibility_state, state) \
  4974. \
  4975. DEF_EVENT (`:CIRCULATE-REQUEST`, CirculateRequest, XCirculateRequestEvent, xcirculaterequest) \
  4976. ESLOT2(`:PARENT`, window, parent) \
  4977. ESLOT2(`:EVENT-WINDOW`, window, parent) \
  4978. ESLOT2(`:WINDOW`, window, window) \
  4979. ESLOT (`:PLACE`, top_or_bottom, place) \
  4980. \
  4981. DEF_EVENT (`:COLORMAP-NOTIFY`, ColormapNotify, XColormapEvent, xcolormap) \
  4982. ESLOT2(`:WINDOW`, window, window) \
  4983. ESLOT2(`:EVENT-WINDOW`, window, window) \
  4984. ESLOT2(`:COLORMAP`, colormap, colormap) \
  4985. ESLOT (`:NEW-P`, bool, c_new) \
  4986. ESLOT (`:INSTALLED-P`, bool, state) \
  4987. \
  4988. DEF_EVENT (`:CONFIGURE-REQUEST`, ConfigureRequest, XConfigureRequestEvent, xconfigurerequest) \
  4989. ESLOT2(`:PARENT`, window, parent) \
  4990. ESLOT2(`:EVENT-WINDOW`, window, parent) \
  4991. ESLOT2(`:WINDOW`, window, window) \
  4992. ESLOT (`:X`, sint16, x) \
  4993. ESLOT (`:Y`, sint16, y) \
  4994. ESLOT (`:WIDTH`, uint16, width) \
  4995. ESLOT (`:HEIGHT`, uint16, height) \
  4996. ESLOT (`:BORDER-WIDTH`, uint16, border_width) \
  4997. ESLOT (`:STACK-MODE`, stack_mode, detail) \
  4998. ESLOT2(`:ABOVE-SIBLING`, window, above) \
  4999. ESLOT (`:VALUE-MASK`, uint16, value_mask) \
  5000. \
  5001. DEF_EVENT (`:MAP-REQUEST`, MapRequest, XMapRequestEvent, xmaprequest) \
  5002. ESLOT2(`:PARENT`, window, parent) \
  5003. ESLOT2(`:EVENT-WINDOW`, window, parent) \
  5004. ESLOT2(`:WINDOW`, window, window) \
  5005. \
  5006. DEF_EVENT (`:RESIZE-REQUEST`, ResizeRequest, XResizeRequestEvent, xresizerequest) \
  5007. ESLOT2(`:WINDOW`, window, window) \
  5008. ESLOT2(`:EVENT-WINDOW`, window, window) \
  5009. ESLOT (`:WIDTH`, uint16, width) \
  5010. ESLOT (`:HEIGHT`, uint16, height) \
  5011. \
  5012. DEF_EVENT (`:CLIENT-MESSAGE`, ClientMessage, XClientMessageEvent, xclient) \
  5013. ESLOT2(`:WINDOW`, window, window) \
  5014. ESLOT2(`:EVENT-WINDOW`, window, window) \
  5015. ESLOT4(S(Ktype), xatom, message_type) \
  5016. ESLOT (`:FORMAT`, client_message_format, format) \
  5017. ESLOT5(`:DATA`, client_message_data, data) \
  5018. \
  5019. DEF_EVENT (`:PROPERTY-NOTIFY`, PropertyNotify, XPropertyEvent, xproperty) \
  5020. ESLOT2(`:WINDOW`, window, window) \
  5021. ESLOT2(`:EVENT-WINDOW`, window, window) \
  5022. ESLOT4(`:ATOM`, xatom, atom) \
  5023. ESLOT (`:STATE`, new_value_or_deleted, state) \
  5024. ESLOT (`:TIME`, uint32, time) \
  5025. \
  5026. DEF_EVENT (`:SELECTION-CLEAR`, SelectionClear, XSelectionClearEvent, xselectionclear) \
  5027. ESLOT2(`:WINDOW`, window, window) \
  5028. ESLOT2(`:EVENT-WINDOW`, window, window) \
  5029. ESLOT4(`:SELECTION`, xatom, selection) \
  5030. ESLOT (`:TIME`, uint32, time) \
  5031. \
  5032. DEF_EVENT (`:SELECTION-NOTIFY`, SelectionNotify, XSelectionEvent, xselection) \
  5033. ESLOT2(`:WINDOW`, window, requestor) \
  5034. ESLOT2(`:EVENT-WINDOW`, window, requestor) \
  5035. ESLOT4(`:SELECTION`, xatom, selection) \
  5036. ESLOT4(`:TARGET`, xatom, target) \
  5037. ESLOT4(`:PROPERTY`, xatom, property) \
  5038. ESLOT (`:TIME`, uint32, time) \
  5039. \
  5040. DEF_EVENT (`:SELECTION-REQUEST`, SelectionRequest, XSelectionRequestEvent, xselectionrequest) \
  5041. ESLOT2(`:WINDOW`, window, owner) \
  5042. ESLOT2(`:EVENT-WINDOW`, window, owner) \
  5043. ESLOT2(`:REQUESTOR`, window, requestor) \
  5044. ESLOT4(`:SELECTION`, xatom, selection) \
  5045. ESLOT4(`:TARGET`, xatom, target) \
  5046. ESLOT4(`:PROPERTY`, xatom, property) \
  5047. ESLOT (`:TIME`, uint32, time) \
  5048. /* vacuous comment to signify the end of the #define */
  5049. /* Some field names differ between C and C++. */
  5050. #ifndef __cplusplus
  5051. #define c_new new
  5052. #endif
  5053. static int disassemble_event_on_stack (XEvent *ev, gcv_object_t *dpy_objf)
  5054. /* Disassembles an X event onto the stack and returns the number of elements
  5055. * push to the stack. [You can then neatly issue a funcall or list call using
  5056. * these stack elements.] */
  5057. {
  5058. #define ESLOT(lispname,type,cslot) \
  5059. pushSTACK((lispname)); \
  5060. pushSTACK(make_##type (container->cslot)); \
  5061. cnt += 2;
  5062. #define ESLOT2(lispname,type,cslot) \
  5063. pushSTACK((lispname)); \
  5064. pushSTACK(make_##type (*dpy_objf, container->cslot)); \
  5065. cnt += 2;
  5066. #define ESLOT3 ESLOT
  5067. #define ESLOT4(lispname,type,cslot) \
  5068. pushSTACK((lispname)); \
  5069. { \
  5070. Display *dpy = get_display(*dpy_objf); \
  5071. pushSTACK(make_##type (dpy, container->cslot)); \
  5072. } \
  5073. cnt += 2;
  5074. #define ESLOT5(lispname,type,cslot) \
  5075. pushSTACK((lispname)); \
  5076. pushSTACK(make_##type (container)); \
  5077. cnt += 2;
  5078. #define DEF_EVENT(lispname, cname, c_container_type, c_container) \
  5079. } \
  5080. break; \
  5081. case cname: \
  5082. { \
  5083. c_container_type *container = &(ev->c_container); \
  5084. pushSTACK(`:EVENT-KEY`); \
  5085. pushSTACK((lispname)); cnt += 2;
  5086. int cnt = 0;
  5087. /* These attributes are common to all events (hopefully) */
  5088. pushSTACK(`:DISPLAY`); pushSTACK(STACK_6); cnt += 2;
  5089. pushSTACK(`:EVENT-CODE`); pushSTACK(fixnum(ev->type)); cnt += 2;
  5090. pushSTACK(`:SEND-EVENT-P`); pushSTACK(make_bool (ev->xany.send_event)); cnt += 2;
  5091. pushSTACK(`:SEQUENCE`); pushSTACK(make_uint16 (ev->xany.serial)); cnt += 2;
  5092. /* BTW I really hate it that the naming convention for events is not
  5093. * consistent , while you have a name for the mask, the event type, the event
  5094. * substructure and all may have different names. (i.e. you have to say
  5095. * 'exposure' and sometimes 'expose') This bothers me really .. :-{}^ */
  5096. switch (ev->type) {
  5097. default: {
  5098. /* Wat nu? Propabably raise some error?! */
  5099. /* THIS LOOKS STRANGE?!
  5100. Well, the first ALL_EVENTS gives is '}' + 'break;' the last thing is '{', so ... */
  5101. ALL_EVENT_DEFS
  5102. }
  5103. break;
  5104. }
  5105. return cnt;
  5106. #undef DEF_EVENT
  5107. #undef ESLOT
  5108. #undef ESLOT2
  5109. #undef ESLOT3
  5110. #undef ESLOT4
  5111. #undef ESLOT5
  5112. }
  5113. static void travel_queque (Display *dpy, int peek_p, int discard_p,
  5114. int force_output_p, struct timeval *timeout)
  5115. { /* peek_p == not remove-processed-p
  5116. discard_p == remove-unprocessed-p
  5117. timeout in sec/usec or NULL to block.
  5118. BUGS:
  5119. - take care that discard-current-event will work as expected!
  5120. - also we need an unwind protect here!
  5121. - handler may also be a vector of functions. [How strange?!]
  5122. TODO:
  5123. - I want this routine to be interruptible by user in a continueable fashion.
  5124. Way to go:
  5125. interruptp( { pushSTACK( <subr name> ); tast_break(); goto <continue>; } );
  5126. Hmm... It may be better to use the appropriate XIf... function.
  5127. [What happens if we throw out of `em? Also they also seem to block?! RTFM] */
  5128. XEvent ev;
  5129. int cnt;
  5130. int r;
  5131. travel_queque:
  5132. if (timeout) {
  5133. X_CALL(XEventsQueued(dpy, force_output_p
  5134. ? QueuedAfterFlush : QueuedAfterReading));
  5135. r = QLength (dpy);
  5136. if (r == 0) {
  5137. int conn;
  5138. fd_set ifds;
  5139. conn = ConnectionNumber (dpy); /* this is the fd. */
  5140. FD_ZERO (&ifds);
  5141. FD_SET (conn, &ifds);
  5142. X_CALL(r = select (conn+1, &ifds, NULL, NULL, timeout));
  5143. if ((r > 0) && FD_ISSET (conn, &ifds)) {
  5144. /* timeout has to reduce by amount waited here for input;
  5145. -- presumably select does that */
  5146. } else {
  5147. /* Nothing there, so just return */
  5148. VALUES1(NIL);
  5149. return;
  5150. }
  5151. }
  5152. }
  5153. /* .. so there is either now an event in the queue or we should hang: */
  5154. X_CALL(XNextEvent (dpy, &ev));
  5155. cnt = disassemble_event_on_stack (&ev, &(STACK_5));
  5156. /* Now invoke the handler function */
  5157. funcall (STACK_(cnt+4), cnt); /* BUG: This may throw out of our control! */
  5158. /* We would need something like an unwind protect here
  5159. But only if discard_p == NIL. */
  5160. /* Look what we got. */
  5161. if (nullp(value1)) {
  5162. if (discard_p) {
  5163. /* travel_queque (dpy, peek_p, discard_p, force_output_p, timeout); */
  5164. goto travel_queque;
  5165. } else {
  5166. travel_queque (dpy, peek_p, discard_p, force_output_p, timeout);
  5167. X_CALL(XPutBackEvent (dpy, &ev));
  5168. }
  5169. } else /* Handler successful */
  5170. if (peek_p) X_CALL(XPutBackEvent (dpy, &ev));
  5171. }
  5172. DEFUN(XLIB:PROCESS-EVENT, display &key HANDLER :TIMEOUT PEEK-P DISCARD-P \
  5173. FORCE-OUTPUT-P)
  5174. {
  5175. Display *dpy = get_display(STACK_5);
  5176. int force_output_p = (boundp(STACK_0) ? get_bool(STACK_0) : 1);
  5177. int discard_p = !missingp(STACK_1), peek_p = !missingp(STACK_2);
  5178. struct timeval tv;
  5179. struct timeval *timeout = sec_usec(STACK_3,NIL,&tv);
  5180. if (!boundp(STACK_4))
  5181. NOTIMPLEMENTED;
  5182. /* Now go into the recursive event queque travel routine */
  5183. travel_queque (dpy, peek_p, discard_p, force_output_p, timeout);
  5184. /* mv_space and mv_count are set by the return of the handler function */
  5185. skipSTACK(6);
  5186. }
  5187. /* 12.4 Managing the Event Queue */
  5188. static int grasp (object slot, uintC n) {
  5189. uintC o;
  5190. for (o = 1 ; o < n; o += 2)
  5191. if (eq (STACK_(o+1), slot))
  5192. return o;
  5193. return 0;
  5194. }
  5195. static void encode_event (uintC n, object event_key, Display *dpy, XEvent *ev)
  5196. { /* encodes an event, which lies in the top /n/ stack locations into ev
  5197. event-key is an optional event key to use, it may also be unbound.
  5198. But hey! Without an event key we could not assemble an event?! */
  5199. int ofs;
  5200. pushSTACK(event_key);
  5201. X_CALL(memset(ev, 0, sizeof(XEvent)));
  5202. #define DEF_EVENT(lnam, cnam, ctype, cslot) \
  5203. } else if (eq (STACK_0, lnam)) { \
  5204. ctype *event = &(ev->cslot); \
  5205. ev->type = cnam;
  5206. #define ESLOT(lnam, type, cslot) \
  5207. { \
  5208. if ((ofs = grasp (lnam, n))) \
  5209. event->cslot = get_##type (STACK_(ofs)); \
  5210. }
  5211. #define ESLOT2(lnam, type, cslot) ESLOT(lnam,type,cslot)
  5212. #define ESLOT3(lnam, type, cslot) \
  5213. { \
  5214. if ((ofs = grasp (lnam, n))) \
  5215. get_##type (STACK_(ofs), (event->cslot)); \
  5216. }
  5217. #define ESLOT4(lnam, type, cslot) \
  5218. { \
  5219. if ((ofs = grasp (lnam, n))) \
  5220. event->cslot = get_##type (dpy, STACK_(ofs)); \
  5221. }
  5222. #define ESLOT5(lnam, type, cslot) \
  5223. { \
  5224. int format_ofs = grasp (`:FORMAT`, n); \
  5225. if (format_ofs && (ofs = grasp (lnam, n))) \
  5226. get_##type (event, \
  5227. get_uint32 (STACK_(format_ofs)), \
  5228. STACK_(ofs)); \
  5229. }
  5230. if(0) {
  5231. /* Same as above in disassemble_event_on_stack this looks strange, but is
  5232. right, since the first thing DEF_EVENT gives is "} else" the last
  5233. thing is "if (..) {", so .... */
  5234. ALL_EVENT_DEFS
  5235. } else my_type_error(`XLIB::EVENT-KEY`,STACK_0);
  5236. #undef DEF_EVENT
  5237. #undef ESLOT
  5238. #undef ESLOT2
  5239. #undef ESLOT3
  5240. #undef ESLOT4
  5241. #undef ESLOT5
  5242. /* pop event_key off the stack. */
  5243. skipSTACK(1);
  5244. }
  5245. /* (queue-event display event-key &rest args &key append-p send-event-p
  5246. &allow-other-keys)
  5247. The event is put at the head of the queue if append-p is nil, else
  5248. the tail. Additional arguments depend on event-key, and are as
  5249. specified above with declare-event, except that both resource-ids and
  5250. resource objects are accepted in the event components. */
  5251. DEFUN(XLIB:QUEUE-EVENT, &rest args)
  5252. {UNDEFINED;}
  5253. /* Take a look at XPutBackEvent, but that functions seems only to
  5254. put events on the head of the queue!
  5255. Maybe we should go and build our own event queque?
  5256. Or we fight with the internals of libX?
  5257. But we could travel the whole event queque until we come to a point,
  5258. where the queque has ended; XPutBackEvent the event to be added at end
  5259. and XputBack all other event above that. [Not very fast, but portable]
  5260. also send-event-p is not in the manual. */
  5261. /* --> discarded-p -- Type boolean
  5262. Discard the current event for DISPLAY.
  5263. Returns NIL when the event queue is empty, else T.
  5264. To ensure events aren't ignored, application code should only call
  5265. this when throwing out of event-case or process-next-event, or from
  5266. inside even-case, event-cond or process-event when :peek-p is T and
  5267. :discard-p is NIL. */
  5268. DEFUN(XLIB:DISCARD-CURRENT-EVENT, display)
  5269. { /* FIXME -- here the manual is a bit imprecise
  5270. - Should we hang?
  5271. - Should we return T/NIL before discarding? properly not. */
  5272. Display *dpy = pop_display ();
  5273. if (QLength (dpy)) { /* no begin/end_call here QLength is a macro */
  5274. XEvent trash_can;
  5275. X_CALL(XNextEvent (dpy, &trash_can));
  5276. value1 = T;
  5277. } else
  5278. value1 = NIL;
  5279. mv_count = 1;
  5280. }
  5281. /* XLIB:EVENT-LISTEN display &optional (timeout 0)
  5282. Returns:
  5283. event-count -- Type (or null integer).
  5284. Returns the number of events queued locally. If the event queue is
  5285. empty, event-listen waits for an event to arrive. If timeout is
  5286. non-nil and no event arrives within the specified timeout interval
  5287. (given in seconds), event-listen returns nil; if timeout is nil,
  5288. event-listen will not return until an event arrives. */
  5289. DEFUN(XLIB:EVENT-LISTEN, display &optional timeout)
  5290. {
  5291. struct timeval tv;
  5292. struct timeval *timeout = sec_usec(popSTACK(),NIL,&tv);
  5293. Display *dpy = pop_display();
  5294. int r;
  5295. XEvent trashcan;
  5296. if (timeout == NULL) { /* Block */
  5297. X_CALL(while (!(r = QLength (dpy))) XPeekEvent (dpy, &trashcan));
  5298. value1 = make_uint32 (r);
  5299. } else {
  5300. r = QLength (dpy);
  5301. if (r) {
  5302. value1 = make_uint32 (r);
  5303. } else {
  5304. /* Wait */
  5305. int conn;
  5306. fd_set ifds;
  5307. conn = ConnectionNumber (dpy); /* this is the fd. */
  5308. FD_ZERO (&ifds);
  5309. FD_SET (conn, &ifds);
  5310. X_CALL(r = select (conn+1, &ifds, NULL, NULL, timeout));
  5311. if ((r > 0) && FD_ISSET (conn, &ifds)) {
  5312. /* RTFS: To flush or not to flush is here the question! */
  5313. X_CALL(r = XEventsQueued (dpy, QueuedAfterReading));
  5314. value1 = make_uint32 (r);
  5315. } else {
  5316. value1 = NIL;
  5317. }
  5318. }
  5319. }
  5320. mv_count = 1;
  5321. }
  5322. /* 12.5 Sending Events */
  5323. /* XLIB:SEND-EVENT window event-key event-mask &rest event-slots
  5324. &key propagate-p &allow-other-keys
  5325. NOTE: The MIT-CLX interface specifies a :display argument here, which
  5326. is not necessary */
  5327. DEFUN(XLIB:SEND-EVENT, &rest args)
  5328. {
  5329. if (argcount < 3) goto too_few;
  5330. {
  5331. XEvent event;
  5332. Display *dpy;
  5333. Window window = get_window_and_display (STACK_(argcount-1), &dpy);
  5334. unsigned long event_mask = get_event_mask (STACK_(argcount-3));
  5335. int propagate_p = 0;
  5336. uintC i;
  5337. /* hunt for the :propagate-p */
  5338. for (i = 0; i < argcount; i += 2)
  5339. if (eq (STACK_(i+1), `:PROPAGATE-P`)) {
  5340. propagate_p = get_bool (STACK_(i));
  5341. break;
  5342. }
  5343. encode_event (argcount-3, STACK_(argcount-2), dpy, &event);
  5344. X_CALL(XSendEvent (dpy, window, propagate_p, event_mask, &event));
  5345. /* XSendEvent returns also some Status, should we interpret it?
  5346. If yes: How?! */
  5347. skipSTACK(argcount);
  5348. VALUES1(NIL);
  5349. return;
  5350. }
  5351. too_few:
  5352. NOTIMPLEMENTED;
  5353. }
  5354. /* 12.6 Pointer Position */
  5355. /* XLIB:QUERY-POINTER window
  5356. -> [1] x
  5357. [2] y
  5358. [3] same-screen-p
  5359. [4] child
  5360. [5] state-mask
  5361. [6] root-x
  5362. [8] root-y
  5363. [9] root */
  5364. DEFUN(XLIB:QUERY-POINTER, window)
  5365. {
  5366. Display *dpy;
  5367. Window win = get_window_and_display (STACK_0, &dpy);
  5368. Window root, child;
  5369. int root_x, root_y;
  5370. int win_x, win_y;
  5371. unsigned int mask;
  5372. Bool same_screen_p;
  5373. X_CALL(same_screen_p = XQueryPointer (dpy, win, &root, &child, &root_x,
  5374. &root_y, &win_x, &win_y, &mask));
  5375. pushSTACK(get_display_obj (STACK_0));
  5376. pushSTACK(make_window (STACK_0, root));
  5377. pushSTACK(make_window (STACK_1, child));
  5378. value1 = make_sint16 (win_x);
  5379. value2 = make_sint16 (win_y);
  5380. value3 = make_bool (same_screen_p);
  5381. value4 = popSTACK(); /* child */
  5382. value5 = make_uint16 (mask);
  5383. value6 = make_sint16 (root_x);
  5384. value7 = make_sint16 (root_y);
  5385. value8 = popSTACK(); /* root */
  5386. mv_count = 8;
  5387. skipSTACK(2); /* all done */
  5388. }
  5389. /* -> [1] root-x
  5390. [2] root-y
  5391. [3] root */
  5392. DEFUN(XLIB:GLOBAL-POINTER-POSITION, display)
  5393. {
  5394. Display *dpy = get_display(STACK_0);
  5395. Window root, child;
  5396. int root_x, root_y;
  5397. int win_x, win_y;
  5398. unsigned int mask;
  5399. Bool same_screen_p;
  5400. X_CALL(same_screen_p = XQueryPointer
  5401. (dpy, DefaultRootWindow (dpy), &root, &child, &root_x, &root_y,
  5402. &win_x, &win_y, &mask));
  5403. VALUES3(make_sint16(root_x),make_sint16(root_y),make_window(STACK_0,root));
  5404. skipSTACK(1);
  5405. }
  5406. /* -> [1] x
  5407. [2] y
  5408. [3] same-screen-p
  5409. [4] child */
  5410. DEFUN(XLIB:POINTER-POSITION, window)
  5411. {
  5412. funcall(``XLIB::QUERY-POINTER``,1);
  5413. mv_count = 4;
  5414. }
  5415. DEFUN(XLIB:MOTION-EVENTS, window &key :START STOP RESULT-TYPE)
  5416. { /* -> (repeat-seq (int16 x) (int16 y) (timestamp time)) */
  5417. Display *dpy;
  5418. Window win = get_window_and_display (STACK_3, &dpy);
  5419. Time start = get_timestamp (STACK_2);
  5420. Time stop = get_timestamp (STACK_1);
  5421. XTimeCoord *events = 0;
  5422. int nevents = 0;
  5423. gcv_object_t *res_type = &STACK_0;
  5424. X_CALL(events = XGetMotionEvents (dpy, win, start, stop, &nevents));
  5425. if (events) {
  5426. int i;
  5427. for (i = 0; i < nevents; i++) {
  5428. pushSTACK(make_sint16 (events[i].x));
  5429. pushSTACK(make_sint16 (events[i].y));
  5430. pushSTACK(make_uint32 (events[i].time));
  5431. }
  5432. X_CALL(XFree(events));
  5433. }
  5434. VALUES1(coerce_result_type(3*nevents,res_type));
  5435. skipSTACK(4);
  5436. }
  5437. DEFUN(XLIB:WARP-POINTER, destination x y)
  5438. {
  5439. int y = get_sint32 (popSTACK());
  5440. int x = get_sint32 (popSTACK());
  5441. Display *dpy;
  5442. Window dest = get_window_and_display (popSTACK(), &dpy);
  5443. X_CALL(XWarpPointer (dpy, None, dest, 0, 0, 0, 0, x, y));
  5444. VALUES1(NIL);
  5445. }
  5446. DEFUN(XLIB:WARP-POINTER-RELATIVE, display delta-x delta-y)
  5447. {
  5448. int dy = get_sint32 (popSTACK());
  5449. int dx = get_sint32 (popSTACK());
  5450. Display *dpy = pop_display ();
  5451. X_CALL(XWarpPointer (dpy, None, None, 0, 0, 0, 0, dx, dy));
  5452. VALUES1(NIL);
  5453. }
  5454. /* XLIB:WARP-POINTER-IF-INSIDE destination destination-x destination-y
  5455. source source-x source-y
  5456. &optional (source-width 0) (source-height 0) */
  5457. DEFUN(XLIB:WARP-POINTER-IF-INSIDE, destination destination-x destination-y \
  5458. source source-x source-y &optional source-width source-height)
  5459. {
  5460. int src_h = get_sint16_0(popSTACK());
  5461. int src_w = get_sint16_0(popSTACK());
  5462. int src_y = get_sint16 (popSTACK());
  5463. int src_x = get_sint16 (popSTACK());
  5464. Window src = get_window (popSTACK());
  5465. int dest_y = get_sint16 (popSTACK());
  5466. int dest_x = get_sint16 (popSTACK());
  5467. Display *dpy;
  5468. Window dest = get_window_and_display (popSTACK(), &dpy);
  5469. X_CALL(XWarpPointer(dpy,src,dest,src_x,src_y,src_w,src_h,dest_x,dest_y));
  5470. VALUES1(NIL);
  5471. }
  5472. /* XLIB:WARP-POINTER-RELATIVE-IF-INSIDE x-offset y-offset source
  5473. source-x source-y &optional (source-width 0) (source-height 0) */
  5474. DEFUN(XLIB:WARP-POINTER-RELATIVE-IF-INSIDE, x-offset y-offset source \
  5475. source-x source-y &optional source-width source-height)
  5476. {
  5477. int src_h = get_sint16_0(popSTACK());
  5478. int src_w = get_sint16_0(popSTACK());
  5479. int src_y = get_sint16 (popSTACK());
  5480. int src_x = get_sint16 (popSTACK());
  5481. Display *dpy;
  5482. Window src = get_window_and_display (popSTACK(), &dpy);
  5483. int y_off = get_sint16 (popSTACK());
  5484. int x_off = get_sint16 (popSTACK());
  5485. X_CALL(XWarpPointer(dpy,src,None,src_x,src_y,src_w,src_h,x_off,y_off));
  5486. VALUES1(NIL);
  5487. }
  5488. /* 12.7 Managing Input Focus */
  5489. DEFCHECKER(check_revert_focus,default=RevertToNone, NONE=RevertToNone \
  5490. POINTER-ROOT=RevertToPointerRoot PARENT=RevertToParent)
  5491. /* btw. why not (SETF INPUT-FOCUS) ?
  5492. FIXME (RTFS): focus and revert-to are actually swapped in manual. */
  5493. DEFUN(XLIB:SET-INPUT-FOCUS , dpy focus revert-to &optional time1)
  5494. {
  5495. Time time = get_timestamp (popSTACK());
  5496. int revert_to = check_revert_focus(popSTACK());
  5497. Window focus = get_window(popSTACK());
  5498. Display *dpy = pop_display();
  5499. X_CALL(XSetInputFocus (dpy, focus, revert_to, time));
  5500. VALUES1(NIL);
  5501. }
  5502. /* -->
  5503. focus -- Type (or window (member :none :pointer-root))
  5504. revert-to -- Type (or window (member :none :pointer-root :parent))
  5505. In the manual is said, that the revert-to could be a window, but
  5506. the libX11 function just returns a state ?! */
  5507. DEFUN(XLIB:INPUT-FOCUS, display)
  5508. {
  5509. Display *dpy = get_display(STACK_0);
  5510. Window focus;
  5511. int revert;
  5512. X_CALL(XGetInputFocus (dpy, &focus, &revert));
  5513. /* value1 (= focus) */
  5514. switch (focus) {
  5515. case PointerRoot: pushSTACK(`:POINTER-ROOT`); break;
  5516. case None: pushSTACK(`:NONE`); break;
  5517. default: pushSTACK(make_window (STACK_0, focus));
  5518. }
  5519. value2 = check_revert_focus_reverse(revert);
  5520. value1 = popSTACK();
  5521. mv_count = 2;
  5522. skipSTACK(1); /* drop dpy */
  5523. }
  5524. static void ungrab_X (int (*X)(Display *dpy, Time time))
  5525. {
  5526. Time time = get_timestamp (popSTACK());
  5527. Display *dpy = pop_display ();
  5528. X_CALL(X (dpy, time));
  5529. VALUES1(NIL);
  5530. }
  5531. DEFCHECKER(check_grab,default=GrabSuccess, SUCCESS=GrabSuccess \
  5532. ALREADY-GRABBED=AlreadyGrabbed INVALID-TIME=GrabInvalidTime \
  5533. NOT-VIEWABLE=GrabNotViewable FROZEN=GrabFrozen)
  5534. DEFUN(XLIB:GRAB-POINTER, window event-mask &key OWNER-P SYNC-POINTER-P \
  5535. SYNC-KEYBOARD-P CONFINE-TO CURSOR TIME)
  5536. {
  5537. Display *dpy;
  5538. Window win = get_window_and_display (STACK_7, &dpy);
  5539. unsigned long event_mask = get_event_mask (STACK_6);
  5540. Bool owner_p = !missingp(STACK_5);
  5541. Bool sync_pointer = missingp(STACK_4);
  5542. Bool sync_keyboard = missingp(STACK_3);
  5543. Window confine_to = boundp(STACK_2) ? get_window(STACK_2) : None;
  5544. Cursor cursor = boundp(STACK_1) ? get_cursor(STACK_1) : None;
  5545. Time time = get_timestamp (STACK_0);
  5546. int r;
  5547. X_CALL(r = XGrabPointer (dpy, win, owner_p, event_mask, sync_pointer,
  5548. sync_keyboard, confine_to, cursor, time));
  5549. VALUES1(check_grab_reverse(r));
  5550. skipSTACK(8);
  5551. }
  5552. DEFUN(XLIB:UNGRAB-POINTER, window &key TIME)
  5553. { ungrab_X (XUngrabPointer); }
  5554. DEFUN(XLIB:CHANGE-ACTIVE-POINTER-GRAB, dpy event-mask &optional cursor time)
  5555. {
  5556. Display *dpy = get_display(STACK_3);
  5557. unsigned long event_mask = get_event_mask (STACK_2);
  5558. Cursor cursor = boundp(STACK_1) ? get_cursor(STACK_1) : None;
  5559. Time time = get_timestamp (STACK_0);
  5560. X_CALL(XChangeActivePointerGrab (dpy, event_mask, cursor, time));
  5561. skipSTACK(4);
  5562. VALUES1(NIL);
  5563. }
  5564. /* 12.9 Grabbing a Button */
  5565. /* XLIB:GRAB-BUTTON window button event-mask &key (:modifiers 0)
  5566. :owner-p :sync-pointer-p :sync-keyboard-p :confine-to :cursor */
  5567. DEFUN(XLIB:GRAB-BUTTON, window button event-mask &key MODIFIERS \
  5568. OWNER-P SYNC-POINTER-P SYNC-KEYBOARD-P CONFINE-TO CURSOR)
  5569. {
  5570. Display *dpy;
  5571. Window win = get_window_and_display (STACK_8, &dpy);
  5572. int button = !(eq (STACK_7, `:ANY`) ? AnyButton : get_uint8 (STACK_7));
  5573. unsigned long event_mask = get_event_mask (STACK_6);
  5574. unsigned int modifiers = get_modifier_mask(STACK_5);
  5575. Bool owner_p = !missingp(STACK_4);
  5576. Bool sync_pointer = missingp(STACK_3);
  5577. Bool sync_keyboard = missingp(STACK_2);
  5578. Window confine_to = boundp(STACK_1) ? get_window(STACK_1) : None;
  5579. Cursor cursor = boundp(STACK_0) ? get_cursor(STACK_0) : None;
  5580. X_CALL(XGrabButton (dpy, button, modifiers, win, owner_p, event_mask,
  5581. sync_pointer, sync_keyboard, confine_to, cursor));
  5582. VALUES1(NIL);
  5583. skipSTACK(9);
  5584. }
  5585. DEFUN(XLIB:UNGRAB-BUTTON, window code &key MODIFIERS)
  5586. {
  5587. Display *dpy;
  5588. Window win = get_window_and_display (STACK_2, &dpy);
  5589. int code = (eq (STACK_1, `:ANY`) ? AnyKey : get_uint8(STACK_1));
  5590. unsigned int modifiers = get_modifier_mask(STACK_0);
  5591. X_CALL(XUngrabButton (dpy, code, modifiers, win));
  5592. VALUES1(NIL);
  5593. skipSTACK(3);
  5594. }
  5595. /* 12.10 Grabbing the Keyboard */
  5596. DEFUN(XLIB:GRAB-KEYBOARD, window \
  5597. &key OWNER-P SYNC-POINTER-P SYNC-KEYBOARD-P TIME)
  5598. {
  5599. Display *dpy;
  5600. Window win = get_window_and_display (STACK_4, &dpy);
  5601. Bool owner_p = !missingp(STACK_3);
  5602. Bool sync_pointer_p = missingp(STACK_2) ? GrabModeAsync : GrabModeSync;
  5603. Bool sync_keyboard_p = missingp(STACK_1) ? GrabModeAsync : GrabModeSync;
  5604. Time time = get_timestamp (STACK_0);
  5605. int r;
  5606. X_CALL(r = XGrabKeyboard (dpy, win, owner_p, sync_pointer_p, sync_keyboard_p,
  5607. time));
  5608. VALUES1(check_grab_reverse(r));
  5609. skipSTACK(5);
  5610. }
  5611. DEFUN(XLIB:UNGRAB-KEYBOARD, window &key TIME)
  5612. { ungrab_X (XUngrabKeyboard); }
  5613. /* 12.11 Grabbing a Key */
  5614. /* XLIB:GRAB-KEY window key &key (:modifiers 0) :owner-p :sync-pointer-p
  5615. :sync-keyboard-p */
  5616. DEFUN(XLIB:GRAB-KEY, window key &key MODIFIERS OWNER-P SYNC-POINTER-P \
  5617. SYNC-KEYBOARD-P)
  5618. {
  5619. Display *dpy;
  5620. Window win = get_window_and_display (STACK_5, &dpy);
  5621. int keycode = get_uint8 (STACK_4);
  5622. unsigned int modifiers = get_modifier_mask(STACK_3);
  5623. Bool owner_p = !missingp(STACK_2);
  5624. Bool sync_pointer_p = missingp(STACK_1) ? GrabModeAsync : GrabModeSync;
  5625. Bool sync_keyboard_p = missingp(STACK_0) ? GrabModeAsync : GrabModeSync;
  5626. X_CALL(XGrabKey (dpy, keycode, modifiers, win, owner_p,
  5627. sync_pointer_p, sync_keyboard_p));
  5628. VALUES1(NIL);
  5629. skipSTACK(6);
  5630. }
  5631. DEFUN(XLIB:UNGRAB-KEY, window code &key MODIFIERS)
  5632. {
  5633. Display *dpy;
  5634. Window win = get_window_and_display (STACK_2, &dpy);
  5635. int code = (eq (STACK_1, `:ANY`) ? AnyKey : get_uint8(STACK_1));
  5636. unsigned int modifiers = get_modifier_mask(STACK_0);
  5637. X_CALL(XUngrabKey (dpy, code, modifiers, win));
  5638. VALUES1(NIL);
  5639. skipSTACK(3);
  5640. }
  5641. /* 12.13 Releasing Queued Events */
  5642. DEFCHECKER(check_allow_events,default=,ASYNC-POINTER=AsyncPointer \
  5643. SYNC-POINTER=SyncPointer REPLAY-POINTER=ReplayPointer \
  5644. ASYNC-KEYBOARD=AsyncKeyboard SYNC-KEYBOARD=SyncKeyboard \
  5645. REPLAY-KEYBOARD=ReplayKeyboard \
  5646. ASYNC-BOTH=AsyncBoth SYNC-BOTH=SyncBoth)
  5647. DEFUN(XLIB:ALLOW-EVENTS, display mode &optional time)
  5648. {
  5649. Time timestamp = get_timestamp (popSTACK());
  5650. int mode = check_allow_events(popSTACK());
  5651. Display *dpy = pop_display ();
  5652. X_CALL(XAllowEvents (dpy, mode, timestamp));
  5653. VALUES1(NIL);
  5654. }
  5655. /* -----------------------------------------------------------------------
  5656. * Chapter 13 Resources
  5657. * ----------------------------------------------------------------------- */
  5658. /* Resources are done in Lisp (code from MIT-CLX).
  5659. This is not an ideal solution because it reduces interoperability with
  5660. other X applications, but the Xlib Xresource.h is a mess:
  5661. -- no facilities to remove a resource (http://groups.google.com/group/comp.windows.x/browse_thread/thread/564dc7a3ad8ea211)
  5662. -- memory allocation complications (who allocates and releases strings?) */
  5663. ##if 0
  5664. /* helpers */
  5665. /* can trigger GC */
  5666. static XrmDatabase check_rdb (gcv_object_t *rdb) {
  5667. *rdb = check_classname(*rdb, `XLIB::RESOURCE-DATABASE`);
  5668. return nullp(TheStructure(*rdb)->recdata[1]) ? NULL
  5669. : (XrmDatabase)TheFpointer(TheStructure(*rdb)->recdata[1])->fp_pointer;
  5670. }
  5671. DEFUN(XLIB::DESTROY-RESOURCE-DATABASE, rdb) {
  5672. XrmDatabase rdb = check_rdb(&STACK_0);
  5673. if (rdb) {
  5674. X_CALL(XrmDestroyDatabase(rdb));
  5675. TheStructure(STACK_0)->recdata[1] = NIL;
  5676. }
  5677. VALUES0; skipSTACK(1);
  5678. }
  5679. #define SET_RDB(o,db) \
  5680. TheFpointer(TheStructure(o)->recdata[1])->fp_pointer=(void*)db
  5681. static Values mk_rdb (XrmDatabase rdb) {
  5682. pushSTACK(allocate_fpointer(rdb));
  5683. funcall(`XLIB::%MAKE-RDB`,1);
  5684. }
  5685. static object mk_rdb_fin (XrmDatabase rdb) {
  5686. mk_rdb(rdb); pushSTACK(value1); pushSTACK(value1);
  5687. pushSTACK(``XLIB::DESTROY-RESOURCE-DATABASE``); funcall(L(finalize),2);
  5688. return popSTACK();
  5689. }
  5690. DEFUN(XLIB:DISPLAY-XDEFAULTS, dpy) {
  5691. Display *dpy = pop_display();
  5692. XrmDatabase rdb;
  5693. X_CALL(rdb = XrmGetDatabase(dpy));
  5694. mk_rdb(rdb); /* do not finalize! */
  5695. }
  5696. DEFUN(XLIB::SET-DISPLAY-XDEFAULTS, dpy rdb)
  5697. { /* (setf (display-defaults dpy) rdb) */
  5698. XrmDatabase rdb = check_rdb(&STACK_0);
  5699. Display *dpy = get_display(STACK_1);
  5700. X_CALL(XrmSetDatabase(dpy,rdb));
  5701. VALUES1(STACK_0); skipSTACK(2);
  5702. }
  5703. DEFUN(XLIB:RESOURCE-DATABASE-LOCALE, rdb) {
  5704. XrmDatabase rdb = check_rdb(&STACK_0);
  5705. const char *locale;
  5706. X_CALL(locale = XrmLocaleOfDatabase(rdb));
  5707. VALUES1(safe_to_string(locale)); skipSTACK(1);
  5708. }
  5709. DEFUN(XLIB:RESOURCE-DATABASE-OF-STRING, string) {
  5710. XrmDatabase rdb;
  5711. with_string_0(check_string(popSTACK()),GLO(misc_encoding),rdbz, {
  5712. X_CALL(rdb = XrmGetStringDatabase(rdbz));
  5713. });
  5714. VALUES1(mk_rdb_fin(rdb));
  5715. }
  5716. /* 13.3 Basic Resource Database Functions */
  5717. DEFUN(XLIB:MAKE-RESOURCE-DATABASE,) {
  5718. XrmDatabase rdb;
  5719. X_CALL(rdb=XrmGetStringDatabase(""));
  5720. VALUES1(mk_rdb_fin(rdb));
  5721. }
  5722. /* can trigger GC */
  5723. static void push_as_string (object o) {
  5724. pushSTACK(o);
  5725. if (!stringp(o)) { funcall(L(princ_to_string),1); pushSTACK(value1); }
  5726. }
  5727. /* can trigger GC */
  5728. static object name_concat (object name_list, object last) {
  5729. uintL count = 0;
  5730. gcv_object_t *tail, *plast;
  5731. pushSTACK(last); plast = &STACK_0;
  5732. pushSTACK(name_list); tail = &STACK_0;
  5733. for (; consp(*tail); *tail = Cdr(*tail), count++) {
  5734. push_as_string(Car(*tail));
  5735. pushSTACK(`"."`);
  5736. }
  5737. if (!nullp(*tail)) error_proper_list_dotted(TheSubr(subr_self)->name,*tail);
  5738. if (eq(*plast,nullobj)) skipSTACK(1); /* drop last "." */
  5739. else { push_as_string(*plast); count++; }
  5740. value1 = string_concat(2*count-1);
  5741. skipSTACK(2); /* drop tail & last */
  5742. return value1;
  5743. }
  5744. DEFUN(XLIB:ADD-RESOURCE, database name-list value) {
  5745. XrmDatabase rdb = check_rdb(&STACK_2);
  5746. object name_string = name_concat(STACK_1,nullobj); STACK_1 = name_string;
  5747. with_string_0(check_string(STACK_0),GLO(misc_encoding),valuez,{
  5748. with_string_0(STACK_1,GLO(misc_encoding),name_stringz,{
  5749. X_CALL(XrmPutStringResource(&rdb,name_stringz,valuez));
  5750. });
  5751. });
  5752. SET_RDB(STACK_2,rdb); VALUES0; skipSTACK(3);
  5753. }
  5754. DEFUN(XLIB:DELETE-RESOURCE, database name-list) {
  5755. XrmDatabase rdb = check_rdb(&STACK_1);
  5756. object name_string = name_concat(STACK_0,nullobj);
  5757. with_string_0(name_string,GLO(misc_encoding),name_stringz,{
  5758. X_CALL(XrmPutStringResource(&rdb,name_stringz,NULL)); /* FIXME:SIGSEGV */
  5759. });
  5760. SET_RDB(STACK_1,rdb); VALUES0; skipSTACK(2);
  5761. }
  5762. DEFUN(XLIB:MAP-RESOURCE, database function &rest args) {
  5763. NOTREACHED;
  5764. }
  5765. DEFUN(XLIB:MERGE-RESOURCES, from-database to-database &key OVERRIDE) {
  5766. bool override = nullp(STACK_0); /* default=true */
  5767. XrmDatabase source_db = check_rdb(&STACK_2);
  5768. XrmDatabase target_db = check_rdb(&STACK_1);
  5769. X_CALL(XrmCombineDatabase(source_db,&target_db,override));
  5770. SET_RDB(STACK_1,target_db);
  5771. VALUES1(STACK_1); skipSTACK(3);
  5772. }
  5773. /* 13.4 Accessing Resource Values */
  5774. DEFUN(XLIB:GET-RESOURCE, database attribute-name attribute-class \
  5775. path-name path-class) {
  5776. XrmDatabase rdb = check_rdb(&STACK_4);
  5777. char *type;
  5778. XrmValue value;
  5779. bool foundp;
  5780. object cat = name_concat(STACK_1,STACK_3); pushSTACK(cat); /* name */
  5781. cat = name_concat(STACK_1,STACK_3); pushSTACK(cat); /* class */
  5782. with_string_0(STACK_0,GLO(misc_encoding),classz,{
  5783. with_string_0(STACK_1,GLO(misc_encoding),namez,{
  5784. X_CALL(foundp = XrmGetResource(rdb,namez,classz,&type,&value));
  5785. });
  5786. });
  5787. if (asciz_equal(type,"String")) /* 1 extra byte for Nul */
  5788. VALUES1(n_char_to_string(value.addr,value.size-1,GLO(misc_encoding)));
  5789. else /* FIXME: return value, not type! */
  5790. VALUES2(n_char_to_string(value.addr,value.size,GLO(misc_encoding)),
  5791. safe_to_string(type));
  5792. skipSTACK(5+2); /* drop 5 arguments and 2 strings */
  5793. }
  5794. DEFUN(XLIB:GET-SEARCH-TABLE, database path-name path-class) {
  5795. /* manual wants the return type to be a list, we return a SEARCH-TABLE */
  5796. NOTREACHED;
  5797. }
  5798. DEFUN(XLIB:GET-SEARCH-RESOURCE, table attribute-name attribute-class) {
  5799. NOTREACHED;
  5800. }
  5801. /* 13.5 Resource Database Files */
  5802. DEFUN(XLIB:READ-RESOURCES, rdb path &key :KEY :TEST :TEST-NOT OVERRIDE)
  5803. { /* FIXME: KEY, TEST, TEST-NOT are ignored */
  5804. XrmDatabase rdb = nullp(STACK_5) ? NULL : check_rdb(&STACK_5);
  5805. bool override = nullp(STACK_0); /* default=true */
  5806. Status status;
  5807. with_string_0(physical_namestring(STACK_4),GLO(pathname_encoding),pathz,{
  5808. X_CALL(status = XrmCombineFileDatabase(pathz,&rdb,override));
  5809. });
  5810. if (status != Success) {
  5811. pushSTACK(STACK_4); pushSTACK(TheSubr(subr_self)->name);
  5812. error(error_condition,GETTEXT("~S: Cannot read ~S"));
  5813. }
  5814. if (nullp(STACK_5)) mk_rdb(rdb);
  5815. else { SET_RDB(STACK_5,rdb); VALUES1(STACK_5); }
  5816. skipSTACK(6);
  5817. }
  5818. DEFUN(XLIB:WRITE-RESOURCES, rdb path &key WRITE :TEST :TEST-NOT)
  5819. { /* FIXME: WRITE, TEST, TEST-NOT are ignored */
  5820. XrmDatabase rdb = check_rdb(&STACK_4);
  5821. with_string_0(physical_namestring(STACK_3),GLO(pathname_encoding),pathz,{
  5822. X_CALL(XrmPutFileDatabase(rdb,pathz));
  5823. });
  5824. VALUES0; skipSTACK(5);
  5825. }
  5826. ##endif
  5827. /* -----------------------------------------------------------------------
  5828. * Chapter 14 Control Functions
  5829. * ----------------------------------------------------------------------- */
  5830. /* 14.1 Grabbing the Server */
  5831. DEFUN(XLIB:GRAB-SERVER, display)
  5832. {
  5833. Display *dpy = pop_display ();
  5834. X_CALL(XGrabServer (dpy));
  5835. VALUES1(NIL);
  5836. }
  5837. DEFUN(XLIB:UNGRAB-SERVER, display)
  5838. {
  5839. Display *dpy = pop_display ();
  5840. X_CALL(XUngrabServer (dpy));
  5841. VALUES1(NIL);
  5842. }
  5843. /* 14.2 Pointer Control */
  5844. DEFUN(XLIB:CHANGE-POINTER-CONTROL, display &key ACCELERATION THRESHOLD)
  5845. {
  5846. Bool do_accel = False;
  5847. Bool do_threshold = False;
  5848. int accel_numerator = -1;
  5849. int accel_denominator = -1;
  5850. int threshold = -1;
  5851. Display *dpy;
  5852. if (!missingp(STACK_0)) {
  5853. do_threshold = True;
  5854. threshold = eq(STACK_1,S(Kdefault)) ? -1 : get_sint16 (STACK_0);
  5855. }
  5856. if (!missingp(STACK_1)) {
  5857. do_accel = True;
  5858. if (eq(STACK_1,S(Kdefault)))
  5859. accel_numerator = -1;
  5860. else {
  5861. /* This is basically a translation from this lisp code:
  5862. (do* ((rational (rationalize number))
  5863. (numerator (numerator rational) (ash numerator -1))
  5864. (denominator (denominator rational) (ash denominator -1)))
  5865. ((or (= numerator 1)
  5866. (and (< (abs numerator) #x8000)
  5867. (< denominator #x8000)))
  5868. (values
  5869. numerator (min denominator #x7fff)))) */
  5870. pushSTACK(STACK_1); /* 0 (LOAD&PUSH 1) ; argument */
  5871. funcall (L(rationalize), 1); /* 1 (CALLS2&PUSH 177) ; RATIONALIZE */
  5872. pushSTACK(value1);
  5873. pushSTACK(STACK_0); /* 3 (LOAD&PUSH 0) */
  5874. funcall (L(numerator), 1); /* 4 (CALLS2&PUSH 178) ; NUMERATOR */
  5875. pushSTACK(value1);
  5876. pushSTACK(STACK_1); /* 6 (LOAD&PUSH 1) */
  5877. funcall (L(denominator), 1); /* 7 (CALLS2&PUSH 179) ; DENOMINATOR */
  5878. pushSTACK(value1);
  5879. goto L21; /* 9 (JMP L21) */
  5880. L11: /* 11 L11 */
  5881. pushSTACK(STACK_1); /* 11 (LOAD&PUSH 1) */
  5882. pushSTACK(Fixnum_minus1);/* 12 (CONST&PUSH 2) ; -1 */
  5883. funcall (L(ash), 2); /* 13 (CALLS2&STORE 210 1) ; ASH */
  5884. STACK_1 = value1;
  5885. pushSTACK(STACK_0); /* 16 (LOAD&PUSH 0) */
  5886. pushSTACK(Fixnum_minus1);/* 17 (CONST&PUSH 2) ; -1 */
  5887. funcall (L(ash), 2); /* 18 (CALLS2&STORE 210 0) ; ASH */
  5888. STACK_0 = value1; /* 18 */
  5889. L21: /* 21 L21 */
  5890. pushSTACK(STACK_1); /* 21 (LOAD&PUSH 1) */
  5891. pushSTACK(Fixnum_1); /* 22 (CONST&PUSH 0) ; 1 */
  5892. funcall(L(numequal),2); /* 23 (CALLSR&JMPIF 1 45 L41) ; = */
  5893. if(!nullp(value1)) goto L41;
  5894. pushSTACK(STACK_1); /* 27 (LOAD&PUSH 1) */
  5895. funcall (L(abs), 1); /* 28 (CALLS2&PUSH 159) ; ABS */
  5896. pushSTACK(value1);
  5897. pushSTACK(fixnum(0x8000)); /* 30 (CONST&PUSH 1) ; 32768 */
  5898. funcall (L(smaller), 2); /* 31 (CALLSR&JMPIFNOT 1 47 L11) ; < */
  5899. if(nullp(value1)) goto L11;
  5900. pushSTACK(STACK_0); /* 35 (LOAD&PUSH 0) */
  5901. pushSTACK(fixnum(0x8000)); /* 36 (CONST&PUSH 1) ; 32768 */
  5902. funcall (L(smaller), 2); /* 37 (CALLSR&JMPIFNOT 1 47 L11) ; < */
  5903. if(nullp(value1)) goto L11;
  5904. L41: /* 41 L41 */
  5905. /* rest done in C ... */
  5906. accel_denominator = get_sint16 (popSTACK());
  5907. accel_numerator = get_sint16 (popSTACK());
  5908. if (accel_denominator > 0x7FFF)
  5909. accel_denominator = 0x7FFF;
  5910. skipSTACK(1); /* right?! */
  5911. /* 41 (LOAD&PUSH 1)
  5912. 42 (LOAD&PUSH 1)
  5913. 43 (CONST&PUSH 3) ; 32767
  5914. 44 (CALLSR&PUSH 1 52) ; MIN
  5915. 47 (STACK-TO-MV 2)
  5916. 49 (SKIP&RET 5) */
  5917. /* Bruno: Why could not a compiler create this?! :-) */
  5918. }
  5919. }
  5920. pushSTACK(STACK_2); dpy = pop_display ();
  5921. X_CALL(XChangePointerControl (dpy, do_accel, do_threshold, accel_numerator,
  5922. accel_denominator, threshold));
  5923. skipSTACK(3);
  5924. VALUES1(NIL);
  5925. }
  5926. DEFUN(XLIB:POINTER-CONTROL, display)
  5927. {
  5928. Display *display = pop_display ();
  5929. int accel_numerator = 0;
  5930. int accel_denominator = 1;
  5931. int threshold = 0;
  5932. X_CALL(XGetPointerControl (display, &accel_numerator, &accel_denominator,
  5933. &threshold));
  5934. pushSTACK(make_sint32 (threshold));
  5935. pushSTACK(make_sint32 (accel_numerator));
  5936. pushSTACK(make_sint32 (accel_denominator));
  5937. funcall (L(slash), 2);
  5938. value2 = popSTACK();
  5939. mv_count = 2;
  5940. }
  5941. DEFUN(XLIB:POINTER-MAPPING, display &key RESULT-TYPE)
  5942. { /* Does the Protocol say anything about the maximum number
  5943. of buttons?! Or the other way round: Are there any
  5944. pointing devices with more than five buttons? */
  5945. unsigned char map [5];
  5946. unsigned int nmap, i;
  5947. Display *dpy = get_display(STACK_1);
  5948. gcv_object_t *res_type = &STACK_0;
  5949. X_CALL(nmap = XGetPointerMapping (dpy, map, sizeof (map)/sizeof (map[0])));
  5950. for (i = 0; i < nmap; i++)
  5951. pushSTACK(make_uint8 (map[i]));
  5952. VALUES1(coerce_result_type(nmap,res_type));
  5953. skipSTACK(2); /* all done */
  5954. }
  5955. /* convert a Lisp sequence of uint8 to a C vector */
  5956. struct seq_uint8 { unsigned char* data; };
  5957. void coerce_into_uint8 (void *arg, object element);
  5958. void coerce_into_uint8 (void *arg, object element)
  5959. { *(((struct seq_uint8 *)arg)->data++) = get_uint8(element); }
  5960. DEFUN(XLIB:SET-POINTER-MAPPING, display mapping)
  5961. { /* (SETF (XLIB:POINTER-MAPPING display) mapping) */
  5962. Display *dpy = get_display(STACK_1);
  5963. int nmap = get_uint32(funcall1(L(length),STACK_0));
  5964. int result;
  5965. struct seq_uint8 su;
  5966. DYNAMIC_ARRAY (map, unsigned char, nmap);
  5967. su.data = map;
  5968. map_sequence(STACK_0,coerce_into_uint8,(void*)&su);
  5969. X_CALL(result = XSetPointerMapping (dpy, map, nmap));
  5970. /* From XSetPointerMapping(3X11):
  5971. If any of the buttons to be altered are logically in the down state,
  5972. XSetPointerMapping returns MappingBusy, and the mapping is not changed.
  5973. What should we do with that?! */
  5974. FREE_DYNAMIC_ARRAY (map);
  5975. VALUES1(STACK_0);
  5976. skipSTACK(2); /* all done */
  5977. /* Isn't that all a overdoze for this functions?! (But since my mouse thinks
  5978. from time to time the left button has only been invented just to make
  5979. noise, I need it now and then) */
  5980. }
  5981. /* 14.3 Keyboard Control */
  5982. DEFUN(XLIB:BELL, display &optional percent)
  5983. {
  5984. int percent = get_sint16_0(popSTACK());
  5985. Display *dpy = pop_display ();
  5986. X_CALL(XBell (dpy, percent));
  5987. VALUES1(NIL);
  5988. }
  5989. DEFCHECKER(check_on_off,default=AutoRepeatModeDefault,OFF=AutoRepeatModeOff\
  5990. ON=AutoRepeatModeOn :DEFAULT=AutoRepeatModeDefault)
  5991. DEFUN(XLIB:CHANGE-KEYBOARD-CONTROL, display \
  5992. &key KEY-CLICK-PERCENT BELL-PERCENT BELL-PITCH BELL-DURATION LED \
  5993. LED-MODE :KEY AUTO-REPEAT-MODE)
  5994. { /* http://www.linuxmanpages.com/man3/XChangeKeyboardControl.3x.php */
  5995. unsigned long value_mask = 0;
  5996. XKeyboardControl xkbc;
  5997. #define GETARG(mask,slot,checker) \
  5998. if (!missingp(STACK_0)) { \
  5999. value_mask |= mask; \
  6000. xkbc.slot = checker(STACK_0); \
  6001. } \
  6002. skipSTACK(1)
  6003. #define on_p(x) (eq(x,`:ON`))
  6004. GETARG(KBAutoRepeatMode,auto_repeat_mode,check_on_off); /* AUTO-REPEAT-MODE */
  6005. GETARG(KBKey,key,get_uint8); /* KEY */
  6006. GETARG(KBLedMode,led_mode,on_p); /* LED-MODE */
  6007. GETARG(KBLed,led,get_uint8); /* LED */
  6008. GETARG(KBBellDuration,bell_duration,get_uint16); /* BELL-DURATION */
  6009. GETARG(KBBellPitch,bell_pitch,get_uint16); /* BELL-PITCH */
  6010. GETARG(KBBellPercent,bell_percent,get_uint8); /* BELL-PERCENT */
  6011. GETARG(KBKeyClickPercent,key_click_percent,get_uint8); /* KEY-CLICK-PERCENT */
  6012. #undef on_p
  6013. #undef GETARG
  6014. {
  6015. Display *dpy = pop_display();
  6016. X_CALL(XChangeKeyboardControl(dpy,value_mask,&xkbc));
  6017. }
  6018. VALUES0;
  6019. }
  6020. DEFUN(XLIB:KEYBOARD-CONTROL, display)
  6021. {
  6022. Display *dpy = pop_display ();
  6023. XKeyboardState coffee;
  6024. X_CALL(XGetKeyboardControl (dpy, &coffee));
  6025. pushSTACK(make_uint32 (coffee.led_mask));
  6026. value7 = make_fill_bit_vector(coffee.auto_repeats,
  6027. sizeof(coffee.auto_repeats));
  6028. value1 = make_uint8 (coffee.key_click_percent);
  6029. value2 = make_uint8 (coffee.bell_percent);
  6030. value3 = make_uint16 (coffee.bell_pitch);
  6031. value4 = make_uint16 (coffee.bell_duration);
  6032. value5 = popSTACK();
  6033. value6 = (coffee.global_auto_repeat == AutoRepeatModeOn) ? `:ON` : `:OFF`;
  6034. mv_count = 7;
  6035. }
  6036. DEFUN(XLIB:MODIFIER-MAPPING, display)
  6037. {
  6038. Display *dpy = pop_display ();
  6039. XModifierKeymap *more_coffee;
  6040. X_CALL(more_coffee = XGetModifierMapping (dpy));
  6041. if (more_coffee) {
  6042. int i;
  6043. for (i = 1; i <= 8*more_coffee->max_keypermod; i++) {
  6044. pushSTACK(fixnum(more_coffee->modifiermap[i-1]));
  6045. if (i % more_coffee->max_keypermod == 0) {
  6046. value1 = listof(more_coffee->max_keypermod);
  6047. pushSTACK(value1);
  6048. }
  6049. }
  6050. X_CALL(XFreeModifiermap (more_coffee));
  6051. STACK_to_mv(8);
  6052. } else
  6053. VALUES0;
  6054. }
  6055. /* NOTE: this function is also different from the manual.
  6056. The manual does not specify the optional argument. */
  6057. DEFUN(XLIB:QUERY-KEYMAP, display &optional bit-vector)
  6058. {
  6059. Display *dpy = get_display(STACK_1);
  6060. if (boundp(STACK_0)) {
  6061. check_bitvec_256(STACK_0);
  6062. } else
  6063. STACK_0 = allocate_bit_vector (Atype_Bit, 256);
  6064. {
  6065. unsigned char *ptr = (unsigned char *) TheSbvector(STACK_0)->data;
  6066. X_CALL(XQueryKeymap (dpy, (char*) ptr)); /* beam it right into the bit-vector! */
  6067. }
  6068. VALUES1(STACK_0);
  6069. skipSTACK(2); /* all done */
  6070. }
  6071. DEFCHECKER(check_set_mod_map,SUCCESS=MappingSuccess FAILED=MappingFailed\
  6072. DEVICE-BUSY=MappingBusy)
  6073. DEFUN(XLIB:SET-MODIFIER-MAPPING, display &key SHIFT LOCK CONTROL \
  6074. MOD1 MOD2 MOD3 MOD4 MOD5)
  6075. { /* http://www.linuxmanpages.com/man3/XModifierKeymap.3x.php */
  6076. XModifierKeymap *xmk;
  6077. int i, max_keys_per_mod=0;
  6078. for (i=0; i<8; i++) {
  6079. unsigned int len = get_uint32(funcall1(L(length),STACK_(i)));
  6080. if (len > max_keys_per_mod) max_keys_per_mod = len;
  6081. }
  6082. X_CALL(xmk = XNewModifiermap(max_keys_per_mod));
  6083. if (xmk == NULL) { skipSTACK(9); VALUES0; return; } /* no values */
  6084. for (i=0; i<8; i++) {
  6085. struct seq_uint8 su;
  6086. su.data = xmk->modifiermap + i * max_keys_per_mod;
  6087. map_sequence(STACK_(8-1-i),coerce_into_uint8,(void*)&su);
  6088. }
  6089. skipSTACK(8); /* drop modifier arguments */
  6090. {
  6091. Display *dpy = pop_display ();
  6092. X_CALL(i = XSetModifierMapping(dpy,xmk);
  6093. XFreeModifiermap(xmk));
  6094. }
  6095. VALUES1(check_set_mod_map_reverse(i));
  6096. }
  6097. /* 14.4 Keyboard Encodings */
  6098. #if SIZEOF_KEYSYM == 4
  6099. # define KBD_MAP_RANK 2
  6100. # define check_dim(a) (array_rank(a)==KBD_MAP_RANK)
  6101. # define KBD_MAP_TYPE `(ARRAY (UNSIGNED-BYTE 32) (* *))`
  6102. # define extra_dim_push()
  6103. #elif SIZEOF_KEYSYM == 8
  6104. # define KBD_MAP_RANK 3
  6105. static inline bool check_dim (object a) {
  6106. uintL rank = array_rank(a);
  6107. if (rank != KBD_MAP_RANK) return false;
  6108. else {
  6109. uintL dims[KBD_MAP_RANK];
  6110. get_array_dimensions(a,KBD_MAP_RANK,dims);
  6111. return dims[KBD_MAP_RANK-1] == 2;
  6112. }
  6113. }
  6114. # define KBD_MAP_TYPE `(ARRAY (UNSIGNED-BYTE 32) (* * 2))`
  6115. # define extra_dim_push() pushSTACK(fixnum(2))
  6116. #else
  6117. # error Unexpected sizeof(KeySym)
  6118. #endif
  6119. static object check_kbdmap_mx (object data) {
  6120. while (array_atype(data = check_array(data)) != Atype_32Bit
  6121. || !check_dim(data)) {
  6122. pushSTACK(NIL); /* no PLACE */
  6123. pushSTACK(STACK_1); /* TYPE-ERROR slot DATUM */
  6124. pushSTACK(KBD_MAP_TYPE); /* EXPECTED-TYPE */
  6125. pushSTACK(STACK_0); pushSTACK(STACK_2);
  6126. pushSTACK(TheSubr(subr_self)->name);
  6127. check_value(type_error,GETTEXT("~S: ~S is not an array of type ~S"));
  6128. data = value1;
  6129. }
  6130. return data;
  6131. }
  6132. DEFUN(XLIB:CHANGE-KEYBOARD-MAPPING, dpy keysyms &key :END FIRST-KEYCODE :START)
  6133. {
  6134. int start = check_uint_defaulted(popSTACK(),0), end;
  6135. int first_keycode = check_uint_defaulted(popSTACK(),start);
  6136. uintL offset = 0, dims[KBD_MAP_RANK];
  6137. Display *dpy = get_display(STACK_2);
  6138. KeySym* data_ptr;
  6139. STACK_1 = check_kbdmap_mx(STACK_1);
  6140. get_array_dimensions(STACK_1,KBD_MAP_RANK,dims);
  6141. end = check_uint_defaulted(popSTACK(),dims[0]);
  6142. STACK_0 = array_displace_check(STACK_0,(end-start)*dims[1],&offset);
  6143. data_ptr = (KeySym*)TheSbvector(STACK_0)->data + offset;
  6144. X_CALL(XChangeKeyboardMapping(dpy,first_keycode,dims[1],data_ptr,end-start));
  6145. VALUES0; skipSTACK(2);
  6146. }
  6147. DEFUN(XLIB:KEYBOARD-MAPPING, dpy &key FIRST-KEYCODE :START :END DATA)
  6148. { /* http://www.linuxmanpages.com/man3/XGetKeyboardMapping.3x.php */
  6149. Display *dpy = get_display(STACK_4);
  6150. int first_keycode, min_keycode, max_keycode, keysyms_per_keycode;
  6151. KeySym *map;
  6152. int start, end, num_codes, keycode_count;
  6153. object data_vector;
  6154. void * data_ptr;
  6155. uintL offset = 0;
  6156. X_CALL(XDisplayKeycodes(dpy,&min_keycode,&max_keycode));
  6157. first_keycode = check_uint_defaulted(STACK_3,min_keycode);
  6158. start = check_uint_defaulted(STACK_2,first_keycode);
  6159. end = check_uint_defaulted(STACK_1,1+max_keycode);
  6160. keycode_count = end-start;
  6161. X_CALL(map = XGetKeyboardMapping(dpy,first_keycode,keycode_count,
  6162. &keysyms_per_keycode));
  6163. if (missingp(STACK_0)) { /* return a fresh array */
  6164. pushSTACK(fixnum(keycode_count));
  6165. pushSTACK(fixnum(keysyms_per_keycode));
  6166. extra_dim_push();
  6167. value1 = listof(KBD_MAP_RANK); pushSTACK(value1); /* dims */
  6168. pushSTACK(S(Kelement_type)); pushSTACK(GLO(type_uint32));
  6169. funcall(L(make_array),3); STACK_0 = value1;
  6170. } else { /* ensure that DATA is a valid uint32 array */
  6171. STACK_0 = check_kbdmap_mx(STACK_0);
  6172. }
  6173. num_codes = keycode_count*keysyms_per_keycode*sizeof(KeySym)/sizeof(uint32);
  6174. data_vector = array_displace_check(STACK_0,num_codes,&offset);
  6175. data_ptr = (uint32*)TheSbvector(data_vector)->data + offset;
  6176. X_CALL(memcpy(data_ptr,map,num_codes*sizeof(uint32)); XFree(map));
  6177. VALUES1(STACK_0);
  6178. skipSTACK(5);
  6179. }
  6180. static KeySym keycode2keysym (Display *dpy, KeyCode keycode, int index) {
  6181. KeySym keysym;
  6182. X_CALL(keysym = XKeycodeToKeysym (dpy, keycode, index);
  6183. /* There is a comment in MIT-CLX, translate.lisp, which I want to quote here:
  6184. The keysym-mapping is brain dammaged.
  6185. Mappings for both-case alphabetic characters have the
  6186. entry for keysym-index zero set to the uppercase keysym
  6187. (this is normally where the lowercase keysym goes), and the
  6188. entry for keysym-index one is zero.
  6189. Then code continues:
  6190. (cond ((zerop keysym-index) ; Lowercase alphabetic keysyms
  6191. (keysym-downcase keysym))
  6192. That [above] is already implemented in libX, but not this [below] klugde:
  6193. ((and (zerop keysym) (plusp keysym-index)) ; Get the uppercase keysym
  6194. (aref mapping keycode 0))
  6195. .. so */
  6196. if (keysym == NoSymbol && index > 0)
  6197. keysym = XKeycodeToKeysym (dpy, keycode, 0));
  6198. return keysym;
  6199. }
  6200. DEFUN(XLIB:KEYCODE->KEYSYM, display keycode keysym-index)
  6201. { /* NOTE: In the Manual this function is called "keycode-keysym" */
  6202. int index = get_uint8 (popSTACK());
  6203. KeyCode keycode = get_uint8 (popSTACK());
  6204. Display *dpy = pop_display ();
  6205. KeySym keysym = keycode2keysym(dpy,keycode,index);
  6206. /* I wanted to say
  6207. "value1 = (keysym == NoSymbol) ? NIL : make_uint32 (keysym);",
  6208. but seeing the MIT-CLX code, I better say simply: */
  6209. VALUES1(make_uint32 (keysym == NoSymbol ? 0 : keysym));
  6210. }
  6211. /* XLIB:KEYCODE->CHARACTER display keysym &optional (state 0)
  6212. NOTE: The manual calls this function "keycode-keysym"
  6213. This functions is somewhat wired:
  6214. - It should be called KEYSYM->SONSTWAS
  6215. - We could also get a string instead of a single character
  6216. - The modifier bits (the state argument) mentioned in the manual are no
  6217. longer in the Common Lisp standard.
  6218. BTW: How does a LISP program determine in a readable way the name of a
  6219. keysym, I think I should add that. (For an idea inspect e.g the libX11
  6220. functions XStringToKeysym and XKeysymToString).
  6221. Well with normal CLX this goes just like this:
  6222. (xlib:keysym->character dpy 97) --> #\a
  6223. (xlib:keysym->character dpy 97 4) --> #\CONTROL-\a ; 4 is <ctrl>
  6224. (xlib:keysym->character dpy 97 8) --> #\META-\a ; 8 is <meta>
  6225. (xlib:keysym->character dpy 65) --> #\A
  6226. (xlib:keysym->character dpy 65 4) --> #\CONTROL-A
  6227. (xlib:keysym->character dpy 65 8) --> #\META-\A
  6228. (xlib:keysym->character dpy #xFF52) --> NIL ; #xFF52 is <up>
  6229. Had we unicode characters, this function would become more interesting.
  6230. Yeah is there any correspondes between the various latin-n maps in X11
  6231. and unicode?!
  6232. I really want unicode support. */
  6233. DEFUN(XLIB:KEYSYM->CHARACTER, display keysym &optional state)
  6234. {
  6235. Display *dpy;
  6236. KeySym keysym;
  6237. /* FIXME for now we ignore the state argument: */
  6238. skipSTACK(1);
  6239. keysym = get_uint32 (popSTACK());
  6240. dpy = pop_display ();
  6241. /* Too wired -- I have to browse some more in the manuals ... Back soon. */
  6242. VALUES1(int_char(keysym)); /* how about just int_char ?! */
  6243. }
  6244. DEFUN(XLIB:KEYSYM-NAME, keysym)
  6245. { /* http://www.xfree86.org/current/XStringToKeysym.3.html */
  6246. KeySym keysym = get_uint32(popSTACK());
  6247. char *name;
  6248. X_CALL(name = XKeysymToString(keysym));
  6249. VALUES1(safe_to_string(name));
  6250. }
  6251. /* Return keycodes for keysym, as multiple values
  6252. Hmm. It goes like this:
  6253. (xlib:keysym->keycode dpy 65) --> 38
  6254. (xlib:keysym->keycode dpy #xFF52) --> 148 ; 98 ; 80 ; #xFF52 keysym for <up> */
  6255. DEFUN(XLIB:KEYSYM->KEYCODES, display keysym) /* NIM */
  6256. { /* http://www.linuxmanpages.com/man3/XGetKeyboardMapping.3x.php */
  6257. uint32 keysym = get_uint32(popSTACK());
  6258. Display *dpy = pop_display();
  6259. int min_keycode, max_keycode, keysyms_per_keycode, retcount=0, kc = 0;
  6260. KeySym *map, *map1;
  6261. begin_x_call();
  6262. XDisplayKeycodes(dpy,&min_keycode,&max_keycode);
  6263. map = XGetKeyboardMapping(dpy,min_keycode,max_keycode-min_keycode+1,
  6264. &keysyms_per_keycode);
  6265. end_x_call();
  6266. for (kc = min_keycode, map1 = map; kc <= max_keycode; kc++) {
  6267. int i = 0;
  6268. for (; i<keysyms_per_keycode; i++)
  6269. if (*map1++ == keysym) {
  6270. retcount++;
  6271. pushSTACK(fixnum(kc));
  6272. }
  6273. }
  6274. X_CALL(XFree(map));
  6275. STACK_to_mv(retcount);
  6276. }
  6277. DEFUN(XLIB:KEYSYM, keysym &rest bytes) { /* see mit-clx/translate.lisp */
  6278. if (uint8_p(STACK_(argcount))) {
  6279. uint32 keysym = get_uint8(STACK_(argcount));
  6280. int count = argcount;
  6281. while (count--) keysym = (keysym<<8) | get_uint8(STACK_(count));
  6282. skipSTACK(argcount+1);
  6283. VALUES1(make_uint32(keysym));
  6284. } else if ((stringp(STACK_(argcount)) || symbolp(STACK_(argcount)))
  6285. && argcount==0) {
  6286. KeySym keysym;
  6287. /* unfortunately, keysyms should be named Hyper_L or Super_R,
  6288. not :left-hyper or :right-super */
  6289. with_stringable_0_tc(STACK_0,GLO(misc_encoding),name, {
  6290. X_CALL(keysym=XStringToKeysym(name));
  6291. });
  6292. skipSTACK(1);
  6293. VALUES1(make_uint32(keysym));
  6294. } else {
  6295. object tmp = listof(argcount+1); pushSTACK(tmp);
  6296. pushSTACK(TheSubr(subr_self)->name);
  6297. error(error_condition,"~S: invalid arguments ~S");
  6298. }
  6299. }
  6300. DEFUN(XLIB:KEYCODE->CHARACTER, display keycode state \
  6301. &key KEYSYM-INDEX KEYSYM-INDEX-FUNCTION) {
  6302. KeyCode keycode = get_uint8(STACK_3);
  6303. Display *dpy = get_display(STACK_4);
  6304. int index;
  6305. if (missingp(STACK_1)) { /* no KEYSYM-INDEX => use KEYSYM-INDEX-FUNCTION */
  6306. object func = missingp(STACK_0) ? ``XLIB::DEFAULT-KEYSYM-INDEX``
  6307. : (object)STACK_0;
  6308. skipSTACK(2);
  6309. funcall(func,3);
  6310. index = get_sint32(value1);
  6311. } else {
  6312. index = get_sint32(STACK_1);
  6313. skipSTACK(5);
  6314. }
  6315. /* state is ignored, just like in keysym->character */
  6316. VALUES1(int_char(keycode2keysym(dpy,keycode,index)));
  6317. }
  6318. /* 14.5 Client Termination */
  6319. DEFUN(XLIB:ADD-TO-SAVE-SET, window)
  6320. { /* WAS: invoke (XAddToSaveSet, 1, "D1w"); */
  6321. Display *dpy;
  6322. Window win = get_window_and_display (STACK_0, &dpy);
  6323. X_CALL(XAddToSaveSet (dpy, win));
  6324. VALUES1(NIL);
  6325. skipSTACK(1);
  6326. }
  6327. DEFUN(XLIB:CLOSE-DOWN-MODE, display)
  6328. { /* FIXME: This is wrong -- The close down mode could not been asked from the
  6329. server, but you could store it in the display structure. (Like
  6330. MIT-CLX does it.) */
  6331. pushSTACK(`XLIB::CLOSE-DOWN-MODE`);
  6332. error(error_condition,"~S can only be set");
  6333. }
  6334. DEFUN(XLIB:SET-CLOSE-DOWN-MODE, mode display)
  6335. {
  6336. Display *dpy = pop_display ();
  6337. int mode = get_close_down_mode (STACK_0);
  6338. X_CALL(XSetCloseDownMode (dpy, mode));
  6339. VALUES1(popSTACK());
  6340. }
  6341. DEFUN(XLIB:KILL-CLIENT, display id)
  6342. {
  6343. XID resource_id = get_uint29 (popSTACK());
  6344. Display *dpy = pop_display ();
  6345. X_CALL(XKillClient (dpy, resource_id));
  6346. VALUES1(NIL);
  6347. }
  6348. DEFUN(XLIB:KILL-TEMPORARY-CLIENTS, display)
  6349. {
  6350. Display *dpy = pop_display ();
  6351. X_CALL(XKillClient (dpy, AllTemporary));
  6352. VALUES1(NIL);
  6353. }
  6354. DEFUN(XLIB:REMOVE-FROM-SAVE-SET, window)
  6355. {
  6356. Display *dpy;
  6357. Window win = get_window_and_display (STACK_0, &dpy);
  6358. X_CALL(XRemoveFromSaveSet (dpy, win));
  6359. VALUES1(NIL);
  6360. skipSTACK(1);
  6361. }
  6362. /* 14.6 Managing Host Access */
  6363. DEFUN(XLIB:ACCESS-CONTROL, display)
  6364. {
  6365. Display *dpy = pop_display ();
  6366. XHostAddress *hosts;
  6367. Bool state;
  6368. int nhosts;
  6369. begin_x_call();
  6370. hosts = XListHosts (dpy, &nhosts, &state);
  6371. if (hosts) XFree (hosts);
  6372. end_x_call();
  6373. VALUES_IF(state);
  6374. }
  6375. DEFUN(XLIB::SET-ACCESS-CONTROL, dpy state)
  6376. {/* (SETF (XLIB:ACCESS-CONTROL dpy) state) */
  6377. Bool state = get_bool(STACK_0);
  6378. Display *dpy = get_display(STACK_1);
  6379. X_CALL(XSetAccessControl (dpy, state));
  6380. VALUES1(popSTACK()); skipSTACK(1);
  6381. }
  6382. #if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_NETDB_H) && defined(HAVE_NETINET_IN_H)
  6383. /* see module syscalls */
  6384. extern Values hostent_to_lisp (struct hostent *he);
  6385. DEFUN(XLIB:ACCESS-HOSTS, display &key RESULT-TYPE)
  6386. { /* http://www.linuxmanpages.com/man3/XListHosts.3x.php */
  6387. Display *dpy = get_display(STACK_1);
  6388. gcv_object_t *res_type = &STACK_0;
  6389. XHostAddress *hosts;
  6390. Bool state;
  6391. int nhosts = 0;
  6392. X_CALL(hosts = XListHosts(dpy,&nhosts,&state));
  6393. if (hosts) {
  6394. int i = nhosts;
  6395. XHostAddress *ho = hosts;
  6396. while (i--) {
  6397. if (ho->length) {
  6398. int family;
  6399. switch (ho->family) {
  6400. # if defined(HAVE_IPV6) && defined(FamilyInternet6)
  6401. case FamilyInternet6: /* IPv6 */
  6402. ASSERT(ho->length == sizeof(struct in6_addr));
  6403. family = AF_INET6;
  6404. goto handle_ipv4;
  6405. # endif
  6406. case FamilyInternet: /* IPv4 */
  6407. ASSERT(ho->length == sizeof(struct in_addr));
  6408. family = AF_INET;
  6409. handle_ipv4: {
  6410. struct hostent *he;
  6411. X_CALL(he = gethostbyaddr((char*)ho->address,ho->length,family));
  6412. hostent_to_lisp(he);
  6413. }
  6414. pushSTACK(value1);
  6415. break;
  6416. # if defined(FamilyServerInterpreted)
  6417. case FamilyServerInterpreted: {
  6418. XServerInterpretedAddress *sia =
  6419. (XServerInterpretedAddress*)ho->address;
  6420. pushSTACK(`:SERVER-INTERPRETED`);
  6421. pushSTACK(n_char_to_string(sia->type,sia->typelength,
  6422. GLO(misc_encoding)));
  6423. pushSTACK(n_char_to_string(sia->value,sia->valuelength,
  6424. GLO(misc_encoding)));
  6425. value1 = listof(3); pushSTACK(value1);
  6426. } break;
  6427. # endif
  6428. default:
  6429. pushSTACK(fixnum(ho->family));
  6430. pushSTACK(allocate_bit_vector(Atype_8Bit,ho->length));
  6431. X_CALL(memcpy(TheSbvector(STACK_0)->data,ho->address,ho->length));
  6432. value1 = listof(2); pushSTACK(value1);
  6433. }
  6434. } else pushSTACK(NIL);
  6435. ho++;
  6436. }
  6437. X_CALL(XFree(hosts));
  6438. }
  6439. VALUES2(coerce_result_type(nhosts,res_type), state ? T : NIL);
  6440. skipSTACK(2);
  6441. }
  6442. static void lisp_to_XHostAddress (object host, XHostAddress *xha) {
  6443. struct hostent *he;
  6444. if (typep_classname(host,`POSIX:HOSTENT`)) {
  6445. pushSTACK(host); funcall(`POSIX:HOSTENT-NAME`,1);
  6446. he = resolve_host(host);
  6447. } else he = resolve_host(host);
  6448. switch (he->h_addrtype) {
  6449. case AF_INET: xha->family = FamilyInternet;
  6450. xha->length = sizeof(struct in_addr); break;
  6451. # if defined(HAVE_IPV6) && defined(FamilyInternet6)
  6452. case AF_INET6: xha->family = FamilyInternet6;
  6453. xha->length = sizeof(struct in6_addr); break;
  6454. # endif
  6455. default: pushSTACK(fixnum(he->h_addrtype));
  6456. pushSTACK(TheSubr(subr_self)->name);
  6457. error(error_condition,GETTEXT("~S: unknown address family ~S"));
  6458. }
  6459. xha->address = he->h_addr_list[0];
  6460. }
  6461. DEFUN(XLIB:ADD-ACCESS-HOST, display host)
  6462. {
  6463. XHostAddress xha;
  6464. Display *dpy;
  6465. lisp_to_XHostAddress(popSTACK(),&xha);
  6466. dpy = pop_display();
  6467. X_CALL(XAddHost(dpy,&xha));
  6468. VALUES0;
  6469. }
  6470. DEFUN(XLIB:REMOVE-ACCESS-HOST, display host)
  6471. {
  6472. XHostAddress xha;
  6473. Display *dpy;
  6474. lisp_to_XHostAddress(popSTACK(),&xha);
  6475. dpy = pop_display();
  6476. X_CALL(XRemoveHost(dpy,&xha));
  6477. VALUES0;
  6478. }
  6479. #endif /* HAVE_SYS_SOCKET_H & HAVE_NETDB_H & HAVE_NETINET_IN_H */
  6480. /* 14.7 Screen Saver */
  6481. DEFUN(XLIB:ACTIVATE-SCREEN-SAVER, display)
  6482. {
  6483. X_CALL(XActivateScreenSaver (pop_display ()));
  6484. VALUES1(NIL);
  6485. }
  6486. DEFUN(XLIB:RESET-SCREEN-SAVER, display)
  6487. {
  6488. X_CALL(XResetScreenSaver (pop_display ()));
  6489. VALUES1(NIL);
  6490. }
  6491. /* Lots of mixing with :on/:off, :yes/:no, why not T and NIL,
  6492. the natural way?!
  6493. [Was that written by Pascal programmers?] @*~#&%" */
  6494. /* same for DontAllowExposures ... */
  6495. DEFCHECKER(check_yes_no,default=DefaultBlanking,\
  6496. NO=DontPreferBlanking YES=PreferBlanking :DEFAULT=DefaultBlanking)
  6497. DEFUN(XLIB:SCREEN-SAVER, display)
  6498. {
  6499. Display *dpy = pop_display ();
  6500. int timeout;
  6501. int interval;
  6502. int prefer_blanking;
  6503. int allow_exposures;
  6504. X_CALL(XGetScreenSaver (dpy, &timeout, &interval, &prefer_blanking,
  6505. &allow_exposures));
  6506. value1 = make_sint16 (timeout);
  6507. value2 = make_sint16 (interval);
  6508. value3 = check_yes_no_reverse(prefer_blanking);
  6509. value4 = check_yes_no_reverse(allow_exposures);
  6510. /* The manual says :YES/:NO but the implementation does :ON/:OFF! */
  6511. mv_count = 4;
  6512. }
  6513. DEFUN(XLIB:SET-SCREEN-SAVER, display timeout period blanking exposures)
  6514. {
  6515. int exposures = check_yes_no(popSTACK());
  6516. int blanking = check_yes_no(popSTACK());
  6517. int period = get_uint32 (popSTACK());
  6518. int timeout = eq(STACK_0,S(Kdefault)) ? (skipSTACK(1),-1)
  6519. : get_sint32(popSTACK());
  6520. Display *dpy = pop_display();
  6521. X_CALL(XSetScreenSaver (dpy, timeout, period, blanking, exposures));
  6522. VALUES1(NIL);
  6523. }
  6524. /* -----------------------------------------------------------------------
  6525. * Chapter 15 Extentsions
  6526. * ----------------------------------------------------------------------- */
  6527. /* 15.1 Extentions */
  6528. DEFUN(XLIB:LIST-EXTENSIONS, display &key RESULT-TYPE)
  6529. {
  6530. int n = 0;
  6531. char **extlist;
  6532. Display *dpy = get_display(STACK_1);
  6533. gcv_object_t *res_type = &STACK_0;
  6534. X_CALL(extlist = XListExtensions (dpy, &n));
  6535. if (extlist) {
  6536. int i;
  6537. for (i = 0; i < n; i++)
  6538. pushSTACK(asciz_to_string (extlist[i], GLO(misc_encoding)));
  6539. X_CALL(XFreeExtensionList (extlist));
  6540. }
  6541. VALUES1(coerce_result_type(n,res_type));
  6542. skipSTACK(2);
  6543. }
  6544. DEFUN(XLIB:QUERY-EXTENSION, display extension)
  6545. {
  6546. int opcode, event, error;
  6547. Display *dpy = get_display(STACK_1);
  6548. Status r;
  6549. with_stringable_0_tc (STACK_0, GLO(misc_encoding), name, {
  6550. X_CALL(r = XQueryExtension (dpy, name, &opcode, &event, &error));
  6551. });
  6552. if (r)
  6553. VALUES3(make_uint8(opcode),make_uint8(event),make_uint8(error));
  6554. else
  6555. VALUES1(NIL);
  6556. skipSTACK(2);
  6557. }
  6558. /* -----------------------------------------------------------------------
  6559. * Chapter 16 Errors
  6560. * ----------------------------------------------------------------------- */
  6561. /* These pages are missing :-(
  6562. Not any more but not rather informative */
  6563. #if 0
  6564. man XErrorEvent says:
  6565. :
  6566. :
  6567. The XErrorEvent structure contains:
  6568. typedef struct {
  6569. int type;
  6570. Display *display; /* Display the event was read from */
  6571. unsigned long serial; /* serial number of failed request */
  6572. unsigned char error_code;/* error code of failed request */
  6573. unsigned char request_code;/* Major op-code of failed request */
  6574. unsigned char minor_code;/* Minor op-code of failed request */
  6575. XID resourceid; /* resource id */
  6576. } XErrorEvent;
  6577. When you receive this event, the structure members are set as follows.
  6578. The serial member is the number of requests, starting from one, sent over
  6579. the network connection since it was opened. It is the number that was the
  6580. value of NextRequest immediately before the failing call was made. The
  6581. request_code member is a protocol request of the procedure that failed, as
  6582. defined in <X11/Xproto.h>.
  6583. #endif
  6584. DEFCHECKER(check_error_code, default=Success, \
  6585. XLIB::UNKNOWN-ERROR=Success XLIB::REQUEST-ERROR=BadRequest \
  6586. XLIB::VALUE-ERROR=BadValue XLIB::WINDOW-ERROR=BadWindow \
  6587. XLIB::PIXMAP-ERROR=BadPixmap XLIB::ATOM-ERROR=BadAtom \
  6588. XLIB::CURSOR-ERROR=BadCursor XLIB::FONT-ERROR=BadFont \
  6589. XLIB::MATCH-ERROR=BadMatch XLIB::DRAWABLE-ERROR=BadDrawable \
  6590. XLIB::ACCESS-ERROR=BadAccess XLIB::ALLOC-ERROR=BadAlloc \
  6591. XLIB::COLORMAP-ERROR=BadColor XLIB::GCONTEXT-ERROR=BadGC \
  6592. XLIB::ID-CHOICE-ERROR=BadIDChoice XLIB::NAME-ERROR=BadName \
  6593. XLIB::LENGTH-ERROR=BadLength \
  6594. XLIB::IMPLEMENTATION-ERROR=BadImplementation)
  6595. /* Error handler for errors occured on the display.
  6596. This error handler is installed on all open displays, we simply call up the
  6597. Lisp error handler here found in the ERROR-HANDLER slot in the display. */
  6598. int xlib_error_handler (Display *display, XErrorEvent *event)
  6599. {
  6600. int f = 13;
  6601. begin_callback ();
  6602. /* find the display. */
  6603. pushSTACK(find_display (display));
  6604. if (nullp (STACK_0))
  6605. NOTREACHED; /* hmm? */
  6606. /* find the error handler */
  6607. pushSTACK(TheStructure (STACK_0)->recdata[slot_DISPLAY_ERROR_HANDLER]);
  6608. if (nullp (STACK_0))
  6609. STACK_0 = `XLIB::DEFAULT-ERROR-HANDLER`;
  6610. else if (listp (STACK_0) || vectorp (STACK_0)) { /* sequencep */
  6611. pushSTACK(fixnum(event->error_code));
  6612. funcall (L(elt), 2);
  6613. pushSTACK(value1);
  6614. }
  6615. /* Build the argument list for the error handler: */
  6616. pushSTACK(STACK_1); /* display */
  6617. pushSTACK(check_error_code_reverse(event->error_code)); /* error code */
  6618. pushSTACK(`:ASYNCHRONOUS`); pushSTACK(T);
  6619. pushSTACK(`:CURRENT-SEQUENCE`); pushSTACK(UL_to_I(NextRequest(display)));
  6620. pushSTACK(`:SEQUENCE`); pushSTACK(UL_to_I(event->serial));
  6621. pushSTACK(`:MAJOR`); pushSTACK(make_uint8 (event->request_code));
  6622. pushSTACK(`:MINOR`); pushSTACK(make_uint8(event->minor_code));
  6623. switch (event->error_code) {
  6624. case BadColor: /* colormap-error */
  6625. case BadCursor: /* cursor-error */
  6626. case BadDrawable: /* drawable-error */
  6627. case BadFont: /* font-error */
  6628. case BadGC: /* gcontext-error */
  6629. case BadIDChoice: /* id-choice-error */
  6630. case BadPixmap: /* pixmap-error */
  6631. case BadWindow: /* window-error */
  6632. pushSTACK(`:RESOURCE-ID`);
  6633. pushSTACK(make_uint32 (event->resourceid));
  6634. f += 2;
  6635. break;
  6636. case BadAtom: /* atom-error */
  6637. pushSTACK(`:ATOM-ID`);
  6638. pushSTACK(make_uint32 (event->resourceid));
  6639. f += 2;
  6640. break;
  6641. case BadValue: /* value-error */
  6642. pushSTACK(S(Kvalue));
  6643. pushSTACK(make_uint32 (event->resourceid));
  6644. f += 2;
  6645. break;
  6646. }
  6647. /* Now call the handler: */
  6648. funcall (L(funcall), f);
  6649. skipSTACK(1); /* clean up */
  6650. end_callback ();
  6651. return 0; /* anything done with this? */
  6652. }
  6653. int xlib_io_error_handler (Display *display)
  6654. {
  6655. begin_callback ();
  6656. pushSTACK(find_display (display));
  6657. error(error_condition,"IO Error on display ~S.");
  6658. }
  6659. int xlib_after_function (Display *display)
  6660. {
  6661. begin_callback ();
  6662. pushSTACK(find_display (display));
  6663. funcall(TheStructure(STACK_0)->recdata[slot_DISPLAY_AFTER_FUNCTION],1);
  6664. end_callback ();
  6665. return 0;
  6666. }
  6667. /* ----------------------------------------------------------------------------
  6668. The Shape Extension
  6669. ---------------------------------------------------------------------------- */
  6670. ##if WANT_XSHAPE
  6671. /* NOTE: The functions in here are my own invents ... */
  6672. /* First three little enums (three? I can only see two!) */
  6673. DEFCHECKER(get_shape_kind,default=ShapeBounding, \
  6674. BOUNDING=ShapeBounding CLIP=ShapeClip)
  6675. DEFCHECKER(get_shape_operation,default=ShapeSet, SET=ShapeSet UNION=ShapeUnion \
  6676. INTERSECT=ShapeIntersect SUBTRACT=ShapeSubtract :INVERT=ShapeInvert)
  6677. static Bool ensure_shape_extension (Display *dpy, object dpy_obj, int error_p)
  6678. { /* Ensures that the SHAPE extension is initialized. If it is not available
  6679. and error_p is set raise an appropriate error message. */
  6680. int event_base, error_base, status;
  6681. X_CALL(status = XShapeQueryExtension(dpy,&event_base,&error_base));
  6682. if (status) {
  6683. /* Everything is ok just proceed */
  6684. return True;
  6685. } else {
  6686. if (error_p) { /* raise an error */
  6687. pushSTACK(dpy_obj); /* the display */
  6688. pushSTACK(TheSubr(subr_self)->name); /* function name */
  6689. error(error_condition,
  6690. "~S: Shape extension is not available on display ~S.");
  6691. } else
  6692. return False;
  6693. }
  6694. }
  6695. /* XLIB:SHAPE-VERSION display
  6696. => major ;
  6697. minor */
  6698. DEFUN(XLIB:SHAPE-VERSION, display)
  6699. {
  6700. Display *dpy = get_display(STACK_0);
  6701. int major_version, minor_version, status;
  6702. if (ensure_shape_extension (dpy, STACK_0, 0)) { /* Is it there? */
  6703. X_CALL(status = XShapeQueryVersion(dpy,&major_version,&minor_version));
  6704. if (status) {
  6705. VALUES2(make_uint16(major_version),make_uint16(minor_version));
  6706. skipSTACK(1);
  6707. return; /* all done */
  6708. }
  6709. }
  6710. /* Just return NIL here */
  6711. VALUES1(NIL);
  6712. skipSTACK(1);
  6713. }
  6714. /* XLIB:SHAPE-COMBINE destination source
  6715. &key (:kind :bounding) (:source-kind :bounding)
  6716. (:x-offset 0) (:y-offset 0)
  6717. (:operation :set) (:ordering :unsorted) */
  6718. DEFUN(XLIB:SHAPE-COMBINE, destination source \
  6719. &key KIND SOURCE-KIND X-OFFSET Y-OFFSET OPERATION ORDERING)
  6720. {
  6721. int ordering = get_ordering(popSTACK());
  6722. int op = get_shape_operation(popSTACK());
  6723. int y_off = get_sint16_0(popSTACK());
  6724. int x_off = get_sint16_0(popSTACK());
  6725. int src_kind = get_shape_kind(popSTACK());
  6726. int kind = get_shape_kind(popSTACK());
  6727. Display *dpy;
  6728. Window dest = get_window_and_display (STACK_1, &dpy);
  6729. (void)ensure_shape_extension (dpy, get_display_obj (STACK_1), 1);
  6730. /* Now we have to select on the second arg, which operation is
  6731. actually wanted:
  6732. pixmap -> XShapeCombineMask
  6733. window -> XShapeCombineShape
  6734. sequence of rectangles -> XShapeCombineRectangles
  6735. FIXME: Should we emit an error message if we get keywords, which are
  6736. not applicable? */
  6737. if (pixmap_p (STACK_0)) {
  6738. Pixmap src = get_pixmap (STACK_0);
  6739. X_CALL(XShapeCombineMask(dpy,dest,kind,x_off,y_off,src,op));
  6740. } else if (window_p (STACK_0)) {
  6741. Pixmap src = get_window (STACK_0);
  6742. X_CALL(XShapeCombineShape(dpy,dest,kind,x_off,y_off,src,src_kind,op));
  6743. } else if (listp (STACK_0) || vectorp (STACK_0)) {
  6744. int nrectangles = get_seq_len(&STACK_0,&`XLIB::RECT-SEQ`,4);
  6745. DYNAMIC_ARRAY (rectangles, XRectangle, nrectangles);
  6746. set_seq(&STACK_0,rectangles,coerce_into_rectangle);
  6747. X_CALL(XShapeCombineRectangles(dpy,dest,kind,x_off,y_off,
  6748. rectangles,nrectangles,op,ordering));
  6749. FREE_DYNAMIC_ARRAY (rectangles);
  6750. }
  6751. VALUES1(NIL);
  6752. skipSTACK(2); /* all done */
  6753. }
  6754. DEFUN(XLIB:SHAPE-OFFSET, destination kind x-offset y-offset)
  6755. {
  6756. Display *dpy;
  6757. Window dest = get_window_and_display (STACK_3, &dpy);
  6758. int kind = get_shape_kind (STACK_2);
  6759. int x_offset = get_sint16 (STACK_1);
  6760. int y_offset = get_sint16 (STACK_0);
  6761. (void)ensure_shape_extension (dpy, get_display_obj (STACK_3), 1);
  6762. X_CALL(XShapeOffsetShape(dpy,dest,kind,x_offset,y_offset));
  6763. VALUES1(NIL);
  6764. skipSTACK(4);
  6765. }
  6766. /* -> bounding-shaped-p
  6767. clip-shaped-p
  6768. x-bounding, y-bounding, x-clip, y-clip
  6769. w-bounding, h-bounding, w-clip, h-clip */
  6770. DEFUN(XLIB:SHAPE-EXTENTS, window)
  6771. {
  6772. Display *dpy;
  6773. Window window = get_window_and_display(popSTACK(),&dpy);
  6774. Bool bounding_shaped;
  6775. int x_bounding;
  6776. int y_bounding;
  6777. unsigned int w_bounding;
  6778. unsigned int h_bounding;
  6779. Bool clip_shaped;
  6780. int x_clip;
  6781. int y_clip;
  6782. unsigned int w_clip;
  6783. unsigned int h_clip;
  6784. Status status;
  6785. X_CALL(status = XShapeQueryExtents(dpy,window,&bounding_shaped,
  6786. &x_bounding,&y_bounding,
  6787. &w_bounding,&h_bounding,
  6788. &clip_shaped,&x_clip,&y_clip,
  6789. &w_clip,&h_clip));
  6790. if (status) VALUES0;
  6791. else {
  6792. value1 = bounding_shaped ? T : NIL;
  6793. value2 = clip_shaped ? T : NIL;
  6794. value3 = fixnum(x_bounding);
  6795. value4 = fixnum(y_bounding);
  6796. value5 = fixnum(x_clip);
  6797. value6 = fixnum(y_clip);
  6798. value7 = fixnum(w_bounding);
  6799. value8 = fixnum(h_bounding);
  6800. value9 = fixnum(w_clip);
  6801. mv_space[9] = fixnum(h_clip); /* 10th value */
  6802. mv_count = 10;
  6803. }
  6804. }
  6805. /* -> rectangles - (rep-seq (sint16 sint16 sint16 sint16))
  6806. ordering - (member :unsorted :y-sorted :yx-sorted :yx-banded) */
  6807. DEFUN(XLIB:SHAPE-RECTANGLES, window kind)
  6808. {
  6809. int kind = get_shape_kind(popSTACK());
  6810. Display *dpy;
  6811. Window window = get_window_and_display(popSTACK(),&dpy);
  6812. XRectangle *rect;
  6813. int count, ordering, i;
  6814. X_CALL(rect = XShapeGetRectangles(dpy,window,kind,&count,&ordering));
  6815. for (i=count; i; i--, rect++) {
  6816. pushSTACK(fixnum(rect->x));
  6817. pushSTACK(fixnum(rect->y));
  6818. pushSTACK(fixnum(rect->width));
  6819. pushSTACK(fixnum(rect->height));
  6820. }
  6821. value1 = listof(4*count); pushSTACK(value1);
  6822. value2 = get_ordering_reverse(ordering);
  6823. value1 = popSTACK();
  6824. mv_count = 2;
  6825. }
  6826. ##endif
  6827. /* -----------------------------------------------------------------------
  6828. * Not explicitly specified functions
  6829. * ----------------------------------------------------------------------- */
  6830. /* I think I will not actually support these functions, until there are needed
  6831. * by some application.
  6832. *
  6833. * Since they are not in the CLX Manual, they are actually undocumented
  6834. * functions of CLX, which should either way round not be used by CLX
  6835. * programs. (But it is strange, that the corresponding symbols are exported
  6836. * from the CLX package!)
  6837. *
  6838. * I may be wrong due to the WM functions, since these seems to be actually
  6839. * used by a couple of applications.
  6840. */
  6841. DEFUN(XLIB:ICONIFY-WINDOW, window screen)
  6842. {
  6843. Screen *scr = get_screen (popSTACK());
  6844. Display *dpy;
  6845. Window win = get_window_and_display (popSTACK(), &dpy);
  6846. X_CALL(XIconifyWindow(dpy,win,XScreenNumberOfScreen(scr)));
  6847. VALUES1(NIL);
  6848. }
  6849. DEFUN(XLIB:WITHDRAW-WINDOW, window screen)
  6850. {
  6851. Screen *scr = get_screen (popSTACK());
  6852. Display *dpy;
  6853. Window win = get_window_and_display (popSTACK(), &dpy);
  6854. X_CALL(XWithdrawWindow(dpy,win,XScreenNumberOfScreen(scr)));
  6855. VALUES1(NIL);
  6856. }
  6857. DEFUN(XLIB:DEFAULT-KEYSYM-INDEX, display keycode state)
  6858. { /* Returns a keysym-index for use with keycode->character */
  6859. int state = get_uint32(popSTACK());
  6860. KeyCode keycode = get_uint8(popSTACK());
  6861. Display *dpy = pop_display();
  6862. /* see comment in keycode2keysym: looks like the only index that
  6863. makes any sense is 0 */
  6864. VALUES1(Fixnum_0);
  6865. }
  6866. DEFCHECKER(check_mapping_request,default=, KEYBOARD=MappingKeyboard \
  6867. MODIFIER=MappingModifier POINTER=MappingPointer)
  6868. DEFUN(XLIB:MAPPING-NOTIFY, display request start count)
  6869. {
  6870. int count = get_sint32 (popSTACK());
  6871. int first_keycode = get_sint32 (popSTACK());
  6872. int request = check_mapping_request(popSTACK());
  6873. Display *dpy = pop_display();
  6874. XEvent ev;
  6875. ev.xmapping.type = MappingNotify;
  6876. /* No idea how to find out ev.xmapping.serial. */
  6877. ev.xmapping.serial = 0;
  6878. ev.xmapping.send_event = False;
  6879. ev.xmapping.display = dpy;
  6880. ev.xmapping.request = request;
  6881. ev.xmapping.first_keycode = first_keycode;
  6882. ev.xmapping.count = count;
  6883. X_CALL (XRefreshKeyboardMapping (&ev.xmapping));
  6884. VALUES0;
  6885. }
  6886. ##if 0
  6887. /* ??? */
  6888. DEFUN(XLIB:DESCRIBE-ERROR, arg1 arg2) {UNDEFINED;}
  6889. DEFUN(XLIB:DESCRIBE-EVENT, a1 a2 a3 &optional a4) {UNDEFINED;}
  6890. DEFUN(XLIB:DESCRIBE-REPLY, arg1 arg2) {UNDEFINED;}
  6891. DEFUN(XLIB:DESCRIBE-REQUEST, arg1 arg2) {UNDEFINED;}
  6892. DEFUN(XLIB:DESCRIBE-TRACE, a1 &optional a2) {UNDEFINED;}
  6893. DEFUN(XLIB:EVENT-HANDLER, arg1 arg2) {UNDEFINED;}
  6894. DEFUN(XLIB:GET-EXTERNAL-EVENT-CODE, arg1 arg2) {UNDEFINED;}
  6895. DEFUN(XLIB:MAKE-EVENT-HANDLERS, &key :TYPE :DEFAULT) {UNDEFINED;}
  6896. DEFUN(XLIB:DECODE-CORE-ERROR, a1 a2 &optional a3) {UNDEFINED;}
  6897. /* Digging with resources */
  6898. DEFUN(XLIB:ROOT-RESOURCES, arg &key DATABASE :KEY :TEST :TEST-NOT) {UNDEFINED;}
  6899. DEFUN(XLIB:RESOURCE-DATABASE-TIMESTAMP, arg) {UNDEFINED;}
  6900. DEFUN(XLIB:RESOURCE-KEY, arg) {UNDEFINED;}
  6901. /* These seem to handle keysym translations */
  6902. DEFUN(XLIB:KEYSYM-IN-MAP-P, arg1 arg2 arg3) {UNDEFINED;}
  6903. DEFUN(XLIB:KEYSYM-SET, a1) {UNDEFINED;}
  6904. DEFUN(XLIB:CHARACTER->KEYSYMS, a1 a2 &optional a3) {UNDEFINED;}
  6905. DEFUN(XLIB:CHARACTER-IN-MAP-P, arg1 arg2 arg3) {UNDEFINED;}
  6906. DEFUN(XLIB:DEFAULT-KEYSYM-TRANSLATE, arg1 arg2 arg3) {UNDEFINED;}
  6907. DEFUN(XLIB:DEFINE-KEYSYM, a1 a2 &key LOWERCASE TRANSLATE MODIFIERS MASK DISPLAY) {UNDEFINED;}
  6908. DEFUN(XLIB:DEFINE-KEYSYM-SET, arg1 arg2 arg3) {UNDEFINED;}
  6909. DEFUN(XLIB:UNDEFINE-KEYSYM, a1 a2 &key DISPLAY MODIFIERS &allow-other-keys){UNDEFINED;}
  6910. /* These seem to be some tracing feature */
  6911. DEFUN(XLIB:UNTRACE-DISPLAY, display) {UNDEFINED;}
  6912. DEFUN(XLIB:SUSPEND-DISPLAY-TRACING, display) {UNDEFINED;}
  6913. DEFUN(XLIB:RESUME-DISPLAY-TRACING, display) {UNDEFINED;}
  6914. DEFUN(XLIB:SHOW-TRACE, display &key :LENGTH SHOW-PROCESS) {UNDEFINED;}
  6915. DEFUN(XLIB:TRACE-DISPLAY, display) {UNDEFINED;}
  6916. /* Somewhat bogus ... */
  6917. DEFUN(XLIB:SET-WM-RESOURCES, a1 a2 &key WRITE :TEST :TEST-NOT) {UNDEFINED;}
  6918. /* [ MOVED TO LISP */
  6919. ##if 0
  6920. /* All these are defined in manager.lisp and are simply droped in ... */
  6921. DEFUN(XLIB:ICON-SIZES, display) {UNDEFINED;}
  6922. DEFUN(XLIB:SET-WM-CLASS, arg1 arg2 arg3) {UNDEFINED;}
  6923. DEFUN(XLIB:SET-WM-PROPERTIES, &rest args) {UNDEFINED;} /* LISPFUN (xlib_set_wm_properties, 1, 0, rest, key, 36, (:NAME :ICON-NAME :RESOURCE-NAME :RESOURCE-CLASS :COMMAND :CLIENT-MACHINE :HINTS :NORMAL-HINTS :ZOOM-HINTS :USER-SPECIFIED-POSITION-P :USER-SPECIFIED-SIZE-P :PROGRAM-SPECIFIED-POSITION-P :PROGRAM-SPECIFIED-SIZE-P :X :Y :WIDTH :HEIGHT :MIN-WIDTH :MIN-HEIGHT :MAX-WIDTH :MAX-HEIGHT :WIDTH-INC :HEIGHT-INC :MIN-ASPECT :MAX-ASPECT :BASE-WIDTH :BASE-HEIGHT :WIN-GRAVITY :INPUT :INITIAL-STATE :ICON-PIXMAP :ICON-WINDOW :ICON-X :ICON-Y :ICON-MASK :WINDOW-GROUP)) */
  6924. DEFUN(XLIB:MAKE-WM-HINTS, &key INPUT INITIAL-STATE ICON-PIXMAP ICON-WINDOW ICON-X ICON-Y ICON-MASK WINDOW-GROUP FLAGS) {UNDEFINED;}
  6925. DEFUN(XLIB:MAKE-WM-SIZE-HINTS, &key USER-SPECIFIED-POSITION-P USER-SPECIFIED-SIZE-P X Y WIDTH HEIGHT MIN-WIDTH MIN-HEIGHT MAX-WIDTH MAX-HEIGHT WIDTH-INC HEIGHT-INC MIN-ASPECT MAX-ASPECT BASE-WIDTH BASE-HEIGHT WIN-GRAVITY PROGRAM-SPECIFIED-POSITION-P PROGRAM-SPECIFIED-SIZE-P) {UNDEFINED;}
  6926. DEFUN(XLIB:GET-WM-CLASS, arg) {UNDEFINED;}
  6927. DEFUN(XLIB:TRANSIENT-FOR, arg) {UNDEFINED;}
  6928. DEFUN(XLIB:WM-CLIENT-MACHINE, arg) {UNDEFINED;}
  6929. DEFUN(XLIB:WM-COLORMAP-WINDOWS, arg) {UNDEFINED;}
  6930. DEFUN(XLIB:WM-COMMAND, arg) {UNDEFINED;}
  6931. DEFUN(XLIB:WM-HINTS, arg) {UNDEFINED;}
  6932. DEFUN(XLIB:WM-HINTS-FLAGS, arg) {UNDEFINED;}
  6933. DEFUN(XLIB:WM-HINTS-ICON-MASK, arg) {UNDEFINED;}
  6934. DEFUN(XLIB:WM-HINTS-ICON-PIXMAP, arg) {UNDEFINED;}
  6935. DEFUN(XLIB:WM-HINTS-ICON-WINDOW, arg) {UNDEFINED;}
  6936. DEFUN(XLIB:WM-HINTS-ICON-X, arg) {UNDEFINED;}
  6937. DEFUN(XLIB:WM-HINTS-ICON-Y, arg) {UNDEFINED;}
  6938. DEFUN(XLIB:WM-HINTS-INITIAL-STATE, arg) {UNDEFINED;}
  6939. DEFUN(XLIB:WM-HINTS-INPUT, arg) {UNDEFINED;}
  6940. DEFUN(XLIB:WM-HINTS-P, arg) {UNDEFINED;}
  6941. DEFUN(XLIB:WM-HINTS-WINDOW-GROUP, arg) {UNDEFINED;}
  6942. DEFUN(XLIB:WM-ICON-NAME, arg) {UNDEFINED;}
  6943. DEFUN(XLIB:WM-NORMAL-HINTS, arg) {UNDEFINED;}
  6944. DEFUN(XLIB:WM-PROTOCOLS, arg) {UNDEFINED;}
  6945. DEFUN(XLIB:WM-RESOURCES, arg1 arg2 &key :KEY :TEST :TEST-NOT) {UNDEFINED;}
  6946. DEFUN(XLIB:WM-SIZE-HINTS-BASE-HEIGHT, arg) {UNDEFINED;}
  6947. DEFUN(XLIB:WM-SIZE-HINTS-BASE-WIDTH, arg) {UNDEFINED;}
  6948. DEFUN(XLIB:WM-SIZE-HINTS-HEIGHT, arg) {UNDEFINED;}
  6949. DEFUN(XLIB:WM-SIZE-HINTS-HEIGHT-INC, arg) {UNDEFINED;}
  6950. DEFUN(XLIB:WM-SIZE-HINTS-MAX-ASPECT, arg) {UNDEFINED;}
  6951. DEFUN(XLIB:WM-SIZE-HINTS-MAX-HEIGHT, arg) {UNDEFINED;}
  6952. DEFUN(XLIB:WM-SIZE-HINTS-MAX-WIDTH, arg) {UNDEFINED;}
  6953. DEFUN(XLIB:WM-SIZE-HINTS-MIN-ASPECT, arg) {UNDEFINED;}
  6954. DEFUN(XLIB:WM-SIZE-HINTS-MIN-HEIGHT, arg) {UNDEFINED;}
  6955. DEFUN(XLIB:WM-SIZE-HINTS-MIN-WIDTH, arg) {UNDEFINED;}
  6956. DEFUN(XLIB:WM-SIZE-HINTS-P, arg) {UNDEFINED;}
  6957. DEFUN(XLIB:WM-SIZE-HINTS-USER-SPECIFIED-POSITION-P, arg) {UNDEFINED;}
  6958. DEFUN(XLIB:WM-SIZE-HINTS-USER-SPECIFIED-SIZE-P, arg) {UNDEFINED;}
  6959. DEFUN(XLIB:WM-SIZE-HINTS-WIDTH, arg) {UNDEFINED;}
  6960. DEFUN(XLIB:WM-SIZE-HINTS-WIDTH-INC, arg) {UNDEFINED;}
  6961. DEFUN(XLIB:WM-SIZE-HINTS-WIN-GRAVITY, arg) {UNDEFINED;}
  6962. DEFUN(XLIB:WM-SIZE-HINTS-X, arg) {UNDEFINED;}
  6963. DEFUN(XLIB:WM-SIZE-HINTS-Y, arg) {UNDEFINED;}
  6964. DEFUN(XLIB:RGB-COLORMAPS, arg1 arg2) {UNDEFINED;}
  6965. DEFUN(XLIB:WM-NAME, arg) {UNDEFINED;}
  6966. /* ... and properly some more ... */
  6967. /* These are simply defstruct generated functions -- moved to Lisp */
  6968. DEFUN(XLIB:VISUAL-INFO-BITS-PER-RGB, arg)
  6969. DEFUN(XLIB:VISUAL-INFO-BLUE-MASK, arg)
  6970. DEFUN(XLIB:VISUAL-INFO-CLASS, arg)
  6971. DEFUN(XLIB:VISUAL-INFO-COLORMAP-ENTRIES, arg)
  6972. DEFUN(XLIB:VISUAL-INFO-DISPLAY, arg)
  6973. DEFUN(XLIB:VISUAL-INFO-GREEN-MASK, arg)
  6974. DEFUN(XLIB:VISUAL-INFO-ID, arg)
  6975. DEFUN(XLIB:VISUAL-INFO-P, arg)
  6976. DEFUN(XLIB:VISUAL-INFO-PLIST, arg)
  6977. DEFUN(XLIB:VISUAL-INFO-RED-MASK, arg)
  6978. /* These here are defined in Lisp: */
  6979. DEFUN(XLIB:CUT-BUFFER, a1 &key BUFFER :TYPE RESULT-TYPE TRANSFORM :START :END) {UNDEFINED;}
  6980. DEFUN(XLIB:ROTATE-CUT-BUFFERS, a1 &optional a2 a3) {UNDEFINED;}
  6981. DEFUN(XLIB:BITMAP-IMAGE, &optional a1 &rest args)
  6982. ##endif
  6983. /* ] */
  6984. /* [ CONSIDERED OBSOLETE */
  6985. ##if 0
  6986. DEFUN(XLIB:WM-ZOOM-HINTS, arg) {UNDEFINED;}
  6987. DEFUN(XLIB:SET-STANDARD-PROPERTIES, a1 &rest rest) {UNDEFINED;}
  6988. DEFUN(XLIB:GET-STANDARD-COLORMAP, arg1 arg2) {UNDEFINED;}
  6989. DEFUN(XLIB:SET-STANDARD-COLORMAP, a1 a2 a3 a4 a5 a6) {UNDEFINED;}
  6990. ##endif
  6991. /* ] */
  6992. ##endif
  6993. /* Puh! That is really lots of typing ...
  6994. ... But what wouldn't I do to get (hopefully) GARNET working? */
  6995. /* But we are not finished yet, we have yet to finish the libX11 :-) */
  6996. /* -----------------------------------------------------------------------
  6997. * Fixups of libX
  6998. * ----------------------------------------------------------------------- */
  6999. static Visual *XVisualIDToVisual (Display *dpy, VisualID vid)
  7000. { /*PORTABLE-P?*/
  7001. XVisualInfo templeight, *r;
  7002. Visual *result;
  7003. int n;
  7004. templeight.visualid = vid;
  7005. X_CALL(r = XGetVisualInfo (dpy, VisualIDMask, &templeight, &n));
  7006. if (n == 1) {
  7007. result = r->visual;
  7008. X_CALL(XFree (r));
  7009. return result;
  7010. } else {
  7011. X_CALL(if (r) XFree (r));
  7012. /* Maybe we emerge a x-bad-SONSTWAS condition here, since the 0 value
  7013. _is_ meaningful to the libX11; It is CopyFromParent. */
  7014. return 0;
  7015. }
  7016. }
  7017. static int XScreenNo (Display *dpy, Screen *screen)
  7018. { /* Find the screen number of an screen */
  7019. int i, cnt = ScreenCount(dpy);
  7020. for (i = 0; i < cnt; i++)
  7021. if (ScreenOfDisplay(dpy,i) == screen)
  7022. return i;
  7023. return -1; /* should really raise an exception... */
  7024. }
  7025. /* So, now we could expose this to the compiler. */
  7026. /* Now the somewhat standard tail of my files, which wander out of my
  7027. small loved five-years old box.
  7028. [Cheers! Long live the ISA bus :-]
  7029. Sorry, if you do not have a wide display or a small font and eyes as
  7030. good as mine.
  7031. Most lines are written between two o`clock and five o`clock in the morning.
  7032. */
  7033. #define SILLY 1
  7034. #if SILLY
  7035. int this_is_a_test_for_the_linker_and_the_debugger_and_the_nm_utility__lets_have_a_look_if_they_could_cope_with_this_indeed_very_long_identifer__still_reading_this__if_not_in_the_editor___CONGRATULATIONS;
  7036. #endif
  7037. /* -----------------------------------------------------------------------
  7038. * Xpm Interface
  7039. * -----------------------------------------------------------------------
  7040. * Need this for my small sokoban port ... */
  7041. ##if WANT_XPM
  7042. #include <X11/xpm.h>
  7043. DEFUN(XPM:READ-FILE-TO-PIXMAP, drawable filename &key SHAPE-MASK-P PIXMAP-P)
  7044. { /* -> pixmap, shape */
  7045. Display *dpy;
  7046. Drawable da = get_drawable_and_display (STACK_3, &dpy);
  7047. int shape_mask_p = !missingp(STACK_1); /* default NIL */
  7048. int pixmap_p = boundp(STACK_0) ? get_bool(STACK_0) : 1; /* default T */
  7049. int r;
  7050. Pixmap pixmap = 0;
  7051. Pixmap shape_mask = 0;
  7052. pushSTACK(get_display_obj (STACK_3));
  7053. STACK_3 = physical_namestring(STACK_3);
  7054. with_string_0 (STACK_3, GLO(pathname_encoding), filename, {
  7055. X_CALL(r = XpmReadFileToPixmap (dpy, da, filename,
  7056. pixmap_p?&pixmap:NULL,
  7057. shape_mask_p?&shape_mask:NULL, NULL));
  7058. });
  7059. if (r != XpmSuccess) { /* http://root.cern.ch/lxr/source/x11/inc/Xpm.h */
  7060. switch (r) {
  7061. case XpmColorError: pushSTACK(`"color error"`); break;
  7062. case XpmOpenFailed: pushSTACK(`"open failed"`); break;
  7063. case XpmFileInvalid: pushSTACK(`"file invalid"`); break;
  7064. case XpmNoMemory: pushSTACK(`"no memory"`); break;
  7065. case XpmColorFailed: pushSTACK(`"color failed"`); break;
  7066. default: NOTREACHED;
  7067. }
  7068. pushSTACK(STACK_4); /* pathname */
  7069. pushSTACK(TheSubr(subr_self)->name);
  7070. error(error_condition,"~S: Cannot read ~S: ~S");
  7071. }
  7072. if (pixmap) pushSTACK(make_pixmap (STACK_0, pixmap));
  7073. else pushSTACK(NIL);
  7074. if (shape_mask) pushSTACK(make_pixmap (STACK_1, shape_mask));
  7075. else pushSTACK(NIL);
  7076. VALUES2(STACK_1,STACK_0);
  7077. skipSTACK(7);
  7078. }
  7079. ##endif
  7080. void module__clx__init_function_2 (module_t *module);
  7081. void module__clx__init_function_2 (module_t *module)
  7082. { /* setze doch `XLIB::*DISPLAYS*` auf NIL ! */
  7083. # if 0
  7084. uintC i;
  7085. for (i = 0 ; i < module__clx__object_tab_size; i++) {
  7086. dprintf (("\n;; otab[%d] = '%s' -->",i,
  7087. module__clx__object_tab_initdata[i]));
  7088. pushSTACK(((gcv_object_t *)( & module__clx__object_tab))[i]);
  7089. funcall (L(princ),1);
  7090. }
  7091. # endif
  7092. # if !defined(RELY_ON_WRITING_TO_SUBPROCESS)
  7093. disable_sigpipe();
  7094. # endif
  7095. X_CALL(XrmInitialize()); /* FIXME: XrmParseCommand */
  7096. }
  7097. #include <X11/Xlibint.h>
  7098. static XID display_resource_base (Display *dpy)
  7099. { return ((struct _XDisplay*)dpy)->resource_base; }
  7100. static XID display_resource_mask (Display *dpy)
  7101. { return ((struct _XDisplay*)dpy)->resource_mask; }