1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-25 13:55:47 -05:00

feat(ipc): Add visibility commands

This commit is contained in:
Michael Carlberg 2017-04-21 18:15:18 +02:00
parent 23a7717120
commit b6c5563b0b
4 changed files with 70 additions and 4 deletions

View file

@ -16,7 +16,7 @@ _polybar_msg() {
case $words[1] in
hook) _arguments ':module name:' ':hook index:'; ret=0 ;;
action) _arguments ':action payload:'; ret=0 ;;
cmd) _arguments ':command payload:'; ret=0 ;;
cmd) _arguments ':command payload:(show hide toggle restart quit)'; ret=0 ;;
esac
;;
esac

View file

@ -41,6 +41,10 @@ class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::propert
void parse(string&& data, bool force = false);
void hide();
void show();
void toggle();
protected:
void restack_window();
void reconfigure_pos();
@ -86,6 +90,8 @@ class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::propert
event_timer m_doubleclick{0L, 150L};
double m_anim_step{0.0};
bool m_visible{true};
};
POLYBAR_NS_END

View file

@ -313,9 +313,12 @@ void bar::parse(string&& data, bool force) {
if (force) {
m_log.trace("bar: Force update");
} else if (!m_visible) {
return m_log.trace("bar: Ignoring update (invisible)");
} else if (m_opts.shaded) {
return m_log.trace("bar: Ignoring update (shaded)");
} else if (data == m_lastinput) {
return m_log.trace("bar: Ignoring update (unchanged)");
return;
}
@ -361,6 +364,57 @@ void bar::parse(string&& data, bool force) {
m_dblclicks = check_dblclicks();
}
/**
* Hide the bar by unmapping its X window
*/
void bar::hide() {
if (!m_visible) {
return;
}
try {
m_log.info("Hiding bar window");
m_sig.emit(visibility_change{false});
m_connection.unmap_window_checked(m_opts.window);
m_connection.flush();
m_visible = false;
} catch (const exception& err) {
m_log.err("Failed to unmap bar window (err=%s", err.what());
}
}
/**
* Show the bar by mapping its X window and
* trigger a redraw of previous content
*/
void bar::show() {
if (m_visible) {
return;
}
try {
m_log.info("Showing bar window");
m_sig.emit(visibility_change{true});
m_connection.map_window_checked(m_opts.window);
m_connection.flush();
m_visible = true;
parse(string{m_lastinput}, true);
} catch (const exception& err) {
m_log.err("Failed to map bar window (err=%s", err.what());
}
}
/**
* Toggle the bar's visibility state
*/
void bar::toggle() {
if (m_visible) {
hide();
} else {
show();
}
}
/**
* Move the bar window above defined sibling
* in the X window stack
@ -458,11 +512,11 @@ void bar::broadcast_visibility() {
auto attr = m_connection.get_window_attributes(m_opts.window);
if (attr->map_state == XCB_MAP_STATE_UNVIEWABLE) {
m_sig.emit(visibility_change{move(false)});
m_sig.emit(visibility_change{false});
} else if (attr->map_state == XCB_MAP_STATE_UNMAPPED) {
m_sig.emit(visibility_change{move(false)});
m_sig.emit(visibility_change{false});
} else {
m_sig.emit(visibility_change{move(true)});
m_sig.emit(visibility_change{true});
}
}

View file

@ -636,6 +636,12 @@ bool controller::on(const signals::ipc::command& evt) {
enqueue(make_quit_evt(false));
} else if (command == "restart") {
enqueue(make_quit_evt(true));
} else if (command == "hide") {
m_bar->hide();
} else if (command == "show") {
m_bar->show();
} else if (command == "toggle") {
m_bar->toggle();
} else {
m_log.warn("\"%s\" is not a valid ipc command", command);
}