Skip to content

Commit

Permalink
better bracket length detection, increase timeout length for mach mes…
Browse files Browse the repository at this point in the history
…sages
  • Loading branch information
FelixKratz committed Aug 3, 2022
1 parent 4cfe167 commit d8ff755
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 23 deletions.
12 changes: 10 additions & 2 deletions src/bar.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void bar_calculate_popup_anchor_for_bar_item(struct bar* bar, struct bar_item* b
if (!bar_item->popup.overrides_cell_size)
bar_item->popup.cell_size = window->frame.size.height;

popup_calculate_bounds(&bar_item->popup);
popup_calculate_bounds(&bar_item->popup, bar);

CGPoint anchor = window->origin;
if (bar_item->popup.align == POSITION_CENTER) {
Expand All @@ -57,6 +57,7 @@ void bar_calculate_popup_anchor_for_bar_item(struct bar* bar, struct bar_item* b
: window->frame.size.height);

popup_set_anchor(&bar_item->popup, anchor, bar->adid);
popup_calculate_bounds(&bar_item->popup, bar);
}

void bar_order_item_windows(struct bar* bar) {
Expand Down Expand Up @@ -218,10 +219,17 @@ void bar_calculate_bounds(struct bar* bar) {
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,
(shadow_offsets.x > 0 ? shadow_offsets.x : 0),
y,
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);
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
Expand Down
7 changes: 0 additions & 7 deletions src/bar_item.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,13 +525,6 @@ uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_heigh
label_position += alias_get_length(&bar_item->alias);
}

if (bar_item->group && group_is_first_member(bar_item->group, bar_item))
group_calculate_bounds(bar_item->group,
x,
y,
bar_item->position == POSITION_RIGHT
|| bar_item->position == POSITION_CENTER_LEFT);

text_calculate_bounds(&bar_item->icon,
icon_position,
content_y + bar_item->y_offset);
Expand Down
9 changes: 5 additions & 4 deletions src/group.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "group.h"
#include "bar.h"

struct group* group_create() {
struct group* group = malloc(sizeof(struct group));
Expand Down Expand Up @@ -44,10 +45,10 @@ bool group_is_first_member(struct group* group, struct bar_item* item) {
return false;
}

uint32_t group_get_length(struct group* group) {
uint32_t group_get_length(struct group* group, struct bar* bar) {
uint32_t length = 0;
for (int i = 1; i < group->num_members; i++) {
if (group->members[i]->drawing) {
if (bar_draws_item(bar, group->members[i])) {
if (!group->members[i]->has_const_width)
length += group->members[i]->background.padding_left
+ group->members[i]->background.padding_right;
Expand Down Expand Up @@ -80,9 +81,9 @@ void group_destroy(struct group* group) {
free(group);
}

void group_calculate_bounds(struct group* group, uint32_t x, uint32_t y, bool rtl) {
void group_calculate_bounds(struct group* group, struct bar* bar, uint32_t x, uint32_t y, bool rtl) {
background_calculate_bounds(&group->members[0]->background, x, y);
group->members[0]->background.bounds.size.width = group_get_length(group);
group->members[0]->background.bounds.size.width = group_get_length(group, bar);
group->members[0]->background.bounds.origin.x = x;
group->members[0]->background.bounds.origin.y = y
- group->members[0]->background.bounds.size.height / 2
Expand Down
6 changes: 4 additions & 2 deletions src/group.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#include "bar_item.h"

struct bar;

struct group {
CGRect bounds;
uint32_t num_members;
Expand All @@ -12,11 +14,11 @@ void group_init(struct group* group);
void group_set_name(struct group* group, char* _name);
void group_add_member(struct group* group, struct bar_item* item);
void group_remove_member(struct group* group, struct bar_item* bar_item);
uint32_t group_get_length(struct group* group);
uint32_t group_get_length(struct group* group, struct bar* bar);
bool group_is_first_member(struct group* group, struct bar_item* item);
struct bar_item* group_get_first_member(struct group* group);

void group_calculate_bounds(struct group* group, uint32_t x, uint32_t y, bool rtl);
void group_calculate_bounds(struct group* group, struct bar* bar, uint32_t x, uint32_t y, bool rtl);
void group_draw(struct group* group, CGContextRef context);
void group_destroy(struct group* group);

Expand Down
2 changes: 1 addition & 1 deletion src/mach.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void mach_receive_message(mach_port_t port, struct mach_buffer* buffer, bool tim
0,
sizeof(struct mach_buffer),
port,
10,
100,
MACH_PORT_NULL );
else
msg_return = mach_msg(&buffer->message.header,
Expand Down
12 changes: 6 additions & 6 deletions src/popup.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "popup.h"
#include "bar_item.h"
#include "bar_manager.h"
#include "bar.h"

void popup_init(struct popup* popup, struct bar_item* host) {
popup->drawing = false;
Expand Down Expand Up @@ -60,14 +61,14 @@ void popup_order_windows(struct popup* popup) {
}
}

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

if (!bar_item->popup.overrides_cell_size)
bar_item->popup.cell_size = window->frame.size.height;

popup_calculate_bounds(&bar_item->popup);
popup_calculate_bounds(&bar_item->popup, bar);

CGPoint anchor = window->origin;
if (bar_item->position != POSITION_POPUP || popup->horizontal) {
Expand Down Expand Up @@ -97,7 +98,7 @@ void popup_calculate_popup_anchor_for_bar_item(struct popup* popup, struct bar_i
popup_set_anchor(&bar_item->popup, anchor, popup->adid);
}

void popup_calculate_bounds(struct popup* popup) {
void popup_calculate_bounds(struct popup* popup, struct bar* bar) {
uint32_t y = popup->background.border_width;
uint32_t x = 0;
uint32_t total_item_width = 0;
Expand Down Expand Up @@ -166,7 +167,7 @@ void popup_calculate_bounds(struct popup* popup) {
if (bar_item->group
&& group_is_first_member(bar_item->group, bar_item)) {

uint32_t group_length = group_get_length(bar_item->group);
uint32_t group_length = group_get_length(bar_item->group, bar);
CGRect group_frame = {{frame.origin.x,
frame.origin.y },
{group_length,
Expand All @@ -179,7 +180,7 @@ void popup_calculate_bounds(struct popup* popup) {
}

if (bar_item->popup.drawing)
popup_calculate_popup_anchor_for_bar_item(popup, bar_item);
popup_calculate_popup_anchor_for_bar_item(popup, bar_item, bar);

if (item_width > width && !popup->horizontal) width = item_width;
if (popup->horizontal) x += item_width;
Expand Down Expand Up @@ -278,7 +279,6 @@ void popup_set_anchor(struct popup* popup, CGPoint anchor, uint32_t adid) {
}

popup->adid = adid;
popup_calculate_bounds(popup);
}

bool popup_set_drawing(struct popup* popup, bool drawing) {
Expand Down
3 changes: 2 additions & 1 deletion src/popup.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "window.h"

struct bar_item;
struct bar;

struct popup {
bool drawing;
Expand Down Expand Up @@ -36,7 +37,7 @@ bool popup_set_drawing(struct popup* popup, bool drawing);
void popup_remove_item(struct popup* popup, struct bar_item* bar_item);

uint32_t popup_get_width(struct popup* popup);
void popup_calculate_bounds(struct popup* popup);
void popup_calculate_bounds(struct popup* popup, struct bar* bar);
void popup_draw(struct popup* popup);
void popup_destroy(struct popup* popup);

Expand Down

0 comments on commit d8ff755

Please sign in to comment.