summaryrefslogtreecommitdiff
path: root/src/services/workspace-service.c
blob: f9a6ecdf6861f54f6dd211a624d8d43dc619adfd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include "services/workspace-service.h"
#include <stdint.h>

//
// 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 );
}

// ---------------------------------------------------------------------------------------------------------------------
// 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 );
}