DirectFB - Home of the pragmatist Roadmap


[directfb-dev] X-Transparency protocol extension
Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[directfb-dev] X-Transparency protocol extension



Hello,

I have been playing with XDirectFB and think it is a nice piece of
work.  The only feature that I find missing is the ability for an X
client to set the transparency of a top level window.  There has been
an ongoing bit of discussion about how to put transparent top-level
windows into X but not much has happened ... until the Xserver was
ported to DirectFB.

Along these lines, I have created a very simple experimental X
protocol extension that will allow X client programs to get and set
the opacity of their or other's top-level windows through the DirectFB
API.  I have tried to make this extension general. It requires that
the Xserver be built on top of a windowing system that supports
transparent top-level windows, such as XDirectFB.  I would like to
submit my patch to this project for your evaluation.  This patch,
simple as it is, should allow development of X11 window managers that
can control true transparency for top-level client windows.  I would
gladly accept feedback from this list about enhancements.

My patch is based on XFree 4.2.1 and XDirectFB-1.0-rc3.  To build
Xdirectfb with this experimental X-Transparency extension, unpack the
X421 sources to a directory and then update the sources to
XDirectFB-1.0-rc3 as directed in the XDirectFB README.  Finally,
install the X-Transparency support by changing to the top level of
your new directory tree and apply this patch.

cd xc
patch -p4 < xc-transparency.diff

Adjust xc/config/cf/hosts.def for your installation and then make
World.  After a successful build you should find a program
demonstrating the use of this extension in xc/programs/xtoggletrans.
You can run xtoggletrans in an xterm and click on a window with the
mouse to change its tranparency.  In my testing of this extension, I
have been running XDirectFB in root window mode, I have not been using
the multiplexing core.
 
In addition to XTransparencyQueryExtension and
XTransparencyQueryVersion functions, libXTransparency.a provides these
2 functions to client programs:

void XSetTransparency(Display *dpy, Window win, OpacityValue value);

    Given value, set the opacity of the top-level window win.
    Attempting to set the transparency of a window that is not
    top-level is an error and an XErrorEvent will be delivered
    asynchronously.  Value varies from 0 for invisible, to 255 for
    fully opaque.

Status XGetTransparency(Display *dpy, Window win, OpacityValue *value);

    Retrieve the current opacity for the given top-level window.
    Attempting to retrieve the opacity for a window that is
    not top-level is an error.

This is a minimal API and more features can be added once I figure out
what they should be.

The extension works by requiring an Xserver to provide callbacks to
get and set the transparency of a window.  These callbacks are hooked
into the Xprotocol layer at server initialization time.  The protocol
layer uses these callbacks to service the client get/set requests.
Hopefully, this scheme is general enough to support other Xservers
that are based on window systems that can also provide transparency.


Thanks,

Scott Brumbaugh



diff -Naur --exclude=host.def /extra/x421.org/xc/config/cf/X11.tmpl /extra/x421/xc/config/cf/X11.tmpl
--- /extra/x421.org/xc/config/cf/X11.tmpl	Tue Dec 24 17:07:19 2002
+++ /extra/x421/xc/config/cf/X11.tmpl	Tue Dec 24 17:31:52 2002
@@ -1021,6 +1021,14 @@
 #endif
 #endif
 
+#ifndef XTransparencyExtensionDefines
+#if BuildTransparency
+#define XTransparencyExtensionDefines -DXTRANSPARENCY
+#else
+#define XTransparencyExtensionDefines /**/
+#endif
+#endif
+
 #ifndef SitePervasiveExtensionDefines
 #define SitePervasiveExtensionDefines /**/
 #endif
@@ -1042,7 +1050,8 @@
 	PexDefines ShmDefines XieDefines BigReqDefines VidModeExtensionDefines \
 	XF86MiscExtensionDefines DBEDefines DPMSDefines EVIDefines \
 	ScreenSaverExtensionDefines XvExtensionDefines XvMCExtensionDefines \
-	GlxDefines FontCacheExtensionDefines SiteExtensionDefines
+	GlxDefines FontCacheExtensionDefines SiteExtensionDefines \
+	XTransparencyExtensionDefines
 #endif
 #define ExtensionDefines BaseExtensionDefines ExtensionOSDefines
 #endif /* ExtensionDefines */
@@ -1722,6 +1731,20 @@
 #endif
 #endif
 
+#if BuildTransparencyLib
+#ifndef SharedLibXTransparency
+#define SharedLibXTransparency	NO
+#endif
+#ifndef NormalLibXTransparency
+#define NormalLibXTransparency	YES
+#endif
+#ifndef DebugLibXTransparency
+#define DebugLibXTransparency	NO
+#endif
+#ifndef ProfileLibXTransparency
+#define ProfileLibXTransparency	NO
+#endif
+#endif
 
 #if BuildDPSLibrary
 #ifndef SharedLibDps
diff -Naur --exclude=host.def /extra/x421.org/xc/config/cf/directfb.cf /extra/x421/xc/config/cf/directfb.cf
--- /extra/x421.org/xc/config/cf/directfb.cf	Tue Dec 24 17:10:34 2002
+++ /extra/x421/xc/config/cf/directfb.cf	Tue Dec 24 17:33:05 2002
@@ -7,7 +7,9 @@
  */
 XCOMM $XConsortium: $
 
-
+/* The X top-level window transparency extension */
+#define BuildTransparency	YES
+#define BuildTransparencyLib	YES
 
 /* no direct graphics extension */
 #define BuildXF86DGA            NO
diff -Naur --exclude=host.def /extra/x421.org/xc/include/extensions/Imakefile /extra/x421/xc/include/extensions/Imakefile
--- /extra/x421.org/xc/include/extensions/Imakefile	Sun Dec 16 10:19:50 2001
+++ /extra/x421/xc/include/extensions/Imakefile	Mon Dec 23 16:59:28 2002
@@ -48,12 +48,15 @@
 XTRAPHEADERS = xtrapbits.h xtrapddmi.h xtrapdi.h xtrapemacros.h xtraplib.h \
 	xtraplibp.h xtrapproto.h
 #endif
