detached 5a09059

fix(theme): read GNOME color-scheme setting for dark mode detection

commit
5a09059fc360dcfbeec0accfe13bd473f52e5682
author
bnema · · 2025-10-23 20:57 UTC
parent
e58fb06
signature
GPG Unverified2B82207D370127A0 The key is unknown
1 file · +13 -2
M pkg/webkit/helpers.go +13 -2
@@ -2,6 +2,7 @@ package webkit
22
33 import (
44 "github.com/diamondburned/gotk4/pkg/gdk/v4"
5+ "github.com/diamondburned/gotk4/pkg/gio/v2"
56 "github.com/diamondburned/gotk4/pkg/glib/v2"
67 "github.com/diamondburned/gotk4/pkg/gtk/v4"
78 )
@@ -239,10 +240,20 @@ func WidgetAllocation(w gtk.Widgetter) (x, y, width, height int) {
239240
240241 // PrefersDarkTheme checks if the system prefers dark theme
241242 func PrefersDarkTheme() bool {
243+ // First try to read GNOME's color-scheme setting (GTK4+)
244+ if gnomeSettings := gio.NewSettings("org.gnome.desktop.interface"); gnomeSettings != nil {
245+ colorScheme := gnomeSettings.String("color-scheme")
246+ if colorScheme == "prefer-dark" {
247+ return true
248+ }
249+ if colorScheme == "prefer-light" {
250+ return false
251+ }
252+ }
253+
254+ // Fallback to GTK's application-level preference
242255 settings := gtk.SettingsGetDefault()
243256 if settings != nil {
244- // In GTK4, check the color scheme preference
245- // The property is "gtk-application-prefer-dark-theme"
246257 obj := settings.Object
247258 if obj != nil {
248259 prop := obj.ObjectProperty("gtk-application-prefer-dark-theme")
@@ -2,6 +2,7 @@ package webkit
2 2
3 import (3 import (
4 "github.com/diamondburned/gotk4/pkg/gdk/v4"4 "github.com/diamondburned/gotk4/pkg/gdk/v4"
5+ "github.com/diamondburned/gotk4/pkg/gio/v2"
5 "github.com/diamondburned/gotk4/pkg/glib/v2"6 "github.com/diamondburned/gotk4/pkg/glib/v2"
6 "github.com/diamondburned/gotk4/pkg/gtk/v4"7 "github.com/diamondburned/gotk4/pkg/gtk/v4"
7 )8 )
@@ -239,10 +240,20 @@ func WidgetAllocation(w gtk.Widgetter) (x, y, width, height int) {
239 240
240 // PrefersDarkTheme checks if the system prefers dark theme241 // PrefersDarkTheme checks if the system prefers dark theme
241 func PrefersDarkTheme() bool {242 func PrefersDarkTheme() bool {
243+ // First try to read GNOME's color-scheme setting (GTK4+)
244+ if gnomeSettings := gio.NewSettings("org.gnome.desktop.interface"); gnomeSettings != nil {
245+ colorScheme := gnomeSettings.String("color-scheme")
246+ if colorScheme == "prefer-dark" {
247+ return true
248+ }
249+ if colorScheme == "prefer-light" {
250+ return false
251+ }
252+ }
253+
254+ // Fallback to GTK's application-level preference
242 settings := gtk.SettingsGetDefault()255 settings := gtk.SettingsGetDefault()
243 if settings != nil {256 if settings != nil {
244- // In GTK4, check the color scheme preference
245- // The property is "gtk-application-prefer-dark-theme"
246 obj := settings.Object257 obj := settings.Object
247 if obj != nil {258 if obj != nil {
248 prop := obj.ObjectProperty("gtk-application-prefer-dark-theme")259 prop := obj.ObjectProperty("gtk-application-prefer-dark-theme")

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close