Compare commits

..

No commits in common. "c2bc19611f105e64ec565c13b2ac8fd9a62ce4b5" and "80fb98c7ac24a8a0ce5543fe2d90a7b1e4000dc8" have entirely different histories.

3 changed files with 12 additions and 156 deletions

View file

@ -5,11 +5,14 @@ use serde::{Deserialize, Serialize};
use std::io::stdin; use std::io::stdin;
use std::io::IsTerminal; use std::io::IsTerminal;
pub fn run_calendar() { use crate::CliArgs;
// use serde_json;
pub fn run_calendar(args: &CliArgs) {
let in_pipe = stdin(); let in_pipe = stdin();
if in_pipe.is_terminal() { if in_pipe.is_terminal() {
error!("Workspace Selector process requires being run as a terminal process"); error!("Calendar Background process requires an input redirection (use a pipe)");
panic!("Expected to be run in a terminal process, but was not"); panic!("Expected to be used with a pipe, but was not");
} }
let (mut moonrise, mut moonset, mut moonday, mut sunrise, mut sunset): ( let (mut moonrise, mut moonset, mut moonday, mut sunrise, mut sunset): (
@ -48,7 +51,9 @@ pub fn run_calendar() {
moonphase = match phase.trim()[0..2].parse::<u32>() { moonphase = match phase.trim()[0..2].parse::<u32>() {
Ok(val) => Some(val), Ok(val) => Some(val),
Err(e) => { Err(e) => {
if args.debug {
debug!("Error parsing: {e}"); debug!("Error parsing: {e}");
}
None None
} }
}; };
@ -137,6 +142,7 @@ pub fn run_calendar() {
} }
} }
if !output_state.has_bg { if !output_state.has_bg {
println!("linear-gradient(0deg, rgba(26, 26, 26, 1), rgba(50, 50, 50, 1))"); println!("linear-gradient(0deg, rgba(26, 26, 26, 1), rgba(50, 50, 50, 1))");
} else { } else {
@ -146,11 +152,7 @@ pub fn run_calendar() {
"#d3d3d3" "#d3d3d3"
}; };
println!( println!("linear-gradient({}deg, {}, rgba(26, 26, 26, 0.0) 30%)", (output_state.gradient_angle_percentage * 180.0 + 90.0) as i32, gradient_color);
"linear-gradient({}deg, {}, rgba(26, 26, 26, 0.0) 30%)",
(output_state.gradient_angle_percentage * 180.0 + 90.0) as i32,
gradient_color
);
} }
// println!("{}", serde_json::to_string(&output_state).unwrap()); // println!("{}", serde_json::to_string(&output_state).unwrap());

View file

@ -3,13 +3,9 @@ use clap::{Parser, ValueEnum};
mod calendar_background; mod calendar_background;
use calendar_background::run_calendar; use calendar_background::run_calendar;
mod workspace_switcher;
use workspace_switcher::run_workspace_selector;
#[derive(ValueEnum, Debug, Clone)] #[derive(ValueEnum, Debug, Clone)]
enum ProcessType { enum ProcessType {
CalendarBackground, CalendarBackground,
WorkspaceSelector,
} }
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
@ -39,10 +35,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.expect("`action` parameter required when calling command") .expect("`action` parameter required when calling command")
{ {
ProcessType::CalendarBackground => { ProcessType::CalendarBackground => {
run_calendar(); run_calendar(&args);
}
ProcessType::WorkspaceSelector => {
run_workspace_selector();
} }
} }
Ok(()) Ok(())

View file

@ -1,139 +0,0 @@
use log::{debug, error};
use std::io::stdin;
use std::io::IsTerminal;
use std::process::Command;
use serde::{Deserialize, Serialize};
use serde_json;
pub fn run_workspace_selector() {
let in_pipe = stdin();
if in_pipe.is_terminal() {
error!("Workspace Selector process requires being run as a terminal process");
panic!("Expected to be run in a terminal process, but was not");
}
let mut buffer = String::new();
let bytes = in_pipe.read_line(&mut buffer).unwrap();
debug!("Received from pipe: {buffer}");
if bytes == 0 {
error!("The input pipe was empty! Unrecoverable error");
panic!("The input pipe was empty! Unrecoverable error");
}
debug!("Attempting to parse buffer");
let src_workspace = match buffer.trim().parse::<i32>() {
Ok(val) => val,
Err(e) => {
error!("Error parsing stdin buffer: {e}");
panic!("Could not parse stdin to i32");
}
};
let output = {
let std_out = match Command::new("hyprctl").arg("monitors").arg("-j").output() {
Ok(val) => val,
Err(e) => {
error!("Error getting the focused monitor: {e}");
panic!("Error getting focused monitor");
}
}
.stdout;
let std_string = match String::from_utf8(std_out) {
Ok(v) => v,
Err(e) => {
error!("Could not parse hyprctl output to string: {e}");
panic!("Could not parse hyprctl output to string");
}
};
debug!("hyprctl command output: {std_string}");
let json_output: Vec<MonitorInfo> = match serde_json::from_str(&std_string) {
Ok(val) => val,
Err(e) => {
error!("Could not parse stdout to json: {e}");
panic!("Could not parse stdout to json");
}
};
json_output
};
debug!("Parsed monitor json: {:#?}", output);
let id: u32 = match output
.iter()
.filter(|x| x.focused)
.map(|x| x.id)
.collect::<Vec<u32>>()
.first()
{
Some(val) => (*val).clone(),
None => {
error!("Could not get focused monitor from json");
panic!("Could not get focused monitor from json");
}
};
debug!("Active monitor: {}", id);
let mut ids: Vec<u32> = output.iter().map(|x| x.id).collect();
ids.sort();
// Because we might only have a monitor 0 and 3, we need a way to consistently get
// to workspaces within the 10 eww watches
let monitor_num = ids.iter().position(|&r| r == id).unwrap();
// It should always exist as it came from this list
debug!("Monitor number adjusted: {}", monitor_num);
// Because there is a monitor 0, make sure it is always at least monitor 1
let target_workspace = src_workspace * (monitor_num + 1) as i32;
debug!("Target workspace: {}", target_workspace);
print!("{}", target_workspace);
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
struct MonitorInfo {
id: u32,
name: String,
description: String,
make: String,
model: String,
serial: String,
width: u32,
height: u32,
refresh_rate: f32,
x: u32,
y: u32,
active_workspace: ActiveWorkspace,
special_workspace: SpecialWorkspace,
reserved: Vec<i32>,
scale: f32,
transform: i32,
focused: bool,
dpms_status: bool,
vrr: bool,
actively_tearing: bool,
}
#[derive(Serialize, Deserialize, Debug)]
struct ActiveWorkspace {
id: i32,
name: String,
}
#[derive(Serialize, Deserialize, Debug)]
struct SpecialWorkspace {
id: i32,
name: String,
}