summaryrefslogtreecommitdiffstats
path: root/src/notify.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix display of time left before next appointmentLars Henriksen2019-04-131-5/+7
| | | | | | | | | | | | | | | | | | In the notify bar, the clock is shown in hours, minutes and seconds, whereas the time left to the next appointment is shown in hours and minutes only. When you read the clock in hours and minutes (discarding the seconds), you are mentally rounding down to the nearest minute. To agree with that reading, the time left (in seconds) should be (programmatically) rounded up to the nearest minute for display. In that way the time left is counted down whenever the minute "hand" of the clock "ticks", and reaches zero when the clock reaches the time of the next appointment, not one minute before. Also, the clock (in hours and minutes) and the time left always add up to the time of the next appointment. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Fix one-second warning period for notificationsLars Henriksen2019-04-131-1/+1
| | | | | | | Adresses GitHub issue #204, the interactive part. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Use time_t for system time valuesLukas Fleischer2019-01-141-3/+3
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Solve deadlock in notification barLars Henriksen2018-07-281-8/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | calcurse deadlocks when 1) an upcoming appointment is on display in the notification bar, 2) an external command (like help) is started, 3) the time for the upcoming appointment arrives, and 4) the external command is exited. The notification bar thread is stopped while the external command is running. Upon exit from the external command, the n-bar thread is restarted and calcurse locks. The cause is the way in which the main notification bar thread is stopped: static pthread_t notify_t_main; void notify_stop_main_thread(void) { if (notify_t_main) { pthread_cancel(notify_t_main); pthread_join(notify_t_main, NULL); } } Objects of type pthread_t are opaque and should not be accessed directly. Initially notify_t_main is an uninitialised static variable (0), but later it has a value, which may or may not be the thread id of the notification main thread. Note that the thread id after exit of a thread may become the thread id of a new thread. Thus the variable set when the thread is created, is invalid after exit of the thread. Specifically, the first time notify_stop_main_thread() is called (by notify_start_main_thread() before the thread is created) is harmless (because notify_t_main is 0). Calling notify_stop_main_thread() later may be either OK because the main thread is running, or harmless because no thread with id notify_t_main is running: the two functions will fail with return value ESRCH (no such process), or fatal because an unrelated thread with this thread id is running: it will be cancelled, and the join may or may not succeed depending on whether the thread is joinable or detached. The "unrelated thread" could be the next-appointment thread, notify_thread_app, launched by notify_check_next_app(). Always calling notify_stop_main_thread() before starting the main thread becomes fatal when notify_check_next_app() is called shortly before notify_start_main_thread(). This is the case in the scenario described. The next-app-thread is then running when notify_stop_main_thread() is called, and apparently it has the thread id of the old main thread (confirmed by logging the return values from pthread_cancel() and pthread_join(); the first succeeds while the second fails with EINVALID which means that the thread is not joinable). The next-app-thread will therefore exit without unlocking mutexes. Ensure that notify_t_main, in case the notify main thread is not running, has a value that it will never have when it is running. A possibility is the thread id of the main() calcurse process (returned by pthread_self()). Check for this condition in notify_stop_main_thread() and set notify_t_main when the thread is stopped. Similar changes have been introduced for the periodic save thread and the calendar date thread. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Do not stop already cancelled notification threadLukas Fleischer2018-06-031-6/+11
| | | | | | | | | Add a static state variable to indicate whether the notification thread is already running or not. Only start the thread if the notification thread is paused. Only stop the thread if the notification thread is actually running. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* notify.c: fix several buffer overflowsLukas Fleischer2018-05-261-13/+18
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Scrollbar and right window border (corrected)Lars Henriksen2018-05-261-2/+2
| | | | | | | | | | | | | | | | | When a scrollbar is on display in APP or TOD windows, the right vertical border (outside the scrollbar) is not highlighted when the window is selected. The scrollbar is always highlighted: - when APP or TOD is deselected - in configuration windows where borders otherwise are not The patch moves the scrollbar parameters (except highlight) from arguments of draw_scrollbar() to the function itself. The highlight argument was 1; instead it is set higher in the call hierarchy (wins_update_panels()) and passed on down. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Rename keys_getch() to keys_get()Lukas Fleischer2017-08-301-3/+3
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Update copyright rangesLukas Fleischer2017-01-121-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Avoid starting the notification thread twiceLukas Fleischer2016-08-241-0/+3
| | | | | | | | | | | | | Starting the notification thread more than once can result in strange behavior. For example, when launching external commands, only the most recently started thread is stopped which results in the external command's screen output being overwritten by the notification bar. Currently, there are a couple of situations where the thread is started twice. As a first countermeasure, explicitly check whether the thread is already running (and terminate it) before starting a new one. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Add proper UTF-8 support to the notification areaLukas Fleischer2016-02-261-30/+17
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Update copyright rangesLukas Fleischer2016-01-301-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Support sending notifications for all appointmentsLukas Fleischer2016-01-271-23/+32
| | | | | | | | | | In 45417bc (Add configuration option to notify all appointments, 2011-07-31), we added an option that allows for choosing whether the user receives notifications only for flagged or only for unflagged appointments. Convert this setting into a three-state option and allow the user to additionally enable notifications for *all* appointments. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Use time_t instead of long in several placesLukas Fleischer2015-02-241-3/+2
| | | | | | | Start converting some variables and return values to store times from long to time_t. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Update copyright rangesLukas Fleischer2015-02-071-1/+1
| | | | Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Initialize prompt buffers in the configuration menusLukas Fleischer2014-07-181-0/+1
| | | | | | | | malloc() does not make sure that the buffer is initialized to contain all zeros. Initialize the buffer with the empty string. Reported-by: HÃ¥kan Jerning <jerning@home.se> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Rework key binding context switchingLukas Fleischer2014-07-171-5/+3
| | | | | | | Store key binding contexts using another data structure to optimize space usage and execution time. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Reintroduce key bindings in configuration menusLukas Fleischer2014-07-171-2/+14
| | | | | | | | | | The key bindings display in the status bar was removed from the general options menu in bd182fb (Use generic list box for general options, 2014-05-13) and from the notification options menu in 5eea05a (Use generic list box for notification options, 2014-05-13). Display the new key bindings to use for navigation. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Add a cleanup handler for the notify main threadLukas Fleischer2014-07-161-0/+13
| | | | | | | Make sure we do not leave behind unusable mutexes when calling pthread_cancel(). Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Add support for caption rows in list boxesLukas Fleischer2014-05-181-1/+8
| | | | | | | This adds support for rows that cannot be selected. Such rows can be used for section headings and the like. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Add support for drawing highlighted decorationLukas Fleischer2014-05-181-2/+2
| | | | | | | This allows for drawing selected scroll windows and list boxes with a highlighted border. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Remove numbers and whitespace from option menusLukas Fleischer2014-05-181-8/+5
| | | | | | | These are no longer needed since items are no longer accessed via numeric keys. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Reduce flicker when resizing in option menusLukas Fleischer2014-05-181-1/+1
| | | | | | | Do not update the main windows when resizing the terminal in the general options menu or in the notification options menu. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Use generic list box for notification optionsLukas Fleischer2014-05-181-106/+107
| | | | | | | | This changes the notification options menu to use the new generic list box implementation. The only user-visible change is that items are now accessed via the arrow and edit key bindings instead of digits. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Rework scroll window implementationLukas Fleischer2014-05-181-15/+6
| | | | | | | | | | This complete rewrite of the scroll window implementation decouples scroll windows from every other window abstraction layer we use. Note that this leads to some code duplication. The long-term purpose of this rewrite, however, is to eventually make every panel use scroll windows. This makes for a huge cleanup of the UI code. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Use tabs instead of spaces for indentationLukas Fleischer2013-04-141-524/+558
| | | | | | | | | | | This completes our switch to the Linux kernel coding style. Note that we still use deeply nested constructs at some places which need to be fixed up later. Converted using the `Lindent` script from the Linux kernel code base, along with some manual fixes. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Fix braces in if-else statementsLukas Fleischer2013-02-171-7/+10
| | | | | | | | | | From the Linux kernel coding guidelines: Do not unnecessarily use braces where a single statement will do. [...] This does not apply if one branch of a conditional statement is a single statement. Use braces in both branches. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Update copyright rangesLukas Fleischer2013-02-041-1/+1
| | | | | | | Add 2013 to the copyright range for all source and documentation files. Reported-by: Frederic Culot <frederic@culot.org> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Add hidden key handler windowLukas Fleischer2012-12-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Release screen mutex if thread diesLukas Fleischer2012-11-231-6/+6
| | | | | | | | | | | | | | | | | We did not setup a thread cleanup procedure which resulted in calcurse freezing if a thread tried to draw on the screen after another thread was canceled while locking the screen. Note that this kind of cleanup handlers should be added to other mutexes as well. This patch just removes the most common case of triggering a deadlock. Also note that we cannot move pthread_cleanup_push() and pthread_cleanup_pop() into the locking/unlocking functions since both pthread_cleanup_push() and pthread_cleanup_pop() may be implemented as macros that must be used in pairs within the same lexical scope. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Lock screen when drawing on the calendar/notification panelLukas Fleischer2012-11-231-0/+6
| | | | | | | | | | | | Lock the screen if either the calendar panel or the notification bar is updated to avoid race conditions. Addresses BUG#6. Note that we currently always use a screen-level lock, even if only one window is affected. This is to be changed in the future. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Replace localtime() with localtime_r()Lukas Fleischer2012-11-221-4/+4
| | | | | | | | | | | | | | Since the result of localtime() is stored in a statically allocated structure, data was overwritten when a context switch occurred during (or shortly after) the execution of localtime(), potentially resulting in critical data corruption. BUG#7 and BUG#8 are likely related. This patch converts all usages of localtime() with localtime_r(), which is thread-safe. Reported-by: Baptiste Jonglez <baptiste@jonglez.org> Reported-by: Erik Saule <esaule@bmi.osu.edu> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Use mvwaddstr() instead of mvwprintw()Baptiste Jonglez2012-05-311-2/+2
| | | | | | | | | | | | | When we only want to display a string at a specific place of the screen, there's no need to use the more complex mvwprintw(), use mvwaddstr() instead. This should be slightly more efficient, and, above all, it prevents weird things to happen if our string contains a '%', being interpreted as an unwanted format string. Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Do not localize configuration optionsLukas Fleischer2012-05-231-8/+8
| | | | | | | | | The configuration options shown in the configuration menu are meant to reflect the keys used in the configuration file. The descriptions displayed alongside each option should be sufficient for non-English speakers. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Merge branch 'maint'Lukas Fleischer2012-05-231-1/+1
|\ | | | | | | | | | | | | Conflicts: src/io.c src/notify.c src/utils.c
| * src/notify.c: Fix printf() misuseLukas Fleischer2012-05-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Make sure we actually copy the notification warning interval to the correct buffer instead of printing it to stdout (using an arbitrary format string). This makes sure the current warning interval is shown when editing the field and also eliminates a potential format string vulnerability. Spotted with "-Wformat-nonliteral". Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Switch to Linux kernel coding styleLukas Fleischer2012-05-211-455/+379
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Convert our code base to adhere to Linux kernel coding style using Lindent, with the following exceptions: * Use spaces, instead of tabs, for indentation. * Use 2-character indentations (instead of 8 characters). Rationale: We currently have too much levels of indentation. Using 8-character tabs would make huge code parts unreadable. These need to be cleaned up before we can switch to 8 characters. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Update configuration dialogsLukas Fleischer2012-05-171-8/+8
| | | | | | | | | | | | | | Rename the configuration options shown in the configuration dialogs to match the new naming scheme used in the configuration file. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Declare several parameters/variables constantLukas Fleischer2012-05-081-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | Add the "const" keyword to parameters and variables that are never modified. Most of these were spotted by "-Wwrite-strings". We cast the second parameter to execvp() explicitly as it expects a "char *const[]" where it should expect a "const char *const[]" (according to the documentation, this is due to compatibility reasons). This should be changed once we come up with a better solution. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Mark localized string literals constantLukas Fleischer2012-04-051-6/+6
| | | | | | | | | | | | | | Translated strings returned by gettext() are statically allocated and shouldn't be modified. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Update copyright rangesLukas Fleischer2012-03-261-1/+1
| | | | | | | | | | | | Add 2012 to the copyright range for all source and documentation files. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Do not strncpy() strings returned by gettext()Lukas Fleischer2012-03-121-1/+1
| | | | | | | | | | | | | | | | Translated strings returned by gettext() are statically allocated. There's no need to copy them to a buffer, we can use the pointers returned by gettext() instead. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Merge branch 'maint'Lukas Fleischer2011-11-111-1/+4
|\| | | | | | | | | | | Conflicts: src/calcurse.h src/io.c
| * Cleanup joinable threads on terminationLukas Fleischer2011-10-041-1/+4
| | | | | | | | | | | | | | Always invoke pthread_join() when we blow up a thread via pthread_cancel() (avoid zombie threads). Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Remove parentheses from return statementsLukas Fleischer2011-11-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | No reason to use "return (x);" here. Refer to the GNU coding guidelines for details. Created using following semantic patch: @@ expression expr; @@ - return (expr); + return expr; Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Make use of the NULL macroLukas Fleischer2011-11-021-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use this constant everywhere when referring to a null pointer instead of casting 0 to various types of pointers. Created using following semantic patch: @@ type type; @@ - (type *)0 + NULL Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Do not cast unused return values to voidLukas Fleischer2011-11-021-22/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A small style fix that removes all remaining "(void)" casts. Using these isn't encouraged in GNU coding guidelines and doesn't serve a certain purpose, except for satisfying a few static code analysis tools. We already nuked some of these in previous patches, but this semantic patch should fix what's left: @@ identifier func; @@ - (void)func ( + func ( ...); Long lines were re-formatted manually. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Avoid use of printf()/fprintf()Lukas Fleischer2011-11-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use one of the following functions where appropriate: * puts() (whenever we print hard coded strings to stdout) * fputs() (whenever we print hard coded strings to a stream) * putchar() (whenever we print a single character to stdout) * fputc() (whenever we print a single character to a stream) * strncpy() (whenever we copy hard coded strings to a buffer) This removes the overhead introduced by the format string parser and reduces the number of false positive C-format strings spotted by xgettext(1)'s heuristics. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Avoid unnecessary start time calculationsLukas Fleischer2011-10-211-7/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Rename recur_*_inday() to recur_*_find_occurrence() and use the new functions whenever we actually care about the start time of an occurrence. Reintroduce recur_*_inday() as wrappers to recur_*_find_occurrence() and pass NULL as start time buffer (which means "skip start time calculation"). Keep using these when we only want to know if a recurrent item belongs to a specific day but do not care about the actual start time. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Pass item durations to recur_item_inday()Lukas Fleischer2011-10-211-4/+4
| | | | | | | | | | | | | | | | Having item's durations eventually allows for better parsing of recurrent appointments as we might be interested in how many days are covered by a multi-day appointment. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>