add inactive faces + logic
1 files changed, 76 insertions(+), 7 deletions(-)

M xc-line.el
M xc-line.el +76 -7
@@ 132,6 132,44 @@ 
   "Face for the second rightmost part"
    :group 'xc-line)
 
+;; Face for non-focused windows
+
+(defface xc-line/part-a-unfocused
+   '((t (:inherit mode-line-inactive :weight semi-bold)))
+  "Face for the leftmost part when the window is not focused"
+   :group 'xc-line)
+
+(defface xc-line/part-z-unfocused
+   '((t (:inherit xc-line/part-a-unfocused)))
+  "Face for the rightmost part when the window is not focused"
+   :group 'xc-line)
+
+(defface xc-line/part-b-unfocused
+   '((t (:inherit xc-line/part-b)))
+  "Face for the second leftmost part when the window is not focused"
+   :group 'xc-line)
+
+(defface xc-line/part-c-unfocused
+   '((t (:inherit xc-line/part-c)))
+  "Face for the third leftmost part when the window is not focused"
+   :group 'xc-line)
+
+(defface xc-line/part-x-unfocused
+   '((t (:inherit (xc-line/part-c-unfocused))))
+  "Face for the third rightmost part when the window is not focused"
+   :group 'xc-line)
+
+(defface xc-line/part-y-unfocused
+   '((t (:inherit (xc-line/part-b-unfocused))))
+  "Face for the second rightmost part when the window is not focused"
+   :group 'xc-line)
+
+;; Face for non-focused windows
+
+;; Face for the container
+
+;; Face for the container
+
 (defface xc-line/container
    '((t (:box (:line-width (-1 . 2)
                :style flat-button))))

          
@@ 237,16 275,25 @@ 
 
 (defun xc-line/format-left (a b c)
   "Makes the left part of the mode line"
-  (let ((a-propd (xc-line/format-part a (xc-line/get-face-for-mode 'a)))
-        (b-propd (xc-line/format-part b 'xc-line/part-b))
-        (c-propd (xc-line/format-part c 'xc-line/part-c)))
+  (let* ((focused (--xc-line/line-focused-p))
+         (a-propd (xc-line/format-part a (if focused (xc-line/get-face-for-mode 'a)
+                                           'xc-line/part-a-unfocused)))
+         (b-propd (xc-line/format-part b (if focused 'xc-line/part-b
+                                           'xc-line/part-b-unfocused)))
+         (c-propd (xc-line/format-part c (if focused 'xc-line/part-c
+                                           'xc-line/part-c-unfocused))))
     (list a-propd b-propd c-propd)))
 
 (defun xc-line/format-right (x y z)
   "Makes the right part of the mode line"
-  (let ((x-propd (xc-line/format-part x 'xc-line/part-x))
-        (y-propd (xc-line/format-part y 'xc-line/part-y))
-        (z-propd (xc-line/format-part z (xc-line/get-face-for-mode 'z) t)))
+  (let* ((focused (--xc-line/line-focused-p))
+         (x-propd (xc-line/format-part x (if focused 'xc-line/part-x
+                                           'xc-line/part-x-unfocused)))
+         (y-propd (xc-line/format-part y (if focused 'xc-line/part-y
+                                           'xc-line/part-y-unfocused)))
+         (z-propd (xc-line/format-part z (if focused (xc-line/get-face-for-mode 'z)
+                                           'xc-line/part-z-unfocused)
+                                       t)))
     (list x-propd y-propd z-propd)))
 
 (defun xc-line/get-left-part ()

          
@@ 273,6 320,21 @@ 
   "Get the mode-line"
   (xc-line/format (xc-line/get-left-part) (xc-line/get-right-part)))
 
+;; Focused/Unfocused
+;; Most of this is either inspired or copied from nrougier's NANO modeline.
+
+(defvar --xc-line/focused-window nil
+  "The current focused window. Used to figure out whether the line should be active or not")
+
+(defun --xc-line/update-focused-window ()
+  "Sets the focused window to the current one"
+  (setq --xc-line/focused-window (selected-window)))
+
+(defun --xc-line/line-focused-p (&optional window)
+  "Queries whether the line is below a focused window or not"
+  (let ((win (or window (get-buffer-window (current-buffer)))))
+     (eq win --xc-line/focused-window)))
+
 ;; Segment variables
 
 (defcustom xc-line/segments-a

          
@@ 370,16 432,23 @@ 
     (setq --xc-line/saved-mode-line-format mode-line-format)
     (setq --xc-line/saved-header-line-format header-line-format))
 
+
+  (--xc-line/update-focused-window)
+
   (setq mode-line-format xc-line/mode-line)
   (setq-default mode-line-format xc-line/mode-line)
 
+  (add-hook 'post-command-hook #'--xc-line/update-focused-window)
+
   (force-mode-line-update t))
   
 (defun xc-line/mode-deactivate ()
   (setq         mode-line-format --xc-line/saved-mode-line-format)
   (setq-default mode-line-format --xc-line/saved-mode-line-format)
   (setq         header-line-format --xc-line/saved-header-line-format)
-  (setq-default header-line-format --xc-line/saved-header-line-format))
+  (setq-default header-line-format --xc-line/saved-header-line-format)
+  (remove-hook 'post-command-hook #'--xc-line/update-focused-window))
+  
   
 
 ;;;###autoload