Skip to content

Commit 9195ee4

Browse files
committed
Add --type-numerical action to rofimoji
Along with other reviewer comments
1 parent 167df25 commit 9195ee4

File tree

11 files changed

+69
-4
lines changed

11 files changed

+69
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ rofimoji.egg-info
99
dist
1010
build
1111
src/picker/data/copyme.py
12+
venv/

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ You can configure `rofimoji` either with cli arguments or with a config file cal
5757

5858
| long option | short option | possible values | default value | description |
5959
|-------------------------------------------------------------------------------------------------------------------------|--------------|----------------------------------------------------------------------------------------------------------------|---------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
60-
| `--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. |
60+
| `--action` | `-a` | `type`, `copy`, `clipboard`, `type-numerical`, `unicode`, `copy-unicode`, `print`, `menu` | `type` | Choose what `rofimoji` should do with the selected characters. See [Actions](#actions) below for details. |
6161
| `--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*. |
6262
| `--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. |
6363
| `--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. |
@@ -69,7 +69,7 @@ You can configure `rofimoji` either with cli arguments or with a config file cal
6969
| `--selector` | | `rofi`, `wofi`, `fuzzel`, `dmenu`, `tofi`, `bemenu`, `wmenu` | (automatically chosen) | Show the selection dialog with this application. |
7070
| `--clipboarder` | | `xsel`, `xclip`, `wl-copy` | (automatically chosen) | Access the clipboard with this application. |
7171
| `--typer` | | `xdotool`, `wtype` | (automatically chosen) | Type the characters using this application. |
72-
| `--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. |
72+
| `--keybinding-copy`, `--keybinding-type`, `--keybinding-clipboard`, `--keybinding-type-numerical`, `--keybinding-unicode`, `--keybinding-copy-unicode` | | | `Alt+c`, `Alt+t`, `Alt+p`, `Alt+n`, `Alt+u`, `Alt+i` | Choose different keybindings than the default values. |
7373

7474
## Example config file
7575
`~/.config/rofimoji.rc`:
@@ -89,6 +89,7 @@ The options are:
8989
| `type` | `alt+t` | Directly type the characters into the last active window. This is the *default* |
9090
| `copy` | `alt+c` | Copy them to the clipboard. |
9191
| `clipboard` | `alt+p` | Insert the selected characters through pasting from the clipboard, instead of directly typing them. See [Insertion Method](#insertion-method). |
92+
| `type-numerical`| `alt+n` | Directly type the emoji(s) by using their Unicode codepoints; this simulates Ctrl+Shift+U<codepoint> on the keyboard |
9293
| `unicode` | `alt+u` | Type the unicode codepoints of the selected characters. |
9394
| `copy-unicode` | `alt+i` | Copy the codepoints to clipboard. |
9495
| `print` | | Print the chosen characters to `stdout`. |

src/picker/action.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def execute_action(
2222
clipboarder.copy_characters_to_clipboard(characters)
2323
elif action == Action.CLIPBOARD:
2424
clipboarder.copy_paste_characters(characters, active_window, typer)
25+
elif action == Action.TYPE_NUMERICAL:
26+
typer.type_numerical(characters, active_window)
2527
elif action == Action.UNICODE:
2628
typer.type_characters(__get_codepoints(characters), active_window)
2729
elif action == Action.COPY_UNICODE:

src/picker/argument_parsing.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ def __parse_arguments(only_known: bool) -> argparse.Namespace:
158158
default="Alt+p",
159159
help="Choose the keyboard shortcut to insert the character via the clipboard",
160160
)
161+
parser.add_argument(
162+
"--keybinding-type-numerical",
163+
dest="keybinding_type_numerical",
164+
action="store",
165+
type=str,
166+
default="Alt+n",
167+
help="Choose the keyboard shortcut to directly type the character's unicode codepoint numerically "
168+
"with Ctrl+Shift+U<codepoint>",
169+
)
161170
parser.add_argument(
162171
"--keybinding-unicode",
163172
dest="keybinding_unicode",
@@ -189,6 +198,7 @@ def __parse_arguments(only_known: bool) -> argparse.Namespace:
189198
Action.TYPE: parsed_args.keybinding_type,
190199
Action.COPY: parsed_args.keybinding_copy,
191200
Action.CLIPBOARD: parsed_args.keybinding_clipboard,
201+
Action.TYPE_NUMERICAL: parsed_args.keybinding_type_numerical,
192202
Action.UNICODE: parsed_args.keybinding_unicode,
193203
Action.COPY_UNICODE: parsed_args.keybinding_copy_unicode,
194204
}

src/picker/mode.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,10 @@ def __choose_action_from_return_code(self, return_code: int) -> List[Action]:
180180
elif return_code == 22:
181181
return [Action.CLIPBOARD]
182182
elif return_code == 23:
183-
return [Action.UNICODE]
183+
return [Action.TYPE_NUMERICAL]
184184
elif return_code == 24:
185+
return [Action.UNICODE]
186+
elif return_code == 25:
185187
return [Action.COPY_UNICODE]
186188
else:
187189
return []

src/picker/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Action(Enum):
66
TYPE = "type"
77
COPY = "copy"
88
CLIPBOARD = "clipboard"
9+
TYPE_NUMERICAL = "type-numerical"
910
UNICODE = "unicode"
1011
COPY_UNICODE = "copy-unicode"
1112
STDOUT = "print"

src/picker/selector/rofi.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ def show_character_selection(
4545
"-kb-custom-13",
4646
keybindings[Action.CLIPBOARD],
4747
"-kb-custom-14",
48-
keybindings[Action.UNICODE],
48+
keybindings[Action.TYPE_NUMERICAL],
4949
"-kb-custom-15",
50+
keybindings[Action.UNICODE],
51+
"-kb-custom-16",
5052
keybindings[Action.COPY_UNICODE],
5153
*additional_args,
5254
]
@@ -77,8 +79,11 @@ def show_character_selection(
7779
action = Action.UNICODE
7880
elif rofi.returncode == 24:
7981
action = Action.COPY_UNICODE
82+
elif rofi.returncode == 25:
83+
action = Action.TYPE_NUMERICAL
8084
else:
8185
action = DEFAULT()
86+
8287
return action, [characters[int(index)].character for index in rofi.stdout.splitlines()]
8388

8489
def __format_characters(

src/picker/typer/noop.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ def type_characters(self, characters: str, active_window: str) -> None:
1818

1919
def insert_from_clipboard(self, active_window: str) -> None:
2020
raise NoTyperFoundException()
21+
22+
def type_numerical(self, characters: str, active_window: str) -> None:
23+
raise NoTyperFoundException()
2124

2225

2326
class NoTyperFoundException(Exception):

src/picker/typer/typer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ def type_characters(self, characters: str, active_window: str) -> None:
3737
@abstractmethod
3838
def insert_from_clipboard(self, active_window: str) -> None:
3939
pass
40+
41+
@abstractmethod
42+
def type_numerical(self, characters: str, active_window: str) -> None:
43+
pass

src/picker/typer/wtype.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from subprocess import run
22

33
from ..abstractionhelper import is_installed, is_wayland
4+
from ..action import __get_codepoints as get_codepoints
45
from .typer import Typer
56

67

@@ -21,3 +22,15 @@ def type_characters(self, characters: str, active_window: str) -> None:
2122

2223
def insert_from_clipboard(self, active_window: str) -> None:
2324
run(["wtype", "-M", "shift", "-P", "Insert", "-p", "Insert", "-m", "shift"])
25+
26+
def type_numerical(self, characters: str, active_window: str) -> None:
27+
unicode_codepoints = get_codepoints(characters)
28+
codepoint_list = unicode_codepoints.split("-")
29+
codepoint_list = ["U" + codepoint for codepoint in codepoint_list]
30+
codepoint_list = " ".join(codepoint_list)
31+
32+
run(["wtype", "-M", "ctrl", "-M", "shift", codepoint_list, "-m", "ctrl", "-m", "shift"])
33+
34+
# Type Space then Backspace to "confirm" the character
35+
run(["wtype", "-k", "Space"])
36+
run(["wtype", "-k", "BackSpace"])

src/picker/typer/xdotool.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from subprocess import run
22

33
from ..abstractionhelper import is_installed, is_wayland
4+
from ..action import __get_codepoints as get_codepoints
45
from .typer import Typer
56

67

@@ -35,3 +36,25 @@ def insert_from_clipboard(self, active_window: str) -> None:
3536
"0.05",
3637
]
3738
)
39+
40+
def type_numerical(self, characters: str, active_window: str) -> None:
41+
for character in characters:
42+
unicode_codepoints = get_codepoints(character)
43+
codepoint_list = unicode_codepoints.split("-")
44+
# Add "U" to the beginning of each element in codepoint list
45+
# and join w spaces
46+
codepoint_list = ["U" + codepoint for codepoint in codepoint_list]
47+
codepoint_list = " ".join(codepoint_list)
48+
# Run Ctrl+Shift+U + the unicode codepoint, then release Ctrl and Shift
49+
run([
50+
"xdotool",
51+
"windowfocus",
52+
"--sync",
53+
active_window,
54+
"key",
55+
"--clearmodifiers",
56+
"Ctrl+Shift",
57+
codepoint_list,
58+
"sleep",
59+
"0.05",
60+
])

0 commit comments

Comments
 (0)