+#if BuildTransparency || BuildTransparencyLibs
+TRANSPARENCYHEADERS = transparency.h transparencyproto.h
+#endif
 
 EXTRAHEADERS = $(SCREENSAVERHEADERS) $(XF86MISCHEADERS) $(XF86BIGFONTHEADERS) \
 	       $(XF86VIDMODEHEADERS) $(XF86DGAHEADERS) $(XINERAMAHEADERS) \
 	       $(LBXHEADERS) $(XVHEADERS) $(XVMCHEADERS) $(XF86RUSHHEADERS) \
 	       $(FONTCACHEHEADERS) $(RENDERHEADERS) $(RANDRHEADERS) \
-	       $(XTRAPHEADERS)
+	       $(XTRAPHEADERS) $(TRANSPARENCYHEADERS)
 
 
 
diff -Naur --exclude=host.def /extra/x421.org/xc/include/extensions/transparency.h /extra/x421/xc/include/extensions/transparency.h
--- /extra/x421.org/xc/include/extensions/transparency.h	Wed Dec 31 16:00:00 1969
+++ /extra/x421/xc/include/extensions/transparency.h	Thu Dec 26 08:45:25 2002
@@ -0,0 +1,31 @@
+/*
+ * transparency.h
+ *
+ * Copyright 2002 Scott Brumbaugh
+ * All rights reserved
+ *
+ * X-Transparency extension, get/set opacity for top level windows.
+ */
+
+#ifndef _TRANSPARENCY_H_
+#define _TRANSPARENCY_H_
+
+#include <X11/Xlib.h>
+#include <X11/Xfuncproto.h>
+
+/* The opacity, 0 invisible, 255 fully opaque */
+typedef unsigned char OpacityValue;
+
+_XFUNCPROTOBEGIN
+
+Bool XTransparencyQueryExtension(Display * dpy, int *event_base, int *error_base);
+
+Status XTransparencyQueryVersion(Display * dpy, int *major, int *minor);
+
+void XSetTransparency(Display * dpy, Window win, OpacityValue value);
+
+Status XGetTransparency(Display * dpy, Window win, OpacityValue *value);
+
+_XFUNCPROTOEND
+
+#endif /* _TRANSPARENCY_H_ */
diff -Naur --exclude=host.def /extra/x421.org/xc/include/extensions/transparencyproto.h /extra/x421/xc/include/extensions/transparencyproto.h
--- /extra/x421.org/xc/include/extensions/transparencyproto.h	Wed Dec 31 16:00:00 1969
+++ /extra/x421/xc/include/extensions/transparencyproto.h	Thu Dec 26 08:45:08 2002
@@ -0,0 +1,98 @@
+/*
+ * transparencyproto.h
+ *
+ * Copyright 2002 Scott Brumbaugh
+ * All rights reserved
+ *
+ * X-Transparency extension, get/set opacity for top level windows.
+ */
+
+#ifndef _TRANSPARENCYPROTO_H_
+#define _TRANSPARENCYPROTO_H_
+
+#include <X11/Xlibint.h>
+
+#define TRANSPARENCY_NAME "X-Transparency"
+#define TRANSPARENCY_MAJOR 0
+#define TRANSPARENCY_MINOR 1
+
+#define X_TRANSPARENCY_ERRORS 0
+#define X_TRANSPARENCY_EVENTS 0
+
+#define X_XTransparencyQueryVersion 0
+#define X_XSetTransparency 1
+#define X_XGetTransparency 2
+
+#define Window CARD32
+#define Transparency CARD32
+
+typedef struct
+{
+    CARD8 reqType;
+    CARD8 transparencyReqType;
+    CARD16 length B16;
+    CARD32 major B32;
+    CARD32 minor B32;
+}
+xXTransparencyQueryVersionReq;
+
+#define sz_xXTransparencyQueryVersionReq 12
+
+typedef struct
+{
+    CARD8 type;                        /* X_Reply */
+    CARD8 pad1;
+    CARD16 sequence B16;
+    CARD32 length B32;
+    CARD32 major B32;
+    CARD32 minor B32;
+    CARD32 pad2 B32;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+}
+xXTransparencyQueryVersionReply;
+
+#define sz_xXTransparencyQueryVersionReply 32
+
+typedef struct
+{
+    CARD8 reqType;
+    CARD8 transparencyReqType;
+    CARD16 length B16;
+    CARD32 window B32;
+}
+xXGetTransparencyReq;
+
+#define sz_xXGetTransparencyReq 8
+
+typedef struct
+{
+    CARD8 type;
+    CARD8 pad1;
+    CARD16 sequence B16;
+    CARD32 length B32;
+    CARD32 value B32;
+    CARD32 pad2 B32;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+}
+xXGetTransparencyReply;
+
+#define sz_xXGetTransparencyReply 32
+
+typedef struct
+{
+    CARD8 reqType;
+    CARD8 transparencyReqType;
+    CARD16 length B16;
+    CARD32 window B32;
+    CARD32 value B32;
+}
+xXSetTransparencyReq;
+
+#define sz_xXSetTransparencyReq 12
+
+#endif /* _TRANSPARENCYPROTO_H_ */
diff -Naur --exclude=host.def /extra/x421.org/xc/include/extensions/transparencystr.h /extra/x421/xc/include/extensions/transparencystr.h
--- /extra/x421.org/xc/include/extensions/transparencystr.h	Wed Dec 31 16:00:00 1969
+++ /extra/x421/xc/include/extensions/transparencystr.h	Thu Dec 26 08:45:18 2002
@@ -0,0 +1,19 @@
+/*
+ * transparencystr.h
+ *
+ * Copyright 2002 Scott Brumbaugh
+ * All rights reserved
+ *
+ * X-Transparency extension, get/set opacity for top level windows.
+ */
+
+#ifndef _TRANSPARENCYSTR_H_
+#define _TRANSPARENCYSTR_H_
+
+typedef Bool(*SetTransparencyProcPtr) (WindowPtr, unsigned char);
+typedef Bool(*GetTransparencyProcPtr) (WindowPtr, unsigned char *);
+
+Bool TransparencyExtAddScreen(ScreenPtr, SetTransparencyProcPtr, GetTransparencyProcPtr);
+void XTransparencyExtensionInit(void);
+
+#endif /* _TRANSPARENCYSTR_H_ */
diff -Naur --exclude=host.def /extra/x421.org/xc/lib/Imakefile /extra/x421/xc/lib/Imakefile
--- /extra/x421.org/xc/lib/Imakefile	Fri Nov  2 15:29:26 2001
+++ /extra/x421/xc/lib/Imakefile	Mon Dec 23 17:01:48 2002
@@ -144,6 +144,10 @@
 FONTCACHELIBDIR = Xfontcache
 #endif
 
