Namespaces
Variants
Actions

How to set wallpaper in Maemo 5

Jump to: navigation, search
Archived.png
Archived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

The article is believed to be still valid for the original topic scope.


Article Metadata

Article
Created: divanov (31 Mar 2010)
Last edited: lpvalente (06 Dec 2012)


Qt doesn't provide general API for setting wallpapers since this is platform dependent. Fortunately API is really simple. Wallpaper settings are saved as Gconf2 keys. Using gconftool-2 it's easy to verify the settings

$ gconftool-2 -R /apps/osso/hildon-desktop/views
current = 1
active = [1,2,3,4]
/apps/osso/hildon-desktop/views/1:
bg-image = /home/user/MyDocs/.images/wallpaper1.png
/apps/osso/hildon-desktop/views/2:
bg-image = /home/user/MyDocs/.images/wallpaper2.png
/apps/osso/hildon-desktop/views/3:
bg-image = /home/user/MyDocs/.images/wallpaper3.png
/apps/osso/hildon-desktop/views/4:
bg-image = /home/user/MyDocs/.images/wallpaper4.png

There are 4 active desktops, current one is first one and some images are set as wallpapers.

Sample application, which takes a screenshot and then set is as a wallpaper to the current active desktop:

#include <QCoreApplication>
#include <QProcess>
#include <QStringList>
#include <QDebug>
 
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
 
#include <gconf/gconf.h>
#include <gconf/gconf-client.h>
 
#define SHOT_NAME "screenshot.png"
 
int main (int argc, char **argv)
{
QCoreApplication app(argc, argv);
 
int currentDesktop = getXIntProperty("_NET_CURRENT_DESKTOP");
takeScreenshot(SHOT_NAME);
QString shotPath = QDir::currentPath() + "/" SHOT_NAME;
QByteArray shotPathUtf8 = shotPath.toUtf8();
setWallpaper(shotPathUtf8.data(), currentDesktop);
 
return 0;
}

Function for obtaining number of currently active desktop:

static int getXIntProperty (const char *propertyName)
{
Atom realType;
int format, status, num;
unsigned long n, extra;
unsigned char *data = 0;
char *display_name = getenv("DISPLAY");
Display *display = XOpenDisplay(display_name);
int screen = DefaultScreen(display);
Window rootWindow = RootWindow(display, screen);
Atom atom = XInternAtom(display, propertyName, false);
 
status = XGetWindowProperty(display, rootWindow, atom, 0L, 16L,
0, XA_CARDINAL, &realType, &format,
&n, &extra, &data);
if (status == Success && realType == XA_CARDINAL &&
format == 32 && n == 1 && data)
num = ((int*)data)[0];
else
num = -1;
 
if (data)
XFree(data);
XCloseDisplay(display);
 
return num;
}

Function for taking a screenshot, it uses screenshot-tool, it has to be installed on the device before you try the sample application:

static void takeScreenshot (const char *shotName)
{
QStringList args;
args << shotName;
if(QProcess::execute ("screenshot-tool", args))
qDebug("Cannot take a screenshot, install screenshot-tool package");
}

Function for setting wallpaper:

static void setWallpaper (const char *uri, giant desktop)
{
GConfClient *client = gconf_client_get_default();
if (client) {
GError *error = 0;
char *path = g_strdup_printf("/apps/osso/hildon-desktop/views/%i/bg-image",
1 + desktop);
if (!gconf_client_set_string(client, path, uri, &error)) {
qDebug() << uri << error->message;
g_error_free(error);
}
g_free(path);
g_object_unref(client);
} else
qDebug("Cannot get GConf2 client");
}

Add these lines to automatically generated .pro file:

unix {
CONFIG += link_pkgconfig
PKGCONFIG += gconf-2.0
}
This page was last modified on 6 December 2012, at 22:05.
114 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved