Skip to content

Commit 6039f62

Browse files
committed
Add WindowMode Option for bordreless and borderless fullscreen windows.
1 parent 03ab019 commit 6039f62

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

application.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,30 @@ func (a *Application) Run() error {
6464
}
6565
defer glfw.Terminate()
6666

67-
a.window, err = glfw.CreateWindow(a.config.windowInitialDimensions.x, a.config.windowInitialDimensions.y, "Loading..", nil, nil)
67+
var monitor *glfw.Monitor
68+
switch a.config.windowMode {
69+
case WindowModeDefault:
70+
// nothing
71+
case WindowModeBorderless:
72+
glfw.WindowHint(glfw.Decorated, glfw.False)
73+
case WindowModeBorderlessFullscreen:
74+
monitor = glfw.GetPrimaryMonitor()
75+
mode := monitor.GetVideoMode()
76+
a.config.windowInitialDimensions.x = mode.Width
77+
a.config.windowInitialDimensions.y = mode.Height
78+
glfw.WindowHint(glfw.RedBits, mode.RedBits)
79+
glfw.WindowHint(glfw.GreenBits, mode.GreenBits)
80+
glfw.WindowHint(glfw.BlueBits, mode.BlueBits)
81+
glfw.WindowHint(glfw.RefreshRate, mode.RefreshRate)
82+
default:
83+
return errors.Errorf("invalid window mode %T", a.config.windowMode)
84+
}
85+
86+
a.window, err = glfw.CreateWindow(a.config.windowInitialDimensions.x, a.config.windowInitialDimensions.y, "Loading..", monitor, nil)
6887
if err != nil {
6988
return errors.Wrap(err, "creating glfw window")
7089
}
90+
glfw.DefaultWindowHints()
7191
defer a.window.Destroy()
7292

7393
if a.config.windowIconProvider != nil {

option.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type config struct {
1616
windowInitializerDeprecated func(*glfw.Window) error
1717
windowIconProvider func() ([]image.Image, error)
1818
windowInitialDimensions windowDimensions
19+
windowMode windowMode
1920

2021
forcePixelRatio float64
2122
keyboardLayout KeyboardShortcuts
@@ -36,6 +37,7 @@ var defaultApplicationConfig = config{
3637
y: 600,
3738
},
3839
keyboardLayout: KeyboardQwertyLayout,
40+
windowMode: WindowModeDefault,
3941
}
4042

4143
// Option for Application

window.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package flutter
2+
3+
// windowMode determines the kind of window mode to use for new windows.
4+
type windowMode int
5+
6+
const (
7+
// WindowModeDefault is the default window mode. Windows are created with
8+
// borders and close/minimize buttons.
9+
WindowModeDefault windowMode = iota
10+
// WindowModeBorderless removes decorations such as borders and
11+
// close/minimize buttons from the window.
12+
WindowModeBorderless
13+
// WindowModeBorderlessFullscreen starts the application in borderless
14+
// fullscreen mode. Currently, only fullscreen on the primary monitor is
15+
// supported. This option overrides WindowInitialDimensions. Note that on
16+
// some systems a fullscreen window is very hard to close. Make sure your
17+
// Flutter application has a close button and use PopBehaviorIconify to
18+
// minimize or PopBehaviorClose to close the application.
19+
WindowModeBorderlessFullscreen
20+
)
21+
22+
// WindowMode sets the window mode on the application.
23+
func WindowMode(w windowMode) Option {
24+
return func(c *config) {
25+
c.windowMode = w
26+
}
27+
}

0 commit comments

Comments
 (0)