tray: implement hiding functionality (#2723)
* tray hiding works * clang-format * Implemented suggestions
This commit is contained in:
parent
86f2baa550
commit
b2c5d8e0e2
@ -110,6 +110,9 @@ namespace signals {
|
||||
struct tray_pos_change : public detail::value_signal<tray_pos_change, int> {
|
||||
using base_type::base_type;
|
||||
};
|
||||
struct tray_visibility : public detail::value_signal<tray_visibility, bool> {
|
||||
using base_type::base_type;
|
||||
};
|
||||
} // namespace ui_tray
|
||||
} // namespace signals
|
||||
|
||||
|
@ -38,7 +38,8 @@ namespace signals {
|
||||
struct mapped_clients;
|
||||
struct tray_width_change;
|
||||
struct tray_pos_change;
|
||||
}
|
||||
struct tray_visibility;
|
||||
} // namespace ui_tray
|
||||
} // namespace signals
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
@ -65,11 +65,12 @@ struct tray_settings {
|
||||
bool detached{false};
|
||||
};
|
||||
|
||||
class tray_manager : public xpp::event::sink<evt::expose, evt::visibility_notify, evt::client_message,
|
||||
evt::configure_request, evt::resize_request, evt::selection_clear, evt::property_notify,
|
||||
evt::reparent_notify, evt::destroy_notify, evt::map_notify, evt::unmap_notify>,
|
||||
public signal_receiver<SIGN_PRIORITY_TRAY, signals::ui::visibility_change, signals::ui::dim_window,
|
||||
signals::ui::update_background, signals::ui_tray::tray_pos_change> {
|
||||
class tray_manager
|
||||
: public xpp::event::sink<evt::expose, evt::visibility_notify, evt::client_message, evt::configure_request,
|
||||
evt::resize_request, evt::selection_clear, evt::property_notify, evt::reparent_notify, evt::destroy_notify,
|
||||
evt::map_notify, evt::unmap_notify>,
|
||||
public signal_receiver<SIGN_PRIORITY_TRAY, signals::ui::visibility_change, signals::ui::dim_window,
|
||||
signals::ui::update_background, signals::ui_tray::tray_pos_change, signals::ui_tray::tray_visibility> {
|
||||
public:
|
||||
using make_type = unique_ptr<tray_manager>;
|
||||
static make_type make(const bar_settings& settings);
|
||||
@ -122,6 +123,7 @@ class tray_manager : public xpp::event::sink<evt::expose, evt::visibility_notify
|
||||
void remove_client(shared_ptr<tray_client>& client, bool reconfigure = true);
|
||||
void remove_client(xcb_window_t win, bool reconfigure = true);
|
||||
unsigned int mapped_clients() const;
|
||||
bool change_visibility(bool visible);
|
||||
|
||||
void handle(const evt::expose& evt) override;
|
||||
void handle(const evt::visibility_notify& evt) override;
|
||||
@ -139,6 +141,7 @@ class tray_manager : public xpp::event::sink<evt::expose, evt::visibility_notify
|
||||
bool on(const signals::ui::dim_window& evt) override;
|
||||
bool on(const signals::ui::update_background& evt) override;
|
||||
bool on(const signals::ui_tray::tray_pos_change& evt) override;
|
||||
bool on(const signals::ui_tray::tray_visibility& evt) override;
|
||||
|
||||
private:
|
||||
connection& m_connection;
|
||||
|
@ -828,6 +828,9 @@ void renderer::apply_tray_position(const tags::context& context) {
|
||||
int absolute_x = static_cast<int>(
|
||||
block_x(context.get_relative_tray_position().first) + context.get_relative_tray_position().second);
|
||||
m_sig.emit(signals::ui_tray::tray_pos_change{absolute_x});
|
||||
m_sig.emit(signals::ui_tray::tray_visibility{true});
|
||||
} else {
|
||||
m_sig.emit(signals::ui_tray::tray_visibility{false});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -914,6 +914,29 @@ unsigned int tray_manager::mapped_clients() const {
|
||||
return mapped_clients;
|
||||
}
|
||||
|
||||
bool tray_manager::change_visibility(bool visible) {
|
||||
unsigned int clients{mapped_clients()};
|
||||
|
||||
m_log.trace("tray: visibility_change (state=%i, activated=%i, mapped=%i, hidden=%i)", visible,
|
||||
static_cast<bool>(m_activated), static_cast<bool>(m_mapped), static_cast<bool>(m_hidden));
|
||||
|
||||
m_hidden = !visible;
|
||||
|
||||
if (!m_activated) {
|
||||
return false;
|
||||
} else if (!m_hidden && !m_mapped && clients) {
|
||||
m_connection.map_window(m_tray);
|
||||
} else if ((!clients || m_hidden) && m_mapped) {
|
||||
m_connection.unmap_window(m_tray);
|
||||
} else if (m_mapped && !m_hidden && clients) {
|
||||
redraw_window();
|
||||
}
|
||||
|
||||
m_connection.flush();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event callback : XCB_EXPOSE
|
||||
*/
|
||||
@ -1024,7 +1047,8 @@ void tray_manager::handle(const evt::property_notify& evt) {
|
||||
}
|
||||
|
||||
// React an wallpaper change, if bar has transparency
|
||||
if (m_opts.transparent && (evt->atom == _XROOTPMAP_ID || evt->atom == _XSETROOT_ID || evt->atom == ESETROOT_PMAP_ID)) {
|
||||
if (m_opts.transparent &&
|
||||
(evt->atom == _XROOTPMAP_ID || evt->atom == _XSETROOT_ID || evt->atom == ESETROOT_PMAP_ID)) {
|
||||
redraw_window(true);
|
||||
return;
|
||||
}
|
||||
@ -1132,27 +1156,7 @@ void tray_manager::handle(const evt::unmap_notify& evt) {
|
||||
* toggle the tray window whenever the visibility of the bar window changes.
|
||||
*/
|
||||
bool tray_manager::on(const signals::ui::visibility_change& evt) {
|
||||
bool visible{evt.cast()};
|
||||
unsigned int clients{mapped_clients()};
|
||||
|
||||
m_log.trace("tray: visibility_change (state=%i, activated=%i, mapped=%i, hidden=%i)", visible,
|
||||
static_cast<bool>(m_activated), static_cast<bool>(m_mapped), static_cast<bool>(m_hidden));
|
||||
|
||||
m_hidden = !visible;
|
||||
|
||||
if (!m_activated) {
|
||||
return false;
|
||||
} else if (!m_hidden && !m_mapped && clients) {
|
||||
m_connection.map_window(m_tray);
|
||||
} else if ((!clients || m_hidden) && m_mapped) {
|
||||
m_connection.unmap_window(m_tray);
|
||||
} else if (m_mapped && !m_hidden && clients) {
|
||||
redraw_window();
|
||||
}
|
||||
|
||||
m_connection.flush();
|
||||
|
||||
return true;
|
||||
return change_visibility(evt.cast());
|
||||
}
|
||||
|
||||
bool tray_manager::on(const signals::ui::dim_window& evt) {
|
||||
@ -1178,4 +1182,8 @@ bool tray_manager::on(const signals::ui_tray::tray_pos_change& evt) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tray_manager::on(const signals::ui_tray::tray_visibility& evt) {
|
||||
return change_visibility(evt.cast());
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
Loading…
Reference in New Issue
Block a user