Exemplo n.º 1
0
static J4statusPluginContext *
_j4status_mem_init(J4statusCoreInterface *core)
{
    const gchar MEM[]= "Memory";
    GKeyFile *key_file = j4status_config_get_key_file(MEM);
    guint period = 0;
    guint good_threshold = 0;
    guint bad_threshold = 0;
    if (key_file) {
        period = g_key_file_get_integer(key_file, MEM, "Frequency", NULL);
        good_threshold = g_key_file_get_integer(
            key_file, MEM, "GoodThreshold", NULL);
        bad_threshold = g_key_file_get_integer(
            key_file, MEM, "BadThreshold", NULL);
        g_key_file_free(key_file);
    }

    J4statusSection *section = j4status_section_new(core);
    j4status_section_set_name(section, "mem");
    if (!j4status_section_insert(section)) {
        j4status_section_free(section);
        return NULL;
    }

    J4statusPluginContext *context = g_new(J4statusPluginContext, 1);
    context->section = section;
    context->good_threshold = good_threshold > 0 ? good_threshold : 50;
    context->bad_threshold = bad_threshold > context->good_threshold ?
        bad_threshold : 90;
    context->period = MAX(period, 1);
    return context;
}
Exemplo n.º 2
0
static J4statusPluginContext *
_j4status_i3focus_init(J4statusCoreInterface *core)
{
    i3ipcConnection *connection;
    i3ipcCommandReply *reply;
    GError *error = NULL;

    connection = i3ipc_connection_new(NULL, &error);
    if ( connection == NULL )
    {
        g_warning("Couldn't connection to i3: %s", error->message);
        g_clear_error(&error);
        return NULL;
    }

    reply = i3ipc_connection_subscribe(connection, I3IPC_EVENT_WINDOW, &error);
    if ( reply == NULL )
    {
        g_warning("Couldn't subscribe to i3 events: %s", error->message);
        g_clear_error(&error);
        g_object_unref(connection);
        return NULL;
    }
    if ( ! reply->success )
    {
        g_warning("Couldn't subscribe to i3 events: %s", reply->error);
        i3ipc_command_reply_free(reply);
        g_object_unref(connection);
        return NULL;
    }
    i3ipc_command_reply_free(reply);

    J4statusPluginContext *context;

    context = g_new0(J4statusPluginContext, 1);
    context->connection = connection;

    context->section = j4status_section_new(core);
    j4status_section_set_name(context->section, "i3focus");
    if ( ! j4status_section_insert(context->section) )
    {
        _j4status_i3focus_uninit(context);
        return NULL;
    }

    g_signal_connect(context->connection, "window", G_CALLBACK(_j4status_i3focus_window_callback), context->section);

    return context;
}
Exemplo n.º 3
0
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);
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
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;
}