NeoMutt  2024-03-23-23-gec7045
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
rootwin.c
Go to the documentation of this file.
1
92#include "config.h"
93#include <stdbool.h>
94#include <string.h>
95#include "mutt/lib.h"
96#include "config/lib.h"
97#include "core/lib.h"
98#include "helpbar/lib.h"
99#include "dialog.h"
100#include "msgcont.h"
101#include "msgwin.h"
102#include "mutt_window.h"
103
104void mutt_resize_screen(void);
105
106struct MuttWindow *RootWindow = NULL;
107
114{
115 if (nc->event_type != NT_CONFIG)
116 return 0;
117 if (!nc->global_data || !nc->event_data)
118 return -1;
119
120 struct EventConfig *ev_c = nc->event_data;
121 struct MuttWindow *win_root = nc->global_data;
122
123 if (!mutt_str_equal(ev_c->name, "status_on_top"))
124 return 0;
125
126 struct MuttWindow *first = TAILQ_FIRST(&win_root->children);
127 if (!first)
128 return 0;
129
130 const bool c_status_on_top = cs_subset_bool(NeoMutt->sub, "status_on_top");
131 if ((c_status_on_top && (first->type == WT_HELP_BAR)) ||
132 (!c_status_on_top && (first->type != WT_HELP_BAR)))
133 {
134 // Swap the HelpBar and the AllDialogsWindow
135 struct MuttWindow *next = TAILQ_NEXT(first, entries);
136 if (!next)
137 return 0;
138 TAILQ_REMOVE(&win_root->children, next, entries);
139 TAILQ_INSERT_HEAD(&win_root->children, next, entries);
140
141 mutt_window_reflow(win_root);
142 mutt_debug(LL_DEBUG5, "config done, request WA_REFLOW\n");
143 }
144
145 return 0;
146}
147
154{
155 if (nc->event_type != NT_RESIZE)
156 return 0;
157 if (!nc->global_data)
158 return -1;
159
162
163 mutt_debug(LL_DEBUG5, "window resize done\n");
164 return 0;
165}
166
175{
176 if (nc->event_type != NT_WINDOW)
177 return 0;
178 if (!nc->global_data || !nc->event_data)
179 return -1;
181 return 0;
182
183 struct MuttWindow *win_root = nc->global_data;
184 struct EventWindow *ev_w = nc->event_data;
185 if (ev_w->win != win_root)
186 return 0;
187
189 if (NeoMutt)
190 {
193 }
194
195 mutt_debug(LL_DEBUG5, "window delete done\n");
196 return 0;
197}
198
203{
204 AllDialogsWindow = NULL;
205 MessageContainer = NULL;
207}
208
214void rootwin_new(void)
215{
217 MUTT_WIN_SIZE_FIXED, 0, 0);
219 RootWindow = win_root;
220
221 struct MuttWindow *win_helpbar = helpbar_new();
222 struct MuttWindow *win_alldlgs = alldialogs_new();
223
224 const bool c_status_on_top = cs_subset_bool(NeoMutt->sub, "status_on_top");
225 if (c_status_on_top)
226 {
227 mutt_window_add_child(win_root, win_alldlgs);
228 mutt_window_add_child(win_root, win_helpbar);
229 }
230 else
231 {
232 mutt_window_add_child(win_root, win_helpbar);
233 mutt_window_add_child(win_root, win_alldlgs);
234 }
235
236 struct MuttWindow *win_cont = msgcont_new();
237 struct MuttWindow *win_msg = msgwin_new(false);
238 mutt_window_add_child(win_cont, win_msg);
239 mutt_window_add_child(win_root, win_cont);
240
244}
245
253void rootwin_set_size(int cols, int rows)
254{
255 if (!RootWindow)
256 return;
257
258 bool changed = false;
259
260 if (RootWindow->state.rows != rows)
261 {
262 RootWindow->state.rows = rows;
263 changed = true;
264 }
265
266 if (RootWindow->state.cols != cols)
267 {
268 RootWindow->state.cols = cols;
269 changed = true;
270 }
271
272 if (changed)
273 {
275 }
276}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
struct MuttWindow * AllDialogsWindow
Parent of all Dialogs.
Definition: dialog.c:80
struct MuttWindow * alldialogs_new(void)
Create the AllDialogs Window.
Definition: dialog.c:210
Dialog Windows.
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
static int rootwin_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: rootwin.c:113
static int rootwin_resize_observer(struct NotifyCallback *nc)
Notification that the terminal has been resized - Implements observer_t -.
Definition: rootwin.c:153
static int rootwin_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: rootwin.c:174
Help Bar Convenience wrapper for the Help Bar headers.
struct MuttWindow * helpbar_new(void)
Create the Help Bar Window.
Definition: helpbar.c:333
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
struct MuttWindow * msgcont_new(void)
Create a new Message Container.
Definition: msgcont.c:46
struct MuttWindow * MessageContainer
Window acting as a stack for the message windows.
Definition: msgcont.c:40
Message Window.
struct MuttWindow * msgwin_new(bool interactive)
Create the Message Window.
Definition: msgwin.c:371
Message Window.
Convenience wrapper for the library headers.
bool notify_observer_remove(struct Notify *notify, const observer_t callback, const void *global_data)
Remove an observer from an object.
Definition: notify.c:230
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:191
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:95
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:709
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:344
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:202
void mutt_window_add_child(struct MuttWindow *parent, struct MuttWindow *child)
Add a child to Window.
Definition: mutt_window.c:446
struct MuttWindow * mutt_window_new(enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
Create a new Window.
Definition: mutt_window.c:182
void window_invalidate_all(void)
Mark all windows as in need of repaint.
Definition: mutt_window.c:767
Window management.
@ WT_ROOT
Parent of All Windows.
Definition: mutt_window.h:72
@ WT_HELP_BAR
Help Bar containing list of useful key bindings.
Definition: mutt_window.h:96
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition: mutt_window.h:38
@ NT_WINDOW_DELETE
Window is about to be deleted.
Definition: mutt_window.h:229
@ MUTT_WIN_SIZE_FIXED
Window has a fixed size.
Definition: mutt_window.h:47
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:57
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:43
@ NT_RESIZE
Window has been resized.
Definition: notify_type.h:52
#define TAILQ_FIRST(head)
Definition: queue.h:723
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
#define TAILQ_NEXT(elm, field)
Definition: queue.h:832
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:796
void mutt_resize_screen(void)
Update NeoMutt's opinion about the window size.
Definition: resize.c:75
void rootwin_set_size(int cols, int rows)
Set the dimensions of the Root Window.
Definition: rootwin.c:253
void rootwin_cleanup(void)
Free all the default Windows.
Definition: rootwin.c:202
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: rootwin.c:106
void rootwin_new(void)
Create the default Windows.
Definition: rootwin.c:214
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition: subset.h:52
A config-change event.
Definition: subset.h:71
const char * name
Name of config item that changed.
Definition: subset.h:73
An Event that happened to a Window.
Definition: mutt_window.h:239
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:240
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:144
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct Notify * notify_resize
Window resize notifications handler.
Definition: neomutt.h:43
struct Notify * notify
Notifications handler.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
Data passed to a notification function.
Definition: observer.h:34
void * event_data
Data from notify_send()
Definition: observer.h:38
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:36
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:37
void * global_data
Data from notify_observer_add()
Definition: observer.h:39
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61