--- gnome-rr-labeler.c	2009-05-20 05:39:00.000000000 -0700
+++ /home/chergert/Projects/patches/gnome-rr-labeler.c	2009-08-06 21:16:09.126995644 -0700
@@ -38,6 +38,8 @@
 
 	GdkColor *palette;
 	GtkWidget **windows;
+
+	gboolean has_rgba;
 };
 
 struct _GnomeRRLabelerClass {
@@ -136,38 +138,109 @@
 	}
 }
 
+static void
+rounded_rectangle (cairo_t *cr,
+                   gint     x,
+                   gint     y,
+                   gint     width,
+                   gint     height,
+                   gint     x_radius,
+                   gint     y_radius)
+{
+	gint x1, x2;
+	gint y1, y2;
+	gint xr1, xr2;
+	gint yr1, yr2;
+
+	x1 = x;
+	x2 = x1 + width;
+	y1 = y;
+	y2 = y1 + height;
+
+	x_radius = MIN (x_radius, width / 2.0);
+	y_radius = MIN (y_radius, width / 2.0);
+
+	xr1 = x_radius;
+	xr2 = x_radius / 2.0;
+	yr1 = y_radius;
+	yr2 = y_radius / 2.0;
+
+	cairo_move_to    (cr, x1 + xr1, y1);
+	cairo_line_to    (cr, x2 - xr1, y1);
+	cairo_curve_to   (cr, x2 - xr2, y1, x2, y1 + yr2, x2, y1 + yr1);
+	cairo_line_to    (cr, x2, y2 - yr1);
+	cairo_curve_to   (cr, x2, y2 - yr2, x2 - xr2, y2, x2 - xr1, y2);
+	cairo_line_to    (cr, x1 + xr1, y2);
+	cairo_curve_to   (cr, x1 + xr2, y2, x1, y2 - yr2, x1, y2 - yr1);
+	cairo_line_to    (cr, x1, y1 + yr1);
+	cairo_curve_to   (cr, x1, y1 + yr2, x1 + xr2, y1, x1 + xr1, y1);
+	cairo_close_path (cr);
+}
+
 #define LABEL_WINDOW_EDGE_THICKNESS 2
 #define LABEL_WINDOW_PADDING 12
 
 static gboolean
 label_window_expose_event_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
 {
+	GnomeRRLabeler *labeler;
 	cairo_t *cr;
 	GdkColor *color;
 
+	labeler = data;
 	color = g_object_get_data (G_OBJECT (widget), "color");
 
 	cr = gdk_cairo_create (widget->window);
 
+	/* clip drawing area to event */
+
+	gdk_cairo_rectangle (cr, &event->area);
+	cairo_clip (cr);
+
+	/* clear background if needed */
+
+	if (labeler->has_rgba) {
+		cairo_save (cr);
+		cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
+		cairo_paint (cr);
+		cairo_restore (cr);
+	}
+
 	/* edge outline */
 
 	cairo_set_source_rgb (cr, 0, 0, 0);
-	cairo_rectangle (cr,
-			 LABEL_WINDOW_EDGE_THICKNESS / 2.0,
-			 LABEL_WINDOW_EDGE_THICKNESS / 2.0,
-			 widget->allocation.width - LABEL_WINDOW_EDGE_THICKNESS,
-			 widget->allocation.height - LABEL_WINDOW_EDGE_THICKNESS);
+	if (labeler->has_rgba)
+		rounded_rectangle (cr,
+		                   LABEL_WINDOW_EDGE_THICKNESS / 2.0,
+		                   LABEL_WINDOW_EDGE_THICKNESS / 2.0,
+		                   widget->allocation.width - LABEL_WINDOW_EDGE_THICKNESS,
+		                   widget->allocation.height - LABEL_WINDOW_EDGE_THICKNESS,
+		                   10, 10);
+	else
+		cairo_rectangle (cr,
+		                 LABEL_WINDOW_EDGE_THICKNESS / 2.0,
+		                 LABEL_WINDOW_EDGE_THICKNESS / 2.0,
+		                 widget->allocation.width - LABEL_WINDOW_EDGE_THICKNESS,
+		                 widget->allocation.height - LABEL_WINDOW_EDGE_THICKNESS);
 	cairo_set_line_width (cr, LABEL_WINDOW_EDGE_THICKNESS);
 	cairo_stroke (cr);
 
 	/* fill */
 
 	gdk_cairo_set_source_color (cr, color);
-	cairo_rectangle (cr,
-			 LABEL_WINDOW_EDGE_THICKNESS,
-			 LABEL_WINDOW_EDGE_THICKNESS,
-			 widget->allocation.width - LABEL_WINDOW_EDGE_THICKNESS * 2,
-			 widget->allocation.height - LABEL_WINDOW_EDGE_THICKNESS * 2);
+	if (labeler->has_rgba)
+		rounded_rectangle (cr,
+		                   LABEL_WINDOW_EDGE_THICKNESS,
+		                   LABEL_WINDOW_EDGE_THICKNESS,
+		                   widget->allocation.width - LABEL_WINDOW_EDGE_THICKNESS * 2,
+		                   widget->allocation.height - LABEL_WINDOW_EDGE_THICKNESS * 2,
+		                   10, 10);
+	else
+		cairo_rectangle (cr,
+		                 LABEL_WINDOW_EDGE_THICKNESS,
+		                 LABEL_WINDOW_EDGE_THICKNESS,
+		                 widget->allocation.width - LABEL_WINDOW_EDGE_THICKNESS * 2,
+		                 widget->allocation.height - LABEL_WINDOW_EDGE_THICKNESS * 2);
 	cairo_fill (cr);
 
 	cairo_destroy (cr);
@@ -182,10 +255,19 @@
 	GtkWidget *widget;
 	char *str;
 	GdkColor black = { 0, 0, 0, 0 };
+	GdkScreen *screen;
+	GdkColormap *colormap;
 
 	window = gtk_window_new (GTK_WINDOW_POPUP);
 	GTK_WIDGET_SET_FLAGS (window, GTK_APP_PAINTABLE);
 
+	/* setup rgba */
+	screen = gtk_widget_get_screen (window);
+	if (NULL != (colormap = gdk_screen_get_rgba_colormap (screen))) {
+		gtk_widget_set_default_colormap (colormap);
+		labeler->has_rgba = TRUE;
+	}
+
 	gtk_container_set_border_width (GTK_CONTAINER (window), LABEL_WINDOW_PADDING + LABEL_WINDOW_EDGE_THICKNESS);
 
 	/* This is semi-dangerous.  The color is part of the labeler->palette
