Skip to content

Commit

Permalink
Add org.kde.klipper native dbus interface support 😺
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaBeloglazov committed Dec 11, 2023
1 parent 5d21309 commit 6a293ca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/clipman/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/clipman/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 6a293ca

Please sign in to comment.