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/config.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index 66b8c8a..bd7b91c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,8 +7,8 @@ use std::fmt; use std::fs::read_to_string; use std::ops::Deref; -#[derive(Deserialize)] -#[serde(default)] +#[derive(Deserialize, Debug)] +#[serde(deny_unknown_fields, default)] pub struct Config { // colors pub background: Color, @@ -79,6 +79,7 @@ impl Config { } } +#[derive(Debug)] pub struct Font(pub FontDescription); impl Font { -- 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/config.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/config.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