Skip to content

Commit

Permalink
Added cursor hiding, Fixed fullscreen sync, fixed ui resizing, Update…
Browse files Browse the repository at this point in the history
…d gotk3

Now during periods of inactivity, while in fullscreen, the mouse cursor
will be hidden along with the HUD. The idea is to reduce distractions in
fullscreen.

Fixed fullscreen state sometimes getting out-of-sync. This could happen
if your Window Manager has a mechanism (like a hot-key) for making a
window fullscreen. Internally the toggleFullscreen message was replaced
with setFullscreen. A new window-state-event was added and cbxv commands
now just set the window to Fullscreen or non-Fullscreen. The change in ui
state, regardless of the cause, is caught in the window-state-event and
the setFullscreen message is sent internally to update the model's
fullscreen state.

Fixed ui (header and nav) refusing to resize when no book was open. This
was mainly cosmetic as there's almost nothing for these components to do
when no book is open, but it was ugly.

Updated gotk3 dependency to get the latest improvements.
  • Loading branch information
mftb0 committed Feb 16, 2024
1 parent 95ed0a9 commit 7131beb
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd/cbxv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/cbxv/messagehandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
1 change: 0 additions & 1 deletion internal/ui/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions internal/ui/pageview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
})

Expand Down
10 changes: 2 additions & 8 deletions internal/ui/pageviewnavcontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

Expand Down Expand Up @@ -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("")
Expand Down
10 changes: 10 additions & 0 deletions internal/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 7131beb

Please sign in to comment.