mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-07-12 12:57:44 +02:00
fix: Update default sink and source after setting it
This commit is contained in:
parent
d3bc2edf88
commit
049a846c36
15 changed files with 425 additions and 258 deletions
|
@ -1,8 +1,10 @@
|
|||
use gtk::prelude::FrameExt;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::components::base::setting_box::SettingBox;
|
||||
use crate::components::base::utils::{start_audio_listener, Listeners};
|
||||
use crate::components::base::utils::{start_audio_listener, Listeners, Position};
|
||||
use crate::components::bluetooth::bluetooth_box::{
|
||||
populate_conntected_bluetooth_devices, start_bluetooth_listener, BluetoothBox,
|
||||
};
|
||||
|
@ -14,9 +16,11 @@ use crate::components::wifi::wifi_box::{
|
|||
use gtk::prelude::WidgetExt;
|
||||
use gtk::{Align, FlowBox, FlowBoxChild, Frame};
|
||||
|
||||
pub const HANDLE_CONNECTIVITY_CLICK: fn(Arc<Listeners>, FlowBox) =
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox| {
|
||||
listeners.stop_audio_listener();
|
||||
pub const HANDLE_CONNECTIVITY_CLICK: fn(Arc<Listeners>, FlowBox, Rc<RefCell<Position>>) =
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox, position: Rc<RefCell<Position>>| {
|
||||
if handle_init(listeners.clone(), position, Position::Connectivity) {
|
||||
return;
|
||||
}
|
||||
let wifi_box = WifiBox::new(listeners.clone());
|
||||
start_event_listener(listeners.clone(), wifi_box.clone());
|
||||
show_stored_connections(wifi_box.clone());
|
||||
|
@ -24,7 +28,7 @@ pub const HANDLE_CONNECTIVITY_CLICK: fn(Arc<Listeners>, FlowBox) =
|
|||
let wifi_frame = wrap_in_flow_box_child(SettingBox::new(&*wifi_box));
|
||||
let bluetooth_box = BluetoothBox::new(listeners.clone());
|
||||
populate_conntected_bluetooth_devices(bluetooth_box.clone());
|
||||
start_bluetooth_listener(listeners.clone(), bluetooth_box.clone());
|
||||
start_bluetooth_listener(listeners, bluetooth_box.clone());
|
||||
let bluetooth_frame = wrap_in_flow_box_child(SettingBox::new(&*bluetooth_box));
|
||||
reset_main.remove_all();
|
||||
reset_main.insert(&wifi_frame, -1);
|
||||
|
@ -32,12 +36,13 @@ pub const HANDLE_CONNECTIVITY_CLICK: fn(Arc<Listeners>, FlowBox) =
|
|||
reset_main.set_max_children_per_line(2);
|
||||
};
|
||||
|
||||
pub const HANDLE_WIFI_CLICK: fn(Arc<Listeners>, FlowBox) =
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox| {
|
||||
listeners.stop_audio_listener();
|
||||
listeners.stop_bluetooth_listener();
|
||||
pub const HANDLE_WIFI_CLICK: fn(Arc<Listeners>, FlowBox, Rc<RefCell<Position>>) =
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox, position: Rc<RefCell<Position>>| {
|
||||
if handle_init(listeners.clone(), position, Position::Wifi) {
|
||||
return;
|
||||
}
|
||||
let wifi_box = WifiBox::new(listeners.clone());
|
||||
start_event_listener(listeners.clone(), wifi_box.clone());
|
||||
start_event_listener(listeners, wifi_box.clone());
|
||||
show_stored_connections(wifi_box.clone());
|
||||
scan_for_wifi(wifi_box.clone());
|
||||
let wifi_frame = wrap_in_flow_box_child(SettingBox::new(&*wifi_box));
|
||||
|
@ -46,12 +51,13 @@ pub const HANDLE_WIFI_CLICK: fn(Arc<Listeners>, FlowBox) =
|
|||
reset_main.set_max_children_per_line(1);
|
||||
};
|
||||
|
||||
pub const HANDLE_BLUETOOTH_CLICK: fn(Arc<Listeners>, FlowBox) =
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox| {
|
||||
listeners.stop_network_listener();
|
||||
listeners.stop_audio_listener();
|
||||
pub const HANDLE_BLUETOOTH_CLICK: fn(Arc<Listeners>, FlowBox, Rc<RefCell<Position>>) =
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox, position: Rc<RefCell<Position>>| {
|
||||
if handle_init(listeners.clone(), position, Position::Bluetooth) {
|
||||
return;
|
||||
}
|
||||
let bluetooth_box = BluetoothBox::new(listeners.clone());
|
||||
start_bluetooth_listener(listeners.clone(), bluetooth_box.clone());
|
||||
start_bluetooth_listener(listeners, bluetooth_box.clone());
|
||||
populate_conntected_bluetooth_devices(bluetooth_box.clone());
|
||||
let bluetooth_frame = wrap_in_flow_box_child(SettingBox::new(&*bluetooth_box));
|
||||
reset_main.remove_all();
|
||||
|
@ -59,33 +65,35 @@ pub const HANDLE_BLUETOOTH_CLICK: fn(Arc<Listeners>, FlowBox) =
|
|||
reset_main.set_max_children_per_line(1);
|
||||
};
|
||||
|
||||
pub const HANDLE_AUDIO_CLICK: fn(Arc<Listeners>, FlowBox) =
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox| {
|
||||
listeners.stop_network_listener();
|
||||
listeners.stop_bluetooth_listener();
|
||||
pub const HANDLE_AUDIO_CLICK: fn(Arc<Listeners>, FlowBox, Rc<RefCell<Position>>) =
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox, position: Rc<RefCell<Position>>| {
|
||||
if handle_init(listeners.clone(), position, Position::Audio) {
|
||||
return;
|
||||
}
|
||||
let audio_output = Arc::new(SinkBox::new());
|
||||
let audio_input = Arc::new(SourceBox::new());
|
||||
start_audio_listener(
|
||||
listeners.clone(),
|
||||
listeners,
|
||||
Some(audio_output.clone()),
|
||||
Some(audio_input.clone()),
|
||||
);
|
||||
populate_sinks(audio_output.clone());
|
||||
let audio_frame = wrap_in_flow_box_child(SettingBox::new(&*audio_output));
|
||||
populate_sources(audio_input.clone());
|
||||
let sink_frame = wrap_in_flow_box_child(SettingBox::new(&*audio_output));
|
||||
let source_frame = wrap_in_flow_box_child(SettingBox::new(&*audio_input));
|
||||
reset_main.remove_all();
|
||||
reset_main.insert(&audio_frame, -1);
|
||||
reset_main.insert(&sink_frame, -1);
|
||||
reset_main.insert(&source_frame, -1);
|
||||
reset_main.set_max_children_per_line(2);
|
||||
};
|
||||
|
||||
pub const HANDLE_VOLUME_CLICK: fn(Arc<Listeners>, FlowBox) =
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox| {
|
||||
listeners.stop_network_listener();
|
||||
listeners.stop_bluetooth_listener();
|
||||
pub const HANDLE_VOLUME_CLICK: fn(Arc<Listeners>, FlowBox, Rc<RefCell<Position>>) =
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox, position: Rc<RefCell<Position>>| {
|
||||
if handle_init(listeners.clone(), position, Position::AudioOutput) {
|
||||
return;
|
||||
}
|
||||
let audio_output = Arc::new(SinkBox::new());
|
||||
start_audio_listener(listeners.clone(), Some(audio_output.clone()), None);
|
||||
start_audio_listener(listeners, Some(audio_output.clone()), None);
|
||||
populate_sinks(audio_output.clone());
|
||||
let audio_frame = wrap_in_flow_box_child(SettingBox::new(&*audio_output));
|
||||
reset_main.remove_all();
|
||||
|
@ -93,12 +101,13 @@ pub const HANDLE_VOLUME_CLICK: fn(Arc<Listeners>, FlowBox) =
|
|||
reset_main.set_max_children_per_line(1);
|
||||
};
|
||||
|
||||
pub const HANDLE_MICROPHONE_CLICK: fn(Arc<Listeners>, FlowBox) =
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox| {
|
||||
listeners.stop_network_listener();
|
||||
listeners.stop_bluetooth_listener();
|
||||
pub const HANDLE_MICROPHONE_CLICK: fn(Arc<Listeners>, FlowBox, Rc<RefCell<Position>>) =
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox, position: Rc<RefCell<Position>>| {
|
||||
if handle_init(listeners.clone(), position, Position::AudioInput) {
|
||||
return;
|
||||
}
|
||||
let audio_input = Arc::new(SourceBox::new());
|
||||
start_audio_listener(listeners.clone(), None, Some(audio_input.clone()));
|
||||
start_audio_listener(listeners, None, Some(audio_input.clone()));
|
||||
populate_sources(audio_input.clone());
|
||||
let source_frame = wrap_in_flow_box_child(SettingBox::new(&*audio_input));
|
||||
reset_main.remove_all();
|
||||
|
@ -106,11 +115,11 @@ pub const HANDLE_MICROPHONE_CLICK: fn(Arc<Listeners>, FlowBox) =
|
|||
reset_main.set_max_children_per_line(1);
|
||||
};
|
||||
|
||||
pub const HANDLE_HOME: fn(Arc<Listeners>, FlowBox) =
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox| {
|
||||
listeners.stop_network_listener();
|
||||
listeners.stop_audio_listener();
|
||||
listeners.stop_bluetooth_listener();
|
||||
pub const HANDLE_HOME: fn(Arc<Listeners>, FlowBox, Rc<RefCell<Position>>) =
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox, position: Rc<RefCell<Position>>| {
|
||||
if handle_init(listeners, position, Position::Home) {
|
||||
return;
|
||||
}
|
||||
reset_main.remove_all();
|
||||
};
|
||||
|
||||
|
@ -125,6 +134,24 @@ fn wrap_in_flow_box_child(widget: SettingBox) -> FlowBoxChild {
|
|||
.build()
|
||||
}
|
||||
|
||||
fn handle_init(
|
||||
listeners: Arc<Listeners>,
|
||||
position: Rc<RefCell<Position>>,
|
||||
clicked_position: Position,
|
||||
) -> bool {
|
||||
{
|
||||
let mut pos_borrow = position.borrow_mut();
|
||||
if *pos_borrow == clicked_position {
|
||||
return true;
|
||||
}
|
||||
*pos_borrow = clicked_position;
|
||||
}
|
||||
listeners.stop_network_listener();
|
||||
listeners.stop_audio_listener();
|
||||
listeners.stop_bluetooth_listener();
|
||||
false
|
||||
}
|
||||
|
||||
// for future implementations
|
||||
// pub const HANDLE_VPN_CLICK: fn(Arc<Listeners>, FlowBox) =
|
||||
// |listeners: Arc<Listeners>, resetMain: FlowBox| {
|
||||
|
|
|
@ -45,7 +45,7 @@ impl ReSetWindow {
|
|||
clone!(@ weak self_imp as flowbox => move |_, y| {
|
||||
let result = y.downcast_ref::<SidebarEntry>().unwrap();
|
||||
let click_event = result.imp().on_click_event.borrow().on_click_event;
|
||||
(click_event)(flowbox.listeners.clone(), flowbox.reset_main.get());
|
||||
(click_event)(flowbox.listeners.clone(), flowbox.reset_main.get(), flowbox.position.clone());
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use adw::glib::StaticTypeExt;
|
||||
|
@ -9,7 +10,7 @@ use gtk::prelude::WidgetExt;
|
|||
use gtk::subclass::prelude::*;
|
||||
use gtk::{glib, Button, CompositeTemplate, FlowBox, ListBox, PopoverMenu, SearchEntry};
|
||||
|
||||
use crate::components::base::utils::Listeners;
|
||||
use crate::components::base::utils::{Listeners, Position};
|
||||
use crate::components::wifi::wifi_box::WifiBox;
|
||||
use crate::components::window::reset_window;
|
||||
use crate::components::window::sidebar_entry::SidebarEntry;
|
||||
|
@ -41,6 +42,7 @@ pub struct ReSetWindow {
|
|||
pub reset_shortcuts_button: TemplateChild<Button>,
|
||||
pub sidebar_entries: RefCell<Vec<(SidebarEntry, Vec<SidebarEntry>)>>,
|
||||
pub listeners: Arc<Listeners>,
|
||||
pub position: Rc<RefCell<Position>>,
|
||||
}
|
||||
|
||||
unsafe impl Send for ReSetWindow {}
|
||||
|
@ -83,7 +85,7 @@ impl WidgetImpl for ReSetWindow {
|
|||
self.reset_main.set_margin_end(60);
|
||||
} else {
|
||||
let div = (width - 540) / 2;
|
||||
if div > 1 {
|
||||
if div > 1 {
|
||||
self.reset_main.set_margin_start(div);
|
||||
self.reset_main.set_margin_end(div);
|
||||
} else {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::components::base::utils::Listeners;
|
||||
use crate::components::base::utils::{Listeners, Position};
|
||||
use crate::components::window::sidebar_entry_impl;
|
||||
use crate::components::window::sidebar_entry_impl::{Categories, SidebarAction};
|
||||
use adw::subclass::prelude::ObjectSubclassIsExt;
|
||||
|
@ -20,7 +22,7 @@ impl SidebarEntry {
|
|||
icon_name: &str,
|
||||
category: Categories,
|
||||
is_subcategory: bool,
|
||||
click_event: fn(Arc<Listeners>, FlowBox),
|
||||
click_event: fn(Arc<Listeners>, FlowBox, Rc<RefCell<Position>>),
|
||||
) -> Self {
|
||||
let entry: SidebarEntry = Object::builder().build();
|
||||
let entry_imp = entry.imp();
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
use std::cell::{Cell, RefCell};
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use glib::subclass::InitializingObject;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{glib, CompositeTemplate, FlowBox, Image, Label, ListBoxRow};
|
||||
|
||||
use crate::components::base::utils::Listeners;
|
||||
use crate::components::base::utils::{Listeners, Position};
|
||||
use crate::components::window::handle_sidebar_click::HANDLE_HOME;
|
||||
use crate::components::window::sidebar_entry;
|
||||
|
||||
|
@ -32,7 +33,7 @@ pub struct SidebarEntry {
|
|||
}
|
||||
|
||||
pub struct SidebarAction {
|
||||
pub on_click_event: fn(Arc<Listeners>, FlowBox),
|
||||
pub on_click_event: fn(Arc<Listeners>, FlowBox, Rc<RefCell<Position>>),
|
||||
}
|
||||
|
||||
impl Default for SidebarAction {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue