forked from carsonip/Penguin-Subtitle-Player
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: global shortcuts to next/previous subtitle (X11 only)
- Loading branch information
1 parent
e54f0c1
commit 3424b29
Showing
4 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "eventfilter.h" | ||
#include "mainwindow.h" | ||
#include <xcb/xcb.h> | ||
#include <X11/Xlib.h> | ||
#include <X11/Xutil.h> | ||
|
||
#include <QtX11Extras/QX11Info> | ||
|
||
|
||
void EventFilter::setup(QWidget *target) | ||
{ | ||
this->target = target; | ||
|
||
Display * display = QX11Info::display(); | ||
keycodePrevious = XKeysymToKeycode(display, XK_A); | ||
keycodeNext = XKeysymToKeycode(display, XK_S); | ||
XGrabKey(display, keycodePrevious, AnyModifier, DefaultRootWindow(display), 1, GrabModeAsync, GrabModeAsync); | ||
XGrabKey(display, keycodeNext, AnyModifier, DefaultRootWindow(display), 1, GrabModeAsync, GrabModeAsync); | ||
} | ||
|
||
bool EventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *) | ||
{ | ||
if (eventType == "xcb_generic_event_t") | ||
{ | ||
xcb_generic_event_t* xcbevent = static_cast<xcb_generic_event_t *>(message); | ||
|
||
switch(xcbevent->response_type) | ||
{ | ||
case XCB_KEY_PRESS: | ||
xcb_key_press_event_t * keypress_event = static_cast<xcb_key_press_event_t *>(message); | ||
if(keypress_event->detail == keycodePrevious) | ||
{ | ||
qobject_cast<MainWindow*>(target->topLevelWidget())->previous(); | ||
} | ||
if(keypress_event->detail == keycodeNext) | ||
{ | ||
qobject_cast<MainWindow*>(target->topLevelWidget())->next(); | ||
} | ||
} | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef EVENTFILTER_H | ||
#define EVENTFILTER_H | ||
|
||
#include <QAbstractNativeEventFilter> | ||
#include <QWidget> | ||
|
||
class EventFilter : public QAbstractNativeEventFilter | ||
{ | ||
public: | ||
void setup(QWidget *target); | ||
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result); | ||
private: | ||
int keycodeNext; | ||
int keycodePrevious; | ||
QWidget * target; | ||
}; | ||
|
||
#endif // EVENTFILTER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters