Go to the documentation of this file.
13 #include <yajl/yajl_common.h>
14 #include <yajl/yajl_gen.h>
15 #include <yajl/yajl_parse.h>
16 #include <yajl/yajl_version.h>
57 static
int json_start_map(
void *
ctx) {
60 LOG(
"creating new swallow\n");
69 DLOG(
"New floating_node\n");
74 DLOG(
"Parent is workspace = %p\n", ws);
94 DLOG(
"Setting layout = L_SPLITH\n");
101 DLOG(
"sanity check: removing swallows specification from split container\n");
146 DLOG(
"Geometry not set, combining children\n");
172 LOG(
"Creating window\n");
179 LOG(
"Fixing floating node without CT_FLOATING_CON parent\n");
195 ELOG(
"Layout file is invalid: found an empty swallow definition.\n");
208 LOG(
"end of array\n");
223 LOG(
"focus (reverse) %d\n", mapping->
old_id);
228 LOG(
"got it! %p\n", con);
245 static int json_key(
void *
ctx,
const unsigned char *val,
size_t len) {
246 LOG(
"key: %.*s\n", (
int)len, val);
250 if (strcasecmp(
last_key,
"swallows") == 0)
253 if (strcasecmp(
last_key,
"gaps") == 0)
256 if (strcasecmp(
last_key,
"rect") == 0)
259 if (strcasecmp(
last_key,
"deco_rect") == 0)
262 if (strcasecmp(
last_key,
"window_rect") == 0)
265 if (strcasecmp(
last_key,
"geometry") == 0)
268 if (strcasecmp(
last_key,
"focus") == 0)
271 if (strcasecmp(
last_key,
"marks") == 0) {
280 LOG(
"string: %.*s for key %s\n", (
int)len, val,
last_key);
284 if (strcasecmp(
last_key,
"class") == 0) {
287 }
else if (strcasecmp(
last_key,
"instance") == 0) {
290 }
else if (strcasecmp(
last_key,
"window_role") == 0) {
293 }
else if (strcasecmp(
last_key,
"title") == 0) {
308 if (strcasecmp(
last_key,
"name") == 0) {
311 }
else if (strcasecmp(
last_key,
"title_format") == 0) {
314 }
else if (strcasecmp(
last_key,
"sticky_group") == 0) {
318 }
else if (strcasecmp(
last_key,
"orientation") == 0) {
327 if (strcasecmp(buf,
"none") == 0 ||
328 strcasecmp(buf,
"horizontal") == 0)
330 else if (strcasecmp(buf,
"vertical") == 0)
333 LOG(
"Unhandled orientation: %s\n", buf);
335 }
else if (strcasecmp(
last_key,
"border") == 0) {
338 if (strcasecmp(buf,
"none") == 0)
340 else if (strcasecmp(buf,
"1pixel") == 0) {
343 }
else if (strcasecmp(buf,
"pixel") == 0)
345 else if (strcasecmp(buf,
"normal") == 0)
348 LOG(
"Unhandled \"border\": %s\n", buf);
350 }
else if (strcasecmp(
last_key,
"type") == 0) {
353 if (strcasecmp(buf,
"root") == 0)
355 else if (strcasecmp(buf,
"output") == 0)
357 else if (strcasecmp(buf,
"con") == 0)
359 else if (strcasecmp(buf,
"floating_con") == 0)
361 else if (strcasecmp(buf,
"workspace") == 0)
363 else if (strcasecmp(buf,
"dockarea") == 0)
366 LOG(
"Unhandled \"type\": %s\n", buf);
368 }
else if (strcasecmp(
last_key,
"layout") == 0) {
371 if (strcasecmp(buf,
"default") == 0)
374 else if (strcasecmp(buf,
"stacked") == 0)
376 else if (strcasecmp(buf,
"tabbed") == 0)
378 else if (strcasecmp(buf,
"dockarea") == 0)
380 else if (strcasecmp(buf,
"output") == 0)
382 else if (strcasecmp(buf,
"splith") == 0)
384 else if (strcasecmp(buf,
"splitv") == 0)
387 LOG(
"Unhandled \"layout\": %s\n", buf);
389 }
else if (strcasecmp(
last_key,
"workspace_layout") == 0) {
392 if (strcasecmp(buf,
"default") == 0)
394 else if (strcasecmp(buf,
"stacked") == 0)
396 else if (strcasecmp(buf,
"tabbed") == 0)
399 LOG(
"Unhandled \"workspace_layout\": %s\n", buf);
401 }
else if (strcasecmp(
last_key,
"last_split_layout") == 0) {
404 if (strcasecmp(buf,
"splith") == 0)
406 else if (strcasecmp(buf,
"splitv") == 0)
409 LOG(
"Unhandled \"last_splitlayout\": %s\n", buf);
411 }
else if (strcasecmp(
last_key,
"mark") == 0) {
412 DLOG(
"Found deprecated key \"mark\".\n");
418 }
else if (strcasecmp(
last_key,
"floating") == 0) {
421 if (strcasecmp(buf,
"auto_off") == 0)
423 else if (strcasecmp(buf,
"auto_on") == 0)
425 else if (strcasecmp(buf,
"user_off") == 0)
427 else if (strcasecmp(buf,
"user_on") == 0)
430 }
else if (strcasecmp(
last_key,
"scratchpad_state") == 0) {
433 if (strcasecmp(buf,
"none") == 0)
435 else if (strcasecmp(buf,
"fresh") == 0)
437 else if (strcasecmp(buf,
"changed") == 0)
440 }
else if (strcasecmp(
last_key,
"previous_workspace_name") == 0) {
451 if (strcasecmp(
last_key,
"type") == 0)
454 if (strcasecmp(
last_key,
"fullscreen_mode") == 0)
457 if (strcasecmp(
last_key,
"num") == 0)
460 if (strcasecmp(
last_key,
"current_border_width") == 0)
463 if (strcasecmp(
last_key,
"depth") == 0)
485 else if (strcasecmp(
last_key,
"y") == 0)
487 else if (strcasecmp(
last_key,
"width") == 0)
489 else if (strcasecmp(
last_key,
"height") == 0)
493 DLOG(
"rect now: (%d, %d, %d, %d)\n",
497 if (strcasecmp(
last_key,
"id") == 0) {
501 if (strcasecmp(
last_key,
"dock") == 0) {
505 if (strcasecmp(
last_key,
"insert_where") == 0) {
511 if (strcasecmp(
last_key,
"inner") == 0)
513 else if (strcasecmp(
last_key,
"top") == 0)
515 else if (strcasecmp(
last_key,
"right") == 0)
517 else if (strcasecmp(
last_key,
"bottom") == 0)
519 else if (strcasecmp(
last_key,
"left") == 0)
528 if (strcasecmp(
last_key,
"focused") == 0 && val) {
532 if (strcasecmp(
last_key,
"sticky") == 0)
536 if (strcasecmp(
last_key,
"restart_mode") == 0) {
547 if (strcasecmp(
last_key,
"percent") == 0) {
570 DLOG(
"string = %.*s, last_key = %s\n", (
int)len, val,
last_key);
571 if (strncasecmp((
const char *)val,
"workspace", len) == 0)
582 yajl_handle hand = yajl_alloc(NULL, NULL, NULL);
584 yajl_config(hand, yajl_allow_comments,
true);
586 yajl_config(hand, yajl_allow_multiple_values,
true);
588 setlocale(LC_NUMERIC,
"C");
589 if (yajl_parse(hand, (
const unsigned char *)buf, len) != yajl_status_ok) {
590 unsigned char *str = yajl_get_error(hand, 1, (
const unsigned char *)buf, len);
591 ELOG(
"JSON parsing error: %s\n", str);
592 yajl_free_error(hand, str);
595 setlocale(LC_NUMERIC,
"");
597 yajl_complete_parse(hand);
612 static yajl_callbacks callbacks = {
620 yajl_handle hand = yajl_alloc(&callbacks, NULL, NULL);
622 yajl_config(hand, yajl_allow_comments,
true);
624 yajl_config(hand, yajl_allow_multiple_values,
true);
625 setlocale(LC_NUMERIC,
"C");
626 const yajl_status stat = yajl_parse(hand, (
const unsigned char *)buf, len);
627 if (stat != yajl_status_ok && stat != yajl_status_client_canceled) {
628 unsigned char *str = yajl_get_error(hand, 1, (
const unsigned char *)buf, len);
629 ELOG(
"JSON parsing error: %s\n", str);
630 yajl_free_error(hand, str);
633 setlocale(LC_NUMERIC,
"");
634 yajl_complete_parse(hand);
641 static yajl_callbacks callbacks = {
646 .yajl_start_map = json_start_map,
651 yajl_handle hand = yajl_alloc(&callbacks, NULL, NULL);
653 yajl_config(hand, yajl_allow_comments,
true);
655 yajl_config(hand, yajl_allow_multiple_values,
true);
666 yajl_config(hand, yajl_dont_validate_strings,
true);
678 setlocale(LC_NUMERIC,
"C");
679 const yajl_status stat = yajl_parse(hand, (
const unsigned char *)buf, len);
680 if (stat != yajl_status_ok) {
681 unsigned char *str = yajl_get_error(hand, 1, (
const unsigned char *)buf, len);
682 ELOG(
"JSON parsing error: %s\n", str);
683 if (errormsg != NULL)
684 *errormsg =
sstrdup((
const char *)str);
685 yajl_free_error(hand, str);
702 setlocale(LC_NUMERIC,
"");
703 yajl_complete_parse(hand);
struct Match * current_swallow
void x_con_init(Con *con)
Initializes the X11 part for the given container.
static bool swallow_is_empty
bool json_validate(const char *buf, const size_t len)
Returns true if the provided JSON could be parsed by yajl.
struct regex * regex_new(const char *pattern)
Creates a new 'regex' struct containing the given pattern and a PCRE compiled regular expression.
enum Con::@22 scratchpad_state
void match_init(Match *match)
Initializes the Match data structure.
void * srealloc(void *ptr, size_t size)
Safe-wrapper around realloc which exits if realloc returns NULL (meaning that there is no more memory...
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 bool parsing_geometry
static int json_end_array(void *ctx)
void floating_enable(Con *con, bool automatic)
Enables floating mode for the given container by detaching it from its parent, creating a new contain...
static TAILQ_HEAD(focus_mappings_head, focus_mapping)
static int json_key(void *ctx, const unsigned char *val, size_t len)
#define TAILQ_EMPTY(head)
long ws_name_to_number(const char *name)
Parses the workspace name as a number.
static json_content_t content_result
static bool parsing_swallows
void con_activate(Con *con)
Sets input focus to the given container and raises it to the top.
#define TAILQ_FOREACH_REVERSE(var, head, headname, field)
#define TAILQ_INSERT_HEAD(head, elm, field)
#define TAILQ_FIRST(head)
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.
static bool parsing_deco_rect
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
static int json_determine_content_shallower(void *ctx)
static int json_int(void *ctx, long long val)
enum Con::@21 floating
floating? (= not in tiling layout) This cannot be simply a bool because we want to keep track of whet...
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...
fullscreen_mode_t fullscreen_mode
void floating_check_size(Con *floating_con, bool prefer_height)
Called when a floating window is created or resized.
void con_mark(Con *con, const char *mark, mark_mode_t mode)
Assigns a mark to the container.
static int json_determine_content_string(void *ctx, const unsigned char *val, size_t len)
#define TAILQ_HEAD_INITIALIZER(head)
json_content_t json_determine_content(const char *buf, const size_t len)
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
void match_free(Match *match)
Frees the given match.
static int json_bool(void *ctx, int val)
static int json_string(void *ctx, const unsigned char *val, size_t len)
A "match" is a data structure which acts like a mask or expression to match certain windows or not.
bool rect_equals(Rect a, Rect b)
void * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
struct pending_marks * marks
static bool parsing_window_rect
static bool parsing_marks
gaps_t gaps
Only applicable for containers of type CT_WORKSPACE.
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
char * previous_workspace_name
Stores a copy of the name of the last used workspace for the workspace back-and-forth switching.
#define TAILQ_FOREACH(var, head, field)
static int json_end_map(void *ctx)
border_style_t border_style
#define TAILQ_ENTRY(type)
#define TAILQ_REMOVE(head, elm, field)
struct Rect geometry
the geometry this window requested when getting mapped
A 'Con' represents everything from the X11 root window down to a single X11 window.
static bool parsing_focus
static xcb_cursor_context_t * ctx
struct regex * window_role
bool con_is_split(Con *con)
Returns true if a container should be considered split.
static int json_determine_content_deeper(void *ctx)
void tree_append_json(Con *con, const char *buf, const size_t len, char **errormsg)
#define TAILQ_INSERT_TAIL(head, elm, field)
static int json_double(void *ctx, double val)
enum Match::@17 insert_where
char * title_format
The format with which the window's name should be displayed.
void con_free(Con *con)
Frees the specified container.
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
layout_t last_split_layout
Con * con_new_skeleton(Con *parent, i3Window *window)
Create a new container (and attach it to the given parent, if not NULL).
void con_fix_percent(Con *con)
Updates the percent attribute of the children of the given container.
Stores a rectangle, for example the size of a window, the child window etc.
char * sstrndup(const char *str, size_t size)
Safe-wrapper around strndup which exits if strndup returns NULL (meaning that there is no more memory...
layout_t workspace_layout