Skip to content

Commit

Permalink
Added all monitors option
Browse files Browse the repository at this point in the history
  • Loading branch information
FieldofClay committed May 17, 2023
1 parent a55d427 commit f9e9f87
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hyprland-workspaces"
version = "1.1.3"
version = "1.2.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ Pass the name of the monitor to follow as the only argument.
```
./hyprland-workspaces eDP-1
```
It will then follow that monitor and output the workspaces details in JSON stdout.
If you wish to get all workspaces across all monitors, pass the special argument "_".
```
./hyprland-workspaces _
```
It will then follow that monitor(s) and output the workspaces details in JSON to stdout.
```json
[{"active":false,"class":"workspace-button w1","id":1,"name":"1: "},{"active":false,"class":"workspace-button w2","id":2,"name":"2: "},{"active":true,"class":"workspace-button w4 workspace-active wa4","id":4,"name":"4: "}]
```
Expand All @@ -33,6 +37,7 @@ hyprctl monitors -j
It can be used as a workspaces widget in Eww with config similar to below.
```yuck
(deflisten workspace0 "hyprland-workspaces `hyprctl monitors -j | jq -r \".[0].name\"`")
(deflisten workspace1 "hyprland-workspaces `hyprctl monitors -j | jq -r \".[1].name\"`")
(defwidget workspaces0 []
(eventbox :onscroll "hyprctl dispatch workspace `echo {} | sed 's/up/+/\' | sed 's/down/-/'`1"
Expand All @@ -41,7 +46,26 @@ It can be used as a workspaces widget in Eww with config similar to below.
(button
:onclick "hyprctl dispatch workspace ${i.id}"
:class "${i.class}"
"${replace(i.name, ':', '')}")))))
"${i.name}")))))
(defwidget workspaces1 []
(eventbox :onscroll "hyprctl dispatch workspace `echo {} | sed 's/up/+/\' | sed 's/down/-/'`1"
(box :class "workspaces"
(for i in workspace1
(button
:onclick "hyprctl dispatch workspace ${i.id}"
:class "${i.class}"
"${i.name}")))))
(defwindow bar0 []
:monitor 0
(box
(workspaces0)
(other_widget)))
(defwindow bar1 []
:monitor 1
(box
(workspaces1)
(other_widget)))
```

The following classes are output, to provide multiple options for theming your workspaces widget.
Expand Down
24 changes: 15 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use hyprland::data::{Monitors, Workspaces};
use hyprland::data::{Monitors, Workspace, Workspaces};
use hyprland::event_listener::EventListenerMutable as EventListener;
use hyprland::shared::HyprData;
use hyprland::shared::HyprDataActive;
use hyprland::Result;
use std::env;
use serde::Serialize;
Expand Down Expand Up @@ -33,12 +34,17 @@ fn output(monitor: &str) {
workspaces.sort_by_key(|w| w.id);

//get active workspace
let active_workspace_name = Monitors::get()
.expect("unable to get monitors")
.find(|m| m.name == monitor)
.unwrap()
.active_workspace
.name;
let mut active_workspace_name = String::new();
if monitor == "_" {
active_workspace_name = Workspace::get_active().expect("unable to get active workspace").name;
} else {
active_workspace_name = Monitors::get()
.expect("unable to get monitors")
.find(|m| m.name == monitor)
.unwrap()
.active_workspace
.name;
}
//active monitor name
let active_monitor_name = Monitors::get()
.expect("unable to get monitors")
Expand All @@ -48,7 +54,7 @@ fn output(monitor: &str) {

let mut out_workspaces: Vec<WorkspaceCustom> = Vec::new();

for workspace in workspaces.iter().filter(|m| m.monitor == monitor) {
for workspace in workspaces.iter().filter(|m| m.monitor == monitor || monitor == "_") {
let mut active = false;
let mut class = format!("workspace-button w{}",workspace.id);
if active_workspace_name == workspace.name && active_monitor_name == monitor {
Expand Down Expand Up @@ -78,7 +84,7 @@ fn main() -> Result<()> {
let mon = env::args().nth(1).unwrap();
if let None = Monitors::get()
.expect("unable to get monitors")
.find(|m| m.name == mon) {
.find(|m| m.name == mon || mon == "_") {
println!("Unable to find monitor {mon}");
std::process::exit(0);
}
Expand Down

0 comments on commit f9e9f87

Please sign in to comment.