core: Replace close dialog implementation with MetaCloseDialog

src/core/delete.c now entirely relies on MetaCloseDialog in order
to handle the "Application is not responding" dialog.

https://bugzilla.gnome.org/show_bug.cgi?id=711619
This commit is contained in:
Carlos Garnacho 2016-07-11 13:19:25 +02:00
parent 68a9675d42
commit fe5138dfc4
4 changed files with 26 additions and 129 deletions

View File

@ -12,7 +12,6 @@ src/compositor/compositor.c
src/compositor/meta-background.c src/compositor/meta-background.c
src/core/bell.c src/core/bell.c
src/core/core.c src/core/core.c
src/core/delete.c
src/core/display.c src/core/display.c
src/core/errors.c src/core/errors.c
src/core/keybindings.c src/core/keybindings.c

View File

@ -25,145 +25,48 @@
#include <config.h> #include <config.h>
#include "util-private.h" #include "util-private.h"
#include "window-private.h" #include "window-private.h"
#include "compositor-private.h"
#include <meta/errors.h> #include <meta/errors.h>
#include <meta/workspace.h> #include <meta/workspace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <unistd.h>
#include <errno.h> #include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
static void static void
dialog_exited (GPid pid, int status, gpointer user_data) close_dialog_response_cb (MetaCloseDialog *dialog,
MetaCloseDialogResponse response,
MetaWindow *window)
{ {
MetaWindow *window = user_data; if (response == META_CLOSE_DIALOG_RESPONSE_FORCE_CLOSE)
window->dialog_pid = -1;
/* exit status of 0 means the user pressed "Force Quit" */
if (WIFEXITED (status) && WEXITSTATUS (status) == 0)
meta_window_kill (window); meta_window_kill (window);
} }
static void static void
present_existing_delete_dialog (MetaWindow *window, meta_window_ensure_close_dialog (MetaWindow *window)
guint32 timestamp)
{ {
meta_topic (META_DEBUG_PING, MetaDisplay *display;
"Presenting existing ping dialog for %s\n",
window->desc);
if (window->dialog_pid >= 0) if (window->close_dialog)
{ return;
GSList *windows;
GSList *tmp;
/* Activate transient for window that belongs to display = window->display;
* mutter-dialog window->close_dialog = meta_compositor_create_close_dialog (display->compositor,
*/ window);
g_signal_connect (window->close_dialog, "response",
windows = meta_display_list_windows (window->display, META_LIST_DEFAULT); G_CALLBACK (close_dialog_response_cb), window);
tmp = windows;
while (tmp != NULL)
{
MetaWindow *w = tmp->data;
if (w->transient_for == window && w->res_class &&
g_ascii_strcasecmp (w->res_class, "mutter-dialog") == 0)
{
meta_window_activate (w, timestamp);
break;
}
tmp = tmp->next;
}
g_slist_free (windows);
}
}
static void
show_delete_dialog (MetaWindow *window,
guint32 timestamp)
{
char *window_title;
gchar *window_content, *tmp;
GPid dialog_pid;
meta_topic (META_DEBUG_PING,
"Got delete ping timeout for %s\n",
window->desc);
if (window->dialog_pid >= 0)
{
present_existing_delete_dialog (window, timestamp);
return;
}
/* This is to get a better string if the title isn't representable
* in the locale encoding; actual conversion to UTF-8 is done inside
* meta_show_dialog */
if (window->title && window->title[0])
{
tmp = g_locale_from_utf8 (window->title, -1, NULL, NULL, NULL);
if (tmp == NULL)
window_title = NULL;
else
window_title = window->title;
g_free (tmp);
}
else
{
window_title = NULL;
}
if (window_title)
/* Translators: %s is a window title */
tmp = g_strdup_printf (_("“%s” is not responding."), window_title);
else
tmp = g_strdup (_("Application is not responding."));
window_content = g_strdup_printf (
"<big><b>%s</b></big>\n\n%s",
tmp,
_("You may choose to wait a short while for it to "
"continue or force the application to quit entirely."));
dialog_pid =
meta_show_dialog ("--question",
window_content, NULL,
window->screen->screen_name,
_("_Force Quit"), _("_Wait"),
"face-sad-symbolic", window->xwindow,
NULL, NULL);
g_free (window_content);
g_free (tmp);
window->dialog_pid = dialog_pid;
g_child_watch_add (dialog_pid, dialog_exited, window);
}
static void
kill_delete_dialog (MetaWindow *window)
{
if (window->dialog_pid > -1)
kill (window->dialog_pid, SIGTERM);
} }
void void
meta_window_set_alive (MetaWindow *window, meta_window_set_alive (MetaWindow *window,
gboolean is_alive) gboolean is_alive)
{ {
if (is_alive) if (is_alive && window->close_dialog)
kill_delete_dialog (window); {
else meta_close_dialog_hide (window->close_dialog);
show_delete_dialog (window, CurrentTime); }
else if (!is_alive)
{
meta_window_ensure_close_dialog (window);
meta_close_dialog_show (window->close_dialog);
}
} }
void void
@ -207,9 +110,5 @@ meta_window_kill (MetaWindow *window)
void void
meta_window_free_delete_dialog (MetaWindow *window) meta_window_free_delete_dialog (MetaWindow *window)
{ {
if (window->dialog_pid >= 0) g_clear_object (&window->close_dialog);
{
kill (window->dialog_pid, 9);
window->dialog_pid = -1;
}
} }

View File

@ -35,6 +35,7 @@
#include <config.h> #include <config.h>
#include <meta/compositor.h> #include <meta/compositor.h>
#include <meta/window.h> #include <meta/window.h>
#include <meta/meta-close-dialog.h>
#include "screen-private.h" #include "screen-private.h"
#include <meta/util.h> #include <meta/util.h>
#include "stack.h" #include "stack.h"
@ -479,7 +480,7 @@ struct _MetaWindow
int stack_position; /* see comment in stack.h */ int stack_position; /* see comment in stack.h */
/* Managed by delete.c */ /* Managed by delete.c */
int dialog_pid; MetaCloseDialog *close_dialog;
/* maintained by group.c */ /* maintained by group.c */
MetaGroup *group; MetaGroup *group;

View File

@ -878,8 +878,6 @@ _meta_window_shared_new (MetaDisplay *display,
window->constructing = TRUE; window->constructing = TRUE;
window->dialog_pid = -1;
window->client_type = client_type; window->client_type = client_type;
window->surface = surface; window->surface = surface;
window->xwindow = xwindow; window->xwindow = xwindow;