Skip to content
This repository was archived by the owner on Oct 27, 2019. It is now read-only.

Commit a5ff3c5

Browse files
committed
Redone icon selection mechanism to fix the KDE > 5.8 issue.
1 parent 6d84f83 commit a5ff3c5

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

usr/lib/prime-indicator/prime-indicator

+30-27
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,22 @@ from gi.repository import AppIndicator3
4141

4242
APP_NAME = "PRIME Indicator"
4343
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/"
4648
CONFIG_PATH = HOME_DIR + "/.config/prime-indicator/prime-indicator.cfg"
47-
TEMP_ICON_PATH = HOME_DIR + "/.config/prime-indicator/icons"
4849
PRIME_SELECT_PATH = "/usr/bin/prime-select"
4950
NVIDIA_SETTINGS_PATH = "/usr/bin/nvidia-settings"
50-
PRIME_INDICATOR_PREFIX = "prime-indicator-"
51-
SYMBOLIC_SUFFIX = "-symbolic"
52-
THEMED_SUFFIX = "-themed"
51+
5352
NVIDIA = "nvidia"
5453
INTEL = "intel"
5554

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+
5660

5761
class Indicator:
5862
def __init__(self):
@@ -68,14 +72,22 @@ class Indicator:
6872
self.custom_color = None
6973

7074
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
7486
else:
75-
self.icon_name = PRIME_INDICATOR_PREFIX + self.icon_name + SYMBOLIC_SUFFIX + THEMED_SUFFIX
7687
if self.theme_icons.startswith("custom"):
7788
self.custom_color = re.search("custom\((.*)\)", self.theme_icons).group(1)
7889
self.create_themed_icons()
90+
self.icon_name = INTEL_SYMBOLIC if self.active_gpu == INTEL else NVIDIA_SYMBOLIC
7991
self.icon_tooltip_text = "Active graphics card: " + ("Intel" if self.active_gpu == INTEL else "NVIDIA")
8092
else:
8193
self.icon_name = "dialog-error"
@@ -135,9 +147,8 @@ class Indicator:
135147
item.show()
136148
self.menu.append(item)
137149

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)
141152
self.icon.set_status(AppIndicator3.IndicatorStatus.ACTIVE)
142153
self.icon.set_icon(self.icon_name)
143154
self.icon.set_title(self.icon_tooltip_text)
@@ -156,20 +167,16 @@ class Indicator:
156167
g=int(style_fg_color[1].green * 255),
157168
b=int(style_fg_color[1].blue * 255))
158169

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:
163173
for line in fin:
164174
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:
168177
for line in fin:
169178
fout.write(line.replace("#bebebe", fg_color_str))
170179

171-
self.icon_path = TEMP_ICON_PATH
172-
173180
def write_default_config(self):
174181
os.makedirs(os.path.dirname(CONFIG_PATH), exist_ok=True)
175182
self.config.clear()
@@ -189,7 +196,7 @@ class Indicator:
189196
iconset = self.config.get("Appearance", "iconset")
190197
if iconset not in ["symbolic", "color", "theme-default"] and \
191198
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"]:
193200
self.write_default_config()
194201
except (configparser.NoSectionError, configparser.NoOptionError):
195202
self.write_default_config()
@@ -330,10 +337,6 @@ def run() -> None:
330337
Indicator().execute()
331338

332339

333-
def restart() -> None:
334-
os.execv(__file__, sys.argv)
335-
336-
337340
if __name__ == "__main__":
338341

339342
# If nvidia-prime isn't installed or isn't supported, exit cleanly

0 commit comments

Comments
 (0)