创建每个屏幕对应的信息条窗口
This commit is contained in:
63
src/main.c
63
src/main.c
@@ -1,3 +1,5 @@
|
||||
#include <cairo-xcb.h>
|
||||
#include <cairo.h>
|
||||
#include <glib.h>
|
||||
#include <glibconfig.h>
|
||||
#include <stdbool.h>
|
||||
@@ -23,6 +25,8 @@ static wallpaper_config_t *parse_wallpaper_config(void);
|
||||
static void free_wallpaper_config(wallpaper_config_t *wallpaper_config);
|
||||
static void init_color_set(void);
|
||||
static void parse_color(const char *hex, color_t *color);
|
||||
static void init_monitor_bar(void);
|
||||
static void get_xresource_config(void);
|
||||
static void init_xcb_event_loop(void);
|
||||
static gboolean handle_xcb_event(GIOChannel *channel, GIOCondition condition,
|
||||
gpointer userdata);
|
||||
@@ -32,6 +36,12 @@ static monitor_t *monitors = NULL;
|
||||
static wallpaper_config_t *wallpaper_config = NULL;
|
||||
static color_set_t *color_set = NULL;
|
||||
static GMainLoop *loop = NULL;
|
||||
static char *font_family = NULL;
|
||||
static uint32_t font_size = default_font_size;
|
||||
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 bar_height = 0;
|
||||
|
||||
/* 调试函数,开发完成后删除 */
|
||||
static void print_monitor_list_info(monitor_t *monitor_list) {
|
||||
@@ -278,6 +288,48 @@ void parse_color(const char *hex, color_t *color) {
|
||||
&color->alpha);
|
||||
}
|
||||
|
||||
void init_monitor_bar(void) {
|
||||
get_xresource_config();
|
||||
uint32_t font_height = get_font_height(font_family, font_size, dpi);
|
||||
bar_height = font_height + bar_y_pad * 2;
|
||||
for (monitor_t *m = monitors; m; m = m->next) {
|
||||
bar_cairo_params_t *p =
|
||||
create_bar_window(m->monitor_x, m->monitor_y, m->monitor_width,
|
||||
bar_height, color_set->bar_bg.argb, cursor_normal);
|
||||
m->window_x = m->monitor_x;
|
||||
m->window_width = m->monitor_width;
|
||||
m->window_y = m->monitor_y + bar_height;
|
||||
m->window_height = m->monitor_height - bar_height;
|
||||
m->bar_window = p->window;
|
||||
|
||||
cairo_surface_t *surface = cairo_xcb_surface_create(
|
||||
p->conn, p->window, p->visual, m->monitor_width, bar_height);
|
||||
cairo_t *cr = cairo_create(surface);
|
||||
cairo_surface_destroy(surface);
|
||||
free(p);
|
||||
|
||||
cairo_status_t status = cairo_status(cr);
|
||||
if (status != CAIRO_STATUS_SUCCESS) {
|
||||
die("cannot create cairo context: %s\n", cairo_status_to_string(status));
|
||||
}
|
||||
|
||||
m->cr = cr;
|
||||
}
|
||||
printf("font height: %u, bar height: %u\n", font_height, bar_height);
|
||||
}
|
||||
|
||||
void get_xresource_config(void) {
|
||||
get_xresource_uint32("Xft.dpi", &dpi);
|
||||
get_xresource_string("zswm.font_family", &font_family, default_font_family);
|
||||
get_xresource_uint32("zswm.font_size", &font_size);
|
||||
get_xresource_uint32("zswm.bar_y_padding", &bar_y_pad);
|
||||
get_xresource_uint32("zswm.tag_x_padding", &tag_x_pad);
|
||||
|
||||
printf("dpi: %u, font family: %s, font size: %u\n", dpi, font_family,
|
||||
font_size);
|
||||
clean_xresource();
|
||||
}
|
||||
|
||||
void init_xcb_event_loop(void) {
|
||||
GIOChannel *channel = g_io_channel_unix_new(get_xcb_connection_fd());
|
||||
g_io_channel_set_encoding(channel, NULL, NULL);
|
||||
@@ -298,7 +350,7 @@ gboolean handle_xcb_event(GIOChannel *channel, GIOCondition condition,
|
||||
}
|
||||
|
||||
void cleanup(void) {
|
||||
clean_xcb();
|
||||
clean_pango_context();
|
||||
|
||||
free_wallpaper_config(wallpaper_config);
|
||||
wallpaper_config = NULL;
|
||||
@@ -306,6 +358,9 @@ void cleanup(void) {
|
||||
free(color_set);
|
||||
color_set = NULL;
|
||||
|
||||
free(font_family);
|
||||
font_family = NULL;
|
||||
|
||||
monitor_t *m = monitors;
|
||||
client_t *c = m->clients;
|
||||
while (m) {
|
||||
@@ -315,11 +370,15 @@ void cleanup(void) {
|
||||
c = tc;
|
||||
}
|
||||
monitor_t *next_monitor = m->next;
|
||||
if (m->cr) cairo_destroy(m->cr);
|
||||
destroy_window(m->bar_window);
|
||||
g_strfreev(m->tags);
|
||||
free(m);
|
||||
m = next_monitor;
|
||||
}
|
||||
monitors = NULL;
|
||||
|
||||
clean_xcb();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
@@ -329,6 +388,8 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
init_monitors();
|
||||
init_color_set();
|
||||
init_monitor_bar();
|
||||
set_root_cursor(cursor_normal);
|
||||
init_wallpaper();
|
||||
|
||||
window_list_t *window_list = scan_window_list();
|
||||
|
||||
Reference in New Issue
Block a user