chore: use std::sync::LazyLock
This commit is contained in:
parent
310cf212eb
commit
fec7c94605
4 changed files with 46 additions and 55 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
use super::{
|
use super::{
|
||||||
window::{Focus, RESIZE_BORDER},
|
|
||||||
CosmicSurface,
|
CosmicSurface,
|
||||||
|
window::{Focus, RESIZE_BORDER},
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
backend::render::cursor::CursorState,
|
backend::render::cursor::CursorState,
|
||||||
|
|
@ -17,28 +17,29 @@ use crate::{
|
||||||
};
|
};
|
||||||
use calloop::LoopHandle;
|
use calloop::LoopHandle;
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
iced::{id::Id, widget as iced_widget, Alignment},
|
Apply, Element as CosmicElement, Theme,
|
||||||
iced_core::{border::Radius, Background, Border, Color, Length},
|
iced::{Alignment, id::Id, widget as iced_widget},
|
||||||
|
iced_core::{Background, Border, Color, Length, border::Radius},
|
||||||
iced_runtime::Task,
|
iced_runtime::Task,
|
||||||
iced_widget::scrollable::AbsoluteOffset,
|
iced_widget::scrollable::AbsoluteOffset,
|
||||||
theme, widget as cosmic_widget, Apply, Element as CosmicElement, Theme,
|
theme, widget as cosmic_widget,
|
||||||
};
|
};
|
||||||
use cosmic_settings_config::shortcuts;
|
use cosmic_settings_config::shortcuts;
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use shortcuts::action::{Direction, FocusDirection};
|
use shortcuts::action::{Direction, FocusDirection};
|
||||||
use smithay::{
|
use smithay::{
|
||||||
backend::{
|
backend::{
|
||||||
input::KeyState,
|
input::KeyState,
|
||||||
renderer::{
|
renderer::{
|
||||||
element::{
|
|
||||||
memory::MemoryRenderBufferRenderElement, surface::WaylandSurfaceRenderElement,
|
|
||||||
AsRenderElements,
|
|
||||||
},
|
|
||||||
ImportAll, ImportMem, Renderer,
|
ImportAll, ImportMem, Renderer,
|
||||||
|
element::{
|
||||||
|
AsRenderElements, memory::MemoryRenderBufferRenderElement,
|
||||||
|
surface::WaylandSurfaceRenderElement,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
desktop::{space::SpaceElement, WindowSurfaceType},
|
desktop::{WindowSurfaceType, space::SpaceElement},
|
||||||
input::{
|
input::{
|
||||||
|
Seat,
|
||||||
keyboard::{KeyboardTarget, KeysymHandle, ModifiersState},
|
keyboard::{KeyboardTarget, KeysymHandle, ModifiersState},
|
||||||
pointer::{
|
pointer::{
|
||||||
AxisFrame, ButtonEvent, CursorImageStatus, GestureHoldBeginEvent, GestureHoldEndEvent,
|
AxisFrame, ButtonEvent, CursorImageStatus, GestureHoldBeginEvent, GestureHoldEndEvent,
|
||||||
|
|
@ -50,7 +51,6 @@ use smithay::{
|
||||||
DownEvent, MotionEvent as TouchMotionEvent, OrientationEvent, ShapeEvent, TouchTarget,
|
DownEvent, MotionEvent as TouchMotionEvent, OrientationEvent, ShapeEvent, TouchTarget,
|
||||||
UpEvent,
|
UpEvent,
|
||||||
},
|
},
|
||||||
Seat,
|
|
||||||
},
|
},
|
||||||
output::Output,
|
output::Output,
|
||||||
reexports::wayland_server::protocol::wl_surface::WlSurface,
|
reexports::wayland_server::protocol::wl_surface::WlSurface,
|
||||||
|
|
@ -63,8 +63,8 @@ use std::{
|
||||||
fmt,
|
fmt,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
sync::{
|
sync::{
|
||||||
|
Arc, LazyLock, Mutex,
|
||||||
atomic::{AtomicBool, AtomicU8, AtomicUsize, Ordering},
|
atomic::{AtomicBool, AtomicU8, AtomicUsize, Ordering},
|
||||||
Arc, Mutex,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -77,7 +77,7 @@ use self::{
|
||||||
tabs::Tabs,
|
tabs::Tabs,
|
||||||
};
|
};
|
||||||
|
|
||||||
static SCROLLABLE_ID: Lazy<Id> = Lazy::new(|| Id::new("scrollable"));
|
static SCROLLABLE_ID: LazyLock<Id> = LazyLock::new(|| Id::new("scrollable"));
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct CosmicStack(pub(super) IcedElement<CosmicStackInternal>);
|
pub struct CosmicStack(pub(super) IcedElement<CosmicStackInternal>);
|
||||||
|
|
@ -314,11 +314,7 @@ impl CosmicStack {
|
||||||
if let Ok(old) =
|
if let Ok(old) =
|
||||||
p.active
|
p.active
|
||||||
.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |val| {
|
.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |val| {
|
||||||
if val < max - 1 {
|
if val < max - 1 { Some(val + 1) } else { None }
|
||||||
Some(val + 1)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
p.previous_keyboard.store(old, Ordering::SeqCst);
|
p.previous_keyboard.store(old, Ordering::SeqCst);
|
||||||
|
|
|
||||||
30
src/state.rs
30
src/state.rs
|
|
@ -35,7 +35,6 @@ use i18n_embed::{
|
||||||
fluent::{fluent_language_loader, FluentLanguageLoader},
|
fluent::{fluent_language_loader, FluentLanguageLoader},
|
||||||
DesktopLanguageRequester,
|
DesktopLanguageRequester,
|
||||||
};
|
};
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use rust_embed::RustEmbed;
|
use rust_embed::RustEmbed;
|
||||||
use smithay::{
|
use smithay::{
|
||||||
backend::{
|
backend::{
|
||||||
|
|
@ -121,7 +120,7 @@ use std::{
|
||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
ffi::OsString,
|
ffi::OsString,
|
||||||
process::Child,
|
process::Child,
|
||||||
sync::{atomic::AtomicBool, Arc, Once},
|
sync::{atomic::AtomicBool, Arc, LazyLock, Once},
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -129,7 +128,8 @@ use std::{
|
||||||
#[folder = "resources/i18n"]
|
#[folder = "resources/i18n"]
|
||||||
struct Localizations;
|
struct Localizations;
|
||||||
|
|
||||||
pub static LANG_LOADER: Lazy<FluentLanguageLoader> = Lazy::new(|| fluent_language_loader!());
|
pub static LANG_LOADER: LazyLock<FluentLanguageLoader> =
|
||||||
|
LazyLock::new(|| fluent_language_loader!());
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! fl {
|
macro_rules! fl {
|
||||||
|
|
@ -295,21 +295,21 @@ impl Default for SurfaceFrameThrottlingState {
|
||||||
impl BackendData {
|
impl BackendData {
|
||||||
pub fn kms(&mut self) -> &mut KmsState {
|
pub fn kms(&mut self) -> &mut KmsState {
|
||||||
match self {
|
match self {
|
||||||
BackendData::Kms(ref mut kms_state) => kms_state,
|
BackendData::Kms(kms_state) => kms_state,
|
||||||
_ => unreachable!("Called kms in non kms backend"),
|
_ => unreachable!("Called kms in non kms backend"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn x11(&mut self) -> &mut X11State {
|
pub fn x11(&mut self) -> &mut X11State {
|
||||||
match self {
|
match self {
|
||||||
BackendData::X11(ref mut x11_state) => x11_state,
|
BackendData::X11(x11_state) => x11_state,
|
||||||
_ => unreachable!("Called x11 in non x11 backend"),
|
_ => unreachable!("Called x11 in non x11 backend"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn winit(&mut self) -> &mut WinitState {
|
pub fn winit(&mut self) -> &mut WinitState {
|
||||||
match self {
|
match self {
|
||||||
BackendData::Winit(ref mut winit_state) => winit_state,
|
BackendData::Winit(winit_state) => winit_state,
|
||||||
_ => unreachable!("Called winit in non winit backend"),
|
_ => unreachable!("Called winit in non winit backend"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -319,8 +319,8 @@ impl BackendData {
|
||||||
BackendData::Winit(_) => {} // We cannot do this on the winit backend.
|
BackendData::Winit(_) => {} // We cannot do this on the winit backend.
|
||||||
// Winit has a very strict render-loop and skipping frames breaks atleast the wayland winit-backend.
|
// Winit has a very strict render-loop and skipping frames breaks atleast the wayland winit-backend.
|
||||||
// Swapping with damage (which should be empty on these frames) is likely good enough anyway.
|
// Swapping with damage (which should be empty on these frames) is likely good enough anyway.
|
||||||
BackendData::X11(ref mut state) => state.schedule_render(output),
|
BackendData::X11(state) => state.schedule_render(output),
|
||||||
BackendData::Kms(ref mut state) => state.schedule_render(output),
|
BackendData::Kms(state) => state.schedule_render(output),
|
||||||
_ => unreachable!("No backend was initialized"),
|
_ => unreachable!("No backend was initialized"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -332,15 +332,15 @@ impl BackendData {
|
||||||
dmabuf: Dmabuf,
|
dmabuf: Dmabuf,
|
||||||
) -> Result<Option<DrmNode>, anyhow::Error> {
|
) -> Result<Option<DrmNode>, anyhow::Error> {
|
||||||
match self {
|
match self {
|
||||||
BackendData::Kms(ref mut state) => {
|
BackendData::Kms(state) => {
|
||||||
return state
|
return state
|
||||||
.dmabuf_imported(client, global, dmabuf)
|
.dmabuf_imported(client, global, dmabuf)
|
||||||
.map(|node| Some(node))
|
.map(|node| Some(node));
|
||||||
}
|
}
|
||||||
BackendData::Winit(ref mut state) => {
|
BackendData::Winit(state) => {
|
||||||
state.backend.renderer().import_dmabuf(&dmabuf, None)?;
|
state.backend.renderer().import_dmabuf(&dmabuf, None)?;
|
||||||
}
|
}
|
||||||
BackendData::X11(ref mut state) => {
|
BackendData::X11(state) => {
|
||||||
state.renderer.import_dmabuf(&dmabuf, None)?;
|
state.renderer.import_dmabuf(&dmabuf, None)?;
|
||||||
}
|
}
|
||||||
_ => unreachable!("No backend set when importing dmabuf"),
|
_ => unreachable!("No backend set when importing dmabuf"),
|
||||||
|
|
@ -382,9 +382,9 @@ impl BackendData {
|
||||||
|
|
||||||
pub fn update_screen_filter(&mut self, screen_filter: &ScreenFilter) -> anyhow::Result<()> {
|
pub fn update_screen_filter(&mut self, screen_filter: &ScreenFilter) -> anyhow::Result<()> {
|
||||||
match self {
|
match self {
|
||||||
BackendData::Kms(ref mut state) => state.update_screen_filter(screen_filter),
|
BackendData::Kms(state) => state.update_screen_filter(screen_filter),
|
||||||
BackendData::Winit(ref mut state) => state.update_screen_filter(screen_filter),
|
BackendData::Winit(state) => state.update_screen_filter(screen_filter),
|
||||||
BackendData::X11(ref mut state) => state.update_screen_filter(screen_filter),
|
BackendData::X11(state) => state.update_screen_filter(screen_filter),
|
||||||
_ => unreachable!("No backend set when setting screen filters"),
|
_ => unreachable!("No backend set when setting screen filters"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,13 @@ use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
fmt,
|
fmt,
|
||||||
hash::{Hash, Hasher},
|
hash::{Hash, Hasher},
|
||||||
sync::{mpsc::Receiver, Arc, Mutex},
|
sync::{Arc, LazyLock, Mutex, mpsc::Receiver},
|
||||||
};
|
};
|
||||||
|
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
|
Theme,
|
||||||
iced::{
|
iced::{
|
||||||
|
Limits, Point as IcedPoint, Size as IcedSize, Task,
|
||||||
advanced::{graphics::text::font_system, widget::Tree},
|
advanced::{graphics::text::font_system, widget::Tree},
|
||||||
event::Event,
|
event::Event,
|
||||||
futures::{FutureExt, StreamExt},
|
futures::{FutureExt, StreamExt},
|
||||||
|
|
@ -14,37 +16,35 @@ use cosmic::{
|
||||||
mouse::{Button as MouseButton, Cursor, Event as MouseEvent, ScrollDelta},
|
mouse::{Button as MouseButton, Cursor, Event as MouseEvent, ScrollDelta},
|
||||||
touch::{Event as TouchEvent, Finger},
|
touch::{Event as TouchEvent, Finger},
|
||||||
window::Event as WindowEvent,
|
window::Event as WindowEvent,
|
||||||
Limits, Point as IcedPoint, Size as IcedSize, Task,
|
|
||||||
},
|
},
|
||||||
iced_core::{clipboard::Null as NullClipboard, id::Id, renderer::Style, Color, Length, Pixels},
|
iced_core::{Color, Length, Pixels, clipboard::Null as NullClipboard, id::Id, renderer::Style},
|
||||||
iced_runtime::{
|
iced_runtime::{
|
||||||
|
Action, Debug,
|
||||||
program::{Program as IcedProgram, State},
|
program::{Program as IcedProgram, State},
|
||||||
task::into_stream,
|
task::into_stream,
|
||||||
Action, Debug,
|
|
||||||
},
|
},
|
||||||
Theme,
|
|
||||||
};
|
};
|
||||||
use iced_tiny_skia::{
|
use iced_tiny_skia::{
|
||||||
graphics::{damage, Viewport},
|
|
||||||
Layer,
|
Layer,
|
||||||
|
graphics::{Viewport, damage},
|
||||||
};
|
};
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use ordered_float::OrderedFloat;
|
use ordered_float::OrderedFloat;
|
||||||
use smithay::{
|
use smithay::{
|
||||||
backend::{
|
backend::{
|
||||||
allocator::Fourcc,
|
allocator::Fourcc,
|
||||||
input::{ButtonState, KeyState},
|
input::{ButtonState, KeyState},
|
||||||
renderer::{
|
renderer::{
|
||||||
element::{
|
|
||||||
memory::{MemoryRenderBuffer, MemoryRenderBufferRenderElement},
|
|
||||||
AsRenderElements, Kind,
|
|
||||||
},
|
|
||||||
ImportMem, Renderer,
|
ImportMem, Renderer,
|
||||||
|
element::{
|
||||||
|
AsRenderElements, Kind,
|
||||||
|
memory::{MemoryRenderBuffer, MemoryRenderBufferRenderElement},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
desktop::space::{RenderZindex, SpaceElement},
|
desktop::space::{RenderZindex, SpaceElement},
|
||||||
input::{
|
input::{
|
||||||
|
Seat,
|
||||||
keyboard::{KeyboardTarget, KeysymHandle, ModifiersState},
|
keyboard::{KeyboardTarget, KeysymHandle, ModifiersState},
|
||||||
pointer::{
|
pointer::{
|
||||||
AxisFrame, ButtonEvent, GestureHoldBeginEvent, GestureHoldEndEvent,
|
AxisFrame, ButtonEvent, GestureHoldBeginEvent, GestureHoldEndEvent,
|
||||||
|
|
@ -56,18 +56,17 @@ use smithay::{
|
||||||
DownEvent, MotionEvent as TouchMotionEvent, OrientationEvent, ShapeEvent, TouchTarget,
|
DownEvent, MotionEvent as TouchMotionEvent, OrientationEvent, ShapeEvent, TouchTarget,
|
||||||
UpEvent,
|
UpEvent,
|
||||||
},
|
},
|
||||||
Seat,
|
|
||||||
},
|
},
|
||||||
output::Output,
|
output::Output,
|
||||||
reexports::calloop::RegistrationToken,
|
reexports::calloop::RegistrationToken,
|
||||||
reexports::calloop::{self, futures::Scheduler, LoopHandle},
|
reexports::calloop::{self, LoopHandle, futures::Scheduler},
|
||||||
utils::{
|
utils::{
|
||||||
Buffer as BufferCoords, IsAlive, Logical, Physical, Point, Rectangle, Scale, Serial, Size,
|
Buffer as BufferCoords, IsAlive, Logical, Physical, Point, Rectangle, Scale, Serial, Size,
|
||||||
Transform,
|
Transform,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static ID: Lazy<Id> = Lazy::new(|| Id::new("Program"));
|
static ID: LazyLock<Id> = LazyLock::new(|| Id::new("Program"));
|
||||||
|
|
||||||
pub struct IcedElement<P: Program + Send + 'static>(pub(crate) Arc<Mutex<IcedElementInternal<P>>>);
|
pub struct IcedElement<P: Program + Send + 'static>(pub(crate) Arc<Mutex<IcedElementInternal<P>>>);
|
||||||
|
|
||||||
|
|
@ -373,7 +372,7 @@ impl<P: Program + Send + 'static> IcedElement<P> {
|
||||||
|
|
||||||
pub fn force_redraw(&self) {
|
pub fn force_redraw(&self) {
|
||||||
let mut internal = self.0.lock().unwrap();
|
let mut internal = self.0.lock().unwrap();
|
||||||
for (_buffer, ref mut old_primitives) in internal.buffers.values_mut() {
|
for (_buffer, old_primitives) in internal.buffers.values_mut() {
|
||||||
*old_primitives = None;
|
*old_primitives = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -914,9 +913,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
scale = scale * internal_ref.additional_scale;
|
scale = scale * internal_ref.additional_scale;
|
||||||
if let Some((buffer, ref mut old_layers)) =
|
if let Some((buffer, old_layers)) = internal_ref.buffers.get_mut(&OrderedFloat(scale.x)) {
|
||||||
internal_ref.buffers.get_mut(&OrderedFloat(scale.x))
|
|
||||||
{
|
|
||||||
let size: Size<i32, BufferCoords> = internal_ref
|
let size: Size<i32, BufferCoords> = internal_ref
|
||||||
.size
|
.size
|
||||||
.to_f64()
|
.to_f64()
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,8 @@
|
||||||
macro_rules! id_gen {
|
macro_rules! id_gen {
|
||||||
($func_name:ident, $id_name:ident, $ids_name:ident) => {
|
($func_name:ident, $id_name:ident, $ids_name:ident) => {
|
||||||
static $id_name: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
|
static $id_name: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
|
||||||
lazy_static::lazy_static! {
|
static $ids_name: std::sync::LazyLock<std::sync::Mutex<std::collections::HashSet<usize>>> =
|
||||||
static ref $ids_name: std::sync::Mutex<std::collections::HashSet<usize>> =
|
std::sync::LazyLock::new(|| std::sync::Mutex::new(std::collections::HashSet::new()));
|
||||||
std::sync::Mutex::new(std::collections::HashSet::new());
|
|
||||||
}
|
|
||||||
|
|
||||||
fn $func_name() -> usize {
|
fn $func_name() -> usize {
|
||||||
let mut ids = $ids_name.lock().unwrap();
|
let mut ids = $ids_name.lock().unwrap();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue