static J4statusAlsaSection * _j4status_alsa_section_new(J4statusCoreInterface *core, gchar *card) { J4statusAlsaSection *section; section = g_new0(J4statusAlsaSection, 1); section->card = card; int error; section->source = g_water_alsa_mixer_source_new(NULL, card, _j4status_alsa_section_mixer_callback, section, NULL, &error); if ( section->source == NULL ) { g_warning("Couldn't create ALSA mixer source for card %s: %s", card, snd_strerror(error)); g_free(section->card); g_free(section); return NULL; } section->mixer = g_water_alsa_mixer_source_get_mixer(section->source); error = snd_mixer_selem_register(section->mixer, NULL, NULL); if ( error < 0 ) { g_warning("Couldn't register ALSA mixer to card %s: %s", card, snd_strerror(error)); g_water_alsa_mixer_source_free(section->source); g_free(section->card); g_free(section); return NULL; } section->section = j4status_section_new(core); j4status_section_set_name(section->section, "alsa"); j4status_section_set_instance(section->section, card); if ( ! j4status_section_insert(section->section) ) { _j4status_alsa_section_free(section); return NULL; } error = snd_mixer_load(section->mixer); if ( error < 0 ) { g_warning("Couldn't load ALSA mixer for card %s: %s", section->card, snd_strerror(error)); _j4status_alsa_section_free(section); return NULL; } return section; }
static void _j4status_sensors_add_feature_temp(J4statusPluginContext *context, const sensors_chip_name *chip, const sensors_feature *feature) { const char *name = _j4status_sensors_get_feature_name(chip, feature); const sensors_subfeature *input; input = sensors_get_subfeature(chip, feature, SENSORS_SUBFEATURE_TEMP_INPUT); if ( input == NULL ) { g_warning("No temperature input on chip '%s', skipping", name); return; } J4statusSensorsFeature *sensor_feature; sensor_feature = g_new0(J4statusSensorsFeature, 1); sensor_feature->section = j4status_section_new(context->core); sensor_feature->chip = chip; sensor_feature->feature = feature; sensor_feature->input = input; sensor_feature->max = sensors_get_subfeature(chip, feature, SENSORS_SUBFEATURE_TEMP_MAX); sensor_feature->crit = sensors_get_subfeature(chip, feature, SENSORS_SUBFEATURE_TEMP_CRIT); char *label; label = sensors_get_label(chip, feature); gint64 max_width = strlen("+100.0*C"); if ( context->config.show_details ) { if ( ( sensor_feature->crit != NULL ) && ( sensor_feature->max != NULL ) ) max_width += strlen(" (high = +100.0°C, crit = +100.0°C)"); else if ( sensor_feature->crit != NULL ) max_width += strlen(" (crit = +100.0°C)"); else if ( sensor_feature->max != NULL ) max_width += strlen(" (high = +100.0°C)"); } j4status_section_set_name(sensor_feature->section, "sensors"); j4status_section_set_instance(sensor_feature->section, name); j4status_section_set_label(sensor_feature->section, label); j4status_section_set_max_width(sensor_feature->section, -max_width); free(label); if ( j4status_section_insert(sensor_feature->section) ) context->sections = g_list_prepend(context->sections, sensor_feature); else _j4status_sensors_feature_free(sensor_feature); }
static J4statusNlSection * _j4status_nl_section_new(J4statusPluginContext *context, J4statusCoreInterface *core, const gchar *interface) { struct rtnl_link *link; link = rtnl_link_get_by_name(context->link_cache, interface); if ( link == NULL ) { g_warning("Couldn't get interface %s", interface); return NULL; } const gchar *name = NULL; switch ( rtnl_link_get_arptype(link) ) { case ARPHRD_ETHER: name = "nl-ether"; break; case ARPHRD_IEEE80211: name = "nl-802.11"; break; default: g_warning("Interface %s has an unsupported type", interface); rtnl_link_put(link); return NULL; } J4statusNlSection *self; self = g_new0(J4statusNlSection, 1); self->context = context; self->ifindex = rtnl_link_get_ifindex(link); self->link = link; self->section = j4status_section_new(core); j4status_section_set_name(self->section, name); j4status_section_set_instance(self->section, interface); j4status_section_set_label(self->section, interface); if ( ! j4status_section_insert(self->section) ) { _j4status_nl_section_free(self); return NULL; } _j4status_nl_section_update(self); return self; }