Beispiel #1
0
/* Plugin constructor. */
static GtkWidget *space_constructor(Panel *panel, config_setting_t *settings)
{
    /* Allocate plugin context and set into Plugin private data pointer. */
    SpacePlugin * sp = g_new0(SpacePlugin, 1);
    GtkWidget * p;

    /* Load parameters from the configuration file. */
    config_setting_lookup_int(settings, "Size", &sp->size);

    /* Save construction pointers */
    sp->panel = panel;
    sp->settings = settings;

    /* Default the size parameter. */
    if (sp->size == 0)
        sp->size = 2;

    /* Allocate top level widget and set into Plugin widget pointer. */
    p = gtk_event_box_new();
    lxpanel_plugin_set_data(p, sp, g_free);
#if GTK_CHECK_VERSION(2,18,0)
    gtk_widget_set_has_window(p,FALSE);
#else
    GTK_WIDGET_SET_FLAGS(p, GTK_NO_WINDOW);
#endif
    gtk_widget_add_events(p, GDK_BUTTON_PRESS_MASK);
    gtk_container_set_border_width(GTK_CONTAINER(p), 0);

    /* Apply the configuration and show the widget. */
    space_apply_configuration(p);
    return p;
}
Beispiel #2
0
static GtkWidget *
thermal_constructor(LXPanel *panel, config_setting_t *settings)
{
    thermal *th;
    GtkWidget *p;
    const char *tmp;

    ENTER;
    th = g_new0(thermal, 1);
    th->panel = panel;
    th->settings = settings;

    p = gtk_event_box_new();
    lxpanel_plugin_set_data(p, th, thermal_destructor);
    gtk_widget_set_has_window(p, FALSE);
    gtk_container_set_border_width( GTK_CONTAINER(p), 2 );

    th->namew = gtk_label_new("ww");
    gtk_container_add(GTK_CONTAINER(p), th->namew);

    th->tip = g_string_new(NULL);

    /* By default, use automatic, that is, "not custom" temperature levels. If
     * we were using custom levels, they would be 0°C at startup, so we would
     * display in warning colors by default. */
    th->not_custom_levels = TRUE;

    if (config_setting_lookup_string(settings, "NormalColor", &tmp))
        th->str_cl_normal = g_strdup(tmp);
    if (config_setting_lookup_string(settings, "Warning1Color", &tmp))
        th->str_cl_warning1 = g_strdup(tmp);
    if (config_setting_lookup_string(settings, "Warning2Color", &tmp))
        th->str_cl_warning2 = g_strdup(tmp);
    config_setting_lookup_int(settings, "AutomaticSensor", &th->auto_sensor);
    /* backward compatibility for wrong variable */
    config_setting_lookup_int(settings, "CustomLevels", &th->not_custom_levels);
    config_setting_lookup_int(settings, "AutomaticLevels", &th->not_custom_levels);
    if (config_setting_lookup_string(settings, "Sensor", &tmp))
        th->sensor = g_strdup(tmp);
    config_setting_lookup_int(settings, "Warning1Temp", &th->warning1);
    config_setting_lookup_int(settings, "Warning2Temp", &th->warning2);

    if(!th->str_cl_normal)
        th->str_cl_normal = g_strdup("#00ff00");
    if(!th->str_cl_warning1)
        th->str_cl_warning1 = g_strdup("#fff000");
    if(!th->str_cl_warning2)
        th->str_cl_warning2 = g_strdup("#ff0000");

    applyConfig(p);

    gtk_widget_show(th->namew);

    update_display(th);
    th->timer = g_timeout_add_seconds(3, (GSourceFunc) update_display_timeout, (gpointer)th);

    RET(p);
}
Beispiel #3
0
static GtkWidget *
monitors_constructor(LXPanel *panel, config_setting_t *settings)
{
    ENTER;
    int i;
    MonitorsPlugin *mp;
    GtkWidget *p;
    const char *tmp;

    mp = g_new0(MonitorsPlugin, 1);
    mp->panel = panel;
    mp->settings = settings;

    p = gtk_hbox_new(TRUE, 2);
    lxpanel_plugin_set_data(p, mp, monitors_destructor);

    /* First time we use this plugin : only display CPU usage */
    mp->displayed_monitors[CPU_POSITION] = 1;

    /* Apply options */
    config_setting_lookup_int(settings, "DisplayCPU",
                              &mp->displayed_monitors[CPU_POSITION]);
    config_setting_lookup_int(settings, "DisplayRAM",
                              &mp->displayed_monitors[MEM_POSITION]);
    if (config_setting_lookup_string(settings, "Action", &tmp))
        mp->action = g_strdup(tmp);
    if (config_setting_lookup_string(settings, "CPUColor", &tmp))
        colors[CPU_POSITION] = g_strndup(tmp, COLOR_SIZE-1);
    if (config_setting_lookup_string(settings, "RAMColor", &tmp))
        colors[MEM_POSITION] = g_strndup(tmp, COLOR_SIZE-1);

    /* Initializing monitors */
    for (i = 0; i < N_MONITORS; i++)
    {
        if (!colors[i])
            colors[i] = g_strndup(default_colors[i], COLOR_SIZE-1);

        if (mp->displayed_monitors[i])
        {
            mp->monitors[i] = monitors_add_monitor(p, mp,
                                                   update_functions[i],
                                                   tooltip_update[i],
                                                   colors[i]);
        }
    }

    /* Adding a timer : monitors will be updated every UPDATE_PERIOD
     * seconds */
    mp->timer = g_timeout_add_seconds(UPDATE_PERIOD, (GSourceFunc) monitors_update,
                              (gpointer) mp);
    RET(p);
}
Beispiel #4
0
static GtkWidget *volume_constructor(LXPanel *panel, config_setting_t *settings)
{
    volume_t *vol;
    GtkWidget *p;
    GtkAdjustment *vol_adjustment;

    vol_before_mute = 1;
    curr_volume = 0;
    curr_image = NULL;
    skip_botton1_event = FALSE;

    ENTER;
    /* check if OSS mixer device could be open */
    mixer_fd = open ("/dev/mixer", O_RDWR, 0);
    if (mixer_fd < 0) {
        RET(NULL);
    }
    /* try to obtain current volume */
    p = create_volume_window(); /* use pointer */
    if (! vol_spin)
        goto _error;
    vol_adjustment = gtk_spin_button_get_adjustment (vol_spin);
    if (! vol_adjustment)
    {
_error:
        gtk_widget_destroy(p);
        RET(NULL);
    }
    curr_volume = gtk_adjustment_get_value (vol_adjustment);

    vol = g_new0(volume_t, 1);
    vol->dlg = p; /* it was reused */

    p = gtk_event_box_new();
    lxpanel_plugin_set_data(p, vol, volume_destructor);
    vol->panel = panel;

    gtk_widget_add_events(p, GDK_BUTTON_PRESS_MASK);
    g_signal_connect(p, "scroll-event", G_CALLBACK(on_mouse_scroll), vol);
    gtk_widget_set_size_request(p, panel_get_icon_size(panel), panel_get_icon_size(panel));

    update_icon(p, vol);
    gtk_widget_destroy( vol->dlg );
    vol->dlg = NULL;

    /* FIXME: display current level in tooltip. ex: "Volume Control: 80%"  */
    gtk_widget_set_tooltip_text(p, _("Volume control"));

    RET(p);
}
Beispiel #5
0
/* Plugin constructor. */
static GtkWidget *wincmd_constructor(LXPanel *panel, config_setting_t *settings)
{
    /* Allocate plugin context and set into Plugin private data pointer. */
    WinCmdPlugin * wc = g_new0(WinCmdPlugin, 1);
    GtkWidget * p;
    const char *str;
    int tmp_int;

    /* Initialize to defaults. */
    wc->button_1_command = WC_ICONIFY;
    wc->button_2_command = WC_SHADE;

    /* Load parameters from the configuration file. */
    if (config_setting_lookup_string(settings, "Button1", &str))
    {
        if (g_ascii_strcasecmp(str, "shade") == 0)
            wc->button_1_command = WC_SHADE;
        else if (g_ascii_strcasecmp(str, "none") == 0)
            wc->button_1_command = WC_NONE;
        /* default is WC_ICONIFY */
    }
    if (config_setting_lookup_string(settings, "Button2", &str))
    {
        if (g_ascii_strcasecmp(str, "iconify") == 0)
            wc->button_2_command = WC_ICONIFY;
        else if (g_ascii_strcasecmp(str, "none") == 0)
            wc->button_2_command = WC_NONE;
    }
    if (config_setting_lookup_string(settings, "image", &str))
        wc->image = expand_tilda(str);
    if (config_setting_lookup_int(settings, "Toggle", &tmp_int))
        wc->toggle_preference = tmp_int != 0;

    /* Default the image if unspecified. */
    if (wc->image == NULL)
        wc->image = g_strdup("window-manager");

    /* Save construction pointers */
    wc->settings = settings;

    /* Allocate top level widget and set into Plugin widget pointer. */
    p = lxpanel_button_new_for_icon(panel, wc->image, NULL, NULL);
    lxpanel_plugin_set_data(p, wc, wincmd_destructor);
    gtk_container_set_border_width(GTK_CONTAINER(p), 0);
    gtk_widget_set_tooltip_text(p, _("Left click to iconify all windows.  Middle click to shade them."));

    /* Show the widget and return. */
    return p;
}
Beispiel #6
0
static GtkWidget *plugin_constructor(LXPanel *panel, config_setting_t *settings)
{
    /* allocate our private structure instance */
    kano_feedback_plugin_t *plugin = g_new0(kano_feedback_plugin_t, 1);
    plugin->panel = panel;

    /* need to create a widget to show */
    GtkWidget *pwid = gtk_button_new();
    gtk_button_set_relief(GTK_BUTTON(pwid), GTK_RELIEF_NONE);

    lxpanel_plugin_set_data(pwid, plugin, g_free);

    /* create an icon */
    GtkWidget *icon = gtk_image_new_from_file(WIDGET_ICON);

    /* set border width */
    gtk_container_set_border_width(GTK_CONTAINER(pwid), 0);

    /* add the label to the container */
    gtk_container_add(GTK_CONTAINER(pwid), GTK_WIDGET(icon));

    /* our widget doesn't have a window... */
    gtk_widget_set_has_window(pwid, FALSE);

    gtk_signal_connect(GTK_OBJECT(pwid), "button-press-event",
               GTK_SIGNAL_FUNC(show_menu), NULL);

    /* Set a tooltip to the icon to show when the mouse sits over the it */
    GtkTooltips *tooltips;
    tooltips = gtk_tooltips_new();
    gtk_tooltips_set_tip(tooltips, GTK_WIDGET(icon), PLUGIN_TOOLTIP, NULL);

    gtk_widget_set_sensitive(icon, TRUE);

    /* show our widget */
    gtk_widget_show_all(pwid);

    return pwid;
}
Beispiel #7
0
/* Plugin constructor. */
static GtkWidget *dirmenu_constructor(LXPanel *panel, config_setting_t *settings)
{
    /* Allocate and initialize plugin context and set into Plugin private data pointer. */
    DirMenuPlugin * dm = g_new0(DirMenuPlugin, 1);
    GtkWidget * p;
    const char *str;

    /* Load parameters from the configuration file. */
    if (config_setting_lookup_string(settings, "image", &str))
        dm->image = g_strdup(str);
    if (config_setting_lookup_string(settings, "path", &str))
        dm->path = expand_tilda(str);
    else
        dm->path = g_strdup(fm_get_home_dir());
    if (config_setting_lookup_string(settings, "name", &str))
        dm->name = g_strdup(str);

    /* Save construction pointers */
    dm->panel = panel;
    dm->settings = settings;

    /* Allocate top level widget and set into Plugin widget pointer.
     * It is not known why, but the button text will not draw if it is edited from empty to non-empty
     * unless this strategy of initializing it with a non-empty value first is followed. */
    p = lxpanel_button_new_for_icon(panel,
                            ((dm->image != NULL) ? dm->image : "file-manager"),
                            NULL, "Temp");
    lxpanel_plugin_set_data(p, dm, dirmenu_destructor);

    /* Initialize the widget. */
    dirmenu_apply_configuration(p);

    g_signal_connect(G_OBJECT(p), "button-release-event",
                     G_CALLBACK(dirmenu_button_release_event), dm);

    /* Show the widget and return. */
    return p;
}