Delete native event filter for print key detection
This commit is contained in:
@@ -18,9 +18,7 @@ Check the user manual [here](./docs/user-manual/userManual.md)
|
||||
|
||||
**Not working on Wayland**
|
||||
|
||||
If you have a system-wide shortcut assigned to the`Print` key, you should disable it because it may interfere with the global key detection.
|
||||
|
||||
As an alternative you can compile the cli-tool in `./tools/flameshot-cli`. The execution of this tool will launch a new capture via DBus (more functionalities will be implemented).
|
||||
In order to launch a new capture you need to execute `flameshot-cli`, the sources of the cli tool are in `./tools/flameshot-cli` (the tool is compiled independently).
|
||||
|
||||
Check the ./docs folder for more information.
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ include(src/Qt-Color-Widgets//color_widgets.pri)
|
||||
DEFINES += QAPPLICATION_CLASS=QApplication
|
||||
|
||||
SOURCES += src/main.cpp\
|
||||
src/nativeeventfilter.cpp \
|
||||
src/controller.cpp \
|
||||
src/capture/button.cpp \
|
||||
src/capture/buttonhandler.cpp \
|
||||
@@ -52,7 +51,6 @@ SOURCES += src/main.cpp\
|
||||
src/flameshotdbusadapter.cpp
|
||||
|
||||
HEADERS += \
|
||||
src/nativeeventfilter.h \
|
||||
src/controller.h \
|
||||
src/capture/button.h \
|
||||
src/capture/buttonhandler.h \
|
||||
|
||||
@@ -42,10 +42,6 @@ Controller::Controller(QObject *parent) : QObject(parent),
|
||||
initDefaults();
|
||||
qApp->setQuitOnLastWindowClosed(false);
|
||||
|
||||
m_nativeEventFilter = new NativeEventFilter(this);
|
||||
qApp->installNativeEventFilter(m_nativeEventFilter);
|
||||
connect(m_nativeEventFilter, &NativeEventFilter::activated, this, &Controller::createCapture);
|
||||
|
||||
QString StyleSheet = Button::getStyle();
|
||||
qApp->setStyleSheet(StyleSheet);
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
#include "nativeeventfilter.h"
|
||||
|
||||
class QMenu;
|
||||
class QSystemTrayIcon;
|
||||
@@ -54,8 +53,6 @@ private:
|
||||
QSystemTrayIcon *m_trayIcon;
|
||||
QMenu *m_trayIconMenu;
|
||||
|
||||
NativeEventFilter *m_nativeEventFilter;
|
||||
|
||||
QPointer<CaptureWidget> m_captureWindow;
|
||||
QPointer<InfoWindow> m_infoWindow;
|
||||
QPointer<ConfigWindow> m_configWindow;
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "nativeeventfilter.h"
|
||||
#include <QVector>
|
||||
#include <QX11Info>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
namespace {
|
||||
Display * display; // Connection to X11
|
||||
Window win; // Grab window
|
||||
int keycode;
|
||||
QVector<quint32> maskModifiers;
|
||||
}
|
||||
|
||||
NativeEventFilter::NativeEventFilter(QObject *parent) : QObject(parent) {
|
||||
display = QX11Info::display();
|
||||
win = DefaultRootWindow(display);
|
||||
maskModifiers << 0 << Mod2Mask << LockMask << (Mod2Mask | LockMask);
|
||||
setShortcut();
|
||||
}
|
||||
|
||||
bool NativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
||||
void *message, long *result)
|
||||
{
|
||||
Q_UNUSED(eventType)
|
||||
Q_UNUSED(result)
|
||||
|
||||
xcb_key_press_event_t *keyEvent;
|
||||
|
||||
// Check xcb event
|
||||
if (eventType == "xcb_generic_event_t") {
|
||||
// cast message xcb event
|
||||
xcb_generic_event_t *event = static_cast<xcb_generic_event_t *>(message);
|
||||
|
||||
// check key press
|
||||
if ((event->response_type & 127) == XCB_KEY_PRESS){
|
||||
|
||||
keyEvent = static_cast<xcb_key_press_event_t *>(message);
|
||||
|
||||
foreach (quint32 maskMods, maskModifiers) {
|
||||
if((keyEvent->state == maskMods)
|
||||
&& keyEvent->detail == keycode){
|
||||
emit activated();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void NativeEventFilter::setShortcut() {
|
||||
keycode = XKeysymToKeycode(display, XK_Print);
|
||||
foreach (quint32 maskMods, maskModifiers) {
|
||||
XGrabKey(display,
|
||||
keycode ,
|
||||
maskMods,
|
||||
win,
|
||||
True,
|
||||
GrabModeAsync,
|
||||
GrabModeAsync);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef NATIVEEVENTFILTER_H
|
||||
#define NATIVEEVENTFILTER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QAbstractNativeEventFilter>
|
||||
|
||||
class NativeEventFilter : public QObject, public QAbstractNativeEventFilter {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NativeEventFilter(QObject *parent = 0);
|
||||
|
||||
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result);
|
||||
|
||||
signals:
|
||||
void activated();
|
||||
|
||||
private:
|
||||
void setShortcut();
|
||||
};
|
||||
|
||||
#endif // NATIVEEVENTFILTER_H
|
||||
Reference in New Issue
Block a user