mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-20 09:10:04 +01:00
replay: use the runtime quirks for our replay quirks
Closes #1166 Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1297>
This commit is contained in:
parent
ce87da63ba
commit
cdfe34f62a
1 changed files with 18 additions and 22 deletions
|
|
@ -30,6 +30,7 @@ import math
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import argparse
|
import argparse
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from tempfile import NamedTemporaryFile
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import libevdev
|
import libevdev
|
||||||
|
|
@ -315,9 +316,8 @@ def create_device_quirk(device, quirks):
|
||||||
return quirk
|
return quirk
|
||||||
|
|
||||||
|
|
||||||
def setup_quirks(recording):
|
def setup_quirks(recording) -> Path | None:
|
||||||
devices = fetch(recording, "devices")
|
devices = fetch(recording, "devices")
|
||||||
overrides = None
|
|
||||||
quirks = []
|
quirks = []
|
||||||
for d in devices:
|
for d in devices:
|
||||||
qs = d.get("quirks") or []
|
qs = d.get("quirks") or []
|
||||||
|
|
@ -331,27 +331,22 @@ def setup_quirks(recording):
|
||||||
if not quirks:
|
if not quirks:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
overrides = Path("/etc/libinput/local-overrides.quirks")
|
runtime_dir = (
|
||||||
if overrides.exists():
|
Path(os.getenv("XDG_RUNTIME_DIR", f"/run/user/{os.geteuid()}")) / "libinput"
|
||||||
print(
|
)
|
||||||
"{} exists, please move it out of the way first".format(overrides),
|
runtime_dir.mkdir(exist_ok=True, parents=True)
|
||||||
file=sys.stderr,
|
with NamedTemporaryFile(
|
||||||
)
|
mode="w+",
|
||||||
sys.exit(1)
|
dir=runtime_dir,
|
||||||
|
suffix=".quirks",
|
||||||
|
prefix="libinput-replay",
|
||||||
|
delete=False,
|
||||||
|
) as fd:
|
||||||
|
fd.write("# This file was generated by libinput replay\n")
|
||||||
|
fd.write("# Unless libinput replay is running right now, remove this file.\n")
|
||||||
|
fd.write("\n\n".join(quirks))
|
||||||
|
|
||||||
overrides.parent.mkdir(exist_ok=True)
|
return Path(fd.name)
|
||||||
try:
|
|
||||||
with overrides.open("w+") as fd:
|
|
||||||
fd.write("# This file was generated by libinput replay\n")
|
|
||||||
fd.write(
|
|
||||||
"# Unless libinput replay is running right now, remove this file.\n"
|
|
||||||
)
|
|
||||||
fd.write("\n\n".join(quirks))
|
|
||||||
except IOError:
|
|
||||||
error("Warning: Couldn't write to {}, please re-run as root".format(overrides))
|
|
||||||
return None
|
|
||||||
|
|
||||||
return overrides
|
|
||||||
|
|
||||||
|
|
||||||
def check_file(recording):
|
def check_file(recording):
|
||||||
|
|
@ -413,6 +408,7 @@ def main():
|
||||||
finally:
|
finally:
|
||||||
if quirks_file:
|
if quirks_file:
|
||||||
quirks_file.unlink()
|
quirks_file.unlink()
|
||||||
|
quirks_file.parent.unlink()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue