Adaptions for API change in json-c v0.13

This commit is contained in:
Björn Esser 2017-12-14 17:14:47 +01:00
parent 8272a9bae0
commit 02da9c4e7c
No known key found for this signature in database
GPG key ID: F52E98007594C21D
7 changed files with 29 additions and 15 deletions

View file

@ -0,0 +1,16 @@
#ifndef _SWAY_JSON_HELPER_H
#define _SWAY_JSON_HELPER_H
#include <json-c/json.h>
// Macros for checking a specific version.
#define JSON_C_VERSION_013 (13 << 8)
// json-c v0.13 uses size_t for array_list_length().
#if defined(JSON_C_VERSION_NUM) && JSON_C_VERSION_NUM >= JSON_C_VERSION_013
typedef size_t json_ar_len_t;
#else
typedef int json_ar_len_t;
#endif
#endif // _SWAY_JSON_HELPER_H

View file

@ -1,4 +1,4 @@
#include <json-c/json.h>
#include "sway_json_helper.h"
#include "wlc/wlc.h"
void init_json_tree(int socketfd);

View file

@ -15,7 +15,6 @@
#include <stdlib.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <json-c/json.h>
#include <list.h>
#include <libinput.h>
#ifdef __linux__
@ -25,6 +24,7 @@ struct ucred {
gid_t gid;
};
#endif
#include "sway_json_helper.h"
#include "sway/ipc-json.h"
#include "sway/ipc-server.h"
#include "sway/security.h"
@ -724,7 +724,7 @@ void ipc_client_handle_command(struct ipc_client *client) {
}
// parse requested event types
for (int i = 0; i < json_object_array_length(request); i++) {
for (json_ar_len_t i = 0; i < json_object_array_length(request); i++) {
const char *event_type = json_object_get_string(json_object_array_get_idx(request, i));
if (strcmp(event_type, "workspace") == 0) {
client->subscribed_events |= event_mask(IPC_EVENT_WORKSPACE);

View file

@ -2,8 +2,8 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <json-c/json.h>
#include "sway_json_helper.h"
#include "swaybar/config.h"
#include "swaybar/status_line.h"
#include "log.h"
@ -70,8 +70,7 @@ static void parse_json(struct bar *bar, const char *text) {
bar->status->block_line = create_list();
int i;
for (i = 0; i < json_object_array_length(results); ++i) {
for (json_ar_len_t i = 0; i < json_object_array_length(results); ++i) {
json_object *full_text, *short_text, *color, *min_width, *align, *urgent;
json_object *name, *instance, *separator, *separator_block_width;
json_object *background, *border, *border_top, *border_bottom;

View file

@ -50,8 +50,7 @@ static json_object *get_focused_container_r(json_object *c) {
} else {
json_object *nodes, *node, *child;
json_object_object_get_ex(c, "nodes", &nodes);
int i;
for (i = 0; i < json_object_array_length(nodes); i++) {
for (json_ar_len_t i = 0; i < json_object_array_length(nodes); i++) {
node = json_object_array_get_idx(nodes, i);
if ((child = get_focused_container_r(node))) {
@ -60,7 +59,7 @@ static json_object *get_focused_container_r(json_object *c) {
}
json_object_object_get_ex(c, "floating_nodes", &nodes);
for (i = 0; i < json_object_array_length(nodes); i++) {
for (json_ar_len_t i = 0; i < json_object_array_length(nodes); i++) {
node = json_object_array_get_idx(nodes, i);
if ((child = get_focused_container_r(node))) {
@ -83,7 +82,7 @@ char *get_focused_output() {
if (!outputs) {
sway_abort("Unabled to get focused output. No nodes in tree.");
}
for (int i = 0; i < json_object_array_length(outputs); i++) {
for (json_ar_len_t i = 0; i < json_object_array_length(outputs); i++) {
output = json_object_array_get_idx(outputs, i);
if (get_focused_container_r(output)) {
@ -131,7 +130,7 @@ json_object *get_output_container(const char *output) {
json_object *outputs, *json_output, *name;
json_object_object_get_ex(tree, "nodes", &outputs);
for (int i = 0; i < json_object_array_length(outputs); i++) {
for (json_ar_len_t i = 0; i < json_object_array_length(outputs); i++) {
json_output = json_object_array_get_idx(outputs, i);
json_object_object_get_ex(json_output, "name", &name);

View file

@ -3,7 +3,6 @@
#include <xkbcommon/xkbcommon.h>
#include <xkbcommon/xkbcommon-names.h>
#include <security/pam_appl.h>
#include <json-c/json.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -13,6 +12,7 @@
#include <signal.h>
#include <stdbool.h>
#include <unistd.h>
#include "sway_json_helper.h"
#include "client/window.h"
#include "client/registry.h"
#include "client/cairo.h"
@ -584,7 +584,7 @@ int main(int argc, char **argv) {
for (i = 0; i < registry->outputs->length; ++i) {
if (displays_paths[i * 2] != NULL) {
for (int j = 0;; ++j) {
for (json_ar_len_t j = 0;; ++j) {
if (j >= json_object_array_length(json_outputs)) {
sway_log(L_ERROR, "%s is not an extant output", displays_paths[i * 2]);
exit(EXIT_FAILURE);

View file

@ -9,7 +9,7 @@
#include <sys/socket.h>
#include <ctype.h>
#include <unistd.h>
#include <json-c/json.h>
#include "sway_json_helper.h"
#include "stringop.h"
#include "ipc-client.h"
#include "readline.h"
@ -149,7 +149,7 @@ static void pretty_print_version(json_object *v) {
static void pretty_print_clipboard(json_object *v) {
if (success(v, true)) {
if (json_object_is_type(v, json_type_array)) {
for (int i = 0; i < json_object_array_length(v); ++i) {
for (json_ar_len_t i = 0; i < json_object_array_length(v); ++i) {
json_object *o = json_object_array_get_idx(v, i);
printf("%s\n", json_object_get_string(o));
}