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 Memcheck:Leak
match-leak-kinds: definite match-leak-kinds: definite
fun:malloc fun:malloc
obj:/usr/lib/libfontconfig.so.1.9.2 obj:/usr/lib/libfontconfig.so.*
obj:/usr/lib/libfontconfig.so.1.9.2 obj:/usr/lib/libfontconfig.so.*
fun:FcPatternAddDouble fun:FcPatternAddDouble
obj:/usr/lib/libXft.so.2.3.2 obj:/usr/lib/libXft.so.*
obj:/usr/lib/libXft.so.2.3.2 obj:/usr/lib/libXft.so.*
obj:/usr/lib/libXft.so.2.3.2 obj:/usr/lib/libXft.so.*
obj:/usr/lib/libXft.so.2.3.2 obj:/usr/lib/libXft.so.*
fun:XftDefaultHasRender fun:XftDefaultHasRender
fun:XftDefaultSubstitute fun:XftDefaultSubstitute
fun:XftFontMatch fun:XftFontMatch
@ -54,8 +54,8 @@
Memcheck:Leak Memcheck:Leak
match-leak-kinds: definite match-leak-kinds: definite
fun:realloc fun:realloc
obj:/usr/lib/libfontconfig.so.1.9.2 obj:/usr/lib/libfontconfig.so.*
obj:/usr/lib/libfontconfig.so.1.9.2 obj:/usr/lib/libfontconfig.so.*
fun:FcFontRenderPrepare fun:FcFontRenderPrepare
fun:FcFontMatch fun:FcFontMatch
fun:XftFontMatch fun:XftFontMatch
@ -71,15 +71,31 @@
Memcheck:Leak Memcheck:Leak
match-leak-kinds: definite match-leak-kinds: definite
fun:realloc fun:realloc
obj:/usr/lib/libX11.so.6.3.0 obj:/usr/lib/libX11.so.*
obj:/usr/lib/libX11.so.6.3.0 obj:/usr/lib/libX11.so.*
obj:/usr/lib/libX11.so.6.3.0 obj:/usr/lib/libX11.so.*
fun:_XlcCreateLC fun:_XlcCreateLC
fun:_XlcDefaultLoader fun:_XlcDefaultLoader
fun:_XOpenLC fun:_XOpenLC
fun:_XrmInitParseInfo fun:_XrmInitParseInfo
obj:/usr/lib/libX11.so.6.3.0 obj:/usr/lib/libX11.so.*
fun:XrmGetStringDatabase 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 "common.hpp"
#include "utils/string.hpp" #include "utils/string.hpp"
#include "x11/xlib.hpp"
POLYBAR_NS POLYBAR_NS

View File

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

View File

@ -46,7 +46,7 @@ class font_manager {
using make_type = unique_ptr<font_manager>; using make_type = unique_ptr<font_manager>;
static make_type make(); 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();
font_manager(const font_manager& o) = delete; 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); window reconfigure_struts(uint16_t w, uint16_t h, int16_t x, bool bottom = false);
void redraw(); void redraw();
void visibility_notify(xcb_visibility_t state);
}; };
POLYBAR_NS_END 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/extensions/all.hpp"
#include "x11/tray_manager.hpp" #include "x11/tray_manager.hpp"
#include "x11/wm.hpp" #include "x11/wm.hpp"
#include "x11/xutils.hpp"
#if ENABLE_I3 #if ENABLE_I3
#include "utils/i3.hpp" #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)); 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.configure_window(m_opts.window, mask, values);
m_connection.flush(); m_connection.flush();

View File

@ -9,8 +9,6 @@
#include "x11/extensions/all.hpp" #include "x11/extensions/all.hpp"
#include "x11/generic.hpp" #include "x11/generic.hpp"
#include "x11/winspec.hpp" #include "x11/winspec.hpp"
#include "x11/xlib.hpp"
#include "x11/xutils.hpp"
POLYBAR_NS POLYBAR_NS
@ -58,7 +56,7 @@ renderer::renderer(connection& conn, signal_emitter& emitter, const logger& logg
m_depth = 24; 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"); 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_params_gc_t params{};
XCB_AUX_ADD_PARAM(&mask, &params, foreground, colors[i]); XCB_AUX_ADD_PARAM(&mask, &params, foreground, colors[i]);
XCB_AUX_ADD_PARAM(&mask, &params, graphics_exposures, 0); 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_colors.emplace(gc(i), colors[i]);
m_gcontexts.emplace(gc(i), m_connection.generate_id()); m_gcontexts.emplace(gc(i), m_connection.generate_id());
@ -524,7 +522,8 @@ void renderer::debug_hints() {
; ;
// clang-format on // 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); m_connection.map_window(hintwin);
} }
} }

View File

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

View File

@ -5,7 +5,6 @@
#include "utils/math.hpp" #include "utils/math.hpp"
#include "x11/connection.hpp" #include "x11/connection.hpp"
#include "x11/graphics.hpp" #include "x11/graphics.hpp"
#include "x11/xutils.hpp"
#include "modules/meta/base.inl" #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); m_value = std::strtoul(&hex[1], nullptr, 16);
m_color = color_util::premultiply_alpha(m_value);
// 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;
} }
string color::source() const { string color::source() const {

View File

@ -1,3 +1,4 @@
#include <algorithm>
#include <iomanip> #include <iomanip>
#include "errors.hpp" #include "errors.hpp"
@ -6,28 +7,22 @@
#include "utils/string.hpp" #include "utils/string.hpp"
#include "x11/atoms.hpp" #include "x11/atoms.hpp"
#include "x11/connection.hpp" #include "x11/connection.hpp"
#include "x11/xlib.hpp"
#include "x11/xutils.hpp"
POLYBAR_NS POLYBAR_NS
/** /**
* Create instance * Create instance
*/ */
connection::make_type connection::make(xcb_connection_t* conn) { connection::make_type connection::make(Display* display) {
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))));
return static_cast<connection::make_type>( 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));
} }
/** connection::connection(Display* dsp) : base_type(XGetXCBConnection(dsp)), m_display(dsp) {
* Preload required xcb atoms XSetEventQueueOwner(m_display, XCBOwnsEventQueue);
*/
void connection::preload_atoms() { // Preload required xcb atoms {{{
vector<xcb_intern_atom_cookie_t> cookies(memory_util::countof(ATOMS)); vector<xcb_intern_atom_cookie_t> cookies(memory_util::countof(ATOMS));
xcb_intern_atom_reply_t* reply{nullptr}; xcb_intern_atom_reply_t* reply{nullptr};
@ -42,12 +37,9 @@ void connection::preload_atoms() {
free(reply); free(reply);
} }
}
/** // }}}
* Query for X extensions // Query for X extensions {{{
*/
void connection::query_extensions() {
#if WITH_XDAMAGE #if WITH_XDAMAGE
damage_util::query_extension(*this); damage_util::query_extension(*this);
#endif #endif
@ -66,6 +58,45 @@ void connection::query_extensions() {
#if WITH_XKB #if WITH_XKB
xkb_util::query_extension(*this); xkb_util::query_extension(*this);
#endif #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); m_registry.dispatch(evt);
} }
// connection::operator Display*() const {
// return xlib::get_display();
// }
POLYBAR_NS_END POLYBAR_NS_END

View File

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

View File

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

View File

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

View File

@ -5,7 +5,6 @@
#include "x11/connection.hpp" #include "x11/connection.hpp"
#include "x11/tray_client.hpp" #include "x11/tray_client.hpp"
#include "x11/xembed.hpp" #include "x11/xembed.hpp"
#include "x11/xutils.hpp"
POLYBAR_NS 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, x, x);
XCB_AUX_ADD_PARAM(&configure_mask, &configure_params, y, y); 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); m_connection.configure_window_checked(window(), configure_mask, configure_values);
} }

