2016-11-21 14:07:00 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-01-25 08:54:18 +00:00
|
|
|
#include <cairo/cairo.h>
|
2019-10-27 21:27:58 +00:00
|
|
|
|
2019-08-06 17:35:07 +00:00
|
|
|
#include <bitset>
|
2019-01-05 00:08:18 +00:00
|
|
|
#include <memory>
|
2017-01-19 04:38:42 +00:00
|
|
|
|
|
|
|
#include "cairo/fwd.hpp"
|
2016-11-21 14:07:00 +00:00
|
|
|
#include "common.hpp"
|
2021-01-06 14:46:57 +00:00
|
|
|
#include "components/renderer_interface.hpp"
|
2016-11-21 14:07:00 +00:00
|
|
|
#include "components/types.hpp"
|
2016-12-05 19:41:00 +00:00
|
|
|
#include "events/signal_fwd.hpp"
|
|
|
|
#include "events/signal_receiver.hpp"
|
2016-12-26 08:40:15 +00:00
|
|
|
#include "x11/extensions/fwd.hpp"
|
2016-11-21 14:07:00 +00:00
|
|
|
#include "x11/types.hpp"
|
|
|
|
|
|
|
|
POLYBAR_NS
|
|
|
|
|
2017-01-19 04:38:42 +00:00
|
|
|
// fwd {{{
|
2016-11-21 14:07:00 +00:00
|
|
|
class connection;
|
2017-01-19 04:38:42 +00:00
|
|
|
class config;
|
2016-11-21 14:07:00 +00:00
|
|
|
class logger;
|
2017-05-23 19:32:34 +00:00
|
|
|
class background_manager;
|
2019-01-05 00:08:18 +00:00
|
|
|
class bg_slice;
|
2017-01-19 04:38:42 +00:00
|
|
|
// }}}
|
2016-11-21 14:07:00 +00:00
|
|
|
|
2016-12-09 08:02:47 +00:00
|
|
|
using std::map;
|
2016-12-05 19:41:00 +00:00
|
|
|
|
2017-01-24 05:59:58 +00:00
|
|
|
struct alignment_block {
|
2017-01-25 08:54:18 +00:00
|
|
|
cairo_pattern_t* pattern;
|
Add units support (POINT, PIXEL, SPACE) (#2578)
* add units support (POINT, PIXEL, SPACE) for polybar
- add a size_with_unit struct
- add a geometry_format_values struct
- move dpi initialisation from renderer.cpp to bar.cpp
- add a string to size_with_unit converter
- add point support (with pt)
- add pixel support (with px)
* Fix unit test compilation
* clang-format
* Better names
The old names didn't really capture the purpose of the structs and
function.
space_type -> spacing_type
space_size -> spacing_val
size_type -> extent_type
geometry -> extent_val
geometry_format_values -> percentage_with_offset
* Remove parse_size_with_unit
No longer needed. The convert<spacing_val> function in config.cpp
already does all the work for us and always setting the type to pixel
was wrong.
In addition, line-size should not be of type spacing_val but extent_val.
* Cleanup
I tried to address most of my comments on the old PR
* Fix renderer width calculation
We can't just blindly add the x difference to the width because for
example the width should increase if x < width and the increase keeps
x < width.
Similarly, we can't just add the offset to the width.
* Rename geom_format_to_pixels to percentage_with_offset_to_pixel
* Cleanup
* Apply suggested changes from Patrick on GitHub
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
* Update src/components/bar.cpp
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
* Update src/components/config.cpp
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
* Update src/components/builder.cpp
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
* Update src/components/builder.cpp
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
* config: Use stod for parsing percentage
* Use stof instead of strtof
* units: Fix test edge cases
* Remove unnecessary clang-format toggle
* Use percentage_with_offset for margin-{top,bottom}
* Support negative extent values
* Rename unit to units and create a cpp file
* Move percentage_with_offset_to_pixel unit test to units
* Add unit tests for units_utils
* Clarify when and how negative spacing/extent is allowed
Negative spacing is never allowed and produces a config error.
Extents allow negative values in theory, but only a few use-cases accept
it.
Only the extent value used for the `%{O}` tag and the offset value in
percentage_with_offset can be negative. Everything else is capped below
at 0.
The final pixel value of percentage_with_offset also caps below at 0.
* Fix parsing errors not being caught in config
* Print a proper error message for uncaught exceptions
* Cleanup module::get_output
All changes preserve the existing semantics
* Stop using remove_trailing_space in module::get_output
Instead, we first check if the current tag is built, and only if it is,
the spacing is prepended.
* Remove unused imports
* Restore old behavior
If there are two tags and the second one isn't built (module::build
returns false), the space in between them is removed.
For example in the mpd module:
format-online = <toggle> <label-song> foo
If mpd is not running, the mpd module will return false when trying to
build the `<label-song>` tag. If we don't remove the space between
`<toggle>` and `<label-song>`, we end up with two spaces between
`<toggle>` and `foo`.
This change is to match the old behavior where at least one trailing
space character was removed from the builder.
* Add changelog entry
* Remove unused setting
* Use percentage with offset for tray-offset
Co-authored-by: Jérôme BOULMIER <jerome.boulmier@outlook.fr>
Co-authored-by: Joe Groocock <github@frebib.net>
2022-02-20 20:08:57 +00:00
|
|
|
/**
|
|
|
|
* The x-position where the next thing will be rendered.
|
|
|
|
*/
|
2017-01-24 05:59:58 +00:00
|
|
|
double x;
|
|
|
|
double y;
|
Add units support (POINT, PIXEL, SPACE) (#2578)
* add units support (POINT, PIXEL, SPACE) for polybar
- add a size_with_unit struct
- add a geometry_format_values struct
- move dpi initialisation from renderer.cpp to bar.cpp
- add a string to size_with_unit converter
- add point support (with pt)
- add pixel support (with px)
* Fix unit test compilation
* clang-format
* Better names
The old names didn't really capture the purpose of the structs and
function.
space_type -> spacing_type
space_size -> spacing_val
size_type -> extent_type
geometry -> extent_val
geometry_format_values -> percentage_with_offset
* Remove parse_size_with_unit
No longer needed. The convert<spacing_val> function in config.cpp
already does all the work for us and always setting the type to pixel
was wrong.
In addition, line-size should not be of type spacing_val but extent_val.
* Cleanup
I tried to address most of my comments on the old PR
* Fix renderer width calculation
We can't just blindly add the x difference to the width because for
example the width should increase if x < width and the increase keeps
x < width.
Similarly, we can't just add the offset to the width.
* Rename geom_format_to_pixels to percentage_with_offset_to_pixel
* Cleanup
* Apply suggested changes from Patrick on GitHub
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
* Update src/components/bar.cpp
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
* Update src/components/config.cpp
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
* Update src/components/builder.cpp
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
* Update src/components/builder.cpp
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
* config: Use stod for parsing percentage
* Use stof instead of strtof
* units: Fix test edge cases
* Remove unnecessary clang-format toggle
* Use percentage_with_offset for margin-{top,bottom}
* Support negative extent values
* Rename unit to units and create a cpp file
* Move percentage_with_offset_to_pixel unit test to units
* Add unit tests for units_utils
* Clarify when and how negative spacing/extent is allowed
Negative spacing is never allowed and produces a config error.
Extents allow negative values in theory, but only a few use-cases accept
it.
Only the extent value used for the `%{O}` tag and the offset value in
percentage_with_offset can be negative. Everything else is capped below
at 0.
The final pixel value of percentage_with_offset also caps below at 0.
* Fix parsing errors not being caught in config
* Print a proper error message for uncaught exceptions
* Cleanup module::get_output
All changes preserve the existing semantics
* Stop using remove_trailing_space in module::get_output
Instead, we first check if the current tag is built, and only if it is,
the spacing is prepended.
* Remove unused imports
* Restore old behavior
If there are two tags and the second one isn't built (module::build
returns false), the space in between them is removed.
For example in the mpd module:
format-online = <toggle> <label-song> foo
If mpd is not running, the mpd module will return false when trying to
build the `<label-song>` tag. If we don't remove the space between
`<toggle>` and `<label-song>`, we end up with two spaces between
`<toggle>` and `foo`.
This change is to match the old behavior where at least one trailing
space character was removed from the builder.
* Add changelog entry
* Remove unused setting
* Use percentage with offset for tray-offset
Co-authored-by: Jérôme BOULMIER <jerome.boulmier@outlook.fr>
Co-authored-by: Joe Groocock <github@frebib.net>
2022-02-20 20:08:57 +00:00
|
|
|
/**
|
|
|
|
* The total width of this block.
|
|
|
|
*
|
|
|
|
* This is always >= x, but may be larger because a negative offset may
|
|
|
|
* decrease x, but the width doesn't change.
|
|
|
|
*/
|
|
|
|
double width;
|
2017-01-24 05:59:58 +00:00
|
|
|
};
|
|
|
|
|
2021-01-10 20:30:10 +00:00
|
|
|
class renderer : public renderer_interface,
|
|
|
|
public signal_receiver<SIGN_PRIORITY_RENDERER, signals::ui::request_snapshot> {
|
2016-11-21 14:07:00 +00:00
|
|
|
public:
|
2016-12-09 08:40:46 +00:00
|
|
|
using make_type = unique_ptr<renderer>;
|
2023-05-01 12:58:52 +00:00
|
|
|
static make_type make(const bar_settings& bar, tags::action_context& action_ctxt, const config&);
|
2016-12-09 08:02:47 +00:00
|
|
|
|
2019-08-06 17:35:07 +00:00
|
|
|
explicit renderer(connection& conn, signal_emitter& sig, const config&, const logger& logger, const bar_settings& bar,
|
2022-08-27 21:02:34 +00:00
|
|
|
background_manager& background_manager, tags::action_context& action_ctxt);
|
2016-11-25 10:41:41 +00:00
|
|
|
~renderer();
|
2016-11-21 14:07:00 +00:00
|
|
|
|
|
|
|
xcb_window_t window() const;
|
2022-03-16 22:11:19 +00:00
|
|
|
xcb_visualtype_t* visual() const;
|
|
|
|
int depth() const;
|
2016-11-21 14:07:00 +00:00
|
|
|
|
2017-01-25 22:36:34 +00:00
|
|
|
void begin(xcb_rectangle_t rect);
|
2016-11-21 14:07:00 +00:00
|
|
|
void end();
|
2017-01-19 04:38:42 +00:00
|
|
|
void flush();
|
2016-11-21 14:07:00 +00:00
|
|
|
|
Add units support (POINT, PIXEL, SPACE) (#2578)
* add units support (POINT, PIXEL, SPACE) for polybar
- add a size_with_unit struct
- add a geometry_format_values struct
- move dpi initialisation from renderer.cpp to bar.cpp
- add a string to size_with_unit converter
- add point support (with pt)
- add pixel support (with px)
* Fix unit test compilation
* clang-format
* Better names
The old names didn't really capture the purpose of the structs and
function.
space_type -> spacing_type
space_size -> spacing_val
size_type -> extent_type
geometry -> extent_val
geometry_format_values -> percentage_with_offset
* Remove parse_size_with_unit
No longer needed. The convert<spacing_val> function in config.cpp
already does all the work for us and always setting the type to pixel
was wrong.
In addition, line-size should not be of type spacing_val but extent_val.
* Cleanup
I tried to address most of my comments on the old PR
* Fix renderer width calculation
We can't just blindly add the x difference to the width because for
example the width should increase if x < width and the increase keeps
x < width.
Similarly, we can't just add the offset to the width.
* Rename geom_format_to_pixels to percentage_with_offset_to_pixel
* Cleanup
* Apply suggested changes from Patrick on GitHub
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
* Update src/components/bar.cpp
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
* Update src/components/config.cpp
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
* Update src/components/builder.cpp
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
* Update src/components/builder.cpp
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
* config: Use stod for parsing percentage
* Use stof instead of strtof
* units: Fix test edge cases
* Remove unnecessary clang-format toggle
* Use percentage_with_offset for margin-{top,bottom}
* Support negative extent values
* Rename unit to units and create a cpp file
* Move percentage_with_offset_to_pixel unit test to units
* Add unit tests for units_utils
* Clarify when and how negative spacing/extent is allowed
Negative spacing is never allowed and produces a config error.
Extents allow negative values in theory, but only a few use-cases accept
it.
Only the extent value used for the `%{O}` tag and the offset value in
percentage_with_offset can be negative. Everything else is capped below
at 0.
The final pixel value of percentage_with_offset also caps below at 0.
* Fix parsing errors not being caught in config
* Print a proper error message for uncaught exceptions
* Cleanup module::get_output
All changes preserve the existing semantics
* Stop using remove_trailing_space in module::get_output
Instead, we first check if the current tag is built, and only if it is,
the spacing is prepended.
* Remove unused imports
* Restore old behavior
If there are two tags and the second one isn't built (module::build
returns false), the space in between them is removed.
For example in the mpd module:
format-online = <toggle> <label-song> foo
If mpd is not running, the mpd module will return false when trying to
build the `<label-song>` tag. If we don't remove the space between
`<toggle>` and `<label-song>`, we end up with two spaces between
`<toggle>` and `foo`.
This change is to match the old behavior where at least one trailing
space character was removed from the builder.
* Add changelog entry
* Remove unused setting
* Use percentage with offset for tray-offset
Co-authored-by: Jérôme BOULMIER <jerome.boulmier@outlook.fr>
Co-authored-by: Joe Groocock <github@frebib.net>
2022-02-20 20:08:57 +00:00
|
|
|
void render_offset(const tags::context& ctxt, const extent_val offset) override;
|
2021-01-10 19:49:50 +00:00
|
|
|
void render_text(const tags::context& ctxt, const string&&) override;
|
|
|
|
|
2021-01-10 20:30:10 +00:00
|
|
|
void change_alignment(const tags::context& ctxt) override;
|
|
|
|
|
2021-02-02 22:03:44 +00:00
|
|
|
double get_x(const tags::context& ctxt) const override;
|
|
|
|
|
|
|
|
double get_alignment_start(const alignment align) const override;
|
2021-01-10 19:49:50 +00:00
|
|
|
|
2022-04-15 21:50:04 +00:00
|
|
|
void apply_tray_position(const tags::context& context) override;
|
|
|
|
|
2021-01-10 19:49:50 +00:00
|
|
|
protected:
|
2016-11-21 14:07:00 +00:00
|
|
|
void fill_background();
|
2021-01-06 15:53:52 +00:00
|
|
|
void fill_overline(rgba color, double x, double w);
|
|
|
|
void fill_underline(rgba color, double x, double w);
|
2017-01-19 04:38:42 +00:00
|
|
|
void fill_borders();
|
2022-04-11 19:30:24 +00:00
|
|
|
void draw_offset(const tags::context& ctxt, rgba color, double x, double w);
|
2016-11-21 14:07:00 +00:00
|
|
|
|
2017-01-24 05:59:58 +00:00
|
|
|
double block_x(alignment a) const;
|
|
|
|
double block_y(alignment a) const;
|
|
|
|
double block_w(alignment a) const;
|
2017-01-25 08:54:18 +00:00
|
|
|
double block_h(alignment a) const;
|
2017-01-24 05:59:58 +00:00
|
|
|
|
Add units support (POINT, PIXEL, SPACE) (#2578)
* add units support (POINT, PIXEL, SPACE) for polybar
- add a size_with_unit struct
- add a geometry_format_values struct
- move dpi initialisation from renderer.cpp to bar.cpp
- add a string to size_with_unit converter
- add point support (with pt)
- add pixel support (with px)
* Fix unit test compilation
* clang-format
* Better names
The old names didn't really capture the purpose of the structs and
function.
space_type -> spacing_type
space_size -> spacing_val
size_type -> extent_type
geometry -> extent_val
geometry_format_values -> percentage_with_offset
* Remove parse_size_with_unit
No longer needed. The convert<spacing_val> function in config.cpp
already does all the work for us and always setting the type to pixel
was wrong.
In addition, line-size should not be of type spacing_val but extent_val.
* Cleanup
I tried to address most of my comments on the old PR
* Fix renderer width calculation
We can't just blindly add the x difference to the width because for
example the width should increase if x < width and the increase keeps
x < width.
Similarly, we can't just add the offset to the width.
* Rename geom_format_to_pixels to percentage_with_offset_to_pixel
* Cleanup
* Apply suggested changes from Patrick on GitHub
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
* Update src/components/bar.cpp
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
* Update src/components/config.cpp
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
* Update src/components/builder.cpp
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
* Update src/components/builder.cpp
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
* config: Use stod for parsing percentage
* Use stof instead of strtof
* units: Fix test edge cases
* Remove unnecessary clang-format toggle
* Use percentage_with_offset for margin-{top,bottom}
* Support negative extent values
* Rename unit to units and create a cpp file
* Move percentage_with_offset_to_pixel unit test to units
* Add unit tests for units_utils
* Clarify when and how negative spacing/extent is allowed
Negative spacing is never allowed and produces a config error.
Extents allow negative values in theory, but only a few use-cases accept
it.
Only the extent value used for the `%{O}` tag and the offset value in
percentage_with_offset can be negative. Everything else is capped below
at 0.
The final pixel value of percentage_with_offset also caps below at 0.
* Fix parsing errors not being caught in config
* Print a proper error message for uncaught exceptions
* Cleanup module::get_output
All changes preserve the existing semantics
* Stop using remove_trailing_space in module::get_output
Instead, we first check if the current tag is built, and only if it is,
the spacing is prepended.
* Remove unused imports
* Restore old behavior
If there are two tags and the second one isn't built (module::build
returns false), the space in between them is removed.
For example in the mpd module:
format-online = <toggle> <label-song> foo
If mpd is not running, the mpd module will return false when trying to
build the `<label-song>` tag. If we don't remove the space between
`<toggle>` and `<label-song>`, we end up with two spaces between
`<toggle>` and `foo`.
This change is to match the old behavior where at least one trailing
space character was removed from the builder.
* Add changelog entry
* Remove unused setting
* Use percentage with offset for tray-offset
Co-authored-by: Jérôme BOULMIER <jerome.boulmier@outlook.fr>
Co-authored-by: Joe Groocock <github@frebib.net>
2022-02-20 20:08:57 +00:00
|
|
|
void increase_x(double dx);
|
|
|
|
|
2017-01-25 08:54:18 +00:00
|
|
|
void flush(alignment a);
|
2017-01-19 04:38:42 +00:00
|
|
|
void highlight_clickable_areas();
|
|
|
|
|
2021-01-04 09:38:43 +00:00
|
|
|
bool on(const signals::ui::request_snapshot& evt) override;
|
2016-11-21 14:07:00 +00:00
|
|
|
|
2016-12-05 02:49:57 +00:00
|
|
|
protected:
|
|
|
|
struct reserve_area {
|
|
|
|
edge side{edge::NONE};
|
2017-01-19 10:11:28 +00:00
|
|
|
unsigned int size{0U};
|
2016-12-05 02:49:57 +00:00
|
|
|
};
|
|
|
|
|
2016-11-21 14:07:00 +00:00
|
|
|
private:
|
|
|
|
connection& m_connection;
|
2016-12-05 19:41:00 +00:00
|
|
|
signal_emitter& m_sig;
|
2017-01-19 04:38:42 +00:00
|
|
|
const config& m_conf;
|
2016-11-21 14:07:00 +00:00
|
|
|
const logger& m_log;
|
|
|
|
const bar_settings& m_bar;
|
2019-01-05 00:08:18 +00:00
|
|
|
std::shared_ptr<bg_slice> m_background;
|
2016-11-21 14:07:00 +00:00
|
|
|
|
2022-03-16 21:13:46 +00:00
|
|
|
int m_depth{-1};
|
2016-11-21 14:07:00 +00:00
|
|
|
xcb_window_t m_window;
|
2022-03-16 22:11:19 +00:00
|
|
|
xcb_colormap_t m_colormap{XCB_NONE};
|
2016-11-21 14:07:00 +00:00
|
|
|
xcb_visualtype_t* m_visual;
|
2017-01-19 04:38:42 +00:00
|
|
|
xcb_gcontext_t m_gcontext;
|
2023-03-23 22:12:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Background pixmap for the bar window
|
|
|
|
*
|
|
|
|
* All bar contents are rendered onto this.
|
|
|
|
*/
|
2016-11-21 14:07:00 +00:00
|
|
|
xcb_pixmap_t m_pixmap;
|
|
|
|
|
2017-01-24 05:59:58 +00:00
|
|
|
xcb_rectangle_t m_rect{0, 0, 0U, 0U};
|
|
|
|
reserve_area m_cleararea{};
|
2016-11-21 14:07:00 +00:00
|
|
|
|
2017-01-19 04:38:42 +00:00
|
|
|
unique_ptr<cairo::context> m_context;
|
2017-01-24 05:59:58 +00:00
|
|
|
unique_ptr<cairo::xcb_surface> m_surface;
|
|
|
|
map<alignment, alignment_block> m_blocks;
|
2017-01-27 14:36:37 +00:00
|
|
|
cairo_pattern_t* m_cornermask{};
|
2017-01-24 05:59:58 +00:00
|
|
|
|
2017-01-27 14:36:37 +00:00
|
|
|
cairo_operator_t m_comp_bg{CAIRO_OPERATOR_SOURCE};
|
2017-01-25 22:36:34 +00:00
|
|
|
cairo_operator_t m_comp_fg{CAIRO_OPERATOR_OVER};
|
|
|
|
cairo_operator_t m_comp_ol{CAIRO_OPERATOR_OVER};
|
|
|
|
cairo_operator_t m_comp_ul{CAIRO_OPERATOR_OVER};
|
|
|
|
cairo_operator_t m_comp_border{CAIRO_OPERATOR_OVER};
|
2018-07-06 13:19:12 +00:00
|
|
|
bool m_pseudo_transparency{false};
|
2017-01-24 05:59:58 +00:00
|
|
|
|
|
|
|
alignment m_align;
|
2016-11-21 14:07:00 +00:00
|
|
|
|
2017-01-24 05:59:58 +00:00
|
|
|
bool m_fixedcenter;
|
|
|
|
string m_snapshot_dst;
|
2016-11-21 14:07:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
POLYBAR_NS_END
|