13 #include <yajl/yajl_common.h> 14 #include <yajl/yajl_gen.h> 15 #include <yajl/yajl_parse.h> 16 #include <yajl/yajl_version.h> 56 static
int json_start_map(
void *
ctx) {
59 LOG(
"creating new swallow\n");
68 DLOG(
"New floating_node\n");
73 DLOG(
"Parent is workspace = %p\n", ws);
93 DLOG(
"Setting layout = L_SPLITH\n");
100 DLOG(
"sanity check: removing swallows specification from split container\n");
145 DLOG(
"Geometry not set, combining children\n");
171 LOG(
"Creating window\n");
181 ELOG(
"Layout file is invalid: found an empty swallow definition.\n");
193 LOG(
"end of array\n");
208 LOG(
"focus (reverse) %d\n", mapping->
old_id);
213 LOG(
"got it! %p\n", con);
230 static int json_key(
void *
ctx,
const unsigned char *val,
size_t len) {
231 LOG(
"key: %.*s\n", (
int)len, val);
235 if (strcasecmp(
last_key,
"swallows") == 0)
238 if (strcasecmp(
last_key,
"rect") == 0)
241 if (strcasecmp(
last_key,
"deco_rect") == 0)
244 if (strcasecmp(
last_key,
"window_rect") == 0)
247 if (strcasecmp(
last_key,
"geometry") == 0)
250 if (strcasecmp(
last_key,
"focus") == 0)
253 if (strcasecmp(
last_key,
"marks") == 0) {
262 LOG(
"string: %.*s for key %s\n", (
int)len, val,
last_key);
266 if (strcasecmp(
last_key,
"class") == 0) {
269 }
else if (strcasecmp(
last_key,
"instance") == 0) {
272 }
else if (strcasecmp(
last_key,
"window_role") == 0) {
275 }
else if (strcasecmp(
last_key,
"title") == 0) {
290 if (strcasecmp(
last_key,
"name") == 0) {
293 }
else if (strcasecmp(
last_key,
"title_format") == 0) {
296 }
else if (strcasecmp(
last_key,
"sticky_group") == 0) {
300 }
else if (strcasecmp(
last_key,
"orientation") == 0) {
309 if (strcasecmp(buf,
"none") == 0 ||
310 strcasecmp(buf,
"horizontal") == 0)
312 else if (strcasecmp(buf,
"vertical") == 0)
315 LOG(
"Unhandled orientation: %s\n", buf);
317 }
else if (strcasecmp(
last_key,
"border") == 0) {
320 if (strcasecmp(buf,
"none") == 0)
322 else if (strcasecmp(buf,
"1pixel") == 0) {
325 }
else if (strcasecmp(buf,
"pixel") == 0)
327 else if (strcasecmp(buf,
"normal") == 0)
330 LOG(
"Unhandled \"border\": %s\n", buf);
332 }
else if (strcasecmp(
last_key,
"type") == 0) {
335 if (strcasecmp(buf,
"root") == 0)
337 else if (strcasecmp(buf,
"output") == 0)
339 else if (strcasecmp(buf,
"con") == 0)
341 else if (strcasecmp(buf,
"floating_con") == 0)
343 else if (strcasecmp(buf,
"workspace") == 0)
345 else if (strcasecmp(buf,
"dockarea") == 0)
348 LOG(
"Unhandled \"type\": %s\n", buf);
350 }
else if (strcasecmp(
last_key,
"layout") == 0) {
353 if (strcasecmp(buf,
"default") == 0)
356 else if (strcasecmp(buf,
"stacked") == 0)
358 else if (strcasecmp(buf,
"tabbed") == 0)
360 else if (strcasecmp(buf,
"dockarea") == 0)
362 else if (strcasecmp(buf,
"output") == 0)
364 else if (strcasecmp(buf,
"splith") == 0)
366 else if (strcasecmp(buf,
"splitv") == 0)
369 LOG(
"Unhandled \"layout\": %s\n", buf);
371 }
else if (strcasecmp(
last_key,
"workspace_layout") == 0) {
374 if (strcasecmp(buf,
"default") == 0)
376 else if (strcasecmp(buf,
"stacked") == 0)
378 else if (strcasecmp(buf,
"tabbed") == 0)
381 LOG(
"Unhandled \"workspace_layout\": %s\n", buf);
383 }
else if (strcasecmp(
last_key,
"last_split_layout") == 0) {
386 if (strcasecmp(buf,
"splith") == 0)
388 else if (strcasecmp(buf,
"splitv") == 0)
391 LOG(
"Unhandled \"last_splitlayout\": %s\n", buf);
393 }
else if (strcasecmp(
last_key,
"mark") == 0) {
394 DLOG(
"Found deprecated key \"mark\".\n");
400 }
else if (strcasecmp(
last_key,
"floating") == 0) {
403 if (strcasecmp(buf,
"auto_off") == 0)
405 else if (strcasecmp(buf,
"auto_on") == 0)
407 else if (strcasecmp(buf,
"user_off") == 0)
409 else if (strcasecmp(buf,
"user_on") == 0)
412 }
else if (strcasecmp(
last_key,
"scratchpad_state") == 0) {
415 if (strcasecmp(buf,
"none") == 0)
417 else if (strcasecmp(buf,
"fresh") == 0)
419 else if (strcasecmp(buf,
"changed") == 0)
422 }
else if (strcasecmp(
last_key,
"previous_workspace_name") == 0) {
433 if (strcasecmp(
last_key,
"type") == 0)
436 if (strcasecmp(
last_key,
"fullscreen_mode") == 0)
439 if (strcasecmp(
last_key,
"num") == 0)
442 if (strcasecmp(
last_key,
"current_border_width") == 0)
445 if (strcasecmp(
last_key,
"depth") == 0)
467 else if (strcasecmp(
last_key,
"y") == 0)
469 else if (strcasecmp(
last_key,
"width") == 0)
471 else if (strcasecmp(
last_key,
"height") == 0)
475 DLOG(
"rect now: (%d, %d, %d, %d)\n",
479 if (strcasecmp(
last_key,
"id") == 0) {
483 if (strcasecmp(
last_key,
"dock") == 0) {
487 if (strcasecmp(
last_key,
"insert_where") == 0) {
498 if (strcasecmp(
last_key,
"focused") == 0 && val) {
502 if (strcasecmp(
last_key,
"sticky") == 0)
506 if (strcasecmp(
last_key,
"restart_mode") == 0) {
517 if (strcasecmp(
last_key,
"percent") == 0) {
540 DLOG(
"string = %.*s, last_key = %s\n", (
int)len, val,
last_key);
541 if (strncasecmp((
const char *)val,
"workspace", len) == 0)
552 yajl_handle hand = yajl_alloc(NULL, NULL, NULL);
554 yajl_config(hand, yajl_allow_comments,
true);
556 yajl_config(hand, yajl_allow_multiple_values,
true);
558 setlocale(LC_NUMERIC,
"C");
559 if (yajl_parse(hand, (
const unsigned char *)buf, len) != yajl_status_ok) {
560 unsigned char *str = yajl_get_error(hand, 1, (
const unsigned char *)buf, len);
561 ELOG(
"JSON parsing error: %s\n", str);
562 yajl_free_error(hand, str);
565 setlocale(LC_NUMERIC,
"");
567 yajl_complete_parse(hand);
582 static yajl_callbacks callbacks = {
590 yajl_handle hand = yajl_alloc(&callbacks, NULL, NULL);
592 yajl_config(hand, yajl_allow_comments,
true);
594 yajl_config(hand, yajl_allow_multiple_values,
true);
595 setlocale(LC_NUMERIC,
"C");
596 const yajl_status stat = yajl_parse(hand, (
const unsigned char *)buf, len);
597 if (stat != yajl_status_ok && stat != yajl_status_client_canceled) {
598 unsigned char *str = yajl_get_error(hand, 1, (
const unsigned char *)buf, len);
599 ELOG(
"JSON parsing error: %s\n", str);
600 yajl_free_error(hand, str);
603 setlocale(LC_NUMERIC,
"");
604 yajl_complete_parse(hand);
611 static yajl_callbacks callbacks = {
616 .yajl_start_map = json_start_map,
621 yajl_handle hand = yajl_alloc(&callbacks, NULL, NULL);
623 yajl_config(hand, yajl_allow_comments,
true);
625 yajl_config(hand, yajl_allow_multiple_values,
true);
636 yajl_config(hand, yajl_dont_validate_strings,
true);
647 setlocale(LC_NUMERIC,
"C");
648 const yajl_status stat = yajl_parse(hand, (
const unsigned char *)buf, len);
649 if (stat != yajl_status_ok) {
650 unsigned char *str = yajl_get_error(hand, 1, (
const unsigned char *)buf, len);
651 ELOG(
"JSON parsing error: %s\n", str);
652 if (errormsg != NULL)
653 *errormsg =
sstrdup((
const char *)str);
654 yajl_free_error(hand, str);
671 setlocale(LC_NUMERIC,
"");
672 yajl_complete_parse(hand);
void con_free(Con *con)
Frees the specified container.
static int json_string(void *ctx, const unsigned char *val, size_t len)
Stores a rectangle, for example the size of a window, the child window etc.
void con_fix_percent(Con *con)
Updates the percent attribute of the children of the given container.
void tree_append_json(Con *con, const char *buf, const size_t len, char **errormsg)
#define TAILQ_HEAD_INITIALIZER(head)
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...
#define TAILQ_FOREACH(var, head, field)
bool json_validate(const char *buf, const size_t len)
Returns true if the provided JSON could be parsed by yajl.
static bool parsing_focus
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 int json_end_array(void *ctx)
layout_t last_split_layout
static bool parsing_swallows
void x_con_init(Con *con)
Initializes the X11 part for the given container.
char * title_format
The format with which the window's name should be displayed.
Con * con_new_skeleton(Con *parent, i3Window *window)
Create a new container (and attach it to the given parent, if not NULL).
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...
static int json_key(void *ctx, const unsigned char *val, size_t len)
static bool parsing_marks
static json_content_t content_result
void match_free(Match *match)
Frees the given match.
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 int json_double(void *ctx, double val)
enum Con::@21 floating
floating? (= not in tiling layout) This cannot be simply a bool because we want to keep track of whet...
long ws_name_to_number(const char *name)
Parses the workspace name as a number.
void con_mark(Con *con, const char *mark, mark_mode_t mode)
Assigns a mark to the container.
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
char * previous_workspace_name
Stores a copy of the name of the last used workspace for the workspace back-and-forth switching...
struct pending_marks * marks
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
#define TAILQ_EMPTY(head)
bool rect_equals(Rect a, Rect b)
static TAILQ_HEAD(focus_mappings_head, focus_mapping)
static int json_end_map(void *ctx)
#define TAILQ_INSERT_HEAD(head, elm, field)
bool con_is_split(Con *con)
Returns true if a container should be considered split.
layout_t workspace_layout
void match_init(Match *match)
Initializes the Match data structure.
#define TAILQ_FOREACH_REVERSE(var, head, headname, field)
enum Match::@17 insert_where
static bool parsing_window_rect
void floating_check_size(Con *floating_con, bool prefer_height)
Called when a floating window is created or resized.
fullscreen_mode_t fullscreen_mode
struct Match * current_swallow
static int json_determine_content_string(void *ctx, const unsigned char *val, size_t len)
struct regex * window_role
border_style_t border_style
#define TAILQ_ENTRY(type)
static int json_determine_content_shallower(void *ctx)
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_determine_content_deeper(void *ctx)
#define TAILQ_INSERT_TAIL(head, elm, field)
static int json_int(void *ctx, long long val)
static bool swallow_is_empty
static bool parsing_geometry
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 * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
json_content_t json_determine_content(const char *buf, const size_t len)
void con_activate(Con *con)
Sets input focus to the given container and raises it to the top.
A "match" is a data structure which acts like a mask or expression to match certain windows or not...
#define TAILQ_FIRST(head)
static bool parsing_deco_rect
static int json_bool(void *ctx, int val)
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
#define TAILQ_REMOVE(head, elm, field)
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
static xcb_cursor_context_t * ctx