Skip to content

Commit 1c79d51

Browse files
committed
Fix Change Theme render timing
1 parent 4fd5e15 commit 1c79d51

File tree

2 files changed

+107
-78
lines changed

2 files changed

+107
-78
lines changed

Flow.Launcher.Core/Resource/Theme.cs

Lines changed: 103 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ public void RefreshFrame()
140140
if (mainWindowSrc == null)
141141
return;
142142

143-
ParameterTypes.MARGINS margins = new ParameterTypes.MARGINS();
144-
margins.cxLeftWidth = -1;
145-
margins.cxRightWidth = -1;
146-
margins.cyTopHeight = -1;
147-
margins.cyBottomHeight = -1;
148-
Methods.ExtendFrame(mainWindowSrc.Handle, margins);
143+
//ParameterTypes.MARGINS margins = new ParameterTypes.MARGINS();
144+
//margins.cxLeftWidth = -1;
145+
//margins.cxRightWidth = -1;
146+
//margins.cyTopHeight = -1;
147+
//margins.cyBottomHeight = -1;
148+
//Methods.ExtendFrame(mainWindowSrc.Handle, margins);
149149

150150
// Remove OS minimizing/maximizing animation
151151
// Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_TRANSITIONS_FORCEDISABLED, 3);
@@ -251,16 +251,16 @@ public void SetBlurForWindow()
251251
// ✅ 설정된 BackdropType 확인
252252
int backdropValue = _settings.BackdropType switch
253253
{
254-
BackdropTypes.Acrylic => 2, // Acrylic (DWM_SYSTEMBACKDROP_TYPE = 2)
255-
BackdropTypes.Mica => 3, // Mica (DWM_SYSTEMBACKDROP_TYPE = 3)
254+
BackdropTypes.Acrylic => 3, // Acrylic (DWM_SYSTEMBACKDROP_TYPE = 2)
255+
BackdropTypes.Mica => 2, // Mica (DWM_SYSTEMBACKDROP_TYPE = 3)
256256
BackdropTypes.MicaAlt => 4, // MicaAlt (DWM_SYSTEMBACKDROP_TYPE = 4)
257257
_ => 0 // None (DWM_SYSTEMBACKDROP_TYPE = 0)
258258
};
259259

260260
Debug.WriteLine("~~~~~~~~~~~~~~~~~~~~");
261261
Debug.WriteLine($"Backdrop Mode: {BlurMode()}, DWM Value: {backdropValue}");
262262

263-
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, backdropValue);
263+
264264

265265
if (BlurEnabled)
266266
{
@@ -269,19 +269,24 @@ public void SetBlurForWindow()
269269
{
270270
windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property.Name == "Background"));
271271
windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)))); // 드래그 가능 투명색
272+
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, backdropValue);
273+
ThemeModeColorforMica(BlurMode()); // ✅ 테마 모드 적용
272274
}
273275
else if (_settings.BackdropType == BackdropTypes.Acrylic)
274276
{
275277
windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property.Name == "Background"));
276278
windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(Colors.Transparent)));
279+
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, 3);
280+
ThemeModeColor(BlurMode()); // ✅ 테마 모드 적용
277281
}
278282
else
279283
{
284+
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, backdropValue);
285+
ThemeModeColor(BlurMode()); // ✅ 테마 모드 적용
280286
//windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property.Name == "Background"));
281287
//windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(Colors.Transparent)));
282288
}
283-
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, backdropValue);
284-
ThemeModeColor(BlurMode()); // ✅ 테마 모드 적용
289+
285290
}
286291
else
287292
{
@@ -364,9 +369,6 @@ public void ThemeModeColor(string Mode)
364369
darkBG = lightBG; // if not darkBG, use lightBG
365370
}
366371

