Skip to content

Commit

Permalink
add option to disable tray icon
Browse files Browse the repository at this point in the history
  • Loading branch information
xdavidwu committed Sep 13, 2021
1 parent 7fe7440 commit 09ebf26
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
7 changes: 6 additions & 1 deletion config.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ static const struct option long_options[] = {
{"background-color", required_argument, NULL, 'b'},
{"selection-color", required_argument, NULL, 's'},
{"selection-text-color",required_argument, NULL, 'S'},
{"no-tray-icon", no_argument, NULL, 'n'},
{"force-default-keymap", no_argument, NULL, 1},
{0},
};
Expand All @@ -38,6 +39,7 @@ static const char help[] = "Usage: %s [OPTIONS]...\n"
" -s, --selection-color=COLOR\tSet candidate panel selection highlight color\n"
" -S, --selection-text-color=COLOR\n"
"\t\t\t\tSet candidate panel selection text color\n"
" -n, --no-tray-icon\t\tDisable tray icon.\n"
"\n"
"COLOR is color specified as either #RRGGBB or #RRGGBBAA.\n";

Expand All @@ -60,6 +62,7 @@ struct wlchewing_config *config_new() {
config->selection_color[1] = 0.25;
config->selection_color[2] = 0.25;
config->selection_color[3] = 1.0;
config->tray_icon = true;
return config;
}

Expand All @@ -83,7 +86,7 @@ static int decode_color(const char *str, double *rgba) {

int config_read_opts(int argc, char *argv[], struct wlchewing_config *config) {
int opt;
while ((opt = getopt_long(argc, argv, "ed:f:tT:b:s:S:", long_options, NULL)) != -1) {
while ((opt = getopt_long(argc, argv, "ed:f:tT:b:s:S:n", long_options, NULL)) != -1) {
if (opt == '?') {
fprintf(stderr, help, argv[0]);
return -EINVAL;
Expand Down Expand Up @@ -134,6 +137,8 @@ int config_read_opts(int argc, char *argv[], struct wlchewing_config *config) {
return -EINVAL;
}
break;
case 'n':
config->tray_icon = false;
case 1:
config->chewing_use_xkb_default = true;
break;
Expand Down
1 change: 1 addition & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct wlchewing_config {
double selection_color[4];
double selection_text_color[4];
bool chewing_use_xkb_default;
bool tray_icon;
};

struct wlchewing_config *config_new();
Expand Down
43 changes: 23 additions & 20 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,28 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}

state->sni = calloc(1, sizeof(struct wlchewing_sni));
if (state->sni == NULL) {
wlchewing_err("Failed to calloc SNI state");
return EXIT_FAILURE;
}
int bus_fd = sni_setup(state->sni);
if (bus_fd < 0) {
wlchewing_err("Failed to setup dbus: %s", strerror(-bus_fd));
return EXIT_FAILURE;
}
struct epoll_event bus_epoll = {
.events = EPOLLIN,
.data = {
.fd = bus_fd,
},
};
if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, bus_fd, &bus_epoll) < 0) {
wlchewing_err("Failed to add bus epoll: %s", strerror(errno));
return EXIT_FAILURE;
int bus_fd;
if (state->config->tray_icon) {
state->sni = calloc(1, sizeof(struct wlchewing_sni));
if (state->sni == NULL) {
wlchewing_err("Failed to calloc SNI state");
return EXIT_FAILURE;
}
bus_fd = sni_setup(state->sni);
if (bus_fd < 0) {
wlchewing_err("Failed to setup dbus: %s", strerror(-bus_fd));
return EXIT_FAILURE;
}
struct epoll_event bus_epoll = {
.events = EPOLLIN,
.data = {
.fd = bus_fd,
},
};
if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, bus_fd, &bus_epoll) < 0) {
wlchewing_err("Failed to add bus epoll: %s", strerror(errno));
return EXIT_FAILURE;
}
}

im_setup(state);
Expand Down Expand Up @@ -183,7 +186,7 @@ int main(int argc, char *argv[]) {
uint64_t count = 0;
read(state->timer_fd, &count, sizeof(uint64_t));
im_key_press(state, state->last_key);
} else if (event_caught.data.fd == bus_fd) {
} else if (state->config->tray_icon && event_caught.data.fd == bus_fd) {
sd_bus_process(state->sni->bus, NULL);
}
}
Expand Down
3 changes: 3 additions & 0 deletions sni.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ static int handle_owner_changed(sd_bus_message *m, void *userdata,
}

int sni_set_icon(struct wlchewing_sni *sni, bool english) {
if (!sni) {
return 0;
}
if (english == sni->english) {
return 0;
}
Expand Down

0 comments on commit 09ebf26

Please sign in to comment.