Skip to content

Commit

Permalink
feat: wlout info need to record
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Dec 19, 2023
1 parent cca7abe commit ca430c5
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ authors = [
"Aakash Sen Sharma <[email protected]>",
]
edition = "2021"
version = "0.2.0"
version = "0.2.1"
license = "MIT"
description = "Wayland native (zwlr_layer_shell) area selection client"
repository = "https://github.com/waycrate/waysip"
keywords = ["wayland", "wlroots", "slurp"]
readme = "README.md"

[workspace.dependencies]
libwaysip = { version = "0.2.0", path = "./libwaysip" }
libwaysip = { version = "0.2.1", path = "./libwaysip" }
88 changes: 76 additions & 12 deletions libwaysip/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,40 @@ struct ZXdgOutputInfo {
description: String,
}

#[derive(Debug, Clone)]
pub struct WlOutputInfo {
output: WlOutput,
description: String,
name: String,
size: (i32, i32),
}

impl WlOutputInfo {
fn new(output: WlOutput) -> Self {
Self {
output,
description: "".to_string(),
name: "".to_string(),
size: (0, 0),
}
}
pub fn get_output(&self) -> &WlOutput {
&self.output
}

pub fn get_size(&self) -> (i32, i32) {
self.size
}

pub fn get_name(&self) -> &str {
&self.name
}

pub fn get_description(&self) -> &str {
&self.description
}
}

impl ZXdgOutputInfo {
fn new(zxdgoutput: zxdg_output_v1::ZxdgOutputV1) -> Self {
Self {
Expand All @@ -84,9 +118,9 @@ impl ZXdgOutputInfo {
description: "".to_string(),
}
}
fn get_screen_info(&self, output: WlOutput) -> ScreenInfo {
fn get_screen_info(&self, output_info: WlOutputInfo) -> ScreenInfo {
ScreenInfo {
output,
output_info,
start_x: self.start_x,
start_y: self.start_y,
width: self.width,
Expand All @@ -101,7 +135,7 @@ impl ZXdgOutputInfo {
/// binded by the screen
#[derive(Debug)]
pub struct ScreenInfo {
output: WlOutput,
output_info: WlOutputInfo,
start_x: i32,
start_y: i32,
width: i32,
Expand All @@ -111,10 +145,9 @@ pub struct ScreenInfo {
}

impl ScreenInfo {

/// get the binding output
pub fn get_output(&self) -> &WlOutput {
&self.output
pub fn get_outputinfo(&self) -> &WlOutputInfo {
&self.output_info
}

/// get the logical size of the screen
Expand Down Expand Up @@ -160,7 +193,7 @@ pub enum WaySipKind {

#[derive(Debug)]
struct SecondState {
outputs: Vec<wl_output::WlOutput>,
outputs: Vec<WlOutputInfo>,
zxdgoutputs: Vec<ZXdgOutputInfo>,
running: bool,
waysipkind: WaySipKind,
Expand Down Expand Up @@ -317,10 +350,42 @@ impl Dispatch<wl_registry::WlRegistry, ()> for SecondState {

if interface == wl_output::WlOutput::interface().name {
let output = proxy.bind::<wl_output::WlOutput, _, _>(name, version, qh, ());
state.outputs.push(output);
state.outputs.push(WlOutputInfo::new(output));
}
}
}

impl Dispatch<wl_output::WlOutput, ()> for SecondState {
fn event(
state: &mut Self,
wl_output: &wl_output::WlOutput,
event: <wl_output::WlOutput as Proxy>::Event,
_data: &(),
_conn: &Connection,
_qhandle: &wayland_client::QueueHandle<Self>,
) {
let output = state
.outputs
.iter_mut()
.find(|x| x.get_output() == wl_output)
.unwrap();

match event {
wl_output::Event::Name { name } => {
output.name = name;
}
wl_output::Event::Description { description } => {
output.description = description;
}
wl_output::Event::Mode { width, height, .. } => {
output.size = (width, height);
}

_ => (),
}
}
}

impl Dispatch<xdg_wm_base::XdgWmBase, ()> for SecondState {
fn event(
_state: &mut Self,
Expand Down Expand Up @@ -529,8 +594,7 @@ impl Dispatch<zxdg_output_v1::ZxdgOutputV1, ()> for SecondState {

delegate_noop!(SecondState: ignore WlCompositor); // WlCompositor is need to create a surface
delegate_noop!(SecondState: ignore WlSurface); // surface is the base needed to show buffer
delegate_noop!(SecondState: ignore WlOutput); // output is need to place layer_shell, although here
// it is not used
//
delegate_noop!(SecondState: ignore WlShm); // shm is used to create buffer pool
delegate_noop!(SecondState: ignore XdgToplevel); // so it is the same with layer_shell, private a
// place for surface
Expand Down Expand Up @@ -608,7 +672,7 @@ pub fn get_area(kind: WaySipKind) -> Result<Option<AreaInfo>, WaySipError> {
.map_err(WaySipError::NotSupportedProtocol)?;

for wloutput in state.outputs.iter() {
let zwloutput = xdg_output_manager.get_xdg_output(wloutput, &qh, ());
let zwloutput = xdg_output_manager.get_xdg_output(wloutput.get_output(), &qh, ());
state.zxdgoutputs.push(ZXdgOutputInfo::new(zwloutput));
}

Expand Down Expand Up @@ -640,7 +704,7 @@ pub fn get_area(kind: WaySipKind) -> Result<Option<AreaInfo>, WaySipError> {

let layer = layer_shell.get_layer_surface(
&wl_surface,
Some(wloutput),
Some(wloutput.get_output()),
Layer::Overlay,
format!("nobody_{index}"),
&qh,
Expand Down
5 changes: 4 additions & 1 deletion waysip/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ fn main() {
let (w, h) = screen_info.get_size();
let name = screen_info.get_name();
let description = screen_info.get_description();
let wlinfo = screen_info.get_outputinfo();
let (wl_w, wl_h) = wlinfo.get_size();
println!("Screen : {name} {description}");
println!("width: {w}, height: {h}");
println!("logic_width: {w}, logic_height: {h}");
println!("width: {wl_w}, height: {wl_h}");
}
Cli::Output => {
let info = get_info!(WaySipKind::Screen);
Expand Down

0 comments on commit ca430c5

Please sign in to comment.