Exemple #1
0
static void
_j4status_sensors_feature_fan_update(J4statusPluginContext *context, J4statusSensorsFeature *feature)
{
    double curr;
    sensors_get_value(feature->chip, feature->input->number, &curr);

    double high = -1;
    if ( feature->max != NULL )
        sensors_get_value(feature->chip, feature->max->number, &high);

    J4statusState state;

    if ( ( high > 0 ) && ( curr > high ) )
        state = J4STATUS_STATE_BAD;
    else
        state = J4STATUS_STATE_GOOD;

    j4status_section_set_state(feature->section, state);

    if ( ! context->config.show_details )
        high = -1;

    gchar *value;
    if ( high > 0 )
        value = g_strdup_printf("%.0frpm (high = %.0frpm)", curr, high);
    else
        value = g_strdup_printf("%.0frpm", curr);

    j4status_section_set_value(feature->section, value);
}
static void
_j4status_i3focus_window_callback(GObject *object, i3ipcWindowEvent *event, gpointer user_data)
{
    J4statusSection *section = user_data;
    gboolean focused;

    g_object_get(event->container, "focused", &focused, NULL);

    if ( focused )
        j4status_section_set_value(section, g_strdup(i3ipc_con_get_name(event->container)));
}
Exemple #3
0
static void
_j4status_sensors_feature_temp_update(J4statusPluginContext *context, J4statusSensorsFeature *feature)
{
    double curr;
    sensors_get_value(feature->chip, feature->input->number, &curr);

    double high = -1;
    if ( feature->max != NULL )
        sensors_get_value(feature->chip, feature->max->number, &high);

    double crit = -1;
    if ( feature->crit != NULL )
        sensors_get_value(feature->chip, feature->crit->number, &crit);

    J4statusState state;

    if ( ( high > 0 ) && ( curr > high ) )
        state = J4STATUS_STATE_BAD;
    else
        state = J4STATUS_STATE_GOOD;

    if ( ( crit > 0 ) && ( curr > crit ) )
        state |= J4STATUS_STATE_URGENT;

    if ( ( ! context->started ) && ( ( state & J4STATUS_STATE_URGENT ) == 0 ) )
        return;

    j4status_section_set_state(feature->section, state);

    if ( ! context->config.show_details )
        high = crit = -1;

    gchar *value;
    if ( ( high > 0 ) && ( crit > 0 ) )
        value = g_strdup_printf("%+.1f°C (high = %+.1f°C, crit = %+.1f°C)", curr, high, crit);
    else if ( high > 0 )
        value = g_strdup_printf("%+.1f°C (high = %+.1f°C)", curr, high);
    else if ( crit > 0 )
        value = g_strdup_printf("%+.1f°C (crit = %+.1f°C)", curr, crit);
    else
        value = g_strdup_printf("%+.1f°C", curr);
    j4status_section_set_value(feature->section, value);
}
Exemple #4
0
static gboolean
_j4status_mem_update(gpointer user_data)
{
    J4statusPluginContext *context = user_data;

    struct sysinfo meminfo;
    sysinfo(&meminfo);

    unsigned long used_ram = meminfo.totalram - meminfo.freeram -
        meminfo.sharedram - meminfo.bufferram;
    double mem_percent = 100.0 * used_ram / meminfo.totalram;

    j4status_section_set_state(context->section,
        mem_percent < context->good_threshold ? J4STATUS_STATE_GOOD :
        mem_percent > context->bad_threshold ? J4STATUS_STATE_BAD :
            J4STATUS_STATE_AVERAGE);
    j4status_section_set_value(context->section,
        g_strdup_printf("%04.1f%%", mem_percent));

    return G_SOURCE_CONTINUE;
}
Exemple #5
0
static void
_j4status_nl_section_update(J4statusNlSection *self)
{
    if ( self->link == NULL )
        return;

    guint flags;
    flags = rtnl_link_get_flags(self->link);

    gchar *value = NULL;
    J4statusState state = J4STATUS_STATE_NO_STATE;
    if ( flags & IFF_LOWER_UP )
    {
        if ( ( self->ipv4_addresses == NULL ) && ( self->ipv6_addresses == NULL ) )
        {
            state = J4STATUS_STATE_AVERAGE;
            value = g_strdup("Connecting");
        }
        else
        {
            gchar *addresses;
            addresses = _j4status_nl_section_get_addresses(self);

            state = J4STATUS_STATE_GOOD;
            value = j4status_format_string_replace(self->context->formats.up, _j4status_nl_format_up_callback, addresses);

            g_free(addresses);
        }
    }
    else if ( flags & (IFF_UP | IFF_RUNNING) )
    {
        state = J4STATUS_STATE_BAD;
        value = g_strdup("Not connected");
        _j4status_nl_section_free_addresses(self);
    }

    j4status_section_set_state(self->section, state);
    j4status_section_set_value(self->section, value);
}
Exemple #6
0
static void
_j4status_alsa_section_update(J4statusAlsaSection *section, snd_mixer_elem_t *elem)
{
    if ( ( ! snd_mixer_selem_has_playback_volume(elem) )
         || ( ! snd_mixer_selem_has_playback_switch(elem) )
         || ( ! snd_mixer_selem_has_playback_channel(elem, SND_MIXER_SCHN_FRONT_LEFT) ) )
        return;

    int error;
    gboolean pswitch = TRUE;
    error = snd_mixer_selem_get_playback_switch(elem, SND_MIXER_SCHN_FRONT_LEFT, &pswitch);
    if ( error < 0 )
        g_warning("Couldn't get muted status: %s", snd_strerror(error));
    else
    {
        if ( pswitch )
            j4status_section_set_state(section->section, J4STATUS_STATE_GOOD);
        else
            j4status_section_set_state(section->section, J4STATUS_STATE_BAD);
    }

    glong volume = 0;
    if ( section->use_dB )
        error = snd_mixer_selem_get_playback_dB(elem, SND_MIXER_SCHN_FRONT_LEFT, &volume);
    else
        error = snd_mixer_selem_get_playback_volume(elem, SND_MIXER_SCHN_FRONT_LEFT, &volume);
    if ( error < 0 )
        g_warning("Couldn't get volume: %s", snd_strerror(error));
    else
    {
        guint8 vol;
        gchar *v;
        vol = _j4status_alsa_get_normalized_volume(volume, section->min, section->max, section->use_dB);
        v = g_strdup_printf("%hu%%", vol);
        j4status_section_set_value(section->section, v);
    }
}