#define CAN_DO_USABLE 0
+typedef enum {
+ WINTYPE_DESKTOP,
+ WINTYPE_DOCK,
+ WINTYPE_TOOLBAR,
+ WINTYPE_MENU,
+ WINTYPE_UTILITY,
+ WINTYPE_SPLASH,
+ WINTYPE_DIALOG,
+ WINTYPE_NORMAL,
+ WINTYPE_DROPDOWN_MENU,
+ WINTYPE_POPUP_MENU,
+ WINTYPE_TOOLTIP,
+ WINTYPE_NOTIFY,
+ WINTYPE_COMBO,
+ WINTYPE_DND,
+ NUM_WINTYPES
+} wintype;
+
typedef struct _ignore {
struct _ignore *next;
unsigned long sequence;
int shadow_width;
int shadow_height;
unsigned int opacity;
- Atom windowType;
+ wintype windowType;
unsigned long damage_sequence; /* sequence when damage was created */
+ Bool need_configure;
+ XConfigureEvent queue_configure;
+
/* for drawing translucent windows */
XserverRegion borderClip;
struct _win *prev_trans;
/* find these once and be done with it */
Atom opacityAtom;
Atom winTypeAtom;
-Atom winDesktopAtom;
-Atom winDockAtom;
-Atom winToolbarAtom;
-Atom winMenuAtom;
-Atom winUtilAtom;
-Atom winSplashAtom;
-Atom winDialogAtom;
-Atom winNormalAtom;
+Atom winType[NUM_WINTYPES];
+double winTypeOpacity[NUM_WINTYPES];
+Bool winTypeShadow[NUM_WINTYPES];
+Bool winTypeFade[NUM_WINTYPES];
/* opacity property name; sometime soon I'll write up an EWMH spec for it */
#define OPACITY_PROP "_NET_WM_WINDOW_OPACITY"
+#define REGISTER_PROP "_NET_WM_CM_S"
#define TRANSLUCENT 0xe0000000
#define OPAQUE 0xffffffff
determine_mode(Display *dpy, win *w);
static double
-get_opacity_percent(Display *dpy, win *w, double def);
+get_opacity_percent(Display *dpy, win *w);
static XserverRegion
win_extents (Display *dpy, win *w);
double fade_out_step = 0.03;
int fade_delta = 10;
int fade_time = 0;
-Bool fadeWindows = False;
-Bool excludeDockShadows = False;
Bool fadeTrans = False;
Bool autoRedirect = False;
r.y = w->a.y;
r.width = w->a.width + w->a.border_width * 2;
r.height = w->a.height + w->a.border_width * 2;
- if (compMode != CompSimple && !(w->windowType == winDockAtom && excludeDockShadows))
+ if (winTypeShadow[w->windowType])
{
if (compMode == CompServerShadows || w->mode != WINDOW_ARGB)
{
for (w = t; w; w = w->prev_trans)
{
XFixesSetPictureClipRegion (dpy, rootBuffer, 0, 0, w->borderClip);
- switch (compMode) {
- case CompSimple:
- break;
- case CompServerShadows:
- /* dont' bother drawing shadows on desktop windows */
- if (w->windowType == winDesktopAtom)
- break;
- set_ignore (dpy, NextRequest (dpy));
- if (w->opacity != OPAQUE && !w->shadowPict)
- w->shadowPict = solid_picture (dpy, True,
- (double) w->opacity / OPAQUE * 0.3,
- 0, 0, 0);
- XRenderComposite (dpy, PictOpOver,
- w->shadowPict ? w->shadowPict : transBlackPicture,
- w->picture, rootBuffer,
- 0, 0, 0, 0,
- w->a.x + w->shadow_dx,
- w->a.y + w->shadow_dy,
- w->shadow_width, w->shadow_height);
- break;
- case CompClientShadows:
- /* don't bother drawing shadows on desktop windows */
- if (w->shadow && w->windowType != winDesktopAtom)
- {
+ if (winTypeShadow[w->windowType]) {
+ switch (compMode) {
+ case CompSimple:
+ break;
+ case CompServerShadows:
+ set_ignore (dpy, NextRequest (dpy));
+ if (w->opacity != OPAQUE && !w->shadowPict)
+ w->shadowPict = solid_picture (dpy, True,
+ (double) w->opacity / OPAQUE * 0.3,
+ 0, 0, 0);
+ XRenderComposite (dpy, PictOpOver,
+ w->shadowPict ? w->shadowPict : transBlackPicture,
+ w->picture, rootBuffer,
+ 0, 0, 0, 0,
+ w->a.x + w->shadow_dx,
+ w->a.y + w->shadow_dy,
+ w->shadow_width, w->shadow_height);
+ break;
+ case CompClientShadows:
XRenderComposite (dpy, PictOpOver, blackPicture, w->shadow, rootBuffer,
0, 0, 0, 0,
w->a.x + w->shadow_dx,
w->a.y + w->shadow_dy,
w->shadow_width, w->shadow_height);
- }
- break;
- }
+ break;
+ }
+ }
if (w->opacity != OPAQUE && !w->alphaPict)
w->alphaPict = solid_picture (dpy, False,
(double) w->opacity / OPAQUE, 0, 0, 0);
w->damaged = 1;
}
+static const char*
+wintype_name(wintype type)
+{
+ const char *t;
+ switch (type) {
+ case WINTYPE_DESKTOP: t = "desktop"; break;
+ case WINTYPE_DOCK: t = "dock"; break;
+ case WINTYPE_TOOLBAR: t = "toolbar"; break;
+ case WINTYPE_MENU: t = "menu"; break;
+ case WINTYPE_UTILITY: t = "utility"; break;
+ case WINTYPE_SPLASH: t = "slash"; break;
+ case WINTYPE_DIALOG: t = "dialog"; break;
+ case WINTYPE_NORMAL: t = "normal"; break;
+ case WINTYPE_DROPDOWN_MENU: t = "dropdown"; break;
+ case WINTYPE_POPUP_MENU: t = "popup"; break;
+ case WINTYPE_TOOLTIP: t = "tooltip"; break;
+ case WINTYPE_NOTIFY: t = "notification"; break;
+ case WINTYPE_COMBO: t = "combo"; break;
+ case WINTYPE_DND: t = "dnd"; break;
+ default: t = "unknown"; break;
+ }
+ return t;
+}
+
+static wintype
+get_wintype_prop(Display * dpy, Window w)
+{
+ Atom actual;
+ wintype ret;
+ int format;
+ unsigned long n, left, off;
+ unsigned char *data;
+
+ ret = (wintype)-1;
+ off = 0;
+
+ do {
+ set_ignore (dpy, NextRequest (dpy));
+ int result = XGetWindowProperty (dpy, w, winTypeAtom, off, 1L, False,
+ XA_ATOM, &actual, &format,
+ &n, &left, &data);
+
+ if (result != Success)
+ break;
+ if (data != None)
+ {
+ int i;
+
+ for (i = 0; i < NUM_WINTYPES; ++i) {
+ Atom a;
+ memcpy (&a, data, sizeof (Atom));
+ if (a == winType[i]) {
+ /* known type */
+ ret = i;
+ break;
+ }
+ }
+
+ XFree ( (void *) data);
+ }
+
+ ++off;
+ } while (left >= 4 && ret == (wintype)-1);
+
+ return ret;
+}
+
+static wintype
+determine_wintype (Display *dpy, Window w, Window top)
+{
+ Window root_return, parent_return;
+ Window *children = NULL;
+ unsigned int nchildren, i;
+ wintype type;
+
+ type = get_wintype_prop (dpy, w);
+ if (type != (wintype)-1)
+ return type;
+
+ set_ignore (dpy, NextRequest (dpy));
+ if (!XQueryTree (dpy, w, &root_return, &parent_return, &children,
+ &nchildren))
+ {
+ /* XQueryTree failed. */
+ if (children)
+ XFree ((void *)children);
+ return (wintype)-1;
+ }
+
+ for (i = 0;i < nchildren;i++)
+ {
+ type = determine_wintype (dpy, children[i], top);
+ if (type != (wintype)-1)
+ return type;
+ }
+
+ if (children)
+ XFree ((void *)children);
+
+ if (w != top)
+ return (wintype)-1;
+ else
+ return WINTYPE_NORMAL;
+}
+
static unsigned int
get_opacity_prop (Display *dpy, win *w, unsigned int def);
static void
+configure_win (Display *dpy, XConfigureEvent *ce);
+
+static void
map_win (Display *dpy, Window id, unsigned long sequence, Bool fade)
{
win *w = find_win (dpy, id);
return;
w->a.map_state = IsViewable;
-
- /* This needs to be here or else we lose transparency messages */
- XSelectInput (dpy, id, PropertyChangeMask);
- /* This needs to be here since we don't get PropertyNotify when unmapped */
+ w->windowType = determine_wintype (dpy, w->id, w->id);
+#if 0
+ printf("window 0x%x type %s\n", w->id, wintype_name(w->windowType));
+#endif
+
+ /* select before reading the property so that no property changes are lost */
+ XSelectInput (dpy, id, PropertyChangeMask);
w->opacity = get_opacity_prop (dpy, w, OPAQUE);
+
determine_mode (dpy, w);
#if CAN_DO_USABLE
#endif
w->damaged = 0;
-#if HAS_NAME_WINDOW_PIXMAP
- /* If the window was previously mapped and its pixmap still exists, it
- is out of date now, so force us to reacquire it. (If the window
- re-maps before the unmap fade-out finished) */
- if (w->pixmap)
- {
- XFreePixmap (dpy, w->pixmap);
- w->pixmap = None;
- }
-#endif
+ if (fade && winTypeFade[w->windowType])
+ set_fade (dpy, w, 0, get_opacity_percent (dpy, w), fade_in_step, 0, True, True);
- if (fade && fadeWindows)
- set_fade (dpy, w, 0, get_opacity_percent (dpy, w, 1.0), fade_in_step, 0, True, True);
+ /* if any configure events happened while the window was unmapped, then
+ configure the window to its correct place */
+ if (w->need_configure)
+ configure_win (dpy, &w->queue_configure);
}
static void
w->picture = None;
}
- /* don't care about properties anymore */
- set_ignore (dpy, NextRequest (dpy));
- XSelectInput(dpy, w->id, 0);
-
if (w->borderSize)
{
set_ignore (dpy, NextRequest (dpy));
if (!w)
return;
w->a.map_state = IsUnmapped;
+
+ /* don't care about properties anymore */
+ set_ignore (dpy, NextRequest (dpy));
+ XSelectInput(dpy, w->id, 0);
+
#if HAS_NAME_WINDOW_PIXMAP
- if (w->pixmap && fade && fadeWindows)
+ if (w->pixmap && fade && winTypeFade[w->windowType])
set_fade (dpy, w, w->opacity*1.0/OPAQUE, 0.0, fade_out_step, unmap_callback, False, True);
else
#endif
otherwise: the value
*/
static double
-get_opacity_percent(Display *dpy, win *w, double def)
+get_opacity_percent(Display *dpy, win *w)
{
+ double def = winTypeOpacity[w->windowType];
unsigned int opacity = get_opacity_prop (dpy, w, (unsigned int)(OPAQUE*def));
return opacity*1.0/OPAQUE;
}
-/* determine mode for window all in one place.
- Future might check for menu flag and other cool things
-*/
-
-static Atom
-get_wintype_prop(Display * dpy, Window w)
-{
- Atom actual;
- int format;
- unsigned long n, left;
-
- unsigned char *data;
- int result = XGetWindowProperty (dpy, w, winTypeAtom, 0L, 1L, False,
- XA_ATOM, &actual, &format,
- &n, &left, &data);
-
- if (result == Success && data != None)
- {
- Atom a;
- memcpy (&a, data, sizeof (Atom));
- XFree ( (void *) data);
- return a;
- }
- return winNormalAtom;
-}
-
static void
determine_mode(Display *dpy, win *w)
{
}
}
-static Atom
-determine_wintype (Display *dpy, Window w)
-{
- Window root_return, parent_return;
- Window *children = NULL;
- unsigned int nchildren, i;
- Atom type;
-
- type = get_wintype_prop (dpy, w);
- if (type != winNormalAtom)
- return type;
-
- if (!XQueryTree (dpy, w, &root_return, &parent_return, &children,
- &nchildren))
- {
- /* XQueryTree failed. */
- if (children)
- XFree ((void *)children);
- return winNormalAtom;
- }
-
- for (i = 0;i < nchildren;i++)
- {
- type = determine_wintype (dpy, children[i]);
- if (type != winNormalAtom)
- return type;
- }
-
- if (children)
- XFree ((void *)children);
-
- return winNormalAtom;
-}
-
static void
add_win (Display *dpy, Window id, Window prev)
{
new->shadow_width = 0;
new->shadow_height = 0;
new->opacity = OPAQUE;
+ new->need_configure = False;
new->borderClip = None;
new->prev_trans = 0;
- new->windowType = determine_wintype (dpy, new->id);
-
new->next = *p;
*p = new;
if (new->a.map_state == IsViewable)
}
return;
}
+
+ if (w->a.map_state == IsUnmapped) {
+ /* save the configure event for when the window maps */
+ w->need_configure = True;
+ w->queue_configure = *ce;
+ }
+ else {
+ w->need_configure = False;
+
#if CAN_DO_USABLE
- if (w->usable)
+ if (w->usable)
#endif
- {
- damage = XFixesCreateRegion (dpy, 0, 0);
- if (w->extents != None)
- XFixesCopyRegion (dpy, damage, w->extents);
- }
- w->a.x = ce->x;
- w->a.y = ce->y;
- /* Only destroy the pixmap if the window is mapped */
- if (w->a.map_state != IsUnmapped &&
- (w->a.width != ce->width || w->a.height != ce->height))
- {
+ {
+ damage = XFixesCreateRegion (dpy, 0, 0);
+ if (w->extents != None)
+ XFixesCopyRegion (dpy, damage, w->extents);
+ }
+
+ w->a.x = ce->x;
+ w->a.y = ce->y;
+ if (w->a.width != ce->width || w->a.height != ce->height)
+ {
#if HAS_NAME_WINDOW_PIXMAP
- if (w->pixmap)
- {
- XFreePixmap (dpy, w->pixmap);
- w->pixmap = None;
- if (w->picture)
- {
- XRenderFreePicture (dpy, w->picture);
- w->picture = None;
- }
- }
+ if (w->pixmap)
+ {
+ XFreePixmap (dpy, w->pixmap);
+ w->pixmap = None;
+ if (w->picture)
+ {
+ XRenderFreePicture (dpy, w->picture);
+ w->picture = None;
+ }
+ }
#endif
- if (w->shadow)
- {
- XRenderFreePicture (dpy, w->shadow);
- w->shadow = None;
- }
+ if (w->shadow)
+ {
+ XRenderFreePicture (dpy, w->shadow);
+ w->shadow = None;
+ }
+ }
+ w->a.width = ce->width;
+ w->a.height = ce->height;
+ w->a.border_width = ce->border_width;
+ if (w->a.map_state != IsUnmapped && damage)
+ {
+ XserverRegion extents = win_extents (dpy, w);
+ XFixesUnionRegion (dpy, damage, damage, extents);
+ XFixesDestroyRegion (dpy, extents);
+ add_damage (dpy, damage);
+ }
}
- w->a.width = ce->width;
- w->a.height = ce->height;
- w->a.border_width = ce->border_width;
w->a.override_redirect = ce->override_redirect;
restack_win (dpy, w, ce->above);
- if (w->a.map_state != IsUnmapped && damage)
- {
- XserverRegion extents = win_extents (dpy, w);
- XFixesUnionRegion (dpy, damage, damage, extents);
- XFixesDestroyRegion (dpy, extents);
- add_damage (dpy, damage);
- }
clipChanged = True;
}
XDamageDestroy (dpy, w->damage);
w->damage = None;
}
+
cleanup_fade (dpy, w);
free (w);
break;
destroy_win (Display *dpy, Window id, Bool fade)
{
win *w = find_win (dpy, id);
+
#if HAS_NAME_WINDOW_PIXMAP
- if (w && w->pixmap && fade && fadeWindows)
+ if (w && w->pixmap && fade && winTypeFade[w->windowType])
set_fade (dpy, w, w->opacity*1.0/OPAQUE, 0.0, fade_out_step,
destroy_callback, False, (w->a.map_state != IsUnmapped));
else
w->a.height <= w->damage_bounds.y + w->damage_bounds.height)
{
clipChanged = True;
- if (fadeWindows)
- set_fade (dpy, w, 0, get_opacity_percent (dpy, w, 1.0), fade_in_step, 0, True, True);
+ if (winTypeFade[w->windowType])
+ set_fade (dpy, w, 0, get_opacity_percent (dpy, w), fade_in_step, 0, True, True);
w->usable = True;
}
}
fprintf (stderr, " -I fade-in-step\n Specifies the opacity change between steps while fading in. (default 0.028)\n");
fprintf (stderr, " -O fade-out-step\n Specifies the opacity change between steps while fading out. (default 0.03)\n");
fprintf (stderr, " -D fade-delta-time\n Specifies the time between steps in a fade in milliseconds. (default 10)\n");
+ fprintf (stderr, " -m opacity\n Specifies the opacity for menus. (default 1.0)\n");
fprintf (stderr, " -a\n Use automatic server-side compositing. Faster, but no special effects.\n");
fprintf (stderr, " -c\n Draw client-side shadows with fuzzy edges.\n");
fprintf (stderr, " -C\n Avoid drawing shadows on dock/panel windows.\n");
}
static void
-register_cm (void)
+register_cm (int scr)
{
Window w;
Atom a;
+ char *buf;
+ int len, s;
+
+ if (scr < 0) return;
w = XCreateSimpleWindow (dpy, RootWindow (dpy, 0), 0, 0, 1, 1, 0, None,
None);
Xutf8SetWMProperties (dpy, w, "xcompmgr", "xcompmgr", NULL, 0, NULL, NULL,
NULL);
- /* FIXME: Don't hard code the screen number */
- a = XInternAtom (dpy, "_NET_WM_CM_S0", False);
+ len = strlen(REGISTER_PROP) + 2;
+ s = scr;
+ while (s >= 10) {
+ ++len;
+ s /= 10;
+ }
+ buf = malloc(len);
+ snprintf(buf, len, REGISTER_PROP"%d", scr);
+
+ a = XInternAtom (dpy, buf, False);
+ free(buf);
XSetSelectionOwner (dpy, a, w, 0);
}
int composite_major, composite_minor;
char *display = 0;
int o;
+ Bool noDockShadow = False;
- while ((o = getopt (argc, argv, "D:I:O:d:r:o:l:t:scnfFCaS")) != -1)
+ for (i = 0; i < NUM_WINTYPES; ++i) {
+ winTypeFade[i] = False;
+ winTypeShadow[i] = False;
+ winTypeOpacity[i] = 1.0;
+ }
+
+ /* don't bother to draw a shadow for the desktop */
+ winTypeShadow[WINTYPE_DESKTOP] = False;
+
+ while ((o = getopt (argc, argv, "D:I:O:d:r:o:m:l:t:scnfFCaS")) != -1)
{
switch (o) {
case 'd':
break;
case 's':
compMode = CompServerShadows;
+ for (i = 0; i < NUM_WINTYPES; ++i)
+ winTypeShadow[i] = True;
break;
case 'c':
compMode = CompClientShadows;
+ for (i = 0; i < NUM_WINTYPES; ++i)
+ winTypeShadow[i] = True;
break;
case 'C':
- excludeDockShadows = True;
+ noDockShadow = True;
break;
case 'n':
compMode = CompSimple;
+ for (i = 0; i < NUM_WINTYPES; ++i)
+ winTypeShadow[i] = False;
+ break;
+ case 'm':
+ winTypeOpacity[WINTYPE_DROPDOWN_MENU] = atof (optarg);
+ winTypeOpacity[WINTYPE_POPUP_MENU] = atof (optarg);
break;
case 'f':
- fadeWindows = True;
+ for (i = 0; i < NUM_WINTYPES; ++i)
+ winTypeFade[i] = True;
break;
case 'F':
fadeTrans = True;
break;
}
}
+
+ if (noDockShadow)
+ winTypeShadow[WINTYPE_DOCK] = False;
dpy = XOpenDisplay (display);
if (!dpy)
exit (1);
}
- register_cm();
+ register_cm(scr);
/* get atoms */
opacityAtom = XInternAtom (dpy, OPACITY_PROP, False);
winTypeAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE", False);
- winDesktopAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DESKTOP", False);
- winDockAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
- winToolbarAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_TOOLBAR", False);
- winMenuAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_MENU", False);
- winUtilAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_UTILITY", False);
- winSplashAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_SPLASH", False);
- winDialogAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
- winNormalAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_NORMAL", False);
+ winType[WINTYPE_DESKTOP] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DESKTOP", False);
+ winType[WINTYPE_DOCK] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
+ winType[WINTYPE_TOOLBAR] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_TOOLBAR", False);
+ winType[WINTYPE_MENU] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_MENU", False);
+ winType[WINTYPE_UTILITY] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_UTILITY", False);
+ winType[WINTYPE_SPLASH] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_SPLASH", False);
+ winType[WINTYPE_DIALOG] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
+ winType[WINTYPE_NORMAL] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_NORMAL", False);
+ winType[WINTYPE_DROPDOWN_MENU] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", False);
+ winType[WINTYPE_POPUP_MENU] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_POPUP_MENU", False);
+ winType[WINTYPE_TOOLTIP] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_TOOLTIP", False);
+ winType[WINTYPE_NOTIFY] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_NOTIFICATION", False);
+ winType[WINTYPE_COMBO] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_COMBO", False);
+ winType[WINTYPE_DND] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DND", False);
pa.subwindow_mode = IncludeInferiors;
if (w)
{
if (fadeTrans)
- set_fade (dpy, w, w->opacity*1.0/OPAQUE, get_opacity_percent (dpy, w, 1.0),
+ set_fade (dpy, w, w->opacity*1.0/OPAQUE, get_opacity_percent (dpy, w),
fade_out_step, 0, True, False);
else
{