[gnome-photos] Handle asynchronous activation of PhotosTool instances
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] Handle asynchronous activation of PhotosTool instances
- Date: Thu, 11 Feb 2016 10:10:28 +0000 (UTC)
commit 91b146bdf0b8228ecdf245b21e08de4f74f20e9a
Author: Debarshi Ray <debarshir gnome org>
Date: Thu Feb 11 10:57:58 2016 +0100
Handle asynchronous activation of PhotosTool instances
Some tools can be activated asynchronously. eg., PhotosToolCrop. We can
not queue a draw until the entire activation step has finished.
Otherwise, we will be asking the tool to draw while it is in an
incoherent state. Therefore, add a new signal to let PhotosTool
sub-classes indicate that they have finished activating.
src/photos-preview-view.c | 33 +++++++++++++++++++++++++++------
src/photos-tool-colors.c | 2 ++
src/photos-tool-crop.c | 11 ++++++++---
src/photos-tool-enhance.c | 4 +++-
src/photos-tool-filters.c | 5 ++++-
src/photos-tool.c | 13 ++++++++++++-
src/photos-tool.h | 3 ++-
7 files changed, 58 insertions(+), 13 deletions(-)
---
diff --git a/src/photos-preview-view.c b/src/photos-preview-view.c
index eba3fa5..fc2faba 100644
--- a/src/photos-preview-view.c
+++ b/src/photos-preview-view.c
@@ -430,6 +430,24 @@ photos_preview_view_sharpen (PhotosPreviewView *self, GVariant *parameter)
static void
+photos_preview_view_tool_activated (PhotosTool *tool, gpointer user_data)
+{
+ PhotosPreviewView *self = PHOTOS_PREVIEW_VIEW (user_data);
+ GtkWidget *view_container;
+ GtkWidget *view;
+
+ g_return_if_fail (self->current_tool == NULL);
+
+ self->current_tool = tool;
+ g_object_add_weak_pointer (G_OBJECT (self->current_tool), (gpointer *) &self->current_tool);
+
+ view_container = gtk_stack_get_visible_child (GTK_STACK (self->stack));
+ view = photos_preview_view_get_view_from_view_container (view_container);
+ gtk_widget_queue_draw (view);
+}
+
+
+static void
photos_preview_view_tool_changed (PhotosPreviewView *self, PhotosTool *tool)
{
GtkWidget *view_container;
@@ -442,24 +460,27 @@ photos_preview_view_tool_changed (PhotosPreviewView *self, PhotosTool *tool)
{
photos_tool_deactivate (self->current_tool);
g_object_remove_weak_pointer (G_OBJECT (self->current_tool), (gpointer *) &self->current_tool);
+ g_signal_handlers_disconnect_by_func (self->current_tool, photos_preview_view_tool_activated, self);
self->current_tool = NULL;
}
view_container = gtk_stack_get_visible_child (GTK_STACK (self->stack));
view = photos_preview_view_get_view_from_view_container (view_container);
- if (tool != NULL)
+ if (tool == NULL)
+ {
+ self->current_tool = NULL;
+ gtk_widget_queue_draw (view);
+ }
+ else
{
PhotosBaseItem *item;
- self->current_tool = tool;
- g_object_add_weak_pointer (G_OBJECT (self->current_tool), (gpointer *) &self->current_tool);
+ g_signal_connect_object (tool, "activated", G_CALLBACK (photos_preview_view_tool_activated), self, 0);
item = PHOTOS_BASE_ITEM (photos_base_manager_get_active_object (self->item_mngr));
- photos_tool_activate (self->current_tool, item, GEGL_GTK_VIEW (view));
+ photos_tool_activate (tool, item, GEGL_GTK_VIEW (view));
}
-
- gtk_widget_queue_draw (view);
}
diff --git a/src/photos-tool-colors.c b/src/photos-tool-colors.c
index e4b11b2..98e9062 100644
--- a/src/photos-tool-colors.c
+++ b/src/photos-tool-colors.c
@@ -188,6 +188,8 @@ photos_tool_colors_activate (PhotosTool *tool, PhotosBaseItem *item, GeglGtkView
photos_tool_colors_brightness_contrast_value_changed,
self);
g_signal_handlers_unblock_by_func (self->saturation_scale, photos_tool_colors_saturation_value_changed,
self);
+
+ g_signal_emit_by_name (self, "activated");
}
diff --git a/src/photos-tool-crop.c b/src/photos-tool-crop.c
index 7bd2a72..f62e877 100644
--- a/src/photos-tool-crop.c
+++ b/src/photos-tool-crop.c
@@ -912,6 +912,10 @@ photos_tool_crop_process (GObject *source_object, GAsyncResult *res, gpointer us
self,
G_CONNECT_SWAPPED);
+ self->activated = TRUE;
+ self->reset = FALSE;
+ g_signal_emit_by_name (self, "activated");
+
out:
gtk_widget_queue_draw (self->view);
g_object_unref (self);
@@ -983,10 +987,11 @@ photos_tool_crop_activate (PhotosTool *tool, PhotosBaseItem *item, GeglGtkView *
G_CALLBACK (photos_tool_crop_size_allocate),
self,
G_CONNECT_SWAPPED);
- }
- self->activated = TRUE;
- self->reset = FALSE;
+ self->activated = TRUE;
+ self->reset = FALSE;
+ g_signal_emit_by_name (self, "activated");
+ }
}
diff --git a/src/photos-tool-enhance.c b/src/photos-tool-enhance.c
index 2b18372..c2e8e06 100644
--- a/src/photos-tool-enhance.c
+++ b/src/photos-tool-enhance.c
@@ -1,6 +1,6 @@
/*
* Photos - access, organize and share your photos on GNOME
- * Copyright © 2015 Red Hat, Inc.
+ * Copyright © 2015, 2016 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -144,6 +144,8 @@ photos_tool_enhance_activate (PhotosTool *tool, PhotosBaseItem *item, GeglGtkVie
g_signal_handlers_block_by_func (self->sharpen_scale, photos_tool_enhance_sharpen_value_changed, self);
gtk_range_set_value (GTK_RANGE (self->sharpen_scale), sharpen_scale);
g_signal_handlers_unblock_by_func (self->sharpen_scale, photos_tool_enhance_sharpen_value_changed, self);
+
+ g_signal_emit_by_name (self, "activated");
}
diff --git a/src/photos-tool-filters.c b/src/photos-tool-filters.c
index a5758a7..cef7e18 100644
--- a/src/photos-tool-filters.c
+++ b/src/photos-tool-filters.c
@@ -109,7 +109,7 @@ photos_tool_filters_activate (PhotosTool *tool, PhotosBaseItem *item, GeglGtkVie
PhotosOperationInstaPreset preset;
if (self->buttons == NULL || self->create_preview_id != 0)
- return;
+ goto out;
g_clear_object (&self->item);
self->item = g_object_ref (item);
@@ -136,6 +136,9 @@ photos_tool_filters_activate (PhotosTool *tool, PhotosBaseItem *item, GeglGtkVie
}
}
}
+
+ out:
+ g_signal_emit_by_name (self, "activated");
}
diff --git a/src/photos-tool.c b/src/photos-tool.c
index c911e49..b22bdd9 100644
--- a/src/photos-tool.c
+++ b/src/photos-tool.c
@@ -1,6 +1,6 @@
/*
* Photos - access, organize and share your photos on GNOME
- * Copyright © 2015 Red Hat, Inc.
+ * Copyright © 2015, 2016 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -30,6 +30,7 @@
enum
{
+ ACTIVATED,
HIDE_REQUESTED,
LAST_SIGNAL
};
@@ -88,6 +89,16 @@ photos_tool_class_init (PhotosToolClass *class)
class->left_unclick_event = photos_tool_default_left_unclick_event;
class->motion_event = photos_tool_default_motion_event;
+ signals[ACTIVATED] = g_signal_new ("activated",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (PhotosToolClass, activated),
+ NULL, /* accumulator */
+ NULL, /* accu_data */
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
signals[HIDE_REQUESTED] = g_signal_new ("hide-requested",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
diff --git a/src/photos-tool.h b/src/photos-tool.h
index a766555..5643719 100644
--- a/src/photos-tool.h
+++ b/src/photos-tool.h
@@ -1,6 +1,6 @@
/*
* Photos - access, organize and share your photos on GNOME
- * Copyright © 2015 Red Hat, Inc.
+ * Copyright © 2015, 2016 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -79,6 +79,7 @@ struct _PhotosToolClass
gboolean (*motion_event) (PhotosTool *self, GdkEventMotion *event);
/* signals */
+ void (*activated) (PhotosTool *self);
void (*hide_requested) (PhotosTool *self);
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]