Tickit::Window(3pm)

๐Ÿฆ‹ Tickit::Window(3pm) ๐Ÿฆ‹

okay bestie, this lilโ€™ page comes from the User Contributed Perl Documentation shelf ๐Ÿ’– and itโ€™s literally all about Tickit::Window โ€” the window object you draw into. no cap.


๐ŸŒธ NAME ๐ŸŒธ

"Tickit::Window" โ€” a window for drawing operations. periodt. ๐Ÿ’…


โœจ SYNOPSIS โœจ

Hereโ€™s the whole vibe in code, exactly as printed:

 use Tickit;
 use Tickit::Pen;

 my $tickit = Tickit->new;

 my $rootwin = $tickit->rootwin;

 $rootwin->bind_event( expose => sub {
    my ( $win, undef, $info ) = @_;

    my $rb = $info->rb;

    $rb->clear;

    $rb->text_at(
       int( $win->lines / 2 ), int( ($win->cols - 12) / 2 ),
       "Hello, world"
    );
 });
 $rootwin->bind_event( geomchange => sub { shift->expose } );
 $rootwin->set_pen( Tickit::Pen->new( fg => "white" ) );

 $rootwin->expose;
 $tickit->run;

๐Ÿ’– DESCRIPTION ๐Ÿ’–

So this class provides coordination of widget drawing activities. A "Window" represents a region of the screen that a widget occupies. iconic.

Windows cannot directly be constructed. Instead they are obtained by sub-division of other windows, ultimately coming from the root window associated with the terminal. thatโ€™s the whole family tree, bestie ๐ŸŒณ

Normally all windows are visible, but a window may be hidden by calling the hide method. After this, the window will not respond to any of the drawing methods, until it is made visible again with the show method. A hidden window will not receive focus or input events. It may still receive geometry change events if it is resized. lowkey important ๐Ÿ’…

๐ŸŒฑ Sub Windows ๐ŸŒฑ

A division of a window made by calling make_sub or make_float obtains a window that represents some portion of the drawing area of the parent window. Child windows are stored in order; make_sub adds a new child to the end of the list, and make_float adds one at the start. stack โ€™em, bestie ๐Ÿฅž

Higher windows (windows more towards the start of the list), will always handle input events before lower siblings. The extent of windows also obscures lower windows; drawing on lower windows may not be visible because higher windows are above it. so yes, the higher ones are main character energy ๐Ÿ‘‘

๐ŸŒ€ Deferred Child Window Operations ๐ŸŒ€

In order to minimise the chances of ordering-specific bugs in window event handlers that cause child window creation, reordering or deletion, the actual child window list is only mutated after the event processing has finished, by using a Tickit later block. the window list is not messy; it is simply fashionably late ๐Ÿ˜Œ


๐Ÿ› ๏ธ METHODS ๐Ÿ› ๏ธ

okay, method time. every signature is copied exactly, because we do not mess with the code. ๐Ÿ’…

๐Ÿ“ฆ close

$win->close

Removes the window from its parent and clears any event handlers set using bind_event. Also recursively closes any child windows. bye bye, cleanly ๐Ÿซถ

๐Ÿšจ heads up: currently this is an optional method, as child windows are stored as weakrefs, so should be destroyed when the last reference to them is dropped. Widgets should make sure to call this method anyway, because this will be changed in a future version. like, please still call it, bestie.

๐ŸŒฑ make_sub

$sub = $win->make_sub( $top, $left, $lines, $cols )

Constructs a new sub-window of the given geometry, and places it at the end of the child window list; below any other siblings. it goes to the back of the sibling queue ๐ŸŽ€

๐Ÿ™ˆ make_hidden_sub

$sub = $win->make_hidden_sub( $top, $left, $lines, $cols )

Constructs a new sub-window like make_sub, but the window starts initially hidden. This avoids having to call hide separately afterwards. stealth mode activated ๐Ÿ’€

๐Ÿฆ‹ make_float

$float = $win->make_float( $top, $left, $lines, $cols )

Constructs a new sub-window of the given geometry, and places it at the start of the child window list; above any other siblings. front of the line, no cap โœจ

