Skip to content

Add WindowMode Option for bordreless and borderless fullscreen windows. #144

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

Merged
merged 1 commit into from
May 19, 2019
Merged
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
22 changes: 21 additions & 1 deletion application.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,30 @@ func (a *Application) Run() error {
}
defer glfw.Terminate()

a.window, err = glfw.CreateWindow(a.config.windowInitialDimensions.x, a.config.windowInitialDimensions.y, "Loading..", nil, nil)
var monitor *glfw.Monitor
switch a.config.windowMode {
case WindowModeDefault:
// nothing
case WindowModeBorderless:
glfw.WindowHint(glfw.Decorated, glfw.False)
case WindowModeBorderlessFullscreen:
monitor = glfw.GetPrimaryMonitor()
mode := monitor.GetVideoMode()
a.config.windowInitialDimensions.x = mode.Width
a.config.windowInitialDimensions.y = mode.Height
glfw.WindowHint(glfw.RedBits, mode.RedBits)
glfw.WindowHint(glfw.GreenBits, mode.GreenBits)
glfw.WindowHint(glfw.BlueBits, mode.BlueBits)
glfw.WindowHint(glfw.RefreshRate, mode.RefreshRate)
default:
return errors.Errorf("invalid window mode %T", a.config.windowMode)
}

a.window, err = glfw.CreateWindow(a.config.windowInitialDimensions.x, a.config.windowInitialDimensions.y, "Loading..", monitor, nil)
if err != nil {
return errors.Wrap(err, "creating glfw window")
}
glfw.DefaultWindowHints()
defer a.window.Destroy()

if a.config.windowIconProvider != nil {
Expand Down
2 changes: 2 additions & 0 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type config struct {
windowInitializerDeprecated func(*glfw.Window) error
windowIconProvider func() ([]image.Image, error)
windowInitialDimensions windowDimensions
windowMode windowMode

forcePixelRatio float64
keyboardLayout KeyboardShortcuts
Expand All @@ -36,6 +37,7 @@ var defaultApplicationConfig = config{
y: 600,
},
keyboardLayout: KeyboardQwertyLayout,
windowMode: WindowModeDefault,
}

// Option for Application
Expand Down
27 changes: 27 additions & 0 deletions window.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package flutter

// windowMode determines the kind of window mode to use for new windows.
type windowMode int

const (
// WindowModeDefault is the default window mode. Windows are created with
// borders and close/minimize buttons.
WindowModeDefault windowMode = iota
// WindowModeBorderless removes decorations such as borders and
// close/minimize buttons from the window.
WindowModeBorderless
// WindowModeBorderlessFullscreen starts the application in borderless
// fullscreen mode. Currently, only fullscreen on the primary monitor is
// supported. This option overrides WindowInitialDimensions. Note that on
// some systems a fullscreen window is very hard to close. Make sure your
// Flutter application has a close button and use PopBehaviorIconify to
// minimize or PopBehaviorClose to close the application.
WindowModeBorderlessFullscreen
)

// WindowMode sets the window mode on the application.
func WindowMode(w windowMode) Option {
return func(c *config) {
c.windowMode = w
}
}