Skip to content

Commit f5d9155

Browse files
committed
Add Mica control in blur function
1 parent 9510a07 commit f5d9155

File tree

1 file changed

+95
-31
lines changed

1 file changed

+95
-31
lines changed

Flow.Launcher.Core/Resource/Theme.cs

Lines changed: 95 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -248,31 +248,46 @@ public void SetBlurForWindow()
248248
if (windowBorderStyle == null)
249249
return;
250250

251-
// Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, 3);
251+
// ✅ 설정된 BackdropType 확인
252+
int backdropValue = _settings.BackdropType switch
253+
{
254+
BackdropTypes.Acrylic => 2, // Acrylic (DWM_SYSTEMBACKDROP_TYPE = 2)
255+
BackdropTypes.Mica => 3, // Mica (DWM_SYSTEMBACKDROP_TYPE = 3)
256+
BackdropTypes.MicaAlt => 4, // MicaAlt (DWM_SYSTEMBACKDROP_TYPE = 4)
257+
_ => 0 // None (DWM_SYSTEMBACKDROP_TYPE = 0)
258+
};
259+
260+
Debug.WriteLine("~~~~~~~~~~~~~~~~~~~~");
261+
Debug.WriteLine($"Backdrop Mode: {BlurMode()}, DWM Value: {backdropValue}");
262+
263+
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, backdropValue);
264+
252265
if (BlurEnabled)
253266
{
254-
// mainWindow.WindowStyle = WindowStyle.SingleBorderWindow;
255-
// BlurColor(BlurMode());
256-
Debug.WriteLine("~~~~~~~~~~~~~~~~~~~~");
257-
Debug.WriteLine(BlurMode());
258-
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, 3);
259-
windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property.Name == "Background"));
260-
windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(Colors.Transparent)));
261-
// SetWindowCornerPreference("Round");
262-
ThemeModeColor(BlurMode());
267+
// ✅ Mica 또는 MicaAlt인 경우 배경을 투명하게 설정
268+
if (_settings.BackdropType == BackdropTypes.Mica || _settings.BackdropType == BackdropTypes.MicaAlt)
269+
{
270+
windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property.Name == "Background"));
271+
windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)))); // 드래그 가능 투명색
272+
}
273+
else
274+
{
275+
windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property.Name == "Background"));
276+
windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(Colors.Transparent)));
277+
}
278+
279+
ThemeModeColor(BlurMode()); // ✅ 테마 모드 적용
263280
}
264281
else
265282
{
266-
// mainWindow.WindowStyle = WindowStyle.None;
267-
// if (windowBorderStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property.Name == "Background") != null)
268-
// {
269-
// windowBorderStyle.Setters.Add(windowBorderStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property.Name == "Background"));
270-
// }
271-
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, 1);
283+
// ✅ Blur가 비활성화되면 기본 스타일 적용
284+
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, 0);
272285
}
286+
273287
UpdateResourceDictionary(dict);
274288
}
275289

290+
276291
// Get Background Color from WindowBorderStyle when there not color for BG.
277292
private Color GetWindowBorderStyleBackground()
278293
{
@@ -344,16 +359,9 @@ public void ThemeModeColor(string Mode)
344359
darkBG = lightBG; // if not darkBG, use lightBG
345360
}
346361

347-
// ✅ 백드롭 타입 확인 (Mica 또는 MicaAlt인 경우 배경을 투명으로 설정)
362+
// ✅ 백드롭 타입 확인 (Mica 또는 MicaAlt인 경우 배경을 투명하게 설정)
348363
bool isMica = _settings.BackdropType == BackdropTypes.Mica || _settings.BackdropType == BackdropTypes.MicaAlt;
349364

350-
if (isMica)
351-
{
352-
// ✅ 드래그 가능한 반투명 배경 적용
353-
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0));
354-
return;
355-
}
356-
357365
if (Mode == "Auto")
358366
{
359367
int themeValue = (int)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme", 1);
@@ -364,13 +372,29 @@ public void ThemeModeColor(string Mode)
364372
{
365373
if (isDarkMode)
366374
{
367-
mainWindow.Background = new SolidColorBrush(darkBG);
375+
if (isMica)
376+
{
377+
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)); // ✅ Mica 배경 투명 처리
378+
}
379+
else
380+
{
381+
mainWindow.Background = new SolidColorBrush(darkBG);
382+
}
383+
368384
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 1);
369385
return;
370386
}
371387
else
372388
{
373-
mainWindow.Background = new SolidColorBrush(lightBG);
389+
if (isMica)
390+
{
391+
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)); // ✅ Mica 배경 투명 처리
392+
}
393+
else
394+
{
395+
mainWindow.Background = new SolidColorBrush(lightBG);
396+
}
397+
374398
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 0);
375399
return;
376400
}
@@ -379,37 +403,77 @@ public void ThemeModeColor(string Mode)
379403
{
380404
if (colorScheme == "Dark")
381405
{
382-
mainWindow.Background = new SolidColorBrush(darkBG);
406+
if (isMica)
407+
{
408+
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)); // ✅ Mica 배경 투명 처리
409+
}
410+
else
411+
{
412+
mainWindow.Background = new SolidColorBrush(darkBG);
413+
}
414+
383415
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 1);
384416
return;
385417
}
386418
else if (colorScheme == "Light")
387419
{
388-
mainWindow.Background = new SolidColorBrush(lightBG);
420+
if (isMica)
421+
{
422+
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)); // ✅ Mica 배경 투명 처리
423+
}
424+
else
425+
{
426+
mainWindow.Background = new SolidColorBrush(lightBG);
427+
}
428+
389429
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 0);
390430
return;
391431
}
392432
}
393433
}
394434
else if (Mode == "Dark")
395435
{
396-
mainWindow.Background = new SolidColorBrush(darkBG);
436+
if (isMica)
437+
{
438+
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)); // ✅ Mica 배경 투명 처리
439+
}
440+
else
441+
{
442+
mainWindow.Background = new SolidColorBrush(darkBG);
443+
}
444+
397445
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 1);
398446
return;
399447
}
400448
else if (Mode == "Light")
401449
{
402-
mainWindow.Background = new SolidColorBrush(lightBG);
450+
if (isMica)
451+
{
452+
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)); // ✅ Mica 배경 투명 처리
453+
}
454+
else
455+
{
456+
mainWindow.Background = new SolidColorBrush(lightBG);
457+
}
458+
403459
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 0);
404460
return;
405461
}
406462
else
407463
{
408-
mainWindow.Background = new SolidColorBrush(Colors.Transparent);
464+
if (isMica)
465+
{
466+
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)); // ✅ Mica 배경 투명 처리
467+
}
468+
else
469+
{
470+
mainWindow.Background = new SolidColorBrush(Colors.Transparent);
471+
}
409472
}
410473
}
411474

412475

476+
413477
public bool IsBlurTheme()
414478
{
415479
if (Environment.OSVersion.Version >= new Version(6, 2))

0 commit comments

Comments
 (0)