added free-options
fixed wm-hints stuff added uppercase/lowercase to keys option
This commit is contained in:
		
							parent
							
								
									da76ea4b48
								
							
						
					
					
						commit
						1d426ce2dd
					
				| 
						 | 
					@ -68,9 +68,22 @@
 | 
				
			||||||
	      option-alist type-alist)
 | 
						      option-alist type-alist)
 | 
				
			||||||
    (make-options dpy colormap option-alist value-alist type-alist)))
 | 
					    (make-options dpy colormap option-alist value-alist type-alist)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define (free-options options)
 | 
					;; if the colormap gets freed, then the colors don't have to
 | 
				
			||||||
  ;; TODO
 | 
					(define (free-options options free-colors?)
 | 
				
			||||||
  #t)
 | 
					  (for-each (lambda (n.v)
 | 
				
			||||||
 | 
						      (let* ((name (car n.v))
 | 
				
			||||||
 | 
							     (value (cdr n.v))
 | 
				
			||||||
 | 
							     (type (assq/false name (options:type-alist options))))
 | 
				
			||||||
 | 
							(cond
 | 
				
			||||||
 | 
							 ((eq? (option-type font) type)
 | 
				
			||||||
 | 
							  (unload-font (options:dpy options) value))
 | 
				
			||||||
 | 
							 ((eq? (option-type color) type)
 | 
				
			||||||
 | 
							  (free-colors (options:dpy options) (options:colormap options)
 | 
				
			||||||
 | 
								       (list value) 0))
 | 
				
			||||||
 | 
							 ((eq? (option-type colors) type)
 | 
				
			||||||
 | 
							  (free-colors (options:dpy options) (options:colormap options)
 | 
				
			||||||
 | 
								       value 0)))))
 | 
				
			||||||
 | 
						    (options:value-alist options)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define (get-option-value options name)
 | 
					(define (get-option-value options name)
 | 
				
			||||||
  (let ((p (assq name (options:value-alist options))))
 | 
					  (let ((p (assq name (options:value-alist options))))
 | 
				
			||||||
| 
						 | 
					@ -120,10 +133,13 @@
 | 
				
			||||||
    (define id (list (list (quote name) (option-type type) default)
 | 
					    (define id (list (list (quote name) (option-type type) default)
 | 
				
			||||||
		     ...)))))
 | 
							     ...)))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(define (options-spec-union spec1 spec2)
 | 
				
			||||||
 | 
					  (append spec1 spec2))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define (allocate-option dpy colormap name type def)
 | 
					(define (allocate-option dpy colormap name type def)
 | 
				
			||||||
  (let ((check (lambda (value pred)
 | 
					  (let ((check (lambda (value pred)
 | 
				
			||||||
		 (if (not (pred value))
 | 
							 (if (not (pred value))
 | 
				
			||||||
		     (error "wrong type argument" value) ;; TODO: other??
 | 
							     (error "wrong type argument" value) ;; TODO: other error??
 | 
				
			||||||
		     value))))
 | 
							     value))))
 | 
				
			||||||
    (cond
 | 
					    (cond
 | 
				
			||||||
     ((eq? type (option-type int)) (check def integer?))
 | 
					     ((eq? type (option-type int)) (check def integer?))
 | 
				
			||||||
| 
						 | 
					@ -167,13 +183,20 @@
 | 
				
			||||||
	 (keys (map (lambda (s) (string->key dpy s)) keys-s)))
 | 
						 (keys (map (lambda (s) (string->key dpy s)) keys-s)))
 | 
				
			||||||
    (and (not (memq #f keys)) keys)))
 | 
					    (and (not (memq #f keys)) keys)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(define (is-uppercase? keysym)
 | 
				
			||||||
 | 
					  (let ((low.up (convert-case keysym)))
 | 
				
			||||||
 | 
					    (not (equal? (car low.up) keysym))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define (string->key dpy s)
 | 
					(define (string->key dpy s)
 | 
				
			||||||
  (let* ((l (reverse (split-minus s)))
 | 
					  (let* ((l (reverse (split-minus s)))
 | 
				
			||||||
	 (mod-strings (reverse (cdr l)))
 | 
						 (mod-strings (reverse (cdr l)))
 | 
				
			||||||
	 (key-string (car l))
 | 
						 (key-string (car l))
 | 
				
			||||||
	 (modifiers (strings->modifiers mod-strings))
 | 
						 (keysym (string->keysym key-string))
 | 
				
			||||||
	 ;; TODO: upcase chars + Shift
 | 
						 (keycode (keysym->keycode dpy keysym))
 | 
				
			||||||
	 (keycode (keysym->keycode dpy (string->keysym key-string))))
 | 
						 (modifiers (enum-set-union (if (is-uppercase? keysym)
 | 
				
			||||||
 | 
										(state-set shift)
 | 
				
			||||||
 | 
										(state-set))
 | 
				
			||||||
 | 
									    (strings->modifiers mod-strings))))
 | 
				
			||||||
    (and modifiers keycode
 | 
					    (and modifiers keycode
 | 
				
			||||||
	 (make-key modifiers keycode))))
 | 
						 (make-key modifiers keycode))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -202,10 +225,9 @@
 | 
				
			||||||
;; *** xlib utilities ************************************************
 | 
					;; *** xlib utilities ************************************************
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define (reparent-to-root dpy window)
 | 
					(define (reparent-to-root dpy window)
 | 
				
			||||||
  ;; reparent window to it's root-window so that it stays virtually at
 | 
					  (let ((r (root-rectangle dpy window)))
 | 
				
			||||||
  ;; the same position.
 | 
					    (reparent-window dpy window (window-root dpy window)
 | 
				
			||||||
  ;; TODO
 | 
							     (rectangle:x r) (rectangle:y r))))
 | 
				
			||||||
  (reparent-window dpy window (window-root dpy window)))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define (window-path dpy window)
 | 
					(define (window-path dpy window)
 | 
				
			||||||
  (cons window
 | 
					  (cons window
 | 
				
			||||||
| 
						 | 
					@ -347,18 +369,21 @@
 | 
				
			||||||
                       (height (cdr size))))))
 | 
					                       (height (cdr size))))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define (desired-size/hints dpy window default-size)
 | 
					(define (desired-size/hints dpy window default-size)
 | 
				
			||||||
  (let* ((hints (get-wm-normal-hints dpy window)) ;; or group-leader?
 | 
					  (let ((hints (get-wm-normal-hints dpy window))) ;; or group-leader?
 | 
				
			||||||
         (size (or (assq/false (size-hint us-size) hints)
 | 
					    (if hints
 | 
				
			||||||
                   (assq/false (size-hint size) hints)
 | 
						(let ((size (or (assq/false (size-hint us-size) hints)
 | 
				
			||||||
                   default-size)))
 | 
								(assq/false (size-hint size) hints)
 | 
				
			||||||
    (adjust-size/hints hints (car size) (cdr size))))
 | 
								default-size)))
 | 
				
			||||||
 | 
						  (adjust-size/hints hints (car size) (cdr size)))
 | 
				
			||||||
 | 
						default-size)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define (desired-position/hints dpy window default-position)
 | 
					(define (desired-position/hints dpy window default-position)
 | 
				
			||||||
  (let* ((hints (get-wm-normal-hints dpy window)) ;; or group-leader?
 | 
					  (let ((hints (get-wm-normal-hints dpy window))) ;; or group-leader?
 | 
				
			||||||
         (pos (or (assq/false (size-hint us-position) hints)
 | 
					    (if hints
 | 
				
			||||||
                  (assq/false (size-hint position) hints)
 | 
						(or (assq/false (size-hint us-position) hints)
 | 
				
			||||||
                  default-position)))
 | 
						    (assq/false (size-hint position) hints)
 | 
				
			||||||
    pos))
 | 
						    default-position)
 | 
				
			||||||
 | 
						default-position)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
;; returns width/height pair that conform to the defined
 | 
					;; returns width/height pair that conform to the defined
 | 
				
			||||||
;; aspects/resize-inc etc. in hints, and are as close as possible to
 | 
					;; aspects/resize-inc etc. in hints, and are as close as possible to
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue