[Xfce4-commits] <xfce4-panel:devel> Highlight the active panel by using a marching ants selection.

Nick Schermer nick at xfce.org
Tue Aug 11 20:28:03 CEST 2009


Updating branch refs/heads/devel
         to 228b5075200b426bf1322ab15ae12a862ea482c0 (commit)
       from cc0809b38a4c65332928d81a77cf5c9c492de72c (commit)

commit 228b5075200b426bf1322ab15ae12a862ea482c0
Author: Nick Schermer <nick at xfce.org>
Date:   Fri Feb 20 23:12:50 2009 +0100

    Highlight the active panel by using a marching ants selection.
    
    This drop quite a bit of code and it highlights the active
    panel a bit better on some backgrounds.

 common/panel-dbus.h           |    1 -
 panel/panel-plugin-external.c |   23 -----------
 panel/panel-plugin-external.h |    3 -
 panel/panel-window.c          |   87 ++++++++++++++++++++++------------------
 wrapper/main.c                |    9 +----
 wrapper/wrapper-plug.c        |   27 +------------
 wrapper/wrapper-plug.h        |    3 -
 7 files changed, 50 insertions(+), 103 deletions(-)

diff --git a/common/panel-dbus.h b/common/panel-dbus.h
index ed6cb9a..5f1caa8 100644
--- a/common/panel-dbus.h
+++ b/common/panel-dbus.h
@@ -39,7 +39,6 @@ enum _DBusPropertyChanged
 
   /* wrapper plug */
   PROPERTY_CHANGED_WRAPPER_BACKGROUND_ALPHA,
-  PROPERTY_CHANGED_WRAPPER_SET_SELECTED,
   PROPERTY_CHANGED_WRAPPER_SET_SENSITIVE,
   PROPERTY_CHANGED_WRAPPER_QUIT
 };
diff --git a/panel/panel-plugin-external.c b/panel/panel-plugin-external.c
index 6a95e6a..120c7f4 100644
--- a/panel/panel-plugin-external.c
+++ b/panel/panel-plugin-external.c
@@ -731,26 +731,3 @@ panel_plugin_external_set_background_alpha (PanelPluginExternal *external,
   /* unset */
   g_value_unset (&value);
 }
