Search code examples
windowsgofyne

Show/Move main window at custom position


Problem

I can't find function to set position of the window. I'v looked into code and I see SetPos func for different elements and wondering why it's not added for fyne.Window type.

func main() {
    a := app.New()
    w := a.NewWindow("Trying to position window")

    if drv, ok := fyne.CurrentApp().Driver().(desktop.Driver); ok {
        w = drv.CreateSplashWindow()
        // something like this?
        // w.SetPos(x, y)  
        // w.Move(x, y)    
    }

Workaround

I forked project and created func:

func (w *window) GLFWindow() *glfw.Window {
    return w.view()
}  

to expose unexported underlying window attribute w.viewport. and it unlocks bunch of methods i can use now

if ww := w.GLFWindow(); ww != nil {
    ww.SetPos(x, y)
}

It looks I'm gonna use it (forked/edited version) but maybe you can suggest fyne-way to do it :)

Question

Is there existing way to set position of the window? Or access underlying w.viewport attribute?


Solution

  • This is not possible with the exported API, because many OS do not support it. See discussion about the decision process at https://github.com/fyne-io/fyne/issues/1155