๐ŸŽ€ make_popup

$popup = $win->make_popup( $top, $left, $lines, $cols )

Constructs a new floating popup window starting at the given coordinates relative to this window. It will be sized to the given limits.

This window will have the root window as its parent, rather than the window the method was called on. Additionally, a popup window will steal all keyboard and mouse events that happen, regardless of focus or mouse position. It is possible that, if the window has an on_mouse handler, that it may receive mouse events from outside the bounds of the window. popup said โ€œmine nowโ€ and honestly? valid. ๐Ÿ’…

๐Ÿท๏ธ bind_event

$id = $win->bind_event( $ev, $code, $data )

Installs a new event handler to watch for the event specified by $ev, invoking the $code reference when it occurs. $code will be invoked with the given window, the event name, an event information object, and the $data value it was installed with. bind_event returns an ID value that may be used to remove the handler by calling unbind_event_id.

 $ret = $code->( $win, $ev, $info, $data )

The type of $info will depend on the kind of event that was received, as indicated by $ev. The information structure types are documented in Tickit::Event. iykyk ๐Ÿ“š

๐Ÿšฉ bind_event (with flags)

$id = $win->bind_event( $ev, $flags, $code, $data )

The $code argument may optionally be preceded by an integer of flag values. This should be zero to apply default semantics, or a bitmask of constants. The constants are documented in "bind_event (with flags)" in Tickit::Term. flags are giving options, bestie ๐Ÿณ๏ธ

โœ‚๏ธ unbind_event_id

$win->unbind_event_id( $id )

Removes an event handler that returned the given $id value. unsubscribe energy ๐Ÿ”Œ

โฌ†๏ธ raise

$win->raise

Moves the order of the window in its parent one higher relative to its siblings. up up up โฌ†๏ธ

โฌ‡๏ธ lower

$win->lower

Moves the order of the window in its parent one lower relative to its siblings. down down down โฌ‡๏ธ

๐Ÿ‘‘ raise_to_front

$win->raise_to_front

Moves the order of the window in its parent to be the front-most among its siblings. main character, front row, no notes ๐Ÿ’…

๐Ÿซฅ lower_to_back

$win->lower_to_back

Moves the order of the window in its parent to be the back-most among its siblings. background character era ๐ŸŒซ๏ธ

๐Ÿ‘ฏ parent

$parentwin = $win->parent

Returns the parent window; i.e. the window on which make_sub or make_float was called to create this one. itโ€™s giving family tree ๐ŸŒณ

๐Ÿงš subwindows

@windows = $win->subwindows

Returns a list of the subwindows of this one. They are returned in order, highest first. the children are lined up by importance ๐Ÿ’–

๐ŸŒˆ root

$rootwin = $win->root

Returns the root window. the original ancestor, the final boss ๐Ÿ‘‘

๐Ÿ–ฅ๏ธ term

$term = $win->term

Returns the Tickit::Term instance of the terminal on which this window lives.

โš ๏ธ note that it is not guaranteed that this method will return the same Perl-level terminal instance that the root window was constructed with. In particular, if the root window in fact lives on a mock terminal created by Tickit::Test::MockTerm this method may โ€œforgetโ€ this fact, returning an object instance simply in the Tickit::Term class instead. While the instance will still be useable as a terminal, the fact it was a mock terminal may get forgotten. mock terminal amnesia is real ๐Ÿ˜ญ

๐Ÿชฉ tickit

$tickit = $win->tickit

Returns the Tickit instance with which this window is associated. the whole event ecosystem, linked ๐Ÿ’ซ

๐Ÿ‘€ show

$win->show

Makes the window visible. Allows drawing methods to output to the terminal. Calling this method also exposes the window, invoking the on_expose handler. Shows the cursor if this window currently has focus. welcome back to the screen, bestie โœจ

๐Ÿ™ˆ hide

$win->hide

Makes the window invisible. Prevents drawing methods outputting to the terminal. Hides the cursor if this window currently has focus. ghost mode, but make it terminal ๐Ÿ’€

โœ… is_visible

$visible = $win->is_visible

Returns true if the window is currently visible. vibe check: visible or not? ๐Ÿซถ

