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

Allow hiding/unhiding the bar with SIGUSR1/2 #415

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 18 additions & 3 deletions bar.c
Expand Up @@ -182,6 +182,16 @@ static void bar_poll_readable(struct bar *bar, const int fd)
}
}

static void bar_hide(struct bar *bar) {
bar->hidden = true;
bar_print(bar);
}

static void bar_unhide(struct bar *bar) {
bar->hidden = false;
bar_print(bar);
}

static int gcd(int a, int b)
{
while (b != 0)
Expand Down Expand Up @@ -239,7 +249,7 @@ static int bar_setup(struct bar *bar)
if (err)
return err;

/* Deprecated signals */
/* Hide/unhide */
err = sys_sigaddset(set, SIGUSR1);
if (err)
return err;
Expand Down Expand Up @@ -380,8 +390,13 @@ static int bar_poll(struct bar *bar)
continue;
}

if (sig == SIGUSR1 || sig == SIGUSR2) {
error("SIGUSR{1,2} are deprecated, ignoring.");
if (sig == SIGUSR1) {
bar_hide(bar);
continue;
}

if (sig == SIGUSR2) {
bar_unhide(bar);
continue;
}

Expand Down
1 change: 1 addition & 0 deletions bar.h
Expand Up @@ -28,6 +28,7 @@ struct bar {
struct block *blocks;
sigset_t sigset;
bool term;
bool hidden;
};

#define bar_printf(bar, lvl, fmt, ...) \
Expand Down
14 changes: 8 additions & 6 deletions i3bar.c
Expand Up @@ -175,20 +175,22 @@ static int i3bar_print_block(struct block *block, void *data)
{
struct block *block = bar->blocks;
unsigned int mcount = 0;
int err;
int err = 0;

if (bar->term) {
i3bar_print_term(bar);
return 0;
}

fprintf(stdout, ",[");
while (block) {
err = i3bar_print_block(block, &mcount);
if (err)
break;
if (!block->bar->hidden) {
while (block) {
err = i3bar_print_block(block, &mcount);
if (err)
break;

block = block->next;
block = block->next;
}
}
fprintf(stdout, "]\n");
fflush(stdout);
Expand Down