@@ -46,6 +46,8 @@ void window_kill_command(char *tokens[], int ntokens, char *response,
46
46
struct turtile_context * context );
47
47
void window_move_to_command (char * tokens [], int ntokens , char * response ,
48
48
struct turtile_context * context );
49
+ void window_master_toggle_command (char * tokens [], int ntokens , char * response ,
50
+ struct turtile_context * context );
49
51
void workspace_command (char * tokens [], int ntokens , char * response ,
50
52
struct turtile_context * context );
51
53
void workspace_list_command (char * tokens [], int ntokens , char * response ,
@@ -67,6 +69,7 @@ static command_t commands[] = {
67
69
{"window" , "cycle" , window_cycle_command },
68
70
{"window" , "kill" , window_kill_command },
69
71
{"window" , "move-to" , window_move_to_command },
72
+ {"window" , "mtoggle" , window_master_toggle_command },
70
73
{"window" , NULL , window_command },
71
74
{"workspace" , "list" , workspace_list_command },
72
75
{"workspace" , "switch" , workspace_switch_command },
@@ -310,6 +313,43 @@ void window_move_to_command(char *tokens[], int ntokens, char *response,
310
313
}
311
314
}
312
315
316
+ void window_master_toggle_command (char * tokens [], int ntokens , char * response ,
317
+ struct turtile_context * context ){
318
+ // Set designated toplevel as master
319
+ struct turtile_server * server = context -> server ;
320
+ struct turtile_toplevel * toplevel ;
321
+
322
+ if (ntokens >= 1 ){
323
+ char * new_toplevel_id = tokens [0 ];
324
+
325
+ wl_list_for_each (toplevel , & server -> focus_toplevels , flink ) {
326
+ if (strcmp (toplevel -> id , new_toplevel_id ) == 0 ){
327
+
328
+ wl_list_remove (& toplevel -> link );
329
+ wl_list_insert (& server -> toplevels , & toplevel -> link );
330
+ server_redraw_windows (server );
331
+
332
+ snprintf (response , MAX_MSG_SIZE ,
333
+ "{\"success\": \"master: %s\"}" ,
334
+ toplevel -> xdg_toplevel -> title );
335
+ return ;
336
+ }
337
+ }
338
+ snprintf (response , MAX_MSG_SIZE ,
339
+ "{\"error\": \"window %s not found\"}" , new_toplevel_id );
340
+
341
+ } else {
342
+ toplevel = get_first_toplevel (server );
343
+
344
+ wl_list_remove (& toplevel -> link );
345
+ wl_list_insert (& server -> toplevels , & toplevel -> link );
346
+ server_redraw_windows (server );
347
+
348
+ snprintf (response , MAX_MSG_SIZE ,
349
+ "{\"success\": \"master: %s\"}" , toplevel -> xdg_toplevel -> title );
350
+ }
351
+ }
352
+
313
353
void workspace_command (char * tokens [], int ntokens , char * response ,
314
354
struct turtile_context * context ){
315
355
// TODO: use this function as a help for the other workspace subcommands
0 commit comments