[gimp] app: fix GimpForegroundSelectTool after GimpFreeSelectTool changes



commit 1abd415a30ba0e2af62d7543e15e6c4517bda5cc
Author: Michael Natterer <mitch gimp org>
Date:   Thu Dec 7 19:49:37 2017 +0100

    app: fix GimpForegroundSelectTool after GimpFreeSelectTool changes
    
    The free select tool now commits on double click inside a closed
    polygon, which caused the foreground select tool to switch modes in
    the middle of a click, breaking both its own and its parent class'
    state.
    
    Fixed by detecting whether the commit was done by double click and
    delaying the mode switch until after the parent class button release
    code is done.
    
    Unrelated: Don't call both COMMIT and HALT, the generic tool mechanism
    does that automatically now, forgot to port this file.

 app/tools/gimpforegroundselecttool.c |   27 ++++++++++++++++++++++++---
 app/tools/gimpforegroundselecttool.h |    1 +
 2 files changed, 25 insertions(+), 3 deletions(-)
---
diff --git a/app/tools/gimpforegroundselecttool.c b/app/tools/gimpforegroundselecttool.c
index 60cfaf2..8e0ad81 100644
--- a/app/tools/gimpforegroundselecttool.c
+++ b/app/tools/gimpforegroundselecttool.c
@@ -403,7 +403,7 @@ gimp_foreground_select_tool_button_press (GimpTool            *tool,
 
       g_array_append_val (fg_select->stroke, point);
 
-      if (!gimp_draw_tool_is_active (draw_tool))
+      if (! gimp_draw_tool_is_active (draw_tool))
         gimp_draw_tool_start (draw_tool, display);
 
       gimp_draw_tool_resume (draw_tool);
@@ -424,6 +424,14 @@ gimp_foreground_select_tool_button_release (GimpTool              *tool,
     {
       GIMP_TOOL_CLASS (parent_class)->button_release (tool, coords, time, state,
                                                       release_type, display);
+
+      /*  see comment in gimp_foreground_select_tool_select()  */
+      if (fg_select->in_double_click)
+        {
+          gimp_foreground_select_tool_set_trimap (fg_select);
+
+          fg_select->in_double_click = FALSE;
+        }
     }
   else
     {
@@ -899,7 +907,20 @@ gimp_foreground_select_tool_select (GimpFreeSelectTool *free_sel,
                                       0, 0, 0.5);
       gimp_scan_convert_free (scan_convert);
 
-      gimp_foreground_select_tool_set_trimap (fg_select);
+      if (! gimp_tool_control_is_active (GIMP_TOOL (fg_select)->control))
+        {
+          gimp_foreground_select_tool_set_trimap (fg_select);
+        }
+      else
+        {
+          /*  if the tool is active we got here by double click
+           *  detected in the parent class. We can't switch to trimap
+           *  mode in the middle of a click. Set a flag and let
+           *  button_release() forward the release to the parent class
+           *  so it can conclude its operation
+           */
+          fg_select->in_double_click = TRUE;
+        }
     }
 }
 
@@ -1154,7 +1175,7 @@ gimp_foreground_select_tool_response (GimpToolGui              *gui,
     {
     case GTK_RESPONSE_APPLY:
       gimp_tool_control (tool, GIMP_TOOL_ACTION_COMMIT, tool->display);
-      /* fallthru */
+      break;
 
     default:
       gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, tool->display);
diff --git a/app/tools/gimpforegroundselecttool.h b/app/tools/gimpforegroundselecttool.h
index ebc61f0..76ab602 100644
--- a/app/tools/gimpforegroundselecttool.h
+++ b/app/tools/gimpforegroundselecttool.h
@@ -48,6 +48,7 @@ struct _GimpForegroundSelectTool
   GimpFreeSelectTool  parent_instance;
 
   MattingState        state;
+  gboolean            in_double_click;
 
   GimpCoords          last_coords;
   GArray             *stroke;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]