static void multiload_read(char **fp, MultiloadPlugin *ma) { guint i, found = 0; /* Initial settings */ ma->speed = 0; ma->size = 0; for ( i = 0; i < NGRAPHS; i++ ) { /* Default visibility and colors */ ma->graph_config[i].visible = FALSE; multiload_colorconfig_default(ma, i); } if ( fp != NULL ) { line s; while ( lxpanel_get_line(fp, &s) != LINE_BLOCK_END ) { if ( s.type == LINE_VAR ) { if ( g_ascii_strcasecmp(s.t[0], "speed") == 0 ) ma->speed = atoi(s.t[1]); else if ( g_ascii_strcasecmp(s.t[0], "size") == 0 ) ma->size = atoi(s.t[1]); else { const char *suffix; /* Set by multiload_find_graph_by_name */ int i = multiload_find_graph_by_name(s.t[0], &suffix); if ( suffix == NULL || i < 0 || i >= NGRAPHS ) continue; else if ( g_ascii_strcasecmp(suffix, "Visible") == 0 ) ma->graph_config[i].visible = atoi(s.t[1]) ? TRUE : FALSE; else if ( g_ascii_strcasecmp(suffix, "Colors") == 0 ) multiload_colorconfig_unstringify(ma, i, s.t[1]); } } else { ERR ("Failed to parse config token %s\n", s.str); break; } } } /* Handle errors from atoi */ if ( ma->speed == 0 ) ma->speed = DEFAULT_SPEED; if ( ma->size == 0 ) ma->size = DEFAULT_SIZE; /* Ensure at lease one graph is visible */ for ( i = 0; i < NGRAPHS; i++ ) if ( ma->graph_config[i].visible == TRUE ) found++; if ( found == 0 ) ma->graph_config[0].visible = TRUE; }
static int netstatus_constructor(Plugin *p, char** fp) { netstatus *ns; line s; NetstatusIface* iface; ENTER; s.len = 256; ns = g_new0(netstatus, 1); g_return_val_if_fail(ns != NULL, 0); p->priv = ns; ns->plugin = p; if( fp ) { while (lxpanel_get_line(fp, &s) != LINE_BLOCK_END) { if (s.type == LINE_NONE) { ERR( "netstatus: illegal token %s\n", s.str); goto error; } if (s.type == LINE_VAR) { if (!g_ascii_strcasecmp(s.t[0], "iface")) ns->iface = g_strdup(s.t[1]); else if (!g_ascii_strcasecmp(s.t[0], "configtool")) ns->config_tool = g_strdup(s.t[1]); else { ERR( "netstatus: unknown var %s\n", s.t[0]); } } else { ERR( "netstatus: illegal in this context %s\n", s.str); goto error; } } } else { ns->iface = g_strdup("eth0"); ns->config_tool = g_strdup("network-admin --configure %i"); } iface = netstatus_iface_new(ns->iface); ns->mainw = netstatus_icon_new( iface ); netstatus_icon_set_show_signal((NetstatusIcon *)ns->mainw, TRUE); gtk_widget_add_events( ns->mainw, GDK_BUTTON_PRESS_MASK ); g_object_unref( iface ); g_signal_connect( ns->mainw, "button-press-event", G_CALLBACK(on_button_press), p ); gtk_widget_show(ns->mainw); p->pwid = ns->mainw; RET(1); error: RET(0); }
/* Plugin constructor. */ static int space_constructor(Plugin * p, char ** fp) { /* Allocate plugin context and set into Plugin private data pointer. */ SpacePlugin * sp = g_new0(SpacePlugin, 1); p->priv = sp; /* Load parameters from the configuration file. */ line s; s.len = 256; if (fp != NULL) { while (lxpanel_get_line(fp, &s) != LINE_BLOCK_END) { if (s.type == LINE_NONE) { ERR( "space: illegal token %s\n", s.str); return 0; } if (s.type == LINE_VAR) { if (g_ascii_strcasecmp(s.t[0], "size") == 0) sp->size = atoi(s.t[1]); else ERR( "space: unknown var %s\n", s.t[0]); } else { ERR( "space: illegal in this context %s\n", s.str); return 0; } } } /* Default the size parameter. */ if (sp->size == 0) sp->size = 2; /* Allocate top level widget and set into Plugin widget pointer. */ p->pwid = gtk_event_box_new(); #if GTK_CHECK_VERSION(2,18,0) gtk_widget_set_has_window(p->pwid,FALSE); #else GTK_WIDGET_SET_FLAGS(p->pwid, GTK_NO_WINDOW); #endif gtk_widget_add_events(p->pwid, GDK_BUTTON_PRESS_MASK); gtk_container_set_border_width(GTK_CONTAINER(p->pwid), 0); /* Connect signals. */ g_signal_connect(p->pwid, "button-press-event", G_CALLBACK(plugin_button_press_event), p); /* Apply the configuration and show the widget. */ space_apply_configuration(p); gtk_widget_show(p->pwid); return 1; }
static int constructor(Plugin *p, char **fp) { ENTER; batt *b; p->priv = b = g_new0(batt, 1); p->pwid = gtk_event_box_new(); GTK_WIDGET_SET_FLAGS( p->pwid, GTK_NO_WINDOW ); gtk_container_set_border_width( GTK_CONTAINER(p->pwid), 1 ); b->drawingArea = gtk_drawing_area_new(); gtk_widget_add_events( b->drawingArea, GDK_BUTTON_PRESS_MASK ); gtk_container_add( (GtkContainer*)p->pwid, b->drawingArea ); if ((b->orientation = p->panel->orientation) == ORIENT_HORIZ) { b->height = b->length = 20; b->thickness = b->width = 8; } else { b->height = b->thickness = 8; b->length = b->width = 20; } gtk_widget_set_size_request(b->drawingArea, b->width, b->height); gtk_widget_show(b->drawingArea); b->bg = gdk_gc_new(p->panel->topgwin->window); b->gc1 = gdk_gc_new(p->panel->topgwin->window); b->gc2 = gdk_gc_new(p->panel->topgwin->window); g_signal_connect (G_OBJECT (b->drawingArea), "button_press_event", G_CALLBACK(buttonPressEvent), (gpointer) p); g_signal_connect (G_OBJECT (b->drawingArea),"configure_event", G_CALLBACK (configureEvent), (gpointer) b); g_signal_connect (G_OBJECT (b->drawingArea), "expose_event", G_CALLBACK (exposeEvent), (gpointer) b); sem_init(&(b->alarmProcessLock), 0, 1); b->alarmCommand = b->backgroundColor = b->chargingColor1 = b->chargingColor2 = b->dischargingColor1 = b->dischargingColor2 = NULL; /* Set default values for integers */ b->alarmTime = 5; b->requestedBorder = 1; b->numSamples = b->rateSamplesSum = b->wasCharging = 0; b->rateSamples = (unsigned int *) malloc(sizeof(int) * MAX_SAMPLES); line s; s.len = 256; if (fp) { /* Apply options */ while (lxpanel_get_line(fp, &s) != LINE_BLOCK_END) { if (s.type == LINE_NONE) { ERR( "batt: illegal token %s\n", s.str); goto error; } if (s.type == LINE_VAR) { if (!g_ascii_strcasecmp(s.t[0], "HideIfNoBattery")) b->hide_if_no_battery = atoi(s.t[1]); else if (!g_ascii_strcasecmp(s.t[0], "AlarmCommand")) b->alarmCommand = g_strdup(s.t[1]); else if (!g_ascii_strcasecmp(s.t[0], "BackgroundColor")) b->backgroundColor = g_strdup(s.t[1]); else if (!g_ascii_strcasecmp(s.t[0], "ChargingColor1")) b->chargingColor1 = g_strdup(s.t[1]); else if (!g_ascii_strcasecmp(s.t[0], "ChargingColor2")) b->chargingColor2 = g_strdup(s.t[1]); else if (!g_ascii_strcasecmp(s.t[0], "DischargingColor1")) b->dischargingColor1 = g_strdup(s.t[1]); else if (!g_ascii_strcasecmp(s.t[0], "DischargingColor2")) b->dischargingColor2 = g_strdup(s.t[1]); else if (!g_ascii_strcasecmp(s.t[0], "AlarmTime")) b->alarmTime = atoi(s.t[1]); else if (!g_ascii_strcasecmp(s.t[0], "BorderWidth")) b->requestedBorder = atoi(s.t[1]); else if (!g_ascii_strcasecmp(s.t[0], "Size")) { b->thickness = MAX(1, atoi(s.t[1])); if (b->orientation == ORIENT_HORIZ) b->width = b->thickness; else b->height = b->thickness; gtk_widget_set_size_request(b->drawingArea, b->width, b->height); } else { ERR( "batt: unknown var %s\n", s.t[0]); continue; } } else { ERR( "batt: illegal in this context %s\n", s.str); goto error; } } } /* Make sure the border value is acceptable */ b->border = MIN(MAX(0, b->requestedBorder), (MIN(b->length, b->thickness) - 1) / 2); /* Apply more default options */ if (! b->alarmCommand) b->alarmCommand = g_strdup("xmessage Battery low"); if (! b->backgroundColor) b->backgroundColor = g_strdup("black"); if (! b->chargingColor1) b->chargingColor1 = g_strdup("#28f200"); if (! b->chargingColor2) b->chargingColor2 = g_strdup("#22cc00"); if (! b->dischargingColor1) b->dischargingColor1 = g_strdup("#ffee00"); if (! b->dischargingColor2) b->dischargingColor2 = g_strdup("#d9ca00"); gdk_color_parse(b->backgroundColor, &b->background); gdk_color_parse(b->chargingColor1, &b->charging1); gdk_color_parse(b->chargingColor2, &b->charging2); gdk_color_parse(b->dischargingColor1, &b->discharging1); gdk_color_parse(b->dischargingColor2, &b->discharging2); gdk_colormap_alloc_color(gdk_drawable_get_colormap( p->panel->topgwin->window), &b->background, FALSE, TRUE); gdk_colormap_alloc_color(gdk_drawable_get_colormap( p->panel->topgwin->window), &b->charging1, FALSE, TRUE); gdk_colormap_alloc_color(gdk_drawable_get_colormap( p->panel->topgwin->window), &b->charging2, FALSE, TRUE); gdk_colormap_alloc_color(gdk_drawable_get_colormap( p->panel->topgwin->window), &b->discharging1, FALSE, TRUE); gdk_colormap_alloc_color(gdk_drawable_get_colormap( p->panel->topgwin->window), &b->discharging2, FALSE, TRUE); gdk_gc_set_foreground(b->bg, &b->background); check_batteries( b ); /* get available batteries */ /* Start the update loop */ #if GTK_CHECK_VERSION( 2, 14, 0 ) b->timer = g_timeout_add_seconds( 3, (GSourceFunc) update_timout, (gpointer) b); #else b->timer = g_timeout_add( 3000, (GSourceFunc) update_timout, (gpointer) b); #endif RET(TRUE); error: destructor( p ); RET(FALSE); }
/* Plugin constructor. */ static int dclock_constructor(Plugin * p, char ** fp) { /* Allocate and initialize plugin context and set into Plugin private data pointer. */ DClockPlugin * dc = g_new0(DClockPlugin, 1); p->priv = dc; dc->plugin = p; /* Load parameters from the configuration file. */ line s; s.len = 256; if (fp != NULL) { while (lxpanel_get_line(fp, &s) != LINE_BLOCK_END) { if (s.type == LINE_NONE) { ERR( "dclock: illegal token %s\n", s.str); return 0; } if (s.type == LINE_VAR) { if (g_ascii_strcasecmp(s.t[0], "ClockFmt") == 0) dc->clock_format = g_strdup(s.t[1]); else if (g_ascii_strcasecmp(s.t[0], "TooltipFmt") == 0) dc->tooltip_format = g_strdup(s.t[1]); else if (g_ascii_strcasecmp(s.t[0], "Action") == 0) dc->action = g_strdup(s.t[1]); else if (g_ascii_strcasecmp(s.t[0], "BoldFont") == 0) dc->bold = str2num(bool_pair, s.t[1], 0); else if (g_ascii_strcasecmp(s.t[0], "IconOnly") == 0) dc->icon_only = str2num(bool_pair, s.t[1], 0); else if (g_ascii_strcasecmp(s.t[0], "CenterText") == 0) dc->center_text = str2num(bool_pair, s.t[1], 0); else ERR( "dclock: unknown var %s\n", s.t[0]); } else { ERR( "dclock: illegal in this context %s\n", s.str); return 0; } } } /* Allocate top level widget and set into Plugin widget pointer. */ p->pwid = gtk_event_box_new(); /* Allocate a horizontal box as the child of the top level. */ GtkWidget * hbox = gtk_hbox_new(TRUE, 0); gtk_container_add(GTK_CONTAINER(p->pwid), hbox); gtk_widget_show(hbox); /* Create a label and an image as children of the horizontal box. * Only one of these is visible at a time, controlled by user preference. */ dc->clock_label = gtk_label_new(NULL); gtk_misc_set_alignment(GTK_MISC(dc->clock_label), 0.5, 0.5); gtk_misc_set_padding(GTK_MISC(dc->clock_label), 4, 0); gtk_container_add(GTK_CONTAINER(hbox), dc->clock_label); dc->clock_icon = gtk_image_new(); gtk_container_add(GTK_CONTAINER(hbox), dc->clock_icon); /* Connect signals. */ g_signal_connect(G_OBJECT (p->pwid), "button_press_event", G_CALLBACK(dclock_button_press_event), (gpointer) p); /* Initialize the clock display. */ if (dc->clock_format == NULL) dc->clock_format = g_strdup(DEFAULT_CLOCK_FORMAT); if (dc->tooltip_format == NULL) dc->tooltip_format = g_strdup(DEFAULT_TIP_FORMAT); dclock_apply_configuration(p); /* Show the widget and return. */ gtk_widget_show(p->pwid); return 1; }
static int monitors_constructor(Plugin *p, char **fp) { ENTER; int i; MonitorsPlugin *mp; mp = g_new0(MonitorsPlugin, 1); p->priv = mp; p->pwid = gtk_hbox_new(TRUE, 2); gtk_container_set_border_width(GTK_CONTAINER(p->pwid), 1); GTK_WIDGET_SET_FLAGS(p->pwid, GTK_NO_WINDOW); g_signal_connect(G_OBJECT(p->pwid), "button_press_event", G_CALLBACK(monitors_button_press_event), (gpointer) p); /* Apply options */ line s; s.len = 256; if (fp) { while (lxpanel_get_line(fp, &s) != LINE_BLOCK_END) { if (s.type == LINE_NONE) { ERR("%s : illegal token %s\n", PLUGIN_NAME, s.str); continue; } if (s.type == LINE_VAR) { if (g_ascii_strcasecmp(s.t[0], "DisplayCPU") == 0) mp->displayed_monitors[CPU_POSITION] = atoi(s.t[1]); else if (g_ascii_strcasecmp(s.t[0], "DisplayRAM") == 0) mp->displayed_monitors[MEM_POSITION] = atoi(s.t[1]); else if (g_ascii_strcasecmp(s.t[0], "Action") == 0) mp->action = g_strdup(s.t[1]); else if (g_ascii_strcasecmp(s.t[0], "CPUColor") == 0) colors[CPU_POSITION] = g_strndup(s.t[1], COLOR_SIZE-1); else if (g_ascii_strcasecmp(s.t[0], "RAMColor") == 0) colors[MEM_POSITION] = g_strndup(s.t[1], COLOR_SIZE-1); else { ERR("%s : unknown var %s\n", PLUGIN_NAME, s.t[0]); continue; } } } } else { /* First time we use this plugin : only display CPU usage */ mp->displayed_monitors[CPU_POSITION] = 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(TRUE); }
static int image_constructor(Plugin *p, char **fp) { gchar *tooltip, *fname; image *img; GdkPixbuf *gp, *gps; GtkWidget *wid; GError *err = NULL; char *config_start, *config_end; line s; s.len = 256; ENTER; img = g_new0(image, 1); g_return_val_if_fail(img != NULL, 0); p->priv = img; tooltip = fname = 0; if( fp ) { config_start = *fp; while (lxpanel_get_line(fp, &s) != LINE_BLOCK_END) { if (s.type == LINE_NONE) { ERR( "image: illegal token %s\n", s.str); goto error; } if (s.type == LINE_VAR) { if (!g_ascii_strcasecmp(s.t[0], "image")) fname = expand_tilda(s.t[1]); else if (!g_ascii_strcasecmp(s.t[0], "tooltip")) tooltip = g_strdup(s.t[1]); else { ERR( "image: unknown var %s\n", s.t[0]); goto error; } } else { ERR( "image: illegal in this context %s\n", s.str); goto error; } } config_end = *fp - 1; while( *config_end != '}' && config_end > config_start ) { --config_end; } if( *config_end == '}' ) --config_end; img->config_data = g_strndup( config_start, (config_end-config_start) ); } else { config_start = config_end = NULL; } img->mainw = gtk_event_box_new(); gtk_widget_show(img->mainw); //g_signal_connect(G_OBJECT(img->mainw), "expose_event", // G_CALLBACK(gtk_widget_queue_draw), NULL); gp = gdk_pixbuf_new_from_file(fname, &err); if (!gp) { g_warning("image: can't read image %s\n", fname); wid = gtk_label_new("?"); } else { float ratio; ratio = (p->panel->orientation == ORIENT_HORIZ) ? (float) (p->panel->ah - 2) / (float) gdk_pixbuf_get_height(gp) : (float) (p->panel->aw - 2) / (float) gdk_pixbuf_get_width(gp); gps = gdk_pixbuf_scale_simple (gp, ratio * ((float) gdk_pixbuf_get_width(gp)), ratio * ((float) gdk_pixbuf_get_height(gp)), GDK_INTERP_HYPER); wid = gtk_image_new_from_pixbuf(gps); g_object_unref(gp); g_object_unref(gps); } gtk_widget_show(wid); gtk_container_add(GTK_CONTAINER(img->mainw), wid); gtk_container_set_border_width(GTK_CONTAINER(img->mainw), 0); g_free(fname); if (tooltip) { gtk_widget_set_tooltip_text(img->mainw, tooltip); g_free(tooltip); } RET(1); error: g_free(fname); g_free(tooltip); image_destructor(p); RET(0); }