+#if BuildTransparencyLib
+TRANSPARENCYLIBDIR = Xtransparency
+#endif
+
 FONTSUBDIR = font
 
 #if BuildFontEncLib
@@ -190,7 +194,8 @@
 	     $(XVLIBDIR) $(GLXLIBDIR) $(GLULIBDIR) $(GLWLIBDIR) \
 	     $(DPSLIBDIR) $(DPSTKLIBDIR) $(PSRESLIBDIR) $(XINERAMADIR) \
 	     $(ZLIBDIR) $(REGEXDIR) $(RENDERLIBDIR) $(FREETYPE2BUILDDIR) \
-	     $(XFTLIBDIR) $(XVMCLIBDIR) $(RANDRLIBDIR) $(XTRAPLIBDIR)
+	     $(XFTLIBDIR) $(XVMCLIBDIR) $(RANDRLIBDIR) $(XTRAPLIBDIR) \
+             $(TRANSPARENCYLIBDIR)
 
 SUBDIRS = $(BERKDIR) xtrans $(LINTSUBDIRS) $(FONTSUBDIR) $(FONTENCSUBDIR) \
 	  $(FONTCACHELIBDIR)
diff -Naur --exclude=host.def /extra/x421.org/xc/lib/Xtransparency/Imakefile /extra/x421/xc/lib/Xtransparency/Imakefile
--- /extra/x421.org/xc/lib/Xtransparency/Imakefile	Wed Dec 31 16:00:00 1969
+++ /extra/x421/xc/lib/Xtransparency/Imakefile	Mon Dec 23 17:00:00 2002
@@ -0,0 +1,30 @@
+XCOMM $XFree86$
+
+#define DoNormalLib NormalLibXTransparency
+#define DoSharedLib SharedLibXTransparency
+#define DoDebugLib DebugLibXTransparency
+#define DoProfileLib ProfileLibXTransparency
+#define LibName XTransparency
+#define SoRev SOXTRANSPARENCYREV
+#define IncSubdir X11
+#define IncSubSubdir extensions
+
+#include <Threads.tmpl>
+
+#ifdef SharedXTransparencyReqs
+REQUIREDLIBS = SharedXTransparencyReqs
+#endif
+
+#if Malloc0ReturnsNull
+ALLOC_DEFINES = -DMALLOC_0_RETURNS_NULL
+#endif
+
+      DEFINES = $(ALLOC_DEFINES)
+     INCLUDES = -I$(XLIBSRC) -I$(EXTINCSRC)
+         SRCS = transparency.c
+         OBJS = transparency.o
+     LINTLIBS = $(LINTXLIB)
+
+#include <Library.tmpl>
+
+DependTarget()
diff -Naur --exclude=host.def /extra/x421.org/xc/lib/Xtransparency/transparency.c /extra/x421/xc/lib/Xtransparency/transparency.c
--- /extra/x421.org/xc/lib/Xtransparency/transparency.c	Wed Dec 31 16:00:00 1969
+++ /extra/x421/xc/lib/Xtransparency/transparency.c	Thu Dec 26 08:46:34 2002
@@ -0,0 +1,196 @@
+/*
+ * transparency.c
+ *
+ * Copyright 2002 Scott Brumbaugh
+ * All rights reserved
+ *
+ * X-Transparency extension, get/set opacity for top level windows.
+ */
+
+#include "transparency.h"
+#include "transparencyproto.h"
+
+#include <X11/Xlib.h>
+#include <X11/Xlibint.h>
+#include <Xext.h>
+#include <extutil.h>
+
+#include <stdio.h>
+
+typedef struct
+{
+    int major;
+    int minor;
+}
+XTransparencyInfo;
+
+XExtensionInfo XTransparencyExtensionInfo;
+
+static Status XTransparencyCloseDisplay(Display * dpy, XExtCodes * codes);
+
+static XExtensionHooks transparency_extension_hooks = {
+    NULL,                              /* create_gc */
+    NULL,                              /* copy_gc */
+    NULL,                              /* flush_gc */
+    NULL,                              /* free_gc */
+    NULL,                              /* create_font */
+    NULL,                              /* free_font */
+    XTransparencyCloseDisplay,         /* close_display */
+    NULL,                              /* wire_to_event */
+    NULL,                              /* event_to_wire */
+    NULL,                              /* error */
+    NULL,                              /* error_string */
+};
+
+#define XTransparencyCheckExtension(dpy,i,val) \
+    XextCheckExtension(dpy,i,TRANSPARENCY_NAME, val)
+#define XTransparencySimpleCheckExtension(dpy,i) \
+    XextSimpleCheckExtension(dpy,i,TRANSPARENCY_NAME)
+
+XExtDisplayInfo *
+XTransparencyFindDisplay(Display * dpy)
+{
+    XExtDisplayInfo *dpyinfo;
+    XTransparencyInfo *xti;
+
+    dpyinfo = XextFindDisplay(&XTransparencyExtensionInfo, dpy);
+
+    if (!dpyinfo) {
+        xti = Xmalloc(sizeof(XTransparencyInfo));
+        if (xti == NULL) {
+            return NULL;
+        }
+
+        dpyinfo = XextAddDisplay(&XTransparencyExtensionInfo, dpy,
+            TRANSPARENCY_NAME, &transparency_extension_hooks, 0, 0);
+
+        xti->major = -1;
+        xti->minor = -1;
+        dpyinfo->data = (char *)xti;
+    }
+
+    return dpyinfo;
+}
+
+Bool
+XTransparencyQueryExtension(Display * dpy, int *event_basep, int *error_basep)
+{
+    XExtDisplayInfo *info = XTransparencyFindDisplay(dpy);
+
+    if (XextHasExtension(info)) {
+        *event_basep = info->codes->first_event;
+        *error_basep = info->codes->first_error;
+        return True;
+    } else {
+        return False;
+    }
+
+}
+
+Status
+XTransparencyQueryVersion(Display * dpy,
+    int *major_versionp, int *minor_versionp)
+{
+
+    XExtDisplayInfo *info = XTransparencyFindDisplay(dpy);
+    XTransparencyInfo *xti;
+    xXTransparencyQueryVersionReq *request;
+    xXTransparencyQueryVersionReply reply;
+
+    XTransparencyCheckExtension(dpy, info, 0);
+
+    xti = (XTransparencyInfo *) info->data;
+
+    LockDisplay(dpy);
+
+    GetReq(XTransparencyQueryVersion, request);
+    request->reqType = info->codes->major_opcode;
+    request->transparencyReqType = X_XTransparencyQueryVersion;
+    request->major = 0;
+    request->minor = 0;
+    if (!_XReply(dpy, (xReply *) & reply, 0, True)) {
+        UnlockDisplay(dpy);
+        SyncHandle();
+        return 0;                      /* failure */
+    }
+
+    xti->major = reply.major;
+    xti->minor = reply.minor;
+
+    UnlockDisplay(dpy);
+
+    *major_versionp = xti->major;
+    *minor_versionp = xti->minor;
+
+    SyncHandle();
+
+    return 1;
+}
+
+void
+XSetTransparency(Display * dpy, Window win, OpacityValue value)
+{
+    XExtDisplayInfo *info = XTransparencyFindDisplay(dpy);
+    xXSetTransparencyReq *request;
+
+    XTransparencySimpleCheckExtension(dpy, info);
+
+    LockDisplay(dpy);
+    GetReq(XSetTransparency, request);
+    request->reqType = info->codes->major_opcode;
+    request->transparencyReqType = X_XSetTransparency;
+    request->window = win;
+    request->value = (CARD32) value;
+    UnlockDisplay(dpy);
+    SyncHandle();
+}
+
+Status
+XGetTransparency(Display * dpy, Window win, OpacityValue *value)
+{
+
+    XExtDisplayInfo *info = XTransparencyFindDisplay(dpy);
+    xXGetTransparencyReq *request;
+    xXGetTransparencyReply reply;
+    unsigned long value1;
+
+    XTransparencyCheckExtension(dpy, info, None);
+
+    LockDisplay(dpy);
+    GetReq(XGetTransparency, request);
+    request->reqType = info->codes->major_opcode;
+    request->transparencyReqType = X_XGetTransparency;
+    request->window = win;
+
+    if (!_XReply(dpy, (xReply *) & reply, 0, xFalse)) {
+        UnlockDisplay(dpy);
+        SyncHandle();
+        return BadRequest;
+    }
+
+    *value = (OpacityValue)reply.value;
+
+    UnlockDisplay(dpy);
+    SyncHandle();
+
+    return Success;
+
+}
+
+static Status
+XTransparencyCloseDisplay(Display * dpy, XExtCodes * codes)
+{
+
+    XExtDisplayInfo *info = XTransparencyFindDisplay(dpy);
+
+    LockDisplay(dpy);
+    if (info->data) {
+        XTransparencyInfo *xti = (XTransparencyInfo *) info->data;
+
+        XFree(xti);
+    }
+    UnlockDisplay(dpy);
+
+    return XextRemoveDisplay(&XTransparencyExtensionInfo, dpy);
+
+}
diff -Naur --exclude=host.def /extra/x421.org/xc/programs/Imakefile /extra/x421/xc/programs/Imakefile
--- /extra/x421.org/xc/programs/Imakefile	Fri Nov  2 15:29:28 2001
+++ /extra/x421/xc/programs/Imakefile	Tue Dec 24 13:34:28 2002
@@ -103,6 +103,10 @@
        XRANDRDIR = xrandr
 #endif
 
