Skip to content

Instantly share code, notes, and snippets.

@deedy5
Last active September 26, 2025 16:34
Show Gist options
  • Select an option

  • Save deedy5/0f04f980fc9009fa46d451850fd80cab to your computer and use it in GitHub Desktop.

Select an option

Save deedy5/0f04f980fc9009fa46d451850fd80cab to your computer and use it in GitHub Desktop.
mask_pixel.py
#!/usr/bin/env python3
import signal
import sys
import time
from contextlib import suppress
from Xlib import X, Xatom, display
X_COORD, Y_COORD = 100, 100
d = display.Display()
root = d.screen().root
atom_opacity = d.intern_atom("_NET_WM_WINDOW_OPACITY", only_if_exists=False)
orig_w = orig_h = 2
pad_x = pad_y = 3
total_w = orig_w + pad_x * 2
total_h = orig_h + pad_y * 2
win_x = X_COORD - (orig_w // 2) - pad_x
win_y = Y_COORD - (orig_h // 2) - pad_y
CENTER_OPACITY = 0x33333333
EDGE_OPACITY = 0x05050505
def lerp(a, b, t):
return int(a + (b - a) * t)
cx0, cx1 = pad_x, pad_x + orig_w - 1
cy0, cy1 = pad_y, pad_y + orig_h - 1
def factor(idx, lo, hi, pad):
if lo <= idx <= hi:
return 1.0
dist = lo - idx if idx < lo else idx - hi
return max(0.0, 1.0 - dist / float(pad))
h_factors = [factor(cx, cx0, cx1, pad_x) for cx in range(total_w)]
v_factors = [factor(cy, cy0, cy1, pad_y) for cy in range(total_h)]
cell_windows = []
depth = d.screen().root_depth
bg = 0x000000
for cx, hf in enumerate(h_factors):
x = win_x + cx
for cy, vf in enumerate(v_factors):
opacity = lerp(EDGE_OPACITY, CENTER_OPACITY, hf * vf)
w = root.create_window(
x,
win_y + cy,
1,
1,
0,
depth,
X.InputOutput,
X.CopyFromParent,
background_pixel=bg,
override_redirect=True,
)
w.change_property(atom_opacity, Xatom.CARDINAL, 32, [opacity])
w.map()
cell_windows.append(w)
d.sync()
def cleanup(*_):
with suppress(Exception):
for w in cell_windows:
with suppress(Exception):
w.unmap()
w.destroy()
d.sync()
sys.exit(0)
signal.signal(signal.SIGINT, cleanup)
signal.signal(signal.SIGTERM, cleanup)
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment