Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a gtk application go fullscreen overcoming the window manager (gtk_window_fullscreen does not apply)

Tags:

c

fullscreen

gtk

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.

like image 551
S Andrew Avatar asked Dec 08 '22 18:12

S Andrew


2 Answers

Set fullscreen mode with:

gtk_window_fullscreen(GTK_WINDOW(window));

like image 129
jackw11111 Avatar answered Dec 27 '22 11:12

jackw11111


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...

like image 27
José Fonte Avatar answered Dec 27 '22 11:12

José Fonte