diff --git a/src/gui/gcal-window.blp b/src/gui/gcal-window.blp index 1acacbffe31fcac8ef2cef6f1b36d19f2c1b3c21..5f4d94f8024c642e98322983e730e99fd8ad0708 100644 --- a/src/gui/gcal-window.blp +++ b/src/gui/gcal-window.blp @@ -105,6 +105,16 @@ template $GcalWindow: Adw.ApplicationWindow { } } + GestureClick { + button: 8; // Hardware back button. + pressed => $on_back_button_pressed_cb(template) not-swapped; + } + + GestureClick { + button: 9; // Hardware forward button. + pressed => $on_forward_button_pressed_cb(template) not-swapped; + } + Adw.ToastOverlay overlay { $GcalDropOverlay drop_overlay { overlayed: Adw.StatusPage drop_status_page { diff --git a/src/gui/gcal-window.c b/src/gui/gcal-window.c index 39c60698ba4d6b2eb5e810de047013c25b876a6f..016b289944d8d2dbce208f6814afc55a7e8af877 100644 --- a/src/gui/gcal-window.c +++ b/src/gui/gcal-window.c @@ -488,6 +488,30 @@ filter_ics_files (GcalWindow *self, g_task_run_in_thread (task, filter_ics_files_thread); } +static void +switch_next_view (GcalWindow *self) +{ + g_autoptr (GDateTime) next_date = NULL; + GcalView *current_view; + + current_view = GCAL_VIEW (self->views[self->active_view]); + next_date = gcal_view_get_next_date (current_view); + + update_active_date (self, next_date); +} + +static void +switch_prev_view (GcalWindow *self) +{ + g_autoptr (GDateTime) previous_date = NULL; + GcalView *current_view; + + current_view = GCAL_VIEW (self->views[self->active_view]); + previous_date = gcal_view_get_previous_date (current_view); + + update_active_date (self, previous_date); +} + /* * Callbacks */ @@ -534,20 +558,33 @@ on_view_action_activated (GSimpleAction *action, GCAL_EXIT; } +static void +on_back_button_pressed_cb (GtkGestureClick *gesture_click, + gint n_press, + gdouble x, + gdouble y, + gpointer *user_data) +{ + switch_prev_view (GCAL_WINDOW (user_data)); +} + +static void +on_forward_button_pressed_cb (GtkGestureClick *gesture_click, + gint n_press, + gdouble x, + gdouble y, + gpointer *user_data) +{ + + switch_next_view (GCAL_WINDOW (user_data)); +} + static void on_window_next_date_activated_cb (GSimpleAction *action, GVariant *param, gpointer user_data) { - g_autoptr (GDateTime) next_date = NULL; - GcalWindow *self; - GcalView *current_view; - - self = GCAL_WINDOW (user_data); - current_view = GCAL_VIEW (self->views[self->active_view]); - next_date = gcal_view_get_next_date (current_view); - - update_active_date (self, next_date); + switch_next_view (GCAL_WINDOW (user_data)); } static void @@ -604,15 +641,7 @@ on_window_previous_date_activated_cb (GSimpleAction *action, GVariant *param, gpointer user_data) { - g_autoptr (GDateTime) previous_date = NULL; - GcalWindow *self; - GcalView *current_view; - - self = GCAL_WINDOW (user_data); - current_view = GCAL_VIEW (self->views[self->active_view]); - previous_date = gcal_view_get_previous_date (current_view); - - update_active_date (self, previous_date); + switch_prev_view (GCAL_WINDOW (user_data)); } static void @@ -1405,6 +1434,10 @@ gcal_window_class_init (GcalWindowClass *klass) /* Drop Target related */ gtk_widget_class_bind_template_callback (widget_class, on_drop_target_accept_cb); gtk_widget_class_bind_template_callback (widget_class, on_drop_target_drop_cb); + + /* Change date related*/ + gtk_widget_class_bind_template_callback (widget_class, on_back_button_pressed_cb); + gtk_widget_class_bind_template_callback (widget_class, on_forward_button_pressed_cb); } static void