Skip to content

Commit

Permalink
style/ci: apply clang-format and verify it in ci (hyprwm#4039)
Browse files Browse the repository at this point in the history
* style: apply clang-format

* ci: add new clang-format job to CI
  • Loading branch information
zephvr authored Dec 6, 2023
1 parent 5489f9f commit 4a42344
Show file tree
Hide file tree
Showing 33 changed files with 131 additions and 143 deletions.
1 change: 1 addition & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
subprojects/**/*
29 changes: 29 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,32 @@ jobs:
run: mkdir -p build && cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DNO_XWAYLAND:STRING=true -H./ -B./build -G Ninja
- name: Compile
run: make release

clang-format:
name: "Code Style (Arch)"
runs-on: ubuntu-latest
container:
image: archlinux
steps:
- name: Download dependencies
run: |
sed -i 's/SigLevel = Required DatabaseOptional/SigLevel = Optional TrustAll/' /etc/pacman.conf
pacman --noconfirm --noprogressbar -Syyu
pacman --noconfirm --noprogressbar -Sy glslang libepoxy libfontenc libxcvt libxfont2 libxkbfile vulkan-headers vulkan-validation-layers git go clang lld libc++ pkgconf meson ninja wayland wayland-protocols libinput libxkbcommon pixman glm libdrm libglvnd cairo pango systemd scdoc base-devel seatd cmake jq python libliftoff tomlplusplus
- name: Set up user
run: |
useradd -m githubuser
echo -e "root ALL=(ALL:ALL) ALL\ngithubuser ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers
- name: Install libdisplay-info from the AUR
run: |
su githubuser -c "cd ~ && git clone https://aur.archlinux.org/libdisplay-info.git && cd ./libdisplay-info && makepkg -si --skippgpcheck --noconfirm --noprogressbar"
- name: Checkout Hyprland
uses: actions/checkout@v3
with:
submodules: true
- name: Configure
run: |
meson obj-x86_64-pc-linux-gnu \
-Ddefault_library=static
- name: clang-format check
run: ninja -C obj-x86_64-pc-linux-gnu clang-format-check
3 changes: 1 addition & 2 deletions src/Compositor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
#include "plugins/PluginSystem.hpp"
#include "helpers/Watchdog.hpp"

enum eManagersInitStage
{
enum eManagersInitStage {
STAGE_PRIORITY = 0,
STAGE_LATE
};
Expand Down
6 changes: 2 additions & 4 deletions src/SharedDefs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

#include "helpers/Vector2D.hpp"

enum eIcons
{
enum eIcons {
ICON_WARNING = 0,
ICON_INFO,
ICON_HINT,
Expand All @@ -13,8 +12,7 @@ enum eIcons
ICON_NONE
};

enum eRenderStage
{
enum eRenderStage {
RENDER_PRE = 0, /* Before binding the gl context */
RENDER_BEGIN, /* Just when the rendering begins, nothing has been rendered yet. Damage, current render data in opengl valid. */
RENDER_PRE_WINDOWS, /* Pre windows, post bottom and overlay layers */
Expand Down
6 changes: 2 additions & 4 deletions src/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@
#include "macros.hpp"
#include "managers/XWaylandManager.hpp"

enum eIdleInhibitMode
{
enum eIdleInhibitMode {
IDLEINHIBIT_NONE = 0,
IDLEINHIBIT_ALWAYS,
IDLEINHIBIT_FULLSCREEN,
IDLEINHIBIT_FOCUS
};

enum eGroupRules
{
enum eGroupRules {
// effective only during first map, except for _ALWAYS variant
GROUP_NONE = 0,
GROUP_SET = 1 << 0, // Open as new group or add to focused group
Expand Down
26 changes: 13 additions & 13 deletions src/debug/CrashReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
std::string getRandomMessage() {

const std::vector<std::string> MESSAGES = {"Sorry, didn't mean to...",
"This was an accident, I swear!",
"Calm down, it was a misinput! MISINPUT!",
"Oops",
"Vaxry is going to be upset.",
"Who tried dividing by zero?!",
"Maybe you should try dusting your PC in the meantime?",
"I tried so hard, and got so far...",
"I don't feel so good...",
"*thud*",
"Well this is awkward.",
"\"stable\"",
"I hope you didn't have any unsaved progress.",
"All these computers..."};
"This was an accident, I swear!",
"Calm down, it was a misinput! MISINPUT!",
"Oops",
"Vaxry is going to be upset.",
"Who tried dividing by zero?!",
"Maybe you should try dusting your PC in the meantime?",
"I tried so hard, and got so far...",
"I don't feel so good...",
"*thud*",
"Well this is awkward.",
"\"stable\"",
"I hope you didn't have any unsaved progress.",
"All these computers..."};

std::random_device dev;
std::mt19937 engine(dev());
Expand Down
29 changes: 14 additions & 15 deletions src/debug/HyprCtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ std::string monitorsRequest(std::string request, HyprCtl::eHyprCtlOutputFormat f
"vrr": {},
"activelyTearing": {}
}},)#",
m->ID, escapeJSONStrings(m->szName), escapeJSONStrings(m->szDescription), (m->output->make ? m->output->make : ""),
(m->output->model ? m->output->model : ""), (m->output->serial ? m->output->serial : ""), (int)m->vecPixelSize.x, (int)m->vecPixelSize.y, m->refreshRate,
(int)m->vecPosition.x, (int)m->vecPosition.y, m->activeWorkspace,
(m->activeWorkspace == -1 ? "" : escapeJSONStrings(g_pCompositor->getWorkspaceByID(m->activeWorkspace)->m_szName)), m->specialWorkspaceID,
m->ID, escapeJSONStrings(m->szName), escapeJSONStrings(m->szDescription), (m->output->make ? m->output->make : ""), (m->output->model ? m->output->model : ""),
(m->output->serial ? m->output->serial : ""), (int)m->vecPixelSize.x, (int)m->vecPixelSize.y, m->refreshRate, (int)m->vecPosition.x, (int)m->vecPosition.y,
m->activeWorkspace, (m->activeWorkspace == -1 ? "" : escapeJSONStrings(g_pCompositor->getWorkspaceByID(m->activeWorkspace)->m_szName)), m->specialWorkspaceID,
escapeJSONStrings(getWorkspaceNameFromSpecialID(m->specialWorkspaceID)), (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y,
(int)m->vecReservedBottomRight.x, (int)m->vecReservedBottomRight.y, m->scale, (int)m->transform, (m.get() == g_pCompositor->m_pLastMonitor ? "true" : "false"),
(m->dpmsStatus ? "true" : "false"), (m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED ? "true" : "false"),
Expand All @@ -93,17 +92,17 @@ std::string monitorsRequest(std::string request, HyprCtl::eHyprCtlOutputFormat f
if (!m->output || m->ID == -1ull)
continue;

result += std::format(
"Monitor {} (ID {}):\n\t{}x{}@{:.5f} at {}x{}\n\tdescription: {}\n\tmake: {}\n\tmodel: {}\n\tserial: {}\n\tactive workspace: {} ({})\n\tspecial "
"workspace: {} ({})\n\treserved: {} "
"{} {} {}\n\tscale: {:.2f}\n\ttransform: "
"{}\n\tfocused: {}\n\tdpmsStatus: {}\n\tvrr: {}\n\tactivelyTearing: {}\n\n",
m->szName, m->ID, (int)m->vecPixelSize.x, (int)m->vecPixelSize.y, m->refreshRate, (int)m->vecPosition.x, (int)m->vecPosition.y,
m->szDescription, (m->output->make ? m->output->make : ""), (m->output->model ? m->output->model : ""),
(m->output->serial ? m->output->serial : ""), m->activeWorkspace, (m->activeWorkspace == -1 ? "" : g_pCompositor->getWorkspaceByID(m->activeWorkspace)->m_szName),
m->specialWorkspaceID, getWorkspaceNameFromSpecialID(m->specialWorkspaceID), (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y,
(int)m->vecReservedBottomRight.x, (int)m->vecReservedBottomRight.y, m->scale, (int)m->transform, (m.get() == g_pCompositor->m_pLastMonitor ? "yes" : "no"),
(int)m->dpmsStatus, (int)(m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED), m->tearingState.activelyTearing);
result +=
std::format("Monitor {} (ID {}):\n\t{}x{}@{:.5f} at {}x{}\n\tdescription: {}\n\tmake: {}\n\tmodel: {}\n\tserial: {}\n\tactive workspace: {} ({})\n\tspecial "
"workspace: {} ({})\n\treserved: {} "
"{} {} {}\n\tscale: {:.2f}\n\ttransform: "
"{}\n\tfocused: {}\n\tdpmsStatus: {}\n\tvrr: {}\n\tactivelyTearing: {}\n\n",
m->szName, m->ID, (int)m->vecPixelSize.x, (int)m->vecPixelSize.y, m->refreshRate, (int)m->vecPosition.x, (int)m->vecPosition.y, m->szDescription,
(m->output->make ? m->output->make : ""), (m->output->model ? m->output->model : ""), (m->output->serial ? m->output->serial : ""), m->activeWorkspace,
(m->activeWorkspace == -1 ? "" : g_pCompositor->getWorkspaceByID(m->activeWorkspace)->m_szName), m->specialWorkspaceID,
getWorkspaceNameFromSpecialID(m->specialWorkspaceID), (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, (int)m->vecReservedBottomRight.x,
(int)m->vecReservedBottomRight.y, m->scale, (int)m->transform, (m.get() == g_pCompositor->m_pLastMonitor ? "yes" : "no"), (int)m->dpmsStatus,
(int)(m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED), m->tearingState.activelyTearing);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/debug/HyprCtl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ namespace HyprCtl {

inline int iSocketFD = -1;

enum eHyprCtlOutputFormat
{
enum eHyprCtlOutputFormat {
FORMAT_NORMAL = 0,
FORMAT_JSON
};
Expand Down
7 changes: 3 additions & 4 deletions src/debug/HyprNotificationOverlay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@

#include <cairo/cairo.h>

enum eIconBackend
{
enum eIconBackend {
ICONS_BACKEND_NONE = 0,
ICONS_BACKEND_NF,
ICONS_BACKEND_FA
};

static const std::array<std::array<std::string, ICON_NONE + 1>, 3 /* backends */> ICONS_ARRAY = {
std::array<std::string, ICON_NONE + 1>{"[!]", "[i]", "[Hint]", "[Err]", "[?]", "[ok]", ""}, std::array<std::string, ICON_NONE + 1>{"", "", "", "", "", "󰸞", ""},
std::array<std::string, ICON_NONE + 1>{"", "", "", "", "", ""}};
std::array<std::string, ICON_NONE + 1>{"[!]", "[i]", "[Hint]", "[Err]", "[?]", "[ok]", ""},
std::array<std::string, ICON_NONE + 1>{"", "", "", "", "", "󰸞", ""}, std::array<std::string, ICON_NONE + 1>{"", "", "", "", "", ""}};
static const std::array<CColor, ICON_NONE + 1> ICONS_COLORS = {CColor{255.0 / 255.0, 204 / 255.0, 102 / 255.0, 1.0},
CColor{128 / 255.0, 255 / 255.0, 255 / 255.0, 1.0},
CColor{179 / 255.0, 255 / 255.0, 204 / 255.0, 1.0},
Expand Down
3 changes: 1 addition & 2 deletions src/debug/Log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#define LOGMESSAGESIZE 1024
#define ROLLING_LOG_SIZE 4096

enum LogLevel
{
enum LogLevel {
NONE = -1,
LOG = 0,
WARN,
Expand Down
2 changes: 1 addition & 1 deletion src/events/Popups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void Events::listener_repositionPopupXDG(void* owner, void* data) {
const auto PMONITOR = g_pCompositor->m_pLastMonitor;

CBox box = {PMONITOR->vecPosition.x - lx + PPOPUP->popup->current.geometry.x, PMONITOR->vecPosition.y - ly + PPOPUP->popup->current.geometry.y, PMONITOR->vecSize.x,
PMONITOR->vecSize.y};
PMONITOR->vecSize.y};
wlr_xdg_popup_unconstrain_from_box(PPOPUP->popup, box.pWlr());
}

Expand Down
12 changes: 5 additions & 7 deletions src/helpers/AnimatedVariable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
#include "../macros.hpp"
#include "../debug/Log.hpp"

enum ANIMATEDVARTYPE
{
enum ANIMATEDVARTYPE {
AVARTYPE_INVALID = -1,
AVARTYPE_FLOAT,
AVARTYPE_VECTOR,
AVARTYPE_COLOR
};

enum AVARDAMAGEPOLICY
{
enum AVARDAMAGEPOLICY {
AVARDAMAGE_NONE = -1,
AVARDAMAGE_ENTIRE = 0,
AVARDAMAGE_BORDER,
Expand All @@ -37,10 +35,10 @@ class CAnimatedVariable {
void create(ANIMATEDVARTYPE, SAnimationPropertyConfig*, void* pWindow, AVARDAMAGEPOLICY);
void create(ANIMATEDVARTYPE, std::any val, SAnimationPropertyConfig*, void* pWindow, AVARDAMAGEPOLICY);

CAnimatedVariable(const CAnimatedVariable&) = delete;
CAnimatedVariable(CAnimatedVariable&&) = delete;
CAnimatedVariable(const CAnimatedVariable&) = delete;
CAnimatedVariable(CAnimatedVariable&&) = delete;
CAnimatedVariable& operator=(const CAnimatedVariable&) = delete;
CAnimatedVariable& operator=(CAnimatedVariable&&) = delete;
CAnimatedVariable& operator=(CAnimatedVariable&&) = delete;

~CAnimatedVariable();

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/Monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CMonitor {
int activeWorkspace = -1;
float scale = 1;

std::string szName = "";
std::string szName = "";
std::string szDescription = "";

Vector2D vecReservedTopLeft = Vector2D(0, 0);
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/WLSurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class CWLSurface {
void assign(wlr_surface* pSurface);
void unassign();

CWLSurface(const CWLSurface&) = delete;
CWLSurface(CWLSurface&&) = delete;
CWLSurface(const CWLSurface&) = delete;
CWLSurface(CWLSurface&&) = delete;
CWLSurface& operator=(const CWLSurface&) = delete;
CWLSurface& operator=(CWLSurface&&) = delete;
CWLSurface& operator=(CWLSurface&&) = delete;

wlr_surface* wlr() const;
bool exists() const;
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/Workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void CWorkspace::startAnim(bool in, bool left, bool instant) {
}
} else if (ANIMSTYLE == "slidevert") {
// fallback is slide
const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID);
const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID);
const auto YDISTANCE = PMONITOR->vecSize.y + *PWORKSPACEGAP;

m_fAlpha.setValueAndWarp(1.f); // fix a bug, if switching from fade -> slide.
Expand All @@ -103,7 +103,7 @@ void CWorkspace::startAnim(bool in, bool left, bool instant) {
}
} else {
// fallback is slide
const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID);
const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID);
const auto XDISTANCE = PMONITOR->vecSize.x + *PWORKSPACEGAP;

m_fAlpha.setValueAndWarp(1.f); // fix a bug, if switching from fade -> slide.
Expand Down
3 changes: 1 addition & 2 deletions src/helpers/XWaylandStubs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ typedef struct {
} xcb_size_hints_t;
typedef unsigned int xcb_window_t;

typedef enum xcb_stack_mode_t
{
typedef enum xcb_stack_mode_t {
XCB_STACK_MODE_ABOVE = 0,
XCB_STACK_MODE_BELOW = 1,
XCB_STACK_MODE_TOP_IF = 2,
Expand Down
2 changes: 1 addition & 1 deletion src/includes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// pthread first because it uses class in a C++ way and XWayland includes that...
#include <pthread.h>

#define class _class
#define class _class
#define namespace _namespace
#define static
#define delete delete_
Expand Down
4 changes: 2 additions & 2 deletions src/init/initHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ bool Init::isSudo() {
}

void Init::gainRealTime() {
const int minPrio = sched_get_priority_min(SCHED_RR);
int old_policy;
const int minPrio = sched_get_priority_min(SCHED_RR);
int old_policy;
struct sched_param param;

if (pthread_getschedparam(pthread_self(), &old_policy, &param)) {
Expand Down
6 changes: 2 additions & 4 deletions src/layout/IHyprLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ struct SLayoutMessageHeader {

enum eFullscreenMode : int8_t;

enum eRectCorner
{
enum eRectCorner {
CORNER_NONE = 0,
CORNER_TOPLEFT,
CORNER_TOPRIGHT,
CORNER_BOTTOMRIGHT,
CORNER_BOTTOMLEFT
};

enum eDirection
{
enum eDirection {
DIRECTION_DEFAULT = -1,
DIRECTION_UP = 0,
DIRECTION_RIGHT,
Expand Down
10 changes: 3 additions & 7 deletions src/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
if (!(expr)) { \
Debug::log(CRIT, "\n==========================================================================================\nASSERTION FAILED! \n\n{}\n\nat: line {} in {}", \
std::format(reason, ##__VA_ARGS__), __LINE__, \
([]() constexpr->std::string { return std::string(__FILE__).substr(std::string(__FILE__).find_last_of('/') + 1); })()); \
([]() constexpr -> std::string { return std::string(__FILE__).substr(std::string(__FILE__).find_last_of('/') + 1); })()); \
printf("Assertion failed! See the log in /tmp/hypr/hyprland.log for more info."); \
raise(SIGABRT); \
}
Expand All @@ -63,9 +63,7 @@
}

#define FORMAT_FLAG(spec__, flag__) \
case spec__: \
(flag__) = true; \
break;
case spec__: (flag__) = true; break;

#define FORMAT_NUMBER(buf__) \
case '0': \
Expand All @@ -77,9 +75,7 @@
case '6': \
case '7': \
case '8': \
case '9': \
(buf__).push_back(*it); \
break;
case '9': (buf__).push_back(*it); break;

#if ISDEBUG
#define UNREACHABLE() \
Expand Down
1 change: 1 addition & 0 deletions src/managers/EventManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class CEventManager {
void startThread();

std::thread m_tThread;

private:
void flushEvents();

Expand Down
3 changes: 1 addition & 2 deletions src/managers/KeybindManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ struct SKeybind {
bool shadowed = false;
};

enum eFocusWindowMode
{
enum eFocusWindowMode {
MODE_CLASS_REGEX = 0,
MODE_TITLE_REGEX,
MODE_ADDRESS,
Expand Down
2 changes: 1 addition & 1 deletion src/managers/input/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ void CInputManager::setCursorIconOnBorder(CWindow* w) {
CBox box = w->getWindowMainSurfaceBox();
eBorderIconDirection direction = BORDERICON_NONE;
CBox boxFullGrabInput = {box.x - *PEXTENDBORDERGRAB - BORDERSIZE, box.y - *PEXTENDBORDERGRAB - BORDERSIZE, box.width + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE),
box.height + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE)};
box.height + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE)};

if (w->hasPopupAt(mouseCoords))
direction = BORDERICON_NONE;
Expand Down
Loading

0 comments on commit 4a42344

Please sign in to comment.