NeoMutt  2022-04-29-247-gc6aae8
Teaching an old dog new tricks
DOXYGEN
window.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stddef.h>
31#include <stdbool.h>
32#include "mutt/lib.h"
33#include "gui/lib.h"
34#include "lib.h"
35
36// #define DEBUG_SHOW_SERIALISE
37
38static struct MuttWindow *win_focus = NULL;
39
40static const char *win_size(const struct MuttWindow *win)
41{
42 if (!win)
43 return "???";
44
45 switch (win->size)
46 {
48 return "FIX";
50 return "MAX";
52 return "MIN";
53 }
54
55 return "???";
56}
57
58static void win_dump(struct MuttWindow *win, int indent)
59{
60 bool visible = mutt_window_is_visible(win);
61
62 mutt_debug(LL_DEBUG1, "%*s%s[%d,%d] %s-%c \033[1;33m%s\033[0m (%d,%d)%s%s\n",
63 indent, "", visible ? "✓" : "✗\033[1;30m", win->state.col_offset,
64 win->state.row_offset, win_size(win),
65 (win->orient == MUTT_WIN_ORIENT_VERTICAL) ? 'V' : 'H',
66 mutt_window_win_name(win), win->state.cols, win->state.rows,
67 visible ? "" : "\033[0m",
68 (win == win_focus) ? " <-- \033[1;31mFOCUS\033[0m" : "");
69
70 struct MuttWindow *np = NULL;
71 TAILQ_FOREACH(np, &win->children, entries)
72 {
73 win_dump(np, indent + 4);
74 }
75}
76
77#ifdef DEBUG_SHOW_SERIALISE
78static void win_serialise(struct MuttWindow *win, struct Buffer *buf)
79{
80 if (!mutt_window_is_visible(win))
81 return;
82
83 mutt_buffer_add_printf(buf, "<%s {%dx,%dy} [%dC,%dR]", win_size(win),
85 win->state.cols, win->state.rows);
86 struct MuttWindow *np = NULL;
87 TAILQ_FOREACH(np, &win->children, entries)
88 {
89 win_serialise(np, buf);
90 }
91 mutt_buffer_addstr(buf, ">");
92}
93#endif
94
96{
98 mutt_debug(LL_DEBUG1, "\n");
100 mutt_debug(LL_DEBUG1, "\n");
101#ifdef DEBUG_SHOW_SERIALISE
102 struct Buffer buf = mutt_buffer_make(1024);
103 win_serialise(RootWindow, &buf);
106#endif
107 win_focus = NULL;
108}
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:67
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:309
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:233
int mutt_buffer_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:211
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
static void win_dump(struct MuttWindow *win, int indent)
Definition: window.c:58
void debug_win_dump(void)
Definition: window.c:95
static const char * win_size(const struct MuttWindow *win)
Definition: window.c:40
static struct MuttWindow * win_focus
Definition: window.c:38
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
Convenience wrapper for the gui headers.
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
Convenience wrapper for the library headers.
bool mutt_window_is_visible(struct MuttWindow *win)
Is the Window visible?
Definition: mutt_window.c:501
const char * mutt_window_win_name(const struct MuttWindow *win)
Get the name of a Window.
Definition: mutt_window.c:710
struct MuttWindow * window_get_focus(void)
Get the currently focused Window.
Definition: mutt_window.c:643
@ 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
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: rootwin.c:104
Key value store.
String manipulation buffer.
Definition: buffer.h:34
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
enum MuttWindowOrientation orient
Which direction the Window will expand.
Definition: mutt_window.h:130
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
enum MuttWindowSize size
Type of Window, e.g. MUTT_WIN_SIZE_FIXED.
Definition: mutt_window.h:131
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