[libadwaita/wip/exalm/tab-style: 11/11] tmp




commit 182e060a3d01da581b9887b9c655fb9261929994
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Wed Apr 6 21:51:17 2022 +0400

    tmp

 src/adw-tab-bar.c                     |  42 ---------
 src/adw-tab-bar.ui                    |   4 -
 src/adw-tab-box.c                     | 169 +++++++++++++++++++---------------
 src/adw-tab.ui                        |   2 +-
 src/stylesheet/widgets/_tab-view.scss |  32 +------
 5 files changed, 100 insertions(+), 149 deletions(-)
---
diff --git a/src/adw-tab-bar.c b/src/adw-tab-bar.c
index 6c7a5c32..b914a9f2 100644
--- a/src/adw-tab-bar.c
+++ b/src/adw-tab-bar.c
@@ -187,46 +187,6 @@ page_detached_cb (AdwTabBar  *self,
   g_signal_handlers_disconnect_by_func (page, notify_pinned_cb, self);
 }
 
-static void
-update_needs_attention (AdwTabBar *self,
-                        gboolean   pinned)
-{
-  GtkStyleContext *context;
-  gboolean left, right;
-
-  g_object_get (pinned ? self->pinned_box : self->box,
-                "needs-attention-left", &left,
-                "needs-attention-right", &right,
-                NULL);
-
-  if (pinned)
-    context = gtk_widget_get_style_context (GTK_WIDGET (self->pinned_scrolled_window));
-  else
-    context = gtk_widget_get_style_context (GTK_WIDGET (self->scrolled_window));
-
-  if (left)
-    gtk_style_context_add_class (context, "needs-attention-left");
-  else
-    gtk_style_context_remove_class (context, "needs-attention-left");
-
-  if (right)
-    gtk_style_context_add_class (context, "needs-attention-right");
-  else
-    gtk_style_context_remove_class (context, "needs-attention-right");
-}
-
-static void
-notify_needs_attention_cb (AdwTabBar *self)
-{
-  update_needs_attention (self, FALSE);
-}
-
-static void
-notify_needs_attention_pinned_cb (AdwTabBar *self)
-{
-  update_needs_attention (self, TRUE);
-}
-
 static inline gboolean
 is_overflowing (GtkAdjustment *adj)
 {
@@ -609,8 +569,6 @@ adw_tab_bar_class_init (AdwTabBarClass *klass)
   gtk_widget_class_bind_template_child (widget_class, AdwTabBar, pinned_scrolled_window);
   gtk_widget_class_bind_template_child (widget_class, AdwTabBar, start_action_bin);
   gtk_widget_class_bind_template_child (widget_class, AdwTabBar, end_action_bin);
-  gtk_widget_class_bind_template_callback (widget_class, notify_needs_attention_cb);
-  gtk_widget_class_bind_template_callback (widget_class, notify_needs_attention_pinned_cb);
   gtk_widget_class_bind_template_callback (widget_class, notify_resize_frozen_cb);
   gtk_widget_class_bind_template_callback (widget_class, stop_kinetic_scrolling_cb);
   gtk_widget_class_bind_template_callback (widget_class, extra_drag_drop_cb);
diff --git a/src/adw-tab-bar.ui b/src/adw-tab-bar.ui
index c6f68e0c..81583d7c 100644
--- a/src/adw-tab-bar.ui
+++ b/src/adw-tab-bar.ui
@@ -33,8 +33,6 @@
                   <object class="AdwTabBox" id="pinned_box">
                     <property name="pinned">True</property>
                     <property name="tab-bar">AdwTabBar</property>
-                    <signal name="notify::needs-attention-left" handler="notify_needs_attention_pinned_cb" 
swapped="true"/>
-                    <signal name="notify::needs-attention-right" handler="notify_needs_attention_pinned_cb" 
swapped="true"/>
                     <signal name="notify::resize-frozen" handler="notify_resize_frozen_cb" swapped="true"/>
                     <signal name="stop-kinetic-scrolling" handler="stop_kinetic_scrolling_cb" 
object="pinned_scrolled_window" swapped="true"/>
                     <signal name="extra-drag-drop" handler="extra_drag_drop_cb" swapped="true"/>
@@ -52,8 +50,6 @@
                 <child>
                   <object class="AdwTabBox" id="box">
                     <property name="tab-bar">AdwTabBar</property>
-                    <signal name="notify::needs-attention-left" handler="notify_needs_attention_cb" 
swapped="true"/>
-                    <signal name="notify::needs-attention-right" handler="notify_needs_attention_cb" 
swapped="true"/>
                     <signal name="notify::resize-frozen" handler="notify_resize_frozen_cb" swapped="true"/>
                     <signal name="stop-kinetic-scrolling" handler="stop_kinetic_scrolling_cb" 
object="scrolled_window" swapped="true"/>
                     <signal name="extra-drag-drop" handler="extra_drag_drop_cb" swapped="true"/>
diff --git a/src/adw-tab-box.c b/src/adw-tab-box.c
index 4e62bb20..862d8ef5 100644
--- a/src/adw-tab-box.c
+++ b/src/adw-tab-box.c
@@ -7,8 +7,9 @@
  */
 
 // FIXME expand broken end padding - unrelated, need to fix regardless
-// FIXME now we can have backdrop styles
+// TODO now we can have backdrop styles
 // FIXME restore the undershoot attention style
+// TODO has popup style
 
 #include "config.h"
 
@@ -96,8 +97,6 @@ struct _AdwTabBox
   AdwTabBar *tab_bar;
   AdwTabView *view;
   GtkAdjustment *adjustment;
-  gboolean needs_attention_left;
-  gboolean needs_attention_right;
   gboolean expand_tabs;
   gboolean inverted;
 
@@ -173,6 +172,9 @@ struct _AdwTabBox
 
   GskGLShader *shader;
   gboolean shader_compiled;
+
+  GtkWidget *needs_attention_left;
+  GtkWidget *needs_attention_right;
 };
 
 G_DEFINE_FINAL_TYPE_WITH_CODE (AdwTabBox, adw_tab_box, GTK_TYPE_WIDGET,
@@ -183,8 +185,6 @@ enum {
   PROP_PINNED,
   PROP_TAB_BAR,
   PROP_VIEW,
-  PROP_NEEDS_ATTENTION_LEFT,
-  PROP_NEEDS_ATTENTION_RIGHT,
   PROP_RESIZE_FROZEN,
   PROP_HADJUSTMENT,
   PROP_VADJUSTMENT,
@@ -769,15 +769,8 @@ update_visible (AdwTabBox *self)
       right = TRUE;
   }
 
-  if (self->needs_attention_left != left) {
-    self->needs_attention_left = left;
-    g_object_notify_by_pspec (G_OBJECT (self), props[PROP_NEEDS_ATTENTION_LEFT]);
-  }
-
-  if (self->needs_attention_right != right) {
-    self->needs_attention_right = right;
-    g_object_notify_by_pspec (G_OBJECT (self), props[PROP_NEEDS_ATTENTION_RIGHT]);
-  }
+  gtk_revealer_set_reveal_child (GTK_REVEALER (self->needs_attention_left), left);
+  gtk_revealer_set_reveal_child (GTK_REVEALER (self->needs_attention_right), right);
 }
 
 static double
