From 3d507acb42554b2551024ee3ca8490c203a1a9f8 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sun, 29 Jun 2025 10:32:13 +0200 Subject: pkgs/river-mk-keymap: Improve with key-chord support and which-key interface --- .../ri/river-mk-keymap/src/wayland/dispatches.rs | 214 +++++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100644 pkgs/by-name/ri/river-mk-keymap/src/wayland/dispatches.rs (limited to 'pkgs/by-name/ri/river-mk-keymap/src/wayland/dispatches.rs') diff --git a/pkgs/by-name/ri/river-mk-keymap/src/wayland/dispatches.rs b/pkgs/by-name/ri/river-mk-keymap/src/wayland/dispatches.rs new file mode 100644 index 00000000..c6e04fdf --- /dev/null +++ b/pkgs/by-name/ri/river-mk-keymap/src/wayland/dispatches.rs @@ -0,0 +1,214 @@ +use std::num::NonZero; + +use keymaps::key_repr::Key; +use wayland_client::{ + globals::GlobalListContents, + protocol::{ + wl_buffer::WlBuffer, wl_compositor::WlCompositor, wl_registry, wl_seat::WlSeat, + wl_shm::WlShm, wl_shm_pool::WlShmPool, wl_surface::WlSurface, + }, + Connection, Dispatch, QueueHandle, +}; + +use wayland_protocols_wlr::layer_shell::v1::client::{ + zwlr_layer_shell_v1::ZwlrLayerShellV1, + zwlr_layer_surface_v1::{self, ZwlrLayerSurfaceV1}, +}; + +use crate::wayland::{ + ansi, render, + river::protocols::river_protocols::{ + zriver_seat_status_v1::{self, ZriverSeatStatusV1}, + zriver_status_manager_v1::ZriverStatusManagerV1, + }, + AppData, +}; + +impl Dispatch for AppData { + fn event( + state: &mut Self, + _: &ZriverSeatStatusV1, + event: ::Event, + (): &(), + _: &Connection, + _: &QueueHandle, + ) { + if let zriver_seat_status_v1::Event::Mode { name } = event { + let new_text = { + if name == "normal" { + // We are back at the normal mode. + // There is no need to display the mappings anymore, exit. + state.should_exit = true; + return; + } else if let Ok(keys) = Key::parse_multiple(&name) { + if let Some(val) = state.config.get(&keys) { + ansi::parse(val.to_string().as_str()) + } else { + // Mode name not know, do nothing. + return; + } + } else { + // Mode name not valid, do nothing. + return; + } + }; + + let px_height; + (state.pixel_data, (state.max_px_width, px_height)) = + render::text(&new_text).expect("Works?"); + + // We add the `5` here, so that our letters don't stop exactly at the border. + state + .window + .0 + .set_size(state.max_px_width + 5, px_height + 5); + state.window.1.commit(); + + if state.configured { + state.draw(); + } + } + } +} + +impl Dispatch for AppData { + fn event( + state: &mut Self, + proxy: &ZwlrLayerSurfaceV1, + event: ::Event, + (): &(), + _: &Connection, + _: &QueueHandle, + ) { + match event { + zwlr_layer_surface_v1::Event::Configure { + serial, + width, + height, + } => { + state.buffer = None; + + proxy.ack_configure(serial); + + state.width = NonZero::new(width).map_or_else(|| state.width, NonZero::get); + state.height = NonZero::new(height).map_or_else(|| state.height, NonZero::get); + + state.draw(); + + state.configured = true; + } + zwlr_layer_surface_v1::Event::Closed => { + state.should_exit = true; + } + _ => (), + } + } +} + +impl Dispatch for AppData { + fn event( + _: &mut AppData, + _: &wl_registry::WlRegistry, + _: wl_registry::Event, + _: &GlobalListContents, + _: &Connection, + _: &QueueHandle, + ) { + } +} + +impl Dispatch for AppData { + fn event( + _: &mut Self, + _: &WlShmPool, + _: ::Event, + (): &(), + _: &Connection, + _: &QueueHandle, + ) { + } +} + +impl Dispatch for AppData { + fn event( + _: &mut Self, + _: &WlShm, + _: ::Event, + (): &(), + _: &Connection, + _: &QueueHandle, + ) { + } +} + +impl Dispatch for AppData { + fn event( + _: &mut Self, + _: &WlSurface, + _: ::Event, + (): &(), + _: &Connection, + _: &QueueHandle, + ) { + } +} + +impl Dispatch for AppData { + fn event( + _: &mut Self, + _: &WlCompositor, + _: ::Event, + (): &(), + _: &Connection, + _: &QueueHandle, + ) { + } +} + +impl Dispatch for AppData { + fn event( + _: &mut Self, + _: &WlSeat, + _: ::Event, + (): &(), + _: &Connection, + _: &QueueHandle, + ) { + } +} + +impl Dispatch for AppData { + fn event( + _: &mut Self, + _: &WlBuffer, + _: ::Event, + (): &(), + _: &Connection, + _: &QueueHandle, + ) { + } +} + +impl Dispatch for AppData { + fn event( + _: &mut Self, + _: &ZriverStatusManagerV1, + _: ::Event, + (): &(), + _: &Connection, + _: &QueueHandle, + ) { + } +} + +impl Dispatch for AppData { + fn event( + _: &mut Self, + _: &ZwlrLayerShellV1, + _: ::Event, + (): &(), + _: &Connection, + _: &QueueHandle, + ) { + } +} -- cgit 1.4.1