2010-04-14 20:26:56 +02:00
|
|
|
|
%{
|
|
|
|
|
/*
|
|
|
|
|
* vim:ts=4:sw=4:expandtab
|
|
|
|
|
*
|
|
|
|
|
* i3 - an improved dynamic tiling window manager
|
2011-05-15 20:10:25 +02:00
|
|
|
|
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
|
2010-04-14 20:26:56 +02:00
|
|
|
|
*
|
|
|
|
|
* cmdparse.y: the parser for commands you send to i3 (or bind on keys)
|
|
|
|
|
*
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <fcntl.h>
|
2011-08-02 22:31:45 +02:00
|
|
|
|
#include <float.h>
|
2010-04-14 20:26:56 +02:00
|
|
|
|
|
|
|
|
|
#include "all.h"
|
|
|
|
|
|
2011-05-15 19:43:35 +02:00
|
|
|
|
/** When the command did not include match criteria (!), we use the currently
|
|
|
|
|
* focused command. Do not confuse this case with a command which included
|
|
|
|
|
* criteria but which did not match any windows. This macro has to be called in
|
|
|
|
|
* every command.
|
|
|
|
|
*/
|
|
|
|
|
#define HANDLE_EMPTY_MATCH do { \
|
|
|
|
|
if (match_is_empty(¤t_match)) { \
|
|
|
|
|
owindow *ow = smalloc(sizeof(owindow)); \
|
|
|
|
|
ow->con = focused; \
|
|
|
|
|
TAILQ_INIT(&owindows); \
|
|
|
|
|
TAILQ_INSERT_TAIL(&owindows, ow, owindows); \
|
|
|
|
|
} \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
2010-04-14 20:26:56 +02:00
|
|
|
|
typedef struct yy_buffer_state *YY_BUFFER_STATE;
|
|
|
|
|
extern int cmdyylex(struct context *context);
|
|
|
|
|
extern int cmdyyparse(void);
|
2011-07-31 17:11:28 +02:00
|
|
|
|
extern int cmdyylex_destroy(void);
|
2010-04-14 20:26:56 +02:00
|
|
|
|
extern FILE *cmdyyin;
|
|
|
|
|
YY_BUFFER_STATE cmdyy_scan_string(const char *);
|
|
|
|
|
|
|
|
|
|
static struct context *context;
|
|
|
|
|
static Match current_match;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Helper data structure for an operation window (window on which the operation
|
|
|
|
|
* will be performed). Used to build the TAILQ owindows.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
typedef struct owindow {
|
|
|
|
|
Con *con;
|
|
|
|
|
TAILQ_ENTRY(owindow) owindows;
|
|
|
|
|
} owindow;
|
|
|
|
|
static TAILQ_HEAD(owindows_head, owindow) owindows;
|
|
|
|
|
|
2010-07-17 15:15:37 +02:00
|
|
|
|
/* Holds the JSON which will be returned via IPC or NULL for the default return
|
|
|
|
|
* message */
|
|
|
|
|
static char *json_output;
|
|
|
|
|
|
2010-04-14 20:26:56 +02:00
|
|
|
|
/* We don’t need yydebug for now, as we got decent error messages using
|
|
|
|
|
* yyerror(). Should you ever want to extend the parser, it might be handy
|
|
|
|
|
* to just comment it in again, so it stays here. */
|
|
|
|
|
//int cmdyydebug = 1;
|
|
|
|
|
|
|
|
|
|
void cmdyyerror(const char *error_message) {
|
|
|
|
|
ELOG("\n");
|
|
|
|
|
ELOG("CMD: %s\n", error_message);
|
2010-11-12 20:22:55 +01:00
|
|
|
|
ELOG("CMD: in command:\n");
|
2010-04-14 20:26:56 +02:00
|
|
|
|
ELOG("CMD: %s\n", context->line_copy);
|
|
|
|
|
ELOG("CMD: ");
|
|
|
|
|
for (int c = 1; c <= context->last_column; c++)
|
|
|
|
|
if (c >= context->first_column)
|
|
|
|
|
printf("^");
|
|
|
|
|
else printf(" ");
|
|
|
|
|
printf("\n");
|
|
|
|
|
ELOG("\n");
|
2010-11-14 01:45:05 +01:00
|
|
|
|
context->compact_error = sstrdup(error_message);
|
2010-04-14 20:26:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int cmdyywrap() {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-17 15:15:37 +02:00
|
|
|
|
char *parse_cmd(const char *new) {
|
2011-08-09 08:41:42 +02:00
|
|
|
|
json_output = NULL;
|
2011-05-15 20:10:25 +02:00
|
|
|
|
LOG("COMMAND: *%s*\n", new);
|
2010-04-14 20:26:56 +02:00
|
|
|
|
cmdyy_scan_string(new);
|
|
|
|
|
|
2010-11-12 19:07:35 +01:00
|
|
|
|
match_init(¤t_match);
|
2010-04-14 20:26:56 +02:00
|
|
|
|
context = scalloc(sizeof(struct context));
|
|
|
|
|
context->filename = "cmd";
|
|
|
|
|
if (cmdyyparse() != 0) {
|
2010-11-12 20:22:55 +01:00
|
|
|
|
fprintf(stderr, "Could not parse command\n");
|
2010-11-14 01:45:05 +01:00
|
|
|
|
asprintf(&json_output, "{\"success\":false, \"error\":\"%s at position %d\"}",
|
|
|
|
|
context->compact_error, context->first_column);
|
2010-11-12 20:22:55 +01:00
|
|
|
|
FREE(context->line_copy);
|
2010-11-14 01:45:05 +01:00
|
|
|
|
FREE(context->compact_error);
|
2010-11-12 20:22:55 +01:00
|
|
|
|
free(context);
|
2010-11-14 01:45:05 +01:00
|
|
|
|
return json_output;
|
2010-04-14 20:26:56 +02:00
|
|
|
|
}
|
2010-07-17 15:15:37 +02:00
|
|
|
|
printf("done, json output = %s\n", json_output);
|
2010-04-14 20:26:56 +02:00
|
|
|
|
|
2011-07-31 17:11:28 +02:00
|
|
|
|
cmdyylex_destroy();
|
2010-04-14 20:26:56 +02:00
|
|
|
|
FREE(context->line_copy);
|
2010-11-14 01:45:05 +01:00
|
|
|
|
FREE(context->compact_error);
|
2010-04-14 20:26:56 +02:00
|
|
|
|
free(context);
|
2010-07-17 15:15:37 +02:00
|
|
|
|
return json_output;
|
2010-04-14 20:26:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-02 22:31:45 +02:00
|
|
|
|
/*
|
|
|
|
|
* Returns true if a is definitely greater than b (using the given epsilon)
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
bool definitelyGreaterThan(float a, float b, float epsilon) {
|
|
|
|
|
return (a - b) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-14 20:26:56 +02:00
|
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
%error-verbose
|
|
|
|
|
%lex-param { struct context *context }
|
|
|
|
|
|
|
|
|
|
%union {
|
|
|
|
|
char *string;
|
2010-05-10 00:06:24 +02:00
|
|
|
|
char chr;
|
2010-05-10 10:12:35 +02:00
|
|
|
|
int number;
|
2010-04-14 20:26:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-05 20:39:05 +02:00
|
|
|
|
%token TOK_EXEC "exec"
|
|
|
|
|
%token TOK_EXIT "exit"
|
|
|
|
|
%token TOK_RELOAD "reload"
|
|
|
|
|
%token TOK_RESTART "restart"
|
|
|
|
|
%token TOK_KILL "kill"
|
2011-05-13 20:41:03 +02:00
|
|
|
|
%token TOK_WINDOW "window"
|
|
|
|
|
%token TOK_CLIENT "client"
|
2011-05-05 20:39:05 +02:00
|
|
|
|
%token TOK_FULLSCREEN "fullscreen"
|
|
|
|
|
%token TOK_GLOBAL "global"
|
|
|
|
|
%token TOK_LAYOUT "layout"
|
|
|
|
|
%token TOK_DEFAULT "default"
|
|
|
|
|
%token TOK_STACKED "stacked"
|
|
|
|
|
%token TOK_TABBED "tabbed"
|
|
|
|
|
%token TOK_BORDER "border"
|
|
|
|
|
%token TOK_NORMAL "normal"
|
|
|
|
|
%token TOK_NONE "none"
|
|
|
|
|
%token TOK_1PIXEL "1pixel"
|
|
|
|
|
%token TOK_MODE "mode"
|
|
|
|
|
%token TOK_TILING "tiling"
|
|
|
|
|
%token TOK_FLOATING "floating"
|
2011-07-04 17:09:52 +02:00
|
|
|
|
%token TOK_MODE_TOGGLE "mode_toggle"
|
2011-06-10 02:06:47 +02:00
|
|
|
|
%token TOK_ENABLE "enable"
|
|
|
|
|
%token TOK_DISABLE "disable"
|
2011-05-05 20:39:05 +02:00
|
|
|
|
%token TOK_WORKSPACE "workspace"
|
|
|
|
|
%token TOK_TOGGLE "toggle"
|
|
|
|
|
%token TOK_FOCUS "focus"
|
|
|
|
|
%token TOK_MOVE "move"
|
|
|
|
|
%token TOK_OPEN "open"
|
2011-06-10 16:03:59 +02:00
|
|
|
|
%token TOK_NEXT "next"
|
2011-05-05 20:39:05 +02:00
|
|
|
|
%token TOK_PREV "prev"
|
|
|
|
|
%token TOK_SPLIT "split"
|
|
|
|
|
%token TOK_HORIZONTAL "horizontal"
|
|
|
|
|
%token TOK_VERTICAL "vertical"
|
|
|
|
|
%token TOK_UP "up"
|
|
|
|
|
%token TOK_DOWN "down"
|
|
|
|
|
%token TOK_LEFT "left"
|
|
|
|
|
%token TOK_RIGHT "right"
|
2011-06-10 01:36:33 +02:00
|
|
|
|
%token TOK_PARENT "parent"
|
|
|
|
|
%token TOK_CHILD "child"
|
2011-06-10 02:15:31 +02:00
|
|
|
|
%token TOK_APPEND_LAYOUT "append_layout"
|
2011-05-05 20:39:05 +02:00
|
|
|
|
%token TOK_MARK "mark"
|
|
|
|
|
%token TOK_RESIZE "resize"
|
|
|
|
|
%token TOK_GROW "grow"
|
|
|
|
|
%token TOK_SHRINK "shrink"
|
|
|
|
|
%token TOK_PX "px"
|
|
|
|
|
%token TOK_OR "or"
|
|
|
|
|
%token TOK_PPT "ppt"
|
|
|
|
|
%token TOK_NOP "nop"
|
|
|
|
|
|
|
|
|
|
%token TOK_CLASS "class"
|
2011-08-04 17:12:54 +02:00
|
|
|
|
%token TOK_INSTANCE "instance"
|
2011-05-05 20:39:05 +02:00
|
|
|
|
%token TOK_ID "id"
|
|
|
|
|
%token TOK_CON_ID "con_id"
|
2011-06-08 23:34:08 +02:00
|
|
|
|
%token TOK_TITLE "title"
|
2011-05-05 20:39:05 +02:00
|
|
|
|
|
|
|
|
|
%token <string> STR "<string>"
|
|
|
|
|
%token <number> NUMBER "<number>"
|
|
|
|
|
|
|
|
|
|
%type <number> direction
|
2011-06-10 02:25:14 +02:00
|
|
|
|
%type <number> split_direction
|
2011-06-10 18:27:20 +02:00
|
|
|
|
%type <number> fullscreen_mode
|
2011-06-10 01:36:33 +02:00
|
|
|
|
%type <number> level
|
2011-07-04 17:09:52 +02:00
|
|
|
|
%type <number> window_mode
|
2011-06-10 02:06:47 +02:00
|
|
|
|
%type <number> boolean
|
2011-05-05 20:39:05 +02:00
|
|
|
|
%type <number> border_style
|
|
|
|
|
%type <number> layout_mode
|
|
|
|
|
%type <number> resize_px
|
|
|
|
|
%type <number> resize_way
|
|
|
|
|
%type <number> resize_tiling
|
2011-05-13 20:41:03 +02:00
|
|
|
|
%type <number> optional_kill_mode
|
2010-04-14 20:26:56 +02:00
|
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
2011-03-14 23:03:13 +01:00
|
|
|
|
commands:
|
2011-05-22 21:26:50 +02:00
|
|
|
|
commands ';' command
|
2010-04-14 20:26:56 +02:00
|
|
|
|
| command
|
|
|
|
|
{
|
|
|
|
|
owindow *current;
|
|
|
|
|
|
|
|
|
|
printf("single command completely parsed, dropping state...\n");
|
|
|
|
|
while (!TAILQ_EMPTY(&owindows)) {
|
|
|
|
|
current = TAILQ_FIRST(&owindows);
|
|
|
|
|
TAILQ_REMOVE(&owindows, current, owindows);
|
|
|
|
|
free(current);
|
|
|
|
|
}
|
2010-08-20 21:41:05 +02:00
|
|
|
|
match_init(¤t_match);
|
2010-04-14 20:26:56 +02:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
command:
|
2011-05-22 21:26:50 +02:00
|
|
|
|
match operations
|
2010-04-14 20:26:56 +02:00
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
match:
|
2011-05-22 21:26:50 +02:00
|
|
|
|
| matchstart criteria matchend
|
2010-04-14 20:26:56 +02:00
|
|
|
|
{
|
|
|
|
|
printf("match parsed\n");
|
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
matchstart:
|
|
|
|
|
'['
|
|
|
|
|
{
|
|
|
|
|
printf("start\n");
|
2010-08-20 21:41:05 +02:00
|
|
|
|
match_init(¤t_match);
|
2010-04-14 20:26:56 +02:00
|
|
|
|
TAILQ_INIT(&owindows);
|
|
|
|
|
/* copy all_cons */
|
|
|
|
|
Con *con;
|
|
|
|
|
TAILQ_FOREACH(con, &all_cons, all_cons) {
|
|
|
|
|
owindow *ow = smalloc(sizeof(owindow));
|
|
|
|
|
ow->con = con;
|
|
|
|
|
TAILQ_INSERT_TAIL(&owindows, ow, owindows);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
matchend:
|
|
|
|
|
']'
|
|
|
|
|
{
|
|
|
|
|
owindow *next, *current;
|
|
|
|
|
|
|
|
|
|
printf("match specification finished, matching...\n");
|
|
|
|
|
/* copy the old list head to iterate through it and start with a fresh
|
|
|
|
|
* list which will contain only matching windows */
|
|
|
|
|
struct owindows_head old = owindows;
|
|
|
|
|
TAILQ_INIT(&owindows);
|
|
|
|
|
for (next = TAILQ_FIRST(&old); next != TAILQ_END(&old);) {
|
|
|
|
|
/* make a copy of the next pointer and advance the pointer to the
|
|
|
|
|
* next element as we are going to invalidate the element’s
|
|
|
|
|
* next/prev pointers by calling TAILQ_INSERT_TAIL later */
|
|
|
|
|
current = next;
|
|
|
|
|
next = TAILQ_NEXT(next, owindows);
|
|
|
|
|
|
|
|
|
|
printf("checking if con %p / %s matches\n", current->con, current->con->name);
|
2010-04-16 15:30:07 +02:00
|
|
|
|
if (current_match.con_id != NULL) {
|
|
|
|
|
if (current_match.con_id == current->con) {
|
|
|
|
|
printf("matches container!\n");
|
|
|
|
|
TAILQ_INSERT_TAIL(&owindows, current, owindows);
|
|
|
|
|
|
|
|
|
|
}
|
2010-06-02 23:32:05 +02:00
|
|
|
|
} 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);
|
|
|
|
|
|
2010-04-14 20:26:56 +02:00
|
|
|
|
} else {
|
2010-04-16 15:30:07 +02:00
|
|
|
|
if (current->con->window == NULL)
|
|
|
|
|
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);
|
|
|
|
|
}
|
2010-04-14 20:26:56 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
printf("matching: %p / %s\n", current->con, current->con->name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
criteria:
|
2011-06-08 23:34:08 +02:00
|
|
|
|
criteria criterion
|
|
|
|
|
| criterion
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
criterion:
|
2010-04-14 20:26:56 +02:00
|
|
|
|
TOK_CLASS '=' STR
|
|
|
|
|
{
|
2011-05-05 20:39:05 +02:00
|
|
|
|
printf("criteria: class = %s\n", $3);
|
|
|
|
|
current_match.class = $3;
|
2010-04-14 20:26:56 +02:00
|
|
|
|
}
|
2011-08-04 17:12:54 +02:00
|
|
|
|
| TOK_INSTANCE '=' STR
|
|
|
|
|
{
|
|
|
|
|
printf("criteria: instance = %s\n", $3);
|
|
|
|
|
current_match.instance = $3;
|
|
|
|
|
}
|
2010-04-16 15:30:07 +02:00
|
|
|
|
| TOK_CON_ID '=' STR
|
|
|
|
|
{
|
2011-05-05 20:39:05 +02:00
|
|
|
|
printf("criteria: id = %s\n", $3);
|
2011-03-14 23:14:40 +01:00
|
|
|
|
char *end;
|
2011-05-05 20:39:05 +02:00
|
|
|
|
long parsed = strtol($3, &end, 10);
|
2011-03-14 23:14:40 +01:00
|
|
|
|
if (parsed == LONG_MIN ||
|
|
|
|
|
parsed == LONG_MAX ||
|
|
|
|
|
parsed < 0 ||
|
|
|
|
|
(end && *end != '\0')) {
|
2011-05-05 20:39:05 +02:00
|
|
|
|
ELOG("Could not parse con id \"%s\"\n", $3);
|
2011-03-14 23:14:40 +01:00
|
|
|
|
} else {
|
|
|
|
|
current_match.con_id = (Con*)parsed;
|
|
|
|
|
printf("id as int = %p\n", current_match.con_id);
|
|
|
|
|
}
|
2010-04-16 15:30:07 +02:00
|
|
|
|
}
|
2010-06-02 17:20:32 +02:00
|
|
|
|
| TOK_ID '=' STR
|
|
|
|
|
{
|
2011-05-05 20:39:05 +02:00
|
|
|
|
printf("criteria: window id = %s\n", $3);
|
2011-03-14 23:14:40 +01:00
|
|
|
|
char *end;
|
2011-05-05 20:39:05 +02:00
|
|
|
|
long parsed = strtol($3, &end, 10);
|
2011-03-14 23:14:40 +01:00
|
|
|
|
if (parsed == LONG_MIN ||
|
|
|
|
|
parsed == LONG_MAX ||
|
|
|
|
|
parsed < 0 ||
|
|
|
|
|
(end && *end != '\0')) {
|
2011-05-05 20:39:05 +02:00
|
|
|
|
ELOG("Could not parse window id \"%s\"\n", $3);
|
2011-03-14 23:14:40 +01:00
|
|
|
|
} else {
|
|
|
|
|
current_match.id = parsed;
|
|
|
|
|
printf("window id as int = %d\n", current_match.id);
|
|
|
|
|
}
|
2010-06-02 17:20:32 +02:00
|
|
|
|
}
|
2010-06-02 23:32:05 +02:00
|
|
|
|
| TOK_MARK '=' STR
|
|
|
|
|
{
|
2011-05-05 20:39:05 +02:00
|
|
|
|
printf("criteria: mark = %s\n", $3);
|
|
|
|
|
current_match.mark = $3;
|
2010-06-02 23:32:05 +02:00
|
|
|
|
}
|
2011-06-08 23:34:08 +02:00
|
|
|
|
| TOK_TITLE '=' STR
|
|
|
|
|
{
|
|
|
|
|
printf("criteria: title = %s\n", $3);
|
|
|
|
|
current_match.title = $3;
|
|
|
|
|
}
|
2010-04-14 20:26:56 +02:00
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
operations:
|
2011-05-22 21:26:50 +02:00
|
|
|
|
operation
|
|
|
|
|
| operations ',' operation
|
2010-04-14 20:26:56 +02:00
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
operation:
|
|
|
|
|
exec
|
|
|
|
|
| exit
|
|
|
|
|
| restart
|
2010-06-30 15:31:29 +02:00
|
|
|
|
| reload
|
2010-11-12 18:41:54 +01:00
|
|
|
|
| border
|
2010-06-01 23:20:57 +02:00
|
|
|
|
| layout
|
2011-06-10 02:15:31 +02:00
|
|
|
|
| append_layout
|
2010-05-11 22:46:49 +02:00
|
|
|
|
| move
|
2010-04-16 15:30:07 +02:00
|
|
|
|
| workspace
|
2010-04-14 20:26:56 +02:00
|
|
|
|
| focus
|
|
|
|
|
| kill
|
2010-04-16 15:30:07 +02:00
|
|
|
|
| open
|
2010-04-17 19:29:44 +02:00
|
|
|
|
| fullscreen
|
2010-05-10 09:33:10 +02:00
|
|
|
|
| split
|
2011-06-10 02:06:47 +02:00
|
|
|
|
| floating
|
2010-06-02 23:32:05 +02:00
|
|
|
|
| mark
|
2010-06-30 19:47:23 +02:00
|
|
|
|
| resize
|
2010-11-20 18:40:25 +01:00
|
|
|
|
| nop
|
2011-06-10 02:38:07 +02:00
|
|
|
|
| mode
|
2010-04-14 20:26:56 +02:00
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
exec:
|
2011-05-22 21:26:50 +02:00
|
|
|
|
TOK_EXEC STR
|
2010-04-14 20:26:56 +02:00
|
|
|
|
{
|
2011-05-22 21:26:50 +02:00
|
|
|
|
printf("should execute %s\n", $2);
|
|
|
|
|
start_application($2);
|
|
|
|
|
free($2);
|
2010-04-14 20:26:56 +02:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
exit:
|
|
|
|
|
TOK_EXIT
|
|
|
|
|
{
|
|
|
|
|
printf("exit, bye bye\n");
|
2010-05-10 10:12:35 +02:00
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
2010-06-30 15:31:29 +02:00
|
|
|
|
reload:
|
|
|
|
|
TOK_RELOAD
|
|
|
|
|
{
|
|
|
|
|
printf("reloading\n");
|
2011-07-10 14:33:19 +02:00
|
|
|
|
kill_configerror_nagbar(false);
|
2010-06-30 15:31:29 +02:00
|
|
|
|
load_configuration(conn, NULL, true);
|
2011-03-19 22:26:15 +01:00
|
|
|
|
x_set_i3_atoms();
|
2010-06-30 15:31:29 +02:00
|
|
|
|
/* Send an IPC event just in case the ws names have changed */
|
|
|
|
|
ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"reload\"}");
|
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
2010-05-10 10:12:35 +02:00
|
|
|
|
restart:
|
|
|
|
|
TOK_RESTART
|
|
|
|
|
{
|
|
|
|
|
printf("restarting i3\n");
|
2010-12-30 21:43:34 +01:00
|
|
|
|
i3_restart(false);
|
2010-04-14 20:26:56 +02:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
focus:
|
|
|
|
|
TOK_FOCUS
|
|
|
|
|
{
|
2010-06-01 18:49:43 +02:00
|
|
|
|
owindow *current;
|
|
|
|
|
|
|
|
|
|
if (match_is_empty(¤t_match)) {
|
2011-06-08 23:34:08 +02:00
|
|
|
|
ELOG("You have to specify which window/container should be focused.\n");
|
|
|
|
|
ELOG("Example: [class=\"urxvt\" title=\"irssi\"] focus\n");
|
|
|
|
|
|
|
|
|
|
asprintf(&json_output, "{\"success\":false, \"error\":\"You have to "
|
|
|
|
|
"specify which window/container should be focused\"}");
|
2011-02-01 15:43:59 +01:00
|
|
|
|
break;
|
2010-06-01 18:49:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-08 23:34:08 +02:00
|
|
|
|
int count = 0;
|
2010-06-01 18:49:43 +02:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
2011-07-14 23:43:57 +02:00
|
|
|
|
Con *ws = con_get_workspace(current->con);
|
|
|
|
|
workspace_show(ws->name);
|
2010-06-01 18:49:43 +02:00
|
|
|
|
LOG("focusing %p / %s\n", current->con, current->con->name);
|
|
|
|
|
con_focus(current->con);
|
2011-06-08 23:34:08 +02:00
|
|
|
|
count++;
|
2010-06-01 18:49:43 +02:00
|
|
|
|
}
|
2011-05-29 12:29:49 +02:00
|
|
|
|
|
2011-06-08 23:34:08 +02:00
|
|
|
|
if (count > 1)
|
|
|
|
|
LOG("WARNING: Your criteria for the focus command matches %d containers, "
|
|
|
|
|
"while only exactly one container can be focused at a time.\n", count);
|
|
|
|
|
|
2011-05-29 12:29:49 +02:00
|
|
|
|
tree_render();
|
2010-04-14 20:26:56 +02:00
|
|
|
|
}
|
2011-06-08 20:49:49 +02:00
|
|
|
|
| TOK_FOCUS direction
|
|
|
|
|
{
|
|
|
|
|
int direction = $2;
|
|
|
|
|
switch (direction) {
|
|
|
|
|
case TOK_LEFT:
|
|
|
|
|
LOG("Focusing left\n");
|
|
|
|
|
tree_next('p', HORIZ);
|
|
|
|
|
break;
|
|
|
|
|
case TOK_RIGHT:
|
|
|
|
|
LOG("Focusing right\n");
|
|
|
|
|
tree_next('n', HORIZ);
|
|
|
|
|
break;
|
|
|
|
|
case TOK_UP:
|
|
|
|
|
LOG("Focusing up\n");
|
|
|
|
|
tree_next('p', VERT);
|
|
|
|
|
break;
|
|
|
|
|
case TOK_DOWN:
|
|
|
|
|
LOG("Focusing down\n");
|
|
|
|
|
tree_next('n', VERT);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ELOG("Invalid focus direction (%d)\n", direction);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tree_render();
|
|
|
|
|
}
|
2011-07-04 17:09:52 +02:00
|
|
|
|
| TOK_FOCUS window_mode
|
|
|
|
|
{
|
|
|
|
|
printf("should focus: ");
|
|
|
|
|
|
|
|
|
|
if ($2 == TOK_TILING)
|
|
|
|
|
printf("tiling\n");
|
|
|
|
|
else if ($2 == TOK_FLOATING)
|
|
|
|
|
printf("floating\n");
|
|
|
|
|
else printf("mode toggle\n");
|
|
|
|
|
|
|
|
|
|
Con *ws = con_get_workspace(focused);
|
|
|
|
|
Con *current;
|
|
|
|
|
if (ws != NULL) {
|
|
|
|
|
int to_focus = $2;
|
|
|
|
|
if ($2 == TOK_MODE_TOGGLE) {
|
|
|
|
|
current = TAILQ_FIRST(&(ws->focus_head));
|
2011-08-24 00:55:11 +02:00
|
|
|
|
if (current != NULL && current->type == CT_FLOATING_CON)
|
2011-07-04 17:09:52 +02:00
|
|
|
|
to_focus = TOK_TILING;
|
|
|
|
|
else to_focus = TOK_FLOATING;
|
|
|
|
|
}
|
|
|
|
|
TAILQ_FOREACH(current, &(ws->focus_head), focused) {
|
|
|
|
|
if ((to_focus == TOK_FLOATING && current->type != CT_FLOATING_CON) ||
|
|
|
|
|
(to_focus == TOK_TILING && current->type == CT_FLOATING_CON))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
con_focus(con_descend_focused(current));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tree_render();
|
|
|
|
|
}
|
2011-06-10 01:36:33 +02:00
|
|
|
|
| TOK_FOCUS level
|
|
|
|
|
{
|
|
|
|
|
if ($2 == TOK_PARENT)
|
|
|
|
|
level_up();
|
|
|
|
|
else level_down();
|
|
|
|
|
|
|
|
|
|
tree_render();
|
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
2011-07-04 17:09:52 +02:00
|
|
|
|
window_mode:
|
|
|
|
|
TOK_TILING { $$ = TOK_TILING; }
|
|
|
|
|
| TOK_FLOATING { $$ = TOK_FLOATING; }
|
|
|
|
|
| TOK_MODE_TOGGLE { $$ = TOK_MODE_TOGGLE; }
|
|
|
|
|
;
|
|
|
|
|
|
2011-06-10 01:36:33 +02:00
|
|
|
|
level:
|
|
|
|
|
TOK_PARENT { $$ = TOK_PARENT; }
|
|
|
|
|
| TOK_CHILD { $$ = TOK_CHILD; }
|
2010-04-14 20:26:56 +02:00
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
kill:
|
2011-05-13 20:41:03 +02:00
|
|
|
|
TOK_KILL optional_kill_mode
|
2010-04-14 20:26:56 +02:00
|
|
|
|
{
|
|
|
|
|
owindow *current;
|
|
|
|
|
|
|
|
|
|
printf("killing!\n");
|
2010-04-17 19:29:44 +02:00
|
|
|
|
/* check if the match is empty, not if the result is empty */
|
2010-04-16 22:50:20 +02:00
|
|
|
|
if (match_is_empty(¤t_match))
|
2011-05-13 20:41:03 +02:00
|
|
|
|
tree_close_con($2);
|
2010-04-16 15:30:07 +02:00
|
|
|
|
else {
|
2010-04-17 19:29:44 +02:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
printf("matching: %p / %s\n", current->con, current->con->name);
|
2011-05-13 20:41:03 +02:00
|
|
|
|
tree_close(current->con, $2, false);
|
2010-04-17 19:29:44 +02:00
|
|
|
|
}
|
2010-04-16 15:30:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 12:29:49 +02:00
|
|
|
|
tree_render();
|
2010-04-16 15:30:07 +02:00
|
|
|
|
}
|
|
|
|
|
;
|
2010-04-14 20:26:56 +02:00
|
|
|
|
|
2011-05-13 20:41:03 +02:00
|
|
|
|
optional_kill_mode:
|
|
|
|
|
/* empty */ { $$ = KILL_WINDOW; }
|
2011-05-22 21:26:50 +02:00
|
|
|
|
| TOK_WINDOW { $$ = KILL_WINDOW; }
|
|
|
|
|
| TOK_CLIENT { $$ = KILL_CLIENT; }
|
2011-05-13 20:41:03 +02:00
|
|
|
|
;
|
|
|
|
|
|
2010-04-16 15:30:07 +02:00
|
|
|
|
workspace:
|
2011-06-10 16:03:59 +02:00
|
|
|
|
TOK_WORKSPACE TOK_NEXT
|
|
|
|
|
{
|
|
|
|
|
workspace_next();
|
|
|
|
|
tree_render();
|
|
|
|
|
}
|
|
|
|
|
| TOK_WORKSPACE TOK_PREV
|
|
|
|
|
{
|
|
|
|
|
workspace_prev();
|
|
|
|
|
tree_render();
|
|
|
|
|
}
|
|
|
|
|
| TOK_WORKSPACE STR
|
2010-04-16 15:30:07 +02:00
|
|
|
|
{
|
2011-05-22 21:26:50 +02:00
|
|
|
|
printf("should switch to workspace %s\n", $2);
|
|
|
|
|
workspace_show($2);
|
|
|
|
|
free($2);
|
2011-05-29 12:29:49 +02:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-04-16 15:30:07 +02:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
open:
|
|
|
|
|
TOK_OPEN
|
|
|
|
|
{
|
|
|
|
|
printf("opening new container\n");
|
2011-06-02 17:21:38 +02:00
|
|
|
|
Con *con = tree_open_con(NULL, NULL);
|
2011-03-06 23:26:02 +01:00
|
|
|
|
con_focus(con);
|
2011-02-01 15:43:59 +01:00
|
|
|
|
asprintf(&json_output, "{\"success\":true, \"id\":%ld}", (long int)con);
|
2011-05-29 12:29:49 +02:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-04-14 20:26:56 +02:00
|
|
|
|
}
|
|
|
|
|
;
|
2010-04-17 19:29:44 +02:00
|
|
|
|
|
|
|
|
|
fullscreen:
|
2011-06-10 18:27:20 +02:00
|
|
|
|
TOK_FULLSCREEN fullscreen_mode
|
2010-04-17 19:29:44 +02:00
|
|
|
|
{
|
2011-06-10 18:27:20 +02:00
|
|
|
|
printf("toggling fullscreen, mode = %s\n", ($2 == CF_OUTPUT ? "normal" : "global"));
|
2010-04-17 19:29:44 +02:00
|
|
|
|
owindow *current;
|
|
|
|
|
|
2011-05-15 19:43:35 +02:00
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
printf("matching: %p / %s\n", current->con, current->con->name);
|
2011-06-10 18:27:20 +02:00
|
|
|
|
con_toggle_fullscreen(current->con, $2);
|
2011-05-15 19:43:35 +02:00
|
|
|
|
}
|
2011-05-29 12:29:49 +02:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-04-17 19:29:44 +02:00
|
|
|
|
}
|
|
|
|
|
;
|
2010-05-10 00:06:24 +02:00
|
|
|
|
|
2011-06-10 18:27:20 +02:00
|
|
|
|
fullscreen_mode:
|
|
|
|
|
/* empty */ { $$ = CF_OUTPUT; }
|
|
|
|
|
| TOK_GLOBAL { $$ = CF_GLOBAL; }
|
|
|
|
|
;
|
|
|
|
|
|
2010-05-10 09:33:10 +02:00
|
|
|
|
split:
|
2011-06-10 02:25:14 +02:00
|
|
|
|
TOK_SPLIT split_direction
|
2010-05-10 09:33:10 +02:00
|
|
|
|
{
|
2010-05-10 10:12:35 +02:00
|
|
|
|
/* TODO: use matches */
|
2011-05-22 21:26:50 +02:00
|
|
|
|
printf("splitting in direction %c\n", $2);
|
|
|
|
|
tree_split(focused, ($2 == 'v' ? VERT : HORIZ));
|
2011-05-29 12:29:49 +02:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-05-10 09:33:10 +02:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
2011-06-10 02:25:14 +02:00
|
|
|
|
split_direction:
|
2011-05-05 20:39:05 +02:00
|
|
|
|
TOK_HORIZONTAL { $$ = 'h'; }
|
|
|
|
|
| 'h' { $$ = 'h'; }
|
|
|
|
|
| TOK_VERTICAL { $$ = 'v'; }
|
|
|
|
|
| 'v' { $$ = 'v'; }
|
2010-05-10 00:06:24 +02:00
|
|
|
|
;
|
2010-05-10 10:12:35 +02:00
|
|
|
|
|
2011-06-10 02:06:47 +02:00
|
|
|
|
floating:
|
|
|
|
|
TOK_FLOATING boolean
|
2010-05-10 10:12:35 +02:00
|
|
|
|
{
|
2011-05-15 20:10:25 +02:00
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
|
|
|
|
owindow *current;
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
printf("matching: %p / %s\n", current->con, current->con->name);
|
2011-05-22 21:26:50 +02:00
|
|
|
|
if ($2 == TOK_TOGGLE) {
|
2011-05-15 20:10:25 +02:00
|
|
|
|
printf("should toggle mode\n");
|
|
|
|
|
toggle_floating_mode(current->con, false);
|
2010-06-30 15:54:34 +02:00
|
|
|
|
} else {
|
2011-05-22 21:26:50 +02:00
|
|
|
|
printf("should switch mode to %s\n", ($2 == TOK_FLOATING ? "floating" : "tiling"));
|
2011-06-10 02:06:47 +02:00
|
|
|
|
if ($2 == TOK_ENABLE) {
|
2011-05-15 20:10:25 +02:00
|
|
|
|
floating_enable(current->con, false);
|
|
|
|
|
} else {
|
|
|
|
|
floating_disable(current->con, false);
|
|
|
|
|
}
|
2010-06-30 15:54:34 +02:00
|
|
|
|
}
|
2010-05-31 22:48:28 +02:00
|
|
|
|
}
|
2011-05-29 12:29:49 +02:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-05-10 10:12:35 +02:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
2011-06-10 02:06:47 +02:00
|
|
|
|
boolean:
|
|
|
|
|
TOK_ENABLE { $$ = TOK_ENABLE; }
|
|
|
|
|
| TOK_DISABLE { $$ = TOK_DISABLE; }
|
|
|
|
|
| TOK_TOGGLE { $$ = TOK_TOGGLE; }
|
2010-05-10 10:12:35 +02:00
|
|
|
|
;
|
|
|
|
|
|
2010-11-12 18:41:54 +01:00
|
|
|
|
border:
|
2011-05-22 21:26:50 +02:00
|
|
|
|
TOK_BORDER border_style
|
2010-11-12 18:41:54 +01:00
|
|
|
|
{
|
2011-05-22 21:26:50 +02:00
|
|
|
|
printf("border style should be changed to %d\n", $2);
|
2010-11-12 18:41:54 +01:00
|
|
|
|
owindow *current;
|
|
|
|
|
|
2011-05-15 19:43:35 +02:00
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
printf("matching: %p / %s\n", current->con, current->con->name);
|
2011-06-10 16:15:52 +02:00
|
|
|
|
if ($2 == TOK_TOGGLE) {
|
|
|
|
|
current->con->border_style++;
|
|
|
|
|
current->con->border_style %= 3;
|
|
|
|
|
} else current->con->border_style = $2;
|
2010-11-12 18:41:54 +01:00
|
|
|
|
}
|
2011-05-29 12:29:49 +02:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-11-12 18:41:54 +01:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
border_style:
|
2011-05-05 20:39:05 +02:00
|
|
|
|
TOK_NORMAL { $$ = BS_NORMAL; }
|
|
|
|
|
| TOK_NONE { $$ = BS_NONE; }
|
|
|
|
|
| TOK_1PIXEL { $$ = BS_1PIXEL; }
|
2011-06-10 16:15:52 +02:00
|
|
|
|
| TOK_TOGGLE { $$ = TOK_TOGGLE; }
|
2010-11-12 18:41:54 +01:00
|
|
|
|
;
|
|
|
|
|
|
2010-05-11 22:46:49 +02:00
|
|
|
|
move:
|
2011-05-22 21:26:50 +02:00
|
|
|
|
TOK_MOVE direction
|
2010-05-11 22:46:49 +02:00
|
|
|
|
{
|
2011-05-22 21:26:50 +02:00
|
|
|
|
printf("moving in direction %d\n", $2);
|
|
|
|
|
tree_move($2);
|
2011-05-29 12:29:49 +02:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-05-11 22:46:49 +02:00
|
|
|
|
}
|
2011-05-22 21:26:50 +02:00
|
|
|
|
| TOK_MOVE TOK_WORKSPACE STR
|
2010-06-30 22:23:32 +02:00
|
|
|
|
{
|
|
|
|
|
owindow *current;
|
|
|
|
|
|
2011-05-22 21:26:50 +02:00
|
|
|
|
printf("should move window to workspace %s\n", $3);
|
2010-06-30 22:23:32 +02:00
|
|
|
|
/* get the workspace */
|
2011-05-22 21:26:50 +02:00
|
|
|
|
Con *ws = workspace_get($3, NULL);
|
|
|
|
|
free($3);
|
2010-06-30 22:23:32 +02:00
|
|
|
|
|
2011-05-15 19:43:35 +02:00
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
printf("matching: %p / %s\n", current->con, current->con->name);
|
2011-08-24 22:59:46 +02:00
|
|
|
|
con_move_to_workspace(current->con, ws, false);
|
2010-06-30 22:23:32 +02:00
|
|
|
|
}
|
2011-05-29 12:29:49 +02:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-06-30 22:23:32 +02:00
|
|
|
|
}
|
2010-05-11 22:46:49 +02:00
|
|
|
|
;
|
|
|
|
|
|
2011-06-10 02:15:31 +02:00
|
|
|
|
append_layout:
|
|
|
|
|
TOK_APPEND_LAYOUT STR
|
2010-05-11 23:00:31 +02:00
|
|
|
|
{
|
2011-05-22 21:26:50 +02:00
|
|
|
|
printf("restoring \"%s\"\n", $2);
|
|
|
|
|
tree_append_json($2);
|
|
|
|
|
free($2);
|
2011-05-29 12:29:49 +02:00
|
|
|
|
tree_render();
|
2010-05-11 23:00:31 +02:00
|
|
|
|
}
|
|
|
|
|
;
|
2010-06-01 23:20:57 +02:00
|
|
|
|
|
|
|
|
|
layout:
|
2011-05-22 21:26:50 +02:00
|
|
|
|
TOK_LAYOUT layout_mode
|
2010-06-01 23:20:57 +02:00
|
|
|
|
{
|
2011-05-22 21:26:50 +02:00
|
|
|
|
printf("changing layout to %d\n", $2);
|
2010-06-01 23:20:57 +02:00
|
|
|
|
owindow *current;
|
|
|
|
|
|
2011-05-15 20:10:25 +02:00
|
|
|
|
/* check if the match is empty, not if the result is empty */
|
|
|
|
|
if (match_is_empty(¤t_match))
|
2011-05-22 21:26:50 +02:00
|
|
|
|
con_set_layout(focused->parent, $2);
|
2011-05-15 20:10:25 +02:00
|
|
|
|
else {
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
printf("matching: %p / %s\n", current->con, current->con->name);
|
2011-05-22 21:26:50 +02:00
|
|
|
|
con_set_layout(current->con, $2);
|
2011-05-15 20:10:25 +02:00
|
|
|
|
}
|
2011-05-15 19:43:35 +02:00
|
|
|
|
}
|
2011-05-29 12:29:49 +02:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-06-01 23:20:57 +02:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
layout_mode:
|
2011-05-05 20:39:05 +02:00
|
|
|
|
TOK_DEFAULT { $$ = L_DEFAULT; }
|
|
|
|
|
| TOK_STACKED { $$ = L_STACKED; }
|
|
|
|
|
| TOK_TABBED { $$ = L_TABBED; }
|
2010-06-01 23:20:57 +02:00
|
|
|
|
;
|
2010-06-02 23:32:05 +02:00
|
|
|
|
|
|
|
|
|
mark:
|
2011-05-22 21:26:50 +02:00
|
|
|
|
TOK_MARK STR
|
2010-06-02 23:32:05 +02:00
|
|
|
|
{
|
2011-05-22 21:26:50 +02:00
|
|
|
|
printf("marking window with str %s\n", $2);
|
2010-06-02 23:32:05 +02:00
|
|
|
|
owindow *current;
|
|
|
|
|
|
2011-05-15 19:43:35 +02:00
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
printf("matching: %p / %s\n", current->con, current->con->name);
|
2011-05-22 21:26:50 +02:00
|
|
|
|
current->con->mark = sstrdup($2);
|
2010-06-02 23:32:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-22 21:26:50 +02:00
|
|
|
|
free($<string>2);
|
2011-05-29 12:29:49 +02:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-06-02 23:32:05 +02:00
|
|
|
|
}
|
|
|
|
|
;
|
2010-06-30 19:47:23 +02:00
|
|
|
|
|
2010-11-20 18:40:25 +01:00
|
|
|
|
nop:
|
2011-05-22 21:26:50 +02:00
|
|
|
|
TOK_NOP STR
|
2010-11-20 18:40:25 +01:00
|
|
|
|
{
|
|
|
|
|
printf("-------------------------------------------------\n");
|
2011-05-22 21:26:50 +02:00
|
|
|
|
printf(" NOP: %s\n", $2);
|
2010-11-20 18:40:25 +01:00
|
|
|
|
printf("-------------------------------------------------\n");
|
2011-05-22 21:26:50 +02:00
|
|
|
|
free($2);
|
2010-11-20 18:40:25 +01:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
2010-06-30 19:47:23 +02:00
|
|
|
|
resize:
|
2011-05-22 21:26:50 +02:00
|
|
|
|
TOK_RESIZE resize_way direction resize_px resize_tiling
|
2010-06-30 19:47:23 +02:00
|
|
|
|
{
|
|
|
|
|
/* resize <grow|shrink> <direction> [<px> px] [or <ppt> ppt] */
|
2011-05-22 21:26:50 +02:00
|
|
|
|
printf("resizing in way %d, direction %d, px %d or ppt %d\n", $2, $3, $4, $5);
|
|
|
|
|
int direction = $3;
|
|
|
|
|
int px = $4;
|
|
|
|
|
int ppt = $5;
|
|
|
|
|
if ($2 == TOK_SHRINK) {
|
2010-06-30 19:47:23 +02:00
|
|
|
|
px *= -1;
|
|
|
|
|
ppt *= -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (con_is_floating(focused)) {
|
|
|
|
|
printf("floating resize\n");
|
|
|
|
|
if (direction == TOK_UP) {
|
|
|
|
|
focused->parent->rect.y -= px;
|
|
|
|
|
focused->parent->rect.height += px;
|
|
|
|
|
} else if (direction == TOK_DOWN) {
|
2011-08-03 14:48:52 +02:00
|
|
|
|
focused->parent->rect.height += px;
|
2010-06-30 19:47:23 +02:00
|
|
|
|
} else if (direction == TOK_LEFT) {
|
2011-08-03 14:48:52 +02:00
|
|
|
|
focused->parent->rect.x -= px;
|
|
|
|
|
focused->parent->rect.width += px;
|
2010-06-30 19:47:23 +02:00
|
|
|
|
} else {
|
2011-08-03 14:48:52 +02:00
|
|
|
|
focused->parent->rect.width += px;
|
2010-06-30 19:47:23 +02:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
LOG("tiling resize\n");
|
2011-08-24 15:14:04 +02:00
|
|
|
|
/* get the appropriate current container (skip stacked/tabbed cons) */
|
|
|
|
|
Con *current = focused;
|
|
|
|
|
while (current->parent->layout == L_STACKED ||
|
|
|
|
|
current->parent->layout == L_TABBED)
|
|
|
|
|
current = current->parent;
|
2010-06-30 19:47:23 +02:00
|
|
|
|
/* get the default percentage */
|
2011-08-24 15:14:04 +02:00
|
|
|
|
int children = con_num_children(current->parent);
|
2010-06-30 19:47:23 +02:00
|
|
|
|
Con *other;
|
|
|
|
|
LOG("ins. %d children\n", children);
|
|
|
|
|
double percentage = 1.0 / children;
|
|
|
|
|
LOG("default percentage = %f\n", percentage);
|
|
|
|
|
|
|
|
|
|
if (direction == TOK_UP || direction == TOK_LEFT) {
|
2011-08-24 15:14:04 +02:00
|
|
|
|
other = TAILQ_PREV(current, nodes_head, nodes);
|
2010-06-30 19:47:23 +02:00
|
|
|
|
} else {
|
2011-08-24 15:14:04 +02:00
|
|
|
|
other = TAILQ_NEXT(current, nodes);
|
2010-06-30 19:47:23 +02:00
|
|
|
|
}
|
|
|
|
|
if (other == TAILQ_END(workspaces)) {
|
|
|
|
|
LOG("No other container in this direction found, cannot resize.\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
LOG("other->percent = %f\n", other->percent);
|
2011-08-24 15:14:04 +02:00
|
|
|
|
LOG("current->percent before = %f\n", current->percent);
|
|
|
|
|
if (current->percent == 0.0)
|
|
|
|
|
current->percent = percentage;
|
2010-06-30 19:47:23 +02:00
|
|
|
|
if (other->percent == 0.0)
|
|
|
|
|
other->percent = percentage;
|
2011-08-24 15:14:04 +02:00
|
|
|
|
double new_current_percent = current->percent + ((double)ppt / 100.0);
|
2011-08-02 22:31:45 +02:00
|
|
|
|
double new_other_percent = other->percent - ((double)ppt / 100.0);
|
2011-08-24 15:14:04 +02:00
|
|
|
|
LOG("new_current_percent = %f\n", new_current_percent);
|
2011-08-02 22:31:45 +02:00
|
|
|
|
LOG("new_other_percent = %f\n", new_other_percent);
|
|
|
|
|
/* Ensure that the new percentages are positive and greater than
|
|
|
|
|
* 0.05 to have a reasonable minimum size. */
|
2011-08-24 15:14:04 +02:00
|
|
|
|
if (definitelyGreaterThan(new_current_percent, 0.05, DBL_EPSILON) &&
|
2011-08-02 22:31:45 +02:00
|
|
|
|
definitelyGreaterThan(new_other_percent, 0.05, DBL_EPSILON)) {
|
2011-08-24 15:14:04 +02:00
|
|
|
|
current->percent += ((double)ppt / 100.0);
|
2011-08-02 22:31:45 +02:00
|
|
|
|
other->percent -= ((double)ppt / 100.0);
|
2011-08-24 15:14:04 +02:00
|
|
|
|
LOG("current->percent after = %f\n", current->percent);
|
2011-08-02 22:31:45 +02:00
|
|
|
|
LOG("other->percent after = %f\n", other->percent);
|
|
|
|
|
} else {
|
|
|
|
|
LOG("Not resizing, already at minimum size\n");
|
|
|
|
|
}
|
2010-06-30 19:47:23 +02:00
|
|
|
|
}
|
2011-05-29 12:29:49 +02:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-06-30 19:47:23 +02:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
resize_px:
|
|
|
|
|
/* empty */
|
|
|
|
|
{
|
2011-05-05 20:39:05 +02:00
|
|
|
|
$$ = 10;
|
2010-06-30 19:47:23 +02:00
|
|
|
|
}
|
2011-05-22 21:26:50 +02:00
|
|
|
|
| NUMBER TOK_PX
|
2010-06-30 19:47:23 +02:00
|
|
|
|
{
|
2011-05-22 21:26:50 +02:00
|
|
|
|
$$ = $1;
|
2010-06-30 19:47:23 +02:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
resize_tiling:
|
|
|
|
|
/* empty */
|
|
|
|
|
{
|
2011-05-05 20:39:05 +02:00
|
|
|
|
$$ = 10;
|
2010-06-30 19:47:23 +02:00
|
|
|
|
}
|
2011-05-22 21:26:50 +02:00
|
|
|
|
| TOK_OR NUMBER TOK_PPT
|
2010-06-30 19:47:23 +02:00
|
|
|
|
{
|
2011-05-22 21:26:50 +02:00
|
|
|
|
$$ = $2;
|
2010-06-30 19:47:23 +02:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
resize_way:
|
2011-05-05 20:39:05 +02:00
|
|
|
|
TOK_GROW { $$ = TOK_GROW; }
|
|
|
|
|
| TOK_SHRINK { $$ = TOK_SHRINK; }
|
2010-06-30 19:47:23 +02:00
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
direction:
|
2011-05-05 20:39:05 +02:00
|
|
|
|
TOK_UP { $$ = TOK_UP; }
|
|
|
|
|
| TOK_DOWN { $$ = TOK_DOWN; }
|
|
|
|
|
| TOK_LEFT { $$ = TOK_LEFT; }
|
|
|
|
|
| TOK_RIGHT { $$ = TOK_RIGHT; }
|
2010-06-30 19:47:23 +02:00
|
|
|
|
;
|
2011-06-10 02:38:07 +02:00
|
|
|
|
|
|
|
|
|
mode:
|
|
|
|
|
TOK_MODE STR
|
|
|
|
|
{
|
|
|
|
|
switch_mode($2);
|
|
|
|
|
}
|
|
|
|
|
;
|