packaging

This commit is contained in:
Raphael Robatsch 2021-10-27 18:20:14 +02:00
parent 57063cb17f
commit b30a695ffc
2 changed files with 61 additions and 2 deletions

View File

@ -10,14 +10,13 @@ constexpr int paddingX = 10;
constexpr int paddingY = 3;
// See https://docs.gtk.org/Pango/type_func.FontDescription.from_string.html
constexpr const char *font = "Source Sans Pro 12";
constexpr const char *font = "Sans 12";
constexpr ColorScheme colorInactive = {Color(0xbb, 0xbb, 0xbb), Color(0x22, 0x22, 0x22)};
constexpr ColorScheme colorActive = {Color(0xee, 0xee, 0xee), Color(0x00, 0x55, 0x77)};
constexpr const char *termcmd[] = {"foot", nullptr};
constexpr Button buttons[] = {
{ ClkTagBar, BTN_LEFT, toggleview, {0} },
{ ClkTagBar, BTN_LEFT, view, {0} },
{ ClkTagBar, BTN_RIGHT, tag, {0} },
{ ClkTagBar, BTN_MIDDLE, toggletag, {0} },

60
src/line_buffer.hpp Normal file
View File

@ -0,0 +1,60 @@
// somebar - dwl bar
// See LICENSE file for copyright and license details.
#pragma once
#include <array>
#include <string.h>
// reads data from Reader, and passes complete lines to Handler.
template<size_t N>
class LineBuffer {
std::array<char, N> _buffer;
size_t _bytesBuffered {0};
size_t _bytesConsumed {0};
bool _discardLine {0};
public:
template<typename Reader, typename Handler>
size_t readLines(const Reader& reader, const Handler& handler)
{
auto d = _buffer.data();
while (true) {
auto bytesRead = reader(d + _bytesBuffered, _buffer.size() - _bytesBuffered);
if (bytesRead <= 0) {
return bytesRead;
}
_bytesBuffered += bytesRead;
char* linePosition = nullptr;
do {
char* lineStart = d + _bytesConsumed;
linePosition = static_cast<char*>(memchr(
lineStart,
'\n',
_bytesBuffered - _bytesConsumed));
if (linePosition) {
int lineLength = linePosition - lineStart;
if (!_discardLine) {
handler(lineStart, lineLength);
}
_bytesConsumed += lineLength + 1;
_discardLine = false;
}
} while (linePosition);
size_t bytesRemaining = _bytesBuffered - _bytesConsumed;
if (bytesRemaining == _buffer.size()) {
// line too long
_discardLine = true;
_bytesBuffered = 0;
_bytesConsumed = 0;
} else if (bytesRemaining > 0 && _bytesConsumed > 0) {
// move the last partial message to the front of the buffer, so a full-sized
// message will fit
memmove(d, d+_bytesConsumed, bytesRemaining);
_bytesBuffered = bytesRemaining;
_bytesConsumed = 0;
}
}
}
};