添加状态栏和调整音量的快捷键
This commit is contained in:
26
src/main.c
26
src/main.c
@@ -17,6 +17,7 @@
|
||||
#include "event-adapter.h"
|
||||
#include "layout.h"
|
||||
#include "renderer.h"
|
||||
#include "status.h"
|
||||
#include "types.h"
|
||||
#include "utils.h"
|
||||
#include "xcb.h"
|
||||
@@ -33,6 +34,7 @@ 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 update_status(status_t *status);
|
||||
static void draw_all_monitor_bars(void);
|
||||
static void draw_monitor_bar(monitor_t *monitor);
|
||||
static void init_xcb_event_loop(void);
|
||||
@@ -77,6 +79,7 @@ static monitor_t *current_monitor = NULL;
|
||||
static cairo_t *wallpaper_cr = NULL;
|
||||
static wallpaper_config_t *wallpaper_config = NULL;
|
||||
static color_set_t *color_set = NULL;
|
||||
static status_t *status = NULL;
|
||||
static GMainLoop *loop = NULL;
|
||||
static event_adapter_t *adapter = NULL;
|
||||
static char *font_family = NULL;
|
||||
@@ -86,6 +89,7 @@ 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 status_x_pad = status_x_padding;
|
||||
static uint32_t bar_height = 0;
|
||||
static uint32_t border_px = border_width;
|
||||
|
||||
@@ -184,6 +188,12 @@ void raise_or_run(const user_action_arg_t *arg) {
|
||||
spawn(&argument);
|
||||
}
|
||||
|
||||
void toggle_mute(const user_action_arg_t *arg) { toggle_pulse_mute(); }
|
||||
|
||||
void change_volume(const user_action_arg_t *arg) {
|
||||
change_pulse_volume(arg->i);
|
||||
}
|
||||
|
||||
/* 调试函数,开发完成后删除 */
|
||||
static void print_monitor_list_info(monitor_t *monitor_list) {
|
||||
logger("========================= monitor info =========================\n");
|
||||
@@ -559,6 +569,7 @@ void get_xresource_config(void) {
|
||||
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.status_x_padding", &status_x_pad);
|
||||
get_xresource_uint32("zswm.border_width", &border_px);
|
||||
|
||||
logger("dpi: %u, font family: %s, font size: %u\n", dpi, font_family,
|
||||
@@ -566,13 +577,18 @@ void get_xresource_config(void) {
|
||||
clean_xresource();
|
||||
}
|
||||
|
||||
static void update_status(status_t *s) {
|
||||
status = s;
|
||||
draw_all_monitor_bars();
|
||||
}
|
||||
|
||||
void draw_all_monitor_bars(void) {
|
||||
for (monitor_t *m = monitors; m; m = m->next) draw_monitor_bar(m);
|
||||
}
|
||||
|
||||
void draw_monitor_bar(monitor_t *m) {
|
||||
draw_bar(m, m == current_monitor, color_set, bar_height, tag_x_pad,
|
||||
layout_symbol_x_pad, client_name_x_pad);
|
||||
draw_bar(m, m == current_monitor, status, color_set, bar_height, tag_x_pad,
|
||||
layout_symbol_x_pad, client_name_x_pad, status_x_pad);
|
||||
flush_xcb_connection();
|
||||
}
|
||||
|
||||
@@ -1117,6 +1133,8 @@ gboolean handle_xcb_event(GIOChannel *channel, GIOCondition condition,
|
||||
}
|
||||
|
||||
void cleanup(void) {
|
||||
clean_status();
|
||||
|
||||
g_main_loop_unref(loop);
|
||||
loop = NULL;
|
||||
|
||||
@@ -1161,12 +1179,15 @@ int main(int argc, char *argv[]) {
|
||||
die("another window manager is already running");
|
||||
}
|
||||
|
||||
loop = g_main_loop_new(NULL, FALSE);
|
||||
|
||||
setup_xcb();
|
||||
init_monitors();
|
||||
init_color_set();
|
||||
init_monitor_bar();
|
||||
change_window_cursor(get_root_window(), cursor_normal);
|
||||
init_wallpaper();
|
||||
init_status(g_main_loop_get_context(loop), update_status);
|
||||
|
||||
draw_all_monitor_bars();
|
||||
|
||||
@@ -1192,7 +1213,6 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
init_xcb_event_loop();
|
||||
|
||||
loop = g_main_loop_new(NULL, FALSE);
|
||||
g_main_loop_run(loop);
|
||||
|
||||
cleanup();
|
||||
|
||||
Reference in New Issue
Block a user