Repository: spyder-ide/spyder

Issue:
A generic icon is shown in gnome-shell in a Wayland session
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [x] Could not reproduce inside ``jupyter qtconsole`` (if console-related) **not applicable**
* [x] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [x] Reset preferences with ``spyder --reset``
    * [x] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)  **not applicable**
    * [x] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description

A generic icon is shown in gnome-shell in a Wayland session.

### What steps reproduce the problem?

1. Enter a Gnome Wayland session.
2. Run `spyder3` or click the desktop file launcher.
3. For some combinations of versions of Spyder and its dependencies, if the warning `Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.` appears, `env QT_QPA_PLATFORM=wayland spyder3` may be needed to reproduce.

### What is the expected output? What do you see instead?

Expect to see the Spyder icon associated with the running application:

![spyder-activities-proper](https://user-images.githubusercontent.com/6898909/93216001-2a1b9700-f735-11ea-8810-2f0f691ed5e2.png) 
![spyder-bar-proper](https://user-images.githubusercontent.com/6898909/93216027-3142a500-f735-11ea-8005-f11e0380ff2d.png)

See a generic icon instead:

![spyder-activities-generic](https://user-images.githubusercontent.com/6898909/93216044-3acc0d00-f735-11ea-8d5a-6398ed901416.png)
![spyder-bar-generic](https://user-images.githubusercontent.com/6898909/93216067-43bcde80-f735-11ea-953c-b62692a45771.png)


### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

**not applicable**

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 3.3.6 or 4.1.5
* Python version: 3.8.5 or 3.9.0rc1
* Qt version: 5.14.2 or 5.15.1
* PyQt version: 5.14.2 or 5.15.0
* Operating System name/version: Fedora 32 or Fedora Rawhide

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

On Fedora Rawhide:

```
# Mandatory:
atomicwrites >=1.2.0           :  1.4.0 (OK)
chardet >=2.0.0                :  3.0.4 (OK)
cloudpickle >=0.5.0            :  1.6.0 (OK)
diff_match_patch >=20181111    :  20200713 (OK)
intervaltree                   :  None (OK)
IPython >=4.0                  :  7.18.1 (OK)
jedi =0.17.1                   :  0.17.1 (OK)
keyring                        :  None (OK)
nbconvert >=4.0                :  5.6.1 (OK)
numpydoc >=0.6.0               :  0.9.2 (OK)
parso =0.7.0                   :  0.7.0 (OK)
pexpect >=4.4.0                :  4.8.0 (OK)
pickleshare >=0.4              :  0.7.5 (OK)
psutil >=5.3                   :  5.7.2 (OK)
pygments >=2.0                 :  2.6.1 (OK)
pylint >=1.0                   :  2.6.0 (OK)
pyls >=0.34.0;<1.0.0           :  0.34.1 (OK)
qdarkstyle >=2.8               :  2.8 (OK)
qtawesome >=0.5.7              :  0.7.2 (OK)
qtconsole >=4.6.0              :  4.7.7 (OK)
qtpy >=1.5.0                   :  1.9.0 (OK)
sphinx >=0.6.6                 :  3.2.1 (OK)
spyder_kernels >=1.9.4;<1.10.0 :  1.9.4 (OK)
watchdog                       :  None (OK)
xdg >=0.26                     :  0.26 (OK)
zmq >=17                       :  19.0.0 (OK)

# Optional:
cython >=0.21                  :  None (OK)
matplotlib >=2.0.0             :  3.3.1 (OK)
numpy >=1.7                    :  1.19.2 (OK)
pandas >=0.13.1                :  1.0.5 (OK)
scipy >=0.17.0                 :  1.5.0 (OK)
sympy >=0.7.3                  :  None (OK)
```

## Diagnosis and Related Issues

I think this is the same issue discussed in [gnome-shell #1779](https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/1779); note that gnome-shell resolved their part of the issue by showing a generic placeholder icon, as I have reported here. Several other projects have encountered a similar issue, e.g. [Lyx #11847](https://www.lyx.org/trac/ticket/11847).

## Possible Resolution

I have tested adding a call to [QGuiApplication.setDesktopFileName](https://www.riverbankcomputing.com/static/Docs/PyQt5/api/qtgui/qguiapplication.html?highlight=setdesktopfilename#setDesktopFileName) as Lyx did, and initial testing looks like it solves the problem. I intend to prepare a PR with this change.


Discussion:
I’ve prepared a PR, #13787, for the `4.x` branch. The same fix should work for `master`.

Also dropping a link to the downstream Fedora bug report, [RHBZ#1832579](https://bugzilla.redhat.com/show_bug.cgi?id=1832579).
Hi @musicinmybrain,

Thanks for reporting and opening the PR, we will review it during the week :)

Resolving patch:
diff --git a/spyder/app/mainwindow.py b/spyder/app/mainwindow.py
--- a/spyder/app/mainwindow.py
+++ b/spyder/app/mainwindow.py
@@ -128,6 +128,7 @@
 #==============================================================================
 from spyder.utils.qthelpers import qapplication
 from spyder.config.base import get_image_path
+from spyder.py3compat import PY3
 MAIN_APP = qapplication()
 
 if PYQT5:
@@ -137,6 +138,10 @@
 
 MAIN_APP.setWindowIcon(APP_ICON)
 
+# Required for correct icon on GNOME/Wayland:
+if hasattr(MAIN_APP, 'setDesktopFileName'):
+    MAIN_APP.setDesktopFileName('spyder3' if PY3 else 'spyder')
+
 #==============================================================================
 # Create splash screen out of MainWindow to reduce perceived startup time.
 #==============================================================================
@@ -170,7 +175,7 @@
 from spyder.config.utils import IMPORT_EXT, is_anaconda, is_gtk_desktop
 from spyder import dependencies
 from spyder.py3compat import (is_text_string, to_text_string,
-                              PY3, qbytearray_to_str, configparser as cp)
+                              qbytearray_to_str, configparser as cp)
 from spyder.utils import encoding, programs
 from spyder.utils import icon_manager as ima
 from spyder.utils.programs import is_module_installed


Test patch: