Files
zed/crates/gpui_shared_string/gpui_shared_string.rs
Mohamad Khani b72a46db68
Some checks failed
Update All Top Ranking Issues / update_top_ranking_issues (push) Has been cancelled
Triage Project Sync (#84) / Sync triage project (push) Has been cancelled
release_nightly / notify_on_failure (push) Has been cancelled
release_nightly / check_style (push) Has been cancelled
release_nightly / run_tests_windows (push) Has been cancelled
release_nightly / clippy_windows (push) Has been cancelled
release_nightly / bundle_linux_aarch64 (push) Has been cancelled
release_nightly / bundle_linux_x86_64 (push) Has been cancelled
release_nightly / bundle_mac_aarch64 (push) Has been cancelled
release_nightly / bundle_mac_x86_64 (push) Has been cancelled
release_nightly / bundle_windows_aarch64 (push) Has been cancelled
release_nightly / bundle_windows_x86_64 (push) Has been cancelled
release_nightly / build_nix_linux_x86_64 (push) Has been cancelled
release_nightly / build_nix_mac_aarch64 (push) Has been cancelled
release_nightly / update_nightly_tag (push) Has been cancelled
Hotfix Review Monitor / check-hotfix-reviews (push) Has been cancelled
Stale PR Review Reminder / check-stale-prs (push) Has been cancelled
Update Weekly Top Ranking Issues / update_top_ranking_issues (push) Has been cancelled
Bump collab-staging Tag / update-collab-staging-tag (push) Has been cancelled
compliance_check / scheduled_compliance_check (push) Has been cancelled
logiguard fork: GPUI xdg-activation keyboard-focus serial fix
Single-commit orphan branch: full zed-industries/zed @ 8c74db0 source tree
with a 3-file patch applied (no upstream history).

Patch (crates/gpui_linux/src/linux/wayland/):
  - serial.rs: add SerialKind::KeyboardEnter
  - client.rs: store wl_keyboard.enter serial; add latest_serial_of()
  - window.rs: activate() uses keyboard-enter serial (Mutter focus gate)

Mutter honors window activation only when the token carries the keyboard-
focus serial from wl_keyboard.enter; GPUI used a stale mouse-press serial.
See docs/tray-window-focus-wayland.md in logiguard.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-14 02:22:17 +03:30

204 lines
4.3 KiB
Rust

use std::{
borrow::{Borrow, Cow},
sync::Arc,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use smol_str::SmolStr;
/// A shared string is an immutable string that can be cheaply cloned in GPUI
/// tasks. Essentially an abstraction over an `Arc<str>` and `&'static str`,
/// currently backed by a [`SmolStr`].
#[derive(Eq, PartialEq, PartialOrd, Ord, Hash, Clone)]
pub struct SharedString(SmolStr);
impl std::ops::Deref for SharedString {
type Target = str;
fn deref(&self) -> &Self::Target {
self.0.as_str()
}
}
impl SharedString {
/// Creates a static [`SharedString`] from a `&'static str`.
pub const fn new_static(str: &'static str) -> Self {
Self(SmolStr::new_static(str))
}
/// Creates a [`SharedString`].
pub fn new(str: impl AsRef<str>) -> Self {
SharedString(SmolStr::new(str))
}
/// Get a &str from the underlying string.
pub fn as_str(&self) -> &str {
&self.0
}
}
impl JsonSchema for SharedString {
fn inline_schema() -> bool {
String::inline_schema()
}
fn schema_name() -> Cow<'static, str> {
String::schema_name()
}
fn json_schema(generator: &mut schemars::SchemaGenerator) -> schemars::Schema {
String::json_schema(generator)
}
}
impl Default for SharedString {
fn default() -> Self {
Self::new_static("")
}
}
impl AsRef<str> for SharedString {
fn as_ref(&self) -> &str {
&self.0
}
}
impl Borrow<str> for SharedString {
fn borrow(&self) -> &str {
self.as_ref()
}
}
impl std::fmt::Debug for SharedString {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl std::fmt::Display for SharedString {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0.as_str())
}
}
impl PartialEq<String> for SharedString {
fn eq(&self, other: &String) -> bool {
self.as_ref() == other
}
}
impl PartialEq<SharedString> for String {
fn eq(&self, other: &SharedString) -> bool {
self == other.as_ref()
}
}
impl PartialEq<str> for SharedString {
fn eq(&self, other: &str) -> bool {
self.as_ref() == other
}
}
impl<'a> PartialEq<&'a str> for SharedString {
fn eq(&self, other: &&'a str) -> bool {
self.as_ref() == *other
}
}
impl From<&SharedString> for SharedString {
#[inline]
fn from(s: &SharedString) -> SharedString {
s.clone()
}
}
impl From<&str> for SharedString {
#[inline]
fn from(s: &str) -> SharedString {
SharedString(SmolStr::from(s))
}
}
impl From<&mut str> for SharedString {
#[inline]
fn from(s: &mut str) -> SharedString {
SharedString(SmolStr::from(s))
}
}
impl From<&String> for SharedString {
#[inline]
fn from(s: &String) -> SharedString {
SharedString(SmolStr::from(s))
}
}
impl From<String> for SharedString {
#[inline(always)]
fn from(text: String) -> Self {
SharedString(SmolStr::from(text))
}
}
impl From<Box<str>> for SharedString {
#[inline]
fn from(s: Box<str>) -> SharedString {
SharedString(SmolStr::from(s))
}
}
impl From<Arc<str>> for SharedString {
#[inline]
fn from(s: Arc<str>) -> SharedString {
SharedString(SmolStr::from(s))
}
}
impl From<&Arc<str>> for SharedString {
#[inline]
fn from(s: &Arc<str>) -> SharedString {
SharedString(SmolStr::from(s.clone()))
}
}
impl<'a> From<Cow<'a, str>> for SharedString {
#[inline]
fn from(s: Cow<'a, str>) -> SharedString {
SharedString(SmolStr::from(s))
}
}
impl From<SharedString> for Arc<str> {
#[inline(always)]
fn from(text: SharedString) -> Self {
text.0.into()
}
}
impl From<SharedString> for String {
#[inline(always)]
fn from(text: SharedString) -> Self {
text.0.into()
}
}
impl Serialize for SharedString {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_ref())
}
}
impl<'de> Deserialize<'de> for SharedString {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
Ok(SharedString::new(&s))
}
}