forked from coyim/coyim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
display_settings.go
88 lines (73 loc) · 1.95 KB
/
display_settings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package gui
import (
"fmt"
"github.com/twstrike/coyim/Godeps/_workspace/src/github.com/twstrike/gotk3adapter/gtki"
"github.com/twstrike/coyim/Godeps/_workspace/src/github.com/twstrike/gotk3adapter/pangoi"
)
type displaySettings struct {
fontSize uint
defaultFontSize uint
provider gtki.CssProvider
}
func (ds *displaySettings) defaultSettingsOn(w gtki.Widget) {
doInUIThread(func() {
styleContext, _ := w.GetStyleContext()
styleContext.AddProvider(ds.provider, 9999)
})
}
func (ds *displaySettings) unifiedBackgroundColor(w gtki.Widget) {
doInUIThread(func() {
styleContext, _ := w.GetStyleContext()
styleContext.AddProvider(ds.provider, 9999)
styleContext.AddClass("currentBackgroundColor")
})
}
func (ds *displaySettings) control(w gtki.Widget) {
doInUIThread(func() {
styleContext, _ := w.GetStyleContext()
styleContext.AddProvider(ds.provider, 9999)
styleContext.AddClass("currentFontSetting")
})
}
func (ds *displaySettings) increaseFontSize() {
ds.fontSize++
ds.update()
}
func (ds *displaySettings) decreaseFontSize() {
ds.fontSize--
ds.update()
}
func (ds *displaySettings) update() {
css := fmt.Sprintf(`
* {
-GtkCheckMenuItem-indicator-size: 16;
}
.currentFontSetting {
font-size: %dpx;
}
.currentBackgroundColor {
background-color: #fff;
}
`, ds.defaultFontSize, ds.fontSize)
doInUIThread(func() {
ds.provider.LoadFromData(css)
})
}
func newDisplaySettings() *displaySettings {
ds := &displaySettings{}
prov, _ := g.gtk.CssProviderNew()
ds.provider = prov
ds.defaultFontSize = 12
return ds
}
func getFontSizeFrom(w gtki.Widget) uint {
styleContext, _ := w.GetStyleContext()
property, _ := styleContext.GetProperty2("font", gtki.STATE_FLAG_NORMAL)
fontDescription := property.(pangoi.FontDescription)
return uint(fontDescription.GetSize() / pangoi.PANGO_SCALE)
}
func detectCurrentDisplaySettingsFrom(w gtki.Widget) *displaySettings {
ds := newDisplaySettings()
ds.fontSize = getFontSizeFrom(w)
return ds
}