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");
144 const Rect zero = {0, 0, 0, 0};
146 DLOG(
"Geometry not set, combining children\n");
172 LOG(
"Creating window\n");
182 ELOG(
"Layout file is invalid: found an empty swallow definition.\n");
194 LOG(
"end of array\n");
209 LOG(
"focus (reverse) %d\n", mapping->
old_id);
214 LOG(
"got it! %p\n", con);
231 static int json_key(
void *
ctx,
const unsigned char *val,
size_t len) {
232 LOG(
"key: %.*s\n", (
int)len, val);
236 if (strcasecmp(
last_key,
"swallows") == 0)
239 if (strcasecmp(
last_key,
"rect") == 0)
242 if (strcasecmp(
last_key,
"deco_rect") == 0)
245 if (strcasecmp(
last_key,
"window_rect") == 0)
248 if (strcasecmp(
last_key,
"geometry") == 0)
251 if (strcasecmp(
last_key,
"focus") == 0)
254 if (strcasecmp(
last_key,
"marks") == 0) {
263 LOG(
"string: %.*s for key %s\n", (
int)len, val,
last_key);
267 if (strcasecmp(
last_key,
"class") == 0) {
270 }
else if (strcasecmp(
last_key,
"instance") == 0) {
273 }
else if (strcasecmp(
last_key,
"window_role") == 0) {
276 }
else if (strcasecmp(
last_key,
"title") == 0) {
291 if (strcasecmp(
last_key,
"name") == 0) {
294 }
else if (strcasecmp(
last_key,
"title_format") == 0) {
297 }
else if (strcasecmp(
last_key,
"sticky_group") == 0) {
301 }
else if (strcasecmp(
last_key,
"orientation") == 0) {
310 if (strcasecmp(buf,
"none") == 0 ||
311 strcasecmp(buf,
"horizontal") == 0)
313 else if (strcasecmp(buf,
"vertical") == 0)
316 LOG(
"Unhandled orientation: %s\n", buf);
318 }
else if (strcasecmp(
last_key,
"border") == 0) {
321 if (strcasecmp(buf,
"none") == 0)
323 else if (strcasecmp(buf,
"1pixel") == 0) {
326 }
else if (strcasecmp(buf,
"pixel") == 0)
328 else if (strcasecmp(buf,
"normal") == 0)
331 LOG(
"Unhandled \"border\": %s\n", buf);
333 }
else if (strcasecmp(
last_key,
"type") == 0) {
336 if (strcasecmp(buf,
"root") == 0)
338 else if (strcasecmp(buf,
"output") == 0)
340 else if (strcasecmp(buf,
"con") == 0)
342 else if (strcasecmp(buf,
"floating_con") == 0)
344 else if (strcasecmp(buf,
"workspace") == 0)
346 else if (strcasecmp(buf,
"dockarea") == 0)
349 LOG(
"Unhandled \"type\": %s\n", buf);
351 }
else if (strcasecmp(
last_key,
"layout") == 0) {
354 if (strcasecmp(buf,
"default") == 0)
357 else if (strcasecmp(buf,
"stacked") == 0)
359 else if (strcasecmp(buf,
"tabbed") == 0)
361 else if (strcasecmp(buf,
"dockarea") == 0)
363 else if (strcasecmp(buf,
"output") == 0)
365 else if (strcasecmp(buf,
"splith") == 0)
367 else if (strcasecmp(buf,
"splitv") == 0)
370 LOG(
"Unhandled \"layout\": %s\n", buf);
372 }
else if (strcasecmp(
last_key,
"workspace_layout") == 0) {
375 if (strcasecmp(buf,
"default") == 0)
377 else if (strcasecmp(buf,
"stacked") == 0)
379 else if (strcasecmp(buf,
"tabbed") == 0)
382 LOG(
"Unhandled \"workspace_layout\": %s\n", buf);
384 }
else if (strcasecmp(
last_key,
"last_split_layout") == 0) {
387 if (strcasecmp(buf,
"splith") == 0)
389 else if (strcasecmp(buf,
"splitv") == 0)
392 LOG(
"Unhandled \"last_splitlayout\": %s\n", buf);
394 }
else if (strcasecmp(
last_key,
"mark") == 0) {
395 DLOG(
"Found deprecated key \"mark\".\n");
401 }
else if (strcasecmp(
last_key,
"floating") == 0) {
404 if (strcasecmp(buf,
"auto_off") == 0)
406 else if (strcasecmp(buf,
"auto_on") == 0)
408 else if (strcasecmp(buf,
"user_off") == 0)
410 else if (strcasecmp(buf,
"user_on") == 0)
413 }
else if (strcasecmp(
last_key,
"scratchpad_state") == 0) {
416 if (strcasecmp(buf,
"none") == 0)
418 else if (strcasecmp(buf,
"fresh") == 0)
420 else if (strcasecmp(buf,
"changed") == 0)
423 }
else if (strcasecmp(
last_key,
"previous_workspace_name") == 0) {
434 if (strcasecmp(
last_key,
"type") == 0)
437 if (strcasecmp(
last_key,
"fullscreen_mode") == 0)
440 if (strcasecmp(
last_key,
"num") == 0)
443 if (strcasecmp(
last_key,
"current_border_width") == 0)
446 if (strcasecmp(
last_key,
"depth") == 0)
468 else if (strcasecmp(
last_key,
"y") == 0)
470 else if (strcasecmp(
last_key,
"width") == 0)
472 else if (strcasecmp(
last_key,
"height") == 0)
476 DLOG(
"rect now: (%d, %d, %d, %d)\n",
480 if (strcasecmp(
last_key,
"id") == 0) {
484 if (strcasecmp(
last_key,
"dock") == 0) {
488 if (strcasecmp(
last_key,
"insert_where") == 0) {
499 if (strcasecmp(
last_key,
"focused") == 0 && val) {
503 if (strcasecmp(
last_key,
"sticky") == 0)
507 if (strcasecmp(
last_key,
"restart_mode") == 0) {
518 if (strcasecmp(
last_key,
"percent") == 0) {
541 DLOG(
"string = %.*s, last_key = %s\n", (
int)len, val,
last_key);
542 if (strncasecmp((
const char *)val,
"workspace", len) == 0)
553 yajl_handle hand = yajl_alloc(NULL, NULL, NULL);
555 yajl_config(hand, yajl_allow_comments,
true);
557 yajl_config(hand, yajl_allow_multiple_values,
true);
559 setlocale(LC_NUMERIC,
"C");
560 if (yajl_parse(hand, (
const unsigned char *)buf, len) != yajl_status_ok) {
561 unsigned char *str = yajl_get_error(hand, 1, (
const unsigned char *)buf, len);
562 ELOG(
"JSON parsing error: %s\n", str);
563 yajl_free_error(hand, str);
566 setlocale(LC_NUMERIC,
"");
568 yajl_complete_parse(hand);
583 static yajl_callbacks callbacks = {
591 yajl_handle hand = yajl_alloc(&callbacks, NULL, NULL);
593 yajl_config(hand, yajl_allow_comments,
true);
595 yajl_config(hand, yajl_allow_multiple_values,
true);
596 setlocale(LC_NUMERIC,
"C");
597 const yajl_status stat = yajl_parse(hand, (
const unsigned char *)buf, len);
598 if (stat != yajl_status_ok && stat != yajl_status_client_canceled) {
599 unsigned char *str = yajl_get_error(hand, 1, (
const unsigned char *)buf, len);
600 ELOG(
"JSON parsing error: %s\n", str);
601 yajl_free_error(hand, str);
604 setlocale(LC_NUMERIC,
"");
605 yajl_complete_parse(hand);
612 static yajl_callbacks callbacks = {
617 .yajl_start_map = json_start_map,
622 yajl_handle hand = yajl_alloc(&callbacks, NULL, NULL);
624 yajl_config(hand, yajl_allow_comments,
true);
626 yajl_config(hand, yajl_allow_multiple_values,
true);
637 yajl_config(hand, yajl_dont_validate_strings,
true);
648 setlocale(LC_NUMERIC,
"C");
649 const yajl_status stat = yajl_parse(hand, (
const unsigned char *)buf, len);
650 if (stat != yajl_status_ok) {
651 unsigned char *str = yajl_get_error(hand, 1, (
const unsigned char *)buf, len);
652 ELOG(
"JSON parsing error: %s\n", str);
653 if (errormsg != NULL)
654 *errormsg =
sstrdup((
const char *)str);
655 yajl_free_error(hand, str);
672 setlocale(LC_NUMERIC,
"");
673 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.
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
layout_t workspace_layout
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...
void floating_check_size(Con *floating_con, bool prefer_height)
Called when a floating window is created or resized.
void * srealloc(void *ptr, size_t size)
Safe-wrapper around realloc which exits if realloc returns NULL (meaning that there is no more memory...
struct regex * window_role
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.
layout_t last_split_layout
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.
static int json_string(void *ctx, const unsigned char *val, size_t len)
#define TAILQ_FOREACH_REVERSE(var, head, headname, field)
Stores a rectangle, for example the size of a window, the child window etc.
#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.
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)
enum Con::@22 scratchpad_state
A 'Con' represents everything from the X11 root window down to a single X11 window.
#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
long ws_name_to_number(const char *name)
Parses the workspace name as a number.
static int json_determine_content_string(void *ctx, const unsigned char *val, size_t len)
fullscreen_mode_t fullscreen_mode
json_content_t json_determine_content(const char *buf, const size_t len)
#define TAILQ_ENTRY(type)
struct pending_marks * marks
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.
border_style_t border_style
char * title_format
The format with which the window's name should be displayed.
static xcb_cursor_context_t * ctx
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_int(void *ctx, long long val)
struct Rect geometry
the geometry this window requested when getting mapped
A "match" is a data structure which acts like a mask or expression to match certain windows or not...
enum Con::@21 floating
floating? (= not in tiling layout) This cannot be simply a bool because we want to keep track of whet...
static int json_determine_content_deeper(void *ctx)
static int json_end_array(void *ctx)
char * previous_workspace_name
Stores a copy of the name of the last used workspace for the workspace back-and-forth switching...
static int json_double(void *ctx, double val)
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)
enum Match::@17 insert_where