summaryrefslogtreecommitdiff
path: root/src/services/workspace-service.c
diff options
context:
space:
mode:
authorHannes Schulze <contact@haschu.me>2026-04-26 01:22:34 +0200
committerHannes Schulze <contact@haschu.me>2026-04-26 01:22:34 +0200
commit00be66dad9d27fb9f271e7a645ef90a343753819 (patch)
tree2d23b0598c3aa580b31bbf19b953a6e3c4d8aa83 /src/services/workspace-service.c
parente80a97f5603658af3a444a3a8213024c0c9d36d6 (diff)
sway workspace service skeleton
Diffstat (limited to 'src/services/workspace-service.c')
-rw-r--r--src/services/workspace-service.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/services/workspace-service.c b/src/services/workspace-service.c
index f9a6ecd..26779c0 100644
--- a/src/services/workspace-service.c
+++ b/src/services/workspace-service.c
@@ -140,6 +140,57 @@ void foobar_workspace_activate( FoobarWorkspace* self )
FOOBAR_WORKSPACE_GET_IFACE( self )->activate( self );
}
+//
+// 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_workspace_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 ) );
+}
+
// ---------------------------------------------------------------------------------------------------------------------
// Service Interface
// ---------------------------------------------------------------------------------------------------------------------