绘制当前显示窗口的名称
This commit is contained in:
@@ -108,8 +108,10 @@ const char *const active_tag_bg = "#005577";
|
||||
const char *const tag_color = "#bbbbbb";
|
||||
const char *const active_tag_color = "#eeeeee";
|
||||
const char *const layout_color = "#bbbbbb";
|
||||
const char *const client_name_bg = "#222222";
|
||||
const char *const client_name_color = "#bbbbbb";
|
||||
const char *const active_client_name_color = "#005577";
|
||||
const char *const active_client_name_bg = "#005577";
|
||||
const char *const active_client_name_color = "#eeeeee";
|
||||
const char *const status_color = "#bbbbbb";
|
||||
const char *const border_color = "#444444";
|
||||
const char *const active_border_color = "#005577";
|
||||
@@ -121,4 +123,5 @@ const uint32_t dpi_fallback = 96;
|
||||
const uint32_t bar_y_padding = 1;
|
||||
const uint32_t tag_x_padding = 10;
|
||||
const uint32_t layout_symbol_x_padding = 10;
|
||||
const uint32_t client_name_x_padding = 10;
|
||||
const uint32_t border_width = 1;
|
||||
|
||||
@@ -14,5 +14,5 @@ uint32_t get_font_height(const char *font_family, const uint32_t font_size,
|
||||
const uint32_t dpi);
|
||||
void draw_bar(monitor_t *monitor, bool is_current_monitor,
|
||||
color_set_t *color_set, uint32_t height, uint32_t tag_x_padding,
|
||||
uint32_t layout_x_padding);
|
||||
uint32_t layout_x_padding, uint32_t client_name_x_padding);
|
||||
void clean_pango_context(void);
|
||||
|
||||
@@ -52,6 +52,8 @@ struct client_t {
|
||||
xcb_window_t window;
|
||||
};
|
||||
|
||||
#define CLIENT_VISIBLE(C) ((C)->tags & (C)->monitor->selected_tags)
|
||||
|
||||
typedef struct wallpaper_config_t {
|
||||
uint32_t count;
|
||||
char **path_list;
|
||||
@@ -109,7 +111,9 @@ typedef struct color_set_t {
|
||||
color_t tag_color;
|
||||
color_t active_tag_color;
|
||||
color_t layout_color;
|
||||
color_t client_name_bg;
|
||||
color_t client_name_color;
|
||||
color_t active_client_name_bg;
|
||||
color_t active_client_name_color;
|
||||
color_t status_color;
|
||||
color_t border_color;
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define CLIENT_VISIBLE(C) ((C)->tags & (C)->monitor->selected_tags)
|
||||
|
||||
/**
|
||||
* 获取下一个需要被布局算法自动管理的可见 client
|
||||
*/
|
||||
|
||||
22
src/main.c
22
src/main.c
@@ -84,6 +84,7 @@ static uint32_t dpi = dpi_fallback;
|
||||
static uint32_t bar_y_pad = bar_y_padding;
|
||||
static uint32_t tag_x_pad = tag_x_padding;
|
||||
static uint32_t layout_symbol_x_pad = layout_symbol_x_padding;
|
||||
static uint32_t client_name_x_pad = client_name_x_padding;
|
||||
static uint32_t bar_height = 0;
|
||||
static uint32_t border_px = border_width;
|
||||
|
||||
@@ -142,7 +143,9 @@ static void print_color_set(color_set_t *set) {
|
||||
print_color("== tag color:", &set->tag_color);
|
||||
print_color("== active tag color:", &set->active_tag_color);
|
||||
print_color("== layout bg:", &set->layout_color);
|
||||
print_color("== client name bg:", &set->client_name_bg);
|
||||
print_color("== client name color:", &set->client_name_color);
|
||||
print_color("== active client name bg:", &set->active_client_name_bg);
|
||||
print_color("== active client name color:", &set->active_client_name_color);
|
||||
print_color("== status color:", &set->status_color);
|
||||
print_color("== border color:", &set->border_color);
|
||||
@@ -385,7 +388,9 @@ void init_color_set(void) {
|
||||
char *tag = NULL;
|
||||
char *active_tag = NULL;
|
||||
char *layout = NULL;
|
||||
char *client_name_background = NULL;
|
||||
char *client_name = NULL;
|
||||
char *active_client_name_background = NULL;
|
||||
char *active_client_name = NULL;
|
||||
char *status = NULL;
|
||||
char *border = NULL;
|
||||
@@ -398,10 +403,14 @@ void init_color_set(void) {
|
||||
get_xresource_string("zswm.color.tag", &tag, tag_color);
|
||||
get_xresource_string("zswm.color.active_tag", &active_tag, active_tag_color);
|
||||
get_xresource_string("zswm.color.layout", &layout, layout_color);
|
||||
get_xresource_string("zswm.color.client_name", &client_name,
|
||||
get_xresource_string("zswm.color.client_name_bg", &client_name_background,
|
||||
client_name_bg);
|
||||
get_xresource_string("zswm.color.client_name_color", &client_name,
|
||||
client_name_color);
|
||||
get_xresource_string("zswm.color.active_client_name", &active_client_name,
|
||||
active_client_name_color);
|
||||
get_xresource_string("zswm.color.active_client_name_bg",
|
||||
&active_client_name_background, active_client_name_bg);
|
||||
get_xresource_string("zswm.color.active_client_name_color",
|
||||
&active_client_name, active_client_name_color);
|
||||
get_xresource_string("zswm.color.status", &status, status_color);
|
||||
get_xresource_string("zswm.color.border", &border, border_color);
|
||||
get_xresource_string("zswm.color.active_border", &active_border,
|
||||
@@ -413,7 +422,9 @@ void init_color_set(void) {
|
||||
parse_color(tag, &color_set->tag_color);
|
||||
parse_color(active_tag, &color_set->active_tag_color);
|
||||
parse_color(layout, &color_set->layout_color);
|
||||
parse_color(client_name_background, &color_set->client_name_bg);
|
||||
parse_color(client_name, &color_set->client_name_color);
|
||||
parse_color(active_client_name_background, &color_set->active_client_name_bg);
|
||||
parse_color(active_client_name, &color_set->active_client_name_color);
|
||||
parse_color(status, &color_set->status_color);
|
||||
parse_color(border, &color_set->border_color);
|
||||
@@ -425,7 +436,9 @@ void init_color_set(void) {
|
||||
free(tag);
|
||||
free(active_tag);
|
||||
free(layout);
|
||||
free(client_name_background);
|
||||
free(client_name);
|
||||
free(active_client_name_background);
|
||||
free(active_client_name);
|
||||
free(status);
|
||||
free(border);
|
||||
@@ -478,6 +491,7 @@ void get_xresource_config(void) {
|
||||
get_xresource_uint32("zswm.bar_y_padding", &bar_y_pad);
|
||||
get_xresource_uint32("zswm.tag_x_padding", &tag_x_pad);
|
||||
get_xresource_uint32("zswm.layout_symbol_x_padding", &layout_symbol_x_pad);
|
||||
get_xresource_uint32("zswm.client_name_x_padding", &client_name_x_pad);
|
||||
get_xresource_uint32("zswm.border_width", &border_px);
|
||||
|
||||
logger("dpi: %u, font family: %s, font size: %u\n", dpi, font_family,
|
||||
@@ -491,7 +505,7 @@ void draw_all_monitor_bars(void) {
|
||||
|
||||
void draw_monitor_bar(monitor_t *m) {
|
||||
draw_bar(m, m == current_monitor, color_set, bar_height, tag_x_pad,
|
||||
layout_symbol_x_pad);
|
||||
layout_symbol_x_pad, client_name_x_pad);
|
||||
flush_xcb_connection();
|
||||
}
|
||||
|
||||
|
||||
@@ -137,19 +137,22 @@ static void draw_rect(cairo_t *cr, int32_t x, int32_t y, uint32_t width,
|
||||
|
||||
void draw_bar(monitor_t *monitor, bool is_current_monitor,
|
||||
color_set_t *color_set, uint32_t height, uint32_t tag_x_padding,
|
||||
uint32_t layout_x_padding) {
|
||||
uint32_t layout_x_padding, uint32_t client_name_x_padding) {
|
||||
cairo_t *cr = monitor->cr;
|
||||
int32_t x = 0;
|
||||
uint32_t width = 0;
|
||||
const char *text;
|
||||
color_t *color;
|
||||
color_t *color, *bg;
|
||||
color_t *bar_bg = &color_set->bar_bg;
|
||||
uint32_t tag_mask_has_client = 0;
|
||||
uint32_t visible_client_count = 0;
|
||||
for (client_t *c = monitor->clients; c; c = c->next) {
|
||||
tag_mask_has_client |= c->tags;
|
||||
if (CLIENT_VISIBLE(c)) visible_client_count++;
|
||||
}
|
||||
|
||||
clean_cairo_context(cr);
|
||||
draw_background(cr, &color_set->bar_bg, 0, 0, monitor->monitor_width, height);
|
||||
draw_background(cr, bar_bg, 0, 0, monitor->monitor_width, height);
|
||||
|
||||
/* 绘制 tags */
|
||||
for (uint32_t i = 0; i < g_strv_length(monitor->tags); i++) {
|
||||
@@ -158,11 +161,12 @@ void draw_bar(monitor_t *monitor, bool is_current_monitor,
|
||||
text = monitor->tags[i];
|
||||
width = get_text_width(text) + tag_x_padding * 2;
|
||||
|
||||
color = selected ? &color_set->active_tag_bg : &color_set->tag_bg;
|
||||
if (color->rgba != color_set->bar_bg.rgba) {
|
||||
draw_background(cr, color, x, 0, width, height);
|
||||
}
|
||||
bg = selected ? &color_set->active_tag_bg : &color_set->tag_bg;
|
||||
color = selected ? &color_set->active_tag_color : &color_set->tag_color;
|
||||
|
||||
if (bg->rgba != bar_bg->rgba) {
|
||||
draw_background(cr, bg, x, 0, width, height);
|
||||
}
|
||||
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;
|
||||
@@ -175,6 +179,29 @@ void draw_bar(monitor_t *monitor, bool is_current_monitor,
|
||||
draw_text(cr, text, color, x, 0, width, height, true);
|
||||
x += width;
|
||||
}
|
||||
/* 绘制 client name 列表 */
|
||||
if (visible_client_count) {
|
||||
uint32_t box_width = (monitor->monitor_width - x) / visible_client_count;
|
||||
width = box_width - 2 * client_name_x_padding;
|
||||
for (client_t *c = monitor->clients; c; c = c->next) {
|
||||
if (!CLIENT_VISIBLE(c)) continue;
|
||||
if (is_current_monitor && c == monitor->selected_client) {
|
||||
bg = &color_set->active_client_name_bg;
|
||||
color = &color_set->active_client_name_color;
|
||||
} else {
|
||||
bg = &color_set->client_name_bg;
|
||||
color = &color_set->client_name_color;
|
||||
}
|
||||
|
||||
text = c->name;
|
||||
if (bg->rgba != bar_bg->rgba) {
|
||||
draw_background(cr, bg, x, 0, box_width, height);
|
||||
}
|
||||
x += client_name_x_padding;
|
||||
draw_text(cr, text, color, x, 0, width, height, false);
|
||||
x += width + client_name_x_padding;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void clean_pango_context(void) {
|
||||
|
||||
Reference in New Issue
Block a user