desktop

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 1 Imported by: 4 modules, 6 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package desktop holds what only desktops have: the window, its title bar and the menus, as NSH's nsh/desktop. It builds on every platform, so one app runs everywhere: on phones and tablets its functions do nothing, and IsAvailable says whether they act.

A title bar of the app's own calls SetTitleBar once, marks its background with core.View's Desktop.WindowDrag and keeps clear of the edges TitleBar reports; SetWindowControls moves or hides the system's controls in it. A window over a material leaves transparent what should show it while ShowsMaterial.

Index

Constants

View Source
const (
	ShutdownOnLastWindowClose = core.ShutdownOnLastWindowClose
	ShutdownOnMainWindowClose = core.ShutdownOnMainWindowClose
	ShutdownOnExplicit        = core.ShutdownOnExplicit
)
View Source
const (
	// HotKeyPending waits for the platform's answer.
	HotKeyPending = core.HotKeyPending
	// HotKeyRegistered is a shortcut the platform fires.
	HotKeyRegistered = core.HotKeyRegistered
	// HotKeyTaken is a combination another registration holds: the app's own, or another app's on Windows and X11; on macOS another app's only when it registered exclusively.
	HotKeyTaken = core.HotKeyTaken
	// HotKeyUnsupported is a key the platform cannot make a global shortcut, or a platform or session with none.
	HotKeyUnsupported = core.HotKeyUnsupported
)
View Source
const (
	TitleBarDefault = core.TitleBarDefault
	TitleBarHidden  = core.TitleBarHidden
)
View Source
const (
	WindowLevelNormal   = core.WindowLevelNormal
	WindowLevelFloating = core.WindowLevelFloating
	WindowLevelDesktop  = core.WindowLevelDesktop
)
View Source
const (
	MenuBarShown    = core.MenuBarShown
	MenuBarAutoHide = core.MenuBarAutoHide
)
View Source
const (
	WindowMaterialNone = core.WindowMaterialNone
	// The materials of window areas.
	WindowMaterialWindow      = core.WindowMaterialWindow
	WindowMaterialContent     = core.WindowMaterialContent
	WindowMaterialSidebar     = core.WindowMaterialSidebar
	WindowMaterialHeader      = core.WindowMaterialHeader
	WindowMaterialTitlebar    = core.WindowMaterialTitlebar
	WindowMaterialUnderWindow = core.WindowMaterialUnderWindow
	WindowMaterialUnderPage   = core.WindowMaterialUnderPage
	// The materials of transient surfaces, Acrylic on Windows.
	WindowMaterialMenu         = core.WindowMaterialMenu
	WindowMaterialPopover      = core.WindowMaterialPopover
	WindowMaterialHUD          = core.WindowMaterialHUD
	WindowMaterialSheet        = core.WindowMaterialSheet
	WindowMaterialTooltip      = core.WindowMaterialTooltip
	WindowMaterialSelection    = core.WindowMaterialSelection
	WindowMaterialFullScreenUI = core.WindowMaterialFullScreenUI
	// Windows 11's system backdrops: Mica, Acrylic and Mica Alt.
	WindowMaterialMica    = core.WindowMaterialMica
	WindowMaterialAcrylic = core.WindowMaterialAcrylic
	WindowMaterialTabbed  = core.WindowMaterialTabbed
)
View Source
const (
	MenuRoleNone         = core.MenuRoleNone
	MenuAbout            = core.MenuAbout
	MenuHide             = core.MenuHide
	MenuHideOthers       = core.MenuHideOthers
	MenuShowAll          = core.MenuShowAll
	MenuQuit             = core.MenuQuit
	MenuUndo             = core.MenuUndo
	MenuRedo             = core.MenuRedo
	MenuCut              = core.MenuCut
	MenuCopy             = core.MenuCopy
	MenuPaste            = core.MenuPaste
	MenuSelectAll        = core.MenuSelectAll
	MenuMinimize         = core.MenuMinimize
	MenuZoom             = core.MenuZoom
	MenuToggleFullScreen = core.MenuToggleFullScreen
	MenuClose            = core.MenuClose
)

Variables

This section is empty.

Functions

func CloseWindow

func CloseWindow(cx *core.Scope)

CloseWindow closes the window as its close button does: the window's OnClosing handlers may keep it, and the app ends by its shutdown mode.

func FullScreen

func FullScreen(cx *core.Scope) bool

FullScreen reports whether the window is in full screen.

func GuidePermission

func GuidePermission(cx *core.Scope, p core.Permission, opts GuideOptions, done func(core.PermissionStatus)) (stop func())

