From e6e305aafef7aedc78e1d404c56c654790f28d7f Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sun, 4 Sep 2022 13:13:24 +0200 Subject: [PATCH] added better code faq --- .../PR-Guidelines.md | 64 +++++++++++++++++++ pages/Contributing and Debugging/_index.md | 16 ++--- 2 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 pages/Contributing and Debugging/PR-Guidelines.md diff --git a/pages/Contributing and Debugging/PR-Guidelines.md b/pages/Contributing and Debugging/PR-Guidelines.md new file mode 100644 index 0000000..08a320b --- /dev/null +++ b/pages/Contributing and Debugging/PR-Guidelines.md @@ -0,0 +1,64 @@ +## PR Requirements + +- Clean, not hacky code +- Described changes and *why* they were there +- Following the style (see below) + +## Code Style + +Hyprland's code style: +```cpp +void myFunction(int arg) { + + if (shortStatement) + doSomething(); + else + doNotDoIt(); + + switch (value) { + case 1: + { // braces optional + blahBlah(); + break; + } + default: + Debug::log(ERR, "error"); + break; + } + + const auto CONSTVALUE = arg == 1 ? 2 : 3; + + void* pLocalPointer = nullptr; + + int localValue = 0; + + if (MY && VERY && LONG && IF && STATEMENT && OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO && SUPERLONG && STATEMENT) { + ; // blank + } +} + +class myClass { +public: + int m_iMyLocalInt = 0; + // ^ member + // ^ int + // ^ camel name + + void classFunction(int, int, bool defaultBool = false); + // ^ most arg names omitted + // ^ arg name mandatory here because C++ + + // Note: omitting args only for functions with clear / few args. For long functions: + void classFunctionLong(int a, int b, bool sure, bool red, bool enabled, void* item, const CColor& color = {0}); +} +``` + +## Some code FAQ + +> Why is the config variable getting so weird? + +Every variable from the config needs to be found in a hashmap. To limit the amount of hashmap searches, getting a config option looks like this: +```cpp +static auto *const PFOLLOWMOUSE = &g_pConfigManager->getConfigValuePtr("input:follow_mouse")->intValue; +``` +Since the hashmap *cannot* be mutated during runtime, this pointer will always be valid, and will not require hashmap lookups every single time it's read. \ No newline at end of file diff --git a/pages/Contributing and Debugging/_index.md b/pages/Contributing and Debugging/_index.md index 5418637..d3590ef 100644 --- a/pages/Contributing and Debugging/_index.md +++ b/pages/Contributing and Debugging/_index.md @@ -1,12 +1,6 @@ # Contributing guidelines -For PRs, make sure that you: - -- follow the code style -- don't write "hacky" code -- check and test the code -- are contributing something useful -- explain your PR as best as you can +PR, code styling and code FAQs are [here](./PR-Guidelines) For issues, please see [the guidelines](https://github.com/hyprwm/Hyprland/blob/main/docs/ISSUE_GUIDELINES.md) @@ -17,8 +11,6 @@ For issues, please see `xcb` stuff, check with your local package provider. -`wlroots-git` - always have the latest wlroots. - `wayland` - of course. *Arch*: @@ -50,6 +42,12 @@ Also, before the first build (or after some updates, possibly) need to `make config`.) {{< /hint >}} +{{< hint type=warning >}} +`make config` will overwrite wlroots headers in `/usr/`, +meaning you'll be unable to build any other wlroots compositor +without a wlroots reinstall. +{{< /hint >}} + # Running when running Hyprland in Debug mode, the config is