This commit is contained in:
恍兮惚兮 2025-01-09 20:51:16 +08:00
parent 0d87dae2b2
commit 4e401a387e
9 changed files with 95 additions and 31 deletions

View File

@ -1,7 +1,7 @@
set(VERSION_MAJOR 6) set(VERSION_MAJOR 6)
set(VERSION_MINOR 19) set(VERSION_MINOR 19)
set(VERSION_PATCH 2) set(VERSION_PATCH 3)
set(VERSION_REVISION 0) set(VERSION_REVISION 0)
set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}") set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}")
add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp) add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp)

View File

@ -26,7 +26,8 @@ typedef enum _WINDOWCOMPOSITIONATTRIB
WCA_FREEZE_REPRESENTATION = 20, WCA_FREEZE_REPRESENTATION = 20,
WCA_EVER_UNCLOAKED = 21, WCA_EVER_UNCLOAKED = 21,
WCA_VISUAL_OWNER = 22, WCA_VISUAL_OWNER = 22,
WCA_LAST = 23 WCA_LAST = 23,
WCA_USEDARKMODECOLORS = 26
} WINDOWCOMPOSITIONATTRIB; } WINDOWCOMPOSITIONATTRIB;
typedef struct _WINDOWCOMPOSITIONATTRIBDATA typedef struct _WINDOWCOMPOSITIONATTRIBDATA
@ -141,3 +142,44 @@ DECLARE_API bool clearEffect(HWND hwnd)
return false; return false;
#endif #endif
} }
uint32_t GetOSversion() noexcept;
DECLARE_API bool setbackdropX(HWND hwnd, bool corner, bool dark)
{
#ifndef WINXP
if (GetOSversion() <= 6)
return false;
ACCENT_POLICY accent;
accent.AccentState = ACCENT_ENABLE_ACRYLICBLURBEHIND;
CRegKey key;
if (ERROR_SUCCESS != key.Open(HKEY_CURRENT_USER, LR"(SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent)"))
return false;
DWORD accent_int;
if (ERROR_SUCCESS != key.QueryDWORDValue(L"AccentColorMenu", accent_int))
return false;
if (dark)
accent.GradientColor = 0x40212121;
else
accent.GradientColor = 0x40f7f7fa;
WINDOWCOMPOSITIONATTRIBDATA data;
data.Attrib = WCA_ACCENT_POLICY;
data.cbData = sizeof(accent);
data.pvData = &accent;
auto setWindowCompositionAttribute = (pfnSetWindowCompositionAttribute)GetProcAddress(GetModuleHandle(L"user32.dll"), "SetWindowCompositionAttribute");
if (!setWindowCompositionAttribute)
return false;
setWindowCompositionAttribute(hwnd, &data);
if (dark)
{
data.Attrib = WCA_USEDARKMODECOLORS;
setWindowCompositionAttribute(hwnd, &data);
}
DWORD corner_ = corner ? 2 : 0;
DwmSetWindowAttribute(hwnd, DWMWA_WINDOW_CORNER_PREFERENCE, &corner_, sizeof(corner_));
return true;
#endif
}

View File

@ -1,7 +1,7 @@
 
