 (defun spacemacs/toggle-transparency ()
   "Toggle between transparent or opaque display."
   (interactive)
-  ;; Define alpha if it's nil
-  (if (eq (frame-parameter (selected-frame) 'alpha) nil)
-      (set-frame-parameter (selected-frame) 'alpha '(100 100)))
-  ;; Do the actual toggle
-  (if (/= (cadr (frame-parameter (selected-frame) 'alpha)) 100)
-      (set-frame-parameter (selected-frame) 'alpha '(100 100))
-    (set-frame-parameter (selected-frame) 'alpha
-                         (list dotspacemacs-active-transparency
-                               dotspacemacs-inactive-transparency)))
+  (let* ((frame (selected-frame))
+         (alpha (frame-parameter frame 'alpha)))
+    (set-frame-parameter
+     frame 'alpha
+     (if (or (null alpha) (= (cdr-safe alpha) 100))
+         (cons dotspacemacs-active-transparency
+               dotspacemacs-inactive-transparency)
+       '(100 . 100))))
   ;; Immediately enter the micro-state, but also keep toggle
   ;; accessible from helm-spacemacs
   (spacemacs/scale-transparency-micro-state))

  (let* ((current-alpha (car (frame-parameter (selected-frame) 'alpha)))
         (increased-alpha (- current-alpha 5)))
    (when (>= increased-alpha frame-alpha-lower-limit)
      (set-frame-parameter (selected-frame) 'alpha (list increased-alpha increased-alpha)))))

(defun spacemacs/decrease-transparency ()
  "Decrease transparency of current frame."

  (let* ((current-alpha (car (frame-parameter (selected-frame) 'alpha)))
         (decreased-alpha (+ current-alpha 5)))
    (when (<= decreased-alpha 100)
      (set-frame-parameter (selected-frame) 'alpha
                           (cons decreased-alpha decreased-alpha)))))

(spacemacs|define-micro-state scale-transparency
  :doc "[+] increase [-] decrease [T] toggle transparency [q] quit"
