1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-01-30 02:28:31 +00:00

set_struts improvements (#1849)

Simplify and speed up strut code

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
This commit is contained in:
Tin Švagelj 2024-04-24 13:56:28 +00:00 committed by GitHub
parent 93ffab51a0
commit c5ee70177c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 52 additions and 76 deletions

View File

@ -313,37 +313,8 @@ bool display_output_x11::main_loop_wait(double t) {
/* update struts */ /* update struts */
if ((changed != 0) && own_window_type.get(*state) == window_type::PANEL) { if ((changed != 0) && own_window_type.get(*state) == window_type::PANEL) {
int sidenum = -1;
NORM_ERR("defining struts"); NORM_ERR("defining struts");
set_struts(text_alignment.get(*state));
alignment align = text_alignment.get(*state);
switch (align) {
case alignment::TOP_LEFT:
case alignment::TOP_RIGHT:
case alignment::TOP_MIDDLE: {
sidenum = 2;
break;
}
case alignment::BOTTOM_LEFT:
case alignment::BOTTOM_RIGHT:
case alignment::BOTTOM_MIDDLE: {
sidenum = 3;
break;
}
case alignment::MIDDLE_LEFT: {
sidenum = 0;
break;
}
case alignment::MIDDLE_RIGHT: {
sidenum = 1;
break;
}
default:
break;
}
if (sidenum != -1) set_struts(sidenum);
} }
} }
#endif #endif

View File

@ -1108,60 +1108,65 @@ constexpr size_t operator*(x11_strut index) {
} }
/* reserve window manager space */ /* reserve window manager space */
void set_struts(int sidenum) { void set_struts(alignment align) {
Atom strut; // Middle and none align don't have least significant bit set.
if ((strut = ATOM(_NET_WM_STRUT)) != None) { // Ensures either vertical or horizontal axis are start/end
/* reserve space at left, right, top, bottom */ if ((*align & 0b0101) == 0) return;
signed long sizes[12] = {0};
int i;
/* define strut depth */ Atom strut = ATOM(_NET_WM_STRUT);
switch (sidenum) { if (strut != None) {
case 0: long sizes[STRUT_COUNT] = {0};
/* left side */
sizes[0] = window.x + window.width;
break;
case 1:
/* right side */
sizes[1] = display_width - window.x;
break;
case 2:
/* top side */
sizes[2] = window.y + window.height;
break;
case 3:
/* bottom side */
sizes[3] = display_height - window.y;
break;
}
/* define partial strut length */ switch (horizontal_alignment(align)) {
if (sidenum <= 1) { case axis_align::START:
sizes[4 + (sidenum * 2)] = window.y; sizes[*x11_strut::LEFT] =
sizes[5 + (sidenum * 2)] = window.y + window.height; std::clamp(window.x + window.width, 0, display_width);
} else if (sidenum <= 3) { sizes[*x11_strut::LEFT_START_Y] =
sizes[4 + (sidenum * 2)] = window.x; std::clamp(window.y, 0, display_height);
sizes[5 + (sidenum * 2)] = window.x + window.width; sizes[*x11_strut::LEFT_END_Y] =
} std::clamp(window.y + window.height, 0, display_height);
break;
/* check constraints */ case axis_align::END:
for (i = 0; i < 12; i++) { sizes[*x11_strut::RIGHT] =
if (sizes[i] < 0) { std::clamp(display_width - window.x, 0, display_width);
sizes[i] = 0; sizes[*x11_strut::RIGHT_START_Y] =
} else { std::clamp(window.y, 0, display_height);
if (i <= 1 || i >= 8) { sizes[*x11_strut::RIGHT_END_Y] =
if (sizes[i] > display_width) { sizes[i] = display_width; } std::clamp(window.y + window.height, 0, display_height);
} else { break;
if (sizes[i] > display_height) { sizes[i] = display_height; } case axis_align::MIDDLE:
switch (vertical_alignment(align)) {
case axis_align::START:
sizes[*x11_strut::TOP] =
std::clamp(window.y + window.height, 0, display_height);
sizes[*x11_strut::TOP_START_X] =
std::clamp(window.x, 0, display_width);
sizes[*x11_strut::TOP_END_X] =
std::clamp(window.x + window.width, 0, display_width);
break;
case axis_align::END:
sizes[*x11_strut::BOTTOM] =
std::clamp(display_height - window.y, 0, display_height);
sizes[*x11_strut::BOTTOM_START_X] =
std::clamp(window.x, 0, display_width);
sizes[*x11_strut::BOTTOM_END_X] =
std::clamp(window.x + window.width, 0, display_width);
break;
case axis_align::MIDDLE:
// can't reserve space in middle of the screen
default:
break;
} }
} default:
break;
} }
XChangeProperty(display, window.window, strut, XA_CARDINAL, 32, XChangeProperty(display, window.window, strut, XA_CARDINAL, 32,
PropModeReplace, reinterpret_cast<unsigned char *>(&sizes), PropModeReplace, reinterpret_cast<unsigned char *>(&sizes),
4); 4);
if ((strut = ATOM(_NET_WM_STRUT_PARTIAL)) != None) { strut = ATOM(_NET_WM_STRUT_PARTIAL);
if (strut != None) {
XChangeProperty(display, window.window, strut, XA_CARDINAL, 32, XChangeProperty(display, window.window, strut, XA_CARDINAL, 32,
PropModeReplace, PropModeReplace,
reinterpret_cast<unsigned char *>(&sizes), 12); reinterpret_cast<unsigned char *>(&sizes), 12);

View File

@ -103,7 +103,7 @@ void destroy_window(void);
void create_gc(void); void create_gc(void);
void set_transparent_background(Window win); void set_transparent_background(Window win);
void get_x11_desktop_info(Display *current_display, Atom atom); void get_x11_desktop_info(Display *current_display, Atom atom);
void set_struts(int); void set_struts(alignment alignment);
void x11_init_window(lua::state &l, bool own); void x11_init_window(lua::state &l, bool own);
void deinit_x11(); void deinit_x11();