Skip to content

Instantly share code, notes, and snippets.

@Lekensteyn
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lekensteyn/fac9cb6df745bdb680c1 to your computer and use it in GitHub Desktop.
Save Lekensteyn/fac9cb6df745bdb680c1 to your computer and use it in GitHub Desktop.
Minimal reproducer for gtk3/mutter bug https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=3961
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <stdlib.h>
static void
activate (GtkApplication* app,
gpointer user_data)
{
(void)user_data;
GdkScreen *screen;
GtkWidget *window;
GtkWidget *button;
GtkWidget *button_box;
GdkRectangle viewable_area = { 0 };
int x;
int width;
int height;
screen = gdk_screen_get_default ();
if (!screen) {
abort();
}
/* Hard-coded for second screen! */
gdk_screen_get_monitor_geometry (screen, 1, &viewable_area);
x = viewable_area.x;
width = viewable_area.width;
height = viewable_area.height;
printf("x=%d width=%d height=%d\n", x, width, height);
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_window_move (GTK_WINDOW (window), x, 0);
gtk_window_set_default_size (GTK_WINDOW (window), width, height);
button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
gtk_widget_set_valign (button_box, GTK_ALIGN_START);
gtk_container_add (GTK_CONTAINER (window), button_box);
button = gtk_button_new_with_label ("Hello World");
gtk_container_add (GTK_CONTAINER (button_box), button);
gtk_widget_show_all (window);
}
int
main (int argc,
char **argv)
{
GtkApplication *app;
int status;
app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
/* vim: set sw=2 ts=2 et: */
CFLAGS = -Wall -Wextra -g $(shell pkg-config --cflags gtk+-3.0)
LDFLAGS = $(shell pkg-config --libs gtk+-3.0)
app: app.c
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
@rbalint
Copy link

rbalint commented Jun 25, 2015

diff --git a/app.c b/app.c
index f6ede76..60fa81a 100644
--- a/app.c
+++ b/app.c
@@ -11,6 +11,7 @@ activate (GtkApplication* app,
   GtkWidget *window;
   GtkWidget *button;
   GtkWidget *button_box;
+  GdkRectangle viewable_area;
   int x;
   int height;

@@ -18,14 +19,15 @@ activate (GtkApplication* app,
   if (!screen) {
     abort();
   }
-  x = gdk_screen_get_width (screen);
-  height = gdk_screen_get_height (screen);
+  gdk_screen_get_monitor_geometry (screen, 1, &viewable_area);
+  x = viewable_area.x;
+  height = viewable_area.height;
   printf("x=%d height=%d\n", x, height);

   window = gtk_application_window_new (app);
   gtk_window_set_title (GTK_WINDOW (window), "Window");
   gtk_window_move (GTK_WINDOW (window), x, 0);
-  gtk_window_set_default_size (GTK_WINDOW (window), 200, height);
+  gtk_window_set_default_size (GTK_WINDOW (window), x, height);

   button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
   gtk_widget_set_valign (button_box, GTK_ALIGN_START);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment