[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master fd70791218 1/7: Add new function xdg-current-desktop to xdg.el
From: |
Stefan Kangas |
Subject: |
master fd70791218 1/7: Add new function xdg-current-desktop to xdg.el |
Date: |
Wed, 14 Sep 2022 05:19:42 -0400 (EDT) |
branch: master
commit fd70791218936da56a622707d3e09efc33feb16d
Author: Stefan Kangas <stefankangas@gmail.com>
Commit: Stefan Kangas <stefankangas@gmail.com>
Add new function xdg-current-desktop to xdg.el
* lisp/xdg.el (xdg-current-desktop): New function.
* test/lisp/xdg-tests.el (xdg-current-desktop): New test.
---
etc/NEWS | 8 ++++++++
lisp/xdg.el | 12 ++++++++++++
test/lisp/xdg-tests.el | 10 ++++++++++
3 files changed, 30 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index ae3f84c1b9..4053e39b77 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -3458,6 +3458,14 @@ version 0.8 (8th May 2021), "contains state data that
should persist
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
diff --git a/lisp/xdg.el b/lisp/xdg.el
index dd0d51290d..5d60aa2f28 100644
--- a/lisp/xdg.el
+++ b/lisp/xdg.el
@@ -281,6 +281,18 @@ Optional argument GROUP defaults to the string \"Desktop
Entry\"."
(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 ":")))
+
;; MIME apps specification
;; https://standards.freedesktop.org/mime-apps-spec/mime-apps-spec-1.0.1.html
diff --git a/test/lisp/xdg-tests.el b/test/lisp/xdg-tests.el
index e8e103348b..882160743a 100644
--- a/test/lisp/xdg-tests.el
+++ b/test/lisp/xdg-tests.el
@@ -59,6 +59,16 @@
(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"))
- master updated (d0b2eee278 -> 41a3155319), Stefan Kangas, 2022/09/14
- master ac479598f1 5/7: * lisp/image/wallpaper.el (wallpaper-commands): Add xwallpaper., Stefan Kangas, 2022/09/14
- master 41a3155319 7/7: Improve wallpaper.el docs for recent changes, Stefan Kangas, 2022/09/14
- master bfafe4aacc 6/7: Allow setting wallpaper from TTY, Stefan Kangas, 2022/09/14
- master fd70791218 1/7: Add new function xdg-current-desktop to xdg.el,
Stefan Kangas <=
- master 7d315ce630 2/7: ; * etc/NEWS: Improve wording of 'xdg-state-home' entry., Stefan Kangas, 2022/09/14
- master 6f06353290 4/7: Support recent KDE Plasma in wallpaper.el, Stefan Kangas, 2022/09/14
- master d537e4c102 3/7: Fix desktop environment check on Ubuntu, Stefan Kangas, 2022/09/14