|
18 | 18 | class Window::Impl { |
19 | 19 | public: |
20 | 20 | Impl(WindowId id, NSWindow* window) |
21 | | - : id_(id), ns_window_(window), title_bar_style_(TitleBarStyle::Normal) {} |
| 21 | + : id_(id), |
| 22 | + ns_window_(window), |
| 23 | + title_bar_style_(TitleBarStyle::Normal), |
| 24 | + visual_effect_(VisualEffect::None), |
| 25 | + visual_effect_view_(nil) {} |
22 | 26 | WindowId id_; |
23 | 27 | NSWindow* ns_window_; |
24 | 28 | TitleBarStyle title_bar_style_; |
| 29 | + VisualEffect visual_effect_; |
| 30 | + NSVisualEffectView* visual_effect_view_; |
25 | 31 | }; |
26 | 32 |
|
27 | 33 | Window::Window() : Window(nullptr) {} |
|
414 | 420 | return [pimpl_->ns_window_ alphaValue]; |
415 | 421 | } |
416 | 422 |
|
| 423 | +void Window::SetVisualEffect(VisualEffect effect) { |
| 424 | + if (pimpl_->visual_effect_ == effect) |
| 425 | + return; |
| 426 | + |
| 427 | + pimpl_->visual_effect_ = effect; |
| 428 | + NSWindow* window = pimpl_->ns_window_; |
| 429 | + |
| 430 | + if (effect == VisualEffect::None) { |
| 431 | + if (pimpl_->visual_effect_view_) { |
| 432 | + [pimpl_->visual_effect_view_ removeFromSuperview]; |
| 433 | + pimpl_->visual_effect_view_ = nil; |
| 434 | + } |
| 435 | + [window setOpaque:YES]; |
| 436 | + [window setBackgroundColor:[NSColor windowBackgroundColor]]; |
| 437 | + return; |
| 438 | + } |
| 439 | + |
| 440 | + if (!pimpl_->visual_effect_view_) { |
| 441 | + NSView* contentView = [window contentView]; |
| 442 | + pimpl_->visual_effect_view_ = [[NSVisualEffectView alloc] initWithFrame:[contentView bounds]]; |
| 443 | + [pimpl_->visual_effect_view_ setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 444 | + [pimpl_->visual_effect_view_ setBlendingMode:NSVisualEffectBlendingModeBehindWindow]; |
| 445 | + [contentView addSubview:pimpl_->visual_effect_view_ positioned:NSWindowBelow relativeTo:nil]; |
| 446 | + } |
| 447 | + |
| 448 | + [window setOpaque:NO]; |
| 449 | + [window setBackgroundColor:[NSColor clearColor]]; |
| 450 | + |
| 451 | + switch (effect) { |
| 452 | + case VisualEffect::Blur: |
| 453 | + [pimpl_->visual_effect_view_ setMaterial:NSVisualEffectMaterialSidebar]; |
| 454 | + break; |
| 455 | + case VisualEffect::Acrylic: |
| 456 | + [pimpl_->visual_effect_view_ setMaterial:NSVisualEffectMaterialUnderWindowBackground]; |
| 457 | + break; |
| 458 | + case VisualEffect::Mica: |
| 459 | + [pimpl_->visual_effect_view_ setMaterial:NSVisualEffectMaterialWindowBackground]; |
| 460 | + break; |
| 461 | + default: |
| 462 | + break; |
| 463 | + } |
| 464 | + |
| 465 | + [pimpl_->visual_effect_view_ setState:NSVisualEffectStateActive]; |
| 466 | +} |
| 467 | + |
| 468 | +VisualEffect Window::GetVisualEffect() const { |
| 469 | + return pimpl_->visual_effect_; |
| 470 | +} |
| 471 | + |
417 | 472 | void Window::SetVisibleOnAllWorkspaces(bool is_visible_on_all_workspaces) { |
418 | 473 | [pimpl_->ns_window_ setCollectionBehavior:is_visible_on_all_workspaces |
419 | 474 | ? NSWindowCollectionBehaviorCanJoinAllSpaces |
|
0 commit comments