cspeterson / splatmoji

Quickly look up and input emoji and/or emoticons/kaomoji on your GNU/Linux desktop via pop-up menu.
MIT License
209 stars 19 forks source link

Switch between "type" and "copypaste" depending on active window #30

Closed jpetazzo closed 3 years ago

jpetazzo commented 3 years ago

Hi!

First, thanks for writing splatmoji; it's my favorite emoji input method (and I tried a bunch of them😅).

On my machine, the type doesn't work on Firefox; and the copypaste method doesn't work in my terminal, because my terminal requires Ctrl+Shift+v to paste. I can't use Ctrl+Shift+v to paste in Firefox because it triggers one of my extensions.

So I came up with the following helper script, which I called autosplatmoji:

#!/bin/sh
WINDOWNAME="$(xdotool getwindowfocus getwindowname)"
case "$WINDOWNAME" in
  *Firefox*)
  exec splatmoji copypaste ;;
  *)
  exec splatmoji type ;;
esac

Of course, other apps can be added to the "exception" list, and the logic could be reversed (i.e. use splatmoji copypaste by default, except for some apps). It's not bullet-proof either; example: the title of my shell windows is my PS1 variable, which contains the current directory; so if I am in a directory containing the string Firefox it won't work. But it covers 99% of my use cases.

What would be best?

Cheers!

cspeterson commented 3 years ago

I'm leaning towards this being a tip for the README. Maybe in the FAQ under "How do I handle different paste keys between terminal emulators and GUI applications?"

Good thinking though and I'm glad to have it documented!

cspeterson commented 3 years ago

There isn't a good way to identify a window as a terminal emulator in general is there? Just poking at different ones with xprop I'm not seeing any properties that could make the distinction across the board :/

jpetazzo commented 3 years ago

Not that I'm aware of, alas!

Let me know if you'd like me to take a stab at a PR for the README, or if you're more comfortable incorporating it yourself to fit your own style etc (you are of course more than welcome to use/adapt/whatever the wording I've put above).

Thanks either way!

(And if some day I come up with an even better solution, I'll report back :))

cspeterson commented 3 years ago

@jpetazzo I've added it to the README! 😁

https://github.com/cspeterson/splatmoji/commit/2eb2e22a33feecf7f2b2888e95427b83086e9546

cspeterson commented 3 years ago

PS if you (or anyone!) have any idea what the equivalent commands are to do this sort of thing in Wayland, it would be helpful as I am planning on implementing Wayland support in the near future ( ・᷄ㅂ・᷅ )