diff --git a/flameshot.pro b/flameshot.pro index c4f21c94..3ebba2cb 100644 --- a/flameshot.pro +++ b/flameshot.pro @@ -4,8 +4,8 @@ # #------------------------------------------------- -VERSION = $$system(git --git-dir $$PWD/.git --work-tree $$PWD describe --always --tags) -DEFINES += APP_VERSION=\\\"$$VERSION\\\" +APP_VERSION = $$system(git --git-dir $$PWD/.git --work-tree $$PWD describe --always --tags) +DEFINES += APP_VERSION QT += core gui @@ -23,6 +23,8 @@ CONFIG += link_pkgconfig TARGET = flameshot TEMPLATE = app +win32:RC_ICONS += img/flameshot.ico + #release: DESTDIR = build/release #debug: DESTDIR = build/debug @@ -183,6 +185,12 @@ unix:!macx { src/utils/dbusutils.h } +win32 { + SOURCES += src/core/globalshortcutfilter.cpp + + HEADERS += src/core/globalshortcutfilter.h +} + RESOURCES += \ graphics.qrc diff --git a/img/flameshot.ico b/img/flameshot.ico new file mode 100644 index 00000000..6d3a1d93 Binary files /dev/null and b/img/flameshot.ico differ diff --git a/src/core/controller.cpp b/src/core/controller.cpp index e10625fa..b99bc963 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -27,6 +27,10 @@ #include #include +#ifdef Q_OS_WIN +#include "src/core/globalshortcutfilter.h" +#endif + // Controller is the core component of Flameshot, creates the trayIcon and // launches the capture widget @@ -34,16 +38,21 @@ Controller::Controller() : m_captureWindow(nullptr) { qApp->setQuitOnLastWindowClosed(false); + initDefaults(); + // init tray icon -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) if (!ConfigHandler().disabledTrayIconValue()) { enableTrayIcon(); } -#else +#elif defined(Q_OS_WIN) enableTrayIcon(); -#endif - initDefaults(); + GlobalShortcutFilter *nativeFilter = new GlobalShortcutFilter(this); + qApp->installNativeEventFilter(nativeFilter); + connect(nativeFilter, &GlobalShortcutFilter::printPressed, + this, [this](){ this->createVisualCapture(); }); +#endif QString StyleSheet = CaptureButton::globalStyleSheet(); qApp->setStyleSheet(StyleSheet); diff --git a/src/core/globalshortcutfilter.cpp b/src/core/globalshortcutfilter.cpp new file mode 100644 index 00000000..534c642d --- /dev/null +++ b/src/core/globalshortcutfilter.cpp @@ -0,0 +1,50 @@ +// Copyright 2017 Alejandro Sirgo Rica +// +// This file is part of Flameshot. +// +// Flameshot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Flameshot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Flameshot. If not, see . + +#include "globalshortcutfilter.h" +#include "src/core/controller.h" +#include + +GlobalShortcutFilter::GlobalShortcutFilter(QObject *parent) : + QObject(parent) +{ + // Forced Print Screen + if (RegisterHotKey(NULL, 1, 0, VK_SNAPSHOT)) { + // ok + } +} + +bool GlobalShortcutFilter::nativeEventFilter( + const QByteArray &eventType, + void *message, + long *result) +{ + Q_UNUSED(eventType); + Q_UNUSED(result); + + MSG* msg = static_cast(message); + if (msg->message == WM_HOTKEY) { + //const quint32 keycode = HIWORD(msg->lParam); + //const quint32 modifiers = LOWORD(msg->lParam); + + // TODO: this is just a temporal workwrround, proper global + // support would need custom shortcuts defined by the user. + Controller::getInstance()->createVisualCapture(); + return true; + } + return false; +} diff --git a/src/core/globalshortcutfilter.h b/src/core/globalshortcutfilter.h new file mode 100644 index 00000000..2709e8a9 --- /dev/null +++ b/src/core/globalshortcutfilter.h @@ -0,0 +1,25 @@ +#ifndef GLOBALSHORTCUTFILTER_H +#define GLOBALSHORTCUTFILTER_H + +#include +#include + +class GlobalShortcutFilter : public QObject, public QAbstractNativeEventFilter { + Q_OBJECT +public: + explicit GlobalShortcutFilter(QObject *parent = 0); + + bool nativeEventFilter(const QByteArray &eventType, void *message, long *result); + +signals: + void printPressed(); + +private: + quint32 getNativeModifier(Qt::KeyboardModifiers modifiers); + quint32 nativeKeycode(Qt::Key key); + bool registerShortcut(quint32 nativeKey, quint32 nativeMods); + bool unregisterShortcut(quint32 nativeKey, quint32 nativeMods); + +}; + +#endif // GLOBALSHORTCUTFILTER_H