mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-07-01 15:57:46 +02:00
feat: Add dynamic window expansion
This commit is contained in:
parent
e03dad964b
commit
4836f1d8c2
10 changed files with 61 additions and 49 deletions
|
@ -5,14 +5,14 @@ use std::time::{Duration, SystemTime};
|
|||
|
||||
use adw::glib;
|
||||
use adw::glib::Object;
|
||||
use adw::prelude::{ComboRowExt, ListModelExtManual};
|
||||
use adw::prelude::{ComboRowExt, ListModelExtManual, PreferencesGroupExt};
|
||||
use adw::subclass::prelude::ObjectSubclassIsExt;
|
||||
use dbus::blocking::Connection;
|
||||
use dbus::message::SignalArgs;
|
||||
use dbus::{Error, Path};
|
||||
use glib::{clone, Cast};
|
||||
use gtk::glib::Variant;
|
||||
use gtk::prelude::{ActionableExt, BoxExt, ButtonExt, ListBoxRowExt, WidgetExt};
|
||||
use gtk::prelude::{ActionableExt, ButtonExt, ListBoxRowExt, WidgetExt};
|
||||
use gtk::{gio, StringObject, Widget};
|
||||
use ReSet_Lib::bluetooth::bluetooth::{BluetoothAdapter, BluetoothDevice};
|
||||
use ReSet_Lib::signals::{BluetoothDeviceAdded, BluetoothDeviceChanged, BluetoothDeviceRemoved};
|
||||
|
@ -183,9 +183,9 @@ pub fn populate_conntected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
|
|||
.borrow_mut()
|
||||
.insert(path, (bluetooth_entry.clone(), entry.clone(), device));
|
||||
if connected {
|
||||
imp.reset_bluetooth_connected_devices.append(&*entry);
|
||||
imp.reset_bluetooth_connected_devices.add(&*entry);
|
||||
} else {
|
||||
imp.reset_bluetooth_available_devices.append(&*entry);
|
||||
imp.reset_bluetooth_available_devices.add(&*entry);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -245,9 +245,9 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
|
|||
(bluetooth_entry.clone(), entry.clone(), ir.bluetooth_device),
|
||||
);
|
||||
if connected {
|
||||
imp.reset_bluetooth_connected_devices.append(&*entry);
|
||||
imp.reset_bluetooth_connected_devices.add(&*entry);
|
||||
} else {
|
||||
imp.reset_bluetooth_available_devices.append(&*entry);
|
||||
imp.reset_bluetooth_available_devices.add(&*entry);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -287,10 +287,10 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
|
|||
if let Some(list_entry) = map.get(&ir.bluetooth_device.path) {
|
||||
if list_entry.2.connected != ir.bluetooth_device.connected {
|
||||
if ir.bluetooth_device.connected {
|
||||
imp.reset_bluetooth_connected_devices.append(&*list_entry.1);
|
||||
imp.reset_bluetooth_connected_devices.add(&*list_entry.1);
|
||||
imp.reset_bluetooth_available_devices.remove(&*list_entry.1);
|
||||
} else {
|
||||
imp.reset_bluetooth_available_devices.append(&*list_entry.1);
|
||||
imp.reset_bluetooth_available_devices.add(&*list_entry.1);
|
||||
imp.reset_bluetooth_connected_devices.remove(&*list_entry.1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use adw::{ActionRow, ComboRow};
|
||||
use adw::{ActionRow, ComboRow, PreferencesGroup};
|
||||
use dbus::Path;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{glib, Button, CompositeTemplate, Switch};
|
||||
|
@ -21,13 +21,13 @@ pub struct BluetoothBox {
|
|||
#[template_child]
|
||||
pub reset_bluetooth_switch: TemplateChild<Switch>,
|
||||
#[template_child]
|
||||
pub reset_bluetooth_available_devices: TemplateChild<gtk::Box>,
|
||||
pub reset_bluetooth_available_devices: TemplateChild<PreferencesGroup>,
|
||||
#[template_child]
|
||||
pub reset_bluetooth_refresh_button: TemplateChild<Button>,
|
||||
#[template_child]
|
||||
pub reset_bluetooth_adapter: TemplateChild<ComboRow>,
|
||||
#[template_child]
|
||||
pub reset_bluetooth_connected_devices: TemplateChild<gtk::Box>,
|
||||
pub reset_bluetooth_connected_devices: TemplateChild<PreferencesGroup>,
|
||||
#[template_child]
|
||||
pub reset_visibility: TemplateChild<ActionRow>,
|
||||
#[template_child]
|
||||
|
|
|
@ -13,7 +13,7 @@ use crate::components::wifi::wifi_box::{
|
|||
scan_for_wifi, show_stored_connections, start_event_listener, WifiBox,
|
||||
};
|
||||
use gtk::prelude::WidgetExt;
|
||||
use gtk::{FlowBox, Frame};
|
||||
use gtk::{Align, FlowBox, FlowBoxChild, Frame};
|
||||
|
||||
pub const HANDLE_CONNECTIVITY_CLICK: fn(Arc<Listeners>, FlowBox) =
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox| {
|
||||
|
@ -22,11 +22,11 @@ pub const HANDLE_CONNECTIVITY_CLICK: fn(Arc<Listeners>, FlowBox) =
|
|||
start_event_listener(listeners.clone(), wifi_box.clone());
|
||||
show_stored_connections(wifi_box.clone());
|
||||
scan_for_wifi(wifi_box.clone());
|
||||
let wifi_frame = wrap_in_frame(SettingBox::new(&*wifi_box));
|
||||
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());
|
||||
let bluetooth_frame = wrap_in_frame(SettingBox::new(&*bluetooth_box));
|
||||
let bluetooth_frame = wrap_in_flow_box_child(SettingBox::new(&*bluetooth_box));
|
||||
reset_main.remove_all();
|
||||
reset_main.insert(&wifi_frame, -1);
|
||||
reset_main.insert(&bluetooth_frame, -1);
|
||||
|
@ -41,7 +41,7 @@ pub const HANDLE_WIFI_CLICK: fn(Arc<Listeners>, FlowBox) =
|
|||
start_event_listener(listeners.clone(), wifi_box.clone());
|
||||
show_stored_connections(wifi_box.clone());
|
||||
scan_for_wifi(wifi_box.clone());
|
||||
let wifi_frame = wrap_in_frame(SettingBox::new(&*wifi_box));
|
||||
let wifi_frame = wrap_in_flow_box_child(SettingBox::new(&*wifi_box));
|
||||
reset_main.remove_all();
|
||||
reset_main.insert(&wifi_frame, -1);
|
||||
reset_main.set_max_children_per_line(1);
|
||||
|
@ -54,7 +54,7 @@ pub const HANDLE_BLUETOOTH_CLICK: fn(Arc<Listeners>, FlowBox) =
|
|||
let bluetooth_box = BluetoothBox::new(listeners.clone());
|
||||
start_bluetooth_listener(listeners.clone(), bluetooth_box.clone());
|
||||
populate_conntected_bluetooth_devices(bluetooth_box.clone());
|
||||
let bluetooth_frame = wrap_in_frame(SettingBox::new(&*bluetooth_box));
|
||||
let bluetooth_frame = wrap_in_flow_box_child(SettingBox::new(&*bluetooth_box));
|
||||
reset_main.remove_all();
|
||||
reset_main.insert(&bluetooth_frame, -1);
|
||||
reset_main.set_max_children_per_line(1);
|
||||
|
@ -72,9 +72,9 @@ pub const HANDLE_AUDIO_CLICK: fn(Arc<Listeners>, FlowBox) =
|
|||
Some(audio_input.clone()),
|
||||
);
|
||||
populate_sinks(audio_output.clone());
|
||||
let audio_frame = wrap_in_frame(SettingBox::new(&*audio_output));
|
||||
let audio_frame = wrap_in_flow_box_child(SettingBox::new(&*audio_output));
|
||||
populate_sources(audio_input.clone());
|
||||
let source_frame = wrap_in_frame(SettingBox::new(&*audio_input));
|
||||
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(&source_frame, -1);
|
||||
|
@ -91,7 +91,7 @@ pub const HANDLE_VOLUME_CLICK: fn(Arc<Listeners>, FlowBox) =
|
|||
std::hint::spin_loop()
|
||||
}
|
||||
populate_sinks(audio_output.clone());
|
||||
let audio_frame = wrap_in_frame(SettingBox::new(&*audio_output));
|
||||
let audio_frame = wrap_in_flow_box_child(SettingBox::new(&*audio_output));
|
||||
reset_main.remove_all();
|
||||
reset_main.insert(&audio_frame, -1);
|
||||
reset_main.set_max_children_per_line(1);
|
||||
|
@ -104,7 +104,7 @@ pub const HANDLE_MICROPHONE_CLICK: fn(Arc<Listeners>, FlowBox) =
|
|||
let audio_input = Arc::new(SourceBox::new());
|
||||
start_audio_listener(listeners.clone(), None, Some(audio_input.clone()));
|
||||
populate_sources(audio_input.clone());
|
||||
let source_frame = wrap_in_frame(SettingBox::new(&*audio_input));
|
||||
let source_frame = wrap_in_flow_box_child(SettingBox::new(&*audio_input));
|
||||
reset_main.remove_all();
|
||||
reset_main.insert(&source_frame, -1);
|
||||
reset_main.set_max_children_per_line(1);
|
||||
|
@ -118,11 +118,15 @@ pub const HANDLE_HOME: fn(Arc<Listeners>, FlowBox) =
|
|||
reset_main.remove_all();
|
||||
};
|
||||
|
||||
fn wrap_in_frame(widget: SettingBox) -> Frame {
|
||||
fn wrap_in_flow_box_child(widget: SettingBox) -> FlowBoxChild {
|
||||
let frame = Frame::new(None);
|
||||
frame.set_child(Some(&widget));
|
||||
frame.add_css_class("resetSettingFrame");
|
||||
frame
|
||||
FlowBoxChild::builder()
|
||||
.child(&frame)
|
||||
.halign(Align::Fill)
|
||||
.valign(Align::Start)
|
||||
.build()
|
||||
}
|
||||
|
||||
// for future implementations
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use adw::glib::clone;
|
||||
use adw::subclass::prelude::ObjectSubclassIsExt;
|
||||
use adw::BreakpointCondition;
|
||||
use glib::Object;
|
||||
use adw::{ApplicationWindow, BreakpointCondition};
|
||||
use glib::{closure_local, Object};
|
||||
use gtk::prelude::*;
|
||||
use gtk::{gio, glib, Application, ListBoxRow, Orientation};
|
||||
|
||||
|
@ -12,7 +12,7 @@ use crate::components::window::sidebar_entry_impl::Categories;
|
|||
|
||||
glib::wrapper! {
|
||||
pub struct ReSetWindow(ObjectSubclass<reset_window_impl::ReSetWindow>)
|
||||
@extends gtk::ApplicationWindow, gtk::Window, gtk::Widget,
|
||||
@extends adw::ApplicationWindow, gtk::Window, gtk::Widget,
|
||||
@implements gio::ActionGroup, gio::ActionMap, gtk::Accessible, gtk::Buildable,
|
||||
gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager;
|
||||
}
|
||||
|
@ -54,18 +54,13 @@ impl ReSetWindow {
|
|||
.connect_clicked(clone!(@ weak self as window => move |_| {
|
||||
window.close();
|
||||
}));
|
||||
|
||||
// selfImp.resetMenu.connect_clicked(|_| {
|
||||
// WifiBox::donotdisturb();
|
||||
//
|
||||
// });
|
||||
}
|
||||
|
||||
pub fn handle_dynamic_sidebar(&self) {
|
||||
let self_imp = self.imp();
|
||||
self_imp
|
||||
.reset_sidebar_breakpoint
|
||||
.set_condition(BreakpointCondition::parse("max-width: 700sp").as_ref().ok());
|
||||
.set_condition(BreakpointCondition::parse("max-width: 950sp").as_ref().ok());
|
||||
self_imp.reset_sidebar_breakpoint.add_setter(
|
||||
&Object::from(self_imp.reset_overlay_split_view.get()),
|
||||
"collapsed",
|
||||
|
@ -143,6 +138,7 @@ impl ReSetWindow {
|
|||
true,
|
||||
HANDLE_BLUETOOTH_CLICK,
|
||||
),
|
||||
// uncommented when VPN is implemented
|
||||
// SidebarEntry::new(
|
||||
// "VPN",
|
||||
// "network-vpn-symbolic",
|
||||
|
@ -191,6 +187,7 @@ impl ReSetWindow {
|
|||
audio_list,
|
||||
));
|
||||
|
||||
// uncommented when implemented
|
||||
// let peripheralsList = vec![
|
||||
// SidebarEntry::new(
|
||||
// "Displays",
|
||||
|
|
|
@ -5,6 +5,7 @@ use adw::glib::StaticTypeExt;
|
|||
use adw::subclass::prelude::AdwApplicationWindowImpl;
|
||||
use adw::{Breakpoint, OverlaySplitView};
|
||||
use glib::subclass::InitializingObject;
|
||||
use gtk::prelude::WidgetExt;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{glib, Button, CompositeTemplate, FlowBox, ListBox, PopoverMenu, SearchEntry};
|
||||
|
||||
|
@ -74,7 +75,24 @@ impl ObjectImpl for ReSetWindow {
|
|||
}
|
||||
}
|
||||
|
||||
impl WidgetImpl for ReSetWindow {}
|
||||
impl WidgetImpl for ReSetWindow {
|
||||
fn size_allocate(&self, width: i32, height: i32, baseline: i32) {
|
||||
// felixusan, use "the force" for debugging
|
||||
// aka this variable
|
||||
// println!("{width}");
|
||||
self.parent_size_allocate(width, height, baseline);
|
||||
if width > 738 {
|
||||
self.reset_main.set_margin_start(100);
|
||||
self.reset_main.set_margin_end(100);
|
||||
} else if width > 600 {
|
||||
self.reset_main.set_margin_start((width - 600)/2);
|
||||
self.reset_main.set_margin_end((width - 600)/2);
|
||||
} else {
|
||||
self.reset_main.set_margin_start(0);
|
||||
self.reset_main.set_margin_end(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl WindowImpl for ReSetWindow {}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue