summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberts Muktupāvels <alberts.muktupavels@gmail.com>2015-04-05 23:02:21 +0300
committerAlberts Muktupāvels <alberts.muktupavels@gmail.com>2015-04-05 23:02:21 +0300
commit3aa71b77bf4c272b31d1e949d62fc31e8bd914c2 (patch)
treed53330a42c3767faa3cf0418d5249999a050b74f
parent8ed7571452b5f1a7a97b5a86632d632521500c73 (diff)
downloadmetacity-3aa71b77bf4c272b31d1e949d62fc31e8bd914c2.tar.gz
fixedtip: use a tooltip style
-rw-r--r--src/ui/fixedtip.c85
1 files changed, 42 insertions, 43 deletions
diff --git a/src/ui/fixedtip.c b/src/ui/fixedtip.c
index 1d2f5f09..2c6c58a7 100644
--- a/src/ui/fixedtip.c
+++ b/src/ui/fixedtip.c
@@ -33,34 +33,29 @@ static GtkWidget *tip = NULL;
* The actual text that gets displayed.
*/
static GtkWidget *label = NULL;
-/*
- * X coordinate of the right-hand edge of the screen.
- *
- * \bug This appears to be a bug; screen_right_edge is calculated only when
- * the window is redrawn. Actually we should never cache it because
- * different windows are different sizes.
- */
-static int screen_right_edge = 0;
-/*
- * Y coordinate of the bottom edge of the screen.
+
+/**
*
- * \bug As with screen_right_edge.
*/
-static int screen_bottom_edge = 0;
+static GdkScreen *screen = NULL;
-static gint
-draw_handler (GtkWidget *tooltips,
- cairo_t *cr,
- gpointer user_data)
+static gboolean
+draw_handler (GtkWidget *widget,
+ cairo_t *cr)
{
- if (tooltips != NULL)
- {
- gtk_render_background (gtk_widget_get_style_context (tooltips),
- cr,
- 0, 0,
- gtk_widget_get_allocated_width (tooltips),
- gtk_widget_get_allocated_height (tooltips));
- }
+ GtkStyleContext *context;
+ gint width;
+ gint height;
+
+ if (widget == NULL)
+ return FALSE;
+
+ context = gtk_widget_get_style_context (widget);
+ width = gtk_widget_get_allocated_width (widget);
+ height = gtk_widget_get_allocated_height (widget);
+
+ gtk_render_background (context, cr, 0, 0, width, height);
+ gtk_render_frame (context, cr, 0, 0, width, height);
return FALSE;
}
@@ -70,35 +65,34 @@ meta_fixed_tip_show (int screen_number,
int root_x, int root_y,
const char *markup_text)
{
- int w, h;
+ gint w;
+ gint h;
+ gint mon_num;
+ GdkRectangle monitor;
+ gint screen_right_edge;
if (tip == NULL)
{
+ GdkVisual *visual;
+
tip = gtk_window_new (GTK_WINDOW_POPUP);
+
gtk_window_set_type_hint (GTK_WINDOW(tip), GDK_WINDOW_TYPE_HINT_TOOLTIP);
+ gtk_style_context_add_class (gtk_widget_get_style_context (tip),
+ GTK_STYLE_CLASS_TOOLTIP);
+
+ screen = gdk_display_get_screen (gdk_display_get_default (), screen_number);
+ visual = gdk_screen_get_rgba_visual (screen);
- {
- GdkScreen *gdk_screen;
- GdkRectangle monitor;
- gint mon_num;
-
- gdk_screen = gdk_display_get_screen (gdk_display_get_default (),
- screen_number);
- gtk_window_set_screen (GTK_WINDOW (tip),
- gdk_screen);
- mon_num = gdk_screen_get_monitor_at_point (gdk_screen, root_x, root_y);
- gdk_screen_get_monitor_geometry (gdk_screen, mon_num, &monitor);
- screen_right_edge = monitor.x + monitor.width;
- screen_bottom_edge = monitor.y + monitor.height;
- }
+ gtk_window_set_screen (GTK_WINDOW (tip), screen);
+
+ if (visual != NULL)
+ gtk_widget_set_visual (tip, visual);
gtk_widget_set_app_paintable (tip, TRUE);
gtk_window_set_resizable (GTK_WINDOW (tip), FALSE);
- gtk_widget_set_name (tip, "gtk-tooltips");
- gtk_container_set_border_width (GTK_CONTAINER (tip), 4);
- g_signal_connect_swapped (tip, "draw",
- G_CALLBACK (draw_handler), NULL);
+ g_signal_connect (tip, "draw", G_CALLBACK (draw_handler), NULL);
label = gtk_label_new (NULL);
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
@@ -106,12 +100,17 @@ meta_fixed_tip_show (int screen_number,
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
gtk_widget_show (label);
+ gtk_container_set_border_width (GTK_CONTAINER (tip), 4);
gtk_container_add (GTK_CONTAINER (tip), label);
g_signal_connect (tip, "destroy",
G_CALLBACK (gtk_widget_destroyed), &tip);
}
+ mon_num = gdk_screen_get_monitor_at_point (screen, root_x, root_y);
+ gdk_screen_get_monitor_geometry (screen, mon_num, &monitor);
+ screen_right_edge = monitor.x + monitor.width;
+
gtk_label_set_markup (GTK_LABEL (label), markup_text);
gtk_window_get_size (GTK_WINDOW (tip), &w, &h);