From 085a9044445adc43fbea81048c797bbc2eb6e1b1 Mon Sep 17 00:00:00 2001 From: dimedtec Date: Tue, 16 Jun 2026 12:41:05 +0200 Subject: [PATCH] Uhr: separates Fenster fuer WebView-Modus, HWND-Airspace-Fix --- ClockWindow.xaml | 16 ++++++++++++++++ ClockWindow.xaml.cs | 13 +++++++++++++ MainWindow.xaml.cs | 40 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 ClockWindow.xaml create mode 100644 ClockWindow.xaml.cs diff --git a/ClockWindow.xaml b/ClockWindow.xaml new file mode 100644 index 0000000..ef4fe54 --- /dev/null +++ b/ClockWindow.xaml @@ -0,0 +1,16 @@ + + + + + diff --git a/ClockWindow.xaml.cs b/ClockWindow.xaml.cs new file mode 100644 index 0000000..169c1ef --- /dev/null +++ b/ClockWindow.xaml.cs @@ -0,0 +1,13 @@ +using System.Windows; + +namespace FritzTV; + +public partial class ClockWindow : Window +{ + public ClockWindow() + { + InitializeComponent(); + } + + public void UpdateTime(string time) => TxtClock.Text = time; +} diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 30bf4e4..bba0f08 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -45,6 +45,7 @@ public partial class MainWindow : Window // Uhr private readonly DispatcherTimer _clockTimer; private bool _clockVisible = false; + private ClockWindow? _clockWindow; // WndProc-Hook für globale Tastatureingaben (auch wenn WebView2 Fokus hat) private System.Windows.Interop.HwndSource? _hwndSource; @@ -99,7 +100,13 @@ public partial class MainWindow : Window // Uhr-Timer (jede Sekunde) _clockTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) }; - _clockTimer.Tick += (_, _) => TxtClock.Text = DateTime.Now.ToString("HH:mm:ss"); + _clockTimer.Tick += (_, _) => + { + var time = DateTime.Now.ToString("HH:mm:ss"); + TxtClock.Text = time; + _clockWindow?.UpdateTime(time); + PositionClockWindow(); + }; Loaded += MainWindow_Loaded; Closing += MainWindow_Closing; @@ -218,6 +225,7 @@ public partial class MainWindow : Window _zapTimer.Stop(); _epgRefreshTimer.Stop(); _clockTimer.Stop(); + _clockWindow?.Close(); _player?.Stop(); _settings.LastChannel = _currentChannel?.Name ?? ""; _settings.Volume = SldVolume.Value; @@ -718,10 +726,19 @@ public partial class MainWindow : Window private void ToggleClock() { _clockVisible = !_clockVisible; + var time = DateTime.Now.ToString("HH:mm:ss"); if (_clockVisible) { - TxtClock.Text = DateTime.Now.ToString("HH:mm:ss"); + // WPF-Overlay (fuer TV-Modus innerhalb VideoView) + TxtClock.Text = time; ClockOverlay.Visibility = Visibility.Visible; + + // Separates Fenster (fuer WebView-Modus, schwebt ueber allem) + _clockWindow = new ClockWindow { Owner = this }; + _clockWindow.UpdateTime(time); + PositionClockWindow(); + _clockWindow.Show(); + _clockTimer.Start(); BtnClock.Foreground = new System.Windows.Media.SolidColorBrush( System.Windows.Media.Color.FromRgb(0x00, 0x78, 0xD4)); @@ -729,12 +746,31 @@ public partial class MainWindow : Window else { ClockOverlay.Visibility = Visibility.Collapsed; + _clockWindow?.Close(); + _clockWindow = null; _clockTimer.Stop(); BtnClock.Foreground = new System.Windows.Media.SolidColorBrush( System.Windows.Media.Color.FromRgb(0x88, 0x88, 0x88)); } } + private void PositionClockWindow() + { + if (_clockWindow == null) return; + try + { + // Oben rechts im Player-Bereich positionieren + var area = VideoView.Visibility == Visibility.Visible + ? (System.Windows.FrameworkElement)VideoView + : WebView; + var pt = area.PointToScreen(new System.Windows.Point(area.ActualWidth, 0)); + // 16px Margin, Fensterbreite abziehen (wird erst nach Show() bekannt) + _clockWindow.Left = pt.X - _clockWindow.ActualWidth - 16; + _clockWindow.Top = pt.Y + 16; + } + catch { } + } + private void ToggleFullscreen() { if (!_isFullscreen)