GuidePermission opens the page of the system's settings that gives p and waits for the user to give it. On macOS, for the panes whose list takes an app dragged into it (all but the microphone's, the camera's, the calendars' and the reminders'), a panel under System Settings' window follows it, never takes the focus, and holds the app for the user to drag into the list. It ends, and done hears the status then, once the app has p, the user closes the panel or System Settings, stop is called or the current owner goes; one guide shows at a time, and a new one ends the one before. On Windows it opens the microphone's or the camera's page and ends once the app has p or Settings closes. Where nothing guides, as on Linux and off desktops, done hears the status at once.

func IsAvailable

func IsAvailable(cx *core.Scope) bool

IsAvailable reports whether the app runs on macOS, Windows or Linux, where this package's functions act.

func LaunchAtLogin

func LaunchAtLogin(cx *core.Scope, done func(on bool))

LaunchAtLogin calls done with whether the system starts the app at login.

func Maximized

func Maximized(cx *core.Scope) bool

Maximized reports whether the window is maximized or zoomed, so a maximize button of the app's own can show restore.

func MinimizeWindow

func MinimizeWindow(cx *core.Scope)

MinimizeWindow minimizes the window.

func Minimized

func Minimized(cx *core.Scope) bool

Minimized reports whether the window is minimized, so an app can stop work the user cannot see and resume it once the window is restored. It is always false on phones and the web, and on Wayland, which reports no minimized state.

func OnOpenFiles

func OnOpenFiles(cx *core.Scope, fn func(paths []string))

OnOpenFiles runs fn with the paths of files the system asks the app to open: the file types nsgo.yaml's file_types declares, opened from the Finder, the Dock or Open With, and on Windows and Linux the files named on the command line. Files the app launched to open wait for the first handler.

func OnQuitRequest

func OnQuitRequest(cx *core.Scope, fn func(q *QuitRequest))

OnQuitRequest runs fn when the user asks the app to quit, by Cmd+Q, the Dock, a tray menu's Quit or the system, on macOS, newest first: a handler may cancel the quit, or defer it with QuitRequest.Defer while it asks the user, and when none does the app quits. core.Scope.Quit and Restart quit without asking:

desktop.OnQuitRequest(cx, func(q *desktop.QuitRequest) {
	if !dirty.Get() {
		return
	}
	done := q.Defer()
	base.ShowAlertDialog(cx, discard, func(label string) { done(label == "Discard") })
})

func OnReopen

func OnReopen(cx *core.Scope, fn func())

OnReopen runs fn when the user opens the app again while it runs: by clicking it in the Dock or launching it a second time. Without a handler the main window shows and takes the focus.

func OrderFront

func OrderFront(cx *core.Scope)

OrderFront shows the window, restoring it when minimized or hidden, brings it to the front of its level and activates the app.

func PopupMenu

func PopupMenu(cx *core.Scope, items []MenuItem, at core.Point, closed func())

PopupMenu shows items as the platform's own context menu, its top left corner at at, in the points of the root view, as a press's or OnContextMenu's PagePosition. closed, when not nil, runs once it closes, after the OnSelect of an item chosen. A menu shown before closes first. Desktops show it; elsewhere closed runs at once.

func Restart

func Restart(cx *core.Scope)

Restart ends the app as core.Scope.Quit does, and nsgo.Run starts it again with the arguments it started with once it has exited, on macOS, Windows and Linux, so a setting read at launch takes effect. Under nsgo dev, and in a view a host embeds, it only quits.

func RevealFile

func RevealFile(cx *core.Scope, path string, done func(error))

RevealFile opens the file manager with path selected.

func SetApplicationMenu

func SetApplicationMenu(cx *core.Scope, items []MenuItem)

SetApplicationMenu replaces the application menu: macOS's menu bar, the window's menu bar on Windows and Linux. nil restores the platform's default. The items' handlers run under the current owner; when it goes, the default menu comes back.

func SetDockVisible

func SetDockVisible(cx *core.Scope, on bool)

SetDockVisible shows the app in the Dock and the app switcher, or leaves it to its tray icon and windows, on macOS; nsgo.HideDock starts it hidden.

func SetLaunchAtLogin

func SetLaunchAtLogin(cx *core.Scope, on bool)

SetLaunchAtLogin has the system start the app as the user logs in, or no more. macOS takes only an app in a bundle, as nsgo build makes it.

func SetMainWindow

func SetMainWindow(cx *core.Scope, w *Window)

SetMainWindow makes w the main window: the one ShutdownOnMainWindowClose follows and reopening the app shows. The window nsgo.SetMainView opens is main.

func SetMenuBar

func SetMenuBar(cx *core.Scope, mode MenuBarMode)

SetMenuBar says when Windows and Linux show the menu bar the window draws for the application menu, which a window with a hidden title bar has none of (SetTitleBar); macOS's is the system's and always shows.

func SetShutdownMode

func SetShutdownMode(cx *core.Scope, mode ShutdownMode)

SetShutdownMode says when the app ends by itself: as its last window closes (the default), as its main window closes, or only by core.Scope.Quit, as a tray app does.

