Skip to content

Commit

Permalink
Add white icon (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
Riey authored Feb 25, 2021
1 parent 8adc073 commit ee26d47
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 23 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Binary file added docs/assets/icon.xcf
Binary file not shown.
Binary file removed res/icons/kime-eng-64x64.png
Binary file not shown.
Binary file added res/icons/kime-eng-black-64x64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/icons/kime-eng-white-64x64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed res/icons/kime-han-64x64.png
Binary file not shown.
Binary file added res/icons/kime-han-black-64x64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/icons/kime-han-white-64x64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion src/tools/check/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
54 changes: 34 additions & 20 deletions src/tools/indicator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -48,51 +51,53 @@ 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,
AppIndicatorStatus_APP_INDICATOR_STATUS_ACTIVE,
);
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();

Expand Down Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions src/tools/version/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -33,7 +36,9 @@ macro_rules! cli_boilerplate {
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION")
);
};

args
}};
}

#[macro_export]
Expand Down

0 comments on commit ee26d47

Please sign in to comment.