-
-
Notifications
You must be signed in to change notification settings - Fork 622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup build flags, global namespace and includes #1841
Conversation
✅ Deploy Preview for conkyweb ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
3fee8d7
to
2cc7944
Compare
Checked for conflicts, PRs that would require some changes are:
Those are minor however, I don't mind helping out if needed. |
enum class alignment : uint8_t { | ||
NONE = 0, | ||
NONE_LEFT = 0b0001, | ||
NONE_MIDDLE = 0b0010, | ||
NONE_RIGHT = 0b0011, | ||
TOP_LEFT = 0b0101, | ||
TOP_MIDDLE = 0b0110, | ||
TOP_RIGHT = 0b0111, | ||
MIDDLE_LEFT = 0b1001, | ||
MIDDLE_MIDDLE = 0b1010, | ||
MIDDLE_RIGHT = 0b1011, | ||
BOTTOM_LEFT = 0b1101, | ||
BOTTOM_MIDDLE = 0b1110, | ||
BOTTOM_RIGHT = 0b1111, | ||
}; | ||
constexpr uint8_t operator*(alignment index) { | ||
return static_cast<uint8_t>(index); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an example of how I changed global enums to enum class
. I did this because headers like gui.h
are included in a lot of places and using pre C++11 style enums declares enum variants as global constants. This in turn means that no other enum can use same variant names (e.g. NONE
).
The bigger issues are:
- Variants cast implicitly into
int
andbool
- Promotes poor code hygiene because function declarations can use any int argument value which leads to same include mess this PR aims to solve.
- Variant names can make it unclear which constant is referenced.
Advantages:
enum class
requires exhaustive matching in switch statements which ensures all places referencing them get updated when new variants are added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, purely matter of taste, window_type::NORMAL
looks much nicer than TYPE_NORMAL
(and is more descriptive).
60843da
to
063f300
Compare
- Separated displays so they don't have to be all built even when the features are disabled. - Removed weird linker magic for display init and replaced it with straightforward (and faster) template functions that behave the same. - Replaced disabled_display_output classes with log messages. - Add explicit errors when feature dependent headers get included where they shouldn't. - Use gperf to build perfect hash for color names instead of custom X11 lookup. This should make it easier to add more color names to the list with no extra cost. - Made alignment use a specific bit layout which greatly simplifies code. - Switch BUILD_MOUSE_EVENTS dependency from OWN_WINDOW to BUILD_X11. - Other minor improvements to some existing code which shouldn't affect behavior. - Add documentation links to sample configs. Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
063f300
to
4cd6714
Compare
4cd6714
to
c23afeb
Compare
own_window_type = 'desktop', | ||
own_window_type = 'normal', | ||
own_window_hints = 'undecorated,sticky,below,skip_taskbar,skip_pager', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed this to normal
because it's the type that most commonly works, on WMs/DEs that are most commonly used (with desktops).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explanation of changes to display output registration.
outputs.reserve(static_cast<size_t>(output_t::OUTPUT_COUNT)); | ||
register_output<output_t::CONSOLE>(outputs); | ||
register_output<output_t::NCURSES>(outputs); | ||
register_output<output_t::FILE>(outputs); | ||
register_output<output_t::HTTP>(outputs); | ||
register_output<output_t::X11>(outputs); | ||
register_output<output_t::WAYLAND>(outputs); | ||
|
||
for (auto out : outputs) { NORM_ERR("FOUND: %s", out->name.c_str()); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we "called" noop init_*_output
functions in order to trigger static initializers, I wondered why not just initialize them from those functions instead of relying on execution flow hidden in constructors of static objects.
enum class output_t : uint32_t { | ||
CONSOLE, | ||
NCURSES, | ||
FILE, | ||
HTTP, | ||
X11, | ||
WAYLAND, | ||
OUTPUT_COUNT | ||
}; | ||
template <output_t Output> | ||
void register_output(display_outputs_t &outputs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be handled by using a templated function, ideally with an enum representing different outputs - but could've been strings or other values, or even discrete types (though that would cause recursive dependency).
It's useful to have an enum of supported outputs in display_output.hh
anyway.
#ifndef BUILD_WAYLAND | ||
template <> | ||
void register_output<output_t::WAYLAND>(display_outputs_t &outputs) { | ||
log_missing("Wayland", "BUILD_WAYLAND"); | ||
} | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that register_output
functions are templated, this means that we can just log if a feature is not enabled. And this causes a linker error if either the display output isn't in compilation or a fallback isn't defined. This function will almost always be inlined by compiler, even with -O1
(unlike class constructors).
I find that to be much less error prone than hoping some global static in some other file gets constructed.
class disabled_display_output : public display_output_base { | ||
public: | ||
const std::string define; | ||
disabled_display_output(const std::string &name, const std::string &define); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So disabled_display_output
is no longer needed.
src/display-wayland.cc
Outdated
namespace { | ||
|
||
#ifdef BUILD_WAYLAND | ||
namespace { | ||
conky::display_output_wayland wayland_output; | ||
#else | ||
conky::disabled_display_output wayland_output_disabled("wayland", | ||
"BUILD_WAYLAND"); | ||
#endif | ||
|
||
} // namespace | ||
extern void init_wayland_output() {} | ||
|
||
template <> | ||
void register_output<output_t::WAYLAND>(display_outputs_t &outputs) { | ||
outputs.push_back(&wayland_output); | ||
} | ||
#endif /* BUILD_WAYLAND */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The functions are pretty straightforward to write, take up less space, and it's much more clear what's going on.
void do_register_display_output(const std::string &name, | ||
display_output_base *output) { | ||
struct display_output_constructor { | ||
display_output_constructor() { display_outputs = new display_outputs_t(); } | ||
~display_output_constructor() { | ||
delete display_outputs; | ||
display_outputs = nullptr; | ||
} | ||
}; | ||
static display_output_constructor constructor; | ||
|
||
bool inserted = display_outputs->insert({name, output}).second; | ||
if (!inserted) { | ||
throw std::logic_error("Display output with name '" + name + | ||
"' already registered"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plus we don't need to handle possible out of order initialization of the static output list, nor possibility of double insertion because it's all handled in a single place.
extern void init_console_output(); | ||
extern void init_ncurses_output(); | ||
extern void init_file_output(); | ||
extern void init_http_output(); | ||
extern void init_x11_output(); | ||
extern void init_wayland_output(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this gets replaced by explicit template specialization, which is a well supported language mechanism.
Fix missing Colour construct alpha argument. Add Makefile ignore to 3rdparty/toluapp Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
Good to see labeler changes working 😆 Moved color parsing into a stacked PR: #1848
|
Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
Moved alignment changes into #1849. |
Display files are now no longer compiled if their features are disabled Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
This reaches 0% unneeded X11 polution in the sources. Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
550f276
to
9a2ec7a
Compare
Added documentation for it. Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
9a2ec7a
to
c69dcaf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a lot in this PR, but overall I like it :)
Thank you. I'll maybe tweak it a tiny bit more before merging (some added checks aren't needed). I wanted to change those things (like enums) all at once so it's just a single merge for others. |
There's a linking error with a specific build flag configuration, holding this off until I resolve it. Maybe it was there before, maybe it wasn't. EDIT: Only locally apparently, I wasn't able to get Imlib2.so to link for some reason. Works on CI. |
Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
46767e8
to
cba15e6
Compare
Hide lua state from conky-imlib2.cc Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
cba15e6
to
8e07629
Compare
Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
Changes
Flags
BUILD_MOUSE_EVENTS
dependency fromOWN_WINDOW
toBUILD_X11
.BUILD_XINPUT
dependency onBUILD_MOUSE_EVENTS
(nowBUILD_X11
directly).Refactor
disabled_display_output
classes with log messages.special_t
tospecial_node
andspecial_type
totext_node_t
.#undef
forHANDLE_EV
macro at the end of the function.axis_align
for single axis alignment matching.Mouse event fixes/improvements
XI_Motion
which means that building withoutBUILD_MOUSE_EVENTS
produces a more performant binary (due to not tracking global (root) mouse movements)Documentation
Related issues
OWN_WINDOW
doesn't compilecolour.cc
make it a lot easier to string (huehue) on new color parsersTesting
Remaining work
include
improvement using visualization