@@ -158,7 +158,7 @@ void UpdateWindowBounds(Measure* measure)
158158
159159void UpdateChildWindowState (Measure* measure, bool enabled, bool shouldDefocus)
160160{
161- if (!measure->skinWindow || !IsWindow (measure->skinWindow ))
161+ if (!measure || measure-> isStopping || !measure ->skinWindow || !IsWindow (measure->skinWindow ))
162162 return ;
163163
164164 for (HWND child = GetWindow (measure->skinWindow , GW_CHILD);
@@ -233,37 +233,16 @@ LRESULT CALLBACK SkinSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP
233233
234234 measure->isCtrlPressed = isCtrlPressed;
235235
236- if (measure->skinControl <= 1 )
236+ if (measure->clickthrough <= 1 )
237237 continue ;
238238
239- if (measure->skinControl == 2 ) // Hold ctrl to enable SkinControl
239+ if (measure->clickthrough >= 2 )
240240 {
241- if (! measure->isSkinControlActive && isCtrlPressed)
241+ if (measure->isClickthroughActive != isCtrlPressed)
242242 {
243- measure->isSkinControlActive = true ;
244- UpdateChildWindowState (measure, false , false );
245- // RmLog(measure->rm, LOG_DEBUG, L"Plugin: Ctrl was pressed");
246- }
247- else if (measure->isSkinControlActive && !isCtrlPressed)
248- {
249- measure->isSkinControlActive = false ;
250- UpdateChildWindowState (measure, true , false );
251- // RmLog(measure->rm, LOG_DEBUG, L"Plugin: Ctrl was released");
252- }
253- }
254- else if (measure->skinControl >= 3 )
255- {
256- if (!measure->isSkinControlActive && isCtrlPressed)
257- {
258- measure->isSkinControlActive = true ;
259- UpdateChildWindowState (measure, true , false );
260- // RmLog(measure->rm, LOG_DEBUG, L"Plugin: Ctrl was pressed");
261- }
262- else if (measure->isSkinControlActive && !isCtrlPressed)
263- {
264- measure->isSkinControlActive = false ;
265- UpdateChildWindowState (measure, false , false );
266- // RmLog(measure->rm, LOG_DEBUG, L"Plugin: Ctrl was released");
243+ measure->isClickthroughActive = isCtrlPressed;
244+
245+ UpdateChildWindowState (measure, !isCtrlPressed, false ); // Enable clickthrough if ctrl is pressed
267246 }
268247 }
269248 }
@@ -279,6 +258,7 @@ LRESULT CALLBACK SkinSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP
279258 }
280259 }
281260 break ;
261+ case WM_DESTROY:
282262 case WM_NCDESTROY:
283263 RemoveWindowSubclass (hWnd, SkinSubclassProc, uIdSubclass);
284264 break ;
@@ -360,11 +340,6 @@ void RemoveKeyboardHook()
360340 UnhookWindowsHookEx (g_kbHook);
361341 g_kbHook = nullptr ;
362342 }
363- if (g_hModule)
364- {
365- FreeLibrary (g_hModule);
366- g_hModule = nullptr ;
367- }
368343}
369344
370345// Rainmeter Plugin Exports
@@ -375,12 +350,11 @@ PLUGIN_EXPORT void Initialize(void** data, void* rm)
375350
376351 if (g_refCount++ == 0 )
377352 {
378- // RmLog(measure->rm, LOG_DEBUG, (L"WebView2: Starting keyboard hook. Current global refCount: " + std::to_wstring(g_refCount)).c_str());
379353 InstallKeyboardHook ();
380354 }
381- else {
382- // RmLog(measure->rm, LOG_DEBUG, (L"WebView2: Current global refCount: " + std::to_wstring(g_refCount)).c_str() );
383- }
355+
356+ bool ctrlDown = g_ctrlDown. load ( std::memory_order_relaxed );
357+ measure-> isCtrlPressed = ctrlDown;
384358
385359 measure->rm = rm;
386360 measure->skin = RmGetSkin (rm);
@@ -492,8 +466,7 @@ PLUGIN_EXPORT void Reload(void* data, void* rm, double* /*maxValue*/)
492466 const int newHeight = RmReadInt (rm, L" H" , 600 );
493467 const int newX = RmReadInt (rm, L" X" , 0 );
494468 const int newY = RmReadInt (rm, L" Y" , 0 );
495- const int newSkinControl = RmReadInt (rm, L" SkinControl" , 2 );
496- const int newContextMenu = RmReadInt (rm, L" ContextMenu" , 1 );
469+ const int newClickthrough = RmReadInt (rm, L" Clickthrough" , 2 );
497470 const double newZoomFactor = RmReadFormula (rm, L" ZoomFactor" , 1.0 );
498471 const bool newVisible = RmReadInt (rm, L" Hidden" , 0 ) <= 0 ;
499472 const bool newNotifications = RmReadInt (rm, L" Notifications" , 0 ) >= 1 ;
@@ -585,7 +558,7 @@ PLUGIN_EXPORT void Reload(void* data, void* rm, double* /*maxValue*/)
585558 const bool zoomFactorChanged = (newZoomFactor != measure->zoomFactor );
586559 const bool zoomControlChanged = (newZoomControl != measure->zoomControl );
587560 const bool userAgentChanged = (newUserAgent != measure->userAgent );
588- const bool skinControlChanged = (newSkinControl != measure->skinControl );
561+ const bool clickthroughChanged = (newClickthrough != measure->clickthrough );
589562 const bool hostChanged = (newHostPath != measure->hostPath || newHostSecurity != measure->hostSecurity || newHostOrigin != measure->hostOrigin );
590563
591564 // Options
@@ -597,10 +570,9 @@ PLUGIN_EXPORT void Reload(void* data, void* rm, double* /*maxValue*/)
597570 measure->zoomFactor = newZoomFactor;
598571 measure->zoomControl = newZoomControl;
599572 measure->visible = newVisible;
600- measure->skinControl = newSkinControl ;
573+ measure->clickthrough = newClickthrough ;
601574 measure->notifications = newNotifications;
602575 measure->newWindow = newNewWindow;
603- measure->contextMenu = newContextMenu;
604576 measure->hostPath = newHostPath;
605577 measure->userAgent = newUserAgent;
606578 measure->assistiveFeatures = newAssistiveFeatures;
@@ -633,14 +605,14 @@ PLUGIN_EXPORT void Reload(void* data, void* rm, double* /*maxValue*/)
633605 }
634606
635607 // Dynamic updates
636- if (skinControlChanged )
608+ if (clickthroughChanged )
637609 {
638- measure->isSkinControlActive = false ;
639- if (measure->skinControl <= 0 || measure->skinControl == 2 )
610+ measure->isClickthroughActive = false ;
611+ if (measure->clickthrough <= 0 || measure->clickthrough == 2 )
640612 {
641613 UpdateChildWindowState (measure, true );
642614 }
643- else if (measure->skinControl == 1 || measure-> skinControl >= 3 )
615+ else if (measure->clickthrough == 1 )
644616 {
645617 UpdateChildWindowState (measure, false );
646618 }
@@ -978,7 +950,7 @@ PLUGIN_EXPORT void Finalize(void* data)
978950 }
979951
980952 // Stop WebView2 and clean up
981- StopWebView2 (measure);
953+ if (measure-> initialized ) StopWebView2 (measure);
982954
983955 g_refCount--;
984956
@@ -987,6 +959,6 @@ PLUGIN_EXPORT void Finalize(void* data)
987959 {
988960 RemoveKeyboardHook ();
989961 }
990-
962+
991963 delete measure;
992964}
0 commit comments