This commit is contained in:
@@ -14,7 +14,7 @@ use crate::backend::brightness_control::{BrightnessManager, BrightnessMessage};
|
|||||||
use crate::backend::commands::ControlSocket;
|
use crate::backend::commands::ControlSocket;
|
||||||
use crate::backend::idle::{IdleDaemon, IdleMessage, IdleState};
|
use crate::backend::idle::{IdleDaemon, IdleMessage, IdleState};
|
||||||
use crate::backend::json_socket::{JsonSocketBackend, State};
|
use crate::backend::json_socket::{JsonSocketBackend, State};
|
||||||
use crate::backend::network::{NetworkBackendHandle, NetworkCommand, NetworkState};
|
use crate::backend::network::{NetworkBackend, NetworkCommand, NetworkState};
|
||||||
use crate::backend::perf_stats::{Stats, StatsBackend};
|
use crate::backend::perf_stats::{Stats, StatsBackend};
|
||||||
use crate::backend::window_manager_hypr::{HyprlandComms, WindowManagerEvent};
|
use crate::backend::window_manager_hypr::{HyprlandComms, WindowManagerEvent};
|
||||||
use crossbeam_channel::{Receiver, Sender};
|
use crossbeam_channel::{Receiver, Sender};
|
||||||
@@ -31,6 +31,13 @@ pub trait BackendThread<M: Debug + Clone, D> {
|
|||||||
fn subscribers(&self) -> &Vec<Sender<M>>;
|
fn subscribers(&self) -> &Vec<Sender<M>>;
|
||||||
fn init(self, registration_rx: Receiver<Sender<M>>);
|
fn init(self, registration_rx: Receiver<Sender<M>>);
|
||||||
fn publish(&self, message: M) {
|
fn publish(&self, message: M) {
|
||||||
|
if self.subscribers().is_empty() {
|
||||||
|
warn!(
|
||||||
|
&LOGGER,
|
||||||
|
"Tried sending message: {message:?} to no subscribers"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
trace!(&LOGGER, "Sending: {message:?} to {:?}", self.subscribers());
|
trace!(&LOGGER, "Sending: {message:?} to {:?}", self.subscribers());
|
||||||
for tx in self.subscribers() {
|
for tx in self.subscribers() {
|
||||||
if let Err(e) = tx.send(message.clone()) {
|
if let Err(e) = tx.send(message.clone()) {
|
||||||
@@ -103,7 +110,7 @@ impl Backend {
|
|||||||
pub fn start(config: &Config) -> Self {
|
pub fn start(config: &Config) -> Self {
|
||||||
debug!(&LOGGER, "Starting Backend threads...");
|
debug!(&LOGGER, "Starting Backend threads...");
|
||||||
let hypr_registrator = HyprlandComms::new().start();
|
let hypr_registrator = HyprlandComms::new().start();
|
||||||
let net_registrator = NetworkBackendHandle::new().start();
|
let net_registrator = NetworkBackend::new().start();
|
||||||
let br_registrator = BrightnessManager::new().start();
|
let br_registrator = BrightnessManager::new().start();
|
||||||
let stats_registrator = StatsBackend::new().start();
|
let stats_registrator = StatsBackend::new().start();
|
||||||
let audio_registrator = AudioBackend::new().start();
|
let audio_registrator = AudioBackend::new().start();
|
||||||
@@ -130,7 +137,7 @@ impl Backend {
|
|||||||
for ch_type in channel_types {
|
for ch_type in channel_types {
|
||||||
match ch_type {
|
match ch_type {
|
||||||
ChannelType::Net => {
|
ChannelType::Net => {
|
||||||
let (rx, tx) = NetworkBackendHandle::subscribe(self.net_registrator.clone());
|
let (rx, tx) = NetworkBackend::subscribe(self.net_registrator.clone());
|
||||||
channels.net_tx = Some(tx);
|
channels.net_tx = Some(tx);
|
||||||
channels.net_rx = Some(rx);
|
channels.net_rx = Some(rx);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ impl HyprlandComms {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn current_monitor() -> MonitorId {
|
pub fn _current_monitor() -> MonitorId {
|
||||||
if let Ok(monitor) = Monitor::get_active() {
|
if let Ok(monitor) = Monitor::get_active() {
|
||||||
return monitor.id;
|
return monitor.id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,10 +80,8 @@ pub fn create_bars(app: &Application, backend: Backend) {
|
|||||||
move || {
|
move || {
|
||||||
while let Ok(cmd) = ctl_rx.try_recv() {
|
while let Ok(cmd) = ctl_rx.try_recv() {
|
||||||
match cmd {
|
match cmd {
|
||||||
ControlCommand::OpenRunMenu => menu.show(),
|
ControlCommand::OpenRunMenu => menu.toggle(),
|
||||||
ControlCommand::OpenNetMenu => {
|
ControlCommand::OpenNetMenu => action_centre.toggle_active_monitor(),
|
||||||
action_centre.show_action_centre_active_monitor()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ControlFlow::Continue
|
ControlFlow::Continue
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ impl ActionCentre {
|
|||||||
let instance = instance.clone();
|
let instance = instance.clone();
|
||||||
move |_, key, _, _| {
|
move |_, key, _, _| {
|
||||||
if key == gdk::Key::Escape {
|
if key == gdk::Key::Escape {
|
||||||
instance.hide_action_centre();
|
instance.hide();
|
||||||
glib::Propagation::Stop
|
glib::Propagation::Stop
|
||||||
} else {
|
} else {
|
||||||
glib::Propagation::Proceed
|
glib::Propagation::Proceed
|
||||||
@@ -319,17 +319,25 @@ impl ActionCentre {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn show_action_centre_active_monitor(&self) {
|
pub fn toggle_active_monitor(&self) {
|
||||||
|
if self.window.is_visible() {
|
||||||
|
self.hide();
|
||||||
|
} else {
|
||||||
|
self.show_active_monitor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn show_active_monitor(&self) {
|
||||||
let Some(display) = Display::default() else {
|
let Some(display) = Display::default() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let Some(monitor) = HyprlandComms::cursor_monitor() else {
|
let Some(monitor) = HyprlandComms::cursor_monitor() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
self.show_action_centre(monitor as u32, &display);
|
self.show(monitor as u32, &display);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn show_action_centre(&self, monitor_idx: u32, display: &Display) {
|
pub fn show(&self, monitor_idx: u32, display: &Display) {
|
||||||
let window = &self.window;
|
let window = &self.window;
|
||||||
let monitors = display.monitors();
|
let monitors = display.monitors();
|
||||||
let Some(monitor) = monitors.item(monitor_idx) else {
|
let Some(monitor) = monitors.item(monitor_idx) else {
|
||||||
@@ -345,7 +353,7 @@ impl ActionCentre {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hide_action_centre(&self) {
|
pub fn hide(&self) {
|
||||||
let clone = self.clone();
|
let clone = self.clone();
|
||||||
self.animate_margin(
|
self.animate_margin(
|
||||||
20,
|
20,
|
||||||
|
|||||||
@@ -189,6 +189,14 @@ impl RunMenu {
|
|||||||
self.window.present();
|
self.window.present();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn toggle(&mut self) {
|
||||||
|
if self.window.is_visible() {
|
||||||
|
self.hide();
|
||||||
|
} else {
|
||||||
|
self.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn create_entry(&self, content_box: >k::Box, entry: &str) -> gtk::Button {
|
fn create_entry(&self, content_box: >k::Box, entry: &str) -> gtk::Button {
|
||||||
let entry_clone = entry.to_owned();
|
let entry_clone = entry.to_owned();
|
||||||
let button = gtk::Button::new();
|
let button = gtk::Button::new();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use crate::backend::{BackendChannels, json_socket};
|
|||||||
use crate::ui::action_centre::ActionCentre;
|
use crate::ui::action_centre::ActionCentre;
|
||||||
use crate::ui::widgets::{ExpandableBarItem, IconSlider};
|
use crate::ui::widgets::{ExpandableBarItem, IconSlider};
|
||||||
use battery::State;
|
use battery::State;
|
||||||
|
use crossbeam_channel::TryRecvError;
|
||||||
use glib::prelude::Cast;
|
use glib::prelude::Cast;
|
||||||
use glib::subclass::prelude::ObjectSubclassIsExt;
|
use glib::subclass::prelude::ObjectSubclassIsExt;
|
||||||
use glib::{ControlFlow, clone};
|
use glib::{ControlFlow, clone};
|
||||||
@@ -205,9 +206,9 @@ pub fn build(
|
|||||||
display,
|
display,
|
||||||
move |_| {
|
move |_| {
|
||||||
if action_centre.window.is_visible() {
|
if action_centre.window.is_visible() {
|
||||||
action_centre.hide_action_centre();
|
action_centre.hide();
|
||||||
} else {
|
} else {
|
||||||
action_centre.show_action_centre(monitor_idx, &display);
|
action_centre.show(monitor_idx, &display);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
@@ -390,10 +391,13 @@ pub fn build(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while let Ok(result) = net_rx.try_recv() {
|
loop {
|
||||||
|
match net_rx.try_recv() {
|
||||||
|
Ok(result) => {
|
||||||
trace!(&LOGGER, "NetworkResult: {:?}", result);
|
trace!(&LOGGER, "NetworkResult: {:?}", result);
|
||||||
match result {
|
match result {
|
||||||
NetworkState::ChangeNetwork(cfg) => {
|
NetworkState::ChangeNetwork(cfg) => {
|
||||||
|
println!("Change network: {cfg:?}");
|
||||||
match cfg {
|
match cfg {
|
||||||
Some(network) => {
|
Some(network) => {
|
||||||
match network.network_type {
|
match network.network_type {
|
||||||
@@ -403,12 +407,14 @@ pub fn build(
|
|||||||
* (WIFI_ICON_PATHS.len() - 1) as f32
|
* (WIFI_ICON_PATHS.len() - 1) as f32
|
||||||
+ 0.5)
|
+ 0.5)
|
||||||
as usize;
|
as usize;
|
||||||
network_icon.set_from_file(Some(WIFI_ICON_PATHS[idx]));
|
network_icon
|
||||||
|
.set_from_file(Some(WIFI_ICON_PATHS[idx]));
|
||||||
network_label.set_label(&network.name);
|
network_label.set_label(&network.name);
|
||||||
network_label.set_visible(true);
|
network_label.set_visible(true);
|
||||||
}
|
}
|
||||||
NetworkType::Wired => {
|
NetworkType::Wired => {
|
||||||
network_icon.set_from_file(Some("icons/ethernet.svg"));
|
network_icon
|
||||||
|
.set_from_file(Some("icons/ethernet.svg"));
|
||||||
network_label.set_visible(false);
|
network_label.set_visible(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -419,7 +425,9 @@ pub fn build(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NetworkState::VpnState { connected, profile } if profile.as_str() == "wg" => {
|
NetworkState::VpnState { connected, profile }
|
||||||
|
if profile.as_str() == "wg" =>
|
||||||
|
{
|
||||||
if connected {
|
if connected {
|
||||||
wg_button.add_css_class("on");
|
wg_button.add_css_class("on");
|
||||||
} else {
|
} else {
|
||||||
@@ -429,6 +437,17 @@ pub fn build(
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(e) => {
|
||||||
|
match e {
|
||||||
|
TryRecvError::Empty => {}
|
||||||
|
TryRecvError::Disconnected => {
|
||||||
|
warn!(&LOGGER, "Network channel disconnected")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
while let Ok(tailscale_state) = netbird_rx.try_recv() {
|
while let Ok(tailscale_state) = netbird_rx.try_recv() {
|
||||||
match tailscale_state {
|
match tailscale_state {
|
||||||
json_socket::State::Disconnected => {
|
json_socket::State::Disconnected => {
|
||||||
|
|||||||
Reference in New Issue
Block a user