-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement cross-platform hacks for window flags manipulation
partially reverts 7442199
- Loading branch information
Showing
10 changed files
with
161 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Nick Korotysh <[email protected]> | ||
* | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <QtGlobal> | ||
|
||
#if defined(Q_OS_WINDOWS) | ||
#define HAVE_NATIVE_WIN_IMPL | ||
#include "win/clock_native_window.hpp" | ||
#endif | ||
|
||
#if defined(Q_OS_MACOS) | ||
#define HAVE_NATIVE_WIN_IMPL | ||
#include "mac/clock_native_window.hpp" | ||
#endif | ||
|
||
#if !defined(HAVE_NATIVE_WIN_IMPL) | ||
#include "gui/clock_window.hpp" | ||
using ClockNativeWindow = ClockWindow; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Nick Korotysh <[email protected]> | ||
* | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "gui/clock_window.hpp" | ||
|
||
class ClockNativeWindow : public ClockWindow | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit ClockNativeWindow(QWidget* parent = nullptr); | ||
|
||
public slots: | ||
void setStayOnTop(bool en) override; | ||
|
||
void setHiddenInMissionControl(bool en); | ||
void setVisibleOnAllDesktops(bool en); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2017-2024 Nick Korotysh <[email protected]> | ||
* SPDX-FileCopyrightText: 2024 Nick Korotysh <[email protected]> | ||
* | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
#include "gui/clock_window.hpp" | ||
#include "clock_native_window.hpp" | ||
|
||
#ifndef NOMINMAX | ||
#define NOMINMAX | ||
|
@@ -38,24 +38,49 @@ static void SetSurviveWinDHackEnabled(WId winId, bool en) | |
SetWindowLongPtr((HWND)winId, GWLP_HWNDPARENT, (LONG_PTR)0); | ||
} | ||
|
||
void ClockWindow::runStayOnTopHacks() | ||
|
||
ClockNativeWindow::ClockNativeWindow(QWidget* parent) | ||
: ClockWindow(parent) | ||
{ | ||
if (!_should_stay_on_top) return; | ||
} | ||
|
||
void ClockNativeWindow::setStayOnTop(bool en) | ||
{ | ||
ClockWindow::setStayOnTop(en); | ||
|
||
SetSurviveWinDHackEnabled(winId(), !en); | ||
runStayOnTopHacks(); | ||
} | ||
|
||
void ClockNativeWindow::runStayOnTopHacks() | ||
{ | ||
// calling winId() for invisible window causes move event from (0,0) to (289,160) | ||
// during startup (doesn't matter what saved coordinates were, each time the same), | ||
// as result real saved position will be overwritten even before it will be read | ||
// so do nothing if window is not visible | ||
if (!isVisible()) return; | ||
|
||
// unfortunately, fullscreen invisible (transparent) windows may exist... we should ignore them | ||
// remember all fullscreen windows on app startup or window's screen change and ignore them later | ||
if (_last_screen != screen()) { | ||
_last_screen = screen(); | ||
_fullscreen_ignore_list = dc::GetFullscreenWindowsOnSameMonitor(winId()); | ||
} | ||
_last_screen = screen(); | ||
_fullscreen_ignore_list = dc::GetFullscreenWindowsOnSameMonitor(winId()); | ||
} | ||
|
||
if (!_should_stay_on_top) return; | ||
|
||
if (_detect_fullscreen && dc::IsFullscreenWndOnSameMonitor(winId(), _fullscreen_ignore_list)) { | ||
// don't stay above fullscreen windows | ||
if ((GetWindowLongPtr((HWND)winId(), GWL_EXSTYLE) & WS_EX_TOPMOST) != 0) { | ||
SetWindowPos((HWND)winId(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); | ||
if (windowFlags() & Qt::WindowStaysOnTopHint) { | ||
setStayOnTop(false); | ||
lower(); | ||
} | ||
} else { | ||
// always on top problem workaround | ||
// sometimes Qt somehow loses Qt::WindowStaysOnTopHint window flag, so set it again | ||
if (!(windowFlags() & Qt::WindowStaysOnTopHint)) { | ||
setStayOnTop(true); | ||
} | ||
// sometimes even window have Qt::WindowStaysOnTopHint window flag, it doesn't have WS_EX_TOPMOST flag, | ||
// so set it manually using WinAPI... | ||
if ((GetWindowLongPtr((HWND)winId(), GWL_EXSTYLE) & WS_EX_TOPMOST) == 0) { | ||
|
@@ -66,22 +91,3 @@ void ClockWindow::runStayOnTopHacks() | |
if (!isActiveWindow()) raise(); | ||
} | ||
} | ||
|
||
void ClockWindow::setStayOnTop(bool en) | ||
{ | ||
_should_stay_on_top = en; | ||
HWND pos = en ? HWND_TOPMOST : HWND_NOTOPMOST; | ||
SetWindowPos((HWND)winId(), pos, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); | ||
SetSurviveWinDHackEnabled(winId(), !en); | ||
runStayOnTopHacks(); | ||
} | ||
|
||
void ClockWindow::setTransparentForInput(bool en) | ||
{ | ||
LONG_PTR st = GetWindowLongPtr((HWND)winId(), GWL_EXSTYLE); | ||
if (en) | ||
st |= WS_EX_TRANSPARENT; | ||
else | ||
st &= ~WS_EX_TRANSPARENT; | ||
SetWindowLongPtr((HWND)winId(), GWL_EXSTYLE, (LONG_PTR)st); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Nick Korotysh <[email protected]> | ||
* | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "gui/clock_window.hpp" | ||
|
||
class ClockNativeWindow : public ClockWindow | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit ClockNativeWindow(QWidget* parent = nullptr); | ||
|
||
public slots: | ||
void setStayOnTop(bool en) override; | ||
|
||
void runStayOnTopHacks(); | ||
}; |