From 17c2f60bf0ae5531431f120d65302a222dc4edb9 Mon Sep 17 00:00:00 2001 From: Dominik Louven Date: Fri, 27 Mar 2020 16:18:15 +0100 Subject: [PATCH] WIP: Desktop Overlay rendering --- ScreenPlayWallpaper/ScreenPlayWallpaper.pro | 2 + ScreenPlayWallpaper/main.cpp | 4 +- ScreenPlayWallpaper/src/linuxwindow.cpp | 266 +++++++++++++++++++- ScreenPlayWallpaper/src/linuxwindow.h | 4 + 4 files changed, 273 insertions(+), 3 deletions(-) diff --git a/ScreenPlayWallpaper/ScreenPlayWallpaper.pro b/ScreenPlayWallpaper/ScreenPlayWallpaper.pro index 011a35d3..eb1cef7f 100644 --- a/ScreenPlayWallpaper/ScreenPlayWallpaper.pro +++ b/ScreenPlayWallpaper/ScreenPlayWallpaper.pro @@ -79,6 +79,8 @@ unix { install_it.path = $${OUT_PWD}/ + LIBS += -lX11 + CONFIG(debug, debug|release) { install_it.files += \ $$PWD/../Common/vcpkg/installed/x64-linux/debug/bin/libcrypto-1_1-x64.so \ diff --git a/ScreenPlayWallpaper/main.cpp b/ScreenPlayWallpaper/main.cpp index 1ea3976b..2c9bd2a5 100644 --- a/ScreenPlayWallpaper/main.cpp +++ b/ScreenPlayWallpaper/main.cpp @@ -49,7 +49,7 @@ int main(int argc, char* argv[]) WinWindow window({ 0 }, "H:/SteamLibrary/SteamApps/workshop/content/672870/MechaGirl", "appid", "1", "fill", false); #endif #if defined(Q_OS_LINUX) - LinuxWindow window(QVector{ 0 }, "test", "appid", "1", "fill",false); + LinuxWindow window({ 0 }, "/home/graphicscore/Desktop/wallpapers/MechaGirl", "appid", "1", "fill", false); #endif #if defined(Q_OS_OSX) MacWindow window({ 0 }, "test", "appid", "1", "fill"); @@ -116,7 +116,7 @@ int main(int argc, char* argv[]) #endif #if defined(Q_OS_LINUX) - LinuxWindow window(list, argumentList.at(2), argumentList.at(3), argumentList.at(4), argumentList.at(5),false); + LinuxWindow window(list, argumentList.at(2), argumentList.at(3), argumentList.at(4), argumentList.at(5), checkWallpaperVisible); QObject::connect(&sdk, &ScreenPlaySDK::sdkDisconnected, &window, &LinuxWindow::destroyThis); QObject::connect(&sdk, &ScreenPlaySDK::incommingMessage, &window, &LinuxWindow::messageReceived); #endif diff --git a/ScreenPlayWallpaper/src/linuxwindow.cpp b/ScreenPlayWallpaper/src/linuxwindow.cpp index 641abb84..e080fcb3 100644 --- a/ScreenPlayWallpaper/src/linuxwindow.cpp +++ b/ScreenPlayWallpaper/src/linuxwindow.cpp @@ -1,14 +1,257 @@ #include "linuxwindow.h" +#include +#include +#include +#include + +#include +//#include + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define WIDTH 512 +#define HEIGHT 384 + +#define OPAQUE 0xffffffff + +#define NAME "xwinwrap" + +#define ATOM(a) XInternAtom(display, #a, False) LinuxWindow::LinuxWindow(QVector activeScreensList, QString projectPath, QString id, QString volume, const QString fillmode,const bool checkWallpaperVisible, QObject* parent) : BaseWindow(projectPath,activeScreensList,checkWallpaperVisible) { + m_window.setWidth(1920); + m_window.setHeight(1080); + + + + /*********/ + m_window.show(); + //m_window.hide(); + setAppID(id); + bool ok = false; float volumeParsed = volume.toFloat(&ok); if (!ok) { qFatal("Could not parse volume"); } + + setVolume(volumeParsed); + setFillMode(fillmode); + + // WARNING: Setting Window flags must be called *here*! + //SetWindowLongPtr(m_windowHandle, GWL_EXSTYLE, WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT); + //SetWindowLongPtr(m_windowHandle, GWL_STYLE, WS_POPUPWINDOW); + + //Calculate window coordinates + calcOffsets(); + + // Ether for one Screen or for all + if ((QApplication::screens().length() == activeScreensList.length()) && (activeScreensList.length() != 1)) { + setupWallpaperForAllScreens(); + } else if (activeScreensList.length() == 1) { + setupWallpaperForOneScreen(activeScreensList.at(0)); + setCanFade(true); + } else if (activeScreensList.length() > 1) { + setupWallpaperForMultipleScreens(activeScreensList); + } + + setWidth(m_window.width()); + setHeight(m_window.height()); + + m_window.setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView); + m_window.rootContext()->setContextProperty("window", this); + //m_window.rootContext()->setContextProperty("desktopProperties", &m_windowsDesktopProperties); + // Instead of setting "renderType: Text.NativeRendering" every time + // we can set it here once :) + + m_window.setTextRenderType(QQuickWindow::TextRenderType::NativeTextRendering); + m_window.setSource(QUrl("qrc:/mainWindow.qml")); + + Window window = m_window.winId(); + + Display *display = XOpenDisplay(""); + + XSetWindowAttributes attrs = { ParentRelative, 0L, 0, 0L, 0, 0, + Always, 0L, 0L, False, StructureNotifyMask | ExposureMask | + ButtonPressMask | ButtonReleaseMask, 0L, False, 0, 0 + }; + + + + XWMHints wmHint; + Atom xa; + + int flags; + + //attrs.colormap = window.colourmap; + flags |= CWBorderPixel | CWColormap; + + XChangeWindowAttributes(display,window,flags,&attrs); + /*window.window = XCreateWindow(display, window.root, window.x, + window.y, window.width, window.height, 0, depth, InputOutput, visual, + flags, &attrs);*/ + + wmHint.flags = InputHint | StateHint; + // wmHint.input = undecorated ? False : True; + wmHint.input = true; + wmHint.initial_state = WithdrawnState; + + XSetWMProperties(display, window, NULL, NULL, NULL, + 0, NULL, &wmHint, NULL); + + xa = ATOM(_NET_WM_WINDOW_TYPE); + + Atom prop; + + //prop = ATOM(_NET_WM_WINDOW_TYPE_DESKTOP); + + + // XChangeProperty(display, window, xa, XA_ATOM, 32, + // PropModeReplace, (unsigned char *) &prop, 1); + + //if (undecorated) { + xa = ATOM(_MOTIF_WM_HINTS); + if (xa != None) { + long prop[5] = { 2, 0, 0, 0, 0 }; + XChangeProperty(display, window, xa, xa, 32, + PropModeReplace, (unsigned char *) prop, 5); + } + //} + + /* Below other windows */ + //if (below) { + + /*xa = ATOM(_WIN_LAYER); + if (xa != None) { + long prop = 0; + + XChangeProperty(display, window, xa, XA_CARDINAL, 32, + PropModeAppend, (unsigned char *) &prop, 1); + }*/ + + xa = ATOM(_NET_WM_STATE); + if (xa != None) { + Atom xa_prop = ATOM(_NET_WM_STATE_BELOW); + + XChangeProperty(display, window, xa, XA_ATOM, 32, + PropModeAppend, (unsigned char *) &xa_prop, 1); + } + //} + + + /* Sticky */ + //if (sticky) { + + xa = ATOM(_NET_WM_DESKTOP); + if (xa != None) { + CARD32 xa_prop = 0xFFFFFFFF; + + XChangeProperty(display, window, xa, XA_CARDINAL, 32, + PropModeAppend, (unsigned char *) &xa_prop, 1); + } + + xa = ATOM(_NET_WM_STATE); + if (xa != None) { + Atom xa_prop = ATOM(_NET_WM_STATE_STICKY); + + XChangeProperty(display, window, xa, XA_ATOM, 32, + PropModeAppend, (unsigned char *) &xa_prop, 1); + } + //} + + /* Skip taskbar */ + //if (skip_taskbar) { + + xa = ATOM(_NET_WM_STATE); + if (xa != None) { + Atom xa_prop = ATOM(_NET_WM_STATE_SKIP_TASKBAR); + + XChangeProperty(display, window, xa, XA_ATOM, 32, + PropModeAppend, (unsigned char *) &xa_prop, 1); + } + //} + + /* Skip pager */ + //if (skip_pager) { + + xa = ATOM(_NET_WM_STATE); + if (xa != None) { + Atom xa_prop = ATOM(_NET_WM_STATE_SKIP_PAGER); + + XChangeProperty(display, window, xa, XA_ATOM, 32, + PropModeAppend, (unsigned char *) &xa_prop, 1); + } + //} + + + //if (opacity != OPAQUE) + // setWindowOpacity (opacity); + + /* if (noInput) + { + Region region; + + region = XCreateRegion (); + if (region) + { + XShapeCombineRegion (display, window.window, ShapeInput, 0, 0, region, ShapeSet); + XDestroyRegion (region); + } + }*/ + + + + XMapWindow(display, window); + + XSync (display, window); + + + /*while (1) + { + XEvent event; + + XNextEvent(display, &event); + } + + XUnmapWindow(display, win); + XCloseDisplay(display);*/ + + + + //m_window.hide(); + + /*QObject::connect(&m_checkForFullScreenWindowTimer, &QTimer::timeout, this, &WinWindow::checkForFullScreenWindow); + + if (checkWallpaperVisible) { + m_checkForFullScreenWindowTimer.start(10); + } + + QTimer::singleShot(1000, [this]() { + setupWindowMouseHook(); + });*/ + + + + /*********/ + + + /*bool ok = false; + float volumeParsed = volume.toFloat(&ok); + if (!ok) { + qFatal("Could not parse volume"); + } setVolume(volumeParsed); // WARNING: Setting Window flags must be called *here*! @@ -20,9 +263,30 @@ LinuxWindow::LinuxWindow(QVector activeScreensList, QString projectPath, QS // Instead of setting "renderType: Text.NativeRendering" every time // we can set it here once :) m_window.setTextRenderType(QQuickWindow::TextRenderType::NativeTextRendering); - m_window.setSource(QUrl("qrc:/mainWindow.qml")); + m_window.setSource(QUrl("qrc:/mainWindow.qml"));*/ } +void LinuxWindow::setupWallpaperForOneScreen(int activeScreen) +{ + +} + +void LinuxWindow::setupWallpaperForAllScreens() +{ + +} + +void LinuxWindow::setupWallpaperForMultipleScreens(const QVector& activeScreensList) +{ + +} + +void LinuxWindow::calcOffsets() +{ + +} + + void LinuxWindow::setVisible(bool show) { m_window.setVisible(show); diff --git a/ScreenPlayWallpaper/src/linuxwindow.h b/ScreenPlayWallpaper/src/linuxwindow.h index f808df07..f03da3c2 100644 --- a/ScreenPlayWallpaper/src/linuxwindow.h +++ b/ScreenPlayWallpaper/src/linuxwindow.h @@ -26,5 +26,9 @@ public slots: void destroyThis() override; private: QQuickView m_window; + void calcOffsets(); + void setupWallpaperForOneScreen(int activeScreen); + void setupWallpaperForAllScreens(); + void setupWallpaperForMultipleScreens(const QVector& activeScreensList); };