summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2012-12-16 00:16:13 +0100
committerLukas Fleischer <calcurse@cryptocrack.de>2012-12-16 02:27:36 +0100
commite492ac6f952043c3b4adbfffb3711be638a93883 (patch)
tree4b414ef1fccdc5c1364e88d2832315ba11c76e8a
parentaa7844942e1d5e33894c236d326abfbb30462c8f (diff)
downloadcalcurse-e492ac6f952043c3b4adbfffb3711be638a93883.tar.gz
calcurse-e492ac6f952043c3b4adbfffb3711be638a93883.zip
Add hidden key handler window
After BUG#6 had apparently been closed with the screen locks introduced in commit a80f8dcf2c6eb3b54658218bc081ee9694204dd5, some people still had problems with random characters appearing in the notification bar. This was obviously caused by wgetch() refreshing the screen if the status panel was changed. From wgetch(3): If the window is not a pad, and it has been moved or modified since the last call to wrefresh, wrefresh will be called before another character is read. Since the wgetch(3) isn't thread-safe, there were race conditions between the notification bar thread drawing to the notification bar and wgetch() updating the screen. Introduce a (hidden) window that handles all key presses and never gets changed in order to avoid this. Also, call wins_wrefresh() explicitly in status_mesg(), since we can no longer rely on wgetch() updating windows automatically. Fixes reopened BUG#6. Note that this is a hotfix -- FR#26 has been opened to ensure we fix this properly in the next major release. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
-rw-r--r--src/calcurse.c7
-rw-r--r--src/calcurse.h1
-rw-r--r--src/calendar.c2
-rw-r--r--src/custom.c14
-rw-r--r--src/help.c2
-rw-r--r--src/interaction.c26
-rw-r--r--src/io.c12
-rw-r--r--src/notify.c2
-rw-r--r--src/utils.c3
-rw-r--r--src/wins.c3
10 files changed, 41 insertions, 31 deletions
diff --git a/src/calcurse.c b/src/calcurse.c
index c55db55..85a7941 100644
--- a/src/calcurse.c
+++ b/src/calcurse.c
@@ -565,6 +565,11 @@ int main(int argc, char **argv)
io_load_todo();
io_load_app();
wins_reinit();
+ /*
+ * Refresh the hidden key handler window here to prevent wgetch() from
+ * implicitly calling wrefresh() later (causing ncurses race conditions).
+ */
+ wins_wrefresh(win[KEY].p);
if (conf.system_dialogs) {
wins_update(FLAG_ALL);
io_startup_screen(no_data_file);
@@ -589,7 +594,7 @@ int main(int argc, char **argv)
wins_reset();
}
- key = keys_getch(win[STA].p, &count, &reg);
+ key = keys_getch(win[KEY].p, &count, &reg);
switch (key) {
case KEY_GENERIC_REDRAW:
resize = 1;
diff --git a/src/calcurse.h b/src/calcurse.h
index 093b9af..16b126a 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -239,6 +239,7 @@ enum win {
TOD,
NOT,
STA,
+ KEY,
NBWINS
};
diff --git a/src/calendar.c b/src/calendar.c
index 0eebd4e..313ec53 100644
--- a/src/calendar.c
+++ b/src/calendar.c
@@ -641,7 +641,7 @@ void calendar_change_day(int datefmt)
}
if (wrong_day) {
status_mesg(mesg_line1, mesg_line2);
- wgetch(win[STA].p);
+ wgetch(win[KEY].p);
}
}
}
diff --git a/src/custom.c b/src/custom.c
index 185f65a..df7feef 100644
--- a/src/custom.c
+++ b/src/custom.c
@@ -226,7 +226,7 @@ void custom_layout_config(void)
display_layout_config(&conf_win, mark, cursor);
clear();
- while ((ch = keys_getch(win[STA].p, NULL, NULL)) != KEY_GENERIC_QUIT) {
+ while ((ch = keys_getch(win[KEY].p, NULL, NULL)) != KEY_GENERIC_QUIT) {
need_reset = 0;
switch (ch) {
case KEY_GENERIC_HELP:
@@ -310,7 +310,7 @@ void custom_sidebar_config(void)
bindings_size, NULL);
wins_doupdate();
- while ((ch = keys_getch(win[STA].p, NULL, NULL)) != KEY_GENERIC_QUIT) {
+ while ((ch = keys_getch(win[KEY].p, NULL, NULL)) != KEY_GENERIC_QUIT) {
switch (ch) {
case KEY_MOVE_UP:
wins_sbar_winc();
@@ -528,7 +528,7 @@ void custom_color_config(void)
theme_changed);
clear();
- while ((ch = keys_getch(win[STA].p, NULL, NULL)) != KEY_GENERIC_QUIT) {
+ while ((ch = keys_getch(win[KEY].p, NULL, NULL)) != KEY_GENERIC_QUIT) {
need_reset = 0;
theme_changed = 0;
@@ -732,7 +732,7 @@ void custom_general_config(void)
wins_scrollwin_display(&cwin);
buf = mem_malloc(BUFSIZ);
- while ((ch = wgetch(win[STA].p)) != 'q') {
+ while ((ch = wgetch(win[KEY].p)) != 'q') {
buf[0] = '\0';
switch (ch) {
@@ -921,7 +921,7 @@ void custom_keys_config(void)
for (;;) {
int ch;
- ch = keys_getch(win[STA].p, NULL, NULL);
+ ch = keys_getch(win[KEY].p, NULL, NULL);
switch (ch) {
case KEY_MOVE_UP:
if (selrow > 0) {
@@ -1032,7 +1032,7 @@ void custom_config_main(void)
int old_layout;
custom_config_bar();
- while ((ch = wgetch(win[STA].p)) != 'q') {
+ while ((ch = wgetch(win[KEY].p)) != 'q') {
switch (ch) {
case 'C':
case 'c':
@@ -1042,7 +1042,7 @@ void custom_config_main(void)
colorize = 0;
wins_erase_status_bar();
mvwaddstr(win[STA].p, 0, 0, no_color_support);
- wgetch(win[STA].p);
+ wgetch(win[KEY].p);
}
break;
case 'L':
diff --git a/src/help.c b/src/help.c
index a8d3edb..d9afd4c 100644
--- a/src/help.c
+++ b/src/help.c
@@ -793,7 +793,7 @@ void help_screen(void)
}
wins_scrollwin_display(&hwin);
- ch = keys_getch(win[STA].p, NULL, NULL);
+ ch = keys_getch(win[KEY].p, NULL, NULL);
}
wins_scrollwin_delete(&hwin);
if (need_resize)
diff --git a/src/interaction.c b/src/interaction.c
index 635f78a..d048239 100644
--- a/src/interaction.c
+++ b/src/interaction.c
@@ -54,7 +54,7 @@ static int day_edit_time(int time, unsigned *new_hour, unsigned *new_minute)
return 1;
} else {
status_mesg(fmt_msg, enter_str);
- wgetch(win[STA].p);
+ wgetch(win[KEY].p);
}
} else
return 0;
@@ -86,7 +86,7 @@ static int day_edit_duration(int start, int dur, unsigned *new_duration)
break;
} else {
status_mesg(fmt_msg, enter_str);
- wgetch(win[STA].p);
+ wgetch(win[KEY].p);
}
} else
return 0;
@@ -115,7 +115,7 @@ static void update_start_time(long *start, long *dur)
valid_date = 1;
} else {
status_mesg(msg_wrong_time, msg_enter);
- wgetch(win[STA].p);
+ wgetch(win[KEY].p);
valid_date = 0;
}
}
@@ -212,7 +212,7 @@ static void update_rept(struct rpt **rpt, const long start)
mem_free(freqstr);
if (newfreq == 0) {
status_mesg(msg_wrong_freq, msg_enter);
- wgetch(win[STA].p);
+ wgetch(win[KEY].p);
}
} else {
mem_free(freqstr);
@@ -249,14 +249,14 @@ static void update_rept(struct rpt **rpt, const long start)
newuntil = date2sec(new_date, lt.tm_hour, lt.tm_min);
if (newuntil < start) {
status_mesg(msg_wrong_time, msg_enter);
- wgetch(win[STA].p);
+ wgetch(win[KEY].p);
date_entered = 0;
} else
date_entered = 1;
} else {
snprintf(outstr, BUFSIZ, msg_fmts, DATEFMT_DESC(conf.input_datefmt));
status_mesg(msg_wrong_date, outstr);
- wgetch(win[STA].p);
+ wgetch(win[KEY].p);
date_entered = 0;
}
}
@@ -447,7 +447,7 @@ void interact_day_item_add(void)
break;
else {
status_mesg(format_message_1, enter_str);
- wgetch(win[STA].p);
+ wgetch(win[KEY].p);
}
} else
return;
@@ -477,7 +477,7 @@ void interact_day_item_add(void)
break;
} else {
status_mesg(format_message_2, enter_str);
- wgetch(win[STA].p);
+ wgetch(win[KEY].p);
}
} else
return;
@@ -606,7 +606,7 @@ void interact_todo_add(void)
if (getstring(win[STA].p, todo_input, BUFSIZ, 0, 1) == GETSTRING_VALID) {
while ((ch < '1') || (ch > '9')) {
status_mesg(mesg_id, "");
- ch = wgetch(win[STA].p);
+ ch = wgetch(win[KEY].p);
}
todo_add(todo_input, ch - '0', NULL);
todo_set_nb(todo_nb() + 1);
@@ -744,7 +744,7 @@ void interact_day_item_repeat(void)
p = day_get_item(item_nb);
if (p->type != APPT && p->type != EVNT) {
status_mesg(wrong_type_1, wrong_type_2);
- wgetch(win[STA].p);
+ wgetch(win[KEY].p);
return;
}
@@ -771,7 +771,7 @@ void interact_day_item_repeat(void)
freq = atoi(user_input);
if (freq == 0) {
status_mesg(mesg_wrong_freq, wrong_type_2);
- wgetch(win[STA].p);
+ wgetch(win[KEY].p);
}
user_input[0] = '\0';
} else
@@ -796,7 +796,7 @@ void interact_day_item_repeat(void)
until = date2sec(until_date, lt.tm_hour, lt.tm_min);
if (until < p->start) {
status_mesg(mesg_older, wrong_type_2);
- wgetch(win[STA].p);
+ wgetch(win[KEY].p);
date_entered = 0;
} else {
date_entered = 1;
@@ -805,7 +805,7 @@ void interact_day_item_repeat(void)
snprintf(outstr, BUFSIZ, mesg_wrong_2,
DATEFMT_DESC(conf.input_datefmt));
status_mesg(mesg_wrong_1, outstr);
- wgetch(win[STA].p);
+ wgetch(win[KEY].p);
date_entered = 0;
}
}
diff --git a/src/io.c b/src/io.c
index bef4c55..1572a49 100644
--- a/src/io.c
+++ b/src/io.c
@@ -175,7 +175,7 @@ static FILE *get_export_stream(enum export_type type)
stream = fopen(stream_name, "w");
if (stream == NULL) {
status_mesg(wrong_name, press_enter);
- wgetch(win[STA].p);
+ wgetch(win[KEY].p);
}
}
mem_free(stream_name);
@@ -421,7 +421,7 @@ void io_save_cal(enum save_display display)
/* Print a message telling data were saved */
if (ui_mode == UI_CURSES && conf.system_dialogs) {
status_mesg(save_success, enter);
- wgetch(win[STA].p);
+ wgetch(win[KEY].p);
}
pthread_mutex_unlock(&io_save_mutex);
@@ -893,7 +893,7 @@ void io_startup_screen(int no_data_file)
status_mesg(_("Welcome to Calcurse. Missing data files were created."),
enter);
- wgetch(win[STA].p);
+ wgetch(win[KEY].p);
}
/* Export calcurse data. */
@@ -928,7 +928,7 @@ void io_export_data(enum export_type type)
if (conf.system_dialogs && ui_mode == UI_CURSES) {
status_mesg(success, enter);
- wgetch(win[STA].p);
+ wgetch(win[KEY].p);
}
}
@@ -952,7 +952,7 @@ static FILE *get_import_stream(enum import_type type)
stream = fopen(stream_name, "r");
if (stream == NULL) {
status_mesg(wrong_file, press_enter);
- wgetch(win[STA].p);
+ wgetch(win[KEY].p);
}
}
mem_free(stream_name);
@@ -1030,7 +1030,7 @@ void io_import_data(enum import_type type, const char *stream_name)
stats_str[1], stats_str[2], stats_str[3],
_("Press [ENTER] to continue"));
status_mesg(read, stat);
- wgetch(win[STA].p);
+ wgetch(win[KEY].p);
} else if (ui_mode == UI_CMDLINE) {
printf(proc_report, stats.lines);
printf("\n%s / %s / %s / %s\n", stats_str[0], stats_str[1],
diff --git a/src/notify.c b/src/notify.c
index ebc9728..c739829 100644
--- a/src/notify.c
+++ b/src/notify.c
@@ -676,7 +676,7 @@ void notify_config_bar(void)
wins_scrollwin_display(&cwin);
buf = mem_malloc(BUFSIZ);
- while ((ch = wgetch(win[STA].p)) != 'q') {
+ while ((ch = wgetch(win[KEY].p)) != 'q') {
buf[0] = '\0';
switch (ch) {
diff --git a/src/utils.c b/src/utils.c
index 60b0278..ba31418 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -174,6 +174,7 @@ void status_mesg(const char *msg1, const char *msg2)
mvwaddstr(win[STA].p, 0, 0, msg1);
mvwaddstr(win[STA].p, 1, 0, msg2);
custom_remove_attr(win[STA].p, ATTR_HIGHEST);
+ wins_wrefresh(win[STA].p);
}
/*
@@ -205,7 +206,7 @@ int status_ask_choice(const char *message, const char choice[], int nb_choice)
status_mesg(message, avail_choice);
for (;;) {
- ch = wgetch(win[STA].p);
+ ch = wgetch(win[KEY].p);
for (i = 1; i <= nb_choice; i++)
if (ch == choice[i])
return i;
diff --git a/src/wins.c b/src/wins.c
index fd8333d..0181ab9 100644
--- a/src/wins.c
+++ b/src/wins.c
@@ -262,8 +262,10 @@ void wins_init(void)
{
wins_init_panels();
win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y, win[STA].x);
+ win[KEY].p = newwin(1, 1, 1, 1);
keypad(win[STA].p, TRUE);
+ keypad(win[KEY].p, TRUE);
/* Notify that the curses mode is now launched. */
ui_mode = UI_CURSES;
@@ -345,6 +347,7 @@ void wins_reinit(void)
delwin(apad.ptrwin);
delwin(win[TOD].p);
delwin(win[STA].p);
+ delwin(win[KEY].p);
wins_get_config();
wins_init();
if (notify_bar())