Skip to content
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

Remove _member_access from geometry #1910

Merged
merged 5 commits into from
May 13, 2024
Merged

Remove _member_access from geometry #1910

merged 5 commits into from
May 13, 2024

Conversation

Caellian
Copy link
Collaborator

@Caellian Caellian commented May 13, 2024

It was difficult/too costly ensuring temporary this was correct when vecs contained in rects were accessed directly.

This PR also adds:

  • semantics to rect for sized & absolute rectangles, and fixes another (unreported) bug with previous PR (Introduce geometry primitives #1862) where I used absolute end positions instead of width/height.
  • some more utility functions and setters.

Fixes #1908.

@github-actions github-actions bot added sources PR modifies project sources display: x11 Issue related to X11 backend display: wayland Issue related to Wayland backend lua Issue or PR related to Lua code mouse events Issue or PR related to mouse events labels May 13, 2024
Copy link

netlify bot commented May 13, 2024

Deploy Preview for conkyweb canceled.

Name Link
🔨 Latest commit 9bb3061
🔍 Latest deploy log https://app.netlify.com/sites/conkyweb/deploys/6641ee7c20069000083f0457

@Caellian Caellian changed the title Remove _member_access from geometry. Remove _member_access from geometry May 13, 2024
@Caellian Caellian added the bug Bug report or bug fix PR label May 13, 2024
@github-actions github-actions bot added the text Issue or PR related to `conky.text` variables label May 13, 2024
@Caellian Caellian force-pushed the fix/geometry-accessors branch 2 times, most recently from 0e14543 to 9bb3061 Compare May 13, 2024 10:42
Comment on lines +183 to +188
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfree-nonheap-object"
// *_allocated takes care of avoiding freeing unallocated objects
if (name_allocated) delete[] error_name;
if (code_allocated) delete[] code_description;
#pragma GCC diagnostic pop
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This produces a (new) warning in GCC 14.1.1

Comment on lines +54 to +57
add_compile_options(
$<$<COMPILE_LANG_AND_ID:CXX,Clang>:-stdlib=libc++>
$<$<COMPILE_LANG_AND_ID:CXX,Clang>:-Wno-unknown-warning-option>
$<$<COMPILE_LANG_AND_ID:CXX,GCC>:-Wno-unknown-warning>)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to add these to avoid warning about new warnings with older compiler versions.

@@ -226,7 +226,7 @@ char *find_and_replace_templates(const char *inbuf) {
outlen += len;
*o = '\0';
outbuf = static_cast<char *>(realloc(outbuf, outlen * sizeof(char)));
strncat(outbuf, tmpl_out, len);
strcat(outbuf, tmpl_out);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was also a warning because the new compiler can tell that len is derived from strlen(tmpl_out) which is then the same as using strcat directly.

Comment on lines -1142 to +1183
int display_width = workarea[2] - workarea[0];
int display_height = workarea[3] - workarea[1];
int display_width = workarea.width();
int display_height = workarea.height();

switch (horizontal_alignment(align)) {
case axis_align::START:
sizes[*x11_strut::LEFT] = std::clamp(
window.geometry.x + window.geometry.width, 0, *workarea.width);
window.geometry.x() + window.geometry.end_x(), 0, display_width);
sizes[*x11_strut::LEFT_START_Y] =
std::clamp(*window.geometry.y, 0, *workarea.height);
std::clamp(window.geometry.y(), 0, display_height);
sizes[*x11_strut::LEFT_END_Y] = std::clamp(
window.geometry.y + window.geometry.height, 0, *workarea.height);
window.geometry.y() + window.geometry.height(), 0, display_height);
break;
case axis_align::END:
sizes[*x11_strut::RIGHT] =
std::clamp(workarea.width - window.geometry.x, 0, *workarea.width);
std::clamp(display_width - window.geometry.x(), 0, display_width);
sizes[*x11_strut::RIGHT_START_Y] =
std::clamp(*window.geometry.y, 0, *workarea.height);
std::clamp(window.geometry.y(), 0, display_height);
sizes[*x11_strut::RIGHT_END_Y] = std::clamp(
window.geometry.y + window.geometry.height, 0, *workarea.height);
window.geometry.y() + window.geometry.height(), 0, display_height);
break;
case axis_align::MIDDLE:
switch (vertical_alignment(align)) {
case axis_align::START:
sizes[*x11_strut::TOP] =
std::clamp(window.geometry.y + window.geometry.height, 0,
*workarea.height);
std::clamp(window.geometry.y() + window.geometry.height(), 0,
display_height);
sizes[*x11_strut::TOP_START_X] =
std::clamp(*window.geometry.x, 0, *workarea.width);
sizes[*x11_strut::TOP_END_X] = std::clamp(
window.geometry.x + window.geometry.width, 0, *workarea.width);
std::clamp(window.geometry.x(), 0, display_width);
sizes[*x11_strut::TOP_END_X] =
std::clamp(window.geometry.x() + window.geometry.width(), 0,
display_width);
break;
case axis_align::END:
sizes[*x11_strut::BOTTOM] = std::clamp(
workarea.height - window.geometry.y, 0, *workarea.height);
display_height - window.geometry.y(), 0, display_height);
sizes[*x11_strut::BOTTOM_START_X] =
std::clamp(*window.geometry.x, 0, *workarea.width);
sizes[*x11_strut::BOTTOM_END_X] = std::clamp(
window.geometry.x + window.geometry.width, 0, *workarea.width);
std::clamp(window.geometry.x(), 0, display_width);
sizes[*x11_strut::BOTTOM_END_X] =
std::clamp(window.geometry.x() + window.geometry.width(), 0,
display_width);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was buggy. I didn't use display_width and display_height at all, and instead workarea.width which was in fact an absolute end x position and not width.

Comment on lines -355 to -358
workarea[0] = ps->x_org;
workarea[1] = ps->y_org;
workarea[2] = workarea[0] + ps->width;
workarea[3] = workarea[1] + ps->height;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As can be seen here.

@Caellian Caellian requested a review from brndnmtthws May 13, 2024 10:51
It was difficult ensuring temporary `this` was correct when combined
with composition.

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
Add some convenience setters.

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
This allows source pragmas for future warnings which are in a newer
version of the compiler but not implemented in an older one.

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
strncat that concatenates to a buffer whose length was determined from
source strlen can be replaced by strcat - if the buffer is invalid
(unterminated), using strlen will result in same behavior.

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
@Caellian Caellian merged commit 2d50767 into main May 13, 2024
63 checks passed
@Caellian Caellian deleted the fix/geometry-accessors branch May 13, 2024 20:08
Caellian pushed a commit that referenced this pull request May 15, 2024
Fixes incorrect member accessing left behind after #1910.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug report or bug fix PR display: wayland Issue related to Wayland backend display: x11 Issue related to X11 backend lua Issue or PR related to Lua code mouse events Issue or PR related to mouse events sources PR modifies project sources text Issue or PR related to `conky.text` variables
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: segmentation fault upon modification of conkyrc. (Regression?)
2 participants