[Xfce4-commits] [xfce/gtk-xfce-engine] 04/08: Added focus_color style property.

noreply at xfce.org noreply at xfce.org
Fri Feb 6 22:24:20 CET 2015


This is an automated email from the git hooks/post-receive script.

peter pushed a commit to branch peter/refresh-gtk2
in repository xfce/gtk-xfce-engine.

commit d320de29d3592fe26c66c7b5ae40d3adc7fbdaf9
Author: Peter de Ridder <peter at xfce.org>
Date:   Fri Dec 27 13:52:17 2013 +0100

    Added focus_color style property.
---
 src/xfce_rc_style.c   |   32 ++++++++++++++++++
 src/xfce_rc_style.h   |   10 ++++++
 src/xfce_theme_draw.c |   88 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 130 insertions(+)

diff --git a/src/xfce_rc_style.c b/src/xfce_rc_style.c
index a732b69..5e36230 100644
--- a/src/xfce_rc_style.c
+++ b/src/xfce_rc_style.c
@@ -78,6 +78,7 @@ theme_symbols[] =
     { "shade_start", TOKEN_SHADE_START },
     { "shade_end", TOKEN_SHADE_END },
     { "flat_border", TOKEN_FLATBORDER },
+    { "focus_color", TOKEN_FOCUSCOLOR },
     { "true", TOKEN_TRUE},
     { "TRUE", TOKEN_TRUE},
     { "false", TOKEN_FALSE},
