X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7d1d359a4c01d1134c0b25733d4aa05f9367b604..05e0b047d879cdbfade7f2ab346c0acdf3e29f96:/src/gtk/toplevel.cpp?ds=inline diff --git a/src/gtk/toplevel.cpp b/src/gtk/toplevel.cpp index bf8bde87c0..7ddd774e3b 100644 --- a/src/gtk/toplevel.cpp +++ b/src/gtk/toplevel.cpp @@ -317,13 +317,9 @@ gtk_frame_realized_callback( GtkWidget * WXUNUSED(widget), else gtk_window_set_policy(GTK_WINDOW(win->m_widget), 1, 1, 1); - // reset the icon - wxIconBundle iconsOld = win->GetIcons(); - if ( !iconsOld.IsEmpty() ) - { - win->SetIcon( wxNullIcon ); - win->SetIcons( iconsOld ); - } + const wxIconBundle& icons = win->GetIcons(); + if (icons.GetIconCount()) + win->SetIcons(icons); if (win->HasFlag(wxFRAME_SHAPED)) win->SetShape(win->m_shape); // it will really set the window shape now @@ -375,6 +371,37 @@ gtk_frame_unmap_callback( GtkWidget * WXUNUSED(widget), } } +//----------------------------------------------------------------------------- + +bool wxGetFrameExtents(GdkWindow* window, int* left, int* right, int* top, int* bottom) +{ + static GdkAtom property = gdk_atom_intern("_NET_FRAME_EXTENTS", false); + Atom xproperty = gdk_x11_atom_to_xatom_for_display( + gdk_drawable_get_display(window), property); + Atom type; + int format; + gulong nitems, bytes_after; + guchar* data; + Status status = XGetWindowProperty( + gdk_x11_drawable_get_xdisplay(window), + gdk_x11_drawable_get_xid(window), + xproperty, + 0, 4, false, XA_CARDINAL, + &type, &format, &nitems, &bytes_after, &data); + const bool success = status == Success && data && nitems == 4; + if (success) + { + long* p = (long*)data; + if (left) *left = int(p[0]); + if (right) *right = int(p[1]); + if (top) *top = int(p[2]); + if (bottom) *bottom = int(p[3]); + } + if (data) + XFree(data); + return success; +} + //----------------------------------------------------------------------------- // "property_notify_event" from m_widget //----------------------------------------------------------------------------- @@ -387,27 +414,13 @@ static gboolean property_notify_event( static GdkAtom property = gdk_atom_intern("_NET_FRAME_EXTENTS", false); if (event->state == GDK_PROPERTY_NEW_VALUE && event->atom == property) { - Atom xproperty = gdk_x11_atom_to_xatom_for_display( - gdk_drawable_get_display(event->window), property); - Atom type; - int format; - gulong nitems, bytes_after; - guchar* data; - Status status = XGetWindowProperty( - gdk_x11_drawable_get_xdisplay(event->window), - gdk_x11_drawable_get_xid(event->window), - xproperty, - 0, 4, false, XA_CARDINAL, - &type, &format, &nitems, &bytes_after, &data); - if (status == Success && data && nitems == 4) + int left, right, top, bottom; + if (wxGetFrameExtents(event->window, &left, &right, &top, &bottom)) { - long* p = (long*)data; const wxSize decorSize = - wxSize(int(p[0] + p[1]), int(p[2] + p[3])); + wxSize(left + right, top + bottom); win->GTKUpdateDecorSize(decorSize); } - if (data) - XFree(data); } return false; } @@ -624,7 +637,10 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent, } } - gtk_window_set_default_size(GTK_WINDOW(m_widget), m_width, m_height); + m_decorSize = GetCachedDecorSize(); + int w, h; + GTKDoGetSize(&w, &h); + gtk_window_set_default_size(GTK_WINDOW(m_widget), w, h); return true; } @@ -975,6 +991,8 @@ void wxTopLevelWindowGTK::DoSetSizeHints( int minW, int minH, void wxTopLevelWindowGTK::GTKUpdateDecorSize(const wxSize& decorSize) { + if (!IsMaximized() && !IsFullScreen()) + GetCachedDecorSize() = decorSize; if (m_decorSize != decorSize) { const wxSize diff = decorSize - m_decorSize; @@ -1021,6 +1039,23 @@ void wxTopLevelWindowGTK::GTKUpdateDecorSize(const wxSize& decorSize) } } +wxSize& wxTopLevelWindowGTK::GetCachedDecorSize() +{ + static wxSize size[8]; + + int index = 0; + // title bar + if (m_gdkDecor & (GDK_DECOR_MENU | GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE | GDK_DECOR_TITLE)) + index = 1; + // border + if (m_gdkDecor & GDK_DECOR_BORDER) + index |= 2; + // utility window decor can be different + if (m_windowStyle & wxFRAME_TOOL_WINDOW) + index |= 4; + return size[index]; +} + void wxTopLevelWindowGTK::OnInternalIdle() { wxWindow::OnInternalIdle(); @@ -1062,16 +1097,17 @@ void wxTopLevelWindowGTK::SetIcons( const wxIconBundle &icons ) wxTopLevelWindowBase::SetIcons( icons ); - GList *list = NULL; - - const size_t numIcons = icons.GetIconCount(); - for ( size_t i = 0; i < numIcons; i++ ) + // Setting icons before window is realized can cause a GTK assertion if + // another TLW is realized before this one, and it has this one as it's + // transient parent. The life demo exibits this problem. + if (GTK_WIDGET_REALIZED(m_widget)) { - list = g_list_prepend(list, icons.GetIconByIndex(i).GetPixbuf()); + GList* list = NULL; + for (size_t i = icons.GetIconCount(); i--;) + list = g_list_prepend(list, icons.GetIconByIndex(i).GetPixbuf()); + gtk_window_set_icon_list(GTK_WINDOW(m_widget), list); + g_list_free(list); } - - gtk_window_set_icon_list(GTK_WINDOW(m_widget), list); - g_list_free(list); } // ----------------------------------------------------------------------------