window title
This commit is contained in:
parent
cf1b262066
commit
841344a76c
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
This client is useful if you want to have a workspace module for somethig like [eww](https://github.com/elkowar/eww) or [waybar](https://github.com/Alexays/Waybar).
|
This client is useful if you want to have a workspace module for somethig like [eww](https://github.com/elkowar/eww) or [waybar](https://github.com/Alexays/Waybar).
|
||||||
|
|
||||||
I also plan to add an option to display the title of the focused window.
|
|
||||||
|
|
||||||
### Dependencies
|
### Dependencies
|
||||||
- rust
|
- rust
|
||||||
|
|
||||||
|
118
src/main.rs
118
src/main.rs
@ -1,16 +1,15 @@
|
|||||||
mod wayland;
|
mod wayland;
|
||||||
|
|
||||||
use wayland_client::protocol::wl_output::WlOutput;
|
use crate::wayland::river_status_unstable_v1::{
|
||||||
use crate::wayland::{
|
zriver_output_status_v1, zriver_seat_status_v1, zriver_status_manager_v1::ZriverStatusManagerV1,
|
||||||
river_status_unstable_v1::zriver_status_manager_v1::ZriverStatusManagerV1,
|
|
||||||
river_status_unstable_v1::zriver_output_status_v1::ZriverOutputStatusV1,
|
|
||||||
};
|
};
|
||||||
use crate::wayland::river_status_unstable_v1::zriver_output_status_v1;
|
use wayland_client::protocol::{wl_output::WlOutput, wl_seat::WlSeat};
|
||||||
use wayland_client::{Display, GlobalManager, Main};
|
use wayland_client::{Display, GlobalManager, Main};
|
||||||
|
|
||||||
struct Globals {
|
struct Globals {
|
||||||
outputs: Vec<WlOutput>,
|
seats: Vec<Main<WlSeat>>,
|
||||||
status_manager: Option<Main<ZriverStatusManagerV1>>
|
outputs: Vec<Main<WlOutput>>,
|
||||||
|
status_manager: Option<Main<ZriverStatusManagerV1>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -18,30 +17,45 @@ fn main() {
|
|||||||
|
|
||||||
let mut event_queue = display.create_event_queue();
|
let mut event_queue = display.create_event_queue();
|
||||||
|
|
||||||
let mut globals = { Globals {
|
let mut globals = {
|
||||||
|
Globals {
|
||||||
|
seats: Vec::new(),
|
||||||
outputs: Vec::new(),
|
outputs: Vec::new(),
|
||||||
status_manager: None
|
status_manager: None,
|
||||||
} };
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let mut args = std::env::args();
|
let mut args = std::env::args();
|
||||||
|
let mut seat = None;
|
||||||
let mut monitor = None;
|
let mut monitor = None;
|
||||||
let mut enable_tag = false;
|
let mut enable_tag = false;
|
||||||
|
let mut enable_title = true;
|
||||||
let mut enable_views_tag = false;
|
let mut enable_views_tag = false;
|
||||||
args.next();
|
args.next();
|
||||||
loop {
|
loop {
|
||||||
match args.next() {
|
match args.next() {
|
||||||
Some(flag) => match flag.as_str() {
|
Some(flag) => match flag.as_str() {
|
||||||
"--monitor" | "-m" => monitor = match args.next().unwrap_or(String::new()).parse::<usize>() {
|
"--seat" | "-s" => {
|
||||||
|
seat = match args.next().unwrap_or(String::new()).parse::<usize>() {
|
||||||
Ok(i) => Some(i),
|
Ok(i) => Some(i),
|
||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
},
|
}
|
||||||
|
}
|
||||||
|
"--monitor" | "-m" => {
|
||||||
|
monitor = match args.next().unwrap_or(String::new()).parse::<usize>() {
|
||||||
|
Ok(i) => Some(i),
|
||||||
|
Err(_) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"--window-title" | "-w" => enable_title = true,
|
||||||
"--tag" | "-t" => enable_tag = true,
|
"--tag" | "-t" => enable_tag = true,
|
||||||
"--view-tags" | "-vt" => enable_views_tag = true,
|
"--view-tags" | "-vt" => enable_views_tag = true,
|
||||||
"--help" | "-h" | "--h" => {
|
"--help" | "-h" | "--h" => {
|
||||||
println!("Usage: status [option]\n");
|
println!("Usage: status [option]\n");
|
||||||
|
println!(" --monitor | -m <uint> : select the monitor");
|
||||||
println!(" --tag | -t : displays the focused tag");
|
println!(" --tag | -t : displays the focused tag");
|
||||||
|
println!(" --tag | -t : displays the title of the focused view");
|
||||||
println!(" --view-tags | -vt : displays the tag of all views");
|
println!(" --view-tags | -vt : displays the tag of all views");
|
||||||
println!(" --monitor | -m : select the monitor index");
|
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
_ => break,
|
_ => break,
|
||||||
@ -62,12 +76,20 @@ fn main() {
|
|||||||
globals.get::<Globals>().unwrap().status_manager = Some(status_manager_obj);
|
globals.get::<Globals>().unwrap().status_manager = Some(status_manager_obj);
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
WlSeat,
|
||||||
|
7,
|
||||||
|
|seat: Main<WlSeat>, mut globals: DispatchData| {
|
||||||
|
seat.quick_assign(move |_, _, _| {});
|
||||||
|
globals.get::<Globals>().unwrap().seats.push(seat);
|
||||||
|
}
|
||||||
|
],
|
||||||
[
|
[
|
||||||
WlOutput,
|
WlOutput,
|
||||||
3,
|
3,
|
||||||
|output: Main<WlOutput>, mut globals: DispatchData| {
|
|output: Main<WlOutput>, mut globals: DispatchData| {
|
||||||
output.quick_assign(move |_, _, _| {});
|
output.quick_assign(move |_, _, _| {});
|
||||||
globals.get::<Globals>().unwrap().outputs.push(output.detach());
|
globals.get::<Globals>().unwrap().outputs.push(output);
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
@ -77,16 +99,52 @@ fn main() {
|
|||||||
.sync_roundtrip(&mut globals, |_, _, _| unreachable!())
|
.sync_roundtrip(&mut globals, |_, _, _| unreachable!())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
for (i, output) in globals.outputs.iter_mut().enumerate() {
|
for (_, seat) in globals
|
||||||
let assign;
|
.seats
|
||||||
match monitor {
|
.iter()
|
||||||
Some(monitor) => if i == monitor {
|
.enumerate()
|
||||||
assign = true;
|
.filter(|(i, _)| match seat {
|
||||||
} else { assign = false },
|
Some(seat) => {
|
||||||
None => assign = true
|
if *i == seat {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
}
|
}
|
||||||
if assign {
|
}
|
||||||
let output_status = globals.status_manager
|
None => true,
|
||||||
|
})
|
||||||
|
{
|
||||||
|
let seat_status = globals
|
||||||
|
.status_manager
|
||||||
|
.as_ref()
|
||||||
|
.expect("Compositor doesn't implement river_status_unstable_v1")
|
||||||
|
.get_river_seat_status(&seat);
|
||||||
|
seat_status.quick_assign(move |_, event, _| match event {
|
||||||
|
zriver_seat_status_v1::Event::FocusedView { title } => {
|
||||||
|
if enable_title {
|
||||||
|
println!("{}", title)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
for (_, output) in globals
|
||||||
|
.outputs
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter(|(i, _)| match monitor {
|
||||||
|
Some(monitor) => {
|
||||||
|
if *i == monitor {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => true,
|
||||||
|
})
|
||||||
|
{
|
||||||
|
let output_status = globals
|
||||||
|
.status_manager
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.expect("Compositor doesn't implement river_status_unstable_v1")
|
.expect("Compositor doesn't implement river_status_unstable_v1")
|
||||||
.get_river_output_status(&output);
|
.get_river_output_status(&output);
|
||||||
@ -100,18 +158,15 @@ fn main() {
|
|||||||
zriver_output_status_v1::Event::ViewTags { tags } => {
|
zriver_output_status_v1::Event::ViewTags { tags } => {
|
||||||
if enable_views_tag {
|
if enable_views_tag {
|
||||||
let len = tags.len();
|
let len = tags.len();
|
||||||
let mut i = 0;
|
for i in (0..len).into_iter().step_by(4) {
|
||||||
while i < len {
|
|
||||||
let buf: [u8; 4] = [tags[i], tags[i + 1], tags[i + 2], tags[i + 3]];
|
let buf: [u8; 4] = [tags[i], tags[i + 1], tags[i + 2], tags[i + 3]];
|
||||||
base10(u32::from_le_bytes(buf));
|
base10(u32::from_le_bytes(buf));
|
||||||
i+=4;
|
|
||||||
}
|
}
|
||||||
println!("");
|
println!("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
event_queue
|
event_queue
|
||||||
@ -130,12 +185,17 @@ fn main() {
|
|||||||
fn base10(tagmask: u32) {
|
fn base10(tagmask: u32) {
|
||||||
let mut tag = 0;
|
let mut tag = 0;
|
||||||
let mut current: u32;
|
let mut current: u32;
|
||||||
while {current = 1 << tag; current <= tagmask} {
|
while {
|
||||||
|
current = 1 << tag;
|
||||||
|
current <= tagmask
|
||||||
|
} {
|
||||||
tag += 1;
|
tag += 1;
|
||||||
if current != tagmask && (tagmask / current) % 2 != 0 {
|
if current != tagmask && (tagmask / current) % 2 != 0 {
|
||||||
base10(tagmask - current);
|
base10(tagmask - current);
|
||||||
break;
|
break;
|
||||||
} else if tag == 32 { break }
|
} else if tag == 32 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
print!("{} ", tag);
|
print!("{} ", tag);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user