summaryrefslogtreecommitdiff
path: root/src/services/workspaces/hyprland-workspace-service.c
diff options
context:
space:
mode:
authorHannes Schulze <contact@haschu.me>2026-04-26 12:11:30 +0200
committerHannes Schulze <contact@haschu.me>2026-04-26 12:11:30 +0200
commit04f6355bdf1696f6afce46a01a03058c12673496 (patch)
treea2c84588f1f6e368042e4d8fda02d9cdc27beba2 /src/services/workspaces/hyprland-workspace-service.c
parent6affbd6c4cb60786993690f35a90711094f18268 (diff)
send sway commands
Diffstat (limited to 'src/services/workspaces/hyprland-workspace-service.c')
-rw-r--r--src/services/workspaces/hyprland-workspace-service.c56
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(