polybar/src/x11/xlib.cpp

47 lines
1.2 KiB
C++
Raw Normal View History

2016-11-02 19:22:45 +00:00
#include "x11/xlib.hpp"
#include "utils/factory.hpp"
2016-11-02 19:22:45 +00:00
2016-11-19 05:22:44 +00:00
POLYBAR_NS
2016-11-02 19:22:45 +00:00
namespace xlib {
shared_ptr<Display> g_display_ptr;
shared_ptr<Visual> g_visual_ptr;
shared_ptr<Display> get_display() {
if (!g_display_ptr) {
// g_display_ptr = shared_ptr<Display>(XOpenDisplay(nullptr), bind(XCloseDisplay, placeholders::_1));
g_display_ptr = shared_ptr<Display>(XOpenDisplay(nullptr), factory_util::null_deleter{});
2016-11-25 12:55:15 +00:00
}
return g_display_ptr;
2016-11-02 19:22:45 +00:00
}
shared_ptr<Visual> get_visual(int screen) {
if (!g_visual_ptr) {
XVisualInfo info;
if (XMatchVisualInfo(get_display().get(), screen, 32, TrueColor, &info)) {
2016-12-15 02:30:41 +00:00
g_visual_ptr = shared_ptr<Visual>(info.visual, [=](Visual* v) { XFree(v); });
}
2016-11-02 19:22:45 +00:00
}
return g_visual_ptr;
2016-11-02 19:22:45 +00:00
}
Colormap create_colormap(int screen) {
return XDefaultColormap(get_display().get(), screen);
}
display_lock::display_lock(shared_ptr<Display>&& display) : m_display(forward<decltype(display)>(display)) {
XLockDisplay(m_display.get());
}
display_lock::~display_lock() {
XUnlockDisplay(m_display.get());
}
inline auto make_display_lock() {
return make_unique<display_lock>(get_display());
2016-11-02 19:22:45 +00:00
}
}
2016-11-19 05:22:44 +00:00
POLYBAR_NS_END