<---- template headericclude ----->
gtk3 color
FedoraForum.org - Fedora Support Forums and Community
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2008
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    gtk3 color

    Dear friends,
    It seems that when I am using adawita theme in f17, I cannot use "gtk_widget_modify_bg" etc to change the color of a widget.
    When using other themes though, (like say Low contrast), its absolutely ok.

    I am posting a complete code below, I will be grateful if somone shows me how to override this behavior.

    Code:
    /*
    *compile it using:
    * gcc `pkg-config --cflags --libs gtk+-3.0` newt.c -o cnew 
    */
    #include <gtk/gtk.h>
    int main(int argc,
            char *argv[]) {
        GtkWidget *window;
        GtkWidget *grid;
        GtkWidget *menubar;
        GtkWidget *filemenu;
        GtkWidget *quit;
        GtkAccelGroup *accel_group = NULL;
    
        gtk_init(&argc, &argv);
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title(GTK_WINDOW(window), "Try Grid");
        gtk_container_set_border_width(GTK_CONTAINER(window), 05);
    
        grid = gtk_grid_new();
        gtk_container_add(GTK_CONTAINER(window), grid);
     gtk_grid_set_column_homogeneous(GTK_GRID(grid),TRUE);
     gtk_grid_set_row_homogeneous(GTK_GRID(grid),TRUE);
        menubar = gtk_menu_bar_new();
        filemenu = gtk_menu_new();
    
        accel_group = gtk_accel_group_new();
        gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
    
        GtkWidget *file = gtk_menu_item_new_with_mnemonic("_File");
        quit = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, accel_group);
    
        gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu);
        gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit);
        gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file);
    
        g_signal_connect(G_OBJECT(quit), "activate", G_CALLBACK(gtk_main_quit), NULL);
    
        gtk_grid_attach(GTK_GRID(grid), menubar, 0, 0, 2, 1);
    
    
        /* Color Scheme */
        GdkColor colorRed2 = {0x0000, 65535, 29555, 24158};
        GdkColor colorBlue = {0x0000, 3598, 57054, 61937};
        GdkColor colorWht = {0x0000, 65535, 65535, 65535};
    
    
        GtkWidget *Abutton = gtk_button_new_with_label("A");
        gtk_grid_attach(GTK_GRID(grid), Abutton, 0, 1, 1, 1);
        gtk_widget_modify_bg(Abutton, GTK_STATE_NORMAL, &colorBlue);
        gtk_widget_modify_bg(Abutton, GTK_STATE_PRELIGHT, &colorWht);
    
        /* Create second button */
        GtkWidget *Bbutton = gtk_button_new_with_label("B");
        gtk_grid_attach(GTK_GRID(grid), Bbutton, 10, 1, 1, 1);
        gtk_widget_modify_bg(Bbutton, GTK_STATE_NORMAL, &colorRed2);
        gtk_widget_modify_bg(Bbutton, GTK_STATE_PRELIGHT, &colorWht);
    
    
        gtk_widget_show_all(window);
        gtk_main();
    
        return 0;
    }
    Last edited by rudra-b; 27th August 2012 at 11:50 AM.

  2. #2
    Join Date
    Oct 2010
    Location
    Canberra
    Posts
    3,897
    Mentioned
    14 Post(s)
    Tagged
    1 Thread(s)

    Re: gtk3 color

    A bit of googling shows up quite a few warnings that you should not use gtk_widget_modify_bg() but gtk_widget_override_background_color() instead.

    The theme dependency might be due to the way the labels are drawn, so that if it uses a pixmap then you cannot change the colour (but I am just guessing on this).

  3. #3
    Join Date
    Jun 2008
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: gtk3 color

    Quote Originally Posted by ocratato
    A bit of googling shows up quite a few warnings that you should not use gtk_widget_modify_bg() but gtk_widget_override_background_color() instead.
    I tried gtk_widget_override_background_color() but with no help. curious thing is that when the window is out of focus, its showing the color, not when in focus.

  4. #4
    Join Date
    Oct 2010
    Location
    Canberra
    Posts
    3,897
    Mentioned
    14 Post(s)
    Tagged
    1 Thread(s)

    Re: gtk3 color

    I have just been looking at the theme definitions. (Search for gtkrc files)

    The low contrast theme defines each colour separately for each state, but Adwaita defines all the states in terms of shades of the bg colour.

    Just thinking aloud here, but it may be that the theme code is taking precedence when the window has focus, but perhaps not otherwise.

  5. #5
    Join Date
    Jun 2008
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: gtk3 color

    So, in gtk, is there any way (other then css) to override window manager's theme?
    css is a valid option, but I think that will be too much!

  6. #6
    Join Date
    Oct 2010
    Location
    Canberra
    Posts
    3,897
    Mentioned
    14 Post(s)
    Tagged
    1 Thread(s)

    Re: gtk3 color

    Quote Originally Posted by rudra-b
    So, in gtk, is there any way (other then css) to override window manager's theme?
    css is a valid option, but I think that will be too much!
    Actually I am no expert in Gtk (and actually prefer Qt) so perhaps someone else can help. However, are you really sure that overriding the theme is the correct option here? If you ignore the theme settings then your program will be non-standard, and not blend into the Gtk/Gnome family.

    It might be better to indicate the state of your program by something other than the colour of buttons, perhaps.

  7. #7
    Join Date
    Apr 2010
    Location
    Earth
    Posts
    901
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: gtk3 color

    Quote Originally Posted by rudra-b
    I tried gtk_widget_override_background_color() but with no help. curious thing is that when the window is out of focus, its showing the color, not when in focus.
    maybe gtk_widget_override_color () is the method you need.

    about the theming changes in GTK3: Theming changes

    if it still doesn't work, maybe ask in the GTK forum instead.

Similar Threads

  1. Tutorial for making GTK3 themes
    By satya164 in forum Guides & Solutions (Not For Questions)
    Replies: 0
    Last Post: 24th June 2012, 09:08 PM
  2. Change GTK3 theme in fedora 16
    By Shmaleb in forum Using Fedora
    Replies: 5
    Last Post: 3rd March 2012, 06:17 PM
  3. How to install this GTK3 theme in Fedora 16
    By rojo2000r in forum Using Fedora
    Replies: 5
    Last Post: 27th November 2011, 02:36 AM
  4. [SOLVED]
    Installing new themes for GTK3 F16
    By bruno9779 in forum Using Fedora
    Replies: 4
    Last Post: 26th November 2011, 09:10 PM
  5. Ambiance GTK3 Theme Doesn't Work
    By HalfEmptyHero in forum Using Fedora
    Replies: 0
    Last Post: 12th August 2011, 05:40 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
[[template footer(Guest)]]