From 5f9b184aab1660868f9672f8b1af30714b223ca9 Mon Sep 17 00:00:00 2001
From: Olivier Fourdan <fourdan.olivier@wanadoo.fr>
Date: Sat, 29 Jan 2005 13:43:27 +0000
Subject: [PATCH] Internal reorg.

(Old svn revision: 12324)
---
 src/client.c     |  56 +++++++++++++-----------
 src/compositor.c |  20 +--------
 src/display.c    |  42 ++++++++++++++++--
 src/display.h    |  12 ++---
 src/events.c     |   5 +--
 src/frame.c      |   2 +-
 src/mypixmap.c   |  20 ++++++---
 src/mywindow.c   | 111 +++++++++++++++++++++++++++++------------------
 src/mywindow.h   |  11 ++---
 src/screen.c     |  12 ++---
 src/wireframe.c  |   1 -
 11 files changed, 171 insertions(+), 121 deletions(-)

diff --git a/src/client.c b/src/client.c
index fc8f3eb5c..83959b07d 100644
--- a/src/client.c
+++ b/src/client.c
@@ -1345,7 +1345,7 @@ clientCheckShape (Client * c)
     screen_info = c->screen_info;
     display_info = screen_info->display_info;
 
-    if (display_info->shape)
+    if (display_info->have_shape)
     {
         XShapeQueryExtents (display_info->dpy, c->window, &boundingShaped, &xws, &yws, &wws,
                             &hws, &clipShaped, &xbs, &ybs, &wbs, &hbs);
@@ -1485,13 +1485,21 @@ clientFrame (DisplayInfo *display_info, Window w, gboolean recapture)
     c->y = attr.y;
     c->width = attr.width;
     c->height = attr.height;
-#ifdef HAVE_COMPOSITOR
-    c->visual = attr.visual;
-    c->depth = attr.depth;
+#ifdef HAVE_RENDER
+    if (display_info->have_render)
+    {
+        c->visual = attr.visual;
+        c->depth  = attr.depth;
+    }
+    else
+    {
+        c->visual = screen_info->visual;
+        c->depth  = screen_info->depth;
+    }
 #else
-    /* We don't support multiple depth/visual w/out compositor */
-    c->visual = DefaultVisual (display_info->dpy, screen_info->screen);
-    c->depth = DefaultDepth (display_info->dpy, screen_info->screen);
+    /* We don't support multiple depth/visual w/out render */
+    c->visual = screen_info->visual;
+    c->depth  = screen_info->depth;
 #endif
     clientGetWMNormalHints (c, FALSE);
 
@@ -1639,6 +1647,7 @@ clientFrame (DisplayInfo *display_info, Window w, gboolean recapture)
     attributes.win_gravity = StaticGravity;
     attributes.bit_gravity = StaticGravity;
     attributes.colormap = attr.colormap;
+
 #ifdef HAVE_COMPOSITOR
     if (c->depth == 32)
     {
@@ -1648,11 +1657,11 @@ clientFrame (DisplayInfo *display_info, Window w, gboolean recapture)
         valuemask |= CWBackPixmap|CWBackPixel|CWBorderPixel;
     }
 #endif
-    
+
     c->frame =
         XCreateWindow (display_info->dpy, screen_info->xroot, 0, 0, 1, 1, 0, 
         c->depth, InputOutput, c->visual, valuemask, &attributes);
-        
+
     XSelectInput (display_info->dpy, c->window, 0);
     XSetWindowBorderWidth (display_info->dpy, c->window, 0);
     XReparentWindow (display_info->dpy, c->window, c->frame, frameLeft (c), frameTop (c));
@@ -1661,7 +1670,7 @@ clientFrame (DisplayInfo *display_info, Window w, gboolean recapture)
     attributes.event_mask = (CLIENT_EVENT_MASK);
     XChangeWindowAttributes (display_info->dpy, c->window, valuemask, &attributes);
     XSelectInput (display_info->dpy, c->window, CLIENT_EVENT_MASK);
-    if ((shaped) && (display_info->shape))
+    if ((shaped) && (display_info->have_shape))
     {
         XShapeSelectInput (display_info->dpy, c->window, ShapeNotifyMask);
     }
@@ -1683,32 +1692,32 @@ clientFrame (DisplayInfo *display_info, Window w, gboolean recapture)
     c->pm_cache.previous_width = -1;
     c->pm_cache.previous_height = -1;
 
-    xfwmWindowCreate (display_info->dpy, screen_info->screen, c->visual, c->depth, c->frame,  
+    xfwmWindowCreate (screen_info, c->visual, c->depth, c->frame,  
         &c->sides[SIDE_LEFT], 
         myDisplayGetCursorResize(screen_info->display_info, 4 + SIDE_LEFT));
-    xfwmWindowCreate (display_info->dpy, screen_info->screen, c->visual, c->depth, c->frame,  
+    xfwmWindowCreate (screen_info,  c->visual, c->depth, c->frame,  
         &c->sides[SIDE_RIGHT],
         myDisplayGetCursorResize(screen_info->display_info, 4 + SIDE_RIGHT));
-    xfwmWindowCreate (display_info->dpy, screen_info->screen, c->visual, c->depth, c->frame,  
+    xfwmWindowCreate (screen_info,  c->visual, c->depth, c->frame,  
         &c->sides[SIDE_BOTTOM],
         myDisplayGetCursorResize(screen_info->display_info, 4 + SIDE_BOTTOM));
-    xfwmWindowCreate (display_info->dpy, screen_info->screen, c->visual, c->depth, c->frame,  
+    xfwmWindowCreate (screen_info,  c->visual, c->depth, c->frame,  
         &c->corners[CORNER_BOTTOM_LEFT],
         myDisplayGetCursorResize(screen_info->display_info, CORNER_BOTTOM_LEFT));
-    xfwmWindowCreate (display_info->dpy, screen_info->screen, c->visual, c->depth, c->frame,  
+    xfwmWindowCreate (screen_info,  c->visual, c->depth, c->frame,  
         &c->corners[CORNER_BOTTOM_RIGHT],
         myDisplayGetCursorResize(screen_info->display_info, CORNER_BOTTOM_RIGHT));
-    xfwmWindowCreate (display_info->dpy, screen_info->screen, c->visual, c->depth, c->frame,  
+    xfwmWindowCreate (screen_info,  c->visual, c->depth, c->frame,  
         &c->corners[CORNER_TOP_LEFT],
         myDisplayGetCursorResize(screen_info->display_info, CORNER_TOP_LEFT));
-    xfwmWindowCreate (display_info->dpy, screen_info->screen, c->visual, c->depth, c->frame,  
+    xfwmWindowCreate (screen_info,  c->visual, c->depth, c->frame,  
         &c->corners[CORNER_TOP_RIGHT],
         myDisplayGetCursorResize(screen_info->display_info, CORNER_TOP_RIGHT));
-    xfwmWindowCreate (display_info->dpy, screen_info->screen, c->visual, c->depth, c->frame,  
+    xfwmWindowCreate (screen_info,  c->visual, c->depth, c->frame,  
         &c->title, None);
     for (i = 0; i < BUTTON_COUNT; i++)
     {
-        xfwmWindowCreate (display_info->dpy, screen_info->screen, c->visual, c->depth, c->frame, 
+        xfwmWindowCreate (screen_info,  c->visual, c->depth, c->frame, 
             &c->buttons[i], None);
     }
 
@@ -1874,8 +1883,7 @@ clientFrameAll (ScreenInfo *screen_info)
 
     display_info = screen_info->display_info;
     clientSetFocus (screen_info, NULL, CurrentTime, NO_FOCUS_FLAG);
-    xfwmWindowTemp (display_info->dpy, 
-                    screen_info->screen,
+    xfwmWindowTemp (screen_info,
                     NULL, 0,
                     screen_info->xroot,
                     &shield, 
@@ -3181,8 +3189,7 @@ clientMove (Client * c, XEvent * e)
     passdata.grab = FALSE;
     passdata.is_transient = clientIsValidTransientOrModal (c);
 
-    xfwmWindowTemp (display_info->dpy, 
-                    screen_info->screen,
+    xfwmWindowTemp (screen_info,
                     NULL, 0,
                     screen_info->xroot,
                     &passdata.tmp_event_window, 
@@ -3654,8 +3661,7 @@ clientResize (Client * c, int corner, XEvent * e)
     passdata.grab = FALSE;
     passdata.corner = corner;
 
-    xfwmWindowTemp (display_info->dpy, 
-                    screen_info->screen,
+    xfwmWindowTemp (screen_info,
                     NULL, 0,
                     screen_info->xroot,
                     &passdata.tmp_event_window, 
diff --git a/src/compositor.c b/src/compositor.c
index a3432fe9f..36613257c 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -1449,7 +1449,7 @@ add_win (DisplayInfo *display_info, Window id, Client *c, guint opacity)
     }
 
     /* Listen for XShape events if applicable */
-    if (display_info->shape)
+    if (display_info->have_shape)
     {
         XShapeSelectInput (display_info->dpy, id, ShapeNotifyMask);
     }
@@ -2142,24 +2142,6 @@ compositorInitDisplay (DisplayInfo *display_info)
     g_return_if_fail (display_info != NULL);
     TRACE ("entering compositorInitDisplay");
 
-    if (!XRenderQueryExtension (display_info->dpy,
-                                &display_info->render_event_base,
-                                &display_info->render_error_base))
-    {
-        g_warning ("The display does not support the XRender extension.");
-        display_info->have_render = FALSE;
-        display_info->render_event_base = 0;
-        display_info->render_error_base = 0;
-    }
-    else
-    {
-        display_info->have_render = TRUE;
-#if DEBUG
-        g_print ("render event base: %i\n", display_info->render_event_base);
-        g_print ("render error base: %i\n", display_info->render_error_base);
-#endif
-    }
-
     if (!XCompositeQueryExtension (display_info->dpy,
                                 &display_info->composite_event_base,
                                 &display_info->composite_error_base))
diff --git a/src/display.c b/src/display.c
index 6caeb3bb4..18eefed49 100644
--- a/src/display.c
+++ b/src/display.c
@@ -172,11 +172,31 @@ myDisplayInit (GdkDisplay *gdisplay)
     }
 
     /* Test XShape extension support */
-    display->shape = 
-        XShapeQueryExtension (display->dpy, &display->shape_event, &dummy);
-    if (!display->shape)
+    if (XShapeQueryExtension (display->dpy, 
+                              &display->shape_event_base, 
+                              &dummy))
+    {
+        display->have_shape = TRUE;
+    }
+    else
     {
         g_warning ("The display does not support the XShape extension.");
+        display->have_shape = FALSE;
+        display->shape_event_base = 0;
+    }
+
+    if (XRenderQueryExtension (display->dpy,
+                               &display->render_event_base,
+                               &display->render_error_base))
+    {
+        display->have_render = TRUE;
+    }
+    else
+    {
+        g_warning ("The display does not support the XRender extension.");
+        display->have_render = FALSE;
+        display->render_event_base = 0;
+        display->render_error_base = 0;
     }
 
     display->root_cursor = 
@@ -240,6 +260,22 @@ myDisplayClose (DisplayInfo *display)
     return display;
 }
 
+gboolean
+myDisplayHaveShape (DisplayInfo *display)
+{
+    g_return_val_if_fail (display != NULL, FALSE);
+    
+    return (display->have_shape);
+}
+
+gboolean
+myDisplayHaveRender (DisplayInfo *display)
+{
+    g_return_val_if_fail (display != NULL, FALSE);
+    
+    return (display->have_render);
+}
+
 Cursor 
 myDisplayGetCursorBusy (DisplayInfo *display)
 {
diff --git a/src/display.h b/src/display.h
index 94124315b..08641d912 100644
--- a/src/display.h
+++ b/src/display.h
@@ -174,8 +174,11 @@ struct _DisplayInfo
     GSList *screens;
     GSList *clients;
 
-    gint shape;
-    gint shape_event;
+    gboolean have_shape;
+    gboolean have_render;
+    gint shape_event_base;
+    gint render_error_base;
+    gint render_event_base;
     gint dbl_click_time;
     gint xgrabcount;
     gint nb_screens;
@@ -185,8 +188,6 @@ struct _DisplayInfo
     gboolean enable_compositor;
 
 #ifdef HAVE_COMPOSITOR
-    gint render_error_base;
-    gint render_event_base;
     gint composite_error_base;
     gint composite_event_base;
     gint damage_error_base;
@@ -194,7 +195,6 @@ struct _DisplayInfo
     gint fixes_error_base;
     gint fixes_event_base;
 
-    gboolean have_render;
     gboolean have_composite;
     gboolean have_damage;
     gboolean have_fixes;
@@ -211,6 +211,8 @@ struct _DisplayInfo
 
 DisplayInfo * myDisplayInit                 (GdkDisplay *); 
 DisplayInfo * myDisplayClose                (DisplayInfo *);
+gboolean      myDisplayHaveShape            (DisplayInfo *);
+gboolean      myDisplayHaveRender           (DisplayInfo *);
 Cursor        myDisplayGetCursorBusy        (DisplayInfo *);
 Cursor        myDisplayGetCursorMove        (DisplayInfo *);
 Cursor        myDisplayGetCursorRoot        (DisplayInfo *);
diff --git a/src/events.c b/src/events.c
index 574318bc0..0068590bd 100644
--- a/src/events.c
+++ b/src/events.c
@@ -2015,7 +2015,7 @@ handleEvent (DisplayInfo *display_info, XEvent * ev)
             handleColormapNotify (display_info, (XColormapEvent *) ev);
             break;
         default:
-            if (display_info->shape && (ev->type == display_info->shape_event))
+            if (display_info->have_shape && (ev->type == display_info->shape_event_base))
             {
                 handleShape (display_info, (XShapeEvent *) ev);
             }
@@ -2291,8 +2291,7 @@ show_popup_cb (GtkWidget * widget, GdkEventButton * ev, gpointer data)
        Don't forget to delete that window once the menu is closed, though, or we'll get in
        trouble.
      */
-    xfwmWindowTemp (clientGetXDisplay (c),  
-                    screen_info->screen,
+    xfwmWindowTemp (screen_info,  
                     NULL, 0,
                     screen_info->xroot,
                     &menu_event_window, 0, 0, 
diff --git a/src/frame.c b/src/frame.c
index 00980cffb..f9f95dd0d 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -517,7 +517,7 @@ frameSetShape (Client * c, int state, ClientPixmapCache * pm_cache, int button_x
     TRACE ("entering frameSetShape");
     TRACE ("setting shape for client (0x%lx)", c->window);
 
-    if (!display_info->shape)
+    if (!display_info->have_shape)
     {
         return;
     }
diff --git a/src/mypixmap.c b/src/mypixmap.c
index fbe0c5688..6e2308303 100644
--- a/src/mypixmap.c
+++ b/src/mypixmap.c
@@ -159,7 +159,9 @@ xfwmPixmapLoad (ScreenInfo * screen_info, xfwmPixmap * pm, gchar * dir, gchar *
     {
         attr.valuemask = attr.valuemask | XpmColorSymbols;
     }
-    if (XpmReadFileToPixmap (myScreenGetXDisplay (screen_info), screen_info->xroot, filename, &pm->pixmap, &pm->mask, &attr))
+    if (XpmReadFileToPixmap (myScreenGetXDisplay (screen_info), 
+                             screen_info->xroot, filename, 
+                             &pm->pixmap, &pm->mask, &attr))
     {
         TRACE ("%s not found", filename);
         g_free (filename);
@@ -177,7 +179,8 @@ xfwmPixmapLoad (ScreenInfo * screen_info, xfwmPixmap * pm, gchar * dir, gchar *
 }
 
 void
-xfwmPixmapCreate (ScreenInfo * screen_info, xfwmPixmap * pm, gint width, gint height)
+xfwmPixmapCreate (ScreenInfo * screen_info, xfwmPixmap * pm, 
+                  gint width, gint height)
 {
     TRACE ("entering xfwmPixmapCreate, width=%i, height=%i", width, height);
     if ((width < 1) || (height < 1) || (!screen_info))
@@ -187,8 +190,11 @@ xfwmPixmapCreate (ScreenInfo * screen_info, xfwmPixmap * pm, gint width, gint he
     else
     {
         pm->screen_info = screen_info;
-        pm->pixmap = XCreatePixmap (myScreenGetXDisplay (screen_info), screen_info->xroot, width, height, screen_info->depth);
-        pm->mask = XCreatePixmap (myScreenGetXDisplay (screen_info), pm->pixmap, width, height, 1);
+        pm->pixmap = XCreatePixmap (myScreenGetXDisplay (screen_info), 
+                                    screen_info->xroot, 
+                                    width, height, screen_info->depth);
+        pm->mask = XCreatePixmap (myScreenGetXDisplay (screen_info), 
+                                  pm->pixmap, width, height, 1);
         pm->width = width;
         pm->height = height;
     }
@@ -223,7 +229,8 @@ xfwmPixmapFree (xfwmPixmap * pm)
 }
 
 static void
-xfwmPixmapFillRectangle (Display *dpy, int screen, Pixmap pm, Drawable d, int x, int y, int width, int height)
+xfwmPixmapFillRectangle (Display *dpy, int screen, Pixmap pm, Drawable d, 
+                         int x, int y, int width, int height)
 {
     XGCValues gv;
     GC gc;
@@ -254,7 +261,8 @@ xfwmPixmapFillRectangle (Display *dpy, int screen, Pixmap pm, Drawable d, int x,
 }
 
 void
-xfwmPixmapFill (xfwmPixmap * src, xfwmPixmap * dst, gint x, gint y, gint width, gint height)
+xfwmPixmapFill (xfwmPixmap * src, xfwmPixmap * dst, 
+                gint x, gint y, gint width, gint height)
 {
     XGCValues gv;
     GC gc;
diff --git a/src/mywindow.c b/src/mywindow.c
index b0819ba20..caccbec2f 100644
--- a/src/mywindow.c
+++ b/src/mywindow.c
@@ -31,6 +31,7 @@
 #include <libxfce4util/libxfce4util.h> 
 #include "mypixmap.h"
 #include "mywindow.h"
+#include "screen.h"
 
 #ifdef HAVE_RENDER
 #include <X11/extensions/Xrender.h>
@@ -39,13 +40,15 @@
 static void
 xfwmWindowSetVisual (xfwmWindow * win, Visual *visual, gint depth)
 {
+    g_return_if_fail (win->screen_info != NULL);
+    
     if (visual)
     {
         win->visual = visual;
     }
     else
     {
-        win->visual = DefaultVisual (win->dpy, win->screen);
+        win->visual = win->screen_info->visual;
     }
     
     if (depth)
@@ -54,16 +57,18 @@ xfwmWindowSetVisual (xfwmWindow * win, Visual *visual, gint depth)
     }
     else
     {
-        win->depth = DefaultDepth (win->dpy, win->screen);
+        win->depth = win->screen_info->depth;
     }
 }
 
 void
 xfwmWindowInit (xfwmWindow * win)
 {
+    g_return_if_fail (win != NULL);
+    
     win->window = None;
     win->map = FALSE;
-    win->dpy = NULL;
+    win->screen_info = NULL;
     win->depth = 0;
     win->x = 0;
     win->y = 0;
@@ -72,21 +77,23 @@ xfwmWindowInit (xfwmWindow * win)
 }
 
 void
-xfwmWindowCreate (Display * dpy, gint screen, Visual *visual, gint depth, Window parent,  
+xfwmWindowCreate (ScreenInfo * screen_info, Visual *visual, gint depth, Window parent,  
                   xfwmWindow * win, Cursor cursor)
 {
     TRACE ("entering xfwmWindowCreate");
 
-    win->window = XCreateSimpleWindow (dpy, parent, 0, 0, 1, 1, 0, 0, 0);
+    g_return_if_fail (screen_info != NULL);
+    
+    win->window = XCreateSimpleWindow (myScreenGetXDisplay (screen_info), 
+                                       parent, 0, 0, 1, 1, 0, 0, 0);
     TRACE ("Created XID 0x%lx", win->window);
     if (cursor != None)
     {
-        XDefineCursor (dpy, win->window, cursor);
+        XDefineCursor (myScreenGetXDisplay (screen_info), 
+                       win->window, cursor);
     }
     win->map = FALSE;
-    win->dpy = dpy;
-    win->depth = depth;
-    win->screen = screen;
+    win->screen_info = screen_info;
     win->x = 0;
     win->y = 0;
     win->width = 1;
@@ -101,7 +108,8 @@ xfwmWindowDelete (xfwmWindow * win)
 
     if (win->window != None)
     {
-        XDestroyWindow (win->dpy, win->window);
+        XDestroyWindow (myScreenGetXDisplay (win->screen_info), 
+                        win->window);
         win->window = None;
     }
     win->map = FALSE;
@@ -124,15 +132,18 @@ xfwmWindowShow (xfwmWindow * win, int x, int y, int width, int height,
     }
     if (!(win->map))
     {
-        XMapWindow (win->dpy, win->window);
+        XMapWindow (myScreenGetXDisplay (win->screen_info), 
+                    win->window);
         win->map = TRUE;
     }
     TRACE ("Showing XID 0x%lx", win->window);
     if (((x != win->x) || (y != win->y)) && ((width != win->width)
             || (height != win->height)))
     {
-        XMoveResizeWindow (win->dpy, win->window, x, y, (unsigned int) width,
-            (unsigned int) height);
+        XMoveResizeWindow (myScreenGetXDisplay (win->screen_info), 
+                           win->window, x, y, 
+                           (unsigned int) width,
+                           (unsigned int) height);
         win->x = x;
         win->y = y;
         win->width = width;
@@ -140,24 +151,30 @@ xfwmWindowShow (xfwmWindow * win, int x, int y, int width, int height,
     }
     else if ((x != win->x) || (y != win->y))
     {
-        XMoveWindow (win->dpy, win->window, x, y);
+        XMoveWindow (myScreenGetXDisplay (win->screen_info), 
+                     win->window, 
+                     x, y);
         if (refresh)
         {
-            XClearWindow (win->dpy, win->window);
+            XClearWindow (myScreenGetXDisplay (win->screen_info), 
+                          win->window);
         }
         win->x = x;
         win->y = y;
     }
     else if ((width != win->width) || (height != win->height))
     {
-        XResizeWindow (win->dpy, win->window, (unsigned int) width,
-            (unsigned int) height);
+        XResizeWindow (myScreenGetXDisplay (win->screen_info), 
+                       win->window, 
+                       (unsigned int) width,
+                       (unsigned int) height);
         win->width = width;
         win->height = height;
     }
     else if (refresh)
     {
-        XClearWindow (win->dpy, win->window);
+        XClearWindow (myScreenGetXDisplay (win->screen_info), 
+                      win->window);
     }
 }
 
@@ -169,7 +186,7 @@ xfwmWindowHide (xfwmWindow * win)
     if (win->map)
     {
         g_assert (win->window);
-        XUnmapWindow (win->dpy, win->window);
+        XUnmapWindow (myScreenGetXDisplay (win->screen_info), win->window);
         win->map = FALSE;
     }
 }
@@ -191,23 +208,26 @@ xfwmWindowDeleted (xfwmWindow *win)
 }        
 
 void 
-xfwmWindowTemp (Display * dpy, gint screen, Visual *visual, gint depth, Window parent,
-                xfwmWindow * win, int x, int y, 
-                int width, int height, long eventmask)
+xfwmWindowTemp (ScreenInfo *screen_info, Visual *visual, 
+                gint depth, Window parent,
+                xfwmWindow * win, 
+                int x, int y, int width, int height, 
+                long eventmask)
 {
     XSetWindowAttributes attributes;
 
     attributes.event_mask = eventmask;
     attributes.override_redirect = TRUE;
-    win->window = XCreateWindow (dpy, parent, x, y, width, height, 0, 0, 
-                         InputOnly, CopyFromParent,
-                         CWEventMask | CWOverrideRedirect, &attributes);
-    XMapRaised (dpy, win->window);
-    XFlush (dpy);
+    win->window = XCreateWindow (myScreenGetXDisplay (screen_info), 
+                                 parent, x, y, width, height, 0, 0, 
+                                 InputOnly, CopyFromParent,
+                                 CWEventMask | CWOverrideRedirect, 
+                                 &attributes);
+    XMapRaised (myScreenGetXDisplay (screen_info), win->window);
+    XFlush (myScreenGetXDisplay (screen_info));
 
     win->map = TRUE;
-    win->dpy = dpy;
-    win->screen = screen;
+    win->screen_info = screen_info;
     win->x = x;
     win->y = y;
     win->width = width;
@@ -223,20 +243,21 @@ xfwmWindowSetBG (xfwmWindow * win, xfwmPixmap * pix)
         return;
     }
 
-    if ((win->visual == DefaultVisual (win->dpy, win->screen))
-        && (win->depth == DefaultDepth (win->dpy, win->screen)))
+    if ((win->visual == win->screen_info->visual) && (win->depth == win->screen_info->depth))
     {
-        XSetWindowBackgroundPixmap (win->dpy, win->window, pix->pixmap);
+        XSetWindowBackgroundPixmap (myScreenGetXDisplay (win->screen_info), win->window, pix->pixmap);
     }
 #ifdef HAVE_RENDER
-    else
+    else if (myDisplayHaveRender (win->screen_info->display_info))
     {
         Picture psrc, pdst;
         XRenderPictFormat *format_src, *format_dst;
         Pixmap temp;
 
-        format_src = XRenderFindVisualFormat (win->dpy, DefaultVisual (win->dpy, win->screen));
-        format_dst = XRenderFindVisualFormat (win->dpy, win->visual);
+        format_src = XRenderFindVisualFormat (myScreenGetXDisplay (pix->screen_info), 
+                                              pix->screen_info->visual);
+        format_dst = XRenderFindVisualFormat (myScreenGetXDisplay (win->screen_info), 
+                                              win->visual);
 
         if (!format_src || !format_dst)
         {
@@ -244,19 +265,23 @@ xfwmWindowSetBG (xfwmWindow * win, xfwmPixmap * pix)
             return;
         }
 
-        temp = XCreatePixmap (win->dpy, win->window, pix->width, pix->height, win->depth);
+        temp = XCreatePixmap (myScreenGetXDisplay (win->screen_info), 
+                              win->window, 
+                              pix->width, pix->height, win->depth);
 
-        psrc = XRenderCreatePicture (win->dpy, pix->pixmap, format_src, 0, NULL);
-        pdst = XRenderCreatePicture (win->dpy, temp, format_dst, 0, NULL);
+        psrc = XRenderCreatePicture (myScreenGetXDisplay (pix->screen_info), 
+                                     pix->pixmap, format_src, 0, NULL);
+        pdst = XRenderCreatePicture (myScreenGetXDisplay (win->screen_info), 
+                                     temp, format_dst, 0, NULL);
 
-        XRenderComposite (win->dpy, PictOpSrc, psrc, None, pdst, 0, 0, 0, 0, 0, 0, pix->width, pix->height);
+        XRenderComposite (myScreenGetXDisplay (win->screen_info), PictOpSrc, psrc, None, pdst, 0, 0, 0, 0, 0, 0, pix->width, pix->height);
 
-        XRenderFreePicture (win->dpy, psrc);
-        XRenderFreePicture (win->dpy, pdst);
+        XRenderFreePicture (myScreenGetXDisplay (pix->screen_info), psrc);
+        XRenderFreePicture (myScreenGetXDisplay (win->screen_info), pdst);
 
-        XSetWindowBackgroundPixmap (win->dpy, win->window, temp);
+        XSetWindowBackgroundPixmap (myScreenGetXDisplay (win->screen_info), win->window, temp);
 
-        XFreePixmap (win->dpy, temp);
+        XFreePixmap (myScreenGetXDisplay (win->screen_info), temp);
     }
 #endif
 }
diff --git a/src/mywindow.h b/src/mywindow.h
index a2744a1fc..a19f2d3ce 100644
--- a/src/mywindow.h
+++ b/src/mywindow.h
@@ -29,16 +29,16 @@
 #include <X11/Xlib.h>
 #include <glib.h>
 #include "mypixmap.h"
+#include "screen.h"
 
 #define MYWINDOW_XWINDOW(w) (w.window)
 
 typedef struct _xfwmWindow xfwmWindow;
 struct _xfwmWindow
 {
-    Display *dpy;
+    ScreenInfo *screen_info;
     Visual *visual;
     gint depth;
-    gint screen;
     Window window;
     gint x, y;
     gint width, height;
@@ -46,15 +46,13 @@ struct _xfwmWindow
 };
 
 void xfwmWindowInit        (xfwmWindow *);
-void xfwmWindowCreate      (Display *,
-                            gint, 
+void xfwmWindowCreate      (ScreenInfo *,
                             Visual *,
                             gint, 
                             Window, 
                             xfwmWindow *, 
                             Cursor);
-void xfwmWindowTemp        (Display *, 
-                            gint, 
+void xfwmWindowTemp        (ScreenInfo *, 
                             Visual *,
                             gint, 
                             Window, 
@@ -76,5 +74,4 @@ gboolean xfwmWindowVisible (xfwmWindow *);
 gboolean xfwmWindowDeleted (xfwmWindow *);
 void xfwmWindowSetBG       (xfwmWindow *, xfwmPixmap *);
 
-
 #endif /* INC_MYWINDOW_H */
diff --git a/src/screen.c b/src/screen.c
index 2bb879d4c..596320b40 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -116,8 +116,7 @@ myScreenInit (DisplayInfo *display_info, GdkScreen *gscr, unsigned long event_ma
     screen_info->button_handler_id = 0L;
     
     /* Create the side windows to detect edge movement */
-    xfwmWindowTemp (display_info->dpy, 
-                    screen_info->screen,
+    xfwmWindowTemp (screen_info,
                     NULL, 0,
                     screen_info->xroot,
                     &screen_info->sidewalk[0], 
@@ -125,8 +124,7 @@ myScreenInit (DisplayInfo *display_info, GdkScreen *gscr, unsigned long event_ma
                     1, gdk_screen_get_height (gscr), 
                     LeaveWindowMask | PointerMotionMask);
 
-    xfwmWindowTemp (display_info->dpy, 
-                    screen_info->screen,
+    xfwmWindowTemp (screen_info,
                     NULL, 0,
                     screen_info->xroot,
                     &screen_info->sidewalk[1], 
@@ -134,8 +132,7 @@ myScreenInit (DisplayInfo *display_info, GdkScreen *gscr, unsigned long event_ma
                     1, gdk_screen_get_height (gscr), 
                     LeaveWindowMask | PointerMotionMask);
 
-    xfwmWindowTemp (display_info->dpy, 
-                    screen_info->screen,
+    xfwmWindowTemp (screen_info,
                     NULL, 0,
                     screen_info->xroot,
                     &screen_info->sidewalk[2], 
@@ -143,8 +140,7 @@ myScreenInit (DisplayInfo *display_info, GdkScreen *gscr, unsigned long event_ma
                     gdk_screen_get_width (gscr), 1,
                     LeaveWindowMask | PointerMotionMask);
 
-    xfwmWindowTemp (display_info->dpy, 
-                    screen_info->screen,
+    xfwmWindowTemp (screen_info,
                     NULL, 0,
                     screen_info->xroot,
                     &screen_info->sidewalk[3], 
diff --git a/src/wireframe.c b/src/wireframe.c
index 9f1a60e02..a19e173cc 100644
--- a/src/wireframe.c
+++ b/src/wireframe.c
@@ -143,4 +143,3 @@ wireframeDelete (ScreenInfo *screen_info, Window xwindow)
     XUnmapWindow (myScreenGetXDisplay (screen_info), xwindow);
     XDestroyWindow (myScreenGetXDisplay (screen_info), xwindow);
 }
-
-- 
GitLab