Documentation
¶
Overview ¶
Package desktop provides desktop specific driver functionality.
Index ¶
- Constants
- func StartDrag(data DragData) bool
- type App
- type AttentionWindow
- type Canvas
- type ChildWindow
- type Cursor
- type Cursorable
- type CustomShortcut
- type DragData
- type DragOutProvider
- type DragSource
- type Driver
- type GlobalShortcutApp
- type KeyModifierDriver
- type Keyable
- type ModalWindow
- type MouseButton
- type MouseEvent
- type Mouseable
- type PositionableWindow
- type ProgressWindow
- type ScreenArea
- type ScreenInfo
- type ScreensDriver
- type StandardCursor
- type Window
Constants ¶
const ( // KeyNone represents no key KeyNone event.KeyName = "" // KeyShiftLeft represents the left shift key KeyShiftLeft event.KeyName = "LeftShift" // KeyShiftRight represents the right shift key KeyShiftRight event.KeyName = "RightShift" // KeyControlLeft represents the left control key KeyControlLeft event.KeyName = "LeftControl" // KeyControlRight represents the right control key KeyControlRight event.KeyName = "RightControl" // KeyAltLeft represents the left alt key KeyAltLeft event.KeyName = "LeftAlt" // KeyAltRight represents the right alt key KeyAltRight event.KeyName = "RightAlt" // KeySuperLeft represents the left "Windows" key (or "Command" key on macOS) KeySuperLeft event.KeyName = "LeftSuper" // KeySuperRight represents the right "Windows" key (or "Command" key on macOS) KeySuperRight event.KeyName = "RightSuper" // KeyMenu represents the left or right menu / application key KeyMenu event.KeyName = "Menu" // KeyPrintScreen represents the key used to cause a screen capture KeyPrintScreen event.KeyName = "PrintScreen" // KeyCapsLock represents the caps lock key, tapping once is the down event then again is the up KeyCapsLock event.KeyName = "CapsLock" )
Variables ¶
This section is empty.
Functions ¶
func StartDrag ¶
StartDrag begins a native drag-and-drop OUT of the app carrying data if the active driver supports it (DragSource), returning whether the drag started. It is package sugar over the driver assertion, mirroring the clipboard-flavor helpers. Call it from a widget's Dragged handler on the main goroutine.
Since: 1.0
Types ¶
type App ¶
type App interface {
// SetSystemTrayMenu sets a menu to be shown from the system tray icon.
// On Linux, see the tray-delivery note on the App interface: the menu is
// only reachable where the desktop environment provides an SNI host.
SetSystemTrayMenu(menu *bellui.Menu)
// SetSystemTrayIcon sets the icon to be used in system tray.
// If you pass a `ThemedResource` then any OS that adjusts look to match theme will adapt the icon.
// On Linux, see the tray-delivery note on the App interface: the icon is
// only visible where the desktop environment provides an SNI host (stock
// GNOME needs the AppIndicator extension; XEmbed-only trays are unsupported).
SetSystemTrayIcon(icon bellui.Resource)
// SetSystemTrayWindow optionally sets a window that this system tray will help to control.
// On systems that support it (Windows, macOS and most Linux) the window will be shown on left-tap.
// If the window is decorated (a regular window) tapping will show it only, however for a splash window
// (without window decorations) tapping when the window is visible will hide it.
// If you also have a menu set this will be triggered with right-mouse tap.
// Note that your menu should probably include a "Show Window" menu item for less-compliant Linux
// systems: on Linux the tray relies on the desktop environment providing a StatusNotifierItem host
// (stock GNOME requires the AppIndicator extension; XEmbed-only trays are unsupported), so the icon
// may never appear and the window needs another way to be reached.
//
// Since: 1.0
SetSystemTrayWindow(bellui.Window)
// SetSystemTrayTooltip sets the hover tooltip text shown for the system tray icon.
// It may be called before the tray has started; the value is applied once it does.
// Not every platform renders a tray tooltip (notably it is unreliable on some Linux
// desktops), so treat it as a best-effort hint.
//
// Since: 1.0
SetSystemTrayTooltip(text string)
// SetSystemTrayOnTapped sets a custom handler for a left-click (primary tap) on the
// system tray icon, for actions other than showing a window. Pass nil to clear it.
//
// This shares the single underlying tap slot with SetSystemTrayWindow, so the two are
// mutually exclusive: whichever was set last wins. On macOS, when a menu is set the
// status item opens the menu on click, so a tap handler cannot be promised alongside a
// menu there.
//
// The handler is invoked on the main goroutine.
//
// Since: 1.0
SetSystemTrayOnTapped(fn func())
}
App defines the desktop specific extensions to a bellui.App.
System tray support (the SetSystemTray* methods below) is delivered through the platform's status-item facilities: a native status item on macOS and Windows, and StatusNotifierItem over D-Bus on Linux/BSD. The Linux path is the fragile one: an item only appears if the desktop environment runs an SNI host. KDE Plasma, most Wayland compositors, and anything with an SNI host show it; stock GNOME shows nothing unless the user installs the AppIndicator (KStatusNotifierItem) shell extension, and legacy XEmbed-only trays (some minimal window managers) are not supported at all. This is a property of the desktop, not a bellui bug, and every non-GTK toolkit shares it. Therefore: never make the tray the only route to a feature — always keep a window or menu path (see the "Show Window" advice on SetSystemTrayWindow).
Since: 1.0
type AttentionWindow ¶
type AttentionWindow interface {
Window
// RequestAttention asks the system to draw the user's attention to this
// window without raising or focusing it. Safe to call before or after the
// window is shown; a call before Show is applied once the window maps.
RequestAttention()
}
AttentionWindow extends Window with a request for the user's attention without stealing focus — a politer signal than bellui.Window.RequestFocus for "a background task finished" or "this window needs you". It maps to the platform's non-intrusive attention affordance: a dock-icon bounce on macOS, a taskbar-button flash on Windows, and the urgency hint (_NET_WM_STATE_DEMANDS_ATTENTION) on Linux/X11.
The request is advisory: the window manager decides how (and whether) to surface it, and it is typically cleared automatically once the window gains focus. On Linux Wayland support depends on the compositor.
Windows on mobile and web targets do not implement this interface.
Since: 1.0
type Canvas ¶
type Canvas interface {
OnKeyDown() func(*event.KeyEvent)
SetOnKeyDown(func(*event.KeyEvent))
OnKeyUp() func(*event.KeyEvent)
SetOnKeyUp(func(*event.KeyEvent))
}
Canvas defines the desktop specific extensions to a core.Canvas.
type ChildWindow ¶
type ChildWindow interface {
Window
// SetParent establishes parent as this window's owner. Call before Show
// for the relationship to take effect as the window maps; calling it while
// already shown applies it immediately where the platform allows. Pass nil
// to clear the relationship.
//
// On platforms or sessions that cannot express window ownership the call is
// a no-op. On Linux Wayland the relationship is applied by the compositor,
// so — unlike [Window.RequestPosition] — it is honoured there.
SetParent(parent bellui.Window)
}
ChildWindow extends Window with a native parent/owner relationship: the window manager keeps this window stacked above its parent, minimizes and restores it together with the parent, and treats it as owned by the parent rather than as an independent top-level window.
This is the native counterpart to the pure-Go modal scrim used by window-hosted dialogs; drivers that support it use both.
Windows on mobile and web targets do not implement this interface.
Since: 1.0
type Cursor ¶
type Cursor interface {
// Image returns the image for the given cursor, or nil if none should be shown.
// It also returns the x and y pixels that should act as the hot-spot (measured from top left corner).
Image() (image.Image, int, int)
}
Cursor interface is used for objects that desire a specific cursor.
Since: 1.0
type Cursorable ¶
type Cursorable interface {
Cursor() Cursor
}
Cursorable describes any CanvasObject that needs a cursor change
type CustomShortcut ¶
type CustomShortcut struct {
event.KeyName
Modifier event.KeyModifier
}
CustomShortcut describes a shortcut desktop event.
func (*CustomShortcut) Key ¶
func (cs *CustomShortcut) Key() event.KeyName
Key returns the key name of this shortcut.
func (*CustomShortcut) Mod ¶
func (cs *CustomShortcut) Mod() event.KeyModifier
Mod returns the modifier of this shortcut.
func (*CustomShortcut) ShortcutName ¶
func (cs *CustomShortcut) ShortcutName() string
ShortcutName returns the shortcut name associated to the event.
type DragData ¶
type DragData struct {
// Text is a plain-text flavor — for example a selection dragged into a text
// editor.
Text string
// URIs are file references dragged out to a file manager. Only file:// URIs
// are carried; other schemes are skipped.
URIs []bellui.URI
// Image is an image flavor and, when set, is also used as the drag image
// that follows the pointer. Nil uses a platform default (the file icon or the
// app icon).
Image image.Image
// DragImageObject is an optional [core.CanvasObject] rendered to supply the
// drag image, bridging the in-canvas drag ghost ([core.DragImageProvider])
// so a widget can declare one drag visual for both in-canvas drag-and-drop
// and drag-out. It is software-rendered to an image when the drag starts and
// only consulted when Image is nil (a raw Image always wins). It carries no
// data flavor — set Text/URIs/Image for the payload.
//
// Since: 1.0
DragImageObject core.CanvasObject
// OnCompleted is an optional callback fired once the native drag finishes,
// reporting whether a target accepted the drop (a copy/move) versus the drag
// being cancelled. It is always called on the main goroutine (via bellui.Do),
// so a source can react to the outcome — for example deleting a file it
// dragged out as a move. Nil to ignore the outcome (fire-and-forget).
//
// Since: 1.0
OnCompleted func(accepted bool)
}
DragData is the payload carried out of the application during a drag-out to another application (Finder/Explorer, a text editor, a browser). Any subset of the flavors may be set; empty or nil fields are omitted from the drag.
It is the outbound counterpart of the inbound bellui.DropEvent.
Since: 1.0
type DragOutProvider ¶
type DragOutProvider interface {
// DragOutData returns the payload to hand to the OS drag and true, or a zero
// value and false to decline (keeping the in-app drag). It is read once at
// drag start and must not depend on prior Dragged calls.
DragOutData() (DragData, bool)
}
DragOutProvider is an optional extension of a drag source (event.Draggable): it lets a driver obtain the drag-out payload at gesture start without relying on the push-based Dragged→[StartDrag] path. It exists for backends that stop delivering pointer-move events once a native drag begins — notably the web (wasm) backend, where the browser's HTML5 Drag and Drop suppresses mousemove/mouseup on the source at dragstart, so the Dragged handler never runs during the drag and there is nothing to hand to the native drag. Such a backend hit-tests at pointerdown, and if the deepest Draggable under the pointer implements DragOutProvider it arms a native drag for that gesture, pulling the payload once at drag start.
Desktop backends keep using the push StartDrag path unchanged; they MAY also consult DragOutProvider (for example to pre-arm). A plain draggable that does not implement it never triggers a drag-out, so in-app dragging is untouched.
Since: 1.0
type DragSource ¶
type DragSource interface {
// StartDragging begins a native drag session carrying data from the key
// window. Call it from a widget's Dragged handler on the main goroutine (a
// native drag may run its own modal loop). It returns false when the driver
// or platform cannot start a native drag, so the caller keeps its in-app drag
// behavior.
StartDragging(data DragData) bool
}
DragSource is an optional capability of a bellui.Driver that starts a native drag-and-drop OUT of the application to other applications. It is the outbound counterpart of the inbound file-drop path (bellui.Droppable).
GLFW exposes no drag-source API, so each desktop backend hand-rolls it against the native window handle; a driver or platform that cannot start a native drag reports false. Detect support with a type assertion, or use StartDrag.
Since: 1.0
type Driver ¶
type Driver interface {
// Create a new borderless window that is centered on screen
CreateSplashWindow() bellui.Window
// Gets the set of key modifiers that are currently active
//
// Since: 1.0
CurrentKeyModifiers() event.KeyModifier
// HasSecondaryDisplay returns true if there are more than one screens available on this computer.
// This is commonly used alongside the desktop [Window.RequestFullScreenSecondary] call.
//
// Since: 1.0
HasSecondaryDisplay() bool
}
Driver represents the extended capabilities of a desktop driver
type GlobalShortcutApp ¶
type GlobalShortcutApp interface {
// RegisterGlobalShortcut binds a system-wide shortcut. handler is invoked on
// the main goroutine each time the shortcut fires. It returns an error if the
// shortcut could not be registered (already owned by another app, an
// unmappable key, or an unsupported platform). Registering the same shortcut
// again replaces its handler.
RegisterGlobalShortcut(shortcut *CustomShortcut, handler func()) error
// UnregisterGlobalShortcut removes a previously registered global shortcut.
// Unknown shortcuts are ignored.
UnregisterGlobalShortcut(shortcut *CustomShortcut)
}
GlobalShortcutApp describes a desktop driver that can register system-wide keyboard shortcuts — hotkeys that fire while the app is unfocused or minimized (push-to-talk, a screenshot tool, a quick-capture note). Unlike bellui.Canvas.AddShortcut these are seen even when no bellui window has focus. Reach it from the running app via
bellui.CurrentApp().Driver().(desktop.GlobalShortcutApp)
Global hotkeys are a contended, OS-mediated resource, so registration returns an error: the combination may already be owned by another application, or the platform may not support it. On Linux Wayland there is no client API by design — registration goes through the org.freedesktop.portal.GlobalShortcuts portal, which may prompt the user for consent and is therefore asynchronous; a nil error there means the request was accepted, not that the binding is necessarily live yet.
Since: 1.0
type KeyModifierDriver ¶
type KeyModifierDriver interface {
// CurrentKeyModifiers returns the set of key modifiers currently active.
CurrentKeyModifiers() event.KeyModifier
// AddKeyModifierListener registers fn to be called on the main goroutine
// whenever the set of active key modifiers changes, regardless of widget
// focus — including a modifier pressed while the pointer rests still, so
// hosts need no hover-move polling. It returns a remove function;
// multiple listeners may be registered. Call on the main goroutine.
AddKeyModifierListener(fn func(event.KeyModifier)) (remove func())
}
KeyModifierDriver describes drivers that track the window-wide keyboard modifier state — updated from every key event (and on the web target from pointer events too), regardless of widget focus — and can notify when it changes. The GLFW driver implements it on both desktop and web targets, so unfocused-widget affordances (e.g. a modifier-hover link highlight) work in the browser as well; assert this instead of Driver when the splash-window capability is not needed.
Since: 1.0
type Keyable ¶
Keyable describes any focusable canvas object that can accept desktop key events. This is the traditional key down and up event that is not applicable to all devices.
type ModalWindow ¶
type ModalWindow interface {
ChildWindow
// SetModal enables or disables native window-modality against the parent
// established with [ChildWindow.SetParent]; call SetParent first. Enabling
// it before Show takes effect as the window maps; toggling it while shown
// applies immediately where the platform allows. Disabling it — or closing
// the window — restores input to the parent.
//
// On platforms or sessions that cannot express window-modality the call is
// a no-op (the scrim still blocks the parent inside the toolkit).
SetModal(modal bool)
}
ModalWindow extends ChildWindow with native window-modality: while this window is shown the window manager blocks input to its parent window (its title bar is greyed and keyboard focus cannot reach it), enforcing at the OS level the modality that the pure-Go modal scrim provides inside the toolkit.
It is the native counterpart to the application-level scrim used by window-hosted dialogs; drivers that support it use both, so the OS and the canvas agree that the parent is blocked.
Windows on mobile and web targets do not implement this interface.
Since: 1.0
type MouseButton ¶
type MouseButton int
MouseButton represents a single button in a desktop MouseEvent
const ( // MouseButtonPrimary is the most common mouse button - on some systems the only one. // This will normally be on the left side of a mouse. // // Since: 1.0 MouseButtonPrimary MouseButton = 1 << iota // MouseButtonSecondary is the secondary button on most mouse input devices. // This will normally be on the right side of a mouse. // // Since: 1.0 MouseButtonSecondary // MouseButtonTertiary is the middle button on the mouse, assuming it has one. // // Since: 1.0 MouseButtonTertiary )
type MouseEvent ¶
type MouseEvent struct {
event.PointEvent
Button MouseButton
Modifier event.KeyModifier
}
MouseEvent contains data relating to desktop mouse events
type Mouseable ¶
type Mouseable interface {
MouseDown(*MouseEvent)
MouseUp(*MouseEvent)
}
Mouseable represents desktop mouse events that can be sent to CanvasObjects
type PositionableWindow ¶
type PositionableWindow interface {
Window
// Position returns the most recently known position of the window on the
// virtual desktop, in the same native coordinates as [Window.RequestPosition].
// While the window is fullscreen this keeps reporting the last windowed
// position, so a save-on-exit records a useful restore point.
// Before the window has been shown it reports the last requested position,
// or (0, 0) if none was requested.
Position() (x, y int)
// SetOnMoved sets a callback that runs on the main goroutine every time
// the window is moved, with the new position in the same native
// coordinates as [Window.RequestPosition]. Moves caused by entering
// fullscreen are not reported. Pass nil to remove the callback.
SetOnMoved(func(x, y int))
}
PositionableWindow extends Window with position read-back and a move subscription, so applications can tile windows, or save and restore window geometry across runs. Coordinates use the same loose native-system contract as Window.RequestPosition — a position read from PositionableWindow.Position can be passed back to RequestPosition verbatim, but carries no unit guarantee beyond that round-trip.
On Linux Wayland the compositor never reveals global window positions, so Position only echoes back the last requested position (zero if none was requested) and OnMoved callbacks do not fire.
Windows on mobile and web targets do not implement this interface.
Since: 1.0
type ProgressWindow ¶
type ProgressWindow interface {
Window
// SetProgress shows task progress in the range 0..1 (values outside the
// range are clamped). A negative value clears the indicator. When
// indeterminate is true the platform shows a busy/marquee animation and the
// value is ignored. Safe to call before or after the window is shown; a call
// before Show is applied once the window maps.
SetProgress(value float64, indeterminate bool)
}
ProgressWindow extends Window with a task-progress indicator drawn on the window's taskbar button (Windows, the flagship for this) or the application's launcher/dock icon on other desktops. It is the natural home for "download is 40% done" or "export running" feedback without a modal progress dialog.
The indicator is advisory and best-effort: platforms without a native progress affordance (currently macOS, and Linux desktops that do not honour the Unity LauncherEntry protocol) treat it as a no-op.
Windows on mobile and web targets do not implement this interface.
Since: 1.0
type ScreenArea ¶
ScreenArea describes a rectangle on the virtual desktop in the same loose native-system coordinates as Window.RequestPosition — positions inside it can be passed to RequestPosition verbatim.
Since: 1.0
type ScreenInfo ¶
type ScreenInfo struct {
// Name is the system-reported name of the display.
Name string
// Bounds is the full extent of the display on the virtual desktop.
Bounds ScreenArea
// WorkArea is the part of Bounds not occupied by task bars, docks or
// menu bars. On systems that do not report a work area it equals Bounds.
WorkArea ScreenArea
// Scale is the output scale Bellui detected for this display — the factor
// between Bellui's device-independent units and the display's native
// coordinates, before any user scale preference is applied.
Scale float32
// Primary reports whether this is the system's primary display.
Primary bool
}
ScreenInfo describes a single display attached to the system, providing enough information for window placement logic — restoring a saved position onto a screen that still exists, or placing a window on a specific display. It is deliberately not a display-configuration API.
Since: 1.0
type ScreensDriver ¶
type ScreensDriver interface {
// Screens returns information about every display attached to the
// system, in system order. The primary display has Primary set.
Screens() []ScreenInfo
}
ScreensDriver describes drivers that can enumerate the displays attached to the system. The GLFW desktop driver implements it; mobile and web drivers do not. Call on the main goroutine.
On Linux Wayland global coordinates are compositor-private, so the reported bounds are best-effort and may not relate to actual window positions.
Since: 1.0
type StandardCursor ¶
type StandardCursor int
StandardCursor represents a standard Bellui cursor. These values were previously of type `bellui.Cursor`.
Since: 1.0
const ( // DefaultCursor is the default cursor typically an arrow DefaultCursor StandardCursor = iota // TextCursor is the cursor often used to indicate text selection TextCursor // CrosshairCursor is the cursor often used to indicate bitmaps CrosshairCursor // PointerCursor is the cursor often used to indicate a link PointerCursor // HResizeCursor is the cursor often used to indicate horizontal resize HResizeCursor // VResizeCursor is the cursor often used to indicate vertical resize VResizeCursor // HiddenCursor will cause the cursor to not be shown HiddenCursor // GrabCursor indicates an item that can be grabbed to drag (open-hand style). // // Since: 1.0 GrabCursor // GrabbingCursor indicates an item currently being dragged (closed-hand / // move style); the driver applies it for the duration of a Draggable drag. // // Since: 1.0 GrabbingCursor // NWSEResizeCursor is the cursor often used to indicate diagonal resize // from the top-left or bottom-right corner (northwest–southeast), such as // the bottom-right resize corner of an [github.com/belluikit/bellui/container.InnerWindow]. // // Since: 1.0 NWSEResizeCursor // NESWResizeCursor is the cursor often used to indicate diagonal resize // from the bottom-left or top-right corner (northeast–southwest). // // Since: 1.0 NESWResizeCursor )
type Window ¶
type Window interface {
// RequestFullScreenSecondary asks for a window to fullscreen on a non-primary monitor.
// When there is only one screen it will fullscreen on the primary monitor.
RequestFullScreenSecondary()
// RequestAlwaysOnTop asks for the window to remain above other windows, call before [bellui.Window.Show].
// This is subject to support on the current system and with the caveat that the window manager
// may decide that other windows or panels remain above this one.
RequestAlwaysOnTop()
// RequestPosition asks the operating system to position this window at the x, y coordinate
// of the native system. These values may be scaled and so not necessarily pixel values.
// This request may be ignored (for example Linux Wayland).
// There is no contract of what these values represent and on multiple monitors may be greater
// than the coordinates of the current monitor.
RequestPosition(x, y int)
}
Window describes desktop specific window features.
The method set matches the upstream Bellui 2.8 desktop.Window interface so that code written against upstream asserts and works unchanged here.
Since: 1.0