utility.scm 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. ; The C-procedures for (xlib-release-X-or-later?) are in the
  2. ; file init.c
  3. (import-lambda-definition-2 xlib-release-4-or-later? ()
  4. "scx_Xlib_Release_4_Or_Later")
  5. (import-lambda-definition-2 xlib-release-5-or-later? ()
  6. "scx_Xlib_Release_5_Or_Later")
  7. (import-lambda-definition-2 xlib-release-6-or-later? ()
  8. "scx_Xlib_Release_6_Or_Later")
  9. ;; get-default returns the user default values of a specified program
  10. ;; from the X-resource database. program and option should be
  11. ;; strings. On success a string is returned, otherwise #f. See
  12. ;; XGetDefault.
  13. (import-xlib-function get-default (display program option)
  14. "scx_Get_Default")
  15. ;; resource-manager-string returns the RESOURCE_MANAGER property from
  16. ;; the server's root window of screen 0, or #f if no such property
  17. ;; exists. See XResourceManagerString.
  18. (import-xlib-function resource-manager-string (display)
  19. "scx_Resource_Manager_String")
  20. ;; parse-geometry parses a string for the standard X format for x, y,
  21. ;; width and height arguments. Definition:
  22. ;; [=][<width>{xX}<height>][{+-}<xoffset>{+-}<yoffset>]. The return
  23. ;; value is a list (x-negative? y-negative? x y width height), where
  24. ;; x, y, width, height can be #f if they were not specified in the
  25. ;; string. See XParseGeometry.
  26. (define (parse-geometry string)
  27. (vector->list (%parse-geometry string)))
  28. (import-lambda-definition-2 %parse-geometry (string)
  29. "scx_Parse_Geometry")
  30. ;; these are some functions for clipboard handling.
  31. (define store-buffer #f)
  32. (define store-bytes #f)
  33. (define fetch-buffer #f)
  34. (define fetch-bytes #f)
  35. (define rotate-buffers #f)
  36. (let ((xa-string 31) ;; from Xatom.h
  37. (xa-cut-buffers '(9 10 11 12 13 14 15 16)))
  38. ;(9...16 are XA_CUT_BUFFER0...XA_CUT_BUFFER7)
  39. (set! store-buffer
  40. (lambda (dpy bytes buf)
  41. (if (<= 0 buf 7)
  42. (change-property dpy (default-root-window dpy)
  43. (list-ref xa-cut-buffers buf)
  44. (change-property-mode replace)
  45. (make-property xa-string
  46. 8
  47. bytes)))))
  48. (set! store-bytes (lambda (dpy bytes)
  49. (store-buffer dpy bytes 0)))
  50. (set! fetch-buffer
  51. (lambda (dpy buf)
  52. (if (<= 0 buf 7)
  53. (let ((p (get-full-window-property
  54. dpy (default-root-window dpy)
  55. (list-ref xa-cut-buffers buf)
  56. #f xa-string)))
  57. (if (and p (eq? (property:type p) xa-string)
  58. (string? (property:data p)))
  59. (property:data p)
  60. "")))))
  61. (set! fetch-bytes (lambda (dpy)
  62. (fetch-buffer dpy 0)))
  63. (set! rotate-buffers (lambda (dpy delta)
  64. (rotate-window-properties dpy
  65. (default-root-window dpy)
  66. xa-cut-buffers delta))))