Rewrite gtkplayer entry cleanly

This commit is contained in:
Stu 2025-12-13 21:46:59 -05:00
parent a4653dd116
commit 2e4b433f01

View File

@ -34,13 +34,11 @@ func main() {
grid.SetRowHomogeneous(false) grid.SetRowHomogeneous(false)
win.Add(grid) win.Add(grid)
// Two panes for compare; left/right
left := newPane() left := newPane()
right := newPane() right := newPane()
controls := buildControls(win, left, right) controls := buildControls(win, left, right)
grid.Attach(controls, 0, 0, 2, 1) grid.Attach(controls, 0, 0, 2, 1)
grid.Attach(left.area, 0, 1, 1, 1) grid.Attach(left.area, 0, 1, 1, 1)
grid.Attach(right.area, 1, 1, 1, 1) grid.Attach(right.area, 1, 1, 1, 1)
@ -73,6 +71,7 @@ func newPane() *pane {
return return
} }
p.mpv = mpv p.mpv = mpv
if w, ok := da.GetWindow(); ok && w != nil { if w, ok := da.GetWindow(); ok && w != nil {
if xid := getWindowID(w); xid != 0 { if xid := getWindowID(w); xid != 0 {
_ = mpv.SetWID(xid) _ = mpv.SetWID(xid)
@ -90,7 +89,6 @@ func buildControls(win *gtk.Window, left, right *pane) *gtk.Box {
box, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 6) box, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 6)
row1, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 4) row1, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 4)
row2, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 4) row2, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 4)
row3, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 4)
openL, _ := gtk.ButtonNewWithLabel("Open Left") openL, _ := gtk.ButtonNewWithLabel("Open Left")
openR, _ := gtk.ButtonNewWithLabel("Open Right") openR, _ := gtk.ButtonNewWithLabel("Open Right")
@ -145,7 +143,6 @@ func buildControls(win *gtk.Window, left, right *pane) *gtk.Box {
} }
}) })
// Poll meta/progress
go func() { go func() {
t := time.NewTicker(500 * time.Millisecond) t := time.NewTicker(500 * time.Millisecond)
defer t.Stop() defer t.Stop()
@ -167,7 +164,6 @@ func buildControls(win *gtk.Window, left, right *pane) *gtk.Box {
box.PackStart(row1, false, false, 0) box.PackStart(row1, false, false, 0)
box.PackStart(row2, false, false, 0) box.PackStart(row2, false, false, 0)
box.PackStart(row3, false, false, 0)
return box return box
} }
@ -209,16 +205,14 @@ func metaSummary(a, b *pane) string {
// getWindowID returns the native window handle (XID on X11, HWND on Windows). // getWindowID returns the native window handle (XID on X11, HWND on Windows).
func getWindowID(w *gdk.Window) uint64 { func getWindowID(w *gdk.Window) uint64 {
// X11 if w == nil {
if xid := gdkWindowGetXID(w); xid != 0 { return 0
return uint64(xid)
} }
// TODO: add Windows handle if needed. return uint64(gdkWindowGetXID(w))
return 0
} }
// gdkWindowGetXID extracts the XID from a GDK window when running on X11. // gdkWindowGetXID extracts the XID from a GDK window when running on X11.
func gdkWindowGetXID(w *gdk.Window) uint { func gdkWindowGetXID(w *gdk.Window) uint {
// gotk3 provides this method on GDK windows under X11
return uint(w.GetXID()) return uint(w.GetXID())
} }