Domanda

I'm writing a relatively simple messaging program in C with GTK, and would like to place my message-viewing window in a particular corner of the screen, so it's out of the way.

The documentation lists a function gtk_window_set_gravity that specifies which corner of the window its coordinates are relative to, and by tracing other information through gtk_window_move, found that the following code would position the window at the bottom-right corner of the screen, ignoring multi-head scenarios.

gtk_window_set_gravity(GTK_WINDOW(win), GDK_GRAVITY_SOUTH_EAST);
gtk_window_move(GTK_WINDOW(win), gdk_screen_width() - window_width, gdk_screen_height() - window_height);

I'm pretty much a novice at working with GTK, and even more a novice of using the GTK interface directly (having been using PyGTK instead), so I don't even know where to start looking right now.

È stato utile?

Soluzione

Turns out the answer to this problem can be found in GDK, not GTK.

The following code is what I've managed to figure out:

GdkDisplay *display = gdk_display_get_default();
// 0 for the first screen, as we're only concerned about the first one
GdkScreen *screen = gdk_display_get_screen(display, 0);
screen_width = gdk_screen_get_width(screen);
screen_height = gdk_screen_get_height(screen);

Note that you'll need to use the gdk_display_get_n_screens(display) function call to determine the number of screens if you're interested in any screen other than the first one.

For reference, check out the documentation for GdkDisplay, GdkScreen, and multi-heading.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top