[Backend+UI] Added platform utils and always on top mode toggle.
This commit is contained in:
parent
aa2cf71b43
commit
fed625fc99
|
@ -24,6 +24,7 @@ pkg_check_modules(Xext REQUIRED xext)
|
|||
set(SOURCES
|
||||
src/main.cpp
|
||||
src/MpvPlayerBackend.cpp
|
||||
src/utils.cpp
|
||||
)
|
||||
|
||||
find_program(CCACHE_FOUND ccache)
|
||||
|
@ -50,7 +51,6 @@ if(DEVELOP)
|
|||
set(SOURCES ${SOURCES} runtimeqml/runtimeqml.cpp)
|
||||
add_definitions(-DQRC_SOURCE_PATH="${PROJECT_SOURCE_DIR}/src/qml")
|
||||
add_definitions(-DQT_QML_DEBUG)
|
||||
|
||||
endif(DEVELOP)
|
||||
|
||||
add_executable(KittehPlayer ${SOURCES} ${qml_QRC})
|
||||
|
|
|
@ -3,19 +3,20 @@ TARGET = KittehPlayer
|
|||
TEMPLATE = app
|
||||
QT += qml quickcontrols2 widgets x11extras
|
||||
|
||||
SOURCES += src/main.cpp src/MpvPlayerBackend.cpp
|
||||
SOURCES += src/main.cpp src/MpvPlayerBackend.cpp src/utils.cpp
|
||||
|
||||
CONFIG += release
|
||||
#CONFIG+=qtquickcompiler
|
||||
QT_CONFIG -= no-pkg-config
|
||||
CONFIG += link_pkgconfig
|
||||
PKGCONFIG += mpv x11 xext
|
||||
PKGCONFIG += mpv
|
||||
RESOURCES += src/qml/qml.qrc
|
||||
|
||||
unix {
|
||||
isEmpty {
|
||||
PREFIX = /usr
|
||||
}
|
||||
PKGCONFIG += x11 xext
|
||||
|
||||
target.path = $$PREFIX/bin
|
||||
|
||||
|
@ -30,7 +31,7 @@ unix {
|
|||
|
||||
INSTALLS += target
|
||||
|
||||
HEADERS += src/MpvPlayerBackend.h
|
||||
HEADERS += src/MpvPlayerBackend.h src/utils.hpp
|
||||
|
||||
|
||||
DISTFILES += KittehPlayer.desktop KittehPlayer.png README.md LICENSE.txt
|
||||
|
|
|
@ -1,20 +1,16 @@
|
|||
|
||||
#include <clocale>
|
||||
#include <stdbool.h>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "MpvPlayerBackend.h"
|
||||
|
||||
#include "utils.hpp"
|
||||
#include <QApplication>
|
||||
#include <QOpenGLContext>
|
||||
#include <QOpenGLFramebufferObject>
|
||||
#include <QQuickWindow>
|
||||
#include <math.h>
|
||||
#include <QX11Info>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include <X11/extensions/dpms.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -156,9 +152,7 @@ MpvPlayerBackend::MpvPlayerBackend(QQuickItem* parent)
|
|||
|
||||
MpvPlayerBackend::~MpvPlayerBackend()
|
||||
{
|
||||
Display *dpy = QX11Info::display();
|
||||
DPMSEnable(dpy);
|
||||
qDebug() << "Enabled DPMS.";
|
||||
SetDPMS(true);
|
||||
mpv_render_context_free(mpv_gl);
|
||||
mpv_terminate_destroy(mpv);
|
||||
}
|
||||
|
@ -307,6 +301,13 @@ MpvPlayerBackend::createTimestamp(const QVariant& seconds) const
|
|||
return hour + minute + second;
|
||||
}
|
||||
|
||||
void
|
||||
MpvPlayerBackend::toggleOnTop()
|
||||
{
|
||||
onTop = !onTop;
|
||||
AlwaysOnTop(window()->winId(), onTop);
|
||||
}
|
||||
|
||||
void
|
||||
MpvPlayerBackend::on_mpv_events()
|
||||
{
|
||||
|
|
|
@ -16,6 +16,7 @@ class MpvPlayerBackend : public QQuickFramebufferObject
|
|||
Q_OBJECT
|
||||
mpv_handle* mpv;
|
||||
mpv_render_context* mpv_gl;
|
||||
bool onTop = false;
|
||||
|
||||
friend class MpvRenderer;
|
||||
|
||||
|
@ -35,6 +36,7 @@ public slots:
|
|||
void nextSubtitleTrack();
|
||||
void prevPlaylistItem();
|
||||
void nextPlaylistItem();
|
||||
void toggleOnTop();
|
||||
QVariant getTracks() const;
|
||||
|
||||
void setVolume(const QVariant& volume);
|
||||
|
|
16
src/main.cpp
16
src/main.cpp
|
@ -2,19 +2,15 @@
|
|||
#include "runtimeqml/runtimeqml.h"
|
||||
#endif
|
||||
|
||||
#include <cstdlib>
|
||||
#include "MpvPlayerBackend.h"
|
||||
#include <QtCore>
|
||||
#include "utils.hpp"
|
||||
#include <cstdlib>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QtCore>
|
||||
#include <stdbool.h>
|
||||
#include <QX11Info>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include <X11/extensions/dpms.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include "setenv_mingw.hpp"
|
||||
|
@ -44,9 +40,7 @@ main(int argc, char* argv[])
|
|||
}
|
||||
}
|
||||
|
||||
Display *dpy = QX11Info::display();
|
||||
DPMSDisable(dpy);
|
||||
qDebug() << "Disabled DPMS.";
|
||||
SetDPMS(false);
|
||||
|
||||
QString newpath =
|
||||
QProcessEnvironment::systemEnvironment().value("APPDIR", "") +
|
||||
|
|
|
@ -13,7 +13,7 @@ Item {
|
|||
|
||||
function getTranslation(code, language) {
|
||||
var lang = Translations.translations[language]
|
||||
if (lang == undefined) {
|
||||
if (lang == undefined || lang == "undefined") {
|
||||
return "TranslationNotFound"
|
||||
}
|
||||
var text = String(Translations.translations[i18n.language][code])
|
||||
|
|
|
@ -734,6 +734,13 @@ ApplicationWindow {
|
|||
}
|
||||
shortcut: keybinds.nyanCat
|
||||
}
|
||||
Action {
|
||||
text: translate.getTranslation("TOGGLE_ALWAYS_ON_TOP",
|
||||
i18n.language)
|
||||
onTriggered: {
|
||||
player.toggleOnTop()
|
||||
}
|
||||
}
|
||||
}
|
||||
Menu {
|
||||
id: aboutMenuBarItem
|
||||
|
|
|
@ -39,7 +39,8 @@ var translations = {
|
|||
TOGGLE_NYAN_CAT: "Toggle Nyan Cat",
|
||||
ABOUT: "About",
|
||||
ABOUT_QT: "About Qt",
|
||||
TITLE: "Title"
|
||||
TITLE: "Title",
|
||||
TOGGLE_ALWAYS_ON_TOP: "Toggle Always On Top"
|
||||
},
|
||||
spanish: {
|
||||
SAVE_SCREENSHOT: "Guardar captura en",
|
||||
|
|
77
src/utils.cpp
Normal file
77
src/utils.cpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
#include "utils.hpp"
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QtCore>
|
||||
|
||||
QString
|
||||
getPlatformName()
|
||||
{
|
||||
QGuiApplication* qapp =
|
||||
qobject_cast<QGuiApplication*>(QCoreApplication::instance());
|
||||
return qapp->platformName();
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
#include <QX11Info>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include <X11/extensions/dpms.h>
|
||||
#include <X11/keysym.h>
|
||||
|
||||
void
|
||||
SetDPMS(bool on)
|
||||
{
|
||||
Display* dpy = QX11Info::display();
|
||||
if (on) {
|
||||
DPMSEnable(dpy);
|
||||
qDebug() << "Enabled DPMS.";
|
||||
} else {
|
||||
DPMSDisable(dpy);
|
||||
qDebug() << "Disabled DPMS.";
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
AlwaysOnTop(WId wid, bool on)
|
||||
{
|
||||
qDebug() << "On Top:" << on;
|
||||
Display* display = QX11Info::display();
|
||||
XEvent event;
|
||||
event.xclient.type = ClientMessage;
|
||||
event.xclient.serial = 0;
|
||||
event.xclient.send_event = True;
|
||||
event.xclient.display = display;
|
||||
event.xclient.window = wid;
|
||||
event.xclient.message_type = XInternAtom(display, "_NET_WM_STATE", False);
|
||||
event.xclient.format = 32;
|
||||
|
||||
event.xclient.data.l[0] = on;
|
||||
event.xclient.data.l[1] = XInternAtom(display, "_NET_WM_STATE_ABOVE", False);
|
||||
event.xclient.data.l[2] = 0;
|
||||
event.xclient.data.l[3] = 0;
|
||||
event.xclient.data.l[4] = 0;
|
||||
|
||||
XSendEvent(display,
|
||||
DefaultRootWindow(display),
|
||||
False,
|
||||
SubstructureRedirectMask | SubstructureNotifyMask,
|
||||
&event);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void
|
||||
AlwaysOnTop(WId wid, bool on)
|
||||
{
|
||||
qDebug() << "Can't set on top for platform: " << getPlatformName();
|
||||
}
|
||||
|
||||
void
|
||||
SetDPMS(bool on)
|
||||
{
|
||||
qDebug() << "Can't set DPMS for platform: " << getPlatformName();
|
||||
}
|
||||
|
||||
#endif
|
11
src/utils.hpp
Normal file
11
src/utils.hpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
#include <QWindow>
|
||||
#include <stdbool.h>
|
||||
|
||||
void
|
||||
SetDPMS(bool on);
|
||||
void
|
||||
AlwaysOnTop(WId wid, bool on);
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue