XShape example usage?

Carsten Haitzler raster at rasterman.com
Fri Dec 22 10:17:42 UTC 2017


On Thu, 21 Dec 2017 11:51:49 +0000 Felix Schütt <felixschuett at outlook.de> said:

> Hello,
> 
> I am currently trying to create a custom shape for a simple X11 window 
> (mostly for a splash screen). Based on the lacking documentation on 
> https://www.x.org/archive/X11R7.5/doc/man/man3/XShape.3.html I can 
> however not find any way to do it. Is there a possiblity of some example 
> / testing code available somewhere? I can't figure out how I should use 
> XShape to create a non-rectangular window.

create a 1 bit pixmap (mask) and draw stuff to it. 1 == solid, 0 ==
transparent. just fill it with a rectangle of 0 values, then maybe draw a few
rectangles with 1's. then use XShapeCombineMask() with the dest being the
window, use 0, 0 as offset (have the pixmap mask be same size as window), use
ShapeBounding for destkind and ShapeSet for op. that'll get you going. code?

https://git.enlightenment.org/core/efl.git/tree/src/lib/ecore_x/ecore_x_window_shape.c

ecore_x is a thin xlib wrapper just to make it more convenient to use, so its
full of useful tidbits of how you use an xlib api.

> My second question regards context menus and borderless windows. In a 
> regular X11 window, I can set the background to be transparent -however, 
> if I do that, I still have the shadows (drawn by the WM) around the 
> window. Is there any way in the X11 protocol or its extensions to 
> disable the shadow (to have a true transparent window)? I have often 

well that depends. if you want it managed by the window manager... you really
don't have a choice. the window manager may or may not add shadows. it's up to
the wm what it may or may not do. and even if you don't want it managed... if
the wm is also the compositor (which is 99% the case these days), then it may
also add shadows to windows that are not managed. like dropdown menus etc.

your BEST bet is to do one of the following:

1. use an override-redirect window (see below) AND use an ARGB visual so your
window has an ALPHA CHANNEL.

or

2. (better) use a normal window that is managed by the wm, BUT use mwm hints to
make it borderless before you display it AND have an ARGB visual:

argb windows:

https://git.enlightenment.org/core/efl.git/tree/src/lib/ecore_x/ecore_x_window.c#n1644

mwm hints:

https://git.enlightenment.org/core/efl.git/tree/src/lib/ecore_x/ecore_x_mwm.c

specifically ecore_x_mwm_borderless_set() is what you want.

this won't guarantee the wm won't put a shadow around it, but it's probably the
most likely path to have this happen. wm's can do whatever they like here and
you can't really enforce something on them.

also be aware... ARGB windows will only be useful if you have a compositor (the
wm is a compositor or an external compositor runs). without a compositor the
transparent bits will all be black. that's a whole topic on its own.

> wondered how context menus are handled - in many ways they seem like 

they use override-redirect windows (generally that bypass wm management and the
app can explicitly show and position and size without the wm getting in the
way. there are gotchas of course with this, so generally only use these windows
for things like popup menus and make sure to behave nicely - like hiding them
when done, or tracking the parent window they are hovering above and
repositioning them correctly when it moves, allowing the user to break away
(grab the keyboard and/or mouse and allow maybe escape key or a click outside
the menu window to break the grab and hide these windows).

> regular windows, however they don't have the usual borders of  a window. 
> For example, if I disable window decorations in Ubuntu Unity, the window 
> borders are still rounded. Context menus, on the other hand, do not have 
> any rounded borders. So they must be doing some kind of trick to get a 
> simple rectangular window working. I asked other people and they told me 
> that these developers are using XShape extensions. Is this true or is 
> there another way to do context menus?

no. menus (generally) use override-redirect windows as above.

> 
> Thanks in advance,
> 
> Felix Schütt
> 
> _______________________________________________
> xorg at lists.x.org: X.Org support
> Archives: http://lists.freedesktop.org/archives/xorg
> Info: https://lists.x.org/mailman/listinfo/xorg
> Your subscription address: %(user_address)s

-- 
------------- Codito, ergo sum - "I code, therefore I am" --------------
Carsten Haitzler - raster at rasterman.com



More information about the xorg mailing list