+#if BuildTransparency && BuildTransparencyLib
+	XTOGGLETRANSDIR = xtoggletrans
+#endif
+
 #if BuildServersOnly || !BuildClients
 SUBDIRS = $(XSSRCDIR)
 #else
@@ -127,7 +131,7 @@
 	$(XTERMSRCDIR) $(XTRAPCLIENTDIRS) $(XVIDTUNESRCDIR) xwd xwininfo xwud \
 	$(XPMCLIENTDIRS) $(XVINFOSRCDIR) \
 	$(XSSRCDIR) $(XASSRCDIR) $(LBXPROXYSRCDIR) $(SCRIPTSDIR) \
-	$(GLXCLIENTDIRS) $(XFTCACHEDIR) $(XRANDRDIR)
+	$(GLXCLIENTDIRS) $(XFTCACHEDIR) $(XRANDRDIR) $(XTOGGLETRANSDIR)
 #endif
 
 MakeSubdirs($(SUBDIRS))
diff -Naur --exclude=host.def /extra/x421.org/xc/programs/Xserver/Imakefile /extra/x421/xc/programs/Xserver/Imakefile
--- /extra/x421.org/xc/programs/Xserver/Imakefile	Tue Dec 24 17:10:13 2002
+++ /extra/x421/xc/programs/Xserver/Imakefile	Mon Dec 23 17:53:01 2002
@@ -521,8 +521,8 @@
 DIRECTFBDIRS = $(STDDIRS) $(FBDIR) $(DIRECTFBDDXDIR) $(DEPDIRS)
 DIRECTFBOBJS = 
 DIRECTFBLIBS = PreFbLibs $(DIRECTFBDDXDIR)/LibraryTargetName(directfb) FbPostFbLibs