@@ -1054,9 +1047,9 @@ start_reordering (AdwTabBox *self,
 
   /* The reordered tab should be displayed above everything else */
   gtk_widget_insert_before (GTK_WIDGET (self->reordered_tab->container),
-                            GTK_WIDGET (self), NULL);
+                            GTK_WIDGET (self), self->needs_attention_left);
   gtk_widget_insert_before (GTK_WIDGET (self->reordered_tab->separator),
-                            GTK_WIDGET (self), NULL);
+                            GTK_WIDGET (self), self->needs_attention_left);
 
   gtk_widget_queue_allocate (GTK_WIDGET (self));
 }
@@ -1775,8 +1768,8 @@ create_tab_info (AdwTabBox  *self,
   gtk_widget_set_can_target (info->separator, FALSE);
 
   gtk_widget_set_parent (GTK_WIDGET (info->tab), info->container);
-  gtk_widget_set_parent (info->separator, GTK_WIDGET (self));
-  gtk_widget_set_parent (info->container, GTK_WIDGET (self));
+  gtk_widget_insert_before (info->separator, GTK_WIDGET (self), self->needs_attention_left);
+  gtk_widget_insert_before (info->container, GTK_WIDGET (self), self->needs_attention_left);
 
   g_signal_connect_object (info->tab, "extra-drag-drop", G_CALLBACK (extra_drag_drop_cb), self, 0);
   g_signal_connect_object (info->tab, "state-flags-changed", G_CALLBACK (state_flags_changed_cb), self, 0);
@@ -3015,28 +3008,34 @@ adw_tab_box_measure (GtkWidget      *widget,
     min = nat = width;
   } else {
     GList *l;
+    int child_min, child_nat;
 
     min = nat = 0;
 
     for (l = self->tabs; l; l = l->next) {
       TabInfo *info = l->data;
-      int child_min, child_nat;
 
       gtk_widget_measure (info->container, orientation, -1,
                           &child_min, &child_nat, NULL, NULL);
 
-      if (child_min > min)
-        min = child_min;
-
-      if (child_nat > nat)
-        nat = child_nat;
+      min = MAX (min, child_min);
+      nat = MAX (nat, child_nat);
 
       gtk_widget_measure (info->separator, orientation, -1,
                           &child_min, NULL, NULL, NULL);
 
-      if (child_min > min)
-        min = child_min;
+      min = MAX (min, child_min);
     }
+
+    gtk_widget_measure (self->needs_attention_left, orientation, -1,
+                        &child_min, NULL, NULL, NULL);
+
+    min = MAX (min, child_min);
+
+    gtk_widget_measure (self->needs_attention_right, orientation, -1,
+                        &child_min, NULL, NULL, NULL);
+
+    min = MAX (min, child_min);
   }
 
   if (minimum)
@@ -3064,6 +3063,8 @@ adw_tab_box_size_allocate (GtkWidget *widget,
   GtkAllocation child_allocation;
   int pos;
   double value;
+  int indicator_size;
+  GskTransform *transform;
 
   adw_tab_box_measure (widget, GTK_ORIENTATION_HORIZONTAL, -1,
                        &self->allocated_width, NULL, NULL, NULL);
@@ -3196,6 +3197,15 @@ adw_tab_box_size_allocate (GtkWidget *widget,
     }
   }
 
+  gtk_widget_measure (self->needs_attention_left, GTK_ORIENTATION_HORIZONTAL, -1,
+                      &indicator_size, NULL, NULL, NULL);
+  gtk_widget_allocate (self->needs_attention_left, indicator_size, height, baseline, NULL);
+
+  gtk_widget_measure (self->needs_attention_right, GTK_ORIENTATION_HORIZONTAL, -1,
+                      &indicator_size, NULL, NULL, NULL);
+  transform = gsk_transform_translate (NULL, &GRAPHENE_POINT_INIT (width - indicator_size, 0));
+  gtk_widget_allocate (self->needs_attention_right, indicator_size, height, baseline, transform);
+
   update_visible (self);
 }
 
