Skip to content

Instantly share code, notes, and snippets.

@glitsj16
Created September 9, 2019 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glitsj16/02cc2d37c8841bbe3b303728aaa54b8a to your computer and use it in GitHub Desktop.
Save glitsj16/02cc2d37c8841bbe3b303728aaa54b8a to your computer and use it in GitHub Desktop.
// Create an invisible maximized window (covering the desktop) to use as focused Xwayland overlay
// valac -X -lm --pkg gtk+-3.0 --pkg cairo --pkg gdk-3.0 gnome-pie-focus-helper.vala
using Gtk;
using Cairo;
public class CairoTransparent : Gtk.Window {
private Surface event_mask;
/**
* Create the window
**/
public CairoTransparent () {
this.title = "TransparentDesktopOverlay";
this.destroy.connect (Gtk.main_quit);
// Properties [https://valadoc.org/gtk+-3.0/Gtk.Window.html]
set_accept_focus(true);
set_app_paintable(true);
set_decorated(false);
set_default_size (16, 16);
set_focus_on_map(true);
set_hide_titlebar_when_maximized(true);
set_keep_above(true);
set_skip_pager_hint(true);
set_skip_taskbar_hint(true);
maximize();
// Get rgba colormap for transparency to work
set_visual(screen.get_rgba_visual());
// Expose event is called when we need to draw the window
draw.connect(on_expose);
}
private void create_mask() {
int width;
int height;
get_size(out width, out height);
event_mask = new ImageSurface(Format.ARGB32, width, height);
// Context
var pmcr = new Context(event_mask);
// Transparency
pmcr.set_source_rgba(1.0,1.0,1.0,0.0);
pmcr.set_operator(Operator.SOURCE);
pmcr.paint();
input_shape_combine_region(Gdk.cairo_region_create_from_surface(event_mask));
}
/**
* Actual drawing
**/
private bool on_expose (Context ctx) {
create_mask();
// Make current color transparent
ctx.set_source_rgba(1.0,1.0,1.0,0.0);
// Paint entire window transparent
ctx.set_operator(Cairo.Operator.SOURCE);
ctx.paint();
return true;
}
static int main (string[] args) {
Gtk.init (ref args);
var cairo_sample = new CairoTransparent ();
cairo_sample.show_all ();
Gtk.main ();
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment