summaryrefslogtreecommitdiff
path: root/src/ui/theme.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/theme.c')
-rw-r--r--src/ui/theme.c129
1 files changed, 88 insertions, 41 deletions
diff --git a/src/ui/theme.c b/src/ui/theme.c
index a7dc8d08..c9f2ab47 100644
--- a/src/ui/theme.c
+++ b/src/ui/theme.c
@@ -64,11 +64,6 @@
#include <math.h>
#if GTK_CHECK_VERSION (3, 0, 0)
-#define MATE_DESKTOP_USE_UNSTABLE_API
-#include <libmate-desktop/mate-desktop-utils.h>
-#endif
-
-#if GTK_CHECK_VERSION (3, 0, 0)
#define GDK_COLOR_RGBA(color) \
((guint32) (0xff | \
((int)((color).red * 255) << 24) | \
@@ -1312,7 +1307,6 @@ meta_color_spec_new_from_string (const char *str,
spec = meta_color_spec_new (META_COLOR_SPEC_GTK);
spec->data.gtk.state = state;
spec->data.gtk.component = component;
- g_assert (spec->data.gtk.state < N_GTK_STATES);
g_assert (spec->data.gtk.component < META_GTK_COLOR_LAST);
}
else if (str[0] == 'b' && str[1] == 'l' && str[2] == 'e' && str[3] == 'n' &&
@@ -1488,6 +1482,72 @@ meta_color_spec_new_gtk (MetaGtkColorComponent component,
#if GTK_CHECK_VERSION (3, 0, 0)
static void
+get_background_color_real (GtkStyleContext *context,
+ GtkStateFlags state,
+ GdkRGBA *color)
+{
+ GdkRGBA *c;
+
+ g_return_if_fail (color != NULL);
+ g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
+
+ gtk_style_context_get (context,
+ state,
+ "background-color", &c,
+ NULL);
+
+ *color = *c;
+ gdk_rgba_free (c);
+}
+
+static void
+get_background_color (GtkStyleContext *context,
+ GtkStateFlags state,
+ GdkRGBA *color)
+{
+ GdkRGBA empty = { 0.0, 0.0, 0.0, 0.0 };
+ GdkRGBA rgba;
+
+ get_background_color_real (context, state, &rgba);
+
+ if (gdk_rgba_equal (&rgba, &empty))
+ {
+ GtkWidget *toplevel;
+ GtkStyleContext *tmp;
+
+ toplevel = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ tmp = gtk_widget_get_style_context (toplevel);
+
+ get_background_color_real (tmp, state, &rgba);
+
+ gtk_widget_destroy (toplevel);
+ }
+
+ *color = rgba;
+}
+
+/* Based on set_color() in gtkstyle.c */
+#define LIGHTNESS_MULT 1.3
+#define DARKNESS_MULT 0.7
+void
+meta_gtk_style_get_light_color (GtkStyleContext *style,
+ GtkStateFlags state,
+ GdkRGBA *color)
+{
+ get_background_color (style, state, color);
+ gtk_style_shade (color, color, LIGHTNESS_MULT);
+}
+
+void
+meta_gtk_style_get_dark_color (GtkStyleContext *style,
+ GtkStateFlags state,
+ GdkRGBA *color)
+{
+ get_background_color (style, state, color);
+ gtk_style_shade (color, color, DARKNESS_MULT);
+}
+
+static void
meta_set_color_from_style (GdkRGBA *color,
GtkStyleContext *context,
GtkStateFlags state,
@@ -1499,7 +1559,7 @@ meta_set_color_from_style (GdkRGBA *color,
{
case META_GTK_COLOR_BG:
case META_GTK_COLOR_BASE:
- gtk_style_context_get_background_color (context, state, color);
+ get_background_color (context, state, color);
break;
case META_GTK_COLOR_FG:
case META_GTK_COLOR_TEXT:
@@ -1514,18 +1574,18 @@ meta_set_color_from_style (GdkRGBA *color,
color->blue = (color->blue + other.blue) / 2;
break;
case META_GTK_COLOR_MID:
- mate_desktop_gtk_style_get_light_color (context, state, color);
- mate_desktop_gtk_style_get_dark_color (context, state, &other);
+ meta_gtk_style_get_light_color (context, state, color);
+ meta_gtk_style_get_dark_color (context, state, &other);
color->red = (color->red + other.red) / 2;
color->green = (color->green + other.green) / 2;
color->blue = (color->blue + other.blue) / 2;
break;
case META_GTK_COLOR_LIGHT:
- mate_desktop_gtk_style_get_light_color (context, state, color);
+ meta_gtk_style_get_light_color (context, state, color);
break;
case META_GTK_COLOR_DARK:
- mate_desktop_gtk_style_get_dark_color (context, state, color);
+ meta_gtk_style_get_dark_color (context, state, color);
break;
case META_GTK_COLOR_LAST:
g_assert_not_reached ();
@@ -3698,44 +3758,31 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
y2 = y1;
/* This is one of the cases where we are matching the exact
- * pixel aligned rectangle produced by X.
+ * pixel aligned rectangle produced by X; for zero-width lines
+ * the generic algorithm produces the right result so we don't
+ * need to handle them here.
*/
- if (y1 == y2 || x1 == x2)
+ if ((y1 == y2 || x1 == x2) && op->data.line.width != 0)
{
- double offset = (op->data.line.width == 0 ||
- op->data.line.width % 2) ? .5 : 0;
- /* X includes end points for lines of width 0 */
- double line_extend = op->data.line.width == 0 ? 1. : 0.;
+ double offset = op->data.line.width % 2 ? .5 : 0;
if (y1 == y2)
{
- if (x2 < x1)
- {
- x1 ^= x2;
- x2 ^= x1;
- x1 ^= x2;
- }
cairo_move_to (cr, x1, y1 + offset);
- cairo_line_to (cr, x2 + line_extend, y2 + offset);
+ cairo_line_to (cr, x2, y2 + offset);
}
else
{
- if (y2 < y1)
- {
- y1 ^= y2;
- y2 ^= y1;
- y1 ^= y2;
- }
cairo_move_to (cr, x1 + offset, y1);
- cairo_line_to (cr, x2 + offset, y2 + line_extend);
+ cairo_line_to (cr, x2 + offset, y2);
}
}
else
{
- if (op->data.line.width <= 0)
- {
- cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
- }
+ /* zero-width lines include both end-points in X, unlike wide lines */
+ if (op->data.line.width == 0)
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+
cairo_move_to (cr, x1 + .5, y1 + .5);
cairo_line_to (cr, x2 + .5, y2 + .5);
}
@@ -4745,10 +4792,10 @@ meta_frame_style_validate (MetaFrameStyle *style,
}
static void
-button_rect (MetaButtonType type,
- const MetaFrameGeometry *fgeom,
- int middle_background_offset,
- GdkRectangle *rect)
+get_button_rect (MetaButtonType type,
+ const MetaFrameGeometry *fgeom,
+ int middle_background_offset,
+ GdkRectangle *rect)
{
switch (type)
{
@@ -5068,7 +5115,7 @@ meta_frame_style_draw_with_style (MetaFrameStyle *style,
{
MetaButtonState button_state;
- button_rect (j, fgeom, middle_bg_offset, &rect);
+ get_button_rect (j, fgeom, middle_bg_offset, &rect);
button_state = map_button_state (j, fgeom, middle_bg_offset, button_states);
op_list = get_button (style, j, button_state);
@@ -5123,7 +5170,7 @@ meta_frame_style_draw_with_style (MetaFrameStyle *style,
{
MetaButtonState button_state;
- button_rect (j, fgeom, middle_bg_offset, &rect);
+ get_button_rect (j, fgeom, middle_bg_offset, &rect);
rect.x += x_offset;
rect.y += y_offset;