mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-20 05:40: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 argparse
|
||||
from pathlib import Path
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
try:
|
||||
import libevdev
|
||||
|
|
@ -315,9 +316,8 @@ def create_device_quirk(device, quirks):
|
|||
return quirk
|
||||
|
||||
|
||||
def setup_quirks(recording):
|
||||
def setup_quirks(recording) -> Path | None:
|
||||
devices = fetch(recording, "devices")
|
||||
overrides = None
|
||||
quirks = []
|
||||
for d in devices:
|
||||
qs = d.get("quirks") or []
|
||||
|
|
@ -331,27 +331,22 @@ def setup_quirks(recording):
|
|||
if not quirks:
|
||||
return None
|
||||
|
||||
overrides = Path("/etc/libinput/local-overrides.quirks")
|
||||
if overrides.exists():
|
||||
print(
|
||||
"{} exists, please move it out of the way first".format(overrides),
|
||||
file=sys.stderr,
|
||||
)
|
||||
sys.exit(1)
|
||||
runtime_dir = (
|
||||
Path(os.getenv("XDG_RUNTIME_DIR", f"/run/user/{os.geteuid()}")) / "libinput"
|
||||
)
|
||||
runtime_dir.mkdir(exist_ok=True, parents=True)
|
||||
with NamedTemporaryFile(
|
||||
mode="w+",
|
||||
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)
|
||||
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
|
||||
return Path(fd.name)
|
||||
|
||||
|
||||
def check_file(recording):
|
||||
|
|
@ -413,6 +408,7 @@ def main():
|
|||
finally:
|
||||
if quirks_file:
|
||||
quirks_file.unlink()
|
||||
quirks_file.parent.unlink()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue