[Xfce4-commits] [xfce/xfwm4] 02/04: Rework the cairo wireframe

noreply at xfce.org noreply at xfce.org
Mon Jan 19 22:54:31 CET 2015


This is an automated email from the git hooks/post-receive script.

olivier pushed a commit to branch master
in repository xfce/xfwm4.

commit 4d6d37888267ccd98f6c9f9768009688be13355b
Author: Olivier Fourdan <fourdan at xfce.org>
Date:   Mon Jan 19 22:16:44 2015 +0100

    Rework the cairo wireframe
    
    Signed-off-by: Olivier Fourdan <fourdan at xfce.org>
---
 src/cycle.c     |    6 +-
 src/wireframe.c |  267 +++++++++++++++++++++++++++++++++----------------------
 src/wireframe.h |   27 ++++--
 3 files changed, 188 insertions(+), 112 deletions(-)

diff --git a/src/cycle.c b/src/cycle.c
index 511fc1d..717fd8d 100644
--- a/src/cycle.c
+++ b/src/cycle.c
@@ -53,7 +53,7 @@ typedef struct _ClientCycleData ClientCycleData;
 struct _ClientCycleData
 {
     Tabwin *tabwin;
-    Window wireframe;
+    WireFrame *wireframe;
     gboolean inside;
 };
 
@@ -497,7 +497,7 @@ clientCycle (Client * c, XKeyEvent * ev)
         return;
     }
 
-    passdata.wireframe = None;
+    passdata.wireframe = NULL;
     passdata.inside = FALSE;
 
     TRACE ("entering cycle loop");
@@ -513,7 +513,7 @@ clientCycle (Client * c, XKeyEvent * ev)
     TRACE ("leaving cycle loop");
     if (passdata.wireframe)
     {
-        wireframeDelete (screen_info, passdata.wireframe);
+        wireframeDelete (passdata.wireframe);
     }
     updateXserverTime (display_info);
 
diff --git a/src/wireframe.c b/src/wireframe.c
index 477143d..dae7530 100644
--- a/src/wireframe.c
+++ b/src/wireframe.c
@@ -33,58 +33,23 @@
 #include <gdk/gdkx.h>
 #include <gtk/gtk.h>
 #include <libxfce4util/libxfce4util.h>
-#include <cairo.h>
-#include <cairo-xlib.h>
-
 #include "screen.h"
 #include "client.h"
 #include "frame.h"
+#include "ui_style.h"
 #include "wireframe.h"
 
 #ifndef OUTLINE_WIDTH
 #define OUTLINE_WIDTH 5
 #endif
 
