NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
rootwin.c
Go to the documentation of this file.
1
22
91
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 "bottombar.h"
100#include "dialog.h"
101#include "module_data.h"
102#include "msgcont.h"
103#include "msgwin.h"
104#include "mutt_window.h"
105#include "utilwin.h"
106
107void mutt_resize_screen(void);
108
115{
116 if (nc->event_type != NT_CONFIG)
117 return 0;
118 if (!nc->global_data || !nc->event_data)
119 return -1;
120
121 struct EventConfig *ev_c = nc->event_data;
122 struct MuttWindow *win_root = nc->global_data;
123
124 if (!mutt_str_equal(ev_c->name, "status_on_top"))
125 return 0;
126
127 struct MuttWindow **wp_first = ARRAY_FIRST(&win_root->children);
128 if (!wp_first)
129 return 0;
130
131 struct MuttWindow *first = *wp_first;
132
133 const bool c_status_on_top = cs_subset_bool(NeoMutt->sub, "status_on_top");
134 if ((c_status_on_top && (first->type == WT_HELP_BAR)) ||
135 (!c_status_on_top && (first->type != WT_HELP_BAR)))
136 {
137 // Swap the HelpBar and the AllDialogsWindow
138 if (ARRAY_SIZE(&win_root->children) < 2)
139 return 0;
140
141 struct MuttWindow **wp_next = ARRAY_GET(&win_root->children, 1);
142 if (!wp_next)
143 return 0;
144
145 struct MuttWindow *next = *wp_next;
146 ARRAY_REMOVE(&win_root->children, wp_next);
147 ARRAY_INSERT(&win_root->children, 0, next);
148
149 mutt_window_reflow(win_root);
150 mutt_debug(LL_DEBUG5, "config done, request WA_REFLOW\n");
151 }
152
153 return 0;
154}
155
162{
163 if (nc->event_type != NT_RESIZE)
164 return 0;
165 if (!nc->global_data)
166 return -1;
167
170
171 mutt_debug(LL_DEBUG5, "window resize done\n");
172 return 0;
173}
174
183{
184 if (nc->event_type != NT_WINDOW)
185 return 0;
186 if (!nc->global_data || !nc->event_data)
187 return -1;
189 return 0;
190
191 struct MuttWindow *win_root = nc->global_data;
192 struct EventWindow *ev_w = nc->event_data;
193 if (ev_w->win != win_root)
194 return 0;
195
197 if (NeoMutt)
198 {
201 }
202
203 mutt_debug(LL_DEBUG5, "window delete done\n");
204 return 0;
205}
206
211void rootwin_cleanup(struct GuiModuleData *mod_data)
212{
213 if (mod_data)
214 {
215 mod_data->all_dialogs_window = NULL;
216 mod_data->bottom_bar = NULL;
217 mod_data->message_container = NULL;
218 mod_data->utility_window = NULL;
219 mutt_window_free(&mod_data->root_window);
220 }
221}
222
229void rootwin_new(struct GuiModuleData *mod_data)
230{
232 MUTT_WIN_SIZE_FIXED, 0, 0);
234 if (mod_data)
235 mod_data->root_window = win_root;
236
237 struct MuttWindow *win_helpbar = helpbar_new();
238 struct MuttWindow *win_alldlgs = alldialogs_new();
239
240 const bool c_status_on_top = cs_subset_bool(NeoMutt->sub, "status_on_top");
241 if (c_status_on_top)
242 {
243 mutt_window_add_child(win_root, win_alldlgs);
244 mutt_window_add_child(win_root, win_helpbar);
245 }
246 else
247 {
248 mutt_window_add_child(win_root, win_helpbar);
249 mutt_window_add_child(win_root, win_alldlgs);
250 }
251
252 struct MuttWindow *win_bbar = bottombar_new();
253 struct MuttWindow *win_cont = msgcont_new();
254 struct MuttWindow *win_msg = msgwin_new(false);
255 struct MuttWindow *win_util = utilwin_new();
256 mutt_window_add_child(win_cont, win_msg);
257 mutt_window_add_child(win_bbar, win_cont);
258 mutt_window_add_child(win_bbar, win_util);
259 mutt_window_add_child(win_root, win_bbar);
260
264}
265
273void rootwin_set_size(int cols, int rows)
274{
276 if (!mod_data || !mod_data->root_window)
277 return;
278
279 struct MuttWindow *win_root = mod_data->root_window;
280 bool changed = false;
281
282 if (win_root->state.rows != rows)
283 {
284 win_root->state.rows = rows;
285 changed = true;
286 }
287
288 if (win_root->state.cols != cols)
289 {
290 win_root->state.cols = cols;
291 changed = true;
292 }
293
294 if (changed)
295 {
296 mutt_window_reflow(win_root);
297 }
298}
#define ARRAY_FIRST(head)
Convenience method to get the first element.
Definition array.h:136
#define ARRAY_INSERT(head, idx, elem)
Insert an element into the, shifting up the subsequent entries.
Definition array.h:338
#define ARRAY_REMOVE(head, elem)
Remove an entry from the array, shifting down the subsequent entries.
Definition array.h:355
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
#define ARRAY_GET(head, idx)
Return the element at index.
Definition array.h:109
struct MuttWindow * bottombar_new(void)
Create the Bottom Bar Container.
Definition bottombar.c:67
Bottom Bar Container.
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
struct MuttWindow * alldialogs_new(void)
Create the AllDialogs Window.
Definition dialog.c:223
Dialog Windows.
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
static int rootwin_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition rootwin.c:114
static int rootwin_resize_observer(struct NotifyCallback *nc)
Notification that the terminal has been resized - Implements observer_t -.
Definition rootwin.c:161
static int rootwin_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition rootwin.c:182
Gui private Module data.
Help Bar Convenience wrapper for the Help Bar headers.
struct MuttWindow * helpbar_new(void)
Create the Help Bar Window.
Definition helpbar.c:321
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:49
@ MODULE_ID_GUI
ModuleGui, Graphical code
Definition module_api.h:45
struct MuttWindow * msgcont_new(void)
Create a new Message Container.
Definition msgcont.c:46
Message Window.
struct MuttWindow * msgwin_new(bool interactive)
Create the Message Window.
Definition msgwin.c:381
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:665
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
void mutt_window_add_child(struct MuttWindow *parent, struct MuttWindow *child)
Add a child to Window.
struct MuttWindow * mutt_window_new(enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
Create a new Window.
void window_invalidate_all(void)
Mark all windows as in need of repaint.
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.
@ MUTT_WIN_SIZE_FIXED
Window has a fixed size.
Definition mutt_window.h:47
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition notify_type.h:58
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition notify_type.h:43
@ NT_RESIZE
Window has been resized.
Definition notify_type.h:53
void rootwin_new(struct GuiModuleData *mod_data)
Create the default Windows.
Definition rootwin.c:229
void mutt_resize_screen(void)
Update NeoMutt's opinion about the window size.
Definition resize.c:76
void rootwin_set_size(int cols, int rows)
Set the dimensions of the Root Window.
Definition rootwin.c:273
void rootwin_cleanup(struct GuiModuleData *mod_data)
Free all the default Windows.
Definition rootwin.c:211
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition subset.h:51
A config-change event.
Definition subset.h:70
const char * name
Name of config item that changed.
Definition subset.h:72
An Event that happened to a Window.
struct MuttWindow * win
Window that changed.
Gui private Module data.
Definition module_data.h:32
struct MuttWindow * root_window
Parent of all Windows.
Definition module_data.h:41
struct MuttWindow * all_dialogs_window
Parent of all Dialogs.
Definition module_data.h:38
struct MuttWindow * utility_window
Utility Window.
Definition module_data.h:42
struct MuttWindow * message_container
Message Container Window.
Definition module_data.h:40
struct MuttWindow * bottom_bar
Bottom Bar Container Window.
Definition module_data.h:39
struct MuttWindowArray children
Children Windows.
struct WindowState state
Current state of the Window.
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Container for Accounts, Notifications.
Definition neomutt.h:41
struct Notify * notify_resize
Window resize notifications handler.
Definition neomutt.h:46
struct Notify * notify
Notifications handler.
Definition neomutt.h:45
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
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
struct MuttWindow * utilwin_new(void)
Create the Utility Window.
Definition utilwin.c:215
Utility Window.