Skip to content

Commit

Permalink
fix: reset today button on 24 hour boundary
Browse files Browse the repository at this point in the history
Fix a bug where the 'today' button in the MessageTray did not update
when a new day occurred.

Signed-off-by: ldelossa <[email protected]>
  • Loading branch information
ldelossa committed Jun 28, 2024
1 parent 1f174de commit a1ad826
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
27 changes: 14 additions & 13 deletions src/panel/message_tray/calendar/calendar.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct _Calendar {
GtkBox *container;
GtkCalendar *calendar;
GtkButton *today;
AdwActionRow *today_row;
struct {
GtkCenterBox *container;
GtkButton *back;
Expand Down Expand Up @@ -75,14 +76,14 @@ static void calendar_handle_clock_tick(ClockService *cs, GDateTime *now,

gtk_label_set_text(self->month_selector.date,
g_date_time_format(now, "%B %Y"));

// update the action row title
adw_preferences_row_set_title(ADW_PREFERENCES_ROW(self->today),
adw_preferences_row_set_title(ADW_PREFERENCES_ROW(self->today_row),
g_date_time_format(now, "%A"));
// update the action row subtitle
adw_action_row_set_subtitle(ADW_ACTION_ROW(self->today),
adw_action_row_set_subtitle(ADW_ACTION_ROW(self->today_row),
g_date_time_format(now, "%B %d %Y"));


// make a copy of GDateTime
self->now = g_date_time_add(now, 0);
calendar_set_dirty(self);
Expand Down Expand Up @@ -157,11 +158,12 @@ static void calendar_init_today_button(Calendar *self) {
gtk_widget_set_name(GTK_WIDGET(self->today), "calendar-today");
gtk_widget_set_hexpand(GTK_WIDGET(self->today), true);

AdwActionRow *row = ADW_ACTION_ROW(adw_action_row_new());
adw_preferences_row_set_title(ADW_PREFERENCES_ROW(row),
g_date_time_format(self->now, "%A"));
adw_action_row_set_subtitle(row, g_date_time_format(self->now, "%B %d %Y"));
gtk_button_set_child(self->today, GTK_WIDGET(row));
self->today_row = ADW_ACTION_ROW(adw_action_row_new());

GDateTime *now = g_date_time_new_now_local();
calendar_handle_clock_tick(clock_service_get_global(), now, self);

gtk_button_set_child(self->today, GTK_WIDGET(self->today_row));

// wire up button to click
g_signal_connect(self->today, "clicked",
Expand All @@ -177,7 +179,7 @@ static void on_day_selected(GtkCalendar *calendar, Calendar *self) {

static void calendar_init_calendar(Calendar *self) {
self->calendar = GTK_CALENDAR(gtk_calendar_new());
gtk_widget_set_size_request(GTK_WIDGET(self->calendar), -1, 224);
gtk_widget_set_size_request(GTK_WIDGET(self->calendar), -1, 224);
gtk_calendar_set_show_heading(self->calendar, false);
gtk_calendar_set_show_week_numbers(self->calendar, false);
gtk_widget_set_hexpand(GTK_WIDGET(self->calendar), true);
Expand All @@ -188,20 +190,19 @@ static void calendar_init_calendar(Calendar *self) {
}

static void calendar_init(Calendar *self) {
self->now = g_date_time_new_now_local();
self->dirty = FALSE;
self->container = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 0));
gtk_widget_add_css_class(GTK_WIDGET(self->container), "calendar-area");

// today button
calendar_init_today_button(self);

// month selector
calendar_init_month_selector(self);

// calendar widget
calendar_init_calendar(self);

// today button
calendar_init_today_button(self);

// lay it out.
gtk_box_append(self->container, GTK_WIDGET(self->today));
gtk_box_append(self->container, GTK_WIDGET(self->month_selector.container));
Expand Down
41 changes: 28 additions & 13 deletions src/services/wayland_service/wayland_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,22 @@ static void toplevel_handle_closed(
"toplevel->title: %s",
toplevel->app_id, toplevel->title);

// allow remove handlers to run before we free the ref.
// check ignored sets and if not ignored emit signal
if (!g_hash_table_contains(self->ignored_toplevel_app_ids,
toplevel->app_id) &&
!g_hash_table_contains(self->ignored_toplevel_titles,
toplevel->title)) {
// a toplevel without a valid app_id and title was never advertised to the
// rest of Way-Shell, so no reason to signal its removal.
if (!toplevel->app_id || !toplevel->title) goto remove;

gboolean ignored = false;
ignored =
g_hash_table_contains(self->ignored_toplevel_app_ids, toplevel->app_id);

if (!ignored)
ignored = g_hash_table_contains(self->ignored_toplevel_titles,
toplevel->title);

if (!ignored)
g_signal_emit(self, service_signals[top_level_removed], 0, toplevel);
}

remove:
// remove it from our inventory
g_hash_table_remove(self->toplevels, handle);

Expand Down Expand Up @@ -264,15 +271,23 @@ static void toplevel_handle_done(
toplevel->app_id, toplevel->title, toplevel->entered,
toplevel->activated);

// check ignored sets and if not ignored emit signal
if (!g_hash_table_contains(self->ignored_toplevel_app_ids,
toplevel->app_id) &&
!g_hash_table_contains(self->ignored_toplevel_titles,
toplevel->title)) {
// if we don't have a valid app_id and title, don't bother signaling this
// toplevel, the rest of Way-Shell expects these fields.
if (!toplevel->app_id || !toplevel->title) goto reset;

gboolean ignored = false;
ignored =
g_hash_table_contains(self->ignored_toplevel_app_ids, toplevel->app_id);

if (!ignored)
ignored = g_hash_table_contains(self->ignored_toplevel_titles,
toplevel->title);

if (!ignored)
g_signal_emit(self, service_signals[top_level_changed], 0,
self->toplevels, toplevel);
}

reset:
// reset bools after handlers read event
toplevel->entered = FALSE;
toplevel->activated = FALSE;
Expand Down

0 comments on commit a1ad826

Please sign in to comment.