๐Ÿ“ resize

$win->resize( $lines, $cols )

Change the size of the window. grow, shrink, slay ๐Ÿ“

๐Ÿšš reposition

$win->reposition( $top, $left )

Move the window relative to its parent. new coordinates, same window ๐Ÿ’…

๐Ÿ”„ change_geometry

$win->change_geometry( $top, $left, $lines, $cols )

A combination of resize and reposition, to atomically change all the coordinates of the window. Will only invoke on_geom_changed once, rather than twice as would be the case calling the above methods individually. one event, not two โ€” efficiency icon โšก

๐Ÿ”† expose

$win->expose( $rect )

Marks the given region of the window as having been exposed, to invoke the on_expose event handler on itself, and all its child windows. The windowโ€™s own handler will be invoked first, followed by all the child windows, in screen order (top to bottom, then left to right).

If $rect is not supplied it defaults to exposing the entire window area.

The on_expose event handler isnโ€™t invoked immediately; instead, the Tickit later method is used to invoke it at the next round of IO event handling. Until then, any other window could be exposed. Duplicates are suppressed; so if a window and any of its ancestors are both queued for expose, the actual handler will only be invoked once per unique region of the window. queued, deduped, and served fresh โœจ

๐ŸŽ›๏ธ getctl / setctl

$value = $win->getctl( $ctl )

$success = $win->setctl( $ctl, $value )

Accessor and mutator for window control options. $ctl should be one of the following options:

  • cursor-blink (bool) โ€” cursor property for the terminal cursor when this window has input focus.
  • cursor-shape (int) โ€” cursor property for the terminal cursor when this window has input focus.
  • cursor-visible (bool) โ€” cursor property for the terminal cursor when this window has input focus.
  • focus-child-notify (bool) โ€” whether the window will also receive focus events about child windows.
  • steal-input (bool) โ€” whether the window is currently stealing input from its siblings.

control options said โ€œcustomize meโ€ and honestly? valid ๐ŸŽ€

๐Ÿงธ set_focus_child_notify

$win->set_focus_child_notify( $notify )

If set to a true value, the on_focus event handler will also be invoked when descendent windows gain or lose focus, in addition to when it gains or loses focus itself. Defaults to false; meaning the on_focus handler only receives notifications about the window itself. nosy? no bestie, informed ๐Ÿ’…

๐Ÿ“ top / bottom / left / right

$top    = $win->top

$bottom = $win->bottom

$left   = $win->left

$right  = $win->right

Returns the coordinates of the start of the window, relative to the parent window. corners and edges, all accounted for ๐Ÿงญ

๐ŸŒ abs_top / abs_left

$top  = $win->abs_top

$left = $win->abs_left

Returns the coordinates of the start of the window, relative to the root window. absolute coordinates, absolute slay โœจ

๐Ÿ“ cols / lines

$cols  = $win->cols

$lines = $win->lines

Obtain the size of the window. width and height said hello ๐Ÿซถ

๐Ÿชž selfrect

$rect = $win->selfrect

Returns a Tickit::Rect representing the windowโ€™s extent within itself. This will have top and left equal to 0. selfie rect, but make it geometry ๐Ÿ“ธ

๐Ÿ–ผ๏ธ rect

$rect = $win->rect

Returns a Tickit::Rect representing the windowโ€™s extent relative to its parent. coordinates, but in the family group chat ๐Ÿ’ฌ

๐Ÿ–Š๏ธ pen

$pen = $win->pen

Returns the current Tickit::Pen object associated with this window. the aesthetic object, iconic ๐Ÿ’…

๐ŸŽจ set_pen

$win->set_pen( $pen )

Replace the current Tickit::Pen object for this window with a new one. The object reference will be stored, allowing it to be shared with other objects. If undef is set, then a new, blank pen will be constructed. new pen, new era ๐Ÿ–Œ๏ธ

๐Ÿ” getpenattr

$val = $win->getpenattr( $attr )

Returns a single attribute from the current pen. one attribute, no extras โœจ

๐ŸŒˆ get_effective_pen

$pen = $win->get_effective_pen

