| | |
| | | private bool _resizing; |
| | | private DisplayLayer? _lastDisplayLayer; |
| | | private bool _desktopLayerAttached; |
| | | private WidgetSessionOverlay _session = WidgetSessionOverlay.Empty; |
| | | |
| | | public WidgetWindow( |
| | | PluginDescriptor plugin, |
| | |
| | | |
| | | public async Task LoadAsync(CancellationToken cancellationToken = default) |
| | | { |
| | | ApplyLayout(_layout, _editMode, _safeInputMode); |
| | | ApplyLayout(_layout, _editMode, _safeInputMode, _session); |
| | | await _webView.InitializeAsync(new WebViewHostOptions |
| | | { |
| | | UserDataFolder = Path.Combine(_paths.WebViewDataDirectory, "widgets", _layout.InstanceId.Value), |
| | |
| | | await _webView.DispatchLifecycleEventAsync("moli:widget-loaded", ToRuntimeState(), cancellationToken).ConfigureAwait(true); |
| | | } |
| | | |
| | | public void ApplyLayout(WidgetLayout layout, bool editMode, bool safeInputMode) |
| | | public void ApplyLayout(WidgetLayout layout, bool editMode, bool safeInputMode, WidgetSessionOverlay? session = null) |
| | | { |
| | | _layout = layout; |
| | | _editMode = editMode; |
| | | _safeInputMode = safeInputMode; |
| | | if (session is not null) |
| | | { |
| | | _session = session; |
| | | } |
| | | |
| | | Left = layout.Bounds.X; |
| | | Top = layout.Bounds.Y; |
| | | Width = layout.Bounds.Width; |
| | | Height = Math.Max(layout.Bounds.Height, _requestedHeight ?? layout.Bounds.Height); |
| | | Opacity = Math.Clamp(layout.Opacity, 0.1, 1.0); |
| | | Visibility = layout.IsVisible ? Visibility.Visible : Visibility.Hidden; |
| | | Visibility = WidgetSurfaceRules.ComputeVisible(_session, layout.IsVisible) ? Visibility.Visible : Visibility.Hidden; |
| | | Topmost = layout.DisplayLayer == DisplayLayer.GlobalTop; |
| | | _editBorder.Visibility = editMode ? Visibility.Visible : Visibility.Collapsed; |
| | | _resizeGrip.Visibility = editMode && !layout.IsLocked ? Visibility.Visible : Visibility.Collapsed; |
| | | ApplyWin32Styles(); |
| | | } |
| | | |
| | | public async Task ApplySessionOverlayAsync( |
| | | WidgetSessionOverlay overlay, |
| | | bool editMode, |
| | | bool safeInputMode, |
| | | CancellationToken cancellationToken = default) |
| | | { |
| | | var wasInteractable = _session.Interactable == true; |
| | | ApplyLayout(_layout, editMode, safeInputMode, overlay); |
| | | var enabled = overlay.Interactable == true; |
| | | if (enabled && !wasInteractable) |
| | | { |
| | | Activate(); |
| | | } |
| | | |
| | | await _webView.DispatchLifecycleEventAsync("moli:interactable-changed", new { enabled }, cancellationToken).ConfigureAwait(true); |
| | | } |
| | | |
| | | public void ApplyRequestedSize(double? width, double? height) |
| | |
| | | ? height.Value |
| | | : null; |
| | | Height = Math.Max(_layout.Bounds.Height, _requestedHeight ?? _layout.Bounds.Height); |
| | | _ = _webView.NotifyParentWindowPositionChangedAsync(); |
| | | } |
| | | |
| | | public Task SetEditModeAsync(bool enabled, CancellationToken cancellationToken = default) |
| | | { |
| | | ApplyLayout(_layout, enabled, _safeInputMode); |
| | | ApplyLayout(_layout, enabled, _safeInputMode, _session); |
| | | return _webView.DispatchLifecycleEventAsync("moli:edit-mode-changed", new { enabled }, cancellationToken); |
| | | } |
| | | |
| | |
| | | PluginId = _layout.PluginId, |
| | | Bounds = _layout.Bounds, |
| | | MonitorId = _layout.MonitorId, |
| | | IsVisible = _layout.IsVisible, |
| | | IsVisible = WidgetSurfaceRules.ComputeVisible(_session, _layout.IsVisible), |
| | | LayoutIsVisible = _layout.IsVisible, |
| | | IsLocked = _layout.IsLocked, |
| | | Opacity = _layout.Opacity, |
| | | ClickThrough = _layout.ClickThrough, |
| | | ClickThrough = WidgetSurfaceRules.ComputeClickThrough(_editMode, _safeInputMode, _session, _layout.ClickThrough), |
| | | LayoutClickThrough = _layout.ClickThrough, |
| | | IsInteractable = _session.Interactable == true, |
| | | HasSessionInteractable = _session.HasInteractableOverride, |
| | | DisplayLayer = _layout.DisplayLayer |
| | | }; |
| | | |
| | |
| | | { |
| | | _interop.SetToolWindow(hwnd, true); |
| | | _interop.SetLayered(hwnd, true); |
| | | _interop.SetClickThrough(hwnd, !_editMode && !_safeInputMode && _layout.ClickThrough); |
| | | _interop.SetClickThrough( |
| | | hwnd, |
| | | WidgetSurfaceRules.ComputeClickThrough(_editMode, _safeInputMode, _session, _layout.ClickThrough)); |
| | | |
| | | var currentLayer = _layout.DisplayLayer; |
| | | var layerChanged = currentLayer != _lastDisplayLayer; |