-DIRECTFBSYSLIBS = $(FONTLIBS) $(SYSLIBS) `directfb-config --libs`
-
+DIRECTFBRPATHDIR = $(shell directfb-config --prefix)/lib
+DIRECTFBSYSLIBS = $(FONTLIBS) $(SYSLIBS) `directfb-config --libs` -Wl,-rpath,$(DIRECTFBRPATHDIR)
 
 SetUIDServerTarget(XDirectFB,$(DIRECTFBDIRS),$(DIRECTFBOBJS), \
 	$(DIRECTFBLIBS),$(DIRECTFBSYSLIBS))
diff -Naur --exclude=host.def /extra/x421.org/xc/programs/Xserver/Xext/Imakefile /extra/x421/xc/programs/Xserver/Xext/Imakefile
--- /extra/x421.org/xc/programs/Xserver/Xext/Imakefile	Sun Mar  4 20:51:55 2001
+++ /extra/x421/xc/programs/Xserver/Xext/Imakefile	Mon Dec 23 17:03:23 2002
@@ -96,20 +96,26 @@
 #endif
 #endif
 
+#if BuildTransparency
+        TRANSPARENCYSRCS = transparency.c
+        TRANSPARENCYOBJS = transparency.o
+#endif
+
+
 
        SRCS = shape.c $(SHMSRCS) $(MULTIBUFSRC) \
               mitmisc.c xtest.c xtest1di.c xtest1dd.c sleepuntil.c \
 	      bigreq.c sync.c $(SCRNSAVSRC) xcmisc.c $(VIDMODESRCS) \
 	      $(XF86MISCSRCS) $(XF86BIGFSRCS) $(XF86DGASRCS) $(SECURITYSRCS) \
 	      $(APPGROUPSRCS) xprint.c $(CUPSRCS) $(PNRXSRCS) $(DPMSSRCS) \
-	      $(EVISRCS) $(XVSRCS) $(FONTCACHESRCS)
+	      $(EVISRCS) $(XVSRCS) $(FONTCACHESRCS) $(TRANSPARENCYSRCS)
 
        OBJS = shape.o $(SHMOBJS) $(MULTIBUFOBJ) \
               mitmisc.o xtest.o xtest1di.o xtest1dd.o sleepuntil.o \
               bigreq.o sync.o $(SCRNSAVOBJ) xcmisc.o $(VIDMODEOBJS) \
 	      $(XF86MISCOBJS) $(XF86BIGFOBJS) $(XF86DGAOBJS) $(SECURITYOBJS) \
 	      $(APPGROUPOBJS) xprint.o $(CUPOBJS) $(PNRXOBJS) $(DPMSOBJS) \
-	      $(EVIOBJS) $(XVOBJS) $(FONTCACHEOBJS)
+	      $(EVIOBJS) $(XVOBJS) $(FONTCACHEOBJS) $(TRANSPARENCYOBJS)
 
       SOBJS = $(SHMOBJS) $(APPGROUPOBJS) $(SECURITYOBJS) xprint.o \
 	      xtest.o xtest1di.o xtest1dd.o sleepuntil.o $(PNRXOBJS) \
