fix(bar): Update struts when hiding (#2702)

When the bar is hidden, the struts should be 0 so that WMs can resize
their windows and not leave a gap.

Ref #2701
This commit is contained in:
Patrick Ziegler 2022-04-27 21:09:59 +02:00 committed by GitHub
parent bc9dda266f
commit efbd8e394f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 35 deletions

View File

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `internal/battery`: `poll-interval` not working ([`#2649`](https://github.com/polybar/polybar/issues/2649), [`#2677`](https://github.com/polybar/polybar/pull/2677)) - `internal/battery`: `poll-interval` not working ([`#2649`](https://github.com/polybar/polybar/issues/2649), [`#2677`](https://github.com/polybar/polybar/pull/2677))
- ipc: Polybar failing to open IPC channel after another user already ran polybar, if `XDG_RUNTIME_DIR` is not set ([`#2683`](https://github.com/polybar/polybar/issues/2683), [`#2684`](https://github.com/polybar/polybar/pull/2684)) - ipc: Polybar failing to open IPC channel after another user already ran polybar, if `XDG_RUNTIME_DIR` is not set ([`#2683`](https://github.com/polybar/polybar/issues/2683), [`#2684`](https://github.com/polybar/polybar/pull/2684))
- No overlines/underlines being drawn when using offsets ([`#2685`](https://github.com/polybar/polybar/pull/2685)) - No overlines/underlines being drawn when using offsets ([`#2685`](https://github.com/polybar/polybar/pull/2685))
- Update struts (`_NET_WM_STRUT_PARTIAL`) when hiding the bar ([`#2702`](https://github.com/polybar/polybar/pull/2702))
## [3.6.2] - 2022-04-03 ## [3.6.2] - 2022-04-03
### Fixed ### Fixed

View File

@ -440,10 +440,11 @@ void bar::hide() {
try { try {
m_log.info("Hiding bar window"); m_log.info("Hiding bar window");
m_visible = false;
reconfigure_struts();
m_sig.emit(visibility_change{false}); m_sig.emit(visibility_change{false});
m_connection.unmap_window_checked(m_opts.window); m_connection.unmap_window_checked(m_opts.window);
m_connection.flush(); m_connection.flush();
m_visible = false;
} catch (const exception& err) { } catch (const exception& err) {
m_log.err("Failed to unmap bar window (err=%s", err.what()); m_log.err("Failed to unmap bar window (err=%s", err.what());
} }
@ -556,42 +557,46 @@ void bar::reconfigure_pos() {
* Reconfigure window strut values * Reconfigure window strut values
*/ */
void bar::reconfigure_struts() { void bar::reconfigure_struts() {
auto geom = m_connection.get_geometry(m_screen->root()); window win{m_connection, m_opts.window};
int h = m_opts.size.h + m_opts.offset.y; if (m_visible) {
auto geom = m_connection.get_geometry(m_screen->root());
int h = m_opts.size.h + m_opts.offset.y;
// Apply user-defined margins // Apply user-defined margins
if (m_opts.bottom) {
h += m_opts.strut.top;
} else {
h += m_opts.strut.bottom;
}
h = std::max(h, 0);
int correction = 0;
// Only apply correction if any space is requested
if (h > 0) {
/*
* Strut coordinates have to be relative to root window and not any monitor.
* If any monitor is not aligned at the top or bottom
*/
if (m_opts.bottom) { if (m_opts.bottom) {
/* h += m_opts.strut.top;
* For bottom-algined bars, the correction is the number of pixels between
* the root window's bottom edge and the monitor's bottom edge
*/
correction = geom->height - (m_opts.monitor->y + m_opts.monitor->h);
} else { } else {
// For top-aligned bars, we simply add the monitor's y-position h += m_opts.strut.bottom;
correction = m_opts.monitor->y;
} }
correction = std::max(correction, 0); h = std::max(h, 0);
}
window win{m_connection, m_opts.window}; int correction = 0;
win.reconfigure_struts(m_opts.size.w, h + correction, m_opts.pos.x, m_opts.bottom);
// Only apply correction if any space is requested
if (h > 0) {
/*
* Strut coordinates have to be relative to root window and not any monitor.
* If any monitor is not aligned at the top or bottom
*/
if (m_opts.bottom) {
/*
* For bottom-algined bars, the correction is the number of pixels between
* the root window's bottom edge and the monitor's bottom edge
*/
correction = geom->height - (m_opts.monitor->y + m_opts.monitor->h);
} else {
// For top-aligned bars, we simply add the monitor's y-position
correction = m_opts.monitor->y;
}
correction = std::max(correction, 0);
}
win.reconfigure_struts(m_opts.size.w, h + correction, m_opts.pos.x, m_opts.bottom);
} else {
// Set struts to 0 for invisible bars
win.reconfigure_struts(0, 0, 0, m_opts.bottom);
}
} }
/** /**
@ -634,6 +639,8 @@ void bar::broadcast_visibility() {
} }
void bar::map_window() { void bar::map_window() {
m_visible = true;
/** /**
* First reconfigures the window so that WMs that discard some information * First reconfigures the window so that WMs that discard some information
* when unmapping have the correct window properties (geometry etc). * when unmapping have the correct window properties (geometry etc).
@ -648,8 +655,6 @@ void bar::map_window() {
* mapping. Additionally updating the window position after mapping seems to fix that. * mapping. Additionally updating the window position after mapping seems to fix that.
*/ */
reconfigure_pos(); reconfigure_pos();
m_visible = true;
} }
void bar::trigger_click(mousebtn btn, int pos) { void bar::trigger_click(mousebtn btn, int pos) {

View File

@ -57,14 +57,16 @@ window window::reconfigure_pos(short int x, short int y) {
window window::reconfigure_struts(uint32_t w, uint32_t strut, uint32_t x, bool bottom) { window window::reconfigure_struts(uint32_t w, uint32_t strut, uint32_t x, bool bottom) {
std::array<uint32_t, 12> values{}; std::array<uint32_t, 12> values{};
uint32_t end_x = std::max<int>(0, x + w - 1);
if (bottom) { if (bottom) {
values[to_integral(strut::BOTTOM)] = strut; values[to_integral(strut::BOTTOM)] = strut;
values[to_integral(strut::BOTTOM_START_X)] = x; values[to_integral(strut::BOTTOM_START_X)] = x;
values[to_integral(strut::BOTTOM_END_X)] = x + w - 1; values[to_integral(strut::BOTTOM_END_X)] = end_x;
} else { } else {
values[to_integral(strut::TOP)] = strut; values[to_integral(strut::TOP)] = strut;
values[to_integral(strut::TOP_START_X)] = x; values[to_integral(strut::TOP_START_X)] = x;
values[to_integral(strut::TOP_END_X)] = x + w - 1; values[to_integral(strut::TOP_END_X)] = end_x;
} }
connection().change_property_checked( connection().change_property_checked(