13 #include <yajl/yajl_common.h> 14 #include <yajl/yajl_gen.h> 15 #include <yajl/yajl_parse.h> 16 #include <yajl/yajl_version.h> 48 static
int json_start_map(
void *
ctx) {
51 LOG(
"creating new swallow\n");
54 current_swallow->
dock = M_DONTCHECK;
60 DLOG(
"New floating_node\n");
63 json_node->
name = NULL;
65 DLOG(
"Parent is workspace = %p\n", ws);
69 json_node->
name = NULL;
70 json_node->
parent = parent;
85 DLOG(
"Setting layout = L_SPLITH\n");
92 DLOG(
"sanity check: removing swallows specification from split container\n");
101 if (json_node->
type == CT_WORKSPACE) {
103 DLOG(
"Attaching workspace. name = %s\n", json_node->
name);
104 if (json_node->
name == NULL || strcmp(json_node->
name,
"") == 0) {
129 if (json_node->
type == CT_FLOATING_CON) {
136 const Rect zero = {0, 0, 0, 0};
137 if (memcmp(&(json_node->
rect), &zero,
sizeof(
Rect)) == 0) {
138 DLOG(
"Geometry not set, combining children\n");
162 LOG(
"Creating window\n");
164 json_node = json_node->
parent;
172 ELOG(
"Layout file is invalid: found an empty swallow definition.\n");
184 LOG(
"end of array\n");
199 LOG(
"focus (reverse) %d\n", mapping->
old_id);
204 LOG(
"got it! %p\n", con);
221 static int json_key(
void *
ctx,
const unsigned char *val,
size_t len) {
222 LOG(
"key: %.*s\n", (
int)len, val);
226 if (strcasecmp(
last_key,
"swallows") == 0)
229 if (strcasecmp(
last_key,
"rect") == 0)
232 if (strcasecmp(
last_key,
"deco_rect") == 0)
235 if (strcasecmp(
last_key,
"window_rect") == 0)
238 if (strcasecmp(
last_key,
"geometry") == 0)
241 if (strcasecmp(
last_key,
"focus") == 0)
244 if (strcasecmp(
last_key,
"marks") == 0) {
253 LOG(
"string: %.*s for key %s\n", (
int)len, val,
last_key);
257 if (strcasecmp(
last_key,
"class") == 0) {
260 }
else if (strcasecmp(
last_key,
"instance") == 0) {
263 }
else if (strcasecmp(
last_key,
"window_role") == 0) {
266 }
else if (strcasecmp(
last_key,
"title") == 0) {
280 if (strcasecmp(
last_key,
"name") == 0) {
282 memcpy(json_node->
name, val, len);
283 }
else if (strcasecmp(
last_key,
"title_format") == 0) {
286 }
else if (strcasecmp(
last_key,
"sticky_group") == 0) {
289 LOG(
"sticky_group of this container is %s\n", json_node->
sticky_group);
290 }
else if (strcasecmp(
last_key,
"orientation") == 0) {
299 if (strcasecmp(buf,
"none") == 0 ||
300 strcasecmp(buf,
"horizontal") == 0)
302 else if (strcasecmp(buf,
"vertical") == 0)
305 LOG(
"Unhandled orientation: %s\n", buf);
307 }
else if (strcasecmp(
last_key,
"border") == 0) {
310 if (strcasecmp(buf,
"none") == 0)
312 else if (strcasecmp(buf,
"1pixel") == 0) {
315 }
else if (strcasecmp(buf,
"pixel") == 0)
317 else if (strcasecmp(buf,
"normal") == 0)
320 LOG(
"Unhandled \"border\": %s\n", buf);
322 }
else if (strcasecmp(
last_key,
"type") == 0) {
325 if (strcasecmp(buf,
"root") == 0)
326 json_node->
type = CT_ROOT;
327 else if (strcasecmp(buf,
"output") == 0)
328 json_node->
type = CT_OUTPUT;
329 else if (strcasecmp(buf,
"con") == 0)
330 json_node->
type = CT_CON;
331 else if (strcasecmp(buf,
"floating_con") == 0)
332 json_node->
type = CT_FLOATING_CON;
333 else if (strcasecmp(buf,
"workspace") == 0)
334 json_node->
type = CT_WORKSPACE;
335 else if (strcasecmp(buf,
"dockarea") == 0)
336 json_node->
type = CT_DOCKAREA;
338 LOG(
"Unhandled \"type\": %s\n", buf);
340 }
else if (strcasecmp(
last_key,
"layout") == 0) {
343 if (strcasecmp(buf,
"default") == 0)
346 else if (strcasecmp(buf,
"stacked") == 0)
348 else if (strcasecmp(buf,
"tabbed") == 0)
350 else if (strcasecmp(buf,
"dockarea") == 0)
352 else if (strcasecmp(buf,
"output") == 0)
354 else if (strcasecmp(buf,
"splith") == 0)
356 else if (strcasecmp(buf,
"splitv") == 0)
359 LOG(
"Unhandled \"layout\": %s\n", buf);
361 }
else if (strcasecmp(
last_key,
"workspace_layout") == 0) {
364 if (strcasecmp(buf,
"default") == 0)
366 else if (strcasecmp(buf,
"stacked") == 0)
368 else if (strcasecmp(buf,
"tabbed") == 0)
371 LOG(
"Unhandled \"workspace_layout\": %s\n", buf);
373 }
else if (strcasecmp(
last_key,
"last_split_layout") == 0) {
376 if (strcasecmp(buf,
"splith") == 0)
378 else if (strcasecmp(buf,
"splitv") == 0)
381 LOG(
"Unhandled \"last_splitlayout\": %s\n", buf);
383 }
else if (strcasecmp(
last_key,
"mark") == 0) {
384 DLOG(
"Found deprecated key \"mark\".\n");
390 }
else if (strcasecmp(
last_key,
"floating") == 0) {
393 if (strcasecmp(buf,
"auto_off") == 0)
394 json_node->
floating = FLOATING_AUTO_OFF;
395 else if (strcasecmp(buf,
"auto_on") == 0)
396 json_node->
floating = FLOATING_AUTO_ON;
397 else if (strcasecmp(buf,
"user_off") == 0)
398 json_node->
floating = FLOATING_USER_OFF;
399 else if (strcasecmp(buf,
"user_on") == 0)
400 json_node->
floating = FLOATING_USER_ON;
402 }
else if (strcasecmp(
last_key,
"scratchpad_state") == 0) {
405 if (strcasecmp(buf,
"none") == 0)
407 else if (strcasecmp(buf,
"fresh") == 0)
409 else if (strcasecmp(buf,
"changed") == 0)
420 if (strcasecmp(
last_key,
"type") == 0)
421 json_node->
type = val;
423 if (strcasecmp(
last_key,
"fullscreen_mode") == 0)
426 if (strcasecmp(
last_key,
"num") == 0)
427 json_node->
num = val;
429 if (strcasecmp(
last_key,
"current_border_width") == 0)
432 if (strcasecmp(
last_key,
"depth") == 0)
433 json_node->
depth = val;
440 focus_mapping->
old_id = val;
447 r = &(json_node->
rect);
454 else if (strcasecmp(
last_key,
"y") == 0)
456 else if (strcasecmp(
last_key,
"width") == 0)
458 else if (strcasecmp(
last_key,
"height") == 0)
462 DLOG(
"rect now: (%d, %d, %d, %d)\n",
466 if (strcasecmp(
last_key,
"id") == 0) {
467 current_swallow->
id = val;
470 if (strcasecmp(
last_key,
"dock") == 0) {
471 current_swallow->
dock = val;
474 if (strcasecmp(
last_key,
"insert_where") == 0) {
485 if (strcasecmp(
last_key,
"focused") == 0 && val) {
489 if (strcasecmp(
last_key,
"sticky") == 0)
493 if (strcasecmp(
last_key,
"restart_mode") == 0) {
504 if (strcasecmp(
last_key,
"percent") == 0) {
524 if (strcasecmp(
last_key,
"type") != 0 || content_level > 1)
527 DLOG(
"string = %.*s, last_key = %s\n", (
int)len, val,
last_key);
528 if (strncasecmp((
const char *)val,
"workspace", len) == 0)
539 yajl_handle hand = yajl_alloc(NULL, NULL, NULL);
541 yajl_config(hand, yajl_allow_comments,
true);
543 yajl_config(hand, yajl_allow_multiple_values,
true);
545 setlocale(LC_NUMERIC,
"C");
546 if (yajl_parse(hand, (
const unsigned char *)buf, len) != yajl_status_ok) {
547 unsigned char *str = yajl_get_error(hand, 1, (
const unsigned char *)buf, len);
548 ELOG(
"JSON parsing error: %s\n", str);
549 yajl_free_error(hand, str);
552 setlocale(LC_NUMERIC,
"");
554 yajl_complete_parse(hand);
569 static yajl_callbacks callbacks = {
577 yajl_handle hand = yajl_alloc(&callbacks, NULL, NULL);
579 yajl_config(hand, yajl_allow_comments,
true);
581 yajl_config(hand, yajl_allow_multiple_values,
true);
582 setlocale(LC_NUMERIC,
"C");
583 const yajl_status stat = yajl_parse(hand, (
const unsigned char *)buf, len);
584 if (stat != yajl_status_ok && stat != yajl_status_client_canceled) {
585 unsigned char *str = yajl_get_error(hand, 1, (
const unsigned char *)buf, len);
586 ELOG(
"JSON parsing error: %s\n", str);
587 yajl_free_error(hand, str);
590 setlocale(LC_NUMERIC,
"");
591 yajl_complete_parse(hand);
598 static yajl_callbacks callbacks = {
603 .yajl_start_map = json_start_map,
608 yajl_handle hand = yajl_alloc(&callbacks, NULL, NULL);
610 yajl_config(hand, yajl_allow_comments,
true);
612 yajl_config(hand, yajl_allow_multiple_values,
true);
623 yajl_config(hand, yajl_dont_validate_strings,
true);
634 setlocale(LC_NUMERIC,
"C");
635 const yajl_status stat = yajl_parse(hand, (
const unsigned char *)buf, len);
636 if (stat != yajl_status_ok) {
637 unsigned char *str = yajl_get_error(hand, 1, (
const unsigned char *)buf, len);
638 ELOG(
"JSON parsing error: %s\n", str);
639 if (errormsg != NULL)
640 *errormsg =
sstrdup((
const char *)str);
641 yajl_free_error(hand, str);
644 DLOG(
"freeing incomplete container %p\n", json_node);
645 if (json_node == to_focus) {
658 setlocale(LC_NUMERIC,
"");
659 yajl_complete_parse(hand);
void con_free(Con *con)
Frees the specified container.
void con_fix_percent(Con *con)
Updates the percent attribute of the children of the given container.
void * srealloc(void *ptr, size_t size)
Safe-wrapper around realloc which exits if realloc returns NULL (meaning that there is no more memory...
static bool parsing_focus
struct Match * current_swallow
bool json_validate(const char *buf, const size_t len)
Returns true if the provided JSON could be parsed by yajl.
void * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
#define TAILQ_EMPTY(head)
static TAILQ_HEAD(focus_mappings_head, focus_mapping)
void * scalloc(size_t num, size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
static int json_key(void *ctx, const unsigned char *val, size_t len)
static json_content_t content_result
Con * con_new_skeleton(Con *parent, i3Window *window)
Create a new container (and attach it to the given parent, if not NULL).
static bool parsing_swallows
void match_free(Match *match)
Frees the given match.
static bool parsing_geometry
static bool parsing_window_rect
static bool parsing_marks
void x_con_init(Con *con)
Initializes the X11 part for the given container.
layout_t workspace_layout
static int json_string(void *ctx, const unsigned char *val, size_t len)
#define TAILQ_FOREACH_REVERSE(var, head, headname, field)
A "match" is a data structure which acts like a mask or expression to match certain windows or not...
enum Match::@17 insert_where
#define TAILQ_INSERT_HEAD(head, elm, field)
void con_mark(Con *con, const char *mark, mark_mode_t mode)
Assigns a mark to the container.
struct regex * window_role
static int json_end_map(void *ctx)
#define TAILQ_REMOVE(head, elm, field)
static bool parsing_deco_rect
static int json_determine_content_shallower(void *ctx)
#define TAILQ_FIRST(head)
int sasprintf(char **strp, const char *fmt,...)
Safe-wrapper around asprintf which exits if it returns -1 (meaning that there is no more memory avail...
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
static bool swallow_is_empty
Stores a rectangle, for example the size of a window, the child window etc.
long ws_name_to_number(const char *name)
Parses the workspace name as a number.
layout_t last_split_layout
static int json_determine_content_string(void *ctx, const unsigned char *val, size_t len)
struct Rect geometry
the geometry this window requested when getting mapped
json_content_t json_determine_content(const char *buf, const size_t len)
#define TAILQ_ENTRY(type)
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
bool con_is_split(Con *con)
Returns true if a container should be considered split.
void floating_check_size(Con *floating_con)
Called when a floating window is created or resized.
static xcb_cursor_context_t * ctx
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
enum Con::@21 floating
floating? (= not in tiling layout) This cannot be simply a bool because we want to keep track of whet...
Con * get_existing_workspace_by_name(const char *name)
Returns the workspace with the given name or NULL if such a workspace does not exist.
enum Con::@22 scratchpad_state
static int json_int(void *ctx, long long val)
A 'Con' represents everything from the X11 root window down to a single X11 window.
static int json_determine_content_deeper(void *ctx)
static int json_end_array(void *ctx)
static int json_double(void *ctx, double val)
char * title_format
The format with which the window's name should be displayed.
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
void con_activate(Con *con)
Sets input focus to the given container and raises it to the top.
static int json_bool(void *ctx, int val)
void match_init(Match *match)
Initializes the Match data structure.
void tree_append_json(Con *con, const char *buf, const size_t len, char **errormsg)
struct regex * regex_new(const char *pattern)
Creates a new 'regex' struct containing the given pattern and a PCRE compiled regular expression...
#define TAILQ_HEAD_INITIALIZER(head)
#define TAILQ_INSERT_TAIL(head, elm, field)
#define TAILQ_FOREACH(var, head, field)
fullscreen_mode_t fullscreen_mode
border_style_t border_style