diff -Naur --exclude=host.def /extra/x421.org/xc/programs/Xserver/Xext/transparency.c /extra/x421/xc/programs/Xserver/Xext/transparency.c
--- /extra/x421.org/xc/programs/Xserver/Xext/transparency.c	Wed Dec 31 16:00:00 1969
+++ /extra/x421/xc/programs/Xserver/Xext/transparency.c	Thu Dec 26 15:07:01 2002
@@ -0,0 +1,285 @@
+/*
+ * transparency.c
+ *
+ * Copyright 2002 Scott Brumbaugh
+ * All rights reserved
+ *
+ * X-Transparency extension, get/set opacity for top level windows.
+ */
+
+#include "X.h"
+#include "Xdefs.h"
+#include "windowstr.h"
+#include "scrnintstr.h"
+#include "extnsionst.h"
+#include "dixstruct.h"
+
+#include "transparencyproto.h"
+#include "transparencystr.h"
+#include "transparency.h"
+
+#define IsTopLevel(pWin) \
+	((pWin) && (pWin)->parent && !(pWin)->parent->parent)
+
+typedef struct _TransparencyPrivate
+{
+    SetTransparencyProcPtr SetTransparencyCallback;
+    GetTransparencyProcPtr GetTransparencyCallback;
+    CloseScreenProcPtr CloseScreen;
+}
+TransparencyPrivate, *TransparencyPrivatePtr;
+
+static int TransparencyScreenPrivateIndex;
+static int TransparencyGeneration = 0;
+
+Bool TransparencyExtAddScreen(ScreenPtr, SetTransparencyProcPtr, GetTransparencyProcPtr);
+static Bool TransparencyCloseScreen(int i, ScreenPtr pScreen);
+
+static int ProcXTransparencyQueryVersion(ClientPtr);
+static int SProcXTransparencyQueryVersion(ClientPtr);
+static int ProcXTransparencySet(ClientPtr);
+static int SProcXTransparencySet(ClientPtr);
+static int ProcXTransparencyGet(ClientPtr);
+static int SProcXTransparencyGet(ClientPtr);
+static int ProcXTransparencyDispatch(ClientPtr);
+static int SProcXTransparencyDispatch(ClientPtr);
+
+static void
+XTransparencyResetProc(ExtensionEntry * extEntry)
+{
+	/* empty */
+}
+
+void
+XTransparencyExtensionInit()
+{
+    ExtensionEntry *extEntry = AddExtension(TRANSPARENCY_NAME,
+        X_TRANSPARENCY_EVENTS, X_TRANSPARENCY_ERRORS,
+        ProcXTransparencyDispatch,
+        SProcXTransparencyDispatch,
+        XTransparencyResetProc,
+        StandardMinorOpcode);
+}
+
+Bool
+TransparencyExtAddScreen(ScreenPtr pScreen,
+    SetTransparencyProcPtr setTransparency,
+    GetTransparencyProcPtr getTransparency)
+{
+
+    TransparencyPrivatePtr pTransparencyPrivate;
+
+    if (TransparencyGeneration != serverGeneration) {
+        TransparencyScreenPrivateIndex = AllocateScreenPrivateIndex();
+        if (TransparencyScreenPrivateIndex < 0) {
+            return FALSE;
+        }
+        TransparencyGeneration = serverGeneration;
+    }
+
+    pTransparencyPrivate = xalloc(sizeof(TransparencyPrivate));
+    if (pTransparencyPrivate == 0) {
+        return FALSE;
+    }
+
+    pTransparencyPrivate->SetTransparencyCallback = setTransparency;
+    pTransparencyPrivate->GetTransparencyCallback = getTransparency;
+    pTransparencyPrivate->CloseScreen = pScreen->CloseScreen;
+
+    pScreen->CloseScreen = TransparencyCloseScreen;
+
+    pScreen->devPrivates[TransparencyScreenPrivateIndex].ptr =
+        (pointer) pTransparencyPrivate;
+
+    return TRUE;
+}
+
+static Bool
+TransparencyCloseScreen(int i, ScreenPtr pScreen)
+{
+
+    TransparencyPrivatePtr pTransparencyPrivate;
+
+    pTransparencyPrivate =
+        (TransparencyPrivatePtr) pScreen->
+        devPrivates[TransparencyScreenPrivateIndex].ptr;
+
+    pScreen->CloseScreen = pTransparencyPrivate->CloseScreen;
+
+    XFree(pTransparencyPrivate);
+
+    return pScreen->CloseScreen(i, pScreen);
+
+}
+
+static int
+ProcXTransparencyQueryVersion(ClientPtr client)
+{
+
+    REQUEST(xXTransparencyQueryVersionReq);
+    xXTransparencyQueryVersionReply reply;
+
+    REQUEST_SIZE_MATCH(xXTransparencyQueryVersionReq);
+
+    reply.type = X_Reply;
+    reply.length = 0;
+    reply.sequence = client->sequence;
+    reply.major = TRANSPARENCY_MAJOR;
+    reply.minor = TRANSPARENCY_MINOR;
+    if (client->swapped) {
+        int n;
+
+        swaps(&reply.sequence, n);
+        swapl(&reply.length, n);
+        swaps(&reply.major, n);
+        swaps(&reply.minor, n);
+    }
+    WriteToClient(client, sz_xXTransparencyQueryVersionReply, (char *)&reply);
+
+    return client->noClientException;
+
+}
+
+static int
+SProcXTransparencyQueryVersion(ClientPtr client)
+{
+    REQUEST(xXTransparencyQueryVersionReq);
+    int n;
+
+    REQUEST_SIZE_MATCH(xXTransparencyQueryVersionReq);
+    swaps(&stuff->major, n);
+    swaps(&stuff->minor, n);
+    return ProcXTransparencyQueryVersion(client);
+}
+
+static int
+ProcXTransparencySet(ClientPtr client)
+{
+
+    REQUEST(xXSetTransparencyReq);
+    WindowPtr pWin;
+    OpacityValue value;
+    TransparencyPrivatePtr pPriv;
+
+    REQUEST_SIZE_MATCH(xXSetTransparencyReq);
+
+    pWin = LookupWindow(stuff->window, client);
+    if (!IsTopLevel(pWin)) {
+        return BadWindow;
+    }
+
+    if (TransparencyScreenPrivateIndex == -1) {
+        return BadMatch;
+    }
+
+    pPriv =
+        (TransparencyPrivatePtr) pWin->drawable.pScreen->
+        devPrivates[TransparencyScreenPrivateIndex].ptr;
+
+    value = (OpacityValue) stuff->value;
+
+    if (!pPriv->SetTransparencyCallback(pWin, value)) {
+        return BadMatch;
+    }
+
+    return client->noClientException;
+}
+
+static int
+SProcXTransparencySet(ClientPtr client)
+{
+    return ProcXTransparencySet(client);
+}
+
+static int
+ProcXTransparencyGet(ClientPtr client)
+{
+
+    REQUEST(xXGetTransparencyReq);
+    xXGetTransparencyReply reply;
+    WindowPtr pWin;
+    OpacityValue value;
+    TransparencyPrivatePtr pPriv;
+
+    REQUEST_SIZE_MATCH(xXGetTransparencyReq);
+
+    pWin = LookupWindow(stuff->window, client);
+    if (!IsTopLevel(pWin)) {
+        return BadWindow;
+    }
+
+    if (TransparencyScreenPrivateIndex == -1) {
+        return BadMatch;
+    }
+
+    pPriv =
+        (TransparencyPrivatePtr) pWin->drawable.pScreen->
+        devPrivates[TransparencyScreenPrivateIndex].ptr;
+
+    if (!pPriv->GetTransparencyCallback(pWin, &value)) {
+        return BadMatch;
+    }
+
+    reply.type = X_Reply;
+    reply.sequence = client->sequence;
+    reply.length = 0;                  /* words */
+    reply.value = (CARD32) value;
+    if (client->swapped) {
+        int n;
+
+        swaps(&reply.sequence, n);
+        swapl(&reply.length, n);
+        swapl(&reply.value, n);
+    }
+
+    WriteToClient(client, sz_xXGetTransparencyReply, (char *)&reply);
+
+    return client->noClientException;
+}
+
+static int
+SProcXTransparencyGet(ClientPtr client)
+{
+    REQUEST(xXGetTransparencyReq);
+
+    REQUEST_SIZE_MATCH(xXGetTransparencyReq);
+
+    return ProcXTransparencyGet(client);
+}
+
+static int
+ProcXTransparencyDispatch(ClientPtr client)
+{
+    REQUEST(xReq);
+
+    switch (stuff->data) {
+    case X_XTransparencyQueryVersion:
+        return ProcXTransparencyQueryVersion(client);
+    case X_XSetTransparency:
+        return ProcXTransparencySet(client);
+    case X_XGetTransparency:
+        return ProcXTransparencyGet(client);
+    }
+
+    return BadRequest;
+}
+
+static int
+SProcXTransparencyDispatch(ClientPtr client)
+{
+    REQUEST(xReq);
+    int n;
+
+    swaps(&stuff->length, n);
+
+    switch (stuff->data) {
+    case X_XTransparencyQueryVersion:
+        return SProcXTransparencyQueryVersion(client);
+    case X_XSetTransparency:
+        return SProcXTransparencySet(client);
+    case X_XGetTransparency:
+        return SProcXTransparencyGet(client);
+    }
+
+    return BadRequest;
+}
diff -Naur --exclude=host.def /extra/x421.org/xc/programs/Xserver/hw/directfb/Imakefile /extra/x421/xc/programs/Xserver/hw/directfb/Imakefile
--- /extra/x421.org/xc/programs/Xserver/hw/directfb/Imakefile	Tue Dec 24 17:11:04 2002
+++ /extra/x421/xc/programs/Xserver/hw/directfb/Imakefile	Tue Dec 24 18:10:48 2002
@@ -33,6 +33,9 @@
 DEFINES = -Wall
 EXTRAMANDEFS = -D__logdir__=$(LOGDIRECTORY)
 
