diff options
Diffstat (limited to 'src/services/workspaces/hyprland-workspace-service.c')
| -rw-r--r-- | src/services/workspaces/hyprland-workspace-service.c | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/src/services/workspaces/hyprland-workspace-service.c b/src/services/workspaces/hyprland-workspace-service.c index 3abe152..9a64c49 100644 --- a/src/services/workspaces/hyprland-workspace-service.c +++ b/src/services/workspaces/hyprland-workspace-service.c @@ -133,6 +133,9 @@ static gint64 foobar_hyprland_workspace_service_parse_id static gchar* foobar_hyprland_workspace_service_get_hyprland_base_path ( void ); static gint foobar_hyprland_workspace_service_compare_ids ( gconstpointer a, gconstpointer b ); +static gint foobar_hyprland_workspace_service_sort_func ( gconstpointer item_a, + gconstpointer item_b, + gpointer userdata ); G_DEFINE_TYPE_WITH_CODE( @@ -452,7 +455,7 @@ void foobar_hyprland_workspace_service_init( FoobarHyprlandWorkspaceService* sel { self->workspaces = g_list_store_new( FOOBAR_TYPE_WORKSPACE ); - GtkCustomSorter* sorter = gtk_custom_sorter_new( foobar_workspace_sort_func, NULL, NULL ); + GtkCustomSorter* sorter = gtk_custom_sorter_new( foobar_hyprland_workspace_service_sort_func, NULL, NULL ); self->sorted_workspaces = gtk_sort_list_model_new( G_LIST_MODEL( g_object_ref( self->workspaces ) ), GTK_SORTER( sorter ) ); @@ -1283,6 +1286,57 @@ gint foobar_hyprland_workspace_service_compare_ids( } // +// Sorting callback for workspaces. Items are sorted to be in the following order: +// 1. normal +// 2. named persistent +// 3. named +// 4. special +// 5. named special +// +gint foobar_hyprland_workspace_service_sort_func( + gconstpointer item_a, + gconstpointer item_b, + gpointer userdata ) +{ + (void)userdata; + + FoobarWorkspace* workspace_a = (FoobarWorkspace*)item_a; + FoobarWorkspace* workspace_b = (FoobarWorkspace*)item_b; + gint64 id_a = foobar_workspace_get_id( workspace_a ); + gint64 id_b = foobar_workspace_get_id( workspace_b ); + gboolean special_a = ( foobar_workspace_get_flags( workspace_a ) & FOOBAR_WORKSPACE_FLAGS_SPECIAL ) != 0; + gboolean special_b = ( foobar_workspace_get_flags( workspace_b ) & FOOBAR_WORKSPACE_FLAGS_SPECIAL ) != 0; + gboolean named_a = id_a < 0; + gboolean named_b = id_b < 0; + + // both normal (includes numbered persistent) => sort by ID + if ( !named_a && !named_b ) + { + if ( id_a < id_b ) { return -1; } + if ( id_a > id_b ) { return 1; } + return 0; + } + + // one normal, one special => normal first + if ( special_a && !special_b ) { return 1; } + if ( !special_a && special_b ) { return -1; } + + // only one normal, one named + if ( named_a && !named_b ) { return -1; } + if ( !named_a && named_b ) { return 1; } + + // both special + if ( special_a && special_b ) + { + // if one is -99 => put it last + if ( id_a == -99 && id_b != -99 ) { return 1; } + if ( id_a != -99 && id_b == -99 ) { return -1; } + } + + return g_strcmp0( foobar_workspace_get_name( workspace_a ), foobar_workspace_get_name( workspace_b ) ); +} + +// // Create a new EventData structure. // static EventData* event_data_new( |
