app: Consider "new-window" action for opening new windows

While can_open_new_window() uses some elaborate heuristics to predict
whether an application can open multiple windows, open_new_window()
will always simply relaunch the application. This is often the best
we can do, but when an application provides a "new-window" action in
its .desktop file or on the bus, it is much more likely to work as
expected than blindly activating the app and hoping for a particular
behavior.

https://bugzilla.gnome.org/show_bug.cgi?id=756844
This commit is contained in:
Florian Müllner 2016-09-22 18:29:29 +02:00 committed by Jonas Ådahl
parent 6688610c23
commit 3efd296fc3

View File

@ -551,15 +551,46 @@ void
shell_app_open_new_window (ShellApp *app, shell_app_open_new_window (ShellApp *app,
int workspace) int workspace)
{ {
GActionGroup *group = NULL;
const char * const *actions;
g_return_if_fail (app->info != NULL); g_return_if_fail (app->info != NULL);
/* Here we just always launch the application again, even if we know /* First check whether the application provides a "new-window" desktop
* action - it is a safe bet that it will open a new window, and activating
* it will trigger startup notification if necessary
*/
actions = g_desktop_app_info_list_actions (G_DESKTOP_APP_INFO (app->info));
if (g_strv_contains (actions, "new-window"))
{
shell_app_launch_action (app, "new-window", 0, workspace);
return;
}
/* Next, check whether the app exports an explicit "new-window" action
* that we can activate on the bus - the muxer will add startup notification
* information to the platform data, so this should work just as well as
* desktop actions.
*/
group = app->running_state ? G_ACTION_GROUP (app->running_state->muxer)
: NULL;
if (group &&
g_action_group_has_action (group, "app.new-window") &&
g_action_group_get_action_parameter_type (group, "app.new-window") == NULL)
{
g_action_group_activate_action (group, "app.new-window", NULL);
return;
}
/* Lastly, just always launch the application again, even if we know
* it was already running. For most applications this * it was already running. For most applications this
* should have the effect of creating a new window, whether that's * should have the effect of creating a new window, whether that's
* a second process (in the case of Calculator) or IPC to existing * a second process (in the case of Calculator) or IPC to existing
* instance (Firefox). There are a few less-sensical cases such * instance (Firefox). There are a few less-sensical cases such
* as say Pidgin. Ideally, we have the application express to us * as say Pidgin.
* that it supports an explicit new-window action.
*/ */
shell_app_launch (app, 0, workspace, FALSE, NULL); shell_app_launch (app, 0, workspace, FALSE, NULL);
} }
@ -586,10 +617,7 @@ shell_app_can_open_new_window (ShellApp *app)
state = app->running_state; state = app->running_state;
/* If the app has an explicit new-window action, then it can /* If the app has an explicit new-window action, then it can
(or it should be able to) ...
(or it should be able to - we don't actually call the action
because we need to trigger startup notification, so it still
depends on what the app decides to do for Activate vs ActivateAction)
*/ */
if (g_action_group_has_action (G_ACTION_GROUP (state->muxer), "app.new-window")) if (g_action_group_has_action (G_ACTION_GROUP (state->muxer), "app.new-window"))
return TRUE; return TRUE;