diff options
author | Alexander Mikhaylenko <alexm@gnome.org> | 2020-04-03 07:08:38 +0500 |
---|---|---|
committer | Alexander Mikhaylenko <alexm@gnome.org> | 2020-04-03 09:53:36 +0500 |
commit | 2d722025687710d3c8f132541c49cba67708b9aa (patch) | |
tree | f285b6bff10334f6f9f815db3f2e6f04971dce71 /src | |
parent | dd7de24074399c1085c58ec99e6a96972f44ecf7 (diff) | |
download | gnome-screenshot-2d722025687710d3c8f132541c49cba67708b9aa.tar.gz |
interactive-dialog: Replace callback with a signal
This allows to make the dialog a completely normal widget.
Diffstat (limited to 'src')
-rw-r--r-- | src/screenshot-application.c | 16 | ||||
-rw-r--r-- | src/screenshot-interactive-dialog.c | 52 | ||||
-rw-r--r-- | src/screenshot-interactive-dialog.h | 4 |
3 files changed, 42 insertions, 30 deletions
diff --git a/src/screenshot-application.c b/src/screenshot-application.c index ef520f5..c5a18bc 100644 --- a/src/screenshot-application.c +++ b/src/screenshot-application.c @@ -682,9 +682,23 @@ screenshot_application_command_line (GApplication *app, } static void +capture_clicked_cb (ScreenshotInteractiveDialog *dialog, + ScreenshotApplication *self) +{ + gtk_widget_destroy (GTK_WIDGET (dialog)); + screenshot_start (self); +} + +static void screenshot_show_interactive_dialog (ScreenshotApplication *self) { - screenshot_interactive_dialog_new ((CaptureClickedCallback) screenshot_start, self); + GtkWidget *dialog; + + dialog = screenshot_interactive_dialog_new (GTK_APPLICATION (self)); + + g_signal_connect_object (dialog, "capture", G_CALLBACK (capture_clicked_cb), self, 0); + + gtk_widget_show (GTK_WIDGET (dialog)); } static void diff --git a/src/screenshot-interactive-dialog.c b/src/screenshot-interactive-dialog.c index f2753ad..4e0a9d7 100644 --- a/src/screenshot-interactive-dialog.c +++ b/src/screenshot-interactive-dialog.c @@ -50,13 +50,17 @@ struct _ScreenshotInteractiveDialog GtkWidget *screen; GtkWidget *window; GtkWidget *selection; - - CaptureClickedCallback callback; - gpointer user_data; }; G_DEFINE_TYPE (ScreenshotInteractiveDialog, screenshot_interactive_dialog, GTK_TYPE_APPLICATION_WINDOW) +enum { + SIGNAL_CAPTURE, + N_SIGNALS, +}; + +static guint signals[N_SIGNALS]; + static void set_mode (ScreenshotInteractiveDialog *self, ScreenshotMode mode) @@ -113,11 +117,7 @@ static void capture_button_clicked_cb (GtkButton *button, ScreenshotInteractiveDialog *self) { - CaptureClickedCallback callback = self->callback; - gpointer user_data = self->user_data; - - gtk_widget_destroy (GTK_WIDGET (self)); - callback (user_data); + g_signal_emit (self, signals[SIGNAL_CAPTURE], 0); } static void @@ -147,6 +147,15 @@ screenshot_interactive_dialog_class_init (ScreenshotInteractiveDialogClass *klas { GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + signals[SIGNAL_CAPTURE] = + g_signal_new ("capture", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, NULL, + G_TYPE_NONE, + 0); + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Screenshot/ui/screenshot-interactive-dialog.ui"); gtk_widget_class_bind_template_child (widget_class, ScreenshotInteractiveDialog, capture_button); @@ -175,23 +184,6 @@ screenshot_interactive_dialog_init (ScreenshotInteractiveDialog *self) (GtkListBoxUpdateHeaderFunc) header_func, self, NULL); -} - -GtkWidget * -screenshot_interactive_dialog_new (CaptureClickedCallback f, - gpointer user_data) -{ - ScreenshotApplication *app = user_data; - ScreenshotInteractiveDialog *self; - - self = g_object_new (SCREENSHOT_TYPE_INTERACTIVE_DIALOG, - "application", app, - NULL); - - self->callback = f; - self->user_data = user_data; - - gtk_widget_show_all (GTK_WIDGET (self)); if (screenshot_config->take_window_shot) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->window), TRUE); @@ -203,6 +195,14 @@ screenshot_interactive_dialog_new (CaptureClickedCallback f, gtk_switch_set_active (GTK_SWITCH (self->pointer), screenshot_config->include_pointer); gtk_adjustment_set_value (self->delay_adjustment, (gdouble) screenshot_config->delay); +} - return GTK_WIDGET (self); +GtkWidget * +screenshot_interactive_dialog_new (GtkApplication *app) +{ + g_return_val_if_fail (GTK_IS_APPLICATION (app), NULL); + + return g_object_new (SCREENSHOT_TYPE_INTERACTIVE_DIALOG, + "application", app, + NULL); } diff --git a/src/screenshot-interactive-dialog.h b/src/screenshot-interactive-dialog.h index 022b662..e73842c 100644 --- a/src/screenshot-interactive-dialog.h +++ b/src/screenshot-interactive-dialog.h @@ -30,8 +30,6 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (ScreenshotInteractiveDialog, screenshot_interactive_dialog, SCREENSHOT, INTERACTIVE_DIALOG, GtkApplicationWindow) -typedef void (*CaptureClickedCallback) (gpointer *user_data); - -GtkWidget *screenshot_interactive_dialog_new (CaptureClickedCallback f, gpointer user_data); +GtkWidget *screenshot_interactive_dialog_new (GtkApplication *app); G_END_DECLS |