diff --git a/include/utils/xcb.hpp b/include/utils/xcb.hpp index f9566f1a..6b41f37b 100644 --- a/include/utils/xcb.hpp +++ b/include/utils/xcb.hpp @@ -35,11 +35,8 @@ namespace xcb struct monitor_t { char name[32] = "NONAME"; + xcb_rectangle_t bounds; int index = 0; - int width = 0; - int height = 0; - int x = 0; - int y = 0; }; std::shared_ptr make_monitor(); diff --git a/src/bar.cpp b/src/bar.cpp index 8ba76ec9..0c5192f5 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -86,14 +86,14 @@ Bar::Bar() : config_path(config::get_bar_path()), opts(std::make_unique auto height = config::get(this->config_path, "height", "30"); if (width.find("%") != std::string::npos) { - this->opts->width = this->opts->monitor->width * (std::atoi(width.c_str()) / 100.0) + 0.5; + this->opts->width = this->opts->monitor->bounds.width * (std::atoi(width.c_str()) / 100.0) + 0.5; this->opts->width -= this->opts->offset_x * 2; } else { this->opts->width = std::atoi(width.c_str()); } if (height.find("%") != std::string::npos) { - this->opts->height = this->opts->monitor->height * (std::atoi(height.c_str()) / 100.0) + 0.5; + this->opts->height = this->opts->monitor->bounds.height * (std::atoi(height.c_str()) / 100.0) + 0.5; this->opts->width -= this->opts->offset_y * 2; } else { this->opts->height = std::atoi(height.c_str()); diff --git a/src/utils/xcb.cpp b/src/utils/xcb.cpp index 7e2050d2..b9e2752d 100644 --- a/src/utils/xcb.cpp +++ b/src/utils/xcb.cpp @@ -7,14 +7,11 @@ namespace xcb return memory::make_malloc_ptr(); } - std::shared_ptr make_monitor(char *name, size_t name_len, int idx, xcb_rectangle_t *rect) + std::shared_ptr make_monitor(char *name, size_t name_len, int idx, xcb_rectangle_t rect) { auto mon = make_monitor(); - mon->x = rect->x; - mon->y = rect->y; - mon->width = rect->width; - mon->height = rect->height; + mon->bounds = rect; mon->index = idx; size_t name_size = name_len + 1; @@ -64,20 +61,18 @@ namespace xcb continue; } - char *name = (char *) xcb_randr_get_output_info_name(info); - - xcb_rectangle_t rect = {cir->x, cir->y, cir->width, cir->height}; - - monitors.emplace_back(xcb::make_monitor(name, info->name_len, i, &rect)); + char *monitor_name = (char *) xcb_randr_get_output_info_name(info); + monitors.emplace_back(xcb::make_monitor(monitor_name, info->name_len, i, + {cir->x, cir->y, cir->width, cir->height})); free(cir); } std::sort(monitors.begin(), monitors.end(), [](std::shared_ptr m1, std::shared_ptr m2) -> bool { - if (m1->x < m2->x || m1->y + m1->height <= m2->y) + if (m1->bounds.x < m2->bounds.x || m1->bounds.y + m1->bounds.height <= m2->bounds.y) return 1; - if (m1->x > m2->x || m1->y + m1->height > m2->y) + if (m1->bounds.x > m2->bounds.x || m1->bounds.y + m1->bounds.height > m2->bounds.y) return -1; return 0; });