mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-28 08:04:13 +08:00
darklight
This commit is contained in:
parent
fd09261f4f
commit
3ae3a0df1f
@ -15,7 +15,7 @@ from PyQt5.QtWidgets import (
|
||||
from PyQt5.QtGui import QResizeEvent
|
||||
from PyQt5.QtWidgets import QTabWidget
|
||||
import qtawesome, darkdetect, gobject
|
||||
import functools
|
||||
import functools, threading, windows, os, winsharedutils
|
||||
from traceback import print_exc
|
||||
from myutils.config import globalconfig, _TR
|
||||
from myutils.utils import wavmp3player
|
||||
@ -47,6 +47,7 @@ class Settin(closeashidewindow):
|
||||
clicksourcesignal = pyqtSignal(str)
|
||||
opensolvetextsig = pyqtSignal()
|
||||
showandsolvesig = pyqtSignal(str)
|
||||
setstylesheetsignal = pyqtSignal()
|
||||
|
||||
def resizefunction(self):
|
||||
|
||||
@ -138,6 +139,8 @@ class Settin(closeashidewindow):
|
||||
setTab_about_dicrect(self)
|
||||
|
||||
self.setstylesheet()
|
||||
self.setstylesheetsignal.connect(self.setstylesheet)
|
||||
threading.Thread(target=self.darklistener).start()
|
||||
|
||||
def inittray(self):
|
||||
|
||||
@ -231,6 +234,15 @@ class Settin(closeashidewindow):
|
||||
setTab_about(self)
|
||||
self.isfirstshow = False
|
||||
|
||||
def darklistener(self):
|
||||
sema = winsharedutils.startdarklistener()
|
||||
while True:
|
||||
# 会触发两次
|
||||
windows.WaitForSingleObject(sema, windows.INFINITE)
|
||||
windows.WaitForSingleObject(sema, windows.INFINITE)
|
||||
if globalconfig["darklight"] == 2:
|
||||
self.setstylesheetsignal.emit()
|
||||
|
||||
def setstylesheet(self):
|
||||
|
||||
dl = globalconfig["darklight"]
|
||||
|
@ -18,7 +18,7 @@ from ctypes import (
|
||||
windll,
|
||||
c_char,
|
||||
)
|
||||
from ctypes.wintypes import WORD
|
||||
from ctypes.wintypes import WORD, HANDLE
|
||||
import gobject
|
||||
|
||||
utilsdll = CDLL(gobject.GetDllpath(("winsharedutils32.dll", "winsharedutils64.dll")))
|
||||
@ -309,3 +309,7 @@ def queryversion(exe):
|
||||
if succ:
|
||||
return _1.value, _2.value, _3.value, _4.value
|
||||
return None
|
||||
|
||||
|
||||
startdarklistener = utilsdll.startdarklistener
|
||||
startdarklistener.restype = HANDLE
|
||||
|
@ -2,7 +2,7 @@
|
||||
project(winsharedutils)
|
||||
|
||||
|
||||
add_library(winsharedutils MODULE version.cpp otsu.cpp cinterface.cpp clipboard.cpp lnk.cpp dllmain.cpp levenshtein.cpp muteprocess.cpp sapi_dll.cpp simplemecab.cpp SimpleBrowser.cpp MWebBrowser.cpp icon.cpp)
|
||||
add_library(winsharedutils MODULE darklistener.cpp version.cpp otsu.cpp cinterface.cpp clipboard.cpp lnk.cpp dllmain.cpp levenshtein.cpp muteprocess.cpp sapi_dll.cpp simplemecab.cpp SimpleBrowser.cpp MWebBrowser.cpp icon.cpp)
|
||||
|
||||
if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
|
||||
set_target_properties(winsharedutils PROPERTIES OUTPUT_NAME "winsharedutils64")
|
||||
|
44
plugins/winsharedutils/darklistener.cpp
Normal file
44
plugins/winsharedutils/darklistener.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include <windows.h>
|
||||
#include <thread>
|
||||
#include <string>
|
||||
#include "define.h"
|
||||
HANDLE hsema;
|
||||
void IsColorSchemeChangeMessage(LPARAM lParam)
|
||||
{
|
||||
if (lParam && CompareStringOrdinal(reinterpret_cast<LPCWCH>(lParam), -1, L"ImmersiveColorSet", -1, TRUE) == CSTR_EQUAL)
|
||||
{
|
||||
ReleaseSemaphore(hsema, 1, 0);
|
||||
}
|
||||
}
|
||||
void startdarklistener_1()
|
||||
{
|
||||
const wchar_t CLASS_NAME[] = L"LunaDarkListener";
|
||||
|
||||
WNDCLASS wc = {};
|
||||
wc.lpfnWndProc = [](HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (WM_SETTINGCHANGE == message)
|
||||
IsColorSchemeChangeMessage(lParam);
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
};
|
||||
wc.hInstance = GetModuleHandle(0);
|
||||
wc.lpszClassName = CLASS_NAME;
|
||||
|
||||
static auto _ = RegisterClass(&wc);
|
||||
HWND hWnd = CreateWindowEx(
|
||||
WS_EX_CLIENTEDGE, CLASS_NAME, CLASS_NAME, WS_OVERLAPPEDWINDOW,
|
||||
0, 0, 0, 0,
|
||||
NULL, NULL, GetModuleHandle(0), 0);
|
||||
MSG msg = {};
|
||||
while (GetMessage(&msg, NULL, 0, 0))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
HANDLE startdarklistener()
|
||||
{
|
||||
hsema = CreateSemaphoreW(0, 0, 10, 0);
|
||||
std::thread(startdarklistener_1).detach();
|
||||
return hsema;
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
#include <Windows.h>
|
||||
extern "C"
|
||||
{
|
||||
__declspec(dllexport) HANDLE startdarklistener();
|
||||
__declspec(dllexport) bool queryversion(const wchar_t *exe, WORD *_1, WORD *_2, WORD *_3, WORD *_4);
|
||||
|
||||
__declspec(dllexport) bool SAPI_Speak(const wchar_t *Content, int version, int voiceid, int rate, int volume, const wchar_t *Filename);
|
||||
|
Loading…
x
Reference in New Issue
Block a user