#include "services/workspace-service.h" #include // // FoobarWorkspaceFlags: // // Some information about the type/state of a workspace. // G_DEFINE_FLAGS_TYPE( FoobarWorkspaceFlags, foobar_workspace_flags, G_DEFINE_ENUM_VALUE( FOOBAR_WORKSPACE_FLAGS_NONE, "none" ), G_DEFINE_ENUM_VALUE( FOOBAR_WORKSPACE_FLAGS_ACTIVE, "active" ), G_DEFINE_ENUM_VALUE( FOOBAR_WORKSPACE_FLAGS_VISIBLE, "visible" ), G_DEFINE_ENUM_VALUE( FOOBAR_WORKSPACE_FLAGS_SPECIAL, "special" ), G_DEFINE_ENUM_VALUE( FOOBAR_WORKSPACE_FLAGS_PERSISTENT, "persistent" ), G_DEFINE_ENUM_VALUE( FOOBAR_WORKSPACE_FLAGS_URGENT, "urgent" ) ) // // FoobarWorkspace: // // Representation of a workspace. // G_DEFINE_INTERFACE( FoobarWorkspace, foobar_workspace, G_TYPE_OBJECT ) static void foobar_workspace_default_init( FoobarWorkspaceInterface* iface ); // // FoobarWorkspaceService: // // Service monitoring the workspaces provided by the window manager. The implementation depends on the window manager. // G_DEFINE_INTERFACE( FoobarWorkspaceService, foobar_workspace_service, G_TYPE_OBJECT ) static void foobar_workspace_service_default_init( FoobarWorkspaceServiceInterface* iface ); enum { SIGNAL_MONITOR_CONFIGURATION_CHANGED, N_SIGNALS, }; static unsigned signals[N_SIGNALS] = { 0 }; // --------------------------------------------------------------------------------------------------------------------- // Workspace // --------------------------------------------------------------------------------------------------------------------- // // Static initialization for workspaces. // void foobar_workspace_default_init( FoobarWorkspaceInterface* iface ) { g_object_interface_install_property( iface, g_param_spec_int64( "id", "ID", "Numeric ID of the workspace.", INT64_MIN, INT64_MAX, 0, G_PARAM_READABLE ) ); g_object_interface_install_property( iface, g_param_spec_string( "name", "Name", "Optional human-readable workspace name.", NULL, G_PARAM_READABLE ) ); g_object_interface_install_property( iface, g_param_spec_string( "monitor", "Monitor", "Connector ID of the workspace's monitor.", NULL, G_PARAM_READABLE ) ); g_object_interface_install_property( iface, g_param_spec_flags( "flags", "Flags", "Flags indicating the current state of the workspace.", FOOBAR_TYPE_WORKSPACE_FLAGS, FOOBAR_WORKSPACE_FLAGS_NONE, G_PARAM_READABLE ) ); } // // Numeric ID of the workspace. // gint64 foobar_workspace_get_id( FoobarWorkspace* self ) { g_return_val_if_fail( FOOBAR_IS_WORKSPACE( self ), 0 ); return FOOBAR_WORKSPACE_GET_IFACE( self )->get_id( self ); } // // Optional human-readable workspace name. // gchar const* foobar_workspace_get_name( FoobarWorkspace* self ) { g_return_val_if_fail( FOOBAR_IS_WORKSPACE( self ), NULL ); return FOOBAR_WORKSPACE_GET_IFACE( self )->get_name( self ); } // // Connector ID of the workspace's monitor. // gchar const* foobar_workspace_get_monitor( FoobarWorkspace* self ) { g_return_val_if_fail( FOOBAR_IS_WORKSPACE( self ), NULL ); return FOOBAR_WORKSPACE_GET_IFACE( self )->get_monitor( self ); } // // Flags indicating the current state of the workspace. // FoobarWorkspaceFlags foobar_workspace_get_flags( FoobarWorkspace* self ) { g_return_val_if_fail( FOOBAR_IS_WORKSPACE( self ), FOOBAR_WORKSPACE_FLAGS_NONE ); return FOOBAR_WORKSPACE_GET_IFACE( self )->get_flags( self ); } // // Let this workspace become the active one. // void foobar_workspace_activate( FoobarWorkspace* self ) { g_return_if_fail( FOOBAR_IS_WORKSPACE( 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 // --------------------------------------------------------------------------------------------------------------------- // // Static initialization for the workspace service. // void foobar_workspace_service_default_init( FoobarWorkspaceServiceInterface* iface ) { g_object_interface_install_property( iface, g_param_spec_object( "workspaces", "Workspaces", "Sorted list of all workspaces.", G_TYPE_LIST_MODEL, G_PARAM_READABLE ) ); signals[SIGNAL_MONITOR_CONFIGURATION_CHANGED] = g_signal_new( "monitor-configuration-changed", FOOBAR_TYPE_WORKSPACE_SERVICE, G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, 0, NULL, NULL, NULL, G_TYPE_NONE, 0 ); } // // Get a sorted list of all workspaces. // GListModel* foobar_workspace_service_get_workspaces( FoobarWorkspaceService* self ) { g_return_val_if_fail( FOOBAR_IS_WORKSPACE_SERVICE( self ), NULL ); return FOOBAR_WORKSPACE_SERVICE_GET_IFACE( self )->get_workspaces( self ); } // // Check whether this implementation is available (i.e., the window manager is running). // gboolean foobar_workspace_service_is_available( FoobarWorkspaceService* self ) { g_return_val_if_fail( FOOBAR_IS_WORKSPACE_SERVICE( self ), FALSE ); return FOOBAR_WORKSPACE_SERVICE_GET_IFACE( self )->is_available( self ); }