window.scm 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. ;; Copyright (c) 2001-2003 by Norbert Freudemann, David Frese
  2. (define-enumerated-type bit-gravity :bit-gravity
  3. bit-gravity? bit-gravities bit-gravity-name bit-gravity-index
  4. (forget north-west north north-east west center east south-west
  5. south south-east static))
  6. (define-exported-binding "scx-bit-gravity" :bit-gravity)
  7. (define-exported-binding "scx-bit-gravities" bit-gravities)
  8. (define-enumerated-type win-gravity :win-gravity
  9. win-gravity? win-gravities win-gravity-name win-gravity-index
  10. (unmap north-west north north-east west center east south-west
  11. south south-east static))
  12. (define-exported-binding "scx-win-gravity" :win-gravity)
  13. (define-exported-binding "scx-win-gravities" win-gravities)
  14. (define-enumerated-type backing-store :backing-store
  15. backing-store? backing-stores backing-store-name backing-store-index
  16. (not-useful when-mapped always))
  17. (define-exported-binding "scx-backing-store" :backing-store)
  18. (define-exported-binding "scx-backing-stores" backing-stores)
  19. (define-enumerated-type set-window-attribute :set-window-attribute
  20. set-window-attribute?
  21. set-window-attributes
  22. set-window-attribute-name
  23. set-window-attribute-index
  24. ;; don't change the order of the attributes! background-pixmap can
  25. ;; be a pixmap including (special-pixmap:none dpy) and
  26. ;; (special-pixmap:parent-relative dpy) border-pixmap can be a
  27. ;; pixmap or (special-pixmap:copy-from-parent dpy)
  28. (background-pixmap background-pixel border-pixmap border-pixel
  29. bit-gravity gravity backing-store backing-planes backing-pixel
  30. override-redirect save-under event-mask do-not-propagate-mask colormap
  31. cursor))
  32. (define-exported-binding "scx-set-window-attribute" :set-window-attribute)
  33. (define-syntax make-set-window-attribute-alist
  34. (syntax-rules
  35. ()
  36. ((make-set-window-attribute-alist (attr arg) rest ...)
  37. (cons (cons (set-window-attribute attr) arg)
  38. (make-set-window-attribute-alist rest ...)))
  39. ((make-set-window-attribute-alist)
  40. '())))
  41. ;; *** create windows ************************************************
  42. (import-xlib-function create-window
  43. (display parent x y width height border_width depth class visual attribs)
  44. "scx_Create_Window")
  45. (import-xlib-function create-simple-window
  46. (display parent x y width height border_width border background)
  47. "scx_Create_Simple_Window")
  48. ;; *** change window attributes **************************************
  49. (import-xlib-function change-window-attributes (display window attribs)
  50. "scx_Change_Window_Attributes")
  51. (define (make-win-attr-setter attribute)
  52. (lambda (display window value)
  53. (change-window-attributes display window (list (cons attribute value)))))
  54. (define set-window-background-pixmap!
  55. (make-win-attr-setter (set-window-attribute background-pixmap)))
  56. (define set-window-background-pixel!
  57. (make-win-attr-setter (set-window-attribute background-pixel)))
  58. (define set-window-border-pixmap!
  59. (make-win-attr-setter (set-window-attribute border-pixmap)))
  60. (define set-window-border-pixel!
  61. (make-win-attr-setter (set-window-attribute border-pixel)))
  62. (define set-window-bit-gravity!
  63. (make-win-attr-setter (set-window-attribute bit-gravity)))
  64. (define set-window-gravity!
  65. (make-win-attr-setter (set-window-attribute gravity)))
  66. (define set-window-backing-store!
  67. (make-win-attr-setter (set-window-attribute backing-store)))
  68. (define set-window-backing-planes!
  69. (make-win-attr-setter (set-window-attribute backing-planes)))
  70. (define set-window-backing-pixel!
  71. (make-win-attr-setter (set-window-attribute backing-pixel)))
  72. (define set-window-save-under!
  73. (make-win-attr-setter (set-window-attribute save-under)))
  74. (define set-window-event-mask!
  75. (make-win-attr-setter (set-window-attribute event-mask)))
  76. (define set-window-do-not-propagate-mask!
  77. (make-win-attr-setter (set-window-attribute do-not-propagate-mask)))
  78. (define set-window-override-redirect!
  79. (make-win-attr-setter (set-window-attribute override-redirect)))
  80. (define set-window-colormap!
  81. (make-win-attr-setter (set-window-attribute colormap)))
  82. (define set-window-cursor!
  83. (make-win-attr-setter (set-window-attribute cursor)))
  84. ;; *** configure windows *********************************************
  85. (define-enumerated-type stack-mode :stack-mode
  86. stack-mode? stack-modes stack-mode-name stack-mode-index
  87. (above below top-if buttom-if opposite))
  88. (define-exported-binding "scx-stack-mode" :stack-mode)
  89. (define-exported-binding "scx-stack-modes" stack-modes)
  90. ;; an enumerated type for XWindowChange. Used in configure-window
  91. (define-enumerated-type window-change :window-change
  92. window-change? window-changes window-change-name window-change-index
  93. (x y width height border-width sibling stack-mode))
  94. (define-exported-binding "scx-window-change" :window-change)
  95. (define-exported-binding "scx-window-changes" window-changes)
  96. (define-syntax make-window-change-alist
  97. (syntax-rules
  98. ()
  99. ((make-window-change-alist (attr arg) rest ...)
  100. (cons (cons (window-change attr) arg)
  101. (make-window-change-alist rest ...)))
  102. ((make-window-change-alist)
  103. '())))
  104. (import-xlib-function configure-window (display window changes)
  105. "scx_Configure_Window")
  106. (define (make-win-configurer change)
  107. (lambda (display window value)
  108. (configure-window display window (list (cons change value)))))
  109. (define set-window-x! (make-win-configurer (window-change x)))
  110. (define set-window-y! (make-win-configurer (window-change y)))
  111. (define set-window-width! (make-win-configurer (window-change width)))
  112. (define set-window-height! (make-win-configurer (window-change height)))
  113. (define set-window-border-width!
  114. (make-win-configurer (window-change border-width)))
  115. (define set-window-sibling! (make-win-configurer (window-change sibling)))
  116. (define set-window-stack-mode!
  117. (make-win-configurer (window-change stack-mode)))
  118. (define (move-window display window x y)
  119. (configure-window display window
  120. (make-window-change-alist (x x) (y y))))
  121. (define (resize-window display window width height)
  122. (configure-window display window
  123. (make-window-change-alist (width width)
  124. (height height))))
  125. (define (move-resize-window display window x y width height)
  126. (configure-window display window
  127. (make-window-change-alist (x x) (y y)
  128. (width width)
  129. (height height))))
  130. ;; *** get current window attribute or geometry **********************
  131. (define-enumerated-type map-state :map-state
  132. map-state? map-states map-state-name map-state-index
  133. (is-unmapped is-unviewable is-viewable))
  134. (define-exported-binding "scx-map-state" :map-state)
  135. (define-exported-binding "scx-map-states" map-states)
  136. (define-enumerated-type window-class :window-class
  137. window-class? window-classes window-class-name window-class-index
  138. (copy-from-parent input-output input-only))
  139. (define-exported-binding "scx-window-class" :window-class)
  140. (define-exported-binding "scx-window-classes" window-classes)
  141. (define-record-type window-attributes :window-attributes
  142. (make-window-attributes x y width height border-width depth visual root
  143. class bit-gravity gravity backing-store
  144. backing-planes backing-pixel save-under
  145. colormap map-installed map-state all-event-masks
  146. your-event-mask do-not-propagate-mask
  147. override-redirect screen)
  148. window-attributes?
  149. (x window-attribute:x)
  150. (y window-attribute:y)
  151. (width window-attribute:width)
  152. (height window-attribute:height)
  153. (border-width window-attribute:border-width)
  154. (depth window-attribute:depth)
  155. (visual window-attribute:visual)
  156. (root window-attribute:root)
  157. (class window-attribute:class)
  158. (bit-gravity window-attribute:bit-gravity)
  159. (gravity window-attribute:gravity)
  160. (backing-store window-attribute:backing-store)
  161. (backing-planes window-attribute:backing-planes)
  162. (backing-pixel window-attribute:backing-pixel)
  163. (save-under window-attribute:save-under)
  164. (colormap window-attribute:colormap)
  165. (map-installed window-attribute:map-installed)
  166. (map-state window-attribute:map-state)
  167. (all-event-masks window-attribute:all-event-masks)
  168. (your-event-mask window-attribute:your-event-mask)
  169. (do-not-propagate-mask window-attribute:do-not-propagate-mask)
  170. (override-redirect window-attribute:override-redirect)
  171. (screen window-attribute:screen))
  172. (define-exported-binding "scx-window-attributes" :window-attributes)
  173. (import-xlib-function get-window-attributes (display window)
  174. "scx_Get_Window_Attributes")
  175. ;; returns a vector #(root-window x y width height border-width depth) or #f
  176. (import-xlib-function get-geometry (display drawable)
  177. "scx_Get_Geometry")
  178. (define (make-geometry-getter i)
  179. (lambda (display window)
  180. (let ((a (get-geometry display window)))
  181. (and a (vector-ref a i)))))
  182. ;;(define window-root (make-geometry-getter 0))
  183. (define window-x (make-geometry-getter 1))
  184. (define window-y (make-geometry-getter 2))
  185. (define window-width (make-geometry-getter 3))
  186. (define window-height (make-geometry-getter 4))
  187. (define window-border-width (make-geometry-getter 5))
  188. (define window-depth (make-geometry-getter 6))
  189. ;; *** map windows ***************************************************
  190. (import-xlib-function map-window (display window)
  191. "scx_Map_Window")
  192. (import-xlib-function map-raised (display window)
  193. "scx_Map_Raised")
  194. (import-xlib-function map-subwindows (display window)
  195. "scx_Map_Subwindows")
  196. ;; *** unmap windows *************************************************
  197. (import-xlib-function unmap-window (display window)
  198. "scx_Unmap_Window")
  199. (import-xlib-function unmap-subwindows (display window)
  200. "scx_Unmap_Subwindows")
  201. ;; *** destroy windows ***********************************************
  202. (import-xlib-function destroy-window (display window)
  203. "scx_Destroy_Window")
  204. (import-xlib-function destroy-subwindows (display window)
  205. "scx_Destroy_Subwindows")
  206. ;; *** change window stacking order **********************************
  207. (import-xlib-function raise-window (display window)
  208. "scx_Raise_Window")
  209. (import-xlib-function lower-window (display window)
  210. "scx_Lower_Window")
  211. (define-enumerated-type circulate-direction :circulate-direction
  212. circulate-direction? circulate-directions circulate-direction-name
  213. circulate-direction-index
  214. (raise-lowest lower-highest))
  215. (define-exported-binding "scx-circulate-direction" :circulate-direction)
  216. (import-xlib-function circulate-subwindows (display window direction)
  217. "scx_Circulate_Subwindows")
  218. (define (circulate-subwindows-up display window)
  219. (circulate-subwindows display window (circulate-direction raise-lowest)))
  220. (define (circulate-subwindows-down display window)
  221. (circulate-subwindows display window (circulate-direction lower-highest)))
  222. (import-xlib-function restack-windows (display windows)
  223. "scx_Restack_Windows")
  224. ;; *** clear area or window ******************************************
  225. (import-xlib-function clear-area
  226. (display window x y width height exposures?)
  227. "scx_Clear_Area")
  228. (import-xlib-function clear-window (display window)
  229. "scx_Clear_Window")
  230. ;; *** query window tree information *********************************
  231. ;; returns a list (root-window parent-window children) or #f
  232. (import-xlib-function query-tree (display window)
  233. "scx_Query_Tree")
  234. (define (window-root display window)
  235. (let ((t (query-tree display window)))
  236. (and t (car t))))
  237. (define (window-parent display window)
  238. (let ((t (query-tree display window)))
  239. (and t (cadr t))))
  240. (define (window-children display window)
  241. (let ((t (query-tree display window)))
  242. (and t (caddr t))))
  243. ;; *** translate window coordinates **********************************
  244. ;; returns a list (dest-x dest-y child) or #f
  245. (import-xlib-function translate-coordinates
  246. (display src-w dest-w src-x src-y)
  247. "scx_Translate_Coordinates")
  248. ;; *** get pointer coordinates ***************************************
  249. (import-xlib-function %query-pointer (display window)
  250. "scx_Query_Pointer")
  251. (define (query-pointer-root display)
  252. (let ((q (%query-pointer display (default-root-window display))))
  253. (and q (list (vector-ref q 0) ;; the root-window that the pointer is on
  254. (vector-ref q 2) ;; x and
  255. (vector-ref q 3))))) ;; y coordinates on that root-window
  256. (define (query-pointer-state display)
  257. (let ((q (%query-pointer display (default-root-window display))))
  258. (and q (vector-ref q 6))))
  259. (define (query-pointer display window)
  260. (let ((q (%query-pointer display window)))
  261. (and q (vector-ref q 7)
  262. (list (vector-ref q 1) ;; child of window that contains
  263. ;; the pointer or None
  264. (vector-ref q 4) ;; x and y coordinates
  265. (vector-ref q 5))))) ;; relative to window
  266. ;; *** convenience functions *****************************************
  267. (define (window-exists? dpy window)
  268. (display-sync dpy #f)
  269. (let ((before (use-x-error-warnings! dpy #t)))
  270. (let ((result
  271. (call-with-current-continuation
  272. (lambda (return)
  273. (with-handler (lambda (condition punt)
  274. (return #f))
  275. (lambda ()
  276. (query-tree dpy window)
  277. (display-sync dpy #f)
  278. #t))))))
  279. (if (not before) (use-x-error-warnings! dpy #f))
  280. result)))