diff options
Diffstat (limited to 'src/bdm.c')
-rw-r--r-- | src/bdm.c | 82 |
1 files changed, 76 insertions, 6 deletions
@@ -16,14 +16,13 @@ #include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include <dlfcn.h> #include "bdm.h" #include <X11/Xlib.h> #include <X11/Xatom.h> -BDMWidgetList * widgetList; - static void renderImage(cairo_t * cr, BDMImage * image, ScreenArea * area) { cairo_set_source_rgba(cr,0,0,0,0); @@ -116,20 +115,22 @@ static void renderText (cairo_t * cr, BDMText * text, ScreenArea * area) static void updateWidgets(cairo_t * cr,ScreenArea * area) { - BDMWidget * widget = widgetList->head; + GSList * widgets; + BDMWidget * widget; BDMImage * image; BDMText * text; - for (widget=widgetList->head;widget;widget=widget->next) + for (widgets=Widgets;widgets;widgets=widgets->next) { + widget = widgets->data; widget->updateWidget(); if (widget->attrib->needsPainting) { - for (image = widget->getImages(); image; image = image->next) + for (image = widget->images; image; image = image->next) { if (image->attrib->needsPainting) renderImage(cr,image,area); } - for (text = widget->getText(); text; text=text->next) + for (text = widget->texts; text; text=text->next) { if (text->attrib->needsPainting) renderText(cr,text,area); @@ -187,6 +188,58 @@ static void on_alpha_screen_changed(GtkWidget * widget, GdkScreen * pOldScreen, gtk_widget_set_colormap(widget,pColormap); } +static void initPaintAttribs (BDMPaintAttribs * attribs) +{ + attribs->width = attribs->height = attribs->x = attribs->y = attribs->alpha = 0; + attribs->needsPainting = attribs->updateFont = 0; +} + +static int loadWidget (char * path) +{ + void * widgetDL; + widgetDL = dlopen (path, RTLD_NOW); + if (!widgetDL) + return 0; + + BDMWidget * widget = malloc (sizeof (BDMWidget)); + if (!widget) + { + dlclose (widgetDL); + return 0; + } + + widget->attrib = malloc (sizeof (BDMPaintAttribs)); + if (!widget->attrib) + { + free (widget); + dlclose (widgetDL); + return 0; + } + initPaintAttribs (widget->attrib); + + widget->initWidget = dlsym (widgetDL, "init"); + widget->finiWidget = dlsym (widgetDL, "fini"); + widget->updateWidget = dlsym (widgetDL, "update"); + + widget->getImages = dlsym (widgetDL, "getImages"); + widget->getTexts = dlsym (widgetDL, "getTexts"); + + widget->handleEvent = dlsym (widgetDL, "handleEvent"); + widget->setBDMWidget = dlsym (widgetDL, "setBDMWidget"); + + widget->images = widget->getImages (); + widget->texts = widget->getTexts (); + + widget->prev = (BDMWidget *) g_slist_last (Widgets); + widget->prev->next = widget; + widget->next = NULL; + + widget->initWidget (); + + Widgets = g_slist_append (Widgets, widget); + + return 1; +} int main(int argc, char * argv[]) { @@ -285,6 +338,7 @@ int main(int argc, char * argv[]) { free(w); } + g_free (s); } if (!Wallpapers) { @@ -292,6 +346,22 @@ int main(int argc, char * argv[]) return 1; } + keys = g_key_file_get_keys (kf, "widgets", &n_keys, &error); + + if (error != NULL || n_keys == 0) + { + fprintf (stderr, "All your widgets are belong to me.\n"); + } + else + { + for(i = 0; i < n_keys; i++) + { + gchar * s = g_key_file_get_string (kf, "widgets", keys[i], NULL); + loadWidget (s); + g_free (s); + } + } + g_key_file_free (kf); GSList * wp = Wallpapers; |