diff options
| author | Victor Kareh <[email protected]> | 2026-07-09 16:46:17 -0400 |
|---|---|---|
| committer | Luke from DC <[email protected]> | 2026-07-27 23:15:29 +0000 |
| commit | 4b452dacfd8bc73581f669baa8d9d3b385b45136 (patch) | |
| tree | a41b3a6b61cf23cc30864c35a7066036a4eb3f41 | |
| parent | 11bbf471c2483bbd852d9ae4c0b638f06e540714 (diff) | |
| download | mate-panel-4b452dacfd8bc73581f669baa8d9d3b385b45136.tar.bz2 mate-panel-4b452dacfd8bc73581f669baa8d9d3b385b45136.tar.xz | |
panel: "Compress" indexes on end of drag
To make sure the pack indexes never grow forever, recompute them on the
end of a drag, starting from 0. This way, we always keep a 0:n range of
indexes, instead of x:x+n with a moving x.
While it could be argued it should not be needed, it's much simpler than
specifically handling some cases where we have to explicitly decrease
all indexes, like when moving an object which is moved to another panel,
or removing an object from the panel.
This is not an action that is urgent to do (since "uncompressed"
indexes don't harm in any way), so the end of a drag is a good enough
place to call that.
Backported from https://gitlab.gnome.org/GNOME/gnome-panel/-/commit/2256381b6
| -rw-r--r-- | mate-panel/panel-widget.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/mate-panel/panel-widget.c b/mate-panel/panel-widget.c index e4a0a4df..26239139 100644 --- a/mate-panel/panel-widget.c +++ b/mate-panel/panel-widget.c @@ -1896,6 +1896,43 @@ panel_widget_applet_drag_start_no_grab (PanelWidget *panel, } static void +panel_widget_compress_pack_indexes_list (PanelWidget *panel, + GList *list) +{ + GList *l; + AppletData *ad; + int index; + + for (l = list, index = 0; l; l = l->next, index++) { + ad = l->data; + if (ad->pack_index != index) { + ad->pack_index = index; + emit_applet_moved (panel, ad); + } + } +} + +/* make sure our lists always start at 0 */ +static void +panel_widget_compress_pack_indexes (PanelWidget *panel) +{ + GList *list; + + list = get_applet_list_pack (panel, PANEL_OBJECT_PACK_START); + panel_widget_compress_pack_indexes_list (panel, list); + g_list_free (list); + + list = get_applet_list_pack (panel, PANEL_OBJECT_PACK_CENTER); + panel_widget_compress_pack_indexes_list (panel, list); + g_list_free (list); + + list = get_applet_list_pack (panel, PANEL_OBJECT_PACK_END); + list = g_list_reverse (list); + panel_widget_compress_pack_indexes_list (panel, list); + g_list_free (list); +} + +static void panel_widget_applet_drag_end_no_grab (PanelWidget *panel) { g_return_if_fail (panel != NULL); @@ -1913,6 +1950,15 @@ panel_widget_applet_drag_end_no_grab (PanelWidget *panel) moving_timeout = 0; been_moved = FALSE; } + + /* Make sure we keep our indexes in a 0:n range, instead of a x:x+n + * range, with a growing x. Note that this is useful not only because + * of moves, but also because of removal of objects (object 0 could be + * removed, but if there is still object 1, we start growing the + * range). But doing this compress only once in a while, after moving + * objects is good enough, since this is nothing urgent and the user + * will move objects before this becomes a real annoying issue. */ + panel_widget_compress_pack_indexes (panel); } void |
