diff --git a/src/core/display-private.h b/src/core/display-private.h index aca7791d9..2858c1944 100644 --- a/src/core/display-private.h +++ b/src/core/display-private.h @@ -150,6 +150,15 @@ struct _MetaDisplay guint32 current_time; + /* We maintain a sequence counter, incremented for each #MetaWindow + * created. This is exposed by meta_window_get_stable_sequence() + * but is otherwise not used inside mutter. + * + * It can be useful to plugins which want to sort windows in a + * stable fashion. + */ + guint32 window_sequence_counter; + /* Pings which we're waiting for a reply from */ GSList *pending_pings; diff --git a/src/core/window-private.h b/src/core/window-private.h index 0e7fb9819..9bc808979 100644 --- a/src/core/window-private.h +++ b/src/core/window-private.h @@ -316,6 +316,9 @@ struct _MetaWindow */ int unmaps_pending; + /* See docs for meta_window_get_stable_sequence() */ + guint32 stable_sequence; + /* set to the most recent user-interaction event timestamp that we know about for this window */ guint32 net_wm_user_time; diff --git a/src/core/window.c b/src/core/window.c index a3997a76b..5d184c0ac 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -802,6 +802,10 @@ meta_window_new_with_attrs (MetaDisplay *display, meta_display_register_x_window (display, &window->xwindow, window); + /* Assign this #MetaWindow a sequence number which can be used + * for sorting. + */ + window->stable_sequence = ++display->window_sequence_counter; /* assign the window to its group, or create a new group if needed */ @@ -8532,6 +8536,26 @@ meta_window_set_user_time (MetaWindow *window, g_object_notify (G_OBJECT (window), "user-time"); } +/** + * meta_window_get_stable_sequence: + * @window: A #MetaWindow + * + * The stable sequence number is a monotonicially increasing + * unique integer assigned to each #MetaWindow upon creation. + * + * This number can be useful for sorting windows in a stable + * fashion. + * + * Returns: Internal sequence number for this window + */ +guint32 +meta_window_get_stable_sequence (MetaWindow *window) +{ + g_return_val_if_fail (META_IS_WINDOW (window), 0); + + return window->stable_sequence; +} + /* Sets the demands_attention hint on a window, but only * if it's at least partially obscured (see #305882). */ diff --git a/src/include/window.h b/src/include/window.h index 782347072..15f4f25ab 100644 --- a/src/include/window.h +++ b/src/include/window.h @@ -118,6 +118,7 @@ const char *meta_window_get_title (MetaWindow *window); MetaWindow *meta_window_get_transient_for (MetaWindow *window); void meta_window_delete (MetaWindow *window, guint32 timestamp); +guint meta_window_get_stable_sequence (MetaWindow *window); guint32 meta_window_get_user_time (MetaWindow *window); int meta_window_get_pid (MetaWindow *window); const char *meta_window_get_client_machine (MetaWindow *window);