windowcontrols: gtk_widget_get_root() can return NULL

This commit is contained in:
Timm Bäder 2020-10-11 12:21:54 +02:00 committed by Matthias Clasen
parent 557a363b4f
commit d9cc589339

View File

@ -107,12 +107,12 @@ static char *
get_layout (GtkWindowControls *self) get_layout (GtkWindowControls *self)
{ {
GtkWidget *widget = GTK_WIDGET (self); GtkWidget *widget = GTK_WIDGET (self);
GtkWidget *toplevel; GtkRoot *root;
char *layout_desc, *layout_half; char *layout_desc, *layout_half;
char **tokens; char **tokens;
toplevel = GTK_WIDGET (gtk_widget_get_root (widget)); root = gtk_widget_get_root (widget);
if (!GTK_IS_WINDOW (toplevel)) if (!root || !GTK_IS_WINDOW (root))
return NULL; return NULL;
if (self->decoration_layout) if (self->decoration_layout)
@ -221,7 +221,6 @@ static void
update_window_buttons (GtkWindowControls *self) update_window_buttons (GtkWindowControls *self)
{ {
GtkWidget *widget = GTK_WIDGET (self); GtkWidget *widget = GTK_WIDGET (self);
GtkWidget *toplevel;
char *layout; char *layout;
char **tokens; char **tokens;
int i; int i;
@ -230,10 +229,11 @@ update_window_buttons (GtkWindowControls *self)
gboolean resizable; gboolean resizable;
gboolean deletable; gboolean deletable;
gboolean empty = TRUE; gboolean empty = TRUE;
GtkRoot *root;
GtkWindow *window = NULL; GtkWindow *window = NULL;
toplevel = GTK_WIDGET (gtk_widget_get_root (widget)); root = gtk_widget_get_root (widget);
if (!GTK_IS_WINDOW (toplevel)) if (!root || !GTK_IS_WINDOW (root))
{ {
set_empty (self, TRUE); set_empty (self, TRUE);
@ -242,23 +242,12 @@ update_window_buttons (GtkWindowControls *self)
clear_controls (self); clear_controls (self);
if (GTK_IS_WINDOW (toplevel)) window = GTK_WINDOW (root);
{ is_sovereign_window = !gtk_window_get_modal (window) &&
window = GTK_WINDOW (toplevel); gtk_window_get_transient_for (window) == NULL;
maximized = gtk_window_is_maximized (window);
is_sovereign_window = !gtk_window_get_modal (window) && resizable = gtk_window_get_resizable (window);
gtk_window_get_transient_for (window) == NULL; deletable = gtk_window_get_deletable (window);
maximized = gtk_window_is_maximized (window);
resizable = gtk_window_get_resizable (window);
deletable = gtk_window_get_deletable (window);
}
else
{
is_sovereign_window = TRUE;
maximized = FALSE;
resizable = TRUE;
deletable = TRUE;
}
layout = get_layout (self); layout = get_layout (self);