Skip to content

Commit

Permalink
Backport: Add 'insert_no_copy' mode
Browse files Browse the repository at this point in the history
Backport insert_no_copy feature from master branch.
  • Loading branch information
jones-josh authored and Mange committed Jul 18, 2024
1 parent 6027d78 commit de70765
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
7 changes: 7 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Version 3.4.0 (2024-07-18)

## Added

- `copy_no_insert` mode for inserting without using the clipboard. May not work
everywhere. ([jones-josh](https://github.com/jones-josh))

# Version 3.3.0 (2024-02-27)

## Changed
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,17 @@ The plugin adds the following command line arguments to `rofi`:
#### Mode
The plugin supports four modes:
The plugin supports five modes:
1. `insert` (default) - Copies the selected emoji, and then tries to insert it
directly in the focused window.
2. `copy` - Only copies the selected emoji to your clipboard without trying to
insert anything.
3. `menu` - Open the menu. Useful if you prefer to always get options when just
3. `insert_no_copy` - Tries to insert the emoji in the focused window, but
without copyiing anything.
4. `menu` - Open the menu. Useful if you prefer to always get options when just
pressing <kbd>Enter</kbd>.
4. `stdout` - Write selected emoji to standard output. This is useful if you
5. `stdout` - Write selected emoji to standard output. This is useful if you
want to use the emoji selector inside of a shell pipeline, like Rofi's
`-dmenu` mode. It will use the `-format` argument to customize the outputted
text, just like `-dmenu`.
Expand Down
6 changes: 5 additions & 1 deletion clipboard-adapter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ main() {
command=help
break
;;
copy | insert | help)
copy | insert | insert_no_copy | help)
command="$1"
shift
;;
Expand Down Expand Up @@ -66,6 +66,10 @@ main() {
printf "%s" "$input" | perform_copy
printf "%s" "$input" | perform_insert
;;
insert_no_copy)
# Same as 'insert' but without the copying fallback.
perform_insert
;;
*)
usage >&2
exit 1
Expand Down
11 changes: 8 additions & 3 deletions src/actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "menu.h"
#include "utils.h"

#include <stdbool.h>

Emoji *get_selected_emoji(EmojiModePrivateData *pd, unsigned int line) {
if (pd->selected_emoji != NULL) {
return pd->selected_emoji;
Expand Down Expand Up @@ -33,7 +35,7 @@ ModeMode copy_emoji(EmojiModePrivateData *pd, unsigned int line) {
return text_adapter_action("copy", pd, emoji->bytes);
}

ModeMode insert_emoji(EmojiModePrivateData *pd, unsigned int line) {
ModeMode insert_emoji(EmojiModePrivateData *pd, unsigned int line, bool copy) {
const Emoji *emoji = get_selected_emoji(pd, line);
if (emoji == NULL) {
return MODE_EXIT;
Expand All @@ -42,7 +44,8 @@ ModeMode insert_emoji(EmojiModePrivateData *pd, unsigned int line) {
// Must hide window and give back focus to whatever app should receive the
// insert action.
rofi_view_hide();
text_adapter_action("insert", pd, emoji->bytes);
const char *action = copy ? "insert" : "insert_no_copy";
text_adapter_action(action, pd, emoji->bytes);

// View is hidden and we cannot get it back again. We must exit at this point.
return MODE_EXIT;
Expand Down Expand Up @@ -112,7 +115,9 @@ ModeMode perform_action(EmojiModePrivateData *pd, const Action action,
case NOOP:
return RELOAD_DIALOG;
case INSERT_EMOJI:
return insert_emoji(pd, line);
return insert_emoji(pd, line, true);
case INSERT_NO_COPY_EMOJI:
return insert_emoji(pd, line, false);
case COPY_EMOJI:
return copy_emoji(pd, line);
case OUTPUT_EMOJI:
Expand Down
1 change: 1 addition & 0 deletions src/actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
typedef enum {
NOOP,
INSERT_EMOJI,
INSERT_NO_COPY_EMOJI,
COPY_EMOJI,
OUTPUT_EMOJI,
COPY_NAME,
Expand Down
11 changes: 8 additions & 3 deletions src/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ const int NUM_MENU_ITEMS = 5;
typedef enum {
EMOJI_MENU_PRIMARY = 0,
EMOJI_MENU_SECONDARY = 1,
EMOJI_MENU_NAME = 2,
EMOJI_MENU_CODEPOINT = 3,
EMOJI_MENU_BACK = 4,
EMOJI_MENU_INSERT_NO_COPY = 2,
EMOJI_MENU_NAME = 3,
EMOJI_MENU_CODEPOINT = 4,
EMOJI_MENU_BACK = 5,
} MenuItem;

char *emoji_menu_get_display_value(const EmojiModePrivateData *pd,
Expand All @@ -25,6 +26,8 @@ char *emoji_menu_get_display_value(const EmojiModePrivateData *pd,
return format_emoji(pd->selected_emoji,
pd->search_default_action == INSERT_EMOJI ?
"Insert emoji ({emoji})" : "Copy emoji ({emoji})");
case EMOJI_MENU_INSERT_NO_COPY:
return format_emoji(pd->selected_emoji, "Insert (without copying) emoji ({emoji})");
case EMOJI_MENU_NAME:
return format_emoji(pd->selected_emoji, "Copy name (<tt>{name}</tt>)");
case EMOJI_MENU_CODEPOINT:
Expand Down Expand Up @@ -96,6 +99,8 @@ Action emoji_menu_select_item(EmojiModePrivateData *pd, unsigned int line) {
return pd->search_default_action == INSERT_EMOJI ? COPY_EMOJI : INSERT_EMOJI;
case EMOJI_MENU_SECONDARY:
return pd->search_default_action == INSERT_EMOJI ? INSERT_EMOJI : COPY_EMOJI;
case EMOJI_MENU_INSERT_NO_COPY:
return INSERT_NO_COPY_EMOJI;
case EMOJI_MENU_NAME:
return COPY_NAME;
case EMOJI_MENU_CODEPOINT:
Expand Down

0 comments on commit de70765

Please sign in to comment.