2010-04-14 14:26:56 -04:00
|
|
|
|
%{
|
|
|
|
|
/*
|
|
|
|
|
* vim:ts=4:sw=4:expandtab
|
|
|
|
|
*
|
|
|
|
|
* i3 - an improved dynamic tiling window manager
|
2011-05-15 14:10:25 -04:00
|
|
|
|
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
|
2010-04-14 14:26:56 -04: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-03-14 18:14:40 -04:00
|
|
|
|
#include <limits.h>
|
2011-08-02 16:31:45 -04:00
|
|
|
|
#include <float.h>
|
2010-04-14 14:26:56 -04:00
|
|
|
|
|
|
|
|
|
#include "all.h"
|
|
|
|
|
|
2011-05-15 13:43:35 -04: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 14:26:56 -04:00
|
|
|
|
typedef struct yy_buffer_state *YY_BUFFER_STATE;
|
|
|
|
|
extern int cmdyylex(struct context *context);
|
|
|
|
|
extern int cmdyyparse(void);
|
2011-07-31 11:11:28 -04:00
|
|
|
|
extern int cmdyylex_destroy(void);
|
2010-04-14 14:26:56 -04: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 09:15:37 -04:00
|
|
|
|
/* Holds the JSON which will be returned via IPC or NULL for the default return
|
|
|
|
|
* message */
|
|
|
|
|
static char *json_output;
|
|
|
|
|
|
2010-04-14 14:26:56 -04: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 14:22:55 -05:00
|
|
|
|
ELOG("CMD: in command:\n");
|
2010-04-14 14:26:56 -04: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-13 19:45:05 -05:00
|
|
|
|
context->compact_error = sstrdup(error_message);
|
2010-04-14 14:26:56 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int cmdyywrap() {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-17 09:15:37 -04:00
|
|
|
|
char *parse_cmd(const char *new) {
|
2011-05-15 14:10:25 -04:00
|
|
|
|
LOG("COMMAND: *%s*\n", new);
|
2010-04-14 14:26:56 -04:00
|
|
|
|
cmdyy_scan_string(new);
|
|
|
|
|
|
2010-11-12 13:07:35 -05:00
|
|
|
|
match_init(¤t_match);
|
2010-04-14 14:26:56 -04:00
|
|
|
|
context = scalloc(sizeof(struct context));
|
|
|
|
|
context->filename = "cmd";
|
2010-07-17 09:15:37 -04:00
|
|
|
|
FREE(json_output);
|
2010-04-14 14:26:56 -04:00
|
|
|
|
if (cmdyyparse() != 0) {
|
2010-11-12 14:22:55 -05:00
|
|
|
|
fprintf(stderr, "Could not parse command\n");
|
2010-11-13 19:45:05 -05:00
|
|
|
|
asprintf(&json_output, "{\"success\":false, \"error\":\"%s at position %d\"}",
|
|
|
|
|
context->compact_error, context->first_column);
|
2010-11-12 14:22:55 -05:00
|
|
|
|
FREE(context->line_copy);
|
2010-11-13 19:45:05 -05:00
|
|
|
|
FREE(context->compact_error);
|
2010-11-12 14:22:55 -05:00
|
|
|
|
free(context);
|
2010-11-13 19:45:05 -05:00
|
|
|
|
return json_output;
|
2010-04-14 14:26:56 -04:00
|
|
|
|
}
|
2010-07-17 09:15:37 -04:00
|
|
|
|
printf("done, json output = %s\n", json_output);
|
2010-04-14 14:26:56 -04:00
|
|
|
|
|
2011-07-31 11:11:28 -04:00
|
|
|
|
cmdyylex_destroy();
|
2010-04-14 14:26:56 -04:00
|
|
|
|
FREE(context->line_copy);
|
2010-11-13 19:45:05 -05:00
|
|
|
|
FREE(context->compact_error);
|
2010-04-14 14:26:56 -04:00
|
|
|
|
free(context);
|
2010-07-17 09:15:37 -04:00
|
|
|
|
return json_output;
|
2010-04-14 14:26:56 -04:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-02 16:31:45 -04: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 14:26:56 -04:00
|
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
%error-verbose
|
|
|
|
|
%lex-param { struct context *context }
|
|
|
|
|
|
|
|
|
|
%union {
|
|
|
|
|
char *string;
|
2010-05-09 18:06:24 -04:00
|
|
|
|
char chr;
|
2010-05-10 04:12:35 -04:00
|
|
|
|
int number;
|
2010-04-14 14:26:56 -04:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-05 14:39:05 -04:00
|
|
|
|
%token TOK_EXEC "exec"
|
|
|
|
|
%token TOK_EXIT "exit"
|
|
|
|
|
%token TOK_RELOAD "reload"
|
|
|
|
|
%token TOK_RESTART "restart"
|
|
|
|
|
%token TOK_KILL "kill"
|
2011-05-13 14:41:03 -04:00
|
|
|
|
%token TOK_WINDOW "window"
|
|
|
|
|
%token TOK_CLIENT "client"
|
2011-05-05 14:39:05 -04: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 11:09:52 -04:00
|
|
|
|
%token TOK_MODE_TOGGLE "mode_toggle"
|
2011-06-09 20:06:47 -04:00
|
|
|
|
%token TOK_ENABLE "enable"
|
|
|
|
|
%token TOK_DISABLE "disable"
|
2011-05-05 14:39:05 -04:00
|
|
|
|
%token TOK_WORKSPACE "workspace"
|
|
|
|
|
%token TOK_TOGGLE "toggle"
|
|
|
|
|
%token TOK_FOCUS "focus"
|
|
|
|
|
%token TOK_MOVE "move"
|
|
|
|
|
%token TOK_OPEN "open"
|
2011-06-10 10:03:59 -04:00
|
|
|
|
%token TOK_NEXT "next"
|
2011-05-05 14:39:05 -04: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-09 19:36:33 -04:00
|
|
|
|
%token TOK_PARENT "parent"
|
|
|
|
|
%token TOK_CHILD "child"
|
2011-06-09 20:15:31 -04:00
|
|
|
|
%token TOK_APPEND_LAYOUT "append_layout"
|
2011-05-05 14:39:05 -04: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"
|
|
|
|
|
%token TOK_ID "id"
|
|
|
|
|
%token TOK_CON_ID "con_id"
|
2011-06-08 17:34:08 -04:00
|
|
|
|
%token TOK_TITLE "title"
|
2011-05-05 14:39:05 -04:00
|
|
|
|
|
|
|
|
|
%token <string> STR "<string>"
|
|
|
|
|
%token <number> NUMBER "<number>"
|
|
|
|
|
|
|
|
|
|
%type <number> direction
|
2011-06-09 20:25:14 -04:00
|
|
|
|
%type <number> split_direction
|
2011-06-10 12:27:20 -04:00
|
|
|
|
%type <number> fullscreen_mode
|
2011-06-09 19:36:33 -04:00
|
|
|
|
%type <number> level
|
2011-07-04 11:09:52 -04:00
|
|
|
|
%type <number> window_mode
|
2011-06-09 20:06:47 -04:00
|
|
|
|
%type <number> boolean
|
2011-05-05 14:39:05 -04:00
|
|
|
|
%type <number> border_style
|
|
|
|
|
%type <number> layout_mode
|
|
|
|
|
%type <number> resize_px
|
|
|
|
|
%type <number> resize_way
|
|
|
|
|
%type <number> resize_tiling
|
2011-05-13 14:41:03 -04:00
|
|
|
|
%type <number> optional_kill_mode
|
2010-04-14 14:26:56 -04:00
|
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
2011-03-14 18:03:13 -04:00
|
|
|
|
commands:
|
2011-05-22 15:26:50 -04:00
|
|
|
|
commands ';' command
|
2010-04-14 14:26:56 -04: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 15:41:05 -04:00
|
|
|
|
match_init(¤t_match);
|
2010-04-14 14:26:56 -04:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
command:
|
2011-05-22 15:26:50 -04:00
|
|
|
|
match operations
|
2010-04-14 14:26:56 -04:00
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
match:
|
2011-05-22 15:26:50 -04:00
|
|
|
|
| matchstart criteria matchend
|
2010-04-14 14:26:56 -04:00
|
|
|
|
{
|
|
|
|
|
printf("match parsed\n");
|
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
matchstart:
|
|
|
|
|
'['
|
|
|
|
|
{
|
|
|
|
|
printf("start\n");
|
2010-08-20 15:41:05 -04:00
|
|
|
|
match_init(¤t_match);
|
2010-04-14 14:26:56 -04: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 09:30:07 -04: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 17:32:05 -04: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 14:26:56 -04:00
|
|
|
|
} else {
|
2010-04-16 09:30:07 -04: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 14:26:56 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
printf("matching: %p / %s\n", current->con, current->con->name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
criteria:
|
2011-06-08 17:34:08 -04:00
|
|
|
|
criteria criterion
|
|
|
|
|
| criterion
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
criterion:
|
2010-04-14 14:26:56 -04:00
|
|
|
|
TOK_CLASS '=' STR
|
|
|
|
|
{
|
2011-05-05 14:39:05 -04:00
|
|
|
|
printf("criteria: class = %s\n", $3);
|
|
|
|
|
current_match.class = $3;
|
2010-04-14 14:26:56 -04:00
|
|
|
|
}
|
2010-04-16 09:30:07 -04:00
|
|
|
|
| TOK_CON_ID '=' STR
|
|
|
|
|
{
|
2011-05-05 14:39:05 -04:00
|
|
|
|
printf("criteria: id = %s\n", $3);
|
2011-03-14 18:14:40 -04:00
|
|
|
|
char *end;
|
2011-05-05 14:39:05 -04:00
|
|
|
|
long parsed = strtol($3, &end, 10);
|
2011-03-14 18:14:40 -04:00
|
|
|
|
if (parsed == LONG_MIN ||
|
|
|
|
|
parsed == LONG_MAX ||
|
|
|
|
|
parsed < 0 ||
|
|
|
|
|
(end && *end != '\0')) {
|
2011-05-05 14:39:05 -04:00
|
|
|
|
ELOG("Could not parse con id \"%s\"\n", $3);
|
2011-03-14 18:14:40 -04:00
|
|
|
|
} else {
|
|
|
|
|
current_match.con_id = (Con*)parsed;
|
|
|
|
|
printf("id as int = %p\n", current_match.con_id);
|
|
|
|
|
}
|
2010-04-16 09:30:07 -04:00
|
|
|
|
}
|
2010-06-02 11:20:32 -04:00
|
|
|
|
| TOK_ID '=' STR
|
|
|
|
|
{
|
2011-05-05 14:39:05 -04:00
|
|
|
|
printf("criteria: window id = %s\n", $3);
|
2011-03-14 18:14:40 -04:00
|
|
|
|
char *end;
|
2011-05-05 14:39:05 -04:00
|
|
|
|
long parsed = strtol($3, &end, 10);
|
2011-03-14 18:14:40 -04:00
|
|
|
|
if (parsed == LONG_MIN ||
|
|
|
|
|
parsed == LONG_MAX ||
|
|
|
|
|
parsed < 0 ||
|
|
|
|
|
(end && *end != '\0')) {
|
2011-05-05 14:39:05 -04:00
|
|
|
|
ELOG("Could not parse window id \"%s\"\n", $3);
|
2011-03-14 18:14:40 -04:00
|
|
|
|
} else {
|
|
|
|
|
current_match.id = parsed;
|
|
|
|
|
printf("window id as int = %d\n", current_match.id);
|
|
|
|
|
}
|
2010-06-02 11:20:32 -04:00
|
|
|
|
}
|
2010-06-02 17:32:05 -04:00
|
|
|
|
| TOK_MARK '=' STR
|
|
|
|
|
{
|
2011-05-05 14:39:05 -04:00
|
|
|
|
printf("criteria: mark = %s\n", $3);
|
|
|
|
|
current_match.mark = $3;
|
2010-06-02 17:32:05 -04:00
|
|
|
|
}
|
2011-06-08 17:34:08 -04:00
|
|
|
|
| TOK_TITLE '=' STR
|
|
|
|
|
{
|
|
|
|
|
printf("criteria: title = %s\n", $3);
|
|
|
|
|
current_match.title = $3;
|
|
|
|
|
}
|
2010-04-14 14:26:56 -04:00
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
operations:
|
2011-05-22 15:26:50 -04:00
|
|
|
|
operation
|
|
|
|
|
| operations ',' operation
|
2010-04-14 14:26:56 -04:00
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
operation:
|
|
|
|
|
exec
|
|
|
|
|
| exit
|
|
|
|
|
| restart
|
2010-06-30 09:31:29 -04:00
|
|
|
|
| reload
|
2010-11-12 12:41:54 -05:00
|
|
|
|
| border
|
2010-06-01 17:20:57 -04:00
|
|
|
|
| layout
|
2011-06-09 20:15:31 -04:00
|
|
|
|
| append_layout
|
2010-05-11 16:46:49 -04:00
|
|
|
|
| move
|
2010-04-16 09:30:07 -04:00
|
|
|
|
| workspace
|
2010-04-14 14:26:56 -04:00
|
|
|
|
| focus
|
|
|
|
|
| kill
|
2010-04-16 09:30:07 -04:00
|
|
|
|
| open
|
2010-04-17 13:29:44 -04:00
|
|
|
|
| fullscreen
|
2010-05-10 03:33:10 -04:00
|
|
|
|
| split
|
2011-06-09 20:06:47 -04:00
|
|
|
|
| floating
|
2010-06-02 17:32:05 -04:00
|
|
|
|
| mark
|
2010-06-30 13:47:23 -04:00
|
|
|
|
| resize
|
2010-11-20 12:40:25 -05:00
|
|
|
|
| nop
|
2011-06-09 20:38:07 -04:00
|
|
|
|
| mode
|
2010-04-14 14:26:56 -04:00
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
exec:
|
2011-05-22 15:26:50 -04:00
|
|
|
|
TOK_EXEC STR
|
2010-04-14 14:26:56 -04:00
|
|
|
|
{
|
2011-05-22 15:26:50 -04:00
|
|
|
|
printf("should execute %s\n", $2);
|
|
|
|
|
start_application($2);
|
|
|
|
|
free($2);
|
2010-04-14 14:26:56 -04:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
exit:
|
|
|
|
|
TOK_EXIT
|
|
|
|
|
{
|
|
|
|
|
printf("exit, bye bye\n");
|
2010-05-10 04:12:35 -04:00
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
2010-06-30 09:31:29 -04:00
|
|
|
|
reload:
|
|
|
|
|
TOK_RELOAD
|
|
|
|
|
{
|
|
|
|
|
printf("reloading\n");
|
2011-07-10 08:33:19 -04:00
|
|
|
|
kill_configerror_nagbar(false);
|
2010-06-30 09:31:29 -04:00
|
|
|
|
load_configuration(conn, NULL, true);
|
2011-03-19 17:26:15 -04:00
|
|
|
|
x_set_i3_atoms();
|
2010-06-30 09:31:29 -04: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 04:12:35 -04:00
|
|
|
|
restart:
|
|
|
|
|
TOK_RESTART
|
|
|
|
|
{
|
|
|
|
|
printf("restarting i3\n");
|
2010-12-30 15:43:34 -05:00
|
|
|
|
i3_restart(false);
|
2010-04-14 14:26:56 -04:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
focus:
|
|
|
|
|
TOK_FOCUS
|
|
|
|
|
{
|
2010-06-01 12:49:43 -04:00
|
|
|
|
owindow *current;
|
|
|
|
|
|
|
|
|
|
if (match_is_empty(¤t_match)) {
|
2011-06-08 17:34:08 -04: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 09:43:59 -05:00
|
|
|
|
break;
|
2010-06-01 12:49:43 -04:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-08 17:34:08 -04:00
|
|
|
|
int count = 0;
|
2010-06-01 12:49:43 -04:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
2011-07-14 17:43:57 -04:00
|
|
|
|
Con *ws = con_get_workspace(current->con);
|
|
|
|
|
workspace_show(ws->name);
|
2010-06-01 12:49:43 -04:00
|
|
|
|
LOG("focusing %p / %s\n", current->con, current->con->name);
|
|
|
|
|
con_focus(current->con);
|
2011-06-08 17:34:08 -04:00
|
|
|
|
count++;
|
2010-06-01 12:49:43 -04:00
|
|
|
|
}
|
2011-05-29 06:29:49 -04:00
|
|
|
|
|
2011-06-08 17:34:08 -04: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 06:29:49 -04:00
|
|
|
|
tree_render();
|
2010-04-14 14:26:56 -04:00
|
|
|
|
}
|
2011-06-08 14:49:49 -04: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 11:09:52 -04: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));
|
|
|
|
|
if (current->type == CT_FLOATING_CON)
|
|
|
|
|
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-09 19:36:33 -04:00
|
|
|
|
| TOK_FOCUS level
|
|
|
|
|
{
|
|
|
|
|
if ($2 == TOK_PARENT)
|
|
|
|
|
level_up();
|
|
|
|
|
else level_down();
|
|
|
|
|
|
|
|
|
|
tree_render();
|
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
2011-07-04 11:09:52 -04:00
|
|
|
|
window_mode:
|
|
|
|
|
TOK_TILING { $$ = TOK_TILING; }
|
|
|
|
|
| TOK_FLOATING { $$ = TOK_FLOATING; }
|
|
|
|
|
| TOK_MODE_TOGGLE { $$ = TOK_MODE_TOGGLE; }
|
|
|
|
|
;
|
|
|
|
|
|
2011-06-09 19:36:33 -04:00
|
|
|
|
level:
|
|
|
|
|
TOK_PARENT { $$ = TOK_PARENT; }
|
|
|
|
|
| TOK_CHILD { $$ = TOK_CHILD; }
|
2010-04-14 14:26:56 -04:00
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
kill:
|
2011-05-13 14:41:03 -04:00
|
|
|
|
TOK_KILL optional_kill_mode
|
2010-04-14 14:26:56 -04:00
|
|
|
|
{
|
|
|
|
|
owindow *current;
|
|
|
|
|
|
|
|
|
|
printf("killing!\n");
|
2010-04-17 13:29:44 -04:00
|
|
|
|
/* check if the match is empty, not if the result is empty */
|
2010-04-16 16:50:20 -04:00
|
|
|
|
if (match_is_empty(¤t_match))
|
2011-05-13 14:41:03 -04:00
|
|
|
|
tree_close_con($2);
|
2010-04-16 09:30:07 -04:00
|
|
|
|
else {
|
2010-04-17 13:29:44 -04:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
printf("matching: %p / %s\n", current->con, current->con->name);
|
2011-05-13 14:41:03 -04:00
|
|
|
|
tree_close(current->con, $2, false);
|
2010-04-17 13:29:44 -04:00
|
|
|
|
}
|
2010-04-16 09:30:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 06:29:49 -04:00
|
|
|
|
tree_render();
|
2010-04-16 09:30:07 -04:00
|
|
|
|
}
|
|
|
|
|
;
|
2010-04-14 14:26:56 -04:00
|
|
|
|
|
2011-05-13 14:41:03 -04:00
|
|
|
|
optional_kill_mode:
|
|
|
|
|
/* empty */ { $$ = KILL_WINDOW; }
|
2011-05-22 15:26:50 -04:00
|
|
|
|
| TOK_WINDOW { $$ = KILL_WINDOW; }
|
|
|
|
|
| TOK_CLIENT { $$ = KILL_CLIENT; }
|
2011-05-13 14:41:03 -04:00
|
|
|
|
;
|
|
|
|
|
|
2010-04-16 09:30:07 -04:00
|
|
|
|
workspace:
|
2011-06-10 10:03:59 -04:00
|
|
|
|
TOK_WORKSPACE TOK_NEXT
|
|
|
|
|
{
|
|
|
|
|
workspace_next();
|
|
|
|
|
tree_render();
|
|
|
|
|
}
|
|
|
|
|
| TOK_WORKSPACE TOK_PREV
|
|
|
|
|
{
|
|
|
|
|
workspace_prev();
|
|
|
|
|
tree_render();
|
|
|
|
|
}
|
|
|
|
|
| TOK_WORKSPACE STR
|
2010-04-16 09:30:07 -04:00
|
|
|
|
{
|
2011-05-22 15:26:50 -04:00
|
|
|
|
printf("should switch to workspace %s\n", $2);
|
|
|
|
|
workspace_show($2);
|
|
|
|
|
free($2);
|
2011-05-29 06:29:49 -04:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-04-16 09:30:07 -04:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
open:
|
|
|
|
|
TOK_OPEN
|
|
|
|
|
{
|
|
|
|
|
printf("opening new container\n");
|
2011-06-02 11:21:38 -04:00
|
|
|
|
Con *con = tree_open_con(NULL, NULL);
|
2011-03-06 17:26:02 -05:00
|
|
|
|
con_focus(con);
|
2011-02-01 09:43:59 -05:00
|
|
|
|
asprintf(&json_output, "{\"success\":true, \"id\":%ld}", (long int)con);
|
2011-05-29 06:29:49 -04:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-04-14 14:26:56 -04:00
|
|
|
|
}
|
|
|
|
|
;
|
2010-04-17 13:29:44 -04:00
|
|
|
|
|
|
|
|
|
fullscreen:
|
2011-06-10 12:27:20 -04:00
|
|
|
|
TOK_FULLSCREEN fullscreen_mode
|
2010-04-17 13:29:44 -04:00
|
|
|
|
{
|
2011-06-10 12:27:20 -04:00
|
|
|
|
printf("toggling fullscreen, mode = %s\n", ($2 == CF_OUTPUT ? "normal" : "global"));
|
2010-04-17 13:29:44 -04:00
|
|
|
|
owindow *current;
|
|
|
|
|
|
2011-05-15 13:43:35 -04:00
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
printf("matching: %p / %s\n", current->con, current->con->name);
|
2011-06-10 12:27:20 -04:00
|
|
|
|
con_toggle_fullscreen(current->con, $2);
|
2011-05-15 13:43:35 -04:00
|
|
|
|
}
|
2011-05-29 06:29:49 -04:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-04-17 13:29:44 -04:00
|
|
|
|
}
|
|
|
|
|
;
|
2010-05-09 18:06:24 -04:00
|
|
|
|
|
2011-06-10 12:27:20 -04:00
|
|
|
|
fullscreen_mode:
|
|
|
|
|
/* empty */ { $$ = CF_OUTPUT; }
|
|
|
|
|
| TOK_GLOBAL { $$ = CF_GLOBAL; }
|
|
|
|
|
;
|
|
|
|
|
|
2010-05-10 03:33:10 -04:00
|
|
|
|
split:
|
2011-06-09 20:25:14 -04:00
|
|
|
|
TOK_SPLIT split_direction
|
2010-05-10 03:33:10 -04:00
|
|
|
|
{
|
2010-05-10 04:12:35 -04:00
|
|
|
|
/* TODO: use matches */
|
2011-05-22 15:26:50 -04:00
|
|
|
|
printf("splitting in direction %c\n", $2);
|
|
|
|
|
tree_split(focused, ($2 == 'v' ? VERT : HORIZ));
|
2011-05-29 06:29:49 -04:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-05-10 03:33:10 -04:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
2011-06-09 20:25:14 -04:00
|
|
|
|
split_direction:
|
2011-05-05 14:39:05 -04:00
|
|
|
|
TOK_HORIZONTAL { $$ = 'h'; }
|
|
|
|
|
| 'h' { $$ = 'h'; }
|
|
|
|
|
| TOK_VERTICAL { $$ = 'v'; }
|
|
|
|
|
| 'v' { $$ = 'v'; }
|
2010-05-09 18:06:24 -04:00
|
|
|
|
;
|
2010-05-10 04:12:35 -04:00
|
|
|
|
|
2011-06-09 20:06:47 -04:00
|
|
|
|
floating:
|
|
|
|
|
TOK_FLOATING boolean
|
2010-05-10 04:12:35 -04:00
|
|
|
|
{
|
2011-05-15 14:10:25 -04:00
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
|
|
|
|
owindow *current;
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
printf("matching: %p / %s\n", current->con, current->con->name);
|
2011-05-22 15:26:50 -04:00
|
|
|
|
if ($2 == TOK_TOGGLE) {
|
2011-05-15 14:10:25 -04:00
|
|
|
|
printf("should toggle mode\n");
|
|
|
|
|
toggle_floating_mode(current->con, false);
|
2010-06-30 09:54:34 -04:00
|
|
|
|
} else {
|
2011-05-22 15:26:50 -04:00
|
|
|
|
printf("should switch mode to %s\n", ($2 == TOK_FLOATING ? "floating" : "tiling"));
|
2011-06-09 20:06:47 -04:00
|
|
|
|
if ($2 == TOK_ENABLE) {
|
2011-05-15 14:10:25 -04:00
|
|
|
|
floating_enable(current->con, false);
|
|
|
|
|
} else {
|
|
|
|
|
floating_disable(current->con, false);
|
|
|
|
|
}
|
2010-06-30 09:54:34 -04:00
|
|
|
|
}
|
2010-05-31 16:48:28 -04:00
|
|
|
|
}
|
2011-05-29 06:29:49 -04:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-05-10 04:12:35 -04:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
2011-06-09 20:06:47 -04:00
|
|
|
|
boolean:
|
|
|
|
|
TOK_ENABLE { $$ = TOK_ENABLE; }
|
|
|
|
|
| TOK_DISABLE { $$ = TOK_DISABLE; }
|
|
|
|
|
| TOK_TOGGLE { $$ = TOK_TOGGLE; }
|
2010-05-10 04:12:35 -04:00
|
|
|
|
;
|
|
|
|
|
|
2010-11-12 12:41:54 -05:00
|
|
|
|
border:
|
2011-05-22 15:26:50 -04:00
|
|
|
|
TOK_BORDER border_style
|
2010-11-12 12:41:54 -05:00
|
|
|
|
{
|
2011-05-22 15:26:50 -04:00
|
|
|
|
printf("border style should be changed to %d\n", $2);
|
2010-11-12 12:41:54 -05:00
|
|
|
|
owindow *current;
|
|
|
|
|
|
2011-05-15 13:43:35 -04:00
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
printf("matching: %p / %s\n", current->con, current->con->name);
|
2011-06-10 10:15:52 -04:00
|
|
|
|
if ($2 == TOK_TOGGLE) {
|
|
|
|
|
current->con->border_style++;
|
|
|
|
|
current->con->border_style %= 3;
|
|
|
|
|
} else current->con->border_style = $2;
|
2010-11-12 12:41:54 -05:00
|
|
|
|
}
|
2011-05-29 06:29:49 -04:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-11-12 12:41:54 -05:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
border_style:
|
2011-05-05 14:39:05 -04:00
|
|
|
|
TOK_NORMAL { $$ = BS_NORMAL; }
|
|
|
|
|
| TOK_NONE { $$ = BS_NONE; }
|
|
|
|
|
| TOK_1PIXEL { $$ = BS_1PIXEL; }
|
2011-06-10 10:15:52 -04:00
|
|
|
|
| TOK_TOGGLE { $$ = TOK_TOGGLE; }
|
2010-11-12 12:41:54 -05:00
|
|
|
|
;
|
|
|
|
|
|
2010-05-11 16:46:49 -04:00
|
|
|
|
move:
|
2011-05-22 15:26:50 -04:00
|
|
|
|
TOK_MOVE direction
|
2010-05-11 16:46:49 -04:00
|
|
|
|
{
|
2011-05-22 15:26:50 -04:00
|
|
|
|
printf("moving in direction %d\n", $2);
|
|
|
|
|
tree_move($2);
|
2011-05-29 06:29:49 -04:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-05-11 16:46:49 -04:00
|
|
|
|
}
|
2011-05-22 15:26:50 -04:00
|
|
|
|
| TOK_MOVE TOK_WORKSPACE STR
|
2010-06-30 16:23:32 -04:00
|
|
|
|
{
|
|
|
|
|
owindow *current;
|
|
|
|
|
|
2011-05-22 15:26:50 -04:00
|
|
|
|
printf("should move window to workspace %s\n", $3);
|
2010-06-30 16:23:32 -04:00
|
|
|
|
/* get the workspace */
|
2011-05-22 15:26:50 -04:00
|
|
|
|
Con *ws = workspace_get($3, NULL);
|
|
|
|
|
free($3);
|
2010-06-30 16:23:32 -04:00
|
|
|
|
|
2011-05-15 13:43:35 -04:00
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
printf("matching: %p / %s\n", current->con, current->con->name);
|
|
|
|
|
con_move_to_workspace(current->con, ws);
|
2010-06-30 16:23:32 -04:00
|
|
|
|
}
|
2011-05-29 06:29:49 -04:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-06-30 16:23:32 -04:00
|
|
|
|
}
|
2010-05-11 16:46:49 -04:00
|
|
|
|
;
|
|
|
|
|
|
2011-06-09 20:15:31 -04:00
|
|
|
|
append_layout:
|
|
|
|
|
TOK_APPEND_LAYOUT STR
|
2010-05-11 17:00:31 -04:00
|
|
|
|
{
|
2011-05-22 15:26:50 -04:00
|
|
|
|
printf("restoring \"%s\"\n", $2);
|
|
|
|
|
tree_append_json($2);
|
|
|
|
|
free($2);
|
2011-05-29 06:29:49 -04:00
|
|
|
|
tree_render();
|
2010-05-11 17:00:31 -04:00
|
|
|
|
}
|
|
|
|
|
;
|
2010-06-01 17:20:57 -04:00
|
|
|
|
|
|
|
|
|
layout:
|
2011-05-22 15:26:50 -04:00
|
|
|
|
TOK_LAYOUT layout_mode
|
2010-06-01 17:20:57 -04:00
|
|
|
|
{
|
2011-05-22 15:26:50 -04:00
|
|
|
|
printf("changing layout to %d\n", $2);
|
2010-06-01 17:20:57 -04:00
|
|
|
|
owindow *current;
|
|
|
|
|
|
2011-05-15 14:10:25 -04:00
|
|
|
|
/* check if the match is empty, not if the result is empty */
|
|
|
|
|
if (match_is_empty(¤t_match))
|
2011-05-22 15:26:50 -04:00
|
|
|
|
con_set_layout(focused->parent, $2);
|
2011-05-15 14:10:25 -04:00
|
|
|
|
else {
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
printf("matching: %p / %s\n", current->con, current->con->name);
|
2011-05-22 15:26:50 -04:00
|
|
|
|
con_set_layout(current->con, $2);
|
2011-05-15 14:10:25 -04:00
|
|
|
|
}
|
2011-05-15 13:43:35 -04:00
|
|
|
|
}
|
2011-05-29 06:29:49 -04:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-06-01 17:20:57 -04:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
layout_mode:
|
2011-05-05 14:39:05 -04:00
|
|
|
|
TOK_DEFAULT { $$ = L_DEFAULT; }
|
|
|
|
|
| TOK_STACKED { $$ = L_STACKED; }
|
|
|
|
|
| TOK_TABBED { $$ = L_TABBED; }
|
2010-06-01 17:20:57 -04:00
|
|
|
|
;
|
2010-06-02 17:32:05 -04:00
|
|
|
|
|
|
|
|
|
mark:
|
2011-05-22 15:26:50 -04:00
|
|
|
|
TOK_MARK STR
|
2010-06-02 17:32:05 -04:00
|
|
|
|
{
|
2011-05-22 15:26:50 -04:00
|
|
|
|
printf("marking window with str %s\n", $2);
|
2010-06-02 17:32:05 -04:00
|
|
|
|
owindow *current;
|
|
|
|
|
|
2011-05-15 13:43:35 -04:00
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
printf("matching: %p / %s\n", current->con, current->con->name);
|
2011-05-22 15:26:50 -04:00
|
|
|
|
current->con->mark = sstrdup($2);
|
2010-06-02 17:32:05 -04:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-22 15:26:50 -04:00
|
|
|
|
free($<string>2);
|
2011-05-29 06:29:49 -04:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-06-02 17:32:05 -04:00
|
|
|
|
}
|
|
|
|
|
;
|
2010-06-30 13:47:23 -04:00
|
|
|
|
|
2010-11-20 12:40:25 -05:00
|
|
|
|
nop:
|
2011-05-22 15:26:50 -04:00
|
|
|
|
TOK_NOP STR
|
2010-11-20 12:40:25 -05:00
|
|
|
|
{
|
|
|
|
|
printf("-------------------------------------------------\n");
|
2011-05-22 15:26:50 -04:00
|
|
|
|
printf(" NOP: %s\n", $2);
|
2010-11-20 12:40:25 -05:00
|
|
|
|
printf("-------------------------------------------------\n");
|
2011-05-22 15:26:50 -04:00
|
|
|
|
free($2);
|
2010-11-20 12:40:25 -05:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
2010-06-30 13:47:23 -04:00
|
|
|
|
resize:
|
2011-05-22 15:26:50 -04:00
|
|
|
|
TOK_RESIZE resize_way direction resize_px resize_tiling
|
2010-06-30 13:47:23 -04:00
|
|
|
|
{
|
|
|
|
|
/* resize <grow|shrink> <direction> [<px> px] [or <ppt> ppt] */
|
2011-05-22 15:26:50 -04: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 13:47:23 -04: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) {
|
|
|
|
|
focused->rect.height += px;
|
|
|
|
|
} else if (direction == TOK_LEFT) {
|
|
|
|
|
focused->rect.x -= px;
|
|
|
|
|
focused->rect.width += px;
|
|
|
|
|
} else {
|
|
|
|
|
focused->rect.width += px;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
LOG("tiling resize\n");
|
|
|
|
|
/* get the default percentage */
|
2010-11-28 16:45:39 -05:00
|
|
|
|
int children = con_num_children(focused->parent);
|
2010-06-30 13:47:23 -04: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) {
|
|
|
|
|
other = TAILQ_PREV(focused, nodes_head, nodes);
|
|
|
|
|
} else {
|
|
|
|
|
other = TAILQ_NEXT(focused, nodes);
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
LOG("focused->percent before = %f\n", focused->percent);
|
|
|
|
|
if (focused->percent == 0.0)
|
|
|
|
|
focused->percent = percentage;
|
|
|
|
|
if (other->percent == 0.0)
|
|
|
|
|
other->percent = percentage;
|
2011-08-02 16:31:45 -04:00
|
|
|
|
double new_focused_percent = focused->percent + ((double)ppt / 100.0);
|
|
|
|
|
double new_other_percent = other->percent - ((double)ppt / 100.0);
|
|
|
|
|
LOG("new_focused_percent = %f\n", new_focused_percent);
|
|
|
|
|
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. */
|
|
|
|
|
if (definitelyGreaterThan(new_focused_percent, 0.05, DBL_EPSILON) &&
|
|
|
|
|
definitelyGreaterThan(new_other_percent, 0.05, DBL_EPSILON)) {
|
|
|
|
|
focused->percent += ((double)ppt / 100.0);
|
|
|
|
|
other->percent -= ((double)ppt / 100.0);
|
|
|
|
|
LOG("focused->percent after = %f\n", focused->percent);
|
|
|
|
|
LOG("other->percent after = %f\n", other->percent);
|
|
|
|
|
} else {
|
|
|
|
|
LOG("Not resizing, already at minimum size\n");
|
|
|
|
|
}
|
2010-06-30 13:47:23 -04:00
|
|
|
|
}
|
2011-05-29 06:29:49 -04:00
|
|
|
|
|
|
|
|
|
tree_render();
|
2010-06-30 13:47:23 -04:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
resize_px:
|
|
|
|
|
/* empty */
|
|
|
|
|
{
|
2011-05-05 14:39:05 -04:00
|
|
|
|
$$ = 10;
|
2010-06-30 13:47:23 -04:00
|
|
|
|
}
|
2011-05-22 15:26:50 -04:00
|
|
|
|
| NUMBER TOK_PX
|
2010-06-30 13:47:23 -04:00
|
|
|
|
{
|
2011-05-22 15:26:50 -04:00
|
|
|
|
$$ = $1;
|
2010-06-30 13:47:23 -04:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
resize_tiling:
|
|
|
|
|
/* empty */
|
|
|
|
|
{
|
2011-05-05 14:39:05 -04:00
|
|
|
|
$$ = 10;
|
2010-06-30 13:47:23 -04:00
|
|
|
|
}
|
2011-05-22 15:26:50 -04:00
|
|
|
|
| TOK_OR NUMBER TOK_PPT
|
2010-06-30 13:47:23 -04:00
|
|
|
|
{
|
2011-05-22 15:26:50 -04:00
|
|
|
|
$$ = $2;
|
2010-06-30 13:47:23 -04:00
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
resize_way:
|
2011-05-05 14:39:05 -04:00
|
|
|
|
TOK_GROW { $$ = TOK_GROW; }
|
|
|
|
|
| TOK_SHRINK { $$ = TOK_SHRINK; }
|
2010-06-30 13:47:23 -04:00
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
direction:
|
2011-05-05 14:39:05 -04:00
|
|
|
|
TOK_UP { $$ = TOK_UP; }
|
|
|
|
|
| TOK_DOWN { $$ = TOK_DOWN; }
|
|
|
|
|
| TOK_LEFT { $$ = TOK_LEFT; }
|
|
|
|
|
| TOK_RIGHT { $$ = TOK_RIGHT; }
|
2010-06-30 13:47:23 -04:00
|
|
|
|
;
|
2011-06-09 20:38:07 -04:00
|
|
|
|
|
|
|
|
|
mode:
|
|
|
|
|
TOK_MODE STR
|
|
|
|
|
{
|
|
|
|
|
switch_mode($2);
|
|
|
|
|
}
|
|
|
|
|
;
|