Skip to content
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
6 changes: 6 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

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

// Focused reports whether has the keyboard focus.
Focused bool
// decoHeight is the height of the fallback decoration for platforms such
Expand Down
15 changes: 13 additions & 2 deletions app/os_macos.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,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.MinimizeButtonHidden = cnf.MinimizeButtonHidden
w.config.MaximizeButtonHidden = cnf.MaximizeButtonHidden
C.setWindowStandardButtonHidden(window, C.NSWindowMiniaturizeButton, toInt(!cnf.Decorated || cnf.MinimizeButtonHidden))
C.setWindowStandardButtonHidden(window, C.NSWindowZoomButton, toInt(!cnf.Decorated || cnf.MaximizeButtonHidden))
// 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 @@ -1162,6 +1165,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
12 changes: 12 additions & 0 deletions app/os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,8 @@ func (w *window) Configure(options []Option) {
w.config.Decorated = cnf.Decorated
w.config.MinSize = cnf.MinSize
w.config.MaxSize = cnf.MaxSize
w.config.MinimizeButtonHidden = cnf.MinimizeButtonHidden
w.config.MaximizeButtonHidden = cnf.MaximizeButtonHidden
windows.SetWindowText(w.hwnd, cnf.Title)

style := windows.GetWindowLong(w.hwnd, windows.GWL_STYLE)
Expand Down Expand Up @@ -758,6 +760,16 @@ func (w *window) Configure(options []Option) {
swpStyle |= windows.SWP_NOMOVE | windows.SWP_NOSIZE
showMode = windows.SW_SHOWMAXIMIZED
}
if w.config.MinimizeButtonHidden {
style &^= windows.WS_MINIMIZEBOX
} else {
style |= windows.WS_MINIMIZEBOX
}
if w.config.MaximizeButtonHidden {
style &^= windows.WS_MAXIMIZEBOX
} else {
style |= windows.WS_MAXIMIZEBOX
}

// Disable window resizing if MinSize and MaxSize are equal.
if cnf.MaxSize != (image.Point{}) && cnf.MinSize == cnf.MaxSize {
Expand Down
18 changes: 18 additions & 0 deletions app/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,24 @@ func Decorated(enabled bool) Option {
}
}

// MinimizeButtonHidden hides the minimize button of the window.
//
// MinimizeButtonHidden is supported on Windows and macOS.
func MinimizeButtonHidden(hidden bool) Option {
return func(_ unit.Metric, cnf *Config) {
cnf.MinimizeButtonHidden = hidden
}
}

// MaximizeButtonHidden hides the maximize button of the window.
//
// MaximizeButtonHidden is supported on Windows and macOS.
func MaximizeButtonHidden(hidden bool) Option {
return func(_ unit.Metric, cnf *Config) {
cnf.MaximizeButtonHidden = 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