@@ -3318,44 +3328,51 @@ adw_tab_box_snapshot (GtkWidget   *widget,
   double value = gtk_adjustment_get_value (self->adjustment);
   double page_size = gtk_adjustment_get_page_size (self->adjustment);
   double upper = gtk_adjustment_get_upper (self->adjustment);
-  graphene_rect_t bounds;
-  int width, height;
+  gboolean draw_fade = value > 0 || value + page_size < upper;
 
-  if (value <= 0 && value + page_size >= upper) {
-    snapshot_tabs (self, snapshot);
+  if (!self->n_tabs)
     return;
-  }
 
-  ensure_shader (self);
+  if (draw_fade) {
+    int width, height;
+    graphene_rect_t bounds;
 
-  width = gtk_widget_get_width (widget);
-  height = gtk_widget_get_height (widget);
+    ensure_shader (self);
 
-  graphene_rect_init (&bounds, 0, 0, width, height);
+    width = gtk_widget_get_width (widget);
+    height = gtk_widget_get_height (widget);
 
-  if (self->shader_compiled) {
-    gboolean fadeLeft = value > 0;
-    gboolean fadeRight = value + page_size < upper;
+    graphene_rect_init (&bounds, 0, 0, width, height);
 
-    gtk_snapshot_push_gl_shader (snapshot, self->shader, &bounds,
-                                 gsk_gl_shader_format_args (self->shader,
-                                                            "offsetLeft", FADE_OFFSET,
-                                                            "offsetRight", FADE_OFFSET,
-                                                            "strengthLeft", fadeLeft ? 1.0f : 0.0f,
-                                                            "strengthRight", fadeRight ? 1.0f : 0.0f,
-                                                            "widthLeft", FADE_WIDTH,
-                                                            "widthRight", FADE_WIDTH,
-                                                            NULL));
-  } else {
-    gtk_snapshot_push_clip (snapshot, &bounds);
+    if (self->shader_compiled) {
+      gboolean fadeLeft = value > 0;
+      gboolean fadeRight = value + page_size < upper;
+
+      gtk_snapshot_push_gl_shader (snapshot, self->shader, &bounds,
+                                   gsk_gl_shader_format_args (self->shader,
+                                                              "offsetLeft", FADE_OFFSET,
+                                                              "offsetRight", FADE_OFFSET,
+                                                              "strengthLeft", fadeLeft ? 1.0f : 0.0f,
+                                                              "strengthRight", fadeRight ? 1.0f : 0.0f,
+                                                              "widthLeft", FADE_WIDTH,
+                                                              "widthRight", FADE_WIDTH,
+                                                              NULL));
+    } else {
+      gtk_snapshot_push_clip (snapshot, &bounds);
+    }
   }
 
   snapshot_tabs (self, snapshot);
 
-  if (self->shader_compiled)
-    gtk_snapshot_gl_shader_pop_texture (snapshot);
+  if (draw_fade) {
+    if (self->shader_compiled)
+      gtk_snapshot_gl_shader_pop_texture (snapshot);
+
+    gtk_snapshot_pop (snapshot);
+  }
 
-  gtk_snapshot_pop (snapshot);
+  gtk_widget_snapshot_child (GTK_WIDGET (self), self->needs_attention_left, snapshot);
+  gtk_widget_snapshot_child (GTK_WIDGET (self), self->needs_attention_right, snapshot);
 }
 
 static gboolean
@@ -3442,6 +3459,9 @@ adw_tab_box_dispose (GObject *object)
   g_clear_object (&self->resize_animation);
   g_clear_object (&self->scroll_animation);
 
+  g_clear_pointer (&self->needs_attention_left, gtk_widget_unparent);
+  g_clear_pointer (&self->needs_attention_right, gtk_widget_unparent);
+
   G_OBJECT_CLASS (adw_tab_box_parent_class)->dispose (object);
 }
 
