Skip to content

Commit 14e9dad

Browse files
committed
add support to hidden minimize and maximize button on macos and windows #143
1 parent 8104d52 commit 14e9dad

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

app/os.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ type Config struct {
4545
CustomRenderer bool
4646
// Decorated reports whether window decorations are provided automatically.
4747
Decorated bool
48+
49+
// MinimizeButtonHidden hide the window's minimize button (only works for windows and macOS)
50+
MinimizeButtonHidden bool
51+
// MaximizeButtonHidden hide the window's maximize button (only works for windows and macOS)
52+
MaximizeButtonHidden bool
53+
4854
// Focused reports whether has the keyboard focus.
4955
Focused bool
5056
// decoHeight is the height of the fallback decoration for platforms such

app/os_macos.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,11 @@ func (w *window) Configure(options []Option) {
495495
C.setWindowTitleVisibility(window, titleVis)
496496
C.setWindowStyleMask(window, mask)
497497
C.setWindowStandardButtonHidden(window, C.NSWindowCloseButton, barTrans)
498-
C.setWindowStandardButtonHidden(window, C.NSWindowMiniaturizeButton, barTrans)
499-
C.setWindowStandardButtonHidden(window, C.NSWindowZoomButton, barTrans)
498+
// no decorated or hide minimize and maximize buttons
499+
w.config.MinimizeButtonHidden = cnf.MinimizeButtonHidden
500+
w.config.MaximizeButtonHidden = cnf.MaximizeButtonHidden
501+
C.setWindowStandardButtonHidden(window, C.NSWindowMiniaturizeButton, toInt(!cnf.Decorated || cnf.MinimizeButtonHidden))
502+
C.setWindowStandardButtonHidden(window, C.NSWindowZoomButton, toInt(!cnf.Decorated || cnf.MaximizeButtonHidden))
500503
// When toggling the titlebar, the layer doesn't update its frame
501504
// until the next resize. Force it.
502505
C.resetLayerFrame(w.view)
@@ -1161,6 +1164,14 @@ func convertMods(mods C.NSUInteger) key.Modifiers {
11611164
return kmods
11621165
}
11631166

1167+
// toInt golang bool to C.int
1168+
func toInt(v bool) C.int {
1169+
if v {
1170+
return C.int(C.YES)
1171+
}
1172+
return C.int(C.NO)
1173+
}
1174+
11641175
func (AppKitViewEvent) implementsViewEvent() {}
11651176
func (AppKitViewEvent) ImplementsEvent() {}
11661177
func (a AppKitViewEvent) Valid() bool {

app/os_windows.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,16 @@ func (w *window) Configure(options []Option) {
758758
swpStyle |= windows.SWP_NOMOVE | windows.SWP_NOSIZE
759759
showMode = windows.SW_SHOWMAXIMIZED
760760
}
761+
if w.config.MinimizeButtonHidden {
762+
style &^= windows.WS_MINIMIZEBOX
763+
} else {
764+
style |= windows.WS_MINIMIZEBOX
765+
}
766+
if w.config.MaximizeButtonHidden {
767+
style &^= windows.WS_MAXIMIZEBOX
768+
} else {
769+
style |= windows.WS_MAXIMIZEBOX
770+
}
761771

762772
// Disable maximize button if MaxSize is set.
763773
if cnf.MaxSize != (image.Point{X: 0, Y: 0}) {

app/window.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,24 @@ func Decorated(enabled bool) Option {
969969
}
970970
}
971971

972+
// MinimizeButtonHidden hides the minimize button of the window.
973+
//
974+
// MinimizeButtonHidden is supported on Windows and macOS.
975+
func MinimizeButtonHidden(hidden bool) Option {
976+
return func(_ unit.Metric, cnf *Config) {
977+
cnf.MinimizeButtonHidden = hidden
978+
}
979+
}
980+
981+
// MaximizeButtonHidden hides the maximize button of the window.
982+
//
983+
// MaximizeButtonHidden is supported on Windows and macOS.
984+
func MaximizeButtonHidden(hidden bool) Option {
985+
return func(_ unit.Metric, cnf *Config) {
986+
cnf.MaximizeButtonHidden = hidden
987+
}
988+
}
989+
972990
// flushEvent is sent to detect when the user program
973991
// has completed processing of all prior events. Its an
974992
// [io/event.Event] but only for internal use.

0 commit comments

Comments
 (0)