Browse Source

startup: import pyperclip & overwrite clipboard mechanism in wayland sessions (to workaround method "gi" always returning empty string)

Fabian Peter Hammerle 1 month ago
parent
commit
11c7fe57ad
2 changed files with 8 additions and 0 deletions
  1. 1 0
      README.md
  2. 7 0
      profile_default/startup/init.py

+ 1 - 0
README.md

@@ -1,5 +1,6 @@
 ```sh
 sudo apt-get install --no-install-recommends \
     python3-pgpdump \
+    python3-pyperclip \
     python3-sympy
 ```

+ 7 - 0
profile_default/startup/init.py

@@ -1,4 +1,5 @@
 import itertools
+import os
 import pathlib
 import typing
 import warnings
@@ -6,6 +7,7 @@ import warnings
 import numpy
 import pandas
 import pgpdump
+import pyperclip
 import scipy.io.wavfile
 import sympy
 import yaml
@@ -14,6 +16,11 @@ from matplotlib import pyplot  # pylint: disable=unused-import; frequently used
 # https://pandas.pydata.org/pandas-docs/stable/user_guide/options.html
 pandas.options.display.max_rows = 200
 
+if os.environ.get("WAYLAND_DISPLAY"):
+    # with default "gi" in python3-pyperclip=1.8.2-2 & python3-gi=3.42.2-3+b1
+    # pyperclip.paste() always returned empty string
+    pyperclip.set_clipboard("wl-clipboard")
+
 # https://docs.sympy.org/latest/modules/interactive.html#module-sympy.interactive.printing
 sympy.init_printing(pretty_print=True)