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 1 commit
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

// HiddenMinimizeButton hide the window's minimize button
HiddenMinimizeButton bool
// HiddenMaximizeButton hide the window's maximize button
HiddenMaximizeButton bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should either note that these don't work under Linux, or make them work under Linux.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried for days to test on ubuntu with os_x11.go, but still not working.

  • _NET_WM_ALLOWED_ACTIONS
  • _MOTIF_WM_HINTS
  • _NET_WM_WINDOW_TYPE: _NET_WM_WINDOW_TYPE_DIALOG

They all didn't work. I belive these properties also depend on window manager implementation, according to infomations bellow:

I'll continue wokring to make them work on x11 and wayland, but this may take long time.
So I add tips "only works for windows and macOS" for the options.
Maybe the feature working only on some os is acceptable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the feature working only on some os is acceptable?

Fine with me. Better than nothing! Thanks for trying.


// Focused reports whether has the keyboard focus.
Focused bool
// decoHeight is the height of the fallback decoration for platforms such
Expand Down
19 changes: 17 additions & 2 deletions app/os_macos.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,14 @@ func (w *window) Configure(options []Option) {
C.setMaxSize(window, C.CGFloat(cnf.MaxSize.X), C.CGFloat(cnf.MaxSize.Y))
}
}
if cnf.Decorated != prev.Decorated || cnf.HiddenMinimizeButton != prev.HiddenMinimizeButton {
hidden := toInt(!cnf.Decorated || cnf.HiddenMinimizeButton)
C.setWindowStandardButtonHidden(window, C.NSWindowMiniaturizeButton, hidden)
}
if cnf.Decorated != prev.Decorated || cnf.HiddenMaximizeButton != prev.HiddenMaximizeButton {
hidden := toInt(!cnf.Decorated || cnf.HiddenMaximizeButton)
C.setWindowStandardButtonHidden(window, C.NSWindowZoomButton, hidden)
}
if cnf.Decorated != prev.Decorated {
w.config.Decorated = cnf.Decorated
mask := C.getWindowStyleMask(window)
Expand All @@ -458,12 +466,11 @@ func (w *window) Configure(options []Option) {
barTrans = C.YES
titleVis = C.NSWindowTitleHidden
}

C.setWindowTitlebarAppearsTransparent(window, barTrans)
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)
// 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 @@ -1072,6 +1079,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
10 changes: 10 additions & 0 deletions app/os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,16 @@ func (w *window) Configure(options []Option) {
height = mi.Monitor.Bottom - mi.Monitor.Top
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
14 changes: 14 additions & 0 deletions app/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,20 @@ func Decorated(enabled bool) Option {
}
}

// HiddenMinimizeButton controls whether show minimize button on macos and windows
func HiddenMinimizeButton(hidden bool) Option {
Comment on lines +981 to +982
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: change name to MinimizeButtonHidden and separate comment about platform support.

// MinimizeButtonHidden hides the minimize button of the window.
//
// MinimizeButtonHidden is supported on Windows and macOS.

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