Skip to content

Commit

Permalink
Reposition window after window show, just in case
Browse files Browse the repository at this point in the history
The GTK documentation on `gtk_window_move` [1] state this:

> Asks the window manager to move window to the given position. Window
> managers are free to ignore this; most window managers ignore requests
> for initial window positions (instead using a user-defined placement
> algorithm) and honor requests after the window has already been shown.

That may be what causes the overlay to the positioned wrong in #18 and
#20 (comment). In any
case, it should do no harm to make sure.

[1]: https://docs.gtk.org/gtk3/method.Window.move.html
  • Loading branch information
anko committed Apr 15, 2024
1 parent 98aef49 commit 024bfb6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static void screen_changed(GtkWidget *widget, GdkScreen *old_screen,
static void composited_changed(GdkScreen *screen, gpointer user_data);
static void on_close_web_view(WebKitWebView *web_view, gpointer user_data);

static void size_to_screen(GtkWindow *window);
static int get_monitor_rects(GdkDisplay *display, GdkRectangle **rectangles) {
int n = gdk_display_get_n_monitors(display);
GdkRectangle *new_rectangles = (GdkRectangle*)malloc(n * sizeof(GdkRectangle));
Expand Down Expand Up @@ -784,6 +785,15 @@ int main(int argc, char **argv) {
// the WM should ignore it.
gdk_window_show(GDK_WINDOW(gdk_window));

// Move window to match monitor layout. This should already have been done
// by `screen_changed` above, but we repeat it here after
// `gdk_window_show`, in case the running window manager applies its own
// overriding rules for initial window positioning when a window becomes
// visible. This could cause a few frames of the wrong window position
// being shown on affected window managers, but should do nothing on window
// managers that behave properly.
size_to_screen(GTK_WINDOW(window));

//
// Set up the JavaScript API
//
Expand Down

0 comments on commit 024bfb6

Please sign in to comment.