Re: [i3] [PATCH] Transparency support

  • From: DR <drdarkraven@xxxxxxxxx>
  • To: "Discussions/Questions about the i3 window manager" <i3-discuss@xxxxxxxxxxxxx>
  • Date: Sat, 28 Jan 2012 20:48:12 +0800

On Sat, Jan 28, 2012 at 5:50 PM, Michael Stapelberg
<michael+i3@xxxxxxxxxxxxx> wrote:

Hi Raven,

Thanks for your patch and sorry for replying so late. Here are my comments:

1) You did not use git format-patch to generate the patch. This is bad because
  then your name is missing from the git log. Please use git format-patch.

2) Your patch has been line-wrapped/mangled by your mail client so that I
  cannot apply it.

Sorry for that. I'll re-send the patch.


3) You did not state what this patch actually fixes and how I can reproduce
  that. I just looked at ticket http://bugs.i3wm.org/220 again and tried the
  following:

in ~/.Xresources:
URxvt.background: [85]black
URxvt.foreground: lightgrey
URxvt.depth: 32

Then start xcompmgr -n, use transset-df and click on an urxvt terminal. It
became transparent (without your patch).

Could you please elaborate on that and re-send your patch?

Bug #220 is exactly what this patch fix.

The expected result is that urxvt would be transparent without
transset-df (and this is how urxvt in most other wm works).

With wm like wmii, you only need to put:

URxvt.depth: 32
Urxvt.background: rgba:0000/0000/0000/7777

In your .Xresources, and start xcompmgr, urxvt would be transparent.


Best regards,
Michael
From 901ce061e941edc007bf5a7103427d151a7d07fa Mon Sep 17 00:00:00 2001
From: darkraven <drdarkraven@xxxxxxxxx>
Date: Sat, 14 Jan 2012 20:27:34 +0800
Subject: [PATCH] add transparency support

some fix
---
include/i3.h | 3 ++
src/main.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/sighandler.c | 2 +-
src/x.c | 17 +++++++++++---
src/xcb.c | 5 ++-
5 files changed, 79 insertions(+), 7 deletions(-)

diff --git a/include/i3.h b/include/i3.h
index d645325..313c68a 100644
--- a/include/i3.h
+++ b/include/i3.h
@@ -48,6 +48,9 @@ extern TAILQ_HEAD(ws_assignments_head, Workspace_Assignment)
ws_assignments;
extern TAILQ_HEAD(assignments_head, Assignment) assignments;
extern SLIST_HEAD(stack_wins_head, Stack_Window) stack_wins;
extern xcb_screen_t *root_screen;
+extern xcb_colormap_t default_colormap;
+extern xcb_visualtype_t *default_visual;
+extern uint8_t default_depth;
extern uint8_t root_depth;
extern bool xcursor_supported, xkb_supported;
extern xcb_window_t root;
diff --git a/src/main.c b/src/main.c
index 32073d2..6642d8b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -50,6 +50,9 @@ xcb_timestamp_t last_timestamp = XCB_CURRENT_TIME;

xcb_screen_t *root_screen;
xcb_window_t root;
+xcb_visualtype_t *default_visual = NULL;
+xcb_colormap_t default_colormap = 0;
+uint8_t default_depth;
uint8_t root_depth;

struct ev_loop *main_loop;
@@ -234,6 +237,43 @@ static void handle_signal(int sig, siginfo_t *info, void
*data) {
raise(sig);
}

