API
WindowAbstractions.BUTTON_PRESSED
WindowAbstractions.BUTTON_RELEASED
WindowAbstractions.KEY_PRESSED
WindowAbstractions.KEY_RELEASED
WindowAbstractions.NO_EVENT
WindowAbstractions.POINTER_ENTERED
WindowAbstractions.POINTER_EXITED
WindowAbstractions.POINTER_MOVED
WindowAbstractions.WINDOW_CLOSED
WindowAbstractions.WINDOW_EXPOSED
WindowAbstractions.WINDOW_GAINED_FOCUS
WindowAbstractions.WINDOW_INVALID
WindowAbstractions.WINDOW_LOST_FOCUS
WindowAbstractions.WINDOW_RESIZED
Core.Type
WindowAbstractions.AbstractWindow
WindowAbstractions.AbstractWindowManager
WindowAbstractions.Event
WindowAbstractions.EventQueue
WindowAbstractions.EventType
WindowAbstractions.KeyCombination
WindowAbstractions.KeyEvent
WindowAbstractions.KeySymbol
WindowAbstractions.MouseEvent
WindowAbstractions.PointerState
Base.close
WindowAbstractions.collect_events!
WindowAbstractions.dpi
WindowAbstractions.extent
WindowAbstractions.get_window
WindowAbstractions.key_symbol
WindowAbstractions.map_window
WindowAbstractions.poll_for_events!
WindowAbstractions.replay_history
WindowAbstractions.resize
WindowAbstractions.save_history
WindowAbstractions.set_icon
WindowAbstractions.set_icon_title
WindowAbstractions.set_title
WindowAbstractions.unmap_window
WindowAbstractions.windows
WindowAbstractions.@key_str
WindowAbstractions.BUTTON_PRESSED
— ConstantA mouse button was released.
WindowAbstractions.BUTTON_RELEASED
— ConstantThe pointer entered the window area.
WindowAbstractions.KEY_PRESSED
— ConstantA key was pressed. Note that some key combinations can be reserved by the OS, so they don't trigger the corresponding event. On Ubuntu 20.04, this is for example the case with some combinations of the form alt+fkey such as alt+f4.
WindowAbstractions.KEY_RELEASED
— ConstantA key was released.
WindowAbstractions.NO_EVENT
— ConstantSignals an absence of event.
WindowAbstractions.POINTER_ENTERED
— ConstantA mouse button was pressed.
WindowAbstractions.POINTER_EXITED
— ConstantThe pointer left the window area.
WindowAbstractions.POINTER_MOVED
— ConstantThe pointer moves in the window.
WindowAbstractions.WINDOW_CLOSED
— ConstantThe window was closed, e.g. manually by the user or by a programmatic action.
WindowAbstractions.WINDOW_EXPOSED
— ConstantA window was exposed to the screen; either right after creation, or when it was previously hidden and then visible again.
WindowAbstractions.WINDOW_GAINED_FOCUS
— ConstantThe window gained focus.
WindowAbstractions.WINDOW_INVALID
— ConstantThe window is detected as invalid (for example, when closed externally).
The conditions for tagging a window as invalid depend on the windowing API used. It is typically used to signal that a window crashed or does not exist, but for which an event was reported. It may however not possible to know exactly why or when a window becomes invalid. For example, the X11 protocol does not offer a way to check for window validity, since the window may get invalidated by the time the X server answer comes back. Windows that are tagged invalid should be terminated.
WindowAbstractions.WINDOW_LOST_FOCUS
— ConstantThe window lost focus.
WindowAbstractions.WINDOW_RESIZED
— ConstantThe window was resized.
Core.Type
— Method(::Type{<:AbstractWindow})(wm::AbstractWindowManager; kwargs...)
Create a window.
WindowAbstractions.AbstractWindow
— TypeAbstract window type.
abstract type AbstractWindow
WindowAbstractions.AbstractWindowManager
— TypeEntity that manages windows.
abstract type AbstractWindowManager
WindowAbstractions.Event
— TypeGeneric event structure identified by its type (see EventType
) and which may hold data depending on the type of event.
The type of data
follows the association (with respect to the event type):
KEY_PRESSED
orKEY_RELEASED
:KeyEvent
, accessible withevent.key_event
BUTTON_PRESSED
orBUTTON_RELEASED
:MouseEvent
, accessible withevent.mouse_event
POINTER_MOVED
:PointerState
, accessible withevent.pointer_state
WINDOW_RESIZED
:Tuple{Float64,Float64}
# new dimensions, accessible withevent.new_dimensions
WINDOW_EXPOSED
:Tuple{Float64,Float64}
# area to redraw, accessible withevent.area
- Other event types:
Nothing
struct Event{W<:AbstractWindow}
type::EventType
data::Any
location::Tuple{Float64, Float64}
time::Float64
win::AbstractWindow
WindowAbstractions.EventQueue
— TypeEvent queue meant to hold events to be processed by an application.
The event queue is bound to a window manager, and will be filled upon notification of low-level events sent by that window manager. Only high-level events will be recorded in the event queue, which are typically suited for use in applications.
The event queue is infinitely iterable, returning Event
s as they are received. When no events are available, the queue will either enter a sleeping state of approximately 1 ms (if sleep = true
) or spin while yielding at every iteration.
Any task iterating over the event queue is therefore a good candidate to be scheduled using an interactive thread from Julia 1.9 onwards.
Alternatively, the event queue may be manually filled with collect_events!
and processed using Base.isempty
and Base.popfirst!
.
The parameter record_history
may be set to true
to save all events that have been processed (either by iteration or manual Base.popfirst!
). Implementations of window managers may extend save_history
and replay_history
to allow for the saving and replay of events that have been stored. Note that record_history
will have to be set to true for save_history
to work.
struct EventQueue{WM<:AbstractWindowManager, W<:AbstractWindow}
wm::AbstractWindowManager
events::Array{Event{W}, 1} where W<:AbstractWindow
history::Array{Event{W}, 1} where W<:AbstractWindow
sleep::Bool
record_history::Bool
WindowAbstractions.EventType
— TypeType of input or window event which may occur on a particular window.
This type is defined as a bitmask, to make it easier to work with sets of events.
struct EventType <: BitMasks.BitMask{UInt32}
val::UInt32
WindowAbstractions.KeyCombination
— TypeKey binding associated to a character and a key modifier state.
struct KeyCombination
key::KeySymbol
exact_modifiers::ModifierState
significant_modifiers::ModifierState
WindowAbstractions.KeyEvent
— TypeDetails surrounding an event produced by a keystroke.
struct KeyEvent
key_name::Symbol
: The name of the physical key.
key::KeySymbol
: The symbol associated with the keystroke.
input::Char
: Printable input (can be the empty string).
modifiers::ModifierState
: Modifier state.
consumed_modifiers::ModifierState
: Modifiers that were used when translating the physical key into a key symbol.
WindowAbstractions.KeySymbol
— TypeRepresentation of a symbol that may be bound to a key, depending on a keyboard layout. It differs from the physical representation of a key, denoted by names such as AD01
which represent physical keys (in this case, q
on a US keyboard). A key symbol is sent when a physical key is pressed, even if no input character is bound to the key. This structure provides a friendly symbol
field, and a prettier description
field (mostly used for printing). For example, the right arrow, with symbol :right_arrow
(resp. :kp_right_arrow
for keypad input), is represented by "→"
(resp. "→ (keypad)"
).
There is no consistent representation, so the one provided here may differ from windowing API implementations.
struct KeySymbol
name::Symbol
description::Union{Char, String}
WindowAbstractions.MouseEvent
— TypeA mouse press/release associated to a certain state.
struct MouseEvent
button::MouseButton
state::MouseButton
WindowAbstractions.PointerState
— TypeContext in which a pointer motion was performed, including active mouse buttons and keyboard modifiers.
struct PointerState
state::MouseButton
modifiers::ModifierState
Base.close
— Methodclose(wm::AbstractWindowManager, win::AbstractWindow)
Close a window.
close(wm::AbstractWindowManager, _::AbstractWindow)
WindowAbstractions.collect_events!
— MethodGather all pending events.
collect_events!(queue::EventQueue)
WindowAbstractions.dpi
— MethodGet window DPI.
dpi(win::AbstractWindow)
WindowAbstractions.extent
— MethodWindow dimensions (width, height).
extent(win::AbstractWindow)
WindowAbstractions.get_window
— MethodRetrieve a window given an identifier id
, would typically be an integer identifier, a handle or a name.
get_window(wm::AbstractWindowManager, id)
WindowAbstractions.key_symbol
— MethodDefine an internal representation and a readable description for some key inputs.
The keys that are listed here are not exhaustive and only cover a very small subset of all possible keys.
key_symbol(name::Symbol) -> Any
WindowAbstractions.map_window
— MethodMap a window to the screen.
map_window(win::AbstractWindow)
WindowAbstractions.poll_for_events!
— MethodNon-blocking poll for events. Must return whether a client event was consumed, even if no Event
is added to the queue.
poll_for_events!(queue::EventQueue)
WindowAbstractions.replay_history
— Functionreplay_history(wm, events)
Replay events generated by save_history
on the provided window manager.
Delays between events should be respected. The window manager is free to assume that no other event will be generated during the replay: user interactinos with the window while the replay is ongoing may affect the integrity of the replication.
Note that any global state such as RNG is not saved; the application is responsible for managing state appropriately for effects outside of the event system.
WindowAbstractions.resize
— MethodResize the window with extent
reflecting the new (width, height).
resize(win::AbstractWindow, extent)
WindowAbstractions.save_history
— Functionsave_history(wm::WM, queue::EventQueue{WM}) -> Vector{<:Event}
Save actions stored inside the event queue for later replay with replay_history
.
The event queue must have been created with record_history = true
.
WindowAbstractions.set_icon
— MethodSet window icon.
set_icon(win::AbstractWindow, icon)
WindowAbstractions.set_icon_title
— MethodSet window icon title.
set_icon_title(win::AbstractWindow, icon_title)
WindowAbstractions.set_title
— MethodSet window title.
set_title(win::AbstractWindow, title)
WindowAbstractions.unmap_window
— MethodUnmap a window from the screen.
unmap_window(win::AbstractWindow)
WindowAbstractions.windows
— MethodRetrieve all the AbstractWindow
s in use by wm
.
windows(wm::AbstractWindowManager)
WindowAbstractions.@key_str
— MacroConstruct a KeyCombination instance from a string as "[<state_1>+[...<state_n>+]]<key>"
. The string must be a list of elements separated by '+' characters, with only one key symbol at the end. For example, "k"
, "alt+k"
and "ctrl+alt+shift+f11"
are valid strings, but "k+a"
is not. Casing is significant, as z
and Z
are different key symbols. For modifier strings, the casing should be lowercase, or will be forcefully converted into a lowercase string (reducing performance).