Compare commits
2 commits
80fb98c7ac
...
c2bc19611f
Author | SHA1 | Date | |
---|---|---|---|
c2bc19611f | |||
686e88815c |
3 changed files with 156 additions and 12 deletions
|
@ -5,14 +5,11 @@ use serde::{Deserialize, Serialize};
|
||||||
use std::io::stdin;
|
use std::io::stdin;
|
||||||
use std::io::IsTerminal;
|
use std::io::IsTerminal;
|
||||||
|
|
||||||
use crate::CliArgs;
|
pub fn run_calendar() {
|
||||||
// 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!("Calendar Background process requires an input redirection (use a pipe)");
|
error!("Workspace Selector process requires being run as a terminal process");
|
||||||
panic!("Expected to be used with a pipe, but was not");
|
panic!("Expected to be run in a terminal process, 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): (
|
||||||
|
@ -51,9 +48,7 @@ pub fn run_calendar(args: &CliArgs) {
|
||||||
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
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -142,7 +137,6 @@ pub fn run_calendar(args: &CliArgs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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 {
|
||||||
|
@ -152,7 +146,11 @@ pub fn run_calendar(args: &CliArgs) {
|
||||||
"#d3d3d3"
|
"#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());
|
// println!("{}", serde_json::to_string(&output_state).unwrap());
|
||||||
|
|
|
@ -3,9 +3,13 @@ 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)]
|
||||||
|
@ -35,7 +39,10 @@ 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(&args);
|
run_calendar();
|
||||||
|
}
|
||||||
|
ProcessType::WorkspaceSelector => {
|
||||||
|
run_workspace_selector();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
139
ewwtilities/src/workspace_switcher.rs
Normal file
139
ewwtilities/src/workspace_switcher.rs
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
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