绘制 tag 的 client 标志
This commit is contained in:
@@ -112,6 +112,29 @@ static void clean_cairo_context(cairo_t *cr) {
|
||||
cairo_restore(cr);
|
||||
}
|
||||
|
||||
static void draw_rect(cairo_t *cr, int32_t x, int32_t y, uint32_t width,
|
||||
uint32_t height, bool fill, color_t *color,
|
||||
uint32_t line_width) {
|
||||
cairo_set_line_width(cr, line_width);
|
||||
if (fill) {
|
||||
cairo_rectangle(cr, x, y, width, height);
|
||||
cairo_set_source_rgba(cr, color->red, color->green, color->blue,
|
||||
color->alpha);
|
||||
cairo_fill(cr);
|
||||
} else {
|
||||
double half_lw = (double)line_width / 2;
|
||||
double sx = x, sy = y, w = width, h = height;
|
||||
sx += half_lw;
|
||||
sy += half_lw;
|
||||
w -= line_width;
|
||||
h -= line_width;
|
||||
cairo_rectangle(cr, sx, sy, w, h);
|
||||
cairo_set_source_rgba(cr, color->red, color->green, color->blue,
|
||||
color->alpha);
|
||||
cairo_stroke(cr);
|
||||
}
|
||||
}
|
||||
|
||||
void draw_bar(monitor_t *monitor, bool is_current_monitor,
|
||||
color_set_t *color_set, uint32_t height, uint32_t tag_x_padding) {
|
||||
cairo_t *cr = monitor->cr;
|
||||
@@ -119,13 +142,18 @@ void draw_bar(monitor_t *monitor, bool is_current_monitor,
|
||||
uint32_t width = 0;
|
||||
const char *text;
|
||||
color_t *color;
|
||||
uint32_t tag_mask_has_client = 0;
|
||||
for (client_t *c = monitor->clients; c; c = c->next) {
|
||||
tag_mask_has_client |= c->tags;
|
||||
}
|
||||
|
||||
clean_cairo_context(cr);
|
||||
draw_background(cr, &color_set->bar_bg, 0, 0, monitor->monitor_width, height);
|
||||
|
||||
/* 绘制 tags */
|
||||
for (int i = 0; i < g_strv_length(monitor->tags); i++) {
|
||||
for (uint32_t i = 0; i < g_strv_length(monitor->tags); i++) {
|
||||
bool selected = (monitor->selected_tags >> i) & 0x1;
|
||||
bool has_client = (1 << i) & tag_mask_has_client;
|
||||
text = monitor->tags[i];
|
||||
width = get_text_width(text) + tag_x_padding * 2;
|
||||
|
||||
@@ -134,6 +162,7 @@ void draw_bar(monitor_t *monitor, bool is_current_monitor,
|
||||
draw_background(cr, color, x, 0, width, height);
|
||||
}
|
||||
color = selected ? &color_set->active_tag_color : &color_set->tag_color;
|
||||
if (has_client) draw_rect(cr, x, 0, 4, 4, selected, color, 1);
|
||||
draw_text(cr, text, color, x, 0, width, height, true);
|
||||
x += width;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user