Bugfix: Window focus linked list

It used to be possible to confuse the window manager in the
CloseActiveWindow() function and the linked list got all broken. Seems
more reliable now! Added function PrintWindows() to inspect the linked
lists.
This commit is contained in:
Noah 2022-02-19 20:14:52 -08:00
parent 49b5cfd037
commit 76ddda352d
2 changed files with 36 additions and 8 deletions

View File

@ -87,7 +87,6 @@ type Supervisor struct {
// List of window focus history for Window Manager.
winFocus *FocusedWindow
winTop *FocusedWindow // pointer to top-most window
winBottom *FocusedWindow // pointer to bottom-most window
}

View File

@ -66,7 +66,6 @@ func (s *Supervisor) addWindow(win *Window) {
s.winFocus = &FocusedWindow{
window: win,
}
s.winTop = s.winFocus
s.winBottom = s.winFocus
win.SetFocus(true)
} else {
@ -138,7 +137,6 @@ func (s *Supervisor) FocusWindow(win *Window) error {
s.winFocus = target
// Fix the top and bottom pointers.
s.winTop = s.winFocus
if newBottom != nil {
s.winBottom = newBottom
}
@ -184,13 +182,44 @@ func (s *Supervisor) CloseAllWindows() int {
func (s *Supervisor) CloseActiveWindow() bool {
var node = s.winFocus
if node != nil {
node.window.Destroy()
node.window.Hide()
s.winFocus = node.next
s.winFocus.window.SetFocus(true)
}
// Find the next visible window to focus.
for node != nil {
if !node.window.Hidden() {
s.FocusWindow(node.window)
break
}
node = node.next
}
return true
}
return false
// PrintWindows is a debug function that walks the window tree and prints them to your console.
func (s *Supervisor) PrintWindows() {
var (
node = s.winBottom
i int
)
fmt.Println("From the bottom:")
for node != nil {
i++
fmt.Printf("%d. %s focused=%+v hidden=%+v\n", i, node.window, node.window.Focused(), node.window.Hidden())
node = node.prev
}
node = s.winFocus
i = 0
fmt.Println("Focus order:")
for node != nil {
i++
fmt.Printf("%d. %s focused=%+v hidden=%+v\n", i, node.window, node.window.Focused(), node.window.Hidden())
node = node.next
}
}
// presentWindows draws the windows from bottom to top.