mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 21:31:29 +11:00
Unify with_app_id
and with_class
methods
Both APIs are used to set application name. This commit unifies the API between Wayland and X11, so downstream applications can remove platform specific code when using `WindowBuilderExtUnix`. Fixes #1739.
This commit is contained in:
parent
bf366cb99d
commit
cbba00d360
|
@ -37,6 +37,7 @@ And please only add new entries to the top of this list, right below the `# Unre
|
||||||
- On Wayland, fix `TouchPhase::Ended` always reporting the location of the first touch down, unless the compositor
|
- On Wayland, fix `TouchPhase::Ended` always reporting the location of the first touch down, unless the compositor
|
||||||
sent a cancel or frame event.
|
sent a cancel or frame event.
|
||||||
- On iOS, send `RedrawEventsCleared` even if there are no redraw events, consistent with other platforms.
|
- On iOS, send `RedrawEventsCleared` even if there are no redraw events, consistent with other platforms.
|
||||||
|
- **Breaking:** Replaced `Window::with_app_id` and `Window::with_class` with `Window::with_name` on `WindowBuilderExtUnix`.
|
||||||
|
|
||||||
# 0.26.1 (2022-01-05)
|
# 0.26.1 (2022-01-05)
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,8 @@ use crate::dpi::Size;
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
use crate::platform_impl::x11::{ffi::XVisualInfo, XConnection};
|
use crate::platform_impl::x11::{ffi::XVisualInfo, XConnection};
|
||||||
use crate::platform_impl::{
|
use crate::platform_impl::{
|
||||||
Backend, EventLoopWindowTarget as LinuxEventLoopWindowTarget, Window as LinuxWindow,
|
ApplicationName, Backend, EventLoopWindowTarget as LinuxEventLoopWindowTarget,
|
||||||
|
Window as LinuxWindow,
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: stupid hack so that glutin can do its work
|
// TODO: stupid hack so that glutin can do its work
|
||||||
|
@ -270,21 +271,34 @@ impl WindowExtUnix for Window {
|
||||||
pub trait WindowBuilderExtUnix {
|
pub trait WindowBuilderExtUnix {
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
fn with_x11_visual<T>(self, visual_infos: *const T) -> Self;
|
fn with_x11_visual<T>(self, visual_infos: *const T) -> Self;
|
||||||
|
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
fn with_x11_screen(self, screen_id: i32) -> Self;
|
fn with_x11_screen(self, screen_id: i32) -> Self;
|
||||||
|
|
||||||
/// Build window with `WM_CLASS` hint; defaults to the name of the binary. Only relevant on X11.
|
/// Build window with the given `general` and `instance` names.
|
||||||
#[cfg(feature = "x11")]
|
///
|
||||||
fn with_class(self, class: String, instance: String) -> Self;
|
/// On Wayland, the `general` name sets an application ID, which should match the `.desktop`
|
||||||
|
/// file destributed with your program. The `instance` is a `no-op`.
|
||||||
|
///
|
||||||
|
/// On X11, the `general` sets general class of `WM_CLASS(STRING)`, while `instance` set the
|
||||||
|
/// instance part of it. The resulted property looks like `WM_CLASS(STRING) = "general", "instance"`.
|
||||||
|
///
|
||||||
|
/// For details about application ID conventions, see the
|
||||||
|
/// [Desktop Entry Spec](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#desktop-file-id)
|
||||||
|
fn with_name(self, general: impl Into<String>, instance: impl Into<String>) -> Self;
|
||||||
|
|
||||||
/// Build window with override-redirect flag; defaults to false. Only relevant on X11.
|
/// Build window with override-redirect flag; defaults to false. Only relevant on X11.
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
fn with_override_redirect(self, override_redirect: bool) -> Self;
|
fn with_override_redirect(self, override_redirect: bool) -> Self;
|
||||||
|
|
||||||
/// Build window with `_NET_WM_WINDOW_TYPE` hints; defaults to `Normal`. Only relevant on X11.
|
/// Build window with `_NET_WM_WINDOW_TYPE` hints; defaults to `Normal`. Only relevant on X11.
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
fn with_x11_window_type(self, x11_window_type: Vec<XWindowType>) -> Self;
|
fn with_x11_window_type(self, x11_window_type: Vec<XWindowType>) -> Self;
|
||||||
|
|
||||||
/// Build window with `_GTK_THEME_VARIANT` hint set to the specified value. Currently only relevant on X11.
|
/// Build window with `_GTK_THEME_VARIANT` hint set to the specified value. Currently only relevant on X11.
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
fn with_gtk_theme_variant(self, variant: String) -> Self;
|
fn with_gtk_theme_variant(self, variant: String) -> Self;
|
||||||
|
|
||||||
/// Build window with resize increment hint. Only implemented on X11.
|
/// Build window with resize increment hint. Only implemented on X11.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -299,6 +313,7 @@ pub trait WindowBuilderExtUnix {
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
fn with_resize_increments<S: Into<Size>>(self, increments: S) -> Self;
|
fn with_resize_increments<S: Into<Size>>(self, increments: S) -> Self;
|
||||||
|
|
||||||
/// Build window with base size hint. Only implemented on X11.
|
/// Build window with base size hint. Only implemented on X11.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -313,14 +328,6 @@ pub trait WindowBuilderExtUnix {
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
fn with_base_size<S: Into<Size>>(self, base_size: S) -> Self;
|
fn with_base_size<S: Into<Size>>(self, base_size: S) -> Self;
|
||||||
|
|
||||||
/// Build window with a given application ID. It should match the `.desktop` file distributed with
|
|
||||||
/// your program. Only relevant on Wayland.
|
|
||||||
///
|
|
||||||
/// For details about application ID conventions, see the
|
|
||||||
/// [Desktop Entry Spec](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#desktop-file-id)
|
|
||||||
#[cfg(feature = "wayland")]
|
|
||||||
fn with_app_id<T: Into<String>>(self, app_id: T) -> Self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WindowBuilderExtUnix for WindowBuilder {
|
impl WindowBuilderExtUnix for WindowBuilder {
|
||||||
|
@ -342,9 +349,8 @@ impl WindowBuilderExtUnix for WindowBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(feature = "x11")]
|
fn with_name(mut self, general: impl Into<String>, instance: impl Into<String>) -> Self {
|
||||||
fn with_class(mut self, instance: String, class: String) -> Self {
|
self.platform_specific.name = Some(ApplicationName::new(general.into(), instance.into()));
|
||||||
self.platform_specific.class = Some((instance, class));
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,13 +388,6 @@ impl WindowBuilderExtUnix for WindowBuilder {
|
||||||
self.platform_specific.base_size = Some(base_size.into());
|
self.platform_specific.base_size = Some(base_size.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
#[cfg(feature = "wayland")]
|
|
||||||
fn with_app_id<T: Into<String>>(mut self, app_id: T) -> Self {
|
|
||||||
self.platform_specific.app_id = Some(app_id.into());
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Additional methods on `MonitorHandle` that are specific to Linux.
|
/// Additional methods on `MonitorHandle` that are specific to Linux.
|
||||||
|
|
|
@ -72,8 +72,21 @@ impl Default for PlatformSpecificEventLoopAttributes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub struct ApplicationName {
|
||||||
|
pub general: String,
|
||||||
|
pub instance: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ApplicationName {
|
||||||
|
pub fn new(general: String, instance: String) -> Self {
|
||||||
|
Self { general, instance }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct PlatformSpecificWindowBuilderAttributes {
|
pub struct PlatformSpecificWindowBuilderAttributes {
|
||||||
|
pub name: Option<ApplicationName>,
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
pub visual_infos: Option<XVisualInfo>,
|
pub visual_infos: Option<XVisualInfo>,
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
|
@ -83,20 +96,17 @@ pub struct PlatformSpecificWindowBuilderAttributes {
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
pub base_size: Option<Size>,
|
pub base_size: Option<Size>,
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
pub class: Option<(String, String)>,
|
|
||||||
#[cfg(feature = "x11")]
|
|
||||||
pub override_redirect: bool,
|
pub override_redirect: bool,
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
pub x11_window_types: Vec<XWindowType>,
|
pub x11_window_types: Vec<XWindowType>,
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
pub gtk_theme_variant: Option<String>,
|
pub gtk_theme_variant: Option<String>,
|
||||||
#[cfg(feature = "wayland")]
|
|
||||||
pub app_id: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for PlatformSpecificWindowBuilderAttributes {
|
impl Default for PlatformSpecificWindowBuilderAttributes {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
name: None,
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
visual_infos: None,
|
visual_infos: None,
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
|
@ -106,15 +116,11 @@ impl Default for PlatformSpecificWindowBuilderAttributes {
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
base_size: None,
|
base_size: None,
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
class: None,
|
|
||||||
#[cfg(feature = "x11")]
|
|
||||||
override_redirect: false,
|
override_redirect: false,
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
x11_window_types: vec![XWindowType::Normal],
|
x11_window_types: vec![XWindowType::Normal],
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
gtk_theme_variant: None,
|
gtk_theme_variant: None,
|
||||||
#[cfg(feature = "wayland")]
|
|
||||||
app_id: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,8 +159,8 @@ impl Window {
|
||||||
window.set_max_size(max_size);
|
window.set_max_size(max_size);
|
||||||
|
|
||||||
// Set Wayland specific window attributes.
|
// Set Wayland specific window attributes.
|
||||||
if let Some(app_id) = platform_attributes.app_id {
|
if let Some(name) = platform_attributes.name {
|
||||||
window.set_app_id(app_id);
|
window.set_app_id(name.general);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set common window attributes.
|
// Set common window attributes.
|
||||||
|
|
|
@ -310,11 +310,11 @@ impl UnownedWindow {
|
||||||
|
|
||||||
// WM_CLASS must be set *before* mapping the window, as per ICCCM!
|
// WM_CLASS must be set *before* mapping the window, as per ICCCM!
|
||||||
{
|
{
|
||||||
let (class, instance) = if let Some((instance, class)) = pl_attribs.class {
|
let (class, instance) = if let Some(name) = pl_attribs.name {
|
||||||
let instance = CString::new(instance.as_str())
|
let instance = CString::new(name.instance.as_str())
|
||||||
.expect("`WM_CLASS` instance contained null byte");
|
.expect("`WM_CLASS` instance contained null byte");
|
||||||
let class =
|
let class = CString::new(name.general.as_str())
|
||||||
CString::new(class.as_str()).expect("`WM_CLASS` class contained null byte");
|
.expect("`WM_CLASS` class contained null byte");
|
||||||
(instance, class)
|
(instance, class)
|
||||||
} else {
|
} else {
|
||||||
let class = env::args()
|
let class = env::args()
|
||||||
|
|
Loading…
Reference in a new issue