NeoMutt  2021-02-05-666-ge300cd
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 static struct MuttWindow *win_focus = NULL;
37 
38 static const char *win_size(const struct MuttWindow *win)
39 {
40  if (!win)
41  return "???";
42 
43  switch (win->size)
44  {
46  return "FIX";
48  return "MAX";
50  return "MIN";
51  }
52 
53  return "???";
54 }
55 
56 static void win_dump(struct MuttWindow *win, int indent)
57 {
58  bool visible = mutt_window_is_visible(win);
59 
60  mutt_debug(LL_DEBUG1, "%*s%s[%d,%d] %s-%c \033[1;33m%s\033[0m (%d,%d)%s%s\n",
61  indent, "", visible ? "✓" : "✗\033[1;30m", win->state.col_offset,
62  win->state.row_offset, win_size(win),
63  (win->orient == MUTT_WIN_ORIENT_VERTICAL) ? 'V' : 'H',
64  mutt_window_win_name(win), win->state.cols, win->state.rows,
65  visible ? "" : "\033[0m",
66  (win == win_focus) ? " <-- \033[1;31mFOCUS\033[0m" : "");
67 
68  struct MuttWindow *np = NULL;
69  TAILQ_FOREACH(np, &win->children, entries)
70  {
71  win_dump(np, indent + 4);
72  }
73 }
74 
75 static void win_serialise(struct MuttWindow *win, struct Buffer *buf)
76 {
77  if (!mutt_window_is_visible(win))
78  return;
79 
80  mutt_buffer_add_printf(buf, "<%s {%dx,%dy} [%dC,%dR]", win_size(win),
81  win->state.col_offset, win->state.row_offset,
82  win->state.cols, win->state.rows);
83  struct MuttWindow *np = NULL;
84  TAILQ_FOREACH(np, &win->children, entries)
85  {
86  win_serialise(np, buf);
87  }
88  mutt_buffer_addstr(buf, ">");
89 }
90 
91 void debug_win_dump(void)
92 {
93  win_focus = window_get_focus();
94  mutt_debug(LL_DEBUG1, "\n");
95  win_dump(RootWindow, 0);
96  mutt_debug(LL_DEBUG1, "\n");
97  struct Buffer buf = mutt_buffer_make(1024);
99  mutt_debug(LL_DEBUG1, "%s\n", mutt_buffer_string(&buf));
100  mutt_buffer_dealloc(&buf);
101  win_focus = NULL;
102 }
Convenience wrapper for the gui headers.
enum MuttWindowOrientation orient
Which direction the Window will expand.
Definition: mutt_window.h:130
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
Window uses all available vertical space.
Definition: mutt_window.h:38
static void win_serialise(struct MuttWindow *win, struct Buffer *buf)
Definition: window.c:75
static const char * win_size(const struct MuttWindow *win)
Definition: window.c:38
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
String manipulation buffer.
Definition: buffer.h:33
static void win_dump(struct MuttWindow *win, int indent)
Definition: window.c:56
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:62
void debug_win_dump(void)
Definition: window.c:91
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
struct MuttWindow * window_get_focus(void)
Get the currently focussed Window.
Definition: mutt_window.c:664
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:294
int mutt_buffer_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:203
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
Window has a fixed size.
Definition: mutt_window.h:47
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
Window size depends on its children.
Definition: mutt_window.h:49
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
bool mutt_window_is_visible(struct MuttWindow *win)
Is the Window visible?
Definition: mutt_window.c:529
short row_offset
Absolute on-screen row.
Definition: mutt_window.h:63
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61
enum MuttWindowSize size
Type of Window, e.g. MUTT_WIN_SIZE_FIXED.
Definition: mutt_window.h:131
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Convenience wrapper for the debug headers.
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: rootwin.c:105
Log at debug level 1.
Definition: logging.h:40
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
Convenience wrapper for the library headers.
const char * mutt_window_win_name(const struct MuttWindow *win)
Get the name of a Window.
Definition: mutt_window.c:731
Window wants as much space as possible.
Definition: mutt_window.h:48