Avoid unnecessary window updates

Add a window bitmask to wins_update() and only update windows that might
actually require an update in our main loop. This improves response
times of the user interface a bit.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2011-09-29 14:04:47 +02:00
parent 5d3ed17bc8
commit 6bdc36b15a
4 changed files with 111 additions and 63 deletions

View File

@ -69,7 +69,6 @@ main (int argc, char **argv)
int non_interactive; int non_interactive;
int no_data_file = 1; int no_data_file = 1;
int cut_item = 0; int cut_item = 0;
unsigned do_update = 1;
char *no_color_support = char *no_color_support =
_("Sorry, colors are not supported by your terminal\n" _("Sorry, colors are not supported by your terminal\n"
"(Press [ENTER] to continue)"); "(Press [ENTER] to continue)");
@ -167,11 +166,11 @@ main (int argc, char **argv)
wins_reinit (); wins_reinit ();
if (notify_bar ()) if (notify_bar ())
notify_start_main_thread (); notify_start_main_thread ();
wins_update (); wins_update (FLAG_ALL);
io_startup_screen (conf.skip_system_dialogs, no_data_file); io_startup_screen (conf.skip_system_dialogs, no_data_file);
inday = *day_process_storage (0, 0, &inday); inday = *day_process_storage (0, 0, &inday);
wins_slctd_set (CAL); wins_slctd_set (CAL);
wins_update (); wins_update (FLAG_ALL);
calendar_start_date_thread (); calendar_start_date_thread ();
if (conf.periodic_save > 0) if (conf.periodic_save > 0)
io_start_psave_thread (&conf); io_start_psave_thread (&conf);
@ -181,14 +180,15 @@ main (int argc, char **argv)
{ {
int key; int key;
do_update = 1; if (resize)
{
resize = 0;
wins_reset ();
}
key = keys_getch (win[STA].p); key = keys_getch (win[STA].p);
switch (key) switch (key)
{ {
case ERR:
do_update = 0;
break;
case KEY_GENERIC_REDRAW: case KEY_GENERIC_REDRAW:
resize = 1; resize = 1;
break; break;
@ -212,10 +212,12 @@ main (int argc, char **argv)
default: default:
break; break;
} }
wins_update (FLAG_ALL);
break; break;
case KEY_GENERIC_OTHER_CMD: case KEY_GENERIC_OTHER_CMD:
wins_other_status_page (wins_slctd ()); wins_other_status_page (wins_slctd ());
wins_update (FLAG_STA);
break; break;
case KEY_GENERIC_GOTO: case KEY_GENERIC_GOTO:
@ -227,6 +229,7 @@ main (int argc, char **argv)
else else
calendar_change_day (conf.input_datefmt); calendar_change_day (conf.input_datefmt);
inday = do_storage (1); inday = do_storage (1);
wins_update (FLAG_CAL | FLAG_APP | FLAG_STA);
break; break;
case KEY_VIEW_ITEM: case KEY_VIEW_ITEM:
@ -234,6 +237,7 @@ main (int argc, char **argv)
day_popup_item (); day_popup_item ();
else if ((wins_slctd () == TOD) && (todo_hilt () != 0)) else if ((wins_slctd () == TOD) && (todo_hilt () != 0))
item_in_popup (NULL, NULL, todo_saved_mesg (), _("To do :")); item_in_popup (NULL, NULL, todo_saved_mesg (), _("To do :"));
wins_update (FLAG_ALL);
break; break;
case KEY_GENERIC_CONFIG_MENU: case KEY_GENERIC_CONFIG_MENU:
@ -279,23 +283,25 @@ main (int argc, char **argv)
continue; continue;
} }
wins_reset (); wins_reset ();
wins_update (); wins_update (FLAG_ALL);
wins_erase_status_bar (); wins_erase_status_bar ();
custom_config_bar (); custom_config_bar ();
inday = do_storage (0); inday = do_storage (0);
} }
wins_update (); wins_update (FLAG_ALL);
break; break;
case KEY_GENERIC_ADD_APPT: case KEY_GENERIC_ADD_APPT:
apoint_add (); apoint_add ();
inday = do_storage (1); inday = do_storage (1);
wins_update (FLAG_CAL | FLAG_APP | FLAG_STA);
break; break;
case KEY_GENERIC_ADD_TODO: case KEY_GENERIC_ADD_TODO:
todo_new_item (); todo_new_item ();
if (todo_hilt () == 0 && todo_nb () == 1) if (todo_hilt () == 0 && todo_nb () == 1)
todo_hilt_increase (); todo_hilt_increase ();
wins_update (FLAG_TOD | FLAG_STA);
break; break;
case KEY_ADD_ITEM: case KEY_ADD_ITEM:
@ -304,11 +310,13 @@ main (int argc, char **argv)
case APP: case APP:
apoint_add (); apoint_add ();
inday = do_storage (0); inday = do_storage (0);
wins_update (FLAG_CAL | FLAG_APP | FLAG_STA);
break; break;
case TOD: case TOD:
todo_new_item (); todo_new_item ();
if (todo_hilt () == 0 && todo_nb () == 1) if (todo_hilt () == 0 && todo_nb () == 1)
todo_hilt_increase (); todo_hilt_increase ();
wins_update (FLAG_TOD | FLAG_STA);
break; break;
default: default:
break; break;
@ -320,9 +328,13 @@ main (int argc, char **argv)
{ {
day_edit_item (&conf); day_edit_item (&conf);
inday = do_storage (0); inday = do_storage (0);
wins_update (FLAG_CAL | FLAG_APP | FLAG_STA);
} }
else if (wins_slctd () == TOD && todo_hilt () != 0) else if (wins_slctd () == TOD && todo_hilt () != 0)
todo_edit_item (); {
todo_edit_item ();
wins_update (FLAG_TOD | FLAG_STA);
}
break; break;
case KEY_DEL_ITEM: case KEY_DEL_ITEM:
@ -330,9 +342,13 @@ main (int argc, char **argv)
{ {
apoint_delete (&conf, &inday.nb_events, &inday.nb_apoints); apoint_delete (&conf, &inday.nb_events, &inday.nb_apoints);
inday = do_storage (0); inday = do_storage (0);
wins_update (FLAG_CAL | FLAG_APP | FLAG_STA);
} }
else if (wins_slctd () == TOD && todo_hilt () != 0) else if (wins_slctd () == TOD && todo_hilt () != 0)
todo_delete (&conf); {
todo_delete (&conf);
wins_update (FLAG_TOD | FLAG_STA);
}
break; break;
case KEY_GENERIC_CUT: case KEY_GENERIC_CUT:
@ -340,6 +356,7 @@ main (int argc, char **argv)
{ {
cut_item = apoint_cut (&inday.nb_events, &inday.nb_apoints); cut_item = apoint_cut (&inday.nb_events, &inday.nb_apoints);
inday = do_storage (0); inday = do_storage (0);
wins_update (FLAG_CAL | FLAG_APP);
} }
break; break;
@ -349,6 +366,7 @@ main (int argc, char **argv)
apoint_paste (&inday.nb_events, &inday.nb_apoints, cut_item); apoint_paste (&inday.nb_events, &inday.nb_apoints, cut_item);
cut_item = 0; cut_item = 0;
inday = do_storage (0); inday = do_storage (0);
wins_update (FLAG_CAL | FLAG_APP);
} }
break; break;
@ -356,6 +374,7 @@ main (int argc, char **argv)
if (wins_slctd () == APP && apoint_hilt () != 0) if (wins_slctd () == APP && apoint_hilt () != 0)
recur_repeat_item (&conf); recur_repeat_item (&conf);
inday = do_storage (0); inday = do_storage (0);
wins_update (FLAG_CAL | FLAG_APP | FLAG_STA);
break; break;
case KEY_FLAG_ITEM: case KEY_FLAG_ITEM:
@ -363,9 +382,13 @@ main (int argc, char **argv)
{ {
apoint_switch_notify (); apoint_switch_notify ();
inday = do_storage (0); inday = do_storage (0);
wins_update (FLAG_APP);
} }
else if (wins_slctd () == TOD && todo_hilt () != 0) else if (wins_slctd () == TOD && todo_hilt () != 0)
todo_flag (); {
todo_flag ();
wins_update (FLAG_TOD);
}
break; break;
case KEY_PIPE_ITEM: case KEY_PIPE_ITEM:
@ -373,6 +396,7 @@ main (int argc, char **argv)
day_pipe_item (&conf); day_pipe_item (&conf);
else if (wins_slctd () == TOD && todo_hilt () != 0) else if (wins_slctd () == TOD && todo_hilt () != 0)
todo_pipe_item (); todo_pipe_item ();
wins_update (FLAG_ALL);
break; break;
case KEY_RAISE_PRIORITY: case KEY_RAISE_PRIORITY:
@ -384,6 +408,7 @@ main (int argc, char **argv)
todo_set_first (todo_hilt ()); todo_set_first (todo_hilt ());
else if (todo_hilt_pos () >= win[TOD].h - 4) else if (todo_hilt_pos () >= win[TOD].h - 4)
todo_set_first (todo_hilt () - win[TOD].h + 5); todo_set_first (todo_hilt () - win[TOD].h + 5);
wins_update (FLAG_TOD);
} }
break; break;
@ -395,6 +420,7 @@ main (int argc, char **argv)
} }
else if (wins_slctd () == TOD && todo_hilt () != 0) else if (wins_slctd () == TOD && todo_hilt () != 0)
todo_edit_note (conf.editor); todo_edit_note (conf.editor);
wins_update (FLAG_ALL);
break; break;
case KEY_VIEW_NOTE: case KEY_VIEW_NOTE:
@ -402,21 +428,25 @@ main (int argc, char **argv)
day_view_note (conf.pager); day_view_note (conf.pager);
else if (wins_slctd () == TOD && todo_hilt () != 0) else if (wins_slctd () == TOD && todo_hilt () != 0)
todo_view_note (conf.pager); todo_view_note (conf.pager);
wins_update (FLAG_ALL);
break; break;
case KEY_GENERIC_HELP: case KEY_GENERIC_HELP:
wins_status_bar (); wins_status_bar ();
help_screen (); help_screen ();
wins_update (FLAG_ALL);
break; break;
case KEY_GENERIC_SAVE: case KEY_GENERIC_SAVE:
io_save_cal (&conf, IO_SAVE_DISPLAY_BAR); io_save_cal (&conf, IO_SAVE_DISPLAY_BAR);
wins_update (FLAG_STA);
break; break;
case KEY_GENERIC_IMPORT: case KEY_GENERIC_IMPORT:
wins_erase_status_bar (); wins_erase_status_bar ();
io_import_data (IO_IMPORT_ICAL, &conf, NULL); io_import_data (IO_IMPORT_ICAL, &conf, NULL);
inday = do_storage (0); inday = do_storage (0);
wins_update (FLAG_ALL);
break; break;
case KEY_GENERIC_EXPORT: case KEY_GENERIC_EXPORT:
@ -436,12 +466,12 @@ main (int argc, char **argv)
break; break;
} }
wins_reset (); wins_reset ();
wins_update (); wins_update (FLAG_ALL);
wins_erase_status_bar (); wins_erase_status_bar ();
io_export_bar (); io_export_bar ();
} }
inday = do_storage (0); inday = do_storage (0);
wins_update (); wins_update (FLAG_ALL);
break; break;
case KEY_GENERIC_NEXT_DAY: case KEY_GENERIC_NEXT_DAY:
@ -450,6 +480,7 @@ main (int argc, char **argv)
{ {
calendar_move (RIGHT); calendar_move (RIGHT);
inday = do_storage (1); inday = do_storage (1);
wins_update (FLAG_CAL | FLAG_APP);
} }
break; break;
@ -459,6 +490,7 @@ main (int argc, char **argv)
{ {
calendar_move (LEFT); calendar_move (LEFT);
inday = do_storage (1); inday = do_storage (1);
wins_update (FLAG_CAL | FLAG_APP);
} }
break; break;
@ -468,17 +500,20 @@ main (int argc, char **argv)
{ {
calendar_move (UP); calendar_move (UP);
inday = do_storage (1); inday = do_storage (1);
wins_update (FLAG_CAL | FLAG_APP);
} }
else if ((wins_slctd () == APP) && (apoint_hilt () > 1)) else if ((wins_slctd () == APP) && (apoint_hilt () > 1))
{ {
apoint_hilt_decrease (); apoint_hilt_decrease ();
apoint_scroll_pad_up (inday.nb_events); apoint_scroll_pad_up (inday.nb_events);
wins_update (FLAG_APP);
} }
else if ((wins_slctd () == TOD) && (todo_hilt () > 1)) else if ((wins_slctd () == TOD) && (todo_hilt () > 1))
{ {
todo_hilt_decrease (); todo_hilt_decrease ();
if (todo_hilt_pos () < 0) if (todo_hilt_pos () < 0)
todo_first_decrease (); todo_first_decrease ();
wins_update (FLAG_TOD);
} }
break; break;
@ -488,18 +523,21 @@ main (int argc, char **argv)
{ {
calendar_move (DOWN); calendar_move (DOWN);
inday = do_storage (1); inday = do_storage (1);
wins_update (FLAG_CAL | FLAG_APP);
} }
else if ((wins_slctd () == APP) && else if ((wins_slctd () == APP) &&
(apoint_hilt () < inday.nb_events + inday.nb_apoints)) (apoint_hilt () < inday.nb_events + inday.nb_apoints))
{ {
apoint_hilt_increase (); apoint_hilt_increase ();
apoint_scroll_pad_down (inday.nb_events, win[APP].h); apoint_scroll_pad_down (inday.nb_events, win[APP].h);
wins_update (FLAG_APP);
} }
else if ((wins_slctd () == TOD) && (todo_hilt () < todo_nb ())) else if ((wins_slctd () == TOD) && (todo_hilt () < todo_nb ()))
{ {
todo_hilt_increase (); todo_hilt_increase ();
if (todo_hilt_pos () == win[TOD].h - 4) if (todo_hilt_pos () == win[TOD].h - 4)
todo_first_increase (); todo_first_increase ();
wins_update (FLAG_TOD);
} }
break; break;
@ -508,6 +546,7 @@ main (int argc, char **argv)
{ {
calendar_move (WEEK_START); calendar_move (WEEK_START);
inday = do_storage (1); inday = do_storage (1);
wins_update (FLAG_CAL | FLAG_APP);
} }
break; break;
@ -516,17 +555,24 @@ main (int argc, char **argv)
{ {
calendar_move (WEEK_END); calendar_move (WEEK_END);
inday = do_storage (1); inday = do_storage (1);
wins_update (FLAG_CAL | FLAG_APP);
} }
break; break;
case KEY_GENERIC_SCROLL_UP: case KEY_GENERIC_SCROLL_UP:
if (wins_slctd () == CAL) if (wins_slctd () == CAL)
calendar_view_prev (); {
calendar_view_prev ();
wins_update (FLAG_CAL | FLAG_APP);
}
break; break;
case KEY_GENERIC_SCROLL_DOWN: case KEY_GENERIC_SCROLL_DOWN:
if (wins_slctd () == CAL) if (wins_slctd () == CAL)
calendar_view_next (); {
calendar_view_next ();
wins_update (FLAG_CAL | FLAG_APP);
}
break; break;
case KEY_GENERIC_QUIT: case KEY_GENERIC_QUIT:
@ -544,6 +590,7 @@ main (int argc, char **argv)
else else
{ {
wins_erase_status_bar (); wins_erase_status_bar ();
wins_update (FLAG_STA);
break; break;
} }
} }
@ -551,19 +598,9 @@ main (int argc, char **argv)
exit_calcurse (EXIT_SUCCESS); exit_calcurse (EXIT_SUCCESS);
break; break;
case ERR:
default: default:
do_update = 0;
break; break;
} }
if (resize)
{
resize = 0;
do_update = 0;
wins_reset ();
}
if (do_update)
wins_update ();
} }
} }

