Skip to content

Commit

Permalink
tray: implement hiding functionality (#2723)
Browse files Browse the repository at this point in the history
* tray hiding works

* clang-format

* Implemented suggestions
  • Loading branch information
raffael0 committed Jun 16, 2022
1 parent 86f2baa commit b2c5d8e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 28 deletions.
3 changes: 3 additions & 0 deletions include/events/signal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion include/events/signal_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 8 additions & 5 deletions include/x11/tray_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/components/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
}

Expand Down
52 changes: 30 additions & 22 deletions src/x11/tray_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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

5 comments on commit b2c5d8e

@moson-mo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this commit, the tray icons start flickering it seems.

@patrick96
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moson-mo Are you using picom or some other compositor?

@moson-mo
Copy link

@moson-mo moson-mo commented on b2c5d8e Jun 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moson-mo Are you using picom or some other compositor?

Nope. But if I run picom, the flickering actually stops :)

edit
It only seems to happen with the battery indicator icon from xfce4-power-manager.
The others are not flickering (like BT and Network)
Others are flickering too. Somewhat depends on the position of a tray icon. The one on the very right flickers most.

image

edit2
Also when I run some fullscreen application like MPV, the tray bar stays visible (like always on-top)

@raffael0
Copy link
Contributor Author

@raffael0 raffael0 commented on b2c5d8e Jun 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moson-mo I just fixed a similar bug(#2742).
Can you test if that fixes it and otherwise file a proper bug report with minimal config?

@moson-mo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raffael0 Tried that. It's still the same though.
Effectively nothing really changes with that patch I guess -> I do use the tray as a module to be able to place it between other modules.

Now when I remove the tray module and put `tray-position = right" there is no flickering...

I'll file a bug report later.
Anyways, thanks a lot for replying.

Please sign in to comment.