property.scm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. ;; Copyright (c) 2001-2003 by David Frese
  2. (define-record-type property :property
  3. (make-property type format data)
  4. property?
  5. (type property:type set-property:type!) ;; an atom
  6. (format property:format set-property:format!) ;; a property-format
  7. ;; a string if format is char, or an integer list otherwise
  8. (data property:data set-property:data!))
  9. (define-exported-binding "scx-property" :property)
  10. ;; *** create or return atom names ***********************************
  11. (import-xlib-function intern-atom (display atom-name only-if-exists?)
  12. "scx_Intern_Atom")
  13. ;; returns a list of atoms or #f
  14. (import-xlib-function intern-atoms (display names only-if-exists?)
  15. "scx_Intern_Atoms")
  16. (import-xlib-function get-atom-name (display atom)
  17. "scx_Get_Atom_Name")
  18. (define (get-atom-names display atoms)
  19. (map (lambda (atom) (get-atom-name display atom)) atoms))
  20. ;; *** obtain and change window properties****************************
  21. (import-xlib-function list-properties (display window)
  22. "scx_List_Properties")
  23. ;; Note: This does not change the list itself.
  24. (import-xlib-function rotate-window-properties
  25. (display window properties npositions)
  26. "scx_Rotate_Window_Properties")
  27. (import-xlib-function delete-property (display window property)
  28. "scx_Delete_Property")
  29. ;; returns a pair (bytes-after . property) or #f
  30. (import-xlib-function get-window-property
  31. (display window atom offset length delete? req-type)
  32. "scx_Get_Window_Property")
  33. (define-enumerated-type change-property-mode :change-property-mode
  34. change-property-mode? change-property-modes change-property-mode-name
  35. change-property-mode-index
  36. (replace prepend append))
  37. (define-exported-binding "scx-change-property-mode" :change-property-mode)
  38. (import-xlib-function change-property
  39. (display window atom mode property)
  40. "scx_Change_Property")
  41. (define (get-full-window-property display window atom delete? req-type)
  42. (let ((res1 (get-window-property display window atom 0 0 #f req-type)))
  43. (and res1
  44. (let ((res2 (get-window-property display window atom 0
  45. (car res1) #f req-type)))
  46. (and res2 (cdr res2))))))
  47. ;; separates a string at 0 characters and returns the bits in a list.
  48. (define (string->string-list s)
  49. (let ((i (string-index s (ascii->char 0))))
  50. (if i
  51. (cons (substring s 0 i)
  52. (string->string-list (substring s (+ i 1)
  53. (string-length s))))
  54. (list s))))
  55. (define (string-list->string strings)
  56. (if (null? strings)
  57. ""
  58. (fold (lambda (res s)
  59. (string-append res (make-string 1 (ascii->char 0))
  60. s))
  61. (car strings)
  62. (cdr strings))))
  63. ;; *** manipulate window selection ***********************************
  64. (import-xlib-function set-selection-owner (display selection owner time)
  65. "scx_Set_Selection_Owner")
  66. (import-xlib-function get-selection-owner (display selection)
  67. "scx_Get_Selection_Owner")
  68. (import-xlib-function convert-selection
  69. (display selection target property requestor time)
  70. "scx_Convert_Selection")