mirror of
https://github.com/polybar/polybar.git
synced 2024-10-27 05:23:39 -04:00
fix(xcb): Use xcb_rectangle for monitor bounds
This commit is contained in:
parent
cc9d385b6f
commit
718cfd294d
3 changed files with 10 additions and 18 deletions
|
@ -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<monitor_t> make_monitor();
|
||||
|
|
|
@ -86,14 +86,14 @@ Bar::Bar() : config_path(config::get_bar_path()), opts(std::make_unique<Options>
|
|||
auto height = config::get<std::string>(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());
|
||||
|
|
|
@ -7,14 +7,11 @@ namespace xcb
|
|||
return memory::make_malloc_ptr<monitor_t>();
|
||||
}
|
||||
|
||||
std::shared_ptr<monitor_t> make_monitor(char *name, size_t name_len, int idx, xcb_rectangle_t *rect)
|
||||
std::shared_ptr<monitor_t> 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<monitor_t> m1, std::shared_ptr<monitor_t> 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;
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue