@@ -41,18 +41,22 @@ from gi.repository import AppIndicator3
41
41
42
42
APP_NAME = "PRIME Indicator"
43
43
HOME_DIR = os .getenv ("HOME" ) # type:str
44
- LIB_PATH = "/usr/lib/prime-indicator"
45
- SCRIPT_CMD = "sudo " + LIB_PATH + "/gpuswitcher"
44
+ LIB_PATH = "/usr/lib/prime-indicator/"
45
+ SCRIPT_CMD = "sudo " + LIB_PATH + "gpuswitcher"
46
+ STD_ICONS_FOLDER = LIB_PATH + "icons/"
47
+ USER_ICONS_FOLDER = HOME_DIR + "/.config/prime-indicator/icons/"
46
48
CONFIG_PATH = HOME_DIR + "/.config/prime-indicator/prime-indicator.cfg"
47
- TEMP_ICON_PATH = HOME_DIR + "/.config/prime-indicator/icons"
48
49
PRIME_SELECT_PATH = "/usr/bin/prime-select"
49
50
NVIDIA_SETTINGS_PATH = "/usr/bin/nvidia-settings"
50
- PRIME_INDICATOR_PREFIX = "prime-indicator-"
51
- SYMBOLIC_SUFFIX = "-symbolic"
52
- THEMED_SUFFIX = "-themed"
51
+
53
52
NVIDIA = "nvidia"
54
53
INTEL = "intel"
55
54
55
+ NVIDIA_COLOR = STD_ICONS_FOLDER + "prime-indicator-nvidia.svg"
56
+ INTEL_COLOR = STD_ICONS_FOLDER + "prime-indicator-intel.svg"
57
+ NVIDIA_SYMBOLIC = USER_ICONS_FOLDER + "prime-indicator-nvidia-symbolic-themed.svg"
58
+ INTEL_SYMBOLIC = USER_ICONS_FOLDER + "prime-indicator-intel-symbolic-themed.svg"
59
+
56
60
57
61
class Indicator :
58
62
def __init__ (self ):
@@ -68,14 +72,22 @@ class Indicator:
68
72
self .custom_color = None
69
73
70
74
if self .active_gpu in [INTEL , NVIDIA ]:
71
- self .icon_name = self .active_gpu
72
- if self .theme_icons == "color" :
73
- self .icon_name = PRIME_INDICATOR_PREFIX + self .icon_name
75
+ if self .theme_icons == "theme-default" :
76
+ theme = Gtk .IconTheme .get_default ()
77
+ if theme .has_icon (self .active_gpu ):
78
+ self .icon_name = theme .lookup_icon (self .active_gpu , max (theme .get_icon_sizes (self .active_gpu )),
79
+ 0 ).get_filename ()
80
+ else :
81
+ self .icon_name = INTEL_COLOR
82
+ print ("ALERT: GTK Icon Theme does not provide an icon for " + (
83
+ "Intel" if self .active_gpu == INTEL else "NVIDIA" ) + ". Using default color icon instead!" )
84
+ elif self .theme_icons == "color" :
85
+ self .icon_name = INTEL_COLOR if self .active_gpu == INTEL else NVIDIA_COLOR
74
86
else :
75
- self .icon_name = PRIME_INDICATOR_PREFIX + self .icon_name + SYMBOLIC_SUFFIX + THEMED_SUFFIX
76
87
if self .theme_icons .startswith ("custom" ):
77
88
self .custom_color = re .search ("custom\((.*)\)" , self .theme_icons ).group (1 )
78
89
self .create_themed_icons ()
90
+ self .icon_name = INTEL_SYMBOLIC if self .active_gpu == INTEL else NVIDIA_SYMBOLIC
79
91
self .icon_tooltip_text = "Active graphics card: " + ("Intel" if self .active_gpu == INTEL else "NVIDIA" )
80
92
else :
81
93
self .icon_name = "dialog-error"
@@ -135,9 +147,8 @@ class Indicator:
135
147
item .show ()
136
148
self .menu .append (item )
137
149
138
- self .icon = AppIndicator3 .Indicator .new_with_path (APP_NAME , "" ,
139
- AppIndicator3 .IndicatorCategory .APPLICATION_STATUS ,
140
- self .icon_path )
150
+ self .icon = AppIndicator3 .Indicator .new (APP_NAME , "" ,
151
+ AppIndicator3 .IndicatorCategory .APPLICATION_STATUS )
141
152
self .icon .set_status (AppIndicator3 .IndicatorStatus .ACTIVE )
142
153
self .icon .set_icon (self .icon_name )
143
154
self .icon .set_title (self .icon_tooltip_text )
@@ -156,20 +167,16 @@ class Indicator:
156
167
g = int (style_fg_color [1 ].green * 255 ),
157
168
b = int (style_fg_color [1 ].blue * 255 ))
158
169
159
- os .makedirs (TEMP_ICON_PATH , exist_ok = True )
160
- with open (LIB_PATH + "/icons/" + PRIME_INDICATOR_PREFIX + NVIDIA + SYMBOLIC_SUFFIX + ".svg" , "r" ) as fin :
161
- with open (TEMP_ICON_PATH + "/" + PRIME_INDICATOR_PREFIX + NVIDIA + SYMBOLIC_SUFFIX + THEMED_SUFFIX + ".svg" ,
162
- "w" ) as fout :
170
+ os .makedirs (USER_ICONS_FOLDER , exist_ok = True )
171
+ with open (STD_ICONS_FOLDER + "prime-indicator-nvidia-symbolic.svg" , "r" ) as fin :
172
+ with open (NVIDIA_SYMBOLIC , "w" ) as fout :
163
173
for line in fin :
164
174
fout .write (line .replace ("#bebebe" , fg_color_str ))
165
- with open (LIB_PATH + "/icons/" + PRIME_INDICATOR_PREFIX + INTEL + SYMBOLIC_SUFFIX + ".svg" , "r" ) as fin :
166
- with open (TEMP_ICON_PATH + "/" + PRIME_INDICATOR_PREFIX + INTEL + SYMBOLIC_SUFFIX + THEMED_SUFFIX + ".svg" ,
167
- "w" ) as fout :
175
+ with open (STD_ICONS_FOLDER + "prime-indicator-intel-symbolic.svg" , "r" ) as fin :
176
+ with open (INTEL_SYMBOLIC , "w" ) as fout :
168
177
for line in fin :
169
178
fout .write (line .replace ("#bebebe" , fg_color_str ))
170
179
171
- self .icon_path = TEMP_ICON_PATH
172
-
173
180
def write_default_config (self ):
174
181
os .makedirs (os .path .dirname (CONFIG_PATH ), exist_ok = True )
175
182
self .config .clear ()
@@ -189,7 +196,7 @@ class Indicator:
189
196
iconset = self .config .get ("Appearance" , "iconset" )
190
197
if iconset not in ["symbolic" , "color" , "theme-default" ] and \
191
198
not re .search ('^custom\(#([a-fA-F0-9]{2}){3}\)$' , iconset ) or \
192
- self .config .get ("PowerManagement" , "enabled" ) not in ["true" , "false" ]:
199
+ self .config .get ("PowerManagement" , "enabled" ) not in ["true" , "false" ]:
193
200
self .write_default_config ()
194
201
except (configparser .NoSectionError , configparser .NoOptionError ):
195
202
self .write_default_config ()
@@ -330,10 +337,6 @@ def run() -> None:
330
337
Indicator ().execute ()
331
338
332
339
333
- def restart () -> None :
334
- os .execv (__file__ , sys .argv )
335
-
336
-
337
340
if __name__ == "__main__" :
338
341
339
342
# If nvidia-prime isn't installed or isn't supported, exit cleanly
0 commit comments