feat(client): redesign native UI, themes, settings and avatars

Separate conversation drafts and voice view state, add native settings and restricted CSS themes, implement validated avatar cropping, and refresh dependencies with documented desktop compatibility backports.
This commit is contained in:
Loki 2026-10-24 14:23:48 +02:00
parent 44d284a568
commit 8e5ab56611
Signed by: boba
GPG key ID: 253067914055423B
276 changed files with 53546 additions and 3399 deletions

View file

@ -0,0 +1,220 @@
// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
use std::{num::NonZeroU32, sync::Arc};
use crate::winit_compat::WindowSurfaceSizeExt;
use glutin::{
config::GlConfig,
context::{ContextApi, ContextAttributesBuilder},
display::GetGlDisplay,
prelude::*,
surface::{SurfaceAttributesBuilder, WindowSurface},
};
use i_slint_core::{graphics::RequestedOpenGLVersion, platform::PlatformError};
use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
pub struct OpenGLContext {
context: glutin::context::PossiblyCurrentContext,
surface: glutin::surface::Surface<glutin::surface::WindowSurface>,
winit_window: Arc<winit::window::Window>,
}
unsafe impl i_slint_renderer_femtovg::opengl::OpenGLInterface for OpenGLContext {
fn ensure_current(&self) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
if !self.context.is_current() {
self.context.make_current(&self.surface).map_err(|glutin_error| -> PlatformError {
format!("FemtoVG: Error making context current: {glutin_error}").into()
})?;
}
Ok(())
}
fn swap_buffers(&self) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
self.winit_window.pre_present_notify();
self.surface.swap_buffers(&self.context).map_err(|glutin_error| -> PlatformError {
format!("FemtoVG: Error swapping buffers: {glutin_error}").into()
})?;
Ok(())
}
fn resize(
&self,
width: NonZeroU32,
height: NonZeroU32,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
self.ensure_current()?;
self.surface.resize(&self.context, width, height);
Ok(())
}
fn get_proc_address(&self, name: &std::ffi::CStr) -> *const std::ffi::c_void {
self.context.display().get_proc_address(name)
}
}
impl OpenGLContext {
pub(crate) fn new_context(
window_attributes: winit::window::WindowAttributes,
active_event_loop: &winit::event_loop::ActiveEventLoop,
requested_opengl_version: Option<RequestedOpenGLVersion>,
) -> Result<(Arc<winit::window::Window>, Self), PlatformError> {
let config_template_builder = glutin::config::ConfigTemplateBuilder::new();
// On macOS, there's only one GL config and that's initialized based on the values in the config template
// builder. So if that one has transparency enabled, it'll show up in the config, and will be set on the
// context later. So we must enable it here, there's no way of enabling it later.
// On EGL/GLX/WGL there are system provided configs that may or may not support transparency. Here in case
// the system doesn't support transparency, we want to fall back to a config that doesn't - better than not
// rendering anything at all. So we don't want to limit the configurations we get to see early on.
// Commented out due to https://github.com/rust-windowing/glutin/issues/1640
#[cfg(target_os = "macos")]
let config_template_builder = config_template_builder.with_transparency(true);
let display_builder = glutin_winit::DisplayBuilder::new()
.with_preference(glutin_winit::ApiPreference::FallbackEgl)
.with_window_attributes(Some(window_attributes.clone()));
let config_picker = |it: Box<dyn Iterator<Item = glutin::config::Config> + '_>| {
it.reduce(|accum, config| {
let transparency_check = config.supports_transparency().unwrap_or(false)
& !accum.supports_transparency().unwrap_or(false);
if transparency_check || config.num_samples() < accum.num_samples() {
config
} else {
accum
}
})
.expect("internal error: Could not find any matching GL configuration")
};
let (window, gl_config) = display_builder
.build(active_event_loop, config_template_builder, config_picker)
.map_err(|glutin_err| {
format!(
"Error creating OpenGL display ({:?}) with glutin: {}",
active_event_loop.display_handle(),
glutin_err
)
})?;
let gl_display = gl_config.display();
let raw_window_handle = window
.as_ref()
.map(|w| w.window_handle())
.transpose()
.map_err(|err| {
format!(
"Failed to retrieve a window handle while creating an OpenGL display: {err:?}"
)
})?
.map(|h| h.as_raw());
let requested_opengl_version =
requested_opengl_version.unwrap_or(RequestedOpenGLVersion::OpenGLES(Some((2, 0))));
let preferred_context_attributes = match requested_opengl_version {
RequestedOpenGLVersion::OpenGL(version) => {
let version =
version.map(|(major, minor)| glutin::context::Version { major, minor });
ContextAttributesBuilder::new()
.with_context_api(ContextApi::OpenGl(version))
.build(raw_window_handle)
}
RequestedOpenGLVersion::OpenGLES(version) => {
let version =
version.map(|(major, minor)| glutin::context::Version { major, minor });
ContextAttributesBuilder::new()
.with_context_api(ContextApi::Gles(version))
.build(raw_window_handle)
}
};
let fallback_context_attributes = ContextAttributesBuilder::new().build(raw_window_handle);
let not_current_gl_context = unsafe {
gl_display
.create_context(&gl_config, &preferred_context_attributes)
.or_else(|_| gl_display.create_context(&gl_config, &fallback_context_attributes))
.map_err(|glutin_err| format!("Cannot create OpenGL context: {glutin_err}"))?
};
let window = match window {
Some(window) => window,
None => glutin_winit::finalize_window(active_event_loop, window_attributes, &gl_config)
.map_err(|winit_os_error| {
format!("Error finalizing window for OpenGL rendering: {winit_os_error}")
})?,
};
let raw_window_handle = window.window_handle().map_err(|err| {
format!("Failed to retrieve a window handle for window we just created: {err:?}")
})?;
let size: winit::dpi::PhysicalSize<u32> = window.surface_size();
let width: std::num::NonZeroU32 = size.width.try_into().map_err(|_| {
format!(
"Attempting to create an OpenGL window surface with an invalid width: {}",
size.width
)
})?;
let height: std::num::NonZeroU32 = size.height.try_into().map_err(|_| {
format!(
"Attempting to create an OpenGL window surface with an invalid height: {}",
size.height
)
})?;
let attrs = SurfaceAttributesBuilder::<WindowSurface>::new().build(
raw_window_handle.as_raw(),
width,
height,
);
let surface = unsafe {
gl_display.create_window_surface(&gl_config, &attrs).map_err(|glutin_err| {
format!("Error creating OpenGL Window surface: {glutin_err}")
})?
};
let context = not_current_gl_context.make_current(&surface)
.map_err(|glutin_error: glutin::error::Error| -> PlatformError {
format!("FemtoVG Renderer: Failed to make newly created OpenGL context current: {glutin_error}")
.into()
})?;
// Align the GL layer to the top-left, so that resizing only invalidates the bottom/right
// part of the window.
#[cfg(target_os = "macos")]
if let raw_window_handle::RawWindowHandle::AppKit(raw_window_handle::AppKitWindowHandle {
ns_view,
..
}) = window
.window_handle()
.map_err(|e| {
format!(
"Error obtaining window handle to adjust nsview layer contents placement: {e}"
)
})?
.as_raw()
{
let ns_view: &objc2_app_kit::NSView = unsafe { ns_view.cast().as_ref() };
ns_view.setLayerContentsPlacement(objc2_app_kit::NSViewLayerContentsPlacement::TopLeft);
}
// Try to default to vsync and ignore if the driver doesn't support it.
surface
.set_swap_interval(
&context,
glutin::surface::SwapInterval::Wait(NonZeroU32::new(1).unwrap()),
)
.ok();
let window = Arc::new(window);
Ok((window.clone(), Self { context, surface, winit_window: window }))
}
}

View file

@ -0,0 +1,142 @@
// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
// cSpell: ignore clipchildren clipsiblings doublebuffer owndc
// cSpell: ignore pixelformatdescriptor wndclassw
use std::sync::OnceLock;
use windows::Win32::Foundation::{HWND, LPARAM, LRESULT, WPARAM};
use windows::Win32::Graphics::Gdi::{GetDC, HDC, ReleaseDC};
use windows::Win32::Graphics::OpenGL::{
ChoosePixelFormat, PFD_DOUBLEBUFFER, PFD_DRAW_TO_WINDOW, PFD_MAIN_PLANE, PFD_SUPPORT_OPENGL,
PFD_TYPE_RGBA, PIXELFORMATDESCRIPTOR, SetPixelFormat, wglCreateContext, wglDeleteContext,
wglGetCurrentContext, wglGetCurrentDC, wglGetProcAddress, wglMakeCurrent,
};
use windows::Win32::UI::WindowsAndMessaging::{
CS_OWNDC, CreateWindowExW, DefWindowProcW, DestroyWindow, RegisterClassW, UnregisterClassW,
WINDOW_EX_STYLE, WNDCLASSW, WS_CLIPCHILDREN, WS_CLIPSIBLINGS, WS_OVERLAPPED,
};
use windows::core::{s, w};
pub fn opengl_2_available() -> bool {
static AVAILABLE: OnceLock<bool> = OnceLock::new();
// A probe that couldn't run says nothing about the driver, and glutin may still
// reach a working one through EGL.
*AVAILABLE.get_or_init(|| unsafe { probe() }.unwrap_or(true))
}
/// Every Windows installation has an opengl32.dll, but in virtual machines it often provides
/// only OpenGL 1.1, without the shader entry points. Creating a context still succeeds there,
/// so probe with a throwaway window and context up-front.
///
/// Returns `None` if the probe couldn't run, which says nothing about the driver.
unsafe fn probe() -> Option<bool> {
unsafe {
let class_name = w!("SlintOpenGLProbe");
let window_class = WNDCLASSW {
style: CS_OWNDC,
lpfnWndProc: Some(window_proc),
lpszClassName: class_name,
..Default::default()
};
if RegisterClassW(&window_class) == 0 {
return None;
}
// WGL requires a window that clips its children and siblings.
let available = CreateWindowExW(
WINDOW_EX_STYLE::default(),
class_name,
w!(""),
WS_OVERLAPPED | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
0,
0,
1,
1,
None,
None,
None,
None,
)
.ok()
.and_then(|window| {
let available = probe_window(window);
let _ = DestroyWindow(window);
available
});
let _ = UnregisterClassW(class_name, None);
available
}
}
unsafe extern "system" fn window_proc(
window: HWND,
message: u32,
wparam: WPARAM,
lparam: LPARAM,
) -> LRESULT {
unsafe { DefWindowProcW(window, message, wparam, lparam) }
}
unsafe fn probe_window(window: HWND) -> Option<bool> {
unsafe {
let hdc = GetDC(Some(window));
if hdc.is_invalid() {
return None;
}
let available = probe_device_context(hdc);
ReleaseDC(Some(window), hdc);
available
}
}
unsafe fn probe_device_context(hdc: HDC) -> Option<bool> {
unsafe {
let pixel_format_descriptor = PIXELFORMATDESCRIPTOR {
nSize: std::mem::size_of::<PIXELFORMATDESCRIPTOR>() as u16,
nVersion: 1,
dwFlags: PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
iPixelType: PFD_TYPE_RGBA,
cColorBits: 32,
cDepthBits: 24,
iLayerType: PFD_MAIN_PLANE.0 as u8,
..Default::default()
};
let pixel_format = ChoosePixelFormat(hdc, &pixel_format_descriptor);
if pixel_format == 0 {
return None;
}
SetPixelFormat(hdc, pixel_format, &pixel_format_descriptor).ok()?;
let context = wglCreateContext(hdc).ok()?;
// Restore whatever was current before, so that probing from a thread that already
// renders through WGL is harmless.
let previous_context = wglGetCurrentContext();
let previous_hdc = wglGetCurrentDC();
let available = wglMakeCurrent(hdc, context).is_ok().then(|| {
let address = wglGetProcAddress(s!("glCreateShader")).map_or(0, |entry| entry as usize);
let _ = wglMakeCurrent(previous_hdc, previous_context);
// Besides null, some drivers report a missing entry point as 1, 2, 3 or -1.
!matches!(address, 0 | 1 | 2 | 3 | usize::MAX)
});
let _ = wglDeleteContext(context);
available
}
}
#[test]
fn probe_runs() {
// The answer depends on the machine, so this only covers the probe running to completion.
opengl_2_available();
}