Skip to content

Commit

Permalink
完成 Mac 初版
Browse files Browse the repository at this point in the history
  • Loading branch information
imlinhanchao committed Mar 2, 2020
1 parent 8413f0e commit 56bb618
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 15 deletions.
8 changes: 7 additions & 1 deletion src/KeyGenius.pro
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ HEADERS += \
inc/cross/definition_win.h \
widget.h

mac:LIBS += -framework ApplicationServices
macx {
LIBS += -framework Foundation
LIBS += -framework AppKit

OBJECTIVE_SOURCES += inc/cross/objectivec.mm
HEADERS += inc/cross/objectivec.h
}

FORMS += \
widget.ui
Expand Down
1 change: 1 addition & 0 deletions src/inc/cross/cross.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
#ifdef Q_OS_MAC

#include "definition_mac.h"
#include "objectivec.h"

#endif
14 changes: 2 additions & 12 deletions src/inc/cross/definition_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,15 @@

#define ICON_RES ":/icon/KeyGenius.icns"

#ifdef __cplusplus

#include <QSettings>
#include <QKeySequence>

extern "C" {
#endif

#include <Carbon/Carbon.h>
#include <ApplicationServices/ApplicationServices.h>

unsigned int Sleep(unsigned int m);
void KeybdEvent(CGKeyCode key, bool bkeydown);

#ifdef __cplusplus

}

CGKeyCode toCGKeyCode(Qt::Key k);

Expand All @@ -39,8 +31,8 @@ typedef struct _HOTKEY_CFG

_HOTKEY_CFG()
{
vkNext = Qt::Key_F1 + Qt::ALT;
vkStop = Qt::Key_F2 + Qt::CTRL;
vkNext = Qt::Key_N + Qt::ALT;
vkStop = Qt::Key_S+ Qt::ALT;
vkKey1 = Qt::Key_S + Qt::CTRL;
vkKey2 = Qt::Key_F7;
nTimeInterval = 5000;
Expand Down Expand Up @@ -99,5 +91,3 @@ typedef struct _HOTKEY_CFG
}HOTKEY_CFG, *PHOTKEY_CFG;

#endif

#endif
10 changes: 10 additions & 0 deletions src/inc/cross/objectivec.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef OBJECTIVE_H
#define OBJECTIVE_H

class ObjectiveC
{
public:
static void HideWindow();
};

#endif // OBJECTIVE_H
9 changes: 9 additions & 0 deletions src/inc/cross/objectivec.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "objectivec.h"
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import <CoreData/CoreData.h>

void ObjectiveC::HideWindow()
{
[NSApp hide:nil];
}
2 changes: 0 additions & 2 deletions src/res/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@
<string>hancel.@EXECUTABLE@</string>
<key>NOTE</key>
<string>This file was generated by Qt/QMake.</string>
<key>LSUIElement</key>
<string>1</string>
</dict>
</plist>
8 changes: 8 additions & 0 deletions src/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ void Widget::InitUi()
{
m_ui->spinBox_interval->setSingleStep(1000);
m_ui->spinBox_interval->setMaximum(2000000000);

m_config = Config::GetConfig();

m_ui->keySequence_switch->setKeySequence(m_config.toKey(HOTKEY_CFG::next));
m_ui->keySequence_start->setKeySequence(m_config.toKey(HOTKEY_CFG::stop));
m_ui->keySequence_key1->setKeySequence(m_config.toKey(HOTKEY_CFG::key1));
m_ui->keySequence_key2->setKeySequence(m_config.toKey(HOTKEY_CFG::key2));
m_ui->spinBox_interval->setValue(m_config.nTimeInterval);


QIcon icon = QIcon(ICON_RES);
m_trayIcon = new QSystemTrayIcon(this);
m_trayIcon->setIcon(icon);
Expand Down Expand Up @@ -129,7 +132,12 @@ void Widget::changeEvent(QEvent *e)
if((e->type() == QEvent::WindowStateChange) && isMinimized())
{
e->ignore();
#ifdef Q_OS_MAC
ObjectiveC *obc = new ObjectiveC();
obc->HideWindow();
#else
hide();
#endif
}
}

Expand Down

0 comments on commit 56bb618

Please sign in to comment.