Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swaymsg is incompatible with json-c-0.14 #5349

Closed
JusterK opened this issue May 16, 2020 · 8 comments
Closed

swaymsg is incompatible with json-c-0.14 #5349

JusterK opened this issue May 16, 2020 · 8 comments

Comments

@JusterK
Copy link

JusterK commented May 16, 2020

On sway version 1.4 swaymsg -t get_outputs shows no outputs, when it's compiled with json-c-0.14. The version json-c-0.13.1 works fine though.

% swaymsg -t get_outputs
Output DP-1 '(null) (null) (null)' (inactive)

Output HDMI-A-1 '(null) (null) (null)' (inactive)

Also see this https://github.com/Alexays/Waybar/issues/709 bug.

@sfar9999
Copy link

sfar9999 commented May 16, 2020

I just hit this. It causes swaybar to crash on startup inside ipc_get_workspaces.

The problem is with the generated JSON from sway. The value of res in

        char *res = ipc_single_command(bar->ipc_socketfd,
                        IPC_GET_WORKSPACES, NULL, &len);

looks like this:

[
  {
    "id": 8,
    "name": "j",
    "rect": {
      "x": 32,
      "y": 32,
      "width": 3776,
      "height": 2096
    },
    "focus": [
      7
    ],
    "border": "none",
    "current_border_width": 0,
    "layout": "splith",
    "orientation": "horizontal",
    "percent": null,
    "window_rect": {
      "x": 0,
      "y": 0,
      "width": 0,
      "height": 0
    },
    "focused": false
  },
  {
    "id": 14,
    "name": "f",
    "rect": {
      "x": 32,
      "y": 32,
      "width": 3776,
      "height": 2096
    },
    "focus": [
      15
    ],
    "border": "none",
    "current_border_width": 0,
    "layout": "splith",
    "orientation": "horizontal",
    "percent": null,
    "window_rect": {
      "x": 0,
      "y": 0,
      "width": 0,
      "height": 0
    },
    "focused": false
  }
  ...
]

(Note: "f" and "j" are workspace names. JSON has been run through jq for readability)

The JSON object is missing a number of properties that swaybar is expecting.

Looking at the code in sway/sway_ipc.c, it seems every property added after window_rect is discarded.

json_object_object_add(object, "window_rect", ipc_json_create_empty_rect());

@sfar9999
Copy link

json-c/json-c#599
"cannot add more than 11 objects. Is this a known issue?"

Yeah that'll be it :)

@JusterK
Copy link
Author

JusterK commented May 16, 2020

@sfar9999 Indeed, just compiled sway with json-c master and everything works again.

Sway still needs an update though. A direct access has been deprecated:
* Added a json_tokener_get_parse_end() function to replace direct access of tok->char_offset.

which is used in i3bar.c

% find -name '*.c' -type f -exec grep -n char_offset {} \+
./swaybar/i3bar.c:198:                                  &status->buffer[buffer_pos + status->tokener->char_offset - 1];
./swaybar/i3bar.c:209:                          buffer_pos += status->tokener->char_offset;

@Xyene
Copy link
Member

Xyene commented May 16, 2020

Thanks for digging and confirming the issue is upstream, I'm going to close this issue since there's not much sway can do about it.

I'm not sure that switching to json_tokener_get_parse_end would be a good idea... right now it's still just a shorthand for tok->char_offset, and we'd end up requiring json-c 0.14 everywhere as a result. json-c 0.14 was just recently released and not yet packaged everywhere (for instance, Debian Sid still packages 0.13, and that's the unstable channel).

I know Arch packages 0.14 now, and that's where a lot of the recent json-c issues have been coming from (like #5290, and this). At least until its wrinkles are ironed out, hard-requiring it for a cosmetic improvement sounds like it'd cause more problems than it'd solve.

@prometheanfire
Copy link

Gentoo just stablized json-c 0.14 as well, not sure this problem is going to just go away. Is there an upstream bug?

@Xyene
Copy link
Member

Xyene commented May 17, 2020

@prometheanfire yes, this is tracked upstream in json-c/json-c#599, and it looks like it's been fixed there, just waiting on package maintainers at this point. There's not much we can do on sway's end.

@prometheanfire
Copy link

ah, thanks, I'll poke the maintianers gentoo side and see if we can get a revbump for that.

@sfar9999
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants