1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-25 13:55:47 -05:00

refactor(x11): Merge xlib/xutils with connection

This commit is contained in:
Michael Carlberg 2016-12-31 07:39:50 +01:00
parent 22b93a1167
commit 210695d377
23 changed files with 163 additions and 278 deletions

View file

@ -20,13 +20,13 @@
Memcheck:Leak
match-leak-kinds: definite
fun:malloc
obj:/usr/lib/libfontconfig.so.1.9.2
obj:/usr/lib/libfontconfig.so.1.9.2
obj:/usr/lib/libfontconfig.so.*
obj:/usr/lib/libfontconfig.so.*
fun:FcPatternAddDouble
obj:/usr/lib/libXft.so.2.3.2
obj:/usr/lib/libXft.so.2.3.2
obj:/usr/lib/libXft.so.2.3.2
obj:/usr/lib/libXft.so.2.3.2
obj:/usr/lib/libXft.so.*
obj:/usr/lib/libXft.so.*
obj:/usr/lib/libXft.so.*
obj:/usr/lib/libXft.so.*
fun:XftDefaultHasRender
fun:XftDefaultSubstitute
fun:XftFontMatch
@ -54,8 +54,8 @@
Memcheck:Leak
match-leak-kinds: definite
fun:realloc
obj:/usr/lib/libfontconfig.so.1.9.2
obj:/usr/lib/libfontconfig.so.1.9.2
obj:/usr/lib/libfontconfig.so.*
obj:/usr/lib/libfontconfig.so.*
fun:FcFontRenderPrepare
fun:FcFontMatch
fun:XftFontMatch
@ -71,15 +71,31 @@
Memcheck:Leak
match-leak-kinds: definite
fun:realloc
obj:/usr/lib/libX11.so.6.3.0
obj:/usr/lib/libX11.so.6.3.0
obj:/usr/lib/libX11.so.6.3.0
obj:/usr/lib/libX11.so.*
obj:/usr/lib/libX11.so.*
obj:/usr/lib/libX11.so.*
fun:_XlcCreateLC
fun:_XlcDefaultLoader
fun:_XOpenLC
fun:_XrmInitParseInfo
obj:/usr/lib/libX11.so.6.3.0
obj:/usr/lib/libX11.so.*
fun:XrmGetStringDatabase
...
...
}
{
xft conditional jump
Memcheck:Cond
obj:/usr/lib/libfreetype.so.*
obj:/usr/lib/libfreetype.so.*
fun:FT_Outline_Decompose
obj:/usr/lib/libfreetype.so.*
obj:/usr/lib/libfreetype.so.*
obj:/usr/lib/libfreetype.so.*
obj:/usr/lib/libfreetype.so.*
obj:/usr/lib/libfreetype.so.*
fun:XftFontLoadGlyphs
fun:XftGlyphExtents
...
...
}

View file

@ -4,7 +4,6 @@
#include "common.hpp"
#include "utils/string.hpp"
#include "x11/xlib.hpp"
POLYBAR_NS

View file

