diff options
| author | MaxVerevkin <maxxverrr@gmail.com> | 2023-08-28 17:41:25 +0300 |
|---|---|---|
| committer | MaxVerevkin <maxxverrr@gmail.com> | 2023-08-29 16:10:56 +0300 |
| commit | bc20894d3758bdfefc82b2133b013e8c23dbfad1 (patch) | |
| tree | 9b12456fb062c8f2dc36612780fd73a07b7fc828 | |
| parent | ff8c5e243c13e52a39c6335031e741ac1dac6fd3 (diff) | |
| download | i3bar-mango-bc20894d3758bdfefc82b2133b013e8c23dbfad1.tar.gz | |
update wayrs
| -rw-r--r-- | Cargo.lock | 55 | ||||
| -rw-r--r-- | Cargo.toml | 6 | ||||
| -rw-r--r-- | src/bar.rs | 56 | ||||
| -rw-r--r-- | src/output.rs | 38 | ||||
| -rw-r--r-- | src/state.rs | 37 | ||||
| -rw-r--r-- | src/wm_info_provider/ext_workspace_unstable.rs | 60 | ||||
| -rw-r--r-- | src/wm_info_provider/river.rs | 51 |
7 files changed, 146 insertions, 157 deletions
@@ -27,12 +27,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] +name = "bitflags" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" + +[[package]] name = "cairo-rs" version = "0.17.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab3603c4028a5e368d09b51c8b624b9a46edcd7c3778284077a6125af73c9f0a" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cairo-sys-rs", "glib", "libc", @@ -181,7 +187,7 @@ version = "0.17.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6973e92937cf98689b6a054a9e56c657ed4ff76de925e36fc331a15f0c5d30a" dependencies = [ - "bitflags", + "bitflags 1.3.2", "futures-channel", "futures-core", "futures-io", @@ -214,7 +220,7 @@ version = "0.17.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3fad45ba8d4d2cea612b432717e834f48031cd8853c8aaf43b2c79fec8d144b" dependencies = [ - "bitflags", + "bitflags 1.3.2", "futures-channel", "futures-core", "futures-executor", @@ -286,7 +292,7 @@ dependencies = [ "anyhow", "clap", "memchr", - "nix", + "nix 0.26.2", "pangocairo", "serde", "serde_json", @@ -336,9 +342,9 @@ dependencies = [ [[package]] name = "memoffset" -version = "0.7.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" dependencies = [ "autocfg", ] @@ -355,14 +361,25 @@ version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if", "libc", - "memoffset", "static_assertions", ] [[package]] +name = "nix" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" +dependencies = [ + "bitflags 2.4.0", + "cfg-if", + "libc", + "memoffset", +] + +[[package]] name = "nom" version = "7.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -384,7 +401,7 @@ version = "0.17.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35be456fc620e61f62dff7ff70fbd54dcbaf0a4b920c0f16de1107c47d921d48" dependencies = [ - "bitflags", + "bitflags 1.3.2", "gio", "glib", "libc", @@ -410,7 +427,7 @@ version = "0.17.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86bf29cb1c2e73817944f66011fb12135e1c6d268e8e4c5cfc689101c25822cf" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cairo-rs", "glib", "libc", @@ -720,29 +737,29 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "wayrs-client" -version = "0.11.1" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b633c5848f93979d10a422660e94b34cb18aae4cd74b837af1fc00cf16ea0a31" +checksum = "e4acba2f832601f9f57e1ff86347af792e6dcb19f5b6155328faec87257bfa76" dependencies = [ - "nix", + "nix 0.27.1", "thiserror", "wayrs-scanner", ] [[package]] name = "wayrs-protocols" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9df58f7f62f777b2ddcac5a3c3bfc236341c7cd45bfbf24358d2635effb16302" +checksum = "089602f245f82e06ca6ff90bb465f7f6c37dbc34561f518926ea0a44f0d53664" dependencies = [ "wayrs-client", ] [[package]] name = "wayrs-scanner" -version = "0.11.1" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13b080e43fe1ce87ed3305040ceb8fd78b800e1c2da17a16d8d80eeea9a49fda" +checksum = "f9dbcde8afbc822b0129b357a9855d1c80cdf334fc189b89064f6bbb6063efe1" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -753,9 +770,9 @@ dependencies = [ [[package]] name = "wayrs-utils" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ee6a15e57e5d5fcfad69237366dd0a51928f4078c1305dc59366dcb44170fba" +checksum = "42800abb4668c3976f4c60a7a82c4ad0b91da23fa101f93ab0a28a1b740c2292" dependencies = [ "memmap2", "shmemfdrs", @@ -20,9 +20,9 @@ serde_json = "1" serde = { version = "1", features = ["derive"] } signal-hook = { version = "0.3", default-features = false } toml = { version = "0.7", default-features = false, features = ["parse"] } -wayrs-client = "0.11" -wayrs-protocols = { version = "0.11", features = ["wlr-layer-shell-unstable-v1", "viewporter", "fractional-scale-v1"] } -wayrs-utils = { version = "0.9", features = ["cursor", "shm_alloc", "seats"] } +wayrs-client = "0.12" +wayrs-protocols = { version = "0.12", features = ["wlr-layer-shell-unstable-v1", "viewporter", "fractional-scale-v1"] } +wayrs-utils = { version = "0.10", features = ["cursor", "shm_alloc", "seats"] } clap = { version = "4.3.23", default-features = false, features = ["derive", "std", "help"] } [profile.release] @@ -1,6 +1,6 @@ use pangocairo::cairo; -use wayrs_client::Connection; +use wayrs_client::{Connection, EventCtx}; use wayrs_utils::shm_alloc::BufferSpec; use crate::blocks_cache::ComputedBlock; @@ -333,10 +333,15 @@ impl Bar { pub fn request_frame(&mut self, conn: &mut Connection<State>) { if self.mapped && !self.hidden && self.frame_cb.is_none() { - self.frame_cb = Some(self.surface.frame_with_cb(conn, |conn, state, cb, _| { - if let Some(bar) = state.bars.iter_mut().find(|bar| bar.frame_cb == Some(cb)) { + self.frame_cb = Some(self.surface.frame_with_cb(conn, |ctx| { + if let Some(bar) = ctx + .state + .bars + .iter_mut() + .find(|bar| bar.frame_cb == Some(ctx.proxy)) + { bar.frame_cb = None; - bar.frame(conn, &mut state.shared_state); + bar.frame(ctx.conn, &mut ctx.state.shared_state); } })); self.surface.commit(conn); @@ -529,60 +534,53 @@ pub fn compute_tag_label(label: &str, config: &Config) -> ComputedText { ) } -fn layer_surface_cb( - conn: &mut Connection<State>, - state: &mut State, - layer_surface: zwlr_layer_surface_v1::ZwlrLayerSurfaceV1, - event: zwlr_layer_surface_v1::Event, -) { - match event { +fn layer_surface_cb(ctx: EventCtx<State, ZwlrLayerSurfaceV1>) { + match ctx.event { zwlr_layer_surface_v1::Event::Configure(args) => { - let bar = state + let bar = ctx + .state .bars .iter_mut() - .find(|bar| bar.layer_surface == layer_surface) + .find(|bar| bar.layer_surface == ctx.proxy) .unwrap(); if bar.hidden { return; } assert_ne!(args.width, 0); bar.width = args.width; - bar.layer_surface.ack_configure(conn, args.serial); + bar.layer_surface.ack_configure(ctx.conn, args.serial); if bar.mapped { - bar.request_frame(conn); + bar.request_frame(ctx.conn); } else { bar.mapped = true; - bar.frame(conn, &mut state.shared_state); + bar.frame(ctx.conn, &mut ctx.state.shared_state); } } zwlr_layer_surface_v1::Event::Closed => { - let bar_index = state + let bar_index = ctx + .state .bars .iter() - .position(|bar| bar.layer_surface == layer_surface) + .position(|bar| bar.layer_surface == ctx.proxy) .unwrap(); - state.drop_bar(conn, bar_index); + ctx.state.drop_bar(ctx.conn, bar_index); } _ => (), } } -fn fractional_scale_cb( - conn: &mut Connection<State>, - state: &mut State, - fractional_scale: WpFractionalScaleV1, - event: wp_fractional_scale_v1::Event, -) { - let wp_fractional_scale_v1::Event::PreferredScale(scale120) = event else { +fn fractional_scale_cb(ctx: EventCtx<State, WpFractionalScaleV1>) { + let wp_fractional_scale_v1::Event::PreferredScale(scale120) = ctx.event else { return; }; - let bar = state + let bar = ctx + .state .bars .iter_mut() - .find(|b| b.fractional_scale == Some(fractional_scale)) + .find(|b| b.fractional_scale == Some(ctx.proxy)) .unwrap(); if bar.scale120 != Some(scale120) { bar.scale120 = Some(scale120); - bar.request_frame(conn); + bar.request_frame(ctx.conn); } } diff --git a/src/output.rs b/src/output.rs index be9a29a..7c492ed 100644 --- a/src/output.rs +++ b/src/output.rs @@ -1,6 +1,6 @@ use wayrs_client::global::{Global, GlobalExt}; -use wayrs_client::protocol::*; use wayrs_client::Connection; +use wayrs_client::{protocol::*, EventCtx}; use crate::state::State; @@ -27,26 +27,36 @@ impl Output { } } -fn wl_output_cb( - conn: &mut Connection<State>, - state: &mut State, - output: WlOutput, - event: wl_output::Event, -) { - match event { +fn wl_output_cb(ctx: EventCtx<State, WlOutput>) { + match ctx.event { wl_output::Event::Name(name) => { - let i = state + let i = ctx + .state .pending_outputs .iter() - .position(|o| o.wl == output) + .position(|o| o.wl == ctx.proxy) .unwrap(); - let output = state.pending_outputs.swap_remove(i); - state.register_output(conn, output, name.to_str().expect("invalid output name")); + let output = ctx.state.pending_outputs.swap_remove(i); + ctx.state.register_output( + ctx.conn, + output, + name.to_str().expect("invalid output name"), + ); } wl_output::Event::Scale(scale) => { - if let Some(bar) = state.bars.iter_mut().find(|bar| bar.output.wl == output) { + if let Some(bar) = ctx + .state + .bars + .iter_mut() + .find(|bar| bar.output.wl == ctx.proxy) + { bar.output.scale = scale as u32; - } else if let Some(output) = state.pending_outputs.iter_mut().find(|o| o.wl == output) { + } else if let Some(output) = ctx + .state + .pending_outputs + .iter_mut() + .find(|o| o.wl == ctx.proxy) + { output.scale = scale as u32; } } diff --git a/src/state.rs b/src/state.rs index ba2c3e6..4b3a0ca 100644 --- a/src/state.rs +++ b/src/state.rs @@ -10,6 +10,7 @@ use std::path::Path; use wayrs_client::global::{GlobalExt, Globals, GlobalsExt}; use wayrs_client::proxy::Proxy; use wayrs_client::Connection; +use wayrs_client::EventCtx; use wayrs_utils::cursor::{CursorImage, CursorShape, CursorTheme, ThemedPointer}; use wayrs_utils::seats::{SeatHandler, Seats}; use wayrs_utils::shm_alloc::ShmAlloc; @@ -284,25 +285,22 @@ fn wl_registry_cb(conn: &mut Connection<State>, state: &mut State, event: &wl_re } } -fn wl_pointer_cb( - conn: &mut Connection<State>, - state: &mut State, - pointer: WlPointer, - event: wl_pointer::Event, -) { - let pointer = state +fn wl_pointer_cb(ctx: EventCtx<State, WlPointer>) { + let pointer = ctx + .state .pointers .iter_mut() - .find(|p| p.pointer == pointer) + .find(|p| p.pointer == ctx.proxy) .unwrap(); use wl_pointer::Event; - match event { + match ctx.event { Event::Frame => { let btn = pointer.pending_button.take(); let scroll = pointer.scroll_frame.finalize(); if let Some(surface) = pointer.current_surface { - let bar = state + let bar = ctx + .state .bars .iter_mut() .find(|bar| bar.surface == surface) @@ -310,8 +308,8 @@ fn wl_pointer_cb( if let Some(btn) = btn { bar.click( - conn, - &mut state.shared_state, + ctx.conn, + &mut ctx.state.shared_state, btn, pointer.seat, pointer.x, @@ -320,7 +318,7 @@ fn wl_pointer_cb( .unwrap(); } - if scroll.is_finger && state.shared_state.config.invert_touchpad_scrolling { + if scroll.is_finger && ctx.state.shared_state.config.invert_touchpad_scrolling { pointer.pending_scroll -= scroll.absolute; } else { pointer.pending_scroll += scroll.absolute; @@ -342,8 +340,8 @@ fn wl_pointer_cb( if let Some(btn) = btn { bar.click( - conn, - &mut state.shared_state, + ctx.conn, + &mut ctx.state.shared_state, btn, pointer.seat, pointer.x, @@ -354,7 +352,8 @@ fn wl_pointer_cb( } } Event::Enter(args) => { - let bar = state + let bar = ctx + .state .bars .iter() .find(|bar| bar.surface.id() == args.surface) @@ -362,10 +361,10 @@ fn wl_pointer_cb( pointer.current_surface = Some(bar.surface); pointer.x = args.surface_x.as_f64(); pointer.y = args.surface_y.as_f64(); - if let Some(default_cursor) = &state.default_cursor { + if let Some(default_cursor) = &ctx.state.default_cursor { pointer.themed_pointer.set_cursor( - conn, - &mut state.shared_state.shm, + ctx.conn, + &mut ctx.state.shared_state.shm, default_cursor, bar.output.scale, args.serial, diff --git a/src/wm_info_provider/ext_workspace_unstable.rs b/src/wm_info_provider/ext_workspace_unstable.rs index 203cba9..c1d7b98 100644 --- a/src/wm_info_provider/ext_workspace_unstable.rs +++ b/src/wm_info_provider/ext_workspace_unstable.rs @@ -1,7 +1,7 @@ -use wayrs_client::global::*; use wayrs_client::object::ObjectId; use wayrs_client::proxy::Proxy; use wayrs_client::Connection; +use wayrs_client::{global::*, EventCtx}; use super::*; use crate::state::State; @@ -30,7 +30,7 @@ struct Workspace { impl ExtWorkspaceUnstable { pub fn bind(conn: &mut Connection<State>, globals: &Globals) -> Option<Self> { Some(Self { - manager: globals.bind_with_cb(conn, 1..=1, manager_cb).ok()?, + manager: globals.bind_with_cb(conn, 1, manager_cb).ok()?, groups: Vec::new(), known_outputs: Vec::new(), }) @@ -112,48 +112,38 @@ impl WmInfoProvider for ExtWorkspaceUnstable { } } -fn manager_cb( - conn: &mut Connection<State>, - state: &mut State, - _: ZextWorkspaceManagerV1, - event: zext_workspace_manager_v1::Event, -) { - let ewu = state.shared_state.get_ewu().unwrap(); +fn manager_cb(ctx: EventCtx<State, ZextWorkspaceManagerV1>) { + let ewu = ctx.state.shared_state.get_ewu().unwrap(); - match event { + match ctx.event { zext_workspace_manager_v1::Event::WorkspaceGroup(group_handle) => { - conn.set_callback_for(group_handle, group_cb); + ctx.conn.set_callback_for(group_handle, group_cb); ewu.groups.push(Group { group_handle, workspaces: Vec::new(), outputs: Vec::new(), }); } - zext_workspace_manager_v1::Event::Done => state.tags_updated(conn, None), + zext_workspace_manager_v1::Event::Done => ctx.state.tags_updated(ctx.conn, None), zext_workspace_manager_v1::Event::Finished => unreachable!(), } } -fn group_cb( - conn: &mut Connection<State>, - state: &mut State, - group_handle: ZextWorkspaceGroupHandleV1, - event: zext_workspace_group_handle_v1::Event, -) { - let ewu = state.shared_state.get_ewu().unwrap(); +fn group_cb(ctx: EventCtx<State, ZextWorkspaceGroupHandleV1>) { + let ewu = ctx.state.shared_state.get_ewu().unwrap(); let group = ewu .groups .iter_mut() - .find(|g| g.group_handle == group_handle) + .find(|g| g.group_handle == ctx.proxy) .unwrap(); - match event { + match ctx.event { zext_workspace_group_handle_v1::Event::OutputEnter(output) => { group.outputs.push(output); } zext_workspace_group_handle_v1::Event::OutputLeave(_) => todo!(), zext_workspace_group_handle_v1::Event::Workspace(workspace_handle) => { - conn.set_callback_for(workspace_handle, workspace_cb); + ctx.conn.set_callback_for(workspace_handle, workspace_cb); group.workspaces.push(Workspace { workspace_handle, name: None, @@ -167,29 +157,21 @@ fn group_cb( } } -fn workspace_cb( - conn: &mut Connection<State>, - state: &mut State, - workspace_handle: ZextWorkspaceHandleV1, - event: zext_workspace_handle_v1::Event, -) { - let ewu = state.shared_state.get_ewu().unwrap(); +fn workspace_cb(ctx: EventCtx<State, ZextWorkspaceHandleV1>) { + let ewu = ctx.state.shared_state.get_ewu().unwrap(); + let group = ewu .groups .iter_mut() - .find(|g| { - g.workspaces - .iter() - .any(|w| w.workspace_handle == workspace_handle) - }) + .find(|g| g.workspaces.iter().any(|w| w.workspace_handle == ctx.proxy)) .unwrap(); let workspace = group .workspaces .iter_mut() - .find(|w| w.workspace_handle == workspace_handle) + .find(|w| w.workspace_handle == ctx.proxy) .unwrap(); - match event { + match ctx.event { zext_workspace_handle_v1::Event::Name(name) => { workspace.name = Some(name.to_string_lossy().into_owned()); } @@ -206,10 +188,8 @@ fn workspace_cb( } } zext_workspace_handle_v1::Event::Remove => { - group - .workspaces - .retain(|w| w.workspace_handle != workspace_handle); - workspace_handle.destroy(conn); + group.workspaces.retain(|w| w.workspace_handle != ctx.proxy); + ctx.proxy.destroy(ctx.conn); } } } diff --git a/src/wm_info_provider/river.rs b/src/wm_info_provider/river.rs index e9904bd..90c6cd1 100644 --- a/src/wm_info_provider/river.rs +++ b/src/wm_info_provider/river.rs @@ -1,7 +1,7 @@ use std::ffi::CString; -use wayrs_client::global::*; use wayrs_client::{cstr, Connection}; +use wayrs_client::{global::*, EventCtx}; use super::*; use crate::state::State; @@ -38,7 +38,7 @@ impl RiverInfoProvider { let wl_seat: WlSeat = globals.bind(conn, ..).ok()?; // river supports just one seat Some(Self { status_manager, - control: globals.bind(conn, 1..=1).ok()?, + control: globals.bind(conn, 1).ok()?, output_statuses: Vec::new(), max_tag: config.river.max_tag, seat_status: SeatStatus { @@ -127,69 +127,54 @@ impl WmInfoProvider for RiverInfoProvider { } } -fn output_status_cb( - conn: &mut Connection<State>, - state: &mut State, - output_status: ZriverOutputStatusV1, - event: zriver_output_status_v1::Event, -) { - let river = state.shared_state.get_river().unwrap(); +fn output_status_cb(ctx: EventCtx<State, ZriverOutputStatusV1>) { + let river = ctx.state.shared_state.get_river().unwrap(); let status = river .output_statuses .iter_mut() - .find(|s| s.status == output_status) + .find(|s| s.status == ctx.proxy) .unwrap(); let output = status.output; use zriver_output_status_v1::Event; - match event { + match ctx.event { Event::FocusedTags(tags) => { status.focused_tags = tags; - state.tags_updated(conn, Some(output)); + ctx.state.tags_updated(ctx.conn, Some(output)); } Event::ViewTags(tags) => { status.active_tags = tags .chunks_exact(4) .map(|bytes| u32::from_ne_bytes(bytes.try_into().unwrap())) .fold(0, |a, b| a | b); - state.tags_updated(conn, Some(output)); + ctx.state.tags_updated(ctx.conn, Some(output)); } Event::UrgentTags(tags) => { status.urgent_tags = tags; - state.tags_updated(conn, Some(output)); + ctx.state.tags_updated(ctx.conn, Some(output)); } Event::LayoutName(ln) => { status.layout_name = Some(ln.to_string_lossy().into()); - state.layout_name_updated(conn, Some(output)); + ctx.state.layout_name_updated(ctx.conn, Some(output)); } Event::LayoutNameClear => { status.layout_name = None; - state.layout_name_updated(conn, Some(output)); + ctx.state.layout_name_updated(ctx.conn, Some(output)); } } } -fn seat_status_cb( - conn: &mut Connection<State>, - state: &mut State, - _: ZriverSeatStatusV1, - event: zriver_seat_status_v1::Event, -) { - if let zriver_seat_status_v1::Event::Mode(mode) = event { - let river = state.shared_state.get_river().unwrap(); +fn seat_status_cb(ctx: EventCtx<State, ZriverSeatStatusV1>) { + if let zriver_seat_status_v1::Event::Mode(mode) = ctx.event { + let river = ctx.state.shared_state.get_river().unwrap(); let mode = mode.to_string_lossy().into_owned(); river.seat_status.mode = (mode != "normal").then_some(mode); - state.mode_name_updated(conn, None); + ctx.state.mode_name_updated(ctx.conn, None); } } -fn river_command_cb( - conn: &mut Connection<State>, - state: &mut State, - _: ZriverCommandCallbackV1, - event: zriver_command_callback_v1::Event, -) { - if let zriver_command_callback_v1::Event::Failure(msg) = event { - state.set_error(conn, msg.to_string_lossy()) +fn river_command_cb(ctx: EventCtx<State, ZriverCommandCallbackV1>) { + if let zriver_command_callback_v1::Event::Failure(msg) = ctx.event { + ctx.state.set_error(ctx.conn, msg.to_string_lossy()) } } |
