MCPcopy Create free account
hub / github.com/efogdev/mpris-timer / NewTimePicker

Function NewTimePicker

internal/ui/ui.go:69–153  ·  view source on GitHub ↗
(app *adw.Application)

Source from the content-addressed store, hash-verified

67}
68
69func NewTimePicker(app *adw.Application) {
70 core.Overrides.Duration = 0
71 win = adw.NewApplicationWindow(&app.Application)
72 handle := gtk.NewWindowHandle()
73 body := adw.NewOverlaySplitView()
74 handle.SetChild(body)
75
76 escCtrl := gtk.NewEventControllerKey()
77 escCtrl.SetPropagationPhase(gtk.PhaseCapture)
78 escCtrl.ConnectKeyPressed(func(keyval, keycode uint, state gdk.ModifierType) (ok bool) {
79 isEsc := slices.Contains(core.KeyEsc.GdkKeyvals(), keyval)
80 isCtrlQ := slices.Contains(core.KeyQ.GdkKeyvals(), keyval) && state == gdk.ControlMask
81 isCtrlW := slices.Contains(core.KeyW.GdkKeyvals(), keyval) && state == gdk.ControlMask
82 isCtrlD := slices.Contains(core.KeyD.GdkKeyvals(), keyval) && state == gdk.ControlMask
83
84 if !isEsc && !isCtrlQ && !isCtrlW && !isCtrlD {
85 return false
86 }
87
88 saveSize()
89 win.Close()
90 os.Exit(0)
91 return true
92 })
93
94 win.AddController(escCtrl)
95 win.SetContent(handle)
96 win.SetTitle(core.AppName)
97 win.SetSizeRequest(minWidth, getMinHeight())
98
99 // ToDo refactor (at least magic numbers)
100 width, height := int(core.UserPrefs.WindowWidth), int(core.UserPrefs.WindowHeight)
101 if core.BreezeTheme && !core.UserPrefs.RememberWinSize {
102 height -= 32
103 width -= 60
104 }
105
106 win.SetDefaultSize(width, height)
107 win.ConnectCloseRequest(func() (ok bool) {
108 saveSize()
109 return false
110 })
111
112 bp := adw.NewBreakpoint(adw.NewBreakpointConditionLength(adw.BreakpointConditionMaxWidth, collapseWidth, adw.LengthUnitSp))
113 bp.AddSetter(body, "collapsed", true)
114 win.AddBreakpoint(bp)
115
116 body.SetVExpand(true)
117 body.SetHExpand(true)
118
119 if core.UserPrefs.PresetsOnRight {
120 body.SetSidebarPosition(gtk.PackEnd)
121 } else {
122 body.SetSidebarPosition(gtk.PackStart)
123 }
124
125 body.SetContent(NewContent())
126 body.SetSidebar(NewSidebar())

Callers 1

InitFunction · 0.85

Calls 5

saveSizeFunction · 0.85
getMinHeightFunction · 0.85
NewContentFunction · 0.85
NewSidebarFunction · 0.85
GdkKeyvalsMethod · 0.80

Tested by

no test coverage detected