From bec1de843989ac6a7e36b244824bf02d920eebff Mon Sep 17 00:00:00 2001 From: Murat Date: Fri, 27 Oct 2023 02:26:03 +0200 Subject: [PATCH] made scroll speed code work also with xwayland windows --- Tricks.md | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Tricks.md b/Tricks.md index 15a618b..751ecb7 100644 --- a/Tricks.md +++ b/Tricks.md @@ -284,19 +284,29 @@ This script set 6x scroll speed only if app like chromium is focused, require ht ```python #!/usr/bin/env python -import i3ipc, re -r = re.compile(r'chrom|telegram|Master PDF Editor|typora',re.I) +import i3ipc +scroll_apps = ['discord'] +default_speed = 1 # Reading current value would be nice + + def on_window_focus(i3, e): - c = e.container.app_id - if not c: + v = default_speed + window_class = getattr(e.container, 'window_class', None) + app_id = getattr(e.container, 'app_id', None) + if window_class: + c = window_class + elif app_id: + c = app_id + else: return - v = 1 - if r.search(c): - v = 6 - i3.command(f"input type:pointer scroll_factor {v}") + + if c in scroll_apps: + v = 8 + i3.command(f'input type:pointer scroll_factor {v}') + i3 = i3ipc.Connection() -i3.on("window::focus", on_window_focus) +i3.on('window::focus', on_window_focus) i3.main() ```