/* Callback when the configuration dialog has recorded a configuration change. */ static gboolean dirmenu_apply_configuration(gpointer user_data) { GtkWidget * p = user_data; DirMenuPlugin * dm = lxpanel_plugin_get_data(p); char * path = dm->path; /* Normalize path */ if (path == NULL) dm->path = g_strdup(fm_get_home_dir()); else if (path[0] == '~') { dm->path = expand_tilda(path); g_free(path); } /* Save configuration */ config_group_set_string(dm->settings, "path", dm->path); config_group_set_string(dm->settings, "name", dm->name); config_group_set_string(dm->settings, "image", dm->image); lxpanel_button_set_icon(p, ((dm->image != NULL) ? dm->image : "file-manager"), -1); lxpanel_button_set_label(p, dm->name); gtk_widget_set_tooltip_text(p, dm->path); return FALSE; }
static int read_dicon(icons_priv *ics, gchar *name) { gchar *fname; GdkPixbuf *gp; int size; gulong *data; ENTER; fname = expand_tilda(name); if (!fname) RET(0); gp = gdk_pixbuf_new_from_file(fname, NULL); if (gp) { if ((data = pixbuf2argb(gp, &size))) { ics->dicon = g_new0 (wmpix_t, 1); ics->dicon->data = data; ics->dicon->size = size; } g_object_unref(gp); } g_free(fname); RET(1); }
/* 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; }
static int read_application(icons_priv *ics, xconf *xc) { GdkPixbuf *gp = NULL; gchar *fname, *iname, *appname, *classname; wmpix_t *wp = NULL; gulong *data; int size; ENTER; iname = fname = appname = classname = NULL; XCG(xc, "image", &fname, str); XCG(xc, "icon", &iname, str); XCG(xc, "appname", &appname, str); XCG(xc, "classname", &classname, str); fname = expand_tilda(fname); DBG("appname=%s classname=%s\n", appname, classname); if (!(fname || iname)) goto error; gp = fb_pixbuf_new(iname, fname, 48, 48, FALSE); if (gp) { if ((data = pixbuf2argb(gp, &size))) { wp = g_new0 (wmpix_t, 1); wp->next = ics->wmpix; wp->data = data; wp->size = size; wp->ch.res_name = g_strdup(appname); wp->ch.res_class = g_strdup(classname); DBG("read name=[%s] class=[%s]\n", wp->ch.res_name, wp->ch.res_class); ics->wmpix = wp; } g_object_unref(gp); } g_free(fname); RET(1); error: g_free(fname); RET(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; }
static void make_button(plugin_instance *p, xconf *xc) { int w, h; menu_priv *m; gchar *fname, *iname; ENTER; m = (menu_priv *) p; /* XXX: this code is duplicated in every plugin. * Lets run it once in a panel */ if (p->panel->orientation == GTK_ORIENTATION_HORIZONTAL) { w = -1; h = p->panel->max_elem_height; } else { w = p->panel->max_elem_height; h = -1; } fname = iname = NULL; XCG(xc, "image", &fname, str); fname = expand_tilda(fname); XCG(xc, "icon", &iname, str); if (fname || iname) { m->bg = fb_button_new(iname, fname, w, h, 0x702020, NULL); gtk_container_add(GTK_CONTAINER(p->pwid), m->bg); if (p->panel->transparent) gtk_bgbox_set_background(m->bg, BG_INHERIT, 0, 0); g_signal_connect (G_OBJECT (m->bg), "button-press-event", G_CALLBACK (my_button_pressed), p); } g_free(fname); }
static int wincmd_constructor(plugin *p) { line s; gchar *tooltip, *fname; wincmd *wc; //GdkPixbuf *gp, *gps; GtkWidget *button; int w, h; ENTER; s.len = 256; wc = g_new0(wincmd, 1); g_return_val_if_fail(wc != NULL, 0); wc->tips = gtk_tooltips_new(); p->priv = wc; tooltip = fname = 0; while (get_line(p->fp, &s) != LINE_BLOCK_END) { if (s.type == LINE_NONE) { ERR( "wincmd: illegal token %s\n", s.str); goto error; } if (s.type == LINE_VAR) { if (!g_ascii_strcasecmp(s.t[0], "Button1")) wc->button1 = str2num(wincmd_pair, s.t[1], WC_ICONIFY); else if (!g_ascii_strcasecmp(s.t[0], "Button2")) wc->button2 = str2num(wincmd_pair, s.t[1], WC_SHADE); else if (!g_ascii_strcasecmp(s.t[0], "tooltip")) tooltip = g_strdup(s.t[1]); else if (!g_ascii_strcasecmp(s.t[0], "image")) fname = expand_tilda(s.t[1]); else { ERR( "wincmd: unknown var %s\n", s.t[0]); goto error; } } else { ERR( "wincmd: illegal in this context %s\n", s.str); goto error; } } if (p->panel->orientation == ORIENT_HORIZ) { w = 10000; h = p->panel->ah; } else { w = p->panel->aw; h = 10000; } button = fb_button_new_from_file(fname, w, h, 0x202020, TRUE); gtk_container_set_border_width(GTK_CONTAINER(button), 0); g_signal_connect(G_OBJECT(button), "button_press_event", G_CALLBACK(clicked), (gpointer)wc); gtk_widget_show(button); gtk_container_add(GTK_CONTAINER(p->pwid), button); if (p->panel->transparent) gtk_bgbox_set_background(button, BG_ROOT, p->panel->tintcolor, p->panel->alpha); g_free(fname); if (tooltip) { gtk_tooltips_set_tip(GTK_TOOLTIPS (wc->tips), button, tooltip, NULL); g_free(tooltip); } RET(1); error: g_free(fname); g_free(tooltip); wincmd_destructor(p); ERR( "%s - exit\n", __FUNCTION__); RET(0); }
static int read_application(plugin *p) { icons *ics = (icons *)p->priv; GdkPixbuf *gp = NULL; line s; gchar *fname, *iname, *appname, *classname; wmpix_t *wp = NULL; gulong *data; int size; ENTER; s.len = 256; iname = fname = appname = classname = NULL; while (get_line(p->fp, &s) != LINE_BLOCK_END) { if (s.type == LINE_NONE) { ERR( "icons: 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], "icon")) iname = g_strdup(s.t[1]); else if (!g_ascii_strcasecmp(s.t[0], "appname")) appname = g_strdup(s.t[1]); else if (!g_ascii_strcasecmp(s.t[0], "classname")) classname = g_strdup(s.t[1]); else { ERR( "icons: unknown var %s\n", s.t[0]); goto error; } } else { ERR( "icons: illegal in this context %s\n", s.str); goto error; } } if (!(fname || iname)) goto error; gp = fb_pixbuf_new_from_icon_file(iname, fname, 48, 48); if (gp) { if ((data = pixbuf2argb(gp, &size))) { wp = g_new0 (wmpix_t, 1); wp->next = ics->wmpix; wp->data = data; wp->size = size; wp->ch.res_name = appname; wp->ch.res_class = classname; ics->wmpix = wp; ics->wmpixno++; } g_object_unref(gp); } g_free(fname); RET(1); error: g_free(fname); g_free(appname); g_free(classname); RET(0); }
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); }
/* Creates menu item. Text and image are read from xconf. Action * depends on @menu. If @menu is NULL, action is to execute external * command. Otherwise it is to pop up @menu menu */ static GtkWidget * menu_create_item(xconf *xc, GtkWidget *menu, menu_priv *m) { gchar *name, *fname, *iname, *action, *cmd; GtkWidget *mi; cmd = name = fname = action = iname = NULL; XCG(xc, "name", &name, str); mi = gtk_image_menu_item_new_with_label(name ? name : ""); gtk_container_set_border_width(GTK_CONTAINER(mi), 0); XCG(xc, "image", &fname, str); fname = expand_tilda(fname); XCG(xc, "icon", &iname, str); if (fname || iname) { GdkPixbuf *pb; if ((pb = fb_pixbuf_new(iname, fname, m->icon_size, m->icon_size, FALSE))) { gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), gtk_image_new_from_pixbuf(pb)); g_object_unref(G_OBJECT(pb)); } } g_free(fname); if (menu) { gtk_menu_item_set_submenu(GTK_MENU_ITEM(mi), menu); goto done; } XCG(xc, "action", &action, str); if (action) { action = expand_tilda(action); g_signal_connect_swapped(G_OBJECT(mi), "activate", (GCallback)run_app, action); g_object_set_data_full(G_OBJECT(mi), "activate", action, g_free); goto done; } XCG(xc, "command", &cmd, str); if (cmd) { /* XXX: implement command API */ #if 0 command *tmp; for (tmp = commands; tmp->name; tmp++) if (!g_ascii_strcasecmp(cmd, tmp->name)) { g_signal_connect(G_OBJECT(mi), "activate", (GCallback)run_command, tmp->cmd); goto done; } #endif } done: return mi; }