Implement mark/goto, modify testcase

This commit is contained in:
Michael Stapelberg
2010-06-02 23:32:05 +02:00
parent 780e773a6a
commit 6897e15e72
6 changed files with 57 additions and 19 deletions

View File

@ -112,10 +112,12 @@ down { return TOK_DOWN; }
before { return TOK_BEFORE; }
after { return TOK_AFTER; }
restore { BEGIN(WANT_WS_STRING); return TOK_RESTORE; }
mark { BEGIN(WANT_WS_STRING); return TOK_MARK; }
class { BEGIN(WANT_QSTRING); return TOK_CLASS; }
id { BEGIN(WANT_QSTRING); return TOK_ID; }
con_id { BEGIN(WANT_QSTRING); return TOK_CON_ID; }
con_mark { BEGIN(WANT_QSTRING); return TOK_MARK; }
. { return (int)yytext[0]; }

View File

@ -124,6 +124,7 @@ void parse_cmd(const char *new) {
%token TOK_AFTER "after"
%token TOK_BEFORE "before"
%token TOK_RESTORE "restore"
%token TOK_MARK "mark"
%token TOK_CLASS "class"
%token TOK_ID "id"
@ -205,6 +206,11 @@ matchend:
TAILQ_INSERT_TAIL(&owindows, current, owindows);
}
} else if (current_match.mark != NULL && current->con->mark != NULL &&
strcasecmp(current_match.mark, current->con->mark) == 0) {
printf("match by mark\n");
TAILQ_INSERT_TAIL(&owindows, current, owindows);
} else {
if (current->con->window == NULL)
continue;
@ -245,6 +251,11 @@ criteria:
current_match.id = atoi($<string>3);
printf("window id as int = %d\n", current_match.id);
}
| TOK_MARK '=' STR
{
printf("criteria: mark = %s\n", $<string>3);
current_match.mark = $<string>3;
}
;
operations:
@ -274,6 +285,7 @@ operation:
| split
| mode
| level
| mark
;
exec:
@ -498,3 +510,23 @@ layout_mode:
| TOK_STACKED { $<number>$ = L_STACKED; }
| TOK_TABBED { $<number>$ = L_TABBED; }
;
mark:
TOK_MARK WHITESPACE STR
{
printf("marking window with str %s\n", $<string>3);
owindow *current;
/* check if the match is empty, not if the result is empty */
if (match_is_empty(&current_match))
focused->mark = sstrdup($<string>3);
else {
TAILQ_FOREACH(current, &owindows, owindows) {
printf("matching: %p / %s\n", current->con, current->con->name);
current->con->mark = sstrdup($<string>3);
}
}
free($<string>3);
}
;

View File

@ -13,6 +13,7 @@ bool match_is_empty(Match *match) {
* TAILQ and I dont want to start with things like assuming that the
* last member of a struct really is at the end in memory… */
return (match->title == NULL &&
match->mark == NULL &&
match->application == NULL &&
match->class == NULL &&
match->instance == NULL &&
@ -33,7 +34,6 @@ bool match_matches_window(Match *match, i3Window *window) {
return true;
}
if (match->id != XCB_NONE && window->id == match->id) {
LOG("match made by window id (%d)\n", window->id);
return true;

View File

@ -201,6 +201,7 @@ void tree_close_con() {
void tree_split(Con *con, orientation_t orientation) {
/* for a workspace, we just need to change orientation */
if (con->type == CT_WORKSPACE) {
DLOG("Workspace, simply changing orientation to %d\n", orientation);
con->orientation = orientation;
return;
}
@ -210,8 +211,12 @@ void tree_split(Con *con, orientation_t orientation) {
* child and has the same orientation like we are trying to
* set, this operation is a no-op to not confuse the user */
if (parent->orientation == orientation &&
TAILQ_NEXT(con, nodes) == TAILQ_END(&(parent->nodes_head)))
TAILQ_NEXT(con, nodes) == TAILQ_END(&(parent->nodes_head))) {
DLOG("Not splitting the same way again\n");
return;
}
DLOG("Splitting in orientation %d\n", orientation);
/* 2: replace it with a new Con */
Con *new = con_new(NULL);