This commit is contained in:
jmb05
2026-11-02 17:26:51 +01:00
parent cdfc5b8d36
commit 11fb03427c
7 changed files with 94 additions and 94 deletions

View File

@@ -475,7 +475,7 @@ impl BackendThread<MediaMessage, Sender<MediaMessage>> for MediaBackend {
let instance = instance.clone();
move || {
while let Ok(sender) = registration_rx.recv() {
if let Ok(_) = sender.send(MediaMessage::Init(tx.clone())) {
if sender.send(MediaMessage::Init(tx.clone())).is_ok() {
let mut instance_guard = instance.lock().unwrap();
if let Some(name) = &instance_guard.active_player
&& let Some(status) = instance_guard.players.get(name)
@@ -517,28 +517,28 @@ impl BackendThread<MediaMessage, Sender<MediaMessage>> for MediaBackend {
};
while let Ok(msg) = rx.recv() {
let mut instance_guard = instance.lock().unwrap();
if let Some(name) = &instance_guard.active_player {
if let Some(status) = instance_guard.players.get(name) {
match msg {
MediaMessage::PlayerPlay => {
if let PlayerStatus::Paused(_) = status {
instance_guard.active_player_play(&connection).await;
}
if let Some(name) = &instance_guard.active_player
&& let Some(status) = instance_guard.players.get(name)
{
match msg {
MediaMessage::PlayerPlay => {
if let PlayerStatus::Paused(_) = status {
instance_guard.active_player_play(&connection).await;
}
MediaMessage::PlayerPause => {
if let PlayerStatus::Playing(_) = status {
instance_guard.active_player_pause(&connection).await;
}
}
MediaMessage::PlayerStop => {
if let PlayerStatus::Playing(_) | PlayerStatus::Paused(_) =
status
{
instance_guard.active_player_stop(&connection).await;
}
}
_ => {}
}
MediaMessage::PlayerPause => {
if let PlayerStatus::Playing(_) = status {
instance_guard.active_player_pause(&connection).await;
}
}
MediaMessage::PlayerStop => {
if let PlayerStatus::Playing(_) | PlayerStatus::Paused(_) =
status
{
instance_guard.active_player_stop(&connection).await;
}
}
_ => {}
}
}
}
@@ -575,7 +575,7 @@ impl MediaBackend {
.collect();
for player in players {
Self::spawn_new_player_watcher(&connection, &instance, &player);
Self::spawn_new_player_watcher(connection, &instance, &player);
}
Ok(())
@@ -680,11 +680,11 @@ impl MediaBackend {
continue;
}
if let Some(value) = args.changed_properties().get("PlaybackStatus") {
if let Ok(status) = <String>::try_from(value.clone()) {
debug!(&LOGGER, "Player ({name}) status has changed to: '{status}'");
Self::insert_or_update_player(&instance, &props, name.into(), status).await;
}
if let Some(value) = args.changed_properties().get("PlaybackStatus")
&& let Ok(status) = <String>::try_from(value.clone())
{
debug!(&LOGGER, "Player ({name}) status has changed to: '{status}'");
Self::insert_or_update_player(&instance, &props, name.into(), status).await;
}
}
debug!(&LOGGER, "(2) Removing player: {name}");
@@ -699,7 +699,7 @@ impl MediaBackend {
player_name: String,
player_status: String,
) {
match Self::get_player_status_from_string(&props, player_status).await {
match Self::get_player_status_from_string(props, player_status).await {
Ok(status) => {
let mut instance_guard = instance.lock().unwrap();
instance_guard.players.insert(player_name.clone(), status);
@@ -757,57 +757,51 @@ impl MediaBackend {
}
async fn active_player_play(&self, connection: &zbus::Connection) {
if let Some(player_name) = &self.active_player {
if let Ok(proxy) = zbus::Proxy::new(
&connection,
if let Some(player_name) = &self.active_player
&& let Ok(proxy) = zbus::Proxy::new(
connection,
player_name.as_str(),
MPRIS_PATH,
MPRIS_PLAYER_INTERFACE,
)
.await
{
if let Err(e) = proxy.call_method("Play", &()).await {
warn!(
&LOGGER,
"Error starting play for player: {player_name}, {e}"
);
}
}
&& let Err(e) = proxy.call_method("Play", &()).await
{
warn!(
&LOGGER,
"Error starting play for player: {player_name}, {e}"
);
}
}
async fn active_player_pause(&mut self, connection: &zbus::Connection) {
if let Some(player_name) = &self.active_player {
if let Ok(proxy) = zbus::Proxy::new(
&connection,
if let Some(player_name) = &self.active_player
&& let Ok(proxy) = zbus::Proxy::new(
connection,
player_name.as_str(),
MPRIS_PATH,
MPRIS_PLAYER_INTERFACE,
)
.await
{
if let Err(e) = proxy.call_method("Pause", &()).await {
warn!(&LOGGER, "Error pausing player: {player_name}, {e}");
}
}
&& let Err(e) = proxy.call_method("Pause", &()).await
{
warn!(&LOGGER, "Error pausing player: {player_name}, {e}");
self.select_active_player(self.active_player.clone());
}
}
async fn active_player_stop(&mut self, connection: &zbus::Connection) {
if let Some(player_name) = &self.active_player {
if let Ok(proxy) = zbus::Proxy::new(
&connection,
if let Some(player_name) = &self.active_player
&& let Ok(proxy) = zbus::Proxy::new(
connection,
player_name.as_str(),
MPRIS_PATH,
MPRIS_PLAYER_INTERFACE,
)
.await
{
if let Err(e) = proxy.call_method("Stop", &()).await {
warn!(&LOGGER, "Error stopping player: {player_name}, {e}");
}
}
&& let Err(e) = proxy.call_method("Stop", &()).await
{
warn!(&LOGGER, "Error stopping player: {player_name}, {e}");
}
self.select_active_player(None);
}

View File

@@ -6,6 +6,7 @@ use jmb_logger_rs::*;
use std::io::Read;
use std::net::Shutdown;
use std::os::unix::net::UnixListener;
use std::str::FromStr;
use std::sync::{Arc, Mutex};
pub struct ControlSocket {
@@ -34,11 +35,11 @@ impl SimpleBackendThread<ControlCommand> for ControlSocket {
}
});
std::thread::spawn(move || {
if std::fs::metadata(SOCKET_PATH).is_ok() {
if let Err(e) = std::fs::remove_file(SOCKET_PATH) {
error!(&LOGGER, "Error deleting old socket file: {e}");
return;
}
if std::fs::metadata(SOCKET_PATH).is_ok()
&& let Err(e) = std::fs::remove_file(SOCKET_PATH)
{
error!(&LOGGER, "Error deleting old socket file: {e}");
return;
}
let socket = UnixListener::bind(SOCKET_PATH);
let Ok(socket) = socket else {
@@ -58,7 +59,7 @@ impl SimpleBackendThread<ControlCommand> for ControlSocket {
let _ = stream.shutdown(Shutdown::Both);
continue;
}
if let Some(command) = ControlCommand::from_str(&read) {
if let Ok(command) = ControlCommand::from_str(&read) {
instance.lock().unwrap().publish(command);
}
}

View File

@@ -97,11 +97,13 @@ impl I915Engine {
let pmu_type = read_number(&format!("{base}/type"))? as u32;
let config = read_config(&format!("{base}/events/{name}"))?;
let mut attr = PerfEventAttr::default();
attr.type_ = pmu_type;
attr.size = size_of::<PerfEventAttr>() as u32;
attr.config = config;
attr.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING;
let attr = PerfEventAttr {
type_: pmu_type,
size: size_of::<PerfEventAttr>() as u32,
config,
read_format: PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING,
..Default::default()
};
// pid = -1 and cpu = -1: system-wide event, if permitted.
let fd = unsafe {
@@ -181,7 +183,7 @@ impl I915UtilizationMonitor {
for (engine, sample) in &mut self.engines {
let new_sample = engine.read().unwrap();
if let Some(last) = sample {
values.push(new_sample.calculate_utilization(&last) as u8);
values.push(new_sample.calculate_utilization(last) as u8);
}
let _ = sample.insert(new_sample);
}

View File

@@ -204,7 +204,7 @@ impl HyprlandComms {
.output()
}
pub fn cursor_monitor() -> Option<MonitorId> {
pub fn _cursor_monitor() -> Option<MonitorId> {
if let Ok(pos) = CursorPosition::get()
&& let Ok(monitors) = Monitors::get()
{

View File

@@ -1,4 +1,5 @@
use serde::Deserialize;
use std::default::Default;
use std::fs;
#[derive(Deserialize, Debug, Clone, Default)]
@@ -10,8 +11,7 @@ impl Config {
pub fn load() -> Config {
fs::read_to_string("jmb-bar.conf")
.ok()
.map(|s| toml::from_str::<Config>(&s).ok())
.flatten()
.and_then(|s| toml::from_str::<Config>(&s).ok())
.unwrap_or_default()
}
}
@@ -33,7 +33,8 @@ impl Default for IdleConfig {
dim_timeout: 60,
lock_timeout: 300,
sleep_timeout: 320,
..Default::default()
lock_command: String::default(),
sleep_command: String::default(),
}
}
}

View File

@@ -1,7 +1,9 @@
use jmb_logger_rs::*;
use std::env;
use std::fmt::{Display, Formatter};
use std::io::Write;
use std::os::unix::net::UnixStream;
use std::str::FromStr;
const CTL_LOGGER: Logger = Logger::create_with_custom_format(Level::DEBUG, String::new());
pub const SOCKET_PATH: &str = "/run/user/1000/jmb-bar.sock";
@@ -11,17 +13,21 @@ pub enum ControlCommand {
OpenRunMenu,
}
impl ControlCommand {
pub fn from_str(s: &str) -> Option<Self> {
match s {
"menu" => Some(ControlCommand::OpenRunMenu),
_ => None,
impl Display for ControlCommand {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
ControlCommand::OpenRunMenu => f.write_str("menu"),
}
}
}
pub fn to_string(self) -> String {
match self {
ControlCommand::OpenRunMenu => String::from("menu"),
impl FromStr for ControlCommand {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"menu" => Ok(ControlCommand::OpenRunMenu),
other => Err(format!("Unknown command: {other}")),
}
}
}
@@ -43,7 +49,7 @@ fn main() {
let args: Vec<String> = env::args().collect();
match args.get(1) {
Some(str) if let Some(cmd) = ControlCommand::from_str(str) => stream
Some(str) if let Ok(cmd) = ControlCommand::from_str(str) => stream
.write(cmd.to_string().as_bytes())
.expect("Error sending message"),
_ => 0usize,

View File

@@ -75,8 +75,6 @@ impl RunMenu {
window.set_monitor(monitor.as_ref());
if let Some(monitor) = monitor {
let geometry = monitor.geometry();
let (_, natural_height, _, _) =
window.child().unwrap().measure(Orientation::Vertical, -1);
let top_margin = (geometry.height()) / 2;
window.set_margin(Edge::Top, top_margin - 100);
} else {
@@ -100,14 +98,12 @@ impl RunMenu {
}
if e.text_length() > 0 {
let text = e.text();
if text.starts_with("=") {
if let Ok(eval) = meval::eval_str(&text[1..]) {
let label = gtk::Label::new(Some(&format!("{eval}")));
label.add_css_class("exec-button");
label.set_halign(Align::Start);
label.set_hexpand(true);
content_box.append(&label);
}
if let Some(eval) = text.strip_prefix("=") {
let label = gtk::Label::new(Some(eval));
label.add_css_class("exec-button");
label.set_halign(Align::Start);
label.set_hexpand(true);
content_box.append(&label);
} else {
instance_clone.list_matching(e, &content_box, &mut matcher_rc.borrow_mut());
instance_clone.window.set_default_size(500, -1);
@@ -164,8 +160,8 @@ impl RunMenu {
self.window.present();
}
fn create_entry(&self, content_box: &gtk::Box, entry: &String) -> gtk::Button {
let entry_clone = entry.clone();
fn create_entry(&self, content_box: &gtk::Box, entry: &str) -> gtk::Button {
let entry_clone = entry.to_owned();
let button = gtk::Button::new();
button.set_halign(Align::Fill);
button.set_hexpand(true);
@@ -198,14 +194,14 @@ impl RunMenu {
content_box: &gtk::Box,
matcher: &mut Matcher,
) -> bool {
let keys: Vec<String> = self.entries.borrow().keys().map(|i| i.clone()).collect();
let keys: Vec<String> = self.entries.borrow().keys().cloned().collect();
let mut first = true;
let mut added = false;
for (entry, _) in Pattern::parse(&entry.text(), CaseMatching::Ignore, Normalization::Smart)
.match_list(keys, matcher)
.iter()
{
let button = self.create_entry(content_box, &entry);
let button = self.create_entry(content_box, entry);
if first {
button.add_css_class("suggested");
first = false;