Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not use clipboard on X11 #42

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions emote/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def create_picker_window(self, show_welcome=False):
self.picker_window.destroy()
self.picker_window = picker.EmojiPicker(
Keybinder.get_current_event_time(),
self.get_current_window(),
self.update_accelerator,
self.update_theme,
show_welcome,
Expand All @@ -100,6 +101,14 @@ def do_activate(self):
print("Second instance launched")
self.create_picker_window()

def get_current_window(self):
if not config.is_wayland:
result = subprocess.run(
['xdotool', 'getactivewindow'],
capture_output = True,
check = True
)
return result.stdout.decode("utf-8").strip()
Comment on lines +106 to +111

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on what versions of python are supported, it might be easier to use subprocess.check_output() with text=True.


def main():
app = EmoteApplication()
Expand Down
37 changes: 15 additions & 22 deletions emote/picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def grouper(iterable, n, fillvalue=None):


class EmojiPicker(Gtk.Window):
def __init__(self, open_time, update_accelerator, update_theme, show_welcome):
def __init__(self, open_time, current_window, update_accelerator, update_theme, show_welcome):
Gtk.Window.__init__(
self,
title="Emote",
Expand All @@ -29,6 +29,7 @@ def __init__(self, open_time, update_accelerator, update_theme, show_welcome):
deletable=False,
name="emote_window",
)
self.current_window = current_window
self.set_default_size(500, 450)
self.set_keep_above(True)
self.dialog_open = False
Expand Down Expand Up @@ -541,7 +542,7 @@ def on_emoji_btn_event(self, btn, event):
self.show_emoji_preview(emoji)

def on_emoji_append(self, emoji):
"""Append the selected emoji to the clipboard"""
"""Append the selected emoji to the current selection"""
print(f"Appending {emoji} to selection")
self.emoji_append_list.append(emoji)

Expand All @@ -551,38 +552,30 @@ def on_emoji_append(self, emoji):
self.previewed_emoji_shortcode_label.set_max_width_chars(20)

self.update_emoji_append_list_preview()

self.copy_to_clipboard("".join(self.emoji_append_list))
self.add_emoji_to_recent(emoji)

def on_emoji_select(self, emoji):
"""
Copy the selected emoji to the clipboard, close the picker window and
make the user's system perform a paste after 150ms, pasting the emoji
to the currently focussed application window.

If we have been appending other emojis first, add this final one first.
Append the given emoji to the current selection.
Then, close the picker window and:
- for X11, make the user's system "type" the selected characters
into the currently focussed application window;
- for Wayland, copy the selected characters to the clipboard.
"""
self.hide()

if len(self.emoji_append_list) > 0:
self.on_emoji_append(emoji)
else:
print(f"Selecting {emoji}")
self.add_emoji_to_recent(emoji)
self.copy_to_clipboard(emoji)

self.on_emoji_append(emoji)
self.destroy()

time.sleep(0.15)

if not config.is_wayland:
os.system("xdotool key ctrl+v")
emojis = "".join(self.emoji_append_list)
if not config.is_wayland and self.current_window:
os.system(f"xdotool windowfocus --sync '{self.current_window}' type --args 1 '{emojis}'")
else:
self.copy_to_clipboard(emojis)

def add_emoji_to_recent(self, emoji):
user_data.update_recent_emojis(emoji)
emojis.update_recent_category()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should probably be reverted.

def copy_to_clipboard(self, content):
cb = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
cb.set_text(content, -1)