update gaypanel patch
This commit is contained in:
parent
eb79311fca
commit
cfbb162ccd
1 changed files with 8 additions and 80 deletions
|
|
@ -1,88 +1,28 @@
|
|||
diff --git a/src/system/sound.rs b/src/system/sound.rs
|
||||
index 3877f83..d7099fa 100644
|
||||
diff -ru a/src/system/sound.rs b/src/system/sound.rs
|
||||
--- a/src/system/sound.rs
|
||||
+++ b/src/system/sound.rs
|
||||
@@ -6,25 +6,21 @@ use alsa::{
|
||||
|
||||
use crate::{bus, system::SystemModule};
|
||||
|
||||
-/// Gets the default mixer. Throws an error if it doesn't exist (this means you probably don't have ALSA installed)
|
||||
+/// Gets the default mixer. Returns None if it doesn't exist (yet), e.g. if the sound server hasn't started
|
||||
macro_rules! mixer {
|
||||
() => {
|
||||
- Mixer::new("default", false).expect("[fatal] alsa: Could not find a mixer named \"default\". gaypanel assumes this is the name of the default mixer. \n[fatal] alsa: **If you have ALSA installed and running and you're *sure* of it, open an issue at codeberg.org/pastthepixels/gaypanel!**")
|
||||
+ Mixer::new("default", false).ok()
|
||||
};
|
||||
}
|
||||
|
||||
/// Finds the first selem with a playback volume in a mixer. Assumes this is the "default"
|
||||
/// e.g. this reflects the actual output volume. I don't know how alsa works.
|
||||
-/// You must have a speaker of some kind or else this'll crap out
|
||||
+/// Returns None if there's no speaker of some kind (yet)
|
||||
macro_rules! sink {
|
||||
($m: expr) => {
|
||||
$m.iter()
|
||||
.flat_map(|e| Selem::new(e))
|
||||
.find(|s| s.has_playback_volume())
|
||||
- .expect(&format!(
|
||||
- "[fatal] alsa: Could not find default sink for mixer {:?}",
|
||||
- $m
|
||||
- ))
|
||||
};
|
||||
}
|
||||
|
||||
@@ -54,9 +50,9 @@ impl SystemModule for VolumeModule {
|
||||
bus!(VolumeModule);
|
||||
|
||||
fn get() -> Option<Self::ReturnType> {
|
||||
- let mixer = mixer!();
|
||||
+ let mixer = mixer!()?;
|
||||
// Sink stats
|
||||
- let sink = sink!(mixer);
|
||||
+ let sink = sink!(mixer)?;
|
||||
let vol = {
|
||||
let max = sink.get_playback_volume_range().1 as f64;
|
||||
let raw_vol = sink
|
||||
@@ -101,8 +97,12 @@ impl SystemModule for VolumeModule {
|
||||
|
||||
fn set(val: Self::ReturnType) {
|
||||
// Sets sink volume
|
||||
- let mixer = mixer!();
|
||||
- let sink = sink!(mixer);
|
||||
+ let Some(mixer) = mixer!() else {
|
||||
+ return;
|
||||
+ };
|
||||
+ let Some(sink) = sink!(mixer) else {
|
||||
+ return;
|
||||
+ };
|
||||
let max = sink.get_playback_volume_range().1 as f64;
|
||||
sink.set_playback_volume_all((val.0.volume * max) as i64)
|
||||
.unwrap();
|
||||
@@ -118,8 +118,17 @@ impl SystemModule for VolumeModule {
|
||||
@@ -158,7 +158,16 @@
|
||||
|
||||
fn init() {
|
||||
std::thread::spawn(|| {
|
||||
- let mixer = mixer!();
|
||||
- let sink = sink!(mixer);
|
||||
- let mixer = mixer!().unwrap();
|
||||
+ // Wait for the sound server to provide a mixer with a sink
|
||||
+ let mixer = loop {
|
||||
+ if let Some(mixer) = mixer!() {
|
||||
+ let has_sink = sink!(mixer).is_some();
|
||||
+ if let Ok(mixer) = mixer!() {
|
||||
+ let has_sink = sink!(mixer).is_ok();
|
||||
+ if has_sink {
|
||||
+ break mixer;
|
||||
+ }
|
||||
+ }
|
||||
+ std::thread::sleep(std::time::Duration::from_secs(1));
|
||||
+ };
|
||||
+ let sink = sink!(mixer).unwrap();
|
||||
let sink = sink!(mixer).unwrap();
|
||||
let source = source!(mixer);
|
||||
let mut pollfds = mixer.get().unwrap();
|
||||
|
||||
diff --git a/src/ui/system/imp.rs b/src/ui/system/imp.rs
|
||||
index cf4f57f..c843d2b 100644
|
||||
diff -ru a/src/ui/system/imp.rs b/src/ui/system/imp.rs
|
||||
--- a/src/ui/system/imp.rs
|
||||
+++ b/src/ui/system/imp.rs
|
||||
@@ -232,7 +232,10 @@ impl ControlCenter {
|
||||
@@ -232,7 +232,10 @@
|
||||
let controller = gtk::EventControllerScroll::new(gtk::EventControllerScrollFlags::VERTICAL);
|
||||
controller.connect_scroll(|_, _, b| {
|
||||
glib::spawn_future_local(async move {
|
||||
|
|
@ -94,15 +34,3 @@ index cf4f57f..c843d2b 100644
|
|||
- b.signum() * VOLUME_SCROLL_STEP)
|
||||
.clamp(0., 1.);
|
||||
system::sound::VolumeModule::set((
|
||||
@@ -277,7 +280,10 @@ impl ControlCenter {
|
||||
}
|
||||
|
||||
// Sound
|
||||
- self.update_sound(system::sound::VolumeModule::get().unwrap());
|
||||
+ // The listener sends an update once sound is available, so it's fine to skip this
|
||||
+ if let Some(stats) = system::sound::VolumeModule::get() {
|
||||
+ self.update_sound(stats);
|
||||
+ }
|
||||
listen!(sound::VolumeModule, update_sound);
|
||||
|
||||
// Battery
|
||||
|
|
|
|||
Loading…
Reference in a new issue