Commit 5c587726 authored by Elijah Newren's avatar Elijah Newren Committed by Elijah Newren
Browse files

Partial audit to fix timestamp usage. One step towards fixing #355180; see

2006-09-18  Elijah Newren  <newren gmail com>

	Partial audit to fix timestamp usage.  One step towards fixing
	#355180; see important comments in that bug.

	* src/core.[ch] (meta_core_unshade, meta_core_shade):
	* src/delete.c (meta_window_present_delete_dialog,
	  delete_ping_timeout_func):
	* src/display.[ch] (meta_display_open, meta_display_close,
	  event_callback, meta_display_begin_grab_op,
	  process_selection_clear, meta_display_unmanage_screen,
	  meta_display_unmanage_windows_for_screen):
	* src/frames.c (meta_frames_button_press_event):
	* src/keybindings.c (handle_toggle_shade):
	* src/main.c (main):
	* src/screen.[ch] (update_num_workspaces, meta_screen_new,
	  meta_screen_free, prefs_changed_callback):
	* src/window.[ch] (meta_window_free, finish_minimize,
	  implement_showing, meta_window_show, meta_window_maximize,
	  meta_window_make_fullscreen_internal,
	  meta_window_unmake_fullscreen, meta_window_shade,
	  meta_window_unshade, window_activate, send_sync_request,
	  meta_window_client_message, menu_callback,
	  meta_window_update_keyboard_resize):
	Remove usage of CurrentTime, meta_display_get_current_time() and
	meta_display_get_current_time_roundtrip() where possible, or
	document why it isn't possible, or at very least add a FIXME with
	some explanation of my laziness and what needs to be done.
