aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFrederic Culot <calcurse@culot.org>2010-03-21 09:21:06 +0000
committerFrederic Culot <calcurse@culot.org>2010-03-21 09:21:06 +0000
commitcc77e839d86fda9871f5fde89350d51465ec208b (patch)
tree82711eb671a98bb525bba4365f19bbfe456b5455 /src
parentec36b968489111707e2b71f27f3c021571471b5e (diff)
downloadcalcurse-cc77e839d86fda9871f5fde89350d51465ec208b.tar.gz
calcurse-cc77e839d86fda9871f5fde89350d51465ec208b.zip
More work on sidebar customization.
Diffstat (limited to 'src')
-rw-r--r--src/calcurse.h13
-rwxr-xr-xsrc/calendar.c9
-rwxr-xr-xsrc/custom.c20
-rwxr-xr-xsrc/io.c7
-rwxr-xr-xsrc/wins.c104
5 files changed, 123 insertions, 30 deletions
diff --git a/src/calcurse.h b/src/calcurse.h
index ce335eb..fa18b56 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -1,4 +1,4 @@
-/* $Id: calcurse.h,v 1.2 2010/03/20 13:29:47 culot Exp $ */
+/* $Id: calcurse.h,v 1.3 2010/03/21 09:21:07 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -133,6 +133,10 @@
/* Maximum number of colors available. */
#define NBUSERCOLORS 6
+/* Side bar width acceptable boundaries. */
+#define SBARMINWIDTH 32
+#define SBARMAXWIDTHPERC 50
+
/* Related to date manipulation. */
#define DAYINSEC 86400
#define HOURINSEC 3600
@@ -893,9 +897,13 @@ void vars_init (struct conf *);
/* wins.c */
extern struct window win[NBWINS];
-extern unsigned sbarwidth;
int wins_layout (void);
void wins_set_layout (int);
+unsigned wins_sbar_width (void);
+unsigned wins_sbar_wperc (void);
+void wins_set_sbar_width (unsigned);
+void wins_sbar_winc (void);
+void wins_sbar_wdec (void);
void wins_slctd_init (void);
enum win wins_slctd (void);
void wins_slctd_set (enum win);
@@ -907,6 +915,7 @@ void wins_scrollwin_display (struct scrollwin *);
void wins_scrollwin_up (struct scrollwin *, int);
void wins_scrollwin_down (struct scrollwin *, int);
void wins_reinit (void);
+void wins_reinit_panels (void);
void wins_show (WINDOW *, char *);
void wins_get_config (void);
void wins_update_border (void);
diff --git a/src/calendar.c b/src/calendar.c
index ae3f4ac..c129ec5 100755
--- a/src/calendar.c
+++ b/src/calendar.c
@@ -1,4 +1,4 @@
-/* $calcurse: calendar.c,v 1.34 2010/03/20 13:29:48 culot Exp $ */
+/* $calcurse: calendar.c,v 1.35 2010/03/21 09:21:07 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -306,17 +306,18 @@ draw_monthly_view (struct window *cwin, struct date *current_day,
unsigned sunday_first)
{
const int OFFY = 2 + (CALHEIGHT - 9) / 2;
- const int OFFX = (sbarwidth - 27) / 2;
struct date check_day;
int c_day, c_day_1, day_1_sav, numdays, j;
unsigned yr, mo;
- int ofs_x, ofs_y;
+ int OFFX, SBAR_WIDTH, ofs_x, ofs_y;
int item_this_day = 0;
mo = slctd_day.mm;
yr = slctd_day.yyyy;
/* offset for centering calendar in window */
+ SBAR_WIDTH = wins_sbar_width ();
+ OFFX = (SBAR_WIDTH - 27) / 2;
ofs_y = OFFY;
ofs_x = OFFX;
@@ -334,7 +335,7 @@ draw_monthly_view (struct window *cwin, struct date *current_day,
/* Write the current month and year on top of the calendar */
custom_apply_attr (cwin->p, ATTR_HIGHEST);
mvwprintw (cwin->p, ofs_y,
- (sbarwidth - (strlen (_(monthnames[mo - 1])) + 5)) / 2,
+ (SBAR_WIDTH - (strlen (_(monthnames[mo - 1])) + 5)) / 2,
"%s %d", _(monthnames[mo - 1]), slctd_day.yyyy);
custom_remove_attr (cwin->p, ATTR_HIGHEST);
++ofs_y;
diff --git a/src/custom.c b/src/custom.c
index 053d30f..007c71b 100755
--- a/src/custom.c
+++ b/src/custom.c
@@ -1,4 +1,4 @@
-/* $calcurse: custom.c,v 1.47 2010/03/20 13:29:48 culot Exp $ */
+/* $calcurse: custom.c,v 1.48 2010/03/21 09:21:07 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -43,7 +43,7 @@
#include "calcurse.h"
/* Available configuration variables. */
-enum {
+enum conf_var {
CUSTOM_CONF_NOVARIABLE,
CUSTOM_CONF_AUTOSAVE,
CUSTOM_CONF_PERIODICSAVE,
@@ -55,6 +55,7 @@ enum {
CUSTOM_CONF_WEEKBEGINSONMONDAY,
CUSTOM_CONF_COLORTHEME,
CUSTOM_CONF_LAYOUT,
+ CUSTOM_CONF_SBAR_WIDTH,
CUSTOM_CONF_NOTIFYBARSHOW,
CUSTOM_CONF_NOTIFYBARDATE,
CUSTOM_CONF_NOTIFYBARCLOCK,
@@ -242,7 +243,7 @@ custom_load_conf (struct conf *conf, int background)
char *mesg_line1 = _("Failed to open config file");
char *mesg_line2 = _("Press [ENTER] to continue");
char buf[BUFSIZ], e_conf[BUFSIZ];
- int var;
+ enum conf_var var;
data_file = fopen (path_conf, "r");
if (data_file == NULL)
@@ -311,6 +312,10 @@ custom_load_conf (struct conf *conf, int background)
wins_set_layout (atoi (e_conf));
var = 0;
break;
+ case CUSTOM_CONF_SBAR_WIDTH:
+ wins_set_sbar_width (atoi (e_conf));
+ var = 0;
+ break;
case CUSTOM_CONF_NOTIFYBARSHOW:
nbar.show = fill_config_var (e_conf);
var = 0;
@@ -375,6 +380,8 @@ custom_load_conf (struct conf *conf, int background)
var = CUSTOM_CONF_COLORTHEME;
else if (strncmp (e_conf, "layout=", 7) == 0)
var = CUSTOM_CONF_LAYOUT;
+ else if (strncmp (e_conf, "side-bar_width=", 15) == 0)
+ var = CUSTOM_CONF_SBAR_WIDTH;
else if (strncmp (e_conf, "notify-bar_show=", 16) == 0)
var = CUSTOM_CONF_NOTIFYBARSHOW;
else if (strncmp (e_conf, "notify-bar_date=", 16) == 0)
@@ -605,6 +612,7 @@ custom_sidebar_config (void)
keys_display_bindings_bar (win[STA].p, binding, 0, binding_size);
doupdate ();
+
while ((ch = keys_getch (win[STA].p)) != KEY_GENERIC_QUIT)
{
unsigned need_update;
@@ -613,11 +621,11 @@ custom_sidebar_config (void)
switch (ch)
{
case KEY_MOVE_UP:
- sbarwidth++;
+ wins_sbar_winc ();
need_update = 1;
break;
case KEY_MOVE_DOWN:
- sbarwidth--;
+ wins_sbar_wdec ();
need_update = 1;
break;
case KEY_GENERIC_HELP:
@@ -629,7 +637,7 @@ custom_sidebar_config (void)
if (need_update)
{
- wins_reinit ();
+ wins_reinit_panels ();
wins_update_border ();
wins_update_panels ();
keys_display_bindings_bar (win[STA].p, binding, 0, binding_size);
diff --git a/src/io.c b/src/io.c
index 28b6bdb..79ca3c0 100755
--- a/src/io.c
+++ b/src/io.c
@@ -1,4 +1,4 @@
-/* $calcurse: io.c,v 1.81 2010/03/20 10:54:46 culot Exp $ */
+/* $calcurse: io.c,v 1.82 2010/03/21 09:21:07 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -887,6 +887,11 @@ io_save_conf (struct conf *conf)
(void)fprintf (fp, "\n# This is the layout of the calendar :\n");
(void)fprintf (fp, "layout=\n");
(void)fprintf (fp, "%d\n", wins_layout ());
+
+ (void)fprintf (fp, "\n# Width (in percentage, 0 being minimun width) "
+ "of the side bar :\n");
+ (void)fprintf (fp, "side-bar_width=\n");
+ (void)fprintf (fp, "%d\n", wins_sbar_wperc ());
if (ui_mode == UI_CURSES)
pthread_mutex_lock (&nbar.mutex);
diff --git a/src/wins.c b/src/wins.c
index 91a7640..8cdd9da 100755
--- a/src/wins.c
+++ b/src/wins.c
@@ -1,4 +1,4 @@
-/* $calcurse: wins.c,v 1.30 2010/03/20 13:29:48 culot Exp $ */
+/* $calcurse: wins.c,v 1.31 2010/03/21 09:21:07 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -46,7 +46,7 @@
struct window win[NBWINS];
/* User-configurable side bar width. */
-unsigned sbarwidth = 30;
+static unsigned sbarwidth;
static enum win slctd_win;
static int layout;
@@ -55,7 +55,7 @@ static int layout;
int
wins_layout (void)
{
- return (layout);
+ return layout;
}
/* Set the current layout. */
@@ -65,6 +65,63 @@ wins_set_layout (int nb)
layout = nb;
}
+/* Get the current side bar width. */
+unsigned
+wins_sbar_width (void)
+{
+ return sbarwidth ? sbarwidth : SBARMINWIDTH;
+}
+
+/*
+ * Return the side bar width in percentage of the total number of columns
+ * available in calcurse's screen.
+ */
+unsigned
+wins_sbar_wperc (void)
+{
+ unsigned perc;
+
+ perc = col ? (unsigned)(100 * sbarwidth / col + 1): 0;
+
+ return perc > SBARMAXWIDTHPERC ? SBARMAXWIDTHPERC : perc;
+}
+
+/*
+ * Set side bar width (unit: number of characters) given a width in percentage
+ * of calcurse's screen total width.
+ * The side bar could not have a width representing more than 50% of the screen,
+ * and could not be less than SBARMINWIDTH characters.
+ */
+void
+wins_set_sbar_width (unsigned perc)
+{
+ if (perc > SBARMAXWIDTHPERC)
+ sbarwidth = col * SBARMAXWIDTHPERC / 100;
+ else if (perc <= 0)
+ sbarwidth = SBARMINWIDTH;
+ else
+ {
+ sbarwidth = (unsigned)(col * perc / 100);
+ if (sbarwidth < SBARMINWIDTH)
+ sbarwidth = SBARMINWIDTH;
+ }
+}
+
+/* Change the width of the side bar within acceptable boundaries. */
+void
+wins_sbar_winc (void)
+{
+ if (sbarwidth < SBARMAXWIDTHPERC * col / 100)
+ sbarwidth++;
+}
+
+void
+wins_sbar_wdec (void)
+{
+ if (sbarwidth > SBARMINWIDTH)
+ sbarwidth--;
+}
+
/* Initialize the selected window in calcurse's interface. */
void
wins_slctd_init (void)
@@ -96,17 +153,12 @@ wins_slctd_next (void)
slctd_win++;
}
-/* Create all the windows. */
-void
-wins_init (void)
+static void
+wins_init_panels (void)
{
char label[BUFSIZ];
-
- /*
- * Create the three main windows plus the status bar and the pad used to
- * display appointments and event.
- */
- win[CAL].p = newwin (CALHEIGHT, sbarwidth, win[CAL].y, win[CAL].x);
+
+ win[CAL].p = newwin (CALHEIGHT, wins_sbar_width (), win[CAL].y, win[CAL].x);
(void)snprintf (label, BUFSIZ, _("Calendar"));
wins_show (win[CAL].p, label);
@@ -120,12 +172,19 @@ wins_init (void)
(void)snprintf (label, BUFSIZ, _("ToDo"));
wins_show (win[TOD].p, label);
- win[STA].p = newwin (win[STA].h, win[STA].w, win[STA].y, win[STA].x);
-
- /* Enable function keys (i.e. arrow keys) in those windows */
+ /* Enable function keys (i.e. arrow keys) in those windows */
keypad (win[CAL].p, TRUE);
keypad (win[APP].p, TRUE);
keypad (win[TOD].p, TRUE);
+}
+
+/* Create all the windows. */
+void
+wins_init (void)
+{
+ wins_init_panels ();
+ win[STA].p = newwin (win[STA].h, win[STA].w, win[STA].y, win[STA].x);
+
keypad (win[STA].p, TRUE);
/* Notify that the curses mode is now launched. */
@@ -195,6 +254,17 @@ wins_scrollwin_down (struct scrollwin *sw, int amount)
sw->first_visible_line += amount;
}
+void
+wins_reinit_panels (void)
+{
+ delwin (win[CAL].p);
+ delwin (win[APP].p);
+ delwin (apad.ptrwin);
+ delwin (win[TOD].p);
+ wins_get_config ();
+ wins_init_panels ();
+}
+
/*
* Delete the existing windows and recreate them with their new
* size and placement.
@@ -202,11 +272,11 @@ wins_scrollwin_down (struct scrollwin *sw, int amount)
void
wins_reinit (void)
{
- delwin (win[STA].p);
delwin (win[CAL].p);
delwin (win[APP].p);
delwin (apad.ptrwin);
delwin (win[TOD].p);
+ delwin (win[STA].p);
wins_get_config ();
wins_init ();
if (notify_bar ())
@@ -260,7 +330,7 @@ wins_get_config (void)
win[NOT].x = 0;
}
- win[CAL].w = sbarwidth;
+ win[CAL].w = wins_sbar_width ();
win[CAL].h = CALHEIGHT;
if (layout <= 4)