+SpecialCObjectRule(directfbScreen,NullParameter,XTransparencyExtensionDefines)
+SpecialCObjectRule(rootlessDirectFB,NullParameter,XTransparencyExtensionDefines)
+
 NormalLibraryObjectRule()
 NormalLibraryTarget(directfb,$(OBJS))
 
diff -Naur --exclude=host.def /extra/x421.org/xc/programs/Xserver/hw/directfb/directfbScreen.c /extra/x421/xc/programs/Xserver/hw/directfb/directfbScreen.c
--- /extra/x421.org/xc/programs/Xserver/hw/directfb/directfbScreen.c	Tue Dec 24 17:11:04 2002
+++ /extra/x421/xc/programs/Xserver/hw/directfb/directfbScreen.c	Tue Dec 24 17:34:55 2002
@@ -33,6 +33,10 @@
 #include "globals.h"
 #include "dix.h"
 
+#ifdef XTRANSPARENCY
+#include "transparencystr.h"
+#endif
+
 /* System headers */
 #include <unistd.h>
 #include <sys/types.h>
@@ -274,6 +278,10 @@
     ShmRegisterFbFuncs(pScreen);
 #endif
 
+#ifdef XTRANSPARENCY
+    TransparencyExtAddScreen(pScreen, XDirectFBSetTransparency, XDirectFBGetTransparency);
+#endif
+
   /* This must be initialized (why doesnt X have a default?) */
   pScreen->SaveScreen = XDirectFBSaveScreen;
 
diff -Naur --exclude=host.def /extra/x421.org/xc/programs/Xserver/hw/directfb/rootlessDirectFB.c /extra/x421/xc/programs/Xserver/hw/directfb/rootlessDirectFB.c
--- /extra/x421.org/xc/programs/Xserver/hw/directfb/rootlessDirectFB.c	Tue Dec 24 17:11:04 2002
+++ /extra/x421/xc/programs/Xserver/hw/directfb/rootlessDirectFB.c	Thu Dec 26 15:22:34 2002
@@ -1067,3 +1067,45 @@
   return FALSE;
 }
 
+#ifdef XTRANSPARENCY
+/* Callbacks for the X-Transparent top level window extention */
+/* Get the current transparency for a window */ 
+Bool XDirectFBGetTransparency(WindowPtr pWin, __u8 * value)
+{
+
+    RootlessWindowRec *pWinRec;
+    DirectFBWindowRec *pDFBWinRec;
+
+    pWinRec = WINREC(pWin);
+    if (!pWinRec)
+    {
+        return FALSE;
+    }
+    pDFBWinRec = DFBWINREC(&pWinRec->frame);
+    *value = pDFBWinRec->opacity.current;
+
+    return TRUE;
+}
+
+/* Set the current opacity for a window */
+Bool XDirectFBSetTransparency(WindowPtr pWin, __u8 value)
+{
+
+    RootlessWindowRec *pWinRec;
+    DirectFBWindowRec *pDFBWinRec;
+    IDirectFBWindow *window;
+
+    pWinRec = WINREC(pWin);
+    if (!pWinRec)
+    {
+        return FALSE;
+    }
+
+    pDFBWinRec = DFBWINREC(&(pWinRec->frame));
+    pDFBWinRec->opacity.current = value;
+    window = pDFBWinRec->window;
+    window->SetOpacity(window, value);
+
+    return TRUE;
+}
+#endif /* XTRANSPARENCY */
diff -Naur --exclude=host.def /extra/x421.org/xc/programs/Xserver/hw/directfb/rootlessDirectFB.h /extra/x421/xc/programs/Xserver/hw/directfb/rootlessDirectFB.h
--- /extra/x421.org/xc/programs/Xserver/hw/directfb/rootlessDirectFB.h	Tue Dec 24 17:11:04 2002
+++ /extra/x421/xc/programs/Xserver/hw/directfb/rootlessDirectFB.h	Thu Dec 26 08:20:27 2002
@@ -33,4 +33,10 @@
  */
 Bool XDirectFBProcessWindowEvent (DFBWindowEvent *event);
 