@@ -3476,14 +3496,6 @@ adw_tab_box_get_property (GObject    *object,
     g_value_set_object (value, self->view);
     break;
 
-  case PROP_NEEDS_ATTENTION_LEFT:
-    g_value_set_boolean (value, self->needs_attention_left);
-    break;
-
-  case PROP_NEEDS_ATTENTION_RIGHT:
-    g_value_set_boolean (value, self->needs_attention_right);
-    break;
-
   case PROP_RESIZE_FROZEN:
     g_value_set_boolean (value, self->tab_resize_mode != TAB_RESIZE_NORMAL);
     break;
@@ -3577,20 +3589,6 @@ adw_tab_box_class_init (AdwTabBoxClass *klass)
                          ADW_TYPE_TAB_VIEW,
                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
-  props[PROP_NEEDS_ATTENTION_LEFT] =
-    g_param_spec_boolean ("needs-attention-left",
-                          "Needs Attention Left",
-                          "Needs Attention Left",
-                          FALSE,
-                          G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY);
-
-  props[PROP_NEEDS_ATTENTION_RIGHT] =
-    g_param_spec_boolean ("needs-attention-right",
-                          "Needs Attention Right",
-                          "Needs Attention Right",
-                          FALSE,
-                          G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY);
-
   props[PROP_RESIZE_FROZEN] =
     g_param_spec_boolean ("resize-frozen",
                           "Resize Frozen",
@@ -3650,6 +3648,7 @@ adw_tab_box_init (AdwTabBox *self)
 {
   GtkEventController *controller;
   AdwAnimationTarget *target;
+  GtkWidget *widget;
 
   self->can_remove_placeholder = TRUE;
   self->expand_tabs = TRUE;
@@ -3722,6 +3721,28 @@ adw_tab_box_init (AdwTabBox *self)
 
   g_signal_connect_swapped (self->scroll_animation, "done",
                             G_CALLBACK (scroll_animation_done_cb), self);
+
+  self->needs_attention_left = gtk_revealer_new ();
+  gtk_revealer_set_transition_type (GTK_REVEALER (self->needs_attention_left),
+                                    GTK_REVEALER_TRANSITION_TYPE_CROSSFADE);
+  gtk_widget_set_can_target (self->needs_attention_left, FALSE);
+  gtk_widget_set_can_focus (self->needs_attention_left, FALSE);
+  gtk_widget_set_parent (self->needs_attention_left, GTK_WIDGET (self));
+
+  widget = adw_gizmo_new ("indicator", NULL, NULL, NULL, NULL, NULL, NULL);
+  gtk_widget_add_css_class (widget, "left");
+  gtk_revealer_set_child (GTK_REVEALER (self->needs_attention_left), widget);
+
+  self->needs_attention_right = gtk_revealer_new ();
+  gtk_revealer_set_transition_type (GTK_REVEALER (self->needs_attention_right),
+                                    GTK_REVEALER_TRANSITION_TYPE_CROSSFADE);
+  gtk_widget_set_can_target (self->needs_attention_right, FALSE);
+  gtk_widget_set_can_focus (self->needs_attention_right, FALSE);
+  gtk_widget_set_parent (self->needs_attention_right, GTK_WIDGET (self));
+
+  widget = adw_gizmo_new ("indicator", NULL, NULL, NULL, NULL, NULL, NULL);
+  gtk_widget_add_css_class (widget, "right");
+  gtk_revealer_set_child (GTK_REVEALER (self->needs_attention_right), widget);
 }
 
 void
diff --git a/src/adw-tab.ui b/src/adw-tab.ui
index cbf5d992..ef9c3730 100644
--- a/src/adw-tab.ui
+++ b/src/adw-tab.ui
@@ -90,7 +90,7 @@
     </child>
     <child>
       <object class="AdwGizmo" id="needs_attention_indicator">
-        <property name="css-name">attention-indicator</property>
+        <property name="css-name">indicator</property>
         <property name="valign">end</property>
       </object>
     </child>
diff --git a/src/stylesheet/widgets/_tab-view.scss b/src/stylesheet/widgets/_tab-view.scss
index eea14252..7b34cd80 100644
--- a/src/stylesheet/widgets/_tab-view.scss
+++ b/src/stylesheet/widgets/_tab-view.scss
@@ -56,26 +56,7 @@ tabbar {
 
   .start-action,
   .end-action {
-    background-color: gtkalpha($shade_color, .6);
-    background-clip: padding-box;
-    border-color: $border_color;
-    border-style: solid;
-    transition: background 150ms ease-in-out;
-
-    button {
-      border: none;
-      border-radius: 0;
-    }
-  }
-
-  .start-action:dir(ltr),
-  .end-action:dir(rtl) {
-    border-right-width: 1px;
-  }
-
-  .start-action:dir(rtl),
-  .end-action:dir(ltr) {
-    border-left-width: 1px;
+    padding: 3px;
   }
 
   &:not(.inline) {
@@ -85,12 +66,6 @@ tabbar {
       border-bottom: 1px solid $headerbar_border_color;
     }
 
-    .start-action,
-    .end-action {
-      background-color: gtkalpha($headerbar_shade_color, .6);
-      border-color: $headerbar_border_color;
-    }
-
     &:backdrop .box {
       background-color: $headerbar_backdrop_color;
       transition: $backdrop_transition;
@@ -102,6 +77,7 @@ dnd tab {
   background-color: $headerbar_bg_color;
   background-image: image($view_selected_active_color);
   color: $headerbar_fg_color;
+  border-radius: $button_radius;
 
   box-shadow: 0 0 0 1px transparentize(black, 0.97),
               0 1px 3px 1px transparentize(black, .93),
@@ -120,7 +96,6 @@ dnd {
   tab {
     min-height: 24px;
     padding: 6px;
-    border-radius: $button_radius;
 
     button.image-button {
       padding: 0;
@@ -130,8 +105,9 @@ dnd {
       border-radius: 99px;
     }
 
-    attention-indicator {
+    indicator {
       min-height: 2px;
+      border-radius: 2px;
       background: if($contrast == 'high', $accent_color, gtkalpha($accent_color, 0.5));
       transform: translateY(6px);
     }


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