-void
-wireframeUpdate (Client *c, Window xwindow)
+static void
+wireframeDrawXlib (WireFrame *wireframe)
 {
-    ScreenInfo *screen_info;
-    XVisualInfo xvisual_info;
-    Visual *xvisual;
-    cairo_surface_t *surface;
-    cairo_t *cr;
-    gboolean composited = FALSE;
-    gdouble rgba = 1.0;
-
-    g_return_if_fail (c != NULL);
-    g_return_if_fail (xwindow != None);
+    ScreenInfo *screen_info = wireframe->screen_info;
 
-    TRACE ("entering wireframeUpdate 0x%lx", xwindow);
-    screen_info = c->screen_info;
-    composited = screen_info->compositor_active;
-    if (composited)
-        rgba = 0.2;
-    XUnmapWindow (clientGetXDisplay (c), xwindow);
-    XMoveResizeWindow (clientGetXDisplay (c), xwindow,
-                       frameX (c), frameY (c), frameWidth (c), frameHeight (c));
-
-    if (XMatchVisualInfo (clientGetXDisplay (c), screen_info->screen,
-                          32, TrueColor, &xvisual_info))
-    {
-        /* RGBA window, if compositing is enabled */
-        xvisual = xvisual_info.visual;
-    }
-    else
-    {
-        xvisual = screen_info->visual;
-    }
-
-    surface = cairo_xlib_surface_create (clientGetXDisplay (c),
-                                         xwindow, xvisual,
-                                         frameWidth (c), frameHeight (c));
-    cr = cairo_create (surface);
-
-    if ((frameWidth (c) > OUTLINE_WIDTH * 2) && (frameHeight (c) > OUTLINE_WIDTH * 2))
+    XUnmapWindow (myScreenGetXDisplay (screen_info), wireframe->xwindow);
+    if ((wireframe->width > OUTLINE_WIDTH * 2) && (wireframe->height > OUTLINE_WIDTH * 2))
     {
         XRectangle xrect;
         Region inner_xregion;
@@ -95,8 +60,8 @@ wireframeUpdate (Client *c, Window xwindow)
 
         xrect.x = 0;
         xrect.y = 0;
-        xrect.width = frameWidth (c);
-        xrect.height = frameHeight (c);
+        xrect.width = wireframe->width;
+        xrect.height = wireframe->height;
         XUnionRectWithRegion (&xrect, outer_xregion, outer_xregion);
 
         xrect.x += OUTLINE_WIDTH;
@@ -108,64 +73,123 @@ wireframeUpdate (Client *c, Window xwindow)
 
         XSubtractRegion (outer_xregion, inner_xregion, outer_xregion);
 
-        if (composited == FALSE)
-            XShapeCombineRegion (clientGetXDisplay (c), xwindow, ShapeBounding,
-                                 0, 0, outer_xregion, ShapeSet);
+        XShapeCombineRegion (myScreenGetXDisplay (screen_info), wireframe->xwindow, ShapeBounding,
+                             0, 0, outer_xregion, ShapeSet);
 
         XDestroyRegion (outer_xregion);
         XDestroyRegion (inner_xregion);
-        XMapWindow (clientGetXDisplay (c), xwindow);
-
-        cairo_set_source_rgba (cr, 0, 0, 0, rgba);
-        cairo_paint (cr);
-
-        cairo_set_line_width (cr, 1);
-        cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
-        cairo_set_source_rgba (cr, rgba, rgba, rgba, rgba + 0.2);
-        cairo_rectangle (cr, 0.5, 0.5, frameWidth (c) - 1, frameHeight (c) - 1);
-        cairo_stroke (cr);
-
-        if (composited == FALSE)
-        {
-            cairo_rectangle (cr,
-                             OUTLINE_WIDTH - 0.5, OUTLINE_WIDTH - 0.5,
-                             frameWidth (c) - 2 * (OUTLINE_WIDTH - 1) - 1,
-                             frameHeight (c)- 2 * (OUTLINE_WIDTH - 1) - 1);
-            cairo_stroke (cr);
-        }
+        XMapWindow (myScreenGetXDisplay (screen_info), wireframe->xwindow);
+
+        XDrawRectangle (myScreenGetXDisplay (screen_info), wireframe->xwindow,
+                        gdk_x11_gc_get_xgc (screen_info->white_gc),
+                        0, 0, wireframe->width - 1, wireframe->height - 1);
+
+        XDrawRectangle (myScreenGetXDisplay (screen_info), wireframe->xwindow,
+                        gdk_x11_gc_get_xgc (screen_info->white_gc),
+                        OUTLINE_WIDTH - 1, OUTLINE_WIDTH - 1,
+                        wireframe->width - 2 * (OUTLINE_WIDTH - 1) - 1,
+                        wireframe->height- 2 * (OUTLINE_WIDTH - 1) - 1);
     }
     else
     {
         /* Unset the shape */
-        XShapeCombineMask (clientGetXDisplay (c), xwindow,
+        XShapeCombineMask (myScreenGetXDisplay (screen_info), wireframe->xwindow,
                            ShapeBounding, 0, 0, None, ShapeSet);
-        XMapWindow (clientGetXDisplay (c), xwindow);
+        XMapWindow (myScreenGetXDisplay (screen_info), wireframe->xwindow);
 
-        cairo_set_source_rgba (cr, 0, 0, 0, rgba);
-        cairo_paint (cr);
+        XDrawRectangle (myScreenGetXDisplay (screen_info), wireframe->xwindow,
+                        gdk_x11_gc_get_xgc (screen_info->white_gc),
+                        0, 0, wireframe->width - 1, wireframe->height - 1);
+    }
+    XFlush (myScreenGetXDisplay (screen_info));
+}
+
+static void
+wireframeDrawCairo (WireFrame *wireframe)
+{
+    ScreenInfo *screen_info = wireframe->screen_info;
+
+    cairo_xlib_surface_set_size(wireframe->surface, wireframe->width, wireframe->height);
+    XClearWindow (myScreenGetXDisplay (screen_info), wireframe->xwindow);
+    cairo_set_source_rgba (wireframe->cr, wireframe->red, wireframe->green, wireframe->blue, wireframe->alpha);
+    cairo_paint (wireframe->cr);
+
+    cairo_set_source_rgba (wireframe->cr, wireframe->red, wireframe->green, wireframe->blue, 1.0);
+    cairo_rectangle (wireframe->cr,
+                     OUTLINE_WIDTH - 0.5, OUTLINE_WIDTH - 0.5,
+                     wireframe->width - 2 * (OUTLINE_WIDTH - 1) - 1,
+                     wireframe->height- 2 * (OUTLINE_WIDTH - 1) - 1);
+    cairo_stroke (wireframe->cr);
+}
+
+void
+wireframeUpdate (Client *c, WireFrame *wireframe)
+{
+    ScreenInfo *screen_info;
+    int width, height;
+
+    g_return_if_fail (c != NULL);
+    g_return_if_fail (wireframe != NULL);
+    TRACE ("entering wireframeUpdate");
 
-        cairo_set_line_width (cr, 1);
-        cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
-        cairo_set_source_rgba (cr, rgba, rgba, rgba, rgba + 0.2);
-        cairo_rectangle (cr, 0.5, 0.5, frameWidth (c) - 1, frameHeight (c) - 1);
-        cairo_stroke (cr);
+    screen_info = wireframe->screen_info;
+    width = frameExtentWidth (c);
+    height = frameExtentHeight (c);
+
+    XMoveResizeWindow (myScreenGetXDisplay (screen_info), wireframe->xwindow,
+                       frameExtentX (c), frameExtentY (c), width, height);
+
+    if ((width == wireframe->width) && (height == wireframe->height))
+    {
+        /* Moving only */
+        return;
     }
+    wireframe->width = width;
+    wireframe->height = height;
 
-    cairo_destroy (cr);
-    cairo_surface_destroy (surface);
+    if (screen_info->compositor_active)
+    {
+         wireframeDrawCairo (wireframe);
+    }
+    else
+    {
+         wireframeDrawXlib (wireframe);
+    }
+}
+
+static void
+wireframeInitColor (WireFrame *wireframe)
+{
+    ScreenInfo *screen_info;
+    gchar *color;
+    GdkColor gcolor;
 
-    XFlush (clientGetXDisplay (c));
+    screen_info = wireframe->screen_info;
+    color = getUIStyle  (myScreenGetGtkWidget (screen_info), "bg", "selected");
+    if (gdk_color_parse (color, &gcolor))
+    {
+        wireframe->red   = (gdouble) gcolor.red / (gdouble) 65535;
+        wireframe->green = (gdouble) gcolor.green / (gdouble) 65535;
+        wireframe->blue  = (gdouble) gcolor.blue / (gdouble) 65535;
+    }
+    else
+    {
+        g_warning ("Cannot parse color %s", color);
+        wireframe->red   = 0.0;
+        wireframe->green = 0.5;
+        wireframe->blue  = 1.0;
+    }
+    g_free (color);
 }
 
-Window
+WireFrame *
 wireframeCreate (Client *c)
 {
     ScreenInfo *screen_info;
+    WireFrame *wireframe;
     XSetWindowAttributes attrs;
-    Window xwindow;
     XVisualInfo xvisual_info;
     Visual *xvisual;
-    Colormap xcolormap;
     int depth;
 
     g_return_val_if_fail (c != NULL, None);
@@ -173,48 +197,83 @@ wireframeCreate (Client *c)
     TRACE ("entering wireframeCreate");
 
     screen_info = c->screen_info;
-
-    if (XMatchVisualInfo (clientGetXDisplay (c), screen_info->screen,
+    wireframe = g_new0 (WireFrame, 1);
+    wireframe->screen_info = screen_info;
+    wireframe->width = 0;
+    wireframe->height = 0;
+    wireframe->cr = NULL;
+    wireframe->surface = NULL;
+    wireframe->alpha = (screen_info->compositor_active ? 0.5 : 1.0);
+
+    if (screen_info->compositor_active &&
+        XMatchVisualInfo (myScreenGetXDisplay (screen_info), screen_info->screen,
                           32, TrueColor, &xvisual_info))
     {
         xvisual = xvisual_info.visual;
         depth = xvisual_info.depth;
-        xcolormap = XCreateColormap (clientGetXDisplay (c), screen_info->xroot,
+        wireframe->xcolormap = XCreateColormap (myScreenGetXDisplay (screen_info), screen_info->xroot,
                                      xvisual, AllocNone);
     }
     else
     {
         xvisual = screen_info->visual;
         depth = screen_info->depth;
-        xcolormap = screen_info->cmap;
+        wireframe->xcolormap = screen_info->cmap;
     }
 
     attrs.override_redirect = True;
-    attrs.colormap = xcolormap;
-    attrs.background_pixel = BlackPixel (clientGetXDisplay (c),
+    attrs.colormap = wireframe->xcolormap;
+    attrs.background_pixel = BlackPixel (myScreenGetXDisplay (screen_info),
                                          screen_info->screen);
-    attrs.border_pixel = BlackPixel (clientGetXDisplay (c),
+    attrs.border_pixel = BlackPixel (myScreenGetXDisplay (screen_info),
                                      screen_info->screen);
-    xwindow = XCreateWindow (clientGetXDisplay (c),
-                             screen_info->xroot,
-                             frameX (c), frameY (c),
-                             frameWidth (c), frameHeight (c),
-                             0, depth, InputOutput,
-                             xvisual,
-                             CWOverrideRedirect | CWColormap | CWBackPixel | CWBorderPixel,
-                             &attrs);
-    wireframeUpdate (c, xwindow);
-
-    return (xwindow);
+    wireframe->xwindow = XCreateWindow (myScreenGetXDisplay (screen_info), screen_info->xroot,
+                                        frameExtentX (c), frameExtentY (c),
+                                        frameExtentWidth (c), frameExtentHeight (c),
+                                        0, depth, InputOutput, xvisual,
+                                        CWOverrideRedirect | CWColormap | CWBackPixel | CWBorderPixel,
+                                        &attrs);
+
+    if (screen_info->compositor_active)
+    {
+        /* Cairo */
+        wireframeInitColor (wireframe);
+        wireframe->surface = cairo_xlib_surface_create (myScreenGetXDisplay (screen_info),
+                                                        wireframe->xwindow, xvisual,
+                                                        frameExtentWidth (c), frameExtentHeight (c));
+        wireframe->cr = cairo_create (wireframe->surface);
+        cairo_set_line_width (wireframe->cr, OUTLINE_WIDTH);
+        cairo_set_line_join (wireframe->cr, CAIRO_LINE_JOIN_MITER);
+    }
+
+    XMapWindow (myScreenGetXDisplay (screen_info), wireframe->xwindow);
+    wireframeUpdate (c, wireframe);
+
+    return (wireframe);
 }
 
 void
-wireframeDelete (ScreenInfo *screen_info, Window xwindow)
+wireframeDelete (WireFrame *wireframe)
 {
-    g_return_if_fail (screen_info != NULL);
-    g_return_if_fail (xwindow != None);
+    ScreenInfo *screen_info;
 
-    TRACE ("entering wireframeDelete 0x%lx", xwindow);
-    XUnmapWindow (myScreenGetXDisplay (screen_info), xwindow);
-    XDestroyWindow (myScreenGetXDisplay (screen_info), xwindow);
+    g_return_if_fail (wireframe != None);
+    TRACE ("entering wireframeDelete");
+
+    screen_info = wireframe->screen_info;
+    XUnmapWindow (myScreenGetXDisplay (screen_info), wireframe->xwindow);
+    XDestroyWindow (myScreenGetXDisplay (screen_info), wireframe->xwindow);
+    if (wireframe->xcolormap != screen_info->cmap)
+    {
+        XFreeColormap (myScreenGetXDisplay (screen_info), wireframe->xcolormap);
+    }
+    if (wireframe->cr)
+    {
+        cairo_destroy (wireframe->cr);
+    }
+    if (wireframe->surface)
+    {
+        cairo_surface_destroy (wireframe->surface);
+    }
+    g_free (wireframe);
 }
diff --git a/src/wireframe.h b/src/wireframe.h
index 2fc10bf..ccc8e75 100644
--- a/src/wireframe.h
+++ b/src/wireframe.h
@@ -29,13 +29,30 @@
 #endif
 
 #include <X11/Xlib.h>
+#include <cairo.h>
+#include <cairo-xlib.h>
 #include "screen.h"
 #include "client.h"
 
-void                     wireframeUpdate                        (Client *c,
-                                                                 Window);
-Window                   wireframeCreate                        (Client *c);
-void                     wireframeDelete                        (ScreenInfo *,
-                                                                 Window);
+typedef struct _WireFrame WireFrame;
+struct _WireFrame
+{
+    ScreenInfo *screen_info;
+    Window xwindow;
+    int width;
+    int height;
+    Colormap xcolormap;
+    cairo_surface_t *surface;
+    cairo_t *cr;
+    gdouble red;
+    gdouble green;
+    gdouble blue;
+    gdouble alpha;
+};
+
+void                     wireframeUpdate                        (Client *,
+                                                                 WireFrame *);
+WireFrame *              wireframeCreate                        (Client *);
+void                     wireframeDelete                        (WireFrame *);
 
 #endif /* INC_WIREFRAME_H */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list