Hi,

I wrote a quick patch for changing the window opacity on X11. It will only work 
on X servers with the Composite extension enabled.

It adds a command 'set-opacity' which take an integer which represents the 
window opacity with 0 meaning completely transparent and 100 opaque.

I found a problem with this patch, using the command in a config file doesn't 
work as EditState->dpy does not seem to be initialized when the config is 
loaded. I guess the problem is that the window is created *after* the config is 
loaded. I will try to find a proper solution to this issue.

Regards,
Philippe Mechai
Index: display.h
===================================================================
RCS file: /sources/qemacs/qemacs/display.h,v
retrieving revision 1.11
diff -u -r1.11 display.h
--- display.h	11 Jan 2008 11:29:28 -0000	1.11
+++ display.h	26 Nov 2008 18:25:58 -0000
@@ -138,6 +138,7 @@
     void (*dpy_bmp_unlock)(QEditScreen *s, QEBitmap *b);
     /* full screen support */
     void (*dpy_full_screen)(QEditScreen *s, int full_screen);
+    void (*dpy_set_opacity)(QEditScreen *s, int opacity);
     QEDisplay *next;
 };
 
Index: qe.c
===================================================================
RCS file: /sources/qemacs/qemacs/qe.c,v
retrieving revision 1.95
diff -u -r1.95 qe.c
--- qe.c	2 May 2008 16:04:09 -0000	1.95
+++ qe.c	26 Nov 2008 18:26:00 -0000
@@ -2296,6 +2296,14 @@
     }
 }
 
+void do_set_opacity(EditState *s, int opacity)
+{
+    QEditScreen *screen = s->screen;
+
+    if (screen->dpy.dpy_set_opacity)
+        screen->dpy.dpy_set_opacity(screen, opacity);
+}
+
 /* NOTE: toggle-full-screen also hide the modeline of the current
    window and the status line */
 void do_toggle_full_screen(EditState *s)
@@ -2335,6 +2343,8 @@
 }
 
 
+
+
 void display_init(DisplayState *s, EditState *e, enum DisplayType do_disp)
 {
     QEFont *font;
Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.96
diff -u -r1.96 qe.h
--- qe.h	4 May 2008 15:54:39 -0000	1.96
+++ qe.h	26 Nov 2008 18:26:01 -0000
@@ -1677,6 +1677,7 @@
 void do_toggle_mode_line(EditState *s);
 void do_set_system_font(EditState *s, const char *qe_font_name,
                         const char *system_fonts);
+void do_set_opacity(EditState *s, int opacity);
 void call_func(CmdSig sig, CmdProto func, int nb_args, CmdArg *args,
                unsigned char *args_type);
 void exec_command(EditState *s, CmdDef *d, int argval, int key);
Index: qeconfig.h
===================================================================
RCS file: /sources/qemacs/qemacs/qeconfig.h,v
retrieving revision 1.36
diff -u -r1.36 qeconfig.h
--- qeconfig.h	29 Apr 2008 18:55:14 -0000	1.36
+++ qeconfig.h	26 Nov 2008 18:26:01 -0000
@@ -303,6 +303,9 @@
           "set-system-font", do_set_system_font, ESss,
 	  "s{Font family: }|fontfamily|"
 	  "s{System fonts: }|fontnames|")
+    CMD2( KEY_NONE, KEY_NONE,
+          "set-opacity", do_set_opacity, ESi,
+          "i{Opacity percentage: }|opacity|")
 
     /*---------------- Miscellaneous ----------------*/
 
Index: tty.c
===================================================================
RCS file: /sources/qemacs/qemacs/tty.c,v
retrieving revision 1.50
diff -u -r1.50 tty.c
--- tty.c	23 Apr 2008 15:30:33 -0000	1.50
+++ tty.c	26 Nov 2008 18:26:02 -0000
@@ -1281,6 +1281,7 @@
     NULL, /* dpy_bmp_lock */
     NULL, /* dpy_bmp_unlock */
     NULL, /* dpy_full_screen */
+    NULL, /* dpy_set_opacity */
     NULL, /* next */
 };
 
Index: win32.c
===================================================================
RCS file: /sources/qemacs/qemacs/win32.c,v
retrieving revision 1.15
diff -u -r1.15 win32.c
--- win32.c	23 Apr 2008 15:29:35 -0000	1.15
+++ win32.c	26 Nov 2008 18:26:02 -0000
@@ -519,6 +519,7 @@
     NULL, /* dpy_bmp_lock */
     NULL, /* dpy_bmp_unlock */
     NULL, /* dpy_full_screen */
+    NULL, /* dpy_set_opacity */
     NULL, /* next */
 };
 
Index: x11.c
===================================================================
RCS file: /sources/qemacs/qemacs/x11.c,v
retrieving revision 1.28
diff -u -r1.28 x11.c
--- x11.c	15 Apr 2008 23:24:04 -0000	1.28
+++ x11.c	26 Nov 2008 18:26:02 -0000
@@ -1048,6 +1048,17 @@
     }
 }
 
+static void x11_set_opacity(__unused__ QEditScreen *s, int opacity)
+{
+    Atom prop = XInternAtom(display, "_NET_WM_WINDOW_OPACITY", False);
+    unsigned long op = (opacity / 100.0) * 0xffffffff;
+
+    XChangeProperty(display, window, prop,
+                    XA_CARDINAL, 32, PropModeReplace,
+                    (unsigned char*)&op, 1L);
+
+}
+
 static void term_selection_activate(__unused__ QEditScreen *s)
 {
     /* own selection from now */
@@ -1759,6 +1770,7 @@
     x11_bmp_lock,
     x11_bmp_unlock,
     x11_full_screen,
+    x11_set_opacity,
     NULL, /* next */
 };
 
_______________________________________________
Qemacs-devel mailing list
Qemacs-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/qemacs-devel

Reply via email to