Skip to content

Commit

Permalink
README & LICENSE & F4 keybind
Browse files Browse the repository at this point in the history
  • Loading branch information
GaZaTu committed Nov 25, 2020
1 parent 9d6a862 commit 4e54d99
Show file tree
Hide file tree
Showing 13 changed files with 306 additions and 17 deletions.
59 changes: 59 additions & 0 deletions .scripts/create-emoji-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,68 @@ public:
${NO_CLDR ? '// NO_CLDR' : 'std::string nameByLocale(const std::string& localeKey = std::locale("").name().substr(0, 2)) const;'}
bool isGenderVariation() const {
const char* MALE_SIGN = u8"\U00002642";
const char* FEMALE_SIGN = u8"\U00002640";
const char* BOY = u8"\U0001F466";
const char* GIRL = u8"\U0001F467";
const char* MAN = u8"\U0001F468";
const char* WOMAN = u8"\U0001F469";
if (
code == MALE_SIGN ||
code == FEMALE_SIGN ||
code == BOY ||
code == GIRL ||
code == MAN ||
code == WOMAN
) {
return false;
}
return (
code.find(MALE_SIGN) != std::string::npos ||
code.find(FEMALE_SIGN) != std::string::npos ||
code.find(BOY) != std::string::npos ||
code.find(GIRL) != std::string::npos ||
code.find(MAN) != std::string::npos ||
code.find(WOMAN) != std::string::npos
);
}
bool isSkinToneVariation() const {
const char* LIGHT = u8"\U0001F3FB";
const char* LIGHT_MEDIUM = u8"\U0001F3FC";
const char* MEDIUM = u8"\U0001F3FD";
const char* DARK_MEDIUM = u8"\U0001F3FE";
const char* DARK = u8"\U0001F3FF";
if (
code == LIGHT ||
code == LIGHT_MEDIUM ||
code == MEDIUM ||
code == DARK_MEDIUM ||
code == DARK
) {
return false;
}
return (
code.find(LIGHT) != std::string::npos ||
code.find(LIGHT_MEDIUM) != std::string::npos ||
code.find(MEDIUM) != std::string::npos ||
code.find(DARK_MEDIUM) != std::string::npos ||
code.find(DARK) != std::string::npos
);
}
bool operator==(const Emoji& other) const {
return code == other.code;
}
operator bool() const {
return code != "";
}
};
// generated from ${UNICODE_EMOJI_LIST_URL}
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.7.2 FATAL_ERROR)
project(emoji-picker VERSION 0.4.0 LANGUAGES CXX)
project(emoji-picker VERSION 0.5.0 LANGUAGES CXX)

cmake_policy(SET CMP0074 NEW)

Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 GaZaTu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
132 changes: 132 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# x11-emoji-picker

A dialog / emoji picker inspired by the Windows 10 emoji picker written for Linux systems using Xorg.

Works for my use case most of the time. 😅 😂👌🔥💯

## Motivation 🤔

I switched from Windows 10 to Linux at work and missed filling my emails with emojis. (the KDE version we use doesn't have the builtin emoji picker yet)

## Screenshots 😮

![dialog with search result](doc/search.png)
*dialog with search result*

![dialog with full emoji list](doc/list.png)
*dialog with full emoji list*

![dialog with github aliases](doc/aliases.png)
*dialog with github aliases*

## Installation 😉

Install Qt5, ICU and xdotool using your package manager.
Example for Debian based systems: `apt install qt5-default libicu libxdo`.

Download the emoji-picker executable from [here](https://github.com/GaZaTu/x11-emoji-picker/releases), or build it yourself.

## Building 🤓

This is a CMake project so you need cmake and some c++ compiler.
I think it uses g++ by default but tbh i have no idea how cmake actually works.
Actually i got it to work with clang+msvc on windows aswell so clang should work.

### Required Libs

- Qt5 (`apt install qtbase5-dev` ?)
- ICU (`apt install libicu-dev`)
- xdo (`apt install libxdo-dev`)

### CMake

- `mkdir build`
- `cd build`
- `cmake ..`
- `make .`

### Codegen

I committed the generated code so you won't have to run any scripts.

- script [.scripts/create-emoji-map.js](.scripts/create-emoji-map.js) to create [src/emojis.hpp](src/emojis.hpp) and [src/emojis.cpp](src/emojis.cpp)
- script [.scripts/create-emoji-aliases-ini.js](.scripts/create-emoji-aliases-ini.js) to create [src/aliases/github-emojis.ini](src/aliases/github-emojis.ini)

## Usage 🧐

First you should add the emoji-picker executable as a keybind (however you do that in your window manager); I use `meta+.` just like the windows keybind.

The emoji picker will always write to the window that was active **before** starting the application. You have to restart it if you want to write to a different window.

After the emoji picker opened you can just begin typing to search for an emoji. Emojis that start with the text you entered will be shown below the text input. You can navigate these by using the **arrow keys**.

When you've selected your emoji you can press the **return key** to write it.

### Keybinds

- `Arrow keys` => navigate through shown emojis
- `Return` => write emoji to previously active window
- `Shift+Return` => write emoji to previously active window and close emoji picker
- `F1` => show recently used emojis (default view)
- `F2` => show list of all emojis (if you press this while searching, the view will jump to the currently selected emoji aswell)
- `F4` => close emoji picker and open settings file

### Settings

The settings file should be located at `/home/<user>/.config/gazatu.xyz/emoji-picker.ini`.

- `[General] | activateWindowBeforeWritingByDefault` => enable this to activate windows by default before writing to them
- `[General] | aliasExactMatching` => enable this to only show aliased emojis when the search matches completely
- `[General] | copyEmojiToClipboardAswellByDefault` => enable this to copy emojis into clipboard after trying to write them
- `[General] | customQssFilePath` => custom styling (colors and shit) for the emoji picker (refer to [src/main.qss](src/main.qss) for examples); useful if you don't like the dark theme
- `[General] | emojiAliasesIniFilePath` => list of custom emoji codes (refer to [src/aliases/github-emojis.ini](src/aliases/github-emojis.ini) for examples); points to the builtin list of github emojis by default ([https://github.com/ikatyang/emoji-cheat-sheet/blob/master/README.md](https://github.com/ikatyang/emoji-cheat-sheet/blob/master/README.md))
- `[General] | gendersDisabled` => `true` if you only want to see gender neutral emojis (jobs or family or w/e)
- `[General] | localeKey` => the emoji translation you want to use (en, de, fr, nl, da, it, pt, es, sv, pl, hr, cs, fi, el, hu) or empty if you want to use english with underscores
- `[General] | maxEmojiVersion` => set this to for example 12 to exclude emojis released after that or -1 to show all emojis
- `[General] | openAtMouseLocation` => enable this if you want to open the emoji picker dialog at the current mouse cursor
- `[General] | skinTonesDisabled` => `true` if you only want to see skin-tone neutral emojis (hands or jobs or family or w/e)
- `[General] | useSystemQtTheme` => enable this if you want to use the system qt theme (not recommended, usually only works with kde i think)
- `[activateWindowBeforeWritingExceptions]` => list of executables that should be an exception to the `[General] | activateWindowBeforeWritingByDefault` setting
- `[copyEmojiToClipboardAswellExceptions]` => list of executables that should be an exception to the `[General] | copyEmojiToClipboardAswellByDefault` setting
- `[recentEmojis]` => list of recently used emojis (edited by the application itself)

#### Defaults

```ini
[General]
activateWindowBeforeWritingByDefault=false
aliasExactMatching=false
copyEmojiToClipboardAswellByDefault=false
customQssFilePath=
emojiAliasesIniFilePath=:/aliases/github-emojis.ini
gendersDisabled=false
localeKey=
maxEmojiVersion=-1
openAtMouseLocation=false
skinTonesDisabled=false
useSystemQtTheme=false

[activateWindowBeforeWritingExceptions]
1\processName=code
2\processName=chromium
size=2

[copyEmojiToClipboardAswellExceptions]
1\processName=example
size=1

[recentEmojis]
size=0
```

## Credits 🤗

- [zneix](https://github.com/zneix) 😊👌

## License 😈

Code licensed under the [MIT](https://opensource.org/licenses/MIT) license: [LICENSE](LICENSE)

Graphics licensed by [Twitter](https://github.com/twitter) under *CC-BY 4.0* at [https://github.com/twitter/twemoji](https://github.com/twitter/twemoji)

Emoji list and translations licensed by [Unicode](https://github.com/unicode-org) at [https://github.com/unicode-org/cldr](https://github.com/unicode-org/cldr/blob/master/unicode-license.txt)
Binary file added doc/aliases.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion src/EmojiLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ void EmojiLabel::setEmoji(const Emoji& emoji, int w, int h) {
_emoji = emoji;

setAccessibleName(QString::fromStdString(_emoji.name));
setPixmap(getPixmapByEmojiStr(_emoji.code).scaled(w, h, Qt::KeepAspectRatio, Qt::SmoothTransformation));

QPixmap emojiPixmap = getPixmapByEmojiStr(_emoji.code).scaled(w, h, Qt::KeepAspectRatio, Qt::SmoothTransformation);

if (emojiPixmap.isNull()) {
setText(QString::fromStdString(_emoji.code));
} else {
setPixmap(emojiPixmap);
}
}

bool EmojiLabel::highlighted() {
Expand Down
2 changes: 2 additions & 0 deletions src/EmojiLineEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ void EmojiLineEdit::keyPressEvent(QKeyEvent* event) {
break;
case Qt::Key_F1:
case Qt::Key_F2:
case Qt::Key_F3:
case Qt::Key_F4:
emit functionKeyPressed(*event);
break;
case Qt::Key_Tab:
Expand Down
1 change: 0 additions & 1 deletion src/EmojiLineEdit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <QLabel>
#include <QLineEdit>
#include <QStackedLayout>
#include <QStyleOptionFrame>

class EmojiLineEdit : public QLineEdit {
Q_OBJECT
Expand Down
37 changes: 23 additions & 14 deletions src/EmojiPicker.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "EmojiPicker.hpp"
#include "EmojiPickerSettings.hpp"
#include <QDesktopServices>

EmojiPicker::EmojiPicker(QWidget* parent) : QWidget(parent) {
setLayout(_mainLayout);
Expand All @@ -9,6 +10,7 @@ EmojiPicker::EmojiPicker(QWidget* parent) : QWidget(parent) {
_gendersDisabled = EmojiPickerSettings::startupSnapshot().gendersDisabled();
_maxEmojiVersion = EmojiPickerSettings::startupSnapshot().maxEmojiVersion();
_aliasedEmojis = EmojiPickerSettings::startupSnapshot().aliasedEmojis();
_settingsPath = EmojiPickerSettings::startupSnapshot().fileName().toStdString();

_emojiLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);

Expand Down Expand Up @@ -124,13 +126,11 @@ bool EmojiPicker::isDisabledEmoji(const Emoji& emoji) {
return true;
}

if (_skinTonesDisabled && (emoji.name.find("_skin_tone") != std::string::npos)) {
if (_skinTonesDisabled && emoji.isSkinToneVariation()) {
return true;
}

if (_gendersDisabled &&
(emoji.name.find("man_") == 0 || emoji.name.find("woman_") == 0 || emoji.name.find("men_") == 0 ||
emoji.name.find("women_") == 0)) {
if (_gendersDisabled && emoji.isGenderVariation()) {
return true;
}

Expand Down Expand Up @@ -189,17 +189,22 @@ void EmojiPicker::fillViewWithEmojisByText(const std::string& text) {
}
}

EmojiLabel* emojiLabel = nullptr;
for (const auto& emoji : emojis) {
if (emoji.code != alias.code) {
continue;
if (emoji.code == alias.code) {
emojiLabel = new EmojiLabel(nullptr, emoji);
break;
}
}

EmojiLabel* emojiLabel = new EmojiLabel(nullptr, emoji);
emojiLabel->setProperty("alias", QString::fromStdString(alias.name));
if (emojiLabel == nullptr) {
emojiLabel = new EmojiLabel(nullptr, alias);
}

if (addEmojiLabel(emojiLabel, row, col)) {
break;
}
emojiLabel->setProperty("alias", QString::fromStdString(alias.name));

if (addEmojiLabel(emojiLabel, row, col)) {
break;
}

if (aliasExactMatching) {
Expand Down Expand Up @@ -249,7 +254,7 @@ void EmojiPicker::fillViewWithEmojisByList() {
_helpEmojiListStartEmoji = {"", ""};
}

if (_helpEmojiListStartEmoji.code != "") {
if (_helpEmojiListStartEmoji) {
for (const auto& emoji : emojis) {
if (isDisabledEmoji(emoji)) {
continue;
Expand Down Expand Up @@ -279,7 +284,7 @@ void EmojiPicker::fillViewWithEmojisByList() {

idx += 1;

if (_helpEmojiListStartEmoji.code != "" && (idx - 1) < (startRow * cols)) {
if (_helpEmojiListStartEmoji && (idx - 1) < (startRow * cols)) {
continue;
}

Expand All @@ -294,7 +299,7 @@ void EmojiPicker::fillViewWithEmojisByList() {
}
}

if (_helpEmojiListStartEmoji.code != "") {
if (_helpEmojiListStartEmoji) {
for (EmojiLabel* emojiLabel : _emojiLayoutWidget->findChildren<EmojiLabel*>()) {
if (emojiLabel->emoji() == _helpEmojiListStartEmoji) {
setSelectedEmojiLabel(emojiLabel);
Expand Down Expand Up @@ -406,6 +411,10 @@ void EmojiPicker::onFunctionKeyPressed(const QKeyEvent& event) {
case Qt::Key_F2:
onHelpPressed(nullptr);
break;
case Qt::Key_F4:
QDesktopServices::openUrl(QUrl::fromLocalFile(QString::fromStdString(_settingsPath)));
emit escapePressed();
break;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/EmojiPicker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class EmojiPicker : public QWidget {
bool _gendersDisabled = false;
int _maxEmojiVersion = -1;
std::vector<Emoji> _aliasedEmojis;
std::string _settingsPath;

EmojiLabel* _selectedEmojiLabel = nullptr;

Expand Down
Loading

0 comments on commit 4e54d99

Please sign in to comment.