+static xcb_visualtype_t *get_argb_visual(xcb_screen_t *s) {
+ xcb_depth_iterator_t depth_iter = xcb_screen_allowed_depths_iterator(s);
+
+ if(depth_iter.data)
+ for(; depth_iter.rem; xcb_depth_next(&depth_iter))
+ if(depth_iter.data->depth == 32)
+ for(xcb_visualtype_iterator_t visual_iter =
xcb_depth_visuals_iterator(depth_iter.data);
+ visual_iter.rem; xcb_visualtype_next(&visual_iter))
+ return visual_iter.data;
+
+ return NULL;
+}
+
+static uint8_t get_visual_depth(xcb_screen_t *s, xcb_visualid_t vis) {
+ xcb_depth_iterator_t depth_iter = xcb_screen_allowed_depths_iterator(s);
+
+ if(depth_iter.data)
+ for(; depth_iter.rem; xcb_depth_next (&depth_iter))
+ for(xcb_visualtype_iterator_t visual_iter =
xcb_depth_visuals_iterator(depth_iter.data);
+ visual_iter.rem; xcb_visualtype_next (&visual_iter))
+ if(vis == visual_iter.data->visual_id)
+ return depth_iter.data->depth;
+ return 24;
+}
+
+static xcb_visualtype_t *get_default_visual(xcb_screen_t *s) {
+ xcb_depth_iterator_t depth_iter = xcb_screen_allowed_depths_iterator(s);
+
+ if(depth_iter.data)
+ for(; depth_iter.rem; xcb_depth_next (&depth_iter))
+ for(xcb_visualtype_iterator_t visual_iter =
xcb_depth_visuals_iterator(depth_iter.data);
+ visual_iter.rem; xcb_visualtype_next (&visual_iter))
+ if(s->root_visual == visual_iter.data->visual_id)
+ return visual_iter.data;
+
+ return NULL;
+}
int main(int argc, char *argv[]) {
char *override_configpath = NULL;
bool autostart = true;
@@ -528,6 +568,25 @@ int main(int argc, char *argv[]) {
}
DLOG("root geometry reply: (%d, %d) %d x %d\n", greply->x, greply->y,
greply->width, greply->height);

+
+ /* Acquire a argb visual */
+ default_visual = get_argb_visual(root_screen);
+ if(!default_visual)
+ default_visual = get_default_visual(root_screen);
+ if (!default_visual) {
+ ELOG("No available visual found, exiting\n");
+ return 1;
+ }
+ default_depth = get_visual_depth(root_screen, default_visual->visual_id);
+ /* Acquire corresponding colormap */
+ default_colormap = root_screen->default_colormap;
+ if(default_depth != root_depth) {
+ default_colormap = xcb_generate_id(conn);
+ xcb_create_colormap(conn, XCB_COLORMAP_ALLOC_NONE,
+ default_colormap, root,
+ default_visual->visual_id);
+ }
+
/* Place requests for the atoms we need as soon as possible */
#define xmacro(atom) \
xcb_intern_atom_cookie_t atom ## _cookie = xcb_intern_atom(conn, 0,
strlen(#atom), #atom);
diff --git a/src/sighandler.c b/src/sighandler.c
index 4a0c13b..7f8ef51 100644
--- a/src/sighandler.c
+++ b/src/sighandler.c
@@ -162,7 +162,7 @@ void handle_signal(int sig, siginfo_t *info, void *data) {
/* Create pixmap */
pixmap = xcb_generate_id(conn);
pixmap_gc = xcb_generate_id(conn);
- xcb_create_pixmap(conn, root_depth, pixmap, win, width, height);
+ xcb_create_pixmap(conn, default_depth, pixmap, win, width, height);
xcb_create_gc(conn, pixmap_gc, pixmap, 0, 0);

/* Grab the keyboard to get all input */
diff --git a/src/x.c b/src/x.c
index e5853fb..8a2aedb 100644
--- a/src/x.c
+++ b/src/x.c
@@ -90,15 +90,24 @@ void x_con_init(Con *con) {
* get the initial geometry right */

uint32_t mask = 0;
- uint32_t values[2];
+ uint32_t values[5];
+
+ mask |= XCB_CW_BACK_PIXEL;
+ values[0] = root_screen->black_pixel;
+
+ mask |= XCB_CW_BORDER_PIXEL;
+ values[1] = root_screen->black_pixel;

/* our own frames should not be managed */
mask |= XCB_CW_OVERRIDE_REDIRECT;
- values[0] = 1;
+ values[2] = 1;

/* see include/xcb.h for the FRAME_EVENT_MASK */
mask |= XCB_CW_EVENT_MASK;
- values[1] = FRAME_EVENT_MASK & ~XCB_EVENT_MASK_ENTER_WINDOW;
+ values[3] = FRAME_EVENT_MASK & ~XCB_EVENT_MASK_ENTER_WINDOW;
+
+ mask |= XCB_CW_COLORMAP;
+ values[4] = default_colormap;

Rect dims = { -15, -15, 10, 10 };
con->frame = create_window(conn, dims, XCB_WINDOW_CLASS_INPUT_OUTPUT,
XCURSOR_CURSOR_POINTER, false, mask, values);
@@ -561,7 +570,7 @@ void x_push_node(Con *con) {
xcb_free_pixmap(conn, con->pixmap);
xcb_free_gc(conn, con->pm_gc);
}
- xcb_create_pixmap(conn, root_depth, con->pixmap, con->frame,
rect.width, rect.height);
+ xcb_create_pixmap(conn, default_depth, con->pixmap, con->frame,
rect.width, rect.height);
/* For the graphics context, we disable GraphicsExposure events.
* Those will be sent when a CopyArea request cannot be fulfilled
* properly due to parts of the source being unmapped or otherwise
diff --git a/src/xcb.c b/src/xcb.c
index 48906a2..1583782 100644
--- a/src/xcb.c
+++ b/src/xcb.c
@@ -21,7 +21,8 @@ xcb_window_t create_window(xcb_connection_t *conn, Rect dims,
uint16_t window_cl
xcb_window_t result = xcb_generate_id(conn);

/* If the window class is XCB_WINDOW_CLASS_INPUT_ONLY, depth has to be 0 */
- uint16_t depth = (window_class == XCB_WINDOW_CLASS_INPUT_ONLY ? 0 :
XCB_COPY_FROM_PARENT);
+ uint16_t depth = (window_class == XCB_WINDOW_CLASS_INPUT_ONLY ? 0 :
default_depth);
+ xcb_visualid_t visual_id= (window_class == XCB_WINDOW_CLASS_INPUT_ONLY ?
XCB_WINDOW_CLASS_COPY_FROM_PARENT : default_visual->visual_id);

xcb_create_window(conn,
depth,
@@ -30,7 +31,7 @@ xcb_window_t create_window(xcb_connection_t *conn, Rect dims,
uint16_t window_cl
dims.x, dims.y, dims.width, dims.height, /* dimensions */
0, /* border = 0, we draw our own */
window_class,
- XCB_WINDOW_CLASS_COPY_FROM_PARENT, /* copy visual from parent */
+ visual_id,
mask,
values);

--
1.7.8.4

Other related posts: