solus-project / budgie-desktop

I Tawt I Taw A Purdy Desktop
https://solus-project.com/
2.33k stars 158 forks source link

budgie wm background is not able to parse xml #227

Closed xiangzhai closed 8 years ago

xiangzhai commented 9 years ago

Hi budgie-desktop developers,

Thanks for your wm background implementation https://github.com/AOSC-Dev/elsa-shell/blob/master/src/wm/background.c I can use it in my Elsa Shell ;P

It use org.gnome.desktop.background schema, so it is able to change the background easily by gnome-control-center background or nautilus.

But when clicked the first wallpaper it is a *.xml file /usr/share/backgrounds/gnome/adwaita-timed.xml budgie wm background is not able to parse it, so I simply patch it shown as below:

diff --git a/src/wm/background.c b/src/wm/background.c
index 8819e40..0552163 100644
--- a/src/wm/background.c
+++ b/src/wm/background.c
@@ -15,6 +15,8 @@
 #include <meta/meta-background.h>
 #include <meta/meta-background-group.h>
 #include <meta/meta-version.h>
+#include <libxml/xmlmemory.h>
+#include <libxml/parser.h>

 #include "background.h"

@@ -182,6 +184,53 @@ static void on_update(MetaBackground *background, BudgieBackground *self)
         g_object_set(self->priv->bg, "opacity", 255, NULL);
         clutter_actor_restore_easing_state(self->priv->bg);
 }
+
+static gchar *_parse_static(xmlDocPtr doc, xmlNodePtr cur)
+{
+        cur = cur->xmlChildrenNode;
+        while (cur) {
+                if (xmlStrcmp(cur->name, "file") == 0)
+                        return xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+
+                cur = cur->next;
+        }
+
+        return NULL;
+}
+
+static gchar *_parse_xml(const gchar *filename)
+{
+        xmlDocPtr doc = NULL;
+        xmlNodePtr cur = NULL;
+        gchar *static_filename = NULL;
+
+        doc = xmlParseFile(filename);
+        if (!doc)
+                goto cleanup;
+
+        cur = xmlDocGetRootElement(doc);
+        if (!cur)
+                goto cleanup;
+
+        cur = cur->xmlChildrenNode;
+        while (cur) {
+                if (xmlStrcmp(cur->name, "static") == 0) {
+                        static_filename = _parse_static(doc, cur);
+                        break;
+                }
+
+                cur = cur->next;
+        }
+
+cleanup:
+        if (doc) {
+                xmlFreeDoc(doc);
+                doc = NULL;
+        }
+
+        return static_filename;
+}
+
 /**
  * Actually update our appearance..
  * ATM this is totally hacky and only uses picture-uri :P
@@ -252,6 +301,9 @@ static void _update(BudgieBackground *self)
                 bg_file = g_file_new_for_uri(bg_filename);

 #if META_MINOR_VERSION > 14
+                if (g_str_has_suffix(bg_filename, ".xml"))
+                        bg_file = g_file_new_for_path(_parse_xml(bg_filename));
+
                 meta_background_set_file(background, bg_file, style);
 #else
                 char *filename = g_file_get_path(bg_file);

Thanks again for your great wm background implementation again ;-)

Regards, Leslie Zhai

ikeydoherty commented 9 years ago

Concept is sound, but inconsistent with our coding style. For the record, the gnome-desktop library has specific handlers for this :] I don't want to add that extra weight, so I'll implement our own internal handler soon for XML slideshows (with update frequency, etc) - which you'll be more than welcome to take back from us :]

xiangzhai commented 9 years ago

Hi @ikeydoherty I am not (very) familiar with libgnome-desktop, but tried to use it to support slideshow ;P https://github.com/AOSC-Dev/elsa-shell/blob/master/configure.ac#L20

I only use gnome_bg_create_thumbnail before as gnome-control-center display did https://git.gnome.org/browse/gnome-control-center/tree/panels/display/cc-display-panel.c#n358

I need to read libgnome-desktop source code https://git.gnome.org/browse/gnome-desktop/ more carefully ;-)

ikeydoherty commented 8 years ago

This is now being tracked in #261