Skip to content
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
17 changes: 17 additions & 0 deletions smile-autopaste@turtl.cc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Smile Autopaste

A Cinnamon extension that automatically pastes emojis selected in [Smile](https://github.com/mijorus/smile) into the previously focused window.

![Screenshot of the Smile Autopaste plugin](./screenshot.png)

## How it works

When you pick an emoji in Smile, Smile copies it to the clipboard and emits a D-Bus signal. This extension listens for that signal and replays `Ctrl+V` into the previously focused window after a short delay, so the emoji lands where the user's cursor was.

## Requirements

- [Smile](https://github.com/mijorus/smile) emoji picker must be installed and running.

## Installation

Clone this repository and copy `files/smile-autopaste@turtl.cc` into `~/.local/share/cinnamon/extensions/`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Clutter = imports.gi.Clutter;
const Settings = imports.ui.settings;

const SMILE_DBUS_INTERFACE = 'it.mijorus.smile';
const SMILE_DBUS_PATH = '/it/mijorus/smile/actions';
const SMILE_SIGNAL = 'CopiedEmojiBroadcast';

let dbusSignalId = null;
let pendingTimeouts = [];
let settings = null;
let pasteDelay = 100;

function getVirtualKeyboard() {
return Clutter.get_default_backend()
.get_default_seat()
.create_virtual_device(Clutter.InputDeviceType.KEYBOARD_DEVICE);
}

function sendCtrlV(keyboard) {
const time = Clutter.get_current_event_time();
keyboard.notify_keyval(time, Clutter.KEY_Control_L, Clutter.KeyState.PRESSED);
keyboard.notify_keyval(time, Clutter.KEY_v, Clutter.KeyState.PRESSED);
keyboard.notify_keyval(time, Clutter.KEY_v, Clutter.KeyState.RELEASED);
keyboard.notify_keyval(time, Clutter.KEY_Control_L, Clutter.KeyState.RELEASED);
}

function clearTimeouts() {
for (let id of pendingTimeouts) {
GLib.Source.remove(id);
}
pendingTimeouts = [];
}

function init(metadata) {
settings = new Settings.ExtensionSettings(this, metadata.uuid);
settings.bind('paste-delay', 'pasteDelay', null);
}

function enable() {
dbusSignalId = Gio.DBus.session.signal_subscribe(
null,
SMILE_DBUS_INTERFACE,
SMILE_SIGNAL,
SMILE_DBUS_PATH,
null,
Gio.DBusSignalFlags.NONE,
function() {
const keyboard = getVirtualKeyboard();
const id = GLib.timeout_add(GLib.PRIORITY_DEFAULT, pasteDelay, function() {
sendCtrlV(keyboard);
return GLib.SOURCE_REMOVE;
});
pendingTimeouts.push(id);
}
);
}

function disable() {
clearTimeouts();

if (dbusSignalId !== null) {
Gio.DBus.session.signal_unsubscribe(dbusSignalId);
dbusSignalId = null;
}

settings = null;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"uuid": "smile-autopaste@turtl.cc",
"name": "Smile Autopaste",
"description": "Automatically pastes emojis selected in Smile into the previously focused window.",
"version": "1.0",
"cinnamon-version": ["6.6"],
"author": "megaturtl",
"website": "https://turtl.cc",
"url": "https://github.com/megaturtl/smile-autopaste"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"paste-delay": {
"type": "spinbutton",
"default": 100,
"min": 50,
"max": 500,
"step": 50,
"units": "ms",
"description": "Paste delay",
"tooltip": "How long to wait after Smile closes before sending Ctrl+V. Increase this if the paste is not landing your target window."
}
}
4 changes: 4 additions & 0 deletions smile-autopaste@turtl.cc/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"author": "megaturtl",
"license": "GPL-3.0"
}
Binary file added smile-autopaste@turtl.cc/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading