I'm using GtkBuilder
with a Glade XML file. I want to change the size of the window to fullscreen without using the gtk_window_fullscreen
method (because this needs to work without a window manager), so I get the screen dimensions and make the window that size. This used to work when I created the widgets programmatically, however when I switched to Glade/GtkBuilder
the window is the same small size as it was in Glade editor. Do I have to do something differently with GtkBuilder
? Here's the code:
#include <gtk/gtk.h>
int main(int argc, char *argv[]) {
gtk_init(&argc, &argv);
GtkBuilder *builder = gtk_builder_new();
gtk_builder_add_from_file(builder, "dm.ui", NULL);
GObject *window = gtk_builder_get_object(builder, "window");
// Make full screen
GdkScreen *screen = gdk_screen_get_default();
gint height = gdk_screen_get_height(screen);
gint width = gdk_screen_get_width(screen);
gtk_window_set_default_size(GTK_WINDOW(window), width, height);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_main();
}
Here's the XML file, dm.ui:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.2 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkWindow" id="window">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLayout" id="main_layout">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkEntry" id="user_text_field">
<property name="width_request">162</property>
<property name="height_request">31</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_right">42</property>
</object>
<packing>
<property name="x">175</property>
<property name="y">73</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="user_label">
<property name="width_request">100</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Username</property>
</object>
<packing>
<property name="x">71</property>
<property name="y">46</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="password_label">
<property name="width_request">100</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Password</property>
</object>
<packing>
<property name="x">72</property>
<property name="y">103</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="password_text_field">
<property name="width_request">162</property>
<property name="height_request">31</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="x">177</property>
<property name="y">129</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
You can try using
void gtk_widget_set_size_request(GtkWidget *widget, gint width, gint height);
or you can use Glade to adjust GtkWindow properties of "default-width" and "default-height" rather than hardcode it. Let me know the result. p.s : that is why i hate Glade :(