Skip to content

Commit

Permalink
Apply set_struts changes
Browse files Browse the repository at this point in the history
This reverts commit dc8b241.

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
  • Loading branch information
Caellian committed Apr 20, 2024
1 parent dc8b241 commit 782b39b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 70 deletions.
31 changes: 1 addition & 30 deletions src/display-x11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,37 +324,8 @@ bool display_output_x11::main_loop_wait(double t) {

/* update struts */
if ((changed != 0) && own_window_type.get(*state) == window_type::PANEL) {
int sidenum = -1;

NORM_ERR("defining struts");

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);
set_struts(text_alignment.get(*state));
}
}
#endif
Expand Down
96 changes: 57 additions & 39 deletions src/x11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1108,60 +1108,78 @@ constexpr size_t operator*(x11_strut index) {
}

/* reserve window manager space */
void set_struts(int sidenum) {
Atom strut;
if ((strut = ATOM(_NET_WM_STRUT)) != None) {
void set_struts(alignment align) {
NORM_ERR("A: %x", (uint8_t)align);

// Middle and none align don't have least significant bit set.
// Ensures either vertical or horizontal axis are start/end
if ((*align & 0b0101) == 0) return;
NORM_ERR("B");

Atom strut = ATOM(_NET_WM_STRUT);
if (strut != None) {
/* reserve space at left, right, top, bottom */
signed long sizes[12] = {0};
uint32_t sizes[STRUT_COUNT] = {0};
int i;

/* define strut depth */
switch (sidenum) {
case 0:
/* left side */
sizes[0] = window.x + window.width;
break;
case 1:
/* right side */
sizes[1] = display_width - window.x;
switch (vertical_alignment(align)) {
case axis_align::START:
NORM_ERR("TOP");
sizes[*x11_strut::TOP] =
std::min(window.y + window.height, display_height);
sizes[*x11_strut::TOP_START_X] = window.x;
sizes[*x11_strut::TOP_END_X] =
std::min(window.x + window.width, display_width);
break;
case 2:
/* top side */
sizes[2] = window.y + window.height;
case axis_align::END:
NORM_ERR("BOTTOM");
sizes[*x11_strut::BOTTOM] =
window.y < display_height ? display_height - window.y : 0;
sizes[*x11_strut::BOTTOM_START_X] = window.x;
sizes[*x11_strut::BOTTOM_END_X] =
std::min(window.x + window.width, display_width);
break;
case 3:
/* bottom side */
sizes[3] = display_height - window.y;
case axis_align::MIDDLE:
// can't reserve space in middle of the screen
default:
break;
}

/* define partial strut length */
if (sidenum <= 1) {
sizes[4 + (sidenum * 2)] = window.y;
sizes[5 + (sidenum * 2)] = window.y + window.height;
} else if (sidenum <= 3) {
sizes[4 + (sidenum * 2)] = window.x;
sizes[5 + (sidenum * 2)] = window.x + window.width;
// adding `(vertical_alignment(align) & 0x1) << 1` makes the switch hit
// MIDDLE if vertical alignment is set to left or right
uint8_t bump = ((*vertical_alignment(align) & 0b1) << 1);
switch (static_cast<axis_align>(*horizontal_alignment(align) + bump)) {
case axis_align::START:
NORM_ERR("LEFT");
sizes[*x11_strut::LEFT] =
std::min(window.x + window.width, display_width);
sizes[*x11_strut::LEFT_START_Y] = window.y;
sizes[*x11_strut::LEFT_END_Y] =
std::min(window.y + window.height, display_height);
break;
case axis_align::END:
NORM_ERR("right");
sizes[*x11_strut::RIGHT] =
window.x < display_width ? display_width - window.x : 0;
sizes[*x11_strut::RIGHT_START_Y] = window.y;
sizes[*x11_strut::RIGHT_END_Y] =
std::min(window.y + window.height, display_height);
break;
case axis_align::MIDDLE:
// can't reserve space in middle of the screen
default:
break;
}

/* check constraints */
for (i = 0; i < 12; i++) {
if (sizes[i] < 0) {
sizes[i] = 0;
} else {
if (i <= 1 || i >= 8) {
if (sizes[i] > display_width) { sizes[i] = display_width; }
} else {
if (sizes[i] > display_height) { sizes[i] = display_height; }
}
}
for (size_t i = 0; i < STRUT_COUNT; i++) {
NORM_ERR("STRUT %d: %d", i, sizes[i]);
}

XChangeProperty(display, window.window, strut, XA_CARDINAL, 32,
PropModeReplace, reinterpret_cast<unsigned char *>(&sizes),
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,
PropModeReplace,
reinterpret_cast<unsigned char *>(&sizes), 12);
Expand Down
2 changes: 1 addition & 1 deletion src/x11.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void destroy_window(void);
void create_gc(void);
void set_transparent_background(Window win);
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 deinit_x11();

Expand Down

0 comments on commit 782b39b

Please sign in to comment.