Returns a new Tickit::Pen containing the effective pen attributes for the window, combined by those of all its parents. inherited aesthetics, bestie ๐Ÿงฌ

๐Ÿงฎ get_effective_penattr

$val = $win->get_effective_penattr( $attr )

Returns the effective value of a pen attribute. This will be the value of this windowโ€™s attribute if set, or the effective value of the attribute from its parent. parentโ€™s settings are still in the group chat ๐Ÿ’ฌ

๐Ÿ“œ scrollrect

Three call forms, exactly as written:

$success = $win->scrollrect( $rect, $downward, $rightward )

$success = $win->scrollrect( $top, $left, $lines, $cols, $downward, $rightward )

$success = $win->scrollrect( ..., $pen )
$success = $win->scrollrect( ..., %attrs )

Okay so scrollrect is the โ€œtry to scroll a rectangleโ€ method, and itโ€™s giving very brave energy. You give it a rectangle โ€” either as a Tickit::Rect or as the first four parameters โ€” and then the last two parameters are the amount to scroll by. Since most terminals cannot perform arbitrary rectangle scrolling, this method returns a boolean to show whether it actually worked. Bestie, the caller should test this return value and fall back to another drawing strategy if the attempt was unsuccessful. ๐Ÿ’…

Optionally, a Tickit::Pen instance or a hash of pen attributes may be provided, to override the background colour used for erased sections behind the scroll. ๐ŸŽ€

The cursor may move as a result of calling this method; its location is undefined if this method returns successful. The terminal pen, in particular the background colour, may be modified by this method even if it fails to scroll the terminal (and returns false). Also, this method will enqueue all of the required expose requests before returning, so in this case the return value is not interesting. ๐Ÿซ 

๐Ÿ’… scroll

$success = $win->scroll( $downward, $rightward )

A shortcut for calling scrollrect on the entire region of the window. Simple, iconic, no notes. โœจ

๐ŸŒ€ scroll_with_children

$win->scroll_with_children( $downward, $rightward )

Similar to scroll but ignores child windows of this one, moving all of the terminal content while paying attention only to obscuring by newer siblings of ancestor windows. ๐Ÿ‘‘

This method is experimental, intended only for use by Tickit::Widget::ScrollBox. After calling this method, the terminal content will have moved and the windows drawing them will be confused unless the window position was also updated. ScrollBox takes care to do this. ๐Ÿšจ

๐ŸŽ€ cursor_at

$win->cursor_at( $line, $col )

Sets the position in the window at which the terminal cursor will be placed if this window has focus. This method does not force the window to take the focus though; for that see take_focus. ๐Ÿซถ

๐Ÿซฃ cursor_visible

$win->cursor_visible( $visible )

Sets whether the terminal cursor is visible on the window when it has focus. Normally it is, but passing a false value will make the cursor hidden even when the window is focused. Blink twice if you need help. ๐Ÿ™ˆ

๐Ÿ’… cursor_shape

$win->cursor_shape( $shape )

Sets the shape that the terminal cursor will have if this window has focus. This method does not force the window to take the focus though; for that see take_focus. Valid values for $shape are the various CURSORSHAPE_* constants from Tickit::Term. โœจ

๐Ÿ‘‘ take_focus

$win->take_focus

Causes this window to take the input focus, and updates the cursor position to the stored active position given by cursor_at. Main character energy: acquired. ๐Ÿ”ฅ

โœจ focus

$win->focus( $line, $col )

A convenient shortcut combining cursor_at with take_focus; setting the focus cursor position and taking the input focus. ๐ŸŽ€

๐Ÿฆ‹ is_focused

$focused = $win->is_focused

Returns true if this window currently has the input focus. ๐Ÿ’–

๐Ÿ’€ is_steal_input

$steal = $win->is_steal_input

Returns true if this window is currently stealing input from its siblings. Sneaky little icon. ๐Ÿ˜ญ

๐Ÿ”ฅ set_steal_input

$win->set_steal_input( $steal )

Controls whether this window is currently stealing input from its siblings. ๐Ÿซถ


๐ŸŒธ EVENTS ๐ŸŒธ

