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

Type Numerical Action #213

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ rofimoji.egg-info
dist
build
src/picker/data/copyme.py
venv/
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ You can configure `rofimoji` either with cli arguments or with a config file cal

| long option | short option | possible values | default value | description |
|-------------------------------------------------------------------------------------------------------------------------|--------------|----------------------------------------------------------------------------------------------------------------|---------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `--action` | `-a` | `type`, `copy`, `clipboard`, `unicode`, `copy-unicode`, `print`, `menu` | `type` | Choose what `rofimoji` should do with the selected characters. See [Actions](#actions) below for details. |
| `--action` | `-a` | `type`, `type-numerical`, `copy`, `clipboard`, `unicode`, `copy-unicode`, `print`, `menu` | `type` | Choose what `rofimoji` should do with the selected characters. See [Actions](#actions) below for details. |
Copy link
Owner

Choose a reason for hiding this comment

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

This is not as important as copy; I'd move it after clipboard.

| `--files` | `-f` | `all`, `<yourfile>` or [any of the files in `data`](https://github.com/fdw/rofimoji/tree/main/src/picker/data) | `emojis` | Define which file(s) to load characters from. A file name without extension (f.e. `emojis_smileys_emotion`) is enough for the distributed ones or any in `${XDG_DATA_HOME}/rofimoji/data`. Globbing with `*` is possible.<br/>`all` is a shortcut for all default files at once. Use with caution, that is a *lot*. |
| `--skin-tone` | `-s` | `light`, `medium-light`, `moderate`, `dark brown`, `black`, as well as `neutral` and `ask` | `ask` | Define the skin tone of supporting emojis. `ask` will always ask the user. |
| `--max-recent` | | 0-10 | 10 | Show at most this many recently picked characters. The number will be capped at 10. Set to `0` to disable the whole feature. |
Expand All @@ -69,7 +69,7 @@ You can configure `rofimoji` either with cli arguments or with a config file cal
| `--selector` | | `rofi`, `wofi`, `fuzzel`, `dmenu`, `tofi`, `bemenu`, `wmenu` | (automatically chosen) | Show the selection dialog with this application. |
| `--clipboarder` | | `xsel`, `xclip`, `wl-copy` | (automatically chosen) | Access the clipboard with this application. |
| `--typer` | | `xdotool`, `wtype` | (automatically chosen) | Type the characters using this application. |
| `--keybinding-copy`, `--keybinding-type`, `--keybinding-clipboard`, `--keybinding-unicode`, `--keybinding-copy-unicode` | | | `Alt+c`, `Alt+t`, `Alt+p`, `Alt+u`, `Alt+i` | Choose different keybindings than the default values. |
| `--keybinding-copy`, `--keybinding-type`, `--keybinding-clipboard`, `--keybinding-unicode`, `--keybinding-copy-unicode`, `--keybinding-type-numerical` | | | `Alt+c`, `Alt+t`, `Alt+p`, `Alt+u`, `Alt+i`, `Alt+n` | Choose different keybindings than the default values. |

## Example config file
`~/.config/rofimoji.rc`:
Expand All @@ -91,6 +91,7 @@ The options are:
| `clipboard` | `alt+p` | Insert the selected characters through pasting from the clipboard, instead of directly typing them. See [Insertion Method](#insertion-method). |
| `unicode` | `alt+u` | Type the unicode codepoints of the selected characters. |
| `copy-unicode` | `alt+i` | Copy the codepoints to clipboard. |
| `type-numerical`|`alt+n` | Directly type the emoji(s) by using their Unicode codepoints; this simulates Ctrl+Shift+U<codepoint> on the keyboard |
| `print` | | Print the chosen characters to `stdout`. |

## Insertion method
Expand Down
2 changes: 2 additions & 0 deletions src/picker/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def execute_action(
typer.type_characters(__get_codepoints(characters), active_window)
elif action == Action.COPY_UNICODE:
clipboarder.copy_characters_to_clipboard(__get_codepoints(characters))
elif action == Action.TYPE_NUMERICAL:
typer.type_numerical(characters, active_window)
elif action == Action.STDOUT:
print(characters)

Expand Down
10 changes: 10 additions & 0 deletions src/picker/argument_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ def __parse_arguments(only_known: bool) -> argparse.Namespace:
default="Alt+i",
help="Choose the keyboard shortcut to copy the character's unicode codepoint to the clipboard",
)
parser.add_argument(
"--keybinding-type-numerical",
dest="keybinding_type_numerical",
action="store",
type=str,
default="Alt+n",
Copy link
Owner

Choose a reason for hiding this comment

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

Do you think this is used often enough to warrant a default keybinding?

help="Choose the keyboard shortcut to directly type the character's unicode codepoint numerically "
"with Ctrl+Shift+U<codepoint>",
)

if only_known:
parsed_args = parser.parse_args()
Expand All @@ -191,6 +200,7 @@ def __parse_arguments(only_known: bool) -> argparse.Namespace:
Action.CLIPBOARD: parsed_args.keybinding_clipboard,
Action.UNICODE: parsed_args.keybinding_unicode,
Action.COPY_UNICODE: parsed_args.keybinding_copy_unicode,
Action.TYPE_NUMERICAL: parsed_args.keybinding_type_numerical,
}

return parsed_args
2 changes: 2 additions & 0 deletions src/picker/mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ def __choose_action_from_return_code(self, return_code: int) -> List[Action]:
return [Action.UNICODE]
elif return_code == 24:
return [Action.COPY_UNICODE]
elif return_code == 25:
return [Action.TYPE_NUMERICAL]
else:
return []

Expand Down
1 change: 1 addition & 0 deletions src/picker/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Action(Enum):
COPY_UNICODE = "copy-unicode"
STDOUT = "print"
MENU = "menu"
TYPE_NUMERICAL = "type-numerical"

def __str__(self):
return self.value
Expand Down
5 changes: 5 additions & 0 deletions src/picker/selector/rofi.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def show_character_selection(
keybindings[Action.UNICODE],
"-kb-custom-15",
keybindings[Action.COPY_UNICODE],
"-kb-custom-16",
keybindings[Action.TYPE_NUMERICAL],
*additional_args,
]

Expand Down Expand Up @@ -77,8 +79,11 @@ def show_character_selection(
action = Action.UNICODE
elif rofi.returncode == 24:
action = Action.COPY_UNICODE
elif rofi.returncode == 25:
action = Action.TYPE_NUMERICAL
else:
action = DEFAULT()

return action, [characters[int(index)].character for index in rofi.stdout.splitlines()]

def __format_characters(
Expand Down
4 changes: 4 additions & 0 deletions src/picker/typer/typer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ def type_characters(self, characters: str, active_window: str) -> None:
@abstractmethod
def insert_from_clipboard(self, active_window: str) -> None:
pass

@abstractmethod
def type_numerical(self, characters: str, active_window: str) -> None:
pass
7 changes: 7 additions & 0 deletions src/picker/typer/wtype.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from subprocess import run

from ..abstractionhelper import is_installed, is_wayland
from ..action import __get_codepoints as get_codepoints
from .typer import Typer


Expand All @@ -21,3 +22,9 @@ def type_characters(self, characters: str, active_window: str) -> None:

def insert_from_clipboard(self, active_window: str) -> None:
run(["wtype", "-M", "shift", "-P", "Insert", "-p", "Insert", "-m", "shift"])

def type_numerical(self, characters: str, active_window: str) -> None:
for character in characters:
unicode_codepoint = get_codepoints(character)
# Run Ctrl+Shift+U + the unicode codepoint, then release Ctrl and Shift
run(["wtype", "-M", "ctrl"," -M", "shift", "u"] + [p for p in unicode_codepoint] + ["-m", "ctrl", "-m", "shift"])
19 changes: 19 additions & 0 deletions src/picker/typer/xdotool.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from subprocess import run

from ..abstractionhelper import is_installed, is_wayland
from ..action import __get_codepoints as get_codepoints
from .typer import Typer


Expand Down Expand Up @@ -35,3 +36,21 @@ def insert_from_clipboard(self, active_window: str) -> None:
"0.05",
]
)

def type_numerical(self, characters: str, active_window: str) -> None:
unicode_codepoint = get_codepoints(characters)
unicode_codepoint = unicode_codepoint.split("-")
for codepoint in unicode_codepoint:
run(
[
"xdotool",
"windowfocus",
"--sync",
active_window,
"key",
"--clearmodifiers",
Copy link
Owner

Choose a reason for hiding this comment

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

This should probably be something like key ctrl+shift+u type codepoints without the loop.

"U" + codepoint,
"sleep",
"0.05",
]
)