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.

@DreamMaoMao
Copy link

DreamMaoMao commented Feb 13, 2024

(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /usr/bin/Hyprland 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
Welcome to Hyprland!
[LOG] Instance Signature: 838ea2c9aae9e4dbf6cc3a8507f65d4f6238448f_1707824159
[LOG] Hyprland PID: 69602
[LOG] ===== SYSTEM INFO: =====
[LOG] System name: Linux
[LOG] Node name: myarch2
[LOG] Release: 6.7.0-arch3-1
[LOG] Version: #1 SMP PREEMPT_DYNAMIC Sat, 13 Jan 2024 14:37:14 +0000


[Detaching after vfork from child process 69607]
[LOG] GPU information:
03:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Picasso/Raven 2 [Radeon Vega Series / Radeon Vega Mobile Series] [1002:15d8] (rev c2) (prog-if 00 [VGA controller])
03:00.7 Non-VGA unclassified device [0000]: Advanced Micro Devices, Inc. [AMD] Raven/Raven2/Renoir Non-Sensor Fusion Hub KMDF driver [1022:15e6]


[LOG] os-release:
[Detaching after vfork from child process 69610]
NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
BUILD_ID=rolling
ANSI_COLOR="38;2;23;147;209"
HOME_URL="https://archlinux.org/"
DOCUMENTATION_URL="https://wiki.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://gitlab.archlinux.org/groups/archlinux/-/issues"
PRIVACY_POLICY_URL="https://terms.archlinux.org/docs/privacy-policy/"
LOGO=archlinux-logo

[LOG] ========================



[INFO] If you are crashing, or encounter any bugs, please consult https://wiki.hyprland.org/Crashes-and-Bugs/


[LOG] 
Current splash: "Hyprland only gives you up on -git" - fazzi


[LOG] Creating the HookSystem!
[LOG] Creating the KeybindManager!
[LOG] [hookSystem] New hook event registered: configReloaded
[LOG] Creating the AnimationManager!
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 76.57µs. Estimated average calc time: 0.01µs.
[LOG] Creating the ConfigManager!
[LOG] NOTE: further logs to stdout / logfile are disabled by default. Use debug:disable_logs and debug:enable_stdout_logs to override this.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 39.56µs. Estimated average calc time: 0.01µs.
[LOG] Using config: /home/wrq/.config/hypr/hyprland.conf
[LOG] Creating the CHyprError!
[LOG] [hookSystem] New hook event registered: focusedMon
[LOG] [hookSystem] New hook event registered: preRender
[LOG] Creating the LayoutManager!
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 39.00µs. Estimated average calc time: 0.01µs.
[LOG] Using config: /home/wrq/.config/hypr/hyprland.conf
[ERR] Invalid dispatcher!
[ERR] Invalid dispatcher!
[ERR] Invalid dispatcher!
[ERR] Invalid dispatcher!
[ERR] Invalid dispatcher!
[ERR] Invalid dispatcher!
[ERR] Invalid dispatcher!
[ERR] Invalid dispatcher!
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 45.23µs. Estimated average calc time: 0.01µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 44.88µs. Estimated average calc time: 0.01µs.
[New Thread 0x7ffff66006c0 (LWP 69611)]
[New Thread 0x7ffff56006c0 (LWP 69612)]
[New Thread 0x7ffff4c006c0 (LWP 69613)]
[New Thread 0x7fffe38006c0 (LWP 69614)]
[New Thread 0x7fffe2e006c0 (LWP 69615)]
[New Thread 0x7fffe24006c0 (LWP 69616)]
[New Thread 0x7fffe1a006c0 (LWP 69617)]
amdgpu: amdgpu_cs_ctx_create2 failed. (-13)
[New Thread 0x7fffe10006c0 (LWP 69618)]
[New Thread 0x7fffdbe006c0 (LWP 69619)]
[New Thread 0x7fffdb4006c0 (LWP 69620)]
[New Thread 0x7fffdaa006c0 (LWP 69621)]
[New Thread 0x7fffda0006c0 (LWP 69622)]
[New Thread 0x7fffd96006c0 (LWP 69623)]
[New Thread 0x7fffd8c006c0 (LWP 69624)]
[New Thread 0x7fffd3e006c0 (LWP 69625)]
[New Thread 0x7fffd34006c0 (LWP 69626)]
[New Thread 0x7fffd2a006c0 (LWP 69627)]
[Detaching after vfork from child process 69628]
terminate called after throwing an instance of 'char const*'

Thread 1 "Hyprland" received signal SIGABRT, Aborted.
0x00007ffff74ac83c in ?? () from /usr/lib/libc.so.6
(gdb) bt
#0  0x00007ffff74ac83c in  () at /usr/lib/libc.so.6
#1  0x00007ffff745c668 in raise () at /usr/lib/libc.so.6
#2  0x00007ffff74444b8 in abort () at /usr/lib/libc.so.6
#3  0x00007ffff769ca6f in __gnu_cxx::__verbose_terminate_handler() ()
    at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/vterminate.cc:95
#4  0x00007ffff76b011c in __cxxabiv1::__terminate(void (*)()) (handler=<optimized out>)
    at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:48
#5  0x00007ffff76b0189 in std::terminate() () at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:58
#6  0x00007ffff76b03ed in __cxxabiv1::__cxa_throw(void*, std::type_info*, void (*)(void*))
    (obj=<optimized out>, tinfo=0x55555598c368 <typeinfo for char const*@CXXABI_1.3>, dest=0x0)
    at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_throw.cc:98
#7  0x00007ffff7b44001 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) [clone .isra.0] [clone .cold] () at /usr/lib/libhyprlang.so.0
#8  0x0000555555687f53 in CConfigManager::removePluginConfig(void*) (this=0x555555a975d0, handle=0x555555ab9440)
    at ../src/config/ConfigManager.cpp:1381
#9  0x00005555557b8f13 in CPluginSystem::unloadPlugin(CPlugin const*, bool)
    (this=0x5555564ac1e0, plugin=0x5555564aeae0, eject=<optimized out>) at /usr/include/c++/13.2.1/bits/unique_ptr.h:199
#10 0x0000555555609bf3 in CPluginSystem::loadPlugin(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (this=this@entry=0x5555564ac1e0, path="/usr/lib/libhycov.so") at ../src/plugins/PluginSystem.cpp:72
#11 0x00005555557bb19f 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&) (this=<optimized out>, plugins=std::vector of length 1, capacity 1 = {...}, changed=@0x7fffffffe0df: false)
    at ../src/plugins/PluginSystem.cpp:153
#12 0x00005555556a46ec in CConfigManager::handlePluginLoads() (this=0x555555a975d0) at ../src/config/ConfigManager.cpp:1321
#13 0x000055555565013f in CCompositor::initManagers(eManagersInitStage) (this=<optimized out>, stage=<optimized out>)
--Type <RET> for more, q to quit, c to continue without paging--
    at /usr/include/c++/13.2.1/bits/unique_ptr.h:199
#14 0x0000555555652118 in CCompositor::initServer() (this=<optimized out>) at ../src/Compositor.cpp:259
#15 0x0000555555627655 in main(int, char**) (argc=<optimized out>, argv=<optimized out>)
    at /usr/include/c++/13.2.1/bits/unique_ptr.h:199
(gdb) 

It seems that the error has not been fixed

@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>
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