PatchworkOS
Loading...
Searching...
No Matches

Window. More...

Data Structures

struct  window_t
 Opaque window structure. More...
 

Typedefs

typedef struct window window_t
 

Enumerations

enum  window_flags_t {
  WINDOW_NONE = 0 ,
  WINDOW_DECO = 1 << 0 ,
  WINDOW_RESIZABLE = 1 << 1 ,
  WINDOW_NO_CONTROLS = 1 << 2
}
 Window flags. More...
 

Functions

window_twindow_new (display_t *disp, const char *name, const rect_t *rect, surface_type_t type, window_flags_t flags, procedure_t procedure, void *private)
 Allocate and initialize a new window.
 
void window_free (window_t *win)
 Free a window.
 
rect_t window_get_rect (window_t *win)
 Get the window's rectangle in screen coordinates.
 
rect_t window_content_rect (window_t *win)
 Get the window's rectangle in local coordinates.
 
display_twindow_get_display (window_t *win)
 Get the display associated with the window.
 
surface_id_t window_get_id (window_t *win)
 Get the surface ID of the window.
 
surface_type_t window_get_type (window_t *win)
 Get the surface type of the window.
 
element_twindow_get_client_element (window_t *win)
 Get the client element of the window.
 
uint64_t window_move (window_t *win, const rect_t *rect)
 Move and/or resize the window.
 
uint64_t window_set_timer (window_t *win, timer_flags_t flags, clock_t timeout)
 Set the window timer.
 
void window_invalidate (window_t *win, const rect_t *rect)
 Invalidate a rectangle of the window.
 
uint64_t window_invalidate_flush (window_t *win)
 Flush invalidated rectangles to the DWM.
 
uint64_t window_dispatch (window_t *win, const event_t *event)
 Dispatch an event to the window's elements.
 
uint64_t window_set_focus (window_t *win)
 Set the focus to the window.
 
uint64_t window_set_visible (window_t *win, bool isVisible)
 Set the visibility of the window.
 

Detailed Description

Window.

A window represents a rectangular area on the screen that can display content and receive user input, this includes panels, cursors, wallpapers and normal application windows. It can be considered to be the client side implementation of the Desktop Window Managers surfaces.

If WINDOW_DECO flag is set, the window will have decorations (titlebar, close/minimize buttons, etc) which will serve as the root element with the client element as a child. This client element is then what the application will draw to and receive events from.

The window system is NOT thread safe, it is the responsibility of the application to ensure that windows are only accessed from a single thread at a time.

Typedef Documentation

◆ window_t

typedef struct window window_t

Definition at line 37 of file window.h.

Enumeration Type Documentation

◆ window_flags_t

Window flags.

Enumerator
WINDOW_NONE 
WINDOW_DECO 

Enable decorations (titlebar, close/minimize buttons, etc).

WINDOW_RESIZABLE 

Allows window_move() to resize the window. TODO: Implement resize handles.

WINDOW_NO_CONTROLS 

Disable controls (close/minimize buttons), only applies if WINDOW_DECO is set.

Definition at line 43 of file window.h.

Function Documentation

◆ window_content_rect()

rect_t window_content_rect ( window_t win)

Get the window's rectangle in local coordinates.

Equivalent to RECT_INIT_DIM(0, 0, width, height).

Parameters
winThe window.
Returns
The window's local rectangle.

◆ window_dispatch()

uint64_t window_dispatch ( window_t win,
const event_t event 
)

Dispatch an event to the window's elements.

Most events will be sent to the root element, which will then propagate the event to its children.

Some events will be handled specially, for example LEVENT_FORCE_ACTION will be sent directly to the specified element.

Parameters
winThe window.
eventThe event to dispatch.
Returns
The result of the window procedure.

Definition at line 598 of file window.c.

References levent_force_action_t::dest, window_t::disp, display_push(), EINVAL, element_dispatch(), element_find(), ERR, errno, EVENT_REPORT, event_report_t::flags, levent_redraw_t::id, element_t::id, LEVENT_FORCE_ACTION, LEVENT_REDRAW, event_t::lForceAction, event_t::lRedraw, NULL, window_t::rect, RECT_HEIGHT, RECT_WIDTH, event_t::report, REPORT_RECT, window_t::root, window_t::surface, event_t::type, and window_invalidate_flush().

