GtkApplication: fixes for NULL session bus

We currently have a couple of cases where GtkApplication assumes that
the session bus will be non-NULL causing critical error output or (in
the case of trying to publish menus) an infinite loop.

Three fixes:

 - if the session bus is NULL due to not having registered the
   GtkApplication yet then give a g_critical on the entry point to the
   menu setters instead of going into an infinite loop.  Document this.

 - check for NULL session bus even when calling the menu setters at the
   right time in order to prevent the infinite loop for
   non-programer-error cases (ie: because we had trouble connecting to
   the session bus)

 - check for NULL session bus when publishing the X11 properties on the
   GtkApplicationWindow and skip publishing them if we're not on the bus

https://bugzilla.gnome.org/show_bug.cgi?id=671249
This commit is contained in:
Ryan Lortie 2012-04-30 13:43:23 -04:00
parent cdf473ec10
commit babd137e32
2 changed files with 16 additions and 5 deletions

View File

@ -185,6 +185,9 @@ gtk_application_x11_publish_menu (GtkApplication *application,
{
gint i;
if (application->priv->session_bus == NULL)
return;
/* unexport any existing menu */
if (*id)
{
@ -999,6 +1002,10 @@ gtk_application_remove_accelerator (GtkApplication *application,
*
* Sets or unsets the application menu for @application.
*
* This can only be done in the primary instance of the application,
* after it has been registered. #GApplication:startup is a good place
* to call this.
*
* The application menu is a single menu containing items that typically
* impact the application as a whole, rather than acting on a specific
* window or document. For example, you would expect to see
@ -1008,8 +1015,6 @@ gtk_application_remove_accelerator (GtkApplication *application,
* If supported, the application menu will be rendered by the desktop
* environment.
*
* You might call this method in your #GApplication:startup signal handler.
*
* Use the base #GActionMap interface to add actions, to respond to the user
* selecting these menu items.
*
@ -1020,6 +1025,8 @@ gtk_application_set_app_menu (GtkApplication *application,
GMenuModel *app_menu)
{
g_return_if_fail (GTK_IS_APPLICATION (application));
g_return_if_fail (g_application_get_is_registered (G_APPLICATION (application)));
g_return_if_fail (!g_application_get_is_remote (G_APPLICATION (application)));
if (app_menu != application->priv->app_menu)
{
@ -1069,6 +1076,10 @@ gtk_application_get_app_menu (GtkApplication *application)
*
* This is a menubar in the traditional sense.
*
* This can only be done in the primary instance of the application,
* after it has been registered. #GApplication:startup is a good place
* to call this.
*
* Depending on the desktop environment, this may appear at the top of
* each window, or at the top of the screen. In some environments, if
* both the application menu and the menubar are set, the application
@ -1077,8 +1088,6 @@ gtk_application_get_app_menu (GtkApplication *application)
* example, the application menu may be rendered by the desktop shell
* while the menubar (if set) remains in each individual window.
*
* You might call this method in your #GApplication:startup signal handler.
*
* Use the base #GActionMap interface to add actions, to respond to the user
* selecting these menu items.
*
@ -1089,6 +1098,8 @@ gtk_application_set_menubar (GtkApplication *application,
GMenuModel *menubar)
{
g_return_if_fail (GTK_IS_APPLICATION (application));
g_return_if_fail (g_application_get_is_registered (G_APPLICATION (application)));
g_return_if_fail (!g_application_get_is_remote (G_APPLICATION (application)));
if (menubar != application->priv->menubar)
{

View File

@ -768,7 +768,7 @@ gtk_application_window_real_realize (GtkWidget *widget)
gdkwindow = gtk_widget_get_window (GTK_WIDGET (window));
if (GDK_IS_X11_WINDOW (gdkwindow))
if (GDK_IS_X11_WINDOW (gdkwindow) && window->priv->session)
{
gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_APPLICATION_ID",
g_application_get_application_id (G_APPLICATION (application)));