// https://github.com/Blinue/Xaml-Islands-Cpp/blob/main/src/XamlIslandsCpp/XamlWindow.h // https://github.com/Blinue/Xaml-Islands-Cpp/blob/main/src/XamlIslandsCpp/XamlWindow.h
static uint32_t GetOSversion() noexcept uint32_t GetOSversion() noexcept
{ {
HMODULE hNtDll = GetModuleHandle(L"ntdll.dll"); HMODULE hNtDll = GetModuleHandle(L"ntdll.dll");
if (!hNtDll) if (!hNtDll)

View File

@ -332,7 +332,9 @@ class MAINUI:
if not text: if not text:
return return
except Exception as e: except Exception as e:
self.translation_ui.displaystatus.emit(stringfyerror(e), TextType.Error_origin) self.translation_ui.displaystatus.emit(
stringfyerror(e), TextType.Error_origin
)
return return
if is_auto_run and ( if is_auto_run and (
@ -557,8 +559,7 @@ class MAINUI:
if iserror: if iserror:
if currentsignature == self.currentsignature: if currentsignature == self.currentsignature:
self.translation_ui.displaystatus.emit( self.translation_ui.displaystatus.emit(
apiname + " " + res, apiname + " " + res, TextType.Error_translator
TextType.Error_translator
) )
if len(usefultranslators) == 0: if len(usefultranslators) == 0:
safe_callback("") safe_callback("")
@ -960,11 +961,18 @@ class MAINUI:
print_exc() print_exc()
def setdarkandbackdrop(self, widget, dark): def setdarkandbackdrop(self, widget, dark):
if self.__dontshowintaborsetbackdrop(widget): ismenulist = isinstance(widget, (QMenu,)) or (type(widget) == QFrame)
if ((not ismenulist)) and self.__dontshowintaborsetbackdrop(widget):
return return
winsharedutils.SetTheme( winsharedutils.SetTheme(
int(widget.winId()), dark, globalconfig["WindowBackdrop"] int(widget.winId()), dark, globalconfig["WindowBackdrop"]
) )
if ismenulist:
darklight = ["light", "dark"][self.currentisdark]
name = globalconfig[darklight + "theme2"]
if name == "QTWin11":
# 这个东西会导致其他主题看起来很怪,而且没办法撤销
winsharedutils.setbackdropX(int(widget.winId()), True, dark)
@threader @threader
def clickwordcallback(self, word, append=False): def clickwordcallback(self, word, append=False):
@ -1068,10 +1076,15 @@ class MAINUI:
style = "" style = ""
for _ in (0,): for _ in (0,):
try: try:
idx = globalconfig[darklight + "theme"] - int(not dark) name = globalconfig[darklight + "theme2"]
if idx == -1: _fn = None
for n in static_data["themes"][darklight]:
if n["name"] == name:
_fn = n["file"]
break
if not _fn:
break break
_fn = static_data["themes"][darklight][idx]["file"]
if _fn.endswith(".py"): if _fn.endswith(".py"):
style = importlib.import_module( style = importlib.import_module(

View File

@ -139,10 +139,15 @@ def wrapedsetstylecallback(_dark, self, func):
def checkthemeissetable(self, dark: bool): def checkthemeissetable(self, dark: bool):
try: try:
darklight = ["light", "dark"][dark] darklight = ["light", "dark"][dark]
idx = globalconfig[darklight + "theme"] - int(not dark) name = globalconfig[darklight + "theme2"]
if idx == -1: _fn = None
for n in static_data["themes"][darklight]:
if n["name"] == name:
_fn = n["file"]
break
if not _fn:
return None return None
_fn = static_data["themes"][darklight][idx]["file"]
if _fn.endswith(".py"): if _fn.endswith(".py"):
try: try:
@ -603,12 +608,13 @@ def otheruisetting(self):
D_getsimplecombobox( D_getsimplecombobox(
["默认"] + themelist("light"), ["默认"] + themelist("light"),
globalconfig, globalconfig,
"lighttheme", "lighttheme2",
functools.partial( functools.partial(
checkthemesettingvisandapply, checkthemesettingvisandapply,
self, self,
False, False,
), ),
internal=["default"] + themelist("light"),
), ),
functools.partial(createbtnthemelight, self), functools.partial(createbtnthemelight, self),
), ),
@ -619,12 +625,13 @@ def otheruisetting(self):
D_getsimplecombobox( D_getsimplecombobox(
themelist("dark"), themelist("dark"),
globalconfig, globalconfig,
"darktheme", "darktheme2",
functools.partial( functools.partial(
checkthemesettingvisandapply, checkthemesettingvisandapply,
self, self,
True, True,
), ),
internal=themelist("dark"),
), ),
functools.partial(createbtnthemedark, self), functools.partial(createbtnthemedark, self),
), ),

View File

@ -1014,21 +1014,22 @@ def getColor(color, parent, alpha=False):
color_dialog = QColorDialog(color, parent) color_dialog = QColorDialog(color, parent)
if alpha: if alpha:
color_dialog.setOption(QColorDialog.ColorDialogOption.ShowAlphaChannel, True) color_dialog.setOption(QColorDialog.ColorDialogOption.ShowAlphaChannel, True)
layout = color_dialog.layout() if alpha:
clearlayout(layout.itemAt(0).layout().takeAt(0)) layout = color_dialog.layout()
layout = layout.itemAt(0).layout().itemAt(0).layout().itemAt(2).widget().layout() clearlayout(layout.itemAt(0).layout().takeAt(0))
layout.takeAt(1).widget().hide() layout = layout.itemAt(0).layout().itemAt(0).layout().itemAt(2).widget().layout()
layout.takeAt(1).widget().hide() layout.takeAt(1).widget().hide()
layout.takeAt(1).widget().hide() layout.takeAt(1).widget().hide()
layout.takeAt(1).widget().hide() layout.takeAt(1).widget().hide()
layout.takeAt(1).widget().hide() layout.takeAt(1).widget().hide()
layout.takeAt(1).widget().hide() layout.takeAt(1).widget().hide()
layout.takeAt(1).widget().hide()
layout.takeAt(layout.count() - 1).widget().hide()
layout.takeAt(layout.count() - 1).widget().hide()
if not alpha:
layout.takeAt(layout.count() - 1).widget().hide() layout.takeAt(layout.count() - 1).widget().hide()
layout.takeAt(layout.count() - 1).widget().hide() layout.takeAt(layout.count() - 1).widget().hide()
if not alpha:
layout.takeAt(layout.count() - 1).widget().hide()
layout.takeAt(layout.count() - 1).widget().hide()
if color_dialog.exec_() != QColorDialog.DialogCode.Accepted: if color_dialog.exec_() != QColorDialog.DialogCode.Accepted:
return QColor() return QColor()
return color_dialog.selectedColor() return color_dialog.selectedColor()

View File

@ -278,7 +278,8 @@ def gdi_screenshot(x1, y1, x2, y2, hwnd=None):
maximum_window = utilsdll.maximum_window maximum_window = utilsdll.maximum_window
maximum_window.argtypes = (HWND,) maximum_window.argtypes = (HWND,)
setbackdropX = utilsdll.setbackdropX
setbackdropX.argtypes = HWND, c_bool, c_bool
setAeroEffect = utilsdll.setAeroEffect setAeroEffect = utilsdll.setAeroEffect
setAeroEffect.argtypes = (HWND, c_bool) setAeroEffect.argtypes = (HWND, c_bool)
setAcrylicEffect = utilsdll.setAcrylicEffect setAcrylicEffect = utilsdll.setAcrylicEffect

@ -1 +1 @@
Subproject commit 195ba64aafc8b63554253c8d3ace4299ec0e9ec1 Subproject commit 0ccbf59b08fd7458820ede53833a8968e93b0d0c

View File

@ -1504,8 +1504,8 @@
} }
}, },
"darklight2": 0, "darklight2": 0,
"darktheme": 0, "darktheme2": "PyQtDarkTheme",
"lighttheme": 1, "lighttheme2": "PyQtDarkTheme",
"usesearchword": false, "usesearchword": false,
"usecopyword": false, "usecopyword": false,
"usewordorigin": false, "usewordorigin": false,