I have a laptop and a monitor connected to it. some times window is showing up on laptop screen and some times on monitor screen.
is there a programmatic way to ensure that the window always open on a particular screen ?
Here is the sample code I have :
#include<gtk/gtk.h>
GtkWidget *main_window;
static void move_window_to_biggest_monitor()
{
GdkDisplay *display = gdk_display_get_default();
GListModel *list = gdk_display_get_monitors( display );
guint size = g_list_model_get_n_items( list );
int monitor_width = 0, monitor_height = 0, window_x = 0, window_y = 0;
GdkMonitor *biggest_monitor = NULL;
for( guint i=0; i<size; i++ )
{
GdkMonitor *temp_monitor = g_list_model_get_item( list, i );
GdkRectangle rect;
gdk_monitor_get_geometry( temp_monitor, &rect );
if( monitor_width < rect.width )
{
monitor_width = rect.width;
monitor_height = rect.height;
window_x = rect.x;
window_y = rect.y;
biggest_monitor = temp_monitor;
}
}
// how to move main_window to biggest_monitor ????
gtk_widget_set_size_request( main_window, monitor_width, monitor_height );
}
static void activate( GtkApplication *app, gpointer user_data )
{
main_window = gtk_application_window_new( app );
move_window_to_biggest_monitor();
gtk_widget_show( main_window );
}
int main( int argc, char **argv )
{
GtkApplication *app = gtk_application_new( "move.gtk", G_APPLICATION_FLAGS_NONE );
g_signal_connect( app, "activate", G_CALLBACK( activate ), NULL );
int status = g_application_run( G_APPLICATION( app ), argc, argv );
g_object_unref( app );
return status;
}
Is there any API in GTK4 to move the window to a specific monitor ?