mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 16:44:13 +08:00
arc
This commit is contained in:
parent
ccd47e6dc9
commit
e523a195b6
@ -32,7 +32,6 @@ from gui.setting_proxy import setTab_proxy
|
|||||||
from gui.settingpage7 import setTab7, settab7direct
|
from gui.settingpage7 import setTab7, settab7direct
|
||||||
from gui.settingpage_about import setTab_about, setTab_about_dicrect
|
from gui.settingpage_about import setTab_about, setTab_about_dicrect
|
||||||
from gui.usefulwidget import closeashidewindow, tabadd_lazy
|
from gui.usefulwidget import closeashidewindow, tabadd_lazy
|
||||||
from myutils.Acrylic import WindowEffect
|
|
||||||
|
|
||||||
|
|
||||||
class gridwidget(QWidget):
|
class gridwidget(QWidget):
|
||||||
@ -261,11 +260,11 @@ class Settin(closeashidewindow):
|
|||||||
for widget in QApplication.topLevelWidgets():
|
for widget in QApplication.topLevelWidgets():
|
||||||
if widget.testAttribute(Qt.WA_TranslucentBackground):
|
if widget.testAttribute(Qt.WA_TranslucentBackground):
|
||||||
if globalconfig["WindowEffect"] == 0:
|
if globalconfig["WindowEffect"] == 0:
|
||||||
WindowEffect().clear(int(widget.winId()))
|
winsharedutils.clearEffect(int(widget.winId()))
|
||||||
elif globalconfig["WindowEffect"] == 1:
|
elif globalconfig["WindowEffect"] == 1:
|
||||||
WindowEffect().setAcrylicEffect(int(widget.winId()))
|
winsharedutils.setAcrylicEffect(int(widget.winId()))
|
||||||
elif globalconfig["WindowEffect"] == 2:
|
elif globalconfig["WindowEffect"] == 2:
|
||||||
WindowEffect().setAeroEffect(int(widget.winId()))
|
winsharedutils.setAeroEffect(int(widget.winId()))
|
||||||
continue
|
continue
|
||||||
winsharedutils.SetTheme(
|
winsharedutils.SetTheme(
|
||||||
int(widget.winId()), dark, globalconfig["WindowBackdrop"]
|
int(widget.winId()), dark, globalconfig["WindowBackdrop"]
|
||||||
|
@ -1,151 +0,0 @@
|
|||||||
# coding:utf-8
|
|
||||||
|
|
||||||
from ctypes import POINTER, Structure
|
|
||||||
from ctypes.wintypes import DWORD, HWND, ULONG
|
|
||||||
from enum import Enum
|
|
||||||
|
|
||||||
# coding:utf-8
|
|
||||||
|
|
||||||
from ctypes import POINTER, c_bool, sizeof, windll, pointer, c_int
|
|
||||||
from ctypes.wintypes import DWORD, HWND, ULONG
|
|
||||||
|
|
||||||
|
|
||||||
class WINDOWCOMPOSITIONATTRIB(Enum):
|
|
||||||
WCA_UNDEFINED = (0,)
|
|
||||||
WCA_NCRENDERING_ENABLED = (1,)
|
|
||||||
WCA_NCRENDERING_POLICY = (2,)
|
|
||||||
WCA_TRANSITIONS_FORCEDISABLED = (3,)
|
|
||||||
WCA_ALLOW_NCPAINT = (4,)
|
|
||||||
WCA_CAPTION_BUTTON_BOUNDS = (5,)
|
|
||||||
WCA_NONCLIENT_RTL_LAYOUT = (6,)
|
|
||||||
WCA_FORCE_ICONIC_REPRESENTATION = (7,)
|
|
||||||
WCA_EXTENDED_FRAME_BOUNDS = (8,)
|
|
||||||
WCA_HAS_ICONIC_BITMAP = (9,)
|
|
||||||
WCA_THEME_ATTRIBUTES = (10,)
|
|
||||||
WCA_NCRENDERING_EXILED = (11,)
|
|
||||||
WCA_NCADORNMENTINFO = (12,)
|
|
||||||
WCA_EXCLUDED_FROM_LIVEPREVIEW = (13,)
|
|
||||||
WCA_VIDEO_OVERLAY_ACTIVE = (14,)
|
|
||||||
WCA_FORCE_ACTIVEWINDOW_APPEARANCE = (15,)
|
|
||||||
WCA_DISALLOW_PEEK = (16,)
|
|
||||||
WCA_CLOAK = (17,)
|
|
||||||
WCA_CLOAKED = (18,)
|
|
||||||
WCA_ACCENT_POLICY = (19,)
|
|
||||||
WCA_FREEZE_REPRESENTATION = (20,)
|
|
||||||
WCA_EVER_UNCLOAKED = (21,)
|
|
||||||
WCA_VISUAL_OWNER = (22,)
|
|
||||||
WCA_LAST = 23
|
|
||||||
|
|
||||||
|
|
||||||
class ACCENT_STATE(Enum):
|
|
||||||
"""客户区状态枚举类"""
|
|
||||||
|
|
||||||
ACCENT_DISABLED = (0,)
|
|
||||||
ACCENT_ENABLE_GRADIENT = (1,)
|
|
||||||
ACCENT_ENABLE_TRANSPARENTGRADIENT = (2,)
|
|
||||||
ACCENT_ENABLE_BLURBEHIND = (3,) # Aero效果
|
|
||||||
ACCENT_ENABLE_ACRYLICBLURBEHIND = (4,) # 亚克力效果
|
|
||||||
ACCENT_INVALID_STATE = 5
|
|
||||||
|
|
||||||
|
|
||||||
class ACCENT_POLICY(Structure):
|
|
||||||
"""设置客户区的具体属性"""
|
|
||||||
|
|
||||||
_fields_ = [
|
|
||||||
("AccentState", DWORD),
|
|
||||||
("AccentFlags", DWORD),
|
|
||||||
("GradientColor", DWORD),
|
|
||||||
("AnimationId", DWORD),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class WINDOWCOMPOSITIONATTRIBDATA(Structure):
|
|
||||||
_fields_ = [
|
|
||||||
("Attribute", DWORD),
|
|
||||||
(
|
|
||||||
"Data",
|
|
||||||
POINTER(ACCENT_POLICY),
|
|
||||||
), # POINTER()接收任何ctypes类型,并返回一个指针类型
|
|
||||||
("SizeOfData", ULONG),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class WindowEffect:
|
|
||||||
"""调用windows api实现窗口效果"""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
# 调用api
|
|
||||||
self.SetWindowCompositionAttribute = windll.user32.SetWindowCompositionAttribute
|
|
||||||
self.SetWindowCompositionAttribute.restype = c_bool
|
|
||||||
self.SetWindowCompositionAttribute.argtypes = [
|
|
||||||
c_int,
|
|
||||||
POINTER(WINDOWCOMPOSITIONATTRIBDATA),
|
|
||||||
]
|
|
||||||
# 初始化结构体
|
|
||||||
self.accentPolicy = ACCENT_POLICY()
|
|
||||||
self.winCompAttrData = WINDOWCOMPOSITIONATTRIBDATA()
|
|
||||||
self.winCompAttrData.Attribute = (
|
|
||||||
WINDOWCOMPOSITIONATTRIB.WCA_ACCENT_POLICY.value[0]
|
|
||||||
)
|
|
||||||
self.winCompAttrData.SizeOfData = sizeof(self.accentPolicy)
|
|
||||||
self.winCompAttrData.Data = pointer(self.accentPolicy)
|
|
||||||
|
|
||||||
def clear(self, hWnd):
|
|
||||||
self.accentPolicy.AccentState = ACCENT_STATE.ACCENT_DISABLED.value[0]
|
|
||||||
self.SetWindowCompositionAttribute(hWnd, pointer(self.winCompAttrData))
|
|
||||||
|
|
||||||
def setAcrylicEffect(
|
|
||||||
self,
|
|
||||||
hWnd: int,
|
|
||||||
gradientColor: str = "F2F2F230",
|
|
||||||
isEnableShadow: bool = True,
|
|
||||||
animationId: int = 0,
|
|
||||||
):
|
|
||||||
"""开启亚克力效果
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
hWnd: int
|
|
||||||
窗口句柄
|
|
||||||
|
|
||||||
gradientColor: str
|
|
||||||
十六进制亚克力混合色,对应 RGBA 四个分量
|
|
||||||
|
|
||||||
isEnableShadow: bool
|
|
||||||
是否启用窗口阴影
|
|
||||||
|
|
||||||
animationId: int
|
|
||||||
控制磨砂动画
|
|
||||||
"""
|
|
||||||
# 亚克力混合色
|
|
||||||
gradientColor = (
|
|
||||||
gradientColor[6:]
|
|
||||||
+ gradientColor[4:6]
|
|
||||||
+ gradientColor[2:4]
|
|
||||||
+ gradientColor[:2]
|
|
||||||
)
|
|
||||||
gradientColor = DWORD(int(gradientColor, base=16))
|
|
||||||
# 磨砂动画
|
|
||||||
animationId = DWORD(animationId)
|
|
||||||
# 窗口阴影
|
|
||||||
accentFlags = DWORD(0x20 | 0x40 | 0x80 | 0x100) if isEnableShadow else DWORD(0)
|
|
||||||
self.accentPolicy.AccentState = (
|
|
||||||
ACCENT_STATE.ACCENT_ENABLE_ACRYLICBLURBEHIND.value[0]
|
|
||||||
)
|
|
||||||
self.accentPolicy.GradientColor = gradientColor
|
|
||||||
self.accentPolicy.AccentFlags = accentFlags
|
|
||||||
self.accentPolicy.AnimationId = animationId
|
|
||||||
# 开启亚克力
|
|
||||||
self.SetWindowCompositionAttribute(hWnd, pointer(self.winCompAttrData))
|
|
||||||
|
|
||||||
def setAeroEffect(self, hWnd: int):
|
|
||||||
"""开启 Aero 效果
|
|
||||||
|
|
||||||
Parameter
|
|
||||||
----------
|
|
||||||
hWnd: int
|
|
||||||
窗口句柄
|
|
||||||
"""
|
|
||||||
self.accentPolicy.AccentState = ACCENT_STATE.ACCENT_ENABLE_BLURBEHIND.value[0]
|
|
||||||
# 开启Aero
|
|
||||||
self.SetWindowCompositionAttribute(hWnd, pointer(self.winCompAttrData))
|
|
@ -382,3 +382,10 @@ 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,)
|
||||||
|
|
||||||
|
setAeroEffect = utilsdll.setAeroEffect
|
||||||
|
setAeroEffect.argtypes = (HWND,)
|
||||||
|
setAcrylicEffect = utilsdll.setAcrylicEffect
|
||||||
|
setAcrylicEffect.argtypes = (HWND,)
|
||||||
|
clearEffect = utilsdll.clearEffect
|
||||||
|
clearEffect.argtypes = (HWND,)
|
||||||
|
111
plugins/winsharedutils/AreoAcrylic.cpp
Normal file
111
plugins/winsharedutils/AreoAcrylic.cpp
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
#include "define.h"
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum _WINDOWCOMPOSITIONATTRIB
|
||||||
|
{
|
||||||
|
CA_UNDEFINED = 0,
|
||||||
|
WCA_NCRENDERING_ENABLED = 1,
|
||||||
|
WCA_NCRENDERING_POLICY = 2,
|
||||||
|
WCA_TRANSITIONS_FORCEDISABLED = 3,
|
||||||
|
WCA_ALLOW_NCPAINT = 4,
|
||||||
|
WCA_CAPTION_BUTTON_BOUNDS = 5,
|
||||||
|
WCA_NONCLIENT_RTL_LAYOUT = 6,
|
||||||
|
WCA_FORCE_ICONIC_REPRESENTATION = 7,
|
||||||
|
WCA_EXTENDED_FRAME_BOUNDS = 8,
|
||||||
|
WCA_HAS_ICONIC_BITMAP = 9,
|
||||||
|
WCA_THEME_ATTRIBUTES = 10,
|
||||||
|
WCA_NCRENDERING_EXILED = 11,
|
||||||
|
WCA_NCADORNMENTINFO = 12,
|
||||||
|
WCA_EXCLUDED_FROM_LIVEPREVIEW = 13,
|
||||||
|
WCA_VIDEO_OVERLAY_ACTIVE = 14,
|
||||||
|
WCA_FORCE_ACTIVEWINDOW_APPEARANCE = 15,
|
||||||
|
WCA_DISALLOW_PEEK = 16,
|
||||||
|
WCA_CLOAK = 17,
|
||||||
|
WCA_CLOAKED = 18,
|
||||||
|
WCA_ACCENT_POLICY = 19,//
|
||||||
|
WCA_FREEZE_REPRESENTATION = 20,
|
||||||
|
WCA_EVER_UNCLOAKED = 21,
|
||||||
|
WCA_VISUAL_OWNER = 22,
|
||||||
|
WCA_LAST = 23
|
||||||
|
} WINDOWCOMPOSITIONATTRIB;
|
||||||
|
|
||||||
|
typedef struct _WINDOWCOMPOSITIONATTRIBDATA
|
||||||
|
{
|
||||||
|
WINDOWCOMPOSITIONATTRIB Attrib;
|
||||||
|
PVOID pvData;
|
||||||
|
SIZE_T cbData;
|
||||||
|
} WINDOWCOMPOSITIONATTRIBDATA;
|
||||||
|
|
||||||
|
typedef enum _ACCENT_STATE
|
||||||
|
{
|
||||||
|
ACCENT_DISABLED = 0,
|
||||||
|
ACCENT_ENABLE_GRADIENT = 1,
|
||||||
|
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
|
||||||
|
ACCENT_ENABLE_BLURBEHIND = 3,
|
||||||
|
ACCENT_ENABLE_ACRYLICBLURBEHIND = 4,
|
||||||
|
ACCENT_INVALID_STATE=5
|
||||||
|
} ACCENT_STATE;
|
||||||
|
|
||||||
|
typedef struct _ACCENT_POLICY
|
||||||
|
{
|
||||||
|
ACCENT_STATE AccentState;
|
||||||
|
DWORD AccentFlags;
|
||||||
|
DWORD GradientColor;
|
||||||
|
DWORD AnimationId;
|
||||||
|
} ACCENT_POLICY;
|
||||||
|
|
||||||
|
WINUSERAPI
|
||||||
|
BOOL
|
||||||
|
WINAPI
|
||||||
|
GetWindowCompositionAttribute(
|
||||||
|
_In_ HWND hWnd,
|
||||||
|
_Inout_ WINDOWCOMPOSITIONATTRIBDATA* pAttrData);
|
||||||
|
|
||||||
|
typedef BOOL(WINAPI* pfnGetWindowCompositionAttribute)(HWND, WINDOWCOMPOSITIONATTRIBDATA*);
|
||||||
|
|
||||||
|
WINUSERAPI
|
||||||
|
BOOL
|
||||||
|
WINAPI
|
||||||
|
SetWindowCompositionAttribute(
|
||||||
|
_In_ HWND hWnd,
|
||||||
|
_Inout_ WINDOWCOMPOSITIONATTRIBDATA* pAttrData);
|
||||||
|
|
||||||
|
typedef BOOL(WINAPI* pfnSetWindowCompositionAttribute)(HWND, WINDOWCOMPOSITIONATTRIBDATA*);
|
||||||
|
|
||||||
|
#define common ACCENT_POLICY accentPolicy;\
|
||||||
|
WINDOWCOMPOSITIONATTRIBDATA winCompAttrData;\
|
||||||
|
ZeroMemory(&accentPolicy,sizeof(accentPolicy));\
|
||||||
|
ZeroMemory(&winCompAttrData,sizeof(winCompAttrData));\
|
||||||
|
winCompAttrData.Attrib = WCA_ACCENT_POLICY;\
|
||||||
|
winCompAttrData.cbData = sizeof(accentPolicy);\
|
||||||
|
winCompAttrData.pvData = &accentPolicy;\
|
||||||
|
auto setWindowCompositionAttribute = (pfnSetWindowCompositionAttribute)GetProcAddress(GetModuleHandle(L"user32.dll"), "SetWindowCompositionAttribute");\
|
||||||
|
if(!setWindowCompositionAttribute)return false;
|
||||||
|
|
||||||
|
DECLARE bool setAcrylicEffect(HWND hwnd){
|
||||||
|
DWORD gradientColor=0x30F2F2F2;//ABGR
|
||||||
|
bool isEnableShadow=true;
|
||||||
|
DWORD animationId= 0;
|
||||||
|
auto accentFlags = isEnableShadow?(DWORD(0x20 | 0x40 | 0x80 | 0x100)):0;
|
||||||
|
common
|
||||||
|
|
||||||
|
accentPolicy.AccentState =ACCENT_ENABLE_ACRYLICBLURBEHIND;
|
||||||
|
accentPolicy.GradientColor = gradientColor;
|
||||||
|
accentPolicy.AccentFlags = accentFlags;
|
||||||
|
accentPolicy.AnimationId = animationId;
|
||||||
|
return setWindowCompositionAttribute(hwnd,&winCompAttrData);
|
||||||
|
}
|
||||||
|
|
||||||
|
DECLARE bool setAeroEffect(HWND hwnd){
|
||||||
|
|
||||||
|
common
|
||||||
|
|
||||||
|
accentPolicy.AccentState =ACCENT_ENABLE_BLURBEHIND;
|
||||||
|
return setWindowCompositionAttribute(hwnd,&winCompAttrData);
|
||||||
|
}
|
||||||
|
DECLARE bool clearEffect(HWND hwnd){
|
||||||
|
|
||||||
|
common
|
||||||
|
accentPolicy.AccentState =ACCENT_DISABLED;
|
||||||
|
return setWindowCompositionAttribute(hwnd,&winCompAttrData);
|
||||||
|
}
|
@ -11,7 +11,7 @@ generate_product_version(
|
|||||||
VERSION_PATCH ${VERSION_PATCH}
|
VERSION_PATCH ${VERSION_PATCH}
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(winsharedutils MODULE screenshot.cpp audio.cpp ../implsapi.cpp hwnd.cpp darklistener.cpp theme.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 maglistener.cpp ${versioninfo})
|
add_library(winsharedutils MODULE AreoAcrylic.cpp screenshot.cpp audio.cpp ../implsapi.cpp hwnd.cpp darklistener.cpp theme.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 maglistener.cpp ${versioninfo})
|
||||||
target_precompile_headers(winsharedutils REUSE_FROM pch)
|
target_precompile_headers(winsharedutils REUSE_FROM pch)
|
||||||
if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
|
if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
|
||||||
set_target_properties(winsharedutils PROPERTIES OUTPUT_NAME "winsharedutils64")
|
set_target_properties(winsharedutils PROPERTIES OUTPUT_NAME "winsharedutils64")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user