View File

@ -21,7 +21,6 @@
#include "x11/winspec.hpp" #include "x11/winspec.hpp"
#include "x11/wm.hpp" #include "x11/wm.hpp"
#include "x11/xembed.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, width, width);
XCB_AUX_ADD_PARAM(&mask, &params, x, x); 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); 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_tray = win << cw_flush(true);
m_log.info("Tray window: %s", m_connection.id(m_tray)); 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, sibling, m_opts.sibling);
XCB_AUX_ADD_PARAM(&mask, &params, stack_mode, XCB_STACK_MODE_ABOVE); 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); m_connection.configure_window_checked(m_tray, mask, values);
} catch (const exception& err) { } catch (const exception& err) {
auto id = m_connection.id(m_opts.sibling); auto id = m_connection.id(m_opts.sibling);

View File

@ -5,7 +5,7 @@
#include "x11/connection.hpp" #include "x11/connection.hpp"
#include "x11/extensions/randr.hpp" #include "x11/extensions/randr.hpp"
#include "x11/window.hpp" #include "x11/window.hpp"
#include "x11/xutils.hpp" #include "utils/memory.hpp"
POLYBAR_NS 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 root = connection().screen()->root;
auto copy = XCB_COPY_FROM_PARENT; auto copy = XCB_COPY_FROM_PARENT;
uint32_t values[16]{0}; 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); connection().create_window_checked(copy, *this, root, x, y, w, h, 0, copy, copy, mask, values);
return *this; 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, x, x);
XCB_AUX_ADD_PARAM(&mask, &params, y, y); XCB_AUX_ADD_PARAM(&mask, &params, y, y);
xutils::pack_values(mask, &params, values); connection::pack_values(mask, &params, values);
configure_checked(mask, values); configure_checked(mask, values);
return *this; 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, x, x);
XCB_AUX_ADD_PARAM(&mask, &params, y, y); XCB_AUX_ADD_PARAM(&mask, &params, y, y);
xutils::pack_values(mask, &params, values); connection::pack_values(mask, &params, values);
configure_checked(mask, values); configure_checked(mask, values);
return *this; 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 * Trigger redraw by toggling visibility state
*/ */
void window::redraw() { void window::redraw() {
xutils::visibility_notify(connection(), *this, XCB_VISIBILITY_FULLY_OBSCURED); visibility_notify(XCB_VISIBILITY_FULLY_OBSCURED);
xutils::visibility_notify(connection(), *this, XCB_VISIBILITY_UNOBSCURED); visibility_notify(XCB_VISIBILITY_UNOBSCURED);
connection().flush(); 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 POLYBAR_NS_END

View File

@ -2,7 +2,6 @@
#include "x11/connection.hpp" #include "x11/connection.hpp"
#include "x11/winspec.hpp" #include "x11/winspec.hpp"
#include "x11/xutils.hpp"
POLYBAR_NS POLYBAR_NS
@ -33,7 +32,7 @@ xcb_window_t winspec::operator<<(const cw_flush& f) {
m_height = 1; m_height = 1;
} }
xutils::pack_values(m_mask, &m_params, values); connection::pack_values(m_mask, &m_params, values);
if (f.checked) { if (f.checked) {
m_connection.create_window_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 <utility>
#include "utils/factory.hpp" #include "utils/factory.hpp"
#include "x11/xlib.hpp" #include "x11/connection.hpp"
#include "x11/xresources.hpp" #include "x11/xresources.hpp"
POLYBAR_NS POLYBAR_NS
@ -13,7 +13,7 @@ POLYBAR_NS
*/ */
xresource_manager::make_type xresource_manager::make() { xresource_manager::make_type xresource_manager::make() {
return static_cast<xresource_manager::make_type>( 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