Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/driver/embedded/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ func (w *noosWindow) Show() {
w.d.renderWindow(w)
}

func (w *noosWindow) ShowAtPos(xPos int, yPos int) {
w.Show()
}

func (w *noosWindow) Hide() {}

func (w *noosWindow) Close() {
Expand Down
26 changes: 23 additions & 3 deletions internal/driver/glfw/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (w *window) detectTextureScale() float32 {
return float32(texWidth) / float32(winWidth)
}

func (w *window) Show() {
func (w *window) show(xPos int, yPos int) {
async.EnsureMain(func() {
if w.view() != nil {
w.doShowAgain()
Expand All @@ -154,14 +154,18 @@ func (w *window) Show() {
view := w.view()
view.SetTitle(w.title)

if xPos != 0 || yPos != 0 {
view.SetPos(xPos, yPos)
}

if !build.IsWayland && w.centered {
w.doCenterOnScreen() // lastly center if that was requested

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that "center on screen" and "show on external monitor" (this PR) conflict. We need to be describing monitors not x/y so that one does not override another.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit addresses this concern. Request for "Center on screencallswindow.getMonitorForWindow. If w.xposandw.ypos` and set before the request for "center on screen", the correct monitor will be resolved and the window centered on the correct monitor.

https://github.com/ndianabasi/fyne/blob/33adf8a39c5c8b71d8df4b631ad3819413034dd9/internal/driver/glfw/window_desktop.go#L282-L314

}
view.Show()

// save coordinates
if !build.IsWayland {
w.xpos, w.ypos = view.GetPos()
if !build.IsWayland || xPos != 0 || yPos != 0 {
w.xpos, w.ypos = xPos, yPos
}

if w.fullScreen { // this does not work if called before viewport.Show()
Expand All @@ -177,6 +181,22 @@ func (w *window) Show() {
})
}

func (w *window) Show() {
xPos, yPos := 0, 0

view := w.view()
if view != nil && !build.IsWayland {
xPos, yPos = view.GetPos()
}

w.show(xPos, yPos)
}

func (w *window) ShowAtPos(xPos int, yPos int) {
println("calling ShowAtPos")
Comment thread
ndianabasi marked this conversation as resolved.
Outdated
w.show(xPos, yPos)
}

func (w *window) Hide() {
async.EnsureMain(func() {
if w.closing || w.viewport == nil {
Expand Down
4 changes: 4 additions & 0 deletions internal/driver/mobile/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ func (w *window) Show() {
}
}

func (w *window) ShowAtPos(xPos int, yPos int) {
w.Show()
}

func (w *window) Hide() {
w.visible = false

Expand Down
4 changes: 4 additions & 0 deletions test/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ func (w *window) Show() {
w.RequestFocus()
}

func (w *window) ShowAtPos(xPos int, yPos int) {
w.RequestFocus()
}

func (w *window) ShowAndRun() {
w.Show()
}
Expand Down
3 changes: 3 additions & 0 deletions window.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ type Window interface {

// Show the window on screen.
Show()
// Show the window on screen at a position.
// Since 2.7

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.7 has already been released - 2.8 is next

ShowAtPos(int, int)
// Hide the window from the user.
// This will not destroy the window or cause the app to exit.
Hide()
Expand Down
Loading