mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-09-15 06:52:34 +02:00
Add activeScreensList to base Window
Add check for multiple monitors for pausing wallpaper if an app is maximized on the same screen
This commit is contained in:
parent
d0baf10cc0
commit
4ebd0af183
@ -5,8 +5,9 @@ BaseWindow::BaseWindow(QObject* parent)
|
||||
{
|
||||
}
|
||||
|
||||
BaseWindow::BaseWindow(QString projectFilePath, QObject* parent)
|
||||
: QObject(parent)
|
||||
BaseWindow::BaseWindow(QString projectFilePath, QVector<int> activeScreensList)
|
||||
: QObject(nullptr)
|
||||
, m_activeScreensList(activeScreensList)
|
||||
{
|
||||
QApplication::instance()->installEventFilter(this);
|
||||
qRegisterMetaType<BaseWindow::WallpaperType>();
|
||||
@ -24,7 +25,7 @@ BaseWindow::BaseWindow(QString projectFilePath, QObject* parent)
|
||||
QJsonDocument configJsonDocument;
|
||||
QJsonParseError parseError;
|
||||
|
||||
if(projectFilePath.contains("file:\\\\\\"))
|
||||
if (projectFilePath.contains("file:\\\\\\"))
|
||||
projectFilePath = projectFilePath.remove("file:\\\\\\");
|
||||
|
||||
projectFile.setFileName(projectFilePath + "/project.json");
|
||||
|
@ -16,10 +16,11 @@ class BaseWindow : public QObject {
|
||||
|
||||
public:
|
||||
BaseWindow(QObject* parent = nullptr);
|
||||
BaseWindow(QString projectFilePath, QObject* parent = nullptr);
|
||||
BaseWindow(QString projectFilePath, QVector<int> activeScreensList);
|
||||
|
||||
Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged)
|
||||
Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged)
|
||||
Q_PROPERTY(QVector<int> activeScreensList READ activeScreensList WRITE setActiveScreensList NOTIFY activeScreensListChanged)
|
||||
|
||||
Q_PROPERTY(QString appID READ appID WRITE setAppID NOTIFY appIDChanged)
|
||||
Q_PROPERTY(QString fullContentPath READ fullContentPath WRITE setFullContentPath NOTIFY fullContentPathChanged)
|
||||
@ -117,6 +118,11 @@ public:
|
||||
return m_height;
|
||||
}
|
||||
|
||||
QVector<int> activeScreensList() const
|
||||
{
|
||||
return m_activeScreensList;
|
||||
}
|
||||
|
||||
signals:
|
||||
void qmlExit();
|
||||
|
||||
@ -135,6 +141,7 @@ signals:
|
||||
void fillModeChanged(QString fillMode);
|
||||
void widthChanged(int width);
|
||||
void heightChanged(int height);
|
||||
void activeScreensListChanged(QVector<int> activeScreensList);
|
||||
|
||||
public slots:
|
||||
virtual void destroyThis() {}
|
||||
@ -291,6 +298,15 @@ public slots:
|
||||
emit heightChanged(m_height);
|
||||
}
|
||||
|
||||
void setActiveScreensList(QVector<int> activeScreensList)
|
||||
{
|
||||
if (m_activeScreensList == activeScreensList)
|
||||
return;
|
||||
|
||||
m_activeScreensList = activeScreensList;
|
||||
emit activeScreensListChanged(m_activeScreensList);
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_loops { true };
|
||||
bool m_isPlaying { true };
|
||||
@ -309,4 +325,5 @@ private:
|
||||
QString m_fillMode;
|
||||
int m_width { 0 };
|
||||
int m_height { 0 };
|
||||
QVector<int> m_activeScreensList;
|
||||
};
|
||||
|
@ -66,7 +66,7 @@ WinWindow::WinWindow(
|
||||
QString id,
|
||||
QString volume,
|
||||
const QString fillmode)
|
||||
: BaseWindow(projectPath)
|
||||
: BaseWindow(projectPath, activeScreensList)
|
||||
{
|
||||
m_window.hide();
|
||||
m_windowHandle = reinterpret_cast<HWND>(m_window.winId());
|
||||
@ -238,9 +238,10 @@ bool WinWindow::searchWorkerWindowToParentTo()
|
||||
return EnumWindows(SearchForWorkerWindow, reinterpret_cast<LPARAM>(&m_windowHandleWorker));
|
||||
}
|
||||
|
||||
QString printWindowNameByhWnd(HWND hWnd){
|
||||
QString printWindowNameByhWnd(HWND hWnd)
|
||||
{
|
||||
std::wstring title(GetWindowTextLength(hWnd) + 1, L'\0');
|
||||
GetWindowTextW(hWnd,&title[0], title.size());
|
||||
GetWindowTextW(hWnd, &title[0], title.size());
|
||||
return QString::fromStdWString(title);
|
||||
}
|
||||
|
||||
@ -249,31 +250,81 @@ BOOL CALLBACK FindTheDesiredWnd(HWND hWnd, LPARAM lParam)
|
||||
DWORD dwStyle = (DWORD)GetWindowLong(hWnd, GWL_STYLE);
|
||||
if ((dwStyle & WS_MAXIMIZE) != 0) {
|
||||
*(reinterpret_cast<HWND*>(lParam)) = hWnd;
|
||||
// qDebug() << "Window found " << printWindowNameByhWnd(hWnd);
|
||||
return false; // stop enumerating
|
||||
}
|
||||
return true; // keep enumerating
|
||||
}
|
||||
|
||||
struct sEnumInfo {
|
||||
int iIndex = 0;
|
||||
HMONITOR hMonitor = NULL;
|
||||
};
|
||||
|
||||
BOOL CALLBACK GetMonitorByHandle(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
|
||||
{
|
||||
auto info = (sEnumInfo*)dwData;
|
||||
if (info->hMonitor == hMonitor)
|
||||
return FALSE;
|
||||
++info->iIndex;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int GetMonitorIndex(HMONITOR hMonitor)
|
||||
{
|
||||
sEnumInfo info;
|
||||
info.hMonitor = hMonitor;
|
||||
|
||||
if (EnumDisplayMonitors(NULL, NULL, GetMonitorByHandle, (LPARAM)&info))
|
||||
return -1;
|
||||
|
||||
return info.iIndex;
|
||||
}
|
||||
|
||||
void WinWindow::checkForFullScreenWindow()
|
||||
{
|
||||
auto hWnd = GetForegroundWindow();
|
||||
DWORD dwStyle = (DWORD)GetWindowLong(hWnd, GWL_STYLE);
|
||||
DWORD dwExStyle = (DWORD)GetWindowLong(hWnd, GWL_EXSTYLE);
|
||||
// If one screen:
|
||||
{
|
||||
auto hWnd = GetForegroundWindow();
|
||||
DWORD dwStyle = (DWORD)GetWindowLong(hWnd, GWL_STYLE);
|
||||
|
||||
if ((dwStyle & WS_MAXIMIZE) != 0) {
|
||||
// do stuff
|
||||
setIsPlaying(false);
|
||||
// qDebug() << "WS_MAXIMIZE: " << printWindowNameByhWnd(hWnd);
|
||||
} else {
|
||||
int screensCount = QGuiApplication::screens().length();
|
||||
if (screensCount == 1) {
|
||||
|
||||
if ((dwStyle & WS_MAXIMIZE) != 0) {
|
||||
// do stuff
|
||||
setIsPlaying(false);
|
||||
qDebug() << "WS_MAXIMIZE: " << printWindowNameByhWnd(hWnd);
|
||||
} else {
|
||||
setIsPlaying(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If multiple screens:
|
||||
{
|
||||
HWND hFoundWnd = nullptr;
|
||||
EnumWindows(&FindTheDesiredWnd, reinterpret_cast<LPARAM>(&hFoundWnd));
|
||||
// True if one window has WS_MAXIMIZE
|
||||
if (hFoundWnd != nullptr) {
|
||||
setIsPlaying(false);
|
||||
DWORD dwFlags = 0;
|
||||
HMONITOR monitor = MonitorFromWindow(hFoundWnd, dwFlags);
|
||||
int monitorIndex = GetMonitorIndex(monitor);
|
||||
// qDebug() << "Window found " << printWindowNameByhWnd(hFoundWnd) << monitorIndex << activeScreensList().at(0);
|
||||
|
||||
// We do not support autopause for multi monitor wallpaper
|
||||
if (activeScreensList().length() == 1) {
|
||||
// If the window that has WS_MAXIMIZE is at the same monitor as this wallpaper
|
||||
if (monitorIndex == activeScreensList().at(0)) {
|
||||
qDebug() << "monitorIndex" << monitorIndex;
|
||||
setIsPlaying(false);
|
||||
} else {
|
||||
setIsPlaying(true);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// qDebug() << "No window found, playing!";
|
||||
setIsPlaying(true);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user