src/eric7/SystemUtilities/DesktopUtilities.py

branch
eric7
changeset 9624
b47dfa7a137d
child 9653
e67609152c5e
equal deleted inserted replaced
9623:9c1f429cb56b 9624:b47dfa7a137d
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing Linux desktop related utility functions.
8 """
9
10 import os
11
12 from eric7.SystemUtilities import OSUtilities
13
14
15 def desktopName():
16 """
17 Function to determine the name of the desktop environment used
18 (Linux only).
19
20 @return name of the desktop environment
21 @rtype str
22 """
23 if OSUtilities.isLinuxPlatform():
24 currDesktop = os.environ.get("XDG_CURRENT_DESKTOP", "")
25 if currDesktop:
26 return currDesktop
27
28 currDesktop = os.environ.get("XDG_SESSION_DESKTOP", "")
29 if currDesktop:
30 return currDesktop
31
32 currDesktop = os.environ.get("GDMSESSION", "")
33 if currDesktop:
34 return currDesktop
35
36 currDesktop = os.environ.get("GNOME_DESKTOP_SESSION_ID", "")
37 if currDesktop:
38 return currDesktop
39
40 currDesktop = os.environ.get("KDE_FULL_SESSION", "")
41 if currDesktop:
42 if currDesktop == "true":
43 return "KDE"
44
45 return currDesktop
46
47 currDesktop = os.environ.get("DESKTOP_SESSION", "")
48 if currDesktop:
49 return currDesktop
50
51 return ""
52
53
54 def isKdeDesktop():
55 """
56 Function to check, if the current session is a KDE desktop (Linux only).
57
58 @return flag indicating a KDE desktop
59 @rtype bool
60 """
61 if OSUtilities.isLinuxPlatform():
62 desktop = (
63 os.environ.get("XDG_CURRENT_DESKTOP", "").lower()
64 or os.environ.get("XDG_SESSION_DESKTOP", "").lower()
65 or os.environ.get("DESKTOP_SESSION", "").lower()
66 )
67 return (
68 "kde" in desktop or "plasma" in desktop
69 if desktop
70 else bool(os.environ.get("KDE_FULL_SESSION", ""))
71 )
72
73 return False
74
75
76 def isGnomeDesktop():
77 """
78 Function to check, if the current session is a Gnome desktop (Linux only).
79
80 @return flag indicating a Gnome desktop
81 @rtype bool
82 """
83 if OSUtilities.isLinuxPlatform():
84 desktop = (
85 os.environ.get("XDG_CURRENT_DESKTOP", "").lower()
86 or os.environ.get("XDG_SESSION_DESKTOP", "").lower()
87 or os.environ.get("GDMSESSION", "").lower()
88 )
89 return (
90 "gnome" in desktop
91 if desktop
92 else bool(os.environ.get("GNOME_DESKTOP_SESSION_ID", ""))
93 )
94
95 return False
96
97
98 def sessionType():
99 """
100 Function to determine the name of the running session (Linux only).
101
102 @return name of the desktop environment
103 @rtype str
104 """
105 if OSUtilities.isLinuxPlatform():
106 sessionType = os.environ.get("XDG_SESSION_TYPE", "").lower()
107 if "x11" in sessionType:
108 return "X11"
109 elif "wayland" in sessionType:
110 return "Wayland"
111
112 sessionType = os.environ.get("WAYLAND_DISPLAY", "").lower()
113 if "wayland" in sessionType:
114 return "Wayland"
115
116 return ""
117
118
119 def isWaylandSession():
120 """
121 Function to check, if the current session is a wayland session.
122
123 @return flag indicating a wayland session
124 @rtype bool
125 """
126 return sessionType() == "Wayland"

eric ide

mercurial