Skip to content

Commit 67920fb

Browse files
committed
Add WindowMode Option for bordreless and borderless fullscreen windows.
1 parent 19902ac commit 67920fb

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ type config struct {
2020
forcePixelRatio float64
2121
keyboardLayout KeyboardShortcuts
2222

23+
windowMode windowMode
24+
2325
// PlatformMessageReceivers map[string][]PluginReceivers // The Key is the Channel name.
2426
plugins []Plugin
2527
}
@@ -37,6 +39,7 @@ var defaultApplicationConfig = config{
3739
y: 600,
3840
},
3941
keyboardLayout: KeyboardQwertyLayout,
42+
windowMode: WindowModeDefault,
4043
}
4144

4245
// 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)