Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Clipboard button #58

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
### Added

- Added a clipboard button

### Fixed

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ position: Top # optional, default Top
# App lancher commanda, it will be used to open the launcher,
# without a value the related button will not appear
appLauncherCmd: "~/.config/rofi/launcher.sh" # optional, default None
# Clipboard command, it will be used to open the clipboard menu,
# without a value the related button will not appear
clipboardCmd: "cliphist-rofi-img | wl-copy" # optional, default None
# Update module configuration.
# Without a value the related button will not appear.
updates: # optional, default None
Expand Down
15 changes: 14 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
get_log_spec,
menu::{menu_wrapper, Menu, MenuPosition, MenuType},
modules::{
self, clock::Clock, launcher, privacy::PrivacyMessage, settings::Settings,
self, clipboard, clock::Clock, launcher, privacy::PrivacyMessage, settings::Settings,
system_info::SystemInfo, title::Title, updates::Updates, workspaces::Workspaces,
},
services::{privacy::PrivacyService, ReadOnlyService, ServiceEvent},
Expand Down Expand Up @@ -41,6 +41,7 @@ pub enum Message {
ConfigChanged(Box<Config>),
CloseMenu,
OpenLauncher,
OpenClipboard,
Updates(modules::updates::Message),
Workspaces(modules::workspaces::Message),
Title(modules::title::Message),
Expand Down Expand Up @@ -117,6 +118,12 @@ impl Application for App {
}
Command::none()
}
Message::OpenClipboard => {
if let Some(clipboard_cmd) = self.config.clipboard_cmd.as_ref() {
utils::launcher::execute_command(clipboard_cmd.to_string());
}
Command::none()
}
Message::Workspaces(msg) => {
self.workspaces.update(msg);

Expand Down Expand Up @@ -185,6 +192,12 @@ impl Application for App {
.as_ref()
.map(|_| launcher::launcher()),
)
.push_maybe(
self.config
.clipboard_cmd
.as_ref()
.map(|_| clipboard::clipboard()),
)
.push_maybe(
self.config
.updates
Expand Down
2 changes: 2 additions & 0 deletions src/components/icons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub enum Icons {
#[default]
None,
Launcher,
Clipboard,
Refresh,
NoUpdatesAvailable,
UpdatesAvailable,
Expand Down Expand Up @@ -71,6 +72,7 @@ impl From<Icons> for &'static str {
match icon {
Icons::None => "",
Icons::Launcher => "󱗼",
Icons::Clipboard => "󰅌",
Icons::Refresh => "󰑐",
Icons::NoUpdatesAvailable => "󰗠",
Icons::UpdatesAvailable => "󰳛",
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ pub struct Config {
#[serde(default)]
pub position: Position,
pub app_launcher_cmd: Option<String>,
pub clipboard_cmd: Option<String>,
#[serde(default = "default_truncate_title_after_length")]
pub truncate_title_after_length: u32,
#[serde(deserialize_with = "try_default")]
Expand Down Expand Up @@ -305,6 +306,7 @@ impl Default for Config {
log_level: default_log_level(),
position: Position::Top,
app_launcher_cmd: None,
clipboard_cmd: None,
truncate_title_after_length: default_truncate_title_after_length(),
updates: None,
system: SystemModuleConfig::default(),
Expand Down
14 changes: 14 additions & 0 deletions src/modules/clipboard.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use crate::{
app::Message,
components::icons::{icon, Icons},
style::HeaderButtonStyle,
};
use iced::{theme, widget::button, Element};

pub fn clipboard<'a>() -> Element<'a, Message> {
button(icon(Icons::Clipboard))
.padding([2, 7])
.on_press(Message::OpenClipboard)
.style(theme::Button::custom(HeaderButtonStyle::Full))
.into()
}
1 change: 1 addition & 0 deletions src/modules/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod clipboard;
pub mod clock;
pub mod launcher;
pub mod privacy;
Expand Down