Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app: add support to hidden minimize and maximize buttons on macos and … #143

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ type Config struct {
CustomRenderer bool
// Decorated reports whether window decorations are provided automatically.
Decorated bool

// HiddenMinimizeButton hide the window's minimize button (only works for windows and macOS)
HiddenMinimizeButton bool
// HiddenMaximizeButton hide the window's maximize button (only works for windows and macOS)
HiddenMaximizeButton bool

// Focused reports whether has the keyboard focus.
Focused bool
// decoHeight is the height of the fallback decoration for platforms such
Expand Down Expand Up @@ -176,6 +182,8 @@ type context interface {
// driver is the interface for the platform implementation
// of a window.
type driver interface {
// DriverName get driver anme
DriverName() string
// Event blocks until an event is available and returns it.
Event() event.Event
// Invalidate requests a FrameEvent.
Expand Down
4 changes: 4 additions & 0 deletions app/os_android.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,10 @@ func (w *window) processEvent(e event.Event) bool {
return true
}

func (w *window) DriverName() string {
return "android"
}

func (w *window) Event() event.Event {
return w.loop.Event()
}
Expand Down
4 changes: 4 additions & 0 deletions app/os_ios.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ func (w *window) ProcessEvent(e event.Event) {
w.loop.FlushEvents()
}

func (w *window) DriverName() string {
return "ios"
}

func (w *window) Event() event.Event {
return w.loop.Event()
}
Expand Down
4 changes: 4 additions & 0 deletions app/os_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ func (w *window) processEvent(e event.Event) bool {
return true
}

func (w *window) DriverName() string {
return "js"
}

func (w *window) Event() event.Event {
for {
evt, ok := w.w.nextEvent()
Expand Down
19 changes: 17 additions & 2 deletions app/os_macos.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,11 @@ func (w *window) Configure(options []Option) {
C.setWindowTitleVisibility(window, titleVis)
C.setWindowStyleMask(window, mask)
C.setWindowStandardButtonHidden(window, C.NSWindowCloseButton, barTrans)
C.setWindowStandardButtonHidden(window, C.NSWindowMiniaturizeButton, barTrans)
C.setWindowStandardButtonHidden(window, C.NSWindowZoomButton, barTrans)
// no decorated or hide minimize and maximize buttons
w.config.HiddenMinimizeButton = cnf.HiddenMinimizeButton
w.config.HiddenMaximizeButton = cnf.HiddenMaximizeButton
C.setWindowStandardButtonHidden(window, C.NSWindowMiniaturizeButton, toInt(!cnf.Decorated || cnf.HiddenMinimizeButton))
C.setWindowStandardButtonHidden(window, C.NSWindowZoomButton, toInt(!cnf.Decorated || cnf.HiddenMaximizeButton))
// When toggling the titlebar, the layer doesn't update its frame
// until the next resize. Force it.
C.resetLayerFrame(w.view)
Expand Down Expand Up @@ -835,6 +838,10 @@ func (w *window) ProcessEvent(e event.Event) {
w.loop.FlushEvents()
}

func (w *window) DriverName() string {
return "macos"
}

func (w *window) Event() event.Event {
return w.loop.Event()
}
Expand Down Expand Up @@ -1041,6 +1048,14 @@ func convertMods(mods C.NSUInteger) key.Modifiers {
return kmods
}

// toInt golang bool to C.int
func toInt(v bool) C.int {
if v {
return C.int(C.YES)
}
return C.int(C.NO)
}

func (AppKitViewEvent) implementsViewEvent() {}
func (AppKitViewEvent) ImplementsEvent() {}
func (a AppKitViewEvent) Valid() bool {
Expand Down
4 changes: 4 additions & 0 deletions app/os_wayland.go
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,10 @@ func (w *window) ProcessEvent(e event.Event) {
w.w.ProcessEvent(e)
}

func (w *window) DriverName() string {
return "wayland"
}

func (w *window) Event() event.Event {
for {
evt, ok := w.w.nextEvent()
Expand Down
14 changes: 14 additions & 0 deletions app/os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,10 @@ func (w *window) ProcessEvent(e event.Event) {
w.loop.FlushEvents()
}

func (w *window) DriverName() string {
return "windows"
}

func (w *window) Event() event.Event {
return w.loop.Event()
}
Expand Down Expand Up @@ -747,6 +751,16 @@ func (w *window) Configure(options []Option) {
swpStyle |= windows.SWP_NOMOVE | windows.SWP_NOSIZE
showMode = windows.SW_SHOWMAXIMIZED
}
if w.config.HiddenMinimizeButton {
style &^= windows.WS_MINIMIZEBOX
} else {
style |= windows.WS_MINIMIZEBOX
}
if w.config.HiddenMaximizeButton {
style &^= windows.WS_MAXIMIZEBOX
} else {
style |= windows.WS_MAXIMIZEBOX
}
windows.SetWindowLong(w.hwnd, windows.GWL_STYLE, style)
windows.SetWindowPos(w.hwnd, 0, x, y, width, height, swpStyle)
windows.ShowWindow(w.hwnd, showMode)
Expand Down
4 changes: 4 additions & 0 deletions app/os_x11.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ func (w *x11Window) ProcessEvent(e event.Event) {
w.w.ProcessEvent(e)
}

func (w *x11Window) DriverName() string {
return "x11"
}

func (w *x11Window) shutdown(err error) {
w.ProcessEvent(X11ViewEvent{})
w.ProcessEvent(DestroyEvent{Err: err})
Expand Down
22 changes: 22 additions & 0 deletions app/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,14 @@ func (w *Window) updateState() {
w.updateAnimation()
}

// DriverName get driver name
func (w *Window) DriverName() string {
if w.driver == nil {
return ""
}
return w.driver.DriverName()
}

// Invalidate the window such that a [FrameEvent] will be generated immediately.
// If the window is inactive, an unspecified event is sent instead.
//
Expand Down Expand Up @@ -970,6 +978,20 @@ func Decorated(enabled bool) Option {
}
}

// HiddenMinimizeButton controls whether show minimize button on macos and windows
func HiddenMinimizeButton(hidden bool) Option {
return func(_ unit.Metric, cnf *Config) {
cnf.HiddenMinimizeButton = hidden
}
}

// HiddenMaximizeButton controls whether show maximize button on macos and windows
func HiddenMaximizeButton(hidden bool) Option {
return func(_ unit.Metric, cnf *Config) {
cnf.HiddenMaximizeButton = hidden
}
}

// flushEvent is sent to detect when the user program
// has completed processing of all prior events. Its an
// [io/event.Event] but only for internal use.
Expand Down