NeoMutt  2025-01-09-81-g753ae0
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
mutt_window.h File Reference

Window management. More...

#include "config.h"
#include <stdbool.h>
#include <stdint.h>
#include "mutt/lib.h"
+ Include dependency graph for mutt_window.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  WindowState
 The current, or old, state of a Window. More...
 
struct  MuttWindow
 
struct  EventWindow
 An Event that happened to a Window. More...
 

Macros

#define MUTT_WIN_SIZE_UNLIMITED   -1
 Use as much space as possible.
 
#define WA_NO_FLAGS   0
 No flags are set.
 
#define WA_REFLOW   (1 << 0)
 Reflow the Window and its children.
 
#define WA_RECALC   (1 << 1)
 Recalculate the contents of the Window.
 
#define WA_REPAINT   (1 << 2)
 Redraw the contents of the Window.
 
#define WN_NO_FLAGS   0
 No flags are set.
 
#define WN_TALLER   (1 << 0)
 Window became taller.
 
#define WN_SHORTER   (1 << 1)
 Window became shorter.
 
#define WN_WIDER   (1 << 2)
 Window became wider.
 
#define WN_NARROWER   (1 << 3)
 Window became narrower.
 
#define WN_MOVED   (1 << 4)
 Window moved.
 
#define WN_VISIBLE   (1 << 5)
 Window became visible.
 
#define WN_HIDDEN   (1 << 6)
 Window became hidden.
 

Typedefs

typedef uint8_t WindowActionFlags
 Flags for Actions waiting to be performed on a MuttWindow, e.g. WA_REFLOW.
 
typedef uint8_t WindowNotifyFlags
 Flags for Changes to a MuttWindow, e.g. WN_TALLER.
 

Enumerations

enum  MuttWindowOrientation { MUTT_WIN_ORIENT_VERTICAL = 1 , MUTT_WIN_ORIENT_HORIZONTAL }
 Which way does the Window expand? More...
 
enum  MuttWindowSize { MUTT_WIN_SIZE_FIXED = 1 , MUTT_WIN_SIZE_MAXIMISE , MUTT_WIN_SIZE_MINIMISE }
 Control the allocation of Window space. More...
 
enum  WindowType {
  WT_ROOT , WT_CONTAINER , WT_ALL_DIALOGS , WT_DLG_ALIAS ,
  WT_DLG_ATTACHMENT , WT_DLG_AUTOCRYPT , WT_DLG_BROWSER , WT_DLG_CERTIFICATE ,
  WT_DLG_COMPOSE , WT_DLG_GPGME , WT_DLG_PAGER , WT_DLG_HISTORY ,
  WT_DLG_INDEX , WT_DLG_PATTERN , WT_DLG_PGP , WT_DLG_POSTPONED ,
  WT_DLG_QUERY , WT_DLG_SMIME , WT_CUSTOM , WT_HELP_BAR ,
  WT_INDEX , WT_MENU , WT_MESSAGE , WT_PAGER ,
  WT_SIDEBAR , WT_STATUS_BAR
}
 Type of Window. More...
 
enum  NotifyWindow {
  NT_WINDOW_ADD = 1 , NT_WINDOW_DELETE , NT_WINDOW_STATE , NT_WINDOW_DIALOG ,
  NT_WINDOW_FOCUS
}
 Window notification types. More...
 

Functions

 TAILQ_HEAD (MuttWindowList, MuttWindow)
 
void mutt_window_add_child (struct MuttWindow *parent, struct MuttWindow *child)
 Add a child to Window.
 
void mutt_window_free (struct MuttWindow **ptr)
 Free a Window and its children.
 
void mutt_window_get_coords (struct MuttWindow *win, int *row, int *col)
 Get the cursor position in the Window.
 
struct MuttWindowmutt_window_new (enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
 Create a new Window.
 
void mutt_window_reflow (struct MuttWindow *win)
 Resize a Window and its children.
 
struct MuttWindowmutt_window_remove_child (struct MuttWindow *parent, struct MuttWindow *child)
 Remove a child from a Window.
 
int mutt_window_wrap_cols (int width, short wrap)
 Calculate the wrap column for a given screen width.
 
int mutt_window_addch (struct MuttWindow *win, int ch)
 Write one character to a Window.
 
int mutt_window_addnstr (struct MuttWindow *win, const char *str, int num)
 Write a partial string to a Window.
 
int mutt_window_addstr (struct MuttWindow *win, const char *str)
 Write a string to a Window.
 
void mutt_window_clearline (struct MuttWindow *win, int row)
 Clear a row of a Window.
 
void mutt_window_clear (struct MuttWindow *win)
 Clear a Window.
 
void mutt_window_clrtoeol (struct MuttWindow *win)
 Clear to the end of the line.
 
int mutt_window_move (struct MuttWindow *win, int row, int col)
 Move the cursor in a Window.
 
int mutt_window_printf (struct MuttWindow *win, const char *format,...) __attribute__((__format__(__printf__
 
int bool mutt_window_is_visible (struct MuttWindow *win)
 Is the Window visible?
 
void mutt_winlist_free (struct MuttWindowList *head)
 Free a tree of Windows.
 
struct MuttWindowwindow_find_child (struct MuttWindow *win, enum WindowType type)
 Recursively find a child Window of a given type.
 
struct MuttWindowwindow_find_parent (struct MuttWindow *win, enum WindowType type)
 Find a (grand-)parent of a Window by type.
 
void window_notify_all (struct MuttWindow *win)
 Notify observers of changes to a Window and its children.
 
void window_set_visible (struct MuttWindow *win, bool visible)
 Set a Window visible or hidden.
 
struct MuttWindowwindow_set_focus (struct MuttWindow *win)
 Set the Window focus.
 
struct MuttWindowwindow_get_focus (void)
 Get the currently focused Window.
 
bool window_is_focused (const struct MuttWindow *win)
 Does the given Window have the focus?
 
void window_redraw (struct MuttWindow *win)
 Reflow, recalc and repaint a tree of Windows.
 
void window_invalidate_all (void)
 Mark all windows as in need of repaint.
 
const char * mutt_window_win_name (const struct MuttWindow *win)
 Get the name of a Window.
 
bool window_status_on_top (struct MuttWindow *panel, struct ConfigSubset *sub)
 Organise windows according to config variable.
 
bool mutt_window_swap (struct MuttWindow *parent, struct MuttWindow *win1, struct MuttWindow *win2)
 Swap the position of two windows.
 

Detailed Description

Window management.

Authors
  • Richard Russon
  • Dennis Schön

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file mutt_window.h.

Macro Definition Documentation

◆ MUTT_WIN_SIZE_UNLIMITED

#define MUTT_WIN_SIZE_UNLIMITED   -1

Use as much space as possible.

Definition at line 53 of file mutt_window.h.

◆ WA_NO_FLAGS

#define WA_NO_FLAGS   0

No flags are set.

Definition at line 108 of file mutt_window.h.

◆ WA_REFLOW

#define WA_REFLOW   (1 << 0)

Reflow the Window and its children.

Definition at line 109 of file mutt_window.h.

◆ WA_RECALC

#define WA_RECALC   (1 << 1)

Recalculate the contents of the Window.

Definition at line 110 of file mutt_window.h.

◆ WA_REPAINT

#define WA_REPAINT   (1 << 2)

Redraw the contents of the Window.

Definition at line 111 of file mutt_window.h.

◆ WN_NO_FLAGS

#define WN_NO_FLAGS   0

No flags are set.

Definition at line 209 of file mutt_window.h.

◆ WN_TALLER

#define WN_TALLER   (1 << 0)

Window became taller.

Definition at line 210 of file mutt_window.h.

◆ WN_SHORTER

#define WN_SHORTER   (1 << 1)

Window became shorter.

Definition at line 211 of file mutt_window.h.

◆ WN_WIDER

#define WN_WIDER   (1 << 2)

Window became wider.

Definition at line 212 of file mutt_window.h.

◆ WN_NARROWER

#define WN_NARROWER   (1 << 3)

Window became narrower.

Definition at line 213 of file mutt_window.h.

◆ WN_MOVED

#define WN_MOVED   (1 << 4)

Window moved.

Definition at line 214 of file mutt_window.h.

◆ WN_VISIBLE

#define WN_VISIBLE   (1 << 5)

Window became visible.

Definition at line 215 of file mutt_window.h.

◆ WN_HIDDEN

#define WN_HIDDEN   (1 << 6)

Window became hidden.

Definition at line 216 of file mutt_window.h.

Typedef Documentation

◆ WindowActionFlags

typedef uint8_t WindowActionFlags

Flags for Actions waiting to be performed on a MuttWindow, e.g. WA_REFLOW.

Definition at line 107 of file mutt_window.h.

◆ WindowNotifyFlags

typedef uint8_t WindowNotifyFlags

Flags for Changes to a MuttWindow, e.g. WN_TALLER.

Definition at line 208 of file mutt_window.h.

Enumeration Type Documentation

◆ MuttWindowOrientation

Which way does the Window expand?

Enumerator
MUTT_WIN_ORIENT_VERTICAL 

Window uses all available vertical space.

MUTT_WIN_ORIENT_HORIZONTAL 

Window uses all available horizontal space.

Definition at line 37 of file mutt_window.h.

38{
41};
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition: mutt_window.h:39
@ MUTT_WIN_ORIENT_HORIZONTAL
Window uses all available horizontal space.
Definition: mutt_window.h:40

◆ MuttWindowSize

Control the allocation of Window space.

Enumerator
MUTT_WIN_SIZE_FIXED 

Window has a fixed size.

MUTT_WIN_SIZE_MAXIMISE 

Window wants as much space as possible.

MUTT_WIN_SIZE_MINIMISE 

Window size depends on its children.

Definition at line 46 of file mutt_window.h.

47{
51};
@ MUTT_WIN_SIZE_FIXED
Window has a fixed size.
Definition: mutt_window.h:48
@ MUTT_WIN_SIZE_MINIMISE
Window size depends on its children.
Definition: mutt_window.h:50
@ MUTT_WIN_SIZE_MAXIMISE
Window wants as much space as possible.
Definition: mutt_window.h:49

◆ WindowType

enum WindowType

Type of Window.

Enumerator
WT_ROOT 

Parent of All Windows.

WT_CONTAINER 

Invisible shaping container Window.

WT_ALL_DIALOGS 

Container for All Dialogs (nested Windows)

WT_DLG_ALIAS 

Alias Dialog, dlg_alias()

WT_DLG_ATTACHMENT 

Attachment Dialog, dlg_attachment()

WT_DLG_AUTOCRYPT 

Autocrypt Dialog, dlg_autocrypt()

WT_DLG_BROWSER 

Browser Dialog, dlg_browser()

WT_DLG_CERTIFICATE 

Certificate Dialog, dlg_certificate()

WT_DLG_COMPOSE 

Compose Dialog, dlg_compose()

WT_DLG_GPGME 

GPGME Dialog, dlg_gpgme()

WT_DLG_PAGER 

Pager Dialog, dlg_pager()

WT_DLG_HISTORY 

History Dialog, dlg_history()

WT_DLG_INDEX 

Index Dialog, dlg_index()

WT_DLG_PATTERN 

Pattern Dialog, dlg_pattern()

WT_DLG_PGP 

Pgp Dialog, dlg_pgp()

WT_DLG_POSTPONED 

Postponed Dialog, dlg_postponed()

WT_DLG_QUERY 

Query Dialog, dlg_query()

WT_DLG_SMIME 

Smime Dialog, dlg_smime()

WT_CUSTOM 

Window with a custom drawing function.

WT_HELP_BAR 

Help Bar containing list of useful key bindings.

WT_INDEX 

A panel containing the Index Window.

WT_MENU 

An Window containing a Menu.

WT_MESSAGE 

Window for messages/errors.

WT_PAGER 

A panel containing the Pager Window.

WT_SIDEBAR 

Side panel containing Accounts or groups of data.

WT_STATUS_BAR 

Status Bar containing extra info about the Index/Pager/etc.

Definition at line 70 of file mutt_window.h.

71{
72 // Structural Windows
73 WT_ROOT,
76
77 // Dialogs (nested Windows) displayed to the user
93
94 // Common Windows
95 WT_CUSTOM,
97 WT_INDEX,
98 WT_MENU,
100 WT_PAGER,
101 WT_SIDEBAR,
103};
@ WT_CUSTOM
Window with a custom drawing function.
Definition: mutt_window.h:95
@ WT_ROOT
Parent of All Windows.
Definition: mutt_window.h:73
@ WT_DLG_ALIAS
Alias Dialog, dlg_alias()
Definition: mutt_window.h:78
@ WT_ALL_DIALOGS
Container for All Dialogs (nested Windows)
Definition: mutt_window.h:75
@ WT_DLG_BROWSER
Browser Dialog, dlg_browser()
Definition: mutt_window.h:81
@ WT_MESSAGE
Window for messages/errors.
Definition: mutt_window.h:99
@ WT_DLG_SMIME
Smime Dialog, dlg_smime()
Definition: mutt_window.h:92
@ WT_DLG_QUERY
Query Dialog, dlg_query()
Definition: mutt_window.h:91
@ WT_DLG_HISTORY
History Dialog, dlg_history()
Definition: mutt_window.h:86
@ WT_DLG_PGP
Pgp Dialog, dlg_pgp()
Definition: mutt_window.h:89
@ WT_CONTAINER
Invisible shaping container Window.
Definition: mutt_window.h:74
@ WT_DLG_CERTIFICATE
Certificate Dialog, dlg_certificate()
Definition: mutt_window.h:82
@ WT_DLG_COMPOSE
Compose Dialog, dlg_compose()
Definition: mutt_window.h:83
@ WT_DLG_INDEX
Index Dialog, dlg_index()
Definition: mutt_window.h:87
@ WT_PAGER
A panel containing the Pager Window.
Definition: mutt_window.h:100
@ WT_DLG_GPGME
GPGME Dialog, dlg_gpgme()
Definition: mutt_window.h:84
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
@ WT_HELP_BAR
Help Bar containing list of useful key bindings.
Definition: mutt_window.h:96
@ WT_DLG_POSTPONED
Postponed Dialog, dlg_postponed()
Definition: mutt_window.h:90
@ WT_INDEX
A panel containing the Index Window.
Definition: mutt_window.h:97
@ WT_DLG_ATTACHMENT
Attachment Dialog, dlg_attachment()
Definition: mutt_window.h:79
@ WT_SIDEBAR
Side panel containing Accounts or groups of data.
Definition: mutt_window.h:101
@ WT_DLG_PAGER
Pager Dialog, dlg_pager()
Definition: mutt_window.h:85
@ WT_DLG_AUTOCRYPT
Autocrypt Dialog, dlg_autocrypt()
Definition: mutt_window.h:80
@ WT_MENU
An Window containing a Menu.
Definition: mutt_window.h:98
@ WT_DLG_PATTERN
Pattern Dialog, dlg_pattern()
Definition: mutt_window.h:88

◆ NotifyWindow

Window notification types.

Observers of NT_WINDOW will be passed an EventWindow.

Note
Delete notifications are sent before the object is deleted.
Other notifications are sent after the event.
Enumerator
NT_WINDOW_ADD 

New Window has been added.

NT_WINDOW_DELETE 

Window is about to be deleted.

NT_WINDOW_STATE 

Window state has changed, e.g. WN_VISIBLE.

NT_WINDOW_DIALOG 

A new Dialog Window has been created, e.g. WT_DLG_INDEX.

NT_WINDOW_FOCUS 

Window focus has changed.

Definition at line 226 of file mutt_window.h.

227{
228 NT_WINDOW_ADD = 1,
233};
@ NT_WINDOW_DIALOG
A new Dialog Window has been created, e.g. WT_DLG_INDEX.
Definition: mutt_window.h:231
@ NT_WINDOW_STATE
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:230
@ NT_WINDOW_DELETE
Window is about to be deleted.
Definition: mutt_window.h:229
@ NT_WINDOW_FOCUS
Window focus has changed.
Definition: mutt_window.h:232
@ NT_WINDOW_ADD
New Window has been added.
Definition: mutt_window.h:228

Function Documentation

◆ TAILQ_HEAD()

TAILQ_HEAD ( MuttWindowList  ,
MuttWindow   
)

◆ mutt_window_add_child()

void mutt_window_add_child ( struct MuttWindow parent,
struct MuttWindow child 
)

Add a child to Window.

Parameters
parentWindow to add to
childWindow to add

Definition at line 411 of file mutt_window.c.

412{
413 if (!parent || !child)
414 return;
415
416 TAILQ_INSERT_TAIL(&parent->children, child, entries);
417 child->parent = parent;
418
419 notify_set_parent(child->notify, parent->notify);
420
421 mutt_debug(LL_NOTIFY, "NT_WINDOW_NEW: %s, %p\n", mutt_window_win_name(child),
422 (void *) child);
423 struct EventWindow ev_w = { child, WN_NO_FLAGS };
424 notify_send(child->notify, NT_WINDOW, NT_WINDOW_ADD, &ev_w);
425}
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_NOTIFY
Log of notifications.
Definition: logging2.h:48
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:173
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:95
const char * mutt_window_win_name(const struct MuttWindow *win)
Get the name of a Window.
Definition: mutt_window.c:700
#define WN_NO_FLAGS
No flags are set.
Definition: mutt_window.h:209
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:57
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:866
An Event that happened to a Window.
Definition: mutt_window.h:239
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_free()

void mutt_window_free ( struct MuttWindow **  ptr)

Free a Window and its children.

Parameters
ptrWindow to free

Definition at line 205 of file mutt_window.c.

206{
207 if (!ptr || !*ptr)
208 return;
209
210 struct MuttWindow *win = *ptr;
211
212 if (win->parent && (win->parent->focus == win))
213 win->parent->focus = NULL;
214
215 mutt_debug(LL_NOTIFY, "NT_WINDOW_DELETE: %s, %p\n", mutt_window_win_name(win),
216 (void *) win);
217 struct EventWindow ev_w = { win, WN_NO_FLAGS };
219
221
222 if (win->wdata_free && win->wdata)
223 win->wdata_free(win, &win->wdata); // Custom function to free private data
224
226
227 FREE(ptr);
228}
#define FREE(x)
Definition: memory.h:55
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:75
void mutt_winlist_free(struct MuttWindowList *head)
Free a tree of Windows.
Definition: mutt_window.c:454
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:240
struct MuttWindow * focus
Focused Window.
Definition: mutt_window.h:140
void * wdata
Private data.
Definition: mutt_window.h:145
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:159
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_get_coords()

void mutt_window_get_coords ( struct MuttWindow win,
int *  row,
int *  col 
)

Get the cursor position in the Window.

Parameters
[in]winWindow
[out]rowRow in Window
[out]colColumn in Window

Assumes the current position is inside the window. Otherwise it will happily return negative or values outside the window boundaries

Definition at line 280 of file mutt_window.c.

281{
282 int x = 0;
283 int y = 0;
284
285 getyx(stdscr, y, x);
286 if (col)
287 *col = x - win->state.col_offset;
288 if (row)
289 *row = y - win->state.row_offset;
290}
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
short row_offset
Absolute on-screen row.
Definition: mutt_window.h:64
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:63
+ Here is the caller graph for this function:

◆ mutt_window_new()

struct MuttWindow * mutt_window_new ( enum WindowType  type,
enum MuttWindowOrientation  orient,
enum MuttWindowSize  size,
int  cols,
int  rows 
)

Create a new Window.

Parameters
typeWindow type, e.g. WT_ROOT
orientWindow orientation, e.g. MUTT_WIN_ORIENT_VERTICAL
sizeWindow size, e.g. MUTT_WIN_SIZE_MAXIMISE
colsInitial number of columns to allocate, can be MUTT_WIN_SIZE_UNLIMITED
rowsInitial number of rows to allocate, can be MUTT_WIN_SIZE_UNLIMITED
Return values
ptrNew Window

Definition at line 182 of file mutt_window.c.

184{
185 struct MuttWindow *win = MUTT_MEM_CALLOC(1, struct MuttWindow);
186
187 win->type = type;
188 win->orient = orient;
189 win->size = size;
190 win->req_rows = rows;
191 win->req_cols = cols;
192 win->state.visible = true;
193 win->notify = notify_new();
194 TAILQ_INIT(&win->children);
195
196 win->actions |= WA_RECALC | WA_REPAINT;
197
198 return win;
199}
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:62
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
#define TAILQ_INIT(head)
Definition: queue.h:822
short req_cols
Number of columns required.
Definition: mutt_window.h:124
enum MuttWindowOrientation orient
Which direction the Window will expand.
Definition: mutt_window.h:130
short req_rows
Number of rows required.
Definition: mutt_window.h:125
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
enum MuttWindowSize size
Type of Window, e.g. MUTT_WIN_SIZE_FIXED.
Definition: mutt_window.h:131
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:144
bool visible
Window is visible.
Definition: mutt_window.h:60
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_reflow()

void mutt_window_reflow ( struct MuttWindow win)

Resize a Window and its children.

Parameters
winWindow to resize

Definition at line 309 of file mutt_window.c.

310{
311 if (OptNoCurses)
312 return;
313
314 if (!win)
315 win = RootWindow;
316
317 window_reflow(win);
319
320 // Allow Windows to resize themselves based on the first reflow
321 window_reflow(win);
323
324#ifdef USE_DEBUG_WINDOW
326#endif
327}
void debug_win_dump(void)
Definition: window.c:96
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: globals.c:69
void window_notify_all(struct MuttWindow *win)
Notify observers of changes to a Window and its children.
Definition: mutt_window.c:145
void window_reflow(struct MuttWindow *win)
Reflow Windows.
Definition: reflow.c:220
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: rootwin.c:106
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_remove_child()

struct MuttWindow * mutt_window_remove_child ( struct MuttWindow parent,
struct MuttWindow child 
)

Remove a child from a Window.

Parameters
parentWindow to remove from
childWindow to remove
Return values
ptrChild Window

Definition at line 433 of file mutt_window.c.

434{
435 if (!parent || !child)
436 return NULL;
437
438 // A notification will be sent when the Window is freed
439 TAILQ_REMOVE(&parent->children, child, entries);
440 child->parent = NULL;
441
442 if (parent->focus == child)
443 parent->focus = NULL;
444
445 notify_set_parent(child->notify, NULL);
446
447 return child;
448}
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:901
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_wrap_cols()

int mutt_window_wrap_cols ( int  width,
short  wrap 
)

Calculate the wrap column for a given screen width.

Parameters
widthScreen width
wrapWrap config
Return values
numColumn that text should be wrapped at

The wrap variable can be negative, meaning there should be a right margin.

Definition at line 337 of file mutt_window.c.

338{
339 if (wrap < 0)
340 return (width > -wrap) ? (width + wrap) : width;
341 if (wrap)
342 return (wrap < width) ? wrap : width;
343 return width;
344}
+ Here is the caller graph for this function:

◆ mutt_window_addch()

int mutt_window_addch ( struct MuttWindow win,
int  ch 
)

Write one character to a Window.

Parameters
winWindow
chCharacter to write
Return values
0Success
-1Error

Definition at line 353 of file mutt_window.c.

354{
355 return addch(ch);
356}
+ Here is the caller graph for this function:

◆ mutt_window_addnstr()

int mutt_window_addnstr ( struct MuttWindow win,
const char *  str,
int  num 
)

Write a partial string to a Window.

Parameters
winWindow
strString
numMaximum number of characters to write
Return values
0Success
-1Error

Definition at line 366 of file mutt_window.c.

367{
368 if (!str)
369 return -1;
370
371 return addnstr(str, num);
372}
+ Here is the caller graph for this function:

◆ mutt_window_addstr()

int mutt_window_addstr ( struct MuttWindow win,
const char *  str 
)

Write a string to a Window.

Parameters
winWindow
strString
Return values
0Success
-1Error

Definition at line 381 of file mutt_window.c.

382{
383 if (!str)
384 return -1;
385
386 return addstr(str);
387}
+ Here is the caller graph for this function:

◆ mutt_window_clearline()

void mutt_window_clearline ( struct MuttWindow win,
int  row 
)

Clear a row of a Window.

Parameters
winWindow
rowRow to clear

Definition at line 235 of file mutt_window.c.

236{
237 mutt_window_move(win, row, 0);
239}
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
Definition: mutt_window.c:300
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:247
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_clear()

void mutt_window_clear ( struct MuttWindow win)

Clear a Window.

Parameters
winWindow

If the Window isn't visible, it won't be cleared.

Definition at line 685 of file mutt_window.c.

686{
687 if (!mutt_window_is_visible(win))
688 return;
689
690 for (int i = 0; i < win->state.rows; i++)
691 mutt_window_clearline(win, i);
692}
bool mutt_window_is_visible(struct MuttWindow *win)
Is the Window visible?
Definition: mutt_window.c:477
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:235
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:62
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_clrtoeol()

void mutt_window_clrtoeol ( struct MuttWindow win)

Clear to the end of the line.

Parameters
winWindow
Note
Assumes the cursor has already been positioned within the window.

Definition at line 247 of file mutt_window.c.

248{
249 if (!win || !stdscr)
250 return;
251
252 if ((win->state.col_offset + win->state.cols) == COLS)
253 {
254 clrtoeol();
255 }
256 else
257 {
258 int row = 0;
259 int col = 0;
260 getyx(stdscr, row, col);
261 int curcol = col;
262 while (curcol < (win->state.col_offset + win->state.cols))
263 {
264 addch(' ');
265 curcol++;
266 }
267 move(row, col);
268 }
269}
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61
+ Here is the caller graph for this function:

◆ mutt_window_move()

int mutt_window_move ( struct MuttWindow win,
int  row,
int  col 
)

Move the cursor in a Window.

Parameters
winWindow
rowRow to move to
colColumn to move to
Return values
OKSuccess
ERRError

Definition at line 300 of file mutt_window.c.

301{
302 return move(win->state.row_offset + row, win->state.col_offset + col);
303}
+ Here is the caller graph for this function:

◆ mutt_window_printf()

int mutt_window_printf ( struct MuttWindow win,
const char *  format,
  ... 
)

◆ mutt_window_is_visible()

int bool mutt_window_is_visible ( struct MuttWindow win)

Is the Window visible?

Parameters
winWindow
Return values
trueThe Window is visible

For a Window to be visible, it must be visible and its parent and grandparent, etc.

Definition at line 477 of file mutt_window.c.

478{
479 if (!win)
480 return false;
481
482 for (; win; win = win->parent)
483 {
484 if (!win->state.visible)
485 return false;
486 }
487
488 return true;
489}
+ Here is the caller graph for this function:

◆ mutt_winlist_free()

void mutt_winlist_free ( struct MuttWindowList *  head)

Free a tree of Windows.

Parameters
headWindowList to free

Definition at line 454 of file mutt_window.c.

455{
456 if (!head)
457 return;
458
459 struct MuttWindow *np = NULL;
460 struct MuttWindow *tmp = NULL;
461 TAILQ_FOREACH_SAFE(np, head, entries, tmp)
462 {
463 TAILQ_REMOVE(head, np, entries);
465 mutt_window_free(&np);
466 }
467}
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:205
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:792
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_find_child()

struct MuttWindow * window_find_child ( struct MuttWindow win,
enum WindowType  type 
)

Recursively find a child Window of a given type.

Parameters
winWindow to start searching
typeWindow type to find, e.g. WT_STATUS_BAR
Return values
ptrMatching Window
NULLNo match

Definition at line 498 of file mutt_window.c.

499{
500 if (!win)
501 return NULL;
502 if (win->type == type)
503 return win;
504
505 struct MuttWindow *np = NULL;
506 struct MuttWindow *match = NULL;
507 TAILQ_FOREACH(np, &win->children, entries)
508 {
509 match = window_find_child(np, type);
510 if (match)
511 return match;
512 }
513
514 return NULL;
515}
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:498
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:782
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_find_parent()

struct MuttWindow * window_find_parent ( struct MuttWindow win,
enum WindowType  type 
)

Find a (grand-)parent of a Window by type.

Parameters
winWindow
typeWindow type, e.g. WT_DLG_INDEX
Return values
ptrWindow

Definition at line 523 of file mutt_window.c.

524{
525 for (; win; win = win->parent)
526 {
527 if (win->type == type)
528 return win;
529 }
530
531 return NULL;
532}
+ Here is the caller graph for this function:

◆ window_notify_all()

void window_notify_all ( struct MuttWindow win)

Notify observers of changes to a Window and its children.

Parameters
winWindow

Definition at line 145 of file mutt_window.c.

146{
147 if (!win)
148 win = RootWindow;
149
150 window_notify(win);
151
152 struct MuttWindow *np = NULL;
153 TAILQ_FOREACH(np, &win->children, entries)
154 {
156 }
157 win->old = win->state;
158}
static void window_notify(struct MuttWindow *win)
Notify observers of changes to a Window.
Definition: mutt_window.c:105
struct WindowState old
Previous state of the Window.
Definition: mutt_window.h:128
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_set_visible()

void window_set_visible ( struct MuttWindow win,
bool  visible 
)

Set a Window visible or hidden.

Parameters
winWindow
visibleIf true, make Window visible, otherwise hidden

Definition at line 165 of file mutt_window.c.

166{
167 if (!win)
168 win = RootWindow;
169
170 win->state.visible = visible;
171}
+ Here is the caller graph for this function:

◆ window_set_focus()

struct MuttWindow * window_set_focus ( struct MuttWindow win)

Set the Window focus.

Parameters
winWindow to focus
Return values
ptrOld focused Window
NULLError, or focus not changed

Definition at line 649 of file mutt_window.c.

650{
651 if (!win)
652 return NULL;
653
654 struct MuttWindow *old_focus = window_get_focus();
655
656 struct MuttWindow *parent = win->parent;
657 struct MuttWindow *child = win;
658
659 // Set the chain of focus, all the way to the root
660 for (; parent; child = parent, parent = parent->parent)
661 parent->focus = child;
662
663 win->focus = NULL;
664
665 if (win == old_focus)
666 return NULL;
667
668 mutt_debug(LL_NOTIFY, "NT_WINDOW_FOCUS: %s, %p\n", mutt_window_win_name(win),
669 (void *) win);
670 struct EventWindow ev_w = { win, WN_NO_FLAGS };
672#ifdef USE_DEBUG_WINDOW
674#endif
675
676 return old_focus;
677}
struct MuttWindow * window_get_focus(void)
Get the currently focused Window.
Definition: mutt_window.c:633
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_get_focus()

struct MuttWindow * window_get_focus ( void  )

Get the currently focused Window.

Return values
ptrWindow with focus

Definition at line 633 of file mutt_window.c.

634{
635 struct MuttWindow *win = RootWindow;
636
637 while (win && win->focus)
638 win = win->focus;
639
640 return win;
641}
+ Here is the caller graph for this function:

◆ window_is_focused()

bool window_is_focused ( const struct MuttWindow win)

Does the given Window have the focus?

Parameters
winWindow to check
Return values
trueWindow has focus

Definition at line 619 of file mutt_window.c.

620{
621 if (!win)
622 return false;
623
624 struct MuttWindow *win_focus = window_get_focus();
625
626 return (win_focus == win);
627}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_redraw()

void window_redraw ( struct MuttWindow win)

Reflow, recalc and repaint a tree of Windows.

Parameters
winWindow to start at
Note
If win is NULL, all windows will be redrawn

Definition at line 599 of file mutt_window.c.

600{
601 if (!win)
602 win = RootWindow;
603
604 window_reflow(win);
606
607 window_recalc(win);
608 window_repaint(win);
610
611 mutt_refresh();
612}
void mutt_refresh(void)
Force a refresh of the screen.
Definition: curs_lib.c:79
static void window_recursor(void)
Recursor the focussed Window.
Definition: mutt_window.c:580
static void window_recalc(struct MuttWindow *win)
Recalculate a tree of Windows.
Definition: mutt_window.c:538
static void window_repaint(struct MuttWindow *win)
Repaint a tree of Windows.
Definition: mutt_window.c:558
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_invalidate_all()

void window_invalidate_all ( void  )

Mark all windows as in need of repaint.

Definition at line 732 of file mutt_window.c.

733{
735 clearok(stdscr, true);
736 keypad(stdscr, true);
737}
static void window_invalidate(struct MuttWindow *win)
Mark a window as in need of repaint.
Definition: mutt_window.c:715
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_win_name()

const char * mutt_window_win_name ( const struct MuttWindow win)

Get the name of a Window.

Parameters
winWindow
Return values
ptrString describing Window
NULLError, or unknown

Definition at line 700 of file mutt_window.c.

701{
702 if (!win)
703 return "UNKNOWN";
704
705 const char *name = mutt_map_get_name(win->type, WindowNames);
706 if (name)
707 return name;
708 return "UNKNOWN";
709}
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
static const struct Mapping WindowNames[]
Lookups for Window Names.
Definition: mutt_window.c:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_status_on_top()

bool window_status_on_top ( struct MuttWindow panel,
struct ConfigSubset sub 
)

Organise windows according to config variable.

Parameters
panelWindow containing WT_MENU and WT_STATUS_BAR
subConfig Subset
Return values
trueWindow order was changed

Set the positions of two Windows based on a config variable $status_on_top.

Note
The children are expected to have types: WT_MENU, WT_STATUS_BAR

Definition at line 749 of file mutt_window.c.

750{
751 const bool c_status_on_top = cs_subset_bool(sub, "status_on_top");
752
753 struct MuttWindow *win = TAILQ_FIRST(&panel->children);
754
755 if ((c_status_on_top && (win->type == WT_STATUS_BAR)) ||
756 (!c_status_on_top && (win->type != WT_STATUS_BAR)))
757 {
758 return false;
759 }
760
761 if (c_status_on_top)
762 {
763 win = TAILQ_LAST(&panel->children, MuttWindowList);
764 TAILQ_REMOVE(&panel->children, win, entries);
765 TAILQ_INSERT_HEAD(&panel->children, win, entries);
766 }
767 else
768 {
769 TAILQ_REMOVE(&panel->children, win, entries);
770 TAILQ_INSERT_TAIL(&panel->children, win, entries);
771 }
772
773 mutt_window_reflow(panel);
775 return true;
776}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:309
void window_invalidate_all(void)
Mark all windows as in need of repaint.
Definition: mutt_window.c:732
#define TAILQ_FIRST(head)
Definition: queue.h:780
#define TAILQ_LAST(head, headname)
Definition: queue.h:876
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:853
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_swap()

bool mutt_window_swap ( struct MuttWindow parent,
struct MuttWindow win1,
struct MuttWindow win2 
)

Swap the position of two windows.

Parameters
parentParent Window
win1Window
win2Window
Return values
trueWindows were switched

Definition at line 785 of file mutt_window.c.

787{
788 if (!parent || !win1 || !win2)
789 return false;
790
791 // ensure both windows are children of the parent
792 if (win1->parent != parent || win2->parent != parent)
793 return false;
794
795 struct MuttWindow *win1_next = TAILQ_NEXT(win1, entries);
796 if (win1_next == win2)
797 {
798 // win1 is directly in front of win2, move it behind
799 TAILQ_REMOVE(&parent->children, win1, entries);
800 TAILQ_INSERT_AFTER(&parent->children, win2, win1, entries);
801 return true;
802 }
803
804 struct MuttWindow *win2_next = TAILQ_NEXT(win2, entries);
805 if (win2_next == win1)
806 {
807 // win2 is directly in front of win1, move it behind
808 TAILQ_REMOVE(&parent->children, win2, entries);
809 TAILQ_INSERT_AFTER(&parent->children, win1, win2, entries);
810 return true;
811 }
812
813 TAILQ_REMOVE(&parent->children, win1, entries);
814 TAILQ_REMOVE(&parent->children, win2, entries);
815
816 if (win1_next)
817 TAILQ_INSERT_BEFORE(win1_next, win2, entries);
818 else
819 TAILQ_INSERT_TAIL(&parent->children, win2, entries);
820
821 if (win2_next)
822 TAILQ_INSERT_BEFORE(win2_next, win1, entries);
823 else
824 TAILQ_INSERT_TAIL(&parent->children, win1, entries);
825
826 return true;
827}
#define TAILQ_NEXT(elm, field)
Definition: queue.h:889
#define TAILQ_INSERT_BEFORE(listelm, elm, field)
Definition: queue.h:843
#define TAILQ_INSERT_AFTER(head, listelm, elm, field)
Definition: queue.h:828
+ Here is the caller graph for this function: