Compare commits
No commits in common. "c2bc19611f105e64ec565c13b2ac8fd9a62ce4b5" and "80fb98c7ac24a8a0ce5543fe2d90a7b1e4000dc8" have entirely different histories.
c2bc19611f
...
80fb98c7ac
3 changed files with 12 additions and 156 deletions
|
@ -5,11 +5,14 @@ use serde::{Deserialize, Serialize};
|
|||
use std::io::stdin;
|
||||
use std::io::IsTerminal;
|
||||
|
||||
pub fn run_calendar() {
|
||||
use crate::CliArgs;
|
||||
// use serde_json;
|
||||
|
||||
pub fn run_calendar(args: &CliArgs) {
|
||||
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");
|
||||
error!("Calendar Background process requires an input redirection (use a pipe)");
|
||||
panic!("Expected to be used with a pipe, but was not");
|
||||
}
|
||||
|
||||
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>() {
|
||||
Ok(val) => Some(val),
|
||||
Err(e) => {
|
||||
if args.debug {
|
||||
debug!("Error parsing: {e}");
|
||||
}
|
||||
None
|
||||
}
|
||||
};
|
||||
|
@ -137,6 +142,7 @@ pub fn run_calendar() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if !output_state.has_bg {
|
||||
println!("linear-gradient(0deg, rgba(26, 26, 26, 1), rgba(50, 50, 50, 1))");
|
||||
} else {
|
||||
|
@ -146,11 +152,7 @@ pub fn run_calendar() {
|
|||
"#d3d3d3"
|
||||
};
|
||||
|
||||
println!(
|
||||
"linear-gradient({}deg, {}, rgba(26, 26, 26, 0.0) 30%)",
|
||||
(output_state.gradient_angle_percentage * 180.0 + 90.0) as i32,
|
||||
gradient_color
|
||||
);
|
||||
println!("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());
|
||||
|
|
|
@ -3,13 +3,9 @@ use clap::{Parser, ValueEnum};
|
|||
mod calendar_background;
|
||||
use calendar_background::run_calendar;
|
||||
|
||||
mod workspace_switcher;
|
||||
use workspace_switcher::run_workspace_selector;
|
||||
|
||||
#[derive(ValueEnum, Debug, Clone)]
|
||||
enum ProcessType {
|
||||
CalendarBackground,
|
||||
WorkspaceSelector,
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
|
@ -39,10 +35,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
.expect("`action` parameter required when calling command")
|
||||
{
|
||||
ProcessType::CalendarBackground => {
|
||||
run_calendar();
|
||||
}
|
||||
ProcessType::WorkspaceSelector => {
|
||||
run_workspace_selector();
|
||||
run_calendar(&args);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
Loading…
Reference in a new issue