From a3e1fa33504d2a365c70f94912dd32f9a9b6c4bf Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 29 Mar 2014 16:07:44 +0800 Subject: [PATCH] gtk: Consider window frame in SetSize. --- atom/browser/native_window_gtk.cc | 13 +++++++++++-- atom/browser/native_window_gtk.h | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/atom/browser/native_window_gtk.cc b/atom/browser/native_window_gtk.cc index 050fea3921..ff79eee296 100644 --- a/atom/browser/native_window_gtk.cc +++ b/atom/browser/native_window_gtk.cc @@ -64,6 +64,7 @@ NativeWindowGtk::NativeWindowGtk(content::WebContents* web_contents, is_always_on_top_(false), is_active_(false), suppress_window_raise_(false), + has_ever_been_shown_(false), frame_cursor_(NULL) { gtk_container_add(GTK_CONTAINER(window_), vbox_); gtk_container_add(GTK_CONTAINER(vbox_), @@ -73,6 +74,7 @@ NativeWindowGtk::NativeWindowGtk(content::WebContents* web_contents, options->GetInteger(switches::kWidth, &width); options->GetInteger(switches::kHeight, &height); + // Fixup the initial window size. if (has_frame_) SubstractBorderSize(&width, &height); @@ -81,7 +83,7 @@ NativeWindowGtk::NativeWindowGtk(content::WebContents* web_contents, GtkAllocation size = { 0, 0, width, height }; gtk_widget_show_all(vbox_); gtk_widget_size_allocate(GTK_WIDGET(window_), &size); - SetSize(gfx::Size(width, height)); + gtk_window_util::SetWindowSize(window_, gfx::Size(width, height)); // Create the underlying gdk window. gtk_widget_realize(GTK_WIDGET(window_)); @@ -157,6 +159,7 @@ bool NativeWindowGtk::IsFocused() { } void NativeWindowGtk::Show() { + has_ever_been_shown_ = true; gtk_widget_show_all(GTK_WIDGET(window_)); } @@ -196,7 +199,13 @@ bool NativeWindowGtk::IsFullscreen() { } void NativeWindowGtk::SetSize(const gfx::Size& size) { - gtk_window_util::SetWindowSize(window_, size); + // When the window has not been mapped the window size does not include frame. + int width = size.width(); + int height = size.height(); + if (has_frame_ && !has_ever_been_shown_) + SubstractBorderSize(&width, &height); + + gtk_window_util::SetWindowSize(window_, gfx::Size(width, height)); } gfx::Size NativeWindowGtk::GetSize() { diff --git a/atom/browser/native_window_gtk.h b/atom/browser/native_window_gtk.h index cafed467ea..398966608d 100644 --- a/atom/browser/native_window_gtk.h +++ b/atom/browser/native_window_gtk.h @@ -125,6 +125,11 @@ class NativeWindowGtk : public NativeWindow, // bar or window border. This is to work around a compiz bug. bool suppress_window_raise_; + // True if the window has been visible for once, on Linux the window frame would + // only be considered as part of the window untill the window has been shown, so + // we need it to correctly set the window size. + bool has_ever_been_shown_; + // The current window cursor. We set it to a resize cursor when over the // custom frame border. We set it to NULL if we want the default cursor. GdkCursor* frame_cursor_;