Skip to content

Commit

Permalink
experimenting with left/right bar positions (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixKratz committed Oct 6, 2022
1 parent 1340a0a commit ac9f35e
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 24 deletions.
214 changes: 191 additions & 23 deletions src/bar.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
#include "misc/helpers.h"
#include "window.h"

void bar_draw_graph(struct bar* bar, struct bar_item* bar_item, uint32_t x, bool right_to_left) {
if (!bar_item->has_graph) return;
}

bool bar_draws_item(struct bar* bar, struct bar_item* bar_item) {
if (!bar_item->drawing || !bar->shown || bar->hidden) return false;

Expand All @@ -35,7 +31,7 @@ bool bar_draws_item(struct bar* bar, struct bar_item* bar_item) {
return true;
}

void bar_calculate_popup_anchor_for_bar_item(struct bar* bar, struct bar_item* bar_item) {
static inline void bar_calculate_popup_anchor_for_bar_item(struct bar* bar, struct bar_item* bar_item) {
if (bar->adid != g_bar_manager.active_adid) return;
struct window* window = bar_item_get_window(bar_item, bar->adid);

Expand Down Expand Up @@ -141,9 +137,7 @@ void bar_draw(struct bar* bar) {
}
}

void bar_calculate_bounds(struct bar* bar) {
if (bar->sid < 1 || bar->adid < 1) return;

static inline void bar_calculate_bounds_top_bottom(struct bar* bar) {
bool is_builtin = CGDisplayIsBuiltin(bar->did);
uint32_t notch_width = is_builtin ? g_bar_manager.notch_width : 0;

Expand Down Expand Up @@ -278,29 +272,203 @@ void bar_calculate_bounds(struct bar* bar) {
}
}

CGRect bar_get_frame(struct bar *bar) {
static inline void bar_calculate_bounds_left_right(struct bar* bar) {
uint32_t notch_width = 0;

uint32_t center_length = bar_manager_length_for_bar_side(&g_bar_manager,
bar,
POSITION_CENTER);

uint32_t bar_left_first_item_y = max(g_bar_manager.background.padding_left,
0 );

uint32_t bar_right_first_item_y = bar->window.frame.size.height
-max(g_bar_manager.background.padding_right,
0 );

uint32_t bar_center_first_item_y = (bar->window.frame.size.height
- 2*g_bar_manager.margin
- center_length) / 2 - 1;

uint32_t bar_center_right_first_item_y = (bar->window.frame.size.height
+ notch_width) / 2 - 1;

uint32_t bar_center_left_first_item_y = (bar->window.frame.size.height
- notch_width) / 2 - 1;

uint32_t* next_position = NULL;

for (int i = 0; i < g_bar_manager.bar_item_count; i++) {
struct bar_item* bar_item = g_bar_manager.bar_items[i];

if (!bar_draws_item(bar, bar_item)
|| bar_item->type == BAR_COMPONENT_GROUP
|| bar_item->position == POSITION_POPUP ) {
continue;
}

uint32_t bar_item_display_height = bar_item_get_height(bar_item);
uint32_t bar_item_display_length = bar_item_get_length(bar_item, true);
uint32_t x = 0;
bool rtl = false;

if (bar_item->position == POSITION_LEFT)
next_position = &bar_left_first_item_y;
else if (bar_item->position == POSITION_CENTER)
next_position = &bar_center_first_item_y;
else if (bar_item->position == POSITION_RIGHT)
next_position = &bar_right_first_item_y, rtl = true;
else if (bar_item->position == POSITION_CENTER_RIGHT)
next_position = &bar_center_right_first_item_y;
else if (bar_item->position == POSITION_CENTER_LEFT)
next_position = &bar_center_left_first_item_y, rtl = true;
else continue;

if (bar_item->position == POSITION_RIGHT
|| bar_item->position == POSITION_CENTER_LEFT) {

*next_position = min(*next_position - bar_item_display_height
- bar_item->background.padding_right,
bar->window.frame.size.height
- bar_item_display_height );
}
else {
*next_position += max((int)-*next_position,
bar_item->background.padding_left);
}

bar_item->graph.rtl = rtl;

CGPoint shadow_offsets = {0, 0};//bar_item_calculate_shadow_offsets(bar_item);
bar_item_calculate_bounds(bar_item,
bar_item_display_height,
(g_bar_manager.background.bounds.size.height
- bar_item_display_length) / 2.
+ max(shadow_offsets.x, 0),
bar_item_display_height / 2.);


CGRect frame = {{bar->window.origin.x + x
- max(shadow_offsets.x, 0),
bar->window.origin.y
+ *next_position
+ -max(-bar_item->y_offset, 0)},
{g_bar_manager.background.bounds.size.height,
bar_item_display_height + abs(bar_item->y_offset)}};

window_set_frame(bar_item_get_window(bar_item, bar->adid), frame);

// if (bar_item->group && group_is_first_member(bar_item->group, bar_item)) {
// group_calculate_bounds(bar_item->group,
// bar,
// max(shadow_offsets.x, 0),
// *next_position,
// bar_item->position == POSITION_RIGHT
// || bar_item->position == POSITION_CENTER_LEFT);
//
// CGPoint shadow_offsets =
// bar_item_calculate_shadow_offsets(bar_item->group->members[0]);
//
// uint32_t group_length = group_get_length(bar_item->group, bar);
// uint32_t group_offset = (bar_item->position == POSITION_RIGHT
// || bar_item->position == POSITION_CENTER_LEFT)
// ? group_length
// - bar_item_get_length(bar_item, false)
// - bar_item->background.padding_right
// : bar_item->background.padding_left;
//
// CGRect group_frame = {{frame.origin.x - group_offset,
// frame.origin.y},
// {group_length
// + shadow_offsets.x
// + shadow_offsets.y,
// frame.size.height} };
//
// window_set_frame(bar_item_get_window(bar_item->group->members[0],
// bar->adid ),
// group_frame );
// }
//
// if (bar_item->popup.drawing)
// bar_calculate_popup_anchor_for_bar_item(bar, bar_item);

if (bar_item->position == POSITION_RIGHT
|| bar_item->position == POSITION_CENTER_LEFT) {
*next_position += bar_item->has_const_width
? bar_item_display_height
+ bar_item->background.padding_right
- bar_item->custom_width
: - bar_item->background.padding_left;
} else {
*next_position += bar_item->has_const_width
? bar_item->custom_width
- bar_item->background.padding_left
: (bar_item_display_height
+ bar_item->background.padding_right);
}
}
}

void bar_calculate_bounds(struct bar* bar) {
if (bar->sid < 1 || bar->adid < 1) return;

if (g_bar_manager.position == POSITION_LEFT
|| g_bar_manager.position == POSITION_RIGHT) {
bar_calculate_bounds_left_right(bar);
} else {
bar_calculate_bounds_top_bottom(bar);
}
}

static inline CGRect bar_get_frame(struct bar *bar) {
bool is_builtin = CGDisplayIsBuiltin(bar->did);
int notch_offset = is_builtin ? g_bar_manager.notch_offset : 0;


CGRect bounds = display_bounds(bar->did);
bounds.size.width -= 2*g_bar_manager.margin;
CGPoint origin = bounds.origin;
origin.x += g_bar_manager.margin;
origin.y += g_bar_manager.background.y_offset + notch_offset;

if (g_bar_manager.position == POSITION_LEFT
|| g_bar_manager.position == POSITION_RIGHT) {
bounds.size.height -= 2*g_bar_manager.background.y_offset;

if (g_bar_manager.position == POSITION_BOTTOM) {
origin.y = CGRectGetMaxY(bounds)
- g_bar_manager.background.bounds.size.height
- 2*(g_bar_manager.background.y_offset) - notch_offset;
} else if (display_menu_bar_visible() && !g_bar_manager.topmost) {
CGRect menu = display_menu_bar_rect(bar->did);
origin.y += menu.size.height;
}
origin.x += (g_bar_manager.position == POSITION_RIGHT
? (bounds.size.width
- g_bar_manager.background.bounds.size.height
- g_bar_manager.margin)
: g_bar_manager.margin);

origin.y += g_bar_manager.background.y_offset;

return (CGRect) {{origin.x, origin.y},{bounds.size.width,
g_bar_manager.background.bounds.size.height}};
if (display_menu_bar_visible() && !g_bar_manager.topmost) {
CGRect menu = display_menu_bar_rect(bar->did);
origin.y += menu.size.height;
bounds.size.height -= menu.size.height;
}

return (CGRect) {{origin.x, origin.y},
{g_bar_manager.background.bounds.size.height,
bounds.size.height }};
} else {
bounds.size.width -= 2*g_bar_manager.margin;
CGPoint origin = bounds.origin;
origin.x += g_bar_manager.margin;
origin.y += g_bar_manager.background.y_offset + notch_offset;


if (g_bar_manager.position == POSITION_BOTTOM) {
origin.y = CGRectGetMaxY(bounds)
- g_bar_manager.background.bounds.size.height
- 2*(g_bar_manager.background.y_offset) - notch_offset;
} else if (display_menu_bar_visible() && !g_bar_manager.topmost) {
CGRect menu = display_menu_bar_rect(bar->did);
origin.y += menu.size.height;
}

return (CGRect) {{origin.x, origin.y},
{bounds.size.width,
g_bar_manager.background.bounds.size.height}};
}
}

void bar_resize(struct bar* bar) {
Expand All @@ -320,7 +488,7 @@ void bar_set_hidden(struct bar* bar, bool hidden) {
else bar_resize(bar);
}

void bar_create_window(struct bar* bar) {
static inline void bar_create_window(struct bar* bar) {
window_init(&bar->window);
window_create(&bar->window, bar_get_frame(bar));
window_assign_mouse_tracking_area(&bar->window, bar->window.frame);
Expand Down
1 change: 0 additions & 1 deletion src/bar.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ struct bar {
};

struct bar *bar_create(uint32_t did);
void bar_create_window(struct bar* bar);
void bar_close_window(struct bar* bar);
void bar_destroy(struct bar* bar);
void bar_set_hidden(struct bar* bar, bool hidden);
Expand Down

0 comments on commit ac9f35e

Please sign in to comment.