Skip to content

Commit 699379c

Browse files
feat: base working master toggle command
1 parent 9cb3781 commit 699379c

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/commands.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ void window_kill_command(char *tokens[], int ntokens, char *response,
4646
struct turtile_context *context);
4747
void window_move_to_command(char *tokens[], int ntokens, char *response,
4848
struct turtile_context *context);
49+
void window_master_toggle_command(char *tokens[], int ntokens, char *response,
50+
struct turtile_context *context);
4951
void workspace_command(char *tokens[], int ntokens, char *response,
5052
struct turtile_context *context);
5153
void workspace_list_command(char *tokens[], int ntokens, char *response,
@@ -67,6 +69,7 @@ static command_t commands[] = {
6769
{"window", "cycle", window_cycle_command},
6870
{"window", "kill", window_kill_command},
6971
{"window", "move-to", window_move_to_command},
72+
{"window", "mtoggle", window_master_toggle_command},
7073
{"window", NULL, window_command},
7174
{"workspace", "list", workspace_list_command},
7275
{"workspace", "switch", workspace_switch_command},
@@ -310,6 +313,43 @@ void window_move_to_command(char *tokens[], int ntokens, char *response,
310313
}
311314
}
312315

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+
313353
void workspace_command(char *tokens[], int ntokens, char *response,
314354
struct turtile_context *context){
315355
// TODO: use this function as a help for the other workspace subcommands

0 commit comments

Comments
 (0)