func SetTitle

func SetTitle(cx *core.Scope, title string)

SetTitle sets the window's title on desktops and the page's on the web.

func SetTitleBar

func SetTitleBar(cx *core.Scope, style TitleBarStyle, height core.Points)

SetTitleBar hides the system's title bar so the app can draw its own height points tall (0: the platform's height), or restores it. The platform centers its window controls in that height. TitleBar then reports the area they keep. A window with a hidden title bar has no menu bar on Windows and Linux; on Windows, Alt and F10 open the application menu as a popup from the window's top corner instead, and Alt with a top-level item's first letter opens that item's menu.

func SetWindowConstraints

func SetWindowConstraints(cx *core.Scope, c WindowConstraints)

SetWindowConstraints limits the window's content size and says whether it resizes, minimizes and maximizes; the zero WindowConstraints limits nothing. The window moves into its new sizes, and MinimizeWindow and ToggleMaximize do nothing where it may not, as its buttons:

desktop.SetWindowConstraints(cx, desktop.WindowConstraints{MinWidth: 480, MinHeight: 320, NoMaximize: true})

A window sets them as it opens with WindowOptions.Constraints, and the main window with nsgo.WindowConstraints. On Linux, GTK 4 has neither maximum sizes nor a way to take the title bar's buttons, so only NoResize, or a maximum equal to the minimum, limits a window from above, and the user's buttons stay.

func SetWindowControls

func SetWindowControls(cx *core.Scope, c WindowControls)

SetWindowControls hides the system's window controls in a hidden title bar, or moves macOS's traffic lights in it, from any time on:

desktop.SetWindowControls(cx, desktop.WindowControls{TrafficLights: core.Point{X: 20, Y: 18}})

Offset moves them from there, as a transition does each frame. TitleBar follows where they are. The zero WindowControls restores the platform's.

func SetWindowFrame

func SetWindowFrame(cx *core.Scope, f WindowFrame)

SetWindowFrame moves and sizes the window: f's top left corner is in points from the main screen's top left on every platform, and fields it leaves out keep their values, so a window given only a new height keeps its top edge. macOS animates the change when f asks. Linux sets the size GTK keeps for the window, and leaves its position to the compositor.

func SetWindowLevel

func SetWindowLevel(cx *core.Scope, level WindowLevel)

SetWindowLevel puts the window at level among the others, on macOS and Windows; Linux leaves stacking to the compositor.

func SetWindowMaterial

func SetWindowMaterial(cx *core.Scope, m WindowMaterial)

SetWindowMaterial puts m behind the window's content, or makes the window opaque again with WindowMaterialNone; nsgo.WindowMaterial starts the window with one. macOS changes it any time; Windows 11 22H2 and later only in a window started with a material, others staying opaque.

func ShowsMaterial

func ShowsMaterial(cx *core.Scope) bool

ShowsMaterial reports whether a material shows behind the window's content, where the app leaves it transparent. Where it is false, give those parts a background of their own.

func TitleBar

func TitleBar(cx *core.Scope) core.Edges

TitleBar returns what a hidden title bar covers: Top is its height, Left and Right the widths the system's window controls take at its ends. It is zero while the system draws the title bar, in full screen and off desktops.

func ToggleFullScreen

func ToggleFullScreen(cx *core.Scope)

ToggleFullScreen enters or leaves full screen.

func ToggleMaximize

func ToggleMaximize(cx *core.Scope)

ToggleMaximize maximizes (zooms) the window, or restores it.

func TrashFile

func TrashFile(cx *core.Scope, path string, done func(trashedAt string, err error))

TrashFile moves path to the user's recoverable Trash or Recycle Bin. It never deletes permanently: where the item cannot be recycled, done gets core.ErrNoTrash and the item stays.

Types

type GuideOptions

type GuideOptions = core.PermissionGuideOptions

GuideOptions say which app GuidePermission holds out for the user to drag.

type HotKey

type HotKey = core.HotKey

HotKey is a global shortcut's registration, whose State follows the platform's answers.

func RegisterHotKey

func RegisterHotKey(cx *core.Scope, key string, fn func()) *HotKey

RegisterHotKey runs fn when key, in core.Scope.OnKey's form such as "alt+space", is pressed whichever app has the focus, while the current owner lives. The handle's State is Pending until the platform answers, then Registered, Taken or Unsupported, and Pending again while a change to the app's shortcuts registers them anew. Global shortcuts work on macOS, on Linux and, for an app run with nsgo.Run(App), on Windows; elsewhere, nsgo.NewView's hosts included, the handle is Unsupported. Linux uses X11 passive grabs, and its compositor's global-shortcut portal on Wayland, where the shortcut is Registered once the user accepts the binding.

type HotKeyState

type HotKeyState = core.HotKeyState

