clippy: clean up all warnings
Mostly `cargo clippy --fix`: needless borrows, redundant field names, match -> if let, io::Error::other, Option::filter/map, let chains, c"" literals. By hand: drop unused impl lifetimes, a type alias for the font preload map, Iterator::find in next_buffer, contains_key, and allow new_ret_no_self where constructors intentionally return the boxed/generic wrapper type. No functional change; tests and release build unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
42ffe9c492
commit
1c6a536026
+4
-13
@@ -1,5 +1,4 @@
|
|||||||
use std::{
|
use std::{
|
||||||
ffi::CStr,
|
|
||||||
fs::File,
|
fs::File,
|
||||||
io,
|
io,
|
||||||
os::unix::io::{FromRawFd, RawFd},
|
os::unix::io::{FromRawFd, RawFd},
|
||||||
@@ -30,10 +29,7 @@ fn create_shm_fd() -> io::Result<RawFd> {
|
|||||||
// Only try memfd on linux
|
// Only try memfd on linux
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
loop {
|
loop {
|
||||||
match memfd::memfd_create(
|
match memfd::memfd_create(c"wldash", memfd::MemFdCreateFlag::MFD_CLOEXEC) {
|
||||||
CStr::from_bytes_with_nul(b"wldash\0").unwrap(),
|
|
||||||
memfd::MemFdCreateFlag::MFD_CLOEXEC,
|
|
||||||
) {
|
|
||||||
Ok(fd) => return Ok(fd),
|
Ok(fd) => return Ok(fd),
|
||||||
Err(Errno::EINTR) => continue,
|
Err(Errno::EINTR) => continue,
|
||||||
Err(Errno::ENOSYS) => break,
|
Err(Errno::ENOSYS) => break,
|
||||||
@@ -103,9 +99,9 @@ impl ShmBuffer {
|
|||||||
let mem_fd = create_shm_fd()?;
|
let mem_fd = create_shm_fd()?;
|
||||||
let file = unsafe { File::from_raw_fd(mem_fd) };
|
let file = unsafe { File::from_raw_fd(mem_fd) };
|
||||||
file.set_len((height * stride) as u64)?;
|
file.set_len((height * stride) as u64)?;
|
||||||
let pool = shm.create_pool(mem_fd, height * stride, &qh, ());
|
let pool = shm.create_pool(mem_fd, height * stride, qh, ());
|
||||||
let mmap = unsafe { MmapMut::map_mut(&file)? };
|
let mmap = unsafe { MmapMut::map_mut(&file)? };
|
||||||
let buffer = pool.create_buffer(0, width, height, stride, format, &qh, ());
|
let buffer = pool.create_buffer(0, width, height, stride, format, qh, ());
|
||||||
|
|
||||||
Ok(ShmBuffer {
|
Ok(ShmBuffer {
|
||||||
refcnt: 0,
|
refcnt: 0,
|
||||||
@@ -148,12 +144,7 @@ impl BufferManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_buffer(&mut self) -> Option<&mut ShmBuffer> {
|
pub fn next_buffer(&mut self) -> Option<&mut ShmBuffer> {
|
||||||
for buf in self.buffers.iter_mut() {
|
self.buffers.iter_mut().find(|buf| buf.refcnt == 0)
|
||||||
if buf.refcnt == 0 {
|
|
||||||
return Some(buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_buffer<D>(
|
pub fn add_buffer<D>(
|
||||||
|
|||||||
+10
-10
@@ -161,7 +161,7 @@ impl Config {
|
|||||||
|
|
||||||
Config {
|
Config {
|
||||||
font_paths: Some(map),
|
font_paths: Some(map),
|
||||||
widget: widget,
|
widget,
|
||||||
mode: OperationMode::LayerSurface((1024, 768)),
|
mode: OperationMode::LayerSurface((1024, 768)),
|
||||||
background: Some(0xFAFAFAFA),
|
background: Some(0xFAFAFAFA),
|
||||||
server: None,
|
server: None,
|
||||||
@@ -251,7 +251,7 @@ impl Config {
|
|||||||
|
|
||||||
Config {
|
Config {
|
||||||
font_paths: Some(map),
|
font_paths: Some(map),
|
||||||
widget: widget,
|
widget,
|
||||||
mode: if clay {
|
mode: if clay {
|
||||||
OperationMode::XdgToplevel
|
OperationMode::XdgToplevel
|
||||||
} else {
|
} else {
|
||||||
@@ -281,7 +281,7 @@ impl Widget {
|
|||||||
pub fn construct_widgets(
|
pub fn construct_widgets(
|
||||||
self,
|
self,
|
||||||
v: &mut Vec<Box<dyn RealWidget>>,
|
v: &mut Vec<Box<dyn RealWidget>>,
|
||||||
mut fm: &mut FontMap,
|
fm: &mut FontMap,
|
||||||
events: &Arc<Mutex<Events>>,
|
events: &Arc<Mutex<Events>>,
|
||||||
) {
|
) {
|
||||||
match self {
|
match self {
|
||||||
@@ -301,12 +301,12 @@ impl Widget {
|
|||||||
Widget::HorizontalLine(width) => v.push(Box::new(Line::new(width, false))),
|
Widget::HorizontalLine(width) => v.push(Box::new(Line::new(width, false))),
|
||||||
Widget::VerticalLine(width) => v.push(Box::new(Line::new(width, true))),
|
Widget::VerticalLine(width) => v.push(Box::new(Line::new(width, true))),
|
||||||
Widget::Clock { font, font_size } => v.push(Box::new(Clock::new(
|
Widget::Clock { font, font_size } => v.push(Box::new(Clock::new(
|
||||||
&mut fm,
|
fm,
|
||||||
leak_or_default(font, "sans"),
|
leak_or_default(font, "sans"),
|
||||||
font_size,
|
font_size,
|
||||||
))),
|
))),
|
||||||
Widget::Date { font, font_size } => v.push(Box::new(Date::new(
|
Widget::Date { font, font_size } => v.push(Box::new(Date::new(
|
||||||
&mut fm,
|
fm,
|
||||||
leak_or_default(font, "sans"),
|
leak_or_default(font, "sans"),
|
||||||
font_size,
|
font_size,
|
||||||
))),
|
))),
|
||||||
@@ -317,7 +317,7 @@ impl Widget {
|
|||||||
sections_x,
|
sections_x,
|
||||||
sections_y,
|
sections_y,
|
||||||
} => v.push(Box::new(Calendar::new(
|
} => v.push(Box::new(Calendar::new(
|
||||||
&mut fm,
|
fm,
|
||||||
leak_or_default(font_primary, "monospace"),
|
leak_or_default(font_primary, "monospace"),
|
||||||
leak_or_default(font_secondary, "sans"),
|
leak_or_default(font_secondary, "sans"),
|
||||||
font_size,
|
font_size,
|
||||||
@@ -330,14 +330,14 @@ impl Widget {
|
|||||||
launch_cmd,
|
launch_cmd,
|
||||||
} => v.push(Box::new(Interface::new(
|
} => v.push(Box::new(Interface::new(
|
||||||
events.clone(),
|
events.clone(),
|
||||||
&mut fm,
|
fm,
|
||||||
leak_or_default(font, "sans"),
|
leak_or_default(font, "sans"),
|
||||||
font_size,
|
font_size,
|
||||||
launch_cmd,
|
launch_cmd,
|
||||||
))),
|
))),
|
||||||
Widget::Battery { font, font_size } => v.push(Box::new(Battery::new(
|
Widget::Battery { font, font_size } => v.push(Box::new(Battery::new(
|
||||||
events.clone(),
|
events.clone(),
|
||||||
&mut fm,
|
fm,
|
||||||
leak_or_default(font, "sans"),
|
leak_or_default(font, "sans"),
|
||||||
font_size,
|
font_size,
|
||||||
))),
|
))),
|
||||||
@@ -347,13 +347,13 @@ impl Widget {
|
|||||||
font_size,
|
font_size,
|
||||||
} => v.push(Box::new(Backlight::new(
|
} => v.push(Box::new(Backlight::new(
|
||||||
leak_or_none(device),
|
leak_or_none(device),
|
||||||
&mut fm,
|
fm,
|
||||||
leak_or_default(font, "sans"),
|
leak_or_default(font, "sans"),
|
||||||
font_size,
|
font_size,
|
||||||
))),
|
))),
|
||||||
Widget::PulseAudio { font, font_size } => v.push(Box::new(PulseAudio::new(
|
Widget::PulseAudio { font, font_size } => v.push(Box::new(PulseAudio::new(
|
||||||
events.clone(),
|
events.clone(),
|
||||||
&mut fm,
|
fm,
|
||||||
Box::leak(font.unwrap_or_else(|| "sans".to_string()).into_boxed_str()),
|
Box::leak(font.unwrap_or_else(|| "sans".to_string()).into_boxed_str()),
|
||||||
font_size,
|
font_size,
|
||||||
))),
|
))),
|
||||||
|
|||||||
+21
-21
@@ -98,7 +98,7 @@ impl<'a> Font<'a> {
|
|||||||
|
|
||||||
pub fn add_str_to_cache(&mut self, s: &str) {
|
pub fn add_str_to_cache(&mut self, s: &str) {
|
||||||
for ch in s.chars() {
|
for ch in s.chars() {
|
||||||
if self.glyphs.get(&ch).is_none() {
|
if !self.glyphs.contains_key(&ch) {
|
||||||
let glyph = CachedGlyph::new(self.font, self.size, ch);
|
let glyph = CachedGlyph::new(self.font, self.size, ch);
|
||||||
self.glyphs.insert(ch, glyph);
|
self.glyphs.insert(ch, glyph);
|
||||||
}
|
}
|
||||||
@@ -118,10 +118,10 @@ impl<'a> Font<'a> {
|
|||||||
let glyph = match self.glyphs.get(&ch) {
|
let glyph = match self.glyphs.get(&ch) {
|
||||||
Some(glyph) => glyph,
|
Some(glyph) => glyph,
|
||||||
None => {
|
None => {
|
||||||
return Err(::std::io::Error::new(
|
return Err(::std::io::Error::other(format!(
|
||||||
::std::io::ErrorKind::Other,
|
"glyph for {:} not in cache",
|
||||||
format!("glyph for {:} not in cache", ch),
|
ch
|
||||||
));
|
)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
glyphs.push(glyph);
|
glyphs.push(glyph);
|
||||||
@@ -151,10 +151,10 @@ impl<'a> Font<'a> {
|
|||||||
let glyph = match self.glyphs.get(&ch) {
|
let glyph = match self.glyphs.get(&ch) {
|
||||||
Some(glyph) => glyph,
|
Some(glyph) => glyph,
|
||||||
None => {
|
None => {
|
||||||
return Err(::std::io::Error::new(
|
return Err(::std::io::Error::other(format!(
|
||||||
::std::io::ErrorKind::Other,
|
"glyph for {:} not in cache",
|
||||||
format!("glyph for {:} not in cache", ch),
|
ch
|
||||||
));
|
)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
glyphs.push(glyph);
|
glyphs.push(glyph);
|
||||||
@@ -203,10 +203,10 @@ impl<'a> Font<'a> {
|
|||||||
let glyph = match self.glyphs.get(&ch) {
|
let glyph = match self.glyphs.get(&ch) {
|
||||||
Some(glyph) => glyph,
|
Some(glyph) => glyph,
|
||||||
None => {
|
None => {
|
||||||
return Err(::std::io::Error::new(
|
return Err(::std::io::Error::other(format!(
|
||||||
::std::io::ErrorKind::Other,
|
"glyph for {:} not in cache",
|
||||||
format!("glyph for {:} not in cache", ch),
|
ch
|
||||||
));
|
)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let width = glyph.advance;
|
let width = glyph.advance;
|
||||||
@@ -252,10 +252,10 @@ impl<'a> Font<'a> {
|
|||||||
let glyph = match self.glyphs.get(&ch) {
|
let glyph = match self.glyphs.get(&ch) {
|
||||||
Some(glyph) => glyph,
|
Some(glyph) => glyph,
|
||||||
None => {
|
None => {
|
||||||
return Err(::std::io::Error::new(
|
return Err(::std::io::Error::other(format!(
|
||||||
::std::io::ErrorKind::Other,
|
"glyph for {:} not in cache",
|
||||||
format!("glyph for {:} not in cache", ch),
|
ch
|
||||||
));
|
)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
glyphs.push(glyph);
|
glyphs.push(glyph);
|
||||||
@@ -284,10 +284,10 @@ impl<'a> Font<'a> {
|
|||||||
let glyph = match self.glyphs.get(&ch) {
|
let glyph = match self.glyphs.get(&ch) {
|
||||||
Some(glyph) => glyph,
|
Some(glyph) => glyph,
|
||||||
None => {
|
None => {
|
||||||
return Err(::std::io::Error::new(
|
return Err(::std::io::Error::other(format!(
|
||||||
::std::io::ErrorKind::Other,
|
"glyph for {:} not in cache",
|
||||||
format!("glyph for {:} not in cache", ch),
|
ch
|
||||||
));
|
)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
glyphs.push(glyph);
|
glyphs.push(glyph);
|
||||||
|
|||||||
+1
-1
@@ -56,6 +56,6 @@ impl Events {
|
|||||||
|
|
||||||
pub fn flush(&mut self) -> Vec<Event> {
|
pub fn flush(&mut self) -> Vec<Event> {
|
||||||
self.dirty = false;
|
self.dirty = false;
|
||||||
self.events.drain(..).collect()
|
std::mem::take(&mut self.events)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -70,10 +70,13 @@ impl PartialEq for ComparableF32 {
|
|||||||
|
|
||||||
impl Eq for ComparableF32 {}
|
impl Eq for ComparableF32 {}
|
||||||
|
|
||||||
|
/// font name -> (font name, [(size, glyphs to preload)])
|
||||||
|
type RequiredFonts = HashMap<&'static str, (&'static str, Vec<(f32, &'static str)>)>;
|
||||||
|
|
||||||
pub struct FontMap {
|
pub struct FontMap {
|
||||||
fonts: HashMap<(&'static str, ComparableF32), draw::Font<'static>>,
|
fonts: HashMap<(&'static str, ComparableF32), draw::Font<'static>>,
|
||||||
font_paths: HashMap<&'static str, String>,
|
font_paths: HashMap<&'static str, String>,
|
||||||
required_fonts: HashMap<&'static str, (&'static str, Vec<(f32, &'static str)>)>,
|
required_fonts: RequiredFonts,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FontMap {
|
impl FontMap {
|
||||||
|
|||||||
+1
-1
@@ -44,7 +44,7 @@ pub struct KeymapDescription {
|
|||||||
|
|
||||||
impl KeymapDescription {
|
impl KeymapDescription {
|
||||||
fn new(fd: OwnedFd, size: u32) -> KeymapDescription {
|
fn new(fd: OwnedFd, size: u32) -> KeymapDescription {
|
||||||
KeymapDescription { fd: fd, size: size }
|
KeymapDescription { fd, size }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-11
@@ -81,17 +81,15 @@ impl KbState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn compose_feed(&mut self, keysym: u32) -> Option<xkb::compose::FeedResult> {
|
pub(crate) fn compose_feed(&mut self, keysym: u32) -> Option<xkb::compose::FeedResult> {
|
||||||
match &mut self.xkb_compose_state {
|
self.xkb_compose_state
|
||||||
Some(compose_state) => Some(compose_state.feed(xkb::Keysym::new(keysym))),
|
.as_mut()
|
||||||
None => None,
|
.map(|compose_state| compose_state.feed(xkb::Keysym::new(keysym)))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn compose_status(&mut self) -> Option<xkb::compose::Status> {
|
pub(crate) fn compose_status(&mut self) -> Option<xkb::compose::Status> {
|
||||||
match &mut self.xkb_compose_state {
|
self.xkb_compose_state
|
||||||
Some(compose_state) => Some(compose_state.status()),
|
.as_mut()
|
||||||
None => None,
|
.map(|compose_state| compose_state.status())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn compose_get_utf8(&mut self) -> Option<String> {
|
pub(crate) fn compose_get_utf8(&mut self) -> Option<String> {
|
||||||
@@ -130,11 +128,11 @@ impl KbState {
|
|||||||
|
|
||||||
pub(crate) fn init_compose(&mut self) {
|
pub(crate) fn init_compose(&mut self) {
|
||||||
let locale = env::var_os("LC_ALL")
|
let locale = env::var_os("LC_ALL")
|
||||||
.and_then(|v| if v.is_empty() { None } else { Some(v) })
|
.filter(|v| !v.is_empty())
|
||||||
.or_else(|| env::var_os("LC_CTYPE"))
|
.or_else(|| env::var_os("LC_CTYPE"))
|
||||||
.and_then(|v| if v.is_empty() { None } else { Some(v) })
|
.filter(|v| !v.is_empty())
|
||||||
.or_else(|| env::var_os("LANG"))
|
.or_else(|| env::var_os("LANG"))
|
||||||
.and_then(|v| if v.is_empty() { None } else { Some(v) })
|
.filter(|v| !v.is_empty())
|
||||||
.unwrap_or_else(|| "C".into());
|
.unwrap_or_else(|| "C".into());
|
||||||
|
|
||||||
let compose_table = match xkb::compose::Table::new_from_locale(
|
let compose_table = match xkb::compose::Table::new_from_locale(
|
||||||
|
|||||||
+13
-16
@@ -159,7 +159,7 @@ fn main() {
|
|||||||
handle
|
handle
|
||||||
.insert_source(
|
.insert_source(
|
||||||
WaylandSource::new(event_queue).expect("Could not create WaylandSource!"),
|
WaylandSource::new(event_queue).expect("Could not create WaylandSource!"),
|
||||||
|_event, queue, mut state| queue.dispatch_pending(&mut state),
|
|_event, queue, state| queue.dispatch_pending(state),
|
||||||
)
|
)
|
||||||
.expect("Failed to insert event source!");
|
.expect("Failed to insert event source!");
|
||||||
|
|
||||||
@@ -239,23 +239,20 @@ fn main() {
|
|||||||
.spawn(move || {
|
.spawn(move || {
|
||||||
let listener = UnixListener::bind(socket_path.clone()).unwrap();
|
let listener = UnixListener::bind(socket_path.clone()).unwrap();
|
||||||
loop {
|
loop {
|
||||||
match listener.accept() {
|
if let Ok((stream, _)) = listener.accept() {
|
||||||
Ok((stream, _)) => {
|
let _ = thread::Builder::new().name("ipc_client".to_string()).spawn(
|
||||||
let _ = thread::Builder::new().name("ipc_client".to_string()).spawn(
|
move || {
|
||||||
move || {
|
let r = BufReader::new(stream);
|
||||||
let r = BufReader::new(stream);
|
for line in r.lines() {
|
||||||
for line in r.lines() {
|
match line {
|
||||||
match line {
|
Ok(ref cmd) if cmd == "kill" => {
|
||||||
Ok(ref cmd) if cmd == "kill" => {
|
std::process::exit(0);
|
||||||
std::process::exit(0);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
);
|
},
|
||||||
}
|
);
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+29
-44
@@ -133,19 +133,16 @@ impl State {
|
|||||||
Ok(token) => token,
|
Ok(token) => token,
|
||||||
Err(_) => return,
|
Err(_) => return,
|
||||||
};
|
};
|
||||||
match (
|
if let (Some(surface), Some(activation)) = (
|
||||||
&self.main_surface.wl_surface,
|
&self.main_surface.wl_surface,
|
||||||
&self.protocols.xdg_activation,
|
&self.protocols.xdg_activation,
|
||||||
) {
|
) {
|
||||||
(Some(surface), Some(activation)) => {
|
activation.activate(key, surface);
|
||||||
activation.activate(key, surface);
|
let activation_token = activation.get_activation_token(qh, ());
|
||||||
let activation_token = activation.get_activation_token(qh, ());
|
activation_token.commit();
|
||||||
activation_token.commit();
|
unsafe {
|
||||||
unsafe {
|
env::remove_var("XDG_ACTIVATION_TOKEN");
|
||||||
env::remove_var("XDG_ACTIVATION_TOKEN");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -333,9 +330,8 @@ impl Dispatch<wl_callback::WlCallback, ()> for State {
|
|||||||
_: &Connection,
|
_: &Connection,
|
||||||
_: &QueueHandle<Self>,
|
_: &QueueHandle<Self>,
|
||||||
) {
|
) {
|
||||||
match event {
|
if let wl_callback::Event::Done { callback_data: _ } = event {
|
||||||
wl_callback::Event::Done { callback_data: _ } => state.ready = true,
|
state.ready = true
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -483,8 +479,8 @@ impl Dispatch<zwlr_layer_surface_v1::ZwlrLayerSurfaceV1, ()> for State {
|
|||||||
&Geometry {
|
&Geometry {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
width: width as u32,
|
width,
|
||||||
height: height as u32,
|
height,
|
||||||
},
|
},
|
||||||
state,
|
state,
|
||||||
);
|
);
|
||||||
@@ -676,13 +672,11 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for State {
|
|||||||
state.running = false;
|
state.running = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if repeats {
|
if repeats && let Event::KeyEvent(k) = ev {
|
||||||
if let Event::KeyEvent(k) = ev {
|
state
|
||||||
state
|
.keyrepeat_sender
|
||||||
.keyrepeat_sender
|
.send(RepeatMessage::KeyEvent(k))
|
||||||
.send(RepeatMessage::KeyEvent(k))
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
state.dirty = true;
|
state.dirty = true;
|
||||||
}
|
}
|
||||||
@@ -742,8 +736,8 @@ impl Dispatch<wl_pointer::WlPointer, ()> for State {
|
|||||||
state.pointer = Some((surface_x, surface_y));
|
state.pointer = Some((surface_x, surface_y));
|
||||||
}
|
}
|
||||||
wl_pointer::Event::Leave { .. } => state.pointer = None,
|
wl_pointer::Event::Leave { .. } => state.pointer = None,
|
||||||
wl_pointer::Event::Axis { axis, value, .. } => match state.pointer {
|
wl_pointer::Event::Axis { axis, value, .. } => {
|
||||||
Some((x, y)) => {
|
if let Some((x, y)) = state.pointer {
|
||||||
let axis = match axis {
|
let axis = match axis {
|
||||||
WEnum::Value(wl_pointer::Axis::VerticalScroll) => {
|
WEnum::Value(wl_pointer::Axis::VerticalScroll) => {
|
||||||
PointerButton::ScrollVertical(value)
|
PointerButton::ScrollVertical(value)
|
||||||
@@ -758,24 +752,22 @@ impl Dispatch<wl_pointer::WlPointer, ()> for State {
|
|||||||
let geo = widget.geometry();
|
let geo = widget.geometry();
|
||||||
if geo.contains(pos) {
|
if geo.contains(pos) {
|
||||||
let pos = (pos.0 - geo.x, pos.1 - geo.y);
|
let pos = (pos.0 - geo.x, pos.1 - geo.y);
|
||||||
let ev = Event::PointerEvent(PointerEvent {
|
let ev = Event::PointerEvent(PointerEvent { button: axis, pos });
|
||||||
button: axis,
|
|
||||||
pos: pos,
|
|
||||||
});
|
|
||||||
widget.event(&ev);
|
widget.event(&ev);
|
||||||
state.dirty = true;
|
state.dirty = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
}
|
||||||
},
|
|
||||||
wl_pointer::Event::Button {
|
wl_pointer::Event::Button {
|
||||||
button,
|
button,
|
||||||
state: button_state,
|
state: button_state,
|
||||||
..
|
..
|
||||||
} => match (button, button_state, state.pointer) {
|
} => {
|
||||||
(button, WEnum::Value(wl_pointer::ButtonState::Pressed), Some((x, y))) => {
|
if let (button, WEnum::Value(wl_pointer::ButtonState::Pressed), Some((x, y))) =
|
||||||
|
(button, button_state, state.pointer)
|
||||||
|
{
|
||||||
let button = match button {
|
let button = match button {
|
||||||
BTN_LEFT => PointerButton::Left,
|
BTN_LEFT => PointerButton::Left,
|
||||||
BTN_RIGHT => PointerButton::Right,
|
BTN_RIGHT => PointerButton::Right,
|
||||||
@@ -787,18 +779,14 @@ impl Dispatch<wl_pointer::WlPointer, ()> for State {
|
|||||||
let geo = widget.geometry();
|
let geo = widget.geometry();
|
||||||
if geo.contains(pos) {
|
if geo.contains(pos) {
|
||||||
let pos = (pos.0 - geo.x, pos.1 - geo.y);
|
let pos = (pos.0 - geo.x, pos.1 - geo.y);
|
||||||
let ev = Event::PointerEvent(PointerEvent {
|
let ev = Event::PointerEvent(PointerEvent { button, pos });
|
||||||
button: button,
|
|
||||||
pos: pos,
|
|
||||||
});
|
|
||||||
widget.event(&ev);
|
widget.event(&ev);
|
||||||
state.dirty = true;
|
state.dirty = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
}
|
||||||
},
|
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -861,14 +849,11 @@ impl Dispatch<xdg_activation_token_v1::XdgActivationTokenV1, ()> for State {
|
|||||||
_: &Connection,
|
_: &Connection,
|
||||||
_: &QueueHandle<Self>,
|
_: &QueueHandle<Self>,
|
||||||
) {
|
) {
|
||||||
match event {
|
if let xdg_activation_token_v1::Event::Done { token } = event {
|
||||||
xdg_activation_token_v1::Event::Done { token } => {
|
let ev = Event::TokenUpdate(token);
|
||||||
let ev = Event::TokenUpdate(token);
|
for widget in state.widgets.iter_mut() {
|
||||||
for widget in state.widgets.iter_mut() {
|
widget.event(&ev);
|
||||||
widget.event(&ev);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,10 +45,10 @@ impl Desktop {
|
|||||||
.map(|x| {
|
.map(|x| {
|
||||||
x.split(';')
|
x.split(';')
|
||||||
.map(|y| y.trim().to_string())
|
.map(|y| y.trim().to_string())
|
||||||
.filter(|z| z != "")
|
.filter(|z| !z.is_empty())
|
||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| vec![]),
|
.unwrap_or_else(std::vec::Vec::new),
|
||||||
}),
|
}),
|
||||||
None => Err(Box::new(io_error::new(
|
None => Err(Box::new(io_error::new(
|
||||||
ErrorKind::NotFound,
|
ErrorKind::NotFound,
|
||||||
|
|||||||
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
use std::{collections::HashMap, error::Error};
|
use std::{collections::HashMap, error::Error};
|
||||||
|
|
||||||
fn parse_field<'a>(line: &'a str) -> Result<(&'a str, &'a str), Box<dyn Error>> {
|
fn parse_field(line: &str) -> Result<(&str, &str), Box<dyn Error>> {
|
||||||
let split = match line.find('=') {
|
let split = match line.find('=') {
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
None => return Err("expected equals sign on line, but found none".into()),
|
None => return Err("expected equals sign on line, but found none".into()),
|
||||||
@@ -30,8 +30,8 @@ pub fn parse<'a>(s: &'a str) -> Result<Inish<'a>, Box<dyn Error>> {
|
|||||||
(Some('['), Some(']')) => {
|
(Some('['), Some(']')) => {
|
||||||
sections.insert(current_section_name, current_section);
|
sections.insert(current_section_name, current_section);
|
||||||
current_section = HashMap::new();
|
current_section = HashMap::new();
|
||||||
let len = line.bytes().count();
|
let len = line.len();
|
||||||
current_section_name = &line[1..len - 1].trim();
|
current_section_name = line[1..len - 1].trim();
|
||||||
}
|
}
|
||||||
(Some('['), v) => {
|
(Some('['), v) => {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fs::{self, OpenOptions},
|
fs::{self, OpenOptions},
|
||||||
io::{Error, ErrorKind, Write},
|
io::{Error, Write},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ fn read_file_as_u64(path: &Path) -> Result<u64, Error> {
|
|||||||
let mut s = fs::read_to_string(path)?;
|
let mut s = fs::read_to_string(path)?;
|
||||||
s.pop();
|
s.pop();
|
||||||
s.parse::<u64>()
|
s.parse::<u64>()
|
||||||
.map_err(|_e| Error::new(ErrorKind::Other, "unable to parse value"))
|
.map_err(|_e| Error::other("unable to parse value"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_file_as_u64(path: &Path, value: u64) -> Result<(), Error> {
|
fn write_file_as_u64(path: &Path, value: u64) -> Result<(), Error> {
|
||||||
@@ -54,6 +54,8 @@ impl Backlight {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wraps the impl in the generic BarWidget on purpose.
|
||||||
|
#[allow(clippy::new_ret_no_self)]
|
||||||
pub fn new(path: Option<&str>, fm: &mut FontMap, font: &'static str, size: f32) -> BarWidget {
|
pub fn new(path: Option<&str>, fm: &mut FontMap, font: &'static str, size: f32) -> BarWidget {
|
||||||
let device_path = match path {
|
let device_path = match path {
|
||||||
Some(path) => Some(Path::new("/sys/class/backlight").join(path)),
|
Some(path) => Some(Path::new("/sys/class/backlight").join(path)),
|
||||||
@@ -104,9 +106,8 @@ impl BarWidgetImpl for Backlight {
|
|||||||
}
|
}
|
||||||
fn click(&mut self, pos: f32, btn: PointerButton) {
|
fn click(&mut self, pos: f32, btn: PointerButton) {
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
match btn {
|
if let PointerButton::Left = btn {
|
||||||
PointerButton::Left => self.set(pos),
|
self.set(pos)
|
||||||
_ => (),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ impl Widget for BarWidget {
|
|||||||
x += geometry.width - w;
|
x += geometry.width - w;
|
||||||
}
|
}
|
||||||
self.geometry = Geometry {
|
self.geometry = Geometry {
|
||||||
x: x,
|
x,
|
||||||
y: geometry.y,
|
y: geometry.y,
|
||||||
width: w,
|
width: w,
|
||||||
height: self.size.ceil() as u32,
|
height: self.size.ceil() as u32,
|
||||||
@@ -97,15 +97,12 @@ impl Widget for BarWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn event(&mut self, event: &Event) {
|
fn event(&mut self, event: &Event) {
|
||||||
match event {
|
if let Event::PointerEvent(ev) = event {
|
||||||
Event::PointerEvent(ev) => {
|
let offset = 4 * self.size.ceil() as u32;
|
||||||
let offset = 4 * self.size.ceil() as u32;
|
if ev.pos.0 >= offset && self.geometry.width > offset {
|
||||||
if ev.pos.0 >= offset && self.geometry.width > offset {
|
let val = (ev.pos.0 - offset) as f32 / (self.geometry.width - offset) as f32;
|
||||||
let val = (ev.pos.0 - offset) as f32 / (self.geometry.width - offset) as f32;
|
self.inner_widget.click(val, ev.button);
|
||||||
self.inner_widget.click(val, ev.button);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,6 +138,8 @@ pub struct Battery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Battery {
|
impl Battery {
|
||||||
|
// Wraps the impl in the generic BarWidget on purpose.
|
||||||
|
#[allow(clippy::new_ret_no_self)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
events: Arc<Mutex<Events>>,
|
events: Arc<Mutex<Events>>,
|
||||||
fm: &mut FontMap,
|
fm: &mut FontMap,
|
||||||
|
|||||||
+10
-16
@@ -69,7 +69,7 @@ impl Calendar {
|
|||||||
fn draw_month(
|
fn draw_month(
|
||||||
&mut self,
|
&mut self,
|
||||||
fonts: &mut FontMap,
|
fonts: &mut FontMap,
|
||||||
mut view: &mut BufferView,
|
view: &mut BufferView,
|
||||||
orig: NaiveDate,
|
orig: NaiveDate,
|
||||||
mut time: NaiveDate,
|
mut time: NaiveDate,
|
||||||
) {
|
) {
|
||||||
@@ -100,7 +100,7 @@ impl Calendar {
|
|||||||
+ (self.size * DAY_FACTOR * 0.2).ceil() as u32,
|
+ (self.size * DAY_FACTOR * 0.2).ceil() as u32,
|
||||||
)),
|
)),
|
||||||
c,
|
c,
|
||||||
&wk_chr,
|
wk_chr,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
@@ -124,9 +124,7 @@ impl Calendar {
|
|||||||
12 => "December",
|
12 => "December",
|
||||||
_ => panic!("impossible value"),
|
_ => panic!("impossible value"),
|
||||||
};
|
};
|
||||||
month_font
|
month_font.draw_text(view, Color::WHITE, month_str).unwrap();
|
||||||
.draw_text(&mut view, Color::WHITE, month_str)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Draw the year
|
// Draw the year
|
||||||
@@ -199,7 +197,7 @@ impl Calendar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Widget for Calendar {
|
impl Widget for Calendar {
|
||||||
fn get_dirty(&self) -> bool {
|
fn get_dirty(&self) -> bool {
|
||||||
self.dirty
|
self.dirty
|
||||||
}
|
}
|
||||||
@@ -209,11 +207,8 @@ impl<'a> Widget for Calendar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn event(&mut self, event: &Event) {
|
fn event(&mut self, event: &Event) {
|
||||||
match event {
|
if let Event::NewMinute = event {
|
||||||
Event::NewMinute => {
|
self.dirty = true;
|
||||||
self.dirty = true;
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,9 +294,8 @@ impl<'a> Widget for Calendar {
|
|||||||
self.geometry = Geometry {
|
self.geometry = Geometry {
|
||||||
x: geometry.x,
|
x: geometry.x,
|
||||||
y: geometry.y,
|
y: geometry.y,
|
||||||
width: cal_width * self.shown_sections_x as u32
|
width: cal_width * self.shown_sections_x + cal_pad * (self.shown_sections_x - 1),
|
||||||
+ cal_pad * (self.shown_sections_x as u32 - 1),
|
height: cal_height * self.shown_sections_y,
|
||||||
height: cal_height * self.shown_sections_y as u32,
|
|
||||||
};
|
};
|
||||||
self.geometry
|
self.geometry
|
||||||
}
|
}
|
||||||
@@ -344,8 +338,8 @@ impl<'a> Widget for Calendar {
|
|||||||
Geometry {
|
Geometry {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
width: width,
|
width,
|
||||||
height: height,
|
height,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ pub struct Clock {
|
|||||||
colon_width: u32,
|
colon_width: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Clock {
|
impl Clock {
|
||||||
pub fn new(fm: &mut FontMap, font: &'static str, size: f32) -> Clock {
|
pub fn new(fm: &mut FontMap, font: &'static str, size: f32) -> Clock {
|
||||||
fm.queue_font(font, size, "0123456789: ");
|
fm.queue_font(font, size, "0123456789: ");
|
||||||
Clock {
|
Clock {
|
||||||
@@ -33,7 +33,7 @@ impl<'a> Clock {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Widget for Clock {
|
impl Widget for Clock {
|
||||||
fn get_dirty(&self) -> bool {
|
fn get_dirty(&self) -> bool {
|
||||||
self.dirty
|
self.dirty
|
||||||
}
|
}
|
||||||
@@ -43,11 +43,8 @@ impl<'a> Widget for Clock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn event(&mut self, event: &Event) {
|
fn event(&mut self, event: &Event) {
|
||||||
match event {
|
if let Event::NewMinute = event {
|
||||||
Event::NewMinute => {
|
self.dirty = true;
|
||||||
self.dirty = true;
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-6
@@ -29,7 +29,7 @@ impl Date {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Widget for Date {
|
impl Widget for Date {
|
||||||
fn get_dirty(&self) -> bool {
|
fn get_dirty(&self) -> bool {
|
||||||
self.dirty
|
self.dirty
|
||||||
}
|
}
|
||||||
@@ -39,11 +39,8 @@ impl<'a> Widget for Date {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn event(&mut self, event: &Event) {
|
fn event(&mut self, event: &Event) {
|
||||||
match event {
|
if let Event::NewMinute = event {
|
||||||
Event::NewMinute => {
|
self.dirty = true;
|
||||||
self.dirty = true;
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-12
@@ -120,7 +120,7 @@ impl Prompt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn append(&mut self, v: &str) {
|
fn append(&mut self, v: &str) {
|
||||||
if self.input.len() == 0 {
|
if self.input.is_empty() {
|
||||||
match v {
|
match v {
|
||||||
"!" => {
|
"!" => {
|
||||||
self.mode = PromptMode::Shell;
|
self.mode = PromptMode::Shell;
|
||||||
@@ -271,7 +271,7 @@ impl Launcher {
|
|||||||
|
|
||||||
Launcher {
|
Launcher {
|
||||||
next_token: None,
|
next_token: None,
|
||||||
options: options,
|
options,
|
||||||
matches: Vec::new(),
|
matches: Vec::new(),
|
||||||
launch_cmd,
|
launch_cmd,
|
||||||
}
|
}
|
||||||
@@ -354,7 +354,7 @@ impl InterfaceWidget for Launcher {
|
|||||||
.auto_draw_text_with_cursor(
|
.auto_draw_text_with_cursor(
|
||||||
&mut prompt_line,
|
&mut prompt_line,
|
||||||
fg,
|
fg,
|
||||||
&format!(" {}", &intf.prompt.input),
|
&format!(" {}", intf.prompt.input),
|
||||||
intf.prompt.cursor + 3,
|
intf.prompt.cursor + 3,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -474,7 +474,7 @@ impl InterfaceWidget for Shell {
|
|||||||
.auto_draw_text_with_cursor(
|
.auto_draw_text_with_cursor(
|
||||||
&mut prompt_line,
|
&mut prompt_line,
|
||||||
fg,
|
fg,
|
||||||
&format!(" {}", &intf.prompt.input),
|
&format!(" {}", intf.prompt.input),
|
||||||
intf.prompt.cursor + 3,
|
intf.prompt.cursor + 3,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -531,7 +531,7 @@ impl Calc {
|
|||||||
|
|
||||||
let old = self.old.lock().unwrap();
|
let old = self.old.lock().unwrap();
|
||||||
for (input, res) in old.iter() {
|
for (input, res) in old.iter() {
|
||||||
write!(f, "{}={}\n", input, res).unwrap();
|
writeln!(f, "{}={}", input, res).unwrap();
|
||||||
}
|
}
|
||||||
f.sync_data().unwrap();
|
f.sync_data().unwrap();
|
||||||
}
|
}
|
||||||
@@ -567,10 +567,7 @@ impl InterfaceWidget for Calc {
|
|||||||
rcalc_lib::parse::eval(&intf.prompt.input, &mut rcalc_lib::parse::CalcState::new())
|
rcalc_lib::parse::eval(&intf.prompt.input, &mut rcalc_lib::parse::CalcState::new())
|
||||||
.map(|x| format!("{}", x))
|
.map(|x| format!("{}", x))
|
||||||
.map_err(|x| format!("{}", x));
|
.map_err(|x| format!("{}", x));
|
||||||
self.result = match res {
|
self.result = res.ok();
|
||||||
Ok(v) => Some(v),
|
|
||||||
Err(_) => None,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(
|
fn draw(
|
||||||
@@ -593,7 +590,7 @@ impl InterfaceWidget for Calc {
|
|||||||
font.auto_draw_text_with_cursor(
|
font.auto_draw_text_with_cursor(
|
||||||
&mut prompt_line,
|
&mut prompt_line,
|
||||||
fg,
|
fg,
|
||||||
&format!(" {} ", &intf.prompt.input),
|
&format!(" {} ", intf.prompt.input),
|
||||||
intf.prompt.cursor + 3,
|
intf.prompt.cursor + 3,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -712,7 +709,7 @@ impl Interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn exit(&mut self) {
|
fn exit(&mut self) {
|
||||||
if self.inner.prompt.input.len() == 0 {
|
if self.inner.prompt.input.is_empty() {
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -810,7 +807,7 @@ impl Widget for Interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn geometry_update(&mut self, _fonts: &mut FontMap, geometry: &Geometry) -> Geometry {
|
fn geometry_update(&mut self, _fonts: &mut FontMap, geometry: &Geometry) -> Geometry {
|
||||||
self.inner.geometry = geometry.clone();
|
self.inner.geometry = *geometry;
|
||||||
self.inner.geometry
|
self.inner.geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// Constructors here deliberately return Box<dyn Layout> so configs compose.
|
||||||
|
#![allow(clippy::new_ret_no_self)]
|
||||||
|
|
||||||
use std::cmp::max;
|
use std::cmp::max;
|
||||||
|
|
||||||
use crate::{fonts::FontMap, state::State, widgets::Geometry};
|
use crate::{fonts::FontMap, state::State, widgets::Geometry};
|
||||||
@@ -30,7 +33,7 @@ impl Layout for HorizontalLayout {
|
|||||||
geometry: &Geometry,
|
geometry: &Geometry,
|
||||||
state: &mut State,
|
state: &mut State,
|
||||||
) -> Geometry {
|
) -> Geometry {
|
||||||
let mut geo = geometry.clone();
|
let mut geo = *geometry;
|
||||||
let mut max_width = 0;
|
let mut max_width = 0;
|
||||||
let mut max_height = 0;
|
let mut max_height = 0;
|
||||||
for w in self.widgets.iter() {
|
for w in self.widgets.iter() {
|
||||||
@@ -79,7 +82,7 @@ impl Layout for VerticalLayout {
|
|||||||
geometry: &Geometry,
|
geometry: &Geometry,
|
||||||
state: &mut State,
|
state: &mut State,
|
||||||
) -> Geometry {
|
) -> Geometry {
|
||||||
let mut geo = geometry.clone();
|
let mut geo = *geometry;
|
||||||
let mut max_width = 0;
|
let mut max_width = 0;
|
||||||
let mut max_height = 0;
|
let mut max_height = 0;
|
||||||
for w in self.widgets.iter() {
|
for w in self.widgets.iter() {
|
||||||
@@ -159,10 +162,10 @@ impl Layout for InvertedHorizontalLayout {
|
|||||||
geometry: &Geometry,
|
geometry: &Geometry,
|
||||||
state: &mut State,
|
state: &mut State,
|
||||||
) -> Geometry {
|
) -> Geometry {
|
||||||
let mut geo = geometry.clone();
|
let mut geo = *geometry;
|
||||||
let mut max_height = 0;
|
let mut max_height = 0;
|
||||||
for w in self.widgets.iter() {
|
for w in self.widgets.iter() {
|
||||||
let mut temp_geo = geo.clone();
|
let mut temp_geo = geo;
|
||||||
let temp_result = w.geometry_update(fonts, &temp_geo, state);
|
let temp_result = w.geometry_update(fonts, &temp_geo, state);
|
||||||
temp_geo.x = geo.x + (geo.width - temp_result.width);
|
temp_geo.x = geo.x + (geo.width - temp_result.width);
|
||||||
let result = w.geometry_update(fonts, &temp_geo, state);
|
let result = w.geometry_update(fonts, &temp_geo, state);
|
||||||
@@ -207,10 +210,10 @@ impl Layout for InvertedVerticalLayout {
|
|||||||
geometry: &Geometry,
|
geometry: &Geometry,
|
||||||
state: &mut State,
|
state: &mut State,
|
||||||
) -> Geometry {
|
) -> Geometry {
|
||||||
let mut geo = geometry.clone();
|
let mut geo = *geometry;
|
||||||
let mut max_width = 0;
|
let mut max_width = 0;
|
||||||
for w in self.widgets.iter() {
|
for w in self.widgets.iter() {
|
||||||
let mut temp_geo = geo.clone();
|
let mut temp_geo = geo;
|
||||||
let temp_result = w.geometry_update(fonts, &temp_geo, state);
|
let temp_result = w.geometry_update(fonts, &temp_geo, state);
|
||||||
temp_geo.y = geo.y + (geo.height - temp_result.height);
|
temp_geo.y = geo.y + (geo.height - temp_result.height);
|
||||||
let result = w.geometry_update(fonts, &temp_geo, state);
|
let result = w.geometry_update(fonts, &temp_geo, state);
|
||||||
|
|||||||
@@ -67,15 +67,15 @@ fn monitor(
|
|||||||
let local_inner = inner.clone();
|
let local_inner = inner.clone();
|
||||||
let local_events = events.clone();
|
let local_events = events.clone();
|
||||||
context.borrow_mut().set_subscribe_callback(Some(Box::new(
|
context.borrow_mut().set_subscribe_callback(Some(Box::new(
|
||||||
move |facility, _operation, index| match facility {
|
move |facility, _operation, index| {
|
||||||
Some(Facility::Sink) => {
|
if let Some(Facility::Sink) = facility {
|
||||||
let introspector = local_context.borrow_mut().introspect();
|
let introspector = local_context.borrow_mut().introspect();
|
||||||
let inner = local_inner.clone();
|
let inner = local_inner.clone();
|
||||||
let events = local_events.clone();
|
let events = local_events.clone();
|
||||||
introspector.get_sink_info_by_index(index, move |res| match res {
|
introspector.get_sink_info_by_index(index, move |res| match res {
|
||||||
ListResult::End | ListResult::Error => (),
|
ListResult::End | ListResult::Error => (),
|
||||||
ListResult::Item(sink_info) => {
|
ListResult::Item(sink_info) => {
|
||||||
if let Some(_) = &sink_info.name {
|
if sink_info.name.is_some() {
|
||||||
let avg = sink_info.volume.avg().0 as f32 / Volume::NORMAL.0 as f32;
|
let avg = sink_info.volume.avg().0 as f32 / Volume::NORMAL.0 as f32;
|
||||||
let mut inner = inner.lock().unwrap();
|
let mut inner = inner.lock().unwrap();
|
||||||
inner.volume = avg;
|
inner.volume = avg;
|
||||||
@@ -88,7 +88,6 @@ fn monitor(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
},
|
},
|
||||||
)));
|
)));
|
||||||
|
|
||||||
@@ -101,7 +100,7 @@ fn monitor(
|
|||||||
introspector.get_sink_info_by_name("@DEFAULT_SINK@", move |res| match res {
|
introspector.get_sink_info_by_name("@DEFAULT_SINK@", move |res| match res {
|
||||||
ListResult::End | ListResult::Error => (),
|
ListResult::End | ListResult::Error => (),
|
||||||
ListResult::Item(sink_info) => {
|
ListResult::Item(sink_info) => {
|
||||||
if let Some(_) = &sink_info.name {
|
if sink_info.name.is_some() {
|
||||||
let avg = sink_info.volume.avg().0 as f32 / Volume::NORMAL.0 as f32;
|
let avg = sink_info.volume.avg().0 as f32 / Volume::NORMAL.0 as f32;
|
||||||
let mut inner = local_inner.lock().unwrap();
|
let mut inner = local_inner.lock().unwrap();
|
||||||
inner.volume = avg;
|
inner.volume = avg;
|
||||||
@@ -119,7 +118,7 @@ fn monitor(
|
|||||||
let local_context = context.clone();
|
let local_context = context.clone();
|
||||||
let local_inner = inner.clone();
|
let local_inner = inner.clone();
|
||||||
let event_source = mainloop.new_io_event(
|
let event_source = mainloop.new_io_event(
|
||||||
pipe as i32,
|
pipe,
|
||||||
IoFlagSet::INPUT,
|
IoFlagSet::INPUT,
|
||||||
Box::new(move |_, _, _| {
|
Box::new(move |_, _, _| {
|
||||||
let mut buf = [0; 8];
|
let mut buf = [0; 8];
|
||||||
@@ -201,6 +200,8 @@ pub struct PulseAudio {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PulseAudio {
|
impl PulseAudio {
|
||||||
|
// Wraps the impl in the generic BarWidget on purpose.
|
||||||
|
#[allow(clippy::new_ret_no_self)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
events: Arc<Mutex<Events>>,
|
events: Arc<Mutex<Events>>,
|
||||||
fm: &mut FontMap,
|
fm: &mut FontMap,
|
||||||
|
|||||||
Reference in New Issue
Block a user