diff --git a/include/components/screen.hpp b/include/components/screen.hpp index f004de21..474e5d9b 100644 --- a/include/components/screen.hpp +++ b/include/components/screen.hpp @@ -24,14 +24,6 @@ class screen : public xpp::event::sink { explicit screen(connection& conn, signal_emitter& emitter, const logger& logger, const config& conf); ~screen(); - struct size size() const { - return m_size; - } - - xcb_window_t root() const { - return m_root; - } - protected: void handle(const evt::randr_screen_change_notify& evt) override; diff --git a/include/x11/connection.hpp b/include/x11/connection.hpp index 542b842d..4d7e0006 100644 --- a/include/x11/connection.hpp +++ b/include/x11/connection.hpp @@ -40,7 +40,7 @@ namespace detail { , Extensions(m_c.get())... , Extensions::error_dispatcher(static_cast(*this).get())... { core::m_screen = s; - m_root_window = screen_of_display(default_screen())->root; + m_root_window = screen_of_display(s)->root; } virtual ~connection_base() {} @@ -54,10 +54,8 @@ namespace detail { return static_cast(*this); } - template - WindowType root() const { - using make = xpp::generic::factory::make; - return make()(*this, m_root_window); + xcb_window_t root() const { + return m_root_window; } shared_ptr wait_for_event() const override { diff --git a/include/x11/extensions/randr.hpp b/include/x11/extensions/randr.hpp index 4eeef380..3c509e64 100644 --- a/include/x11/extensions/randr.hpp +++ b/include/x11/extensions/randr.hpp @@ -20,7 +20,7 @@ struct position; namespace evt { using randr_notify = xpp::randr::event::notify; using randr_screen_change_notify = xpp::randr::event::screen_change_notify; -} // namespace evt +} // namespace evt struct backlight_values { unsigned int atom{0}; @@ -57,12 +57,11 @@ namespace randr_util { monitor_t make_monitor(xcb_randr_output_t randr, string name, unsigned short int w, unsigned short int h, short int x, short int y, bool primary); - vector get_monitors( - connection& conn, xcb_window_t root, bool connected_only = false, bool purge_clones = true); + vector get_monitors(connection& conn, bool connected_only = false, bool purge_clones = true); monitor_t match_monitor(vector monitors, const string& name, bool exact_match); void get_backlight_range(connection& conn, const monitor_t& mon, backlight_values& dst); void get_backlight_value(connection& conn, const monitor_t& mon, backlight_values& dst); -} // namespace randr_util +} // namespace randr_util POLYBAR_NS_END diff --git a/src/components/bar.cpp b/src/components/bar.cpp index 14074999..85c6abac 100644 --- a/src/components/bar.cpp +++ b/src/components/bar.cpp @@ -80,7 +80,7 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const auto monitor_name_fallback = m_conf.get(bs, "monitor-fallback", ""s); m_opts.monitor_strict = m_conf.get(bs, "monitor-strict", m_opts.monitor_strict); m_opts.monitor_exact = m_conf.get(bs, "monitor-exact", m_opts.monitor_exact); - auto monitors = randr_util::get_monitors(m_connection, m_connection.screen()->root, m_opts.monitor_strict, false); + auto monitors = randr_util::get_monitors(m_connection, m_opts.monitor_strict, false); if (monitors.empty()) { throw application_error("No monitors found"); @@ -98,7 +98,7 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const // if still not found (and not strict matching), get first connected monitor if (monitor_name.empty() && !m_opts.monitor_strict) { - auto connected_monitors = randr_util::get_monitors(m_connection, m_connection.screen()->root, true, false); + auto connected_monitors = randr_util::get_monitors(m_connection, true, false); if (!connected_monitors.empty()) { monitor_name = connected_monitors[0]->name; m_log.warn("No monitor specified, using \"%s\"", monitor_name); @@ -497,7 +497,7 @@ void bar::restack_window() { if (wm_restack == "generic") { try { - auto children = m_connection.query_tree(m_connection.screen()->root).children(); + auto children = m_connection.query_tree(m_connection.root()).children(); if (children.begin() != children.end() && *children.begin() != m_opts.window) { const unsigned int value_mask = XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE; const unsigned int value_list[2]{*children.begin(), XCB_STACK_MODE_BELOW}; @@ -556,7 +556,7 @@ void bar::reconfigure_pos() { * Reconfigure window strut values */ void bar::reconfigure_struts() { - auto geom = m_connection.get_geometry(m_screen->root()); + auto geom = m_connection.get_geometry(m_connection.root()); int h = m_opts.size.h + m_opts.offset.y; // Apply user-defined margins diff --git a/src/components/renderer.cpp b/src/components/renderer.cpp index d650232a..26a40877 100644 --- a/src/components/renderer.cpp +++ b/src/components/renderer.cpp @@ -61,7 +61,7 @@ renderer::renderer(connection& conn, signal_emitter& sig, const config& conf, co m_log.trace("renderer: Allocate colormap"); m_colormap = m_connection.generate_id(); - m_connection.create_colormap(XCB_COLORMAP_ALLOC_NONE, m_colormap, m_connection.screen()->root, m_visual->visual_id); + m_connection.create_colormap(XCB_COLORMAP_ALLOC_NONE, m_colormap, m_connection.root(), m_visual->visual_id); m_log.trace("renderer: Allocate output window"); // clang-format off diff --git a/src/components/screen.cpp b/src/components/screen.cpp index a349f9f5..c79fe90a 100644 --- a/src/components/screen.cpp +++ b/src/components/screen.cpp @@ -35,7 +35,7 @@ screen::screen(connection& conn, signal_emitter& emitter, const logger& logger, , m_log(logger) , m_conf(conf) , m_root(conn.root()) - , m_monitors(randr_util::get_monitors(m_connection, m_root, true, false)) + , m_monitors(randr_util::get_monitors(m_connection, true, false)) , m_size({conn.screen()->width_in_pixels, conn.screen()->height_in_pixels}) { // Check if the reloading has been disabled by the user if (!m_conf.get("settings", "screenchange-reload", false)) { @@ -120,7 +120,7 @@ void screen::handle(const evt::randr_screen_change_notify& evt) { * Fetches the monitor list and compares it with the one stored */ bool screen::have_monitors_changed() const { - auto monitors = randr_util::get_monitors(m_connection, m_root, true, false); + auto monitors = randr_util::get_monitors(m_connection, true, false); if (monitors.size() != m_monitors.size()) { return true; diff --git a/src/main.cpp b/src/main.cpp index e2aa9e1e..2697da99 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -82,7 +82,7 @@ int main(int argc, char** argv) { //================================================== if (cli->has("list-monitors") || cli->has("list-all-monitors")) { bool purge_clones = !cli->has("list-all-monitors"); - auto monitors = randr_util::get_monitors(conn, conn.root(), true, purge_clones); + auto monitors = randr_util::get_monitors(conn, true, purge_clones); for (auto&& mon : monitors) { if (mon->output == XCB_NONE) { printf("%s: %ix%i+%i+%i (no output%s)\n", mon->name.c_str(), mon->w, mon->h, mon->x, mon->y, diff --git a/src/modules/xbacklight.cpp b/src/modules/xbacklight.cpp index 6e391aac..85d2a3d0 100644 --- a/src/modules/xbacklight.cpp +++ b/src/modules/xbacklight.cpp @@ -23,7 +23,7 @@ namespace modules { auto output = m_conf.get(name(), "output", m_bar.monitor->name); - auto monitors = randr_util::get_monitors(m_connection, m_connection.root(), bar.monitor_strict, false); + auto monitors = randr_util::get_monitors(m_connection, bar.monitor_strict, false); m_output = randr_util::match_monitor(monitors, output, bar.monitor_exact); diff --git a/src/modules/xworkspaces.cpp b/src/modules/xworkspaces.cpp index 9fb04dec..a0cd8aae 100644 --- a/src/modules/xworkspaces.cpp +++ b/src/modules/xworkspaces.cpp @@ -84,7 +84,7 @@ namespace modules { } // Get list of monitors - m_monitors = randr_util::get_monitors(m_connection, m_connection.root(), false); + m_monitors = randr_util::get_monitors(m_connection, false); // Get desktop details m_desktop_names = get_desktop_names(); diff --git a/src/utils/bspwm.cpp b/src/utils/bspwm.cpp index 570b1753..8b66e76a 100644 --- a/src/utils/bspwm.cpp +++ b/src/utils/bspwm.cpp @@ -1,7 +1,8 @@ +#include "utils/bspwm.hpp" + #include #include "errors.hpp" -#include "utils/bspwm.hpp" #include "utils/env.hpp" #include "x11/connection.hpp" @@ -13,7 +14,7 @@ namespace bspwm_util { */ vector root_windows(connection& conn) { vector roots; - auto children = conn.query_tree(conn.screen()->root).children(); + auto children = conn.query_tree(conn.root()).children(); for (auto it = children.begin(); it != children.end(); it++) { xcb_icccm_get_wm_class_reply_t reply{}; @@ -146,6 +147,6 @@ namespace bspwm_util { } return conn; } -} +} // namespace bspwm_util POLYBAR_NS_END diff --git a/src/utils/i3.cpp b/src/utils/i3.cpp index 01ee68dc..0a576436 100644 --- a/src/utils/i3.cpp +++ b/src/utils/i3.cpp @@ -1,9 +1,11 @@ +#include "utils/i3.hpp" + #include + #include #include "common.hpp" #include "settings.hpp" -#include "utils/i3.hpp" #include "utils/socket.hpp" #include "utils/string.hpp" #include "x11/connection.hpp" @@ -42,7 +44,7 @@ namespace i3_util { * Get main root window */ xcb_window_t root_window(connection& conn) { - auto children = conn.query_tree(conn.screen()->root).children(); + auto children = conn.query_tree(conn.root()).children(); const auto wm_name = [&](xcb_connection_t* conn, xcb_window_t win) -> string { string title; if (!(title = ewmh_util::get_wm_name(win)).empty()) { @@ -78,6 +80,6 @@ namespace i3_util { } return false; } -} +} // namespace i3_util POLYBAR_NS_END diff --git a/src/x11/background_manager.cpp b/src/x11/background_manager.cpp index 73256db0..3579ae33 100644 --- a/src/x11/background_manager.cpp +++ b/src/x11/background_manager.cpp @@ -96,8 +96,8 @@ void background_manager::fetch_root_pixmap() { } // fill the slice - auto translated = m_connection.translate_coordinates( - slice->m_window, m_connection.screen()->root, slice->m_rect.x, slice->m_rect.y); + auto translated = + m_connection.translate_coordinates(slice->m_window, m_connection.root(), slice->m_rect.x, slice->m_rect.y); auto src_x = math_util::cap(translated->dst_x, pixmap_geom.x, int16_t(pixmap_geom.x + pixmap_geom.width)); auto src_y = math_util::cap(translated->dst_y, pixmap_geom.y, int16_t(pixmap_geom.y + pixmap_geom.height)); auto w = math_util::cap(slice->m_rect.width, uint16_t(0), uint16_t(pixmap_geom.width - (src_x - pixmap_geom.x))); diff --git a/src/x11/connection.cpp b/src/x11/connection.cpp index 0680b09b..80277604 100644 --- a/src/x11/connection.cpp +++ b/src/x11/connection.cpp @@ -169,7 +169,7 @@ bool connection::root_pixmap(xcb_pixmap_t* pixmap, int* depth, xcb_rectangle_t* const xcb_atom_t pixmap_properties[3]{_XROOTPMAP_ID, ESETROOT_PMAP_ID, _XSETROOT_ID}; for (auto&& property : pixmap_properties) { try { - auto prop = get_property(false, screen()->root, property, XCB_ATOM_PIXMAP, 0L, 1L); + auto prop = get_property(false, root(), property, XCB_ATOM_PIXMAP, 0L, 1L); if (prop->format == 32 && prop->value_len == 1) { *pixmap = *prop.value().begin(); } diff --git a/src/x11/extensions/randr.cpp b/src/x11/extensions/randr.cpp index 82f112f8..e57c6a36 100644 --- a/src/x11/extensions/randr.cpp +++ b/src/x11/extensions/randr.cpp @@ -105,22 +105,20 @@ namespace randr_util { /** * Create a list of all available randr outputs */ - vector get_monitors(connection& conn, xcb_window_t root, bool connected_only, bool purge_clones) { + vector get_monitors(connection& conn, bool connected_only, bool purge_clones) { + xcb_window_t root = conn.root(); vector monitors; bool found = false; if (check_monitor_support()) { #if WITH_XRANDR_MONITORS /* Use C, because XPP does not provide access to output info from monitors. */ - xcb_generic_error_t *err; - auto rrmonitors = - xcb_randr_get_monitors_reply( - conn, xcb_randr_get_monitors(conn, root, true), &err); + xcb_generic_error_t* err; + auto rrmonitors = xcb_randr_get_monitors_reply(conn, xcb_randr_get_monitors(conn, root, true), &err); if (err != NULL) { free(err); } else { - for (auto iter = xcb_randr_get_monitors_monitors_iterator(rrmonitors); - iter.rem; + for (auto iter = xcb_randr_get_monitors_monitors_iterator(rrmonitors); iter.rem; xcb_randr_monitor_info_next(&iter)) { auto mon = iter.data; auto name = conn.get_atom_name(mon->name).name(); @@ -129,7 +127,8 @@ namespace randr_util { int randr_output_len = xcb_randr_monitor_info_outputs_length(mon); auto randr_outputs = xcb_randr_monitor_info_outputs(mon); auto output = (randr_output_len >= 1) ? randr_outputs[0] : XCB_NONE; - monitors.emplace_back(make_monitor(output, move(name), mon->width, mon->height, mon->x, mon->y, mon->primary)); + monitors.emplace_back( + make_monitor(output, move(name), mon->width, mon->height, mon->x, mon->y, mon->primary)); found = true; } free(rrmonitors); @@ -160,8 +159,10 @@ namespace randr_util { auto crtc = conn.get_crtc_info(info->crtc); auto primary = (primary_name == name); - if (!std::any_of(monitors.begin(), monitors.end(), [name](const auto &monitor) { return monitor->name == name; })) { - monitors.emplace_back(make_monitor(output, move(name), crtc->width, crtc->height, crtc->x, crtc->y, primary)); + if (!std::any_of( + monitors.begin(), monitors.end(), [name](const auto& monitor) { return monitor->name == name; })) { + monitors.emplace_back( + make_monitor(output, move(name), crtc->width, crtc->height, crtc->x, crtc->y, primary)); } } catch (const exception&) { // silently ignore output @@ -269,6 +270,6 @@ namespace randr_util { dst.val = static_cast(value); } } -} // namespace randr_util +} // namespace randr_util POLYBAR_NS_END diff --git a/src/x11/tray_manager.cpp b/src/x11/tray_manager.cpp index 5a6e1ccb..72f2ec79 100644 --- a/src/x11/tray_manager.cpp +++ b/src/x11/tray_manager.cpp @@ -573,8 +573,9 @@ void tray_manager::create_bg() { * Set window WM hints */ void tray_manager::set_wm_hints() { - const unsigned int visual{m_connection.screen()->root_visual}; - const unsigned int orientation{_NET_SYSTEM_TRAY_ORIENTATION_HORZ}; + // TODO use same visual as bar/tray window + const xcb_visualid_t visual{m_connection.screen()->root_visual}; + const uint32_t orientation{_NET_SYSTEM_TRAY_ORIENTATION_HORZ}; m_log.trace("bar: Set window WM_NAME / WM_CLASS"); icccm_util::set_wm_name(m_connection, m_tray, TRAY_WM_NAME, 19_z, TRAY_WM_CLASS, 12_z); diff --git a/src/x11/winspec.cpp b/src/x11/winspec.cpp index 92e57ba2..000a999e 100644 --- a/src/x11/winspec.cpp +++ b/src/x11/winspec.cpp @@ -21,7 +21,7 @@ xcb_window_t winspec::operator<<(const cw_flush& f) { m_window = m_connection.generate_id(); } if (m_parent == XCB_NONE) { - m_parent = m_connection.screen()->root; + m_parent = m_connection.root(); } if (m_width <= 0) {