1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-03 04:33:30 -05:00
polybar/include/common.hpp
Michael Carlberg 20350e5fe6 fix: Make sure clickable areas are aligned properly
- Avoid odd glyph width's for center-aligned text
since it breaks the positioning of clickable area's

- Added visual hints for clickable areas for debugging
2016-10-11 03:19:53 +02:00

127 lines
3.1 KiB
C++

#pragma once
#ifdef DEBUG
#define BOOST_DI_CFG_DIAGNOSTICS_LEVEL 2
#endif
#include <atomic>
#include <boost/di.hpp>
#include <boost/optional.hpp>
#include <cassert>
#include <cerrno>
#include <chrono>
#include <cstring>
#include <functional>
#include <map>
#include <memory>
#include <string>
#include <thread>
#include <vector>
#include "config.hpp"
#define LEMONBUDDY_NS \
namespace lemonbuddy { \
inline namespace v2_0_0 {
#define LEMONBUDDY_NS_END \
} \
}
#define LEMONBUDDY_NS_PATH "lemonbuddy::v2_0_0"
#define PIPE_READ 0
#define PIPE_WRITE 1
#define LOG(m) std::cout << m << std::endl
#ifdef DEBUG
#include "debug.hpp"
#endif
LEMONBUDDY_NS
//==================================================
// Include common types (i.e, unclutter editor!)
//==================================================
namespace di = boost::di;
namespace chrono = std::chrono;
namespace this_thread = std::this_thread;
using namespace std::chrono_literals;
using std::string;
using std::stringstream;
using std::size_t;
using std::bind;
using std::forward;
using std::function;
using std::shared_ptr;
using std::unique_ptr;
using std::make_unique;
using std::make_shared;
using std::make_pair;
using std::array;
using std::map;
using std::vector;
using std::to_string;
using std::strerror;
using std::getenv;
using std::thread;
using boost::optional;
using stateflag = std::atomic<bool>;
//==================================================
// Errors and exceptions
//==================================================
namespace factory {
template <class InstanceType, class... Deps>
unique_ptr<InstanceType> generic_instance(Deps... deps) {
return make_unique<InstanceType>(deps...);
}
template <class InstanceType, class... Deps>
shared_ptr<InstanceType> generic_singleton(Deps... deps) {
static auto instance = make_shared<InstanceType>(deps...);
return instance;
}
}
//==================================================
// Errors and exceptions
//==================================================
class application_error : public std::runtime_error {
public:
int m_code;
explicit application_error(string&& message, int code = 0)
: std::runtime_error(forward<string>(message)), m_code(code) {}
};
class system_error : public application_error {
public:
explicit system_error() : application_error(strerror(errno), errno) {}
explicit system_error(string&& message)
: application_error(forward<string>(message) + " (reason: " + strerror(errno) + ")", errno) {}
};
#define DEFINE_CHILD_ERROR(error, parent) \
class error : public parent { \
using parent::parent; \
}
#define DEFINE_ERROR(error) DEFINE_CHILD_ERROR(error, application_error)
//==================================================
// Various tools and helpers functions
//==================================================
auto has_env = [](const char* var) { return getenv(var) != nullptr; };
auto read_env = [](const char* var, string&& fallback = "") {
const char* value{getenv(var)};
return value != nullptr ? value : fallback;
};
LEMONBUDDY_NS_END