MCPcopy Create free account
hub / github.com/MiniZinc/MiniZincIDE / init

Method init

MiniZincIDE/darkmodenotifier.cpp:47–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45};
46
47void DarkModeNotifier::init()
48{
49 auto getDarkMode = [=] () {
50 if (!_internal->ok) { return false; }
51 DWORD value = 1;
52 DWORD size = sizeof(DWORD);
53 auto result = RegGetValue(_internal->hKey, nullptr, L"AppsUseLightTheme", RRF_RT_REG_DWORD, nullptr, &value, &size);
54 if (result != ERROR_SUCCESS) {
55 _internal->ok = false;
56 return false;
57 }
58 return value == 0;
59 };
60
61 _internal = new Internal;
62
63 // Get dark mode registry key
64 auto result = RegOpenKey(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", &_internal->hKey);
65 _internal->ok = result == ERROR_SUCCESS;
66 if (!_internal->ok) { return; }
67
68 // Get initial dark mode
69 _darkMode = getDarkMode();
70 if (!_internal->ok) { return; }
71
72 // Setup event to be triggered on registry change
73 _internal->hEvent = CreateEvent(nullptr, true, false, nullptr);
74 _internal->ok = _internal->hEvent != nullptr;
75 if (!_internal->ok) { return; }
76
77 // Listen for event
78 _internal->notifier = new QWinEventNotifier(_internal->hEvent);
79 connect(_internal->notifier, &QWinEventNotifier::activated, this, [=] () {
80 bool newDarkMode = getDarkMode();
81 if (!_internal->ok) { return; }
82 if (newDarkMode != _darkMode) {
83 _darkMode = newDarkMode;
84 emit darkModeChanged(newDarkMode);
85 }
86 _internal->ok = ResetEvent(_internal->hEvent) != 0;
87 if (!_internal->ok) { return; }
88 auto result = RegNotifyChangeKeyValue(_internal->hKey,
89 true,
90 REG_NOTIFY_CHANGE_NAME | REG_NOTIFY_CHANGE_LAST_SET,
91 _internal->hEvent,
92 true);
93 _internal->ok = result == ERROR_SUCCESS;
94 });
95
96 // Start notifier
97 result = RegNotifyChangeKeyValue(_internal->hKey,
98 true,
99 REG_NOTIFY_CHANGE_NAME | REG_NOTIFY_CHANGE_LAST_SET,
100 _internal->hEvent,
101 true);
102 _internal->ok = result == ERROR_SUCCESS;
103}
104

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected