revert noiz.py state (first pywebview experiment with working zoom)

This commit is contained in:
Armin 2026-07-07 02:00:19 +02:00
commit 55b92ab42f
2 changed files with 46 additions and 5 deletions

23
Makefile Normal file
View file

@ -0,0 +1,23 @@
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
CFLAGS ?= -O2 -Wall -Wextra
CFLAGS += $(shell pkg-config --cflags gtk+-3.0 webkit2gtk-4.1)
LIBS = $(shell pkg-config --libs gtk+-3.0 webkit2gtk-4.1)
.PHONY: all clean install uninstall
all: noiz
noiz: noiz.c
$(CC) $(CFLAGS) -o $@ $< $(LIBS)
clean:
rm -f noiz
install: noiz
install -d $(DESTDIR)$(BINDIR)
install -m 755 noiz $(DESTDIR)$(BINDIR)/noiz
uninstall:
rm -f $(DESTDIR)$(BINDIR)/noiz

28
noiz.py
View file

@ -1,8 +1,26 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import webview import webview
webview.create_window( def inject_zoom_shortcuts(window):
"noiz://", window.evaluate_js(
"./index.html" """
) document.addEventListener('keydown', function(e) {
webview.start() if (!e.ctrlKey) return;
var key = e.key;
if (key === '=' || key === '+' || key === '-') {
e.preventDefault();
var cur = parseFloat(document.body.style.zoom) || 1;
if (key === '-') {
document.body.style.zoom = Math.max(0.25, +(cur - 0.1).toFixed(2));
} else {
document.body.style.zoom = Math.min(3, +(cur + 0.1).toFixed(2));
}
} else if (key === '0') {
e.preventDefault();
document.body.style.zoom = 1;
}
});
"""
)
window = webview.create_window("noiz://", "https://bsd.pm/noiz/", zoomable=True)
webview.start(inject_zoom_shortcuts, window)