dmedvinsky / gsimplecal

Simple and lightweight GTK calendar (BSD license)
http://dmedvinsky.github.io/gsimplecal
Other
198 stars 19 forks source link

dynamic time #31

Closed elerocks closed 3 years ago

elerocks commented 6 years ago

Hello, I use following time format: clock_format = %H:%M:%S

And I correctly see the time, however it is not changing (it is kind of frozen to the time when I opened the calendar). Is it possible to make it dynamic?

(use case: I use gsimplecal in tint, triggered by click on clock. I sometimes want to use it as stopwatch and I'm missing the seconds :))

By the way, great software

marciniuk commented 5 years ago

Yes, I have a problem with that too ;/

dtwooton commented 3 years ago

This is rather late for a reply. I just found gsimplecal. I too want these things.

Here is the way I fixed the need for seconds

*** gsimplecal/src/gsimplecal.cpp.orig  Mon Feb  8 13:36:22 2021
--- gsimplecal/src/gsimplecal.cpp       Mon Feb  8 13:37:07 2021
***************
*** 110,116 ****
                       GCallback(destroy), NULL);

      if (config->show_timezones) {
!         g_timeout_add(30000, (GSourceFunc)time_handler, NULL);
      }
      if (config->close_on_unfocus) {
          g_signal_connect(main_window->getWindow(), "focus-out-event",
--- 110,116 ----
                       GCallback(destroy), NULL);

      if (config->show_timezones) {
!         g_timeout_add(1000, (GSourceFunc)time_handler, NULL);
      }
      if (config->close_on_unfocus) {
          g_signal_connect(main_window->getWindow(), "focus-out-event",

Here is the way I fixed the frozer-in-time


*** gsimplecal/src/Calendar.cpp.orig    Tue Feb  9 19:41:51 2021
--- gsimplecal/src/Calendar.cpp Wed Feb 10 09:40:16 2021
***************
*** 145,157 ****

  bool Calendar::markToday()
  {
      guint year, month;
      gtk_calendar_get_date((GtkCalendar*)widget, &year, &month, NULL);
      if (year == today_year && month == today_month) {
          gtk_calendar_mark_day((GtkCalendar*)widget, today_day);
          return true;
      } else {
-         gtk_calendar_unmark_day((GtkCalendar*)widget, today_day);
          return false;
      }
  }
--- 145,166 ----

  bool Calendar::markToday()
  {
+     struct timeval clock_time;
+     gettimeofday(&clock_time, 0);
+     struct tm tm;
+     localtime_r(&clock_time.tv_sec, &tm);
+     today_year = tm.tm_year + 1900;
+     today_month = tm.tm_mon;
+     today_day = tm.tm_mday;
+ 
+     gtk_calendar_clear_marks((GtkCalendar*)widget);
+ 
      guint year, month;
      gtk_calendar_get_date((GtkCalendar*)widget, &year, &month, NULL);
      if (year == today_year && month == today_month) {
          gtk_calendar_mark_day((GtkCalendar*)widget, today_day);
          return true;
      } else {
          return false;
      }
  }
*** gsimplecal/src/MainWindow.cpp.orig  Wed Feb 10 15:04:51 2021
--- gsimplecal/src/MainWindow.cpp       Wed Feb 10 15:07:49 2021
***************
*** 183,188 ****
--- 183,193 ----
      if (timezones) {
          timezones->updateTime();
      }
+ 
+     Config* config = Config::getInstance();
+     if (config->mark_today) {
+       calendar->markToday();
+     }
  }

  void MainWindow::close()
dmedvinsky commented 3 years ago

I've reduced the clock refresh delay if the seconds are rendered. Now it updates each second instead of each minute.

That fixes the OP's problem. Took me just a couple of years. 😖

I decided not to update "today" mark. I don't think that's an issue given the nature of the app (designed to be quick-peek-then-kill).

Still, huge props to @dtwooton for raising this issue and forcing me to actually do it.