Skip to content

Commit

Permalink
Drop various unsupported glfw calls on Wayland
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Dec 23, 2023
1 parent 5680ae7 commit 1d2c0c9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
11 changes: 8 additions & 3 deletions internal/driver/glfw/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/internal/app"
"fyne.io/fyne/v2/internal/build"
"fyne.io/fyne/v2/internal/cache"
"fyne.io/fyne/v2/internal/driver"
"fyne.io/fyne/v2/internal/driver/common"
Expand Down Expand Up @@ -148,13 +149,15 @@ func (w *window) doShow() {
view := w.view()
view.SetTitle(w.title)

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

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

if w.fullScreen { // this does not work if called before viewport.Show()
go func() {
Expand Down Expand Up @@ -973,7 +976,9 @@ func (w *window) doShowAgain() {
}

view := w.view()
view.SetPos(w.xpos, w.ypos)
if !build.IsWayland {
view.SetPos(w.xpos, w.ypos)
}
view.Show()
w.viewLock.Lock()
w.visible = true
Expand Down
40 changes: 25 additions & 15 deletions internal/driver/glfw/window_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ func (w *window) SetFullScreen(full bool) {
}

func (w *window) CenterOnScreen() {
if build.IsWayland {
return
}

w.centered = true

if w.view() != nil {
Expand Down Expand Up @@ -192,6 +196,10 @@ func (w *window) RequestFocus() {

func (w *window) SetIcon(icon fyne.Resource) {
w.icon = icon
if build.IsWayland {
return
}

if icon == nil {
appIcon := fyne.CurrentApp().Icon()
if appIcon != nil {
Expand Down Expand Up @@ -265,24 +273,26 @@ func (w *window) fitContent() {
}

func (w *window) getMonitorForWindow() *glfw.Monitor {
x, y := w.xpos, w.ypos
if w.fullScreen {
x, y = w.viewport.GetPos()
}
xOff := x + (w.width / 2)
yOff := y + (w.height / 2)
if !build.IsWayland {
x, y := w.xpos, w.ypos
if w.fullScreen {
x, y = w.viewport.GetPos()
}
xOff := x + (w.width / 2)
yOff := y + (w.height / 2)

for _, monitor := range glfw.GetMonitors() {
x, y := monitor.GetPos()
for _, monitor := range glfw.GetMonitors() {
x, y := monitor.GetPos()

if x > xOff || y > yOff {
continue
}
if videoMode := monitor.GetVideoMode(); x+videoMode.Width <= xOff || y+videoMode.Height <= yOff {
continue
}
if x > xOff || y > yOff {
continue
}
if videoMode := monitor.GetVideoMode(); x+videoMode.Width <= xOff || y+videoMode.Height <= yOff {
continue
}

return monitor
return monitor
}
}

// try built-in function to detect monitor if above logic didn't succeed
Expand Down

0 comments on commit 1d2c0c9

Please sign in to comment.