+#ifdef XTRANSPARENCY
+/* Callbacks for the X top-level window transparency extension */
+Bool XDirectFBSetTransparency(WindowPtr pWin, __u8 value);
+Bool XDirectFBGetTransparency(WindowPtr pWin, __u8 * value);
+#endif
+
 #endif /* _ROOTLESSDIRECTFB_H */
diff -Naur --exclude=host.def /extra/x421.org/xc/programs/Xserver/mi/miinitext.c /extra/x421/xc/programs/Xserver/mi/miinitext.c
--- /extra/x421.org/xc/programs/Xserver/mi/miinitext.c	Fri Dec 14 12:00:23 2001
+++ /extra/x421/xc/programs/Xserver/mi/miinitext.c	Tue Dec 24 17:34:06 2002
@@ -104,6 +104,9 @@
 #ifdef XF86BIGFONT
 #include "xf86bigfstr.h"
 #endif
+#ifdef XTRANSPARENCY
+#include "transparencystr.h"
+#endif
 
 /* FIXME: this whole block of externs should be from the appropriate headers */
 #ifdef BEZIER
@@ -222,6 +225,9 @@
 #ifdef RANDR
 extern void RRExtensionInit(INITARGS);
 #endif
+#ifdef XTRANSPARENCY
+extern void XTransparencyExtensionInit(INITARGS);
+#endif
 
 #ifndef XFree86LOADER
 
@@ -354,6 +360,10 @@
 #ifdef RANDR
     RRExtensionInit();
 #endif
+#ifdef XTRANSPARENCY
+	XTransparencyExtensionInit();
+#endif
+
 }
 
 void
diff -Naur --exclude=host.def /extra/x421.org/xc/programs/xtoggletrans/Imakefile /extra/x421/xc/programs/xtoggletrans/Imakefile
--- /extra/x421.org/xc/programs/xtoggletrans/Imakefile	Wed Dec 31 16:00:00 1969
+++ /extra/x421/xc/programs/xtoggletrans/Imakefile	Tue Dec 24 16:46:15 2002
@@ -0,0 +1,9 @@
+        DEPLIBS = $(DEPXMUULIB) $(DEPXLIB)
+LOCAL_LIBRARIES = $(XMUULIB) $(XLIB) -lXTransparency
+           SRCS = xtoggletrans.c dsimple.c
+           OBJS = xtoggletrans.o dsimple.o
+
+LinkSourceFile(dsimple.c,../xlsfonts)
+LinkSourceFile(dsimple.h,../xlsfonts)
+
+ComplexProgramTargetNoMan(xtoggletrans)
diff -Naur --exclude=host.def /extra/x421.org/xc/programs/xtoggletrans/xtoggletrans.c /extra/x421/xc/programs/xtoggletrans/xtoggletrans.c
--- /extra/x421.org/xc/programs/xtoggletrans/xtoggletrans.c	Wed Dec 31 16:00:00 1969
+++ /extra/x421/xc/programs/xtoggletrans/xtoggletrans.c	Thu Dec 26 14:56:00 2002
@@ -0,0 +1,92 @@
+/*
+ * xtoggletrans.c
+ *
+ * Copyright 2002 Scott Brumbaugh
+ * All rights reserved
+ *
+ * Demonstrates use of the X-Transparency extension wich allows
+ * clients to get/set opacity value of top-level windows.
+ */
+
+#include <stdio.h>
+
+#include <X11/Xlib.h>
+#include <X11/extensions/transparency.h>
+
+#include "dsimple.h"
+
+extern Display *dpy;
+
+void
+usage()
+{
+    fprintf(stdout,
+        "xtoggletrans [-value number]\n"
+        "\n"
+        "Toggle transparency of top-level X window with a mouse click.\n"
+        "If the selected window is already partly transparent, it is reset to opaque.\n"
+        "Otherwise, the transparency of the window is set to number.\n"
+        "Number is 0 for transparent, 255 for opaque, default is 127\n");
+
+    exit(1);
+
+}
+
+int
+main(int argc, char *argv[])
+{
+
+    Window window;
+    int event_base, error_base;
+    int major, minor;
+    OpacityValue orig_value;
+    OpacityValue new_value = 127;
+    int i;
+
+    Setup_Display_And_Screen(&argc, argv);
+
+    for (i = 1; i < argc; i++) {
+        if (!strncmp(argv[i], "-value", 6) && argv[++i]) {
+            new_value = (OpacityValue) atoi(argv[i]);
+            continue;
+        }
+        usage();
+    }
+
+    if (!XTransparencyQueryExtension(dpy, &event_base, &error_base)) {
+        fprintf(stderr, "Transparency extension not found\n");
+        exit(1);
+    }
+
+    if (!XTransparencyQueryVersion(dpy, &major, &minor)) {
+        fprintf(stderr, "Query transparency extension version failed\n");
+        exit(1);
+    }
+
+    fprintf(stdout, "Using X-Transparency extension version %d.%d\n",
+        major, minor);
+    fprintf(stdout, "Select a top level window\n");
+
+    window = Select_Window(dpy);
+
+    if (XGetTransparency(dpy, window, &orig_value) != 0) {
+        fprintf(stderr, "Failed to get window transparency\n");
+        exit(1);
+    }
+
+    /*
+     * Toggle the transparency value between full opacity and the new value
+     * If the window is already partly transparent reset it to opaque
+     */
+    if (orig_value != 255) {
+        new_value = 255;
+    }
+
+    XSetTransparency(dpy, window, new_value);
+
+    XSync(dpy, False);
+
+    fprintf(stdout, "Window id 0x%lx: transparency was %d now %d\n", window, orig_value,
+        new_value);
+
+}



-- 
Info:  To unsubscribe send a mail to listar@directfb.org with 
"unsubscribe directfb-dev" as subject.



Home | Main Index | Thread Index


directfb.org / Development / Old Archives