Compare commits

..

2 Commits

2 changed files with 15 additions and 11 deletions

View File

@@ -3,6 +3,7 @@
#include <glib.h>
#include <math.h>
#include <pulse/context.h>
#include <pulse/def.h>
#include <pulse/glib-mainloop.h>
#include <pulse/introspect.h>
#include <pulse/subscribe.h>
@@ -47,6 +48,7 @@ static status_changed_notify listener = NULL;
static bool pulse_inited = false;
static pa_cvolume current_volume;
static pa_context *context = NULL;
static pa_glib_mainloop *loop = NULL;
static double calc_cpu_usage(cpu_stat_t curr, cpu_stat_t prev) {
uint64_t curr_idle = curr.idle + curr.iowait;
@@ -291,7 +293,6 @@ static void sink_info_callback(pa_context *c, const pa_sink_info *info, int eol,
}
if (info) {
context = c;
parse_sink(info, &status.pulse);
current_volume = info->volume;
pulse_inited = true;
@@ -307,15 +308,11 @@ static void server_info_callback(pa_context *c, const pa_server_info *info,
static void subscribe_callback(pa_context *c, pa_subscription_event_type_t t,
uint32_t idx, void *userdata) {
pa_subscription_event_type_t event = t & PA_SUBSCRIPTION_EVENT_TYPE_MASK;
uint32_t facility = t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK;
if (facility != PA_SUBSCRIPTION_EVENT_SINK) {
return;
}
if (event == PA_SUBSCRIPTION_EVENT_CHANGE) {
if (facility == PA_SUBSCRIPTION_EVENT_SINK) {
pa_context_get_server_info(c, server_info_callback, NULL);
return;
}
}
@@ -327,7 +324,9 @@ static void clean_pulse() {
pa_context_unref(context);
context = NULL;
}
if (loop) pa_glib_mainloop_free(loop);
pulse_inited = false;
loop = NULL;
}
static void init_pulse(GMainContext *g_context);
@@ -336,7 +335,7 @@ static void state_callback(pa_context *c, void *userdata) {
if (PA_CONTEXT_IS_GOOD(state)) {
pa_context_set_subscribe_callback(c, subscribe_callback, NULL);
pa_context_subscribe(c, PA_SUBSCRIPTION_MASK_SINK, NULL, NULL);
pa_context_get_server_info(c, server_info_callback, userdata);
pa_context_get_server_info(c, server_info_callback, NULL);
} else if (state == PA_CONTEXT_FAILED) {
clean_pulse();
init_pulse((GMainContext *)userdata);
@@ -344,11 +343,12 @@ static void state_callback(pa_context *c, void *userdata) {
}
static void init_pulse(GMainContext *g_context) {
if (loop) pa_glib_mainloop_free(loop);
pa_glib_mainloop *loop = pa_glib_mainloop_new(g_context);
pa_mainloop_api *api = pa_glib_mainloop_get_api(loop);
pa_context *ctx = pa_context_new(api, "ZSWM-Status-Volume");
pa_context_connect(ctx, NULL, PA_CONTEXT_NOFAIL, NULL);
pa_context_set_state_callback(ctx, state_callback, g_context);
context = pa_context_new(api, "ZSWM-Status-Volume");
pa_context_connect(context, NULL, PA_CONTEXT_NOFAIL, NULL);
pa_context_set_state_callback(context, state_callback, g_context);
}
static gboolean update_status(gpointer data) {

View File

@@ -10,6 +10,7 @@
#include <xcb/xcb_ewmh.h>
#include <xcb/xcb_icccm.h>
#include <xcb/xcb_image.h>
#include <xcb/xcb_keysyms.h>
#include <xcb/xinerama.h>
#include <xcb/xproto.h>
@@ -288,9 +289,11 @@ void clean_xcb(void) {
focus_window(XCB_WINDOW_NONE);
clean_xcb_cursor();
clean_ewmh_extension();
if (key_symbols) xcb_key_symbols_free(key_symbols);
xcb_disconnect(conn);
conn = NULL;
screen = NULL;
key_symbols = NULL;
}
void grab_keybindings(const keybinding_t *keys, const size_t length) {
@@ -310,6 +313,7 @@ void grab_keybindings(const keybinding_t *keys, const size_t length) {
keycode = xcb_key_symbols_get_keycode(key_symbols, keysym);
modifiers = keys[i].modifiers;
cookie = xcb_grab_key(conn, key, root, modifiers, *keycode, mode, mode);
free(keycode);
error = xcb_request_check(conn, cookie);
if (error) {
clean_xcb();