Last active
September 4, 2021 18:02
-
-
Save seven1m/71752ad615ca4627795f20af174dc0ce to your computer and use it in GitHub Desktop.
A small Python script that creates a semi-transparent resizable frame that stays on top. I use it to mark an area of my screen (the area where my webcam is overlayed) off-limits when screencasting.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# shamelessly stolen and adapted from https://gist.github.com/KurtJacobson/374c8cb83aee4851d39981b9c7e2c22c | |
# usage: python3 frame.py [width] [height] [x] [y] [opacity] | |
import cairo | |
import gi | |
import sys | |
import resource | |
gi.require_version('Gtk', '3.0') | |
gi.require_version('Gdk', '3.0') | |
from gi.repository import Gtk | |
from gi.repository import Gdk | |
class TransparentWindow(Gtk.Window): | |
def __init__(self): | |
Gtk.Window.__init__(self) | |
if len(sys.argv) >= 3: | |
w = int(sys.argv[1]) | |
h = int(sys.argv[2]) | |
else: | |
w = 400 | |
h = 300 | |
self.set_size_request(w, h) | |
if len(sys.argv) >= 5: | |
x = int(sys.argv[3]) | |
y = int(sys.argv[4]) | |
self.move(x, y) | |
self.set_title('') | |
self.set_skip_taskbar_hint(True) | |
self.connect('destroy', Gtk.main_quit) | |
self.connect('draw', self.draw) | |
screen = self.get_screen() | |
visual = screen.get_rgba_visual() | |
if visual and screen.is_composited(): | |
self.set_visual(visual) | |
self.set_app_paintable(True) | |
self.show_all() | |
self.set_keep_above(True) | |
def draw(self, widget, context): | |
if len(sys.argv) >= 6: | |
opacity = float(sys.argv[5]) | |
else: | |
opacity = 0.1 | |
context.set_source_rgba(1, 1, 1, opacity) | |
context.set_operator(cairo.OPERATOR_SOURCE) | |
context.paint() | |
context.set_operator(cairo.OPERATOR_OVER) | |
#print(self.get_size()) | |
TransparentWindow() | |
Gtk.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment