-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turn PwVolumeBox into a common parent class.
- Loading branch information
Showing
10 changed files
with
401 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- SPDX-License-Identifier: GPL-3.0-or-later --> | ||
<interface> | ||
<requires lib="gtk" version="4.0" /> | ||
<requires lib="Adw" version="1.0" /> | ||
<template class="PwOutputBox" parent="PwVolumeBox"> | ||
<child type="extra"> | ||
<object class="GtkLabel" id="onlabel"> | ||
<property name="label" translatable="yes">on</property> | ||
<!-- <property name="visible" bind-source="outputdevice_dropdown" | ||
bind-property="visible" bind-flags="sync-create" /> --> | ||
</object> | ||
|
||
<object class="PwOutputDropDown" id="output_dropdown"> | ||
</object> | ||
</child> | ||
</template> | ||
|
||
</interface> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- SPDX-License-Identifier: GPL-3.0-or-later --> | ||
<interface> | ||
<requires lib="gtk" version="4.0" /> | ||
<requires lib="Adw" version="1.0" /> | ||
<template class="PwSinkBox" parent="PwVolumeBox"> | ||
<child type="extra"> | ||
<object class="GtkToggleButton" id="default_sink_toggle"> | ||
<property name="hexpand">0</property> | ||
<property name="valign">center</property> | ||
<signal name="toggled" handler="default_sink_toggle_toggled" swapped="true" /> | ||
<style> | ||
<class name="suffixes" /> | ||
<class name="expander-row-arrow" /> | ||
</style> | ||
<property name="icon-name">emblem-default-symbolic</property> | ||
</object> | ||
</child> | ||
</template> | ||
|
||
</interface> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
use crate::{ | ||
application::PwvucontrolApplication, | ||
pwnodeobject::PwNodeObject, | ||
volumebox::{PwVolumeBox, PwVolumeBoxImpl}, | ||
output_dropdown::PwOutputDropDown, | ||
}; | ||
use glib::{closure_local, clone}; | ||
use gtk::{prelude::*, subclass::prelude::*}; | ||
use wireplumber as wp; | ||
|
||
mod imp { | ||
use super::*; | ||
|
||
#[derive(Default, gtk::CompositeTemplate)] | ||
#[template(resource = "/com/saivert/pwvucontrol/gtk/outputbox.ui")] | ||
pub struct PwOutputBox { | ||
#[template_child] | ||
pub output_dropdown: TemplateChild<PwOutputDropDown>, | ||
} | ||
|
||
#[glib::object_subclass] | ||
impl ObjectSubclass for PwOutputBox { | ||
const NAME: &'static str = "PwOutputBox"; | ||
type Type = super::PwOutputBox; | ||
type ParentType = PwVolumeBox; | ||
|
||
fn class_init(klass: &mut Self::Class) { | ||
klass.bind_template(); | ||
} | ||
|
||
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) { | ||
obj.init_template(); | ||
} | ||
} | ||
|
||
impl ObjectImpl for PwOutputBox { | ||
fn constructed(&self) { | ||
|
||
let app = PwvucontrolApplication::default(); | ||
let manager = app.manager(); | ||
|
||
let obj = self.obj(); | ||
let parent: &PwVolumeBox = obj.upcast_ref(); | ||
let item = parent.row_data().expect("nodeobj"); | ||
|
||
parent.add_default_node_change_handler(clone!(@weak self as widget => move || { | ||
widget.obj().update_output_device_dropdown(); | ||
})); | ||
|
||
self.parent_constructed(); | ||
|
||
|
||
if let Some(metadata) = manager.imp().metadata.borrow().as_ref() { | ||
let boundid = item.boundid(); | ||
let widget = self.obj(); | ||
let changed_closure = closure_local!(@watch widget => | ||
move |_obj: &wp::pw::Metadata, id: u32, key: Option<String>, _type: Option<String>, _value: Option<String>| { | ||
let key = key.unwrap_or_default(); | ||
if id == boundid && key.contains("target.") { | ||
wp::log::info!("metadata changed handler id: {boundid} {key:?} {_value:?}!"); | ||
widget.update_output_device_dropdown(); | ||
} | ||
}); | ||
metadata.connect_closure("changed", false, changed_closure); | ||
} | ||
|
||
// Create our custom output dropdown widget and add it to the layout | ||
self.output_dropdown.set_nodeobj(Some(&item)); | ||
|
||
glib::idle_add_local_once(clone!(@weak self as widget => move || { | ||
widget.obj().update_output_device_dropdown(); | ||
})); | ||
} | ||
|
||
} | ||
impl WidgetImpl for PwOutputBox {} | ||
impl ListBoxRowImpl for PwOutputBox {} | ||
impl PwVolumeBoxImpl for PwOutputBox {} | ||
|
||
impl PwOutputBox { | ||
|
||
} | ||
} | ||
|
||
glib::wrapper! { | ||
pub struct PwOutputBox(ObjectSubclass<imp::PwOutputBox>) | ||
@extends gtk::Widget, gtk::ListBoxRow, PwVolumeBox, | ||
@implements gtk::Actionable; | ||
} | ||
|
||
impl PwOutputBox { | ||
pub(crate) fn new(row_data: &impl glib::IsA<PwNodeObject>) -> Self { | ||
glib::Object::builder() | ||
.property("row-data", row_data) | ||
// .property( | ||
// "channelmodel", | ||
// gio::ListStore::new::<crate::pwchannelobject::PwChannelObject>(), | ||
// ) | ||
.build() | ||
} | ||
|
||
pub(crate) fn update_output_device_dropdown(&self) { | ||
let app = PwvucontrolApplication::default(); | ||
let manager = app.manager(); | ||
|
||
let sinkmodel = &manager.imp().sinkmodel; | ||
|
||
let imp = self.imp(); | ||
let parent: &PwVolumeBox = self.upcast_ref(); | ||
|
||
let output_dropdown = imp.output_dropdown.get(); | ||
|
||
let id = parent.imp().default_node.get(); | ||
|
||
let string = if let Ok(node) = sinkmodel.get_node(id) { | ||
format!("Default ({})", node.name().unwrap()) | ||
} else { | ||
"Default".to_string() | ||
}; | ||
output_dropdown.set_default_text(&string); | ||
|
||
let item = parent.row_data().expect("row_data in pwvolumebox"); | ||
|
||
if let Some(deftarget) = item.default_target() { | ||
// let model: gio::ListModel = imp | ||
// .outputdevice_dropdown | ||
// .model() | ||
// .expect("Model from dropdown") | ||
// .downcast() | ||
// .unwrap(); | ||
// let pos = model.iter::<glib::Object>().enumerate().find_map(|o| { | ||
// if let Ok(Ok(node)) = o.1.map(|x| x.downcast::<PwNodeObject>()) { | ||
// if node.boundid() == deftarget.boundid() { | ||
// return Some(o.0); | ||
// } | ||
// } | ||
// None | ||
// }); | ||
|
||
if let Some(pos) = sinkmodel.get_node_pos_from_id(deftarget.boundid()) { | ||
wp::log::info!( | ||
"switching to preferred target pos={pos} boundid={} serial={}", | ||
deftarget.boundid(), | ||
deftarget.serial() | ||
); | ||
output_dropdown.set_selected_no_send(pos+1); | ||
} | ||
} else { | ||
output_dropdown.set_selected_no_send(0); | ||
|
||
// let id = self.imp().default_node.get(); | ||
// wp::log::info!("default_node is {id}"); | ||
// if id != u32::MAX { | ||
// if let Some(pos) = sinkmodel.get_node_pos_from_id(id) { | ||
// wp::log::info!("switching to default target"); | ||
// if true | ||
// /* imp.outputdevice_dropdown.selected() != pos */ | ||
// { | ||
// wp::log::info!("actually switching to default target"); | ||
// imp.outputdevice_dropdown_block_signal.set(true); | ||
// imp.outputdevice_dropdown.set_selected(pos); | ||
// imp.outputdevice_dropdown_block_signal.set(false); | ||
// } | ||
// } | ||
// } | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.