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
- func AddRecentFile(cx *core.Scope, path string)
- func CanDockPanels(cx *core.Scope) bool
- func CanLookUp(cx *core.Scope) bool
- func CanMakeWindowsTransparent(cx *core.Scope) bool
- func CanPlaceWindows(cx *core.Scope) bool
- func CanQuickLook(cx *core.Scope) bool
- func CanReadFrontmostApp(cx *core.Scope) bool
- func CanSetWindowLevel(cx *core.Scope) bool
- func CanSetWindowWorkspaces(cx *core.Scope) bool
- func CanSkipTaskbar(cx *core.Scope) bool
- func ClearRecentFiles(cx *core.Scope)
- func CloseWindow(cx *core.Scope)
- func CursorPoint(cx *core.Scope, done func(point core.Point, available bool))
- func FullScreen(cx *core.Scope) bool
- func GuidePermission(cx *core.Scope, p core.Permission, opts GuideOptions, ...) (stop func())
- func IsAvailable(cx *core.Scope) bool
- func LaunchAtLogin(cx *core.Scope, done func(on bool))
- func LaunchedAtLogin(cx *core.Scope) bool
- func LookUp(cx *core.Scope, text string, in *core.Ref, at core.Bounds) bool
- func Maximized(cx *core.Scope) bool
- func MinimizeWindow(cx *core.Scope)
- func Minimized(cx *core.Scope) bool
- func Monitors(cx *core.Scope) []core.DisplayInfo
- func OnOpenFiles(cx *core.Scope, fn func(paths []string))
- func OnOpenLinks(cx *core.Scope, fn func(links []string))
- func OnQuitRequest(cx *core.Scope, fn func(q *QuitRequest))
- func OnReopen(cx *core.Scope, fn func())
- func OrderFront(cx *core.Scope)
- func PopupMenu(cx *core.Scope, items []MenuItem, at core.Point, closed func())
- func QuickLook(cx *core.Scope, paths []string, index int) bool
- func RequestQuit(cx *core.Scope)
- func RequestRestart(cx *core.Scope)
- func Restart(cx *core.Scope)
- func RevealFile(cx *core.Scope, path string, done func(error))
- func SetApplicationMenu(cx *core.Scope, items []MenuItem)
- func SetDockMenu(cx *core.Scope, items []MenuItem)
- func SetDockVisible(cx *core.Scope, on bool)
- func SetFullScreen(cx *core.Scope, on bool, displayID ...string)
- func SetLaunchAtLogin(cx *core.Scope, on bool)
- func SetMainWindow(cx *core.Scope, w *Window)
- func SetMenuBar(cx *core.Scope, mode MenuBarMode)
- func SetShutdownMode(cx *core.Scope, mode ShutdownMode)
- func SetSkipTaskbar(cx *core.Scope, on bool)
- func SetTitle(cx *core.Scope, title string)
- func SetTitleBar(cx *core.Scope, style TitleBarStyle, height core.Points)
- func SetWindowConstraints(cx *core.Scope, c WindowConstraints)
- func SetWindowControls(cx *core.Scope, c WindowControls)
- func SetWindowFrame(cx *core.Scope, f WindowFrame)
- func SetWindowLevel(cx *core.Scope, level WindowLevel)
- func SetWindowMaterial(cx *core.Scope, m WindowMaterial)
- func SetWindowPointerEvents(cx *core.Scope, p WindowPointerEvents)
- func SetWindowShadow(cx *core.Scope, on bool)
- func SetWindowTransparent(cx *core.Scope, on bool)
- func SetWindowWorkspaces(cx *core.Scope, w WindowWorkspaces)
- func ShowsMaterial(cx *core.Scope) bool
- func TitleBar(cx *core.Scope) core.Edges
- func ToggleFullScreen(cx *core.Scope)
- func ToggleMaximize(cx *core.Scope)
- func Transparent(cx *core.Scope) bool
- func TrashFile(cx *core.Scope, path string, done func(trashedAt string, err error))
- func UserDir(cx *core.Scope, dir StandardDir) (string, error)
- type FrontmostAppInfo
- type GuideOptions
- type HotKey
- type HotKeyState
- type MenuBarMode
- type MenuIcon
- type MenuItem
- type MenuRole
- type PanelDock
- type PanelOptions
- type QuitRequest
- type ShutdownMode
- type StandardDir
- type TitleBarStyle
- type Tray
- type TrayOptions
- type Window
- type WindowClosing
- type WindowConstraints
- type WindowControls
- type WindowControlsStyle
- type WindowFrame
- type WindowLevel
- type WindowMaterial
- type WindowOptions
- type WindowPointerEvents
- type WindowWorkspaces
Constants ¶
const ( ShutdownOnLastWindowClose = core.ShutdownOnLastWindowClose ShutdownOnMainWindowClose = core.ShutdownOnMainWindowClose ShutdownOnExplicit = core.ShutdownOnExplicit )
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; on Wayland one the compositor or the user did not bind. HotKeyTaken = core.HotKeyTaken // HotKeyUnsupported is a key the platform cannot make a global shortcut, or a platform or session with none. HotKeyUnsupported = core.HotKeyUnsupported )
const ( DocumentsDir = core.DocumentsDir DownloadsDir = core.DownloadsDir DesktopDir = core.DesktopDir PicturesDir = core.PicturesDir MusicDir = core.MusicDir // VideosDir is macOS's Movies. VideosDir = core.VideosDir )
const ( TitleBarDefault = core.TitleBarDefault TitleBarHidden = core.TitleBarHidden )
const ( // WindowControlsDefault draws NSGo's compact rounded caption buttons on Windows. WindowControlsDefault = core.WindowControlsDefault // WindowControlsSystem draws Windows 11's full-height caption buttons, flush with the window's edge. WindowControlsSystem = core.WindowControlsSystem )
const ( WindowLevelNormal = core.WindowLevelNormal WindowLevelFloating = core.WindowLevelFloating WindowLevelDesktop = core.WindowLevelDesktop )
const ( // WindowWorkspacesCurrent keeps a window on the workspace it opened on. WindowWorkspacesCurrent = core.WindowWorkspacesCurrent // WindowWorkspacesAll shows it on every workspace. WindowWorkspacesAll = core.WindowWorkspacesAll )
const ( // WindowPointerAuto takes the pointer everywhere in the window, as windows do. WindowPointerAuto = core.WindowPointerAuto // WindowPointerNone lets every press, scroll and hover through to what is below, as a heads-up display does. WindowPointerNone = core.WindowPointerNone // WindowPointerPainted takes the pointer only over the views that draw something, such as a background, a border, a text or an image, or that hear it, such as a pressable, a context menu or a window drag handle; elsewhere it goes through, as around a desktop pet. WindowPointerPainted = core.WindowPointerPainted )
const ( MenuBarShown = core.MenuBarShown MenuBarAutoHide = core.MenuBarAutoHide )
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 )
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 MenuPasteAndMatchStyle = core.MenuPasteAndMatchStyle MenuDelete = core.MenuDelete MenuStartSpeaking = core.MenuStartSpeaking MenuStopSpeaking = core.MenuStopSpeaking MenuBringAllToFront = core.MenuBringAllToFront MenuServices = core.MenuServices MenuWindowMenu = core.MenuWindowMenu MenuHelpMenu = core.MenuHelpMenu )
Variables ¶
This section is empty.
Functions ¶
func AddRecentFile ¶ added in v0.2.0
AddRecentFile records path as a document the user opened, which the system offers again: in the Dock menu and File › Open Recent on macOS, for the types nsgo.yaml's file_types declares, and in the Recent category of the Jump List on Windows, for the types the app is registered to open. Linux records it in the desktop's recently used files under the app's ID, respecting GTK's history setting. Choosing one reaches OnOpenFiles. Elsewhere it does nothing.
func CanDockPanels ¶
CanDockPanels reports whether PanelOptions.Dock can attach a panel to a display's usable edge; a missing library or protocol on Wayland returns false.
func CanLookUp ¶ added in v0.2.0
CanLookUp reports whether LookUp shows the system's dictionary panel: in a window on macOS. Windows, Linux and the web have no such panel, so it is false there, as for the app's own scope and a tray icon's, which show in no window.
func CanMakeWindowsTransparent ¶ added in v0.2.0
CanMakeWindowsTransparent reports whether the scope's window shows what is behind it while transparent: on macOS; on Windows in a window opened transparent where DirectComposition draws it, the only one SetWindowTransparent changes; on Linux where the display composites with an RGBA visual, as Wayland always does and X11 with a compositing manager. It is false elsewhere, where a transparent window stays opaque, and for a view a host embeds, the app's own scope, a panel or a tray icon, which show in no window of their own. It is what the window could do, not what it does: Transparent says whether the window or a transparent panel draws nothing of its own now.
func CanPlaceWindows ¶ added in v0.2.0
CanPlaceWindows reports whether SetWindowFrame moves the scope's window to the position it gives: on macOS, Windows and X11, and for an Android overlay (mobile.OpenOverlay), which it keeps on the screen, but not for a view a host embeds, the app's own scope or a tray icon's, which show in no window, or an ordinary Wayland toplevel.
func CanQuickLook ¶
CanQuickLook reports whether a window can ask for file previews: macOS's panel, Windows' registered preview handlers, or a running or activatable GNOME Sushi service on Linux. It is false on other targets, in an embedded view, and for the app's own scope and a tray icon's. Available formats depend on the previewer; true does not guarantee a preview for every file.
func CanReadFrontmostApp ¶ added in v0.2.0
CanReadFrontmostApp reports whether FrontmostApp follows the application in front, tracked: on macOS, Windows, X11 and Wayland compositors exposing version 2 or later of wlr foreign-toplevel management. Wayland provides application IDs but no PID. Other compositors, phones, the web and mini programs report false, as does code whose Access refuses core.AccessFrontmostApp.
func CanSetWindowLevel ¶ added in v0.2.0
CanSetWindowLevel reports whether SetWindowLevel stacks the scope's window: on macOS, Windows and Linux on X11, but not for a view a host embeds, the app's own scope or a tray icon's, which show in no window, a Linux panel no window manager manages, or on Wayland.
func CanSetWindowWorkspaces ¶ added in v0.2.0
CanSetWindowWorkspaces reports whether SetWindowWorkspaces puts the scope's window on the workspaces it names: on macOS, and on Linux on X11 where the window manager lists _NET_WM_DESKTOP among the hints it supports (_NET_SUPPORTED), as it says when the window opens. It is false on Windows, on Wayland, on phones and the web, and for a view a host embeds, the app's own scope or a tray icon's, which show in no window, or a Linux panel no window manager manages.
func CanSkipTaskbar ¶ added in v0.2.0
CanSkipTaskbar reports whether SkipTaskbar and SetSkipTaskbar keep the scope's window off the taskbar: on Windows, on Linux under X11, and on macOS, where they keep it out of the Window menu and Cmd+` and SetDockVisible is the Dock's. Wayland has no way for an app to, and it is false there, on phones and the web, and for a view a host embeds, the app's own scope, a panel or a tray icon.
func ClearRecentFiles ¶ added in v0.2.0
ClearRecentFiles forgets the documents AddRecentFile recorded, the app's alone.
func CloseWindow ¶
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 CursorPoint ¶
CursorPoint calls done with the pointer position, even outside the app's windows, in the same points and coordinate space as Monitors and Window.ShowAt. The bool is false when the position is unavailable, including on Wayland. Poll by calling CursorPoint again when another sample is needed.
func FullScreen ¶
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 ¶
IsAvailable reports whether the app runs on macOS, Windows or Linux, where this package's functions act; a web build that runs as one (core.Env.Simulated) does not.
func LaunchAtLogin ¶
LaunchAtLogin calls done with whether the system starts the app at login: false where registration is unavailable, and on Windows while Startup apps or policy disables it. On Flatpak it reports only the last Background portal reply in this run, false before any reply: that portal has no read-only autostart query.
func LaunchedAtLogin ¶ added in v0.2.0
LaunchedAtLogin reports whether the system started this run as a login item, as a tray app reads it to open no window then. It is known when the app's function first runs and stays the same for the run, reopens included; a restart (Restart) reports false. macOS reads the launch Apple event, or the LaunchAgent's marker on macOS 11 and 12, and Windows and Linux the marker their login entries start the app with, or the StartupTask activation kind in an MSIX; phones and the web report false. Tests set it with nsgotest.Environment(core.Environment{LaunchedAtLogin: true}).
func LookUp ¶ added in v0.2.0
LookUp shows the system's dictionary panel for text, as a three-finger tap or Ctrl-Cmd-D does on macOS, with the text drawn over at, a box in the view in refers to (the surface's when in is nil), such as a TextSelection's Text and Bounds with its Selectable view's Ref. It reports whether the panel was asked for: false for blank text, an in that is not mounted, where CanLookUp is false, and for a confined view the user is not using (core.Scope.Confine).
func Maximized ¶
Maximized reports whether the window is maximized or zoomed, so a maximize button of the app's own can show restore.
func Minimized ¶
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 Monitors ¶
func Monitors(cx *core.Scope) []core.DisplayInfo
Monitors returns the displays and their bounds in desktop screen coordinates.
func OnOpenFiles ¶
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, on Windows and Linux the files named on the command line, and on iOS temporary copies imported through the scene delegate. Move iOS imports into cx.DataDir() to preserve them. Files the app launched to open wait for the first handler.
func OnOpenLinks ¶ added in v0.2.0
OnOpenLinks runs fn with links of the app's own URL schemes, which nsgo.yaml's url_schemes declares and the macOS, Windows and Linux packages register, that the system asks the app to open: clicked in a browser or another app, or opened with open, start or xdg-open. They reach the running app, on Windows and Linux through its one-instance claim, which brings its window to the front if it shows and does not run OnReopen; the link the app launched to open waits for the first handler. On Windows and Linux any link the app is started with arrives, as a development build registers no scheme, so check the scheme; on Windows a launch that names a link opens no files with it, as the shell does not escape a link's quotes. A link carries whatever the page that made it chose, so treat its contents as untrusted input and confirm with the user before acting on it.
func OnQuitRequest ¶
func OnQuitRequest(cx *core.Scope, fn func(q *QuitRequest))
OnQuitRequest runs fn when the user chooses Quit from a desktop menu, or the system ends the session. On Windows and Linux, closing a window also asks when its close would end the app. Handlers run newest first and may cancel or defer a user quit. Check QuitRequest.Forced before asking the user for a decision. core.Scope.Quit and Restart quit without asking.
desktop.OnQuitRequest(cx, func(q *desktop.QuitRequest) {
if q.Forced() || !dirty.Get() {
return
}
done := q.Defer()
base.ShowAlertDialog(cx, discard, func(label string) { done(label == "Discard") })
})
func OnReopen ¶
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 ¶
OrderFront shows the window, restoring it when minimized or hidden, brings it to the front of its level and activates the app.
func PopupMenu ¶
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 QuickLook ¶
QuickLook shows the system's file preview panel on paths, starting at index, as Space does in the Finder; called again while the panel shows, it shows the new paths, as the Finder's panel follows its selection. The user closes it with Space or Escape. It reports whether the panel was asked for: false for no paths, a path that is not a regular file, where CanQuickLook is false, and for a confined view the user is not using (core.Scope.Confine). The panel reads the files while it shows them.
func RequestQuit ¶
RequestQuit asks the app to quit as a desktop Quit menu item does.
func RequestRestart ¶
RequestRestart asks the OnQuitRequest handlers before restarting. A canceled request leaves the app running; a deferred one waits for its answer.
func Restart ¶
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 ¶
RevealFile opens the file manager with path selected.
func SetApplicationMenu ¶
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 SetDockMenu ¶ added in v0.2.0
SetDockMenu sets the items the app's icon offers above the system's own, nil none: the menu of its Dock icon on macOS, with submenus, separators, check marks and disabled items as the application menu has them, the quicklist on Linux launchers that support Unity LauncherEntry (Ubuntu dock, Plasma and Dash to Dock), and the Tasks of its Jump List on Windows, its taskbar button's and Start menu entry's. The items' handlers run under the current owner; when it goes, the items go too. The app has one such menu, the one any window set last.
A Jump List task is a top-level enabled item with a label and an OnSelect; submenus, separators and check marks are left out. Windows keeps the list while the app is not running: a task starts the app again, which hands the task to the copy already running when nsgo.yaml gives the app an id, and the item labeled as the task runs once the app has set its menu. Phones and the web ignore the menu.
func SetDockVisible ¶
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 SetFullScreen ¶
SetFullScreen enters or leaves full screen. A display ID from Env.Displays selects a desktop display. An omitted ID uses the window's current display. On the web, call it from a press or another user gesture. The browser chooses the display and Env.FullScreen follows changes, including leaving with Esc.
func SetLaunchAtLogin ¶
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: SMAppService registers it on macOS 13 and later, and a per-user LaunchAgent, which takes effect at the next login, on macOS 11 and 12. Windows uses the user's Run key, or StartupTask in an MSIX; Linux writes an XDG entry, uses Snap's declared autostart file, or requests Flatpak's Background portal. A portal may ask for consent, and Windows does not override a startup task disabled by the user or policy. A failure is logged.
func SetMainWindow ¶
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 SetSkipTaskbar ¶ added in v0.2.0
SetSkipTaskbar keeps the window off the Windows taskbar and Alt+Tab, off the task list on X11, and out of macOS's Window menu and Cmd+`, or puts it back; WindowOptions.SkipTaskbar and nsgo.SkipTaskbar open a window so. On macOS the Dock shows the app rather than its windows, and SetDockVisible takes it out. CanSkipTaskbar says whether it takes effect.
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. Linux applies maximum sizes through X11's window manager and filters GTK's native titlebar buttons. Wayland supports fixed sizes, but nonfixed maximums remain unsupported.
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. Animated eases visible panels on macOS and Windows unless reduced motion is on; other macOS windows use AppKit's resize animation. Linux sets the size GTK keeps for the window and positions it on X11; a Wayland compositor places an ordinary toplevel itself; CanPlaceWindows says whether the position moves the window.
func SetWindowLevel ¶
func SetWindowLevel(cx *core.Scope, level WindowLevel)
SetWindowLevel puts the window at level among the others. macOS floats it at NSFloatingWindowLevel, or sinks it to the desktop's icons on every space; Windows makes it topmost, or puts it at the bottom of the z-order; Linux on X11 asks the window manager for _NET_WM_STATE_ABOVE or _NET_WM_STATE_BELOW, again each time the window shows. A Wayland compositor stacks its windows itself, and where CanSetWindowLevel is false the level does nothing.
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 SetWindowPointerEvents ¶ added in v0.2.0
func SetWindowPointerEvents(cx *core.Scope, p WindowPointerEvents)
SetWindowPointerEvents says where the window takes the pointer, from its next frame: everywhere, the default, nowhere, or only where it draws something, the pointer going through to the windows below elsewhere. WindowOptions.PointerEvents and PanelOptions.PointerEvents open a window so. A window that takes none hears no presses, so an app that lets one through entirely switches it back from elsewhere, such as a global shortcut or a tray icon; one that takes the pointer where it draws hears it there:
desktop.SetWindowPointerEvents(cx, desktop.WindowPointerPainted)
Code held to an Access needs it to grant core.AccessOverlay, else the window takes the pointer. A view whose background fills the window makes a painted window take it everywhere, and the title bar the system draws, which is no view, lets it through.
func SetWindowShadow ¶ added in v0.2.0
SetWindowShadow gives the window the system's shadow, or takes it away; WindowOptions.NoShadow and nsgo.WindowNoShadow open a window without it. Windows draws none around a transparent window and keeps it around a framed one.
func SetWindowTransparent ¶ added in v0.2.0
SetWindowTransparent makes the window transparent, without a background or frame, so what is behind it shows wherever the app draws nothing, or gives it back both; WindowOptions.Transparent and nsgo.WindowTransparent open a window so. It takes effect where CanMakeWindowsTransparent is true: macOS and Linux change it any time, and Windows only in a window opened transparent, whose composition holds from its creation; such a window is opaque, white behind the app's views, while framed.
func SetWindowWorkspaces ¶ added in v0.2.0
func SetWindowWorkspaces(cx *core.Scope, w WindowWorkspaces)
SetWindowWorkspaces shows the window on every workspace, as a desktop pet, a HUD or a timer does, or back on one, the one the user is on; WindowOptions.Workspaces opens a window so. On macOS a window on every Space also shows over other apps' full screen spaces and stays out of Cmd-` cycling, and SetWindowLevel keeps it on every Space; a level that floats keeps it above the windows there, and the desktop's level behind them, out of full screen spaces. Linux puts it on every virtual desktop on X11, where the window manager supports _NET_WM_DESKTOP. Windows, which has no public way to pin a window to every virtual desktop, and Wayland leave it on the one it opened on; CanSetWindowWorkspaces says whether it takes effect.
func ShowsMaterial ¶
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 ¶
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 ¶
ToggleFullScreen enters or leaves full screen. On the web, call it from a press handler. Browser refusals go to the log.
func ToggleMaximize ¶
ToggleMaximize maximizes (zooms) the window, or restores it.
func Transparent ¶ added in v0.2.0
Transparent reports whether the scope's window or panel draws nothing of its own now, no background, frame or shadow, so what is behind it shows wherever the content draws nothing: a panel opened with PanelOptions.Transparent, or a window opened with WindowOptions.Transparent or nsgo.WindowTransparent or made so by SetWindowTransparent, where the platform could. CanMakeWindowsTransparent says whether a window could be transparent, Transparent whether it is: it turns false as SetWindowTransparent gives the window its frame back, and stays false where the platform could not clear it, as on Linux without a compositor or on Windows in a window not opened transparent. Where it is false, give the content a background of its own.
func TrashFile ¶
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.
func UserDir ¶
func UserDir(cx *core.Scope, dir StandardDir) (string, error)
UserDir returns the absolute path of the user's folder dir as the system names it now, which may not exist yet: under the home directory on macOS (a sandboxed app's container links them), the known folder on Windows, which follows one the user moved, and the XDG user directory on Linux, where only the desktop has a default and a folder set to the home directory is disabled. Elsewhere, and for a folder the system does not name, it returns core.ErrUserDirUnavailable: phones and the web reach the user's files through core.Scope.PickFiles and PickDirectories.
Types ¶
type FrontmostAppInfo ¶ added in v0.2.0
type FrontmostAppInfo = core.FrontmostAppInfo
FrontmostAppInfo is the application in front on the desktop: its ID, its name, its process ID and whether its frontmost window is in full screen.
func FrontmostApp ¶ added in v0.2.0
func FrontmostApp(cx *core.Scope) FrontmostAppInfo
FrontmostApp returns the application in front on the desktop, the app itself included, tracked: an effect or binding reading it runs again when another app comes to the front or the one in front enters or leaves full screen.
front := desktop.FrontmostApp(cx) coding := front.ID == "com.microsoft.VSCode" && !front.FullScreen
It is zero where CanReadFrontmostApp is false. Tests set it with nsgotest.Environment(core.Environment{FrontmostApp: ..., CanReadFrontmostApp: true}).
type GuideOptions ¶
type GuideOptions = core.PermissionGuideOptions
GuideOptions say which app GuidePermission holds out for the user to drag.
type HotKey ¶
HotKey is a global shortcut's registration, whose State follows the platform's answers.
func RegisterHotKey ¶
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, and Taken when the binding leaves it out.
type HotKeyState ¶
type HotKeyState = core.HotKeyState
HotKeyState is what the platform answered a global shortcut's registration.
type MenuBarMode ¶
type MenuBarMode = core.MenuBarMode
MenuBarMode says when Windows and Linux show the menu bar.
type 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 ¶
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 takes its content's, whether it hides as it loses the focus, whether it never takes it, whether it draws anything of its own, and where it takes the pointer.
type QuitRequest ¶
type QuitRequest = core.QuitRequest
QuitRequest is a user or system request to quit. Forced reports a system session ending.
type ShutdownMode ¶
type ShutdownMode = core.ShutdownMode
ShutdownMode says when the app ends by itself.
type StandardDir ¶
type StandardDir = core.StandardDir
StandardDir names one of the user's standard folders.
type TitleBarStyle ¶
type TitleBarStyle = core.TitleBarStyle
TitleBarStyle is whether the system draws the window's title bar.
type 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 cx 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. Title shows beside either image or view on macOS. Read Tray.ClickBounds in OnClick or Menu to place a custom panel with Window.ShowAt where bounds are available.
type TrayOptions ¶
type TrayOptions = core.TrayOptions
TrayOptions are a tray icon's image or view, and what its clicks show.
type Window ¶
Window is a window or a panel the app opened.
func CurrentWindow ¶
CurrentWindow returns the window cx is in, nil in the app's own scope.
func MainWindow ¶
MainWindow returns the main window, nil once it closed.
func OpenPanel ¶
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. Like OpenWindow, the panel belongs to cx itself rather than the running owner. 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)
A popup card draws itself on a Transparent panel, which shows nothing around it, sized to it with FitContent, up to Width and Height:
lookup := desktop.OpenPanel(cx, desktop.PanelOptions{Width: 380, Height: 520, FitContent: true, Transparent: true, HideOnBlur: true}, Card)
func OpenWindow ¶
OpenWindow opens a window showing content, which belongs to cx and closes when cx goes — not the batch a build owns while it runs this code, so a window opened from a click outlives the rebuild that click causes. 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 WindowControlsStyle ¶
type WindowControlsStyle = core.WindowControlsStyle
WindowControlsStyle chooses the look of the caption buttons NSGo draws on Windows.
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, key and where it takes the pointer.
type WindowPointerEvents ¶ added in v0.2.0
type WindowPointerEvents = core.WindowPointerEvents
WindowPointerEvents is where a window takes the pointer: everywhere, nowhere, or only where it draws something.
type WindowWorkspaces ¶ added in v0.2.0
type WindowWorkspaces = core.WindowWorkspaces
WindowWorkspaces are the workspaces a window shows on: macOS's Spaces, the virtual desktops of Windows and Linux.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package locales says the words the backends show and announce in the language the app shows: those of the platforms' menus, the standard items' and the menus apps build around them, of macOS's permission guide, its panel with the titles of System Settings' privacy panes, and the roles and states the screen readers of Android and Windows announce where the system has no word of its own.
|
Package locales says the words the backends show and announce in the language the app shows: those of the platforms' menus, the standard items' and the menus apps build around them, of macOS's permission guide, its panel with the titles of System Settings' privacy panes, and the roles and states the screen readers of Android and Windows announce where the system has no word of its own. |