more progresses

This commit is contained in:
nixo 2020-05-10 18:31:26 +02:00
parent c8f383329d
commit 03cbf0a766
4 changed files with 289 additions and 300 deletions

View File

@ -2,35 +2,19 @@ static void GENERATED_call(const int call_identifier, struct CommandResultIR *re
switch (call_identifier) { switch (call_identifier) {
case 0: case 0:
result->next_state = INITIAL; result->next_state = INITIAL;
#ifndef TEST_PARSER
cmd_rename_workspace(&current_match, result, "to", get_string("new_name"));
#else
fprintf(stderr, "cmd_rename_workspace(%s, %s)\n", "to", get_string("new_name")); fprintf(stderr, "cmd_rename_workspace(%s, %s)\n", "to", get_string("new_name"));
#endif
break; break;
case 1: case 1:
result->next_state = INITIAL; result->next_state = INITIAL;
#ifndef TEST_PARSER
cmd_rename_workspace(&current_match, result, NULL, "to");
#else
fprintf(stderr, "cmd_rename_workspace(NULL, %s)\n", "to"); fprintf(stderr, "cmd_rename_workspace(NULL, %s)\n", "to");
#endif
break; break;
case 2: case 2:
result->next_state = INITIAL; result->next_state = INITIAL;
#ifndef TEST_PARSER
cmd_rename_workspace(&current_match, result, get_string("old_name"), get_string("new_name"));
#else
fprintf(stderr, "cmd_rename_workspace(%s, %s)\n", get_string("old_name"), get_string("new_name")); fprintf(stderr, "cmd_rename_workspace(%s, %s)\n", get_string("old_name"), get_string("new_name"));
#endif
break; break;
case 3: case 3:
result->next_state = INITIAL; result->next_state = INITIAL;
#ifndef TEST_PARSER
cmd_rename_workspace(&current_match, result, NULL, get_string("new_name"));
#else
fprintf(stderr, "cmd_rename_workspace(NULL, %s)\n", get_string("new_name")); fprintf(stderr, "cmd_rename_workspace(NULL, %s)\n", get_string("new_name"));
#endif
break; break;
case 4: case 4:
result->next_state = INITIAL; result->next_state = INITIAL;
@ -186,43 +170,23 @@ static void GENERATED_call(const int call_identifier, struct CommandResultIR *re
break; break;
case 23: case 23:
result->next_state = INITIAL; result->next_state = INITIAL;
#ifndef TEST_PARSER
cmd_move_con_to_workspace(&current_match, result, get_string("workspace"));
#else
fprintf(stderr, "cmd_move_con_to_workspace(%s)\n", get_string("workspace")); fprintf(stderr, "cmd_move_con_to_workspace(%s)\n", get_string("workspace"));
#endif
break; break;
case 24: case 24:
result->next_state = INITIAL; result->next_state = INITIAL;
#ifndef TEST_PARSER
cmd_move_con_to_workspace(&current_match, result, get_string("workspace"));
#else
fprintf(stderr, "cmd_move_con_to_workspace(%s)\n", get_string("workspace")); fprintf(stderr, "cmd_move_con_to_workspace(%s)\n", get_string("workspace"));
#endif
break; break;
case 25: case 25:
result->next_state = INITIAL; result->next_state = INITIAL;
#ifndef TEST_PARSER
cmd_move_con_to_workspace(&current_match, result, get_string("workspace"));
#else
fprintf(stderr, "cmd_move_con_to_workspace(%s)\n", get_string("workspace")); fprintf(stderr, "cmd_move_con_to_workspace(%s)\n", get_string("workspace"));
#endif
break; break;
case 26: case 26:
result->next_state = INITIAL; result->next_state = INITIAL;
#ifndef TEST_PARSER
cmd_move_con_to_workspace(&current_match, result, get_string("workspace"));
#else
fprintf(stderr, "cmd_move_con_to_workspace(%s)\n", get_string("workspace")); fprintf(stderr, "cmd_move_con_to_workspace(%s)\n", get_string("workspace"));
#endif
break; break;
case 27: case 27:
result->next_state = INITIAL; result->next_state = INITIAL;
#ifndef TEST_PARSER
cmd_move_con_to_workspace(&current_match, result, get_string("workspace"));
#else
fprintf(stderr, "cmd_move_con_to_workspace(%s)\n", get_string("workspace")); fprintf(stderr, "cmd_move_con_to_workspace(%s)\n", get_string("workspace"));
#endif
break; break;
case 28: case 28:
result->next_state = INITIAL; result->next_state = INITIAL;
@ -250,19 +214,11 @@ static void GENERATED_call(const int call_identifier, struct CommandResultIR *re
break; break;
case 31: case 31:
result->next_state = INITIAL; result->next_state = INITIAL;
#ifndef TEST_PARSER
cmd_layout_toggle(&current_match, result, get_string("toggle_mode"));
#else
fprintf(stderr, "cmd_layout_toggle(%s)\n", get_string("toggle_mode")); fprintf(stderr, "cmd_layout_toggle(%s)\n", get_string("toggle_mode"));
#endif
break; break;
case 32: case 32:
result->next_state = INITIAL; result->next_state = INITIAL;
#ifndef TEST_PARSER
cmd_layout_toggle(&current_match, result, get_string("toggle_mode"));
#else
fprintf(stderr, "cmd_layout_toggle(%s)\n", get_string("toggle_mode")); fprintf(stderr, "cmd_layout_toggle(%s)\n", get_string("toggle_mode"));
#endif
break; break;
case 33: case 33:
result->next_state = INITIAL; result->next_state = INITIAL;
@ -514,51 +470,27 @@ static void GENERATED_call(const int call_identifier, struct CommandResultIR *re
break; break;
case 64: case 64:
result->next_state = INITIAL; result->next_state = INITIAL;
#ifndef TEST_PARSER
cmd_layout(&current_match, result, get_string("layout_mode"));
#else
fprintf(stderr, "cmd_layout(%s)\n", get_string("layout_mode")); fprintf(stderr, "cmd_layout(%s)\n", get_string("layout_mode"));
#endif
break; break;
case 65: case 65:
result->next_state = INITIAL; result->next_state = INITIAL;
#ifndef TEST_PARSER
cmd_layout(&current_match, result, get_string("layout_mode"));
#else
fprintf(stderr, "cmd_layout(%s)\n", get_string("layout_mode")); fprintf(stderr, "cmd_layout(%s)\n", get_string("layout_mode"));
#endif
break; break;
case 66: case 66:
result->next_state = INITIAL; result->next_state = INITIAL;
#ifndef TEST_PARSER
cmd_layout(&current_match, result, get_string("layout_mode"));
#else
fprintf(stderr, "cmd_layout(%s)\n", get_string("layout_mode")); fprintf(stderr, "cmd_layout(%s)\n", get_string("layout_mode"));
#endif
break; break;
case 67: case 67:
result->next_state = INITIAL; result->next_state = INITIAL;
#ifndef TEST_PARSER
cmd_layout(&current_match, result, get_string("layout_mode"));
#else
fprintf(stderr, "cmd_layout(%s)\n", get_string("layout_mode")); fprintf(stderr, "cmd_layout(%s)\n", get_string("layout_mode"));
#endif
break; break;
case 68: case 68:
result->next_state = INITIAL; result->next_state = INITIAL;
#ifndef TEST_PARSER
cmd_layout(&current_match, result, get_string("layout_mode"));
#else
fprintf(stderr, "cmd_layout(%s)\n", get_string("layout_mode")); fprintf(stderr, "cmd_layout(%s)\n", get_string("layout_mode"));
#endif
break; break;
case 69: case 69:
result->next_state = INITIAL; result->next_state = INITIAL;
#ifndef TEST_PARSER
cmd_layout(&current_match, result, get_string("layout_mode"));
#else
fprintf(stderr, "cmd_layout(%s)\n", get_string("layout_mode")); fprintf(stderr, "cmd_layout(%s)\n", get_string("layout_mode"));
#endif
break; break;
case 70: case 70:
result->next_state = INITIAL; result->next_state = INITIAL;

View File

@ -44,7 +44,7 @@ void cmd_criteria_add(I3_CMD, const char *ctype, const char *cvalue);
* next|prev|next_on_output|prev_on_output'. * next|prev|next_on_output|prev_on_output'.
* *
*/ */
void cmd_move_con_to_workspace(I3_CMD, const char *which); SCM guile_move_con_to_workspace(SCM which);
/** /**
* Implementation of 'move [window|container] [to] workspace back_and_forth'. * Implementation of 'move [window|container] [to] workspace back_and_forth'.
@ -218,13 +218,13 @@ void cmd_move_direction(I3_CMD, const char *direction_str, long move_px);
* Implementation of 'layout default|stacked|stacking|tabbed|splitv|splith'. * Implementation of 'layout default|stacked|stacking|tabbed|splitv|splith'.
* *
*/ */
void cmd_layout(I3_CMD, const char *layout_str); SCM guile_layout(SCM layout);
/** /**
* Implementation of 'layout toggle [all|split]'. * Implementation of 'layout toggle [all|split]'.
* *
*/ */
void cmd_layout_toggle(I3_CMD, const char *toggle_mode); SCM guile_layout_toggle(SCM toggle_mode);
/** /**
* Implementation of 'exit'. * Implementation of 'exit'.
@ -302,7 +302,7 @@ void cmd_title_format(I3_CMD, const char *format);
* Implementation of 'rename workspace <name> to <name>' * Implementation of 'rename workspace <name> to <name>'
* *
*/ */
void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name); SCM guile_rename_workspace(SCM old_name, SCM new_name);
/** /**
* Implementation of 'bar mode dock|hide|invisible|toggle [<bar_id>]' * Implementation of 'bar mode dock|hide|invisible|toggle [<bar_id>]'

View File

@ -296,10 +296,44 @@ static void move_matches_to_workspace(Con *ws) {
* next|prev|next_on_output|prev_on_output|current'. * next|prev|next_on_output|prev_on_output|current'.
* *
*/ */
void cmd_move_con_to_workspace(I3_CMD, const char *which) { // FIXME: NOT WORKING
SCM guile_move_con_to_workspace(SCM g_which) {
const char * which = scm_to_locale_string(g_which);
DLOG("which=%s\n", which); DLOG("which=%s\n", which);
CHECK_MOVE_CON_TO_WORKSPACE; while (!TAILQ_EMPTY(&owindows)) {
owindow *ow = TAILQ_FIRST(&owindows);
TAILQ_REMOVE(&owindows, ow, owindows);
free(ow);
}
owindow *ow = smalloc(sizeof(owindow));
ow->con = focused;
TAILQ_INIT(&owindows);
TAILQ_INSERT_TAIL(&owindows, ow, owindows);
if (TAILQ_EMPTY(&owindows)) {
/* yerror("Nothing to move: specified criteria don't match any window"); */
return SCM_BOOL_F;
}
bool found = false;
owindow *current = TAILQ_FIRST(&owindows);
while (current) {
owindow *next = TAILQ_NEXT(current, owindows);
if (current->con->type == CT_WORKSPACE && !con_has_children(current->con)) {
TAILQ_REMOVE(&owindows, current, owindows);
} else {
found = true;
}
current = next;
}
if (!found) {
/* yerror("Nothing to move: workspace empty"); */
return SCM_BOOL_F;
}
/* get the workspace */ /* get the workspace */
Con *ws; Con *ws;
@ -314,15 +348,14 @@ void cmd_move_con_to_workspace(I3_CMD, const char *which) {
else if (strcmp(which, "current") == 0) else if (strcmp(which, "current") == 0)
ws = con_get_workspace(focused); ws = con_get_workspace(focused);
else { else {
yerror("BUG: called with which=%s", which); /* yerror("BUG: called with which=%s", which); */
return; return SCM_BOOL_F;
} }
move_matches_to_workspace(ws); move_matches_to_workspace(ws);
cmd_output->needs_tree_render = true; tree_render();
// XXX: default reply for now, make this a better reply return SCM_BOOL_T;
ysuccess(true);
} }
/* /*
@ -1381,113 +1414,6 @@ void cmd_sticky(I3_CMD, const char *action) {
ysuccess(true); ysuccess(true);
} }
/*
* Implementation of 'move <direction> [<pixels> [px]]'.
*
*/
void cmd_move_direction(I3_CMD, const char *direction_str, long move_px) {
owindow *current;
HANDLE_EMPTY_MATCH;
Con *initially_focused = focused;
direction_t direction = parse_direction(direction_str);
TAILQ_FOREACH (current, &owindows, owindows) {
DLOG("moving in direction %s, px %ld\n", direction_str, move_px);
if (con_is_floating(current->con)) {
DLOG("floating move with %ld pixels\n", move_px);
Rect newrect = current->con->parent->rect;
switch (direction) {
case D_LEFT:
newrect.x -= move_px;
break;
case D_RIGHT:
newrect.x += move_px;
break;
case D_UP:
newrect.y -= move_px;
break;
case D_DOWN:
newrect.y += move_px;
break;
}
cmd_output->needs_tree_render = floating_reposition(current->con->parent, newrect);
} else {
tree_move(current->con, direction);
cmd_output->needs_tree_render = true;
}
}
/* The move command should not disturb focus. con_exists is called because
* tree_move calls tree_flatten. */
if (focused != initially_focused && con_exists(initially_focused)) {
con_activate(initially_focused);
}
// XXX: default reply for now, make this a better reply
ysuccess(true);
}
/*
* Implementation of 'layout default|stacked|stacking|tabbed|splitv|splith'.
*
*/
void cmd_layout(I3_CMD, const char *layout_str) {
HANDLE_EMPTY_MATCH;
layout_t layout;
if (!layout_from_name(layout_str, &layout)) {
yerror("Unknown layout \"%s\", this is a mismatch between code and parser spec.", layout_str);
return;
}
DLOG("changing layout to %s (%d)\n", layout_str, layout);
owindow *current;
TAILQ_FOREACH (current, &owindows, owindows) {
if (con_is_docked(current->con)) {
ELOG("cannot change layout of a docked container, skipping it.\n");
continue;
}
DLOG("matching: %p / %s\n", current->con, current->con->name);
con_set_layout(current->con, layout);
}
cmd_output->needs_tree_render = true;
// XXX: default reply for now, make this a better reply
ysuccess(true);
}
/*
* Implementation of 'layout toggle [all|split]'.
*
*/
void cmd_layout_toggle(I3_CMD, const char *toggle_mode) {
owindow *current;
if (toggle_mode == NULL)
toggle_mode = "default";
DLOG("toggling layout (mode = %s)\n", toggle_mode);
/* check if the match is empty, not if the result is empty */
if (match_is_empty(current_match))
con_toggle_layout(focused, toggle_mode);
else {
TAILQ_FOREACH (current, &owindows, owindows) {
DLOG("matching: %p / %s\n", current->con, current->con->name);
con_toggle_layout(current->con, toggle_mode);
}
}
cmd_output->needs_tree_render = true;
// XXX: default reply for now, make this a better reply
ysuccess(true);
}
/* /*
* Implementation of 'exit'. * Implementation of 'exit'.
* *
@ -1858,11 +1784,15 @@ void cmd_title_format(I3_CMD, const char *format) {
* Implementation of 'rename workspace [<name>] to <name>' * Implementation of 'rename workspace [<name>] to <name>'
* *
*/ */
void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) { SCM guile_rename_workspace(SCM g_old_name, SCM g_new_name) {
char * old_name = scm_to_locale_string(g_old_name);
char * new_name = scm_to_locale_string(g_new_name);
if (strncasecmp(new_name, "__", strlen("__")) == 0) { if (strncasecmp(new_name, "__", strlen("__")) == 0) {
yerror("Cannot rename workspace to \"%s\": names starting with __ are i3-internal.", new_name); /* yerror("Cannot rename workspace to \"%s\": names starting with __ are i3-internal.", new_name); */
return; return SCM_BOOL_F;
} }
// FIXME
if (old_name) { if (old_name) {
LOG("Renaming workspace \"%s\" to \"%s\"\n", old_name, new_name); LOG("Renaming workspace \"%s\" to \"%s\"\n", old_name, new_name);
} else { } else {
@ -1878,8 +1808,8 @@ void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) {
} }
if (!workspace) { if (!workspace) {
yerror("Old workspace \"%s\" not found", old_name); /* yerror("Old workspace \"%s\" not found", old_name); */
return; return SCM_BOOL_F;
} }
Con *check_dest = get_existing_workspace_by_name(new_name); Con *check_dest = get_existing_workspace_by_name(new_name);
@ -1887,8 +1817,8 @@ void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) {
/* If check_dest == workspace, the user might be changing the case of the /* If check_dest == workspace, the user might be changing the case of the
* workspace, or it might just be a no-op. */ * workspace, or it might just be a no-op. */
if (check_dest != NULL && check_dest != workspace) { if (check_dest != NULL && check_dest != workspace) {
yerror("New workspace \"%s\" already exists", new_name); /* yerror("New workspace \"%s\" already exists", new_name); */
return; return SCM_BOOL_F;
} }
/* Change the name and try to parse it as a number. */ /* Change the name and try to parse it as a number. */
@ -1955,13 +1885,13 @@ void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) {
previous_workspace_name = sstrdup(new_name); previous_workspace_name = sstrdup(new_name);
} }
cmd_output->needs_tree_render = true; tree_render();
ysuccess(true);
ewmh_update_desktop_properties(); ewmh_update_desktop_properties();
startup_sequence_rename_workspace(old_name_copy, new_name); startup_sequence_rename_workspace(old_name_copy, new_name);
free(old_name_copy); free(old_name_copy);
return SCM_BOOL_T;
} }
/* /*
@ -2221,13 +2151,27 @@ SCM guile_focus_direction(SCM g_direction) {
char * direction_str = scm_to_locale_string(g_direction); char * direction_str = scm_to_locale_string(g_direction);
Con * con; Con * con;
owindow * ow; owindow * ow;
int count = 0;
owindow *current;
/* if (current_match->error != NULL) { */
/* /\* yerror("Invalid match: %s", current_match->error); *\/ */
/* return SCM_BOOL_F; */
/* } */
/* if (match_is_empty(current_match)) { */
while (!TAILQ_EMPTY(&owindows)) { while (!TAILQ_EMPTY(&owindows)) {
ow = TAILQ_FIRST(&owindows); ow = TAILQ_FIRST(&owindows);
TAILQ_REMOVE(&owindows, ow, owindows); TAILQ_REMOVE(&owindows, ow, owindows);
free(ow); free(ow);
} }
int count = 0; ow = smalloc(sizeof(owindow));
owindow *current; ow->con = focused;
TAILQ_INIT(&owindows);
TAILQ_INSERT_TAIL(&owindows, ow, owindows);
/* } */
TAILQ_FOREACH (current, &owindows, owindows) { TAILQ_FOREACH (current, &owindows, owindows) {
count++; count++;
} }
@ -2236,7 +2180,6 @@ SCM guile_focus_direction(SCM g_direction) {
"while only exactly one container can be focused at a time.\n", "while only exactly one container can be focused at a time.\n",
count); count);
} }
direction_t direction; direction_t direction;
position_t position; position_t position;
bool auto_direction = true; bool auto_direction = true;
@ -2264,3 +2207,112 @@ SCM guile_focus_direction(SCM g_direction) {
tree_render(); tree_render();
return SCM_BOOL_T; return SCM_BOOL_T;
} }
/*
* Implementation of 'move <direction> [<pixels> [px]]'.
*
*/
void cmd_move_direction(I3_CMD, const char *direction_str, long move_px) {
owindow *current;
HANDLE_EMPTY_MATCH;
Con *initially_focused = focused;
direction_t direction = parse_direction(direction_str);
TAILQ_FOREACH (current, &owindows, owindows) {
DLOG("moving in direction %s, px %ld\n", direction_str, move_px);
if (con_is_floating(current->con)) {
DLOG("floating move with %ld pixels\n", move_px);
Rect newrect = current->con->parent->rect;
switch (direction) {
case D_LEFT:
newrect.x -= move_px;
break;
case D_RIGHT:
newrect.x += move_px;
break;
case D_UP:
newrect.y -= move_px;
break;
case D_DOWN:
newrect.y += move_px;
break;
}
cmd_output->needs_tree_render = floating_reposition(current->con->parent, newrect);
} else {
tree_move(current->con, direction);
cmd_output->needs_tree_render = true;
}
}
/* The move command should not disturb focus. con_exists is called because
* tree_move calls tree_flatten. */
if (focused != initially_focused && con_exists(initially_focused)) {
con_activate(initially_focused);
}
// XXX: default reply for now, make this a better reply
ysuccess(true);
}
/*
* Implementation of 'layout default|stacked|stacking|tabbed|splitv|splith'.
*
*/
SCM guile_layout(SCM g_layout) {
owindow *ow;
while (!TAILQ_EMPTY(&owindows)) {
ow = TAILQ_FIRST(&owindows);
TAILQ_REMOVE(&owindows, ow, owindows);
free(ow);
}
ow = smalloc(sizeof(owindow));
ow->con = focused;
TAILQ_INIT(&owindows);
TAILQ_INSERT_TAIL(&owindows, ow, owindows);
char * layout_str = scm_to_locale_string(g_layout);
layout_t layout;
if (!layout_from_name(layout_str, &layout)) {
/* yerror("Unknown layout \"%s\", this is a mismatch between code and parser spec.", layout_str); */
return SCM_BOOL_F;
}
DLOG("changing layout to %s (%d)\n", layout_str, layout);
owindow *current;
TAILQ_FOREACH (current, &owindows, owindows) {
if (con_is_docked(current->con)) {
ELOG("cannot change layout of a docked container, skipping it.\n");
continue;
}
DLOG("matching: %p / %s\n", current->con, current->con->name);
con_set_layout(current->con, layout);
}
tree_render();
return SCM_BOOL_T;
}
/*
* Implementation of 'layout toggle [all|split]'.
*
*/
SCM guile_layout_toggle(SCM g_toggle_mode) {
owindow *current;
char * toggle_mode = scm_to_locale_string(g_toggle_mode);
DLOG("toggling layout (mode = %s)\n", toggle_mode);
/* check if the match is empty, not if the result is empty */
con_toggle_layout(focused, toggle_mode);
tree_render();
return SCM_BOOL_T;
}

View File

@ -337,6 +337,11 @@ register_functions (void* data) {
scm_c_define_gsubr ("kill", 0, 0, 0, &guile_kill); scm_c_define_gsubr ("kill", 0, 0, 0, &guile_kill);
scm_c_define_gsubr ("split", 1, 0, 0, &guile_split); scm_c_define_gsubr ("split", 1, 0, 0, &guile_split);
scm_c_define_gsubr ("focus-direction", 1, 0, 0, &guile_focus_direction); scm_c_define_gsubr ("focus-direction", 1, 0, 0, &guile_focus_direction);
scm_c_define_gsubr ("layout", 1, 0, 0, &guile_layout);
scm_c_define_gsubr ("toggle-layout", 1, 0, 0, &guile_layout_toggle);
scm_c_define_gsubr ("move-to-workspace", 1, 0, 0, &guile_move_con_to_workspace);
scm_c_define_gsubr ("rename-workspace", 2, 0, 0, &guile_rename_workspace);
return NULL; return NULL;
} }