[Xfce4-commits] <xfwm4:master> Add some fancy cairo-drawing if the compositor is in use FIXME: add theming possibilities for roundness, colors, border-width and alpha

Nick Schermer noreply at xfce.org
Sun Feb 23 21:10:02 CET 2014


Updating branch refs/heads/master
         to 413bccdc0f58cf3f7259b5b0e9c714b922ea3696 (commit)
       from 57249e54924c8a22d74a927e888cef621f13f434 (commit)

commit 413bccdc0f58cf3f7259b5b0e9c714b922ea3696
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date:   Thu Jul 11 10:53:33 2013 +0200

    Add some fancy cairo-drawing if the compositor is in use
    FIXME: add theming possibilities for roundness, colors, border-width and alpha

 src/tabwin.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/src/tabwin.c b/src/tabwin.c
index 3111fb0..ad949df 100644
--- a/src/tabwin.c
+++ b/src/tabwin.c
@@ -96,6 +96,44 @@ get_color (GtkWidget *win, GtkStateType state_type)
 }
 
 static gboolean
+tabwin_expose (GtkWidget *tbw, GdkEventExpose *event, gpointer data)
+{
+    GtkWindow *window;
+    GdkScreen *screen;
+    cairo_t *cr;
+    gint radius = 10.0;
+    double degrees = 3.14 / 180.0;
+    double width = tbw->allocation.width;
+    double height = tbw->allocation.height;
+
+    window = GTK_WINDOW(tbw);
+    screen = gtk_window_get_screen(window);
+
+    cr = gdk_cairo_create (tbw->window);
+    cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
+    gdk_cairo_region(cr, event->region);
+    cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.0);
+    cairo_fill_preserve(cr);
+    cairo_clip(cr);
+    cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+
+    //Draw a filled rounded rectangle with an outline
+    cairo_set_line_width (cr, 1.0);
+    cairo_arc (cr, width - radius - 0.5, radius + 0.5, radius, -90 * degrees, 0 * degrees);
+    cairo_arc (cr, width - radius - 0.5, height - radius - 0.5, radius, 0 * degrees, 90 * degrees);
+    cairo_arc (cr, radius + 0.5, height - radius - 0.5, radius, 90 * degrees, 180 * degrees);
+    cairo_arc (cr, radius + 0.5, radius + 0.5, radius, 180 * degrees, 270 * degrees);
+    cairo_close_path(cr);
+    cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.8);
+    cairo_fill_preserve (cr);
+    cairo_set_source_rgba (cr, 0.95, 0.95, 0.95, 0.3);
+    cairo_stroke (cr);
+
+    cairo_destroy (cr);
+    return FALSE;
+}
+
+static gboolean
 paint_selected (GtkWidget *w, GdkEventExpose *event, gpointer data)
 {
     g_return_val_if_fail (GTK_IS_WIDGET(w), FALSE);
@@ -351,6 +389,7 @@ static TabwinWidget *
 tabwinCreateWidget (Tabwin *tabwin, ScreenInfo *screen_info, gint monitor_num)
 {
     TabwinWidget *tbw;
+    GdkScreen *screen;
     GtkWidget *vbox;
     GtkWidget *windowlist;
     GdkRectangle monitor;
@@ -370,8 +409,19 @@ tabwinCreateWidget (Tabwin *tabwin, ScreenInfo *screen_info, gint monitor_num)
     gtk_widget_style_get (GTK_WIDGET (tbw), "border-width", &border_width, NULL);
     gtk_window_set_screen (GTK_WINDOW (tbw), screen_info->gscr);
     gtk_widget_set_name (GTK_WIDGET (tbw), "xfwm4-tabwin");
+
+    /* Only do the rounded corners and transparency if a compositor is in use */
+    screen = gtk_widget_get_screen(GTK_WIDGET(tbw));
+    if(gdk_screen_is_composited(screen)) {
+        g_signal_connect (tbw, "expose-event", GTK_SIGNAL_FUNC (tabwin_expose), (gpointer) tbw);
+        GdkColormap *cmap = gdk_screen_get_rgba_colormap(screen);
+        if(cmap)
+            gtk_widget_set_colormap(GTK_WIDGET(tbw), cmap);
+    }
+
     gtk_widget_realize (GTK_WIDGET (tbw));
     gtk_container_set_border_width (GTK_CONTAINER (tbw), 6);
+    gtk_widget_set_app_paintable(GTK_WIDGET(tbw), TRUE);
     gtk_window_set_position (GTK_WINDOW (tbw), GTK_WIN_POS_NONE);
     gdk_screen_get_monitor_geometry (screen_info->gscr, tbw->monitor_num, &monitor);
     gtk_window_move (GTK_WINDOW(tbw), monitor.x + monitor.width / 2,


More information about the Xfce4-commits mailing list