HotKeyState is what the platform answered a global shortcut's registration.

type MenuBarMode = core.MenuBarMode

MenuBarMode says when Windows and Linux show the menu bar.

type MenuItem = core.MenuItem

MenuItem is one item of a menu: an action, a submenu when it has Items, or a line between groups when Separator. The application menu's top-level items are the menu bar's menus; on macOS the first is the app menu.

type MenuRole = core.MenuRole

MenuRole is a standard menu item the platform carries out, labelling it and giving it its usual shortcut when the item has none of its own.

type PanelOptions

type PanelOptions = core.PanelOptions

PanelOptions are a panel's size, whether it hides as it loses the focus, and whether it never takes it.

type QuitRequest

type QuitRequest = core.QuitRequest

QuitRequest is a quit the user asked for, which OnQuitRequest's handlers may cancel, or defer while they ask the user.

type ShutdownMode

type ShutdownMode = core.ShutdownMode

ShutdownMode says when the app ends by itself.

type TitleBarStyle

type TitleBarStyle = core.TitleBarStyle

TitleBarStyle is whether the system draws the window's title bar.

type Tray

type Tray = core.Tray

Tray is a tray icon: in the macOS menu bar, or a Linux StatusNotifierItem.

func NewTray

func NewTray(cx *core.Scope, opts TrayOptions) *Tray

NewTray adds a tray icon, which the current owner keeps: an image, or a view that draws it and may change, a panel its primary click shows under it, and a menu its secondary click shows.

type TrayOptions

type TrayOptions = core.TrayOptions

TrayOptions are a tray icon's image or view, and what its clicks show.

type Window

type Window = core.Window

Window is a window or a panel the app opened.

func CurrentWindow

func CurrentWindow(cx *core.Scope) *Window

CurrentWindow returns the window cx is in, nil in the app's own scope.

func MainWindow

func MainWindow(cx *core.Scope) *Window

MainWindow returns the main window, nil once it closed.

func OpenPanel

func OpenPanel(cx *core.Scope, opts PanelOptions, content func(cx *core.Scope) core.Node) *Window

OpenPanel opens a hidden panel showing content: a borderless window above the others, which takes the keyboard without activating the app, for Window.Toggle, a global shortcut or a tray icon to show, as a launcher or a tray icon's panel does. With PanelOptions.NoActivate it never takes the keyboard, for Window.ShowAt to place beside another app's text caret, as an input method's candidate window does:

candidates := desktop.OpenPanel(cx, desktop.PanelOptions{Width: 320, Height: 40, NoActivate: true}, Candidates)
candidates.ShowAt(caret, core.PlaceBottom)

func OpenWindow

func OpenWindow(cx *core.Scope, opts WindowOptions, content func(cx *core.Scope) core.Node) *Window

OpenWindow opens a window showing content, which belongs to the current owner and closes when that owner goes. A window with opts.Key already open shows and takes the focus instead:

settings := desktop.OpenWindow(cx, desktop.WindowOptions{Title: "Settings", Key: "settings"}, Settings)

type WindowClosing

type WindowClosing = core.WindowClosing

WindowClosing is a close the user asked for, which Window.OnClosing may cancel.

type WindowConstraints

type WindowConstraints = core.WindowConstraints

WindowConstraints limit a window's size and what the user may do to it.

type WindowControls

type WindowControls = core.WindowControls

WindowControls is how a hidden title bar shows the system's window controls: hidden for the app to draw its own, or macOS's traffic lights moved.

type WindowFrame

type WindowFrame = core.WindowFrame

WindowFrame is where a window moves and how large it becomes, in points from the main screen's top left.

func Frame

func Frame(cx *core.Scope) WindowFrame

Frame returns where the window is and how large, as SetWindowFrame and nsgo.WindowFrame take them, changing as it moves and resizes. While the window is maximized or in full screen it is that frame, so an app remembering a window keeps the one it last had otherwise. Linux knows only the size GTK keeps, which ignores those states, and Move says no position came; zero without a window.

type WindowLevel

type WindowLevel = core.WindowLevel

WindowLevel is where a window stacks among the others.

type WindowMaterial

type WindowMaterial = core.WindowMaterial

WindowMaterial is a translucent material behind the window's content: one of macOS's vibrancy materials, or of Windows 11's system backdrops, each platform showing its closest.

type WindowOptions

type WindowOptions = core.WindowOptions

WindowOptions are a window's title, size, constraints and key.

Directories

Path Synopsis
Package locales says the words of the platforms' menus and of macOS's permission guide, which the backends show in the language the app shows: the standard items', the menus apps build around them, and the guide's panel with the titles of System Settings' privacy panes.
Package locales says the words of the platforms' menus and of macOS's permission guide, which the backends show in the language the app shows: the standard items', the menus apps build around them, and the guide's panel with the titles of System Settings' privacy panes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL