NeoMutt  2024-12-12-19-ge4b57e
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
observer.c File Reference

Sidebar observers. More...

#include "config.h"
#include <stdbool.h>
#include <stddef.h>
#include "private.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "color/lib.h"
#include "index/lib.h"
+ Include dependency graph for observer.c:

Go to the source code of this file.

Functions

void sb_win_remove_observers (struct MuttWindow *win)
 Remove Observers from the Sidebar Window.
 
static bool calc_divider (struct SidebarWindowData *wdata)
 Decide what actions are required for the divider.
 
static struct MuttWindowsb_win_init (struct MuttWindow *dlg)
 Initialise and insert the Sidebar Window.
 
static void sb_init_data (struct MuttWindow *win)
 Initialise the Sidebar data.
 
static int sb_account_observer (struct NotifyCallback *nc)
 Notification that an Account has changed - Implements observer_t -.
 
static int sb_color_observer (struct NotifyCallback *nc)
 Notification that a Color has changed - Implements observer_t -.
 
static int sb_command_observer (struct NotifyCallback *nc)
 Notification that a Command has occurred - Implements observer_t -.
 
static int sb_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t -.
 
static int sb_index_observer (struct NotifyCallback *nc)
 Notification that the Index has changed - Implements observer_t -.
 
static int sb_mailbox_observer (struct NotifyCallback *nc)
 Notification that a Mailbox has changed - Implements observer_t -.
 
static int sb_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t -.
 
void sb_win_add_observers (struct MuttWindow *win)
 Add Observers to the Sidebar Window.
 
int sb_insertion_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t -.
 

Detailed Description

Sidebar observers.

Authors
  • Richard Russon
  • Ashish Panigrahi
  • Pietro Cerutti

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file observer.c.

Function Documentation

◆ sb_win_remove_observers()

void sb_win_remove_observers ( struct MuttWindow win)

Remove Observers from the Sidebar Window.

Parameters
winSidebar Window

Definition at line 454 of file observer.c.

455{
456 if (!win || !NeoMutt)
457 return;
458
459 struct MuttWindow *dlg = window_find_parent(win, WT_DLG_INDEX);
460
468}
void mutt_color_observer_remove(observer_t callback, void *global_data)
Remove an observer.
Definition: notify.c:71
static int sb_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: observer.c:405
static int sb_mailbox_observer(struct NotifyCallback *nc)
Notification that a Mailbox has changed - Implements observer_t -.
Definition: observer.c:376
static int sb_account_observer(struct NotifyCallback *nc)
Notification that an Account has changed - Implements observer_t -.
Definition: observer.c:173
static int sb_command_observer(struct NotifyCallback *nc)
Notification that a Command has occurred - Implements observer_t -.
Definition: observer.c:246
static int sb_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t -.
Definition: observer.c:200
static int sb_index_observer(struct NotifyCallback *nc)
Notification that the Index has changed - Implements observer_t -.
Definition: observer.c:352
static int sb_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: observer.c:267
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
struct MuttWindow * window_find_parent(struct MuttWindow *win, enum WindowType type)
Find a (grand-)parent of a Window by type.
Definition: mutt_window.c:558
@ WT_DLG_INDEX
Index Dialog, dlg_index()
Definition: mutt_window.h:87
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition: subset.h:52
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct Notify * notify
Notifications handler.
Definition: neomutt.h:43
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ calc_divider()

static bool calc_divider ( struct SidebarWindowData wdata)
static

Decide what actions are required for the divider.

Parameters
wdataSidebar data
Return values
trueThe width has changed

If the divider changes width, then Window will need to be reflowed.

Definition at line 51 of file observer.c.

52{
53 enum DivType type = SB_DIV_USER;
54 bool changed = false;
55 const char *const c_sidebar_divider_char = cs_subset_string(NeoMutt->sub, "sidebar_divider_char");
56
57 // Calculate the width of the delimiter in screen cells
58 int width = mutt_strwidth(c_sidebar_divider_char);
59 if (width < 1)
60 {
61 type = SB_DIV_ASCII;
62 goto done;
63 }
64
65 const bool c_ascii_chars = cs_subset_bool(NeoMutt->sub, "ascii_chars");
66 if (c_ascii_chars || !CharsetIsUtf8)
67 {
68 const size_t len = mutt_str_len(c_sidebar_divider_char);
69 for (size_t i = 0; i < len; i++)
70 {
71 if (c_sidebar_divider_char[i] & ~0x7F) // high-bit is set
72 {
73 type = SB_DIV_ASCII;
74 width = 1;
75 break;
76 }
77 }
78 }
79
80done:
81 changed = (width != wdata->divider_width);
82
83 wdata->divider_type = type;
84 wdata->divider_width = width;
85
86 return changed;
87}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:291
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
size_t mutt_strwidth(const char *s)
Measure a string's width in screen cells.
Definition: curs_lib.c:443
bool CharsetIsUtf8
Is the user's current character set utf-8?
Definition: charset.c:66
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:496
DivType
Source of the sidebar divider character.
Definition: private.h:79
@ SB_DIV_ASCII
An ASCII vertical bar (pipe)
Definition: private.h:81
@ SB_DIV_USER
User configured using $sidebar_divider_char.
Definition: private.h:80
short divider_width
Width of the divider in screen columns.
Definition: private.h:100
enum DivType divider_type
Type of divider to use, e.g. SB_DIV_ASCII.
Definition: private.h:99
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_win_init()

static struct MuttWindow * sb_win_init ( struct MuttWindow dlg)
static

Initialise and insert the Sidebar Window.

Parameters
dlgIndex Dialog
Return values
ptrSidebar Window

Definition at line 94 of file observer.c.

95{
97
98 struct MuttWindow *index_panel = TAILQ_FIRST(&dlg->children);
99 mutt_window_remove_child(dlg, index_panel);
100
101 struct MuttWindow *pager_panel = TAILQ_FIRST(&dlg->children);
102 mutt_window_remove_child(dlg, pager_panel);
103
107 dlg->focus = cont_right;
108
109 mutt_window_add_child(cont_right, index_panel);
110 mutt_window_add_child(cont_right, pager_panel);
111 cont_right->focus = index_panel;
112
113 const short c_sidebar_width = cs_subset_number(NeoMutt->sub, "sidebar_width");
115 MUTT_WIN_SIZE_FIXED, c_sidebar_width,
117 const bool c_sidebar_visible = cs_subset_bool(NeoMutt->sub, "sidebar_visible");
118 win_sidebar->state.visible = c_sidebar_visible && (c_sidebar_width > 0);
119
120 struct IndexSharedData *shared = dlg->wdata;
121 win_sidebar->wdata = sb_wdata_new(win_sidebar, shared);
122 win_sidebar->wdata_free = sb_wdata_free;
123
124 calc_divider(win_sidebar->wdata);
125
126 win_sidebar->recalc = sb_recalc;
127 win_sidebar->repaint = sb_repaint;
128
129 const bool c_sidebar_on_right = cs_subset_bool(NeoMutt->sub, "sidebar_on_right");
130 if (c_sidebar_on_right)
131 {
132 mutt_window_add_child(dlg, cont_right);
133 mutt_window_add_child(dlg, win_sidebar);
134 }
135 else
136 {
137 mutt_window_add_child(dlg, win_sidebar);
138 mutt_window_add_child(dlg, cont_right);
139 }
140
141 sb_win_add_observers(win_sidebar);
142
143 return win_sidebar;
144}
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:143
int sb_recalc(struct MuttWindow *win)
Recalculate the Sidebar display - Implements MuttWindow::recalc() -.
Definition: window.c:506
int sb_repaint(struct MuttWindow *win)
Repaint the Sidebar display - Implements MuttWindow::repaint() -.
Definition: window.c:695
void sb_wdata_free(struct MuttWindow *win, void **ptr)
Free Sidebar Window data - Implements MuttWindow::wdata_free() -.
Definition: wdata.c:56
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
struct MuttWindow * mutt_window_remove_child(struct MuttWindow *parent, struct MuttWindow *child)
Remove a child from a Window.
Definition: mutt_window.c:468
@ WT_CONTAINER
Invisible shaping container Window.
Definition: mutt_window.h:74
@ WT_SIDEBAR
Side panel containing Accounts or groups of data.
Definition: mutt_window.h:101
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition: mutt_window.h:39
@ MUTT_WIN_ORIENT_HORIZONTAL
Window uses all available horizontal space.
Definition: mutt_window.h:40
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:53
@ MUTT_WIN_SIZE_FIXED
Window has a fixed size.
Definition: mutt_window.h:48
@ MUTT_WIN_SIZE_MAXIMISE
Window wants as much space as possible.
Definition: mutt_window.h:49
#define TAILQ_FIRST(head)
Definition: queue.h:741
void sb_win_add_observers(struct MuttWindow *win)
Add Observers to the Sidebar Window.
Definition: observer.c:434
static bool calc_divider(struct SidebarWindowData *wdata)
Decide what actions are required for the divider.
Definition: observer.c:51
struct SidebarWindowData * sb_wdata_new(struct MuttWindow *win, struct IndexSharedData *shared)
Create new Window data for the Sidebar.
Definition: wdata.c:44
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:37
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:187
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
struct MuttWindow * focus
Focused Window.
Definition: mutt_window.h:140
void * wdata
Private data.
Definition: mutt_window.h:145
enum MuttWindowOrientation orient
Which direction the Window will expand.
Definition: mutt_window.h:130
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:173
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:159
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
bool visible
Window is visible.
Definition: mutt_window.h:60
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_init_data()