Referenced by display_dispatch().

◆ window_free()

◆ window_get_client_element()

element_t * window_get_client_element ( window_t win)

Get the client element of the window.

The client element is the window element that applications should draw to and receive events from, if the window has decorations this will be the child of the deco element, otherwise it will be the root element.

Parameters
winThe window.
Returns
The client element.

Definition at line 497 of file window.c.

References window_t::clientElement, and NULL.

Referenced by start_menu_close(), start_menu_get_state(), start_menu_load_entries(), start_menu_open(), and terminal_loop().

◆ window_get_display()

display_t * window_get_display ( window_t win)

Get the display associated with the window.

Parameters
winThe window.
Returns
The display.

Definition at line 467 of file window.c.

References window_t::disp, and NULL.

Referenced by popup_procedure(), procedure(), start_menu_close(), start_menu_open(), startmenu_procedure(), taskbar_procedure(), terminal_loop(), terminal_procedure(), and window_deco_init_controls().

◆ window_get_id()

surface_id_t window_get_id ( window_t win)

Get the surface ID of the window.

Parameters
winThe window.
Returns
The surface ID or SURFACE_ID_NONE if win is NULL.

Definition at line 477 of file window.c.

References NULL, window_t::surface, and SURFACE_ID_NONE.

Referenced by start_menu_close(), and terminal_loop().

◆ window_get_rect()

rect_t window_get_rect ( window_t win)

Get the window's rectangle in screen coordinates.

Equivalent to RECT_INIT_DIM(x, y, width, height).

Parameters
winThe window.
Returns
The window's rectangle.

Definition at line 447 of file window.c.

References NULL, and window_t::rect.

Referenced by start_menu_open(), and startmenu_procedure().

◆ window_get_type()

surface_type_t window_get_type ( window_t win)

Get the surface type of the window.

Parameters
winThe window.
Returns
The surface type or SURFACE_NONE if win is NULL.

Definition at line 487 of file window.c.

References NULL, SURFACE_NONE, and window_t::type.

◆ window_invalidate()

void window_invalidate ( window_t win,
const rect_t rect 
)

Invalidate a rectangle of the window.

This is used to notify the DWM of the change not to redraw the specified rectangle.

The changes will be flushed to the DWM when window_invalidate_flush() is called.

Parameters
winThe window.
rectThe rectangle to invalidate, in local coordinates.

Definition at line 553 of file window.c.

References window_t::invalidRect, NULL, RECT_AREA, and RECT_EXPAND_TO_CONTAIN.

Referenced by element_draw_end().

◆ window_invalidate_flush()

uint64_t window_invalidate_flush ( window_t win)

Flush invalidated rectangles to the DWM.

This will send the invalidated rectangle to the DWM and clear the invalid rectangle.

Parameters
winThe window.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 570 of file window.c.

References CMD_SURFACE_INVALIDATE, window_t::disp, display_cmd_alloc(), display_cmds_flush(), EINVAL, ERR, errno, cmd_surface_invalidate_t::invalidRect, window_t::invalidRect, NULL, RECT_AREA, window_t::surface, and cmd_surface_invalidate_t::target.

Referenced by window_dispatch().

◆ window_move()

uint64_t window_move ( window_t win,
const rect_t rect 
)

Move and/or resize the window.

Parameters
winThe window.
rectThe new screen rectangle for the window.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 507 of file window.c.

References CMD_SURFACE_MOVE, window_t::disp, display_cmd_alloc(), display_cmds_flush(), EINVAL, EPERM, ERR, errno, window_t::flags, NULL, cmd_surface_move_t::rect, window_t::rect, RECT_HEIGHT, RECT_WIDTH, window_t::surface, cmd_surface_move_t::target, and WINDOW_RESIZABLE.

Referenced by start_menu_open(), startmenu_procedure(), and window_deco_handle_dragging().

◆ window_new()

window_t * window_new ( display_t disp,
const char *  name,
const rect_t rect,
surface_type_t  type,
window_flags_t  flags,
procedure_t  procedure,
void *  private 
)

