55#include <stdlib.h>
66#include <string.h>
77#include <wayland-client.h>
8- #include "wlr -workspace-unstable-v1-client-protocol.h"
8+ #include "ext -workspace-unstable-v1-client-protocol.h"
99
10- #define WLR_WORKSPACE_VERSION 1
10+ #define WLR_EXT_WORKSPACE_VERSION 1
1111
1212/**
1313 * Usage:
14- * 1. wlr -workspace
14+ * 1. ext -workspace
1515 * List all workspace groups and their workspaces
16- * 2. wlr -workspace -w X
16+ * 2. ext -workspace -w X
1717 * Focus workspace with name X
18- * 3. wlr -workspace -m
18+ * 3. ext -workspace -m
1919 * Continuously monitor for changes and print new state.
20+ * 4. ext-workspace -c X
21+ * Create a new workspace with name hint X in some workspace group
22+ * 5. ext-workspace -r X
23+ * Request removal of workspace X
2024 */
2125
2226enum workspace_state_field {
@@ -44,7 +48,7 @@ static void copy_state(struct workspace_state *current,
4448
4549struct workspace_v1 {
4650 struct wl_list link ;
47- struct zwlr_workspace_handle_v1 * handle ;
51+ struct zext_workspace_handle_v1 * handle ;
4852 struct workspace_state current , pending ;
4953};
5054
@@ -70,45 +74,44 @@ static uint32_t array_to_state(struct wl_array *array) {
7074 uint32_t state = 0 ;
7175 uint32_t * entry ;
7276 wl_array_for_each (entry , array ) {
73- if (* entry == ZWLR_WORKSPACE_HANDLE_V1_STATE_ACTIVE )
77+ if (* entry == ZEXT_WORKSPACE_HANDLE_V1_STATE_ACTIVE )
7478 state |= WORKSPACE_FOCUSED ;
7579 }
7680
7781 return state ;
7882}
7983
80-
8184static void workspace_handle_name (void * data ,
82- struct zwlr_workspace_handle_v1 * workspace_handle_v1 ,
85+ struct zext_workspace_handle_v1 * workspace_handle_v1 ,
8386 const char * name ) {
8487 struct workspace_v1 * workspace = (struct workspace_v1 * )
85- zwlr_workspace_handle_v1_get_user_data (workspace_handle_v1 );
88+ zext_workspace_handle_v1_get_user_data (workspace_handle_v1 );
8689
8790 free (workspace -> pending .name );
8891 workspace -> pending .name = strdup (name );
8992}
9093
9194static void workspace_handle_coordinates (void * data ,
92- struct zwlr_workspace_handle_v1 * workspace_handle ,
95+ struct zext_workspace_handle_v1 * workspace_handle ,
9396 struct wl_array * coordinates ) {
9497 struct workspace_v1 * workspace = (struct workspace_v1 * )
95- zwlr_workspace_handle_v1_get_user_data (workspace_handle );
98+ zext_workspace_handle_v1_get_user_data (workspace_handle );
9699 wl_array_copy (& workspace -> pending .coordinates , coordinates );
97100}
98101
99102static void workspace_handle_state (void * data ,
100- struct zwlr_workspace_handle_v1 * workspace_handle ,
103+ struct zext_workspace_handle_v1 * workspace_handle ,
101104 struct wl_array * state ) {
102105 struct workspace_v1 * workspace = (struct workspace_v1 * )
103- zwlr_workspace_handle_v1_get_user_data (workspace_handle );
106+ zext_workspace_handle_v1_get_user_data (workspace_handle );
104107 workspace -> pending .state = array_to_state (state );
105108}
106109
107110static void workspace_handle_remove (void * data ,
108- struct zwlr_workspace_handle_v1 * workspace_handle ) {
111+ struct zext_workspace_handle_v1 * workspace_handle ) {
109112 struct workspace_v1 * workspace = (struct workspace_v1 * )
110- zwlr_workspace_handle_v1_get_user_data (workspace_handle );
111- zwlr_workspace_handle_v1_destroy (workspace_handle );
113+ zext_workspace_handle_v1_get_user_data (workspace_handle );
114+ zext_workspace_handle_v1_destroy (workspace_handle );
112115
113116 wl_list_remove (& workspace -> link );
114117 free (workspace -> current .name );
@@ -118,7 +121,7 @@ static void workspace_handle_remove(void *data,
118121 free (workspace );
119122}
120123
121- static const struct zwlr_workspace_handle_v1_listener workspace_listener = {
124+ static const struct zext_workspace_handle_v1_listener workspace_listener = {
122125 .name = workspace_handle_name ,
123126 .coordinates = workspace_handle_coordinates ,
124127 .state = workspace_handle_state ,
@@ -128,33 +131,34 @@ static const struct zwlr_workspace_handle_v1_listener workspace_listener = {
128131struct group_v1 {
129132 struct wl_list link ;
130133
134+ struct zext_workspace_group_handle_v1 * handle ;
131135 int32_t id ;
132136 struct wl_list workspaces ;
133137};
134138
135139static void group_handle_output_enter (void * data ,
136- struct zwlr_workspace_group_handle_v1 * group_handle ,
140+ struct zext_workspace_group_handle_v1 * group_handle ,
137141 struct wl_output * output ) {
138142 struct group_v1 * group = (struct group_v1 * )
139- zwlr_workspace_group_handle_v1_get_user_data (group_handle );
143+ zext_workspace_group_handle_v1_get_user_data (group_handle );
140144 printf ("Group %d output_enter %u\n" , group -> id ,
141145 (uint32_t )(size_t )wl_output_get_user_data (output ));
142146}
143147
144148static void group_handle_output_leave (void * data ,
145- struct zwlr_workspace_group_handle_v1 * group_handle ,
149+ struct zext_workspace_group_handle_v1 * group_handle ,
146150 struct wl_output * output ) {
147151 struct group_v1 * group = (struct group_v1 * )
148- zwlr_workspace_group_handle_v1_get_user_data (group_handle );
152+ zext_workspace_group_handle_v1_get_user_data (group_handle );
149153 printf ("Group %d output_leave %u\n" , group -> id ,
150154 (uint32_t )(size_t )wl_output_get_user_data (output ));
151155}
152156
153157static void group_handle_workspace (void * data ,
154- struct zwlr_workspace_group_handle_v1 * group_handle ,
155- struct zwlr_workspace_handle_v1 * workspace_handle ) {
158+ struct zext_workspace_group_handle_v1 * group_handle ,
159+ struct zext_workspace_handle_v1 * workspace_handle ) {
156160 struct group_v1 * group = (struct group_v1 * )
157- zwlr_workspace_group_handle_v1_get_user_data (group_handle );
161+ zext_workspace_group_handle_v1_get_user_data (group_handle );
158162 struct workspace_v1 * workspace = (struct workspace_v1 * )
159163 calloc (1 , sizeof (struct workspace_v1 ));
160164
@@ -163,15 +167,15 @@ static void group_handle_workspace(void *data,
163167 wl_array_init (& workspace -> current .coordinates );
164168
165169 workspace -> handle = workspace_handle ;
166- zwlr_workspace_handle_v1_add_listener (workspace_handle ,
170+ zext_workspace_handle_v1_add_listener (workspace_handle ,
167171 & workspace_listener , NULL );
168- zwlr_workspace_handle_v1_set_user_data (workspace_handle , workspace );
172+ zext_workspace_handle_v1_set_user_data (workspace_handle , workspace );
169173}
170174
171175static void group_handle_remove (void * data ,
172- struct zwlr_workspace_group_handle_v1 * group_handle ) {
176+ struct zext_workspace_group_handle_v1 * group_handle ) {
173177 struct group_v1 * group = (struct group_v1 * )
174- zwlr_workspace_group_handle_v1_get_user_data (group_handle );
178+ zext_workspace_group_handle_v1_get_user_data (group_handle );
175179 wl_list_remove (& group -> link );
176180 if (!wl_list_empty (& group -> workspaces )) {
177181 printf ("Compositor bug! Group destroyed before its workspaces.\n" );
@@ -180,33 +184,34 @@ static void group_handle_remove(void *data,
180184 free (group );
181185}
182186
183- static const struct zwlr_workspace_group_handle_v1_listener group_listener = {
187+ static const struct zext_workspace_group_handle_v1_listener group_listener = {
184188 .output_enter = group_handle_output_enter ,
185189 .output_leave = group_handle_output_leave ,
186190 .workspace = group_handle_workspace ,
187191 .remove = group_handle_remove ,
188192};
189193
190- static struct zwlr_workspace_manager_v1 * workspace_manager = NULL ;
194+ static struct zext_workspace_manager_v1 * workspace_manager = NULL ;
191195static struct wl_list group_list ;
192196static int32_t last_group_id = 0 ;
193197
194198static void workspace_manager_handle_workspace_group (void * data ,
195- struct zwlr_workspace_manager_v1 * zwlr_workspace_manager_v1 ,
196- struct zwlr_workspace_group_handle_v1 * workspace_group ) {
199+ struct zext_workspace_manager_v1 * zext_workspace_manager_v1 ,
200+ struct zext_workspace_group_handle_v1 * workspace_group ) {
197201 struct group_v1 * group = (struct group_v1 * )
198202 calloc (1 , sizeof (struct group_v1 ));
199203 group -> id = last_group_id ++ ;
204+ group -> handle = workspace_group ;
200205 wl_list_init (& group -> workspaces );
201206 wl_list_insert (& group_list , & group -> link );
202207
203- zwlr_workspace_group_handle_v1_add_listener (workspace_group ,
208+ zext_workspace_group_handle_v1_add_listener (workspace_group ,
204209 & group_listener , NULL );
205- zwlr_workspace_group_handle_v1_set_user_data (workspace_group , group );
210+ zext_workspace_group_handle_v1_set_user_data (workspace_group , group );
206211}
207212
208213static void workspace_manager_handle_done (void * data ,
209- struct zwlr_workspace_manager_v1 * zwlr_workspace_manager_v1 ) {
214+ struct zext_workspace_manager_v1 * zext_workspace_manager_v1 ) {
210215
211216 printf ("*** Workspace configuration ***\n" );
212217 struct group_v1 * group ;
@@ -221,11 +226,11 @@ static void workspace_manager_handle_done(void *data,
221226}
222227
223228static void workspace_manager_handle_finished (void * data ,
224- struct zwlr_workspace_manager_v1 * zwlr_workspace_manager_v1 ) {
225- zwlr_workspace_manager_v1_destroy ( zwlr_workspace_manager_v1 );
229+ struct zext_workspace_manager_v1 * zext_workspace_manager_v1 ) {
230+ zext_workspace_manager_v1_destroy ( zext_workspace_manager_v1 );
226231}
227232
228- static const struct zwlr_workspace_manager_v1_listener workspace_manager_impl = {
233+ static const struct zext_workspace_manager_v1_listener workspace_manager_impl = {
229234 .workspace_group = workspace_manager_handle_workspace_group ,
230235 .done = workspace_manager_handle_done ,
231236 .finished = workspace_manager_handle_finished ,
@@ -239,12 +244,12 @@ static void handle_global(void *data, struct wl_registry *registry,
239244 & wl_output_interface , version );
240245 wl_output_set_user_data (output , (void * )(size_t )name ); // assign some ID to the output
241246 } else if (strcmp (interface ,
242- zwlr_workspace_manager_v1_interface .name ) == 0 ) {
247+ zext_workspace_manager_v1_interface .name ) == 0 ) {
243248 workspace_manager = wl_registry_bind (registry , name ,
244- & zwlr_workspace_manager_v1_interface , WLR_WORKSPACE_VERSION );
249+ & zext_workspace_manager_v1_interface , WLR_EXT_WORKSPACE_VERSION );
245250
246251 wl_list_init (& group_list );
247- zwlr_workspace_manager_v1_add_listener (workspace_manager ,
252+ zext_workspace_manager_v1_add_listener (workspace_manager ,
248253 & workspace_manager_impl , NULL );
249254 }
250255}
@@ -278,11 +283,19 @@ static struct workspace_v1 *workspace_by_name_or_bail(const char *name) {
278283
279284int main (int argc , char * * argv ) {
280285 int c ;
281- char * focus_name = NULL ;
286+ char * focus_name = NULL ;
287+ char * create_name = NULL ;
288+ char * remove_name = NULL ;
282289 bool monitor = false;
283290
284- while ((c = getopt (argc , argv , "w:m" )) != -1 ) {
291+ while ((c = getopt (argc , argv , "c:r: w:m" )) != -1 ) {
285292 switch (c ) {
293+ case 'c' :
294+ create_name = strdup (optarg );
295+ break ;
296+ case 'r' :
297+ remove_name = strdup (optarg );
298+ break ;
286299 case 'w' :
287300 focus_name = strdup (optarg );
288301 break ;
@@ -319,11 +332,24 @@ int main(int argc, char **argv) {
319332
320333 wl_list_for_each (group , & group_list , link ) {
321334 wl_list_for_each (workspace , & group -> workspaces , link ) {
322- zwlr_workspace_handle_v1_deactivate (workspace -> handle );
335+ zext_workspace_handle_v1_deactivate (workspace -> handle );
323336 }
324337 }
325- zwlr_workspace_handle_v1_activate (focus -> handle );
326- zwlr_workspace_manager_v1_commit (workspace_manager );
338+ zext_workspace_handle_v1_activate (focus -> handle );
339+ zext_workspace_manager_v1_commit (workspace_manager );
340+ }
341+
342+ if (create_name != NULL ) {
343+ struct group_v1 * group ;
344+ wl_list_for_each (group , & group_list , link ) {
345+ zext_workspace_group_handle_v1_create_workspace (group -> handle , create_name );
346+ break ;
347+ }
348+ }
349+
350+ if (remove_name != NULL ) {
351+ struct workspace_v1 * remove = workspace_by_name_or_bail (remove_name );
352+ zext_workspace_handle_v1_remove (remove -> handle );
327353 }
328354
329355 wl_display_flush (display );
0 commit comments