diff --git a/src/clipman/__init__.py b/src/clipman/__init__.py index 88af635..6477e1f 100644 --- a/src/clipman/__init__.py +++ b/src/clipman/__init__.py @@ -83,7 +83,11 @@ def check_run_command(command, engine): class DataClass(): """ Class for storing module data """ def __init__(self): + # - = + self.klipper = None self.windows_native_backend = None + # - = + self.os_name = detect_os() self.engine = None self.init_called = False @@ -102,6 +106,17 @@ def detect_clipboard_engine(): except KeyError: graphical_backend = "< NOT SET >" + try: + import dbus + bus = dbus.SessionBus() + dataclass.klipper = dbus.Interface(bus.get_object("org.kde.klipper", "/klipper"), "org.kde.klipper.klipper") + + dataclass.klipper.getClipboardContents(dbus_interface="org.kde.klipper.klipper") + + return 'org.kde.klipper' + except: + pass + if graphical_backend == "x11": if check_binary_installed("xsel"): # Preffer xsel because is it less laggy and more fresh return check_run_command(['xsel', '-b', '-n', '-o'], "xsel") @@ -175,6 +190,11 @@ def call(method, text=None): # pylint: disable=R0911 # too-many-return-statement text = str(text) # - = LINUX - = - = - = - = - = - = - = + if dataclass.engine == "org.kde.klipper": + if method == "set": + return dataclass.klipper.setClipboardContents(text, dbus_interface="org.kde.klipper.klipper") + if method == "get": + return str(dataclass.klipper.getClipboardContents(dbus_interface="org.kde.klipper.klipper")) if dataclass.engine == "xsel": if method == "set": return run_command_with_paste(['xsel', '-b', '-i'], text) diff --git a/src/clipman/exceptions.py b/src/clipman/exceptions.py index 87367c0..499b55f 100644 --- a/src/clipman/exceptions.py +++ b/src/clipman/exceptions.py @@ -34,7 +34,7 @@ class ClipmanBaseException(Exception): class NoInitializationError(ClipmanBaseException): """ Called if dev don't called clipman.init() """ # - = - = - = - = - = - = - ↓ Set default error message ↓ - def __init__(self, message="Initialization was not been performed or it failed! Call initialization: clipman.init()"): + def __init__(self, message="Initialization was not been performed or it failed! Call initialization first: clipman.init()"): super().__init__(message) class UnsupportedError(ClipmanBaseException):