NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
rootwin.c
Go to the documentation of this file.
1 
94 #include "config.h"
95 #include <stdbool.h>
96 #include <string.h>
97 #include "mutt/lib.h"
98 #include "config/lib.h"
99 #include "core/lib.h"
100 #include "helpbar/lib.h"
101 #include "dialog.h"
102 #include "msgwin.h"
103 #include "mutt_window.h"
104 
105 struct MuttWindow *RootWindow = NULL;
106 
113 {
114  if ((nc->event_type != NT_CONFIG) || !nc->global_data || !nc->event_data)
115  return -1;
116 
117  struct EventConfig *ev_c = nc->event_data;
118  struct MuttWindow *win_root = nc->global_data;
119 
120  if (!mutt_str_equal(ev_c->name, "status_on_top"))
121  return 0;
122 
123  struct MuttWindow *first = TAILQ_FIRST(&win_root->children);
124  if (!first)
125  return 0;
126 
127  const bool c_status_on_top = cs_subset_bool(NeoMutt->sub, "status_on_top");
128  if ((c_status_on_top && (first->type == WT_HELP_BAR)) ||
129  (!c_status_on_top && (first->type != WT_HELP_BAR)))
130  {
131  // Swap the HelpBar and the AllDialogsWindow
132  struct MuttWindow *next = TAILQ_NEXT(first, entries);
133  if (!next)
134  return 0;
135  TAILQ_REMOVE(&win_root->children, next, entries);
136  TAILQ_INSERT_HEAD(&win_root->children, next, entries);
137 
138  mutt_window_reflow(win_root);
139  mutt_debug(LL_DEBUG5, "config done, request WA_REFLOW\n");
140  }
141 
142  return 0;
143 }
144 
153 {
154  if ((nc->event_type != NT_WINDOW) || !nc->global_data || !nc->event_data)
155  return -1;
156 
157  if (nc->event_subtype != NT_WINDOW_DELETE)
158  return 0;
159 
160  struct MuttWindow *win_root = nc->global_data;
161  struct EventWindow *ev_w = nc->event_data;
162  if (ev_w->win != win_root)
163  return 0;
164 
166  if (NeoMutt)
168 
169  mutt_debug(LL_DEBUG5, "window delete done\n");
170  return 0;
171 }
172 
176 void rootwin_free(void)
177 {
178  mutt_window_free(&RootWindow);
179 }
180 
186 void rootwin_new(void)
187 {
188  struct MuttWindow *win_root =
190  notify_set_parent(win_root->notify, NeoMutt->notify);
191  RootWindow = win_root;
192 
193  struct MuttWindow *win_helpbar = helpbar_new();
194  struct MuttWindow *win_alldlgs = alldialogs_new();
195  struct MuttWindow *win_msg = msgwin_new();
196 
197  const bool c_status_on_top = cs_subset_bool(NeoMutt->sub, "status_on_top");
198  if (c_status_on_top)
199  {
200  mutt_window_add_child(win_root, win_alldlgs);
201  mutt_window_add_child(win_root, win_helpbar);
202  }
203  else
204  {
205  mutt_window_add_child(win_root, win_helpbar);
206  mutt_window_add_child(win_root, win_alldlgs);
207  }
208 
209  mutt_window_add_child(win_root, win_msg);
210 
213 }
214 
222 void rootwin_set_size(int cols, int rows)
223 {
224  if (!RootWindow)
225  return;
226 
227  bool changed = false;
228 
229  if (RootWindow->state.rows != rows)
230  {
231  RootWindow->state.rows = rows;
232  changed = true;
233  }
234 
235  if (RootWindow->state.cols != cols)
236  {
237  RootWindow->state.cols = cols;
238  changed = true;
239  }
240 
241  if (changed)
242  {
243  mutt_window_reflow(RootWindow);
244  }
245 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
#define TAILQ_FIRST(head)
Definition: queue.h:723
Data passed to a notification function.
Definition: observer.h:39
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
Window management.
An Event that happened to a Window.
Definition: mutt_window.h:215
struct MuttWindow * alldialogs_new(void)
Create the AllDialogs Window.
Definition: dialog.c:207
Window uses all available vertical space.
Definition: mutt_window.h:38
A config-change event.
Definition: subset.h:69
Parent of All Windows.
Definition: mutt_window.h:72
Window is about to be deleted.
Definition: mutt_window.h:206
struct MuttWindow * helpbar_new(void)
Create the Help Bar Window.
Definition: helpbar.c:327
struct MuttWindow * msgwin_new(void)
Create the Message Window.
Definition: msgwin.c:197
Container for Accounts, Notifications.
Definition: neomutt.h:36
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
Convenience wrapper for the config headers.
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:200
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:43
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
static int rootwin_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t.
Definition: rootwin.c:112
Convenience wrapper for the core headers.
Help Bar Convenience wrapper for the Help Bar headers.
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:189
void rootwin_new(void)
Create the default Windows.
Definition: rootwin.c:186
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
Window has a fixed size.
Definition: mutt_window.h:47
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61
Message Window.
Help Bar containing list of useful key bindings.
Definition: mutt_window.h:96
static int rootwin_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t.
Definition: rootwin.c:152
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
void mutt_window_add_child(struct MuttWindow *parent, struct MuttWindow *child)
Add a child to Window.
Definition: mutt_window.c:468
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:796
Dialog Windows.
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:361
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:228
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:93
#define TAILQ_NEXT(elm, field)
Definition: queue.h:832
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
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:180
void rootwin_set_size(int cols, int rows)
Set the dimensions of the Root Window.
Definition: rootwin.c:222
Log at debug level 5.
Definition: logging.h:44
Convenience wrapper for the library headers.
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:144
const char * name
Name of config item that changed.
Definition: subset.h:72
void rootwin_free(void)
Free all the default Windows.
Definition: rootwin.c:176