Skip to content

Commit

Permalink
Merge branch 'gi-wayland'
Browse files Browse the repository at this point in the history
  • Loading branch information
virtuald committed Dec 11, 2015
2 parents 5f76aeb + 49aa3dd commit dc83ba4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
6 changes: 5 additions & 1 deletion xlgui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ def __init__(self, exaile):
.child_set_property(self.panel_notebook, 'shrink', False)

if settings.get_option('gui/use_tray', False):
self.tray_icon = tray.TrayIcon(self.main)
if tray.is_supported():
self.tray_icon = tray.TrayIcon(self.main)
else:
settings.set_option('gui/use_tray', False)
logger.warn("Tray icons are not supported on your platform. Disabling tray icon.")

from xl import event
event.add_ui_callback(self.add_device_panel, 'device_connected')
Expand Down
13 changes: 12 additions & 1 deletion xlgui/preferences/appearance.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from xl import xdg
from xl.nls import gettext as _
from xlgui.preferences import widgets
from xlgui import tray

name = _('Appearance')
icon = 'preferences-desktop-theme'
Expand Down Expand Up @@ -89,10 +90,20 @@ def apply(self, value=None):
return return_value


class UseTrayPreference(widgets.CheckPreference):
class UseTrayPreference(widgets.CheckPreference, widgets.Conditional):
default = False
name = 'gui/use_tray'

def __init__(self, preferences, widget):
widgets.CheckPreference.__init__(self, preferences, widget)
widgets.Conditional.__init__(self)
if not tray.is_supported():
self.widget.set_tooltip_text(_("Tray icons are not supported on your platform"))

def on_check_condition(self):
return tray.is_supported()


class MinimizeToTrayPreference(widgets.CheckPreference, widgets.CheckConditional):
default = False
name = 'gui/minimize_to_tray'
Expand Down
21 changes: 21 additions & 0 deletions xlgui/tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
# do so. If you do not wish to do so, delete this exception statement
# from your version.

import logging

from gi.repository import Gdk
from gi.repository import Gtk

Expand All @@ -37,6 +39,25 @@
from xlgui.widgets.info import TrackToolTip
from xlgui.widgets import rating, menu, menuitems, playlist, playback

logger = logging.getLogger(__name__)


def is_supported():
"""
On some platforms (e.g. Linux+Wayland) tray icons are not supported.
"""
supported = not __platform_is_wayland()

if not supported:
logger.debug("No tray icon support on this platform")

return supported


def __platform_is_wayland():
display_name = Gdk.Display.get_default().get_name()
return display_name == 'Wayland'


def __create_tray_context_menu():
sep = menu.simple_separator
Expand Down

0 comments on commit dc83ba4

Please sign in to comment.