From 4f47ba2541f12cb3b9f50a8d37d805f50b954542 Mon Sep 17 00:00:00 2001 From: Superxwolf Date: Sun, 7 Jun 2015 05:02:36 -0400 Subject: [PATCH] Automatic discovery of new wallpaper Added registry watch to actively check for wallpaper change. Automatically updates wallpaper without needing a litestep recycle. --- nDesk/DesktopPainter.cpp | 26 ++++++++++++++++++++++++++ nDesk/DesktopPainter.hpp | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/nDesk/DesktopPainter.cpp b/nDesk/DesktopPainter.cpp index a198557..3e1382a 100644 --- a/nDesk/DesktopPainter.cpp +++ b/nDesk/DesktopPainter.cpp @@ -65,6 +65,11 @@ DesktopPainter::DesktopPainter(HWND hWnd) : Window(hWnd, L"nDesk", g_pClickHandl nCore::System::RegisterWindow(L"nDesk", this); UpdateWallpaper(true); + + //Create the notification for wallpaper change + hWallpaperEvent = CreateEvent(NULL, false, false, NULL); + RegOpenKeyEx(HKEY_CURRENT_USER, L"Control Panel\\Desktop", 0, KEY_NOTIFY, &hWallpaperKey); + RegNotifyChangeKeyValue(hWallpaperKey, FALSE, REG_NOTIFY_CHANGE_LAST_SET, hWallpaperEvent, TRUE); } /// @@ -78,6 +83,12 @@ DesktopPainter::~DesktopPainter() { if (m_TransitionEffect) { delete m_TransitionEffect; } + + //Close the wallpaper event + CloseHandle(hWallpaperEvent); + + //Close the wallpaper registry key + RegCloseKey(hWallpaperKey); } /// @@ -328,6 +339,20 @@ void DesktopPainter::PaintComposite() { /// Handles certain window messages. /// LRESULT DesktopPainter::HandleMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { + + //Check if the wallpaper registry has been changed + if (WaitForSingleObject(hWallpaperEvent, 0) == WAIT_OBJECT_0) + { + //Fetch the new wallpaper + UpdateWallpaper(); + + //Force window to redraw + this->Repaint(); + + //RegNotifyChangeKeyValue() expires after the event has changed state + RegNotifyChangeKeyValue(hWallpaperKey, FALSE, REG_NOTIFY_CHANGE_LAST_SET, hWallpaperEvent, TRUE); + } + switch (uMsg) { case WM_ERASEBKGND: return 1; @@ -335,6 +360,7 @@ LRESULT DesktopPainter::HandleMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA case WM_PAINT: { if (!mDontRenderWallpaper) { + UpdateLock lock(this); bool inAnimation = false; diff --git a/nDesk/DesktopPainter.hpp b/nDesk/DesktopPainter.hpp index 2e8e3e6..3bc17c4 100644 --- a/nDesk/DesktopPainter.hpp +++ b/nDesk/DesktopPainter.hpp @@ -118,4 +118,8 @@ class DesktopPainter : protected Window // If on, every window will be repainted when the wallpaper is changed instead of just the // desktop background. Fixes issues with other modules (xModules). bool m_bInvalidateAllOnUpdate; + + //Event to check if Desktop Wallpaper has been changed + HANDLE hWallpaperEvent; + HKEY hWallpaperKey; };