diff options
author | Frederic Culot <calcurse@culot.org> | 2010-03-20 13:29:47 +0000 |
---|---|---|
committer | Frederic Culot <calcurse@culot.org> | 2010-03-20 13:29:47 +0000 |
commit | ec36b968489111707e2b71f27f3c021571471b5e (patch) | |
tree | a8de15d4e0e6cc809c3a96c03558485028949249 | |
parent | a8cb1c92eff88acc685d7d876647844bacb71e8e (diff) | |
download | calcurse-ec36b968489111707e2b71f27f3c021571471b5e.zip |
Work on sidebar width user-customization.
-rwxr-xr-x | ChangeLog | 9 | ||||
-rwxr-xr-x | src/calcurse.c | 6 | ||||
-rw-r--r-- | src/calcurse.h | 7 | ||||
-rwxr-xr-x | src/calendar.c | 31 | ||||
-rwxr-xr-x | src/custom.c | 78 | ||||
-rwxr-xr-x | src/wins.c | 30 |
6 files changed, 123 insertions, 38 deletions
@@ -1,6 +1,15 @@ 2010-03-20 Frederic Culot <frederic@culot.org> * src/calcurse.h: new header to gather all existing ones + + * src/calcurse.c + * src/calendar.c + * src/wins.c + * src/custom.c (custom_sidebar_config): sidebar configuration + added, allowing to change sidebar's width + + * src/wins.c (wins_update_border, wins_update_panels): new + functions extracted from wins_update() 2010-03-19 Frederic Culot <frederic@culot.org> diff --git a/src/calcurse.c b/src/calcurse.c index ab3febf..59f2d4e 100755 --- a/src/calcurse.c +++ b/src/calcurse.c @@ -1,4 +1,4 @@ -/* $calcurse: calcurse.c,v 1.87 2010/03/20 10:54:42 culot Exp $ */ +/* $calcurse: calcurse.c,v 1.88 2010/03/20 13:29:47 culot Exp $ */ /* * Calcurse - text-based organizer @@ -279,6 +279,10 @@ main (int argc, char **argv) case 'k': custom_keys_config (); break; + case 's': + case 'S': + custom_sidebar_config (); + break; } wins_reset (); wins_update (); diff --git a/src/calcurse.h b/src/calcurse.h index 8af1166..ce335eb 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -1,4 +1,4 @@ -/* $Id: calcurse.h,v 1.1 2010/03/20 10:54:42 culot Exp $ */ +/* $Id: calcurse.h,v 1.2 2010/03/20 13:29:47 culot Exp $ */ /* * Calcurse - text-based organizer @@ -144,7 +144,6 @@ /* Calendar window. */ #define CALHEIGHT 12 -#define CALWIDTH 30 /* Key definitions. */ #define CTRLVAL 0x1F @@ -637,6 +636,7 @@ void custom_remove_attr (WINDOW *, int); void custom_load_conf (struct conf *, int); void custom_config_bar (void); void custom_layout_config (void); +void custom_sidebar_config (void); void custom_color_config (void); void custom_color_theme_name (char *); void custom_confwin_init (struct window *, char *); @@ -893,6 +893,7 @@ void vars_init (struct conf *); /* wins.c */ extern struct window win[NBWINS]; +extern unsigned sbarwidth; int wins_layout (void); void wins_set_layout (int); void wins_slctd_init (void); @@ -908,6 +909,8 @@ void wins_scrollwin_down (struct scrollwin *, int); void wins_reinit (void); void wins_show (WINDOW *, char *); void wins_get_config (void); +void wins_update_border (void); +void wins_update_panels (void); void wins_update (void); void wins_reset (void); void wins_launch_external (const char *, const char *); diff --git a/src/calendar.c b/src/calendar.c index bd318e3..ae3f4ac 100755 --- a/src/calendar.c +++ b/src/calendar.c @@ -1,4 +1,4 @@ -/* $calcurse: calendar.c,v 1.33 2010/03/20 10:54:43 culot Exp $ */ +/* $calcurse: calendar.c,v 1.34 2010/03/20 13:29:48 culot Exp $ */ /* * Calcurse - text-based organizer @@ -302,8 +302,11 @@ date_change (struct tm *date, int delta_month, int delta_day) /* Draw the monthly view inside calendar panel. */ static void -draw_monthly_view (struct window *cwin, struct date *current_day, unsigned sunday_first) +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; @@ -314,8 +317,8 @@ draw_monthly_view (struct window *cwin, struct date *current_day, unsigned sunda yr = slctd_day.yyyy; /* offset for centering calendar in window */ - ofs_y = 2 + (CALHEIGHT - 9) / 2; - ofs_x = (CALWIDTH - 27) / 2; + ofs_y = OFFY; + ofs_x = OFFX; /* checking the number of days in february */ numdays = days[mo - 1]; @@ -330,7 +333,8 @@ draw_monthly_view (struct window *cwin, struct date *current_day, unsigned sunda /* Write the current month and year on top of the calendar */ custom_apply_attr (cwin->p, ATTR_HIGHEST); - mvwprintw (cwin->p, ofs_y, (CALWIDTH - (strlen (_(monthnames[mo - 1])) + 5)) / 2, + mvwprintw (cwin->p, ofs_y, + (sbarwidth - (strlen (_(monthnames[mo - 1])) + 5)) / 2, "%s %d", _(monthnames[mo - 1]), slctd_day.yyyy); custom_remove_attr (cwin->p, ATTR_HIGHEST); ++ofs_y; @@ -358,8 +362,8 @@ draw_monthly_view (struct window *cwin, struct date *current_day, unsigned sunda /* Go to next line, the week is over. */ if (!c_day_1 && 1 != c_day) { - ++ofs_y; - ofs_x = 2 - day_1_sav - 4 * c_day - 1; + ofs_y++; + ofs_x = OFFX - day_1_sav - 4 * c_day; } /* This is today, so print it in yellow. */ @@ -369,28 +373,31 @@ draw_monthly_view (struct window *cwin, struct date *current_day, unsigned sunda && current_day->dd != slctd_day.dd) { custom_apply_attr (cwin->p, ATTR_LOWEST); - mvwprintw (cwin->p, ofs_y + 1, - ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day); + mvwprintw (cwin->p, ofs_y + 1, + ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day); custom_remove_attr (cwin->p, ATTR_LOWEST); } else if (c_day == slctd_day.dd) { /* This is the selected day, print it according to user's theme. */ custom_apply_attr (cwin->p, ATTR_HIGHEST); - mvwprintw (cwin->p, ofs_y + 1, ofs_x + day_1_sav + 4 * c_day + 1, "%2d", + mvwprintw (cwin->p, ofs_y + 1, + ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day); custom_remove_attr (cwin->p, ATTR_HIGHEST); } else if (item_this_day) { custom_apply_attr (cwin->p, ATTR_LOW); - mvwprintw (cwin->p, ofs_y + 1, ofs_x + day_1_sav + 4 * c_day + 1, "%2d", + mvwprintw (cwin->p, ofs_y + 1, + ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day); custom_remove_attr (cwin->p, ATTR_LOW); } else /* otherwise, print normal days in black */ - mvwprintw (cwin->p, ofs_y + 1, ofs_x + day_1_sav + 4 * c_day + 1, "%2d", + mvwprintw (cwin->p, ofs_y + 1, + ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day); } } diff --git a/src/custom.c b/src/custom.c index 82a4057..053d30f 100755 --- a/src/custom.c +++ b/src/custom.c @@ -1,4 +1,4 @@ -/* $calcurse: custom.c,v 1.46 2010/03/20 10:54:43 culot Exp $ */ +/* $calcurse: custom.c,v 1.47 2010/03/20 13:29:48 culot Exp $ */ /* * Calcurse - text-based organizer @@ -402,26 +402,26 @@ custom_load_conf (struct conf *conf, int background) void custom_config_bar (void) { - int smlspc, spc; - - smlspc = 2; - spc = 15; + const int SMLSPC = 2; + const int SPC = 15; custom_apply_attr (win[STA].p, ATTR_HIGHEST); mvwprintw (win[STA].p, 0, 2, "Q"); mvwprintw (win[STA].p, 1, 2, "G"); - mvwprintw (win[STA].p, 0, 2 + spc, "L"); - mvwprintw (win[STA].p, 1, 2 + spc, "C"); - mvwprintw (win[STA].p, 0, 2 + 2 * spc, "N"); - mvwprintw (win[STA].p, 1, 2 + 2 * spc, "K"); + mvwprintw (win[STA].p, 0, 2 + SPC, "L"); + mvwprintw (win[STA].p, 1, 2 + SPC, "S"); + mvwprintw (win[STA].p, 0, 2 + 2 * SPC, "C"); + mvwprintw (win[STA].p, 1, 2 + 2 * SPC, "N"); + mvwprintw (win[STA].p, 0, 2 + 3 * SPC, "K"); custom_remove_attr (win[STA].p, ATTR_HIGHEST); - mvwprintw (win[STA].p, 0, 2 + smlspc, _("Exit")); - mvwprintw (win[STA].p, 1, 2 + smlspc, _("General")); - mvwprintw (win[STA].p, 0, 2 + spc + smlspc, _("Layout")); - mvwprintw (win[STA].p, 1, 2 + spc + smlspc, _("Color")); - mvwprintw (win[STA].p, 0, 2 + 2 * spc + smlspc, _("Notify")); - mvwprintw (win[STA].p, 1, 2 + 2 * spc + smlspc, _("Keys")); + mvwprintw (win[STA].p, 0, 2 + SMLSPC, _("Exit")); + mvwprintw (win[STA].p, 1, 2 + SMLSPC, _("General")); + mvwprintw (win[STA].p, 0, 2 + SPC + SMLSPC, _("Layout")); + mvwprintw (win[STA].p, 1, 2 + SPC + SMLSPC, _("Sidebar")); + mvwprintw (win[STA].p, 0, 2 + 2 * SPC + SMLSPC, _("Color")); + mvwprintw (win[STA].p, 1, 2 + 2 * SPC + SMLSPC, _("Notify")); + mvwprintw (win[STA].p, 0, 2 + 3 * SPC + SMLSPC, _("Keys")); wnoutrefresh (win[STA].p); wmove (win[STA].p, 0, 0); @@ -591,6 +591,54 @@ custom_layout_config (void) #undef NBLAYOUTS #undef LAYOUTSPERCOL +/* Sidebar configuration screen. */ +void +custom_sidebar_config (void) +{ + struct binding inc = {_("Width +"), KEY_MOVE_UP}; + struct binding dec = {_("Width -"), KEY_MOVE_DOWN}; + struct binding help = {_("Help"), KEY_GENERIC_HELP}; + struct binding *binding[] = {&inc, &dec, &help}; + int ch, binding_size; + + binding_size = sizeof (binding) / sizeof (binding[0]); + + 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; + + need_update = 0; + switch (ch) + { + case KEY_MOVE_UP: + sbarwidth++; + need_update = 1; + break; + case KEY_MOVE_DOWN: + sbarwidth--; + need_update = 1; + break; + case KEY_GENERIC_HELP: + /* XXX + Add help screen for sidebar configuration + */ + break; + } + + if (need_update) + { + wins_reinit (); + wins_update_border (); + wins_update_panels (); + keys_display_bindings_bar (win[STA].p, binding, 0, binding_size); + doupdate (); + need_update = 0; + } + } +} + static void set_confwin_attr (struct window *cwin) { @@ -1,4 +1,4 @@ -/* $calcurse: wins.c,v 1.29 2010/03/20 10:54:49 culot Exp $ */ +/* $calcurse: wins.c,v 1.30 2010/03/20 13:29:48 culot Exp $ */ /* * Calcurse - text-based organizer @@ -45,6 +45,9 @@ /* Variables to handle calcurse windows. */ struct window win[NBWINS]; +/* User-configurable side bar width. */ +unsigned sbarwidth = 30; + static enum win slctd_win; static int layout; @@ -103,7 +106,7 @@ wins_init (void) * Create the three main windows plus the status bar and the pad used to * display appointments and event. */ - win[CAL].p = newwin (CALHEIGHT, CALWIDTH, win[CAL].y, win[CAL].x); + win[CAL].p = newwin (CALHEIGHT, sbarwidth, win[CAL].y, win[CAL].x); (void)snprintf (label, BUFSIZ, _("Calendar")); wins_show (win[CAL].p, label); @@ -257,7 +260,7 @@ wins_get_config (void) win[NOT].x = 0; } - win[CAL].w = CALWIDTH; + win[CAL].w = sbarwidth; win[CAL].h = CALHEIGHT; if (layout <= 4) @@ -400,12 +403,8 @@ border_nocolor (WINDOW *window) wnoutrefresh (window); } -/* - * Update all of the three windows and put a border around the - * selected window. - */ void -wins_update (void) +wins_update_border (void) { switch (slctd_win) { @@ -428,10 +427,25 @@ wins_update (void) EXIT (_("no window selected")); /* NOTREACHED */ } +} +void +wins_update_panels (void) +{ apoint_update_panel (slctd_win); todo_update_panel (slctd_win); calendar_update_panel (&win[CAL]); +} + +/* + * Update all of the three windows and put a border around the + * selected window. + */ +void +wins_update (void) +{ + wins_update_border (); + wins_update_panels (); wins_status_bar (); if (notify_bar ()) notify_update_bar (); |