Skip to content

Commit 98d99a6

Browse files
committed
Gtk3Backend: Fix Alert styling, Gtk3 styling is a nightmare...
1 parent 6204808 commit 98d99a6

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

Examples/Package.resolved

Lines changed: 6 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/Gtk3/Utility/CSS/CSSProvider.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ import CGtk3
22

33
/// Swift representation of a Gtk CSS provider
44
public class CSSProvider {
5-
var pointer: UnsafeMutablePointer<GtkCssProvider>
6-
var context: UnsafeMutablePointer<GtkStyleContext>
5+
public var pointer: UnsafeMutablePointer<GtkCssProvider>
6+
var context: UnsafeMutablePointer<GtkStyleContext>?
77

8-
init(
8+
public init() {
9+
pointer = gtk_css_provider_new()
10+
}
11+
12+
public init(
913
forContext context: UnsafeMutablePointer<GtkStyleContext>,
1014
priority: UInt32 = UInt32(GTK_STYLE_PROVIDER_PRIORITY_APPLICATION)
1115
) {
@@ -16,6 +20,10 @@ public class CSSProvider {
1620
}
1721

1822
deinit {
23+
guard let context else {
24+
return
25+
}
26+
1927
gtk_style_context_remove_provider(context, OpaquePointer(pointer))
2028
g_object_unref(context)
2129
}

Sources/Gtk3Backend/Gtk3Backend.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ public final class Gtk3Backend: AppBackend {
6262
gtkApp.run { window in
6363
self.precreatedWindow = window
6464
callback()
65+
66+
let provider = CSSProvider()
67+
provider.loadCss(
68+
from: """
69+
.dialog-vbox .horizontal .vertical {
70+
padding-top: 20px;
71+
margin-bottom: -10px;
72+
}
73+
"""
74+
)
75+
gtk_style_context_add_provider_for_screen(
76+
gdk_screen_get_default(),
77+
OpaquePointer(provider.pointer),
78+
guint(GTK_STYLE_PROVIDER_PRIORITY_APPLICATION)
79+
)
6580
}
6681
}
6782

0 commit comments

Comments
 (0)