Repository: pwr-Solaar/Solaar

Issue:
Wrong icons in GNOME 3
Adwaita (full default): 

![image](https://user-images.githubusercontent.com/6510020/44201662-7ceb8480-a152-11e8-8811-c0b8745e54be.png)

[Materia](https://github.com/nana-4/materia-theme) + [Paper icons](https://github.com/snwh/paper-icon-theme):

![image](https://user-images.githubusercontent.com/6510020/44203345-49f7bf80-a157-11e8-8be8-bfcf1c43871d.png)

It was light-gray, as others. 

I think it's not theme issue because it's black with any theme, even default.

After upgrade from `r961.59b7285` to `r985.b852903`.


Discussion:
This is probably caused by b5d43cd (via #295 by @cschreib).

All icons seem however present with the Adwaita theme. Do you get any errors? If you strace Solaar, can you figure out which files it tried? If you revert that commit, how will it look like?
> This is probably caused by b5d43cd (via #295 by @cschreib).

Yep, looks like this.

> Do you get any errors?

No.

> If you strace Solaar, can you figure out which files it tried?

I don't know how to strace, sorry. Do you have any guide for this?

But I saw in this repo how to enable debug logs:

```
19:07:06,605    DEBUG [MainThread] solaar.ui.icons: sys.path[0] = /usr/bin
19:07:06,606    DEBUG [MainThread] solaar.ui.icons: looking for icons in /usr/icons
19:07:06,606    DEBUG [MainThread] solaar.ui.icons: looking for icons in /usr/share/solaar/icons
19:07:06,606    DEBUG [MainThread] solaar.ui.icons: looking for icons in /home/alex/.local/share/solaar/icons
19:07:06,606    DEBUG [MainThread] solaar.ui.icons: looking for icons in /usr/local/share/solaar/icons
19:07:06,606    DEBUG [MainThread] solaar.ui.icons: looking for icons in /usr/share/solaar/icons
19:07:06,606    DEBUG [MainThread] solaar.ui.icons: icon theme paths: ['/usr/share/solaar/icons', '/usr/share/solaar/icons', '/home/alex/.local/share/icons', '/home/alex/.icons', '/usr/local/share/icons', '/usr/share/icons', '/usr/local/share/pixmaps', '/usr/share/pixmaps']
19:07:06,617    DEBUG [MainThread] solaar.ui.icons: detected icon sets: Mint True, gpm True, oxygen False, gnome True, elementary True
```

So, yes, it finds `Mint` icons. I don't know how — I don't have installed anything with `mint`.

> If you revert that commit, how will it look like?

It looks OK, light-gray. Debug log:

```
19:12:26,279    DEBUG [MainThread] solaar.ui.icons: sys.path[0] = /home/alex/Projects/Solaar/lib
19:12:26,279    DEBUG [MainThread] solaar.ui.icons: looking for icons in /home/alex/Projects/Solaar/icons
19:12:26,279    DEBUG [MainThread] solaar.ui.icons: looking for icons in /home/alex/Projects/Solaar/share/solaar/icons
19:12:26,279    DEBUG [MainThread] solaar.ui.icons: looking for icons in /home/alex/.local/share/solaar/icons
19:12:26,279    DEBUG [MainThread] solaar.ui.icons: looking for icons in /usr/local/share/solaar/icons
19:12:26,279    DEBUG [MainThread] solaar.ui.icons: looking for icons in /usr/share/solaar/icons
19:12:26,279    DEBUG [MainThread] solaar.ui.icons: icon theme paths: ['/usr/share/solaar/icons', '/home/alex/Projects/Solaar/share/solaar/icons', '/home/alex/.local/share/icons', '/home/alex/.icons', '/usr/local/share/icons', '/usr/share/icons', '/usr/local/share/pixmaps', '/usr/share/pixmaps']
19:12:26,290    DEBUG [MainThread] solaar.ui.icons: detected icon sets: gpm True, oxygen False, gnome True, elementary True
```
> So, yes, it finds Mint icons.

It is a misnomer, it actually looks for names that are part of the Adwaita theme in GNOME. As for strace, close existing solaar instances and run:

    strace -e file -o strace.txt solaar

Then inspect the (large) strace.txt file for paths containing `battery-good-symbolic`.
> Then inspect the (large) strace.txt file for paths containing battery-good-symbolic.

Not found, only `battery-full-symbolic`: [strace.txt](https://github.com/pwr/Solaar/files/2297502/strace.txt)

Can you post a strace with the faulty commit reverted?
Yes, I can on Monday (this computer at work 😬 ).
same problem on xfce. Icon theme Papirus with [hardcode-tray](https://github.com/bilelmoussaoui/Hardcode-Tray) in use. Before upgrade papirus icons was used.
![image](https://user-images.githubusercontent.com/17298149/44299784-cd5f0f80-a315-11e8-888b-415c1932d667.png)

@Lekensteyn my strace also contain only battery-full-symbolic.
[strace.txt](https://github.com/pwr/Solaar/files/2299643/strace.txt)

after downgrade to r961.59b7285 I receive error
```
Traceback (most recent call last):
  File "/usr/bin/solaar", line 56, in <module>
    import solaar.gtk
ModuleNotFoundError: No module named 'solaar'
```
> Can you post a strace with the faulty commit reverted?

Here it's: 
[strace.txt](https://github.com/pwr/Solaar/files/2306073/strace.txt)

Also, for 50% icon. How it was (or how it's with reverted commit):

![image](https://user-images.githubusercontent.com/6510020/44837893-83dec080-ac43-11e8-9210-8f5e4f1d35c5.png)

How it's now:

![image](https://user-images.githubusercontent.com/6510020/44837919-92c57300-ac43-11e8-924c-e6ce3cf6682a.png)

![image](https://user-images.githubusercontent.com/6510020/44837946-a40e7f80-ac43-11e8-90af-0a2ff1ab3965.png)

It doesn't look like a half.
Seeing incorrect icons in Fedora 29 also.  When I query the status either from the command line or using the GUI my battery is at 70%.
![image](https://user-images.githubusercontent.com/34752304/48071610-b7404d00-e1a8-11e8-8016-488075178b4c.png)

Same here… Fedora 29 using `solaar-0.9.2-10.20180813gitf0fc63e.fc29.noarch`
![screenshot from 2018-12-10 14-33-36](https://user-images.githubusercontent.com/1649785/49735854-bce9f080-fc88-11e8-9c89-3b3e0a573423.png)

#543 fixes using the wrong icons for battery levels >20 and <90
#548 Fixes this by checking the current loaded theme
This way you can use Mint Icons if available or use the regular ones available in all themes and distros
Mint Example:
Window:
![window-example](https://user-images.githubusercontent.com/29512992/62404448-8df2f880-b551-11e9-919c-486e4ba5ddc8.png)

Taskbar:
![task-bar-example](https://user-images.githubusercontent.com/29512992/62404366-e8d82000-b550-11e9-84a1-c6ac29adec58.png)

Mouse Icons:
![mouse-battery-empty](https://user-images.githubusercontent.com/29512992/62404406-440a1280-b551-11e9-8f36-e498e830c436.png)
![mouse-battery-medium](https://user-images.githubusercontent.com/29512992/62404408-47050300-b551-11e9-90d8-7a37f2b76ab0.png)
![mouse-battery-full](https://user-images.githubusercontent.com/29512992/62404409-48363000-b551-11e9-8f4d-b10a36f79783.png)
#548 should have solved the problem.  If not, you can reopen this issue.
> #548 should have solved the problem.

Not merged PR should have solved the problem… how?
Oops, my bad.  I looked at CLOSED and didn't notice that it had not been merged.  My apologies.  I'm reopening.


Solaar is trying to adapt its battery icon names to the current theme. Unfortunately, the debugging logging that would show just what name is being used has been commented out.  strace shows which files have been accessed but not why they were accessed.
If you can run solaar from this repository then you can turn this debugging back on.  Just uncomment the two commented lines in the battery function in lib/solaar/ui/icons.py
Then run solaar -dd
This will produce a lot of output.  What is of interest are the lines from this logging output, i.e., lines containing "battery icon for".
This will show what solar thinks of the battery and which icon name it will use.

For example, what I see are 
19:46:34,188    DEBUG [MainThread] solaar.ui.icons: battery icon for None:None = battery-missing-symbolic
19:46:35,205    DEBUG [MainThread] solaar.ui.icons: battery icon for good:False = battery-good-symbolic
which look appropriate to me.

Resolving patch:
diff --git a/lib/solaar/ui/icons.py b/lib/solaar/ui/icons.py
--- a/lib/solaar/ui/icons.py
+++ b/lib/solaar/ui/icons.py
@@ -73,12 +73,6 @@ def _look_for_application_icons():
 
 
 _default_theme = None
-_has_mint_icons = None
-_has_gpm_icons = None
-_has_oxygen_icons = None
-_has_gnome_icons = None
-_has_elementary_icons = None
-
 
 def _init_icon_paths():
 	global _default_theme
@@ -91,23 +85,8 @@ def _init_icon_paths():
 	if _log.isEnabledFor(_DEBUG):
 		_log.debug("icon theme paths: %s", _default_theme.get_search_path())
 
-	global _has_mint_icons, _has_gpm_icons, _has_oxygen_icons, _has_gnome_icons, _has_elementary_icons
-
-	_has_mint_icons = _default_theme.has_icon('battery-good-symbolic')
-	_has_gpm_icons = _default_theme.has_icon('gpm-battery-020-charging')
-	_has_oxygen_icons = _default_theme.has_icon('battery-charging-caution') and \
-						_default_theme.has_icon('battery-charging-040')
-	_has_gnome_icons = _default_theme.has_icon('battery-caution-charging') and \
-						_default_theme.has_icon('battery-full-charged')
-	_has_elementary_icons = _default_theme.has_icon('battery-020-charging')
-
-	if _log.isEnabledFor(_DEBUG):
-		_log.debug("detected icon sets: Mint %s, gpm %s, oxygen %s, gnome %s, elementary %s",
-						_has_mint_icons, _has_gpm_icons, _has_oxygen_icons, _has_gnome_icons, _has_elementary_icons)
-
-	if (not _has_mint_icons and not _has_gpm_icons and not _has_oxygen_icons and
-		not _has_gnome_icons and not _has_elementary_icons):
-		_log.warning("failed to detect a known icon set")
+	if not _default_theme.has_icon('battery-good'):
+		_log.warning("failed to detect icons")
 
 #
 #
@@ -117,8 +96,8 @@ def battery(level=None, charging=False):
 	icon_name = _battery_icon_name(level, charging)
 	if not _default_theme.has_icon(icon_name):
 		_log.warning("icon %s not found in current theme", icon_name);
-	# elif _log.isEnabledFor(_DEBUG):
-	# 	_log.debug("battery icon for %s:%s = %s", level, charging, icon_name)
+	elif _log.isEnabledFor(_DEBUG):
+		_log.debug("battery icon for %s:%s = %s", level, charging, icon_name)
 	return icon_name
 
 # return first res where val >= guard
@@ -130,48 +109,10 @@ def _battery_icon_name(level, charging):
 	_init_icon_paths()
 
 	if level is None or level < 0:
-		if _has_mint_icons:
-			return 'battery-missing-symbolic'
-		if _has_gpm_icons and _default_theme.has_icon('gpm-battery-missing'):
-			return 'gpm-battery-missing'
 		return 'battery-missing'
 
-	level_approx = 20 * ((level  + 10) // 20)
-
-	if _has_mint_icons:
-		if level == 100 and charging:
-			return 'battery-full-charged-symbolic'
-		level_name = _first_res(level,((90,'full'), (50,'good'), (20,'low'), (5,'caution'), (0,'empty')))
-		return 'battery-%s%s-symbolic' % (level_name, '-charging' if charging else '')
-
-	if _has_gpm_icons:
-		if level == 100 and charging:
-			return 'gpm-battery-charged'
-		return 'gpm-battery-%03d%s' % (level_approx, '-charging' if charging else '')
-
-	if _has_oxygen_icons:
-		if level_approx == 100 and charging:
-			return 'battery-charging'
-		level_name = _first_res(level,((90,'100'), (75,'080'), (55,'060'), (35,'040'), (15,'low'), (0,'caution')))
-		return 'battery%s-%s' % ('-charging' if charging else '', level_name)
-
-	if _has_elementary_icons:
-		if level == 100 and charging:
-			return 'battery-charged'
-		return 'battery-%03d%s' % (level_approx, '-charging' if charging else '')
-
-	if _has_gnome_icons:
-		if level == 100 and charging:
-			return 'battery-full-charged'
-		if level_approx == 0 and charging:
-			return 'battery-caution-charging'
-		level_name = _first_res(level,((90,'full'), (50,'good'), (20,'low'), (5,'caution'), (0,'empty')))
-		return 'battery-%s%s' % (level_name, '-charging' if charging else '')
-
-	# fallback... most likely will fail
-	if level == 100 and charging:
-		return 'battery-charged'
-	return 'battery-%03d%s' % (level_approx, '-charging' if charging else '')
+	level_name = _first_res(level,((90,'full'), (50,'good'), (20,'low'), (5,'caution'), (0,'empty')))
+	return 'battery-%s%s' % (level_name, '-charging' if charging else '')
 
 #
 #
diff --git a/lib/solaar/ui/tray.py b/lib/solaar/ui/tray.py
--- a/lib/solaar/ui/tray.py
+++ b/lib/solaar/ui/tray.py
@@ -203,6 +203,9 @@ def _update_tray_icon():
 			battery_charging = device_status.get(_K.BATTERY_CHARGING)
 			tray_icon_name = _icons.battery(battery_level, battery_charging)
 
+			# get around system tray icons not having styling and not having css class
+			tray_icon_name = tray_icon_name + ( "-symbolic" if "SOLAAR_TRAY_BATTERY_ICON_SYBOLIC" in os.environ else "" )
+
 			description =  '%s: %s' % (name, device_status.to_string())
 		else:
 			# there may be a receiver, but no peripherals
@@ -260,6 +263,9 @@ def _update_tray_icon():
 			battery_level = device_status.get(_K.BATTERY_LEVEL)
 			battery_charging = device_status.get(_K.BATTERY_CHARGING)
 			tray_icon_name = _icons.battery(battery_level, battery_charging)
+
+			# get around system tray icons not having styling and not having css class
+			tray_icon_name = tray_icon_name + ( "-symbolic" if "SOLAAR_TRAY_BATTERY_ICON_SYBOLIC" in os.environ else "" )
 		else:
 			# there may be a receiver, but no peripherals
 			tray_icon_name = _icons.TRAY_OKAY if _devices_info else _icons.TRAY_ATTENTION


Test patch: