NeoMutt  2025-12-11-769-g906513
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
window.c
Go to the documentation of this file.
1
22
28
29#include "config.h"
30#include <stdbool.h>
31#include <stddef.h>
32#include "mutt/lib.h"
33#include "core/lib.h"
34#include "gui/lib.h"
35#include "gui/module_data.h"
36#include "lib.h"
37
38// #define DEBUG_SHOW_SERIALISE
39
42static struct MuttWindow *WinFocus = NULL;
43
49static void win_dump(struct MuttWindow *win, int indent)
50{
51 bool visible = mutt_window_is_visible(win);
52
53 mutt_debug(LL_DEBUG1, "%*s%s[%d,%d] %s-%c \033[1;33m%s\033[0m (%d,%d)%s%s\n",
54 indent, "", visible ? "✓" : "✗\033[1;30m", win->state.col_offset,
56 (win->orient == MUTT_WIN_ORIENT_VERTICAL) ? 'V' : 'H',
57 mutt_window_win_name(win), win->state.cols, win->state.rows,
58 visible ? "" : "\033[0m",
59 (win == WinFocus) ? " <-- \033[1;31mFOCUS\033[0m" : "");
60
61 struct MuttWindow **wp = NULL;
62 ARRAY_FOREACH(wp, &win->children)
63 {
64 win_dump(*wp, indent + 4);
65 }
66}
67
68#ifdef DEBUG_SHOW_SERIALISE
74static const char *win_size(struct MuttWindow *win)
75{
76 if (!win)
77 return "???";
78
79 switch (win->size)
80 {
82 return "FIX";
84 return "MAX";
86 return "MIN";
87 }
88
89 return "???";
90}
91
97static void win_serialise(struct MuttWindow *win, struct Buffer *buf)
98{
99 if (!mutt_window_is_visible(win))
100 return;
101
102 buf_add_printf(buf, "<%s {%dx,%dy} [%dC,%dR]", win_size(win), win->state.col_offset,
103 win->state.row_offset, win->state.cols, win->state.rows);
104 struct MuttWindow *np = NULL;
105 TAILQ_FOREACH(np, &win->children, entries)
106 {
107 win_serialise(np, buf);
108 }
109 buf_addstr(buf, ">");
110}
111#endif
112
117{
119 struct MuttWindow *win_root = gui_data ? gui_data->root_window : NULL;
120
122 mutt_debug(LL_DEBUG1, "\n");
123 win_dump(win_root, 0);
124 mutt_debug(LL_DEBUG1, "\n");
125#ifdef DEBUG_SHOW_SERIALISE
126 struct Buffer buf = buf_pool_get();
127 win_serialise(win_root, buf);
128 mutt_debug(LL_DEBUG1, "%s\n", buf_string(buf));
129 buf_pool_release(&buf);
130#endif
131 WinFocus = NULL;
132}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition buffer.c:204
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:226
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
Convenience wrapper for the core headers.
Convenience wrapper for the debug headers.
const char * name_window_size(const struct MuttWindow *win)
Get the name of a window size.
Definition names.c:416
static void win_dump(struct MuttWindow *win, int indent)
Recursively dump window structure.
Definition window.c:49
void debug_win_dump(void)
Dump all windows to debug output.
Definition window.c:116
static struct MuttWindow * WinFocus
The Window that is currently focused.
Definition window.c:42
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
Convenience wrapper for the gui headers.
Gui private Module data.
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
@ MODULE_ID_GUI
ModuleGui, Graphical code
Definition module_api.h:45
Convenience wrapper for the library headers.
bool mutt_window_is_visible(struct MuttWindow *win)
Is the Window visible?
const char * mutt_window_win_name(const struct MuttWindow *win)
Get the name of a Window.
struct MuttWindow * window_get_focus(void)
Get the currently focused Window.
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition mutt_window.h:38
@ MUTT_WIN_SIZE_FIXED
Window has a fixed size.
Definition mutt_window.h:47
@ MUTT_WIN_SIZE_MINIMISE
Window size depends on its children.
Definition mutt_window.h:49
@ MUTT_WIN_SIZE_MAXIMISE
Window wants as much space as possible.
Definition mutt_window.h:48
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:665
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:782
String manipulation buffer.
Definition buffer.h:36
Gui private Module data.
Definition module_data.h:32
struct MuttWindow * root_window
Parent of all Windows.
Definition module_data.h:40
struct MuttWindowArray children
Children Windows.
struct WindowState state
Current state of the Window.
enum MuttWindowOrientation orient
Which direction the Window will expand.
enum MuttWindowSize size
Type of Window, e.g. MUTT_WIN_SIZE_FIXED.
Container for Accounts, Notifications.
Definition neomutt.h:41
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition mutt_window.h:60
short row_offset
Absolute on-screen row.
Definition mutt_window.h:63
short col_offset
Absolute on-screen column.
Definition mutt_window.h:62
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition mutt_window.h:61