formatting: add .clang-format

This commit is contained in:
Alex Denes 2026-04-21 14:11:09 +00:00
parent a2d03cf618
commit 1feb41da8e
No known key found for this signature in database
GPG Key ID: F92BA85F61F4C173
6 changed files with 415 additions and 294 deletions

30
.clang-format Normal file
View File

@ -0,0 +1,30 @@
Language: C
BasedOnStyle: LLVM
ColumnLimit: 100
IndentWidth: 8
TabWidth: 8
UseTab: ForIndentation
ContinuationIndentWidth: 8
BreakBeforeBraces: Linux
BreakAfterReturnType: AllDefinitions
AlwaysBreakAfterReturnType: AllDefinitions
PointerAlignment: Right
IndentCaseLabels: false
AlignAfterOpenBracket: DontAlign
BinPackParameters: true
BinPackArguments: true
AllowShortFunctionsOnASingleLine: None
AllowShortBlocksOnASingleLine: Never
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
SpaceBeforeParens: ControlStatements
SpaceAfterCStyleCast: false
AlignConsecutiveMacros:
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignTrailingComments: false
AlignArrayOfStructures: Left
SortIncludes: true
IncludeBlocks: Regroup

View File

@ -64,10 +64,12 @@ toplevel_from_wlr_surface(struct wlr_surface *s, Client **pc, LayerSurface **pl)
if (!xdg_surface->popup || !xdg_surface->popup->parent) if (!xdg_surface->popup || !xdg_surface->popup->parent)
return -1; return -1;
tmp_xdg_surface = wlr_xdg_surface_try_from_wlr_surface(xdg_surface->popup->parent); tmp_xdg_surface =
wlr_xdg_surface_try_from_wlr_surface(xdg_surface->popup->parent);
if (!tmp_xdg_surface) if (!tmp_xdg_surface)
return toplevel_from_wlr_surface(xdg_surface->popup->parent, pc, pl); return toplevel_from_wlr_surface(
xdg_surface->popup->parent, pc, pl);
xdg_surface = tmp_xdg_surface; xdg_surface = tmp_xdg_surface;
break; break;
@ -112,8 +114,9 @@ client_set_bounds(Client *c, int32_t width, int32_t height)
return 0; return 0;
#endif #endif
if (wl_resource_get_version(c->surface.xdg->toplevel->resource) >= if (wl_resource_get_version(c->surface.xdg->toplevel->resource) >=
XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION && width >= 0 && height >= 0 XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION &&
&& (c->bounds.width != width || c->bounds.height != height)) { width >= 0 && height >= 0 &&
(c->bounds.width != width || c->bounds.height != height)) {
c->bounds.width = width; c->bounds.width = width;
c->bounds.height = height; c->bounds.height = height;
return wlr_xdg_toplevel_set_bounds(c->surface.xdg->toplevel, width, height); return wlr_xdg_toplevel_set_bounds(c->surface.xdg->toplevel, width, height);
@ -135,10 +138,10 @@ static inline void
client_get_clip(Client *c, struct wlr_box *clip) client_get_clip(Client *c, struct wlr_box *clip)
{ {
*clip = (struct wlr_box){ *clip = (struct wlr_box){
.x = 0, .x = 0,
.y = 0, .y = 0,
.width = c->geom.width - c->bw, .width = c->geom.width - c->bw,
.height = c->geom.height - c->bw, .height = c->geom.height - c->bw,
}; };
#ifdef XWAYLAND #ifdef XWAYLAND
@ -177,7 +180,8 @@ client_get_parent(Client *c)
} }
#endif #endif
if (c->surface.xdg->toplevel->parent) if (c->surface.xdg->toplevel->parent)
toplevel_from_wlr_surface(c->surface.xdg->toplevel->parent->base->surface, &p, NULL); toplevel_from_wlr_surface(
c->surface.xdg->toplevel->parent->base->surface, &p, NULL);
return p; return p;
} }
@ -216,24 +220,28 @@ client_is_float_type(Client *c)
if (surface->modal) if (surface->modal)
return 1; return 1;
if (wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DIALOG) if (wlr_xwayland_surface_has_window_type(
|| wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_SPLASH) surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DIALOG) ||
|| wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_TOOLBAR) wlr_xwayland_surface_has_window_type(
|| wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_UTILITY)) { surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_SPLASH) ||
wlr_xwayland_surface_has_window_type(
surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_TOOLBAR) ||
wlr_xwayland_surface_has_window_type(
surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_UTILITY)) {
return 1; return 1;
} }
return size_hints && size_hints->min_width > 0 && size_hints->min_height > 0 return size_hints && size_hints->min_width > 0 && size_hints->min_height > 0 &&
&& (size_hints->max_width == size_hints->min_width (size_hints->max_width == size_hints->min_width ||
|| size_hints->max_height == size_hints->min_height); size_hints->max_height == size_hints->min_height);
} }
#endif #endif
toplevel = c->surface.xdg->toplevel; toplevel = c->surface.xdg->toplevel;
state = toplevel->current; state = toplevel->current;
return toplevel->parent || (state.min_width != 0 && state.min_height != 0 return toplevel->parent || (state.min_width != 0 && state.min_height != 0 &&
&& (state.min_width == state.max_width (state.min_width == state.max_width ||
|| state.min_height == state.max_height)); state.min_height == state.max_height));
} }
static inline int static inline int
@ -246,9 +254,8 @@ client_is_rendered_on_mon(Client *c, Monitor *m)
int unused_lx, unused_ly; int unused_lx, unused_ly;
if (!wlr_scene_node_coords(&c->scene->node, &unused_lx, &unused_ly)) if (!wlr_scene_node_coords(&c->scene->node, &unused_lx, &unused_ly))
return 0; return 0;
wl_list_for_each(s, &client_surface(c)->current_outputs, link) wl_list_for_each(s, &client_surface(c)->current_outputs,
if (s->output == m->wlr_output) link) if (s->output == m->wlr_output) return 1;
return 1;
return 0; return 0;
} }
@ -263,7 +270,7 @@ client_is_stopped(Client *c)
#endif #endif
wl_client_get_credentials(c->surface.xdg->client->client, &pid, NULL, NULL); wl_client_get_credentials(c->surface.xdg->client->client, &pid, NULL, NULL);
if (waitid(P_PID, pid, &in, WNOHANG|WCONTINUED|WSTOPPED|WNOWAIT) < 0) { if (waitid(P_PID, pid, &in, WNOHANG | WCONTINUED | WSTOPPED | WNOWAIT) < 0) {
/* This process is not our child process, while is very unlikely that /* This process is not our child process, while is very unlikely that
* it is stopped, in order to do not skip frames, assume that it is. */ * it is stopped, in order to do not skip frames, assume that it is. */
if (errno == ECHILD) if (errno == ECHILD)
@ -292,8 +299,8 @@ static inline void
client_notify_enter(struct wlr_surface *s, struct wlr_keyboard *kb) client_notify_enter(struct wlr_surface *s, struct wlr_keyboard *kb)
{ {
if (kb) if (kb)
wlr_seat_keyboard_notify_enter(seat, s, kb->keycodes, wlr_seat_keyboard_notify_enter(
kb->num_keycodes, &kb->modifiers); seat, s, kb->keycodes, kb->num_keycodes, &kb->modifiers);
else else
wlr_seat_keyboard_notify_enter(seat, s, NULL, 0, NULL); wlr_seat_keyboard_notify_enter(seat, s, NULL, 0, NULL);
} }
@ -342,13 +349,13 @@ client_set_size(Client *c, uint32_t width, uint32_t height)
{ {
#ifdef XWAYLAND #ifdef XWAYLAND
if (client_is_x11(c)) { if (client_is_x11(c)) {
wlr_xwayland_surface_configure(c->surface.xwayland, wlr_xwayland_surface_configure(
c->geom.x + c->bw, c->geom.y + c->bw, width, height); c->surface.xwayland, c->geom.x + c->bw, c->geom.y + c->bw, width, height);
return 0; return 0;
} }
#endif #endif
if ((int32_t)width == c->surface.xdg->toplevel->current.width if ((int32_t)width == c->surface.xdg->toplevel->current.width &&
&& (int32_t)height == c->surface.xdg->toplevel->current.height) (int32_t)height == c->surface.xdg->toplevel->current.height)
return 0; return 0;
return wlr_xdg_toplevel_set_size(c->surface.xdg->toplevel, (int32_t)width, (int32_t)height); return wlr_xdg_toplevel_set_size(c->surface.xdg->toplevel, (int32_t)width, (int32_t)height);
} }
@ -358,13 +365,13 @@ client_set_tiled(Client *c, uint32_t edges)
{ {
#ifdef XWAYLAND #ifdef XWAYLAND
if (client_is_x11(c)) { if (client_is_x11(c)) {
wlr_xwayland_surface_set_maximized(c->surface.xwayland, wlr_xwayland_surface_set_maximized(
edges != WLR_EDGE_NONE, edges != WLR_EDGE_NONE); c->surface.xwayland, edges != WLR_EDGE_NONE, edges != WLR_EDGE_NONE);
return; return;
} }
#endif #endif
if (wl_resource_get_version(c->surface.xdg->toplevel->resource) if (wl_resource_get_version(c->surface.xdg->toplevel->resource) >=
>= XDG_TOPLEVEL_STATE_TILED_RIGHT_SINCE_VERSION) { XDG_TOPLEVEL_STATE_TILED_RIGHT_SINCE_VERSION) {
wlr_xdg_toplevel_set_tiled(c->surface.xdg->toplevel, edges); wlr_xdg_toplevel_set_tiled(c->surface.xdg->toplevel, edges);
} else { } else {
wlr_xdg_toplevel_set_maximized(c->surface.xdg->toplevel, edges != WLR_EDGE_NONE); wlr_xdg_toplevel_set_maximized(c->surface.xdg->toplevel, edges != WLR_EDGE_NONE);
@ -386,9 +393,10 @@ static inline int
client_wants_focus(Client *c) client_wants_focus(Client *c)
{ {
#ifdef XWAYLAND #ifdef XWAYLAND
return client_is_unmanaged(c) return client_is_unmanaged(c) &&
&& wlr_xwayland_surface_override_redirect_wants_focus(c->surface.xwayland) wlr_xwayland_surface_override_redirect_wants_focus(c->surface.xwayland) &&
&& wlr_xwayland_surface_icccm_input_model(c->surface.xwayland) != WLR_ICCCM_INPUT_MODEL_NONE; wlr_xwayland_surface_icccm_input_model(c->surface.xwayland) !=
WLR_ICCCM_INPUT_MODEL_NONE;
#endif #endif
return 0; return 0;
} }

View File

@ -1,18 +1,20 @@
/* Taken from https://github.com/djpohly/dwl/issues/466 */ /* Taken from https://github.com/djpohly/dwl/issues/466 */
#define COLOR(hex) { ((hex >> 24) & 0xFF) / 255.0f, \ #define COLOR(hex) \
((hex >> 16) & 0xFF) / 255.0f, \ {((hex >> 24) & 0xFF) / 255.0f, ((hex >> 16) & 0xFF) / 255.0f, \
((hex >> 8) & 0xFF) / 255.0f, \ ((hex >> 8) & 0xFF) / 255.0f, (hex & 0xFF) / 255.0f}
(hex & 0xFF) / 255.0f }
/* appearance */ /* appearance */
static const int sloppyfocus = 1; /* focus follows mouse */ static const int sloppyfocus = 1; /* focus follows mouse */
static const int bypass_surface_visibility = 0; /* 1 means idle inhibitors will disable idle tracking even if it's surface isn't visible */ static const int bypass_surface_visibility = 0; /* 1 means idle inhibitors will disable idle
static const unsigned int borderpx = 1; /* border pixel of windows */ * tracking even if it's surface isn't
static const float rootcolor[] = COLOR(0x222222ff); * visible */
static const float bordercolor[] = COLOR(0x444444ff); static const unsigned int borderpx = 1; /* border pixel of windows */
static const float focuscolor[] = COLOR(0x005577ff); static const float rootcolor[] = COLOR(0x222222ff);
static const float urgentcolor[] = COLOR(0xff0000ff); static const float bordercolor[] = COLOR(0x444444ff);
static const float focuscolor[] = COLOR(0x005577ff);
static const float urgentcolor[] = COLOR(0xff0000ff);
/* This conforms to the xdg-protocol. Set the alpha to zero to restore the old behavior */ /* This conforms to the xdg-protocol. Set the alpha to zero to restore the old behavior */
static const float fullscreen_bg[] = {0.0f, 0.0f, 0.0f, 1.0f}; /* You can also use glsl colors */ static const float fullscreen_bg[] = {0.0f, 0.0f, 0.0f, 1.0f}; /* You can also use glsl colors */
/* tagging - TAGCOUNT must be no greater than 31 */ /* tagging - TAGCOUNT must be no greater than 31 */
#define TAGCOUNT (9) #define TAGCOUNT (9)
@ -20,13 +22,16 @@ static const float fullscreen_bg[] = {0.0f, 0.0f, 0.0f, 1.0f}; /* You ca
/* logging */ /* logging */
static int log_level = WLR_ERROR; static int log_level = WLR_ERROR;
// clang-format off
static const Rule rules[] = { static const Rule rules[] = {
/* app_id title tags mask isfloating monitor */ /* app_id title tags mask isfloating monitor */
{ "Gimp_EXAMPLE", NULL, 0, 1, -1 }, /* Start on currently visible tags floating, not tiled */ { "Gimp_EXAMPLE", NULL, 0, 1, -1 }, /* Start on currently visible tags floating, not tiled */
{ "firefox_EXAMPLE", NULL, 1 << 8, 0, -1 }, /* Start on ONLY tag "9" */ { "firefox_EXAMPLE", NULL, 1 << 8, 0, -1 }, /* Start on ONLY tag "9" */
/* default/example rule: can be changed but cannot be eliminated; at least one rule must exist */ /* default/example rule: can be changed but cannot be eliminated; at least one rule must exist */
}; };
// clang-format on
// clang-format off
/* layout(s) */ /* layout(s) */
static const Layout layouts[] = { static const Layout layouts[] = {
/* symbol arrange function */ /* symbol arrange function */
@ -34,26 +39,29 @@ static const Layout layouts[] = {
{ "><>", NULL }, /* no layout function means floating behavior */ { "><>", NULL }, /* no layout function means floating behavior */
{ "[M]", monocle }, { "[M]", monocle },
}; };
// clang-format on
// clang-format off
/* monitors */ /* monitors */
/* (x=-1, y=-1) is reserved as an "autoconfigure" monitor position indicator /* (x=-1, y=-1) is reserved as an "autoconfigure" monitor position indicator
* WARNING: negative values other than (-1, -1) cause problems with Xwayland clients due to * WARNING: negative values other than (-1, -1) cause problems with Xwayland clients due to
* https://gitlab.freedesktop.org/xorg/xserver/-/issues/899 */ * https://gitlab.freedesktop.org/xorg/xserver/-/issues/899 */
static const MonitorRule monrules[] = { static const MonitorRule monrules[] = {
/* name mfact nmaster scale layout rotate/reflect x y /* name mfact nmaster scale layout rotate/reflect x y
* example of a HiDPI laptop monitor: * example of a HiDPI laptop monitor:
{ "eDP-1", 0.5f, 1, 2, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 }, */ { "eDP-1", 0.5f, 1, 2, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 }, */
{ NULL, 0.55f, 1, 1, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 }, { NULL, 0.55f, 1, 1, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 },
/* default monitor rule: can be changed but cannot be eliminated; at least one monitor rule must exist */ /* default monitor rule: can be changed but cannot be eliminated; at least one monitor rule must exist */
}; };
// clang-format on
/* keyboard */ /* keyboard */
static const struct xkb_rule_names xkb_rules = { static const struct xkb_rule_names xkb_rules = {
/* can specify fields: rules, model, layout, variant, options */ /* can specify fields: rules, model, layout, variant, options */
/* example: /* example:
.options = "ctrl:nocaps", .options = "ctrl:nocaps",
*/ */
.options = NULL, .options = NULL,
}; };
static const int repeat_rate = 25; static const int repeat_rate = 25;
@ -80,7 +88,8 @@ LIBINPUT_CONFIG_CLICK_METHOD_NONE
LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS
LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER
*/ */
static const enum libinput_config_click_method click_method = LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS; static const enum libinput_config_click_method click_method =
LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
/* You can choose between: /* You can choose between:
LIBINPUT_CONFIG_SEND_EVENTS_ENABLED LIBINPUT_CONFIG_SEND_EVENTS_ENABLED
@ -93,7 +102,8 @@ static const uint32_t send_events_mode = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT
LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE
*/ */
static const enum libinput_config_accel_profile accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE; static const enum libinput_config_accel_profile accel_profile =
LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE;
static const double accel_speed = 0.0; static const double accel_speed = 0.0;
/* You can choose between: /* You can choose between:
@ -105,19 +115,28 @@ static const enum libinput_config_tap_button_map button_map = LIBINPUT_CONFIG_TA
/* If you want to use the windows key for MODKEY, use WLR_MODIFIER_LOGO */ /* If you want to use the windows key for MODKEY, use WLR_MODIFIER_LOGO */
#define MODKEY WLR_MODIFIER_ALT #define MODKEY WLR_MODIFIER_ALT
#define TAGKEYS(KEY,SKEY,TAG) \ // clang-format off
{ MODKEY, KEY, view, {.ui = 1 << TAG} }, \ #define TAGKEYS(KEY, SKEY, TAG) \
{ MODKEY|WLR_MODIFIER_CTRL, KEY, toggleview, {.ui = 1 << TAG} }, \ {MODKEY, KEY, view, {.ui = 1 << TAG}}, \
{ MODKEY|WLR_MODIFIER_SHIFT, SKEY, tag, {.ui = 1 << TAG} }, \ {MODKEY | WLR_MODIFIER_CTRL, KEY, toggleview, {.ui = 1 << TAG}}, \
{ MODKEY|WLR_MODIFIER_CTRL|WLR_MODIFIER_SHIFT,SKEY,toggletag, {.ui = 1 << TAG} } {MODKEY | WLR_MODIFIER_SHIFT, SKEY, tag, {.ui = 1 << TAG}}, \
{MODKEY | WLR_MODIFIER_CTRL | WLR_MODIFIER_SHIFT, SKEY, toggletag, {.ui = 1 << TAG}}
// clang-format on
/* helper for spawning shell commands in the pre dwm-5.0 fashion */ /* helper for spawning shell commands in the pre dwm-5.0 fashion */
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } #define SHCMD(cmd) \
{ \
.v = (const char *[]) \
{ \
"/bin/sh", "-c", cmd, NULL \
} \
}
/* commands */ /* commands */
static const char *termcmd[] = { "foot", NULL }; static const char *termcmd[] = {"foot", NULL};
static const char *menucmd[] = { "wmenu-run", NULL }; static const char *menucmd[] = {"wmenu-run", NULL};
// clang-format off
static const Key keys[] = { static const Key keys[] = {
/* Note that Shift changes certain key codes: 2 -> at, etc. */ /* Note that Shift changes certain key codes: 2 -> at, etc. */
/* modifier key function argument */ /* modifier key function argument */
@ -164,9 +183,12 @@ static const Key keys[] = {
CHVT(1), CHVT(2), CHVT(3), CHVT(4), CHVT(5), CHVT(6), CHVT(1), CHVT(2), CHVT(3), CHVT(4), CHVT(5), CHVT(6),
CHVT(7), CHVT(8), CHVT(9), CHVT(10), CHVT(11), CHVT(12), CHVT(7), CHVT(8), CHVT(9), CHVT(10), CHVT(11), CHVT(12),
}; };
// clang-format on
// clang-format off
static const Button buttons[] = { static const Button buttons[] = {
{ MODKEY, BTN_LEFT, moveresize, {.ui = CurMove} }, { MODKEY, BTN_LEFT, moveresize, {.ui = CurMove} },
{ MODKEY, BTN_MIDDLE, togglefloating, {0} }, { MODKEY, BTN_MIDDLE, togglefloating, {0} },
{ MODKEY, BTN_RIGHT, moveresize, {.ui = CurResize} }, { MODKEY, BTN_RIGHT, moveresize, {.ui = CurResize} },
}; };
// clang-format on

498
dwl.c

File diff suppressed because it is too large Load Diff

14
util.c
View File

@ -1,21 +1,22 @@
/* See LICENSE.dwm file for copyright and license details. */ /* See LICENSE.dwm file for copyright and license details. */
#include "util.h"
#include <fcntl.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <fcntl.h>
#include "util.h"
void void
die(const char *fmt, ...) { die(const char *fmt, ...)
{
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vfprintf(stderr, fmt, ap); vfprintf(stderr, fmt, ap);
va_end(ap); va_end(ap);
if (fmt[0] && fmt[strlen(fmt)-1] == ':') { if (fmt[0] && fmt[strlen(fmt) - 1] == ':') {
fputc(' ', stderr); fputc(' ', stderr);
perror(NULL); perror(NULL);
} else { } else {
@ -36,7 +37,8 @@ ecalloc(size_t nmemb, size_t size)
} }
int int
fd_set_nonblock(int fd) { fd_set_nonblock(int fd)
{
int flags = fcntl(fd, F_GETFL); int flags = fcntl(fd, F_GETFL);
if (flags < 0) { if (flags < 0) {
perror("fcntl(F_GETFL):"); perror("fcntl(F_GETFL):");

1
util.h
View File

@ -1,4 +1,5 @@
/* See LICENSE.dwm file for copyright and license details. */ /* See LICENSE.dwm file for copyright and license details. */
#include <stddef.h>
void die(const char *fmt, ...); void die(const char *fmt, ...);
void *ecalloc(size_t nmemb, size_t size); void *ecalloc(size_t nmemb, size_t size);