refactor(xcb): Namespacing
This commit is contained in:
parent
b8a1dd628e
commit
e1279d6582
@ -39,8 +39,16 @@ namespace xcb
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::shared_ptr<monitor_t> make_monitor();
|
namespace connection
|
||||||
std::shared_ptr<monitor_t> make_monitor(char *name, size_t name_len, int idx, xcb_rectangle_t *rect);
|
{
|
||||||
|
bool check(xcb_connection_t *connection);
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::shared_ptr<monitor_t>> get_monitors(xcb_connection_t *connection, xcb_window_t root);
|
namespace monitor
|
||||||
|
{
|
||||||
|
std::shared_ptr<monitor_t> make_object();
|
||||||
|
std::shared_ptr<monitor_t> make_object(char *name, size_t name_len, int idx, xcb_rectangle_t *rect);
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<monitor_t>> get_list(xcb_connection_t *connection, xcb_window_t root);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ Bar::Bar() : config_path(config::get_bar_path()), opts(std::make_unique<Options>
|
|||||||
} catch (config::MissingValueException &e) {}
|
} catch (config::MissingValueException &e) {}
|
||||||
|
|
||||||
auto monitor_name = config::get<std::string>(this->config_path, "monitor", "");
|
auto monitor_name = config::get<std::string>(this->config_path, "monitor", "");
|
||||||
auto monitors = xcb::get_monitors(x::connection(), x::connection().root());
|
auto monitors = xcb::monitor::get_list(x::connection(), x::connection().root());
|
||||||
|
|
||||||
// In case we're not connected to X, we'll just ignore the monitor
|
// In case we're not connected to X, we'll just ignore the monitor
|
||||||
if (!monitors.empty()) {
|
if (!monitors.empty()) {
|
||||||
@ -77,7 +77,7 @@ Bar::Bar() : config_path(config::get_bar_path()), opts(std::make_unique<Options>
|
|||||||
|
|
||||||
// Create an empty monitor as fallback
|
// Create an empty monitor as fallback
|
||||||
if (!this->opts->monitor)
|
if (!this->opts->monitor)
|
||||||
this->opts->monitor = xcb::make_monitor();
|
this->opts->monitor = xcb::monitor::make_object();
|
||||||
|
|
||||||
this->opts->offset_x = config::get<int>(this->config_path, "offset_x", defaults.offset_x);
|
this->opts->offset_x = config::get<int>(this->config_path, "offset_x", defaults.offset_x);
|
||||||
this->opts->offset_y = config::get<int>(this->config_path, "offset_y", defaults.offset_y);
|
this->opts->offset_y = config::get<int>(this->config_path, "offset_y", defaults.offset_y);
|
||||||
|
@ -1,15 +1,60 @@
|
|||||||
#include "utils/xcb.hpp"
|
#include "utils/xcb.hpp"
|
||||||
#include "utils/memory.hpp"
|
#include "utils/memory.hpp"
|
||||||
|
#include "services/logger.hpp"
|
||||||
|
|
||||||
namespace xcb
|
namespace xcb
|
||||||
{
|
{
|
||||||
std::shared_ptr<monitor_t> make_monitor() {
|
namespace connection
|
||||||
|
{
|
||||||
|
bool check(xcb_connection_t *connection)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
|
if ((err = xcb_connection_has_error(connection)) == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
log_error("xcb: The server closed the connection");
|
||||||
|
|
||||||
|
switch (err) {
|
||||||
|
case XCB_CONN_ERROR:
|
||||||
|
log_error("- socket, pipe or stream error");
|
||||||
|
break;
|
||||||
|
case XCB_CONN_CLOSED_EXT_NOTSUPPORTED:
|
||||||
|
log_error("- unsupported extension");
|
||||||
|
break;
|
||||||
|
case XCB_CONN_CLOSED_MEM_INSUFFICIENT:
|
||||||
|
log_error("- not enough memory");
|
||||||
|
break;
|
||||||
|
case XCB_CONN_CLOSED_REQ_LEN_EXCEED:
|
||||||
|
log_error("- request length exceeded");
|
||||||
|
break;
|
||||||
|
case XCB_CONN_CLOSED_PARSE_ERR:
|
||||||
|
log_error("- can't parse display string");
|
||||||
|
break;
|
||||||
|
case XCB_CONN_CLOSED_INVALID_SCREEN:
|
||||||
|
log_error("- invalid screen");
|
||||||
|
break;
|
||||||
|
case XCB_CONN_CLOSED_FDPASSING_FAILED:
|
||||||
|
log_error("- failed to pass FD");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
log_error("- unknown error");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace monitor
|
||||||
|
{
|
||||||
|
std::shared_ptr<monitor_t> make_object() {
|
||||||
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_object(char *name, size_t name_len, int idx, xcb_rectangle_t rect)
|
||||||
{
|
{
|
||||||
auto mon = make_monitor();
|
auto mon = make_object();
|
||||||
|
|
||||||
mon->bounds = rect;
|
mon->bounds = rect;
|
||||||
mon->index = idx;
|
mon->index = idx;
|
||||||
@ -23,7 +68,7 @@ namespace xcb
|
|||||||
return mon;
|
return mon;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::shared_ptr<monitor_t>> get_monitors(xcb_connection_t *connection, xcb_window_t root)
|
std::vector<std::shared_ptr<monitor_t>> get_list(xcb_connection_t *connection, xcb_window_t root)
|
||||||
{
|
{
|
||||||
std::vector<std::shared_ptr<monitor_t>> monitors;
|
std::vector<std::shared_ptr<monitor_t>> monitors;
|
||||||
|
|
||||||
@ -62,7 +107,7 @@ namespace xcb
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *monitor_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,
|
monitors.emplace_back(make_object(monitor_name, info->name_len, i,
|
||||||
{cir->x, cir->y, cir->width, cir->height}));
|
{cir->x, cir->y, cir->width, cir->height}));
|
||||||
|
|
||||||
free(cir);
|
free(cir);
|
||||||
@ -79,4 +124,5 @@ namespace xcb
|
|||||||
|
|
||||||
return monitors;
|
return monitors;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user