screen: Use the standard for-loop iteration for iterating over lists

This commit is contained in:
Jasper St. Pierre 2014-08-15 19:49:49 -04:00
parent 06d55bf019
commit a119ea96a3

View File

@ -406,17 +406,13 @@ meta_screen_xinerama_index_to_monitor_index (MetaScreen *screen,
static void static void
reload_monitor_infos (MetaScreen *screen) reload_monitor_infos (MetaScreen *screen)
{ {
GList *tmp; GList *l;
MetaMonitorManager *manager; MetaMonitorManager *manager;
tmp = screen->workspaces; for (l = screen->workspaces; l != NULL; l = l->next)
while (tmp != NULL)
{ {
MetaWorkspace *space = tmp->data; MetaWorkspace *space = l->data;
meta_workspace_invalidate_work_area (space); meta_workspace_invalidate_work_area (space);
tmp = tmp->next;
} }
/* Any previous screen->monitor_infos or screen->outputs is freed by the caller */ /* Any previous screen->monitor_infos or screen->outputs is freed by the caller */
@ -997,8 +993,7 @@ meta_screen_foreach_window (MetaScreen *screen,
MetaScreenWindowFunc func, MetaScreenWindowFunc func,
gpointer data) gpointer data)
{ {
GSList *winlist; GSList *winlist, *l;
GSList *tmp;
/* If we end up doing this often, just keeping a list /* If we end up doing this often, just keeping a list
* of windows might be sensible. * of windows might be sensible.
@ -1011,22 +1006,19 @@ meta_screen_foreach_window (MetaScreen *screen,
winlist = g_slist_sort (winlist, ptrcmp); winlist = g_slist_sort (winlist, ptrcmp);
tmp = winlist; for (l = winlist; l != NULL; l = l->next)
while (tmp != NULL)
{ {
/* If the next node doesn't contain this window /* If the next node doesn't contain this window
* a second time, delete the window. * a second time, delete the window.
*/ */
if (tmp->next == NULL || if (l->next == NULL ||
(tmp->next && tmp->next->data != tmp->data)) (l->next && l->next->data != l->data))
{ {
MetaWindow *window = tmp->data; MetaWindow *window = l->data;
if (META_IS_WINDOW (window) && !window->override_redirect) if (META_IS_WINDOW (window) && !window->override_redirect)
(* func) (screen, window, data); (* func) (screen, window, data);
} }
tmp = tmp->next;
} }
g_slist_free (winlist); g_slist_free (winlist);
} }
@ -1133,8 +1125,7 @@ meta_screen_remove_workspace (MetaScreen *screen, MetaWorkspace *workspace,
gboolean active_index_changed; gboolean active_index_changed;
int new_num; int new_num;
l = screen->workspaces; for (l = screen->workspaces; l != NULL; l = next)
while (l)
{ {
MetaWorkspace *w = l->data; MetaWorkspace *w = l->data;
@ -1155,8 +1146,6 @@ meta_screen_remove_workspace (MetaScreen *screen, MetaWorkspace *workspace,
break; break;
} }
l = l->next;
} }
if (!neighbour) if (!neighbour)
@ -1186,14 +1175,10 @@ meta_screen_remove_workspace (MetaScreen *screen, MetaWorkspace *workspace,
if (active_index_changed) if (active_index_changed)
meta_screen_set_active_workspace_hint (screen); meta_screen_set_active_workspace_hint (screen);
l = next; for (l = next; l != NULL; l = l->next)
while (l)
{ {
MetaWorkspace *w = l->data; MetaWorkspace *w = l->data;
meta_workspace_update_window_hints (w); meta_workspace_update_window_hints (w);
l = l->next;
} }
meta_screen_queue_workarea_recalc (screen); meta_screen_queue_workarea_recalc (screen);
@ -1253,7 +1238,7 @@ update_num_workspaces (MetaScreen *screen,
guint32 timestamp) guint32 timestamp)
{ {
int new_num, old_num; int new_num, old_num;
GList *tmp; GList *l;
int i; int i;
GList *extras; GList *extras;
MetaWorkspace *last_remaining; MetaWorkspace *last_remaining;
@ -1292,10 +1277,9 @@ update_num_workspaces (MetaScreen *screen,
last_remaining = NULL; last_remaining = NULL;
extras = NULL; extras = NULL;
i = 0; i = 0;
tmp = screen->workspaces; for (l = screen->workspaces; l != NULL; l = l->next)
while (tmp != NULL)
{ {
MetaWorkspace *w = tmp->data; MetaWorkspace *w = l->data;
if (i >= new_num) if (i >= new_num)
extras = g_list_prepend (extras, w); extras = g_list_prepend (extras, w);
@ -1303,7 +1287,6 @@ update_num_workspaces (MetaScreen *screen,
last_remaining = w; last_remaining = w;
++i; ++i;
tmp = tmp->next;
} }
old_num = i; old_num = i;
@ -1316,32 +1299,26 @@ update_num_workspaces (MetaScreen *screen,
* is on a removed workspace ;-) * is on a removed workspace ;-)
*/ */
need_change_space = FALSE; need_change_space = FALSE;
tmp = extras; for (l = extras; l != NULL; l = l->next)
while (tmp != NULL)
{ {
MetaWorkspace *w = tmp->data; MetaWorkspace *w = l->data;
meta_workspace_relocate_windows (w, last_remaining); meta_workspace_relocate_windows (w, last_remaining);
if (w == screen->active_workspace) if (w == screen->active_workspace)
need_change_space = TRUE; need_change_space = TRUE;
tmp = tmp->next;
} }
if (need_change_space) if (need_change_space)
meta_workspace_activate (last_remaining, timestamp); meta_workspace_activate (last_remaining, timestamp);
/* Should now be safe to free the workspaces */ /* Should now be safe to free the workspaces */
tmp = extras; for (l = extras; l != NULL; l = l->next)
while (tmp != NULL)
{ {
MetaWorkspace *w = tmp->data; MetaWorkspace *w = l->data;
g_assert (w->windows == NULL); g_assert (w->windows == NULL);
meta_workspace_remove (w); meta_workspace_remove (w);
tmp = tmp->next;
} }
g_list_free (extras); g_list_free (extras);
@ -2083,18 +2060,17 @@ static void
set_work_area_hint (MetaScreen *screen) set_work_area_hint (MetaScreen *screen)
{ {
int num_workspaces; int num_workspaces;
GList *tmp_list; GList *l;
unsigned long *data, *tmp; unsigned long *data, *tmp;
MetaRectangle area; MetaRectangle area;
num_workspaces = meta_screen_get_n_workspaces (screen); num_workspaces = meta_screen_get_n_workspaces (screen);
data = g_new (unsigned long, num_workspaces * 4); data = g_new (unsigned long, num_workspaces * 4);
tmp_list = screen->workspaces;
tmp = data; tmp = data;
while (tmp_list != NULL) for (l = screen->workspaces; l != NULL; l = l->next)
{ {
MetaWorkspace *workspace = tmp_list->data; MetaWorkspace *workspace = l->data;
meta_workspace_get_work_area_all_monitors (workspace, &area); meta_workspace_get_work_area_all_monitors (workspace, &area);
tmp[0] = area.x; tmp[0] = area.x;
@ -2103,8 +2079,6 @@ set_work_area_hint (MetaScreen *screen)
tmp[3] = area.height; tmp[3] = area.height;
tmp += 4; tmp += 4;
tmp_list = tmp_list->next;
} }
meta_error_trap_push (screen->display); meta_error_trap_push (screen->display);
@ -2524,8 +2498,7 @@ meta_screen_update_showing_desktop_hint (MetaScreen *screen)
static void static void
queue_windows_showing (MetaScreen *screen) queue_windows_showing (MetaScreen *screen)
{ {
GSList *windows; GSList *windows, *l;
GSList *tmp;
/* Must operate on all windows on display instead of just on the /* Must operate on all windows on display instead of just on the
* active_workspace's window list, because the active_workspace's * active_workspace's window list, because the active_workspace's
@ -2533,14 +2506,10 @@ queue_windows_showing (MetaScreen *screen)
*/ */
windows = meta_display_list_windows (screen->display, META_LIST_DEFAULT); windows = meta_display_list_windows (screen->display, META_LIST_DEFAULT);
tmp = windows; for (l = windows; l != NULL; l = l->next)
while (tmp != NULL)
{ {
MetaWindow *w = tmp->data; MetaWindow *w = l->data;
meta_window_queue (w, META_QUEUE_CALC_SHOWING); meta_window_queue (w, META_QUEUE_CALC_SHOWING);
tmp = tmp->next;
} }
g_slist_free (windows); g_slist_free (windows);
@ -2550,20 +2519,14 @@ void
meta_screen_minimize_all_on_active_workspace_except (MetaScreen *screen, meta_screen_minimize_all_on_active_workspace_except (MetaScreen *screen,
MetaWindow *keep) MetaWindow *keep)
{ {
GList *windows; GList *l;
GList *tmp;
windows = screen->active_workspace->windows; for (l = screen->active_workspace->windows; l != NULL; l = l->next)
tmp = windows;
while (tmp != NULL)
{ {
MetaWindow *w = tmp->data; MetaWindow *w = l->data;
if (w->has_minimize_func && w != keep) if (w->has_minimize_func && w != keep)
meta_window_minimize (w); meta_window_minimize (w);
tmp = tmp->next;
} }
} }
@ -2571,7 +2534,7 @@ void
meta_screen_show_desktop (MetaScreen *screen, meta_screen_show_desktop (MetaScreen *screen,
guint32 timestamp) guint32 timestamp)
{ {
GList *windows; GList *l;
if (screen->active_workspace->showing_desktop) if (screen->active_workspace->showing_desktop)
return; return;
@ -2583,21 +2546,17 @@ meta_screen_show_desktop (MetaScreen *screen,
/* Focus the most recently used META_WINDOW_DESKTOP window, if there is one; /* Focus the most recently used META_WINDOW_DESKTOP window, if there is one;
* see bug 159257. * see bug 159257.
*/ */
windows = screen->active_workspace->mru_list; for (l = screen->active_workspace->mru_list; l != NULL; l = l->next)
while (windows != NULL)
{ {
MetaWindow *w = windows->data; MetaWindow *w = l->data;
if (w->type == META_WINDOW_DESKTOP) if (w->type == META_WINDOW_DESKTOP)
{ {
meta_window_focus (w, timestamp); meta_window_focus (w, timestamp);
break; break;
} }
windows = windows->next;
} }
meta_screen_update_showing_desktop_hint (screen); meta_screen_update_showing_desktop_hint (screen);
} }
@ -2726,7 +2685,7 @@ startup_sequence_timeout (void *data)
{ {
MetaScreen *screen = data; MetaScreen *screen = data;
CollectTimedOutData ctod; CollectTimedOutData ctod;
GSList *tmp; GSList *l;
ctod.list = NULL; ctod.list = NULL;
g_get_current_time (&ctod.now); g_get_current_time (&ctod.now);
@ -2734,18 +2693,15 @@ startup_sequence_timeout (void *data)
collect_timed_out_foreach, collect_timed_out_foreach,
&ctod); &ctod);
tmp = ctod.list; for (l = ctod.list; l != NULL; l = l->next)
while (tmp != NULL)
{ {
SnStartupSequence *sequence = tmp->data; SnStartupSequence *sequence = l->data;
meta_topic (META_DEBUG_STARTUP, meta_topic (META_DEBUG_STARTUP,
"Timed out sequence %s\n", "Timed out sequence %s\n",
sn_startup_sequence_get_id (sequence)); sn_startup_sequence_get_id (sequence));
sn_startup_sequence_complete (sequence); sn_startup_sequence_complete (sequence);
tmp = tmp->next;
} }
g_slist_free (ctod.list); g_slist_free (ctod.list);
@ -2846,7 +2802,7 @@ meta_screen_apply_startup_properties (MetaScreen *screen,
{ {
#ifdef HAVE_STARTUP_NOTIFICATION #ifdef HAVE_STARTUP_NOTIFICATION
const char *startup_id; const char *startup_id;
GSList *tmp; GSList *l;
SnStartupSequence *sequence; SnStartupSequence *sequence;
/* Does the window have a startup ID stored? */ /* Does the window have a startup ID stored? */
@ -2864,12 +2820,12 @@ meta_screen_apply_startup_properties (MetaScreen *screen,
* startup-notification library whether there's anything * startup-notification library whether there's anything
* stored for the resource name or resource class hints. * stored for the resource name or resource class hints.
*/ */
tmp = screen->startup_sequences; for (l = screen->startup_sequences; l != NULL; l = l->next)
while (tmp != NULL)
{ {
const char *wmclass; const char *wmclass;
SnStartupSequence *seq = l->data;
wmclass = sn_startup_sequence_get_wmclass (tmp->data); wmclass = sn_startup_sequence_get_wmclass (seq);
if (wmclass != NULL && if (wmclass != NULL &&
((window->res_class && ((window->res_class &&
@ -2877,7 +2833,7 @@ meta_screen_apply_startup_properties (MetaScreen *screen,
(window->res_name && (window->res_name &&
strcmp (wmclass, window->res_name) == 0))) strcmp (wmclass, window->res_name) == 0)))
{ {
sequence = tmp->data; sequence = seq;
g_assert (window->startup_id == NULL); g_assert (window->startup_id == NULL);
window->startup_id = g_strdup (sn_startup_sequence_get_id (sequence)); window->startup_id = g_strdup (sn_startup_sequence_get_id (sequence));
@ -2891,8 +2847,6 @@ meta_screen_apply_startup_properties (MetaScreen *screen,
sn_startup_sequence_complete (sequence); sn_startup_sequence_complete (sequence);
break; break;
} }
tmp = tmp->next;
} }
} }
@ -2906,20 +2860,18 @@ meta_screen_apply_startup_properties (MetaScreen *screen,
*/ */
if (sequence == NULL) if (sequence == NULL)
{ {
tmp = screen->startup_sequences; for (l = screen->startup_sequences; l != NULL; l = l->next)
while (tmp != NULL)
{ {
SnStartupSequence *seq = l->data;
const char *id; const char *id;
id = sn_startup_sequence_get_id (tmp->data); id = sn_startup_sequence_get_id (seq);
if (strcmp (id, startup_id) == 0) if (strcmp (id, startup_id) == 0)
{ {
sequence = tmp->data; sequence = seq;
break; break;
} }
tmp = tmp->next;
} }
} }