diff --git a/include/components/x11/randr.hpp b/include/components/x11/randr.hpp index 4eb82ea9..b81df11e 100644 --- a/include/components/x11/randr.hpp +++ b/include/components/x11/randr.hpp @@ -74,28 +74,29 @@ namespace randr_util { inline void get_backlight_range(connection& conn, const monitor_t& mon, backlight_values& dst) { auto reply = conn.query_output_property(mon->randr_output, Backlight); + dst.min = 0; + dst.max = 0; + if (!reply->range || reply->length != 2) reply = conn.query_output_property(mon->randr_output, BACKLIGHT); - if (!reply->range || reply->length != 2) return; auto range = reply.valid_values().begin(); - dst.min = *range++; - dst.max = *range; + dst.min = static_cast(*range++); + dst.max = static_cast(*range); } inline void get_backlight_value(connection& conn, const monitor_t& mon, backlight_values& dst) { auto reply = conn.get_output_property(mon->randr_output, Backlight, XCB_ATOM_NONE, 0, 4, 0, 0); - if (!reply->num_items) + if (reply->num_items != 1 || reply->format != 32 || reply->type != XCB_ATOM_INTEGER) reply = conn.get_output_property(mon->randr_output, BACKLIGHT, XCB_ATOM_NONE, 0, 4, 0, 0); - - if(!reply->num_items) - return; - - dst.val = *reply.data().begin(); + if (reply->num_items == 1 && reply->format == 32 && reply->type == XCB_ATOM_INTEGER) + dst.val = *reinterpret_cast(xcb_randr_get_output_property_data(reply.get().get())); + else + dst.val = 0; } } diff --git a/include/modules/xbacklight.hpp b/include/modules/xbacklight.hpp index ace3d540..609aa814 100644 --- a/include/modules/xbacklight.hpp +++ b/include/modules/xbacklight.hpp @@ -111,7 +111,7 @@ namespace modules { // Query for the new backlight value auto& bl = m_output->backlight; randr_util::get_backlight_value(m_connection, m_output, bl); - m_percentage = math_util::percentage(bl.val, bl.min, bl.max); + m_percentage = math_util::percentage(bl.val, bl.min, bl.max); // Update label tokens if (m_label) {