aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui-calendar.c
Commit message (Collapse)AuthorAgeFilesLines
* Solve deadlock in notification barLars Henriksen2018-07-281-5/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Scrollbar and right window border (corrected)Lars Henriksen2018-05-261-1/+1
| | | | | | | | | | | | | | | | | 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>
* Fix no-colour themeLars Henriksen2017-12-101-9/+4
| | | | | | | | | | | | | In colour customization, pressing cancel ('ESC' by default) will deselect all colours and put calcurse in no-color mode. For this to work, all colour changes must be performed with the routines custom_apply_attr()/custom_remove_attr(). Fixed for the getstring cursor, the scroll window border and the week number. In addition, the week number is unconditionally coloured as the rest of the calendar contents whether CAL is selected or not. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Check for the year span 1902-2037Lars Henriksen2017-11-231-6/+18
| | | | | | | | | | | | | Reintroduce year check for systems with a 32-bit time_t type. Remove the lower limit (1902) for systems with a 64-bit time_t. This limits movements in the calendar (for 32-bit systems) and in no way ensures constistency of data. Commit a12833e (Handle dates past January 19th, 2038, 2015-01-19) removed the upper limit (2037) on dates but left the lower limit (1902). It did not ensure the support of the target system. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Do not tie ISO 8601 week numbering to MondayLars Henriksen2017-10-171-7/+12
| | | | | | | | | | | | | | | | | | | | | | | | The week number in the calendar panel is calculated according to ISO 8601. Hence, Monday is the first day of the week and the week number changes from Sunday to Monday. However, calcurse ties the week number not to Monday, but to the first day of the week as configured for display. Thus, when Sunday is shown as first day of the week, the week number is correct for Sunday, but wrong for the rest of the week (one behind). With this patch the week number always follows the mon-sun week as required by ISO 8601. A side effect is that when Sunday is displayed as first day of the week, and Sunday is the selected day, the week number displayed is invalid for the rest of the week (but changes to the correct one when the selected day moves forward). This raises the question whether the week numbering scheme should follow the "first day of the week" choice and use the American week numbering scheme instead of ISO 8601 when Sunday is the first day of the week. But that is for the future. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Remove phase of moon featureLars Henriksen2017-09-081-181/+0
| | | | | | | | | | The computation never really worked before and it seems like the feature is not very helpful, sometimes even confusing (see GitHub issue #21). The macro ISLEAP is moved to calcurse.h. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Fix phase of moon calculationLars Henriksen2017-09-081-27/+30
| | | | | | | | | | | | The reported phase was often one day early because calculations were based on midnight. For full and new moon this is changed to noon. For first and last quarter a direct check of the appearance of the half moon during the selected day is performed. Comments are relocated and expanded. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Add a function to wait for any key pressLukas Fleischer2017-09-031-1/+1
| | | | | | | Introduce a new function keys_wait_for_any_key() and use it instead of wgetch() whenever the return value is discarded. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Use nl_langinfo() for month and day namesLars Henriksen2017-08-281-5/+7
| | | | | | | | Use the locale setting to fetch the month names and abbreviated day names. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Make the selected day in the calendar stand outLars Henriksen2017-08-281-2/+2
| | | | | Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Update copyright rangesLukas Fleischer2017-01-121-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Remove duplicate code in draw_monthly_view()Lukas Fleischer2016-06-271-35/+22
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Highlight days with non-recurrent itemsLukas Fleischer2016-06-271-2/+10
| | | | | | | | Use a different color for days with non-recurrent items in the calendar panel. This makes it possible to easily spot days that actually contain appointments. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Support durations in recurrence ending datesLukas Fleischer2016-02-261-20/+0
| | | | | | | When spending the end date of recurring items, allow date duration specifiers such as "+5d" or "+3w2d". Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Update copyright rangesLukas Fleischer2016-01-301-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Highlight week number when the calendar is selectedLukas Fleischer2015-04-101-0/+4
| | | | Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Show week numbers in the monthly viewLukas Fleischer2015-04-101-0/+4
| | | | | Suggested-by: HÃ¥kan Jerning <jerning@home.se> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Split out code for drawing week numbersLukas Fleischer2015-04-101-97/+106
| | | | | | | This allows for easily adding week numbers to other panel modes, such as the monthly view. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Use time_t instead of long in several placesLukas Fleischer2015-02-241-1/+1
| | | | | | | Start converting some variables and return values to store times from long to time_t. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Redraw calendar panel when switching viewsLukas Fleischer2015-02-231-0/+6
| | | | Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Update copyright rangesLukas Fleischer2015-02-071-1/+1
| | | | Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Handle dates past January 19th, 2038Lukas Fleischer2015-02-071-7/+1
| | | | | | Try to support dates past year 2038 on systems with 64-bit time_t. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Only werase() calendar if month is changedLukas Fleischer2014-10-171-8/+6
| | | | | | | Optimize the monthly view by only erasing the window content when a new month is selected. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Replace several uses of snprintf() by asprintf()Lukas Fleischer2014-07-221-3/+3
| | | | | | | | Use asprintf() in some cold code paths. While allocating memory on the heap is a bit slower, using asprintf() is a bit more memory efficient and less prone to buffer overflow errors. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Fix calendar centeringLukas Fleischer2014-05-191-11/+9
| | | | | | | Adjust the positions of the weekly and monthly views inside the calendar panel. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* ui-calendar: Use scroll window implementationLukas Fleischer2014-05-181-53/+50
| | | | | | | | | Make use of the generic scroll window implementation for the calendar view. Note that this is useful despite the panel not needing a scroll bar, since the scroll window functions can be used to draw the panel border and take care of relative positions. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Use tabs instead of spaces for indentationLukas Fleischer2013-04-141-573/+609
| | | | | | | | | | | 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-6/+5
| | | | | | | | | | 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>
* calendar.c: Rename to "ui-calendar.c"Lukas Fleischer2013-02-141-0/+915
This unit belongs to the presentation layer -- rename the file accordingly. Also, rename calendar_*() to ui_calendar_*(). Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>