bluegenetic bluegenetic - 1 month ago 23
C Question

Background color for GTK_WINDOW_TOPLEVEL Gtk Widget

In the following code, I want the background colour of the main GTK_WINDOW_TOPLEVEL to be 0xc0deed. But when I run it is appearing black. I even tried gtk_drawing_area_new and adding it to the main window. But still it is appearing black although I could get other colours like red, blue, white etc

#include <gtk/gtk.h>

int main( int argc, char *argv[])
{
GtkWidget *p_s_window = NULL;
GdkColor color;
color.red = 0x00C0;
color.green = 0x00DE;
color.blue = 0x00ED;
gtk_init(&argc, &argv);
p_s_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(p_s_window), GTK_WIN_POS_CENTER);
gtk_window_set_title(GTK_WINDOW(p_s_window), "hello");
gtk_widget_modify_bg(p_s_window, GTK_STATE_NORMAL, &color);
g_signal_connect_swapped(G_OBJECT(p_s_window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show_all(p_s_window);
gtk_main();
return 0;
}

Answer

The GdkColor components are 16-bit, thus having a range of 0 through 65535. Multiply your values with 65535/255 and you'll be alright.

For example yellow would be:

color.red = 0xffff;
color.green = 0xffff;
color.blue = 0;