buffer once found icon names #259
This commit is contained in:
@@ -18,6 +18,7 @@ dwl_instances = []
|
|||||||
app_dirs = []
|
app_dirs = []
|
||||||
name2icon_dict = {}
|
name2icon_dict = {}
|
||||||
scratchpad_cons = {}
|
scratchpad_cons = {}
|
||||||
|
app_name2icon_name = {}
|
||||||
|
|
||||||
commands = {
|
commands = {
|
||||||
"light": False,
|
"light": False,
|
||||||
|
@@ -544,7 +544,7 @@ def main():
|
|||||||
save_string("-c {} -s {}".format(args.config, args.style), os.path.join(local_dir(), "args"))
|
save_string("-c {} -s {}".format(args.config, args.style), os.path.join(local_dir(), "args"))
|
||||||
|
|
||||||
common.app_dirs = get_app_dirs()
|
common.app_dirs = get_app_dirs()
|
||||||
common.name2icon_dict = map_odd_desktop_files()
|
# common.name2icon_dict = map_odd_desktop_files()
|
||||||
|
|
||||||
config_file = os.path.join(common.config_dir, args.config)
|
config_file = os.path.join(common.config_dir, args.config)
|
||||||
|
|
||||||
|
@@ -72,32 +72,36 @@ def get_app_dirs():
|
|||||||
return desktop_dirs
|
return desktop_dirs
|
||||||
|
|
||||||
|
|
||||||
def map_odd_desktop_files():
|
# def map_odd_desktop_files():
|
||||||
name2icon_dict = {}
|
# name2icon_dict = {}
|
||||||
for d in nwg_panel.common.app_dirs:
|
# for d in nwg_panel.common.app_dirs:
|
||||||
if os.path.exists(d):
|
# if os.path.exists(d):
|
||||||
for path in os.listdir(d):
|
# for path in os.listdir(d):
|
||||||
if os.path.isfile(os.path.join(d, path)):
|
# if os.path.isfile(os.path.join(d, path)):
|
||||||
if path.endswith(".desktop") and path.count(".") > 1:
|
# if path.endswith(".desktop") and path.count(".") > 1:
|
||||||
try:
|
# try:
|
||||||
content = load_text_file(os.path.join(d, path))
|
# content = load_text_file(os.path.join(d, path))
|
||||||
except Exception as e:
|
# except Exception as e:
|
||||||
eprint(e)
|
# eprint(e)
|
||||||
if content:
|
# if content:
|
||||||
for line in content.splitlines():
|
# for line in content.splitlines():
|
||||||
if line.startswith("[") and not line == "[Desktop Entry]":
|
# if line.startswith("[") and not line == "[Desktop Entry]":
|
||||||
break
|
# break
|
||||||
if line.upper().startswith("ICON="):
|
# if line.upper().startswith("ICON="):
|
||||||
icon = line.split("=")[1]
|
# icon = line.split("=")[1]
|
||||||
name2icon_dict[path] = icon
|
# name2icon_dict[path] = icon
|
||||||
break
|
# break
|
||||||
|
#
|
||||||
return name2icon_dict
|
# return name2icon_dict
|
||||||
|
|
||||||
|
|
||||||
def get_icon_name(app_name):
|
def get_icon_name(app_name):
|
||||||
if not app_name:
|
if not app_name:
|
||||||
return ""
|
return ""
|
||||||
|
# the name might've been already found in .desktop files and stored
|
||||||
|
if app_name in nwg_panel.common.app_name2icon_name:
|
||||||
|
return nwg_panel.common.app_name2icon_name[app_name]
|
||||||
|
|
||||||
# GIMP returns "app_id": null and for some reason "class": "Gimp-2.10" instead of just "gimp".
|
# GIMP returns "app_id": null and for some reason "class": "Gimp-2.10" instead of just "gimp".
|
||||||
# Until the GTK3 version is released, let's make an exception for GIMP.
|
# Until the GTK3 version is released, let's make an exception for GIMP.
|
||||||
if "GIMP" in app_name.upper():
|
if "GIMP" in app_name.upper():
|
||||||
@@ -114,7 +118,9 @@ def get_icon_name(app_name):
|
|||||||
if content:
|
if content:
|
||||||
for line in content.splitlines():
|
for line in content.splitlines():
|
||||||
if line.upper().startswith("ICON"):
|
if line.upper().startswith("ICON"):
|
||||||
return line.split("=")[1]
|
icon_name = line.split("=")[1]
|
||||||
|
nwg_panel.common.app_name2icon_name[app_name] = icon_name
|
||||||
|
return icon_name
|
||||||
|
|
||||||
# Otherwise, we need to search all .desktop files
|
# Otherwise, we need to search all .desktop files
|
||||||
if os.path.isdir(d):
|
if os.path.isdir(d):
|
||||||
@@ -125,13 +131,15 @@ def get_icon_name(app_name):
|
|||||||
if content:
|
if content:
|
||||||
for line in content.splitlines():
|
for line in content.splitlines():
|
||||||
if line.upper().startswith("ICON"):
|
if line.upper().startswith("ICON"):
|
||||||
return line.split("=")[1]
|
icon_name = line.split("=")[1]
|
||||||
|
nwg_panel.common.app_name2icon_name[app_name] = icon_name
|
||||||
|
return icon_name
|
||||||
|
|
||||||
# Search the dictionary made of .desktop files that use "reverse DNS"-style names, prepared on startup.
|
# Search the dictionary made of .desktop files that use "reverse DNS"-style names, prepared on startup.
|
||||||
# see: https://github.com/nwg-piotr/nwg-panel/issues/64
|
# see: https://github.com/nwg-piotr/nwg-panel/issues/64
|
||||||
for key in nwg_panel.common.name2icon_dict.keys():
|
# for key in nwg_panel.common.name2icon_dict.keys():
|
||||||
if app_name in key.split("."):
|
# if app_name in key.split("."):
|
||||||
return nwg_panel.common.name2icon_dict[key]
|
# return nwg_panel.common.name2icon_dict[key]
|
||||||
|
|
||||||
# if all above fails
|
# if all above fails
|
||||||
return app_name
|
return app_name
|
||||||
|
Reference in New Issue
Block a user