]> Dogcows Code - chaz/openbox/blobdiff - openbox/frame.c
support clients which use true transparency 32-bit visuals.
[chaz/openbox] / openbox / frame.c
index 2c495b27e76e4071c081e2428547f5c755f364d4..57a1b8ab9ad1073d3beaf06555e7a56aa4649d38 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
 
    frame.c for the Openbox window manager
-   Copyright (c) 2004        Mikael Magnusson
+   Copyright (c) 2006        Mikael Magnusson
    Copyright (c) 2003        Ben Jansens
 
    This program is free software; you can redistribute it and/or modify
 static void layout_title(ObFrame *self);
 static void flash_done(gpointer data);
 static gboolean flash_timeout(gpointer data);
-static void flash_client_dest(ObClient *client, gpointer data);
 
 static void set_theme_statics(ObFrame *self);
 static void free_theme_statics(ObFrame *self);
 
-static Window createWindow(Window parent, gulong mask,
-                           XSetWindowAttributes *attrib)
+static Window createWindow(Window parent, Visual *visual,
+                           gulong mask, XSetWindowAttributes *attrib)
 {
     return XCreateWindow(ob_display, parent, 0, 0, 1, 1, 0,
-                         RrDepth(ob_rr_inst), InputOutput,
-                         RrVisual(ob_rr_inst), mask, attrib);
+                         (visual ? 32 : RrDepth(ob_rr_inst)), InputOutput,
+                         (visual ? visual : RrVisual(ob_rr_inst)),
+                         mask, attrib);
                        
 }
 
-void frame_startup(gboolean reconfig)
+static Visual *check_32bit_client(ObClient *c)
 {
-    if (reconfig) return;
-    client_add_destructor(flash_client_dest, NULL);
-}
+    XWindowAttributes wattrib;
+    Status ret;
 
-void frame_shutdown(gboolean reconfig)
-{
-    if (reconfig) return;
-    client_remove_destructor(flash_client_dest);
+    ret = XGetWindowAttributes(ob_display, c->window, &wattrib);
+    g_assert(ret != BadDrawable);
+    g_assert(ret != BadWindow);
+
+    if (wattrib.depth == 32)
+        return wattrib.visual;
+    return NULL;
 }
 
-ObFrame *frame_new()
+ObFrame *frame_new(ObClient *client)
 {
     XSetWindowAttributes attrib;
     gulong mask;
     ObFrame *self;
+    Visual *visual;
 
     self = g_new0(ObFrame, 1);
 
     self->obscured = TRUE;
 
-    /* create all of the decor windows */
+    visual = check_32bit_client(client);
+
+    /* create the non-visible decor windows */
+
     mask = CWEventMask;
+    if (visual) {
+        /* client has a 32-bit visual */
+        mask |= CWColormap | CWBackPixel | CWBorderPixel;
+        /* create a colormap with the visual */
+        self->colormap = attrib.colormap =
+            XCreateColormap(ob_display,
+                            RootWindow(ob_display, ob_screen),
+                            visual, AllocNone);
+        attrib.background_pixel = BlackPixel(ob_display, 0);
+        attrib.border_pixel = BlackPixel(ob_display, 0);
+    }
     attrib.event_mask = FRAME_EVENTMASK;
-    self->window = createWindow(RootWindow(ob_display, ob_screen),
+    self->window = createWindow(RootWindow(ob_display, ob_screen), visual,
                                 mask, &attrib);
+    mask &= ~CWEventMask;
+    self->plate = createWindow(self->window, visual, mask, &attrib);
 
-    mask = 0;
-    self->plate = createWindow(self->window, mask, &attrib);
+    /* create the visible decor windows */
 
     mask = CWEventMask;
+    if (visual) {
+        /* client has a 32-bit visual */
+        mask |= CWColormap | CWBackPixel | CWBorderPixel;
+        attrib.colormap = RrColormap(ob_rr_inst);
+    }
     attrib.event_mask = ELEMENT_EVENTMASK;
-    self->title = createWindow(self->window, mask, &attrib);
+    self->title = createWindow(self->window, NULL, mask, &attrib);
 
     mask |= CWCursor;
     attrib.cursor = ob_cursor(OB_CURSOR_NORTHWEST);
-    self->tlresize = createWindow(self->title, mask, &attrib);
+    self->tlresize = createWindow(self->title, NULL, mask, &attrib);
     attrib.cursor = ob_cursor(OB_CURSOR_NORTHEAST);
-    self->trresize = createWindow(self->title, mask, &attrib);
+    self->trresize = createWindow(self->title, NULL, mask, &attrib);
 
     mask &= ~CWCursor;
-    self->label = createWindow(self->title, mask, &attrib);
-    self->max = createWindow(self->title, mask, &attrib);
-    self->close = createWindow(self->title, mask, &attrib);
-    self->desk = createWindow(self->title, mask, &attrib);
-    self->shade = createWindow(self->title, mask, &attrib);
-    self->icon = createWindow(self->title, mask, &attrib);
-    self->iconify = createWindow(self->title, mask, &attrib);
-    self->handle = createWindow(self->window, mask, &attrib);
+    self->label = createWindow(self->title, NULL, mask, &attrib);
+    self->max = createWindow(self->title, NULL, mask, &attrib);
+    self->close = createWindow(self->title, NULL, mask, &attrib);
+    self->desk = createWindow(self->title, NULL, mask, &attrib);
+    self->shade = createWindow(self->title, NULL, mask, &attrib);
+    self->icon = createWindow(self->title, NULL, mask, &attrib);
+    self->iconify = createWindow(self->title, NULL, mask, &attrib);
+    self->handle = createWindow(self->window, NULL, mask, &attrib);
 
     mask |= CWCursor;
     attrib.cursor = ob_cursor(OB_CURSOR_SOUTHWEST);
-    self->lgrip = createWindow(self->handle, mask, &attrib);
+    self->lgrip = createWindow(self->handle, NULL, mask, &attrib);
     attrib.cursor = ob_cursor(OB_CURSOR_SOUTHEAST);
-    self->rgrip = createWindow(self->handle, mask, &attrib); 
+    self->rgrip = createWindow(self->handle, NULL, mask, &attrib); 
 
     self->focused = FALSE;
 
@@ -194,6 +217,8 @@ static void frame_free(ObFrame *self)
     free_theme_statics(self);
 
     XDestroyWindow(ob_display, self->window);
+    if (self->colormap)
+        XFreeColormap(ob_display, self->colormap);
 
     g_free(self);
 }
@@ -569,7 +594,7 @@ void frame_release_client(ObFrame *self, ObClient *client)
     g_hash_table_remove(window_map, &self->tlresize);
     g_hash_table_remove(window_map, &self->trresize);
 
-    ob_main_loop_timeout_remove_data(ob_main_loop, flash_timeout, self);
+    ob_main_loop_timeout_remove_data(ob_main_loop, flash_timeout, self, TRUE);
 
     frame_free(self);
 }
