Index | Files | Directories

package app

import ""

Package app provides a platform-independent interface to operating system functionality for running graphical user interfaces.

See for instructions to set up and run Gio programs.


Create a new Window by calling NewWindow. On mobile platforms or when Gio is embedded in another project, NewWindow merely connects with a previously created window.

A Window is run by receiving events from its Events channel. The most important event is FrameEvent that prompts an update of the window contents and state.

For example:

import ""

w := app.NewWindow()
for e := range w.Events() {
	if e, ok := e.(system.FrameEvent); ok {
		// Add operations to ops.
		// Completely replace the window contents and state.

A program must keep receiving events from the event channel until DestroyEvent is received.


The Main function must be called from a program's main function, to hand over control of the main thread to operating systems that need it.

Because Main is also blocking on some platforms, the event loop of a Window must run in a goroutine.

For example, to display a blank but otherwise functional window:

package main

import ""

func main() {
	go func() {
		w := app.NewWindow()
		for range w.Events() {

Event queue

A FrameEvent's Queue method returns an event.Queue implementation that distributes incoming events to the event handlers declared in the last frame. See the package for more information about event handlers.


The packages under should be imported by a Gio program or by one of its dependencies to indicate that specific operating-system permissions are required. Please see documentation for package for more information.


Package Files

app.go datadir.go doc.go loop.go window.go

func DataDir Uses

func DataDir() (string, error)

DataDir returns a path to use for application-specific configuration data. On desktop systems, DataDir use os.UserConfigDir. On iOS NSDocumentDirectory is queried. For Android Context.getFilesDir is used.

BUG: DataDir blocks on Android until init functions have completed.

func Main Uses

func Main()

Main must be called last from the program main function. On most platforms Main blocks forever, for Android and iOS it returns immediately to give control of the main thread back to the system.

Calling Main is necessary because some operating systems require control of the main thread of the program for running windows.

type Option Uses

type Option func(opts *window.Options)

WindowOption configures a Window.

func MaxSize Uses

func MaxSize(w, h unit.Value) Option

MaxSize sets the maximum size of the window.

func MinSize Uses

func MinSize(w, h unit.Value) Option

MinSize sets the minimum size of the window.

func Size Uses

func Size(w, h unit.Value) Option

Size sets the size of the window.

func Title Uses

func Title(t string) Option

Title sets the title of the window.

type Window Uses

type Window struct {
    // contains filtered or unexported fields

Window represents an operating system window.

func NewWindow Uses

func NewWindow(options ...Option) *Window

NewWindow creates a new window for a set of window options. The options are hints; the platform is free to ignore or adjust them.

If the current program is running on iOS and Android, NewWindow returns the window previously created by the platform.

Calling NewWindow more than once is not supported on iOS, Android, WebAssembly.

func (*Window) Close Uses

func (w *Window) Close()

Close the window. The window's event loop should exit when it receives system.DestroyEvent.

Currently, only macOS, Windows and X11 drivers implement this functionality, all others are stubbed.

func (*Window) Events Uses

func (w *Window) Events() <-chan event.Event

Events returns the channel where events are delivered.

func (*Window) Invalidate Uses

func (w *Window) Invalidate()

Invalidate the window such that a FrameEvent will be generated immediately. If the window is inactive, the event is sent when the window becomes active. Invalidate is safe for concurrent use.

func (*Window) ReadClipboard Uses

func (w *Window) ReadClipboard()

ReadClipboard initiates a read of the clipboard in the form of a system.ClipboardEvent. Multiple reads may be coalesced to a single event.

func (*Window) WriteClipboard Uses

func (w *Window) WriteClipboard(s string)

WriteClipboard writes a string to the clipboard.


headlessPackage headless implements headless windows for rendering an operation list to an image.
internal/cocoainitPackage cocoainit initializes support for multithreaded programs in Cocoa.
internal/logPackage points standard output, standard error and the standard library package log to the platform logger.
internal/windowPackage window implements platform specific windows and GPU contexts.
internal/xkbPackage xkb implements a Go interface for the X Keyboard Extension library.
permissionPackage permission includes sub-packages that should be imported by a Gio program or by one of its dependencies to indicate that specific operating-system permissions are required.
permission/bluetoothPackage bluetooth implements permissions to access Bluetooth and Bluetooth Low Energy hardware, including the ability to discover and pair devices.
permission/cameraPackage camera implements permissions to access camera ardware.
permission/storagePackage storage implements read and write storage permissions on mobile devices.

Package app imports 16 packages (graph) and is imported by 56 packages. Updated 2020-10-19. Refresh now. Tools for package owners.