2009-08-03 14 views

Respuesta

9

Aunque la pregunta era gnome-específica, también hay una manera de lidiar con el fondo de pantalla que no se depepndant en los kits de herramientas de capas superiores. Usted debe ser capaz de hacer frente a la ventana raíz (que el fondo de pantalla es, de hecho) mediante el estudio de la fuente de xsetroot.c, la parte más interesante de la que CopyPaste aquí:

static void 
SetBackgroundToBitmap(Pixmap bitmap, unsigned int width, unsigned int height) 
{ 
    Pixmap pix; 
    GC gc; 
    XGCValues gc_init; 

    gc_init.foreground = NameToPixel(fore_color, BlackPixel(dpy, screen)); 
    gc_init.background = NameToPixel(back_color, WhitePixel(dpy, screen)); 
    if (reverse) { 
     unsigned long temp=gc_init.foreground; 
     gc_init.foreground=gc_init.background; 
     gc_init.background=temp; 
    } 
    gc = XCreateGC(dpy, root, GCForeground|GCBackground, &gc_init); 
    pix = XCreatePixmap(dpy, root, width, height, 
         (unsigned int)DefaultDepth(dpy, screen)); 
    XCopyPlane(dpy, bitmap, pix, gc, 0, 0, width, height, 0, 0, (unsigned long)1); 
    XSetWindowBackgroundPixmap(dpy, root, pix); 
    XFreeGC(dpy, gc); 
    XFreePixmap(dpy, bitmap); 
    if (save_colors) 
     save_pixmap = pix; 
    else 
     XFreePixmap(dpy, pix); 
    XClearWindow(dpy, root); 
    unsave_past = 1; 
} 
+0

Gracias. Eso funciona perfectamente. – computergeek6

2

Si nada más, es probable que podría utilizar system() a invocar una de las líneas de comando sugeridas aquí:

http://www.linuxquestions.org/questions/linux-general-1/change-background-via-command-line-350936/

+2

OP preguntó acerca de GNOME, no de KDE. –

+0

¿A quién le importa? El hilo enlazado no responde ninguna de las preguntas. – innaM

+1

Si va al post # 5 en el hilo, se menciona un comando gconftool-2 que establece la imagen de fondo en GNOME. – Amber

18

Usted podría utilizar gconf biblioteca para hacerlo. El siguiente ejemplo es un completo programa para cambiar el fondo:

// bkgmanage.c 
#include <glib.h> 
#include <gconf/gconf-client.h> 
#include <stdio.h> 

typedef enum { 
    WALLPAPER_ALIGN_TILED  = 0, 
    WALLPAPER_ALIGN_CENTERED = 1, 
    WALLPAPER_ALIGN_STRETCHED = 2, 
    WALLPAPER_ALIGN_SCALED = 3, 
    WALLPAPER_NONE   = 4 
} WallpaperAlign; 

gboolean set_as_wallpaper(const gchar *image_path, WallpaperAlign align) 
{ 
    GConfClient *client; 
    char  *options = "none"; 

    client = gconf_client_get_default(); 

    // TODO: check that image_path is a file 
    if (image_path == NULL) options = "none"; 
    else { 
     gconf_client_set_string(client, 
      "/desktop/gnome/background/picture_filename", 
      image_path, 
      NULL); 
     switch (align) { 
      case WALLPAPER_ALIGN_TILED: options = "wallpaper"; break; 
      case WALLPAPER_ALIGN_CENTERED: options = "centered"; break; 
      case WALLPAPER_ALIGN_STRETCHED: options = "stretched"; break; 
      case WALLPAPER_ALIGN_SCALED: options = "scaled"; break; 
      case WALLPAPER_NONE: options = "none"; break; 
     } 
    } 
    gboolean result = gconf_client_set_string(client, 
     "/desktop/gnome/background/picture_options", 
     options, 
     NULL); 
    g_object_unref(G_OBJECT(client)); 

    return result; 
} 

int main(int argc, const char* argv[]) 
{ 
    if (argc > 1) { 
    printf("Setting %s as wallpaper... ", argv[1]); 
    if (set_as_wallpaper(argv[1], WALLPAPER_ALIGN_STRETCHED)) printf("Ok\n"); 
    else printf("Failed\n"); 
    } else printf("Usage: ./bkgmanage <filename>\n"); 

    return 0; 
} 

La fuente se basa en la anterior gthumb proyecto. Podría ser compilado con la siguiente secuencia:

gcc -Wall -g `pkg-config --libs --cflags glib-2.0 gconf-2.0` bkgmanage.c -o bkgmanage 
Cuestiones relacionadas