Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click through transparent xlib windows

Tags:

c

xlib

I have a transparent, watermark like application that is written with XLib in C. Currently if you click anywhere on the application nothing happens but I would like it to pass mouse input to whatever is below it. e.g. If you click the X to close a window that is below the application it should close the application, not do nothing.

like image 500
Corey Avatar asked May 06 '13 14:05

Corey


3 Answers

Well this is what I found.

Note that this feature was added in the last decade so if you have an old version of X11, this may or may not work.

First include these into your project as they would be needed:

#include <X11/extensions/shape.h>
#include <X11/extensions/Xfixes.h>

And to change the input geometry (that is the place where you can interact with the window), in this case we'll set it to 0 by 0 pixels which would mean none. This is an example:

XRectangle rect;
XserverRegion region = XFixesCreateRegion(display, &rect, 1);
XFixesSetWindowShapeRegion(display, window, ShapeInput, 0, 0, region);
XFixesDestroyRegion(display, region);

And add this to the project linker -lXfixes

like image 181
nik123 Avatar answered Oct 21 '22 21:10

nik123


If you don't want your "watermark" window to receive any input, and instead have the input go to the window below it, then I would look into the implementation behind gtk_widget_input_shape_combine_region. I previously used its predecessor gtk_widget_input_shape_combine_mask to cause all parts of a popup window not to receive any events.

I'm out of my comfort zone here, but it looks like XShapeCombineRectangles is the relevant call (the linked do_shape_combine_region is called with shape = ShapeInput for this case).

like image 41
Michael Urman Avatar answered Oct 21 '22 21:10

Michael Urman


I think XQueryTree could be of help. Execute it onto the root window and get the list of child windows, find their locations and pass the mouse/keyboard's XEvent to the appropriate window.

Note: You have to take care of active/inactive windows, active/inactive area of window, child of another window, size and x/y location of other windows. Code is going to be messy for this.

like image 1
bikram990 Avatar answered Oct 21 '22 23:10

bikram990