diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index d61ec442..46288334 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -13,6 +13,7 @@ * Add `FlexibleComposeOrder` addon [#318](https://github.com/Riey/kime/issues/318) * Check LANG env in kime-check [#317](https://github.com/Riey/kime/issues/317) * Add `Commit` hotkey, `ConsumeIfProcessed` hotkey result [#315](https://github.com/Riey/kime/issues/315) +* Add white icon [#316](https://github.com/Riey/kime/issues/316) ## 1.1.3 diff --git a/docs/assets/icon.xcf b/docs/assets/icon.xcf new file mode 100644 index 00000000..afea36ab Binary files /dev/null and b/docs/assets/icon.xcf differ diff --git a/res/icons/kime-eng-64x64.png b/res/icons/kime-eng-64x64.png deleted file mode 100644 index 372ef766..00000000 Binary files a/res/icons/kime-eng-64x64.png and /dev/null differ diff --git a/res/icons/kime-eng-black-64x64.png b/res/icons/kime-eng-black-64x64.png new file mode 100644 index 00000000..e37f30d6 Binary files /dev/null and b/res/icons/kime-eng-black-64x64.png differ diff --git a/res/icons/kime-eng-white-64x64.png b/res/icons/kime-eng-white-64x64.png new file mode 100644 index 00000000..37cf3fda Binary files /dev/null and b/res/icons/kime-eng-white-64x64.png differ diff --git a/res/icons/kime-han-64x64.png b/res/icons/kime-han-64x64.png deleted file mode 100644 index 0e116857..00000000 Binary files a/res/icons/kime-han-64x64.png and /dev/null differ diff --git a/res/icons/kime-han-black-64x64.png b/res/icons/kime-han-black-64x64.png new file mode 100644 index 00000000..29948075 Binary files /dev/null and b/res/icons/kime-han-black-64x64.png differ diff --git a/res/icons/kime-han-white-64x64.png b/res/icons/kime-han-white-64x64.png new file mode 100644 index 00000000..c6c4a88c Binary files /dev/null and b/res/icons/kime-han-white-64x64.png differ diff --git a/src/tools/check/src/main.rs b/src/tools/check/src/main.rs index 9da94c44..31ea6dc7 100644 --- a/src/tools/check/src/main.rs +++ b/src/tools/check/src/main.rs @@ -75,7 +75,12 @@ impl Check { Check::Icons => { let dirs = xdg::BaseDirectories::with_prefix("kime").expect("Load xdg dirs"); - let icons = &["kime-han-64x64.png", "kime-eng-64x64.png"]; + let icons = &[ + "kime-han-black-64x64.png", + "kime-han-white-64x64.png", + "kime-eng-black-64x64.png", + "kime-eng-white-64x64.png", + ]; for icon in icons { match dirs.find_data_file(format!("icons/{}", icon)) { diff --git a/src/tools/indicator/src/main.rs b/src/tools/indicator/src/main.rs index c158f8a9..cfa55bae 100644 --- a/src/tools/indicator/src/main.rs +++ b/src/tools/indicator/src/main.rs @@ -12,15 +12,18 @@ macro_rules! cs { }; } -const HAN_ICON: &str = "kime-han-64x64.png"; -const ENG_ICON: &str = "kime-eng-64x64.png"; +enum IconColor { + Black, + White, +} struct Indicator { indicator: *mut AppIndicator, + color: IconColor, } impl Indicator { - pub fn new() -> Self { + pub fn new(color: IconColor) -> Self { unsafe fn set_icon_path(indicator: *mut AppIndicator, path: &Path) { let s = path.to_str().unwrap(); let s = CString::new(s).unwrap(); @@ -48,13 +51,11 @@ impl Indicator { cs!(""), libappindicator_sys::AppIndicatorCategory_APP_INDICATOR_CATEGORY_APPLICATION_STATUS, ); - let han = icon_dirs.find_data_file(HAN_ICON).unwrap(); - let eng = icon_dirs.find_data_file(ENG_ICON).unwrap(); - set_icon_path(indicator, han.parent().unwrap()); - if han != eng { - set_icon_path(indicator, eng.parent().unwrap()); - } + let icon = icon_dirs + .find_data_file("kime-han-white-64x64.png") + .expect("Can't find image"); + set_icon_path(indicator, icon.parent().unwrap()); libappindicator_sys::app_indicator_set_status( indicator, @@ -62,37 +63,41 @@ impl Indicator { ); libappindicator_sys::app_indicator_set_menu(indicator, m.cast()); gtk_sys::gtk_widget_show_all(m); - Self { indicator } + Self { indicator, color } } } pub fn enable_hangul(&mut self) { unsafe { - libappindicator_sys::app_indicator_set_icon_full( + libappindicator_sys::app_indicator_set_icon( self.indicator, - cs!("kime-han-64x64"), - cs!("icon"), + match self.color { + IconColor::Black => cs!("kime-han-black-64x64"), + IconColor::White => cs!("kime-han-white-64x64"), + }, ); } } pub fn disable_hangul(&mut self) { unsafe { - libappindicator_sys::app_indicator_set_icon_full( + libappindicator_sys::app_indicator_set_icon( self.indicator, - cs!("kime-eng-64x64"), - cs!("icon"), + match self.color { + IconColor::Black => cs!("kime-eng-black-64x64"), + IconColor::White => cs!("kime-eng-white-64x64"), + }, ); } } } -fn daemon_main() -> Result<()> { +fn indicator_main(color: IconColor) -> Result<()> { unsafe { gtk_sys::gtk_init(ptr::null_mut(), ptr::null_mut()); } - let mut indicator = Indicator::new(); + let mut indicator = Indicator::new(color); indicator.disable_hangul(); @@ -147,9 +152,18 @@ fn daemon_main() -> Result<()> { } fn main() { - kime_version::cli_boilerplate!(); + let mut args = kime_version::cli_boilerplate!( + "--dark: show dark icon (default)", + "--white: show white icon", + ); + + let mut color = IconColor::Black; + + if args.contains("--white") { + color = IconColor::White; + } - match daemon_main() { + match indicator_main(color) { Ok(_) => {} Err(err) => { log::error!("Error: {}", err); diff --git a/src/tools/version/src/lib.rs b/src/tools/version/src/lib.rs index 37d71aee..f4252dec 100644 --- a/src/tools/version/src/lib.rs +++ b/src/tools/version/src/lib.rs @@ -5,13 +5,16 @@ pub mod build { #[macro_export] macro_rules! cli_boilerplate { - () => { + ($($help:expr,)*) => {{ let mut args = pico_args::Arguments::from_env(); if args.contains(["-h", "--help"]) { println!("-h or --help: show help"); println!("-v or --version: show version"); println!("--verbose: show verbose log"); + $( + println!($help); + )* return; } @@ -33,7 +36,9 @@ macro_rules! cli_boilerplate { env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION") ); - }; + + args + }}; } #[macro_export]