]> Dogcows Code - chaz/openbox/blobdiff - openbox/frame.c
support clients which use true transparency 32-bit visuals.
[chaz/openbox] / openbox / frame.c
index f390887ae8908fd27226abbf2fbd9ca4c57785a3..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
@@ -47,59 +47,95 @@ static gboolean flash_timeout(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);
                        
 }
 
-ObFrame *frame_new()
+static Visual *check_32bit_client(ObClient *c)
+{
+    XWindowAttributes wattrib;
+    Status ret;
+
+    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(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;
 
@@ -181,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);
 }
@@ -417,12 +455,11 @@ void frame_adjust_area(ObFrame *self, gboolean moved,
 
         if (resized) {
             framerender_frame(self);
-
             frame_adjust_shape(self);
         }
 
         if (!STRUT_EQUAL(self->size, oldsize)) {
-            guint32 vals[4];
+            gulong vals[4];
             vals[0] = self->size.left;
             vals[1] = self->size.right;
             vals[2] = self->size.top;
@@ -436,6 +473,9 @@ void frame_adjust_area(ObFrame *self, gboolean moved,
         if (focus_cycle_target == self->client)
             focus_cycle_draw_indicator();
     }
+    if (resized && (self->decorations & OB_FRAME_DECOR_TITLEBAR))
+        XResizeWindow(ob_display, self->label, self->label_width,
+                      ob_rr_theme->label_height);
 }
 
 void frame_adjust_state(ObFrame *self)
@@ -554,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);
 }
@@ -579,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 +
@@ -587,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 +
@@ -595,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 +
@@ -607,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 +
@@ -615,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 +
@@ -625,9 +670,6 @@ static void layout_title(ObFrame *self)
     }
     if (self->label_width < 1) self->label_width = 1;
 
-    XResizeWindow(ob_display, self->label, self->label_width,
-                  ob_rr_theme->label_height);
-  
     if (!n) XUnmapWindow(ob_display, self->icon);
     if (!d) XUnmapWindow(ob_display, self->desk);
     if (!s) XUnmapWindow(ob_display, self->shade);
This page took 0.027364 seconds and 4 git commands to generate.