;; -*- lexical-binding: t -*-

;;;###autoload
(defun display-assume-graphic-p ()
  "My Emacs instances are dedicated to either the graphical environment or the
terminal. My customizations differ slightly between the two. This functions
returns whether this Emacs instance is dedicated to the graphical environment."
  (or (display-graphic-p)
      (string-equal (getenv "EMACS_SOCKET_NAME") "server-x")))

;;;###autoload
(defun display-scaling-factor ()
  "Reads the display scaling factor from the Cinnamon dconf database.
This will return 2 on Hi-DPI displays, 1 otherwise."
  (pcase (getenv "DESKTOP_SESSION")
    ("plasma"
     (round (string-to-number
             (shell-command-to-string
              "xrdb -query | awk -F :\\\\t 'BEGIN { dpi = 96 } $1 == \"Xft.dpi\" { dpi = $2 } END { print dpi }'"))
            96))
    ("cinnamon"
     (string-to-number
      (shell-command-to-string
       "dconf read /org/cinnamon/active-display-scale")))
    ("gnome"
     (string-to-number
      (shell-command-to-string
       "dconf read /org/gnome/desktop/interface/scaling-factor | awk '{ print $2 }'")))
    (_ 1)))

;;;###autoload
(defun display-adjusted-font-size ()
  "Returns my preferred font size of 14 point multiplied by the screen scaling
factor set by the desktop environment."
  (* 14 (display-scaling-factor)))

(provide 'display)

;; -*- lexical-binding: t -*-

;;;###autoload
(defun display-assume-graphic-p ()
  "My Emacs instances are dedicated to either the graphical environment or the
terminal. My customizations differ slightly between the two. This functions
returns whether this Emacs instance is dedicated to the graphical environment."
  (or (display-graphic-p)
      (string-equal (daemonp) "server-x")))

;;;###autoload
(defun display-scaling-factor ()
  "Reads the display scaling factor from the Cinnamon dconf database.
This will return 2 on Hi-DPI displays, 1 otherwise."
  (pcase (getenv "DESKTOP_SESSION")
    ("plasma"
     (round (string-to-number
             (shell-command-to-string
              "xrdb -query | awk -F :\\\\t 'BEGIN { dpi = 96 } $1 == \"Xft.dpi\" { dpi = $2 } END { print dpi }'"))
            96))
    ("cinnamon"
     (string-to-number
      (shell-command-to-string
       "dconf read /org/cinnamon/active-display-scale")))
    ("gnome"
     (string-to-number
      (shell-command-to-string
       "dconf read /org/gnome/desktop/interface/scaling-factor | awk '{ print $2 }'")))
    (_ 1)))

;;;###autoload
(defun display-adjusted-font-size ()
  "Returns my preferred font size of 14 point multiplied by the screen scaling
factor set by the desktop environment."
  (* 14 (display-scaling-factor)))

(provide 'display)

Make check for the "GUI" daemon instance more robust
Make check for the "GUI" daemon instance more robust

There is no need to read the environment variable (which might not be set,
that's the brittle part) to determine the name of the server socket. We can
rather use (daemonp) which doesn't return a boolean, as the suffix "p" might
suggest, rather it returns the socket name.

amfranz/spacemacs.d