fix(xcb): Use xcb_rectangle for monitor bounds

This commit is contained in:
Michael Carlberg 2016-06-24 01:42:58 +02:00
parent cc9d385b6f
commit 718cfd294d
3 changed files with 10 additions and 18 deletions

View File

@ -35,11 +35,8 @@ namespace xcb
struct monitor_t struct monitor_t
{ {
char name[32] = "NONAME"; char name[32] = "NONAME";
xcb_rectangle_t bounds;
int index = 0; int index = 0;
int width = 0;
int height = 0;
int x = 0;
int y = 0;
}; };
std::shared_ptr<monitor_t> make_monitor(); std::shared_ptr<monitor_t> make_monitor();

View File

@ -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"); auto height = config::get<std::string>(this->config_path, "height", "30");
if (width.find("%") != std::string::npos) { 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; this->opts->width -= this->opts->offset_x * 2;
} else { } else {
this->opts->width = std::atoi(width.c_str()); this->opts->width = std::atoi(width.c_str());
} }
if (height.find("%") != std::string::npos) { 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; this->opts->width -= this->opts->offset_y * 2;
} else { } else {
this->opts->height = std::atoi(height.c_str()); this->opts->height = std::atoi(height.c_str());

View File

@ -7,14 +7,11 @@ namespace xcb
return memory::make_malloc_ptr<monitor_t>(); 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(); auto mon = make_monitor();
mon->x = rect->x; mon->bounds = rect;
mon->y = rect->y;
mon->width = rect->width;
mon->height = rect->height;
mon->index = idx; mon->index = idx;
size_t name_size = name_len + 1; size_t name_size = name_len + 1;
@ -64,20 +61,18 @@ namespace xcb
continue; continue;
} }
char *name = (char *) xcb_randr_get_output_info_name(info); char *monitor_name = (char *) xcb_randr_get_output_info_name(info);
monitors.emplace_back(xcb::make_monitor(monitor_name, info->name_len, i,
xcb_rectangle_t rect = {cir->x, cir->y, cir->width, cir->height}; {cir->x, cir->y, cir->width, cir->height}));
monitors.emplace_back(xcb::make_monitor(name, info->name_len, i, &rect));
free(cir); free(cir);
} }
std::sort(monitors.begin(), monitors.end(), [](std::shared_ptr<monitor_t> m1, std::shared_ptr<monitor_t> m2) -> bool 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; 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 -1;
return 0; return 0;
}); });