tray: Cleanup position calculation
This commit is contained in:
parent
b5f8466117
commit
7fbd2d175c
@ -47,6 +47,11 @@ struct tray_settings {
|
||||
*/
|
||||
unsigned spacing{0U};
|
||||
|
||||
/**
|
||||
* Number of pixels added before and after each tray icon
|
||||
*/
|
||||
unsigned padding{0U};
|
||||
|
||||
/**
|
||||
* Background color used in the client wrapper window
|
||||
*
|
||||
@ -114,12 +119,10 @@ class manager : public xpp::event::sink<evt::expose, evt::client_message, evt::c
|
||||
void track_selection_owner(xcb_window_t owner);
|
||||
void process_docking_request(xcb_window_t win);
|
||||
|
||||
/**
|
||||
* Final x-position of the tray window relative to the very top-left bar window.
|
||||
*/
|
||||
int calculate_x() const;
|
||||
|
||||
unsigned calculate_w() const;
|
||||
unsigned calculate_w(unsigned count) const;
|
||||
|
||||
int calculate_client_y();
|
||||
|
||||
|
@ -233,19 +233,20 @@ void manager::recalculate_width() {
|
||||
void manager::reconfigure_clients() {
|
||||
m_log.trace("tray: Reconfigure clients");
|
||||
|
||||
int x = calculate_x() + m_opts.spacing;
|
||||
int base_x = calculate_x();
|
||||
|
||||
bool has_error = false;
|
||||
|
||||
unsigned count = 0;
|
||||
|
||||
for (auto& client : m_clients) {
|
||||
try {
|
||||
client->ensure_state();
|
||||
|
||||
if (client->mapped()) {
|
||||
client->set_position(x, calculate_client_y());
|
||||
client->set_position(base_x + calculate_w(count), calculate_client_y());
|
||||
count++;
|
||||
}
|
||||
|
||||
x += m_opts.client_size.w + m_opts.spacing;
|
||||
} catch (const xpp::x::error::window& err) {
|
||||
m_log.err("Failed to reconfigure %s, removing ... (%s)", client->name(), err.what());
|
||||
client.reset();
|
||||
@ -417,6 +418,9 @@ void manager::process_docking_request(xcb_window_t win) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Final x-position of the tray window relative to the very top-left bar window.
|
||||
*/
|
||||
int manager::calculate_x() const {
|
||||
return m_bar_opts.inner_area(false).x + m_pos.x;
|
||||
}
|
||||
@ -427,15 +431,21 @@ int manager::calculate_x() const {
|
||||
* This many pixels need to be reserved on the bar in order to draw the tray.
|
||||
*/
|
||||
unsigned manager::calculate_w() const {
|
||||
unsigned width = m_opts.spacing;
|
||||
unsigned count{0};
|
||||
for (const auto& client : m_clients) {
|
||||
if (client->mapped()) {
|
||||
count++;
|
||||
width += m_opts.spacing + m_opts.client_size.w;
|
||||
}
|
||||
unsigned count =
|
||||
std::count_if(m_clients.begin(), m_clients.end(), [](const auto& client) { return client->mapped(); });
|
||||
|
||||
return calculate_w(count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the width taken up by count tray icons in pixels
|
||||
*/
|
||||
unsigned manager::calculate_w(unsigned count) const {
|
||||
if (count) {
|
||||
return m_opts.spacing + count * (m_opts.spacing + m_opts.client_size.w);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return count ? width : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user