opinionated reformatting

This commit is contained in:
Emile Clark-Boman 2025-08-27 12:50:29 +10:00
parent 9d18bb4439
commit 2be61ea3d1
3 changed files with 2581 additions and 2744 deletions

View file

@ -6,18 +6,14 @@
*/
/* Leave these functions first; they're used in the others */
static inline int
client_is_x11(Client *c)
{
static inline int client_is_x11(Client *c) {
#ifdef XWAYLAND
return c->type == X11;
#endif
return 0;
}
static inline struct wlr_surface *
client_surface(Client *c)
{
static inline struct wlr_surface *client_surface(Client *c) {
#ifdef XWAYLAND
if (client_is_x11(c))
return c->surface.xwayland->surface;
@ -25,9 +21,8 @@ client_surface(Client *c)
return c->surface.xdg->surface;
}
static inline int
toplevel_from_wlr_surface(struct wlr_surface *s, Client **pc, LayerSurface **pl)
{
static inline int toplevel_from_wlr_surface(struct wlr_surface *s, Client **pc,
LayerSurface **pl) {
struct wlr_xdg_surface *xdg_surface, *tmp_xdg_surface;
struct wlr_surface *root_surface;
struct wlr_layer_surface_v1 *layer_surface;
@ -50,7 +45,8 @@ toplevel_from_wlr_surface(struct wlr_surface *s, Client **pc, LayerSurface **pl)
}
#endif
if ((layer_surface = wlr_layer_surface_v1_try_from_wlr_surface(root_surface))) {
if ((layer_surface =
wlr_layer_surface_v1_try_from_wlr_surface(root_surface))) {
l = layer_surface->data;
type = LayerShell;
goto end;
@ -64,7 +60,8 @@ 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);
@ -89,9 +86,8 @@ end:
}
/* The others */
static inline void
client_activate_surface(struct wlr_surface *s, int activated)
{
static inline void client_activate_surface(struct wlr_surface *s,
int activated) {
struct wlr_xdg_toplevel *toplevel;
#ifdef XWAYLAND
struct wlr_xwayland_surface *xsurface;
@ -104,16 +100,16 @@ client_activate_surface(struct wlr_surface *s, int activated)
wlr_xdg_toplevel_set_activated(toplevel, activated);
}
static inline uint32_t
client_set_bounds(Client *c, int32_t width, int32_t height)
{
static inline uint32_t client_set_bounds(Client *c, int32_t width,
int32_t height) {
#ifdef XWAYLAND
if (client_is_x11(c))
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);
@ -121,19 +117,16 @@ client_set_bounds(Client *c, int32_t width, int32_t height)
return 0;
}
static inline const char *
client_get_appid(Client *c)
{
static inline const char *client_get_appid(Client *c) {
#ifdef XWAYLAND
if (client_is_x11(c))
return c->surface.xwayland->class ? c->surface.xwayland->class : "broken";
#endif
return c->surface.xdg->toplevel->app_id ? c->surface.xdg->toplevel->app_id : "broken";
return c->surface.xdg->toplevel->app_id ? c->surface.xdg->toplevel->app_id
: "broken";
}
static inline void
client_get_clip(Client *c, struct wlr_box *clip)
{
static inline void client_get_clip(Client *c, struct wlr_box *clip) {
*clip = (struct wlr_box){
.x = 0,
.y = 0,
@ -150,9 +143,7 @@ client_get_clip(Client *c, struct wlr_box *clip)
clip->y = c->surface.xdg->geometry.y;
}
static inline void
client_get_geometry(Client *c, struct wlr_box *geom)
{
static inline void client_get_geometry(Client *c, struct wlr_box *geom) {
#ifdef XWAYLAND
if (client_is_x11(c)) {
geom->x = c->surface.xwayland->x;
@ -165,9 +156,7 @@ client_get_geometry(Client *c, struct wlr_box *geom)
*geom = c->surface.xdg->geometry;
}
static inline Client *
client_get_parent(Client *c)
{
static inline Client *client_get_parent(Client *c) {
Client *p = NULL;
#ifdef XWAYLAND
if (client_is_x11(c)) {
@ -177,13 +166,12 @@ 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;
}
static inline int
client_has_children(Client *c)
{
static inline int client_has_children(Client *c) {
#ifdef XWAYLAND
if (client_is_x11(c))
return !wl_list_empty(&c->surface.xwayland->children);
@ -193,19 +181,16 @@ client_has_children(Client *c)
return wl_list_length(&c->surface.xdg->link) > 1;
}
static inline const char *
client_get_title(Client *c)
{
static inline const char *client_get_title(Client *c) {
#ifdef XWAYLAND
if (client_is_x11(c))
return c->surface.xwayland->title ? c->surface.xwayland->title : "broken";
#endif
return c->surface.xdg->toplevel->title ? c->surface.xdg->toplevel->title : "broken";
return c->surface.xdg->toplevel->title ? c->surface.xdg->toplevel->title
: "broken";
}
static inline int
client_is_float_type(Client *c)
{
static inline int client_is_float_type(Client *c) {
struct wlr_xdg_toplevel *toplevel;
struct wlr_xdg_toplevel_state state;
@ -216,29 +201,32 @@ 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
client_is_rendered_on_mon(Client *c, Monitor *m)
{
static inline int client_is_rendered_on_mon(Client *c, Monitor *m) {
/* This is needed for when you don't want to check formal assignment,
* but rather actual displaying of the pixels.
* Usually VISIBLEON suffices and is also faster. */
@ -246,15 +234,12 @@ 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;
}
static inline int
client_is_stopped(Client *c)
{
static inline int client_is_stopped(Client *c) {
int pid;
siginfo_t in = {0};
#ifdef XWAYLAND
@ -263,7 +248,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)
@ -278,9 +263,7 @@ client_is_stopped(Client *c)
return 0;
}
static inline int
client_is_unmanaged(Client *c)
{
static inline int client_is_unmanaged(Client *c) {
#ifdef XWAYLAND
if (client_is_x11(c))
return c->surface.xwayland->override_redirect;
@ -288,19 +271,16 @@ client_is_unmanaged(Client *c)
return 0;
}
static inline void
client_notify_enter(struct wlr_surface *s, struct wlr_keyboard *kb)
{
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);
}
static inline void
client_send_close(Client *c)
{
static inline void client_send_close(Client *c) {
#ifdef XWAYLAND
if (client_is_x11(c)) {
wlr_xwayland_surface_close(c->surface.xwayland);
@ -310,17 +290,14 @@ client_send_close(Client *c)
wlr_xdg_toplevel_send_close(c->surface.xdg->toplevel);
}
static inline void
client_set_border_color(Client *c, const float color[static 4])
{
static inline void client_set_border_color(Client *c,
const float color[static 4]) {
int i;
for (i = 0; i < 4; i++)
wlr_scene_rect_set_color(c->border[i], color);
}
static inline void
client_set_fullscreen(Client *c, int fullscreen)
{
static inline void client_set_fullscreen(Client *c, int fullscreen) {
#ifdef XWAYLAND
if (client_is_x11(c)) {
wlr_xwayland_surface_set_fullscreen(c->surface.xwayland, fullscreen);
@ -330,50 +307,45 @@ client_set_fullscreen(Client *c, int fullscreen)
wlr_xdg_toplevel_set_fullscreen(c->surface.xdg->toplevel, fullscreen);
}
static inline void
client_set_scale(struct wlr_surface *s, float scale)
{
static inline void client_set_scale(struct wlr_surface *s, float scale) {
wlr_fractional_scale_v1_notify_scale(s, scale);
wlr_surface_set_preferred_buffer_scale(s, (int32_t)ceilf(scale));
}
static inline uint32_t
client_set_size(Client *c, uint32_t width, uint32_t height)
{
static inline uint32_t 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);
return wlr_xdg_toplevel_set_size(c->surface.xdg->toplevel, (int32_t)width,
(int32_t)height);
}
static inline void
client_set_tiled(Client *c, uint32_t edges)
{
static inline void 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);
wlr_xdg_toplevel_set_maximized(c->surface.xdg->toplevel,
edges != WLR_EDGE_NONE);
}
}
static inline void
client_set_suspended(Client *c, int suspended)
{
static inline void client_set_suspended(Client *c, int suspended) {
#ifdef XWAYLAND
if (client_is_x11(c))
return;
@ -382,20 +354,18 @@ client_set_suspended(Client *c, int suspended)
wlr_xdg_toplevel_set_suspended(c->surface.xdg->toplevel, suspended);
}
static inline int
client_wants_focus(Client *c)
{
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;
}
static inline int
client_wants_fullscreen(Client *c)
{
static inline int client_wants_fullscreen(Client *c) {
#ifdef XWAYLAND
if (client_is_x11(c))
return c->surface.xwayland->fullscreen;

File diff suppressed because it is too large Load diff

View file

@ -1,21 +1,20 @@
/* See LICENSE.dwm file for copyright and license details. */
#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, ...) {
void 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 {
@ -25,9 +24,7 @@ die(const char *fmt, ...) {
exit(1);
}
void *
ecalloc(size_t nmemb, size_t size)
{
void *ecalloc(size_t nmemb, size_t size) {
void *p;
if (!(p = calloc(nmemb, size)))
@ -35,8 +32,7 @@ ecalloc(size_t nmemb, size_t size)
return p;
}
int
fd_set_nonblock(int fd) {
int fd_set_nonblock(int fd) {
int flags = fcntl(fd, F_GETFL);
if (flags < 0) {
perror("fcntl(F_GETFL):");