4
votes

I am trying to make gtk application which when launched will go full screen. The UI is made in glade and it contains a MainWindow, frame and a label. I need to display some information on label so it has to be full screen. I have a monitor of size 1366x768. I have set the width & height of the MainWindow, frame and label to 1366x768. Below is the code:

int main(int argc, char *argv[])
{

GtkBuilder      *builder;
GtkWidget       *window;
GError     *error = NULL;
gtk_init(&argc, &argv);
builder = gtk_builder_new();
if( ! gtk_builder_add_from_file( builder, "UI.glade", &error ) )
{
        g_warning( "%s", error->message );
        g_free( error );
        return( 1 );
}
window = GTK_WIDGET(gtk_builder_get_object(builder, "MainWindow"));
frame1 = GTK_WIDGET(gtk_builder_get_object(builder, "frame1"));
gtk_builder_connect_signals(builder, NULL);
g_signal_connect (window, "delete_event", G_CALLBACK (on_MainWindow_destroy_event), NULL);
label1 = GTK_WIDGET(gtk_builder_get_object(builder, "label1"));
g_object_unref(builder);
GdkColor black = {0, 0x0000, 0x0000, 0x0000};
GdkColor white = {0, 0xFFFF, 0xFFFF, 0xFFFF};
gtk_widget_modify_bg(frame1, GTK_STATE_NORMAL, &black); 
gtk_widget_modify_fg(frame1, GTK_STATE_NORMAL, &white);

gtk_widget_show(window);
gtk_main();
return 0;

}

When launched it looked like below:

enter image description here

As you can see the the window is not fullscreen because the side left toolbar and the top title bar is still showing. I then read the documentation and found out that I need to include gtk_window_fullscreen. But still its not coming in fullscreen mode. Can anyone please tell me how can I make this window fullscreen. Please help. Thanks.

3
when you put applications (browser, etc...) in fullscreen this happens too, right? It's the window manager that won't allow the window to take that extra space. Can you set the bar to auto-hide?José Fonte
@JoséFonte No I have tried this too. It didnt worked. I set it to auto hide but that bar space was still there.S Andrew
Thats a window manager problem, not gtk. Try disabling the ubuntu dock bar for a while.José Fonte
Try gtk_widget_set_size_requestJosé Fonte
read the reference. default_size allows the window to shrink but set_size_request sets the minimum size (problem is that you can't shrink it to less than that afterwards).José Fonte

3 Answers

11
votes

Set fullscreen mode with:

gtk_window_fullscreen(GTK_WINDOW(window));

2
votes

Use:

gtk_widget_set_size_request (GTK_WIDGET(window), 1366, 768);

Drawback, window cannot be shrank to lower size than that. From the api reference:

Sets the minimum size of a widget; that is, the widget’s size request will be at least width by height . You can use this function to force a widget to be larger than it normally would be. In most cases, gtk_window_set_default_size() is a better choice for toplevel windows than this function; setting the default size will still allow users to shrink the window. Setting the size request will force them to leave the window at least as large as the size request.

Note:

For those that don't read the topic. The question is exactly about overcoming the window manager. gtk_window_fullscreen is not the solution as the question points out:

I then read the documentation and found out that I need to include gtk_window_fullscreen. But still its not coming in fullscreen mode. Can anyone please tell me how can I make this window fullscreen. Please help

As can be seen in the question comments:

Thank You. Using gtk_widget_set_size_request worked

It may not be advised to use this function as there are some drawbacks as indicated but nevertheless there are situations where this solution may be needed.

To make a window fullscreen in normal applications and most situations, developers should, obviously, use gtk_window_fullscreen...

0
votes

You can set Fullscreen using void gtk_window_fullscreen ():

gtk_window_fullscreen (GTK_WINDOW(gtk_widget_get_root_window (widget)));

Also, you can use Maximize:

gtk_window_maximize (GTK_WINDOW(gtk_widget_get_root_window (widget)));

If you wan to set it using GTK#, use:

Fullscreen();

Or:

Maximize();

Take a look of the GTK Window reference: https://developer.gnome.org/gtk2/stable/GtkWindow.html