use crate::channels::{AsyncSenderExt, BroadcastReceiverExt}; use crate::clients::clipboard::{self, ClipboardEvent}; use crate::clients::wayland::{ClipboardItem, ClipboardValue}; use crate::config::{CommonConfig, LayoutConfig, TruncateMode}; use crate::gtk_helpers::IronbarGtkExt; use crate::gtk_helpers::IronbarLabelExt; use crate::image::IconButton; use crate::modules::{ Module, ModuleInfo, ModuleParts, ModulePopup, ModuleUpdateEvent, PopupButton, WidgetContext, }; use crate::{module_impl, spawn}; use glib::Propagation; use gtk::gdk_pixbuf::Pixbuf; use gtk::gio::{Cancellable, MemoryInputStream}; use gtk::prelude::*; use gtk::{Button, EventBox, Image, Label, Orientation, RadioButton, Widget}; use serde::Deserialize; use std::collections::HashMap; use std::ops::Deref; use tokio::sync::mpsc; use tracing::{debug, error}; #[derive(Debug, Deserialize, Clone)] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub struct ClipboardModule { /// The icon to show on the bar widget button. /// Supports [image](images) icons. /// /// **Default**: `󰨸` #[serde(default = "default_icon")] icon: String, /// The size to render the icon at. /// Note this only applies to image-type icons. /// /// **Default**: `32` #[serde(default = "default_icon_size")] icon_size: i32, /// The maximum number of items to keep in the history, /// and to show in the popup. /// /// **Default**: `10` #[serde(default = "default_max_items")] max_items: usize, // -- Common -- /// See [truncate options](module-level-options#truncate-mode). /// /// **Default**: `null` truncate: Option, /// See [layout options](module-level-options#layout) #[serde(default, flatten)] layout: LayoutConfig, /// See [common options](module-level-options#common-options). #[serde(flatten)] pub common: Option, } fn default_icon() -> String { String::from("󰨸") } const fn default_icon_size() -> i32 { 32 } const fn default_max_items() -> usize { 10 } #[derive(Debug, Clone)] pub enum ControllerEvent { Add(usize, ClipboardItem), Remove(usize), Activate(usize), Deactivate, } #[derive(Debug, Clone)] pub enum UIEvent { Copy(usize), Remove(usize), } impl Module