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

Use glaze to parse hyprctl json output, other improvements #8812

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zjeffer
Copy link
Contributor

@zjeffer zjeffer commented Dec 22, 2024

Describe your PR, what does it fix/add?

  • Removed the very ugly manual parsing of the output of hyprctl plugin list | grep Plugin, by replacing it with a simple glaze parse of the json output of hyprctl plugin list -j in PluginManager.cpp
  • While I was busy, I noticed the patterns folder + "/" + filename and folder + "/filename.ext" came up a lot. I really dislike this so I replaced it with the std::filesystem / operator (in a separate commit)
  • I also added a helper method to get the state.toml files for every plugin, because the exact same logic was used 4 times in the same file. I extracted the logic into a new helper function "getPluginstates" in DataState.
  • Also took care of some clang-tidy suggestions, for example find was being called with a single-character string "x" instead of just a character 'x'.

Is there anything you want to mention? (unchecked code, possible bugs, found problems, breaking compatibility, etc.)

I'm planning on replacing more of these hyprctl calls with json parsing, like we discussed in this PR: #7152 (comment)

Is it ready for merging, or does it need work?

Ready to merge

@zjeffer zjeffer force-pushed the feat/zjeffer/improvements branch 3 times, most recently from 27cf1f6 to 0d52d6c Compare December 22, 2024 21:25
@vaxerski
Copy link
Member

can you use something that doesn't suck as horrendously as nlohmann's json

@zjeffer
Copy link
Contributor Author

zjeffer commented Dec 22, 2024

What would you prefer? Here you said nlohmann::json is ok, and I'd get banned for using boost::json, and you said you don't know jsoncpp.

rapidjson? see latest commit for how that would look (I prefer nlohmann::json for its simplicity in this case, though)

@vaxerski
Copy link
Member

yeh I was a bit quick on that one back then. Nlohmann's json is ungodly slow. Check out https://github.com/stephenberry/glaze

@zjeffer
Copy link
Contributor Author

zjeffer commented Dec 23, 2024

done, let me know if you want me to use git submodules instead of cmake's fetchcontent

@zjeffer zjeffer changed the title Use nlohmann::json to parse hyprctl output, other improvements Use glaze to parse hyprctl json output, other improvements Dec 23, 2024
hyprpm/CMakeLists.txt Outdated Show resolved Hide resolved
@zjeffer zjeffer force-pushed the feat/zjeffer/improvements branch from 5ed2134 to f4ff963 Compare December 25, 2024 20:40
@github-actions github-actions bot added the Nix NixOS issue label Dec 26, 2024
@fufexan
Copy link
Member

fufexan commented Dec 26, 2024

I'm not sure whether the arch package for glaze contains a .pc file, but the Nixpkgs one only includes cmake files, so I had to modify the lookup method in meson.build.

@zjeffer
Copy link
Contributor Author

zjeffer commented Dec 26, 2024

Thanks! Ready to merge now.

* Use std::filesystem::path in hyprpm DataState to avoid concatenating strings with (folder + "/" + file)
* Added getPluginStates helper method in DataState
* Small clang-tidy improvements
@zjeffer zjeffer force-pushed the feat/zjeffer/improvements branch from f884eca to 55607e0 Compare December 26, 2024 17:15
if (!entry.is_directory() || entry.path().stem() == "headersRoot")
continue;

if (!std::filesystem::exists(entry.path().string() + "/state.toml"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you remove all these safeguards?

Copy link
Contributor Author

@zjeffer zjeffer Dec 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't, I extracted them into the method getPluginStates() because these safeguards were duplicated 4 times.

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

Successfully merging this pull request may close these issues.

3 participants