mirror of
https://codeberg.org/dwl/dwl.git
synced 2026-05-06 07:03:23 +00:00
formatting: add .clang-format
This commit is contained in:
parent
a2d03cf618
commit
1feb41da8e
30
.clang-format
Normal file
30
.clang-format
Normal 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
|
||||
82
client.h
82
client.h
@ -64,10 +64,12 @@ toplevel_from_wlr_surface(struct wlr_surface *s, Client **pc, LayerSurface **pl)
|
||||
if (!xdg_surface->popup || !xdg_surface->popup->parent)
|
||||
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)
|
||||
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;
|
||||
break;
|
||||
@ -112,8 +114,9 @@ client_set_bounds(Client *c, int32_t width, int32_t height)
|
||||
return 0;
|
||||
#endif
|
||||
if (wl_resource_get_version(c->surface.xdg->toplevel->resource) >=
|
||||
XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION && width >= 0 && height >= 0
|
||||
&& (c->bounds.width != width || c->bounds.height != height)) {
|
||||
XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION &&
|
||||
width >= 0 && height >= 0 &&
|
||||
(c->bounds.width != width || c->bounds.height != height)) {
|
||||
c->bounds.width = width;
|
||||
c->bounds.height = 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)
|
||||
{
|
||||
*clip = (struct wlr_box){
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = c->geom.width - c->bw,
|
||||
.height = c->geom.height - c->bw,
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = c->geom.width - c->bw,
|
||||
.height = c->geom.height - c->bw,
|
||||
};
|
||||
|
||||
#ifdef XWAYLAND
|
||||
@ -177,7 +180,8 @@ client_get_parent(Client *c)
|
||||
}
|
||||
#endif
|
||||
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;
|
||||
}
|
||||
|
||||
@ -216,24 +220,28 @@ client_is_float_type(Client *c)
|
||||
if (surface->modal)
|
||||
return 1;
|
||||
|
||||
if (wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DIALOG)
|
||||
|| wlr_xwayland_surface_has_window_type(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)) {
|
||||
if (wlr_xwayland_surface_has_window_type(
|
||||
surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DIALOG) ||
|
||||
wlr_xwayland_surface_has_window_type(
|
||||
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 size_hints && size_hints->min_width > 0 && size_hints->min_height > 0
|
||||
&& (size_hints->max_width == size_hints->min_width
|
||||
|| size_hints->max_height == size_hints->min_height);
|
||||
return size_hints && size_hints->min_width > 0 && size_hints->min_height > 0 &&
|
||||
(size_hints->max_width == size_hints->min_width ||
|
||||
size_hints->max_height == size_hints->min_height);
|
||||
}
|
||||
#endif
|
||||
|
||||
toplevel = c->surface.xdg->toplevel;
|
||||
state = toplevel->current;
|
||||
return toplevel->parent || (state.min_width != 0 && state.min_height != 0
|
||||
&& (state.min_width == state.max_width
|
||||
|| state.min_height == state.max_height));
|
||||
return toplevel->parent || (state.min_width != 0 && state.min_height != 0 &&
|
||||
(state.min_width == state.max_width ||
|
||||
state.min_height == state.max_height));
|
||||
}
|
||||
|
||||
static inline int
|
||||
@ -246,9 +254,8 @@ client_is_rendered_on_mon(Client *c, Monitor *m)
|
||||
int unused_lx, unused_ly;
|
||||
if (!wlr_scene_node_coords(&c->scene->node, &unused_lx, &unused_ly))
|
||||
return 0;
|
||||
wl_list_for_each(s, &client_surface(c)->current_outputs, link)
|
||||
if (s->output == m->wlr_output)
|
||||
return 1;
|
||||
wl_list_for_each(s, &client_surface(c)->current_outputs,
|
||||
link) if (s->output == m->wlr_output) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -263,7 +270,7 @@ client_is_stopped(Client *c)
|
||||
#endif
|
||||
|
||||
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
|
||||
* it is stopped, in order to do not skip frames, assume that it is. */
|
||||
if (errno == ECHILD)
|
||||
@ -292,8 +299,8 @@ static inline void
|
||||
client_notify_enter(struct wlr_surface *s, struct wlr_keyboard *kb)
|
||||
{
|
||||
if (kb)
|
||||
wlr_seat_keyboard_notify_enter(seat, s, kb->keycodes,
|
||||
kb->num_keycodes, &kb->modifiers);
|
||||
wlr_seat_keyboard_notify_enter(
|
||||
seat, s, kb->keycodes, kb->num_keycodes, &kb->modifiers);
|
||||
else
|
||||
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
|
||||
if (client_is_x11(c)) {
|
||||
wlr_xwayland_surface_configure(c->surface.xwayland,
|
||||
c->geom.x + c->bw, c->geom.y + c->bw, width, height);
|
||||
wlr_xwayland_surface_configure(
|
||||
c->surface.xwayland, c->geom.x + c->bw, c->geom.y + c->bw, width, height);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
if ((int32_t)width == c->surface.xdg->toplevel->current.width
|
||||
&& (int32_t)height == c->surface.xdg->toplevel->current.height)
|
||||
if ((int32_t)width == c->surface.xdg->toplevel->current.width &&
|
||||
(int32_t)height == c->surface.xdg->toplevel->current.height)
|
||||
return 0;
|
||||
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
|
||||
if (client_is_x11(c)) {
|
||||
wlr_xwayland_surface_set_maximized(c->surface.xwayland,
|
||||
edges != WLR_EDGE_NONE, edges != WLR_EDGE_NONE);
|
||||
wlr_xwayland_surface_set_maximized(
|
||||
c->surface.xwayland, edges != WLR_EDGE_NONE, edges != WLR_EDGE_NONE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (wl_resource_get_version(c->surface.xdg->toplevel->resource)
|
||||
>= XDG_TOPLEVEL_STATE_TILED_RIGHT_SINCE_VERSION) {
|
||||
if (wl_resource_get_version(c->surface.xdg->toplevel->resource) >=
|
||||
XDG_TOPLEVEL_STATE_TILED_RIGHT_SINCE_VERSION) {
|
||||
wlr_xdg_toplevel_set_tiled(c->surface.xdg->toplevel, edges);
|
||||
} else {
|
||||
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)
|
||||
{
|
||||
#ifdef XWAYLAND
|
||||
return client_is_unmanaged(c)
|
||||
&& wlr_xwayland_surface_override_redirect_wants_focus(c->surface.xwayland)
|
||||
&& wlr_xwayland_surface_icccm_input_model(c->surface.xwayland) != WLR_ICCCM_INPUT_MODEL_NONE;
|
||||
return client_is_unmanaged(c) &&
|
||||
wlr_xwayland_surface_override_redirect_wants_focus(c->surface.xwayland) &&
|
||||
wlr_xwayland_surface_icccm_input_model(c->surface.xwayland) !=
|
||||
WLR_ICCCM_INPUT_MODEL_NONE;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
84
config.def.h
84
config.def.h
@ -1,18 +1,20 @@
|
||||
/* Taken from https://github.com/djpohly/dwl/issues/466 */
|
||||
#define COLOR(hex) { ((hex >> 24) & 0xFF) / 255.0f, \
|
||||
((hex >> 16) & 0xFF) / 255.0f, \
|
||||
((hex >> 8) & 0xFF) / 255.0f, \
|
||||
(hex & 0xFF) / 255.0f }
|
||||
#define COLOR(hex) \
|
||||
{((hex >> 24) & 0xFF) / 255.0f, ((hex >> 16) & 0xFF) / 255.0f, \
|
||||
((hex >> 8) & 0xFF) / 255.0f, (hex & 0xFF) / 255.0f}
|
||||
|
||||
/* appearance */
|
||||
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 unsigned int borderpx = 1; /* border pixel of windows */
|
||||
static const float rootcolor[] = COLOR(0x222222ff);
|
||||
static const float bordercolor[] = COLOR(0x444444ff);
|
||||
static const float focuscolor[] = COLOR(0x005577ff);
|
||||
static const float urgentcolor[] = COLOR(0xff0000ff);
|
||||
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 unsigned int borderpx = 1; /* border pixel of windows */
|
||||
static const float rootcolor[] = COLOR(0x222222ff);
|
||||
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 */
|
||||
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 */
|
||||
#define TAGCOUNT (9)
|
||||
@ -20,13 +22,16 @@ static const float fullscreen_bg[] = {0.0f, 0.0f, 0.0f, 1.0f}; /* You ca
|
||||
/* logging */
|
||||
static int log_level = WLR_ERROR;
|
||||
|
||||
// clang-format off
|
||||
static const Rule rules[] = {
|
||||
/* app_id title tags mask isfloating monitor */
|
||||
{ "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" */
|
||||
/* 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) */
|
||||
static const Layout layouts[] = {
|
||||
/* symbol arrange function */
|
||||
@ -34,26 +39,29 @@ static const Layout layouts[] = {
|
||||
{ "><>", NULL }, /* no layout function means floating behavior */
|
||||
{ "[M]", monocle },
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
// clang-format off
|
||||
/* monitors */
|
||||
/* (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
|
||||
* https://gitlab.freedesktop.org/xorg/xserver/-/issues/899 */
|
||||
static const MonitorRule monrules[] = {
|
||||
/* name mfact nmaster scale layout rotate/reflect x y
|
||||
* example of a HiDPI laptop monitor:
|
||||
{ "eDP-1", 0.5f, 1, 2, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 }, */
|
||||
/* name mfact nmaster scale layout rotate/reflect x y
|
||||
* example of a HiDPI laptop monitor:
|
||||
{ "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 },
|
||||
/* default monitor rule: can be changed but cannot be eliminated; at least one monitor rule must exist */
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
/* keyboard */
|
||||
static const struct xkb_rule_names xkb_rules = {
|
||||
/* can specify fields: rules, model, layout, variant, options */
|
||||
/* example:
|
||||
.options = "ctrl:nocaps",
|
||||
*/
|
||||
.options = NULL,
|
||||
/* can specify fields: rules, model, layout, variant, options */
|
||||
/* example:
|
||||
.options = "ctrl:nocaps",
|
||||
*/
|
||||
.options = NULL,
|
||||
};
|
||||
|
||||
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_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:
|
||||
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_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;
|
||||
|
||||
/* 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 */
|
||||
#define MODKEY WLR_MODIFIER_ALT
|
||||
|
||||
#define TAGKEYS(KEY,SKEY,TAG) \
|
||||
{ MODKEY, KEY, view, {.ui = 1 << TAG} }, \
|
||||
{ MODKEY|WLR_MODIFIER_CTRL, KEY, toggleview, {.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 off
|
||||
#define TAGKEYS(KEY, SKEY, TAG) \
|
||||
{MODKEY, KEY, view, {.ui = 1 << TAG}}, \
|
||||
{MODKEY | WLR_MODIFIER_CTRL, KEY, toggleview, {.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 */
|
||||
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
|
||||
#define SHCMD(cmd) \
|
||||
{ \
|
||||
.v = (const char *[]) \
|
||||
{ \
|
||||
"/bin/sh", "-c", cmd, NULL \
|
||||
} \
|
||||
}
|
||||
|
||||
/* commands */
|
||||
static const char *termcmd[] = { "foot", NULL };
|
||||
static const char *menucmd[] = { "wmenu-run", NULL };
|
||||
static const char *termcmd[] = {"foot", NULL};
|
||||
static const char *menucmd[] = {"wmenu-run", NULL};
|
||||
|
||||
// clang-format off
|
||||
static const Key keys[] = {
|
||||
/* Note that Shift changes certain key codes: 2 -> at, etc. */
|
||||
/* 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(7), CHVT(8), CHVT(9), CHVT(10), CHVT(11), CHVT(12),
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
// clang-format off
|
||||
static const Button buttons[] = {
|
||||
{ MODKEY, BTN_LEFT, moveresize, {.ui = CurMove} },
|
||||
{ MODKEY, BTN_MIDDLE, togglefloating, {0} },
|
||||
{ MODKEY, BTN_RIGHT, moveresize, {.ui = CurResize} },
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
14
util.c
14
util.c
@ -1,21 +1,22 @@
|
||||
/* See LICENSE.dwm file for copyright and license details. */
|
||||
#include "util.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
void
|
||||
die(const char *fmt, ...) {
|
||||
die(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
|
||||
if (fmt[0] && fmt[strlen(fmt) - 1] == ':') {
|
||||
fputc(' ', stderr);
|
||||
perror(NULL);
|
||||
} else {
|
||||
@ -36,7 +37,8 @@ ecalloc(size_t nmemb, size_t size)
|
||||
}
|
||||
|
||||
int
|
||||
fd_set_nonblock(int fd) {
|
||||
fd_set_nonblock(int fd)
|
||||
{
|
||||
int flags = fcntl(fd, F_GETFL);
|
||||
if (flags < 0) {
|
||||
perror("fcntl(F_GETFL):");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user