Skip to content

Commit

Permalink
Merge pull request #4182 from Jacalz/more-driver-cleanup2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz authored Aug 23, 2023
2 parents 9bd989e + 75dd527 commit 6f3bf59
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 39 deletions.
23 changes: 9 additions & 14 deletions internal/driver/glfw/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (c *glCanvas) reloadScale() {
}

c.Lock()
c.scale = c.context.(*window).calculatedScale()
c.scale = w.calculatedScale()
c.Unlock()
c.SetDirty()

Expand Down Expand Up @@ -237,37 +237,33 @@ func (c *glCanvas) buildMenu(w *window, m *fyne.MainMenu) {
func (c *glCanvas) canvasSize(contentSize fyne.Size) fyne.Size {
canvasSize := contentSize.Add(fyne.NewSize(0, c.menuHeight()))
if c.Padded() {
pad := theme.Padding() * 2
canvasSize = canvasSize.Add(fyne.NewSize(pad, pad))
return canvasSize.Add(fyne.NewSquareSize(theme.Padding() * 2))
}
return canvasSize
}

func (c *glCanvas) contentPos() fyne.Position {
contentPos := fyne.NewPos(0, c.menuHeight())
if c.Padded() {
contentPos = contentPos.Add(fyne.NewPos(theme.Padding(), theme.Padding()))
return contentPos.Add(fyne.NewSquareOffsetPos(theme.Padding()))
}
return contentPos
}

func (c *glCanvas) contentSize(canvasSize fyne.Size) fyne.Size {
contentSize := fyne.NewSize(canvasSize.Width, canvasSize.Height-c.menuHeight())
if c.Padded() {
pad := theme.Padding() * 2
contentSize = contentSize.Subtract(fyne.NewSize(pad, pad))
return contentSize.Subtract(fyne.NewSquareSize(theme.Padding() * 2))
}
return contentSize
}

func (c *glCanvas) menuHeight() float32 {
switch c.menu {
case nil:
// no menu or native menu -> does not consume space on the canvas
return 0
default:
return c.menu.MinSize().Height
if c.menu == nil {
return 0 // no menu or native menu -> does not consume space on the canvas
}

return c.menu.MinSize().Height
}

func (c *glCanvas) overlayChanged() {
Expand Down Expand Up @@ -340,10 +336,9 @@ func (c *glCanvas) applyThemeOutOfTreeObjects() {
}

func newCanvas() *glCanvas {
c := &glCanvas{scale: 1.0, texScale: 1.0}
c := &glCanvas{scale: 1.0, texScale: 1.0, padded: true}
c.Initialize(c, c.overlayChanged)
c.setContent(&canvas.Rectangle{FillColor: theme.BackgroundColor()})
c.padded = true
c.debug = fyne.CurrentApp().Settings().BuildType() == fyne.BuildDebug
return c
}
2 changes: 1 addition & 1 deletion internal/driver/glfw/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (d *gLDriver) Run() {
panic("Run() or ShowAndRun() must be called from main goroutine")
}

go catchTerm(d)
go d.catchTerm()
d.runGL()
}

Expand Down
24 changes: 8 additions & 16 deletions internal/driver/glfw/driver_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,8 @@ func (d *gLDriver) SetSystemTrayMenu(m *fyne.Menu) {
// the only way we know the app was asked to quit is if this window is asked to close...
w := d.CreateWindow("SystrayMonitor")
w.(*window).create()
w.SetCloseIntercept(func() {
d.Quit()
})
w.SetOnClosed(func() {
systray.Quit()
})
w.SetCloseIntercept(d.Quit)
w.SetOnClosed(systray.Quit)
})

d.refreshSystray(m)
Expand Down Expand Up @@ -169,14 +165,12 @@ func (d *gLDriver) CurrentKeyModifiers() fyne.KeyModifier {
return d.currentKeyModifiers
}

func catchTerm(d *gLDriver) {
terminateSignals := make(chan os.Signal, 1)
signal.Notify(terminateSignals, syscall.SIGINT, syscall.SIGTERM)
func (d *gLDriver) catchTerm() {
terminateSignal := make(chan os.Signal, 1)
signal.Notify(terminateSignal, syscall.SIGINT, syscall.SIGTERM)

for range terminateSignals {
d.Quit()
break
}
<-terminateSignal
d.Quit()
}

func addMissingQuitForMenu(menu *fyne.Menu, d *gLDriver) {
Expand All @@ -194,9 +188,7 @@ func addMissingQuitForMenu(menu *fyne.Menu, d *gLDriver) {
}
for _, item := range menu.Items {
if item.IsQuit && item.Action == nil {
item.Action = func() {
d.Quit()
}
item.Action = d.Quit
}
}
}
2 changes: 1 addition & 1 deletion internal/driver/glfw/driver_web.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ func (d *gLDriver) SetSystemTrayMenu(m *fyne.Menu) {
// no-op for mobile apps using this driver
}

func catchTerm(_ *gLDriver) {
func (d *gLDriver) catchTerm() {
}
2 changes: 1 addition & 1 deletion internal/driver/glfw/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (d *gLDriver) runGL() {
func (d *gLDriver) repaintWindow(w *window) {
canvas := w.canvas
w.RunWithContext(func() {
if w.canvas.EnsureMinSize() {
if canvas.EnsureMinSize() {
w.viewLock.Lock()
w.shouldExpand = true
w.viewLock.Unlock()
Expand Down
11 changes: 5 additions & 6 deletions internal/driver/glfw/menu_bar.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ func (b *MenuBar) Toggle() {
}

func (b *MenuBar) activateChild(item *menuBarItem) {
if !b.active {
b.active = true
}
b.active = true
if item.Child() != nil {
item.Child().DeactivateChild()
}
Expand Down Expand Up @@ -142,13 +140,14 @@ func (r *menuBarRenderer) Layout(size fyne.Size) {
} else {
r.underlay.Resize(fyne.NewSize(0, 0))
}
r.cont.Resize(fyne.NewSize(size.Width-2*theme.InnerPadding(), size.Height))
r.cont.Move(fyne.NewPos(theme.InnerPadding(), 0))
innerPadding := theme.InnerPadding()
r.cont.Resize(fyne.NewSize(size.Width-2*innerPadding, size.Height))
r.cont.Move(fyne.NewPos(innerPadding, 0))
if item := r.b.activeItem; item != nil {
if item.Child().Size().IsZero() {
item.Child().Resize(item.Child().MinSize())
}
item.Child().Move(fyne.NewPos(item.Position().X+theme.InnerPadding(), item.Size().Height))
item.Child().Move(fyne.NewPos(item.Position().X+innerPadding, item.Size().Height))
}
r.background.Resize(size)
}
Expand Down

0 comments on commit 6f3bf59

Please sign in to comment.