Mercurial > repos > other > Adwaita-Dark-Green
comparison gtk-2.0/adwaita_engine.c @ 0:a48477723cfe
Base Adwaita theme for GTK 3.16
https://github.com/GNOME/gnome-themes-standard/tree/gnome-3-14/themes/Adwaita @ 7c9d684
with gtk-3.0 directory replaced with
https://github.com/GNOME/gtk/tree/gtk-3-16/gtk/theme/Adwaita @ ff9ee56
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 09 Apr 2016 20:21:23 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a48477723cfe |
---|---|
1 /* Adwaita - a GTK+ engine | |
2 * | |
3 * Copyright (C) 2012 Red Hat, Inc. | |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2.1 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
18 * | |
19 * Authors: Cosimo Cecchi <cosimoc@gnome.org> | |
20 */ | |
21 | |
22 #include <gmodule.h> | |
23 #include <glib.h> | |
24 #include <gtk/gtk.h> | |
25 | |
26 #ifdef GDK_WINDOWING_X11 | |
27 #include <gdk/gdkx.h> | |
28 #endif | |
29 | |
30 /***************************************/ | |
31 /* Register & Initialize Drawing Style */ | |
32 /***************************************/ | |
33 #define ADWAITA_TYPE_STYLE (adwaita_style_get_type ()) | |
34 #define ADWAITA_STYLE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), ADWAITA_TYPE_STYLE, AdwaitaStyle)) | |
35 #define ADWAITA_STYLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ADWAITA_TYPE_STYLE, AdwaitaStyleClass)) | |
36 #define ADWAITA_IS_STYLE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), ADWAITA_TYPE_STYLE)) | |
37 #define ADWAITA_IS_STYLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ADWAITA_TYPE_STYLE)) | |
38 #define ADWAITA_STYLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ADWAITA_TYPE_STYLE, AdwaitaStyleClass)) | |
39 | |
40 typedef struct | |
41 { | |
42 GtkStyle parent_instance; | |
43 } AdwaitaStyle; | |
44 | |
45 typedef struct | |
46 { | |
47 GtkStyleClass parent_class; | |
48 } AdwaitaStyleClass; | |
49 | |
50 G_DEFINE_DYNAMIC_TYPE (AdwaitaStyle, adwaita_style, GTK_TYPE_STYLE) | |
51 | |
52 static void | |
53 do_toplevel_hack (GtkWidget *widget, | |
54 const gchar *widget_name) | |
55 { | |
56 gboolean tried_hack; | |
57 | |
58 tried_hack = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "adwaita-toplevel-hack")); | |
59 | |
60 if (!tried_hack) | |
61 { | |
62 g_object_set_data (G_OBJECT (widget), | |
63 "adwaita-toplevel-hack", GINT_TO_POINTER (1)); | |
64 gtk_widget_set_name (widget, widget_name); | |
65 } | |
66 } | |
67 | |
68 static gboolean | |
69 wm_is_fallback (void) | |
70 { | |
71 #ifdef GDK_WINDOWING_X11 | |
72 const gchar *name; | |
73 name = gdk_x11_screen_get_window_manager_name (gdk_screen_get_default ()); | |
74 return g_strcmp0 (name, "GNOME Shell") != 0; | |
75 #else | |
76 return TRUE; | |
77 #endif | |
78 } | |
79 | |
80 static cairo_t * | |
81 drawable_to_cairo (GdkDrawable *window, | |
82 GdkRectangle *area) | |
83 { | |
84 cairo_t *cr; | |
85 | |
86 g_return_val_if_fail (window != NULL, NULL); | |
87 | |
88 cr = (cairo_t*) gdk_cairo_create (window); | |
89 cairo_set_line_width (cr, 1.0); | |
90 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); | |
91 cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER); | |
92 | |
93 if (area) | |
94 { | |
95 cairo_rectangle (cr, area->x, area->y, area->width, area->height); | |
96 cairo_clip_preserve (cr); | |
97 cairo_new_path (cr); | |
98 } | |
99 | |
100 return cr; | |
101 } | |
102 | |
103 static void | |
104 adwaita_draw_box (GtkStyle * style, | |
105 GdkWindow * window, | |
106 GtkStateType state_type, | |
107 GtkShadowType shadow_type, | |
108 GdkRectangle * area, | |
109 GtkWidget * widget, | |
110 const gchar * detail, | |
111 gint x, | |
112 gint y, | |
113 gint width, | |
114 gint height) | |
115 { | |
116 if (GTK_IS_MENU (widget) && | |
117 g_strcmp0 (detail, "menu") == 0 && | |
118 wm_is_fallback ()) | |
119 { | |
120 cairo_t *cr = drawable_to_cairo (window, area); | |
121 cairo_pattern_t *pattern = cairo_pattern_create_linear (x, y, x, y + height); | |
122 gdouble stop_1, stop_2, stop_3; | |
123 | |
124 stop_1 = MIN (1.0, 6.0 / (gdouble) height); | |
125 stop_2 = MAX (stop_1, 0.33); | |
126 stop_3 = MAX (stop_2, 0.66); | |
127 | |
128 cairo_pattern_add_color_stop_rgba (pattern, 0.0, 0.66, 0.66, 0.66, 0.0); | |
129 cairo_pattern_add_color_stop_rgba (pattern, stop_1, 0.66, 0.66, 0.66, 0.25); | |
130 cairo_pattern_add_color_stop_rgba (pattern, stop_2, 0.66, 0.66, 0.66, 0.80); | |
131 cairo_pattern_add_color_stop_rgba (pattern, stop_3, 0.66, 0.66, 0.66, 1.0); | |
132 cairo_pattern_add_color_stop_rgba (pattern, 1.0, 0.66, 0.66, 0.66, 1.0); | |
133 cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); | |
134 | |
135 cairo_set_source (cr, pattern); | |
136 cairo_rectangle (cr, x, y, width, height); | |
137 cairo_stroke (cr); | |
138 | |
139 cairo_destroy (cr); | |
140 cairo_pattern_destroy (pattern); | |
141 } | |
142 else | |
143 { | |
144 GTK_STYLE_CLASS (adwaita_style_parent_class)->draw_box (style, window, state_type, shadow_type, | |
145 area, widget, detail, | |
146 x, y, width, height); | |
147 } | |
148 } | |
149 | |
150 void | |
151 adwaita_draw_flat_box (GtkStyle *style, | |
152 GdkWindow *window, | |
153 GtkStateType state_type, | |
154 GtkShadowType shadow_type, | |
155 GdkRectangle *area, | |
156 GtkWidget *widget, | |
157 const gchar *detail, | |
158 gint x, | |
159 gint y, | |
160 gint width, | |
161 gint height) | |
162 { | |
163 const gchar *app_name; | |
164 | |
165 GTK_STYLE_CLASS (adwaita_style_parent_class)->draw_flat_box (style, window, state_type, shadow_type, | |
166 area, widget, detail, | |
167 x, y, width, height); | |
168 | |
169 /* HACK: this is totally awful, but I don't see a better way to "tag" the OO.o hierarchy */ | |
170 if (!GTK_IS_WINDOW (widget) || | |
171 (gtk_window_get_window_type (GTK_WINDOW (widget)) != GTK_WINDOW_TOPLEVEL)) | |
172 return; | |
173 | |
174 app_name = g_get_application_name (); | |
175 if (g_str_has_prefix (app_name, "OpenOffice.org")) | |
176 do_toplevel_hack (widget, "openoffice-toplevel"); | |
177 else if (g_str_has_prefix (app_name, "LibreOffice")) | |
178 do_toplevel_hack (widget, "libreoffice-toplevel"); | |
179 } | |
180 | |
181 static void | |
182 adwaita_style_init (AdwaitaStyle *style) | |
183 { | |
184 } | |
185 | |
186 static void | |
187 adwaita_style_class_init (AdwaitaStyleClass * klass) | |
188 { | |
189 GtkStyleClass *style_class = GTK_STYLE_CLASS (klass); | |
190 | |
191 style_class->draw_box = adwaita_draw_box; | |
192 style_class->draw_flat_box = adwaita_draw_flat_box; | |
193 } | |
194 | |
195 static void | |
196 adwaita_style_class_finalize (AdwaitaStyleClass * klass) | |
197 { | |
198 } | |
199 | |
200 /**********************************/ | |
201 /* Register & Initialize RC Style */ | |
202 /**********************************/ | |
203 #define ADWAITA_TYPE_RC_STYLE (adwaita_rc_style_get_type ()) | |
204 #define ADWAITA_RC_STYLE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), ADWAITA_TYPE_RC_STYLE, AdwaitaRcStyle)) | |
205 #define ADWAITA_RC_STYLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ADWAITA_TYPE_RC_STYLE, AdwaitaRcStyleClass)) | |
206 #define ADWAITA_IS_RC_STYLE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), ADWAITA_TYPE_RC_STYLE)) | |
207 #define ADWAITA_IS_RC_STYLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ADWAITA_TYPE_RC_STYLE)) | |
208 #define ADWAITA_RC_STYLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ADWAITA_TYPE_RC_STYLE, AdwaitaRcStyleClass)) | |
209 | |
210 typedef struct | |
211 { | |
212 GtkRcStyle parent_instance; | |
213 } AdwaitaRcStyle; | |
214 | |
215 typedef struct | |
216 { | |
217 GtkRcStyleClass parent_class; | |
218 } AdwaitaRcStyleClass; | |
219 | |
220 G_DEFINE_DYNAMIC_TYPE (AdwaitaRcStyle, adwaita_rc_style, GTK_TYPE_RC_STYLE) | |
221 | |
222 static GtkStyle * | |
223 adwaita_rc_style_create_style (GtkRcStyle *rc_style) | |
224 { | |
225 return g_object_new (ADWAITA_TYPE_STYLE, NULL); | |
226 } | |
227 | |
228 static void | |
229 adwaita_rc_style_init (AdwaitaRcStyle *rc_style) | |
230 { | |
231 } | |
232 | |
233 static void | |
234 adwaita_rc_style_class_init (AdwaitaRcStyleClass * klass) | |
235 { | |
236 GtkRcStyleClass *rc_class = GTK_RC_STYLE_CLASS (klass); | |
237 | |
238 rc_class->create_style = adwaita_rc_style_create_style; | |
239 } | |
240 | |
241 static void | |
242 adwaita_rc_style_class_finalize (AdwaitaRcStyleClass * klass) | |
243 { | |
244 } | |
245 | |
246 /**************** | |
247 * Engine Hooks * | |
248 ****************/ | |
249 void | |
250 theme_init (GTypeModule * module) | |
251 { | |
252 adwaita_rc_style_register_type (module); | |
253 adwaita_style_register_type (module); | |
254 } | |
255 | |
256 void | |
257 theme_exit (void) | |
258 { | |
259 } | |
260 | |
261 GtkRcStyle * | |
262 theme_create_rc_style (void) | |
263 { | |
264 return g_object_new (ADWAITA_TYPE_RC_STYLE, NULL); | |
265 } |