[gnome-love] Setting the background of a gtk_window



Hi everybody,

I'm trying to set the background of a gtk_window to some program defined
color (i.e. without using any resource file), but that does not work:
The background remains grey (which is the default).

I'using gdk_window_set_background in the following manner, just before
gtk_main, but without sucess:

----
[...]
  gtk_widget_show           ( a_gtk_window);
  gdk_window_set_background ( a_gtk_window->window, newColor ) ;

  gtk_main ();
} /* End Of Main */
----
The variable newColor is a GdkColor* that I've allocated with
gtk_widget_get_colormap & gdk_colormap_alloc_color.

I attach the whole small program to this mail, to show what I'm excatly
doing.
Would anyone have an idea of what is wrong in my code ?

Thanks in advance

Francois
/**
 * HelloWolrd.c
 * 
 * Francois Taiani   <taiani laas fr>
 * Time-stamp: <01/08/24 21:43:35 ftaiani>
 * 
 */
#include <stdlib.h>
#include <gtk/gtk.h>


void destroy (GtkWidget *widget, gpointer data)
{
  g_print ("Signal destroy was received.\n");
  gtk_main_quit ();
}

int main (int argc, char *argv[])
{
  GtkWidget    * a_gtk_window   ;
  GdkColor     * newColor ;
  GdkColormap  * colormap ;

  gtk_init (&argc, &argv);
          
  a_gtk_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  newColor = (GdkColor*)malloc(sizeof(GdkColor)) ;
  newColor->red   = 255 ;
  newColor->green =   0 ;
  newColor->blue  =   0 ;

  colormap =  gtk_widget_get_colormap (a_gtk_window);

  gdk_colormap_alloc_color ( colormap,
                             newColor,
                             0,  /* is writable ?   */
                             1 ) /* is best match ? */ ;
          
  gtk_signal_connect (GTK_OBJECT (a_gtk_window), "destroy",
                      GTK_SIGNAL_FUNC (destroy), NULL);
          
  gtk_container_border_width( GTK_CONTAINER (a_gtk_window), 100);
  gtk_widget_show           ( a_gtk_window);
  gdk_window_set_background ( a_gtk_window->window, newColor ) ;

  gtk_main ();
          
  return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]