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

Migrate the config to hyprlang #4656

Merged
merged 31 commits into from
Feb 18, 2024
Merged

Migrate the config to hyprlang #4656

merged 31 commits into from
Feb 18, 2024

Conversation

vaxerski
Copy link
Member

@vaxerski vaxerski commented Feb 9, 2024

cc @fufexan @MightyPlaza @DreamMaoMao @outfoxxed @horriblename @thejch

Breaking: everything internally (all plugins)

This MR migrates hyprland's config to hyprlang. PLEASE NOTE this requires latest hyprlang-git. Once this mr is gtg, I'll bump ver to 0.3.0.

Please test this, some parts have been written at 3AM and I'll be surprised if I havent missed some *PVAR -> **PVAR occurrences.

TODO:

  • CI (@fufexan pls)
  • Meson (@fufexan pls)
  • getOption hyprctl
  • plugin config keywords
  • more testing
  • Better error reporting (keywords do not throw errors at all atm)

List of breaking changes for end users:

  • hyprctl getoption has a new return syntax
  • device sections take name = ... instead of device:... {
  • All config-related plugin APIs are broken (need updates)

@vaxerski vaxerski requested a review from fufexan February 9, 2024 03:33
@DreamMaoMao
Copy link

DreamMaoMao commented Feb 9, 2024

image

image

Even updating hyprlang to 0.2.1

this branch of hyprland still fail to build.

@DreamMaoMao
Copy link

DreamMaoMao commented Feb 9, 2024

build fail by use meson

success by use cmake

@fufexan
Copy link
Member

fufexan commented Feb 9, 2024

@DreamMaoMao meson should work now.

@outfoxxed
Copy link
Member

I can test once you have a way for me to add plugin settings. Normal workflow does not work without hy3.

@vaxerski
Copy link
Member Author

vaxerski commented Feb 9, 2024

@outfoxxed done. Check the PluginAPI header for API changes.

@vaxerski
Copy link
Member Author

vaxerski commented Feb 9, 2024

from my testing this is ready to review.

@thejch
Copy link
Contributor

thejch commented Feb 9, 2024

seems to have removed case insensitivity. not sure if intended or not.
e.g. it breaks

OpenGL {
    nvidia_anti_flicker = true
}

has to be

opengl {
    nvidia_anti_flicker = true
}

now

@vaxerski
Copy link
Member Author

vaxerski commented Feb 9, 2024

true, hyprlang is case-sensitive. IDK, never was meant to be capitalized, tbh

@thejch
Copy link
Contributor

thejch commented Feb 10, 2024

This also breaks multiple #s
e.g.
## comment throws an error

@vaxerski
Copy link
Member Author

nice catch. Needs a fix in hyprlang.

@vaxerski
Copy link
Member Author

vaxerski commented Feb 13, 2024

should be fixed.

@DreamMaoMao Your plugin's code is wrong, though.

static const auto *pEnable_hotarea_config = (Hyprlang::INT *const *)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hycov:enable_hotarea");

no, read the API signature...

static const auto *pEnable_hotarea_config = (Hyprlang::INT *const *)(HyprlandAPI::getConfigValue(PHANDLE, "plugin:hycov:enable_hotarea")->getDataStaticPtr());

Note: the fix I committed requires hyprlang-git to work

@DreamMaoMao
Copy link

DreamMaoMao commented Feb 14, 2024

should be fixed. 应该是固定的。

@DreamMaoMao Your plugin's code is wrong, though. 但是你的插件代码是错误的。

static const auto *pEnable_hotarea_config = (Hyprlang::INT *const *)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hycov:enable_hotarea");

no, read the API signature...不,读取API签名.

static const auto *pEnable_hotarea_config = (Hyprlang::INT *const *)(HyprlandAPI::getConfigValue(PHANDLE, "plugin:hycov:enable_hotarea")->getDataStaticPtr());

Note: the fix I committed requires hyprlang-git to work注意:我提交的修复需要hyprlang-git才能工作

The plug-in is loaded successfully

@DreamMaoMao
Copy link

image
However, the plug-in option configuration in the configuration file is not read, and the option value is still the default value of the code

By the way, the debug logging option configuration does not take effect either
image

@romanstingler
Copy link
Contributor

don't forget to mention that no multiline hyprland.conf entries are supported (probably mostly issue with swayidle entry)

@outfoxxed
Copy link
Member

Crashes when I create a string value, then the plugin loader eats the error message.

[LOG] Creating the PluginSystem!
[LOG] Loading plugin /home/admin/programming/outfoxxed/hyprland/hy3/build/libhy3.so which is now present in config
[Detaching after vfork from child process 176517]
[Detaching after vfork from child process 176518]

Thread 1 "Hyprland" hit Breakpoint 1.2, 0x00007ffff784c200 in __interceptor___cxa_throw ()
   from /nix/store/i236hrg5ma355ryppkq80ad6myklw9hq-gcc-13.2.0-lib/lib/libasan.so.8
(gdb) bt
#0  0x00007ffff784c200 in __interceptor___cxa_throw () from /nix/store/i236hrg5ma355ryppkq80ad6myklw9hq-gcc-13.2.0-lib/lib/libasan.so.8
#1  0x0000000000a0668a in std::__throw_bad_any_cast() ()
#2  0x00007ffff749eddf in Hyprlang::CConfigValue::setFrom(Hyprlang::CConfigValue const*) [clone .cold] ()
   from /nix/store/rwqbaxb4d4ifmckp9zr9yxygj46780a6-hyprlang-0.pre+date=2024-02-12_689b405/lib/libhyprlang.so.0
#3  0x00000000009c88d9 in CConfigManager::addPluginConfigVar(void*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Hyprlang::CConfigValue const&) ()
#4  0x000000000103945b in addConfigValue ()
#5  0x00007fffd0f80abf in pluginInit (handle=<optimized out>)
    at /nix/store/NFDLK5G11PQPQ5JHKHBGAJ5DMLIRMVYI-gcc-13.2.0/include/c++/13.2.0/bits/basic_string.tcc:238
#6  0x000000000106230a in CPluginSystem::loadPlugin(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ()
#7  0x0000000001065c1f in CPluginSystem::updateConfigPlugins(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool&) ()
#8  0x00000000009c7bf4 in CConfigManager::handlePluginLoads() ()
#9  0x00000000006dd303 in CCompositor::initManagers(eManagersInitStage) ()
#10 0x00000000006d34bc in CCompositor::initServer() ()
#11 0x0000000000e1dca7 in main ()
(gdb) c
Continuing.

Thread 1 "Hyprland" hit Breakpoint 1.1, 0x00007ffff70bc490 in __cxa_throw ()
   from /nix/store/i236hrg5ma355ryppkq80ad6myklw9hq-gcc-13.2.0-lib/lib/libstdc++.so.6
(gdb) c
Continuing.
[ERR]  [PluginSystem] Plugin /home/admin/programming/outfoxxed/hyprland/hy3/build/libhy3.so (Handle 61a00001c280) crashed in init. Unloading.
[LOG]  [PluginSystem] Plugin  unloaded.

Happens at "Sans"

#define CONF(NAME, TYPE, VALUE)                                                                    \
	HyprlandAPI::addConfigValue(PHANDLE, "plugin:hy3:" NAME, Hyprlang::CConfigValue((Hyprlang::TYPE) VALUE))

	// general
	CONF("no_gaps_when_only", INT, 0);
	CONF("node_collapse_policy", INT, 2);
	CONF("group_inset", INT, 10);
	CONF("tab_first_window", INT, 0);

	// tabs
	CONF("tabs:height", INT, 15);
	CONF("tabs:padding", INT, 5);
	CONF("tabs:from_top", INT, 0);
	CONF("tabs:rounding", INT, 3);
	CONF("tabs:render_text", INT, 1);
	CONF("tabs:text_center", INT, 0);
	CONF("tabs:text_font", STRING, "Sans");
	CONF("tabs:text_height", INT, 8);
	CONF("tabs:text_padding", INT, 3);
	CONF("tabs:col.active", INT, 0xff32b4ff);
	CONF("tabs:col.urgent", INT, 0xffff4f4f);
	CONF("tabs:col.inactive", INT, 0x80808080);
	CONF("tabs:col.text.active", INT, 0xff000000);
	CONF("tabs:col.text.urgent", INT, 0xff000000);
	CONF("tabs:col.text.inactive", INT, 0xff000000);

	// autotiling
	CONF("autotile:enable", INT, 0);
	CONF("autotile:ephemeral_groups", INT, 1);
	CONF("autotile:trigger_height", INT, 0);
	CONF("autotile:trigger_width", INT, 0);
	CONF("autotile:workspaces", STRING, "all");

#undef CONF

@vaxerski
Copy link
Member Author

don't forget to mention that no multiline hyprland.conf entries are supported (probably mostly issue with swayidle entry)

was this supported in hl?

@DreamMaoMao You're reading the initial values and storing them, why would you expect them to be updated?

image

If you want to keep track of the actual values, store the static pointers.

@outfoxxed odd, code above in maomao's case has strings too and it works. Where can I find your code?

@vaxerski
Copy link
Member Author

@outfoxxed to me it seems like the bug that I fixed yesterday. Update hyprlang to git and recompile latest commit from this branch.

@DreamMaoMao
Copy link

DreamMaoMao commented Feb 14, 2024

static const auto *pEnable_hotarea_config = (Hyprlang::INT *const *)(HyprlandAPI::getConfigValue(PHANDLE, "plugin:hycov:enable_hotarea")->getDataStaticPtr());

Why not update when it is available in the configuration file as before, and use the default value in the code when the option is not found in the configuration.

I don't want to keep track of the latest changes but I just want to get the values in the configuration file once in this code, which I could have done in the previous code.

@vaxerski
Copy link
Member Author

would be horribly inefficient and I can't see how that has worked before. The config needs to be parsed for the values in the config to propagate. If that was done every time you queried getConfigValue that's like 30 parses just in your handler...

If you wanna do this once for whatever reason (instead of grabbing the static ptr and in your uses just use **g_option), register a dynamic handler for configReloaded and set them there.

@DreamMaoMao
Copy link

would be horribly inefficient and I can't see how that has worked before. The config needs to be parsed for the values in the config to propagate. If that was done every time you queried getConfigValue that's like 30 parses just in your handler...

If you wanna do this once for whatever reason (instead of grabbing the static ptr and in your uses just use **g_option), register a dynamic handler for configReloaded and set them there.

This is a bit different from my design, I have to get the value configured in the actual configuration file before doing everything to decide whether to hook functions and register events to avoid unnecessary hooks, is there no way for me to actively get the actual value on the configuration file?

@vaxerski
Copy link
Member Author

if you really want to you can call HyprlandAPI::reloadConfig() followed by an explicit g_pConfigManager->tick() after you register your config values. That will force an instant reload. After that, you'll have user-set values...

@DreamMaoMao
Copy link

if you really want to you can call HyprlandAPI::reloadConfig() followed by an explicit g_pConfigManager->tick() after you register your config values. That will force an instant reload. After that, you'll have user-set values...

thanks it work now.

@outfoxxed
Copy link
Member

Works for hy3 now.

@vaxerski
Copy link
Member Author

set to merge once arc lonix updates to 0.3.2

@vaxerski vaxerski merged commit 13f6f0b into main Feb 18, 2024
10 of 20 checks passed
fufexan added a commit to fufexan/Hyprland that referenced this pull request Feb 23, 2024
* Migrate to hyprlang

* pop up errors

* fix swapped args

* Meson & Nix: build with hyprlang

* CI: add hyprlang to setup action

* add infra for plugin stuff

* fix hyprctl getoption

* fix hyprctl getoption with json

* format

* fix post parse logic

* fix autogen config

* oops missed exec-once

* fmt

* fix ws rules

* require 0.3.0 for hyprlang

* nix: flaek

* minor type fixes

* fix cfg usages in swipe

* use cvarlist for ws rules

* fix throw in addPluginConfigVar

* Nix: update hyprlang

* minor fixes

* fix disableLogs

* mention hyprlang docs

* bump hyprlang dep in cmake

* Meson: bump min hyprlang version

Nix: update hyprlang

* minor fix

* Nix: update meson patch

---------

Co-authored-by: Mihai Fufezan <fufexan@protonmail.com>
lisuke pushed a commit to lisuke/Hyprland that referenced this pull request Apr 15, 2024
* Migrate to hyprlang

* pop up errors

* fix swapped args

* Meson & Nix: build with hyprlang

* CI: add hyprlang to setup action

* add infra for plugin stuff

* fix hyprctl getoption

* fix hyprctl getoption with json

* format

* fix post parse logic

* fix autogen config

* oops missed exec-once

* fmt

* fix ws rules

* require 0.3.0 for hyprlang

* nix: flaek

* minor type fixes

* fix cfg usages in swipe

* use cvarlist for ws rules

* fix throw in addPluginConfigVar

* Nix: update hyprlang

* minor fixes

* fix disableLogs

* mention hyprlang docs

* bump hyprlang dep in cmake

* Meson: bump min hyprlang version

Nix: update hyprlang

* minor fix

* Nix: update meson patch

---------

Co-authored-by: Mihai Fufezan <fufexan@protonmail.com>
@vaxerski vaxerski deleted the hyprlang-migration branch November 18, 2024 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants