Skip to content

Commit f3e34c3

Browse files
authored
Fix window icons for Wayland (slgobinath#703)
* fix window icons for wayland apparently, when using Gtk.Builder, we always need to manually associate the application (also see the example: https://gitlab.gnome.org/GNOME/gtk/-/blob/86e735cd5ca7555e64e96179692fd9436e1432f2/examples/builder.c) * add note about window icons when running from source * fix missing argument
1 parent ee770c0 commit f3e34c3

File tree

10 files changed

+45
-16
lines changed

10 files changed

+45
-16
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ python3 -m safeeyes
145145

146146
Safe Eyes installers install the required icons to `/usr/share/icons/hicolor`. When you run Safe Eyes from source without, some icons may not appear.
147147

148+
Note that on Wayland, this may still not be enough to get window icons working properly, as Wayland requires the .desktop file to match the running application, which is hard to do when running from source. If at all possible, prefer using an installed package.
149+
148150

149151
### Install in a virtual environment
150152

@@ -176,6 +178,8 @@ Some Linux systems like CentOS do not have matching dependencies available in th
176178

177179
For more details, please check the issue: [#329](https://github.com/slgobinath/SafeEyes/issues/329)
178180

181+
This method has the same caveats about icons/window icons as running from source.
182+
179183
## Features
180184

181185
- Remind you to take breaks with exercises to reduce RSI

safeeyes/glade/about_dialog.glade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ along with this program. If not, see &lt;https://www.gnu.org/licenses/&gt;.</pr
3838
<object class="GtkWindow" id="window_about">
3939
<property name="title">Safe Eyes</property>
4040
<property name="resizable">0</property>
41-
<property name="icon-name">safeeyes</property>
41+
<property name="icon-name">io.github.slgobinath.SafeEyes</property>
4242
<child>
4343
<object class="GtkBox" id="layout_box">
4444
<property name="visible">1</property>

safeeyes/glade/break_screen.glade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<interface>
2222
<requires lib="gtk" version="4.0"/>
2323
<object class="GtkWindow" id="window_main">
24-
<property name="icon_name">safeeyes</property>
24+
<property name="icon-name">io.github.slgobinath.SafeEyes</property>
2525
<property name="decorated">0</property>
2626
<property name="deletable">0</property>
2727
<child>

safeeyes/glade/new_break.glade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<property name="default-width">500</property>
4848
<property name="default-height">50</property>
4949
<property name="destroy-with-parent">1</property>
50-
<property name="icon-name">safeeyes</property>
50+
<property name="icon-name">io.github.slgobinath.SafeEyes</property>
5151
<child>
5252
<object class="GtkBox" id="box_settings">
5353
<property name="visible">1</property>

safeeyes/glade/settings_break.glade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<property name="default-width">500</property>
5555
<property name="default-height">50</property>
5656
<property name="destroy-with-parent">1</property>
57-
<property name="icon-name">safeeyes</property>
57+
<property name="icon-name">io.github.slgobinath.SafeEyes</property>
5858
<child>
5959
<object class="GtkBox" id="box_settings">
6060
<property name="visible">1</property>

safeeyes/glade/settings_plugin.glade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<property name="default-width">400</property>
2929
<property name="default-height">10</property>
3030
<property name="destroy-with-parent">1</property>
31-
<property name="icon-name">safeeyes</property>
31+
<property name="icon-name">io.github.slgobinath.SafeEyes</property>
3232
<child>
3333
<object class="GtkBox" id="box_settings">
3434
<property name="visible">1</property>

safeeyes/safeeyes.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ def do_startup(self):
105105
self.context["session"] = {"plugin": {}}
106106

107107
self.break_screen = BreakScreen(
108-
self.context, self.on_skipped, self.on_postponed, utility.STYLE_SHEET_PATH
108+
self,
109+
self.context,
110+
self.on_skipped,
111+
self.on_postponed,
112+
utility.STYLE_SHEET_PATH,
109113
)
110114
self.break_screen.initialize(self.config)
111115
self.plugins_manager = PluginManager()
@@ -193,7 +197,9 @@ def show_settings(self):
193197
if not self.settings_dialog_active:
194198
logging.info("Show Settings dialog")
195199
self.settings_dialog_active = True
196-
settings_dialog = SettingsDialog(self.config.clone(), self.save_settings)
200+
settings_dialog = SettingsDialog(
201+
self, self.config.clone(), self.save_settings
202+
)
197203
settings_dialog.show()
198204

199205
def show_required_plugin_dialog(self, error: RequiredPluginException):
@@ -228,7 +234,7 @@ def show_about(self):
228234
dialog.
229235
"""
230236
logging.info("Show About dialog")
231-
about_dialog = AboutDialog(SAFE_EYES_VERSION)
237+
about_dialog = AboutDialog(self, SAFE_EYES_VERSION)
232238
about_dialog.show()
233239

234240
def quit(self):

safeeyes/ui/about_dialog.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ class AboutDialog:
3333
license and the GitHub url.
3434
"""
3535

36-
def __init__(self, version):
36+
def __init__(self, application, version):
3737
builder = utility.create_gtk_builder(ABOUT_DIALOG_GLADE)
3838
self.window = builder.get_object("window_about")
39+
self.window.set_application(application)
3940

4041
self.window.connect("close-request", self.on_window_delete)
4142
builder.get_object("btn_close").connect("clicked", self.on_close_clicked)

safeeyes/ui/break_screen.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ class BreakScreen:
4343
interface.
4444
"""
4545

46-
def __init__(self, context, on_skipped, on_postponed, style_sheet_path):
46+
def __init__(
47+
self, application, context, on_skipped, on_postponed, style_sheet_path
48+
):
49+
self.application = application
4750
self.context = context
4851
self.count_labels = []
4952
self.x11_display = None
@@ -162,6 +165,7 @@ def __show_break_screen(self, message, image_path, widget, tray_actions):
162165
builder.add_from_file(BREAK_SCREEN_GLADE)
163166

164167
window = builder.get_object("window_main")
168+
window.set_application(self.application)
165169
window.connect("close-request", self.on_window_delete)
166170
window.set_title("SafeEyes-" + str(i))
167171
lbl_message = builder.get_object("lbl_message")

safeeyes/ui/settings_dialog.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
class SettingsDialog:
5555
"""Create and initialize SettingsDialog instance."""
5656

57-
def __init__(self, config, on_save_settings):
57+
def __init__(self, application, config, on_save_settings):
58+
self.application = application
5859
self.config = config
5960
self.on_save_settings = on_save_settings
6061
self.plugin_switches = {}
@@ -67,6 +68,7 @@ def __init__(self, config, on_save_settings):
6768
builder = utility.create_gtk_builder(SETTINGS_DIALOG_GLADE)
6869

6970
self.window = builder.get_object("window_settings")
71+
self.window.set_application(application)
7072
self.box_short_breaks = builder.get_object("box_short_breaks")
7173
self.box_long_breaks = builder.get_object("box_long_breaks")
7274
self.box_plugins = builder.get_object("box_plugins")
@@ -291,7 +293,7 @@ def __create_plugin_item(self, plugin_config):
291293

292294
def __show_plugins_properties_dialog(self, plugin_config):
293295
"""Show the PluginProperties dialog."""
294-
dialog = PluginSettingsDialog(plugin_config)
296+
dialog = PluginSettingsDialog(self.application, plugin_config)
295297
dialog.show()
296298

297299
def __disable_errored_plugin(self, button, plugin_config):
@@ -304,7 +306,14 @@ def __show_break_properties_dialog(
304306
):
305307
"""Show the BreakProperties dialog."""
306308
dialog = BreakSettingsDialog(
307-
break_config, is_short, parent, self.plugin_map, on_close, on_add, on_remove
309+
self.application,
310+
break_config,
311+
is_short,
312+
parent,
313+
self.plugin_map,
314+
on_close,
315+
on_add,
316+
on_remove,
308317
)
309318
dialog.show()
310319

@@ -363,9 +372,10 @@ def on_warn_bar_rpc_server_close(self, warnbar, *user_data):
363372
"""Event handler for warning bar close action."""
364373
self.warn_bar_rpc_server.hide()
365374

366-
def add_break(self, button):
375+
def add_break(self, button) -> None:
367376
"""Event handler for add break button."""
368377
dialog = NewBreakDialog(
378+
self.application,
369379
self.config,
370380
lambda is_short, break_config: self.__create_break_item(
371381
break_config, is_short
@@ -413,12 +423,13 @@ def on_window_delete(self, *args):
413423
class PluginSettingsDialog:
414424
"""Builds a settings dialog based on the configuration of a plugin."""
415425

416-
def __init__(self, config):
426+
def __init__(self, application, config):
417427
self.config = config
418428
self.property_controls = []
419429

420430
builder = utility.create_gtk_builder(SETTINGS_DIALOG_PLUGIN_GLADE)
421431
self.window = builder.get_object("dialog_settings_plugin")
432+
self.window.set_application(application)
422433
box_settings = builder.get_object("box_settings")
423434
self.window.set_title(_("Plugin Settings"))
424435
for setting in config.get("settings"):
@@ -505,6 +516,7 @@ class BreakSettingsDialog:
505516

506517
def __init__(
507518
self,
519+
application,
508520
break_config,
509521
is_short,
510522
parent_config,
@@ -523,6 +535,7 @@ def __init__(
523535

524536
builder = utility.create_gtk_builder(SETTINGS_DIALOG_BREAK_GLADE)
525537
self.window = builder.get_object("dialog_settings_break")
538+
self.window.set_application(application)
526539
self.txt_break = builder.get_object("txt_break")
527540
self.switch_override_interval = builder.get_object("switch_override_interval")
528541
self.switch_override_duration = builder.get_object("switch_override_duration")
@@ -702,12 +715,13 @@ def show(self):
702715
class NewBreakDialog:
703716
"""Builds a new break dialog."""
704717

705-
def __init__(self, parent_config, on_add):
718+
def __init__(self, application, parent_config, on_add):
706719
self.parent_config = parent_config
707720
self.on_add = on_add
708721

709722
builder = utility.create_gtk_builder(SETTINGS_DIALOG_NEW_BREAK_GLADE)
710723
self.window = builder.get_object("dialog_new_break")
724+
self.window.set_application(application)
711725
self.txt_break = builder.get_object("txt_break")
712726
self.cmb_type = builder.get_object("cmb_type")
713727
list_types = builder.get_object("lst_break_types")

0 commit comments

Comments
 (0)