static void sb_init_data ( struct MuttWindow win)
static

Initialise the Sidebar data.

Parameters
winSidebar Window

Definition at line 150 of file observer.c.

151{
153 if (!wdata)
154 return;
155
156 if (!ARRAY_EMPTY(&wdata->entries))
157 return;
158
159 struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
161 struct MailboxNode *np = NULL;
162 STAILQ_FOREACH(np, &ml, entries)
163 {
164 if (np->mailbox->visible)
165 sb_add_mailbox(wdata, np->mailbox);
166 }
168}
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:74
@ MUTT_MAILBOX_ANY
Match any Mailbox type.
Definition: mailbox.h:42
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:168
size_t neomutt_mailboxlist_get_all(struct MailboxList *head, struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
Definition: neomutt.c:191
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:324
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
void sb_add_mailbox(struct SidebarWindowData *wdata, struct Mailbox *m)
Add a Mailbox to the Sidebar.
Definition: sidebar.c:89
struct SidebarWindowData * sb_wdata_get(struct MuttWindow *win)
Get the Sidebar data for this window.
Definition: wdata.c:77
List of Mailboxes.
Definition: mailbox.h:166
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:167
bool visible
True if a result of "mailboxes".
Definition: mailbox.h:130
Sidebar private Window data -.
Definition: private.h:88
struct MuttWindow * win
Sidebar Window.
Definition: private.h:89
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_win_add_observers()

void sb_win_add_observers ( struct MuttWindow win)

Add Observers to the Sidebar Window.

Parameters
winSidebar Window

Definition at line 434 of file observer.c.

435{
436 if (!win || !NeoMutt)
437 return;
438
439 struct MuttWindow *dlg = window_find_parent(win, WT_DLG_INDEX);
440
448}
void mutt_color_observer_add(observer_t callback, void *global_data)
Add an observer.
Definition: notify.c:61
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
@ 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_MAILBOX
Mailbox has changed, NotifyMailbox, EventMailbox.
Definition: notify_type.h:49
@ NT_COMMAND
A Command has been executed, Command.
Definition: notify_type.h:42
@ NT_ACCOUNT
Account has changed, NotifyAccount, EventAccount.
Definition: notify_type.h:36
@ NT_ALL
Register for all notifications.
Definition: notify_type.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function: