mirror of
https://codeberg.org/armin/noiz.git
synced 2026-09-01 05:50:52 +02:00
revert noiz.py state (first pywebview experiment with working zoom)
This commit is contained in:
parent
358b840f2c
commit
55b92ab42f
2 changed files with 46 additions and 5 deletions
23
Makefile
Normal file
23
Makefile
Normal 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
28
noiz.py
|
|
@ -1,8 +1,26 @@
|
|||
#!/usr/bin/env python3
|
||||
import webview
|
||||
webview.create_window(
|
||||
"noiz://",
|
||||
"./index.html"
|
||||
)
|
||||
webview.start()
|
||||
def inject_zoom_shortcuts(window):
|
||||
window.evaluate_js(
|
||||
"""
|
||||
document.addEventListener('keydown', function(e) {
|
||||
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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue