diff --git a/src/celluloid-controller-input.c b/src/celluloid-controller-input.c index 3be0a3d8..9adeb8bf 100644 --- a/src/celluloid-controller-input.c +++ b/src/celluloid-controller-input.c @@ -345,8 +345,8 @@ celluloid_controller_input_connect_signals(CelluloidController *controller) G_CALLBACK(key_released_handler), controller ); - GtkGesture *click_gesture = - gtk_gesture_click_new(); + GtkGesture *const click_gesture = + controller->click_gesture; gtk_gesture_single_set_button (GTK_GESTURE_SINGLE(click_gesture), 0); gtk_widget_add_controller @@ -365,8 +365,8 @@ celluloid_controller_input_connect_signals(CelluloidController *controller) G_CALLBACK(button_stopped_handler), controller ); - GtkEventController *motion_controller = - gtk_event_controller_motion_new(); + GtkEventController *const motion_controller = + controller->motion_controller; gtk_widget_add_controller (GTK_WIDGET(video_area), GTK_EVENT_CONTROLLER(motion_controller)); @@ -375,9 +375,8 @@ celluloid_controller_input_connect_signals(CelluloidController *controller) G_CALLBACK(mouse_move_handler), controller ); - GtkEventController *scroll_controller = - gtk_event_controller_scroll_new - (GTK_EVENT_CONTROLLER_SCROLL_BOTH_AXES | GTK_EVENT_CONTROLLER_SCROLL_DISCRETE); + GtkEventController *const scroll_controller = + controller->scroll_controller; gtk_widget_add_controller (GTK_WIDGET(video_area), GTK_EVENT_CONTROLLER(scroll_controller)); @@ -386,3 +385,19 @@ celluloid_controller_input_connect_signals(CelluloidController *controller) G_CALLBACK(scroll_handler), controller ); } + +void +celluloid_controller_input_disconnect_signals(CelluloidController *controller) +{ + CelluloidMainWindow *wnd = + celluloid_view_get_main_window(controller->view); + GtkWidget *video_area = + GTK_WIDGET(celluloid_main_window_get_video_area(wnd)); + + gtk_widget_remove_controller + (video_area, controller->motion_controller); + gtk_widget_remove_controller + (video_area, controller->scroll_controller); + gtk_widget_remove_controller + (video_area, GTK_EVENT_CONTROLLER(controller->click_gesture)); +} diff --git a/src/celluloid-controller-input.h b/src/celluloid-controller-input.h index d4adc220..c64b3d00 100644 --- a/src/celluloid-controller-input.h +++ b/src/celluloid-controller-input.h @@ -29,6 +29,9 @@ G_BEGIN_DECLS void celluloid_controller_input_connect_signals(CelluloidController *controller); +void +celluloid_controller_input_disconnect_signals(CelluloidController *controller); + G_END_DECLS #endif diff --git a/src/celluloid-controller-private.h b/src/celluloid-controller-private.h index 6eab968b..14f96a1e 100644 --- a/src/celluloid-controller-private.h +++ b/src/celluloid-controller-private.h @@ -42,6 +42,9 @@ struct _CelluloidController GObject parent; GtkEventController *key_controller; + GtkEventController *motion_controller; + GtkEventController *scroll_controller; + GtkGesture *click_gesture; CelluloidApplication *app; CelluloidModel *model; diff --git a/src/celluloid-controller.c b/src/celluloid-controller.c index 1aac02b5..33582674 100644 --- a/src/celluloid-controller.c +++ b/src/celluloid-controller.c @@ -375,6 +375,12 @@ dispose(GObject *object) if(controller->view) { + gtk_widget_remove_controller + ( GTK_WIDGET(controller->view), + controller->key_controller ); + + celluloid_controller_input_disconnect_signals(controller); + celluloid_view_make_gl_context_current(controller->view); g_clear_object(&controller->model); @@ -1395,7 +1401,18 @@ celluloid_controller_class_init(CelluloidControllerClass *klass) static void celluloid_controller_init(CelluloidController *controller) { - controller->key_controller = gtk_event_controller_key_new(); + const GtkEventControllerScrollFlags scroll_flags = + GTK_EVENT_CONTROLLER_SCROLL_BOTH_AXES | + GTK_EVENT_CONTROLLER_SCROLL_DISCRETE; + + controller->key_controller = + gtk_event_controller_key_new(); + controller->motion_controller = + gtk_event_controller_motion_new(); + controller->scroll_controller = + gtk_event_controller_scroll_new(scroll_flags); + controller->click_gesture = + gtk_gesture_click_new(); gtk_event_controller_set_propagation_phase (controller->key_controller, GTK_PHASE_CAPTURE);