6
6
7
7
from .keys import gtk_accel
8
8
from .libs import (
9
+ GTK_VERSION ,
9
10
IS_WAYLAND ,
10
11
TOGA_DEFAULT_STYLES ,
11
12
Gdk ,
@@ -34,7 +35,7 @@ def __init__(self, interface):
34
35
# Stimulate the build of the app
35
36
self .native = Gtk .Application (
36
37
application_id = self .interface .app_id ,
37
- flags = Gio .ApplicationFlags .FLAGS_NONE ,
38
+ flags = Gio .ApplicationFlags .DEFAULT_FLAGS ,
38
39
)
39
40
self .native_about_dialog = None
40
41
@@ -53,12 +54,20 @@ def gtk_startup(self, data=None):
53
54
54
55
# Set any custom styles
55
56
css_provider = Gtk .CssProvider ()
56
- css_provider .load_from_data (TOGA_DEFAULT_STYLES )
57
57
58
- context = Gtk .StyleContext ()
59
- context .add_provider_for_screen (
60
- Gdk .Screen .get_default (), css_provider , Gtk .STYLE_PROVIDER_PRIORITY_USER
61
- )
58
+ if GTK_VERSION < (4 , 0 , 0 ): # pragma: no-cover-if-gtk4
59
+ css_provider .load_from_data (TOGA_DEFAULT_STYLES )
60
+ context = Gtk .StyleContext ()
61
+ context .add_provider_for_screen (
62
+ Gdk .Screen .get_default (), css_provider , Gtk .STYLE_PROVIDER_PRIORITY_USER
63
+ )
64
+ elif GTK_VERSION >= (4 , 12 , 0 ): # pragma: no-cover-if-gtk3
65
+ css_provider .load_from_string (TOGA_DEFAULT_STYLES )
66
+ elif GTK_VERSION >= (4 , 8 , 0 ): # pragma: no-cover-if-gtk3
67
+ css_provider .load_from_data (TOGA_DEFAULT_STYLES , len (TOGA_DEFAULT_STYLES ))
68
+ else : # pragma: no-cover-if-gtk3
69
+ # Earlier than GTK 4.8
70
+ css_provider .load_from_data (TOGA_DEFAULT_STYLES .encode ("utf-8" ))
62
71
63
72
######################################################################
64
73
# Commands and menus
@@ -173,20 +182,24 @@ def set_main_window(self, window):
173
182
174
183
def get_screens (self ):
175
184
display = Gdk .Display .get_default ()
176
- if IS_WAYLAND : # pragma: no-cover-if-linux-x
177
- # `get_primary_monitor()` doesn't work on wayland, so return as it is.
178
- return [
179
- ScreenImpl (native = display .get_monitor (i ))
180
- for i in range (display .get_n_monitors ())
181
- ]
182
- else : # pragma: no-cover-if-linux-wayland
183
- primary_screen = ScreenImpl (display .get_primary_monitor ())
184
- screen_list = [primary_screen ] + [
185
- ScreenImpl (native = display .get_monitor (i ))
186
- for i in range (display .get_n_monitors ())
187
- if display .get_monitor (i ) != primary_screen .native
188
- ]
189
- return screen_list
185
+ if GTK_VERSION < (4 , 0 , 0 ): # pragma: no-cover-if-gtk4
186
+ if IS_WAYLAND : # pragma: no-cover-if-linux-x
187
+ # `get_primary_monitor()` doesn't work on wayland, so return as it is.
188
+ return [
189
+ ScreenImpl (native = display .get_monitor (i ))
190
+ for i in range (display .get_n_monitors ())
191
+ ]
192
+
193
+ else : # pragma: no-cover-if-linux-wayland
194
+ primary_screen = ScreenImpl (display .get_primary_monitor ())
195
+ screen_list = [primary_screen ] + [
196
+ ScreenImpl (native = display .get_monitor (i ))
197
+ for i in range (display .get_n_monitors ())
198
+ if display .get_monitor (i ) != primary_screen .native
199
+ ]
200
+ return screen_list
201
+ else : # pragma: no-cover-if-gtk3
202
+ return [ScreenImpl (native = monitor ) for monitor in display .get_monitors ()]
190
203
191
204
######################################################################
192
205
# App state
@@ -201,7 +214,10 @@ def get_dark_mode_state(self):
201
214
######################################################################
202
215
203
216
def beep (self ):
204
- Gdk .beep ()
217
+ if GTK_VERSION < (4 , 0 , 0 ): # pragma: no-cover-if-gtk4
218
+ Gdk .beep ()
219
+ else : # pragma: no-cover-if-gtk3
220
+ Gdk .Display .get_default ().beep ()
205
221
206
222
def _close_about (self , dialog , * args , ** kwargs ):
207
223
self .native_about_dialog .destroy ()
0 commit comments