Allocate and initialize a new window.

Parameters
dispThe connection to the DWM.
nameThe name of the window.
rectThe rectangle defining the position and size of the window.
typeThe type of surface to create, (e.g., panels, cursors, wallpapers, normal windows, etc).
flagsThe window flags.
procedureThe procedure for the window's client element.
privatePrivate data to associate with the window's client element.
Returns
On success, the new window. On failure, returns NULL and errno is set.

Definition at line 301 of file window.c.

References rect_t::bottom, window_t::buffer, claim(), window_t::clientElement, close(), CMD_SURFACE_NEW, window_t::disp, display_cmd_alloc(), display_cmds_flush(), display_wait(), EINVAL, element_new(), element_new_root(), ELEMENT_NONE, ENOMEM, window_t::entry, ERR, errno, EVENT_SURFACE_NEW, window_t::flags, theme_t::frameSize, free(), window_t::invalidRect, rect_t::left, list_entry_init(), list_push(), malloc(), MAX_NAME, mmap(), mtx_lock(), mtx_unlock(), display_t::mutex, cmd_surface_new_t::name, window_t::name, NULL, procedure(), PROT_READ, PROT_WRITE, cmd_surface_new_t::rect, window_t::rect, RECT_HEIGHT, RECT_INIT, RECT_INIT_DIM, RECT_WIDTH, rect_t::right, window_t::root, event_surface_new_t::shmemKey, strcpy(), strnlen_s(), window_t::surface, event_t::surfaceNew, theme, theme_global_get(), theme_t::titlebarSize, rect_t::top, cmd_surface_new_t::type, window_t::type, WINDOW_CLIENT_ELEM_ID, WINDOW_DECO, WINDOW_DECO_ELEM_ID, window_deco_procedure(), window_free(), and display_t::windows.

Referenced by main(), popup_open(), start_menu_new(), taskbar_new(), and terminal_new().

◆ window_set_focus()

uint64_t window_set_focus ( window_t win)

Set the focus to the window.

Causes the window to be moved to the front and to, for example, receive keyboard input.

Parameters
winThe window.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 673 of file window.c.

References CMD_SURFACE_FOCUS_SET, window_t::disp, display_cmd_alloc(), display_cmds_flush(), EINVAL, ERR, errno, cmd_surface_focus_set_t::isGlobal, NULL, window_t::surface, and cmd_surface_focus_set_t::target.

Referenced by start_menu_open().

◆ window_set_timer()

uint64_t window_set_timer ( window_t win,
timer_flags_t  flags,
clock_t  timeout 
)

Set the window timer.

When the timer fires an event of type EVENT_TIMER will be sent to the window's procedure.

Parameters
winThe window.
flagsThe timer flags.
timeoutThe timer timeout in clock ticks, or CLOCKS_NEVER to disable the timer. Setting a new timer will overide the previous timer if one is set.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 533 of file window.c.

References CMD_SURFACE_TIMER_SET, window_t::disp, display_cmd_alloc(), display_cmds_flush(), EINVAL, ERR, errno, cmd_surface_timer_set_t::flags, NULL, window_t::surface, cmd_surface_timer_set_t::target, and cmd_surface_timer_set_t::timeout.

Referenced by procedure(), start_menu_close(), start_menu_open(), startmenu_procedure(), taskbar_procedure(), terminal_handle_output(), and terminal_procedure().

◆ window_set_visible()

uint64_t window_set_visible ( window_t win,
bool  isVisible 
)

Set the visibility of the window.

Windows are invisible by default, so they must be made visible after creation to be seen.

Will also dispatch all currently pending LEVENT_REDRAW events for the window.

Parameters
winThe window.
isVisibleWhether the window should be visible.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 692 of file window.c.

References CMD_SURFACE_VISIBLE_SET, window_t::disp, display_cmd_alloc(), display_cmds_flush(), display_dispatch_pending(), EINVAL, ERR, errno, cmd_surface_visible_set_t::isGlobal, cmd_surface_visible_set_t::isVisible, LEVENT_REDRAW, NULL, window_t::surface, and cmd_surface_visible_set_t::target.

Referenced by main(), start_menu_new(), taskbar_new(), and terminal_new().