Rework timestamp pinging

If a window temporarily goes unresponsive, and then returns later, we
should hide the kill dialog that we showed to the user.
This commit is contained in:
Jasper St. Pierre
2014-05-20 14:48:08 -04:00
parent 56906a29e0
commit 4053c92abf
4 changed files with 94 additions and 116 deletions

View File

@@ -39,35 +39,58 @@
#include "wayland/meta-wayland-surface.h"
static void meta_window_present_delete_dialog (MetaWindow *window,
guint32 timestamp);
static void
delete_ping_reply_func (MetaWindow *window,
guint32 timestamp,
void *user_data)
{
meta_topic (META_DEBUG_PING, "Got reply to delete ping for %s\n", window->desc);
/* we do nothing */
}
static void
dialog_exited (GPid pid, int status, gpointer user_data)
{
MetaWindow *ours = (MetaWindow*) user_data;
MetaWindow *window = user_data;
ours->dialog_pid = -1;
window->dialog_pid = -1;
/* exit status of 1 means the user pressed "Force Quit" */
if (WIFEXITED (status) && WEXITSTATUS (status) == 1)
meta_window_kill (ours);
meta_window_kill (window);
}
static void
delete_ping_timeout_func (MetaWindow *window,
guint32 timestamp,
void *user_data)
present_existing_delete_dialog (MetaWindow *window,
guint32 timestamp)
{
meta_topic (META_DEBUG_PING,
"Presenting existing ping dialog for %s\n",
window->desc);
if (window->dialog_pid >= 0)
{
GSList *windows;
GSList *tmp;
/* Activate transient for window that belongs to
* mutter-dialog
*/
windows = meta_display_list_windows (window->display, META_LIST_DEFAULT);
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;
@@ -79,7 +102,7 @@ delete_ping_timeout_func (MetaWindow *window,
if (window->dialog_pid >= 0)
{
meta_window_present_delete_dialog (window, timestamp);
present_existing_delete_dialog (window, timestamp);
return;
}
@@ -128,15 +151,33 @@ delete_ping_timeout_func (MetaWindow *window,
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
meta_window_set_alive (MetaWindow *window,
gboolean is_alive)
{
if (window->is_alive == is_alive)
return;
window->is_alive = is_alive;
if (window->is_alive)
kill_delete_dialog (window);
else
show_delete_dialog (window, CurrentTime);
}
void
meta_window_check_alive (MetaWindow *window,
guint32 timestamp)
{
meta_display_ping_window (window,
timestamp,
delete_ping_reply_func,
delete_ping_timeout_func,
NULL);
meta_display_ping_window (window, timestamp);
}
void
@@ -191,39 +232,3 @@ meta_window_free_delete_dialog (MetaWindow *window)
window->dialog_pid = -1;
}
}
static void
meta_window_present_delete_dialog (MetaWindow *window, guint32 timestamp)
{
meta_topic (META_DEBUG_PING,
"Presenting existing ping dialog for %s\n",
window->desc);
if (window->dialog_pid >= 0)
{
GSList *windows;
GSList *tmp;
/* Activate transient for window that belongs to
* mutter-dialog
*/
windows = meta_display_list_windows (window->display, META_LIST_DEFAULT);
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);
}
}