Merge branch 'hotfix/3.6.1'
This commit is contained in:
commit
1a4ad828c6
15
CHANGELOG.md
15
CHANGELOG.md
@ -10,6 +10,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [3.6.1] - 2022-03-05
|
||||
### Build
|
||||
- Fixed compiler warning in Clang 13 ([`#2613`](https://github.com/polybar/polybar/pull/2613))
|
||||
- Fixed compiler error in GCC 12 ([`#2616`](https://github.com/polybar/polybar/pull/2616), [`#2614`](https://github.com/polybar/polybar/issues/2614))
|
||||
- Fixed installation of docs when some are not generated (man, html...) ([`#2612`](https://github.com/polybar/polybar/pull/2612))
|
||||
- Fix `LDFLAGS` not being respected ([`#2619`](https://github.com/polybar/polybar/pull/2619))
|
||||
|
||||
### Fixed
|
||||
- `tray-offset-x`, `tray-offset-y`, `offset-x`, and `offset-y` were mistakenly capped below at 0 ([`#2620`](https://github.com/polybar/polybar/pull/2620))
|
||||
- `custom/script`: Polybar shutdown being stalled by hanging script ([`#2621`](https://github.com/polybar/polybar/pull/2621))
|
||||
- `polybar-msg`: Wrong hint when using deprecated `hook` ([`#2624`](https://github.com/polybar/polybar/pull/2624))
|
||||
|
||||
## [3.6.0] - 2022-03-01
|
||||
### Breaking
|
||||
- We added the backslash escape character (\\) for configuration values. This means that the literal backslash character now has special meaning in configuration files, therefore if you want to use it in a value as a literal backslash, you need to escape it with the backslash escape character. The parser logs an error if any unescaped backslashes are found in a value. This affects you only if you are using two consecutive backslashes in a config value, which will now be interpreted as a single literal backslash. ([`#2354`](https://github.com/polybar/polybar/issues/2354))
|
||||
@ -151,7 +163,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Fixed
|
||||
- Empty color values are no longer treated as invalid and no longer produce an error.
|
||||
|
||||
[Unreleased]: https://github.com/polybar/polybar/compare/3.6.0...HEAD
|
||||
[Unreleased]: https://github.com/polybar/polybar/compare/3.6.1...HEAD
|
||||
[3.6.1]: https://github.com/polybar/polybar/releases/tag/3.6.1
|
||||
[3.6.0]: https://github.com/polybar/polybar/releases/tag/3.6.0
|
||||
[3.5.7]: https://github.com/polybar/polybar/releases/tag/3.5.7
|
||||
[3.5.6]: https://github.com/polybar/polybar/releases/tag/3.5.6
|
||||
|
36
README.md
36
README.md
@ -24,7 +24,7 @@ A fast and easy-to-use tool for creating status bars.
|
||||
**Polybar** aims to help users build beautiful and highly customizable status bars
|
||||
for their desktop environment, without the need of having a black belt in shell scripting.
|
||||
|
||||
![sample screenshot](doc/_static/default.png)
|
||||
![default configuration screenshot](doc/_static/default.png)
|
||||
|
||||
## Table of Contents
|
||||
|
||||
@ -33,8 +33,7 @@ for their desktop environment, without the need of having a black belt in shell
|
||||
* [Contributing](#contributing)
|
||||
* [Getting started](#getting-started)
|
||||
* [Installation](#installation)
|
||||
* [Configuration](#configuration)
|
||||
* [Running](#running)
|
||||
* [First Steps](#first-steps)
|
||||
* [Community](#community)
|
||||
* [Contributors](#contributors)
|
||||
* [Donations](#donations)
|
||||
@ -128,35 +127,8 @@ If you are using **Fedora**, you can install [polybar](https://src.fedoraproject
|
||||
|
||||
If you can't find your distro here, you will have to [build from source](https://github.com/polybar/polybar/wiki/Compiling).
|
||||
|
||||
### Configuration
|
||||
|
||||
Details on how to setup and configure the bar and each module have been moved to [the wiki](https://github.com/polybar/polybar/wiki/Configuration).
|
||||
|
||||
#### Install the example configuration
|
||||
|
||||
For a normal installation, polybar will install the example config to
|
||||
`/usr/share/doc/polybar/config` or ` /usr/local/share/doc/polybar/config`
|
||||
(depending on your install parameters)
|
||||
|
||||
From there you can copy it to `~/.config/polybar/config` to get started (make
|
||||
sure to backup any existing config file there).
|
||||
|
||||
**Note:** This example file is meant to showcase available modules and
|
||||
configuration options.
|
||||
Running it as-is will work but many modules will likely not start because they
|
||||
require machine-specific configuration and many of the font icons will not show
|
||||
up because they require a very specific [font
|
||||
configuration](https://github.com/polybar/polybar/wiki/Fonts).
|
||||
We encourage you to use it as a reference when building
|
||||
your own configuration.
|
||||
|
||||
#### Launch the example bar
|
||||
~~~ sh
|
||||
$ polybar example
|
||||
~~~
|
||||
|
||||
### Running
|
||||
[See the wiki for details on how to run polybar](https://github.com/polybar/polybar/wiki).
|
||||
### First Steps
|
||||
[See the wiki for details on how to run and configure polybar](https://github.com/polybar/polybar/wiki).
|
||||
|
||||
## Community
|
||||
Want to get in touch?
|
||||
|
@ -15,7 +15,7 @@ option(BUILD_POLYBAR "Build the main polybar executable" ${DEFAULT_ON})
|
||||
option(BUILD_POLYBAR_MSG "Build polybar-msg" ${DEFAULT_ON})
|
||||
option(BUILD_TESTS "Build testsuite" OFF)
|
||||
option(BUILD_DOC "Build documentation" ${DEFAULT_ON})
|
||||
option(BUILD_CONFIG "Generate sample configuration" ${DEFAULT_ON})
|
||||
option(BUILD_CONFIG "Generate default configuration" ${DEFAULT_ON})
|
||||
option(BUILD_SHELL "Generate shell completion files" ${DEFAULT_ON})
|
||||
|
||||
include(CMakeDependentOption)
|
||||
|
@ -26,7 +26,7 @@ colored_option(" testsuite" BUILD_TESTS)
|
||||
colored_option(" documentation" BUILD_DOC)
|
||||
colored_option(" html" BUILD_DOC_HTML)
|
||||
colored_option(" man" BUILD_DOC_MAN)
|
||||
colored_option(" sample config" BUILD_CONFIG)
|
||||
colored_option(" default config" BUILD_CONFIG)
|
||||
colored_option(" shell files" BUILD_SHELL)
|
||||
|
||||
if (BUILD_LIBPOLY)
|
||||
|
@ -108,4 +108,4 @@ string(REPLACE ";" " " cxx_flags_str "${cxx_flags}")
|
||||
string(REPLACE ";" " " cxx_linker_flags_str "${cxx_linker_flags}")
|
||||
|
||||
# TODO use target_link_options once min cmake version is >= 3.13
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${cxx_linker_flags_str}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${cxx_linker_flags_str}")
|
||||
|
@ -49,10 +49,12 @@ endforeach()
|
||||
# Dummy target that depends on all documentation targets
|
||||
add_custom_target(doc ALL DEPENDS ${doc_targets})
|
||||
|
||||
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/
|
||||
if (BUILD_DOC_HTML)
|
||||
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/
|
||||
DESTINATION ${CMAKE_INSTALL_DOCDIR}
|
||||
COMPONENT doc
|
||||
PATTERN ".buildinfo" EXCLUDE)
|
||||
endif()
|
||||
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/CHANGELOG.md
|
||||
DESTINATION ${CMAKE_INSTALL_DOCDIR}
|
||||
@ -62,14 +64,17 @@ install(FILES ${CMAKE_CURRENT_LIST_DIR}/config.ini
|
||||
DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples
|
||||
COMPONENT doc)
|
||||
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/polybar.1
|
||||
if (BUILD_DOC_MAN)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/polybar.1
|
||||
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1
|
||||
COMPONENT doc)
|
||||
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/polybar-msg.1
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/polybar-msg.1
|
||||
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1
|
||||
COMPONENT doc)
|
||||
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/polybar.5
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/polybar.5
|
||||
DESTINATION ${CMAKE_INSTALL_MANDIR}/man5
|
||||
COMPONENT doc)
|
||||
endif()
|
||||
|
||||
|
@ -8,7 +8,7 @@ SYNOPSIS
|
||||
DESCRIPTION
|
||||
-----------
|
||||
Polybar aims to help users build beautiful and highly customizable status bars for their desktop environment, without the need of having a black belt in shell scripting.
|
||||
If the *BAR* argument is not provided and the configuration file only contains one bar definition, Polybar will display this bar.
|
||||
If the *BAR* argument is not provided and the configuration file only contains one bar definition, polybar will display this bar.
|
||||
|
||||
OPTIONS
|
||||
-------
|
||||
|
@ -40,6 +40,19 @@ enabled.
|
||||
.. note:: IPC messages are only sent to polybar instances running under the
|
||||
same user as ``polybar-msg`` is running as.
|
||||
|
||||
Concretely, ``polybar`` and ``polybar-msg`` use the
|
||||
``$XDG_RUNTIME_DIR`` environment variable in accordance with the `XDG
|
||||
Base Directory Specification`_ to determine where to find the socket
|
||||
to communicate.
|
||||
|
||||
If ``polybar`` and ``polybar-msg`` don't have the same value for
|
||||
``$XDG_RUNTIME_DIR``, they will likely not be able to communicate.
|
||||
The variable may not be set if you use ``su`` or ``sudo`` to execute
|
||||
``polybar-msg`` as a different user, often a full user session is
|
||||
required.
|
||||
|
||||
.. _XDG Base Directory Specification: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||
|
||||
The ``<type>`` argument is either :ref:`action <ipc-actions>` or
|
||||
:ref:`cmd <ipc-commands>`.
|
||||
The allowed values for ``<payload>`` depend on the type.
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <deque>
|
||||
#include <iterator>
|
||||
|
||||
#include "cairo/font.hpp"
|
||||
#include "cairo/surface.hpp"
|
||||
@ -117,9 +118,12 @@ namespace cairo {
|
||||
|
||||
context& operator<<(const rounded_corners& c) {
|
||||
cairo_new_sub_path(m_c);
|
||||
cairo_arc(m_c, c.x + c.w - c.radius.top_right, c.y + c.radius.top_right, c.radius.top_right, -90 * degree, 0 * degree);
|
||||
cairo_arc(m_c, c.x + c.w - c.radius.bottom_right, c.y + c.h - c.radius.bottom_right, c.radius.bottom_right, 0 * degree, 90 * degree);
|
||||
cairo_arc(m_c, c.x + c.radius.bottom_left, c.y + c.h - c.radius.bottom_left, c.radius.bottom_left, 90 * degree, 180 * degree);
|
||||
cairo_arc(
|
||||
m_c, c.x + c.w - c.radius.top_right, c.y + c.radius.top_right, c.radius.top_right, -90 * degree, 0 * degree);
|
||||
cairo_arc(m_c, c.x + c.w - c.radius.bottom_right, c.y + c.h - c.radius.bottom_right, c.radius.bottom_right,
|
||||
0 * degree, 90 * degree);
|
||||
cairo_arc(m_c, c.x + c.radius.bottom_left, c.y + c.h - c.radius.bottom_left, c.radius.bottom_left, 90 * degree,
|
||||
180 * degree);
|
||||
cairo_arc(m_c, c.x + c.radius.top_left, c.y + c.radius.top_left, c.radius.top_left, 180 * degree, 270 * degree);
|
||||
cairo_close_path(m_c);
|
||||
return *this;
|
||||
@ -142,7 +146,8 @@ namespace cairo {
|
||||
cairo_rel_line_to(m_c, 0, segment.w);
|
||||
break;
|
||||
}
|
||||
cairo_arc_negative(m_c, segment.x, segment.y, segment.radius - segment.w, segment.angle_to * degree, segment.angle_from * degree);
|
||||
cairo_arc_negative(m_c, segment.x, segment.y, segment.radius - segment.w, segment.angle_to * degree,
|
||||
segment.angle_from * degree);
|
||||
cairo_close_path(m_c);
|
||||
return *this;
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "components/config.hpp"
|
||||
#include "modules/meta/timer_module.hpp"
|
||||
#include "settings.hpp"
|
||||
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#include "modules/meta/timer_module.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "utils/http.hpp"
|
||||
|
@ -21,7 +21,8 @@ namespace units_utils {
|
||||
|
||||
string extent_to_string(extent_val extent);
|
||||
|
||||
unsigned percentage_with_offset_to_pixel(percentage_with_offset g_format, double max, double dpi);
|
||||
int percentage_with_offset_to_pixel(percentage_with_offset g_format, double max, double dpi);
|
||||
unsigned percentage_with_offset_to_pixel_nonnegative(percentage_with_offset g_format, double max, double dpi);
|
||||
|
||||
spacing_type parse_spacing_unit(const string& str);
|
||||
spacing_val parse_spacing(const string& str);
|
||||
|
@ -40,9 +40,6 @@ class background_manager;
|
||||
class bg_slice;
|
||||
|
||||
struct tray_settings {
|
||||
tray_settings() = default;
|
||||
tray_settings& operator=(const tray_settings& o) = default;
|
||||
|
||||
alignment align{alignment::NONE};
|
||||
bool running{false};
|
||||
int rel_x{0};
|
||||
|
@ -1,9 +1,10 @@
|
||||
#include "adapters/net.hpp"
|
||||
|
||||
#include <linux/nl80211.h>
|
||||
#include <netlink/genl/ctrl.h>
|
||||
#include <netlink/genl/genl.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "adapters/net.hpp"
|
||||
#include "utils/file.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
@ -166,8 +167,8 @@ namespace net {
|
||||
m_essid.clear();
|
||||
|
||||
if (bss[NL80211_BSS_INFORMATION_ELEMENTS] != nullptr) {
|
||||
// Information Element ID from ieee80211.h
|
||||
#define WLAN_EID_SSID 0
|
||||
// Information Element ID from ieee80211.h
|
||||
#define WLAN_EID_SSID 0
|
||||
|
||||
auto ies = static_cast<char*>(nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]));
|
||||
auto ies_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]);
|
||||
|
@ -96,16 +96,35 @@ script_runner::interval script_runner::run() {
|
||||
auto cmd = command_util::make_command<output_policy::REDIRECTED>(exec);
|
||||
|
||||
try {
|
||||
cmd->exec(true, m_env);
|
||||
cmd->exec(false, m_env);
|
||||
} catch (const exception& err) {
|
||||
m_log.err("script_runner: %s", err.what());
|
||||
throw modules::module_error("Failed to execute command, stopping module...");
|
||||
}
|
||||
|
||||
m_exit_status = cmd->get_exit_status();
|
||||
int fd = cmd->get_stdout(PIPE_READ);
|
||||
assert(fd != -1);
|
||||
bool changed = io_util::poll_read(fd) && set_output(cmd->readline());
|
||||
|
||||
bool changed = false;
|
||||
|
||||
bool got_output = false;
|
||||
while (!m_stopping && cmd->is_running() && !io_util::poll(fd, POLLHUP, 0)) {
|
||||
/**
|
||||
* For non-tailed scripts, we only use the first line. However, to ensure interruptability when the module shuts
|
||||
* down, we still need to continue polling.
|
||||
*/
|
||||
if (io_util::poll_read(fd, 25) && !got_output) {
|
||||
changed = set_output(cmd->readline());
|
||||
got_output = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_stopping) {
|
||||
cmd->terminate();
|
||||
return 0s;
|
||||
}
|
||||
|
||||
m_exit_status = cmd->wait();
|
||||
|
||||
if (!changed && m_exit_status != 0) {
|
||||
clear_output();
|
||||
|
@ -221,8 +221,10 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
|
||||
// Load values used to adjust the struts atom
|
||||
auto margin_top = m_conf.get("global/wm", "margin-top", percentage_with_offset{});
|
||||
auto margin_bottom = m_conf.get("global/wm", "margin-bottom", percentage_with_offset{});
|
||||
m_opts.strut.top = units_utils::percentage_with_offset_to_pixel(margin_top, m_opts.monitor->h, m_opts.dpi_y);
|
||||
m_opts.strut.bottom = units_utils::percentage_with_offset_to_pixel(margin_bottom, m_opts.monitor->h, m_opts.dpi_y);
|
||||
m_opts.strut.top =
|
||||
units_utils::percentage_with_offset_to_pixel_nonnegative(margin_top, m_opts.monitor->h, m_opts.dpi_y);
|
||||
m_opts.strut.bottom =
|
||||
units_utils::percentage_with_offset_to_pixel_nonnegative(margin_bottom, m_opts.monitor->h, m_opts.dpi_y);
|
||||
|
||||
// Load commands used for fallback click handlers
|
||||
vector<action> actions;
|
||||
@ -295,19 +297,19 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
|
||||
|
||||
m_opts.borders.emplace(edge::TOP, border_settings{});
|
||||
m_opts.borders[edge::TOP].size =
|
||||
units_utils::percentage_with_offset_to_pixel(border_top, m_opts.monitor->h, m_opts.dpi_y);
|
||||
units_utils::percentage_with_offset_to_pixel_nonnegative(border_top, m_opts.monitor->h, m_opts.dpi_y);
|
||||
m_opts.borders[edge::TOP].color = parse_or_throw_color("border-top-color", border_color);
|
||||
m_opts.borders.emplace(edge::BOTTOM, border_settings{});
|
||||
m_opts.borders[edge::BOTTOM].size =
|
||||
units_utils::percentage_with_offset_to_pixel(border_bottom, m_opts.monitor->h, m_opts.dpi_y);
|
||||
units_utils::percentage_with_offset_to_pixel_nonnegative(border_bottom, m_opts.monitor->h, m_opts.dpi_y);
|
||||
m_opts.borders[edge::BOTTOM].color = parse_or_throw_color("border-bottom-color", border_color);
|
||||
m_opts.borders.emplace(edge::LEFT, border_settings{});
|
||||
m_opts.borders[edge::LEFT].size =
|
||||
units_utils::percentage_with_offset_to_pixel(border_left, m_opts.monitor->w, m_opts.dpi_x);
|
||||
units_utils::percentage_with_offset_to_pixel_nonnegative(border_left, m_opts.monitor->w, m_opts.dpi_x);
|
||||
m_opts.borders[edge::LEFT].color = parse_or_throw_color("border-left-color", border_color);
|
||||
m_opts.borders.emplace(edge::RIGHT, border_settings{});
|
||||
m_opts.borders[edge::RIGHT].size =
|
||||
units_utils::percentage_with_offset_to_pixel(border_right, m_opts.monitor->w, m_opts.dpi_x);
|
||||
units_utils::percentage_with_offset_to_pixel_nonnegative(border_right, m_opts.monitor->w, m_opts.dpi_x);
|
||||
m_opts.borders[edge::RIGHT].color = parse_or_throw_color("border-right-color", border_color);
|
||||
|
||||
// Load geometry values
|
||||
@ -316,8 +318,8 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
|
||||
auto offsetx = m_conf.get(m_conf.section(), "offset-x", percentage_with_offset{});
|
||||
auto offsety = m_conf.get(m_conf.section(), "offset-y", percentage_with_offset{});
|
||||
|
||||
m_opts.size.w = units_utils::percentage_with_offset_to_pixel(w, m_opts.monitor->w, m_opts.dpi_x);
|
||||
m_opts.size.h = units_utils::percentage_with_offset_to_pixel(h, m_opts.monitor->h, m_opts.dpi_y);
|
||||
m_opts.size.w = units_utils::percentage_with_offset_to_pixel_nonnegative(w, m_opts.monitor->w, m_opts.dpi_x);
|
||||
m_opts.size.h = units_utils::percentage_with_offset_to_pixel_nonnegative(h, m_opts.monitor->h, m_opts.dpi_y);
|
||||
m_opts.offset.x = units_utils::percentage_with_offset_to_pixel(offsetx, m_opts.monitor->w, m_opts.dpi_x);
|
||||
m_opts.offset.y = units_utils::percentage_with_offset_to_pixel(offsety, m_opts.monitor->h, m_opts.dpi_y);
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <sys/statvfs.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <utility>
|
||||
|
||||
#include "drawtypes/label.hpp"
|
||||
#include "drawtypes/progressbar.hpp"
|
||||
|
@ -141,7 +141,7 @@ static std::pair<ipc::type_t, string> parse_message(deque<string> args) {
|
||||
|
||||
fprintf(stderr,
|
||||
"Warning: Using IPC hook commands is deprecated, use the hook action on the ipc module: %s %s \"%s\"\n", exec,
|
||||
ipc_type.c_str(), ipc_payload.c_str());
|
||||
"action", ipc_payload.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,11 +39,14 @@ namespace units_utils {
|
||||
/**
|
||||
* Converts a percentage with offset into pixels
|
||||
*/
|
||||
unsigned int percentage_with_offset_to_pixel(percentage_with_offset g_format, double max, double dpi) {
|
||||
int percentage_with_offset_to_pixel(percentage_with_offset g_format, double max, double dpi) {
|
||||
int offset_pixel = extent_to_pixel(g_format.offset, dpi);
|
||||
|
||||
return static_cast<unsigned int>(
|
||||
std::max<double>(0, math_util::percentage_to_value<double, double>(g_format.percentage, max) + offset_pixel));
|
||||
return static_cast<int>(math_util::percentage_to_value<double, double>(g_format.percentage, max) + offset_pixel);
|
||||
}
|
||||
|
||||
unsigned percentage_with_offset_to_pixel_nonnegative(percentage_with_offset g_format, double max, double dpi) {
|
||||
return std::max<int>(0, percentage_with_offset_to_pixel(g_format, max, dpi));
|
||||
}
|
||||
|
||||
extent_type parse_extent_unit(const string& str) {
|
||||
|
@ -6,7 +6,6 @@
|
||||
using namespace polybar;
|
||||
using namespace units_utils;
|
||||
|
||||
|
||||
namespace polybar {
|
||||
bool operator==(const extent_val lhs, const extent_val rhs) {
|
||||
return lhs.type == rhs.type && lhs.value == rhs.value;
|
||||
@ -24,9 +23,9 @@ namespace polybar {
|
||||
* value represents the format string. The max value is always 1000 and dpi is always 96
|
||||
*/
|
||||
class GeomFormatToPixelsTest : public ::testing::Test,
|
||||
public ::testing::WithParamInterface<pair<unsigned, percentage_with_offset>> {};
|
||||
public ::testing::WithParamInterface<pair<int, percentage_with_offset>> {};
|
||||
|
||||
vector<pair<unsigned, percentage_with_offset>> to_pixels_no_offset_list = {
|
||||
vector<pair<int, percentage_with_offset>> to_pixels_no_offset_list = {
|
||||
{1000, percentage_with_offset{100.}},
|
||||
{0, percentage_with_offset{0.}},
|
||||
{1000, percentage_with_offset{150.}},
|
||||
@ -36,34 +35,33 @@ vector<pair<unsigned, percentage_with_offset>> to_pixels_no_offset_list = {
|
||||
{1, percentage_with_offset{0., extent_val{extent_type::PIXEL, 1}}},
|
||||
};
|
||||
|
||||
vector<pair<unsigned, percentage_with_offset>> to_pixels_with_offset_list = {
|
||||
vector<pair<int, percentage_with_offset>> to_pixels_with_pixels_list = {
|
||||
{1000, percentage_with_offset{100., ZERO_PX_EXTENT}},
|
||||
{1010, percentage_with_offset{100., extent_val{extent_type::PIXEL, 10}}},
|
||||
{990, percentage_with_offset{100., extent_val{extent_type::PIXEL, -10}}},
|
||||
{10, percentage_with_offset{0., extent_val{extent_type::PIXEL, 10}}},
|
||||
{1000, percentage_with_offset{99., extent_val{extent_type::PIXEL, 10}}},
|
||||
{0, percentage_with_offset{1., extent_val{extent_type::PIXEL, -100}}},
|
||||
{-90, percentage_with_offset{1., extent_val{extent_type::PIXEL, -100}}},
|
||||
};
|
||||
|
||||
vector<pair<unsigned, percentage_with_offset>> to_pixels_with_units_list = {
|
||||
vector<pair<int, percentage_with_offset>> to_pixels_with_points_list = {
|
||||
{1013, percentage_with_offset{100., extent_val{extent_type::POINT, 10}}},
|
||||
{987, percentage_with_offset{100., extent_val{extent_type::POINT, -10}}},
|
||||
{1003, percentage_with_offset{99., extent_val{extent_type::POINT, 10}}},
|
||||
{13, percentage_with_offset{0., extent_val{extent_type::POINT, 10}}},
|
||||
{0, percentage_with_offset{0, extent_val{extent_type::POINT, -10}}},
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(NoOffset, GeomFormatToPixelsTest, ::testing::ValuesIn(to_pixels_no_offset_list));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(WithOffset, GeomFormatToPixelsTest, ::testing::ValuesIn(to_pixels_with_offset_list));
|
||||
INSTANTIATE_TEST_SUITE_P(WithPixels, GeomFormatToPixelsTest, ::testing::ValuesIn(to_pixels_with_pixels_list));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(WithUnits, GeomFormatToPixelsTest, ::testing::ValuesIn(to_pixels_with_units_list));
|
||||
INSTANTIATE_TEST_SUITE_P(WithPoints, GeomFormatToPixelsTest, ::testing::ValuesIn(to_pixels_with_points_list));
|
||||
|
||||
static constexpr int MAX_WIDTH = 1000;
|
||||
static constexpr int DPI = 96;
|
||||
|
||||
TEST_P(GeomFormatToPixelsTest, correctness) {
|
||||
unsigned exp = GetParam().first;
|
||||
int exp = GetParam().first;
|
||||
percentage_with_offset geometry = GetParam().second;
|
||||
EXPECT_DOUBLE_EQ(exp, percentage_with_offset_to_pixel(geometry, MAX_WIDTH, DPI));
|
||||
}
|
||||
@ -83,17 +81,6 @@ TEST(UnitsUtils, extent_to_pixel) {
|
||||
EXPECT_EQ(0, extent_to_pixel_nonnegative({extent_type::POINT, -36}, 96));
|
||||
}
|
||||
|
||||
TEST(UnitsUtils, percentage_with_offset_to_pixel) {
|
||||
EXPECT_EQ(1100, percentage_with_offset_to_pixel({100, {extent_type::PIXEL, 100}}, 1000, 0));
|
||||
EXPECT_EQ(1048, percentage_with_offset_to_pixel({100, {extent_type::POINT, 36}}, 1000, 96));
|
||||
|
||||
EXPECT_EQ(900, percentage_with_offset_to_pixel({100, {extent_type::PIXEL, -100}}, 1000, 0));
|
||||
EXPECT_EQ(952, percentage_with_offset_to_pixel({100, {extent_type::POINT, -36}}, 1000, 96));
|
||||
|
||||
EXPECT_EQ(0, percentage_with_offset_to_pixel({0, {extent_type::PIXEL, -100}}, 1000, 0));
|
||||
EXPECT_EQ(100, percentage_with_offset_to_pixel({0, {extent_type::PIXEL, 100}}, 1000, 0));
|
||||
}
|
||||
|
||||
TEST(UnitsUtils, parse_extent_unit) {
|
||||
EXPECT_EQ(extent_type::PIXEL, parse_extent_unit("px"));
|
||||
EXPECT_EQ(extent_type::POINT, parse_extent_unit("pt"));
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Polybar version information
|
||||
# Update this on every release
|
||||
# This is used to create the version string if a git repo is not available
|
||||
3.6.0
|
||||
3.6.1
|
||||
|
Loading…
Reference in New Issue
Block a user