Skip to content

Commit

Permalink
refactor(x11): Merge xlib/xutils with connection
Browse files Browse the repository at this point in the history
  • Loading branch information
jaagr committed Dec 31, 2016
1 parent 22b93a1 commit 210695d
Show file tree
Hide file tree
Showing 23 changed files with 162 additions and 277 deletions.
40 changes: 28 additions & 12 deletions .valgrind-suppressions
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
...
...
}
1 change: 0 additions & 1 deletion include/utils/color.hpp
Expand Up @@ -4,7 +4,6 @@

#include "common.hpp"
#include "utils/string.hpp"
#include "x11/xlib.hpp"

POLYBAR_NS

Expand Down
46 changes: 30 additions & 16 deletions include/x11/connection.hpp
@@ -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>
Expand All @@ -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>... {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
static make_type make(Display* display = nullptr);

template <typename... Args>
explicit connection(Args&&... args) : base_type(forward<Args>(args)...) {}
explicit connection(Display* dsp);
~connection();

const connection& operator=(const connection& o) {
return o;
}

// operator Display*() const;

void preload_atoms();
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 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;

Expand Down Expand Up @@ -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};
};
Expand Down
2 changes: 1 addition & 1 deletion include/x11/fonts.hpp
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions include/x11/window.hpp
Expand Up @@ -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
30 changes: 0 additions & 30 deletions include/x11/xlib.hpp

This file was deleted.

32 changes: 0 additions & 32 deletions include/x11/xutils.hpp

This file was deleted.

3 changes: 1 addition & 2 deletions src/components/bar.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down
9 changes: 4 additions & 5 deletions src/components/renderer.cpp
Expand Up @@ -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

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}
}
Expand Down
11 changes: 3 additions & 8 deletions src/main.cpp
Expand Up @@ -16,7 +16,6 @@
#include "utils/process.hpp"
#include "x11/connection.hpp"
#include "x11/tray_manager.hpp"
#include "x11/xutils.hpp"

using namespace polybar;

Expand Down Expand Up @@ -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);

//==================================================
Expand Down
1 change: 0 additions & 1 deletion src/modules/xbacklight.cpp
Expand Up @@ -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"

Expand Down
9 changes: 1 addition & 8 deletions src/x11/color.cpp
Expand Up @@ -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 {
Expand Down

0 comments on commit 210695d

Please sign in to comment.