The following event types are emitted and may be observed by bind_event. Event girlies, this is your moment. ๐Ÿ’…

โŒจ๏ธ key

Emitted when a key on the keyboard is pressed while this window or one of its child windows has the input focus, or is set to steal input anyway. ๐Ÿ”‘

The event handler should return a true value if it considers the keypress dealt with, or false to pass it up to its parent window. ๐Ÿ“จ

Before passing it to its parent, a window will also try any other non-focused sibling windows of the currently-focused window in order of creation (though note this order is not necessarily the order the child widgets that own those windows were created or added to their container). ๐ŸŒ€

If no window actually handles the keypress, then every window will eventually be consulted about it, preferring windows closer to the focused one. ๐Ÿ‘€

This broadcast-like behaviour allows widgets to handle keypresses that should make sense even though their window does not actually have the keyboard focus. This feature should be used sparingly, to only capture one or two keypresses that really make sense; for example to capture the PageUp and PageDown keys in a scrolling list, or a numbered function key that performs some special action. Donโ€™t be greedy with it, bestie. ๐Ÿ“

๐Ÿ–ฑ๏ธ mouse

Emitted when a mouse button is pressed or released, the cursor moved while a button is held (a dragging event), or the wheel is scrolled. ๐Ÿซถ

The following event names may be observed:

  • press โ€” A mouse button has been pressed down on this cell. ๐ŸŽฏ
  • drag_start โ€” The mouse was moved while a button was held, and was initially in the given cell. ๐ŸŒ€
  • drag โ€” The mouse was moved while a button was held, and is now in the given cell. ๐Ÿ‘‘
  • drag_outside โ€” The mouse was moved outside of the window that handled the drag_start event, and is still being dragged. ๐Ÿšช
  • drag_drop โ€” A mouse button was released after having been moved, while in the given cell. ๐Ÿ’…
  • drag_stop โ€” The drag operation has finished. This event is always given directly to the window that handled the drag_start event, rather than the window on which the mouse release event happened. ๐Ÿ›‘
  • release โ€” A mouse button was released after being pressed. โœจ
  • wheel โ€” The mouse wheel was moved. button will indicate the wheel direction as a string "up" or "down". ๐ŸŽก

The invoked code should return a true value if it considers the mouse event dealt with, or false to pass it up to its parent window. ๐Ÿ“จ

Once a dragging operation has begun via drag_start, the window that handled the event will always receive drag, drag_outside, and an eventual drag_stop event even if the mouse moves outside that window. No other window will receive a drag_outside or drag_stop event than the one that started the operation. ๐Ÿ’–

๐Ÿฆ‹ geomchange

Emitted when the window is resized or repositioned; i.e. whenever its geometry changes. Glow-up or glow-down, the event knows. ๐ŸŒˆ

๐ŸŒธ expose

Emitted when a region of the window is exposed by the expose method, or implicitly because it or another window has changed size, been shown or hidden, or the stacking order has been changed. ๐Ÿ‘€

When invoked, render buffer passed in the event will have its origin set to that of the window, and its clipping will be set to the damage rectangle. ๐ŸŽ€

If any child windows overlap the region, these will be exposed first, before the containing window. Children first, always. ๐Ÿงš

๐Ÿ’– focus

Emitted when the window gains or loses input focus. โœจ

If the focus-child-notify behavior is enabled, this callback is also invoked for changes of focus on descendent windows. In this case, it is passed an additional argument, being the immediate child window in which the focus chain has now changed (which may or may not be the focused window directly; it could itself be another ancestor). ๐ŸŒ€

When a window gains focus, any of its ancestors that have focus-child-notify enabled will be informed first, from the outermost inwards, before the window itself. When one loses focus, it is notified first, and then its parents from the innermost outwards. Family group chat rules, honestly. ๐Ÿ’ฌ


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Paul Evans <leonerd@leonerd.org.uk> ๐Ÿ’Œ

๐Ÿ’– Thatโ€™s the page, bestie! This one comes from perl v5.42.3, dated 2026-08-19, and itโ€™s the Tickit::Window(3pm) manual. Go make those windows behave. ๐ŸŽ€

๐Ÿ“ฆ where this page comes from