parent 87100b64
2006-09-18 Elijah Newren <newren gmail com>
Partial audit to fix timestamp usage. One step towards fixing
#355180; see important comments in that bug.
* src/core.[ch] (meta_core_unshade, meta_core_shade):
* src/delete.c (meta_window_present_delete_dialog,
delete_ping_timeout_func):
* src/display.[ch] (meta_display_open, meta_display_close,
event_callback, meta_display_begin_grab_op,
process_selection_clear, meta_display_unmanage_screen,
meta_display_unmanage_windows_for_screen):
* src/frames.c (meta_frames_button_press_event):
* src/keybindings.c (handle_toggle_shade):
* src/main.c (main):
* src/screen.[ch] (update_num_workspaces, meta_screen_new,
meta_screen_free, prefs_changed_callback):
* src/window.[ch] (meta_window_free, finish_minimize,
implement_showing, meta_window_show, meta_window_maximize,
meta_window_make_fullscreen_internal,
meta_window_unmake_fullscreen, meta_window_shade,
meta_window_unshade, window_activate, send_sync_request,
meta_window_client_message, menu_callback,
meta_window_update_keyboard_resize):
Remove usage of CurrentTime, meta_display_get_current_time() and
meta_display_get_current_time_roundtrip() where possible, or
document why it isn't possible, or at very least add a FIXME with
some explanation of my laziness and what needs to be done.
2006-09-18 Elijah Newren <newren gmail com>
* src/spring-model.c (on_end_move, model_is_calm): Patch from Maik
......
......@@ -339,20 +339,22 @@ meta_core_delete (Display *xdisplay,
void
meta_core_unshade (Display *xdisplay,
Window frame_xwindow)
Window frame_xwindow,
guint32 timestamp)
{
MetaWindow *window = get_window (xdisplay, frame_xwindow);
meta_window_unshade (window);
meta_window_unshade (window, timestamp);
}
void
meta_core_shade (Display *xdisplay,
Window frame_xwindow)
Window frame_xwindow,
guint32 timestamp)
{
MetaWindow *window = get_window (xdisplay, frame_xwindow);
meta_window_shade (window);
meta_window_shade (window, timestamp);
}
void
......
......@@ -95,9 +95,11 @@ void meta_core_delete (Display *xdisplay,
Window frame_xwindow,
guint32 timestamp);
void meta_core_unshade (Display *xdisplay,
Window frame_xwindow);
Window frame_xwindow,
guint32 timestamp);
void meta_core_shade (Display *xdisplay,
Window frame_xwindow);
Window frame_xwindow,
guint32 timestamp);
void meta_core_unstick (Display *xdisplay,
Window frame_xwindow);
void meta_core_stick (Display *xdisplay,
......
......@@ -34,7 +34,8 @@
#include <stdlib.h>
#include <stdio.h>
static void meta_window_present_delete_dialog (MetaWindow *window);
static void meta_window_present_delete_dialog (MetaWindow *window,
guint32 timestamp);
static void
delete_ping_reply_func (MetaDisplay *display,
......@@ -311,7 +312,7 @@ delete_ping_timeout_func (MetaDisplay *display,
if (window->dialog_pid >= 0)
{
meta_window_present_delete_dialog (window);
meta_window_present_delete_dialog (window, timestamp);
return;
}
......@@ -476,7 +477,7 @@ meta_window_free_delete_dialog (MetaWindow *window)
}
static void
meta_window_present_delete_dialog (MetaWindow *window)
meta_window_present_delete_dialog (MetaWindow *window, guint32 timestamp)
{
meta_topic (META_DEBUG_PING,
"Presenting existing ping dialog for %s\n",
......@@ -501,8 +502,7 @@ meta_window_present_delete_dialog (MetaWindow *window)
w->res_class &&
g_strcasecmp (w->res_class, "metacity-dialog") == 0)
{
meta_window_activate (w,
meta_display_get_current_time (w->display));
meta_window_activate (w, timestamp);
break;
}
......
......@@ -707,7 +707,7 @@ meta_display_open (void)
/* This would typically happen because all the screens already
* have window managers.
*/
meta_display_close (display);
meta_display_close (display, timestamp);
return FALSE;
}
......@@ -842,7 +842,8 @@ meta_display_list_windows (MetaDisplay *display)
}
void
meta_display_close (MetaDisplay *display)
meta_display_close (MetaDisplay *display,
guint32 timestamp)
{
GSList *tmp;
......@@ -868,7 +869,7 @@ meta_display_close (MetaDisplay *display)
while (tmp != NULL)
{
MetaScreen *screen = tmp->data;
meta_screen_free (screen);
meta_screen_free (screen, timestamp);
tmp = tmp->next;
}
......@@ -2000,9 +2001,16 @@ event_callback (XEvent *event,
case DestroyNotify:
if (window)
{
/* FIXME: It sucks that DestroyNotify events don't come with
* a timestamp; could we do something better here? Maybe X
* will change one day?
*/
guint32 timestamp;
timestamp = meta_display_get_current_time_roundtrip (display);
if (display->grab_op != META_GRAB_OP_NONE &&
display->grab_window == window)
meta_display_end_grab_op (display, CurrentTime);
meta_display_end_grab_op (display, timestamp);
if (frame_was_receiver)
{
......@@ -2014,7 +2022,8 @@ event_callback (XEvent *event,
}
else
{
meta_window_free (window); /* Unmanage destroyed window */
/* Unmanage destroyed window */
meta_window_free (window, timestamp);
window = NULL;
}
}
......@@ -2022,10 +2031,17 @@ event_callback (XEvent *event,
case UnmapNotify:
if (window)
{
/* FIXME: It sucks that UnmapNotify events don't come with
* a timestamp; could we do something better here? Maybe X
* will change one day?
*/
guint32 timestamp;
timestamp = meta_display_get_current_time_roundtrip (display);
if (display->grab_op != META_GRAB_OP_NONE &&
display->grab_window == window &&
((window->frame == NULL) || !window->frame->mapped))
meta_display_end_grab_op (display, CurrentTime);
meta_display_end_grab_op (display, timestamp);
if (!frame_was_receiver)
{
......@@ -2035,10 +2051,11 @@ event_callback (XEvent *event,
"Window %s withdrawn\n",
window->desc);
meta_effect_run_close (window, NULL, NULL);
meta_effect_run_close (window, NULL, NULL);
/* Unmanage withdrawn window */
window->withdrawn = TRUE;
meta_window_free (window); /* Unmanage withdrawn window */
meta_window_free (window, timestamp);
window = NULL;
}
else
......@@ -2206,7 +2223,12 @@ event_callback (XEvent *event,
/* do this here instead of at end of function
* so we can return
*/
/* FIXME: Clearing display->current_time here makes no sense to
* me; who put this here and why?
*/
display->current_time = CurrentTime;
process_selection_clear (display, event);
/* Note that processing that may have resulted in
* closing the display... so return right away.
......@@ -2256,7 +2278,12 @@ event_callback (XEvent *event,
/* Handle clients using the older version of the spec... */
if (time == 0 && workspace)
time = meta_display_get_current_time_roundtrip (display);
{
meta_warning ("Received a NET_CURRENT_DESKTOP message "
"from a broken (outdated) client who sent "
"a 0 timestamp\n");
time = meta_display_get_current_time_roundtrip (display);
}
if (workspace)
meta_workspace_activate (workspace, time);
......@@ -2275,22 +2302,26 @@ event_callback (XEvent *event,
meta_prefs_set_num_workspaces (num_spaces);
}
else if (event->xclient.message_type ==
display->atom_net_showing_desktop)
{
gboolean showing_desktop;
else if (event->xclient.message_type ==
display->atom_net_showing_desktop)
{
gboolean showing_desktop;
guint32 timestamp;
showing_desktop = event->xclient.data.l[0] != 0;
meta_verbose ("Request to %s desktop\n", showing_desktop ? "show" : "hide");
showing_desktop = event->xclient.data.l[0] != 0;
/* FIXME: Braindead protocol doesn't have a timestamp */
timestamp = meta_display_get_current_time_roundtrip (display);
meta_verbose ("Request to %s desktop\n",
showing_desktop ? "show" : "hide");
if (showing_desktop)
meta_screen_show_desktop (screen, meta_display_get_current_time_roundtrip (display));
else
{
meta_screen_unshow_desktop (screen);
meta_workspace_focus_default_window (screen->active_workspace, NULL, meta_display_get_current_time_roundtrip (display));
}
}
if (showing_desktop)
meta_screen_show_desktop (screen, timestamp);
else
{
meta_screen_unshow_desktop (screen);
meta_workspace_focus_default_window (screen->active_workspace, NULL, timestamp);
}
}
else if (event->xclient.message_type ==
display->atom_metacity_restart_message)
{
......@@ -3331,8 +3362,8 @@ meta_display_begin_grab_op (MetaDisplay *display,
{
meta_topic (META_DEBUG_WINDOW_OPS,
"grabbing all keys failed, ungrabbing pointer\n");
XUngrabPointer (display->xdisplay, CurrentTime);
display->grab_have_pointer = FALSE;
XUngrabPointer (display->xdisplay, timestamp);
display->grab_have_pointer = FALSE;
return FALSE;
}
}
......@@ -4675,7 +4706,9 @@ process_selection_clear (MetaDisplay *display,
meta_verbose ("Got selection clear for screen %d on display %s\n",
screen->number, display->name);
meta_display_unmanage_screen (display, screen);
meta_display_unmanage_screen (display,
screen,
event->xselectionclear.time);
/* display and screen may both be invalid memory... */
......@@ -4699,23 +4732,25 @@ process_selection_clear (MetaDisplay *display,
void
meta_display_unmanage_screen (MetaDisplay *display,
MetaScreen *screen)
MetaScreen *screen,
guint32 timestamp)
{
meta_verbose ("Unmanaging screen %d on display %s\n",
screen->number, display->name);
g_return_if_fail (g_slist_find (display->screens, screen) != NULL);
meta_screen_free (screen);
meta_screen_free (screen, timestamp);
display->screens = g_slist_remove (display->screens, screen);
if (display->screens == NULL)
meta_display_close (display);
meta_display_close (display, timestamp);
}
void
meta_display_unmanage_windows_for_screen (MetaDisplay *display,
MetaScreen *screen)
MetaScreen *screen,
guint32 timestamp)
{
GSList *tmp;
GSList *winlist;
......@@ -4725,8 +4760,8 @@ meta_display_unmanage_windows_for_screen (MetaDisplay *display,
/* Unmanage all windows */
tmp = winlist;
while (tmp != NULL)
{
meta_window_free (tmp->data);
{
meta_window_free (tmp->data, timestamp);
tmp = tmp->next;
}
......
......@@ -388,7 +388,8 @@ struct _MetaDisplay
)
gboolean meta_display_open (void);
void meta_display_close (MetaDisplay *display);
void meta_display_close (MetaDisplay *display,
guint32 timestamp);
MetaScreen* meta_display_screen_for_root (MetaDisplay *display,
Window xroot);
MetaScreen* meta_display_screen_for_x_screen (MetaDisplay *display,
......@@ -399,10 +400,12 @@ void meta_display_grab (MetaDisplay *display);
void meta_display_ungrab (MetaDisplay *display);
void meta_display_unmanage_screen (MetaDisplay *display,
MetaScreen *screen);
MetaScreen *screen,
guint32 timestamp);
void meta_display_unmanage_windows_for_screen (MetaDisplay *display,
MetaScreen *screen);
MetaScreen *screen,
guint32 timestamp);
/* A given MetaWindow may have various X windows that "belong"
* to it, such as the frame window.
......
......@@ -1254,10 +1254,12 @@ meta_frames_button_press_event (GtkWidget *widget,
{
if (flags & META_FRAME_SHADED)
meta_core_unshade (gdk_display,
frame->xwindow);
frame->xwindow,
event->time);
else
meta_core_shade (gdk_display,
frame->xwindow);
frame->xwindow,
event->time);
}
}
break;
......
......@@ -3300,9 +3300,9 @@ handle_toggle_shade (MetaDisplay *display,
if (window)
{
if (window->shaded)
meta_window_unshade (window);
meta_window_unshade (window, event->xkey.time);
else if (window->has_shade_func)
meta_window_shade (window);
meta_window_shade (window, event->xkey.time);
}
}
......
......@@ -399,7 +399,9 @@ main (int argc, char **argv)
tmp = displays;
while (tmp != NULL)
{
meta_display_close (tmp->data);
guint32 timestamp;
timestamp = CurrentTime; /* I doubt correct timestamps matter here */
meta_display_close (tmp->data, timestamp);
tmp = tmp->next;
}
g_slist_free (displays);
......
......@@ -52,7 +52,8 @@
static char* get_screen_name (MetaDisplay *display,
int number);
static void update_num_workspaces (MetaScreen *screen);
static void update_num_workspaces (MetaScreen *screen,
guint32 timestamp);
static void update_focus_mode (MetaScreen *screen);
static void set_workspace_names (MetaScreen *screen);
static void prefs_changed_callback (MetaPreference pref,
......@@ -608,7 +609,7 @@ meta_screen_new (MetaDisplay *display,
* so create that required workspace.
*/
meta_workspace_activate (meta_workspace_new (screen), timestamp);
update_num_workspaces (screen);
update_num_workspaces (screen, timestamp);
set_workspace_names (screen);
......@@ -654,7 +655,8 @@ meta_screen_new (MetaDisplay *display,
}
void
meta_screen_free (MetaScreen *screen)
meta_screen_free (MetaScreen *screen,
guint32 timestamp)
{
MetaDisplay *display;
XGCValues gc_values = { 0 };
......@@ -671,7 +673,7 @@ meta_screen_free (MetaScreen *screen)
screen);
}
meta_display_unmanage_windows_for_screen (display, screen);
meta_display_unmanage_windows_for_screen (display, screen, timestamp);
meta_prefs_remove_listener (prefs_changed_callback, screen);
......@@ -855,7 +857,12 @@ prefs_changed_callback (MetaPreference pref,
if (pref == META_PREF_NUM_WORKSPACES)
{
update_num_workspaces (screen);
/* GConf doesn't provide timestamps, but luckily update_num_workspaces
* often doesn't need it...
*/
guint32 timestamp =
meta_display_get_current_time_roundtrip (screen->display);
update_num_workspaces (screen, timestamp);
}
else if (pref == META_PREF_FOCUS_MODE)
{
......@@ -1083,7 +1090,8 @@ set_desktop_viewport_hint (MetaScreen *screen)
}
static void
update_num_workspaces (MetaScreen *screen)
update_num_workspaces (MetaScreen *screen,
guint32 timestamp)
{
int new_num;
GList *tmp;
......@@ -1136,7 +1144,7 @@ update_num_workspaces (MetaScreen *screen)
}
if (need_change_space)
meta_workspace_activate (last_remaining, meta_display_get_current_time_roundtrip (screen->display));
meta_workspace_activate (last_remaining, timestamp);
/* Should now be safe to free the workspaces */
tmp = extras;
......
......@@ -123,7 +123,8 @@ struct _MetaScreen
MetaScreen* meta_screen_new (MetaDisplay *display,
int number,
guint32 timestamp);
void meta_screen_free (MetaScreen *screen);
void meta_screen_free (MetaScreen *screen,
guint32 timestamp);
void meta_screen_manage_all_windows (MetaScreen *screen);
MetaScreen* meta_screen_for_x_screen (Screen *xscreen);
void meta_screen_foreach_window (MetaScreen *screen,
......
......@@ -910,7 +910,8 @@ meta_window_apply_session_info (MetaWindow *window,
}
void
meta_window_free (MetaWindow *window)
meta_window_free (MetaWindow *window,
guint32 timestamp)
{
GList *tmp;
......@@ -963,7 +964,9 @@ meta_window_free (MetaWindow *window)
meta_topic (META_DEBUG_FOCUS,
"Focusing default window since we're unmanaging %s\n",
window->desc);
meta_workspace_focus_default_window (window->screen->active_workspace, window, meta_display_get_current_time_roundtrip (window->display));
meta_workspace_focus_default_window (window->screen->active_workspace,
window,
timestamp);
}
else if (window->display->expected_focus_window == window)
{
......@@ -971,7 +974,9 @@ meta_window_free (MetaWindow *window)
"Focusing default window since expected focus window freed %s\n",
window->desc);
window->display->expected_focus_window = NULL;
meta_workspace_focus_default_window (window->screen->active_workspace, window, meta_display_get_current_time_roundtrip (window->display));
meta_workspace_focus_default_window (window->screen->active_workspace,
window,
timestamp);
}
else
{
......@@ -992,8 +997,7 @@ meta_window_free (MetaWindow *window)
}
if (window->display->grab_window == window)
meta_display_end_grab_op (window->display,
meta_display_get_current_time (window->display));
meta_display_end_grab_op (window->display, timestamp);
g_assert (window->display->grab_window != window);
......@@ -1338,14 +1342,20 @@ finish_minimize (const MetaEffect *effect,
gpointer data)
{
MetaWindow *window = data;
/* FIXME: It really sucks to put timestamp pinging here; it'd
* probably make more sense in implement_showing() so that it's at
* least not duplicated in meta_window_show; but since
* finish_minimize is a callback making things just slightly icky, I
* haven't done that yet.
*/
guint32 timestamp = meta_display_get_current_time_roundtrip (window->display);
meta_window_hide (window);
if (window->has_focus)
{
meta_workspace_focus_default_window
(window->screen->active_workspace,
window,
meta_display_get_current_time_roundtrip (window->display));
meta_workspace_focus_default_window (window->screen->active_workspace,
window,
timestamp);
}
}
......@@ -1373,11 +1383,11 @@ implement_showing (MetaWindow *window,
if (on_workspace && window->minimized && window->mapped &&
!meta_prefs_get_reduced_resources ())
{
MetaRectangle icon_rect, window_rect;
gboolean result;
/* Check if the window has an icon geometry */
result = meta_window_get_icon_geometry (window, &icon_rect);
MetaRectangle icon_rect, window_rect;
gboolean result;
/* Check if the window has an icon geometry */
result = meta_window_get_icon_geometry (window, &icon_rect);
if (!result)
{
......@@ -1392,16 +1402,16 @@ implement_showing (MetaWindow *window,
meta_window_get_outer_rect (window, &window_rect);
meta_effect_run_minimize (window,
&window_rect,
&icon_rect,
finish_minimize,
window);
}
meta_effect_run_minimize (window,
&window_rect,
&icon_rect,
finish_minimize,
window);
}
else
{
finish_minimize (NULL, window);
}
{
finish_minimize (NULL, window);
}
}
else
{
......@@ -1852,6 +1862,13 @@ meta_window_show (MetaWindow *window)
gboolean place_on_top_on_map;
gboolean needs_stacking_adjustment;
MetaWindow *focus_window;
guint32 timestamp;
/* FIXME: It really sucks to put timestamp pinging here; it'd
* probably make more sense in implement_showing() so that it's at
* least not duplicated in finish_minimize. *shrug*
*/
timestamp = meta_display_get_current_time_roundtrip (window->display);
meta_topic (META_DEBUG_WINDOW_STATE,
"Showing window %s, shaded: %d iconic: %d placed: %d\n",
......@@ -1885,7 +1902,9 @@ meta_window_show (MetaWindow *window)
"ancestor.\n",
focus_window->desc, window->desc);
meta_display_focus_the_no_focus_window (window->display, window->screen, meta_display_get_current_time_roundtrip (window->display));
meta_display_focus_the_no_focus_window (window->display,
window->screen,
timestamp);
}
else
{
......@@ -2054,8 +2073,7 @@ meta_window_show (MetaWindow *window)
window->showing_for_first_time = FALSE;
if (takes_focus_on_map)
{
meta_window_focus (window,
meta_display_get_current_time_roundtrip (window->display));
meta_window_focus (window, timestamp);
}
else
{
......@@ -2261,7 +2279,14 @@ meta_window_maximize (MetaWindow *window,
(maximize_vertically && !window->maximized_vertically))
{
if (window->shaded && maximize_vertically)
meta_window_unshade (window);
{
/* Shading sucks anyway; I'm not adding a timestamp argument
* to this function just for this niche usage & corner case.
*/
guint32 timestamp =
meta_display_get_current_time_roundtrip (window->display);
meta_window_unshade (window, timestamp);
}
/* if the window hasn't been placed yet, we'll maximize it then
*/
......@@ -2384,7 +2409,14 @@ meta_window_make_fullscreen_internal (MetaWindow *window)
"Fullscreening %s\n", window->desc);
if (window->shaded)