From 1851c56e407cac72ca104cc5e75692cd9c648986 Mon Sep 17 00:00:00 2001 From: MaxVerevkin Date: Mon, 8 Aug 2022 23:12:23 +0300 Subject: rewrite using latest walayd libs & implement HiDPI --- src/state.rs | 430 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 430 insertions(+) create mode 100644 src/state.rs (limited to 'src/state.rs') diff --git a/src/state.rs b/src/state.rs new file mode 100644 index 0000000..ea5ca4e --- /dev/null +++ b/src/state.rs @@ -0,0 +1,430 @@ +use std::{future::pending, io}; + +use smithay_client_toolkit::{ + compositor::{CompositorHandler, CompositorState}, + delegate_compositor, delegate_layer, delegate_output, delegate_pointer, delegate_registry, + delegate_seat, delegate_shm, + output::{OutputHandler, OutputState}, + reexports::client::{ + protocol::{wl_output, wl_pointer, wl_seat, wl_surface}, + Connection, EventQueue, QueueHandle, + }, + registry::{ProvidesRegistryState, RegistryState}, + registry_handlers, + seat::{ + pointer::{PointerEvent, PointerEventKind, PointerHandler}, + Capability, SeatHandler, SeatState, + }, + shell::layer::{Anchor, Layer, LayerHandler, LayerState, LayerSurface, LayerSurfaceConfigure}, + shm::{slot::SlotPool, ShmHandler, ShmState}, +}; +use tokio::io::unix::AsyncFdReadyGuard; + +use crate::{ + bar::Bar, + config::Config, + delegate_river_control, delegate_river_status, + i3bar_protocol::Block, + pointer_btn::PointerBtn, + river_protocols::{ + control::{RiverControlHandler, RiverControlState}, + status::{RiverOutputStatus, RiverStatusHandler, RiverStatusState}, + }, + shared_state::SharedState, + status_cmd::StatusCmd, + text::ComputedText, +}; + +pub struct State { + registry_state: RegistryState, + seat_state: SeatState, + output_state: OutputState, + compositor_state: CompositorState, + shm_state: ShmState, + layer_state: LayerState, + river_status_state: RiverStatusState, + river_control_state: RiverControlState, + + pointers: Vec<(wl_pointer::WlPointer, wl_seat::WlSeat)>, + bars: Vec, + pub shared_state: Option, +} + +impl State { + pub fn new(conn: &Connection, event_queue: &mut EventQueue) -> Self { + let mut error = Ok(()); + + let config = Config::new() + .map_err(|e| error = Err(e)) + .unwrap_or_default(); + + let status_cmd = match &error { + Err(_) => None, + Ok(()) => config.command.as_ref().and_then(|cmd| { + StatusCmd::new(cmd) + .map_err(|e| error = Err(anyhow!(e))) + .ok() + }), + }; + + let mut this = Self { + registry_state: RegistryState::new(conn, &event_queue.handle()), + seat_state: SeatState::new(), + output_state: OutputState::new(), + compositor_state: CompositorState::new(), + shm_state: ShmState::new(), + layer_state: LayerState::new(), + river_status_state: RiverStatusState::new(), + river_control_state: RiverControlState::new(), + + pointers: Vec::new(), + bars: Vec::new(), + shared_state: None, + }; + + while !this.registry_state.ready() { + event_queue.blocking_dispatch(&mut this).unwrap(); + } + + this.shared_state = Some(SharedState { + qh: event_queue.handle(), + pool: SlotPool::new(1, &this.shm_state).expect("Failed to create pool"), + config, + status_cmd, + blocks: Vec::new(), + blocks_cache: Vec::new(), + }); + + if let Err(e) = error { + this.set_error(e.to_string()); + } + + this + } + + pub fn set_blocks(&mut self, blocks: Vec) { + self.shared_state.as_mut().unwrap().blocks = blocks; + self.draw_all(); + } + + pub fn set_error(&mut self, error: impl Into) { + self.set_blocks(vec![Block { + full_text: error.into(), + ..Default::default() + }]); + } + + pub fn notify_available(&mut self) -> anyhow::Result<()> { + if let Some(cmd) = &mut self.shared_state.as_mut().unwrap().status_cmd { + if let Some(blocks) = cmd.notify_available()? { + self.set_blocks(blocks); + } + } + Ok(()) + } + + pub fn draw_all(&mut self) { + for bar in &mut self.bars { + bar.draw(self.shared_state.as_mut().unwrap()); + } + } + + pub async fn wait_for_status_cmd(&self) -> io::Result> { + match &self.shared_state.as_ref().unwrap().status_cmd { + Some(cmd) => cmd.async_fd.readable().await, + None => { + pending::<()>().await; + unreachable!() + } + } + } +} + +impl CompositorHandler for State { + fn compositor_state(&mut self) -> &mut CompositorState { + &mut self.compositor_state + } + + fn scale_factor_changed( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + surface: &wl_surface::WlSurface, + scale: i32, + ) { + if let Some(bar) = self + .bars + .iter_mut() + .find(|bar| bar.layer.wl_surface() == surface) + { + bar.scale = scale; + bar.draw(self.shared_state.as_mut().expect("no shared_state?")); + } + } + + fn frame( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _surface: &wl_surface::WlSurface, + _time: u32, + ) { + } +} + +impl OutputHandler for State { + fn output_state(&mut self) -> &mut OutputState { + &mut self.output_state + } + + fn new_output( + &mut self, + _conn: &Connection, + qh: &QueueHandle, + output: wl_output::WlOutput, + ) { + let height = self.shared_state.as_ref().unwrap().config.height; + let surface = self.compositor_state.create_surface(qh).unwrap(); + let layer = LayerSurface::builder() + .output(&output) + .size((0, height)) + .anchor(Anchor::TOP | Anchor::LEFT | Anchor::RIGHT) + .namespace("i3bar-river") + .map(qh, &mut self.layer_state, surface, Layer::Top) + .expect("layer surface creation"); + let river_output_status = self.river_status_state.new_output_status(qh, &output).ok(); + self.bars.push(Bar { + first_configure: true, + width: 0, + height, + scale: 1, + layer, + blocks_btns: Default::default(), + river_output_status, + river_control: self.river_control_state.clone(), + tags_btns: Default::default(), + tags_info: Default::default(), + tags_computed: Vec::new(), + }); + } + + fn update_output( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _output: wl_output::WlOutput, + ) { + } + + fn output_destroyed( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _output: wl_output::WlOutput, + ) { + } +} + +impl LayerHandler for State { + fn layer_state(&mut self) -> &mut LayerState { + &mut self.layer_state + } + + fn closed(&mut self, _conn: &Connection, _qh: &QueueHandle, layer: &LayerSurface) { + self.bars.retain(|b| &b.layer != layer) + } + + fn configure( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + layer: &LayerSurface, + configure: LayerSurfaceConfigure, + _serial: u32, + ) { + self.bars + .iter_mut() + .find(|b| &b.layer == layer) + .unwrap() + .configure(self.shared_state.as_mut().unwrap(), configure.new_size.0); + } +} + +impl SeatHandler for State { + fn seat_state(&mut self) -> &mut SeatState { + &mut self.seat_state + } + + fn new_seat(&mut self, _: &Connection, _: &QueueHandle, _: wl_seat::WlSeat) {} + + fn new_capability( + &mut self, + _conn: &Connection, + qh: &QueueHandle, + seat: wl_seat::WlSeat, + capability: Capability, + ) { + if capability == Capability::Pointer { + let pointer = self + .seat_state + .get_pointer(qh, &seat) + .expect("Failed to create pointer"); + self.pointers.push((pointer, seat)); + } + } + + fn remove_capability( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + seat: wl_seat::WlSeat, + capability: Capability, + ) { + if capability == Capability::Pointer { + self.pointers.retain(|p| p.1 == seat); + } + } + + fn remove_seat(&mut self, _: &Connection, _: &QueueHandle, _: wl_seat::WlSeat) {} +} + +impl PointerHandler for State { + fn pointer_frame( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + pointer: &wl_pointer::WlPointer, + events: &[PointerEvent], + ) { + let seat = &self.pointers.iter().find(|p| &p.0 == pointer).unwrap().1; + for event in events { + if let Some(bar) = self + .bars + .iter_mut() + .find(|b| b.layer.wl_surface() == &event.surface) + { + match event.kind { + PointerEventKind::Enter { .. } => { + // TODO: set_cursor() + } + PointerEventKind::Press { button, .. } => { + bar.click( + self.shared_state.as_mut().unwrap(), + button.into(), + seat, + event.position.0, + event.position.1, + ) + .unwrap(); + } + PointerEventKind::Axis { vertical, .. } => { + bar.click( + self.shared_state.as_mut().unwrap(), + if vertical.discrete > 0 { + PointerBtn::WheelDown + } else { + PointerBtn::WheelUp + }, + seat, + event.position.0, + event.position.1, + ) + .unwrap(); + } + _ => (), + } + } + } + } +} + +impl ShmHandler for State { + fn shm_state(&mut self) -> &mut ShmState { + &mut self.shm_state + } +} + +impl RiverStatusHandler for State { + fn river_status_state(&mut self) -> &mut RiverStatusState { + &mut self.river_status_state + } + + fn focused_tags_updated( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + output_status: &RiverOutputStatus, + focused: u32, + ) { + let bar = self + .bars + .iter_mut() + .find(|b| b.river_output_status.as_ref() == Some(output_status)) + .unwrap(); + bar.tags_info.focused = focused; + bar.draw(self.shared_state.as_mut().unwrap()); + } + + fn urgent_tags_updated( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + output_status: &RiverOutputStatus, + urgent: u32, + ) { + let bar = self + .bars + .iter_mut() + .find(|b| b.river_output_status.as_ref() == Some(output_status)) + .unwrap(); + bar.tags_info.urgent = urgent; + bar.draw(self.shared_state.as_mut().unwrap()); + } +} + +impl RiverControlHandler for State { + fn river_control_state(&mut self) -> &mut RiverControlState { + &mut self.river_control_state + } + + fn command_failure(&mut self, _: &Connection, _: &QueueHandle, message: String) { + self.set_error(format!("[river_control] {message}")); + } + + fn command_success(&mut self, _: &Connection, _: &QueueHandle, message: String) { + info!("river_control: {message}"); + } +} + +delegate_compositor!(State); +delegate_output!(State); +delegate_shm!(State); +delegate_seat!(State); +delegate_pointer!(State); +delegate_layer!(State); +delegate_registry!(State); +delegate_river_status!(State); +delegate_river_control!(State); + +impl ProvidesRegistryState for State { + fn registry(&mut self) -> &mut RegistryState { + &mut self.registry_state + } + registry_handlers![ + CompositorState, + OutputState, + ShmState, + SeatState, + LayerState, + RiverStatusState, + RiverControlState, + ]; +} + +#[derive(Debug)] +pub struct ComputedBlock { + pub block: Block, + pub full: ComputedText, + pub short: Option, + pub min_width: Option, +} -- cgit v1.3.1 From 2a3c0d9ceac54c9f6d9312c610d2a161a4bb37c9 Mon Sep 17 00:00:00 2001 From: MaxVerevkin Date: Tue, 9 Aug 2022 22:04:22 +0300 Subject: some renames --- src/bar.rs | 8 ++++---- src/state.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/state.rs') diff --git a/src/bar.rs b/src/bar.rs index f3dc95c..b157190 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -20,7 +20,7 @@ use crate::{ }; pub struct Bar { - pub first_configure: bool, + pub configured: bool, pub width: u32, pub height: u32, pub scale: i32, @@ -35,12 +35,12 @@ pub struct Bar { impl Bar { pub fn configure(&mut self, ss: &mut SharedState, width: u32) { - if self.width != width { + if self.width != width && width != 0 { self.width = width; self.layer.set_exclusive_zone(self.height as i32); } - self.first_configure = false; + self.configured = true; self.draw(ss); } @@ -84,7 +84,7 @@ impl Bar { } pub fn draw(&mut self, ss: &mut SharedState) { - if self.first_configure { + if !self.configured { return; } diff --git a/src/state.rs b/src/state.rs index ea5ca4e..131e20f 100644 --- a/src/state.rs +++ b/src/state.rs @@ -194,7 +194,7 @@ impl OutputHandler for State { .expect("layer surface creation"); let river_output_status = self.river_status_state.new_output_status(qh, &output).ok(); self.bars.push(Bar { - first_configure: true, + configured: false, width: 0, height, scale: 1, -- cgit v1.3.1 From b154262dcbf0d1a5686921f24eb0b0c41ed95f29 Mon Sep 17 00:00:00 2001 From: MaxVerevkin Date: Thu, 25 Aug 2022 09:18:56 +0300 Subject: feat: add hide_inactive_tags option --- src/bar.rs | 27 ++++++++++++++++----------- src/config.rs | 7 +++++++ src/river_protocols/status.rs | 8 ++++++++ src/river_protocols/status/dispatch.rs | 8 +++++++- src/state.rs | 16 ++++++++++++++++ src/tags.rs | 6 +++++- 6 files changed, 59 insertions(+), 13 deletions(-) (limited to 'src/state.rs') diff --git a/src/bar.rs b/src/bar.rs index ffc4d7c..18ad54c 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -127,24 +127,28 @@ impl Bar { let mut offset_left = 0.0; if self.has_tags_provider() { if self.tags_computed.is_empty() { - let mut x_offset = 0.0; // TODO make configurable - for (id, text) in ["1", "2", "3", "4", "5", "6", "7", "8", "9"] - .iter() - .enumerate() - { - let tag = compute_tag_label(text, ss.config.font.clone(), &cairo_ctx); - self.tags_btns.push(x_offset, tag.width, id); - x_offset += tag.width; - self.tags_computed.push(tag); + for text in ["1", "2", "3", "4", "5", "6", "7", "8", "9"] { + self.tags_computed.push(compute_tag_label( + text, + ss.config.font.clone(), + &cairo_ctx, + )); } } + self.tags_btns.clear(); for (i, label) in self.tags_computed.iter().enumerate() { let state = self.tags_info.get_state(i); let (bg, fg) = match state { - TagState::Focused => (ss.config.tag_focused_bg, ss.config.tag_focused_fg), - TagState::Inactive => (ss.config.tag_bg, ss.config.tag_fg), TagState::Urgent => (ss.config.tag_urgent_bg, ss.config.tag_urgent_fg), + TagState::Focused => (ss.config.tag_focused_bg, ss.config.tag_focused_fg), + TagState::Active => (ss.config.tag_bg, ss.config.tag_fg), + TagState::Inactive => { + if ss.config.hide_inactive_tags { + continue; + } + (ss.config.tag_inactive_bg, ss.config.tag_inactive_fg) + } }; label.render( &cairo_ctx, @@ -167,6 +171,7 @@ impl Bar { overlap: 0.0, }, ); + self.tags_btns.push(offset_left, label.width, i); offset_left += label.width; } } diff --git a/src/config.rs b/src/config.rs index bd7b91c..9ae2395 100644 --- a/src/config.rs +++ b/src/config.rs @@ -20,6 +20,8 @@ pub struct Config { pub tag_focused_bg: Color, pub tag_urgent_fg: Color, pub tag_urgent_bg: Color, + pub tag_inactive_fg: Color, + pub tag_inactive_bg: Color, // font and size pub font: Font, pub height: u32, @@ -29,6 +31,8 @@ pub struct Config { pub blocks_overlap: f64, // command pub command: Option, + // misc + pub hide_inactive_tags: bool, } impl Default for Config { @@ -44,6 +48,8 @@ impl Default for Config { tag_focused_bg: Color::from_rgba_hex(0x689d68ff), tag_urgent_fg: Color::from_rgba_hex(0x282828ff), tag_urgent_bg: Color::from_rgba_hex(0xcc241dff), + tag_inactive_fg: Color::from_rgba_hex(0xd79921ff), + tag_inactive_bg: Color::from_rgba_hex(0x282828ff), font: Font::new("monospace 10"), height: 24, separator_width: 2.0, @@ -51,6 +57,7 @@ impl Default for Config { blocks_r: 0.0, blocks_overlap: 0.0, command: None, + hide_inactive_tags: false, } } } diff --git a/src/river_protocols/status.rs b/src/river_protocols/status.rs index 50c85e0..f19ac5f 100644 --- a/src/river_protocols/status.rs +++ b/src/river_protocols/status.rs @@ -96,6 +96,14 @@ pub trait RiverStatusHandler: Sized { output_status: &RiverOutputStatus, urgent: u32, ); + + fn views_tags_updated( + &mut self, + conn: &Connection, + qh: &QueueHandle, + output_status: &RiverOutputStatus, + tags: Vec, + ); } #[derive(Debug, Clone)] diff --git a/src/river_protocols/status/dispatch.rs b/src/river_protocols/status/dispatch.rs index d38037d..65d6e0c 100644 --- a/src/river_protocols/status/dispatch.rs +++ b/src/river_protocols/status/dispatch.rs @@ -79,7 +79,13 @@ where match event { Event::FocusedTags { tags } => data.focused_tags_updated(conn, qh, &status, tags), Event::UrgentTags { tags } => data.urgent_tags_updated(conn, qh, &status, tags), - Event::ViewTags { tags: _ } => (), + Event::ViewTags { tags } => { + let tags = tags + .chunks_exact(4) + .map(|bytes| u32::from_ne_bytes(bytes.try_into().unwrap())) + .collect(); + data.views_tags_updated(conn, qh, &status, tags); + } } } } diff --git a/src/state.rs b/src/state.rs index 131e20f..4dd9414 100644 --- a/src/state.rs +++ b/src/state.rs @@ -380,6 +380,22 @@ impl RiverStatusHandler for State { bar.tags_info.urgent = urgent; bar.draw(self.shared_state.as_mut().unwrap()); } + + fn views_tags_updated( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + output_status: &RiverOutputStatus, + tags: Vec, + ) { + let bar = self + .bars + .iter_mut() + .find(|b| b.river_output_status.as_ref() == Some(output_status)) + .unwrap(); + bar.tags_info.active = tags.into_iter().fold(0, |a, b| a | b); + bar.draw(self.shared_state.as_mut().unwrap()); + } } impl RiverControlHandler for State { diff --git a/src/tags.rs b/src/tags.rs index 0c63570..5a4a1b2 100644 --- a/src/tags.rs +++ b/src/tags.rs @@ -5,15 +5,17 @@ use pangocairo::{cairo, pango}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum TagState { + Urgent, Focused, + Active, Inactive, - Urgent, } #[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] pub struct TagsInfo { pub focused: u32, pub urgent: u32, + pub active: u32, } impl TagsInfo { @@ -22,6 +24,8 @@ impl TagsInfo { TagState::Urgent } else if self.focused >> tag & 1 == 1 { TagState::Focused + } else if self.active >> tag & 1 == 1 { + TagState::Active } else { TagState::Inactive } -- cgit v1.3.1 From a68c55c3462fa9c716a4d286a11cc451ac917800 Mon Sep 17 00:00:00 2001 From: MaxVerevkin Date: Fri, 26 Aug 2022 13:21:52 +0300 Subject: feat: add invert_touchpad_scrolling option --- src/config.rs | 4 +++- src/state.rs | 68 ++++++++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 56 insertions(+), 16 deletions(-) (limited to 'src/state.rs') diff --git a/src/config.rs b/src/config.rs index 9ae2395..2af9af0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -33,6 +33,7 @@ pub struct Config { pub command: Option, // misc pub hide_inactive_tags: bool, + pub invert_touchpad_scrolling: bool, } impl Default for Config { @@ -57,7 +58,8 @@ impl Default for Config { blocks_r: 0.0, blocks_overlap: 0.0, command: None, - hide_inactive_tags: false, + hide_inactive_tags: true, + invert_touchpad_scrolling: true, } } } diff --git a/src/state.rs b/src/state.rs index 4dd9414..0390525 100644 --- a/src/state.rs +++ b/src/state.rs @@ -45,11 +45,17 @@ pub struct State { river_status_state: RiverStatusState, river_control_state: RiverControlState, - pointers: Vec<(wl_pointer::WlPointer, wl_seat::WlSeat)>, + seats: Vec, bars: Vec, pub shared_state: Option, } +struct Seat { + seat: wl_seat::WlSeat, + pointer: wl_pointer::WlPointer, + finger_scroll: f64, +} + impl State { pub fn new(conn: &Connection, event_queue: &mut EventQueue) -> Self { let mut error = Ok(()); @@ -77,7 +83,7 @@ impl State { river_status_state: RiverStatusState::new(), river_control_state: RiverControlState::new(), - pointers: Vec::new(), + seats: Vec::new(), bars: Vec::new(), shared_state: None, }; @@ -269,7 +275,11 @@ impl SeatHandler for State { .seat_state .get_pointer(qh, &seat) .expect("Failed to create pointer"); - self.pointers.push((pointer, seat)); + self.seats.push(Seat { + seat, + pointer, + finger_scroll: 0.0, + }); } } @@ -281,7 +291,7 @@ impl SeatHandler for State { capability: Capability, ) { if capability == Capability::Pointer { - self.pointers.retain(|p| p.1 == seat); + self.seats.retain(|p| p.seat == seat); } } @@ -296,7 +306,12 @@ impl PointerHandler for State { pointer: &wl_pointer::WlPointer, events: &[PointerEvent], ) { - let seat = &self.pointers.iter().find(|p| &p.0 == pointer).unwrap().1; + let seat = self + .seats + .iter_mut() + .find(|p| &p.pointer == pointer) + .unwrap(); + let shared_state = self.shared_state.as_mut().unwrap(); for event in events { if let Some(bar) = self .bars @@ -309,23 +324,46 @@ impl PointerHandler for State { } PointerEventKind::Press { button, .. } => { bar.click( - self.shared_state.as_mut().unwrap(), + shared_state, button.into(), - seat, + &seat.seat, event.position.0, event.position.1, ) .unwrap(); } - PointerEventKind::Axis { vertical, .. } => { - bar.click( - self.shared_state.as_mut().unwrap(), - if vertical.discrete > 0 { - PointerBtn::WheelDown + PointerEventKind::Axis { + vertical, source, .. + } => { + if source == Some(wl_pointer::AxisSource::Finger) { + if shared_state.config.invert_touchpad_scrolling { + seat.finger_scroll -= vertical.absolute; } else { - PointerBtn::WheelUp - }, - seat, + seat.finger_scroll += vertical.absolute; + } + if vertical.stop { + seat.finger_scroll = 0.0; + } + } + + let btn = if vertical.discrete > 0 { + PointerBtn::WheelDown + } else if vertical.discrete < 0 { + PointerBtn::WheelUp + } else if seat.finger_scroll >= 15.0 { + seat.finger_scroll = 0.0; + PointerBtn::WheelDown + } else if seat.finger_scroll <= -15.0 { + seat.finger_scroll = 0.0; + PointerBtn::WheelUp + } else { + continue; + }; + + bar.click( + shared_state, + btn, + &seat.seat, event.position.0, event.position.1, ) -- cgit v1.3.1 From f0e53e6b8119d872f5986c3fcb4403d7b8214382 Mon Sep 17 00:00:00 2001 From: MaxVerevkin Date: Sat, 27 Aug 2022 09:16:12 +0300 Subject: refactor --- src/bar.rs | 2 +- src/main.rs | 2 +- src/shared_state.rs | 16 +++++++++++++-- src/state.rs | 58 +++++++++++++++++++++++------------------------------ 4 files changed, 41 insertions(+), 37 deletions(-) (limited to 'src/state.rs') diff --git a/src/bar.rs b/src/bar.rs index 188152f..ae69d37 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -95,7 +95,7 @@ impl Bar { let height_f = height as f64; let (buffer, canvas) = ss - .pool + .get_pool(height as usize * stride as usize) .create_buffer( width * self.scale, height * self.scale, diff --git a/src/main.rs b/src/main.rs index b158c91..7f8dd38 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,7 +50,7 @@ async fn main() -> anyhow::Result<()> { readable = state.wait_for_status_cmd() => { readable?.clear_ready(); if let Err(e) = state.notify_available() { - if let Some(mut status_cmd) = state.shared_state.as_mut().unwrap().status_cmd.take() { + if let Some(mut status_cmd) = state.shared_state.status_cmd.take() { let _ = status_cmd.child.kill(); } state.set_error(e.to_string()); diff --git a/src/shared_state.rs b/src/shared_state.rs index c4ec9d6..554d856 100644 --- a/src/shared_state.rs +++ b/src/shared_state.rs @@ -1,4 +1,7 @@ -use smithay_client_toolkit::{reexports::client::QueueHandle, shm::slot::SlotPool}; +use smithay_client_toolkit::{ + reexports::client::QueueHandle, + shm::{slot::SlotPool, ShmState}, +}; use crate::{ config::Config, @@ -10,9 +13,18 @@ use crate::{ #[derive(Debug)] pub struct SharedState { pub qh: QueueHandle, - pub pool: SlotPool, + pub shm_state: ShmState, + pub pool: Option, pub config: Config, pub status_cmd: Option, pub blocks: Vec, pub blocks_cache: Vec, } + +impl SharedState { + pub fn get_pool(&mut self, len: usize) -> &mut SlotPool { + self.pool.get_or_insert_with(|| { + SlotPool::new(len, &self.shm_state).expect("Failed to create pool") + }) + } +} diff --git a/src/state.rs b/src/state.rs index 0390525..f459681 100644 --- a/src/state.rs +++ b/src/state.rs @@ -16,7 +16,7 @@ use smithay_client_toolkit::{ Capability, SeatHandler, SeatState, }, shell::layer::{Anchor, Layer, LayerHandler, LayerState, LayerSurface, LayerSurfaceConfigure}, - shm::{slot::SlotPool, ShmHandler, ShmState}, + shm::{ShmHandler, ShmState}, }; use tokio::io::unix::AsyncFdReadyGuard; @@ -40,14 +40,13 @@ pub struct State { seat_state: SeatState, output_state: OutputState, compositor_state: CompositorState, - shm_state: ShmState, layer_state: LayerState, river_status_state: RiverStatusState, river_control_state: RiverControlState, seats: Vec, bars: Vec, - pub shared_state: Option, + pub shared_state: SharedState, } struct Seat { @@ -78,29 +77,23 @@ impl State { seat_state: SeatState::new(), output_state: OutputState::new(), compositor_state: CompositorState::new(), - shm_state: ShmState::new(), layer_state: LayerState::new(), river_status_state: RiverStatusState::new(), river_control_state: RiverControlState::new(), seats: Vec::new(), bars: Vec::new(), - shared_state: None, + shared_state: SharedState { + qh: event_queue.handle(), + shm_state: ShmState::new(), + pool: None, + config, + status_cmd, + blocks: Vec::new(), + blocks_cache: Vec::new(), + }, }; - while !this.registry_state.ready() { - event_queue.blocking_dispatch(&mut this).unwrap(); - } - - this.shared_state = Some(SharedState { - qh: event_queue.handle(), - pool: SlotPool::new(1, &this.shm_state).expect("Failed to create pool"), - config, - status_cmd, - blocks: Vec::new(), - blocks_cache: Vec::new(), - }); - if let Err(e) = error { this.set_error(e.to_string()); } @@ -109,7 +102,7 @@ impl State { } pub fn set_blocks(&mut self, blocks: Vec) { - self.shared_state.as_mut().unwrap().blocks = blocks; + self.shared_state.blocks = blocks; self.draw_all(); } @@ -121,7 +114,7 @@ impl State { } pub fn notify_available(&mut self) -> anyhow::Result<()> { - if let Some(cmd) = &mut self.shared_state.as_mut().unwrap().status_cmd { + if let Some(cmd) = &mut self.shared_state.status_cmd { if let Some(blocks) = cmd.notify_available()? { self.set_blocks(blocks); } @@ -131,12 +124,12 @@ impl State { pub fn draw_all(&mut self) { for bar in &mut self.bars { - bar.draw(self.shared_state.as_mut().unwrap()); + bar.draw(&mut self.shared_state); } } pub async fn wait_for_status_cmd(&self) -> io::Result> { - match &self.shared_state.as_ref().unwrap().status_cmd { + match &self.shared_state.status_cmd { Some(cmd) => cmd.async_fd.readable().await, None => { pending::<()>().await; @@ -164,7 +157,7 @@ impl CompositorHandler for State { .find(|bar| bar.layer.wl_surface() == surface) { bar.scale = scale; - bar.draw(self.shared_state.as_mut().expect("no shared_state?")); + bar.draw(&mut self.shared_state); } } @@ -189,7 +182,7 @@ impl OutputHandler for State { qh: &QueueHandle, output: wl_output::WlOutput, ) { - let height = self.shared_state.as_ref().unwrap().config.height; + let height = self.shared_state.config.height; let surface = self.compositor_state.create_surface(qh).unwrap(); let layer = LayerSurface::builder() .output(&output) @@ -252,7 +245,7 @@ impl LayerHandler for State { .iter_mut() .find(|b| &b.layer == layer) .unwrap() - .configure(self.shared_state.as_mut().unwrap(), configure.new_size.0); + .configure(&mut self.shared_state, configure.new_size.0); } } @@ -311,7 +304,6 @@ impl PointerHandler for State { .iter_mut() .find(|p| &p.pointer == pointer) .unwrap(); - let shared_state = self.shared_state.as_mut().unwrap(); for event in events { if let Some(bar) = self .bars @@ -324,7 +316,7 @@ impl PointerHandler for State { } PointerEventKind::Press { button, .. } => { bar.click( - shared_state, + &mut self.shared_state, button.into(), &seat.seat, event.position.0, @@ -336,7 +328,7 @@ impl PointerHandler for State { vertical, source, .. } => { if source == Some(wl_pointer::AxisSource::Finger) { - if shared_state.config.invert_touchpad_scrolling { + if self.shared_state.config.invert_touchpad_scrolling { seat.finger_scroll -= vertical.absolute; } else { seat.finger_scroll += vertical.absolute; @@ -361,7 +353,7 @@ impl PointerHandler for State { }; bar.click( - shared_state, + &mut self.shared_state, btn, &seat.seat, event.position.0, @@ -378,7 +370,7 @@ impl PointerHandler for State { impl ShmHandler for State { fn shm_state(&mut self) -> &mut ShmState { - &mut self.shm_state + &mut self.shared_state.shm_state } } @@ -400,7 +392,7 @@ impl RiverStatusHandler for State { .find(|b| b.river_output_status.as_ref() == Some(output_status)) .unwrap(); bar.tags_info.focused = focused; - bar.draw(self.shared_state.as_mut().unwrap()); + bar.draw(&mut self.shared_state); } fn urgent_tags_updated( @@ -416,7 +408,7 @@ impl RiverStatusHandler for State { .find(|b| b.river_output_status.as_ref() == Some(output_status)) .unwrap(); bar.tags_info.urgent = urgent; - bar.draw(self.shared_state.as_mut().unwrap()); + bar.draw(&mut self.shared_state); } fn views_tags_updated( @@ -432,7 +424,7 @@ impl RiverStatusHandler for State { .find(|b| b.river_output_status.as_ref() == Some(output_status)) .unwrap(); bar.tags_info.active = tags.into_iter().fold(0, |a, b| a | b); - bar.draw(self.shared_state.as_mut().unwrap()); + bar.draw(&mut self.shared_state); } } -- cgit v1.3.1 From a5baa2574ac0f8ff9ca8fbec0ff57145641ded47 Mon Sep 17 00:00:00 2001 From: MaxVerevkin Date: Fri, 23 Sep 2022 10:14:05 +0300 Subject: update dependencies --- Cargo.lock | 139 +++++++++++++++++++++++------------------ Cargo.toml | 6 +- src/main.rs | 5 +- src/river_protocols/control.rs | 8 ++- src/river_protocols/status.rs | 8 ++- src/state.rs | 2 +- 6 files changed, 94 insertions(+), 74 deletions(-) (limited to 'src/state.rs') diff --git a/Cargo.lock b/Cargo.lock index 55e7af7..c0dcd48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,18 +4,18 @@ version = 3 [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" dependencies = [ "memchr", ] [[package]] name = "anyhow" -version = "1.0.60" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c794e162a5eff65c72ef524dfe393eb923c354e350bb78b9c7383df13f3bc142" +checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" [[package]] name = "atty" @@ -123,9 +123,9 @@ checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" [[package]] name = "env_logger" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" +checksum = "c90bf5f19754d10198ccb95b70664fc925bd1fc090a0fd9a6ebc54acc8cd6272" dependencies = [ "atty", "humantime", @@ -136,24 +136,24 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" +checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" dependencies = [ "futures-core", ] [[package]] name = "futures-core" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" +checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" [[package]] name = "futures-executor" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6" +checksum = "9ff63c23854bee61b6e9cd331d523909f238fc7636290b96826e9cfa5faa00ab" dependencies = [ "futures-core", "futures-task", @@ -162,15 +162,15 @@ dependencies = [ [[package]] name = "futures-task" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" +checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" [[package]] name = "futures-util" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" +checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" dependencies = [ "futures-core", "futures-task", @@ -287,6 +287,16 @@ dependencies = [ "wayland-scanner", ] +[[package]] +name = "io-lifetimes" +version = "1.0.0-rc1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f65dae1d3aa98e6877917ab4e6fdbfdfb00e95885ea7c4f4f29e3a5dfc08fdf" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "itoa" version = "1.0.3" @@ -301,9 +311,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.127" +version = "0.2.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "505e71a4706fa491e9b1b55f51b95d4037d0821ee40131190475f692b35b009b" +checksum = "c0f80d65747a3e43d1596c7c5492d95d5edddaabd45a7fcdb02b95f644164966" [[package]] name = "libloading" @@ -332,9 +342,9 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memmap2" -version = "0.5.5" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a79b39c93a7a5a27eeaf9a23b5ff43f1b9e0ad6b1cdd441140ae53c35613fc7" +checksum = "95af15f345b17af2efc8ead6080fb8bc376f8cec1b35277b935637595fe77498" dependencies = [ "libc", ] @@ -390,9 +400,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" [[package]] name = "pango" @@ -508,6 +518,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quick-xml" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11bafc859c6815fbaffbbbf4229ecb767ac913fecb27f9ad4343662e9ef099ea" +dependencies = [ + "memchr", +] + [[package]] name = "quote" version = "1.0.21" @@ -568,18 +587,18 @@ checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" [[package]] name = "serde" -version = "1.0.142" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e590c437916fb6b221e1d00df6e3294f3fccd70ca7e92541c475d6ed6ef5fee2" +checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.142" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34b5b8d809babe02f538c2cfec6f2c1ed10804c0e5a6a041a049a4f5588ccc2e" +checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" dependencies = [ "proc-macro2", "quote", @@ -588,9 +607,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.83" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38dd04e3c8279e75b31ef29dbdceebfe5ad89f4d0937213c53f7d49d01b3d5a7" +checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" dependencies = [ "itoa", "ryu", @@ -615,7 +634,7 @@ checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" [[package]] name = "smithay-client-toolkit" version = "0.16.0" -source = "git+https://github.com/Smithay/client-toolkit#32bb7a6521d621baf278dd0f3abb0618cb3d2234" +source = "git+https://github.com/Smithay/client-toolkit#1cc11af8538040f46173bf021ac079c342ddeebb" dependencies = [ "bitflags", "dlib", @@ -630,13 +649,14 @@ dependencies = [ "wayland-cursor", "wayland-protocols", "wayland-protocols-wlr", + "wayland-scanner", ] [[package]] name = "socket2" -version = "0.4.4" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" dependencies = [ "libc", "winapi", @@ -644,9 +664,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.99" +version = "1.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" +checksum = "52205623b1b0f064a4e71182c3b18ae902267282930c6d5462c91b859668426e" dependencies = [ "proc-macro2", "quote", @@ -677,18 +697,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.32" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5f6586b7f764adc0231f4c79be7b920e766bb2f3e51b3661cdb263828f19994" +checksum = "c53f98874615aea268107765aa1ed8f6116782501d18e53d08b471733bea6c85" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.32" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12bafc5b54507e0149cdf1b145a5d80ab80a90bcd9275df43d4fff68460f6c21" +checksum = "f8b463991b4eab2d801e724172285ec4195c650e8ec79b149e6c2a8e6dd3f783" dependencies = [ "proc-macro2", "quote", @@ -697,9 +717,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.20.1" +version = "1.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" +checksum = "0020c875007ad96677dcc890298f4b942882c5d4eb7cc8f439fc3bf813dc9c95" dependencies = [ "autocfg", "libc", @@ -733,9 +753,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" +checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" [[package]] name = "version-compare" @@ -757,12 +777,13 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wayland-backend" -version = "0.1.0-beta.8" +version = "0.1.0-beta.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ee8e77c63b0cdc68bfc7b407b862b0fe2718949ce060b32d4f94ef1ea9607a4" +checksum = "30c089c872513a8dcc2b5cc26209d83f5ffab1841d8c7973edf2583620ebc018" dependencies = [ "cc", "downcast-rs", + "io-lifetimes", "nix", "scoped-tls", "smallvec", @@ -771,9 +792,9 @@ dependencies = [ [[package]] name = "wayland-client" -version = "0.30.0-beta.8" +version = "0.30.0-beta.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f9e0d862c23f07b2c4b49de66b0680948af5dd1d2def17f1ddc16520352bf14" +checksum = "bd71253f97d86ac930fb296ba995e31c178f1be6a7026244c3b3f3811d5086be" dependencies = [ "bitflags", "futures-channel", @@ -786,9 +807,9 @@ dependencies = [ [[package]] name = "wayland-cursor" -version = "0.30.0-beta.8" +version = "0.30.0-beta.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53732b42facd4f5ba891ed5d5f16fc02231ca543a0eb5bd16233947aa5900027" +checksum = "e39f4325f2ea5c1548cda2a6edabb74c68b072c9d6db7d7363cd9fe4994b124b" dependencies = [ "nix", "wayland-client", @@ -797,9 +818,9 @@ dependencies = [ [[package]] name = "wayland-protocols" -version = "0.30.0-beta.8" +version = "0.30.0-beta.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e47c45a60d531d5a513601f47f51a4743901836778ddae208ae9124606be1719" +checksum = "60406a2fb43ff670ece4976cdd0537bbcd1e583b54c3cd9a1b61065e966df0a7" dependencies = [ "bitflags", "wayland-backend", @@ -809,9 +830,9 @@ dependencies = [ [[package]] name = "wayland-protocols-wlr" -version = "0.1.0-beta.8" +version = "0.1.0-beta.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0b477d16e0c1d7512f11799403c8dbb1964e756667208569ec0ea2bd1abbccb" +checksum = "f1cfe42e0cfcce47a421844ee82e49316cfab3ec6bcbb3a1076a0a2dd6c8d61e" dependencies = [ "bitflags", "wayland-backend", @@ -822,21 +843,21 @@ dependencies = [ [[package]] name = "wayland-scanner" -version = "0.30.0-beta.8" +version = "0.30.0-beta.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87933ccc3df4f6335cf240aca0647aa34319fdd693dda503f645ca4df4e10386" +checksum = "a1398566f240c3ef845bdfd310c8ee6ba800d4db695d007f23f2190eeedfff93" dependencies = [ "proc-macro2", + "quick-xml", "quote", "syn", - "xml-rs", ] [[package]] name = "wayland-sys" -version = "0.30.0-beta.8" +version = "0.30.0-beta.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "beca223ed017df1b356ff181d4d6e7f2b135418c4888df5bb02df7a563f02ab0" +checksum = "bacc6b678c3350910e5ad6c057b7503666080952c4ece0a7e8958fd33937b1f5" dependencies = [ "dlib", "log", @@ -925,9 +946,3 @@ checksum = "463705a63313cd4301184381c5e8042f0a7e9b4bb63653f216311d4ae74690b7" dependencies = [ "nom", ] - -[[package]] -name = "xml-rs" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3" diff --git a/Cargo.toml b/Cargo.toml index e1737b4..90ea6c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,9 @@ pangocairo = "0.15" serde = { version = "1", features = ["derive"] } serde_json = "1" memchr = "2" -wayland-client = "0.30.0-beta.8" -wayland-scanner = "0.30.0-beta.8" -wayland-backend = "0.1.0-beta.8" +wayland-client = "0.30.0-beta.10" +wayland-scanner = "0.30.0-beta.10" +wayland-backend = "0.1.0-beta.10" [dependencies.smithay-client-toolkit] git = "https://github.com/Smithay/client-toolkit" diff --git a/src/main.rs b/src/main.rs index 7f8dd38..fb52f07 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,8 @@ mod tags; mod text; mod utils; +use std::os::unix::io::AsRawFd; + use smithay_client_toolkit::reexports::client::Connection; use tokio::io::{unix::AsyncFd, Interest}; @@ -32,12 +34,11 @@ async fn main() -> anyhow::Result<()> { let mut state = State::new(&conn, &mut event_queue); let async_fd = AsyncFd::with_interest( - event_queue.prepare_read()?.connection_fd(), + event_queue.prepare_read()?.connection_fd().as_raw_fd(), Interest::READABLE, )?; event_queue.roundtrip(&mut state)?; - event_queue.flush()?; loop { tokio::select! { diff --git a/src/river_protocols/control.rs b/src/river_protocols/control.rs index 0e7d7e4..525a9db 100644 --- a/src/river_protocols/control.rs +++ b/src/river_protocols/control.rs @@ -60,7 +60,7 @@ impl RiverControlState { for arg in args { control.add_argument(arg.into()); } - control.run_command(seat, qh, RiverCommandCallbackData {})?; + control.run_command(seat, qh, RiverCommandCallbackData {}); Ok(()) } } @@ -82,8 +82,10 @@ pub struct RiverCommandCallbackData { macro_rules! delegate_river_control { ($ty: ty) => { ::smithay_client_toolkit::reexports::client::delegate_dispatch!($ty: [ - $crate::river_protocols::control::protocol::zriver_control_v1::ZriverControlV1: ::smithay_client_toolkit::globals::GlobalData, - $crate::river_protocols::control::protocol::zriver_command_callback_v1::ZriverCommandCallbackV1: $crate::river_protocols::control::RiverCommandCallbackData, + $crate::river_protocols::control::protocol::zriver_control_v1::ZriverControlV1: ::smithay_client_toolkit::globals::GlobalData + ] => $crate::river_protocols::control::RiverControlState); + ::smithay_client_toolkit::reexports::client::delegate_dispatch!($ty: [ + $crate::river_protocols::control::protocol::zriver_command_callback_v1::ZriverCommandCallbackV1: $crate::river_protocols::control::RiverCommandCallbackData ] => $crate::river_protocols::control::RiverControlState); }; } diff --git a/src/river_protocols/status.rs b/src/river_protocols/status.rs index f19ac5f..079572a 100644 --- a/src/river_protocols/status.rs +++ b/src/river_protocols/status.rs @@ -66,7 +66,7 @@ impl RiverStatusState { + 'static, { let manager = self.status_manager()?; - let output_status = manager.get_river_output_status(output, qh, RiverStatusData {})?; + let output_status = manager.get_river_output_status(output, qh, RiverStatusData {}); let output_status = RiverOutputStatus(Arc::new(OutputStatusInner { status: output_status, @@ -124,8 +124,10 @@ pub struct RiverStatusData { macro_rules! delegate_river_status { ($ty: ty) => { ::smithay_client_toolkit::reexports::client::delegate_dispatch!($ty: [ - $crate::river_protocols::status::protocol::zriver_status_manager_v1::ZriverStatusManagerV1: ::smithay_client_toolkit::globals::GlobalData, - $crate::river_protocols::status::protocol::zriver_output_status_v1::ZriverOutputStatusV1: $crate::river_protocols::status::RiverStatusData, + $crate::river_protocols::status::protocol::zriver_status_manager_v1::ZriverStatusManagerV1: ::smithay_client_toolkit::globals::GlobalData + ] => $crate::river_protocols::status::RiverStatusState); + ::smithay_client_toolkit::reexports::client::delegate_dispatch!($ty: [ + $crate::river_protocols::status::protocol::zriver_output_status_v1::ZriverOutputStatusV1: $crate::river_protocols::status::RiverStatusData ] => $crate::river_protocols::status::RiverStatusState); }; } diff --git a/src/state.rs b/src/state.rs index f459681..3d5b2d4 100644 --- a/src/state.rs +++ b/src/state.rs @@ -189,7 +189,7 @@ impl OutputHandler for State { .size((0, height)) .anchor(Anchor::TOP | Anchor::LEFT | Anchor::RIGHT) .namespace("i3bar-river") - .map(qh, &mut self.layer_state, surface, Layer::Top) + .map(qh, &self.layer_state, surface, Layer::Top) .expect("layer surface creation"); let river_output_status = self.river_status_state.new_output_status(qh, &output).ok(); self.bars.push(Bar { -- cgit v1.3.1 From d45a4ef408c0f5a2071194d4c3285f0b7cb27dd0 Mon Sep 17 00:00:00 2001 From: MaxVerevkin Date: Sun, 27 Nov 2022 21:06:35 +0200 Subject: update wayland libs & readd set_cursor --- Cargo.lock | 130 +++++++++++++++++++++++--------- Cargo.toml | 8 +- src/bar.rs | 10 +-- src/main.rs | 5 +- src/river_protocols/control.rs | 115 ++++++++++++++++------------ src/river_protocols/control/dispatch.rs | 70 ----------------- src/river_protocols/status.rs | 129 +++++++++++++++++++++---------- src/river_protocols/status/dispatch.rs | 92 ---------------------- src/state.rs | 81 ++++++++++---------- src/text.rs | 2 +- 10 files changed, 305 insertions(+), 337 deletions(-) delete mode 100644 src/river_protocols/control/dispatch.rs delete mode 100644 src/river_protocols/status/dispatch.rs (limited to 'src/state.rs') diff --git a/Cargo.lock b/Cargo.lock index c0dcd48..15e4189 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -42,22 +42,23 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "cairo-rs" -version = "0.15.12" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c76ee391b03d35510d9fa917357c7f1855bd9a6659c95a1b392e33f49b3369bc" +checksum = "08f9ee4a4ca9239c9a839453dce04b7ddee2f859ec4cd7acd1f5703b68db549c" dependencies = [ "bitflags", "cairo-sys-rs", "glib", "libc", + "once_cell", "thiserror", ] [[package]] name = "cairo-sys-rs" -version = "0.15.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c55d429bef56ac9172d25fecb85dc8068307d17acd74b377866b7a1ef25d3c8" +checksum = "5119ea655ec777b523f0b57279e70f8a4542f61b0e98a48f892b4ef043fd4c5d" dependencies = [ "glib-sys", "libc", @@ -160,6 +161,23 @@ dependencies = [ "futures-util", ] +[[package]] +name = "futures-io" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" + +[[package]] +name = "futures-macro" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42cd15d1c7456c04dbdf7e88bcd69760d74f3a798d6444e16974b505b0e62f17" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "futures-task" version = "0.3.24" @@ -173,6 +191,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" dependencies = [ "futures-core", + "futures-macro", "futures-task", "pin-project-lite", "pin-utils", @@ -190,17 +209,52 @@ dependencies = [ "wasi", ] +[[package]] +name = "gio" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33c1debf8d0315d69be0153aa76249db3c858ef69b7778ad3cc669e6d370c485" +dependencies = [ + "bitflags", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "gio-sys", + "glib", + "libc", + "once_cell", + "pin-project-lite", + "smallvec", + "thiserror", +] + +[[package]] +name = "gio-sys" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6da1bba9d3f2ab13a6e9932c40f240dc99ebc9f0bdc35cfb130d1a3df36f374c" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", + "winapi", +] + [[package]] name = "glib" -version = "0.15.12" +version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edb0306fbad0ab5428b0ca674a23893db909a98582969c9b537be4ced78c505d" +checksum = "d5abffa711471e015eb93d65d6ea20e7e9f6f7951fc0a1042280439319b2de06" dependencies = [ "bitflags", "futures-channel", "futures-core", "futures-executor", "futures-task", + "futures-util", + "gio-sys", "glib-macros", "glib-sys", "gobject-sys", @@ -212,9 +266,9 @@ dependencies = [ [[package]] name = "glib-macros" -version = "0.15.11" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a68131a662b04931e71891fb14aaf65ee4b44d08e8abc10f49e77418c86c64" +checksum = "e195c1311fa6b04d7b896ea39385f6bd60ef5d25bf74a7c11c8c3f94f6c1a572" dependencies = [ "anyhow", "heck", @@ -227,9 +281,9 @@ dependencies = [ [[package]] name = "glib-sys" -version = "0.15.10" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef4b192f8e65e9cf76cbf4ea71fa8e3be4a0e18ffe3d68b8da6836974cc5bad4" +checksum = "b33357bb421a77bd849f6a0bfcaf3b4b256a2577802971bb5dd522d530f27021" dependencies = [ "libc", "system-deps", @@ -237,9 +291,9 @@ dependencies = [ [[package]] name = "gobject-sys" -version = "0.15.10" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d57ce44246becd17153bd035ab4d32cfee096a657fc01f2231c9278378d1e0a" +checksum = "63ca11a57400f3d4fda594e002844be47900c9fb8b29e2155c6e37a1f24e51b3" dependencies = [ "glib-sys", "libc", @@ -378,10 +432,11 @@ dependencies = [ [[package]] name = "nix" -version = "0.24.2" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc" +checksum = "e322c04a9e3440c327fca7b6c8a63e6890a32fa2ad689db972425f07e0d22abb" dependencies = [ + "autocfg", "bitflags", "cfg-if", "libc", @@ -406,11 +461,12 @@ checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" [[package]] name = "pango" -version = "0.15.10" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e4045548659aee5313bde6c582b0d83a627b7904dd20dc2d9ef0895d414e4f" +checksum = "7208c60f224cf6e44c551df5ee2ef38f9da0fd29d7c5a0402000b8ab0520e798" dependencies = [ "bitflags", + "gio", "glib", "libc", "once_cell", @@ -419,9 +475,9 @@ dependencies = [ [[package]] name = "pango-sys" -version = "0.15.10" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2a00081cde4661982ed91d80ef437c20eacaf6aa1a5962c0279ae194662c3aa" +checksum = "922441c228366ed98d3534b87bc7c987c50564094c3abbc3513717786419252d" dependencies = [ "glib-sys", "gobject-sys", @@ -431,9 +487,9 @@ dependencies = [ [[package]] name = "pangocairo" -version = "0.15.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7876a45c1f1d1a75a2601dc6d9ef2cb5a8be0e3d76f909d82450759929035366" +checksum = "a726760a29e5e17d965d5d7573548e385ae9ce99cb7adcf70d75d4627f23fc7a" dependencies = [ "bitflags", "cairo-rs", @@ -445,9 +501,9 @@ dependencies = [ [[package]] name = "pangocairo-sys" -version = "0.15.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78cf746594916c81d5f739af9335c5f55a1f4606d80b3e1d821f18cf95a29494" +checksum = "b8281198ea4596bdc6e22b0d3565471c9456d7125e423a785f866640c18b57ec" dependencies = [ "cairo-sys-rs", "glib-sys", @@ -634,7 +690,7 @@ checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" [[package]] name = "smithay-client-toolkit" version = "0.16.0" -source = "git+https://github.com/Smithay/client-toolkit#1cc11af8538040f46173bf021ac079c342ddeebb" +source = "git+https://github.com/Smithay/client-toolkit#e5d7c9084f8d80bef4c625c6ef52ec42dde4e211" dependencies = [ "bitflags", "dlib", @@ -777,9 +833,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wayland-backend" -version = "0.1.0-beta.10" +version = "0.1.0-beta.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30c089c872513a8dcc2b5cc26209d83f5ffab1841d8c7973edf2583620ebc018" +checksum = "f3f96c52ca34b33e6bb55497327428be54dad648973aa5d3d1e02982d2fcc298" dependencies = [ "cc", "downcast-rs", @@ -792,9 +848,9 @@ dependencies = [ [[package]] name = "wayland-client" -version = "0.30.0-beta.10" +version = "0.30.0-beta.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd71253f97d86ac930fb296ba995e31c178f1be6a7026244c3b3f3811d5086be" +checksum = "0f6ab5911cc8a28e9d781933c1afe0f97ffa6885ad8941294784d025f06e5ad9" dependencies = [ "bitflags", "futures-channel", @@ -807,9 +863,9 @@ dependencies = [ [[package]] name = "wayland-cursor" -version = "0.30.0-beta.10" +version = "0.30.0-beta.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e39f4325f2ea5c1548cda2a6edabb74c68b072c9d6db7d7363cd9fe4994b124b" +checksum = "fa5ce1bbc13a3d806648974cba1d53481fea2ac29483eb147e4cce1250fc5263" dependencies = [ "nix", "wayland-client", @@ -818,9 +874,9 @@ dependencies = [ [[package]] name = "wayland-protocols" -version = "0.30.0-beta.10" +version = "0.30.0-beta.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60406a2fb43ff670ece4976cdd0537bbcd1e583b54c3cd9a1b61065e966df0a7" +checksum = "e32104ba51988754f4429dbb59c7b7fd2ccf1feaa0009bb59e49a5e2f91e985d" dependencies = [ "bitflags", "wayland-backend", @@ -830,9 +886,9 @@ dependencies = [ [[package]] name = "wayland-protocols-wlr" -version = "0.1.0-beta.10" +version = "0.1.0-beta.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1cfe42e0cfcce47a421844ee82e49316cfab3ec6bcbb3a1076a0a2dd6c8d61e" +checksum = "130613a48629204e4ab50ea4b5de2efa2e17c58f71a5af15b39535f99421f8c3" dependencies = [ "bitflags", "wayland-backend", @@ -843,9 +899,9 @@ dependencies = [ [[package]] name = "wayland-scanner" -version = "0.30.0-beta.10" +version = "0.30.0-beta.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1398566f240c3ef845bdfd310c8ee6ba800d4db695d007f23f2190eeedfff93" +checksum = "1fb55ca28710dcc155078db4e2bd29aacf24bd311261c48750f38c6c5430bf1f" dependencies = [ "proc-macro2", "quick-xml", @@ -855,9 +911,9 @@ dependencies = [ [[package]] name = "wayland-sys" -version = "0.30.0-beta.10" +version = "0.30.0-beta.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bacc6b678c3350910e5ad6c057b7503666080952c4ece0a7e8958fd33937b1f5" +checksum = "882bda56e8397384ad66ec0ebe763e0b3b53153a6327344f7d74b85981a271e1" dependencies = [ "dlib", "log", diff --git a/Cargo.toml b/Cargo.toml index 90ea6c7..40a46bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,13 +9,13 @@ env_logger = "0.9" anyhow = "1" dirs-next = "2" toml = "0.5" -pangocairo = "0.15" +pangocairo = "0.16" serde = { version = "1", features = ["derive"] } serde_json = "1" memchr = "2" -wayland-client = "0.30.0-beta.10" -wayland-scanner = "0.30.0-beta.10" -wayland-backend = "0.1.0-beta.10" +wayland-client = "0.30.0-beta.13" +wayland-scanner = "0.30.0-beta.13" +wayland-backend = "0.1.0-beta.13" [dependencies.smithay-client-toolkit] git = "https://github.com/Smithay/client-toolkit" diff --git a/src/bar.rs b/src/bar.rs index 0569b71..dfa63a3 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -27,7 +27,7 @@ pub struct Bar { pub layer: LayerSurface, pub blocks_btns: ButtonManager<(Option, Option)>, pub river_output_status: Option, - pub river_control: RiverControlState, + pub river_control: Option, pub tags_btns: ButtonManager, pub tags_info: TagsInfo, pub tags_computed: Vec, @@ -58,17 +58,13 @@ impl Bar { _y: f64, ) -> anyhow::Result<()> { if let Some(tag) = self.tags_btns.click(x) { - if self.river_control.is_available() { + if let Some(river_control) = &self.river_control { let cmd = match button { PointerBtn::Left => "set-focused-tags", PointerBtn::Right => "toggle-focused-tags", _ => return Ok(()), }; - self.river_control.run_command( - &ss.qh, - seat, - [cmd.into(), (1u32 << tag).to_string()], - )?; + river_control.run_command(&ss.qh, seat, [cmd.into(), (1u32 << tag).to_string()]); } } else if let Some((name, instance)) = self.blocks_btns.click(x) { if let Some(cmd) = &mut ss.status_cmd { diff --git a/src/main.rs b/src/main.rs index fb52f07..8ae31aa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,14 +24,15 @@ use smithay_client_toolkit::reexports::client::Connection; use tokio::io::{unix::AsyncFd, Interest}; use state::State; +use wayland_client::globals::registry_queue_init; #[tokio::main(flavor = "current_thread")] async fn main() -> anyhow::Result<()> { env_logger::init(); let conn = Connection::connect_to_env()?; - let mut event_queue = conn.new_event_queue(); - let mut state = State::new(&conn, &mut event_queue); + let (globals, mut event_queue) = registry_queue_init(&conn).unwrap(); + let mut state = State::new(&mut event_queue, &globals); let async_fd = AsyncFd::with_interest( event_queue.prepare_read()?.connection_fd().as_raw_fd(), diff --git a/src/river_protocols/control.rs b/src/river_protocols/control.rs index 525a9db..7cce23d 100644 --- a/src/river_protocols/control.rs +++ b/src/river_protocols/control.rs @@ -1,67 +1,34 @@ -pub mod protocol { - use smithay_client_toolkit::reexports::client as wayland_client; - use smithay_client_toolkit::reexports::client::protocol::*; - - pub mod __interfaces { - use smithay_client_toolkit::reexports::client::protocol::__interfaces::*; - wayland_scanner::generate_interfaces!("protocols/river-control-unstable-v1.xml"); - } - use self::__interfaces::*; - - wayland_scanner::generate_client_code!("protocols/river-control-unstable-v1.xml"); -} - -mod dispatch; - -use std::sync::Arc; - -use smithay_client_toolkit::globals::GlobalData; +use wayland_client::globals::{BindError, GlobalList}; use wayland_client::{protocol::wl_seat, Connection, Dispatch, QueueHandle}; use protocol::{zriver_command_callback_v1, zriver_control_v1}; -use smithay_client_toolkit::error::GlobalError; -use smithay_client_toolkit::registry::GlobalProxy; - #[derive(Debug, Clone)] pub struct RiverControlState { - control: Arc>, + control: zriver_control_v1::ZriverControlV1, } impl RiverControlState { - pub fn new() -> Self { - Self { - control: Arc::new(GlobalProxy::NotReady), - } - } - - pub fn is_available(&self) -> bool { - self.control.get().is_ok() - } - - pub fn control(&self) -> Result<&zriver_control_v1::ZriverControlV1, GlobalError> { - self.control.get() + pub fn new(globals: &GlobalList, qh: &QueueHandle) -> Result + where + D: Dispatch + 'static, + { + let control = globals.bind(qh, 1..=1, ())?; + Ok(Self { control }) } - pub fn run_command( - &self, - qh: &QueueHandle, - seat: &wl_seat::WlSeat, - args: Args, - ) -> Result<(), GlobalError> + pub fn run_command(&self, qh: &QueueHandle, seat: &wl_seat::WlSeat, args: Args) where - D: Dispatch - + Dispatch + D: Dispatch + 'static, Args: IntoIterator, Arg: Into, { - let control = self.control()?; for arg in args { - control.add_argument(arg.into()); + self.control.add_argument(arg.into()); } - control.run_command(seat, qh, RiverCommandCallbackData {}); - Ok(()) + self.control + .run_command(seat, qh, RiverCommandCallbackData {}); } } @@ -82,10 +49,64 @@ pub struct RiverCommandCallbackData { macro_rules! delegate_river_control { ($ty: ty) => { ::smithay_client_toolkit::reexports::client::delegate_dispatch!($ty: [ - $crate::river_protocols::control::protocol::zriver_control_v1::ZriverControlV1: ::smithay_client_toolkit::globals::GlobalData + $crate::river_protocols::control::protocol::zriver_control_v1::ZriverControlV1: () ] => $crate::river_protocols::control::RiverControlState); ::smithay_client_toolkit::reexports::client::delegate_dispatch!($ty: [ $crate::river_protocols::control::protocol::zriver_command_callback_v1::ZriverCommandCallbackV1: $crate::river_protocols::control::RiverCommandCallbackData ] => $crate::river_protocols::control::RiverControlState); }; } + +impl Dispatch for RiverControlState +where + D: Dispatch + RiverControlHandler + 'static, +{ + fn event( + _: &mut D, + _: &zriver_control_v1::ZriverControlV1, + _: zriver_control_v1::Event, + _: &(), + _: &Connection, + _: &QueueHandle, + ) { + unreachable!("zriver_control_v1 has no events") + } +} + +impl Dispatch + for RiverControlState +where + D: Dispatch + + RiverControlHandler + + 'static, +{ + fn event( + data: &mut D, + _callback: &zriver_command_callback_v1::ZriverCommandCallbackV1, + event: zriver_command_callback_v1::Event, + _udata: &RiverCommandCallbackData, + conn: &Connection, + qh: &QueueHandle, + ) { + use zriver_command_callback_v1::Event; + match event { + Event::Success { output } => data.command_success(conn, qh, output), + Event::Failure { failure_message } => data.command_success(conn, qh, failure_message), + } + } +} + +pub mod protocol { + #![allow(non_upper_case_globals)] + + use smithay_client_toolkit::reexports::client as wayland_client; + use smithay_client_toolkit::reexports::client::protocol::*; + + pub mod __interfaces { + use smithay_client_toolkit::reexports::client::protocol::__interfaces::*; + wayland_scanner::generate_interfaces!("protocols/river-control-unstable-v1.xml"); + } + use self::__interfaces::*; + + wayland_scanner::generate_client_code!("protocols/river-control-unstable-v1.xml"); +} diff --git a/src/river_protocols/control/dispatch.rs b/src/river_protocols/control/dispatch.rs deleted file mode 100644 index 14759e7..0000000 --- a/src/river_protocols/control/dispatch.rs +++ /dev/null @@ -1,70 +0,0 @@ -use std::sync::Arc; - -use super::protocol::{zriver_command_callback_v1, zriver_control_v1}; -use wayland_client::{Connection, Dispatch, QueueHandle}; - -use smithay_client_toolkit::{ - error::GlobalError, - globals::{GlobalData, ProvidesBoundGlobal}, - registry::{ProvidesRegistryState, RegistryHandler}, -}; - -use super::{RiverCommandCallbackData, RiverControlHandler, RiverControlState}; - -impl RegistryHandler for RiverControlState -where - D: Dispatch - + RiverControlHandler - + ProvidesRegistryState - + 'static, -{ - fn ready(data: &mut D, _conn: &Connection, qh: &QueueHandle) { - data.river_control_state().control = - Arc::new(data.registry().bind_one(qh, 1..=1, GlobalData).into()); - } -} - -impl ProvidesBoundGlobal for RiverControlState { - fn bound_global(&self) -> Result { - self.control.get().cloned() - } -} - -impl Dispatch for RiverControlState -where - D: Dispatch + RiverControlHandler + 'static, -{ - fn event( - _: &mut D, - _: &zriver_control_v1::ZriverControlV1, - _: zriver_control_v1::Event, - _: &GlobalData, - _: &Connection, - _: &QueueHandle, - ) { - unreachable!("zriver_control_v1 has no events") - } -} - -impl Dispatch - for RiverControlState -where - D: Dispatch - + RiverControlHandler - + 'static, -{ - fn event( - data: &mut D, - _callback: &zriver_command_callback_v1::ZriverCommandCallbackV1, - event: zriver_command_callback_v1::Event, - _udata: &RiverCommandCallbackData, - conn: &Connection, - qh: &QueueHandle, - ) { - use zriver_command_callback_v1::Event; - match event { - Event::Success { output } => data.command_success(conn, qh, output), - Event::Failure { failure_message } => data.command_success(conn, qh, failure_message), - } - } -} diff --git a/src/river_protocols/status.rs b/src/river_protocols/status.rs index 079572a..1779719 100644 --- a/src/river_protocols/status.rs +++ b/src/river_protocols/status.rs @@ -1,46 +1,29 @@ -pub mod protocol { - use smithay_client_toolkit::reexports::client as wayland_client; - use smithay_client_toolkit::reexports::client::protocol::*; - - pub mod __interfaces { - use smithay_client_toolkit::reexports::client::protocol::__interfaces::*; - wayland_scanner::generate_interfaces!("protocols/river-status-unstable-v1.xml"); - } - use self::__interfaces::*; - - wayland_scanner::generate_client_code!("protocols/river-status-unstable-v1.xml"); -} - -mod dispatch; - use std::sync::{Arc, Weak}; -use smithay_client_toolkit::globals::GlobalData; -use wayland_client::{protocol::wl_output, Connection, Dispatch, QueueHandle}; +use wayland_client::{ + globals::{BindError, GlobalList}, + protocol::wl_output, + Connection, Dispatch, QueueHandle, +}; use protocol::{zriver_output_status_v1, zriver_status_manager_v1}; -use smithay_client_toolkit::error::GlobalError; -use smithay_client_toolkit::registry::GlobalProxy; - -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct RiverStatusState { - status_manager: GlobalProxy, + status_manager: zriver_status_manager_v1::ZriverStatusManagerV1, output_statuses: Vec>, } impl RiverStatusState { - pub fn new() -> Self { - Self { - status_manager: GlobalProxy::NotReady, + pub fn new(globals: &GlobalList, qh: &QueueHandle) -> Result + where + D: Dispatch + 'static, + { + let status_manager = globals.bind(qh, 1..=1, ())?; + Ok(Self { + status_manager, output_statuses: Vec::new(), - } - } - - pub fn status_manager( - &self, - ) -> Result<&zriver_status_manager_v1::ZriverStatusManagerV1, GlobalError> { - self.status_manager.get() + }) } pub fn get_output_status( @@ -59,14 +42,15 @@ impl RiverStatusState { &mut self, qh: &QueueHandle, output: &wl_output::WlOutput, - ) -> Result + ) -> RiverOutputStatus where - D: Dispatch + D: Dispatch + Dispatch + 'static, { - let manager = self.status_manager()?; - let output_status = manager.get_river_output_status(output, qh, RiverStatusData {}); + let output_status = + self.status_manager + .get_river_output_status(output, qh, RiverStatusData {}); let output_status = RiverOutputStatus(Arc::new(OutputStatusInner { status: output_status, @@ -74,7 +58,7 @@ impl RiverStatusState { self.output_statuses.push(Arc::downgrade(&output_status.0)); - Ok(output_status) + output_status } } @@ -124,7 +108,7 @@ pub struct RiverStatusData { macro_rules! delegate_river_status { ($ty: ty) => { ::smithay_client_toolkit::reexports::client::delegate_dispatch!($ty: [ - $crate::river_protocols::status::protocol::zriver_status_manager_v1::ZriverStatusManagerV1: ::smithay_client_toolkit::globals::GlobalData + $crate::river_protocols::status::protocol::zriver_status_manager_v1::ZriverStatusManagerV1: () ] => $crate::river_protocols::status::RiverStatusState); ::smithay_client_toolkit::reexports::client::delegate_dispatch!($ty: [ $crate::river_protocols::status::protocol::zriver_output_status_v1::ZriverOutputStatusV1: $crate::river_protocols::status::RiverStatusData @@ -142,3 +126,72 @@ impl Drop for OutputStatusInner { self.status.destroy(); } } + +impl Dispatch for RiverStatusState +where + D: Dispatch + RiverStatusHandler + 'static, +{ + fn event( + _: &mut D, + _: &zriver_status_manager_v1::ZriverStatusManagerV1, + _: zriver_status_manager_v1::Event, + _: &(), + _: &Connection, + _: &QueueHandle, + ) { + unreachable!("zriver_status_manager_v1 has no events") + } +} + +impl Dispatch + for RiverStatusState +where + D: Dispatch + + RiverStatusHandler + + 'static, +{ + fn event( + data: &mut D, + status: &zriver_output_status_v1::ZriverOutputStatusV1, + event: zriver_output_status_v1::Event, + _udata: &RiverStatusData, + conn: &Connection, + qh: &QueueHandle, + ) { + use zriver_output_status_v1::Event; + + // Remove any statuses that have been dropped + data.river_status_state() + .output_statuses + .retain(|status| status.upgrade().is_some()); + + if let Some(status) = data.river_status_state().get_output_status(status) { + match event { + Event::FocusedTags { tags } => data.focused_tags_updated(conn, qh, &status, tags), + Event::UrgentTags { tags } => data.urgent_tags_updated(conn, qh, &status, tags), + Event::ViewTags { tags } => { + let tags = tags + .chunks_exact(4) + .map(|bytes| u32::from_ne_bytes(bytes.try_into().unwrap())) + .collect(); + data.views_tags_updated(conn, qh, &status, tags); + } + } + } + } +} + +pub mod protocol { + #![allow(non_upper_case_globals)] + + use smithay_client_toolkit::reexports::client as wayland_client; + use smithay_client_toolkit::reexports::client::protocol::*; + + pub mod __interfaces { + use smithay_client_toolkit::reexports::client::protocol::__interfaces::*; + wayland_scanner::generate_interfaces!("protocols/river-status-unstable-v1.xml"); + } + use self::__interfaces::*; + + wayland_scanner::generate_client_code!("protocols/river-status-unstable-v1.xml"); +} diff --git a/src/river_protocols/status/dispatch.rs b/src/river_protocols/status/dispatch.rs deleted file mode 100644 index 65d6e0c..0000000 --- a/src/river_protocols/status/dispatch.rs +++ /dev/null @@ -1,92 +0,0 @@ -use super::protocol::{zriver_output_status_v1, zriver_status_manager_v1}; -use wayland_client::{Connection, Dispatch, QueueHandle}; - -use smithay_client_toolkit::{ - error::GlobalError, - globals::{GlobalData, ProvidesBoundGlobal}, - registry::{ProvidesRegistryState, RegistryHandler}, -}; - -use super::{RiverStatusData, RiverStatusHandler, RiverStatusState}; - -impl RegistryHandler for RiverStatusState -where - D: Dispatch - + RiverStatusHandler - + ProvidesRegistryState - + 'static, -{ - fn ready(data: &mut D, _conn: &Connection, qh: &QueueHandle) { - data.river_status_state().status_manager = - data.registry().bind_one(qh, 1..=2, GlobalData).into(); - } -} - -impl ProvidesBoundGlobal for RiverStatusState { - fn bound_global(&self) -> Result { - self.status_manager.get().cloned() - } -} - -impl ProvidesBoundGlobal for RiverStatusState { - fn bound_global(&self) -> Result { - self.status_manager.get().cloned() - } -} - -impl Dispatch - for RiverStatusState -where - D: Dispatch - + RiverStatusHandler - + 'static, -{ - fn event( - _: &mut D, - _: &zriver_status_manager_v1::ZriverStatusManagerV1, - _: zriver_status_manager_v1::Event, - _: &GlobalData, - _: &Connection, - _: &QueueHandle, - ) { - unreachable!("zriver_status_manager_v1 has no events") - } -} - -impl Dispatch - for RiverStatusState -where - D: Dispatch - + RiverStatusHandler - + 'static, -{ - fn event( - data: &mut D, - status: &zriver_output_status_v1::ZriverOutputStatusV1, - event: zriver_output_status_v1::Event, - _udata: &RiverStatusData, - conn: &Connection, - qh: &QueueHandle, - ) { - use zriver_output_status_v1::Event; - - // Remove any statuses that have been dropped - data.river_status_state() - .output_statuses - .retain(|status| status.upgrade().is_some()); - - if let Some(status) = data.river_status_state().get_output_status(status) { - match event { - Event::FocusedTags { tags } => data.focused_tags_updated(conn, qh, &status, tags), - Event::UrgentTags { tags } => data.urgent_tags_updated(conn, qh, &status, tags), - Event::ViewTags { tags } => { - let tags = tags - .chunks_exact(4) - .map(|bytes| u32::from_ne_bytes(bytes.try_into().unwrap())) - .collect(); - data.views_tags_updated(conn, qh, &status, tags); - } - } - } - } -} diff --git a/src/state.rs b/src/state.rs index 3d5b2d4..ed6c3d1 100644 --- a/src/state.rs +++ b/src/state.rs @@ -12,13 +12,16 @@ use smithay_client_toolkit::{ registry::{ProvidesRegistryState, RegistryState}, registry_handlers, seat::{ - pointer::{PointerEvent, PointerEventKind, PointerHandler}, + pointer::{PointerEvent, PointerEventKind, PointerHandler, ThemeSpec, ThemedPointer}, Capability, SeatHandler, SeatState, }, - shell::layer::{Anchor, Layer, LayerHandler, LayerState, LayerSurface, LayerSurfaceConfigure}, + shell::layer::{ + Anchor, Layer, LayerShell, LayerShellHandler, LayerSurface, LayerSurfaceConfigure, + }, shm::{ShmHandler, ShmState}, }; use tokio::io::unix::AsyncFdReadyGuard; +use wayland_client::globals::GlobalList; use crate::{ bar::Bar, @@ -40,9 +43,9 @@ pub struct State { seat_state: SeatState, output_state: OutputState, compositor_state: CompositorState, - layer_state: LayerState, - river_status_state: RiverStatusState, - river_control_state: RiverControlState, + layer_state: LayerShell, + river_status_state: Option, + river_control_state: Option, seats: Vec, bars: Vec, @@ -52,13 +55,17 @@ pub struct State { struct Seat { seat: wl_seat::WlSeat, pointer: wl_pointer::WlPointer, + themed_pointer: ThemedPointer, + pointer_surface: wl_surface::WlSurface, finger_scroll: f64, } impl State { - pub fn new(conn: &Connection, event_queue: &mut EventQueue) -> Self { + pub fn new(event_queue: &mut EventQueue, globals: &GlobalList) -> Self { let mut error = Ok(()); + let qh = event_queue.handle(); + let config = Config::new() .map_err(|e| error = Err(e)) .unwrap_or_default(); @@ -73,19 +80,19 @@ impl State { }; let mut this = Self { - registry_state: RegistryState::new(conn, &event_queue.handle()), - seat_state: SeatState::new(), - output_state: OutputState::new(), - compositor_state: CompositorState::new(), - layer_state: LayerState::new(), - river_status_state: RiverStatusState::new(), - river_control_state: RiverControlState::new(), + registry_state: RegistryState::new(globals), + seat_state: SeatState::new(globals, &qh), + output_state: OutputState::new(globals, &qh), + compositor_state: CompositorState::bind(globals, &qh).unwrap(), + layer_state: LayerShell::bind(globals, &qh).unwrap(), + river_status_state: RiverStatusState::new(globals, &qh).ok(), + river_control_state: RiverControlState::new(globals, &qh).ok(), seats: Vec::new(), bars: Vec::new(), shared_state: SharedState { qh: event_queue.handle(), - shm_state: ShmState::new(), + shm_state: ShmState::bind(globals, &qh).unwrap(), pool: None, config, status_cmd, @@ -140,10 +147,6 @@ impl State { } impl CompositorHandler for State { - fn compositor_state(&mut self) -> &mut CompositorState { - &mut self.compositor_state - } - fn scale_factor_changed( &mut self, _conn: &Connection, @@ -191,7 +194,10 @@ impl OutputHandler for State { .namespace("i3bar-river") .map(qh, &self.layer_state, surface, Layer::Top) .expect("layer surface creation"); - let river_output_status = self.river_status_state.new_output_status(qh, &output).ok(); + let river_output_status = self + .river_status_state + .as_mut() + .map(|s| s.new_output_status(qh, &output)); self.bars.push(Bar { configured: false, width: 0, @@ -224,11 +230,7 @@ impl OutputHandler for State { } } -impl LayerHandler for State { - fn layer_state(&mut self) -> &mut LayerState { - &mut self.layer_state - } - +impl LayerShellHandler for State { fn closed(&mut self, _conn: &Connection, _qh: &QueueHandle, layer: &LayerSurface) { self.bars.retain(|b| &b.layer != layer) } @@ -264,13 +266,15 @@ impl SeatHandler for State { capability: Capability, ) { if capability == Capability::Pointer { - let pointer = self + let (pointer, themed_pointer) = self .seat_state - .get_pointer(qh, &seat) + .get_pointer_with_theme(qh, &seat, ThemeSpec::System, 1) .expect("Failed to create pointer"); self.seats.push(Seat { seat, pointer, + themed_pointer, + pointer_surface: self.compositor_state.create_surface(qh).unwrap(), // TODO: make a PR to remove this unwrap finger_scroll: 0.0, }); } @@ -294,7 +298,7 @@ impl SeatHandler for State { impl PointerHandler for State { fn pointer_frame( &mut self, - _conn: &Connection, + conn: &Connection, _qh: &QueueHandle, pointer: &wl_pointer::WlPointer, events: &[PointerEvent], @@ -312,7 +316,14 @@ impl PointerHandler for State { { match event.kind { PointerEventKind::Enter { .. } => { - // TODO: set_cursor() + seat.themed_pointer + .set_cursor( + conn, + "default", + self.shared_state.shm_state.wl_shm(), + &seat.pointer_surface, + ) + .unwrap(); } PointerEventKind::Press { button, .. } => { bar.click( @@ -376,7 +387,7 @@ impl ShmHandler for State { impl RiverStatusHandler for State { fn river_status_state(&mut self) -> &mut RiverStatusState { - &mut self.river_status_state + self.river_status_state.as_mut().unwrap() } fn focused_tags_updated( @@ -430,7 +441,7 @@ impl RiverStatusHandler for State { impl RiverControlHandler for State { fn river_control_state(&mut self) -> &mut RiverControlState { - &mut self.river_control_state + self.river_control_state.as_mut().unwrap() } fn command_failure(&mut self, _: &Connection, _: &QueueHandle, message: String) { @@ -456,15 +467,7 @@ impl ProvidesRegistryState for State { fn registry(&mut self) -> &mut RegistryState { &mut self.registry_state } - registry_handlers![ - CompositorState, - OutputState, - ShmState, - SeatState, - LayerState, - RiverStatusState, - RiverControlState, - ]; + registry_handlers![OutputState,]; } #[derive(Debug)] diff --git a/src/text.rs b/src/text.rs index 7a3b7fc..9b27a11 100644 --- a/src/text.rs +++ b/src/text.rs @@ -49,7 +49,7 @@ pub struct ComputedText { impl ComputedText { pub fn new(text: &str, mut attr: Attributes, context: &cairo::Context) -> Self { - let layout = pangocairo::create_layout(context).unwrap(); + let layout = pangocairo::create_layout(context); layout.set_font_description(Some(attr.font)); if attr.markup { layout.set_markup(text); -- cgit v1.3.1