* lisp/xdg.el (xdg-current-desktop): New function.
* test/lisp/xdg-tests.el (xdg-current-desktop): New test.
between (application) restarts, but that is not important or portable
enough to the user that it should be stored in $XDG_DATA_HOME".
+---
+*** New function 'xdg-current-desktop'.
+It returns a list of strings, corresponding to the colon-separated
+list of names in the 'XDG_CURRENT_DESKTOP' environment variable, which
+identify the current desktop environment.
+(This variable was introduced in XDG Desktop Entry Specification
+version 1.2.)
+
+++
** New macro 'with-delayed-message'.
This macro is like 'progn', but will output the specified message if
(when (null (string-match-p "[^[:blank:]]" (car res))) (pop res))
(nreverse res)))
+(defun xdg-current-desktop ()
+ "Return a list of strings identifying the current desktop environment.
+
+According to the XDG Desktop Entry Specification version 0.5:
+
+ If $XDG_CURRENT_DESKTOP is set then it contains a
+ colon-separated list of strings ... $XDG_CURRENT_DESKTOP
+ should have been set by the login manager, according to the
+ value of the DesktopNames found in the session file."
+ (when-let ((ret (getenv "XDG_CURRENT_DESKTOP")))
+ (string-split ret ":")))
+
\f
;; MIME apps specification
;; https://standards.freedesktop.org/mime-apps-spec/mime-apps-spec-1.0.1.html
(should (equal (xdg-desktop-strings " ") nil))
(should (equal (xdg-desktop-strings "a; ;") '("a" " "))))
+(ert-deftest xdg-current-desktop ()
+ (let ((env (getenv "XDG_CURRENT_DESKTOP")))
+ (unwind-protect
+ (progn
+ (setenv "XDG_CURRENT_DESKTOP" "KDE")
+ (should (equal (xdg-current-desktop) '("KDE")))
+ (setenv "XDG_CURRENT_DESKTOP" "ubuntu:GNOME")
+ (should (equal (xdg-current-desktop) '("ubuntu" "GNOME"))))
+ (setenv "XDG_CURRENT_DESKTOP" env))))
+
(ert-deftest xdg-mime-associations ()
"Test reading MIME associations from files."
(let* ((apps (ert-resource-file "mimeapps.list"))