@@ -594,7 +619,8 @@ static void layout_title(ObFrame *self)
             break;
         case 'D':
             if (d) { *lc = ' '; break; }
-            if (!(self->decorations & OB_FRAME_DECOR_ALLDESKTOPS) && config_theme_hidedisabled)
+            if (!(self->decorations & OB_FRAME_DECOR_ALLDESKTOPS)
+                && config_theme_hidedisabled)
                 break;
             d = TRUE;
             self->label_width -= (ob_rr_theme->button_size +
@@ -602,7 +628,8 @@ static void layout_title(ObFrame *self)
             break;
         case 'S':
             if (s) { *lc = ' '; break; }
-            if (!(self->decorations & OB_FRAME_DECOR_SHADE) && config_theme_hidedisabled)
+            if (!(self->decorations & OB_FRAME_DECOR_SHADE)
+                && config_theme_hidedisabled)
                 break;
             s = TRUE;
             self->label_width -= (ob_rr_theme->button_size +
@@ -610,7 +637,8 @@ static void layout_title(ObFrame *self)
             break;
         case 'I':
             if (i) { *lc = ' '; break; }
-            if (!(self->decorations & OB_FRAME_DECOR_ICONIFY) && config_theme_hidedisabled)
+            if (!(self->decorations & OB_FRAME_DECOR_ICONIFY)
+                && config_theme_hidedisabled)
                 break;
             i = TRUE;
             self->label_width -= (ob_rr_theme->button_size +
@@ -622,7 +650,8 @@ static void layout_title(ObFrame *self)
             break;
         case 'M':
             if (m) { *lc = ' '; break; }
-            if (!(self->decorations & OB_FRAME_DECOR_MAXIMIZE) && config_theme_hidedisabled)
+            if (!(self->decorations & OB_FRAME_DECOR_MAXIMIZE)
+                && config_theme_hidedisabled)
                 break;
             m = TRUE;
             self->label_width -= (ob_rr_theme->button_size +
@@ -630,7 +659,8 @@ static void layout_title(ObFrame *self)
             break;
         case 'C':
             if (c) { *lc = ' '; break; }
-            if (!(self->decorations & OB_FRAME_DECOR_CLOSE) && config_theme_hidedisabled)
+            if (!(self->decorations & OB_FRAME_DECOR_CLOSE)
+                && config_theme_hidedisabled)
                 break;
             c = TRUE;
             self->label_width -= (ob_rr_theme->button_size +
@@ -921,11 +951,6 @@ static gboolean flash_timeout(gpointer data)
     return TRUE; /* go again */
 }
 
-static void flash_client_dest(ObClient *client, gpointer data)
-{
-    ob_main_loop_timeout_remove_data(ob_main_loop, flash_timeout, client);
-}
-
 void frame_flash_start(ObFrame *self)
 {
     self->flash_on = self->focused;
This page took 0.026597 seconds and 4 git commands to generate.