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);
@ -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;
} }
@ -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,11 +1,13 @@
/* 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
* tracking even if it's surface isn't
* visible */
static const unsigned int borderpx = 1; /* border pixel of windows */ static const unsigned int borderpx = 1; /* border pixel of windows */
static const float rootcolor[] = COLOR(0x222222ff); static const float rootcolor[] = COLOR(0x222222ff);
static const float bordercolor[] = COLOR(0x444444ff); static const float bordercolor[] = COLOR(0x444444ff);
@ -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,7 +39,9 @@ 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
@ -46,6 +53,7 @@ static const MonitorRule monrules[] = {
{ 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 = {
@ -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
// clang-format off
#define TAGKEYS(KEY, SKEY, TAG) \ #define TAGKEYS(KEY, SKEY, TAG) \
{MODKEY, KEY, view, {.ui = 1 << TAG}}, \ {MODKEY, KEY, view, {.ui = 1 << TAG}}, \
{MODKEY | WLR_MODIFIER_CTRL, KEY, toggleview, {.ui = 1 << TAG}}, \ {MODKEY | WLR_MODIFIER_CTRL, KEY, toggleview, {.ui = 1 << TAG}}, \
{MODKEY | WLR_MODIFIER_SHIFT, SKEY, tag, {.ui = 1 << TAG}}, \ {MODKEY | WLR_MODIFIER_SHIFT, SKEY, tag, {.ui = 1 << TAG}}, \
{MODKEY | WLR_MODIFIER_CTRL | WLR_MODIFIER_SHIFT, SKEY, toggletag, {.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

434
dwl.c
View File

@ -80,12 +80,27 @@
#define END(A) ((A) + LENGTH(A)) #define END(A) ((A) + LENGTH(A))
#define TAGMASK ((1u << TAGCOUNT) - 1) #define TAGMASK ((1u << TAGCOUNT) - 1)
#define LISTEN(E, L, H) wl_signal_add((E), ((L)->notify = (H), (L))) #define LISTEN(E, L, H) wl_signal_add((E), ((L)->notify = (H), (L)))
#define LISTEN_STATIC(E, H) do { struct wl_listener *_l = ecalloc(1, sizeof(*_l)); _l->notify = (H); wl_signal_add((E), _l); } while (0) #define LISTEN_STATIC(E, H) \
do { \
struct wl_listener *_l = ecalloc(1, sizeof(*_l)); \
_l->notify = (H); \
wl_signal_add((E), _l); \
} while (0)
/* enums */ /* enums */
enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */ enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */
enum { XDGShell, LayerShell, X11 }; /* client types */ enum { XDGShell, LayerShell, X11 }; /* client types */
enum { LyrBg, LyrBottom, LyrTile, LyrFloat, LyrTop, LyrFS, LyrOverlay, LyrBlock, NUM_LAYERS }; /* scene layers */ enum {
LyrBg,
LyrBottom,
LyrTile,
LyrFloat,
LyrTop,
LyrFS,
LyrOverlay,
LyrBlock,
NUM_LAYERS
}; /* scene layers */
typedef union { typedef union {
int i; int i;
@ -244,8 +259,8 @@ typedef struct {
static void applybounds(Client *c, struct wlr_box *bbox); static void applybounds(Client *c, struct wlr_box *bbox);
static void applyrules(Client *c); static void applyrules(Client *c);
static void arrange(Monitor *m); static void arrange(Monitor *m);
static void arrangelayer(Monitor *m, struct wl_list *list, static void arrangelayer(
struct wlr_box *usable_area, int exclusive); Monitor *m, struct wl_list *list, struct wlr_box *usable_area, int exclusive);
static void arrangelayers(Monitor *m); static void arrangelayers(Monitor *m);
static void axisnotify(struct wl_listener *listener, void *data); static void axisnotify(struct wl_listener *listener, void *data);
static void buttonpress(struct wl_listener *listener, void *data); static void buttonpress(struct wl_listener *listener, void *data);
@ -302,15 +317,15 @@ static void mapnotify(struct wl_listener *listener, void *data);
static void maximizenotify(struct wl_listener *listener, void *data); static void maximizenotify(struct wl_listener *listener, void *data);
static void monocle(Monitor *m); static void monocle(Monitor *m);
static void motionabsolute(struct wl_listener *listener, void *data); static void motionabsolute(struct wl_listener *listener, void *data);
static void motionnotify(uint32_t time, struct wlr_input_device *device, double sx, static void motionnotify(uint32_t time, struct wlr_input_device *device, double sx, double sy,
double sy, double sx_unaccel, double sy_unaccel); double sx_unaccel, double sy_unaccel);
static void motionrelative(struct wl_listener *listener, void *data); static void motionrelative(struct wl_listener *listener, void *data);
static void moveresize(const Arg *arg); static void moveresize(const Arg *arg);
static void outputmgrapply(struct wl_listener *listener, void *data); static void outputmgrapply(struct wl_listener *listener, void *data);
static void outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int test); static void outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int test);
static void outputmgrtest(struct wl_listener *listener, void *data); static void outputmgrtest(struct wl_listener *listener, void *data);
static void pointerfocus(Client *c, struct wlr_surface *surface, static void pointerfocus(
double sx, double sy, uint32_t time); Client *c, struct wlr_surface *surface, double sx, double sy, uint32_t time);
static void printstatus(void); static void printstatus(void);
static void powermgrsetmode(struct wl_listener *listener, void *data); static void powermgrsetmode(struct wl_listener *listener, void *data);
static void quit(const Arg *arg); static void quit(const Arg *arg);
@ -349,8 +364,8 @@ static void view(const Arg *arg);
static void virtualkeyboard(struct wl_listener *listener, void *data); static void virtualkeyboard(struct wl_listener *listener, void *data);
static void virtualpointer(struct wl_listener *listener, void *data); static void virtualpointer(struct wl_listener *listener, void *data);
static Monitor *xytomon(double x, double y); static Monitor *xytomon(double x, double y);
static void xytonode(double x, double y, struct wlr_surface **psurface, static void xytonode(double x, double y, struct wlr_surface **psurface, Client **pc,
Client **pc, LayerSurface **pl, double *nx, double *ny); LayerSurface **pl, double *nx, double *ny);
static void zoom(const Arg *arg); static void zoom(const Arg *arg);
/* variables */ /* variables */
@ -488,12 +503,12 @@ applyrules(Client *c)
title = client_get_title(c); title = client_get_title(c);
for (r = rules; r < END(rules); r++) { for (r = rules; r < END(rules); r++) {
if ((!r->title || strstr(title, r->title)) if ((!r->title || strstr(title, r->title)) && (!r->id || strstr(appid, r->id))) {
&& (!r->id || strstr(appid, r->id))) {
c->isfloating = r->isfloating; c->isfloating = r->isfloating;
newtags |= r->tags; newtags |= r->tags;
i = 0; i = 0;
wl_list_for_each(m, &mons, link) { wl_list_for_each(m, &mons, link)
{
if (r->monitor == i++) if (r->monitor == i++)
mon = m; mon = m;
} }
@ -512,29 +527,28 @@ arrange(Monitor *m)
if (!m->wlr_output->enabled) if (!m->wlr_output->enabled)
return; return;
wl_list_for_each(c, &clients, link) { wl_list_for_each(c, &clients, link)
{
if (c->mon == m) { if (c->mon == m) {
wlr_scene_node_set_enabled(&c->scene->node, VISIBLEON(c, m)); wlr_scene_node_set_enabled(&c->scene->node, VISIBLEON(c, m));
client_set_suspended(c, !VISIBLEON(c, m)); client_set_suspended(c, !VISIBLEON(c, m));
} }
} }
wlr_scene_node_set_enabled(&m->fullscreen_bg->node, wlr_scene_node_set_enabled(&m->fullscreen_bg->node, (c = focustop(m)) && c->isfullscreen);
(c = focustop(m)) && c->isfullscreen);
strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, LENGTH(m->ltsymbol)); strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, LENGTH(m->ltsymbol));
/* We move all clients (except fullscreen and unmanaged) to LyrTile while /* We move all clients (except fullscreen and unmanaged) to LyrTile while
* in floating layout to avoid "real" floating clients be always on top */ * in floating layout to avoid "real" floating clients be always on top */
wl_list_for_each(c, &clients, link) { wl_list_for_each(c, &clients, link)
{
if (c->mon != m || c->scene->node.parent == layers[LyrFS]) if (c->mon != m || c->scene->node.parent == layers[LyrFS])
continue; continue;
wlr_scene_node_reparent(&c->scene->node, wlr_scene_node_reparent(&c->scene->node,
(!m->lt[m->sellt]->arrange && c->isfloating) (!m->lt[m->sellt]->arrange && c->isfloating) ? layers[LyrTile]
? layers[LyrTile] : (m->lt[m->sellt]->arrange && c->isfloating) ? layers[LyrFloat]
: (m->lt[m->sellt]->arrange && c->isfloating)
? layers[LyrFloat]
: c->scene->node.parent); : c->scene->node.parent);
} }
@ -550,7 +564,8 @@ arrangelayer(Monitor *m, struct wl_list *list, struct wlr_box *usable_area, int
LayerSurface *l; LayerSurface *l;
struct wlr_box full_area = m->m; struct wlr_box full_area = m->m;
wl_list_for_each(l, list, link) { wl_list_for_each(l, list, link)
{
struct wlr_layer_surface_v1 *layer_surface = l->layer_surface; struct wlr_layer_surface_v1 *layer_surface = l->layer_surface;
if (!layer_surface->initialized) if (!layer_surface->initialized)
@ -592,7 +607,8 @@ arrangelayers(Monitor *m)
/* Find topmost keyboard interactive layer, if such a layer exists */ /* Find topmost keyboard interactive layer, if such a layer exists */
for (i = 0; i < (int)LENGTH(layers_above_shell); i++) { for (i = 0; i < (int)LENGTH(layers_above_shell); i++) {
wl_list_for_each_reverse(l, &m->layers[layers_above_shell[i]], link) { wl_list_for_each_reverse(l, &m->layers[layers_above_shell[i]], link)
{
if (locked || !l->layer_surface->current.keyboard_interactive || !l->mapped) if (locked || !l->layer_surface->current.keyboard_interactive || !l->mapped)
continue; continue;
/* Deactivate the focused client. */ /* Deactivate the focused client. */
@ -614,8 +630,7 @@ axisnotify(struct wl_listener *listener, void *data)
/* TODO: allow usage of scroll wheel for mousebindings, it can be implemented /* TODO: allow usage of scroll wheel for mousebindings, it can be implemented
* by checking the event's orientation and the delta of the event */ * by checking the event's orientation and the delta of the event */
/* Notify the client with pointer focus of the axis event. */ /* Notify the client with pointer focus of the axis event. */
wlr_seat_pointer_notify_axis(seat, wlr_seat_pointer_notify_axis(seat, event->time_msec, event->orientation, event->delta,
event->time_msec, event->orientation, event->delta,
event->delta_discrete, event->source, event->relative_direction); event->delta_discrete, event->source, event->relative_direction);
} }
@ -645,8 +660,8 @@ buttonpress(struct wl_listener *listener, void *data)
keyboard = wlr_seat_get_keyboard(seat); keyboard = wlr_seat_get_keyboard(seat);
mods = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0; mods = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0;
for (b = buttons; b < END(buttons); b++) { for (b = buttons; b < END(buttons); b++) {
if (CLEANMASK(mods) == CLEANMASK(b->mod) && if (CLEANMASK(mods) == CLEANMASK(b->mod) && event->button == b->button &&
event->button == b->button && b->func) { b->func) {
b->func(&b->arg); b->func(&b->arg);
return; return;
} }
@ -669,8 +684,7 @@ buttonpress(struct wl_listener *listener, void *data)
} }
/* If the event wasn't handled by the compositor, notify the client with /* If the event wasn't handled by the compositor, notify the client with
* pointer focus that a button press has occurred */ * pointer focus that a button press has occurred */
wlr_seat_pointer_notify_button(seat, wlr_seat_pointer_notify_button(seat, event->time_msec, event->button, event->state);
event->time_msec, event->button, event->state);
} }
void void
@ -684,11 +698,13 @@ checkidleinhibitor(struct wlr_surface *exclude)
{ {
int inhibited = 0, unused_lx, unused_ly; int inhibited = 0, unused_lx, unused_ly;
struct wlr_idle_inhibitor_v1 *inhibitor; struct wlr_idle_inhibitor_v1 *inhibitor;
wl_list_for_each(inhibitor, &idle_inhibit_mgr->inhibitors, link) { wl_list_for_each(inhibitor, &idle_inhibit_mgr->inhibitors, link)
{
struct wlr_surface *surface = wlr_surface_get_root_surface(inhibitor->surface); struct wlr_surface *surface = wlr_surface_get_root_surface(inhibitor->surface);
struct wlr_scene_tree *tree = surface->data; struct wlr_scene_tree *tree = surface->data;
if (exclude != surface && (bypass_surface_visibility || (!tree if (exclude != surface &&
|| wlr_scene_node_coords(&tree->node, &unused_lx, &unused_ly)))) { (bypass_surface_visibility || (!tree || wlr_scene_node_coords(&tree->node,
&unused_lx, &unused_ly)))) {
inhibited = 1; inhibited = 1;
break; break;
} }
@ -807,10 +823,15 @@ closemon(Monitor *m)
selmon = NULL; selmon = NULL;
} }
wl_list_for_each(c, &clients, link) { wl_list_for_each(c, &clients, link)
{
if (c->isfloating && c->geom.x > m->m.width) if (c->isfloating && c->geom.x > m->m.width)
resize(c, (struct wlr_box){.x = c->geom.x - m->w.width, .y = c->geom.y, resize(c,
.width = c->geom.width, .height = c->geom.height}, 0); (struct wlr_box){.x = c->geom.x - m->w.width,
.y = c->geom.y,
.width = c->geom.width,
.height = c->geom.height},
0);
if (c->mon == m) if (c->mon == m)
setmon(c, selmon, c->tags); setmon(c, selmon, c->tags);
} }
@ -846,8 +867,10 @@ commitlayersurfacenotify(struct wl_listener *listener, void *data)
wlr_scene_node_reparent(&l->scene->node, scene_layer); wlr_scene_node_reparent(&l->scene->node, scene_layer);
wl_list_remove(&l->link); wl_list_remove(&l->link);
wl_list_insert(&l->mon->layers[layer_surface->current.layer], &l->link); wl_list_insert(&l->mon->layers[layer_surface->current.layer], &l->link);
wlr_scene_node_reparent(&l->popups->node, (layer_surface->current.layer wlr_scene_node_reparent(&l->popups->node,
< ZWLR_LAYER_SHELL_V1_LAYER_TOP ? layers[LyrTop] : scene_layer)); (layer_surface->current.layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP
? layers[LyrTop]
: scene_layer));
} }
arrangelayers(l->mon); arrangelayers(l->mon);
@ -871,8 +894,8 @@ commitnotify(struct wl_listener *listener, void *data)
} }
setmon(c, NULL, 0); /* Make sure to reapply rules in mapnotify() */ setmon(c, NULL, 0); /* Make sure to reapply rules in mapnotify() */
wlr_xdg_toplevel_set_wm_capabilities(c->surface.xdg->toplevel, wlr_xdg_toplevel_set_wm_capabilities(
WLR_XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN); c->surface.xdg->toplevel, WLR_XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN);
if (c->decoration) if (c->decoration)
requestdecorationmode(&c->set_decoration_mode, c->decoration); requestdecorationmode(&c->set_decoration_mode, c->decoration);
wlr_xdg_toplevel_set_size(c->surface.xdg->toplevel, 0, 0); wlr_xdg_toplevel_set_size(c->surface.xdg->toplevel, 0, 0);
@ -902,8 +925,7 @@ commitpopup(struct wl_listener *listener, void *data)
type = toplevel_from_wlr_surface(popup->base->surface, &c, &l); type = toplevel_from_wlr_surface(popup->base->surface, &c, &l);
if (!popup->parent || type < 0) if (!popup->parent || type < 0)
return; return;
popup->base->surface->data = wlr_scene_xdg_surface_create( popup->base->surface->data = wlr_scene_xdg_surface_create(popup->parent->data, popup->base);
popup->parent->data, popup->base);
if ((l && !l->mon) || (c && !c->mon)) { if ((l && !l->mon) || (c && !c->mon)) {
wlr_xdg_popup_destroy(popup); wlr_xdg_popup_destroy(popup);
return; return;
@ -960,8 +982,7 @@ createkeyboardgroup(void)
/* Prepare an XKB keymap and assign it to the keyboard group. */ /* Prepare an XKB keymap and assign it to the keyboard group. */
context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!(keymap = xkb_keymap_new_from_names(context, &xkb_rules, if (!(keymap = xkb_keymap_new_from_names(context, &xkb_rules, XKB_KEYMAP_COMPILE_NO_FLAGS)))
XKB_KEYMAP_COMPILE_NO_FLAGS)))
die("failed to compile keymap"); die("failed to compile keymap");
wlr_keyboard_set_keymap(&group->wlr_group->keyboard, keymap); wlr_keyboard_set_keymap(&group->wlr_group->keyboard, keymap);
@ -993,8 +1014,8 @@ createlayersurface(struct wl_listener *listener, void *data)
struct wlr_surface *surface = layer_surface->surface; struct wlr_surface *surface = layer_surface->surface;
struct wlr_scene_tree *scene_layer = layers[layermap[layer_surface->pending.layer]]; struct wlr_scene_tree *scene_layer = layers[layermap[layer_surface->pending.layer]];
if (!layer_surface->output if (!layer_surface->output &&
&& !(layer_surface->output = selmon ? selmon->wlr_output : NULL)) { !(layer_surface->output = selmon ? selmon->wlr_output : NULL)) {
wlr_layer_surface_v1_destroy(layer_surface); wlr_layer_surface_v1_destroy(layer_surface);
return; return;
} }
@ -1009,8 +1030,9 @@ createlayersurface(struct wl_listener *listener, void *data)
l->mon = layer_surface->output->data; l->mon = layer_surface->output->data;
l->scene_layer = wlr_scene_layer_surface_v1_create(scene_layer, layer_surface); l->scene_layer = wlr_scene_layer_surface_v1_create(scene_layer, layer_surface);
l->scene = l->scene_layer->tree; l->scene = l->scene_layer->tree;
l->popups = surface->data = wlr_scene_tree_create(layer_surface->current.layer l->popups = surface->data = wlr_scene_tree_create(
< ZWLR_LAYER_SHELL_V1_LAYER_TOP ? layers[LyrTop] : scene_layer); layer_surface->current.layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP ? layers[LyrTop]
: scene_layer);
l->scene->node.data = l->popups->node.data = l; l->scene->node.data = l->popups->node.data = l;
wl_list_insert(&l->mon->layers[layer_surface->pending.layer], &l->link); wl_list_insert(&l->mon->layers[layer_surface->pending.layer], &l->link);
@ -1023,8 +1045,8 @@ createlocksurface(struct wl_listener *listener, void *data)
SessionLock *lock = wl_container_of(listener, lock, new_surface); SessionLock *lock = wl_container_of(listener, lock, new_surface);
struct wlr_session_lock_surface_v1 *lock_surface = data; struct wlr_session_lock_surface_v1 *lock_surface = data;
Monitor *m = lock_surface->output->data; Monitor *m = lock_surface->output->data;
struct wlr_scene_tree *scene_tree = lock_surface->surface->data struct wlr_scene_tree *scene_tree = lock_surface->surface->data =
= wlr_scene_subsurface_tree_create(lock->scene, lock_surface->surface); wlr_scene_subsurface_tree_create(lock->scene, lock_surface->surface);
m->lock_surface = lock_surface; m->lock_surface = lock_surface;
wlr_scene_node_set_position(&scene_tree->node, m->m.x, m->m.y); wlr_scene_node_set_position(&scene_tree->node, m->m.x, m->m.y);
@ -1142,8 +1164,8 @@ void
createpointer(struct wlr_pointer *pointer) createpointer(struct wlr_pointer *pointer)
{ {
struct libinput_device *device; struct libinput_device *device;
if (wlr_input_device_is_libinput(&pointer->base) if (wlr_input_device_is_libinput(&pointer->base) &&
&& (device = wlr_libinput_get_device_handle(&pointer->base))) { (device = wlr_libinput_get_device_handle(&pointer->base))) {
if (libinput_device_config_tap_get_finger_count(device)) { if (libinput_device_config_tap_get_finger_count(device)) {
libinput_device_config_tap_set_enabled(device, tap_to_click); libinput_device_config_tap_set_enabled(device, tap_to_click);
@ -1153,7 +1175,8 @@ createpointer(struct wlr_pointer *pointer)
} }
if (libinput_device_config_scroll_has_natural_scroll(device)) if (libinput_device_config_scroll_has_natural_scroll(device))
libinput_device_config_scroll_set_natural_scroll_enabled(device, natural_scrolling); libinput_device_config_scroll_set_natural_scroll_enabled(
device, natural_scrolling);
if (libinput_device_config_dwt_is_available(device)) if (libinput_device_config_dwt_is_available(device))
libinput_device_config_dwt_set_enabled(device, disable_while_typing); libinput_device_config_dwt_set_enabled(device, disable_while_typing);
@ -1162,12 +1185,15 @@ createpointer(struct wlr_pointer *pointer)
libinput_device_config_left_handed_set(device, left_handed); libinput_device_config_left_handed_set(device, left_handed);
if (libinput_device_config_middle_emulation_is_available(device)) if (libinput_device_config_middle_emulation_is_available(device))
libinput_device_config_middle_emulation_set_enabled(device, middle_button_emulation); libinput_device_config_middle_emulation_set_enabled(
device, middle_button_emulation);
if (libinput_device_config_scroll_get_methods(device) != LIBINPUT_CONFIG_SCROLL_NO_SCROLL) if (libinput_device_config_scroll_get_methods(device) !=
LIBINPUT_CONFIG_SCROLL_NO_SCROLL)
libinput_device_config_scroll_set_method(device, scroll_method); libinput_device_config_scroll_set_method(device, scroll_method);
if (libinput_device_config_click_get_methods(device) != LIBINPUT_CONFIG_CLICK_METHOD_NONE) if (libinput_device_config_click_get_methods(device) !=
LIBINPUT_CONFIG_CLICK_METHOD_NONE)
libinput_device_config_click_set_method(device, click_method); libinput_device_config_click_set_method(device, click_method);
if (libinput_device_config_send_events_get_modes(device)) if (libinput_device_config_send_events_get_modes(device))
@ -1187,8 +1213,8 @@ createpointerconstraint(struct wl_listener *listener, void *data)
{ {
PointerConstraint *pointer_constraint = ecalloc(1, sizeof(*pointer_constraint)); PointerConstraint *pointer_constraint = ecalloc(1, sizeof(*pointer_constraint));
pointer_constraint->constraint = data; pointer_constraint->constraint = data;
LISTEN(&pointer_constraint->constraint->events.destroy, LISTEN(&pointer_constraint->constraint->events.destroy, &pointer_constraint->destroy,
&pointer_constraint->destroy, destroypointerconstraint); destroypointerconstraint);
} }
void void
@ -1354,7 +1380,8 @@ destroynotify(struct wl_listener *listener, void *data)
void void
destroypointerconstraint(struct wl_listener *listener, void *data) destroypointerconstraint(struct wl_listener *listener, void *data)
{ {
PointerConstraint *pointer_constraint = wl_container_of(listener, pointer_constraint, destroy); PointerConstraint *pointer_constraint =
wl_container_of(listener, pointer_constraint, destroy);
if (active_constraint == pointer_constraint->constraint) { if (active_constraint == pointer_constraint->constraint) {
cursorwarptohint(); cursorwarptohint();
@ -1390,12 +1417,12 @@ dirtomon(enum wlr_direction dir)
struct wlr_output *next; struct wlr_output *next;
if (!wlr_output_layout_get(output_layout, selmon->wlr_output)) if (!wlr_output_layout_get(output_layout, selmon->wlr_output))
return selmon; return selmon;
if ((next = wlr_output_layout_adjacent_output(output_layout, if ((next = wlr_output_layout_adjacent_output(
dir, selmon->wlr_output, selmon->m.x, selmon->m.y))) output_layout, dir, selmon->wlr_output, selmon->m.x, selmon->m.y)))
return next->data; return next->data;
if ((next = wlr_output_layout_farthest_output(output_layout, if ((next = wlr_output_layout_farthest_output(output_layout,
dir ^ (WLR_DIRECTION_LEFT|WLR_DIRECTION_RIGHT), dir ^ (WLR_DIRECTION_LEFT | WLR_DIRECTION_RIGHT), selmon->wlr_output,
selmon->wlr_output, selmon->m.x, selmon->m.y))) selmon->m.x, selmon->m.y)))
return next->data; return next->data;
return selmon; return selmon;
} }
@ -1442,14 +1469,14 @@ focusclient(Client *c, int lift)
/* If an overlay is focused, don't focus or activate the client, /* If an overlay is focused, don't focus or activate the client,
* but only update its position in fstack to render its border with focuscolor * but only update its position in fstack to render its border with focuscolor
* and focus it after the overlay is closed. */ * and focus it after the overlay is closed. */
if (old_client_type == LayerShell && wlr_scene_node_coords( if (old_client_type == LayerShell &&
&old_l->scene->node, &unused_lx, &unused_ly) wlr_scene_node_coords(&old_l->scene->node, &unused_lx, &unused_ly) &&
&& old_l->layer_surface->current.layer >= ZWLR_LAYER_SHELL_V1_LAYER_TOP) { old_l->layer_surface->current.layer >= ZWLR_LAYER_SHELL_V1_LAYER_TOP) {
return; return;
} else if (old_c && old_c == exclusive_focus && client_wants_focus(old_c)) { } else if (old_c && old_c == exclusive_focus && client_wants_focus(old_c)) {
return; return;
/* Don't deactivate old client if the new one wants focus, as this causes issues with winecfg /* Don't deactivate old client if the new one wants focus, as this causes
* and probably other clients */ * issues with winecfg and probably other clients */
} else if (old_c && !client_is_unmanaged(old_c) && (!c || !client_wants_focus(c))) { } else if (old_c && !client_is_unmanaged(old_c) && (!c || !client_wants_focus(c))) {
client_set_border_color(old_c, bordercolor); client_set_border_color(old_c, bordercolor);
@ -1494,14 +1521,16 @@ focusstack(const Arg *arg)
if (!sel || (sel->isfullscreen && !client_has_children(sel))) if (!sel || (sel->isfullscreen && !client_has_children(sel)))
return; return;
if (arg->i > 0) { if (arg->i > 0) {
wl_list_for_each(c, &sel->link, link) { wl_list_for_each(c, &sel->link, link)
{
if (&c->link == &clients) if (&c->link == &clients)
continue; /* wrap past the sentinel node */ continue; /* wrap past the sentinel node */
if (VISIBLEON(c, selmon)) if (VISIBLEON(c, selmon))
break; /* found it */ break; /* found it */
} }
} else { } else {
wl_list_for_each_reverse(c, &sel->link, link) { wl_list_for_each_reverse(c, &sel->link, link)
{
if (&c->link == &clients) if (&c->link == &clients)
continue; /* wrap past the sentinel node */ continue; /* wrap past the sentinel node */
if (VISIBLEON(c, selmon)) if (VISIBLEON(c, selmon))
@ -1519,7 +1548,8 @@ Client *
focustop(Monitor *m) focustop(Monitor *m)
{ {
Client *c; Client *c;
wl_list_for_each(c, &fstack, flink) { wl_list_for_each(c, &fstack, flink)
{
if (VISIBLEON(c, m)) if (VISIBLEON(c, m))
return c; return c;
} }
@ -1550,7 +1580,8 @@ gpureset(struct wl_listener *listener, void *data)
wlr_compositor_set_renderer(compositor, drw); wlr_compositor_set_renderer(compositor, drw);
wl_list_for_each(m, &mons, link) { wl_list_for_each(m, &mons, link)
{
wlr_output_init_render(m->wlr_output, alloc, drw); wlr_output_init_render(m->wlr_output, alloc, drw);
} }
@ -1562,7 +1593,8 @@ void
handlesig(int signo) handlesig(int signo)
{ {
if (signo == SIGCHLD) if (signo == SIGCHLD)
while (waitpid(-1, NULL, WNOHANG) > 0); while (waitpid(-1, NULL, WNOHANG) > 0)
;
else if (signo == SIGINT || signo == SIGTERM) else if (signo == SIGINT || signo == SIGTERM)
quit(NULL); quit(NULL);
} }
@ -1616,9 +1648,8 @@ keybinding(uint32_t mods, xkb_keysym_t sym)
*/ */
const Key *k; const Key *k;
for (k = keys; k < END(keys); k++) { for (k = keys; k < END(keys); k++) {
if (CLEANMASK(mods) == CLEANMASK(k->mod) if (CLEANMASK(mods) == CLEANMASK(k->mod) &&
&& xkb_keysym_to_lower(sym) == xkb_keysym_to_lower(k->keysym) xkb_keysym_to_lower(sym) == xkb_keysym_to_lower(k->keysym) && k->func) {
&& k->func) {
k->func(&k->arg); k->func(&k->arg);
return 1; return 1;
} }
@ -1638,8 +1669,7 @@ keypress(struct wl_listener *listener, void *data)
uint32_t keycode = event->keycode + 8; uint32_t keycode = event->keycode + 8;
/* Get a list of keysyms based on the keymap for this keyboard */ /* Get a list of keysyms based on the keymap for this keyboard */
const xkb_keysym_t *syms; const xkb_keysym_t *syms;
int nsyms = xkb_state_key_get_syms( int nsyms = xkb_state_key_get_syms(group->wlr_group->keyboard.xkb_state, keycode, &syms);
group->wlr_group->keyboard.xkb_state, keycode, &syms);
int handled = 0; int handled = 0;
uint32_t mods = wlr_keyboard_get_modifiers(&group->wlr_group->keyboard); uint32_t mods = wlr_keyboard_get_modifiers(&group->wlr_group->keyboard);
@ -1657,8 +1687,8 @@ keypress(struct wl_listener *listener, void *data)
group->mods = mods; group->mods = mods;
group->keysyms = syms; group->keysyms = syms;
group->nsyms = nsyms; group->nsyms = nsyms;
wl_event_source_timer_update(group->key_repeat_source, wl_event_source_timer_update(
group->wlr_group->keyboard.repeat_info.delay); group->key_repeat_source, group->wlr_group->keyboard.repeat_info.delay);
} else { } else {
group->nsyms = 0; group->nsyms = 0;
wl_event_source_timer_update(group->key_repeat_source, 0); wl_event_source_timer_update(group->key_repeat_source, 0);
@ -1669,8 +1699,7 @@ keypress(struct wl_listener *listener, void *data)
wlr_seat_set_keyboard(seat, &group->wlr_group->keyboard); wlr_seat_set_keyboard(seat, &group->wlr_group->keyboard);
/* Pass unhandled keycodes along to the client. */ /* Pass unhandled keycodes along to the client. */
wlr_seat_keyboard_notify_key(seat, event->time_msec, wlr_seat_keyboard_notify_key(seat, event->time_msec, event->keycode, event->state);
event->keycode, event->state);
} }
void void
@ -1682,8 +1711,7 @@ keypressmod(struct wl_listener *listener, void *data)
wlr_seat_set_keyboard(seat, &group->wlr_group->keyboard); wlr_seat_set_keyboard(seat, &group->wlr_group->keyboard);
/* Send modifiers to the client. */ /* Send modifiers to the client. */
wlr_seat_keyboard_notify_modifiers(seat, wlr_seat_keyboard_notify_modifiers(seat, &group->wlr_group->keyboard.modifiers);
&group->wlr_group->keyboard.modifiers);
} }
int int
@ -1694,8 +1722,8 @@ keyrepeat(void *data)
if (!group->nsyms || group->wlr_group->keyboard.repeat_info.rate <= 0) if (!group->nsyms || group->wlr_group->keyboard.repeat_info.rate <= 0)
return 0; return 0;
wl_event_source_timer_update(group->key_repeat_source, wl_event_source_timer_update(
1000 / group->wlr_group->keyboard.repeat_info.rate); group->key_repeat_source, 1000 / group->wlr_group->keyboard.repeat_info.rate);
for (i = 0; i < group->nsyms; i++) for (i = 0; i < group->nsyms; i++)
keybinding(group->mods, group->keysyms[i]); keybinding(group->mods, group->keysyms[i]);
@ -1769,8 +1797,8 @@ mapnotify(struct wl_listener *listener, void *data)
} }
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
c->border[i] = wlr_scene_rect_create(c->scene, 0, 0, c->border[i] = wlr_scene_rect_create(
c->isurgent ? urgentcolor : bordercolor); c->scene, 0, 0, c->isurgent ? urgentcolor : bordercolor);
c->border[i]->node.data = c; c->border[i]->node.data = c;
} }
@ -1797,7 +1825,8 @@ mapnotify(struct wl_listener *listener, void *data)
unset_fullscreen: unset_fullscreen:
m = c->mon ? c->mon : xytomon(c->geom.x, c->geom.y); m = c->mon ? c->mon : xytomon(c->geom.x, c->geom.y);
wl_list_for_each(w, &clients, link) { wl_list_for_each(w, &clients, link)
{
if (w != c && w != p && w->isfullscreen && m == w->mon && (w->tags & c->tags)) if (w != c && w != p && w->isfullscreen && m == w->mon && (w->tags & c->tags))
setfullscreen(w, 0); setfullscreen(w, 0);
} }
@ -1815,9 +1844,9 @@ maximizenotify(struct wl_listener *listener, void *data)
* protocol version * protocol version
* wlr_xdg_surface_schedule_configure() is used to send an empty reply. */ * wlr_xdg_surface_schedule_configure() is used to send an empty reply. */
Client *c = wl_container_of(listener, c, maximize); Client *c = wl_container_of(listener, c, maximize);
if (c->surface.xdg->initialized if (c->surface.xdg->initialized &&
&& wl_resource_get_version(c->surface.xdg->toplevel->resource) wl_resource_get_version(c->surface.xdg->toplevel->resource) <
< XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION) XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION)
wlr_xdg_surface_schedule_configure(c->surface.xdg); wlr_xdg_surface_schedule_configure(c->surface.xdg);
} }
@ -1827,7 +1856,8 @@ monocle(Monitor *m)
Client *c; Client *c;
int n = 0; int n = 0;
wl_list_for_each(c, &clients, link) { wl_list_for_each(c, &clients, link)
{
if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen) if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
continue; continue;
resize(c, m->w, 0); resize(c, m->w, 0);
@ -1853,7 +1883,8 @@ motionabsolute(struct wl_listener *listener, void *data)
if (!event->time_msec) /* this is 0 with virtual pointers */ if (!event->time_msec) /* this is 0 with virtual pointers */
wlr_cursor_warp_absolute(cursor, &event->pointer->base, event->x, event->y); wlr_cursor_warp_absolute(cursor, &event->pointer->base, event->x, event->y);
wlr_cursor_absolute_to_layout_coords(cursor, &event->pointer->base, event->x, event->y, &lx, &ly); wlr_cursor_absolute_to_layout_coords(
cursor, &event->pointer->base, event->x, event->y, &lx, &ly);
dx = lx - cursor->x; dx = lx - cursor->x;
dy = ly - cursor->y; dy = ly - cursor->y;
motionnotify(event->time_msec, &event->pointer->base, dx, dy, dx, dy); motionnotify(event->time_msec, &event->pointer->base, dx, dy, dx, dy);
@ -1872,9 +1903,9 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double d
/* Find the client under the pointer and send the event along. */ /* Find the client under the pointer and send the event along. */
xytonode(cursor->x, cursor->y, &surface, &c, NULL, &sx, &sy); xytonode(cursor->x, cursor->y, &surface, &c, NULL, &sx, &sy);
if (cursor_mode == CurPressed && !seat->drag if (cursor_mode == CurPressed && !seat->drag &&
&& surface != seat->pointer_state.focused_surface surface != seat->pointer_state.focused_surface &&
&& toplevel_from_wlr_surface(seat->pointer_state.focused_surface, &w, &l) >= 0) { toplevel_from_wlr_surface(seat->pointer_state.focused_surface, &w, &l) >= 0) {
c = w; c = w;
surface = seat->pointer_state.focused_surface; surface = seat->pointer_state.focused_surface;
sx = cursor->x - (l ? l->scene->node.x : w->geom.x); sx = cursor->x - (l ? l->scene->node.x : w->geom.x);
@ -1883,20 +1914,20 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double d
/* time is 0 in internal calls meant to restore pointer focus. */ /* time is 0 in internal calls meant to restore pointer focus. */
if (time) { if (time) {
wlr_relative_pointer_manager_v1_send_relative_motion( wlr_relative_pointer_manager_v1_send_relative_motion(relative_pointer_mgr, seat,
relative_pointer_mgr, seat, (uint64_t)time * 1000, (uint64_t)time * 1000, dx, dy, dx_unaccel, dy_unaccel);
dx, dy, dx_unaccel, dy_unaccel);
wl_list_for_each(constraint, &pointer_constraints->constraints, link) wl_list_for_each(constraint, &pointer_constraints->constraints, link)
cursorconstrain(constraint); cursorconstrain(constraint);
if (active_constraint && cursor_mode != CurResize && cursor_mode != CurMove) { if (active_constraint && cursor_mode != CurResize && cursor_mode != CurMove) {
toplevel_from_wlr_surface(active_constraint->surface, &c, NULL); toplevel_from_wlr_surface(active_constraint->surface, &c, NULL);
if (c && active_constraint->surface == seat->pointer_state.focused_surface) { if (c &&
active_constraint->surface == seat->pointer_state.focused_surface) {
sx = cursor->x - c->geom.x - c->bw; sx = cursor->x - c->geom.x - c->bw;
sy = cursor->y - c->geom.y - c->bw; sy = cursor->y - c->geom.y - c->bw;
if (wlr_region_confine(&active_constraint->region, sx, sy, if (wlr_region_confine(&active_constraint->region, sx, sy, sx + dx,
sx + dx, sy + dy, &sx_confined, &sy_confined)) { sy + dy, &sx_confined, &sy_confined)) {
dx = sx_confined - sx; dx = sx_confined - sx;
dy = sy_confined - sy; dy = sy_confined - sy;
} }
@ -1920,12 +1951,20 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double d
/* If we are currently grabbing the mouse, handle and return */ /* If we are currently grabbing the mouse, handle and return */
if (cursor_mode == CurMove) { if (cursor_mode == CurMove) {
/* Move the grabbed client to the new position. */ /* Move the grabbed client to the new position. */
resize(grabc, (struct wlr_box){.x = (int)round(cursor->x) - grabcx, .y = (int)round(cursor->y) - grabcy, resize(grabc,
.width = grabc->geom.width, .height = grabc->geom.height}, 1); (struct wlr_box){.x = (int)round(cursor->x) - grabcx,
.y = (int)round(cursor->y) - grabcy,
.width = grabc->geom.width,
.height = grabc->geom.height},
1);
return; return;
} else if (cursor_mode == CurResize) { } else if (cursor_mode == CurResize) {
resize(grabc, (struct wlr_box){.x = grabc->geom.x, .y = grabc->geom.y, resize(grabc,
.width = (int)round(cursor->x) - grabc->geom.x, .height = (int)round(cursor->y) - grabc->geom.y}, 1); (struct wlr_box){.x = grabc->geom.x,
.y = grabc->geom.y,
.width = (int)round(cursor->x) - grabc->geom.x,
.height = (int)round(cursor->y) - grabc->geom.y},
1);
return; return;
} }
@ -1973,8 +2012,7 @@ moveresize(const Arg *arg)
case CurResize: case CurResize:
/* Doesn't work for X11 output - the next absolute motion event /* Doesn't work for X11 output - the next absolute motion event
* returns the cursor to where it started */ * returns the cursor to where it started */
wlr_cursor_warp_closest(cursor, NULL, wlr_cursor_warp_closest(cursor, NULL, grabc->geom.x + grabc->geom.width,
grabc->geom.x + grabc->geom.width,
grabc->geom.y + grabc->geom.height); grabc->geom.y + grabc->geom.height);
wlr_cursor_set_xcursor(cursor, cursor_mgr, "se-resize"); wlr_cursor_set_xcursor(cursor, cursor_mgr, "se-resize");
break; break;
@ -2000,7 +2038,8 @@ outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int test)
struct wlr_output_configuration_head_v1 *config_head; struct wlr_output_configuration_head_v1 *config_head;
int ok = 1; int ok = 1;
wl_list_for_each(config_head, &config->heads, link) { wl_list_for_each(config_head, &config->heads, link)
{
struct wlr_output *wlr_output = config_head->state.output; struct wlr_output *wlr_output = config_head->state.output;
Monitor *m = wlr_output->data; Monitor *m = wlr_output->data;
struct wlr_output_state state; struct wlr_output_state state;
@ -2024,8 +2063,8 @@ outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int test)
wlr_output_state_set_transform(&state, config_head->state.transform); wlr_output_state_set_transform(&state, config_head->state.transform);
wlr_output_state_set_scale(&state, config_head->state.scale); wlr_output_state_set_scale(&state, config_head->state.scale);
wlr_output_state_set_adaptive_sync_enabled(&state, wlr_output_state_set_adaptive_sync_enabled(
config_head->state.adaptive_sync_enabled); &state, config_head->state.adaptive_sync_enabled);
apply_or_test: apply_or_test:
ok &= test ? wlr_output_test_state(wlr_output, &state) ok &= test ? wlr_output_test_state(wlr_output, &state)
@ -2034,9 +2073,10 @@ apply_or_test:
/* Don't move monitors if position wouldn't change. This avoids /* Don't move monitors if position wouldn't change. This avoids
* wlroots marking the output as manually configured. * wlroots marking the output as manually configured.
* wlr_output_layout_add does not like disabled outputs */ * wlr_output_layout_add does not like disabled outputs */
if (!test && wlr_output->enabled && (m->m.x != config_head->state.x || m->m.y != config_head->state.y)) if (!test && wlr_output->enabled &&
wlr_output_layout_add(output_layout, wlr_output, (m->m.x != config_head->state.x || m->m.y != config_head->state.y))
config_head->state.x, config_head->state.y); wlr_output_layout_add(output_layout, wlr_output, config_head->state.x,
config_head->state.y);
wlr_output_state_finish(&state); wlr_output_state_finish(&state);
} }
@ -2059,13 +2099,12 @@ outputmgrtest(struct wl_listener *listener, void *data)
} }
void void
pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy, pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy, uint32_t time)
uint32_t time)
{ {
struct timespec now; struct timespec now;
if (surface != seat->pointer_state.focused_surface && if (surface != seat->pointer_state.focused_surface && sloppyfocus && time && c &&
sloppyfocus && time && c && !client_is_unmanaged(c)) !client_is_unmanaged(c))
focusclient(c, 0); focusclient(c, 0);
/* If surface is NULL, clear pointer focus */ /* If surface is NULL, clear pointer focus */
@ -2093,9 +2132,11 @@ printstatus(void)
Client *c; Client *c;
uint32_t occ, urg, sel; uint32_t occ, urg, sel;
wl_list_for_each(m, &mons, link) { wl_list_for_each(m, &mons, link)
{
occ = urg = 0; occ = urg = 0;
wl_list_for_each(c, &clients, link) { wl_list_for_each(c, &clients, link)
{
if (c->mon != m) if (c->mon != m)
continue; continue;
occ |= c->tags; occ |= c->tags;
@ -2160,8 +2201,10 @@ rendermon(struct wl_listener *listener, void *data)
/* Render if no XDG clients have an outstanding resize and are visible on /* Render if no XDG clients have an outstanding resize and are visible on
* this monitor. */ * this monitor. */
wl_list_for_each(c, &clients, link) { wl_list_for_each(c, &clients, link)
if (c->resize && !c->isfloating && client_is_rendered_on_mon(c, m) && !client_is_stopped(c)) {
if (c->resize && !c->isfloating && client_is_rendered_on_mon(c, m) &&
!client_is_stopped(c))
goto skip; goto skip;
} }
@ -2179,8 +2222,8 @@ requestdecorationmode(struct wl_listener *listener, void *data)
{ {
Client *c = wl_container_of(listener, c, set_decoration_mode); Client *c = wl_container_of(listener, c, set_decoration_mode);
if (c->surface.xdg->initialized) if (c->surface.xdg->initialized)
wlr_xdg_toplevel_decoration_v1_set_mode(c->decoration, wlr_xdg_toplevel_decoration_v1_set_mode(
WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); c->decoration, WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
} }
void void
@ -2188,8 +2231,7 @@ requeststartdrag(struct wl_listener *listener, void *data)
{ {
struct wlr_seat_request_start_drag_event *event = data; struct wlr_seat_request_start_drag_event *event = data;
if (wlr_seat_validate_pointer_grab_serial(seat, event->origin, if (wlr_seat_validate_pointer_grab_serial(seat, event->origin, event->serial))
event->serial))
wlr_seat_start_pointer_drag(seat, event->drag, event->serial); wlr_seat_start_pointer_drag(seat, event->drag, event->serial);
else else
wlr_data_source_destroy(event->drag->source); wlr_data_source_destroy(event->drag->source);
@ -2230,8 +2272,7 @@ resize(Client *c, struct wlr_box geo, int interact)
wlr_scene_node_set_position(&c->border[3]->node, c->geom.width - c->bw, c->bw); wlr_scene_node_set_position(&c->border[3]->node, c->geom.width - c->bw, c->bw);
/* this is a no-op if size hasn't changed */ /* this is a no-op if size hasn't changed */
c->resize = client_set_size(c, c->geom.width - 2 * c->bw, c->resize = client_set_size(c, c->geom.width - 2 * c->bw, c->geom.height - 2 * c->bw);
c->geom.height - 2 * c->bw);
client_get_clip(c, &clip); client_get_clip(c, &clip);
wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip); wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip);
} }
@ -2313,8 +2354,7 @@ setcursor(struct wl_listener *listener, void *data)
* hardware cursor on the output that it's currently on and continue to * hardware cursor on the output that it's currently on and continue to
* do so as the cursor moves between outputs. */ * do so as the cursor moves between outputs. */
if (event->seat_client == seat->pointer_state.focused_client) if (event->seat_client == seat->pointer_state.focused_client)
wlr_cursor_set_surface(cursor, event->surface, wlr_cursor_set_surface(cursor, event->surface, event->hotspot_x, event->hotspot_y);
event->hotspot_x, event->hotspot_y);
} }
void void
@ -2327,8 +2367,7 @@ setcursorshape(struct wl_listener *listener, void *data)
* actually has pointer focus first. If so, we can tell the cursor to * actually has pointer focus first. If so, we can tell the cursor to
* use the provided cursor shape. */ * use the provided cursor shape. */
if (event->seat_client == seat->pointer_state.focused_client) if (event->seat_client == seat->pointer_state.focused_client)
wlr_cursor_set_xcursor(cursor, cursor_mgr, wlr_cursor_set_xcursor(cursor, cursor_mgr, wlr_cursor_shape_v1_name(event->shape));
wlr_cursor_shape_v1_name(event->shape));
} }
void void
@ -2339,9 +2378,10 @@ setfloating(Client *c, int floating)
/* If in floating layout do not change the client's layer */ /* If in floating layout do not change the client's layer */
if (!c->mon || !client_surface(c)->mapped || !c->mon->lt[c->mon->sellt]->arrange) if (!c->mon || !client_surface(c)->mapped || !c->mon->lt[c->mon->sellt]->arrange)
return; return;
wlr_scene_node_reparent(&c->scene->node, layers[c->isfullscreen || wlr_scene_node_reparent(
(p && p->isfullscreen) ? LyrFS &c->scene->node, layers[c->isfullscreen || (p && p->isfullscreen) ? LyrFS
: c->isfloating ? LyrFloat : LyrTile]); : c->isfloating ? LyrFloat
: LyrTile]);
arrange(c->mon); arrange(c->mon);
printstatus(); printstatus();
} }
@ -2354,8 +2394,9 @@ setfullscreen(Client *c, int fullscreen)
return; return;
c->bw = fullscreen ? 0 : borderpx; c->bw = fullscreen ? 0 : borderpx;
client_set_fullscreen(c, fullscreen); client_set_fullscreen(c, fullscreen);
wlr_scene_node_reparent(&c->scene->node, layers[c->isfullscreen wlr_scene_node_reparent(&c->scene->node, layers[c->isfullscreen ? LyrFS
? LyrFS : c->isfloating ? LyrFloat : LyrTile]); : c->isfloating ? LyrFloat
: LyrTile]);
if (fullscreen) { if (fullscreen) {
c->prev = c->geom; c->prev = c->geom;
@ -2414,7 +2455,8 @@ setmon(Client *c, Monitor *m, uint32_t newtags)
if (m) { if (m) {
/* Make sure window actually overlaps with the monitor */ /* Make sure window actually overlaps with the monitor */
resize(c, c->geom, 0); resize(c, c->geom, 0);
c->tags = newtags ? newtags : m->tagset[m->seltags]; /* assign tags of target monitor */ c->tags = newtags ? newtags
: m->tagset[m->seltags]; /* assign tags of target monitor */
setfullscreen(c, c->isfullscreen); /* This will call arrange(c->mon) */ setfullscreen(c, c->isfullscreen); /* This will call arrange(c->mon) */
setfloating(c, c->isfloating); setfloating(c, c->isfloating);
} }
@ -2492,12 +2534,12 @@ setup(void)
if (wlr_renderer_get_texture_formats(drw, WLR_BUFFER_CAP_DMABUF)) { if (wlr_renderer_get_texture_formats(drw, WLR_BUFFER_CAP_DMABUF)) {
wlr_drm_create(dpy, drw); wlr_drm_create(dpy, drw);
wlr_scene_set_linux_dmabuf_v1(scene, wlr_scene_set_linux_dmabuf_v1(
wlr_linux_dmabuf_v1_create_with_renderer(dpy, 5, drw)); scene, wlr_linux_dmabuf_v1_create_with_renderer(dpy, 5, drw));
} }
if ((drm_fd = wlr_renderer_get_drm_fd(drw)) >= 0 && drw->features.timeline if ((drm_fd = wlr_renderer_get_drm_fd(drw)) >= 0 && drw->features.timeline &&
&& backend->features.timeline) backend->features.timeline)
wlr_linux_drm_syncobj_manager_v1_create(dpy, 1, drm_fd); wlr_linux_drm_syncobj_manager_v1_create(dpy, 1, drm_fd);
/* Autocreates an allocator for us. /* Autocreates an allocator for us.
@ -2571,13 +2613,12 @@ setup(void)
session_lock_mgr = wlr_session_lock_manager_v1_create(dpy); session_lock_mgr = wlr_session_lock_manager_v1_create(dpy);
wl_signal_add(&session_lock_mgr->events.new_lock, &new_session_lock); wl_signal_add(&session_lock_mgr->events.new_lock, &new_session_lock);
locked_bg = wlr_scene_rect_create(layers[LyrBlock], sgeom.width, sgeom.height, locked_bg = wlr_scene_rect_create(
(float [4]){0.1f, 0.1f, 0.1f, 1.0f}); layers[LyrBlock], sgeom.width, sgeom.height, (float[4]){0.1f, 0.1f, 0.1f, 1.0f});
wlr_scene_node_set_enabled(&locked_bg->node, 0); wlr_scene_node_set_enabled(&locked_bg->node, 0);
/* Use decoration protocols to negotiate server-side decorations */ /* Use decoration protocols to negotiate server-side decorations */
wlr_server_decoration_manager_set_default_mode( wlr_server_decoration_manager_set_default_mode(wlr_server_decoration_manager_create(dpy),
wlr_server_decoration_manager_create(dpy),
WLR_SERVER_DECORATION_MANAGER_MODE_SERVER); WLR_SERVER_DECORATION_MANAGER_MODE_SERVER);
xdg_decoration_mgr = wlr_xdg_decoration_manager_v1_create(dpy); xdg_decoration_mgr = wlr_xdg_decoration_manager_v1_create(dpy);
wl_signal_add(&xdg_decoration_mgr->events.new_toplevel_decoration, &new_xdg_decoration); wl_signal_add(&xdg_decoration_mgr->events.new_toplevel_decoration, &new_xdg_decoration);
@ -2628,11 +2669,9 @@ setup(void)
*/ */
wl_signal_add(&backend->events.new_input, &new_input_device); wl_signal_add(&backend->events.new_input, &new_input_device);
virtual_keyboard_mgr = wlr_virtual_keyboard_manager_v1_create(dpy); virtual_keyboard_mgr = wlr_virtual_keyboard_manager_v1_create(dpy);
wl_signal_add(&virtual_keyboard_mgr->events.new_virtual_keyboard, wl_signal_add(&virtual_keyboard_mgr->events.new_virtual_keyboard, &new_virtual_keyboard);
&new_virtual_keyboard);
virtual_pointer_mgr = wlr_virtual_pointer_manager_v1_create(dpy); virtual_pointer_mgr = wlr_virtual_pointer_manager_v1_create(dpy);
wl_signal_add(&virtual_pointer_mgr->events.new_virtual_pointer, wl_signal_add(&virtual_pointer_mgr->events.new_virtual_pointer, &new_virtual_pointer);
&new_virtual_pointer);
seat = wlr_seat_create(dpy, "seat0"); seat = wlr_seat_create(dpy, "seat0");
wl_signal_add(&seat->events.request_set_cursor, &request_cursor); wl_signal_add(&seat->events.request_set_cursor, &request_cursor);
@ -2718,9 +2757,8 @@ tile(Monitor *m)
int i, n = 0; int i, n = 0;
Client *c; Client *c;
wl_list_for_each(c, &clients, link) wl_list_for_each(
if (VISIBLEON(c, m) && !c->isfloating && !c->isfullscreen) c, &clients, link) if (VISIBLEON(c, m) && !c->isfloating && !c->isfullscreen) n++;
n++;
if (n == 0) if (n == 0)
return; return;
@ -2729,16 +2767,25 @@ tile(Monitor *m)
else else
mw = m->w.width; mw = m->w.width;
i = my = ty = 0; i = my = ty = 0;
wl_list_for_each(c, &clients, link) { wl_list_for_each(c, &clients, link)
{
if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen) if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
continue; continue;
if (i < m->nmaster) { if (i < m->nmaster) {
resize(c, (struct wlr_box){.x = m->w.x, .y = m->w.y + my, .width = mw, resize(c,
.height = (m->w.height - my) / (MIN(n, m->nmaster) - i)}, 0); (struct wlr_box){.x = m->w.x,
.y = m->w.y + my,
.width = mw,
.height = (m->w.height - my) / (MIN(n, m->nmaster) - i)},
0);
my += c->geom.height; my += c->geom.height;
} else { } else {
resize(c, (struct wlr_box){.x = m->w.x + mw, .y = m->w.y + ty, resize(c,
.width = m->w.width - mw, .height = (m->w.height - ty) / (n - i)}, 0); (struct wlr_box){.x = m->w.x + mw,
.y = m->w.y + ty,
.width = m->w.width - mw,
.height = (m->w.height - ty) / (n - i)},
0);
ty += c->geom.height; ty += c->geom.height;
} }
i++; i++;
@ -2848,14 +2895,14 @@ updatemons(struct wl_listener *listener, void *data)
* positions, focus, and the stored configuration in wlroots' * positions, focus, and the stored configuration in wlroots'
* output-manager implementation. * output-manager implementation.
*/ */
struct wlr_output_configuration_v1 *config struct wlr_output_configuration_v1 *config = wlr_output_configuration_v1_create();
= wlr_output_configuration_v1_create();
Client *c; Client *c;
struct wlr_output_configuration_head_v1 *config_head; struct wlr_output_configuration_head_v1 *config_head;
Monitor *m; Monitor *m;
/* First remove from the layout the disabled monitors */ /* First remove from the layout the disabled monitors */
wl_list_for_each(m, &mons, link) { wl_list_for_each(m, &mons, link)
{
if (m->wlr_output->enabled || m->asleep) if (m->wlr_output->enabled || m->asleep)
continue; continue;
config_head = wlr_output_configuration_head_v1_create(config, m->wlr_output); config_head = wlr_output_configuration_head_v1_create(config, m->wlr_output);
@ -2866,9 +2913,9 @@ updatemons(struct wl_listener *listener, void *data)
m->m = m->w = (struct wlr_box){0}; m->m = m->w = (struct wlr_box){0};
} }
/* Insert outputs that need to */ /* Insert outputs that need to */
wl_list_for_each(m, &mons, link) { wl_list_for_each(m, &mons, link)
if (m->wlr_output->enabled {
&& !wlr_output_layout_get(output_layout, m->wlr_output)) if (m->wlr_output->enabled && !wlr_output_layout_get(output_layout, m->wlr_output))
wlr_output_layout_add_auto(output_layout, m->wlr_output); wlr_output_layout_add_auto(output_layout, m->wlr_output);
} }
@ -2882,7 +2929,8 @@ updatemons(struct wl_listener *listener, void *data)
wlr_scene_node_set_position(&locked_bg->node, sgeom.x, sgeom.y); wlr_scene_node_set_position(&locked_bg->node, sgeom.x, sgeom.y);
wlr_scene_rect_set_size(locked_bg, sgeom.width, sgeom.height); wlr_scene_rect_set_size(locked_bg, sgeom.width, sgeom.height);
wl_list_for_each(m, &mons, link) { wl_list_for_each(m, &mons, link)
{
if (!m->wlr_output->enabled) if (!m->wlr_output->enabled)
continue; continue;
config_head = wlr_output_configuration_head_v1_create(config, m->wlr_output); config_head = wlr_output_configuration_head_v1_create(config, m->wlr_output);
@ -2898,7 +2946,8 @@ updatemons(struct wl_listener *listener, void *data)
if (m->lock_surface) { if (m->lock_surface) {
struct wlr_scene_tree *scene_tree = m->lock_surface->surface->data; struct wlr_scene_tree *scene_tree = m->lock_surface->surface->data;
wlr_scene_node_set_position(&scene_tree->node, m->m.x, m->m.y); wlr_scene_node_set_position(&scene_tree->node, m->m.x, m->m.y);
wlr_session_lock_surface_v1_configure(m->lock_surface, m->m.width, m->m.height); wlr_session_lock_surface_v1_configure(
m->lock_surface, m->m.width, m->m.height);
} }
/* Calculate the effective monitor geometry to use for clients */ /* Calculate the effective monitor geometry to use for clients */
@ -2922,14 +2971,15 @@ updatemons(struct wl_listener *listener, void *data)
} }
if (selmon && selmon->wlr_output->enabled) { if (selmon && selmon->wlr_output->enabled) {
wl_list_for_each(c, &clients, link) { wl_list_for_each(c, &clients, link)
{
if (!c->mon && client_surface(c)->mapped) if (!c->mon && client_surface(c)->mapped)
setmon(c, selmon, c->tags); setmon(c, selmon, c->tags);
} }
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), 1);
if (selmon->lock_surface) { if (selmon->lock_surface) {
client_notify_enter(selmon->lock_surface->surface, client_notify_enter(
wlr_seat_get_keyboard(seat)); selmon->lock_surface->surface, wlr_seat_get_keyboard(seat));
client_activate_surface(selmon->lock_surface->surface, 1); client_activate_surface(selmon->lock_surface->surface, 1);
} }
} }
@ -3014,8 +3064,8 @@ xytomon(double x, double y)
} }
void void
xytonode(double x, double y, struct wlr_surface **psurface, xytonode(double x, double y, struct wlr_surface **psurface, Client **pc, LayerSurface **pl,
Client **pc, LayerSurface **pl, double *nx, double *ny) double *nx, double *ny)
{ {
struct wlr_scene_node *node, *pnode; struct wlr_scene_node *node, *pnode;
struct wlr_surface *surface = NULL; struct wlr_surface *surface = NULL;
@ -3028,8 +3078,9 @@ xytonode(double x, double y, struct wlr_surface **psurface,
continue; continue;
if (node->type == WLR_SCENE_NODE_BUFFER) if (node->type == WLR_SCENE_NODE_BUFFER)
surface = wlr_scene_surface_try_from_buffer( surface =
wlr_scene_buffer_from_node(node))->surface; wlr_scene_surface_try_from_buffer(wlr_scene_buffer_from_node(node))
->surface;
/* Walk the tree to find a node that knows the client */ /* Walk the tree to find a node that knows the client */
for (pnode = node; pnode && !c; pnode = &pnode->parent->node) for (pnode = node; pnode && !c; pnode = &pnode->parent->node)
c = pnode->data; c = pnode->data;
@ -3039,9 +3090,12 @@ xytonode(double x, double y, struct wlr_surface **psurface,
} }
} }
if (psurface) *psurface = surface; if (psurface)
if (pc) *pc = c; *psurface = surface;
if (pl) *pl = l; if (pc)
*pc = c;
if (pl)
*pl = l;
} }
void void
@ -3054,7 +3108,8 @@ zoom(const Arg *arg)
/* Search for the first tiled window that is not sel, marking sel as /* Search for the first tiled window that is not sel, marking sel as
* NULL if we pass it along the way */ * NULL if we pass it along the way */
wl_list_for_each(c, &clients, link) { wl_list_for_each(c, &clients, link)
{
if (VISIBLEON(c, selmon) && !c->isfloating) { if (VISIBLEON(c, selmon) && !c->isfloating) {
if (c != sel) if (c != sel)
break; break;
@ -3103,20 +3158,23 @@ configurex11(struct wl_listener *listener, void *data)
Client *c = wl_container_of(listener, c, configure); Client *c = wl_container_of(listener, c, configure);
struct wlr_xwayland_surface_configure_event *event = data; struct wlr_xwayland_surface_configure_event *event = data;
if (!client_surface(c) || !client_surface(c)->mapped) { if (!client_surface(c) || !client_surface(c)->mapped) {
wlr_xwayland_surface_configure(c->surface.xwayland, wlr_xwayland_surface_configure(
event->x, event->y, event->width, event->height); c->surface.xwayland, event->x, event->y, event->width, event->height);
return; return;
} }
if (client_is_unmanaged(c)) { if (client_is_unmanaged(c)) {
wlr_scene_node_set_position(&c->scene->node, event->x, event->y); wlr_scene_node_set_position(&c->scene->node, event->x, event->y);
wlr_xwayland_surface_configure(c->surface.xwayland, wlr_xwayland_surface_configure(
event->x, event->y, event->width, event->height); c->surface.xwayland, event->x, event->y, event->width, event->height);
return; return;
} }
if ((c->isfloating && c != grabc) || !c->mon->lt[c->mon->sellt]->arrange) { if ((c->isfloating && c != grabc) || !c->mon->lt[c->mon->sellt]->arrange) {
resize(c, (struct wlr_box){.x = event->x - c->bw, resize(c,
.y = event->y - c->bw, .width = event->width + c->bw * 2, (struct wlr_box){.x = event->x - c->bw,
.height = event->height + c->bw * 2}, 0); .y = event->y - c->bw,
.width = event->width + c->bw * 2,
.height = event->height + c->bw * 2},
0);
} else { } else {
arrange(c->mon); arrange(c->mon);
} }
@ -3178,10 +3236,10 @@ xwaylandready(struct wl_listener *listener, void *data)
/* Set the default XWayland cursor to match the rest of dwl. */ /* Set the default XWayland cursor to match the rest of dwl. */
if ((xcursor = wlr_xcursor_manager_get_xcursor(cursor_mgr, "default", 1))) if ((xcursor = wlr_xcursor_manager_get_xcursor(cursor_mgr, "default", 1)))
wlr_xwayland_set_cursor(xwayland, wlr_xwayland_set_cursor(xwayland, xcursor->images[0]->buffer,
xcursor->images[0]->buffer, xcursor->images[0]->width * 4, xcursor->images[0]->width * 4, xcursor->images[0]->width,
xcursor->images[0]->width, xcursor->images[0]->height, xcursor->images[0]->height, xcursor->images[0]->hotspot_x,
xcursor->images[0]->hotspot_x, xcursor->images[0]->hotspot_y); xcursor->images[0]->hotspot_y);
} }
#endif #endif

12
util.c
View File

@ -1,14 +1,15 @@
/* 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);
@ -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);