[gimp] Issue #6030: Mask related Shortcuts conflicting with Multiple Layers…



commit d6d8e43cb5799c25213b59c465f6aed76880d3e0
Author: Jehan <jehan girinstud io>
Date:   Mon Dec 14 12:10:21 2020 +0100

    Issue #6030: Mask related Shortcuts conflicting with Multiple Layers…
    
    … Selection.
    I first wanted to switch the modifiers to Alt+shift, Alt+Ctrl clicks and
    even implemented the changes, but realized the existing "Alpha to
    selection" on Alt thumbnail clicks already mapped these for
    Add/Remove/Intersect Alpha to Selection (though I broke this with commit
    14b4c08881 but re-allows properly with exact modifier recognition in
    order not to catch other types of combinations).
    
    In the end, I see no other solutions than actually removing the mask
    add/remove modifiers (#if-ed 0 for now, we'll see) in favor of the most
    ancient feature.

 app/widgets/gimpitemtreeview.c  |   8 +--
 app/widgets/gimplayertreeview.c | 113 +++++++++++++++++++++++++++++++---------
 2 files changed, 93 insertions(+), 28 deletions(-)
---
diff --git a/app/widgets/gimpitemtreeview.c b/app/widgets/gimpitemtreeview.c
index e9793d031a..81c953be7d 100644
--- a/app/widgets/gimpitemtreeview.c
+++ b/app/widgets/gimpitemtreeview.c
@@ -1783,13 +1783,15 @@ gimp_item_tree_view_item_pre_clicked (GimpCellRendererViewable *cell,
   GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (item_view);
   GtkTreePath           *path;
   GtkTreeIter            iter;
-  GdkModifierType        modifiers = gimp_get_all_modifiers_mask ();
+  GdkModifierType        modifiers = (state & gimp_get_all_modifiers_mask ());
   gboolean               handled   = FALSE;
 
   path = gtk_tree_path_new_from_string (path_str);
 
-  if (gtk_tree_model_get_iter (tree_view->model, &iter, path) &&
-      (state & modifiers) == GDK_MOD1_MASK)
+  /* Alt modifier at least and none other than Alt, Shift and Ctrl. */
+  if ((modifiers & GDK_MOD1_MASK)                                          &&
+      ! (modifiers & ~(GDK_MOD1_MASK | GDK_SHIFT_MASK | GDK_CONTROL_MASK)) &&
+      gtk_tree_model_get_iter (tree_view->model, &iter, path))
     {
       GimpImage        *image    = gimp_item_tree_view_get_image (item_view);
       GimpViewRenderer *renderer = NULL;
diff --git a/app/widgets/gimplayertreeview.c b/app/widgets/gimplayertreeview.c
index 12f75ce4df..6085738b63 100644
--- a/app/widgets/gimplayertreeview.c
+++ b/app/widgets/gimplayertreeview.c
@@ -31,6 +31,11 @@
 
 #include "widgets-types.h"
 
+#if 0
+/* For mask features in gimp_layer_tree_view_layer_clicked() */
+#include "config/gimpdialogconfig.h"
+#endif
+
 #include "core/gimp.h"
 #include "core/gimpchannel.h"
 #include "core/gimpcontainer.h"
@@ -1563,8 +1568,7 @@ gimp_layer_tree_view_layer_clicked (GimpCellRendererViewable *cell,
   GtkTreePath           *path      = gtk_tree_path_new_from_string (path_str);
   GtkTreeIter            iter;
 
-  if (gtk_tree_model_get_iter (tree_view->model, &iter, path) &&
-      ! (state & GDK_MOD1_MASK))
+  if (gtk_tree_model_get_iter (tree_view->model, &iter, path))
     {
       GimpUIManager    *ui_manager;
       GimpActionGroup  *group;
@@ -1579,39 +1583,98 @@ gimp_layer_tree_view_layer_clicked (GimpCellRendererViewable *cell,
 
       if (renderer)
         {
-          GimpLayer     *layer = GIMP_LAYER (renderer->viewable);
-          GimpLayerMask *mask  = gimp_layer_get_mask (layer);
+          GimpLayer       *layer     = GIMP_LAYER (renderer->viewable);
+          GimpLayerMask   *mask      = gimp_layer_get_mask (layer);
+          GdkModifierType  modifiers = (state & gimp_get_all_modifiers_mask ());
 
-          if (state & gimp_get_extend_selection_mask ())
+#if 0
+/* This feature has been removed because it clashes with the
+ * multi-selection (Shift/Ctrl are reserved), and we can't move it to
+ * Alt+ because then it would clash with the alpha-to-selection features
+ * (cf. gimp_item_tree_view_item_pre_clicked()).
+ * Just macro-ing them out for now, just in case, but I don't think
+ * there is a chance to revive them as there is no infinite modifiers.
+ */
+          GimpImage       *image;
+
+          image = gimp_item_get_image (GIMP_ITEM (layer));
+
+          if ((modifiers & GDK_MOD1_MASK))
             {
-              if (state & gimp_get_modify_selection_mask ())
+              /* Alternative functions (Alt key or equivalent) when
+               * clicking on a layer preview. The actions happen only on
+               * the clicked layer, not on selected layers.
+               *
+               * Note: Alt-click is already reserved for Alpha to
+               * selection in GimpItemTreeView.
+               */
+              if (modifiers == (GDK_MOD1_MASK | GDK_SHIFT_MASK))
                 {
-                  /* Shift-Control-click apply a layer mask */
+                  /* Alt-Shift-click adds a layer mask with last values */
+                  GimpDialogConfig *config;
+                  GimpChannel      *channel = NULL;
 
+                  if (! mask)
+                    {
+                      config = GIMP_DIALOG_CONFIG (image->gimp->config);
+
+                      if (config->layer_add_mask_type == GIMP_ADD_MASK_CHANNEL)
+                        {
+                          channel = gimp_image_get_active_channel (image);
+
+                          if (! channel)
+                            {
+                              GimpContainer *channels = gimp_image_get_channels (image);
+
+                              channel = GIMP_CHANNEL (gimp_container_get_first_child (channels));
+                            }
+
+                          if (! channel)
+                            {
+                              /* No channel. We cannot perform the add
+                               * mask action. */
+                              g_message (_("No channels to create a layer mask from."));
+                            }
+                        }
+
+                      if (config->layer_add_mask_type != GIMP_ADD_MASK_CHANNEL || channel)
+                        {
+                          mask = gimp_layer_create_mask (layer,
+                                                         config->layer_add_mask_type,
+                                                         channel);
+
+                          if (config->layer_add_mask_invert)
+                            gimp_channel_invert (GIMP_CHANNEL (mask), FALSE);
+
+                          gimp_layer_add_mask (layer, mask, TRUE, NULL);
+                          gimp_image_flush (image);
+                        }
+                    }
+                }
+              else if (modifiers == (GDK_MOD1_MASK | GDK_CONTROL_MASK))
+                {
+                  /* Alt-Control-click removes a layer mask */
                   if (mask)
-                    gimp_ui_manager_activate_action (ui_manager, "layers",
-                                                     "layers-mask-apply");
+                    {
+                      gimp_layer_apply_mask (layer, GIMP_MASK_DISCARD, TRUE);
+                      gimp_image_flush (image);
+                    }
                 }
-              else
+              else if (modifiers == (GDK_MOD1_MASK | GDK_CONTROL_MASK | GDK_SHIFT_MASK))
                 {
-                  /* Shift-click add a layer mask with last values */
-
-                  if (! mask)
-                    gimp_ui_manager_activate_action (ui_manager, "layers",
-                                                     "layers-mask-add-last-values");
+                  /* Alt-Shift-Control-click applies a layer mask */
+                  if (mask)
+                    {
+                      gimp_layer_apply_mask (layer, GIMP_MASK_APPLY, TRUE);
+                      gimp_image_flush (image);
+                    }
                 }
             }
-          else if (state & gimp_get_modify_selection_mask ())
-            {
-              /* Control-click remove a layer mask */
-
-              if (mask)
-                gimp_ui_manager_activate_action (ui_manager, "layers",
-                                                 "layers-mask-delete");
-            }
-          else if (mask && gimp_layer_get_edit_mask (layer))
+          else
+#endif
+          if (! modifiers && mask && gimp_layer_get_edit_mask (layer))
             {
-              /* other clicks activate the layer */
+              /* Simple clicks (without modifiers) activate the layer */
 
               if (mask)
                 gimp_action_group_set_action_active (group,


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