Ulauncher / ulauncher-emoji

Emoji Extension
115 stars 16 forks source link

Feature request: option to auto paste emoji after choosing it #11

Open AXeL-dev opened 4 years ago

AXeL-dev commented 4 years ago

I would love to see an auto paste feature, like in many others emoji selectors.

@MyriaCore Could you help on implementing this feature on your fork please? I'm not sure if it's doable, what do you think?

MyriaCore commented 4 years ago

I was thinking about this too. In the past, I've used xdotool for things like this. Maybe it'd be possible to use a shell subprocess and call it?

I could provide assistance, but I'm trying to pull back from open source and personal projects because of university, which gobbles up like 110% of my free time lol

MyriaCore commented 4 years ago

Could also be possible to copy and then insert by putting the copy action and the insert action in an Action List.

Regardless, it's probably doable.

AXeL-dev commented 4 years ago

I was thinking about this too. In the past, I've used xdotool for things like this. Maybe it'd be possible to use a shell subprocess and call it?

In fact i'm using a Clipboard Manager called Clipped which already has this feature. & from sources i think that it use fake events same as xdotool.

AXeL-dev commented 4 years ago

I figured out that the XTest library used in Clipped is available on python too:

So we could maybe use it instead of calling xdotool using a subprocess?

MyriaCore commented 4 years ago

Sure, if u think it'll be faster. xdotool was just the one I thought of, plus it does character encoding for typing simulations I think, so it's not JUST sending shift-insert.

Regardless, I think it'll just be cool that it's working lol. Lmk how it works out! I'll be here if u need help with the implementation

AXeL-dev commented 4 years ago

@MyriaCore I think that creating a custom action didn't work since i'm getting the following error message:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/ulauncher/utils/SimpleWebSocketServer.py", line 574, in _parseMessage
    self._handlePacket()
  File "/usr/lib/python3/dist-packages/ulauncher/utils/SimpleWebSocketServer.py", line 245, in _handlePacket
    self.handleMessage()
  File "/usr/lib/python3/dist-packages/ulauncher/api/server/ExtensionController.py", line 70, in handleMessage
    response = pickle.loads(self.data)
AttributeError: Can't get attribute 'PasteAction' on <module '__main__' from '/usr/bin/ulauncher'>

Edit: I tested the key press simulation code in a separated python script & it did work so i don't think that the problem comes from there.

So, what do you suggest? have i done something wrong?

AXeL-dev commented 4 years ago

Finally got it to work, based on code from ulauncher-kill extension.

@MyriaCore thanks for the help :wink:

MyriaCore commented 4 years ago

Sweet! Yeah, the custom actions seem kinda fiddly. Glad you figured it out!

MyriaCore commented 4 years ago

There are still some users who might want to just copy the emoji, so it might be wise to add an action setting in the settings. Maybe the user could choose from "Auto-Insert" or "Copy".

MyriaCore commented 4 years ago

Just checked out your code. I think instead of sending Ctrl-V, u should send Shift-Insert, since some applications won't accept Ctrl-V (like terminals).

Didn't look too hard at it, but other than that, it looks good.

MyriaCore commented 4 years ago

any updates @AXeL-dev?

AXeL-dev commented 4 years ago

any updates @AXeL-dev?

Well i didn't rework on this since the last time. I'll try to this night.

AXeL-dev commented 4 years ago

@MyriaCore it seems like pasting emojis using Shift-Insert doesn't work on my terminal app (Tilix), it pastes only the last copied textual value, but it works weirdly using paste option of the mouse right click menu.

image

P.S.: pasting emojis doesn't either work with Ctrl-V as you said before.

MyriaCore commented 4 years ago

Maybe instead of copying into the clipboard, we should copy into the primary buffer? I think Shift-Insert might be for the primary buffer, although I'm not sure. Middle click also pastes the primary buffer.

MyriaCore commented 4 years ago

The CopyToClipboardAction is defined here.

After looking at relevant docs, it looks like maybe we could use the following to make Shift-Insert work:

class CopyToPrimarySelectionAction(CopyToClipboardAction):
    """
    Copy text to the clipboard
    :param str text: text to copy
    """
    def run(self):
        clipboard = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY)
        clipboard.set_text(self.text, -1)
        clipboard.store()
MyriaCore commented 4 years ago

@AXeL-dev you can test this on your terminal by:

  1. selecting something in your terminal
  2. immediately Shift-insert
  3. See the thing you selected in your terminal

If we use the primary selection instead of the clipboard, shift-insert should basically work everywhere, since AFAIK it's accepted everywhere, since it's more of a system thing than a user-controllable clipboard thing.

MyriaCore commented 4 years ago

I've implemented this in MyriaCore/auto-paste.

MyriaCore commented 4 years ago

HMMM, still not working. This is super weird. I get a completely different bug when trying to do both as well, so im not sure what to do here. Needless to say, for this to be useful for regular use, this will probably need to be debugged.

MyriaCore commented 4 years ago

Maybe the primary clipboard is read only? How does xsel do it then, cause im pretty sure xsel can copy into the primary clipboard. I mean, the easy way out here could totally be just to subprocess out into xsel.

This is honestly pretty frustrating. Maybe it would've been better if we had just piped out at the beginning.

AXeL-dev commented 4 years ago

I guess there should be a way to achieve it, the most common problem in Linux (i mean the one i always face) is the lake of good documentation, especially on some low level libraries.. Anyway, i'll try to give it a look from my side once i get enough free time for.

By the way, xsel is open source? this one: https://github.com/kfish/xsel ?

MyriaCore commented 4 years ago

Yeah. IDK, documentation is there, I guess I just don't know as much as I thought about the clipboard system.

Most of my experience comes from working on a fork of texpander. Here, Shift-Insert is used to paste, and the text content is placed into the primary buffer and into the clipboard buffer.

As I said, worst case we can use xsel to copy, and then use this XTest library to paste. IDK why the gtk clipboard stuff isn't working, but AFAIK that stuff is supposed to be used for implementing copy/paste in GUI apps, so I guess we'd be kinda abusing the feature a bit here.

gerardbosch commented 2 years ago

Hi there!

I'd love this feature is implemented ❤ Is there any update?

I give my two cents here on what I think is a common use case: If I get it right from the discussion I understood that the choice is on which clipboard to copy the emoji; or if directly insert it without copying to a clipboard.

IMO, and for my use case, to be really useful it should do both: copy to the X clipboard (the one that pastes with Ctrl-v) + insert the emoji right after.

Reason: Many times you want to insert several times the same emoji, like 👏👏👏 - so you should be able to look for the emoji in the picker once, hit return to insert, and in the event you want to insert more press ctrl-vvv....

shift - insert is not very ergonomic, specially on laptop keyboards as involves more keys like fn that are far from home and wrist twisting 😬

What do you think? Hope this helps, cheers!!

MyriaCore commented 2 years ago

I haven't worked on this since 2020 so no updates unfortunately. I don't remember if I got this to work or not in my fork. Commits look ok but I never merged it, so I have to assume it's at least somewhat not working

Again uni takes up a lot of my time so in general I've taken a step back from open source stuff. If you have experience with python why not take a stab at it yourself?