[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
|
set(SOURCES
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
src/MpvPlayerBackend.cpp
|
src/MpvPlayerBackend.cpp
|
||||||
|
src/utils.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
find_program(CCACHE_FOUND ccache)
|
find_program(CCACHE_FOUND ccache)
|
||||||
|
@ -50,7 +51,6 @@ if(DEVELOP)
|
||||||
set(SOURCES ${SOURCES} runtimeqml/runtimeqml.cpp)
|
set(SOURCES ${SOURCES} runtimeqml/runtimeqml.cpp)
|
||||||
add_definitions(-DQRC_SOURCE_PATH="${PROJECT_SOURCE_DIR}/src/qml")
|
add_definitions(-DQRC_SOURCE_PATH="${PROJECT_SOURCE_DIR}/src/qml")
|
||||||
add_definitions(-DQT_QML_DEBUG)
|
add_definitions(-DQT_QML_DEBUG)
|
||||||
|
|
||||||
endif(DEVELOP)
|
endif(DEVELOP)
|
||||||
|
|
||||||
add_executable(KittehPlayer ${SOURCES} ${qml_QRC})
|
add_executable(KittehPlayer ${SOURCES} ${qml_QRC})
|
||||||
|
|
|
@ -3,19 +3,20 @@ TARGET = KittehPlayer
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
QT += qml quickcontrols2 widgets x11extras
|
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 += release
|
||||||
#CONFIG+=qtquickcompiler
|
#CONFIG+=qtquickcompiler
|
||||||
QT_CONFIG -= no-pkg-config
|
QT_CONFIG -= no-pkg-config
|
||||||
CONFIG += link_pkgconfig
|
CONFIG += link_pkgconfig
|
||||||
PKGCONFIG += mpv x11 xext
|
PKGCONFIG += mpv
|
||||||
RESOURCES += src/qml/qml.qrc
|
RESOURCES += src/qml/qml.qrc
|
||||||
|
|
||||||
unix {
|
unix {
|
||||||
isEmpty {
|
isEmpty {
|
||||||
PREFIX = /usr
|
PREFIX = /usr
|
||||||
}
|
}
|
||||||
|
PKGCONFIG += x11 xext
|
||||||
|
|
||||||
target.path = $$PREFIX/bin
|
target.path = $$PREFIX/bin
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ unix {
|
||||||
|
|
||||||
INSTALLS += target
|
INSTALLS += target
|
||||||
|
|
||||||
HEADERS += src/MpvPlayerBackend.h
|
HEADERS += src/MpvPlayerBackend.h src/utils.hpp
|
||||||
|
|
||||||
|
|
||||||
DISTFILES += KittehPlayer.desktop KittehPlayer.png README.md LICENSE.txt
|
DISTFILES += KittehPlayer.desktop KittehPlayer.png README.md LICENSE.txt
|
||||||
|
|
|
@ -1,20 +1,16 @@
|
||||||
|
|
||||||
#include <clocale>
|
#include <clocale>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include "MpvPlayerBackend.h"
|
#include "MpvPlayerBackend.h"
|
||||||
|
|
||||||
|
#include "utils.hpp"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QOpenGLContext>
|
#include <QOpenGLContext>
|
||||||
#include <QOpenGLFramebufferObject>
|
#include <QOpenGLFramebufferObject>
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
#include <math.h>
|
#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 {
|
namespace {
|
||||||
|
|
||||||
|
@ -156,9 +152,7 @@ MpvPlayerBackend::MpvPlayerBackend(QQuickItem* parent)
|
||||||
|
|
||||||
MpvPlayerBackend::~MpvPlayerBackend()
|
MpvPlayerBackend::~MpvPlayerBackend()
|
||||||
{
|
{
|
||||||
Display *dpy = QX11Info::display();
|
SetDPMS(true);
|
||||||
DPMSEnable(dpy);
|
|
||||||
qDebug() << "Enabled DPMS.";
|
|
||||||
mpv_render_context_free(mpv_gl);
|
mpv_render_context_free(mpv_gl);
|
||||||
mpv_terminate_destroy(mpv);
|
mpv_terminate_destroy(mpv);
|
||||||
}
|
}
|
||||||
|
@ -307,6 +301,13 @@ MpvPlayerBackend::createTimestamp(const QVariant& seconds) const
|
||||||
return hour + minute + second;
|
return hour + minute + second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MpvPlayerBackend::toggleOnTop()
|
||||||
|
{
|
||||||
|
onTop = !onTop;
|
||||||
|
AlwaysOnTop(window()->winId(), onTop);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MpvPlayerBackend::on_mpv_events()
|
MpvPlayerBackend::on_mpv_events()
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,6 +16,7 @@ class MpvPlayerBackend : public QQuickFramebufferObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
mpv_handle* mpv;
|
mpv_handle* mpv;
|
||||||
mpv_render_context* mpv_gl;
|
mpv_render_context* mpv_gl;
|
||||||
|
bool onTop = false;
|
||||||
|
|
||||||
friend class MpvRenderer;
|
friend class MpvRenderer;
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ public slots:
|
||||||
void nextSubtitleTrack();
|
void nextSubtitleTrack();
|
||||||
void prevPlaylistItem();
|
void prevPlaylistItem();
|
||||||
void nextPlaylistItem();
|
void nextPlaylistItem();
|
||||||
|
void toggleOnTop();
|
||||||
QVariant getTracks() const;
|
QVariant getTracks() const;
|
||||||
|
|
||||||
void setVolume(const QVariant& volume);
|
void setVolume(const QVariant& volume);
|
||||||
|
|
20
src/main.cpp
20
src/main.cpp
|
@ -2,19 +2,15 @@
|
||||||
#include "runtimeqml/runtimeqml.h"
|
#include "runtimeqml/runtimeqml.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
#include "MpvPlayerBackend.h"
|
#include "MpvPlayerBackend.h"
|
||||||
#include <QtCore>
|
#include "utils.hpp"
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QProcessEnvironment>
|
#include <QProcessEnvironment>
|
||||||
#include <QQmlApplicationEngine>
|
#include <QQmlApplicationEngine>
|
||||||
|
#include <QtCore>
|
||||||
#include <stdbool.h>
|
#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
|
#ifdef WIN32
|
||||||
#include "setenv_mingw.hpp"
|
#include "setenv_mingw.hpp"
|
||||||
|
@ -44,9 +40,7 @@ main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Display *dpy = QX11Info::display();
|
SetDPMS(false);
|
||||||
DPMSDisable(dpy);
|
|
||||||
qDebug() << "Disabled DPMS.";
|
|
||||||
|
|
||||||
QString newpath =
|
QString newpath =
|
||||||
QProcessEnvironment::systemEnvironment().value("APPDIR", "") +
|
QProcessEnvironment::systemEnvironment().value("APPDIR", "") +
|
||||||
|
@ -54,8 +48,8 @@ main(int argc, char* argv[])
|
||||||
setenv("PATH", newpath.toUtf8().constData(), 1);
|
setenv("PATH", newpath.toUtf8().constData(), 1);
|
||||||
|
|
||||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
QApplication::setAttribute(Qt::AA_NativeWindows);
|
QApplication::setAttribute(Qt::AA_NativeWindows);
|
||||||
|
|
||||||
qmlRegisterType<MpvPlayerBackend>("player", 1, 0, "PlayerBackend");
|
qmlRegisterType<MpvPlayerBackend>("player", 1, 0, "PlayerBackend");
|
||||||
std::setlocale(LC_NUMERIC, "C");
|
std::setlocale(LC_NUMERIC, "C");
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ Item {
|
||||||
|
|
||||||
function getTranslation(code, language) {
|
function getTranslation(code, language) {
|
||||||
var lang = Translations.translations[language]
|
var lang = Translations.translations[language]
|
||||||
if (lang == undefined) {
|
if (lang == undefined || lang == "undefined") {
|
||||||
return "TranslationNotFound"
|
return "TranslationNotFound"
|
||||||
}
|
}
|
||||||
var text = String(Translations.translations[i18n.language][code])
|
var text = String(Translations.translations[i18n.language][code])
|
||||||
|
|
|
@ -734,6 +734,13 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
shortcut: keybinds.nyanCat
|
shortcut: keybinds.nyanCat
|
||||||
}
|
}
|
||||||
|
Action {
|
||||||
|
text: translate.getTranslation("TOGGLE_ALWAYS_ON_TOP",
|
||||||
|
i18n.language)
|
||||||
|
onTriggered: {
|
||||||
|
player.toggleOnTop()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Menu {
|
Menu {
|
||||||
id: aboutMenuBarItem
|
id: aboutMenuBarItem
|
||||||
|
|
|
@ -39,7 +39,8 @@ var translations = {
|
||||||
TOGGLE_NYAN_CAT: "Toggle Nyan Cat",
|
TOGGLE_NYAN_CAT: "Toggle Nyan Cat",
|
||||||
ABOUT: "About",
|
ABOUT: "About",
|
||||||
ABOUT_QT: "About Qt",
|
ABOUT_QT: "About Qt",
|
||||||
TITLE: "Title"
|
TITLE: "Title",
|
||||||
|
TOGGLE_ALWAYS_ON_TOP: "Toggle Always On Top"
|
||||||
},
|
},
|
||||||
spanish: {
|
spanish: {
|
||||||
SAVE_SCREENSHOT: "Guardar captura en",
|
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