Skip to content
This repository has been archived by the owner on Oct 17, 2019. It is now read-only.

Commit

Permalink
macOS: Use the native emoji picker
Browse files Browse the repository at this point in the history
fixes #79
  • Loading branch information
mujx committed Sep 19, 2018
1 parent 1716502 commit 1b7816f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ else()
endif()

if (APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Foundation")
set(SRC_FILES ${SRC_FILES} src/notifications/ManagerMac.mm)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Foundation -framework Cocoa")
set(SRC_FILES ${SRC_FILES} src/notifications/ManagerMac.mm src/emoji/MacHelper.mm)
elseif (WIN32)
file(DOWNLOAD
"https://raw.githubusercontent.com/mohabouje/WinToast/41ed1c58d5dce0ee9c01dbdeac05be45358d4f57/src/wintoastlib.cpp"
Expand Down
15 changes: 15 additions & 0 deletions src/TextInputWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#include "ui/FlatButton.h"
#include "ui/LoadingIndicator.h"

#if defined(Q_OS_MAC)
#include "emoji/MacHelper.h"
#endif

static constexpr size_t INPUT_HISTORY_SIZE = 127;
static constexpr int MAX_TEXTINPUT_HEIGHT = 120;
static constexpr int InputHeight = 26;
Expand Down Expand Up @@ -124,6 +128,12 @@ FilteredTextEdit::keyPressEvent(QKeyEvent *event)
{
const bool isModifier = (event->modifiers() != Qt::NoModifier);

#if defined(Q_OS_MAC)
if (event->modifiers() == (Qt::ControlModifier | Qt::MetaModifier) &&
event->key() == Qt::Key_Space)
MacHelper::showEmojiWindow();
#endif

if (!isModifier) {
if (!typingTimer_->isActive())
emit startedTyping();
Expand Down Expand Up @@ -503,6 +513,11 @@ TextInputWidget::TextInputWidget(QWidget *parent)
emojiBtn_ = new emoji::PickButton(this);
emojiBtn_->setToolTip(tr("Emoji"));

#if defined(Q_OS_MAC)
// macOS has a native emoji picker.
emojiBtn_->hide();
#endif

QIcon emoji_icon;
emoji_icon.addFile(":/icons/icons/ui/smile.png");
emojiBtn_->setIcon(emoji_icon);
Expand Down
10 changes: 10 additions & 0 deletions src/emoji/MacHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <QMenuBar>

class MacHelper
{
public:
static void showEmojiWindow();
static void initializeMenus();
};
26 changes: 26 additions & 0 deletions src/emoji/MacHelper.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "MacHelper.h"

#include <Cocoa/Cocoa.h>
#include <Foundation/Foundation.h>
#include <Foundation/NSString.h>
#include <QCoreApplication>

void
MacHelper::showEmojiWindow()
{
NSApplication *theNSApplication = [NSApplication sharedApplication];
[theNSApplication orderFrontCharacterPalette:nil];
}

void
MacHelper::initializeMenus()
{
NSApplication *theNSApplication = [NSApplication sharedApplication];

NSArray<NSMenuItem *> *menus = [theNSApplication mainMenu].itemArray;
NSUInteger size = menus.count;
for (NSUInteger i = 0; i < size; i++) {
NSMenuItem *item = [menus objectAtIndex:i];
[item setTitle:@"Edit"];
}
}
10 changes: 10 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
#include "Utils.h"
#include "version.h"

#if defined(Q_OS_MAC)
#include "emoji/MacHelper.h"
#endif

#if defined(Q_OS_LINUX)
#include <boost/stacktrace.hpp>
#include <signal.h>
Expand Down Expand Up @@ -186,6 +190,12 @@ main(int argc, char *argv[])
}
});

#if defined(Q_OS_MAC)
// Temporary solution for the emoji picker until
// nheko has a proper menu bar with more functionality.
MacHelper::initializeMenus();
#endif

nhlog::ui()->info("starting nheko {}", nheko::version);

return app.exec();
Expand Down

0 comments on commit 1b7816f

Please sign in to comment.