367-
// ✅ 백드롭 타입 확인 (Mica 또는 MicaAlt인 경우 배경을 투명하게 설정)
368-
bool isMica = _settings.BackdropType == BackdropTypes.Mica || _settings.BackdropType == BackdropTypes.MicaAlt;
369-
370372
if (Mode == "Auto")
371373
{
372374
int themeValue = (int)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme", 1);
@@ -377,29 +379,13 @@ public void ThemeModeColor(string Mode)
377379
{
378380
if (isDarkMode)
379381
{
380-
if (isMica)
381-
{
382-
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)); // ✅ Mica 배경 투명 처리
383-
}
384-
else
385-
{
386-
mainWindow.Background = new SolidColorBrush(darkBG);
387-
}
388-
382+
mainWindow.Background = new SolidColorBrush(darkBG);
389383
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 1);
390384
return;
391385
}
392386
else
393387
{
394-
if (isMica)
395-
{
396-
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)); // ✅ Mica 배경 투명 처리
397-
}
398-
else
399-
{
400-
mainWindow.Background = new SolidColorBrush(lightBG);
401-
}
402-
388+
mainWindow.Background = new SolidColorBrush(lightBG);
403389
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 0);
404390
return;
405391
}
@@ -408,77 +394,120 @@ public void ThemeModeColor(string Mode)
408394
{
409395
if (colorScheme == "Dark")
410396
{
411-
if (isMica)
412-
{
413-
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)); // ✅ Mica 배경 투명 처리
414-
}
415-
else
416-
{
417-
mainWindow.Background = new SolidColorBrush(darkBG);
418-
}
419-
397+
mainWindow.Background = new SolidColorBrush(darkBG);
420398
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 1);
421399
return;
422400
}
423401
else if (colorScheme == "Light")
424402
{
425-
if (isMica)
426-
{
427-
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)); // ✅ Mica 배경 투명 처리
428-
}
429-
else
430-
{
431-
mainWindow.Background = new SolidColorBrush(lightBG);
432-
}
433-
403+
mainWindow.Background = new SolidColorBrush(lightBG);
434404
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 0);
435405
return;
436406
}
437407
}
438408
}
439409
else if (Mode == "Dark")
440410
{
441-
if (isMica)
442-
{
443-
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)); // ✅ Mica 배경 투명 처리
444-
}
445-
else
446-
{
447-
mainWindow.Background = new SolidColorBrush(darkBG);
448-
}
449-
411+
mainWindow.Background = new SolidColorBrush(darkBG);
450412
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 1);
451413
return;
452414
}
453415
else if (Mode == "Light")
454416
{
455-
if (isMica)
456-
{
457-
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)); // ✅ Mica 배경 투명 처리
458-
}
459-
else
460-
{
461-
mainWindow.Background = new SolidColorBrush(lightBG);
462-
}
463-
417+
mainWindow.Background = new SolidColorBrush(lightBG);
464418
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 0);
465419
return;
466420
}
467421
else
468422
{
469-
if (isMica)
423+
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0));
424+
}
425+
}
426+
427+
public void ThemeModeColorforMica(string Mode)
428+
{
429+
var dict = GetThemeResourceDictionary(_settings.Theme);
430+
431+
Color lightBG;
432+
Color darkBG;
433+
434+
// get lightBG value. if not, get windowborderstyle's background.
435+
try
436+
{
437+
lightBG = dict.Contains("lightBG") ? (Color)dict["lightBG"] : GetWindowBorderStyleBackground();
438+
}
439+
catch (Exception)
440+
{
441+
// if not lightBG, use windowborderstyle's background.
442+
lightBG = GetWindowBorderStyleBackground();
443+
}
444+
445+
// get darkBG value, (if not, use lightBG)
446+
try
447+
{
448+
darkBG = dict.Contains("darkBG") ? (Color)dict["darkBG"] : lightBG;
449+
}
450+
catch (Exception)
451+
{
452+
darkBG = lightBG; // if not darkBG, use lightBG
453+
}
454+
455+
if (Mode == "Auto")
456+
{
457+
int themeValue = (int)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme", 1);
458+
string colorScheme = _settings.ColorScheme;
459+
bool isDarkMode = themeValue == 0; // 0 is dark mode.
460+
461+
if (colorScheme == "System")
470462
{
471-
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)); // ✅ Mica 배경 투명 처리
463+
if (isDarkMode)
464+
{
465+
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0));
466+
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 1);
467+
return;
468+
}
469+
else
470+
{
471+
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0));
472+
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 0);
473+
return;
474+
}
472475
}
473476
else
474477
{
475-
mainWindow.Background = new SolidColorBrush(Colors.Transparent);
478+
if (colorScheme == "Dark")
479+
{
480+
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0));
481+
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 1);
482+
return;
483+
}
484+
else if (colorScheme == "Light")
485+
{
486+
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0));
487+
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 0);
488+
return;
489+
}
476490
}
477491
}
492+
else if (Mode == "Dark")
493+
{
494+
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0));
495+
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 1);
496+
return;
497+
}
498+
else if (Mode == "Light")
499+
{
500+
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0));
501+
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 0);
502+
return;
503+
}
504+
else
505+
{
506+
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0));
507+
}
478508
}
479509

480510

481-
482511
public bool IsBlurTheme()
483512
{
484513
if (Environment.OSVersion.Version >= new Version(6, 2))
@@ -549,8 +578,8 @@ public bool ChangeTheme(string theme)
549578
}
550579

551580
BlurEnabled = Win32Helper.IsBlurTheme();
552-
if (_settings.UseDropShadowEffect)
553-
AddDropShadowEffectToCurrentTheme();
581+
//if (_settings.UseDropShadowEffect)
582+
// AddDropShadowEffectToCurrentTheme();
554583

555584

556585

Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public Theme.ThemeData SelectedTheme
3939

4040
if (ThemeManager.Instance.BlurEnabled && Settings.UseDropShadowEffect == false)
4141
DropShadowEffect = true;
42-
ThemeManager.Instance.RefreshFrame();
43-
//ThemeManager.Instance.SetBlurForWindow();
42+
//ThemeManager.Instance.RefreshFrame();
43+
ThemeManager.Instance.SetBlurForWindow();
4444
}
4545
}
4646

@@ -194,8 +194,8 @@ public void ApplyBackdrop()
194194
BackdropTypes.MicaAlt => 4, // ✅ MicaAlt (DWM_SYSTEMBACKDROP_TYPE = 4)
195195
_ => 0 // ✅ None (DWM_SYSTEMBACKDROP_TYPE = 0)
196196
};
197-
198-
Methods.SetWindowAttribute(hWnd, ParameterTypes.DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, backdropValue);
197+
ThemeManager.Instance.SetBlurForWindow();
198+
//Methods.SetWindowAttribute(hWnd, ParameterTypes.DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, backdropValue);
199199
}
200200
}
201201

0 commit comments

Comments
 (0)