implement con_id for matching containers, extend testcase
This commit is contained in:
parent
caa1e9a962
commit
93600ce0fd
|
@ -239,6 +239,7 @@ struct Match {
|
||||||
char *class;
|
char *class;
|
||||||
char *instance;
|
char *instance;
|
||||||
xcb_window_t id;
|
xcb_window_t id;
|
||||||
|
Con *con_id;
|
||||||
bool floating;
|
bool floating;
|
||||||
|
|
||||||
enum { M_GLOBAL, M_OUTPUT, M_WORKSPACE } levels;
|
enum { M_GLOBAL, M_OUTPUT, M_WORKSPACE } levels;
|
||||||
|
|
|
@ -95,11 +95,14 @@ none { return TOK_NONE; }
|
||||||
mode { return TOK_MODE; }
|
mode { return TOK_MODE; }
|
||||||
tiling { return TOK_TILING; }
|
tiling { return TOK_TILING; }
|
||||||
floating { return TOK_FLOATING; }
|
floating { return TOK_FLOATING; }
|
||||||
workspace { return TOK_WORKSPACE; }
|
workspace { BEGIN(WANT_WS_STRING); return TOK_WORKSPACE; }
|
||||||
focus { return TOK_FOCUS; }
|
focus { return TOK_FOCUS; }
|
||||||
move { return TOK_MOVE; }
|
move { return TOK_MOVE; }
|
||||||
|
open { return TOK_OPEN; }
|
||||||
|
|
||||||
class { BEGIN(WANT_QSTRING); return TOK_CLASS; }
|
class { BEGIN(WANT_QSTRING); return TOK_CLASS; }
|
||||||
|
id { BEGIN(WANT_QSTRING); return TOK_ID; }
|
||||||
|
con_id { BEGIN(WANT_QSTRING); return TOK_CON_ID; }
|
||||||
|
|
||||||
. { return (int)yytext[0]; }
|
. { return (int)yytext[0]; }
|
||||||
|
|
||||||
|
|
|
@ -109,8 +109,11 @@ void parse_cmd(const char *new) {
|
||||||
%token TOK_WORKSPACE "workspace"
|
%token TOK_WORKSPACE "workspace"
|
||||||
%token TOK_FOCUS "focus"
|
%token TOK_FOCUS "focus"
|
||||||
%token TOK_MOVE "move"
|
%token TOK_MOVE "move"
|
||||||
|
%token TOK_OPEN "open"
|
||||||
|
|
||||||
%token TOK_CLASS "class"
|
%token TOK_CLASS "class"
|
||||||
|
%token TOK_ID "id"
|
||||||
|
%token TOK_CON_ID "con_id"
|
||||||
|
|
||||||
%token WHITESPACE "<whitespace>"
|
%token WHITESPACE "<whitespace>"
|
||||||
%token STR "<string>"
|
%token STR "<string>"
|
||||||
|
@ -156,9 +159,6 @@ matchstart:
|
||||||
/* copy all_cons */
|
/* copy all_cons */
|
||||||
Con *con;
|
Con *con;
|
||||||
TAILQ_FOREACH(con, &all_cons, all_cons) {
|
TAILQ_FOREACH(con, &all_cons, all_cons) {
|
||||||
if (con->window == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
owindow *ow = smalloc(sizeof(owindow));
|
owindow *ow = smalloc(sizeof(owindow));
|
||||||
ow->con = con;
|
ow->con = con;
|
||||||
TAILQ_INSERT_TAIL(&owindows, ow, owindows);
|
TAILQ_INSERT_TAIL(&owindows, ow, owindows);
|
||||||
|
@ -184,12 +184,22 @@ matchend:
|
||||||
next = TAILQ_NEXT(next, owindows);
|
next = TAILQ_NEXT(next, owindows);
|
||||||
|
|
||||||
printf("checking if con %p / %s matches\n", current->con, current->con->name);
|
printf("checking if con %p / %s matches\n", current->con, current->con->name);
|
||||||
if (match_matches_window(¤t_match, current->con->window)) {
|
if (current_match.con_id != NULL) {
|
||||||
printf("matches!\n");
|
if (current_match.con_id == current->con) {
|
||||||
TAILQ_INSERT_TAIL(&owindows, current, owindows);
|
printf("matches container!\n");
|
||||||
|
TAILQ_INSERT_TAIL(&owindows, current, owindows);
|
||||||
|
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("doesnt match\n");
|
if (current->con->window == NULL)
|
||||||
free(current);
|
continue;
|
||||||
|
if (match_matches_window(¤t_match, current->con->window)) {
|
||||||
|
printf("matches window!\n");
|
||||||
|
TAILQ_INSERT_TAIL(&owindows, current, owindows);
|
||||||
|
} else {
|
||||||
|
printf("doesnt match\n");
|
||||||
|
free(current);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,6 +216,13 @@ criteria:
|
||||||
printf("criteria: class = %s\n", $<string>3);
|
printf("criteria: class = %s\n", $<string>3);
|
||||||
current_match.class = $<string>3;
|
current_match.class = $<string>3;
|
||||||
}
|
}
|
||||||
|
| TOK_CON_ID '=' STR
|
||||||
|
{
|
||||||
|
printf("criteria: id = %s\n", $<string>3);
|
||||||
|
/* TODO: correctly parse number */
|
||||||
|
current_match.con_id = atoi($<string>3);
|
||||||
|
printf("id as int = %d\n", current_match.con_id);
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
operations:
|
operations:
|
||||||
|
@ -226,9 +243,11 @@ operation:
|
||||||
| mode
|
| mode
|
||||||
| workspace
|
| workspace
|
||||||
| move*/
|
| move*/
|
||||||
|
| workspace
|
||||||
| attach
|
| attach
|
||||||
| focus
|
| focus
|
||||||
| kill
|
| kill
|
||||||
|
| open
|
||||||
;
|
;
|
||||||
|
|
||||||
exec:
|
exec:
|
||||||
|
@ -265,10 +284,32 @@ kill:
|
||||||
owindow *current;
|
owindow *current;
|
||||||
|
|
||||||
printf("killing!\n");
|
printf("killing!\n");
|
||||||
|
/* TODO: check if the match is empty, not if the result is empty */
|
||||||
|
if (TAILQ_EMPTY(&owindows))
|
||||||
|
tree_close(focused);
|
||||||
|
else {
|
||||||
TAILQ_FOREACH(current, &owindows, owindows) {
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
||||||
printf("matching: %p / %s\n", current->con, current->con->name);
|
printf("matching: %p / %s\n", current->con, current->con->name);
|
||||||
tree_close(current->con);
|
tree_close(current->con);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
workspace:
|
||||||
|
TOK_WORKSPACE WHITESPACE STR
|
||||||
|
{
|
||||||
|
printf("should switch to workspace %s\n", $<string>3);
|
||||||
|
workspace_show($<string>3);
|
||||||
|
free($<string>3);
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
open:
|
||||||
|
TOK_OPEN
|
||||||
|
{
|
||||||
|
printf("opening new container\n");
|
||||||
|
tree_open_con(NULL);
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
|
@ -114,7 +114,7 @@ IPC_HANDLER(command) {
|
||||||
* message_size bytes out of the buffer */
|
* message_size bytes out of the buffer */
|
||||||
char *command = scalloc(message_size);
|
char *command = scalloc(message_size);
|
||||||
strncpy(command, (const char*)message, message_size);
|
strncpy(command, (const char*)message, message_size);
|
||||||
parse_command((const char*)command);
|
parse_cmd((const char*)command);
|
||||||
free(command);
|
free(command);
|
||||||
|
|
||||||
/* For now, every command gets a positive acknowledge
|
/* For now, every command gets a positive acknowledge
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
#
|
#
|
||||||
# Tests whether opening an empty container and killing it again works
|
# Tests whether opening an empty container and killing it again works
|
||||||
#
|
#
|
||||||
use Test::More tests => 3;
|
use Test::More tests => 6;
|
||||||
|
use Data::Dumper;
|
||||||
use FindBin;
|
use FindBin;
|
||||||
use lib "$FindBin::Bin/lib";
|
use lib "$FindBin::Bin/lib";
|
||||||
use i3test;
|
use i3test;
|
||||||
|
@ -25,4 +26,25 @@ ok(@{get_ws_content($tmp)} == 1, 'container opened');
|
||||||
$i3->command("kill")->recv;
|
$i3->command("kill")->recv;
|
||||||
ok(@{get_ws_content($tmp)} == 0, 'container killed');
|
ok(@{get_ws_content($tmp)} == 0, 'container killed');
|
||||||
|
|
||||||
|
##############################################################
|
||||||
|
# open two containers and kill the one which is not focused
|
||||||
|
# by its ID to test if the parser correctly matches the window
|
||||||
|
##############################################################
|
||||||
|
|
||||||
|
$i3->command('open')->recv;
|
||||||
|
$i3->command('open')->recv;
|
||||||
|
ok(@{get_ws_content($tmp)} == 2, 'two containers opened');
|
||||||
|
|
||||||
|
my $content = get_ws_content($tmp);
|
||||||
|
# TODO: get the focused window, don’t assume that it is
|
||||||
|
# the latest one
|
||||||
|
my $id = $content->[0]->{id};
|
||||||
|
diag('id of not focused = ' . $id);
|
||||||
|
|
||||||
|
$i3->command("[con_id=\"$id\"] kill")->recv;
|
||||||
|
|
||||||
|
$content = get_ws_content($tmp);
|
||||||
|
ok(@{$content} == 1, 'one container killed');
|
||||||
|
ok($content->[0]->{id} != $id, 'correct window killed');
|
||||||
|
|
||||||
diag( "Testing i3, Perl $], $^X" );
|
diag( "Testing i3, Perl $], $^X" );
|
||||||
|
|
Loading…
Reference in New Issue