@ -1,5 +1,8 @@
#pragma once
#include <X11/X.h>
#include <X11/Xlib-xcb.h>
#include <X11/Xutil.h>
#include <cstdlib>
#include <xpp/core.hpp>
#include <xpp/generic/factory.hpp>
@ -15,6 +18,19 @@
POLYBAR_NS
namespace detail {
class displaylock {
public:
explicit displaylock(Display* display) : m_display(forward<decltype(display)>(display)) {
XLockDisplay(m_display);
}
~displaylock() {
XUnlockDisplay(m_display);
}
protected:
Display* m_display;
};
template <typename Connection, typename... Extensions>
class interfaces : public xpp::x::extension::interface<interfaces<Connection, Extensions...>, Connection>,
public Extensions::template interface<interfaces<Connection, Extensions...>, Connection>... {
@ -44,10 +60,6 @@ namespace detail {
virtual ~connection_base() {}
const Derived& operator=(const Derived& o) {
return o;
}
void operator()(const shared_ptr<xcb_generic_error_t>& error) const {
check<xpp::x::extension, Extensions...>(error);
}
@ -59,7 +71,7 @@ namespace detail {
template <typename WindowType = xcb_window_t>
WindowType root() const {
using make = xpp::generic::factory::make<Derived, xcb_window_t, WindowType>;
using make = xpp::generic::factory::make<connection_base, xcb_window_t, WindowType>;
return make()(*this, m_root_window);
}
@ -102,32 +114,32 @@ namespace detail {
class connection : public detail::connection_base<connection&, XPP_EXTENSION_LIST> {
public:
using base_type = detail::connection_base<connection&, XPP_EXTENSION_LIST>;
using make_type = connection&;
static make_type make(xcb_connection_t* conn = nullptr);
template <typename... Args>
explicit connection(Args&&... args) : base_type(forward<Args>(args)...) {}
using make_type = connection&;
static make_type make(Display* display = nullptr);
explicit connection(Display* dsp);
~connection();
const connection& operator=(const connection& o) {
return o;
}
// operator Display*() const;
static void pack_values(uint32_t mask, const uint32_t* src, uint32_t* dest);
static void pack_values(uint32_t mask, const xcb_params_cw_t* src, uint32_t* dest);
static void pack_values(uint32_t mask, const xcb_params_gc_t* src, uint32_t* dest);
static void pack_values(uint32_t mask, const xcb_params_configure_window_t* src, uint32_t* dest);
void preload_atoms();
void query_extensions();
operator Display*() const;
Visual* visual(uint8_t depth = 32U);
xcb_screen_t* screen(bool realloc = false);
string id(xcb_window_t w) const;
xcb_screen_t* screen(bool realloc = false);
void ensure_event_mask(xcb_window_t win, uint32_t event);
void clear_event_mask(xcb_window_t win);
shared_ptr<xcb_client_message_event_t> make_client_message(xcb_atom_t type, xcb_window_t target) const;
void send_client_message(const shared_ptr<xcb_client_message_event_t>& message, xcb_window_t target,
uint32_t event_mask = 0xFFFFFF, bool propagate = false) const;
@ -169,6 +181,8 @@ class connection : public detail::connection_base<connection&, XPP_EXTENSION_LIS
}
protected:
Display* m_display{nullptr};
map<uint8_t, Visual*> m_visual;
registry m_registry{*this};
xcb_screen_t* m_screen{nullptr};
};

View file

@ -46,7 +46,7 @@ class font_manager {
using make_type = unique_ptr<font_manager>;
static make_type make();
explicit font_manager(connection& conn, const logger& logger, Display* dsp, Visual* vis, Colormap&& cm);
explicit font_manager(connection& conn, const logger& logger);
~font_manager();
font_manager(const font_manager& o) = delete;

View file

@ -27,6 +27,8 @@ class window : public xpp::window<connection&> {
window reconfigure_struts(uint16_t w, uint16_t h, int16_t x, bool bottom = false);
void redraw();
void visibility_notify(xcb_visibility_t state);
};
POLYBAR_NS_END

View file

@ -1,30 +0,0 @@
#pragma once
#include <X11/Xutil.h>
#include "common.hpp"
POLYBAR_NS
namespace xlib {
namespace detail {
/**
* RAII wrapper for Xlib display locking
*/
class display_lock {
public:
explicit display_lock(Display* display);
~display_lock();
protected:
Display* m_display;
};
}
Display* get_display();
Visual* get_visual(int screen = 0, uint8_t depth = 32);
Colormap create_colormap(int screen = 0);
inline auto make_display_lock();
}
POLYBAR_NS_END

View file

@ -1,32 +0,0 @@
#pragma once
#include <X11/Xlib-xcb.h>
#include <xcb/xcb_util.h>
#include "common.hpp"
POLYBAR_NS
class connection;
class config;
namespace xutils {
struct xcb_connection_deleter {
void operator()(xcb_connection_t* c) {
xcb_disconnect(c);
}
};
xcb_connection_t* get_connection();
void pack_values(uint32_t mask, const uint32_t* src, uint32_t* dest);
void pack_values(uint32_t mask, const xcb_params_cw_t* src, uint32_t* dest);
void pack_values(uint32_t mask, const xcb_params_gc_t* src, uint32_t* dest);
void pack_values(uint32_t mask, const xcb_params_configure_window_t* src, uint32_t* dest);
void visibility_notify(connection& conn, const xcb_window_t& win, xcb_visibility_t state);
void compton_shadow_exclude(connection& conn, const xcb_window_t& win);
}
POLYBAR_NS_END

View file

@ -20,7 +20,6 @@
#include "x11/extensions/all.hpp"
#include "x11/tray_manager.hpp"
#include "x11/wm.hpp"
#include "x11/xutils.hpp"
#if ENABLE_I3
#include "utils/i3.hpp"
@ -712,7 +711,7 @@ bool bar::on(const sig_ui::tick&) {
params.y = std::max(params.y, static_cast<int32_t>(m_opts.shade_pos.y));
}
xutils::pack_values(mask, &params, values);
connection::pack_values(mask, &params, values);
m_connection.configure_window(m_opts.window, mask, values);
m_connection.flush();

View file

@ -9,8 +9,6 @@
#include "x11/extensions/all.hpp"
#include "x11/generic.hpp"
#include "x11/winspec.hpp"
#include "x11/xlib.hpp"
#include "x11/xutils.hpp"
POLYBAR_NS
@ -58,7 +56,7 @@ renderer::renderer(connection& conn, signal_emitter& emitter, const logger& logg
m_depth = 24;
m_fontmanager->set_visual(xlib::get_visual(m_connection.default_screen(), m_depth));
m_fontmanager->set_visual(m_connection.visual(m_depth));
}
m_log.trace("renderer: Allocate colormap");
@ -112,7 +110,7 @@ renderer::renderer(connection& conn, signal_emitter& emitter, const logger& logg
xcb_params_gc_t params{};
XCB_AUX_ADD_PARAM(&mask, &params, foreground, colors[i]);
XCB_AUX_ADD_PARAM(&mask, &params, graphics_exposures, 0);
xutils::pack_values(mask, &params, value_list);
connection::pack_values(mask, &params, value_list);
m_colors.emplace(gc(i), colors[i]);
m_gcontexts.emplace(gc(i), m_connection.generate_id());
@ -524,7 +522,8 @@ void renderer::debug_hints() {
;
// clang-format on
xutils::compton_shadow_exclude(m_connection, hintwin);
const uint32_t shadow{0};
m_connection.change_property(XCB_PROP_MODE_REPLACE, hintwin, _COMPTON_SHADOW, XCB_ATOM_CARDINAL, 32, 1, &shadow);
m_connection.map_window(hintwin);
}
}

View file

@ -16,7 +16,6 @@
#include "utils/process.hpp"
#include "x11/connection.hpp"
#include "x11/tray_manager.hpp"
#include "x11/xutils.hpp"
using namespace polybar;
@ -71,18 +70,14 @@ int main(int argc, char** argv) {
// Connect to X server
//==================================================
XInitThreads();
Display* xdisplay{XOpenDisplay(nullptr)};
// Store the xcb connection pointer with a disconnect deleter
unique_ptr<xcb_connection_t, xutils::xcb_connection_deleter> xcbconn{xutils::get_connection()};
if (!xcbconn) {
if (xdisplay == nullptr) {
logger.err("A connection to X could not be established... ");
return EXIT_FAILURE;
}
connection& conn{connection::make(&*xcbconn)};
conn.preload_atoms();
conn.query_extensions();
connection& conn{connection::make(xdisplay)};
conn.ensure_event_mask(conn.root(), XCB_EVENT_MASK_PROPERTY_CHANGE);
//==================================================

View file

@ -5,7 +5,6 @@
#include "utils/math.hpp"
#include "x11/connection.hpp"
#include "x11/graphics.hpp"
#include "x11/xutils.hpp"
#include "modules/meta/base.inl"

View file

@ -20,14 +20,7 @@ color::color(string hex) : m_source(hex) {
}
m_value = std::strtoul(&hex[1], nullptr, 16);
// Premultiply alpha
auto a = color_util::alpha_channel(m_value);
auto r = color_util::red_channel(m_value) * a / 255;
auto g = color_util::green_channel(m_value) * a / 255;
auto b = color_util::blue_channel(m_value) * a / 255;
m_color = (a << 24) | (r << 16) | (g << 8) | b;
m_color = color_util::premultiply_alpha(m_value);
}
string color::source() const {

View file

@ -1,3 +1,4 @@
#include <algorithm>
#include <iomanip>
#include "errors.hpp"
@ -6,28 +7,22 @@
#include "utils/string.hpp"
#include "x11/atoms.hpp"
#include "x11/connection.hpp"
#include "x11/xlib.hpp"
#include "x11/xutils.hpp"
POLYBAR_NS
/**
* Create instance
*/
connection::make_type connection::make(xcb_connection_t* conn) {
if (conn == nullptr) {
conn = xutils::get_connection();
}
// return static_cast<connection::make_type>(*factory_util::singleton<std::remove_reference_t<connection::make_type>>(
// conn, file_util::make_file_descriptor(xcb_get_file_descriptor(conn))));
connection::make_type connection::make(Display* display) {
return static_cast<connection::make_type>(
*factory_util::singleton<std::remove_reference_t<connection::make_type>>(conn));
*factory_util::singleton<std::remove_reference_t<connection::make_type>>(display));
}
/**
* Preload required xcb atoms
*/
void connection::preload_atoms() {
connection::connection(Display* dsp) : base_type(XGetXCBConnection(dsp)), m_display(dsp) {
XSetEventQueueOwner(m_display, XCBOwnsEventQueue);
// Preload required xcb atoms {{{
vector<xcb_intern_atom_cookie_t> cookies(memory_util::countof(ATOMS));
xcb_intern_atom_reply_t* reply{nullptr};
@ -42,12 +37,9 @@ void connection::preload_atoms() {
free(reply);
}
}
/**
* Query for X extensions
*/
void connection::query_extensions() {
// }}}
// Query for X extensions {{{
#if WITH_XDAMAGE
damage_util::query_extension(*this);
#endif
@ -66,6 +58,45 @@ void connection::query_extensions() {
#if WITH_XKB
xkb_util::query_extension(*this);
#endif
// }}}
}
connection::~connection() {
disconnect();
std::for_each(m_visual.begin(), m_visual.end(), [=](pair<uint8_t, Visual*> p) { XFree(p.second); });
m_visual.clear();
}
void connection::pack_values(uint32_t mask, const uint32_t* src, uint32_t* dest) {
for (; mask; mask >>= 1, src++) {
if (mask & 1) {
*dest++ = *src;
}
}
}
void connection::pack_values(uint32_t mask, const xcb_params_cw_t* src, uint32_t* dest) {
pack_values(mask, reinterpret_cast<const uint32_t*>(src), dest);
}
void connection::pack_values(uint32_t mask, const xcb_params_gc_t* src, uint32_t* dest) {
pack_values(mask, reinterpret_cast<const uint32_t*>(src), dest);
}
void connection::pack_values(uint32_t mask, const xcb_params_configure_window_t* src, uint32_t* dest) {
pack_values(mask, reinterpret_cast<const uint32_t*>(src), dest);
}
connection::operator Display*() const {
return m_display;
}
Visual* connection::visual(uint8_t depth) {
auto visual_it = m_visual.find(depth);
if (visual_it == m_visual.end()) {
XVisualInfo info{};
if (XMatchVisualInfo(*this, default_screen(), depth, TrueColor, &info)) {
visual_it = m_visual.emplace_hint(visual_it, depth, info.visual);
}
}
return visual_it->second;
}
/**
@ -184,8 +215,4 @@ void connection::dispatch_event(const shared_ptr<xcb_generic_event_t>& evt) cons
m_registry.dispatch(evt);
}
// connection::operator Display*() const {
// return xlib::get_display();
// }
POLYBAR_NS_END

View file

@ -1,6 +1,6 @@
#include "x11/ewmh.hpp"
#include "components/types.hpp"
#include "x11/xutils.hpp"
#include "x11/connection.hpp"
POLYBAR_NS
@ -10,8 +10,7 @@ namespace ewmh_util {
if (!g_connection) {
g_connection = memory_util::make_malloc_ptr<xcb_ewmh_connection_t>(
[=](xcb_ewmh_connection_t* c) { xcb_ewmh_connection_wipe(c); });
xcb_ewmh_init_atoms_replies(
&*g_connection, xcb_ewmh_init_atoms(xutils::get_connection(), &*g_connection), nullptr);
xcb_ewmh_init_atoms_replies(&*g_connection, xcb_ewmh_init_atoms(connection::make(), &*g_connection), nullptr);
}
return g_connection;
}

View file

@ -1,5 +1,3 @@
#include <X11/Xlib-xcb.h>
#include "components/logger.hpp"
#include "errors.hpp"
#include "utils/color.hpp"
@ -8,8 +6,6 @@
#include "x11/connection.hpp"
#include "x11/draw.hpp"
#include "x11/fonts.hpp"
#include "x11/xlib.hpp"
#include "x11/xutils.hpp"
POLYBAR_NS
@ -17,11 +13,14 @@ void font_ref::_deleter::operator()(font_ref* font) {
font->glyph_widths.clear();
font->width_lut.clear();
if (font->xft != nullptr) {
XftFontClose(&*xlib::get_display(), font->xft);
}
if (font->ptr != XCB_NONE) {
xcb_close_font(&*xutils::get_connection(), font->ptr);
if (font->xft != nullptr || font->ptr != XCB_NONE) {
auto& conn = connection::make();
if (font->xft != nullptr) {
XftFontClose(conn, font->xft);
}
if (font->ptr != XCB_NONE) {
xcb_close_font(conn, font->ptr);
}
}
delete font;
}
@ -30,16 +29,15 @@ void font_ref::_deleter::operator()(font_ref* font) {
* Create instance
*/
font_manager::make_type font_manager::make() {
return factory_util::unique<font_manager>(
connection::make(), logger::make(), xlib::get_display(), xlib::get_visual(), xlib::create_colormap());
return factory_util::unique<font_manager>(connection::make(), logger::make());
}
font_manager::font_manager(connection& conn, const logger& logger, Display* dsp, Visual* vis, Colormap&& cm)
font_manager::font_manager(connection& conn, const logger& logger)
: m_connection(conn)
, m_logger(logger)
, m_display(forward<decltype(dsp)>(dsp))
, m_visual(forward<decltype(vis)>(vis))
, m_colormap(forward<decltype(cm)>(cm)) {
, m_display(m_connection)
, m_visual(m_connection.visual())
, m_colormap(XDefaultColormap(m_display, m_connection.default_screen())) {
if (!XftInit(nullptr) || !XftInitFtLibrary()) {
throw application_error("Could not initialize Xft library");
}

View file

@ -6,7 +6,6 @@
#include "x11/atoms.hpp"
#include "x11/connection.hpp"
#include "x11/graphics.hpp"
#include "x11/xutils.hpp"
POLYBAR_NS
@ -66,7 +65,7 @@ namespace graphics_util {
uint32_t values[32];
XCB_AUX_ADD_PARAM(&mask, &params, graphics_exposures, 1);
xutils::pack_values(mask, &params, values);
connection::pack_values(mask, &params, values);
*gc = conn.generate_id();
conn.create_gc_checked(*gc, drawable, mask, values);

View file

@ -5,7 +5,6 @@
#include "x11/connection.hpp"
#include "x11/tray_client.hpp"
#include "x11/xembed.hpp"
#include "x11/xutils.hpp"
POLYBAR_NS
@ -95,7 +94,7 @@ void tray_client::reconfigure(int16_t x, int16_t y) const {
XCB_AUX_ADD_PARAM(&configure_mask, &configure_params, x, x);
XCB_AUX_ADD_PARAM(&configure_mask, &configure_params, y, y);
xutils::pack_values(configure_mask, &configure_params, configure_values);
connection::pack_values(configure_mask, &configure_params, configure_values);
m_connection.configure_window_checked(window(), configure_mask, configure_values);
}

View file

@ -21,7 +21,6 @@
#include "x11/winspec.hpp"
#include "x11/wm.hpp"
#include "x11/xembed.hpp"
#include "x11/xutils.hpp"
// ====================================================================================================
//
@ -366,7 +365,7 @@ void tray_manager::reconfigure_window() {
XCB_AUX_ADD_PARAM(&mask, &params, width, width);
XCB_AUX_ADD_PARAM(&mask, &params, x, x);
xutils::pack_values(mask, &params, values);
connection::pack_values(mask, &params, values);
m_connection.configure_window_checked(m_tray, mask, values);
}
@ -561,7 +560,8 @@ void tray_manager::create_window() {
m_tray = win << cw_flush(true);
m_log.info("Tray window: %s", m_connection.id(m_tray));
xutils::compton_shadow_exclude(m_connection, m_tray);
const uint32_t shadow{0};
m_connection.change_property(XCB_PROP_MODE_REPLACE, m_tray, _COMPTON_SHADOW, XCB_ATOM_CARDINAL, 32, 1, &shadow);
}
/**
@ -617,7 +617,7 @@ void tray_manager::restack_window() {
XCB_AUX_ADD_PARAM(&mask, &params, sibling, m_opts.sibling);
XCB_AUX_ADD_PARAM(&mask, &params, stack_mode, XCB_STACK_MODE_ABOVE);
xutils::pack_values(mask, &params, values);
connection::pack_values(mask, &params, values);
m_connection.configure_window_checked(m_tray, mask, values);
} catch (const exception& err) {
auto id = m_connection.id(m_opts.sibling);

View file

@ -5,7 +5,7 @@
#include "x11/connection.hpp"
#include "x11/extensions/randr.hpp"
#include "x11/window.hpp"
#include "x11/xutils.hpp"
#include "utils/memory.hpp"
POLYBAR_NS
@ -25,7 +25,7 @@ window window::create_checked(int16_t x, int16_t y, uint16_t w, uint16_t h, uint
auto root = connection().screen()->root;
auto copy = XCB_COPY_FROM_PARENT;
uint32_t values[16]{0};
xutils::pack_values(mask, p, values);
connection::pack_values(mask, p, values);
connection().create_window_checked(copy, *this, root, x, y, w, h, 0, copy, copy, mask, values);
return *this;
@ -60,7 +60,7 @@ window window::reconfigure_geom(uint16_t w, uint16_t h, int16_t x, int16_t y) {
XCB_AUX_ADD_PARAM(&mask, &params, x, x);
XCB_AUX_ADD_PARAM(&mask, &params, y, y);
xutils::pack_values(mask, &params, values);
connection::pack_values(mask, &params, values);
configure_checked(mask, values);
return *this;
@ -77,7 +77,7 @@ window window::reconfigure_pos(int16_t x, int16_t y) {
XCB_AUX_ADD_PARAM(&mask, &params, x, x);
XCB_AUX_ADD_PARAM(&mask, &params, y, y);
xutils::pack_values(mask, &params, values);
connection::pack_values(mask, &params, values);
configure_checked(mask, values);
return *this;
@ -111,9 +111,22 @@ window window::reconfigure_struts(uint16_t w, uint16_t h, int16_t x, bool bottom
* Trigger redraw by toggling visibility state
*/
void window::redraw() {
xutils::visibility_notify(connection(), *this, XCB_VISIBILITY_FULLY_OBSCURED);
xutils::visibility_notify(connection(), *this, XCB_VISIBILITY_UNOBSCURED);
visibility_notify(XCB_VISIBILITY_FULLY_OBSCURED);
visibility_notify(XCB_VISIBILITY_UNOBSCURED);
connection().flush();
}
/**
* Send visibility notify event
*/
void window::visibility_notify(xcb_visibility_t state) {
auto notify = memory_util::make_malloc_ptr<xcb_visibility_notify_event_t, 32_z>();
notify->response_type = XCB_VISIBILITY_NOTIFY;
notify->window = *this;
notify->state = state;
uint32_t mask{XCB_EVENT_MASK_NO_EVENT};
connection().send_event(false, *this, mask, reinterpret_cast<const char*>(notify.get()));
}
POLYBAR_NS_END

View file

@ -2,7 +2,6 @@
#include "x11/connection.hpp"
#include "x11/winspec.hpp"
#include "x11/xutils.hpp"
POLYBAR_NS
@ -33,7 +32,7 @@ xcb_window_t winspec::operator<<(const cw_flush& f) {
m_height = 1;
}
xutils::pack_values(m_mask, &m_params, values);
connection::pack_values(m_mask, &m_params, values);
if (f.checked) {
m_connection.create_window_checked(

View file

@ -1,44 +0,0 @@
#include <X11/X.h>
#include "utils/factory.hpp"
#include "x11/xlib.hpp"
POLYBAR_NS
namespace xlib {
namespace detail {
display_lock::display_lock(Display* display) : m_display(forward<decltype(display)>(display)) {
XLockDisplay(m_display);
}
display_lock::~display_lock() {
XUnlockDisplay(m_display);
}
}
Display* get_display() {
static Display* display{XOpenDisplay(nullptr)};
return display;
}
Visual* get_visual(int screen, uint8_t depth) {
static shared_ptr<Visual> visual;
if (!visual) {
XVisualInfo info{};
if (XMatchVisualInfo(get_display(), screen, depth, TrueColor, &info)) {
visual = shared_ptr<Visual>(info.visual, [=](Visual* v) { XFree(v); });
}
}
return &*visual;
}
Colormap create_colormap(int screen) {
return XDefaultColormap(get_display(), screen);
}
inline auto make_display_lock() {
return make_unique<detail::display_lock>(get_display());
}
}
POLYBAR_NS_END

View file

@ -3,7 +3,7 @@
#include <utility>
#include "utils/factory.hpp"
#include "x11/xlib.hpp"
#include "x11/connection.hpp"
#include "x11/xresources.hpp"
POLYBAR_NS
@ -13,7 +13,7 @@ POLYBAR_NS
*/
xresource_manager::make_type xresource_manager::make() {
return static_cast<xresource_manager::make_type>(
*factory_util::singleton<std::remove_reference_t<xresource_manager::make_type>>(xlib::get_display()));
*factory_util::singleton<std::remove_reference_t<xresource_manager::make_type>>(connection::make()));
}
/**

View file

@ -1,59 +0,0 @@
#include <xcb/xcb.h>
#include "components/config.hpp"
#include "utils/memory.hpp"
#include "x11/atoms.hpp"
#include "x11/connection.hpp"
#include "x11/xlib.hpp"
#include "x11/xutils.hpp"
POLYBAR_NS
namespace xutils {
xcb_connection_t* get_connection() {
static xcb_connection_t* connection;
if (!connection) {
auto display = xlib::get_display();
if (display != nullptr) {
XSetEventQueueOwner(display, XCBOwnsEventQueue);
connection = XGetXCBConnection(xlib::get_display());
}
}
return connection;
}
void pack_values(uint32_t mask, const uint32_t* src, uint32_t* dest) {
for (; mask; mask >>= 1, src++) {
if (mask & 1) {
*dest++ = *src;
}
}
}
void pack_values(uint32_t mask, const xcb_params_cw_t* src, uint32_t* dest) {
xutils::pack_values(mask, reinterpret_cast<const uint32_t*>(src), dest);
}
void pack_values(uint32_t mask, const xcb_params_gc_t* src, uint32_t* dest) {
xutils::pack_values(mask, reinterpret_cast<const uint32_t*>(src), dest);
}
void pack_values(uint32_t mask, const xcb_params_configure_window_t* src, uint32_t* dest) {
xutils::pack_values(mask, reinterpret_cast<const uint32_t*>(src), dest);
}
void visibility_notify(connection& conn, const xcb_window_t& win, xcb_visibility_t state) {
auto notify = memory_util::make_malloc_ptr<xcb_visibility_notify_event_t, 32_z>();
notify->response_type = XCB_VISIBILITY_NOTIFY;
notify->window = win;
notify->state = state;
conn.send_event(true, win, XCB_EVENT_MASK_NO_EVENT, reinterpret_cast<const char*>(&*notify));
}
void compton_shadow_exclude(connection& conn, const xcb_window_t& win) {
const uint32_t shadow{0};
conn.change_property(XCB_PROP_MODE_REPLACE, win, _COMPTON_SHADOW, XCB_ATOM_CARDINAL, 32, 1, &shadow);
}
}
POLYBAR_NS_END