2025-12-19 09:30:16 +00:00
|
|
|
// Licensed to the .NET Foundation under one or more agreements.
|
|
|
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
|
|
|
|
|
|
|
|
using Microsoft.Maui.Handlers;
|
|
|
|
|
using Microsoft.Maui.Graphics;
|
|
|
|
|
using SkiaSharp;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.Maui.Platform.Linux.Handlers;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handler for Switch on Linux using Skia rendering.
|
|
|
|
|
/// Maps ISwitch interface to SkiaSwitch platform view.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class SwitchHandler : ViewHandler<ISwitch, SkiaSwitch>
|
|
|
|
|
{
|
|
|
|
|
public static IPropertyMapper<ISwitch, SwitchHandler> Mapper = new PropertyMapper<ISwitch, SwitchHandler>(ViewHandler.ViewMapper)
|
|
|
|
|
{
|
|
|
|
|
[nameof(ISwitch.IsOn)] = MapIsOn,
|
|
|
|
|
[nameof(ISwitch.TrackColor)] = MapTrackColor,
|
|
|
|
|
[nameof(ISwitch.ThumbColor)] = MapThumbColor,
|
|
|
|
|
[nameof(IView.Background)] = MapBackground,
|
Major production merge: GTK support, context menus, and dispatcher fixes
Core Infrastructure:
- Add Dispatching folder with LinuxDispatcher, LinuxDispatcherProvider, LinuxDispatcherTimer
- Add Native folder with P/Invoke wrappers (GTK, GLib, GDK, Cairo, WebKit)
- Add GTK host window system with GtkHostWindow and GtkSkiaSurfaceWidget
- Update LinuxApplication with GTK mode, theme handling, and icon support
- Fix duplicate LinuxDispatcher in LinuxMauiContext
Handlers:
- Add GtkWebViewManager and GtkWebViewPlatformView for GTK WebView
- Add FlexLayoutHandler and GestureManager
- Update multiple handlers with ToViewHandler fix and missing mappers
- Add MauiHandlerExtensions with ToViewHandler extension method
Views:
- Add SkiaContextMenu with hover, keyboard, and dark theme support
- Add LinuxDialogService with context menu management
- Add SkiaFlexLayout for flex container support
- Update SkiaShell with RefreshTheme, MauiShell, ContentRenderer
- Update SkiaWebView with SetMainWindow, ProcessGtkEvents
- Update SkiaImage with LoadFromBitmap method
Services:
- Add AppInfoService, ConnectivityService, DeviceDisplayService, DeviceInfoService
- Add GtkHostService, GtkContextMenuService, MauiIconGenerator
Window:
- Add CursorType enum and GtkHostWindow
- Update X11Window with SetIcon, SetCursor methods
Build: SUCCESS (0 errors)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 11:19:58 -05:00
|
|
|
[nameof(IView.IsEnabled)] = MapIsEnabled,
|
2025-12-19 09:30:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static CommandMapper<ISwitch, SwitchHandler> CommandMapper = new(ViewHandler.ViewCommandMapper)
|
|
|
|
|
{
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public SwitchHandler() : base(Mapper, CommandMapper)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SwitchHandler(IPropertyMapper? mapper, CommandMapper? commandMapper = null)
|
|
|
|
|
: base(mapper ?? Mapper, commandMapper ?? CommandMapper)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override SkiaSwitch CreatePlatformView()
|
|
|
|
|
{
|
|
|
|
|
return new SkiaSwitch();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void ConnectHandler(SkiaSwitch platformView)
|
|
|
|
|
{
|
|
|
|
|
base.ConnectHandler(platformView);
|
|
|
|
|
platformView.Toggled += OnToggled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void DisconnectHandler(SkiaSwitch platformView)
|
|
|
|
|
{
|
|
|
|
|
platformView.Toggled -= OnToggled;
|
|
|
|
|
base.DisconnectHandler(platformView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnToggled(object? sender, Platform.ToggledEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (VirtualView is not null && VirtualView.IsOn != e.Value)
|
|
|
|
|
{
|
|
|
|
|
VirtualView.IsOn = e.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapIsOn(SwitchHandler handler, ISwitch @switch)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
handler.PlatformView.IsOn = @switch.IsOn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapTrackColor(SwitchHandler handler, ISwitch @switch)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
|
2026-01-16 04:54:18 +00:00
|
|
|
// TrackColor sets the On track color (MAUI's OnColor)
|
2025-12-19 09:30:16 +00:00
|
|
|
if (@switch.TrackColor is not null)
|
|
|
|
|
{
|
2026-01-16 04:54:18 +00:00
|
|
|
handler.PlatformView.OnTrackColor = @switch.TrackColor;
|
|
|
|
|
// Off track is a lighter/desaturated version
|
|
|
|
|
handler.PlatformView.OffTrackColor = @switch.TrackColor.WithAlpha(0.5f);
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapThumbColor(SwitchHandler handler, ISwitch @switch)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
|
|
|
|
|
if (@switch.ThumbColor is not null)
|
2026-01-16 04:54:18 +00:00
|
|
|
handler.PlatformView.ThumbColor = @switch.ThumbColor;
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapBackground(SwitchHandler handler, ISwitch @switch)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
|
|
|
|
|
if (@switch.Background is SolidPaint solidPaint && solidPaint.Color is not null)
|
|
|
|
|
{
|
2026-01-16 04:54:18 +00:00
|
|
|
// Background color for the switch container (not the track)
|
2026-01-17 03:10:29 +00:00
|
|
|
handler.PlatformView.BackgroundColor = solidPaint.Color;
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
Major production merge: GTK support, context menus, and dispatcher fixes
Core Infrastructure:
- Add Dispatching folder with LinuxDispatcher, LinuxDispatcherProvider, LinuxDispatcherTimer
- Add Native folder with P/Invoke wrappers (GTK, GLib, GDK, Cairo, WebKit)
- Add GTK host window system with GtkHostWindow and GtkSkiaSurfaceWidget
- Update LinuxApplication with GTK mode, theme handling, and icon support
- Fix duplicate LinuxDispatcher in LinuxMauiContext
Handlers:
- Add GtkWebViewManager and GtkWebViewPlatformView for GTK WebView
- Add FlexLayoutHandler and GestureManager
- Update multiple handlers with ToViewHandler fix and missing mappers
- Add MauiHandlerExtensions with ToViewHandler extension method
Views:
- Add SkiaContextMenu with hover, keyboard, and dark theme support
- Add LinuxDialogService with context menu management
- Add SkiaFlexLayout for flex container support
- Update SkiaShell with RefreshTheme, MauiShell, ContentRenderer
- Update SkiaWebView with SetMainWindow, ProcessGtkEvents
- Update SkiaImage with LoadFromBitmap method
Services:
- Add AppInfoService, ConnectivityService, DeviceDisplayService, DeviceInfoService
- Add GtkHostService, GtkContextMenuService, MauiIconGenerator
Window:
- Add CursorType enum and GtkHostWindow
- Update X11Window with SetIcon, SetCursor methods
Build: SUCCESS (0 errors)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 11:19:58 -05:00
|
|
|
|
|
|
|
|
public static void MapIsEnabled(SwitchHandler handler, ISwitch @switch)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
handler.PlatformView.IsEnabled = @switch.IsEnabled;
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|