diff --git a/cmd/cbxv/main.go b/cmd/cbxv/main.go index 78fd64e..e616587 100644 --- a/cmd/cbxv/main.go +++ b/cmd/cbxv/main.go @@ -28,7 +28,7 @@ func update(m *model.Model, u *ui.UI, msgChan chan util.Message, msgHandlers *Me (msg.TypeName != "quit" && msg.TypeName != "openFile" && msg.TypeName != "openFileResult" && - msg.TypeName != "toggleFullscreen") { + msg.TypeName != "setFullscreen") { continue } diff --git a/cmd/cbxv/messagehandlers.go b/cmd/cbxv/messagehandlers.go index ca9e29c..2b55bd8 100644 --- a/cmd/cbxv/messagehandlers.go +++ b/cmd/cbxv/messagehandlers.go @@ -120,11 +120,11 @@ func NewMessageHandlers(m *model.Model, u *ui.UI) *MessageHandlerList { handlers.List["leftPage"] = r } - handlers.List["toggleFullscreen"] = func(data string) { - if m.Fullscreen == true { - m.Fullscreen = false - } else { + handlers.List["setFullscreen"] = func(data string) { + if data == "true" { m.Fullscreen = true + } else { + m.Fullscreen = false } } diff --git a/internal/ui/commands.go b/internal/ui/commands.go index 7c9f718..f96021c 100644 --- a/internal/ui/commands.go +++ b/internal/ui/commands.go @@ -129,7 +129,6 @@ func NewCommands(m *model.Model, u *UI) *CommandList { } else { u.MainWindow.Fullscreen() } - u.SendMessage(util.Message{TypeName: "toggleFullscreen"}) })) AddCommand(cmds, NewCommand("openFile", "Open File", diff --git a/internal/ui/pageview.go b/internal/ui/pageview.go index cd2bcca..dbfe68f 100644 --- a/internal/ui/pageview.go +++ b/internal/ui/pageview.go @@ -131,6 +131,9 @@ func (v *PageView) initRenderer(m *model.Model) { util.Log("w:%d,h:%d\n", int64(x2-x1), int64(y2-y1)) cr.Rectangle(x1, y1, x2, y2) cr.Fill() + w := v.hud.GetAllocatedWidth() - 40 + v.hdrControl.container.SetSizeRequest(w, 8) + v.navControl.container.SetSizeRequest(w, 8) if m.Spreads == nil { return false } @@ -145,9 +148,6 @@ func (v *PageView) initRenderer(m *model.Model) { renderOnePageSpread(s) } } - w := v.hud.GetAllocatedWidth() - 40 - v.hdrControl.container.SetSizeRequest(w, 8) - v.navControl.container.SetSizeRequest(w, 8) return true }) diff --git a/internal/ui/pageviewnavcontrol.go b/internal/ui/pageviewnavcontrol.go index 11da70b..ae7c411 100644 --- a/internal/ui/pageviewnavcontrol.go +++ b/internal/ui/pageviewnavcontrol.go @@ -109,11 +109,6 @@ func NewNavControl(m *model.Model, u *UI) *PageViewNavControl { }) fsc.Connect("clicked", func() { - if m.Fullscreen { - u.MainWindow.Unfullscreen() - } else { - u.MainWindow.Fullscreen() - } u.Commands.Names["toggleFullscreen"].Execute() }) @@ -181,10 +176,9 @@ func (c *PageViewNavControl) Render(m *model.Model) { } if m.Fullscreen { - c.container.SetSizeRequest(1400, 8) - c.fullscreenControl.SetLabel(util.FullscreenIcon()) - } else { c.fullscreenControl.SetLabel(util.RestoreIcon()) + } else { + c.fullscreenControl.SetLabel(util.FullscreenIcon()) } c.rightPageNum.SetLabel("") diff --git a/internal/ui/ui.go b/internal/ui/ui.go index c974f8c..464810b 100644 --- a/internal/ui/ui.go +++ b/internal/ui/ui.go @@ -37,6 +37,16 @@ func NewUI(m *model.Model, messenger util.Messenger) *UI { u.Commands.Names["quit"].Execute() return true }) + u.MainWindow.Connect("window-state-event", func(w *gtk.Window, event *gdk.Event) bool { + ev := gdk.EventWindowStateNewFromEvent(event) + if ev.ChangedMask() & ev.NewWindowState() == gdk.WINDOW_STATE_FULLSCREEN { + u.SendMessage(util.Message{TypeName: "setFullscreen", Data: "true"}) + } else { + u.SendMessage(util.Message{TypeName: "setFullscreen", Data: "false"}) + } + return true + }) + u.MainWindow.SetDefaultSize(1024, 768) iPath := util.AppIconPath()