Skip to content

Commit 3c81d6e

Browse files
committed
Change text cursor color and progress bar bg color based on color scheme
1 parent 0b56815 commit 3c81d6e

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

Sources/Gtk/Datatypes/Color.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ public struct Color: Equatable {
1818
self.alpha = alpha
1919
}
2020

21+
public static func eightBit(
22+
_ red: UInt8,
23+
_ green: UInt8,
24+
_ blue: UInt8,
25+
_ alpha: UInt8 = 255
26+
) -> Color {
27+
Color(
28+
Float(red) / 255,
29+
Float(green) / 255,
30+
Float(blue) / 255,
31+
Float(alpha) / 255
32+
)
33+
}
34+
2135
public var gdkColor: GdkRGBA {
2236
return GdkRGBA(red: red, green: green, blue: blue, alpha: alpha)
2337
}

Sources/Gtk3/Utility/CSS/CSSProperty.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public struct CSSProperty: Equatable {
2222
CSSProperty(key: "background", value: rgba(color))
2323
}
2424

25+
public static func caretColor(_ color: Color) -> CSSProperty {
26+
CSSProperty(key: "caret-color", value: rgba(color))
27+
}
28+
2529
public static func lineLimit(_ limit: Int) -> CSSProperty {
2630
CSSProperty(key: "max-lines", value: "\(limit)")
2731
}

Sources/Gtk3/Widgets/Widget.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ open class Widget: GObject {
1919
didMoveToParent()
2020
} else {
2121
didMoveFromParent()
22-
removeSignals()
2322
}
2423
}
2524
}

Sources/Gtk3Backend/Gtk3Backend.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,9 +963,11 @@ public final class Gtk3Backend: AppBackend {
963963
case .light:
964964
properties.append(.border(color: Color.eightBit(209, 209, 209), width: 1))
965965
properties.append(.backgroundColor(Color(1, 1, 1, 1)))
966+
properties.append(.caretColor(Color.eightBit(139, 142, 143)))
966967
case .dark:
967968
properties.append(.border(color: Color.eightBit(32, 32, 32), width: 1))
968969
properties.append(.backgroundColor(Color(1, 1, 1, 0.1)))
970+
properties.append(.caretColor(Color(1, 1, 1)))
969971
}
970972
properties.append(.init(key: "box-shadow", value: "none"))
971973
}

Sources/GtkBackend/GtkBackend.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public final class GtkBackend: AppBackend {
5252
flags: G_APPLICATION_HANDLES_OPEN
5353
)
5454
gtkApp.registerSession = true
55-
print(appIdentifier)
5655
}
5756

5857
public func runMainLoop(_ callback: @escaping () -> Void) {
@@ -721,6 +720,20 @@ public final class GtkBackend: AppBackend {
721720
) {
722721
let progressBar = widget as! ProgressBar
723722
progressBar.fraction = progressFraction ?? 0
723+
let backgroundColor: Gtk.Color
724+
switch environment.colorScheme {
725+
case .light:
726+
backgroundColor = Gtk.Color.eightBit(61, 61, 61, 38)
727+
case .dark:
728+
backgroundColor = Gtk.Color.eightBit(90, 90, 90)
729+
}
730+
progressBar.cssProvider.loadCss(
731+
from: """
732+
trough {
733+
background-color: \(CSSProperty.rgba(backgroundColor));
734+
}
735+
"""
736+
)
724737
}
725738

726739
public func createPopoverMenu() -> PopoverMenu {

0 commit comments

Comments
 (0)