-
-
-
-void
-panel_plugin_external_set_active_panel (PanelPluginExternal *external,
-                                        gboolean             active)
-{
-  GValue value = { 0, };
-
-  panel_return_if_fail (PANEL_IS_PLUGIN_EXTERNAL (external));
-
-  /* set the boolean */
-  g_value_init (&value, G_TYPE_BOOLEAN);
-  g_value_set_boolean (&value, active);
-
-  /* send message */
-  panel_plugin_external_set_property (external,
-                                      PROPERTY_CHANGED_WRAPPER_SET_SELECTED,
-                                      &value);
-
-  /* unset */
-  g_value_unset (&value);
-}
diff --git a/panel/panel-plugin-external.h b/panel/panel-plugin-external.h
index 83eb634..131a9e1 100644
--- a/panel/panel-plugin-external.h
+++ b/panel/panel-plugin-external.h
@@ -47,9 +47,6 @@ XfcePanelPluginProvider *panel_plugin_external_new                  (PanelModule
 void                     panel_plugin_external_set_background_alpha (PanelPluginExternal  *external,
                                                                      gint                  percentage);
 
-void                     panel_plugin_external_set_active_panel     (PanelPluginExternal  *external,
-                                                                     gboolean              active);
-
 G_END_DECLS
 
 #endif /* !__PANEL_PLUGIN_EXTERNAL_H__ */
diff --git a/panel/panel-window.c b/panel/panel-window.c
index 87532c1..3a18c59 100644
--- a/panel/panel-window.c
+++ b/panel/panel-window.c
@@ -74,7 +74,6 @@ static void panel_window_set_autohide (PanelWindow *window, gboolean autohide);
 static void panel_window_menu_quit (gpointer boolean);
 static void panel_window_menu_deactivate (GtkMenu *menu, PanelWindow *window);
 static void panel_window_menu_popup (PanelWindow *window);
-static void panel_window_set_plugin_active_panel (GtkWidget *widget, gpointer user_data);
 static void panel_window_set_plugin_background_alpha (GtkWidget *widget, gpointer user_data);
 static void panel_window_set_plugin_size (GtkWidget *widget, gpointer user_data);
 static void panel_window_set_plugin_orientation (GtkWidget *widget, gpointer user_data);
@@ -169,8 +168,8 @@ struct _PanelWindow
   /* whether the panel is locked */
   guint                locked : 1;
 
-  /* when this is the active panel */
-  guint                is_active_panel : 1;
+  /* active panel redraw timeout id */
+  guint                active_timeout_id;
 
   /* panel orientation */
   guint                horizontal : 1;
@@ -234,7 +233,7 @@ panel_window_class_init (PanelWindowClass *klass)
   gtkwidget_class->size_request = panel_window_size_request;
   gtkwidget_class->size_allocate = panel_window_size_allocate;
   gtkwidget_class->screen_changed = panel_window_screen_changed;
-  
+
   g_object_class_install_property (gobject_class,
                                    PROP_HORIZONTAL,
                                    g_param_spec_boolean ("horizontal", NULL, NULL,
@@ -304,8 +303,8 @@ panel_window_class_init (PanelWindowClass *klass)
   g_object_class_install_property (gobject_class,
                                    PROP_SNAP_EDGE,
                                    g_param_spec_uint ("snap-edge", NULL, NULL,
-                                                      PANEL_SNAP_EGDE_NONE, 
-                                                      PANEL_SNAP_EGDE_S, 
+                                                      PANEL_SNAP_EGDE_NONE,
+                                                      PANEL_SNAP_EGDE_S,
                                                       PANEL_SNAP_EGDE_NONE,
                                                       EXO_PARAM_READWRITE));
 
@@ -345,7 +344,7 @@ panel_window_init (PanelWindow *window)
   window->autohide_status = DISABLED;
   window->autohide_block = 0;
   window->autohide_window = NULL;
-  window->is_active_panel = FALSE;
+  window->active_timeout_id = 0;
 
   /* set additional events we want to have */
   gtk_widget_add_events (GTK_WIDGET (window), GDK_BUTTON_PRESS_MASK);
@@ -571,6 +570,10 @@ panel_window_finalize (GObject *object)
 {
   PanelWindow *window = PANEL_WINDOW (object);
 
+  /* stop a running active timeout id */
+  if (window->active_timeout_id != 0)
+    g_source_remove (window->active_timeout_id);
+
   /* stop the autohide timeout */
   if (window->autohide_timer != 0)
     g_source_remove (window->autohide_timer);
@@ -615,11 +618,7 @@ panel_window_expose_event (GtkWidget      *widget,
       gdk_cairo_rectangle (cr, &event->area);
       cairo_clip (cr);
 
-      /* use another state when the panel is selected */
-      if (G_UNLIKELY (window->is_active_panel))
-        state = GTK_STATE_SELECTED;
-
-      if (alpha < 1.00 || window->is_active_panel)
+      if (alpha < 1.00 || window->active_timeout_id != 0)
         {
           /* get the background gdk color */
           color = &(widget->style->bg[state]);
@@ -1332,13 +1331,11 @@ panel_window_paint_handle (PanelWindow  *window,
   gint           x, y, width, height;
   guint          i, xx, yy;
   GdkColor      *color;
-  gdouble        alpha;
+  gdouble        alpha = 1.00;
 
   /* set the alpha (always show to handle for atleast 50%) */
-  if (window->is_composited)
+  if (window->active_timeout_id == 0 && window->is_composited)
     alpha = 0.50 + window->background_alpha / 2.00;
-  else
-    alpha = 1.00;
 
   /* set initial numbers */
   x = alloc->x + 2;
@@ -1399,16 +1396,26 @@ panel_window_paint_borders (PanelWindow  *window,
   GtkWidget     *widget = GTK_WIDGET (window);
   GtkAllocation *alloc = &(widget->allocation);
   GdkColor      *color;
-  gdouble        alpha = window->is_composited ? window->background_alpha : 1.00;
+  gdouble        alpha = 1.00;
+  const gdouble  dashes[] = {4.00, 4.00};
+  GTimeVal       timeval;
 
   /* 1px line (1.5 results in a sharp 1px line) */
   cairo_set_line_width (cr, 1.5);
 
+  if (G_UNLIKELY (window->active_timeout_id != 0))
+    g_get_current_time (&timeval);
+  else if (window->is_composited)
+    alpha = window->background_alpha;
+
   /* possibly save some time */
   if (PANEL_HAS_FLAG (window->borders, (PANEL_BORDER_BOTTOM | PANEL_BORDER_RIGHT)))
     {
       /* dark color */
-      color = &(widget->style->dark[state]);
+      if (G_UNLIKELY (window->active_timeout_id != 0))
+          color = &(widget->style->black);
+      else
+          color = &(widget->style->dark[state]);
       xfce_panel_cairo_set_source_rgba (cr, color, alpha);
 
       /* move the cursor the the bottom left */
@@ -1426,6 +1433,10 @@ panel_window_paint_borders (PanelWindow  *window,
       else
         cairo_rel_move_to (cr, 0, -alloc->height);
 
+      if (G_UNLIKELY (window->active_timeout_id != 0))
+        cairo_set_dash (cr, dashes, G_N_ELEMENTS (dashes),
+                        timeval.tv_sec % 2 ? 0.00 : 4.00);
+
       /* stroke this part */
       cairo_stroke (cr);
     }
@@ -1434,7 +1445,10 @@ panel_window_paint_borders (PanelWindow  *window,
   if (PANEL_HAS_FLAG (window->borders, (PANEL_BORDER_TOP | PANEL_BORDER_LEFT)))
     {
       /* light color */
-      color = &(widget->style->light[state]);
+      if (G_UNLIKELY (window->active_timeout_id != 0))
+          color = &(widget->style->black);
+      else
+          color = &(widget->style->light[state]);
       xfce_panel_cairo_set_source_rgba (cr, color, alpha);
 
       /* move the cursor the the bottom left */
@@ -1452,6 +1466,10 @@ panel_window_paint_borders (PanelWindow  *window,
       else
         cairo_rel_move_to (cr, alloc->width, 0);
 
+      if (G_UNLIKELY (window->active_timeout_id != 0))
+        cairo_set_dash (cr, dashes, G_N_ELEMENTS (dashes),
+                        timeval.tv_sec % 2 ? 0.00 : -4.00);
+
       /* stroke the lines */
       cairo_stroke (cr);
     }
@@ -2106,19 +2124,6 @@ panel_window_menu_popup (PanelWindow *window)
 
 
 static void
-panel_window_set_plugin_active_panel (GtkWidget *widget,
-                                      gpointer   user_data)
-{
-  panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (widget));
-
-  if (PANEL_IS_PLUGIN_EXTERNAL (widget))
-    panel_plugin_external_set_active_panel (PANEL_PLUGIN_EXTERNAL (widget),
-                                            !!GPOINTER_TO_UINT (user_data));
-}
-
-
-
-static void
 panel_window_set_plugin_background_alpha (GtkWidget *widget,
                                           gpointer   user_data)
 {
@@ -2174,18 +2179,22 @@ panel_window_set_active_panel (PanelWindow *window,
 {
   panel_return_if_fail (PANEL_IS_WINDOW (window));
 
-  if (G_UNLIKELY (window->is_active_panel != active))
+  if (G_UNLIKELY ((window->active_timeout_id != 0) != active))
     {
       /* set new value */
-      window->is_active_panel = !!active;
+      if (active)
+        {
+          window->active_timeout_id = g_timeout_add_seconds (1,
+              (GSourceFunc) gtk_widget_queue_draw, window);
+        }
+      else
+        {
+          g_source_remove (window->active_timeout_id);
+          window->active_timeout_id = 0;
+        }
 
       /* queue a redraw */
       gtk_widget_queue_draw (GTK_WIDGET (window));
-
-      /* poke all the plugins */
-      gtk_container_foreach (GTK_CONTAINER (gtk_bin_get_child (GTK_BIN (window))),
-                             panel_window_set_plugin_active_panel,
-                             GUINT_TO_POINTER (active));
     }
 }
 
diff --git a/wrapper/main.c b/wrapper/main.c
index 822f246..4078798 100644
--- a/wrapper/main.c
+++ b/wrapper/main.c
@@ -126,15 +126,8 @@ dbus_gproxy_property_changed (DBusGProxy              *dbus_gproxy,
         break;
 
       case PROPERTY_CHANGED_WRAPPER_BACKGROUND_ALPHA:
-      case PROPERTY_CHANGED_WRAPPER_SET_SELECTED:
-        /* get the plug */
         plug = g_object_get_qdata (G_OBJECT (provider), plug_quark);
-
-        /* set a plug value */
-        if (property == PROPERTY_CHANGED_WRAPPER_BACKGROUND_ALPHA)
-          wrapper_plug_set_background_alpha (plug, g_value_get_int (value) / 100.00);
-        else
-          wrapper_plug_set_selected (plug, g_value_get_boolean (value));
+        wrapper_plug_set_background_alpha (plug, g_value_get_int (value) / 100.00);
         break;
 
       default:
diff --git a/wrapper/wrapper-plug.c b/wrapper/wrapper-plug.c
index c088de3..139651f 100644
--- a/wrapper/wrapper-plug.c
+++ b/wrapper/wrapper-plug.c
@@ -47,9 +47,6 @@ struct _WrapperPlug
   /* background alpha */
   gdouble background_alpha;
 
-  /* if the plugin background should be the selection color */
-  guint   is_selected : 1;
-
   /* whether the wrapper has a rgba colormap */
   guint   is_composited : 1;
 };
@@ -81,7 +78,6 @@ wrapper_plug_init (WrapperPlug *plug)
 {
   /* init vars */
   plug->background_alpha = 1.00;
-  plug->is_selected = FALSE;
   plug->is_composited = FALSE;
 
   /* allow painting, else compositing won't work */
@@ -108,16 +104,11 @@ wrapper_plug_expose_event (GtkWidget      *widget,
   GtkStateType   state = GTK_STATE_NORMAL;
   gdouble        alpha = plug->is_composited ? plug->background_alpha : 1.00;
 
-  if (GTK_WIDGET_DRAWABLE (widget) &&
-      (alpha < 1.00 || plug->is_selected))
+  if (GTK_WIDGET_DRAWABLE (widget) && alpha < 1.00)
     {
       /* create the cairo context */
       cr = gdk_cairo_create (widget->window);
 
-      /* change the state is this plugin is on an active panel */
-      if (G_UNLIKELY (plug->is_selected))
-        state = GTK_STATE_SELECTED;
-
       /* get the background gdk color */
       color = &(widget->style->bg[state]);
 
@@ -235,19 +226,3 @@ wrapper_plug_set_background_alpha (WrapperPlug *plug,
   if (plug->is_composited)
     gtk_widget_queue_draw (GTK_WIDGET (plug));
 }
-
-
-
-void
-wrapper_plug_set_selected (WrapperPlug *plug,
-                           gboolean     selected)
-{
-  panel_return_if_fail (WRAPPER_IS_PLUG (plug));
-  panel_return_if_fail (GTK_IS_WIDGET (plug));
-
-  /* set value */
-  plug->is_selected = !!selected;
-
-  /* redraw */
-  gtk_widget_queue_draw (GTK_WIDGET (plug));
-}
diff --git a/wrapper/wrapper-plug.h b/wrapper/wrapper-plug.h
index 025a8c4..e744fd5 100644
--- a/wrapper/wrapper-plug.h
+++ b/wrapper/wrapper-plug.h
@@ -45,9 +45,6 @@ WrapperPlug  *wrapper_plug_new                  (GdkNativeWindow  socket_id);
 void          wrapper_plug_set_background_alpha (WrapperPlug     *plug,
                                                  gdouble          alpha);
 
-void          wrapper_plug_set_selected         (WrapperPlug     *plug,
-                                                 gboolean         selected);
-
 G_END_DECLS
 
 #endif /* !__WRAPPER_PLUG_H__ */



More information about the Xfce4-commits mailing list