View File

@ -430,6 +430,13 @@ enum win {
NBWINS NBWINS
}; };
#define FLAG_CAL (1 << CAL)
#define FLAG_APP (1 << APP)
#define FLAG_TOD (1 << TOD)
#define FLAG_NOT (1 << NOT)
#define FLAG_STA (1 << STA)
#define FLAG_ALL ((1 << NBWINS) - 1)
enum ui_mode { enum ui_mode {
UI_CURSES, UI_CURSES,
UI_CMDLINE, UI_CMDLINE,
@ -946,9 +953,9 @@ void wins_reinit (void);
void wins_reinit_panels (void); void wins_reinit_panels (void);
void wins_show (WINDOW *, char *); void wins_show (WINDOW *, char *);
void wins_get_config (void); void wins_get_config (void);
void wins_update_border (void); void wins_update_border (int);
void wins_update_panels (void); void wins_update_panels (int);
void wins_update (void); void wins_update (int);
void wins_reset (void); void wins_reset (void);
void wins_prepare_external (void); void wins_prepare_external (void);
void wins_unprepare_external (void); void wins_unprepare_external (void);

View File

@ -696,8 +696,8 @@ custom_sidebar_config (void)
else else
{ {
wins_reinit_panels (); wins_reinit_panels ();
wins_update_border (); wins_update_border (FLAG_ALL);
wins_update_panels (); wins_update_panels (FLAG_ALL);
keys_display_bindings_bar (win[STA].p, binding, 0, binding_size); keys_display_bindings_bar (win[STA].p, binding, 0, binding_size);
wins_doupdate (); wins_doupdate ();
} }

View File

@ -539,37 +539,40 @@ border_nocolor (WINDOW *window)
} }
void void
wins_update_border (void) wins_update_border (int flags)
{ {
switch (slctd_win) if (flags & FLAG_CAL)
{ {
case CAL: if (slctd_win == CAL)
border_color (win[CAL].p); border_color (win[CAL].p);
border_nocolor (win[APP].p); else
border_nocolor (win[TOD].p); border_nocolor (win[CAL].p);
break; }
case APP: if (flags & FLAG_APP)
border_color (win[APP].p); {
border_nocolor (win[CAL].p); if (slctd_win == APP)
border_nocolor (win[TOD].p); border_color (win[APP].p);
break; else
case TOD: border_nocolor (win[APP].p);
border_color (win[TOD].p); }
border_nocolor (win[APP].p); if (flags & FLAG_TOD)
border_nocolor (win[CAL].p); {
break; if (slctd_win == TOD)
default: border_color (win[TOD].p);
EXIT (_("no window selected")); else
/* NOTREACHED */ border_nocolor (win[TOD].p);
} }
} }
void void
wins_update_panels (void) wins_update_panels (int flags)
{ {
apoint_update_panel (slctd_win); if (flags & FLAG_APP)
todo_update_panel (slctd_win); apoint_update_panel (slctd_win);
calendar_update_panel (&win[CAL]); if (flags & FLAG_TOD)
todo_update_panel (slctd_win);
if (flags & FLAG_CAL)
calendar_update_panel (&win[CAL]);
} }
/* /*
@ -577,12 +580,13 @@ wins_update_panels (void)
* selected window. * selected window.
*/ */
void void
wins_update (void) wins_update (int flags)
{ {
wins_update_border (); wins_update_border (flags);
wins_update_panels (); wins_update_panels (flags);
wins_status_bar (); if (flags & FLAG_STA)
if (notify_bar ()) wins_status_bar ();
if ((flags & FLAG_NOT) && notify_bar ())
notify_update_bar (); notify_update_bar ();
wmove (win[STA].p, 0, 0); wmove (win[STA].p, 0, 0);
wins_doupdate (); wins_doupdate ();
@ -596,7 +600,7 @@ wins_reset (void)
wins_refresh (); wins_refresh ();
curs_set (0); curs_set (0);
wins_reinit (); wins_reinit ();
wins_update (); wins_update (FLAG_ALL);
} }
/* Prepare windows for the execution of an external command. */ /* Prepare windows for the execution of an external command. */