aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2024-07-07 18:42:35 +0530
committerRaghuram Subramani <raghus2247@gmail.com>2024-07-07 18:42:35 +0530
commitdde1d66ddc3236d076858736fb6faaf06a3c7d8c (patch)
tree343bcd27455005413bcfea3aad8a6f1a4b4e7566
parent21ef958760beea3cacf9ae5937101348bd6ecc4c (diff)
updstream
-rw-r--r--Makefile2
-rw-r--r--client.h2
-rw-r--r--config.def.h1
-rw-r--r--dwl.c62
-rw-r--r--util.c16
-rw-r--r--util.h1
6 files changed, 57 insertions, 27 deletions
diff --git a/Makefile b/Makefile
index 686d80f..4401ad0 100644
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ DWLDEVCFLAGS = -g -pedantic -Wall -Wextra -Wdeclaration-after-statement \
# CFLAGS / LDFLAGS
PKGS = wlroots wayland-server xkbcommon libinput $(XLIBS)
DWLCFLAGS = `$(PKG_CONFIG) --cflags $(PKGS)` $(DWLCPPFLAGS) $(DWLDEVCFLAGS) $(CFLAGS)
-LDLIBS = `$(PKG_CONFIG) --libs $(PKGS)` $(LIBS)
+LDLIBS = `$(PKG_CONFIG) --libs $(PKGS)` -lm $(LIBS)
all: dwl
dwl: dwl.o util.o
diff --git a/client.h b/client.h
index 19861b9..42f225f 100644
--- a/client.h
+++ b/client.h
@@ -350,7 +350,7 @@ 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->geom.y, width, height);
+ c->geom.x + c->bw, c->geom.y + c->bw, width, height);
return 0;
}
#endif
diff --git a/config.def.h b/config.def.h
index 9457970..b33dbd8 100644
--- a/config.def.h
+++ b/config.def.h
@@ -35,6 +35,7 @@ static const char *const autostart[] = {
};
+/* NOTE: ALWAYS keep a rule declared even if you don't use rules (e.g leave at least one example) */
static const Rule rules[] = {
/* app_id title tags mask isfloating monitor */
{ NULL, "float", NULL, 1, -1 }
diff --git a/dwl.c b/dwl.c
index 975d5f3..03c22a1 100644
--- a/dwl.c
+++ b/dwl.c
@@ -4,6 +4,7 @@
#include <getopt.h>
#include <libinput.h>
#include <linux/input-event-codes.h>
+#include <math.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -70,7 +71,6 @@
/* macros */
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#define MIN(A, B) ((A) < (B) ? (A) : (B))
-#define ROUND(X) ((int)((X < 0) ? (X - 0.5) : (X + 0.5)))
#define CLEANMASK(mask) (mask & ~WLR_MODIFIER_CAPS)
#define VISIBLEON(C, M) ((M) && (C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags]))
#define LENGTH(X) (sizeof X / sizeof X[0])
@@ -177,7 +177,6 @@ typedef struct {
struct wlr_layer_surface_v1 *layer_surface;
struct wl_listener destroy;
- struct wl_listener map;
struct wl_listener unmap;
struct wl_listener surface_commit;
} LayerSurface;
@@ -300,7 +299,6 @@ static void keypressmod(struct wl_listener *listener, void *data);
static int keyrepeat(void *data);
static void killclient(const Arg *arg);
static void locksession(struct wl_listener *listener, void *data);
-static void maplayersurfacenotify(struct wl_listener *listener, void *data);
static void mapnotify(struct wl_listener *listener, void *data);
static void maximizenotify(struct wl_listener *listener, void *data);
static void monocle(Monitor *m);
@@ -455,9 +453,9 @@ applybounds(Client *c, struct wlr_box *bbox)
c->geom.x = bbox->x + bbox->width - c->geom.width;
if (c->geom.y >= bbox->y + bbox->height)
c->geom.y = bbox->y + bbox->height - c->geom.height;
- if (c->geom.x + c->geom.width + 2 * (int)c->bw <= bbox->x)
+ if (c->geom.x + c->geom.width <= bbox->x)
c->geom.x = bbox->x;
- if (c->geom.y + c->geom.height + 2 * (int)c->bw <= bbox->y)
+ if (c->geom.y + c->geom.height <= bbox->y)
c->geom.y = bbox->y;
}
@@ -643,6 +641,7 @@ buttonpress(struct wl_listener *listener, void *data)
switch (event->state) {
case WLR_BUTTON_PRESSED:
cursor_mode = CurPressed;
+ selmon = xytomon(cursor->x, cursor->y);
if (locked)
break;
@@ -822,6 +821,20 @@ commitnotify(struct wl_listener *listener, void *data)
{
Client *c = wl_container_of(listener, c, commit);
+
+ if (c->surface.xdg->initial_commit) {
+ /*
+ * Get the monitor this client will be rendered on
+ * Note that if the user set a rule in which the client is placed on
+ * a different monitor based on its title this will likely select
+ * a wrong monitor.
+ */
+ applyrules(c);
+ wlr_surface_set_preferred_buffer_scale(client_surface(c), (int)ceilf(c->mon->wlr_output->scale));
+ wlr_fractional_scale_v1_notify_scale(client_surface(c), c->mon->wlr_output->scale);
+ setmon(c, NULL, 0); /* Make sure to reapply rules in mapnotify() */
+ }
+
if (client_surface(c)->mapped && c->mon) {
if (c->mon && c->mon->lt[c->mon->sellt]->arrange && !c->isfullscreen && !c->isfloating)
c->mon->lt[c->mon->sellt]->arrange(c->mon);
@@ -922,7 +935,6 @@ createlayersurface(struct wl_listener *listener, void *data)
l = layer_surface->data = ecalloc(1, sizeof(*l));
l->type = LayerShell;
LISTEN(&surface->events.commit, &l->surface_commit, commitlayersurfacenotify);
- LISTEN(&surface->events.map, &l->map, maplayersurfacenotify);
LISTEN(&surface->events.unmap, &l->unmap, unmaplayersurfacenotify);
LISTEN(&layer_surface->events.destroy, &l->destroy, destroylayersurfacenotify);
@@ -936,6 +948,8 @@ createlayersurface(struct wl_listener *listener, void *data)
wl_list_insert(&l->mon->layers[layer_surface->pending.layer],&l->link);
wlr_surface_send_enter(surface, layer_surface->output);
+ wlr_fractional_scale_v1_notify_scale(surface, l->mon->wlr_output->scale);
+ wlr_surface_set_preferred_buffer_scale(surface, (int32_t)ceilf(l->mon->wlr_output->scale));
/* Temporarily set the layer's current state to pending
* so that we can easily arrange it
@@ -1230,7 +1244,6 @@ destroylayersurfacenotify(struct wl_listener *listener, void *data)
wl_list_remove(&l->link);
wl_list_remove(&l->destroy.link);
- wl_list_remove(&l->map.link);
wl_list_remove(&l->unmap.link);
wl_list_remove(&l->surface_commit.link);
wlr_scene_node_destroy(&l->scene->node);
@@ -1699,12 +1712,6 @@ locksession(struct wl_listener *listener, void *data)
}
void
-maplayersurfacenotify(struct wl_listener *listener, void *data)
-{
- motionnotify(0, NULL, 0, 0, 0, 0);
-}
-
-void
mapnotify(struct wl_listener *listener, void *data)
{
/* Called when the surface is mapped, or ready to display on-screen. */
@@ -1727,8 +1734,7 @@ mapnotify(struct wl_listener *listener, void *data)
if (client_is_unmanaged(c)) {
/* Unmanaged clients always are floating */
wlr_scene_node_reparent(&c->scene->node, layers[LyrFloat]);
- wlr_scene_node_set_position(&c->scene->node, c->geom.x + borderpx,
- c->geom.y + borderpx);
+ wlr_scene_node_set_position(&c->scene->node, c->geom.x, c->geom.y);
if (client_wants_focus(c)) {
focusclient(c, 1);
exclusive_focus = c;
@@ -1887,12 +1893,12 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double d
}
/* Update drag icon's position */
- wlr_scene_node_set_position(&drag_icon->node, ROUND(cursor->x), ROUND(cursor->y));
+ wlr_scene_node_set_position(&drag_icon->node, (int)round(cursor->x), (int)round(cursor->y));
/* If we are currently grabbing the mouse, handle and return */
if (cursor_mode == CurMove) {
/* Move the grabbed client to the new position. */
- resize(grabc, (struct wlr_box){.x = ROUND(cursor->x) - grabcx, .y = ROUND(cursor->y) - grabcy,
+ resize(grabc, (struct wlr_box){.x = (int)round(cursor->x) - grabcx, .y = (int)round(cursor->y) - grabcy,
.width = grabc->geom.width, .height = grabc->geom.height}, 1, 1);
return;
} else if (cursor_mode == CurResize) {
@@ -1938,8 +1944,8 @@ moveresize(const Arg *arg)
setfloating(grabc, 1);
switch (cursor_mode = arg->ui) {
case CurMove:
- grabcx = ROUND(cursor->x) - grabc->geom.x;
- grabcy = ROUND(cursor->y) - grabc->geom.y;
+ grabcx = (int)round(cursor->x) - grabc->geom.x;
+ grabcy = (int)round(cursor->y) - grabc->geom.y;
wlr_cursor_set_xcursor(cursor, cursor_mgr, "fleur");
break;
case CurResize:
@@ -2019,7 +2025,7 @@ apply_or_test:
wlr_output_configuration_v1_send_failed(config);
wlr_output_configuration_v1_destroy(config);
- /* TODO: use a wrapper function? */
+ /* https://codeberg.org/dwl/dwl/issues/577 */
updatemons(NULL, NULL);
}
@@ -2208,7 +2214,7 @@ resize(Client *c, struct wlr_box geo, int interact, int draw_borders)
struct wlr_box *bbox;
struct wlr_box clip;
- if (!c->mon)
+ if (!c->mon || !c->scene)
return;
bbox = interact ? &sgeom : &c->mon->w;
@@ -2270,6 +2276,12 @@ run(char *startup_cmd)
close(piperw[1]);
close(piperw[0]);
}
+
+ /* Mark stdout as non-blocking to avoid people who does not close stdin
+ * nor consumes it in their startup script getting dwl frozen */
+ if (fd_set_nonblock(STDOUT_FILENO) < 0)
+ close(STDOUT_FILENO);
+
printstatus();
/* At this point the outputs are initialized, choose initial selmon based on
@@ -2330,7 +2342,7 @@ setfloating(Client *c, int floating)
Client *p = client_get_parent(c);
c->isfloating = floating;
/* If in floating layout do not change the client's layer */
- if (!c->mon || !c->mon->lt[c->mon->sellt]->arrange)
+ if (!c->mon || !client_surface(c)->mapped || !c->mon->lt[c->mon->sellt]->arrange)
return;
wlr_scene_node_reparent(&c->scene->node, layers[c->isfullscreen ||
(p && p->isfullscreen) ? LyrFS
@@ -2345,7 +2357,7 @@ void
setfullscreen(Client *c, int fullscreen)
{
c->isfullscreen = fullscreen;
- if (!c->mon)
+ if (!c->mon || !client_surface(c)->mapped)
return;
c->bw = fullscreen ? 0 : borderpx;
client_set_fullscreen(c, fullscreen);
@@ -2731,7 +2743,7 @@ tile(Monitor *m)
draw_borders = 0;
if (n > m->nmaster)
- mw = m->nmaster ? ROUND(m->w.width * m->mfact) : 0;
+ mw = m->nmaster ? (int)roundf(m->w.width * m->mfact) : 0;
else
mw = m->w.width;
i = my = ty = 0;
@@ -3173,7 +3185,7 @@ createnotifyx11(struct wl_listener *listener, void *data)
c = xsurface->data = ecalloc(1, sizeof(*c));
c->surface.xwayland = xsurface;
c->type = X11;
- c->bw = borderpx;
+ c->bw = client_is_unmanaged(c) ? 0 : borderpx;
/* Listen to the various events it can emit */
LISTEN(&xsurface->events.associate, &c->associate, associatex11);
diff --git a/util.c b/util.c
index cca7c19..51130af 100644
--- a/util.c
+++ b/util.c
@@ -3,6 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <fcntl.h>
#include "util.h"
@@ -33,3 +34,18 @@ ecalloc(size_t nmemb, size_t size)
die("calloc:");
return p;
}
+
+int
+fd_set_nonblock(int fd) {
+ int flags = fcntl(fd, F_GETFL);
+ if (flags < 0) {
+ perror("fcntl(F_GETFL):");
+ return -1;
+ }
+ if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
+ perror("fcntl(F_SETFL):");
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/util.h b/util.h
index 4c94117..226980d 100644
--- a/util.h
+++ b/util.h
@@ -2,3 +2,4 @@
void die(const char *fmt, ...);
void *ecalloc(size_t nmemb, size_t size);
+int fd_set_nonblock(int fd);