1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
diff -up gtk+-2.91.3/gtk/gtktooltip.c.fresh-tooltips gtk+-2.91.3/gtk/gtktooltip.c
--- gtk+-2.91.3/gtk/gtktooltip.c.fresh-tooltips 2010-10-31 14:28:19.000000000 -0400
+++ gtk+-2.91.3/gtk/gtktooltip.c 2010-11-01 14:12:41.027410023 -0400
@@ -35,6 +35,9 @@
#include "gtkalignment.h"
#include "gtksizerequest.h"
+#ifdef GDK_WINDOWING_X11
+#include "gdk/x11/gdkx.h"
+#endif
/**
* SECTION:gtktooltip
@@ -165,6 +168,7 @@ static void gtk_tooltip_display_cl
GtkTooltip *tooltip);
static void gtk_tooltip_set_last_window (GtkTooltip *tooltip,
GdkWindow *window);
+static void update_shape (GtkTooltip *tooltip);
G_DEFINE_TYPE (GtkTooltip, gtk_tooltip, G_TYPE_OBJECT);
@@ -180,6 +184,40 @@ gtk_tooltip_class_init (GtkTooltipClass
}
static void
+on_composited_changed (GtkWidget *window,
+ GtkTooltip *tooltip)
+{
+ update_shape (tooltip);
+}
+
+static void
+on_screen_changed (GtkWidget *window,
+ GdkScreen *previous,
+ GtkTooltip *tooltip)
+{
+ GdkScreen *screen;
+ GdkVisual *visual;
+
+ screen = gtk_widget_get_screen (window);
+
+
+ visual = NULL;
+ if (gdk_screen_is_composited (screen))
+ visual = gdk_screen_get_rgba_visual (screen);
+ if (visual == NULL)
+ visual = gdk_screen_get_system_visual (screen);
+
+ gtk_widget_set_visual (window, visual);
+}
+
+static void
+on_realized (GtkWidget *window,
+ GtkTooltip *tooltip)
+{
+ update_shape (tooltip);
+}
+
+static void
gtk_tooltip_init (GtkTooltip *tooltip)
{
GtkStyle *style;
@@ -199,8 +237,12 @@ gtk_tooltip_init (GtkTooltip *tooltip)
tooltip->last_window = NULL;
tooltip->window = g_object_ref (gtk_window_new (GTK_WINDOW_POPUP));
+
+ on_screen_changed (tooltip->window, NULL, tooltip);
+
gtk_window_set_type_hint (GTK_WINDOW (tooltip->window),
GDK_WINDOW_TYPE_HINT_TOOLTIP);
+
gtk_widget_set_app_paintable (tooltip->window, TRUE);
gtk_window_set_resizable (GTK_WINDOW (tooltip->window), FALSE);
gtk_widget_set_name (tooltip->window, "gtk-tooltip");
@@ -234,6 +276,13 @@ gtk_tooltip_init (GtkTooltip *tooltip)
gtk_box_pack_start (GTK_BOX (tooltip->box), tooltip->label,
FALSE, FALSE, 0);
+ g_signal_connect (tooltip->window, "composited-changed",
+ G_CALLBACK (on_composited_changed), tooltip);
+ g_signal_connect (tooltip->window, "screen-changed",
+ G_CALLBACK (on_screen_changed), tooltip);
+ g_signal_connect (tooltip->window, "realize",
+ G_CALLBACK (on_realized), tooltip);
+
tooltip->custom_widget = NULL;
}
@@ -583,19 +632,209 @@ gtk_tooltip_window_style_set (GtkTooltip
gtk_widget_queue_draw (tooltip->window);
}
+static void
+draw_round_rect (cairo_t *cr,
+ gdouble aspect,
+ gdouble x,
+ gdouble y,
+ gdouble corner_radius,
+ gdouble width,
+ gdouble height)
+{
+ gdouble radius = corner_radius / aspect;
+
+ cairo_move_to (cr, x + radius, y);
+
+ /* top-right, left of the corner */
+ cairo_line_to (cr, x + width - radius, y);
+
+ /* top-right, below the corner */
+ cairo_arc (cr,
+ x + width - radius, y + radius, radius,
+ -90.0f * G_PI / 180.0f, 0.0f * G_PI / 180.0f);
+
+ /* bottom-right, above the corner */
+ cairo_line_to (cr, x + width, y + height - radius);
+
+ /* bottom-right, left of the corner */
+ cairo_arc (cr,
+ x + width - radius, y + height - radius, radius,
+ 0.0f * G_PI / 180.0f, 90.0f * G_PI / 180.0f);
+
+ /* bottom-left, right of the corner */
+ cairo_line_to (cr, x + radius, y + height);
+
+ /* bottom-left, above the corner */
+ cairo_arc (cr,
+ x + radius, y + height - radius, radius,
+ 90.0f * G_PI / 180.0f, 180.0f * G_PI / 180.0f);
+
+ /* top-left, below the corner */
+ cairo_line_to (cr, x, y + radius);
+
+ /* top-left, right of the corner */
+ cairo_arc (cr,
+ x + radius, y + radius, radius,
+ 180.0f * G_PI / 180.0f, 270.0f * G_PI / 180.0f);
+
+ cairo_close_path (cr);
+}
+
+static void
+fill_background (GtkWidget *widget,
+ cairo_t *cr)
+{
+ GdkColor color;
+ gdouble r, g, b;
+ gint radius;
+ gdouble background_alpha;
+ GtkStyle *style;
+ GtkAllocation allocation;
+
+ if (gdk_screen_is_composited (gtk_widget_get_screen (widget)))
+ background_alpha = 0.90;
+ else
+ background_alpha = 1.0;
+
+ style = gtk_widget_get_style (widget);
+
+ radius = MIN (style->xthickness, style->ythickness);
+ radius = MAX (radius, 1);
+
+ cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
+ cairo_paint (cr);
+ cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+
+ gtk_widget_get_allocation (widget, &allocation);
+
+ draw_round_rect (cr,
+ 1.0, 0.5, 0.5, radius,
+ allocation.width - 1,
+ allocation.height - 1);
+
+ color = style->bg [GTK_STATE_NORMAL];
+ r = (float)color.red / 65535.0;
+ g = (float)color.green / 65535.0;
+ b = (float)color.blue / 65535.0;
+ cairo_set_source_rgba (cr, r, g, b, background_alpha);
+ cairo_fill_preserve (cr);
+
+ color = style->bg [GTK_STATE_SELECTED];
+ r = (float) color.red / 65535.0;
+ g = (float) color.green / 65535.0;
+ b = (float) color.blue / 65535.0;
+
+ cairo_set_source_rgba (cr, r, g, b, background_alpha);
+ cairo_set_line_width (cr, 1.0);
+ cairo_stroke (cr);
+}
+
+static void
+update_shape (GtkTooltip *tooltip)
+{
+ GdkScreen *screen;
+ cairo_t *cr;
+ cairo_surface_t *surface;
+ cairo_region_t *region;
+ gint width, height;
+ gboolean new_style;
+ gint radius;
+ GtkStyle *style;
+
+ gtk_widget_style_get (tooltip->window, "new-tooltip-style", &new_style, NULL);
+
+ if (!new_style)
+ {
+ gtk_widget_shape_combine_region (tooltip->window, NULL);
+ return;
+ }
+
+ screen = gtk_widget_get_screen (tooltip->window);
+ style = gtk_widget_get_style (tooltip->window);
+
+ gtk_window_get_size (GTK_WINDOW (tooltip->window), &width, &height);
+
+ if (gdk_screen_is_composited (screen))
+ {
+ const char *wm;
+
+ gtk_widget_shape_combine_region (tooltip->window, NULL);
+#ifdef GDK_WINDOWING_X11
+ /* This is a hack to keep the Metacity compositor from slapping a
+ * non-shaped shadow around the shaped tooltip
+ */
+ if (!gtk_widget_get_mapped (tooltip->window))
+ {
+ wm = gdk_x11_screen_get_window_manager_name (screen);
+ if (g_strcmp0 (wm, "Metacity") == 0)
+ gtk_window_set_type_hint (GTK_WINDOW (tooltip->window),
+ GDK_WINDOW_TYPE_HINT_DND);
+ }
+#endif
+ return;
+ }
+
+ radius = MIN (style->xthickness, style->ythickness);
+ radius = MAX (radius, 1);
+ surface = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);
+ cr = cairo_create (surface);
+ if (cairo_status (cr) == CAIRO_STATUS_SUCCESS)
+ {
+ cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
+ cairo_paint (cr);
+
+ cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+ cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+ draw_round_rect (cr, 1.0, 0, 0, radius + 1, width, height);
+ cairo_fill (cr);
+ region = gdk_cairo_region_create_from_surface (surface);
+ gtk_widget_shape_combine_region (tooltip->window, region);
+ cairo_region_destroy (region);
+ }
+ cairo_destroy (cr);
+ cairo_surface_destroy (surface);
+}
+
static gboolean
gtk_tooltip_paint_window (GtkTooltip *tooltip,
- cairo_t *cr)
+ cairo_t *context)
{
- gtk_paint_flat_box (gtk_widget_get_style (tooltip->window),
- cr,
- GTK_STATE_NORMAL,
- GTK_SHADOW_OUT,
- tooltip->window,
- "tooltip",
- 0, 0,
- gtk_widget_get_allocated_width (tooltip->window),
- gtk_widget_get_allocated_height (tooltip->window));
+ gboolean new_style;
+
+ gtk_widget_style_get (tooltip->window, "new-tooltip-style", &new_style, NULL);
+
+ if (new_style)
+ {
+ cairo_surface_t *surface;
+ cairo_t *cr;
+
+ cairo_set_operator (context, CAIRO_OPERATOR_SOURCE);
+ surface = cairo_surface_create_similar (cairo_get_target (context),
+ CAIRO_CONTENT_COLOR_ALPHA,
+ gtk_widget_get_allocated_width (tooltip->window),
+ gtk_widget_get_allocated_height (tooltip->window));
+ cr = cairo_create (surface);
+ fill_background (tooltip->window, cr);
+ cairo_destroy (cr);
+
+ cairo_set_source_surface (context, surface, 0, 0);
+ cairo_paint (context);
+ cairo_surface_destroy (surface);
+
+ update_shape (tooltip);
+ }
+ else
+ {
+ gtk_paint_flat_box (gtk_widget_get_style (tooltip->window),
+ context,
+ GTK_STATE_NORMAL,
+ GTK_SHADOW_OUT,
+ tooltip->window,
+ "tooltip",
+ 0, 0,
+ gtk_widget_get_allocated_width (tooltip->window),
+ gtk_widget_get_allocated_height (tooltip->window));
+ }
return FALSE;
}
diff -up gtk+-2.91.3/gtk/gtkwidget.c.fresh-tooltips gtk+-2.91.3/gtk/gtkwidget.c
--- gtk+-2.91.3/gtk/gtkwidget.c.fresh-tooltips 2010-11-01 09:17:21.000000000 -0400
+++ gtk+-2.91.3/gtk/gtkwidget.c 2010-11-01 14:11:38.921410003 -0400
@@ -3190,6 +3190,14 @@ gtk_widget_class_init (GtkWidgetClass *k
1, G_MAXINT, 16,
GTK_PARAM_READABLE));
+ gtk_widget_class_install_style_property (klass,
+ g_param_spec_boolean ("new-tooltip-style",
+ NULL,
+ NULL,
+ FALSE,
+ GTK_PARAM_READABLE));
+
+
g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
}
|