Fix Windows tray show handling
This commit is contained in:
@@ -48,8 +48,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QCursor>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
#include <QGuiApplication>
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
|
#include <QScreen>
|
||||||
|
|
||||||
using namespace Qt::Literals::StringLiterals;
|
using namespace Qt::Literals::StringLiterals;
|
||||||
using namespace OCC;
|
using namespace OCC;
|
||||||
@@ -97,6 +100,32 @@ void setUpInitialSyncFolder(AccountStatePtr accountStatePtr, bool useVfs)
|
|||||||
Qt::SingleShotConnection);
|
Qt::SingleShotConnection);
|
||||||
accountStatePtr->account()->spacesManager()->checkReady();
|
accountStatePtr->account()->spacesManager()->checkReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ensureWindowIntersectsAvailableScreen(QWidget *window)
|
||||||
|
{
|
||||||
|
if (!window) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto frame = window->frameGeometry();
|
||||||
|
for (const auto *screen : QGuiApplication::screens()) {
|
||||||
|
if (screen->availableGeometry().intersects(frame)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto *screen = QGuiApplication::screenAt(QCursor::pos());
|
||||||
|
if (!screen) {
|
||||||
|
screen = QGuiApplication::primaryScreen();
|
||||||
|
}
|
||||||
|
if (!screen) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto availableGeometry = screen->availableGeometry();
|
||||||
|
window->resize(window->size().boundedTo(availableGeometry.size()));
|
||||||
|
window->move(availableGeometry.center() - window->rect().center());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Application::displayLanguage() const
|
QString Application::displayLanguage() const
|
||||||
@@ -244,23 +273,33 @@ AccountStatePtr Application::addNewAccount(AccountPtr newAccount)
|
|||||||
void Application::showSettings()
|
void Application::showSettings()
|
||||||
{
|
{
|
||||||
auto window = ocApp()->settingsDialog();
|
auto window = ocApp()->settingsDialog();
|
||||||
|
ensureWindowIntersectsAvailableScreen(window);
|
||||||
|
|
||||||
|
if (window->windowState().testFlag(Qt::WindowMinimized)) {
|
||||||
|
window->setWindowState(window->windowState() & ~Qt::WindowMinimized);
|
||||||
|
}
|
||||||
|
|
||||||
window->show();
|
window->show();
|
||||||
|
ensureWindowIntersectsAvailableScreen(window);
|
||||||
window->raise();
|
window->raise();
|
||||||
window->activateWindow();
|
window->activateWindow();
|
||||||
|
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
// Windows disallows raising a Window when you're not the active application.
|
// Windows disallows raising a Window when you're not the active application.
|
||||||
// Use a common hack to attach to the active application
|
// Use a common hack to attach to the active application.
|
||||||
const auto activeProcessId = GetWindowThreadProcessId(GetForegroundWindow(), nullptr);
|
const auto foregroundWindow = GetForegroundWindow();
|
||||||
if (activeProcessId != qApp->applicationPid()) {
|
const auto foregroundThreadId = foregroundWindow ? GetWindowThreadProcessId(foregroundWindow, nullptr) : 0;
|
||||||
const auto threadId = GetCurrentThreadId();
|
const auto currentThreadId = GetCurrentThreadId();
|
||||||
// don't step here with a debugger...
|
const auto attachedToForegroundThread =
|
||||||
if (AttachThreadInput(threadId, activeProcessId, true)) {
|
foregroundThreadId != 0 && foregroundThreadId != currentThreadId && AttachThreadInput(currentThreadId, foregroundThreadId, true);
|
||||||
const auto hwnd = reinterpret_cast<HWND>(window->winId());
|
|
||||||
SetForegroundWindow(hwnd);
|
const auto hwnd = reinterpret_cast<HWND>(window->winId());
|
||||||
SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
|
ShowWindow(hwnd, SW_RESTORE);
|
||||||
AttachThreadInput(threadId, activeProcessId, false);
|
SetForegroundWindow(hwnd);
|
||||||
}
|
SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
|
||||||
|
|
||||||
|
if (attachedToForegroundThread) {
|
||||||
|
AttachThreadInput(currentThreadId, foregroundThreadId, false);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#include "csync.h"
|
#include "csync.h"
|
||||||
#include "syncfileitem.h"
|
#include "syncfileitem.h"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
@@ -74,7 +75,9 @@ time_t FileSystem::fileTimeToTime_t(std::filesystem::file_time_type fileTime)
|
|||||||
#ifdef HAS_CLOCK_CAST
|
#ifdef HAS_CLOCK_CAST
|
||||||
return std::chrono::system_clock::to_time_t(std::chrono::clock_cast<std::chrono::system_clock>(fileTime));
|
return std::chrono::system_clock::to_time_t(std::chrono::clock_cast<std::chrono::system_clock>(fileTime));
|
||||||
#else
|
#else
|
||||||
const auto systemTime = std::chrono::time_point_cast<std::chrono::system_clock::duration>(std::chrono::file_clock::to_sys(fileTime));
|
const auto fileNow = std::filesystem::file_time_type::clock::now();
|
||||||
|
const auto systemNow = std::chrono::system_clock::now();
|
||||||
|
const auto systemTime = std::chrono::time_point_cast<std::chrono::system_clock::duration>(systemNow + (fileTime - fileNow));
|
||||||
return std::chrono::system_clock::to_time_t(systemTime);
|
return std::chrono::system_clock::to_time_t(systemTime);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -83,7 +86,10 @@ std::filesystem::file_time_type FileSystem::time_tToFileTime(time_t fileTime)
|
|||||||
#ifdef HAS_CLOCK_CAST
|
#ifdef HAS_CLOCK_CAST
|
||||||
return std::chrono::clock_cast<std::chrono::file_clock>(std::chrono::system_clock::from_time_t(fileTime));
|
return std::chrono::clock_cast<std::chrono::file_clock>(std::chrono::system_clock::from_time_t(fileTime));
|
||||||
#else
|
#else
|
||||||
return std::chrono::file_clock::from_sys(std::chrono::system_clock::from_time_t(fileTime));
|
const auto fileNow = std::filesystem::file_time_type::clock::now();
|
||||||
|
const auto systemNow = std::chrono::system_clock::now();
|
||||||
|
return std::chrono::time_point_cast<std::filesystem::file_time_type::duration>(
|
||||||
|
fileNow + (std::chrono::system_clock::from_time_t(fileTime) - systemNow));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user