Skip to content

Commit 9dcff84

Browse files
author
RicardoTM05
committed
Removed ContextMenu
Renamed SkinControl back to Clickthrough Fixed crashes on unload Improved simpleini implementation
1 parent 4490d2c commit 9dcff84

File tree

9 files changed

+119
-159
lines changed

9 files changed

+119
-159
lines changed
-1.02 KB
Binary file not shown.

Resources/Skins/WebView2/Calendar/Calendar.ini

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,12 @@ H=(300*#Scale#)
3636
X=0
3737
Y=0
3838
;Add options to make the skin non-interactable and scalable while holding CTRL.
39-
SkinControl=2
39+
Clickthrough=2
4040
ZoomFactor=#Scale#
41-
;Set the context menu to the Skin Menu
42-
ContextMenu=2
4341
;Disable internal ZoomControl
4442
ZoomControl=0
45-
;Disable default hotkeys
46-
Hotkeys=0
43+
;Disable Assistive Features (Print, Caret Browsing and Find)
44+
AssistiveFeatures=0
4745
DynamicVariables=1
4846

4947
; ========================================

Resources/Skins/WebView2/Clock/Clock.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ H=(160*#Scale#)
4848
X=0
4949
Y=0
5050
;Add options to make the skin non-interactable and scalable.
51-
SkinControl=1
51+
Clickthrough=1
5252
ZoomFactor=[#Scale]
5353
DynamicVariables=1
5454

Resources/Skins/WebView2/IslamicDate/IslamicDate.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ W=(280*#Scale#)
2222
H=(160*#Scale#)
2323
X=0
2424
Y=0
25-
SkinControl=1
25+
Clickthrough=1
2626
ZoomFactor=#Scale#
2727
DynamicVariables=1
2828

Resources/Skins/WebView2/Weather/Weather.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ H=(300*#Scale#)
2929
X=0
3030
Y=0
3131
ZoomFactor=#Scale#
32-
SkinControl=1
32+
Clickthrough=1
3333
DynamicVariables=1
3434

3535
; ========================================

Resources/Skins/WebView2/YoutubePlayer/YoutubePlayer.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ URL=index.html
7878
W=(#W#*#Scale#)
7979
H=(#H#*#Scale#)
8080

81-
; Allow CTRL + drag to move skin and open context menu
82-
SkinControl=2
81+
; Allow CTRL + drag to move skin and open skin menu
82+
Clickthrough=2
8383

8484
; Allow links to open in external windows
8585
NewWindow=1

WebView2/Plugin.cpp

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void UpdateWindowBounds(Measure* measure)
158158

159159
void 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
}

WebView2/Plugin.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
#pragma once
33

44
#include <Windows.h>
5+
#include <WebView2.h>
6+
#include "SimpleIni.h"
7+
#include <wil/com.h>
8+
#include <wrl.h>
59
#include <string>
610
#include <vector>
711
#include <map>
8-
#include <wrl.h>
9-
#include <wil/com.h>
10-
#include <WebView2.h>
1112
#include <memory>
1213
#include <unordered_map>
1314
#include <unordered_set>
@@ -56,15 +57,14 @@ struct Measure
5657
int height;
5758
int x;
5859
int y;
59-
int skinControl = 1;
60-
int contextMenu = 1;
60+
int clickthrough = 1;
6161
double zoomFactor = 1.0;
6262
bool disabled = false;
6363
bool autoStart = true;
6464
bool visible = true;
6565
bool initialized = false;
6666
bool isFirstLoad = true;
67-
bool isSkinControlActive = false;
67+
bool isClickthroughActive = false;
6868
bool notifications = false;
6969
bool zoomControl = true;
7070
bool newWindow = false;
@@ -89,6 +89,9 @@ struct Measure
8989
std::wstring onPageLoadFinishAction;
9090
std::wstring onPageReloadAction;
9191

92+
CSimpleIniW ini;
93+
bool iniDirty = false;
94+
9295
wil::com_ptr<ICoreWebView2Environment> webViewEnvironment;
9396
wil::com_ptr<ICoreWebView2Controller> webViewController;
9497
wil::com_ptr<ICoreWebView2ControllerOptions2>webViewControllerOptions2;

0 commit comments

Comments
 (0)