From 2a06e4a6b9fa8392bc9360bf64f3f6daf9c2f3be Mon Sep 17 00:00:00 2001 From: pegasko Date: Wed, 12 Jun 2024 02:07:30 +0300 Subject: [PATCH] Wayland support --- README.md | 1 + fleepit.py | 31 +++++++++++++++++++++++++++++++ setup.py | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a10b92a..9581a07 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Text seleciton keyboard layout switcher based on xclip / etc for X11 & wayland 1. Install required packages: * X11: `xclip`, `xdotool` + * Wayland: `wl-clipboard` 2. install module: `pip install fleepit` diff --git a/fleepit.py b/fleepit.py index 642a83e..8d8caa2 100644 --- a/fleepit.py +++ b/fleepit.py @@ -87,6 +87,35 @@ def do_x11(args: argparse.Namespace): result.check_returncode() +def do_wayland(args: argparse.Namespace): + # Extract selection + result = subprocess.run([ 'wl-paste', '-primary' ], capture_output=True, text=True) + result.check_returncode() + clip = result.stdout + if clip.strip() == '': + if args.verbose: + print(f'clipboard is empty') + return + + if args.verbose: + print(f'clipboard: "{ clip }"') + + # Do convert + if args.langset: + conv = make_langset_dict(LANGSETS[args.langset]) + else: + with open(args.langset_file, 'r') as f: + conv = make_langset_dict(json.load(f)['langset']) + converted = flip_langset(clip, conv) + + if args.verbose: + print(f'converted: "{ converted }"') + + # Write selection + result = subprocess.run([ 'wl-paste', '-primary' ], text=True, input=converted) + result.check_returncode() + + def main(): parser = argparse.ArgumentParser('fleep') parser.add_argument( @@ -120,6 +149,8 @@ def main(): if args.mode == 'x11': do_x11(args) + elif args.mode == 'wayland': + do_wayland(args) else: raise NotImplementedError() diff --git a/setup.py b/setup.py index 00bf92b..ffd3c0a 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ except: setup( name='fleepit', - version='5', + version='6', py_modules=['fleepit'], description='Text seleciton keyboard layout switcher based on xclip / etc for X11 & wayland', url='https://git.pegasko.art/bitrate16/fleepit',