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::{
|
||||
window::{Focus, RESIZE_BORDER},
|
||||
CosmicSurface,
|
||||
window::{Focus, RESIZE_BORDER},
|
||||
};
|
||||
use crate::{
|
||||
backend::render::cursor::CursorState,
|
||||
|
|
@ -17,28 +17,29 @@ use crate::{
|
|||
};
|
||||
use calloop::LoopHandle;
|
||||
use cosmic::{
|
||||
iced::{id::Id, widget as iced_widget, Alignment},
|
||||
iced_core::{border::Radius, Background, Border, Color, Length},
|
||||
Apply, Element as CosmicElement, Theme,
|
||||
iced::{Alignment, id::Id, widget as iced_widget},
|
||||
iced_core::{Background, Border, Color, Length, border::Radius},
|
||||
iced_runtime::Task,
|
||||
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 once_cell::sync::Lazy;
|
||||
use shortcuts::action::{Direction, FocusDirection};
|
||||
use smithay::{
|
||||
backend::{
|
||||
input::KeyState,
|
||||
renderer::{
|
||||
element::{
|
||||
memory::MemoryRenderBufferRenderElement, surface::WaylandSurfaceRenderElement,
|
||||
AsRenderElements,
|
||||
},
|
||||
ImportAll, ImportMem, Renderer,
|
||||
element::{
|
||||
AsRenderElements, memory::MemoryRenderBufferRenderElement,
|
||||
surface::WaylandSurfaceRenderElement,
|
||||
},
|
||||
},
|
||||
},
|
||||
desktop::{space::SpaceElement, WindowSurfaceType},
|
||||
desktop::{WindowSurfaceType, space::SpaceElement},
|
||||
input::{
|
||||
Seat,
|
||||
keyboard::{KeyboardTarget, KeysymHandle, ModifiersState},
|
||||
pointer::{
|
||||
AxisFrame, ButtonEvent, CursorImageStatus, GestureHoldBeginEvent, GestureHoldEndEvent,
|
||||
|
|
@ -50,7 +51,6 @@ use smithay::{
|
|||
DownEvent, MotionEvent as TouchMotionEvent, OrientationEvent, ShapeEvent, TouchTarget,
|
||||
UpEvent,
|
||||
},
|
||||
Seat,
|
||||
},
|
||||
output::Output,
|
||||
reexports::wayland_server::protocol::wl_surface::WlSurface,
|
||||
|
|
@ -63,8 +63,8 @@ use std::{
|
|||
fmt,
|
||||
hash::Hash,
|
||||
sync::{
|
||||
Arc, LazyLock, Mutex,
|
||||
atomic::{AtomicBool, AtomicU8, AtomicUsize, Ordering},
|
||||
Arc, Mutex,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -77,7 +77,7 @@ use self::{
|
|||
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)]
|
||||
pub struct CosmicStack(pub(super) IcedElement<CosmicStackInternal>);
|
||||
|
|
@ -314,11 +314,7 @@ impl CosmicStack {
|
|||
if let Ok(old) =
|
||||
p.active
|
||||
.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |val| {
|
||||
if val < max - 1 {
|
||||
Some(val + 1)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
if val < max - 1 { Some(val + 1) } else { None }
|
||||
})
|
||||
{
|
||||
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},
|
||||
DesktopLanguageRequester,
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
use rust_embed::RustEmbed;
|
||||
use smithay::{
|
||||
backend::{
|
||||
|
|
@ -121,7 +120,7 @@ use std::{
|
|||
collections::HashSet,
|
||||
ffi::OsString,
|
||||
process::Child,
|
||||
sync::{atomic::AtomicBool, Arc, Once},
|
||||
sync::{atomic::AtomicBool, Arc, LazyLock, Once},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
|
|
@ -129,7 +128,8 @@ use std::{
|
|||
#[folder = "resources/i18n"]
|
||||
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_rules! fl {
|
||||
|
|
@ -295,21 +295,21 @@ impl Default for SurfaceFrameThrottlingState {
|
|||
impl BackendData {
|
||||
pub fn kms(&mut self) -> &mut KmsState {
|
||||
match self {
|
||||
BackendData::Kms(ref mut kms_state) => kms_state,
|
||||
BackendData::Kms(kms_state) => kms_state,
|
||||
_ => unreachable!("Called kms in non kms backend"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn x11(&mut self) -> &mut X11State {
|
||||
match self {
|
||||
BackendData::X11(ref mut x11_state) => x11_state,
|
||||
BackendData::X11(x11_state) => x11_state,
|
||||
_ => unreachable!("Called x11 in non x11 backend"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn winit(&mut self) -> &mut WinitState {
|
||||
match self {
|
||||
BackendData::Winit(ref mut winit_state) => winit_state,
|
||||
BackendData::Winit(winit_state) => winit_state,
|
||||
_ => unreachable!("Called winit in non winit backend"),
|
||||
}
|
||||
}
|
||||
|
|
@ -319,8 +319,8 @@ impl BackendData {
|
|||
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.
|
||||
// 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::Kms(ref mut state) => state.schedule_render(output),
|
||||
BackendData::X11(state) => state.schedule_render(output),
|
||||
BackendData::Kms(state) => state.schedule_render(output),
|
||||
_ => unreachable!("No backend was initialized"),
|
||||
}
|
||||
}
|
||||
|
|
@ -332,15 +332,15 @@ impl BackendData {
|
|||
dmabuf: Dmabuf,
|
||||
) -> Result<Option<DrmNode>, anyhow::Error> {
|
||||
match self {
|
||||
BackendData::Kms(ref mut state) => {
|
||||
BackendData::Kms(state) => {
|
||||
return state
|
||||
.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)?;
|
||||
}
|
||||
BackendData::X11(ref mut state) => {
|
||||
BackendData::X11(state) => {
|
||||
state.renderer.import_dmabuf(&dmabuf, None)?;
|
||||
}
|
||||
_ => 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<()> {
|
||||
match self {
|
||||
BackendData::Kms(ref mut state) => state.update_screen_filter(screen_filter),
|
||||
BackendData::Winit(ref mut state) => state.update_screen_filter(screen_filter),
|
||||
BackendData::X11(ref mut state) => state.update_screen_filter(screen_filter),
|
||||
BackendData::Kms(state) => state.update_screen_filter(screen_filter),
|
||||
BackendData::Winit(state) => state.update_screen_filter(screen_filter),
|
||||
BackendData::X11(state) => state.update_screen_filter(screen_filter),
|
||||
_ => unreachable!("No backend set when setting screen filters"),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,13 @@ use std::{
|
|||
collections::{HashMap, HashSet},
|
||||
fmt,
|
||||
hash::{Hash, Hasher},
|
||||
sync::{mpsc::Receiver, Arc, Mutex},
|
||||
sync::{Arc, LazyLock, Mutex, mpsc::Receiver},
|
||||
};
|
||||
|
||||
use cosmic::{
|
||||
Theme,
|
||||
iced::{
|
||||
Limits, Point as IcedPoint, Size as IcedSize, Task,
|
||||
advanced::{graphics::text::font_system, widget::Tree},
|
||||
event::Event,
|
||||
futures::{FutureExt, StreamExt},
|
||||
|
|
@ -14,37 +16,35 @@ use cosmic::{
|
|||
mouse::{Button as MouseButton, Cursor, Event as MouseEvent, ScrollDelta},
|
||||
touch::{Event as TouchEvent, Finger},
|
||||
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::{
|
||||
Action, Debug,
|
||||
program::{Program as IcedProgram, State},
|
||||
task::into_stream,
|
||||
Action, Debug,
|
||||
},
|
||||
Theme,
|
||||
};
|
||||
use iced_tiny_skia::{
|
||||
graphics::{damage, Viewport},
|
||||
Layer,
|
||||
graphics::{Viewport, damage},
|
||||
};
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use ordered_float::OrderedFloat;
|
||||
use smithay::{
|
||||
backend::{
|
||||
allocator::Fourcc,
|
||||
input::{ButtonState, KeyState},
|
||||
renderer::{
|
||||
element::{
|
||||
memory::{MemoryRenderBuffer, MemoryRenderBufferRenderElement},
|
||||
AsRenderElements, Kind,
|
||||
},
|
||||
ImportMem, Renderer,
|
||||
element::{
|
||||
AsRenderElements, Kind,
|
||||
memory::{MemoryRenderBuffer, MemoryRenderBufferRenderElement},
|
||||
},
|
||||
},
|
||||
},
|
||||
desktop::space::{RenderZindex, SpaceElement},
|
||||
input::{
|
||||
Seat,
|
||||
keyboard::{KeyboardTarget, KeysymHandle, ModifiersState},
|
||||
pointer::{
|
||||
AxisFrame, ButtonEvent, GestureHoldBeginEvent, GestureHoldEndEvent,
|
||||
|
|
@ -56,18 +56,17 @@ use smithay::{
|
|||
DownEvent, MotionEvent as TouchMotionEvent, OrientationEvent, ShapeEvent, TouchTarget,
|
||||
UpEvent,
|
||||
},
|
||||
Seat,
|
||||
},
|
||||
output::Output,
|
||||
reexports::calloop::RegistrationToken,
|
||||
reexports::calloop::{self, futures::Scheduler, LoopHandle},
|
||||
reexports::calloop::{self, LoopHandle, futures::Scheduler},
|
||||
utils::{
|
||||
Buffer as BufferCoords, IsAlive, Logical, Physical, Point, Rectangle, Scale, Serial, Size,
|
||||
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>>>);
|
||||
|
||||
|
|
@ -373,7 +372,7 @@ impl<P: Program + Send + 'static> IcedElement<P> {
|
|||
|
||||
pub fn force_redraw(&self) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -914,9 +913,7 @@ where
|
|||
}
|
||||
|
||||
scale = scale * internal_ref.additional_scale;
|
||||
if let Some((buffer, ref mut old_layers)) =
|
||||
internal_ref.buffers.get_mut(&OrderedFloat(scale.x))
|
||||
{
|
||||
if let Some((buffer, old_layers)) = internal_ref.buffers.get_mut(&OrderedFloat(scale.x)) {
|
||||
let size: Size<i32, BufferCoords> = internal_ref
|
||||
.size
|
||||
.to_f64()
|
||||
|
|
|
|||
|
|
@ -4,10 +4,8 @@
|
|||
macro_rules! id_gen {
|
||||
($func_name:ident, $id_name:ident, $ids_name:ident) => {
|
||||
static $id_name: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
|
||||
lazy_static::lazy_static! {
|
||||
static ref $ids_name: std::sync::Mutex<std::collections::HashSet<usize>> =
|
||||
std::sync::Mutex::new(std::collections::HashSet::new());
|
||||
}
|
||||
static $ids_name: std::sync::LazyLock<std::sync::Mutex<std::collections::HashSet<usize>>> =
|
||||
std::sync::LazyLock::new(|| std::sync::Mutex::new(std::collections::HashSet::new()));
|
||||
|
||||
fn $func_name() -> usize {
|
||||
let mut ids = $ids_name.lock().unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue