mirror of
				https://github.com/larstvei/Focus.git
				synced 2025-11-04 02:00:11 +00:00 
			
		
		
		
	Added function to generate color based on `focus-dimness'
This commit is contained in:
		
							parent
							
								
									90806dc7ea
								
							
						
					
					
						commit
						eeb12d8db8
					
				
							
								
								
									
										15
									
								
								focus.el
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								focus.el
									
									
									
									
									
								
							@ -69,6 +69,17 @@ of RGB values of the given colors."
 | 
				
			|||||||
         (avg    (mapcar (lambda (v) (/ v len)) sums)))
 | 
					         (avg    (mapcar (lambda (v) (/ v len)) sums)))
 | 
				
			||||||
    (apply 'color-rgb-to-hex avg)))
 | 
					    (apply 'color-rgb-to-hex avg)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(defun focus-make-dim-color ()
 | 
				
			||||||
 | 
					  "Uses `focus-dimness' to determine how dim a color that should
 | 
				
			||||||
 | 
					be generated, and returns this color."
 | 
				
			||||||
 | 
					  (let ((background (face-attribute 'default :background))
 | 
				
			||||||
 | 
					        (foreground (face-attribute 'default :foreground))
 | 
				
			||||||
 | 
					        (backgrounds (if (> focus-dimness 0)    focus-dimness  1))
 | 
				
			||||||
 | 
					        (foregrounds (if (< focus-dimness 0) (- focus-dimness) 1)))
 | 
				
			||||||
 | 
					    (apply 'focus-average-colors
 | 
				
			||||||
 | 
					           (append (make-list backgrounds background)
 | 
				
			||||||
 | 
					                   (make-list foregrounds foreground)))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defun focus-move-focus ()
 | 
					(defun focus-move-focus ()
 | 
				
			||||||
  "If `focus-mode' is enabled, this command fires after each
 | 
					  "If `focus-mode' is enabled, this command fires after each
 | 
				
			||||||
command, and moves the dimming overlays."
 | 
					command, and moves the dimming overlays."
 | 
				
			||||||
@ -84,9 +95,7 @@ are invisible until `focus-move-focus' is run. It adds
 | 
				
			|||||||
focus-move-focus to `post-command-hook'."
 | 
					focus-move-focus to `post-command-hook'."
 | 
				
			||||||
  (setq focus-pre-overlay  (make-overlay (point-min) (point-min))
 | 
					  (setq focus-pre-overlay  (make-overlay (point-min) (point-min))
 | 
				
			||||||
        focus-post-overlay (make-overlay (point-max) (point-max)))
 | 
					        focus-post-overlay (make-overlay (point-max) (point-max)))
 | 
				
			||||||
  (let ((color (focus-average-colors
 | 
					  (let ((color (focus-make-dim-color)))
 | 
				
			||||||
                (face-attribute 'default :foreground)
 | 
					 | 
				
			||||||
                (face-attribute 'default :background))))
 | 
					 | 
				
			||||||
    (mapc (lambda (o) (overlay-put o 'face (cons 'foreground-color color)))
 | 
					    (mapc (lambda (o) (overlay-put o 'face (cons 'foreground-color color)))
 | 
				
			||||||
          (list focus-pre-overlay focus-post-overlay)))
 | 
					          (list focus-pre-overlay focus-post-overlay)))
 | 
				
			||||||
  (add-hook 'post-command-hook 'focus-move-focus nil t))
 | 
					  (add-hook 'post-command-hook 'focus-move-focus nil t))
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user