Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 116 additions & 35 deletions mods/taskbar-music-lounge.wh.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// ==WindhawkMod==
// @id taskbar-music-lounge
// @name Taskbar Music Lounge
// @id taskbar-music-lounge-fork

Check warning on line 2 in mods/taskbar-music-lounge.wh.cpp

View workflow job for this annotation

GitHub Actions / Test changed files

Expected @‌id (taskbar-music-lounge-fork) to match the file name (taskbar-music-lounge)

Check warning on line 2 in mods/taskbar-music-lounge.wh.cpp

View workflow job for this annotation

GitHub Actions / Test changed files

Expected @‌id (taskbar-music-lounge-fork) to match the file name (taskbar-music-lounge)
// @name Taskbar Music Lounge - Fork
// @description A native-style music ticker with media controls.
// @version 4.0.2
// @author Hashah2311
// @github https://github.com/Hashah2311

Check warning on line 7 in mods/taskbar-music-lounge.wh.cpp

View workflow job for this annotation

GitHub Actions / Test changed files

Expected @‌github (https://github.com/Hashah2311) to match the pull request author (https://github.com/tiago-coderia). Note that only the original author of the mod is allowed to submit updates. If you are not the original author, you might want to contact them to submit the update instead. For more information about submitting a mod update, refer to the "Submitting a Mod Update" section in the repository's README.md.

Check warning on line 7 in mods/taskbar-music-lounge.wh.cpp

View workflow job for this annotation

GitHub Actions / Test changed files

Expected @‌github (https://github.com/Hashah2311) to match the pull request author (https://github.com/tiago-coderia). Note that only the original author of the mod is allowed to submit updates. If you are not the original author, you might want to contact them to submit the update instead. For more information about submitting a mod update, refer to the "Submitting a Mod Update" section in the repository's README.md.
// @include explorer.exe
// @compilerOptions -lole32 -ldwmapi -lgdi32 -luser32 -lwindowsapp -lshcore -lgdiplus -lshell32
// ==/WindhawkMod==
Expand Down Expand Up @@ -255,55 +255,117 @@
if (!g_SessionManager) {
g_SessionManager = GlobalSystemMediaTransportControlsSessionManager::RequestAsync().get();
}
if (!g_SessionManager) return;

// Iterate ALL sessions to find one that is actively PLAYING.
GlobalSystemMediaTransportControlsSession session = nullptr;
bool foundActive = false;
if (!g_SessionManager)
return;

GlobalSystemMediaTransportControlsSession session = nullptr;
auto sessionsList = g_SessionManager.GetSessions();

// ======================================================
// PRIORIDADE 1: SPOTIFY
// ======================================================
for (auto const& s : sessionsList) {
auto source = s.SourceAppUserModelId();
auto pb = s.GetPlaybackInfo();
if (pb && pb.PlaybackStatus() == GlobalSystemMediaTransportControlsSessionPlaybackStatus::Playing) {
session = s;
foundActive = true;
break;

if (pb &&
pb.PlaybackStatus() ==
GlobalSystemMediaTransportControlsSessionPlaybackStatus::Playing)
{
std::wstring sourceStr = source.c_str();

if (sourceStr.find(L"Spotify") != std::wstring::npos ||
sourceStr.find(L"spotify") != std::wstring::npos)
{
session = s;
break;
}
}
}

if (!foundActive) {
// ======================================================
// PRIORIDADE 2: QUALQUER MÍDIA TOCANDO
// ======================================================
if (!session) {
for (auto const& s : sessionsList) {
auto pb = s.GetPlaybackInfo();

if (pb &&
pb.PlaybackStatus() ==
GlobalSystemMediaTransportControlsSessionPlaybackStatus::Playing)
{
session = s;
break;
}
}
}

// ======================================================
// PRIORIDADE 3: CURRENT SESSION
// ======================================================
if (!session) {
session = g_SessionManager.GetCurrentSession();
}

// ======================================================
// ATUALIZA DADOS
// ======================================================
if (session) {
auto props = session.TryGetMediaPropertiesAsync().get();
auto info = session.GetPlaybackInfo();

lock_guard<mutex> guard(g_MediaState.lock);

wstring newTitle = props.Title().c_str();
if (newTitle != g_MediaState.title || g_MediaState.albumArt == nullptr) {
if (g_MediaState.albumArt) { delete g_MediaState.albumArt; g_MediaState.albumArt = nullptr; }

if (newTitle != g_MediaState.title || g_MediaState.albumArt == nullptr)
{
if (g_MediaState.albumArt) {
delete g_MediaState.albumArt;
g_MediaState.albumArt = nullptr;
}

auto thumbRef = props.Thumbnail();

if (thumbRef) {
auto stream = thumbRef.OpenReadAsync().get();
g_MediaState.albumArt = StreamToBitmap(stream);
}
}

g_MediaState.title = newTitle;
g_MediaState.artist = props.Artist().c_str();
g_MediaState.isPlaying = (info.PlaybackStatus() == GlobalSystemMediaTransportControlsSessionPlaybackStatus::Playing);
g_MediaState.isPlaying =
(info.PlaybackStatus() ==
GlobalSystemMediaTransportControlsSessionPlaybackStatus::Playing);

g_MediaState.hasMedia = true;
} else {
}
else {
lock_guard<mutex> guard(g_MediaState.lock);

g_MediaState.hasMedia = false;
g_MediaState.title = L"No Media";
g_MediaState.artist = L"";
if (g_MediaState.albumArt) { delete g_MediaState.albumArt; g_MediaState.albumArt = nullptr; }

if (g_MediaState.albumArt) {
delete g_MediaState.albumArt;
g_MediaState.albumArt = nullptr;
}
}
} catch (...) {
}
catch (...) {
lock_guard<mutex> guard(g_MediaState.lock);

g_MediaState.hasMedia = false;
g_MediaState.title = L"No Media";
g_MediaState.artist = L"";

if (g_MediaState.albumArt) {
delete g_MediaState.albumArt;
g_MediaState.albumArt = nullptr;
}
}
}

Expand Down Expand Up @@ -477,6 +539,31 @@
}
}

bool IsFullscreenAppRunning()
{
HWND fg = GetForegroundWindow();
if (!fg)
return false;

RECT rcWindow;
GetWindowRect(fg, &rcWindow);

HMONITOR hMon = MonitorFromWindow(fg, MONITOR_DEFAULTTOPRIMARY);

MONITORINFO mi{};
mi.cbSize = sizeof(mi);

if (!GetMonitorInfo(hMon, &mi))
return false;

RECT rcMonitor = mi.rcMonitor;

return rcWindow.left <= rcMonitor.left &&
rcWindow.top <= rcMonitor.top &&
rcWindow.right >= rcMonitor.right &&
rcWindow.bottom >= rcMonitor.bottom;
}

// --- Event Hook ---
bool IsTaskbarWindow(HWND hwnd) {
WCHAR cls[64];
Expand Down Expand Up @@ -561,15 +648,11 @@
bool shouldHide = false;

// 1. Check Fullscreen
if (g_Settings.hideFullscreen) {
QUERY_USER_NOTIFICATION_STATE state;
if (SUCCEEDED(SHQueryUserNotificationState(&state))) {
if (state == QUNS_BUSY || state == QUNS_RUNNING_D3D_FULL_SCREEN || state == QUNS_PRESENTATION_MODE) {
shouldHide = true;
}
}
if (g_Settings.hideFullscreen)
{
shouldHide = IsFullscreenAppRunning();
}

// 2. Check Idle Timeout
bool isPlaying = false;
{
Expand Down Expand Up @@ -639,11 +722,9 @@
if (!g_IsHiddenByIdle && !IsWindowVisible(hwnd)) {
// Double check fullscreen mode isn't forcing hide
bool gameModeHide = false;
if (g_Settings.hideFullscreen) {
QUERY_USER_NOTIFICATION_STATE state;
if (SUCCEEDED(SHQueryUserNotificationState(&state))) {
if (state == QUNS_BUSY || state == QUNS_RUNNING_D3D_FULL_SCREEN || state == QUNS_PRESENTATION_MODE) gameModeHide = true;
}
if (g_Settings.hideFullscreen)
{
gameModeHide = IsFullscreenAppRunning();
}
if (!gameModeHide) ShowWindow(hwnd, SW_SHOWNOACTIVATE);
}
Expand All @@ -662,7 +743,7 @@
(myRc.bottom - myRc.top) != g_Settings.height) {
SetWindowPos(
hwnd,
HWND_TOPMOST,
HWND_NOTOPMOST,
x, y,
g_Settings.width,
g_Settings.height,
Expand Down Expand Up @@ -770,12 +851,12 @@

if (CreateWindowInBand) {
g_hMediaWindow = CreateWindowInBand(
WS_EX_LAYERED | WS_EX_TOOLWINDOW | WS_EX_TOPMOST,
WS_EX_LAYERED | WS_EX_TOOLWINDOW,
wc.lpszClassName, TEXT("MusicLounge"),
WS_POPUP | WS_VISIBLE,
0, 0, g_Settings.width, g_Settings.height,
NULL, NULL, wc.hInstance, NULL,
ZBID_IMMERSIVE_NOTIFICATION
ZBID_DESKTOP
);
if (g_hMediaWindow) {
Wh_Log(L"Created window in ZBID_IMMERSIVE_NOTIFICATION band");
Expand All @@ -785,7 +866,7 @@
if (!g_hMediaWindow) {
Wh_Log(L"Falling back to CreateWindowEx");
g_hMediaWindow = CreateWindowEx(
WS_EX_LAYERED | WS_EX_TOOLWINDOW | WS_EX_TOPMOST,
WS_EX_LAYERED | WS_EX_TOOLWINDOW,
wc.lpszClassName, TEXT("MusicLounge"),
WS_POPUP | WS_VISIBLE,
0, 0, g_Settings.width, g_Settings.height,
Expand Down
Loading