@@ -111,6 +112,7 @@ void xfce_rc_style_register_type(GTypeModule * module)
 
 static void xfce_rc_style_init(XfceRcStyle * style)
 {
+    style->flags = XFCE_RC_FLAGS_NONE;
     style->smooth_edge = FALSE;
     style->grip_style = XFCE_RC_GRIP_ROUGH;
     style->gradient = FALSE;
@@ -375,6 +377,24 @@ static guint theme_parse_grip_style (GScanner * scanner, GTokenType wanted_token
     return G_TOKEN_NONE;
 }
 
+static guint theme_parse_color (GScanner *scanner, GTokenType wanted_token, GtkRcStyle *style, GdkColor *retval)
+{
+    guint token;
+
+    token = g_scanner_get_next_token (scanner);
+    if (token != wanted_token)
+    {
+        return wanted_token;
+    }
+    token = g_scanner_get_next_token (scanner);
+    if (token != G_TOKEN_EQUAL_SIGN)
+    {
+        return G_TOKEN_EQUAL_SIGN;
+    }
+
+    return gtk_rc_parse_color_full (scanner, style, retval);
+}
+
 static guint xfce_rc_style_parse(GtkRcStyle * rc_style, GtkSettings * settings, GScanner * scanner)
 {
     static GQuark scope_id = 0;
@@ -383,6 +403,7 @@ static guint xfce_rc_style_parse(GtkRcStyle * rc_style, GtkSettings * settings,
     guint token;
     guint i;
     gboolean b;
+    GdkColor c;
 
     /* Set up a new scope in this scanner. */
     if(!scope_id)
@@ -432,6 +453,15 @@ static guint xfce_rc_style_parse(GtkRcStyle * rc_style, GtkSettings * settings,
                 }
                 theme_data->flat_border = b;
                 break;
+            case TOKEN_FOCUSCOLOR:
+                token = theme_parse_color (scanner, TOKEN_FOCUSCOLOR, rc_style, &c);
+                if(token != G_TOKEN_NONE)
+                {
+                    break;
+                }
+                theme_data->focus_color = c;
+                theme_data->flags |= XFCE_RC_FOCUS_COLOR;
+                break;
             default:
                 g_scanner_get_next_token(scanner);
                 token = G_TOKEN_RIGHT_CURLY;
@@ -464,6 +494,7 @@ static void xfce_rc_style_merge(GtkRcStyle * dest, GtkRcStyle * src)
     src_data = XFCE_RC_STYLE(src);
     dest_data = XFCE_RC_STYLE(dest);
 
+    dest_data->flags = src_data->flags;
     dest_data->smooth_edge = src_data->smooth_edge;
     dest_data->grip_style = src_data->grip_style;
     dest_data->gradient = src_data->gradient;
@@ -471,6 +502,7 @@ static void xfce_rc_style_merge(GtkRcStyle * dest, GtkRcStyle * src)
     dest_data->shade_start = src_data->shade_start;
     dest_data->shade_end = src_data->shade_end;
     dest_data->flat_border = src_data->flat_border;
+    dest_data->focus_color = src_data->focus_color;
 }
 
 /* Create an empty style suitable to this RC style
diff --git a/src/xfce_rc_style.h b/src/xfce_rc_style.h
index c2c94e1..0b8d609 100644
--- a/src/xfce_rc_style.h
+++ b/src/xfce_rc_style.h
@@ -71,10 +71,18 @@ typedef enum
     XFCE_RC_GRIP_SLIDE
 } XfceRcHandlerType;
 
+typedef enum
+{
+    XFCE_RC_FLAGS_NONE = 0,
+    XFCE_RC_FOCUS_COLOR = 1<<0
+} XfceRcFlags;
+
 struct _XfceRcStyle
 {
     GtkRcStyle parent_instance;
 
+    XfceRcFlags flags;
+
     gboolean smooth_edge;
     XfceRcHandlerType grip_style;
     gboolean gradient;
@@ -82,6 +90,7 @@ struct _XfceRcStyle
     gfloat shade_start;
     gfloat shade_end;
     gboolean flat_border;
+    GdkColor focus_color;
 };
 
 struct _XfceRcStyleClass
@@ -111,6 +120,7 @@ enum
     TOKEN_SHADE_START,
     TOKEN_SHADE_END,
     TOKEN_FLATBORDER,
+    TOKEN_FOCUSCOLOR,
     TOKEN_TRUE,
     TOKEN_FALSE
 };
diff --git a/src/xfce_theme_draw.c b/src/xfce_theme_draw.c
index a50c692..1e0c0db 100644
--- a/src/xfce_theme_draw.c
+++ b/src/xfce_theme_draw.c
@@ -1706,6 +1706,93 @@ static void draw_handle(GtkStyle * style, GdkWindow * window, GtkStateType state
     xfce_draw_grips(style, window, state_type, area, widget, x, y, width, height, orientation);
 }
 
+static void draw_focus(GtkStyle * style, GdkWindow * window, GtkStateType state_type, GdkRectangle * area, GtkWidget * widget, const gchar * detail, gint x, gint y, gint width, gint height)
+{
+    cairo_t *cr;
+    gboolean free_dash_list = FALSE;
+    gint line_width = 1;
+    gint8 *dash_list = (gint8 *) "\1\1";
+
+    CHECK_ARGS;
+    SANITIZE_SIZE;
+
+    if (widget)
+    {
+        gtk_widget_style_get (widget,
+                "focus-line-width", &line_width,
+                "focus-line-pattern", (gchar *)&dash_list,
+                NULL);
+
+        free_dash_list = TRUE;
+    }
+
+    if (DETAIL("add-mode"))
+    {
+        if (free_dash_list)
+            g_free (dash_list);
+
+        dash_list = (gint8 *) "\4\4";
+        free_dash_list = FALSE;
+    }
+
+    cr = gdk_cairo_create (window);
+
+    if (DETAIL("colorwheel_light"))
+        cairo_set_source_rgb (cr, 0., 0., 0.);
+    else if (DETAIL("colorwheel_dark"))
+        cairo_set_source_rgb (cr, 1., 1., 1.);
+    else if (XFCE_RC_STYLE(style->rc_style)->flags & XFCE_RC_FOCUS_COLOR)
+        gdk_cairo_set_source_color (cr, &XFCE_RC_STYLE(style->rc_style)->focus_color);
+    else
+        gdk_cairo_set_source_color (cr, &style->fg[state_type]);
+
+    cairo_set_line_width (cr, line_width);
+
+    if (dash_list[0])
+    {
+        gint n_dashes = strlen ((const gchar *) dash_list);
+        gdouble *dashes = g_new (gdouble, n_dashes);
+        gdouble total_length = 0;
+        gdouble dash_offset;
+        gint i;
+
+        for (i = 0; i < n_dashes; i++)
+        {
+            dashes[i] = dash_list[i];
+            total_length += dash_list[i];
+        }
+
+        /* The dash offset here aligns the pattern to integer pixels
+         * by starting the dash at the right side of the left border
+         * Negative dash offsets in cairo don't work
+         * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
+         */
+        dash_offset = - line_width / 2.;
+        while (dash_offset < 0)
+            dash_offset += total_length;
+
+        cairo_set_dash (cr, dashes, n_dashes, dash_offset);
+        g_free (dashes);
+    }
+
+    if (area)
+    {
+        gdk_cairo_rectangle (cr, area);
+        cairo_clip (cr);
+    }
+
+    cairo_rectangle (cr,
+            x + line_width / 2.,
+            y + line_width / 2.,
+            width - line_width,
+            height - line_width);
+    cairo_stroke (cr);
+    cairo_destroy (cr);
+
+    if (free_dash_list)
+        g_free (dash_list);
+}
+
 GType xfce_type_style = 0;
 
 void xfce_style_register_type(GTypeModule * module)
@@ -1745,4 +1832,5 @@ static void xfce_style_class_init(XfceStyleClass * klass)
     style_class->draw_extension = draw_extension;
     style_class->draw_slider = draw_slider;
     style_class->draw_handle = draw_handle;
+    style_class->draw_focus = draw_focus;
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list