main 5041353

detector_adwaita.go RawHistoryFolder

1package colorscheme
2
3import (
4	"sync/atomic"
5
6	"github.com/bnema/puregotk/v4/adw"
7)
8
9const (
10	detectorNameAdwaita = "libadwaita"
11	priorityAdwaita     = 100
12)
13
14// AdwaitaDetector detects color scheme from libadwaita's StyleManager.
15// This is the most accurate detector after adw.Init() has been called,
16// as it reflects the same state that WebKit uses for prefers-color-scheme.
17type AdwaitaDetector struct {
18	available atomic.Bool
19}
20
21// NewAdwaitaDetector creates a new libadwaita-based detector.
22// Initially unavailable until MarkAvailable() is called after adw.Init().
23func NewAdwaitaDetector() *AdwaitaDetector {
24	return &AdwaitaDetector{}
25}
26
27// Name implements port.ColorSchemeDetector.
28func (*AdwaitaDetector) Name() string {
29	return detectorNameAdwaita
30}
31
32// Priority implements port.ColorSchemeDetector.
33func (*AdwaitaDetector) Priority() int {
34	return priorityAdwaita
35}
36
37// Available implements port.ColorSchemeDetector.
38// Returns true only after MarkAvailable() has been called.
39func (d *AdwaitaDetector) Available() bool {
40	return d.available.Load()
41}
42
43// MarkAvailable should be called after adw.Init() completes.
44// This enables the detector to query StyleManager.
45func (d *AdwaitaDetector) MarkAvailable() {
46	d.available.Store(true)
47}
48
49// Detect implements port.ColorSchemeDetector.
50// Queries libadwaita's StyleManager for the dark mode preference.
51func (d *AdwaitaDetector) Detect() (prefersDark, ok bool) {
52	if !d.Available() {
53		return false, false
54	}
55
56	styleMgr := adw.StyleManagerGetDefault()
57	if styleMgr == nil {
58		return false, false
59	}
60
61	return styleMgr.GetDark(), true
62}

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