summaryrefslogtreecommitdiff
path: root/dwl.c
diff options
context:
space:
mode:
Diffstat (limited to 'dwl.c')
-rw-r--r--dwl.c1196
1 files changed, 1078 insertions, 118 deletions
diff --git a/dwl.c b/dwl.c
index 12f441e..d129406 100644
--- a/dwl.c
+++ b/dwl.c
@@ -3,11 +3,14 @@
*/
#include <getopt.h>
#include <libinput.h>
+#include <limits.h>
#include <linux/input-event-codes.h>
#include <math.h>
+#include <libdrm/drm_fourcc.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
+#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
@@ -59,6 +62,7 @@
#include <wlr/types/wlr_xdg_decoration_v1.h>
#include <wlr/types/wlr_xdg_output_v1.h>
#include <wlr/types/wlr_xdg_shell.h>
+#include <wlr/interfaces/wlr_buffer.h>
#include <wlr/util/log.h>
#include <wlr/util/region.h>
#include <xkbcommon/xkbcommon.h>
@@ -68,23 +72,28 @@
#include <xcb/xcb_icccm.h>
#endif
+#include "dwl-ipc-unstable-v2-protocol.h"
#include "util.h"
+#include "drwl.h"
/* macros */
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#define MIN(A, B) ((A) < (B) ? (A) : (B))
#define CLEANMASK(mask) (mask & ~WLR_MODIFIER_CAPS)
-#define VISIBLEON(C, M) ((M) && (C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags]))
+#define VISIBLEON(C, M) ((M) && (C)->mon == (M) && (((C)->tags & (M)->tagset[(M)->seltags]) || C->issticky))
#define LENGTH(X) (sizeof X / sizeof X[0])
#define END(A) ((A) + LENGTH(A))
-#define TAGMASK ((1u << TAGCOUNT) - 1)
+#define TAGMASK ((1u << LENGTH(tags)) - 1)
#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 TEXTW(mon, text) (drwl_font_getwidth(mon->drw, text) + mon->lrpad)
/* enums */
+enum { SchemeNorm, SchemeSel, SchemeTagSel, SchemeUrg }; /* color schemes */
enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */
enum { XDGShell, LayerShell, X11 }; /* client types */
enum { LyrBg, LyrBottom, LyrTile, LyrFloat, LyrTop, LyrFS, LyrOverlay, LyrBlock, NUM_LAYERS }; /* scene layers */
+enum { ClkTagBar, ClkLtSymbol, ClkStatus, ClkTitle, ClkClient, ClkRoot }; /* clicks */
typedef union {
int i;
@@ -94,6 +103,7 @@ typedef union {
} Arg;
typedef struct {
+ unsigned int click;
unsigned int mod;
unsigned int button;
void (*func)(const Arg *);
@@ -101,7 +111,8 @@ typedef struct {
} Button;
typedef struct Monitor Monitor;
-typedef struct {
+typedef struct Client Client;
+struct Client {
/* Must keep this field first */
unsigned int type; /* XDGShell or X11* */
@@ -137,9 +148,18 @@ typedef struct {
#endif
unsigned int bw;
uint32_t tags;
- int isfloating, isurgent, isfullscreen;
+ int iscentered, isfloating, isurgent, isfullscreen, issticky, isterm, noswallow;
+ char scratchkey;
uint32_t resize; /* configure serial of a pending resize */
-} Client;
+ pid_t pid;
+ Client *swallowing, *swallowedby;
+};
+
+typedef struct {
+ struct wl_list link;
+ struct wl_resource *resource;
+ Monitor *mon;
+} DwlIpcOutput;
typedef struct {
uint32_t mod;
@@ -183,10 +203,20 @@ typedef struct {
void (*arrange)(Monitor *);
} Layout;
+typedef struct {
+ struct wlr_buffer base;
+ struct wl_listener release;
+ bool busy;
+ Img *image;
+ uint32_t data[];
+} Buffer;
+
struct Monitor {
struct wl_list link;
+ struct wl_list dwl_ipc_outputs;
struct wlr_output *wlr_output;
struct wlr_scene_output *scene_output;
+ struct wlr_scene_buffer *scene_buffer; /* bar buffer */
struct wlr_scene_rect *fullscreen_bg; /* See createmon() for info */
struct wl_listener frame;
struct wl_listener destroy;
@@ -194,17 +224,26 @@ struct Monitor {
struct wl_listener destroy_lock_surface;
struct wlr_session_lock_surface_v1 *lock_surface;
struct wlr_box m; /* monitor area, layout-relative */
+ struct {
+ int width, height;
+ int real_width, real_height; /* non-scaled */
+ float scale;
+ } b; /* bar area */
struct wlr_box w; /* window area, layout-relative */
struct wl_list layers[4]; /* LayerSurface.link */
const Layout *lt[2];
unsigned int seltags;
unsigned int sellt;
uint32_t tagset[2];
+ int gappx;
float mfact;
int gamma_lut_changed;
int nmaster;
char ltsymbol[16];
int asleep;
+ Drwl *drw;
+ Buffer *pool[2];
+ int lrpad;
};
typedef struct {
@@ -226,8 +265,12 @@ typedef struct {
const char *id;
const char *title;
uint32_t tags;
+ int iscentered;
int isfloating;
+ int isterm;
+ int noswallow;
int monitor;
+ const char scratchkey;
} Rule;
typedef struct {
@@ -246,7 +289,15 @@ static void arrange(Monitor *m);
static void arrangelayer(Monitor *m, struct wl_list *list,
struct wlr_box *usable_area, int exclusive);
static void arrangelayers(Monitor *m);
+static void autostartexec(void);
static void axisnotify(struct wl_listener *listener, void *data);
+static bool baracceptsinput(struct wlr_scene_buffer *buffer, double *sx, double *sy);
+static void bufdestroy(struct wlr_buffer *buffer);
+static bool bufdatabegin(struct wlr_buffer *buffer, uint32_t flags,
+ void **data, uint32_t *format, size_t *stride);
+static void bufdataend(struct wlr_buffer *buffer);
+static Buffer *bufmon(Monitor *m);
+static void bufrelease(struct wl_listener *listener, void *data);
static void buttonpress(struct wl_listener *listener, void *data);
static void chvt(const Arg *arg);
static void checkidleinhibitor(struct wlr_surface *exclude);
@@ -282,8 +333,23 @@ static void destroypointerconstraint(struct wl_listener *listener, void *data);
static void destroysessionlock(struct wl_listener *listener, void *data);
static void destroykeyboardgroup(struct wl_listener *listener, void *data);
static Monitor *dirtomon(enum wlr_direction dir);
+static void drawbar(Monitor *m);
+static void drawbars(void);
+static void dwl_ipc_manager_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id);
+static void dwl_ipc_manager_destroy(struct wl_resource *resource);
+static void dwl_ipc_manager_get_output(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *output);
+static void dwl_ipc_manager_release(struct wl_client *client, struct wl_resource *resource);
+static void dwl_ipc_output_destroy(struct wl_resource *resource);
+static void dwl_ipc_output_printstatus(Monitor *monitor);
+static void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output);
+static void dwl_ipc_output_set_client_tags(struct wl_client *client, struct wl_resource *resource, uint32_t and_tags, uint32_t xor_tags);
+static void dwl_ipc_output_set_layout(struct wl_client *client, struct wl_resource *resource, uint32_t index);
+static void dwl_ipc_output_set_tags(struct wl_client *client, struct wl_resource *resource, uint32_t tagmask, uint32_t toggle_tagset);
+static void dwl_ipc_output_release(struct wl_client *client, struct wl_resource *resource);
static void focusclient(Client *c, int lift);
static void focusmon(const Arg *arg);
+static void focusortogglematchingscratch(const Arg *arg);
+static void focusortogglescratch(const Arg *arg);
static void focusstack(const Arg *arg);
static Client *focustop(Monitor *m);
static void fullscreennotify(struct wl_listener *listener, void *data);
@@ -300,6 +366,7 @@ static void locksession(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);
+static void movestack(const Arg *arg);
static void motionabsolute(struct wl_listener *listener, void *data);
static void motionnotify(uint32_t time, struct wlr_input_device *device, double sx,
double sy, double sx_unaccel, double sy_unaccel);
@@ -310,47 +377,60 @@ static void outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int
static void outputmgrtest(struct wl_listener *listener, void *data);
static void pointerfocus(Client *c, struct wlr_surface *surface,
double sx, double sy, uint32_t time);
-static void printstatus(void);
static void powermgrsetmode(struct wl_listener *listener, void *data);
static void quit(const Arg *arg);
static void rendermon(struct wl_listener *listener, void *data);
static void requestdecorationmode(struct wl_listener *listener, void *data);
static void requeststartdrag(struct wl_listener *listener, void *data);
static void requestmonstate(struct wl_listener *listener, void *data);
-static void resize(Client *c, struct wlr_box geo, int interact);
-static void run(char *startup_cmd);
+static void resize(Client *c, struct wlr_box geo, int interact, int draw_borders);
+static void run(char *startup_cmd, uid_t uid);
static void setcursor(struct wl_listener *listener, void *data);
static void setcursorshape(struct wl_listener *listener, void *data);
static void setfloating(Client *c, int floating);
static void setfullscreen(Client *c, int fullscreen);
+static void setgaps(const Arg *arg);
static void setlayout(const Arg *arg);
static void setmfact(const Arg *arg);
static void setmon(Client *c, Monitor *m, uint32_t newtags);
static void setpsel(struct wl_listener *listener, void *data);
static void setsel(struct wl_listener *listener, void *data);
+static void setsticky(Client *c, int sticky);
static void setup(void);
static void spawn(const Arg *arg);
+static void spawnscratch(const Arg *arg);
static void startdrag(struct wl_listener *listener, void *data);
+static int statusin(int fd, unsigned int mask, void *data);
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
static void tile(Monitor *m);
+static void togglebar(const Arg *arg);
static void togglefloating(const Arg *arg);
+static void togglesticky(const Arg *arg);
static void togglefullscreen(const Arg *arg);
+static void togglegaps(const Arg *arg);
+static void togglescratch(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
static void unlocksession(struct wl_listener *listener, void *data);
static void unmaplayersurfacenotify(struct wl_listener *listener, void *data);
static void unmapnotify(struct wl_listener *listener, void *data);
static void updatemons(struct wl_listener *listener, void *data);
+static void updatebar(Monitor *m);
static void updatetitle(struct wl_listener *listener, void *data);
static void urgent(struct wl_listener *listener, void *data);
static void view(const Arg *arg);
static void virtualkeyboard(struct wl_listener *listener, void *data);
static void virtualpointer(struct wl_listener *listener, void *data);
+static void warpcursortoclient(Client *c);
static Monitor *xytomon(double x, double y);
static void xytonode(double x, double y, struct wlr_surface **psurface,
Client **pc, LayerSurface **pl, double *nx, double *ny);
static void zoom(const Arg *arg);
+static pid_t getparentprocess(pid_t p);
+static int isdescprocess(pid_t p, pid_t c);
+static Client *termforwin(Client *w);
+static void swallow(Client *c, Client *w);
/* variables */
static pid_t child_pid = -1;
@@ -406,6 +486,18 @@ static struct wlr_box sgeom;
static struct wl_list mons;
static Monitor *selmon;
+static struct zdwl_ipc_manager_v2_interface dwl_manager_implementation = {.release = dwl_ipc_manager_release, .get_output = dwl_ipc_manager_get_output};
+static struct zdwl_ipc_output_v2_interface dwl_output_implementation = {.release = dwl_ipc_output_release, .set_tags = dwl_ipc_output_set_tags, .set_layout = dwl_ipc_output_set_layout, .set_client_tags = dwl_ipc_output_set_client_tags};
+
+static char stext[256];
+static struct wl_event_source *status_event_source;
+
+static const struct wlr_buffer_impl buffer_impl = {
+ .destroy = bufdestroy,
+ .begin_data_ptr_access = bufdatabegin,
+ .end_data_ptr_access = bufdataend,
+};
+
/* global event handlers */
static struct wl_listener cursor_axis = {.notify = axisnotify};
static struct wl_listener cursor_button = {.notify = buttonpress};
@@ -455,6 +547,9 @@ static struct wlr_xwayland *xwayland;
/* attempt to encapsulate suck into one file */
#include "client.h"
+static pid_t *autostart_pids;
+static size_t autostart_len;
+
/* function implementations */
void
applybounds(Client *c, struct wlr_box *bbox)
@@ -483,13 +578,21 @@ applyrules(Client *c)
const Rule *r;
Monitor *mon = selmon, *m;
+ c->isfloating = client_is_float_type(c);
+ c->scratchkey = 0;
appid = client_get_appid(c);
title = client_get_title(c);
+ c->pid = client_get_pid(c);
+
for (r = rules; r < END(rules); r++) {
if ((!r->title || strstr(title, r->title))
&& (!r->id || strstr(appid, r->id))) {
+ c->iscentered = r->iscentered;
c->isfloating = r->isfloating;
+ c->scratchkey = r->scratchkey;
+ c->isterm = r->isterm;
+ c->noswallow = r->noswallow;
newtags |= r->tags;
i = 0;
wl_list_for_each(m, &mons, link) {
@@ -498,8 +601,27 @@ applyrules(Client *c)
}
}
}
+ if (!c->noswallow && !client_is_float_type(c)
+ && !c->surface.xdg->initial_commit) {
+ Client *p = termforwin(c);
+ if (p) {
+ c->swallowedby = p;
+ p->swallowing = c;
+ wl_list_remove(&c->link);
+ wl_list_remove(&c->flink);
+ swallow(c, p);
+ wl_list_remove(&p->link);
+ wl_list_remove(&p->flink);
+ mon = p->mon;
+ newtags = p->tags;
+ }
+ }
+
+ if (c->iscentered) {
+ c->geom.x = (mon->w.width - c->geom.width) / 2 + mon->m.x;
+ c->geom.y = (mon->w.height - c->geom.height) / 2 + mon->m.y;
+ }
- c->isfloating |= client_is_float_type(c);
setmon(c, mon, newtags);
}
@@ -540,6 +662,8 @@ arrange(Monitor *m)
if (m->lt[m->sellt]->arrange)
m->lt[m->sellt]->arrange(m);
motionnotify(0, NULL, 0, 0, 0, 0);
+
+ if (c && mousefollowsfocus) warpcursortoclient(c);
checkidleinhibitor(NULL);
}
@@ -576,6 +700,11 @@ arrangelayers(Monitor *m)
if (!m->wlr_output->enabled)
return;
+ if (m->scene_buffer->node.enabled) {
+ usable_area.height -= m->b.real_height;
+ usable_area.y += topbar ? m->b.real_height : 0;
+ }
+
/* Arrange exclusive surfaces from top->bottom */
for (i = 3; i >= 0; i--)
arrangelayer(m, &m->layers[i], &usable_area, 1);
@@ -604,6 +733,27 @@ arrangelayers(Monitor *m)
}
void
+autostartexec(void) {
+ const char *const *p;
+ size_t i = 0;
+
+ /* count entries */
+ for (p = autostart; *p; autostart_len++, p++)
+ while (*++p);
+
+ autostart_pids = calloc(autostart_len, sizeof(pid_t));
+ for (p = autostart; *p; i++, p++) {
+ if ((autostart_pids[i] = fork()) == 0) {
+ setsid();
+ execvp(*p, (char *const *)p);
+ die("dwl: execvp %s:", *p);
+ }
+ /* skip arguments */
+ while (*++p);
+ }
+}
+
+void
axisnotify(struct wl_listener *listener, void *data)
{
/* This event is forwarded by the cursor when a pointer emits an axis event,
@@ -618,17 +768,103 @@ axisnotify(struct wl_listener *listener, void *data)
event->delta_discrete, event->source, event->relative_direction);
}
+bool
+baracceptsinput(struct wlr_scene_buffer *buffer, double *sx, double *sy)
+{
+ return true;
+}
+
+void
+bufdestroy(struct wlr_buffer *wlr_buffer)
+{
+ Buffer *buf = wl_container_of(wlr_buffer, buf, base);
+ if (buf->busy)
+ wl_list_remove(&buf->release.link);
+ drwl_image_destroy(buf->image);
+ free(buf);
+}
+
+bool
+bufdatabegin(struct wlr_buffer *wlr_buffer, uint32_t flags,
+ void **data, uint32_t *format, size_t *stride)
+{
+ Buffer *buf = wl_container_of(wlr_buffer, buf, base);
+
+ if (flags & WLR_BUFFER_DATA_PTR_ACCESS_WRITE) return false;
+
+ *data = buf->data;
+ *stride = wlr_buffer->width * 4;
+ *format = DRM_FORMAT_ARGB8888;
+
+ return true;
+}
+
+void
+bufdataend(struct wlr_buffer *wlr_buffer)
+{
+}
+
+Buffer *
+bufmon(Monitor *m)
+{
+ size_t i;
+ Buffer *buf = NULL;
+
+ for (i = 0; i < LENGTH(m->pool); i++) {
+ if (m->pool[i]) {
+ if (m->pool[i]->busy)
+ continue;
+ buf = m->pool[i];
+ break;
+ }
+
+ buf = ecalloc(1, sizeof(Buffer) + (m->b.width * 4 * m->b.height));
+ buf->image = drwl_image_create(NULL, m->b.width, m->b.height, buf->data);
+ wlr_buffer_init(&buf->base, &buffer_impl, m->b.width, m->b.height);
+ m->pool[i] = buf;
+ break;
+ }
+ if (!buf)
+ return NULL;
+
+ buf->busy = true;
+ LISTEN(&buf->base.events.release, &buf->release, bufrelease);
+ wlr_buffer_lock(&buf->base);
+ drwl_setimage(m->drw, buf->image);
+ return buf;
+}
+
+void
+bufrelease(struct wl_listener *listener, void *data)
+{
+ Buffer *buf = wl_container_of(listener, buf, release);
+ buf->busy = false;
+ wl_list_remove(&buf->release.link);
+}
+
void
buttonpress(struct wl_listener *listener, void *data)
{
+ unsigned int i = 0, x = 0;
+ double cx;
+ unsigned int click;
struct wlr_pointer_button_event *event = data;
struct wlr_keyboard *keyboard;
+ struct wlr_scene_node *node;
+ struct wlr_scene_buffer *buffer;
uint32_t mods;
+ Arg arg = {0};
Client *c;
const Button *b;
+ uint32_t occ = 0;
wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
+ click = ClkRoot;
+ xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL);
+ if (c)
+ click = ClkClient;
+
switch (event->state) {
case WL_POINTER_BUTTON_STATE_PRESSED:
cursor_mode = CurPressed;
@@ -636,17 +872,47 @@ buttonpress(struct wl_listener *listener, void *data)
if (locked)
break;
+ if (!c && !exclusive_focus &&
+ (node = wlr_scene_node_at(&layers[LyrBottom]->node, cursor->x, cursor->y, NULL, NULL)) &&
+ (buffer = wlr_scene_buffer_from_node(node)) && buffer == selmon->scene_buffer) {
+ cx = (cursor->x - selmon->m.x) * selmon->wlr_output->scale;
+
+ // Get shown tags
+ wl_list_for_each(c, &clients, link) {
+ if (c->mon != selmon)
+ continue;
+ occ |= c->tags == TAGMASK ? 0 : c->tags;
+ }
+
+
+ do {
+ // Check if the tag is shown
+ if (!((occ & 1 << i) || selmon->tagset[selmon->seltags] & 1 << i))
+ continue;
+
+ x += TEXTW(selmon, tags[i]);
+ } while (cx >= x && ++i < LENGTH(tags));
+ if (i < LENGTH(tags)) {
+ click = ClkTagBar;
+ arg.ui = 1 << i;
+ } else if (cx < x + TEXTW(selmon, selmon->ltsymbol))
+ click = ClkLtSymbol;
+ else if (cx > selmon->b.width - (TEXTW(selmon, stext) - selmon->lrpad + 2)) {
+ click = ClkStatus;
+ } else
+ click = ClkTitle;
+ }
+
/* Change focus if the button was _pressed_ over a client */
xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL);
- if (c && (!client_is_unmanaged(c) || client_wants_focus(c)))
+ if (click == ClkClient && (!client_is_unmanaged(c) || client_wants_focus(c)))
focusclient(c, 1);
keyboard = wlr_seat_get_keyboard(seat);
mods = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0;
for (b = buttons; b < END(buttons); b++) {
- if (CLEANMASK(mods) == CLEANMASK(b->mod) &&
- event->button == b->button && b->func) {
- b->func(&b->arg);
+ if (CLEANMASK(mods) == CLEANMASK(b->mod) && event->button == b->button && click == b->click && b->func) {
+ b->func(click == ClkTagBar && b->arg.i == 0 ? &arg : &b->arg);
return;
}
}
@@ -699,12 +965,22 @@ checkidleinhibitor(struct wlr_surface *exclude)
void
cleanup(void)
{
+ size_t i;
cleanuplisteners();
#ifdef XWAYLAND
wlr_xwayland_destroy(xwayland);
xwayland = NULL;
#endif
wl_display_destroy_clients(dpy);
+
+ /* kill child processes */
+ for (i = 0; i < autostart_len; i++) {
+ if (0 < autostart_pids[i]) {
+ kill(autostart_pids[i], SIGTERM);
+ waitpid(autostart_pids[i], NULL, 0);
+ }
+ }
+
if (child_pid > 0) {
kill(-child_pid, SIGTERM);
waitpid(child_pid, NULL, 0);
@@ -721,6 +997,8 @@ cleanup(void)
/* Destroy after the wayland display (when the monitors are already destroyed)
to avoid destroying them with an invalid scene output. */
wlr_scene_node_destroy(&scene->tree.node);
+
+ drwl_fini();
}
void
@@ -730,12 +1008,22 @@ cleanupmon(struct wl_listener *listener, void *data)
LayerSurface *l, *tmp;
size_t i;
+ DwlIpcOutput *ipc_output, *ipc_output_tmp;
+ wl_list_for_each_safe(ipc_output, ipc_output_tmp, &m->dwl_ipc_outputs, link)
+ wl_resource_destroy(ipc_output->resource);
+
/* m->layers[i] are intentionally not unlinked */
for (i = 0; i < LENGTH(m->layers); i++) {
wl_list_for_each_safe(l, tmp, &m->layers[i], link)
wlr_layer_surface_v1_destroy(l->layer_surface);
}
+ for (i = 0; i < LENGTH(m->pool); i++)
+ wlr_buffer_drop(&m->pool[i]->base);
+
+ drwl_setimage(m->drw, NULL);
+ drwl_destroy(m->drw);
+
wl_list_remove(&m->destroy.link);
wl_list_remove(&m->frame.link);
wl_list_remove(&m->link);
@@ -748,6 +1036,7 @@ cleanupmon(struct wl_listener *listener, void *data)
closemon(m);
wlr_scene_node_destroy(&m->fullscreen_bg->node);
+ wlr_scene_node_destroy(&m->scene_buffer->node);
free(m);
}
@@ -809,12 +1098,12 @@ closemon(Monitor *m)
wl_list_for_each(c, &clients, link) {
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,
- .width = c->geom.width, .height = c->geom.height}, 0);
+ .width = c->geom.width, .height = c->geom.height}, 0, 1);
if (c->mon == m)
setmon(c, selmon, c->tags);
}
focusclient(focustop(selmon), 1);
- printstatus();
+ drawbars();
}
void
@@ -878,7 +1167,11 @@ commitnotify(struct wl_listener *listener, void *data)
return;
}
- resize(c, c->geom, (c->isfloating && !c->isfullscreen));
+ if (client_surface(c)->mapped && c->mon && c->mon->lt[c->mon->sellt]->arrange
+ && !c->isfullscreen && !c->isfloating)
+ c->mon->lt[c->mon->sellt]->arrange(c->mon);
+ else
+ resize(c, c->geom, (c->isfloating && !c->isfullscreen), (c->isfloating && !c->isfullscreen));
/* mark a pending resize as completed */
if (c->resize && c->resize <= c->surface.xdg->current.configure_serial)
@@ -1052,6 +1345,8 @@ createmon(struct wl_listener *listener, void *data)
m = wlr_output->data = ecalloc(1, sizeof(*m));
m->wlr_output = wlr_output;
+ wl_list_init(&m->dwl_ipc_outputs);
+
for (i = 0; i < LENGTH(m->layers); i++)
wl_list_init(&m->layers[i]);
@@ -1064,6 +1359,7 @@ createmon(struct wl_listener *listener, void *data)
m->m.y = r->y;
m->mfact = r->mfact;
m->nmaster = r->nmaster;
+ m->gappx = gappx;
m->lt[0] = r->lt;
m->lt[1] = &layouts[LENGTH(layouts) > 1 && r->lt != &layouts[1]];
strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, LENGTH(m->ltsymbol));
@@ -1088,8 +1384,15 @@ createmon(struct wl_listener *listener, void *data)
wlr_output_commit_state(wlr_output, &state);
wlr_output_state_finish(&state);
+ if (!(m->drw = drwl_create()))
+ die("failed to create drwl context");
+
+ m->scene_buffer = wlr_scene_buffer_create(layers[LyrBottom], NULL);
+ m->scene_buffer->point_accepts_input = baracceptsinput;
+ updatebar(m);
+
wl_list_insert(&mons, &m->link);
- printstatus();
+ drawbars();
/* The xdg-protocol specifies:
*
@@ -1400,6 +1703,264 @@ dirtomon(enum wlr_direction dir)
}
void
+dwl_ipc_manager_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
+{
+ struct wl_resource *manager_resource = wl_resource_create(client, &zdwl_ipc_manager_v2_interface, version, id);
+ if (!manager_resource) {
+ wl_client_post_no_memory(client);
+ return;
+ }
+ wl_resource_set_implementation(manager_resource, &dwl_manager_implementation, NULL, dwl_ipc_manager_destroy);
+
+ zdwl_ipc_manager_v2_send_tags(manager_resource, LENGTH(tags));
+
+ for (unsigned int i = 0; i < LENGTH(layouts); i++)
+ zdwl_ipc_manager_v2_send_layout(manager_resource, layouts[i].symbol);
+}
+
+void
+dwl_ipc_manager_destroy(struct wl_resource *resource)
+{
+ /* No state to destroy */
+}
+
+void
+dwl_ipc_manager_get_output(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *output)
+{
+ DwlIpcOutput *ipc_output;
+ Monitor *monitor = wlr_output_from_resource(output)->data;
+ struct wl_resource *output_resource = wl_resource_create(client, &zdwl_ipc_output_v2_interface, wl_resource_get_version(resource), id);
+ if (!output_resource)
+ return;
+
+ ipc_output = ecalloc(1, sizeof(*ipc_output));
+ ipc_output->resource = output_resource;
+ ipc_output->mon = monitor;
+ wl_resource_set_implementation(output_resource, &dwl_output_implementation, ipc_output, dwl_ipc_output_destroy);
+ wl_list_insert(&monitor->dwl_ipc_outputs, &ipc_output->link);
+ dwl_ipc_output_printstatus_to(ipc_output);
+}
+
+void
+dwl_ipc_manager_release(struct wl_client *client, struct wl_resource *resource)
+{
+ wl_resource_destroy(resource);
+}
+
+static void
+dwl_ipc_output_destroy(struct wl_resource *resource)
+{
+ DwlIpcOutput *ipc_output = wl_resource_get_user_data(resource);
+ wl_list_remove(&ipc_output->link);
+ free(ipc_output);
+}
+
+void
+dwl_ipc_output_printstatus(Monitor *monitor)
+{
+ DwlIpcOutput *ipc_output;
+ wl_list_for_each(ipc_output, &monitor->dwl_ipc_outputs, link)
+ dwl_ipc_output_printstatus_to(ipc_output);
+}
+
+void
+dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output)
+{
+ Monitor *monitor = ipc_output->mon;
+ Client *c, *focused;
+ int tagmask, state, numclients, focused_client, tag;
+ const char *title, *appid;
+ focused = focustop(monitor);
+ zdwl_ipc_output_v2_send_active(ipc_output->resource, monitor == selmon);
+
+ for (tag = 0 ; tag < LENGTH(tags); tag++) {
+ numclients = state = focused_client = 0;
+ tagmask = 1 << tag;
+ if ((tagmask & monitor->tagset[monitor->seltags]) != 0)
+ state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_ACTIVE;
+
+ wl_list_for_each(c, &clients, link) {
+ if (c->mon != monitor)
+ continue;
+ if (!(c->tags & tagmask))
+ continue;
+ if (c == focused)
+ focused_client = 1;
+ if (c->isurgent)
+ state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_URGENT;
+
+ numclients++;
+ }
+ zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state, numclients, focused_client);
+ }
+ title = focused ? client_get_title(focused) : "";
+ appid = focused ? client_get_appid(focused) : "";
+
+ zdwl_ipc_output_v2_send_layout(ipc_output->resource, monitor->lt[monitor->sellt] - layouts);
+ zdwl_ipc_output_v2_send_title(ipc_output->resource, title);
+ zdwl_ipc_output_v2_send_appid(ipc_output->resource, appid);
+ zdwl_ipc_output_v2_send_layout_symbol(ipc_output->resource, monitor->ltsymbol);
+ if (wl_resource_get_version(ipc_output->resource) >= ZDWL_IPC_OUTPUT_V2_FULLSCREEN_SINCE_VERSION) {
+ zdwl_ipc_output_v2_send_fullscreen(ipc_output->resource, focused ? focused->isfullscreen : 0);
+ }
+ if (wl_resource_get_version(ipc_output->resource) >= ZDWL_IPC_OUTPUT_V2_FLOATING_SINCE_VERSION) {
+ zdwl_ipc_output_v2_send_floating(ipc_output->resource, focused ? focused->isfloating : 0);
+ }
+ zdwl_ipc_output_v2_send_frame(ipc_output->resource);
+}
+
+void
+dwl_ipc_output_set_client_tags(struct wl_client *client, struct wl_resource *resource, uint32_t and_tags, uint32_t xor_tags)
+{
+ DwlIpcOutput *ipc_output;
+ Monitor *monitor;
+ Client *selected_client;
+ unsigned int newtags = 0;
+
+ ipc_output = wl_resource_get_user_data(resource);
+ if (!ipc_output)
+ return;
+
+ monitor = ipc_output->mon;
+ selected_client = focustop(monitor);
+ if (!selected_client)
+ return;
+
+ newtags = (selected_client->tags & and_tags) ^ xor_tags;
+ if (!newtags)
+ return;
+
+ selected_client->tags = newtags;
+ if (selmon == monitor)
+ focusclient(focustop(monitor), 1);
+ arrange(selmon);
+ //printstatus();
+}
+
+void
+dwl_ipc_output_set_layout(struct wl_client *client, struct wl_resource *resource, uint32_t index)
+{
+ DwlIpcOutput *ipc_output;
+ Monitor *monitor;
+
+ ipc_output = wl_resource_get_user_data(resource);
+ if (!ipc_output)
+ return;
+
+ monitor = ipc_output->mon;
+ if (index >= LENGTH(layouts))
+ return;
+ if (index != monitor->lt[monitor->sellt] - layouts)
+ monitor->sellt ^= 1;
+
+ monitor->lt[monitor->sellt] = &layouts[index];
+ arrange(monitor);
+ //printstatus();
+}
+
+void
+dwl_ipc_output_set_tags(struct wl_client *client, struct wl_resource *resource, uint32_t tagmask, uint32_t toggle_tagset)
+{
+ DwlIpcOutput *ipc_output;
+ Monitor *monitor;
+ unsigned int newtags = tagmask & TAGMASK;
+
+ ipc_output = wl_resource_get_user_data(resource);
+ if (!ipc_output)
+ return;
+ monitor = ipc_output->mon;
+
+ if (!newtags || newtags == monitor->tagset[monitor->seltags])
+ return;
+ if (toggle_tagset)
+ monitor->seltags ^= 1;
+
+ monitor->tagset[monitor->seltags] = newtags;
+ if (selmon == monitor)
+ focusclient(focustop(monitor), 1);
+ arrange(monitor);
+ //printstatus();
+}
+
+void
+dwl_ipc_output_release(struct wl_client *client, struct wl_resource *resource)
+{
+ wl_resource_destroy(resource);
+}
+
+void
+drawbar(Monitor *m)
+{
+ int x, w, tw = 0;
+ int boxs = m->drw->font->height / 9;
+ int boxw = m->drw->font->height / 6 + 2;
+ uint32_t i, occ = 0, urg = 0;
+ Client *c;
+ Buffer *buf;
+
+ if (!m->scene_buffer->node.enabled)
+ return;
+ if (!(buf = bufmon(m)))
+ return;
+
+ /* draw status first so it can be overdrawn by tags later */
+ if (m == selmon) { /* status is only drawn on selected monitor */
+ drwl_setscheme(m->drw, colors[SchemeNorm]);
+ tw = TEXTW(m, stext) - m->lrpad + 2; /* 2px right padding */
+ drwl_text(m->drw, m->b.width - tw, 0, tw, m->b.height, 0, stext, 0);
+ }
+
+ wl_list_for_each(c, &clients, link) {
+ if (c->mon != m)
+ continue;
+ occ |= c->tags == TAGMASK ? 0 : c->tags;
+ if (c->isurgent)
+ urg |= c->tags;
+ }
+ x = 0;
+ c = focustop(m);
+ for (i = 0; i < LENGTH(tags); i++) {
+ // Skip drawing this tag, if not in focus, or empty
+ if (!((occ & 1 << i) || m->tagset[m->seltags] & 1 << i)) continue;
+ w = TEXTW(m, tags[i]);
+ drwl_setscheme(m->drw, colors[m->tagset[m->seltags] & 1 << i ? SchemeTagSel : SchemeNorm]);
+ drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, tags[i], urg & 1 << i);
+ x += w;
+ }
+ w = TEXTW(m, m->ltsymbol);
+ drwl_setscheme(m->drw, colors[SchemeNorm]);
+ x = drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, m->ltsymbol, 0);
+
+ if ((w = m->b.width - tw - x) > m->b.height) {
+ if (c) {
+ drwl_setscheme(m->drw, colors[m == selmon ? SchemeSel : SchemeNorm]);
+ drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, client_get_title(c), 0);
+ if (c && c->isfloating)
+ drwl_rect(m->drw, x + boxs, boxs, boxw, boxw, 0, 0);
+ } else {
+ drwl_setscheme(m->drw, colors[SchemeNorm]);
+ drwl_rect(m->drw, x, 0, w, m->b.height, 1, 1);
+ }
+ }
+
+ wlr_scene_buffer_set_dest_size(m->scene_buffer,
+ m->b.real_width, m->b.real_height);
+ wlr_scene_node_set_position(&m->scene_buffer->node, m->m.x,
+ m->m.y + (topbar ? 0 : m->m.height - m->b.real_height));
+ wlr_scene_buffer_set_buffer(m->scene_buffer, &buf->base);
+ wlr_buffer_unlock(&buf->base);
+}
+
+void
+drawbars(void)
+{
+ Monitor *m = NULL;
+
+ wl_list_for_each(m, &mons, link)
+ drawbar(m);
+}
+
+void
focusclient(Client *c, int lift)
{
struct wlr_surface *old = seat->keyboard_state.focused_surface;
@@ -1433,13 +1994,13 @@ focusclient(Client *c, int lift)
/* Don't change border color if there is an exclusive focus or we are
* handling a drag operation */
if (!exclusive_focus && !seat->drag)
- client_set_border_color(c, focuscolor);
+ client_set_border_color(c, (float[])COLOR(colors[SchemeSel][ColBorder]));
}
/* Deactivate old client if focus is changing */
if (old && (!c || client_surface(c) != old)) {
/* 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 its color
* and focus it after the overlay is closed. */
if (old_client_type == LayerShell && wlr_scene_node_coords(
&old_l->scene->node, &unused_lx, &unused_ly)
@@ -1450,12 +2011,11 @@ focusclient(Client *c, int lift)
/* Don't deactivate old client if the new one wants focus, as this causes issues with winecfg
* and probably other clients */
} 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, (float[])COLOR(colors[SchemeNorm][ColBorder]));
client_activate_surface(old, 0);
}
}
- printstatus();
+ drawbars();
if (!c) {
/* With no client, all we have left is to clear focus */
@@ -1477,12 +2037,102 @@ void
focusmon(const Arg *arg)
{
int i = 0, nmons = wl_list_length(&mons);
+ Client *c = NULL;
if (nmons) {
do /* don't switch to disabled mons */
selmon = dirtomon(arg->i);
while (!selmon->wlr_output->enabled && i++ < nmons);
}
- focusclient(focustop(selmon), 1);
+
+ c = focustop(selmon);
+ focusclient(c, 1);
+
+ if (mousefollowsfocus) warpcursortoclient(c);
+}
+
+void
+focusortogglematchingscratch(const Arg *arg)
+{
+ Client *c;
+ unsigned int found = 0;
+ unsigned int hide = 0;
+
+ wl_list_for_each(c, &clients, link) {
+ if (c->scratchkey == 0) {
+ continue;
+ }
+ if (c->scratchkey == ((char**)arg->v)[0][0]) {
+ if (VISIBLEON(c, selmon)) {
+ if (found == 1) {
+ if (hide == 1) {
+ c->tags = 0;
+ focusclient(focustop(selmon), 1);
+ }
+ continue;
+ }
+ if (focustop(selmon) == c) {
+ // hide
+ c->tags = 0;
+ focusclient(focustop(selmon), 1);
+ hide = 1;
+ } else {
+ // focus
+ focusclient(c, 1);
+ }
+ } else {
+ // show
+ c->tags = selmon->tagset[selmon->seltags];
+ // focus
+ focusclient(c, 1);
+ }
+ found = 1;
+ continue;
+ }
+ if (VISIBLEON(c, selmon)) {
+ // hide
+ c->tags = 0;
+ }
+ }
+
+ if (found) {
+ arrange(selmon);
+ } else {
+ spawnscratch(arg);
+ }
+}
+
+void
+focusortogglescratch(const Arg *arg)
+{
+ Client *c;
+ unsigned int found = 0;
+
+ /* search for first window that matches the scratchkey */
+ wl_list_for_each(c, &clients, link)
+ if (c->scratchkey == ((char**)arg->v)[0][0]) {
+ found = 1;
+ break;
+ }
+
+ if (found) {
+ if (VISIBLEON(c, selmon)) {
+ if (focustop(selmon) == c) {
+ // hide
+ c->tags = 0;
+ focusclient(focustop(selmon), 1);
+ } else {
+ // focus
+ focusclient(c, 1);
+ }
+ } else {
+ // show
+ c->tags = selmon->tagset[selmon->seltags];
+ focusclient(c, 1);
+ }
+ arrange(selmon);
+ } else{
+ spawnscratch(arg);
+ }
}
void
@@ -1492,7 +2142,21 @@ focusstack(const Arg *arg)
Client *c, *sel = focustop(selmon);
if (!sel || (sel->isfullscreen && !client_has_children(sel)))
return;
- if (arg->i > 0) {
+ /* If i == 0 select the first client */
+ if (arg->i == 0) {
+ wl_list_for_each(c, &clients, link) {
+ if (!VISIBLEON(c, selmon) || c->isfloating || c->isfullscreen)
+ continue;
+ break;
+ }
+ /* If i == INT_MAX select the last client */
+ } else if (arg->i == INT_MAX) {
+ wl_list_for_each_reverse(c, &clients, link) {
+ if (!VISIBLEON(c, selmon) || c->isfloating || c->isfullscreen)
+ continue;
+ break;
+ }
+ } else if (arg->i > 0) {
wl_list_for_each(c, &sel->link, link) {
if (&c->link == &clients)
continue; /* wrap past the sentinel node */
@@ -1509,6 +2173,7 @@ focusstack(const Arg *arg)
}
/* If only one client is visible on selmon, then c == sel */
focusclient(c, 1);
+ if (mousefollowsfocus) warpcursortoclient(c);
}
/* We probably should change the name of this: it sounds like it
@@ -1561,9 +2226,89 @@ void
handlesig(int signo)
{
if (signo == SIGCHLD)
- while (waitpid(-1, NULL, WNOHANG) > 0);
- else if (signo == SIGINT || signo == SIGTERM)
+ {
+ siginfo_t in;
+ /* wlroots expects to reap the XWayland process itself, so we
+ * use WNOWAIT to keep the child waitable until we know it's not
+ * XWayland.
+ */
+ while (!waitid(P_ALL, 0, &in, WEXITED|WNOHANG|WNOWAIT) && in.si_pid
+ ) {
+ pid_t *p, *lim;
+ waitpid(in.si_pid, NULL, 0);
+ if (in.si_pid == child_pid)
+ child_pid = -1;
+ if (!(p = autostart_pids))
+ continue;
+ lim = &p[autostart_len];
+
+ for (; p < lim; p++) {
+ if (*p == in.si_pid) {
+ *p = -1;
+ break;
+ }
+ }
+ }
+ } else if (signo == SIGINT || signo == SIGTERM) {
quit(NULL);
+ }
+}
+
+pid_t
+getparentprocess(pid_t p)
+{
+ unsigned int v = 0;
+
+ FILE *f;
+ char buf[256];
+ snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)p);
+
+ if (!(f = fopen(buf, "r")))
+ return 0;
+
+ fscanf(f, "%*u %*s %*c %u", &v);
+ fclose(f);
+
+ return (pid_t)v;
+}
+
+int
+isdescprocess(pid_t p, pid_t c)
+{
+ while (p != c && c != 0)
+ c = getparentprocess(c);
+
+ return (int)c;
+}
+
+Client *
+termforwin(Client *w)
+{
+ Client *c;
+
+ if (!w->pid || w->isterm || w->noswallow)
+ return NULL;
+
+ wl_list_for_each(c, &fstack, flink)
+ if (c->isterm && !c->swallowing && c->pid && isdescprocess(c->pid, w->pid))
+ return c;
+
+ return NULL;
+}
+
+void
+swallow(Client *c, Client *w)
+{
+ c->bw = w->bw;
+ c->isfloating = w->isfloating;
+ c->isurgent = w->isurgent;
+ c->isfullscreen = w->isfullscreen;
+ c->tags = w->tags;
+ c->geom = w->geom;
+ wl_list_insert(&w->link, &c->link);
+ wl_list_insert(&w->flink, &c->flink);
+ wlr_scene_node_set_enabled(&w->scene->node, 0);
+ wlr_scene_node_set_enabled(&c->scene->node, 1);
}
void
@@ -1768,7 +2513,7 @@ mapnotify(struct wl_listener *listener, void *data)
for (i = 0; i < 4; i++) {
c->border[i] = wlr_scene_rect_create(c->scene, 0, 0,
- c->isurgent ? urgentcolor : bordercolor);
+ (float[])COLOR(colors[c->isurgent ? SchemeUrg : SchemeNorm][ColBorder]));
c->border[i]->node.data = c;
}
@@ -1791,7 +2536,7 @@ mapnotify(struct wl_listener *listener, void *data)
} else {
applyrules(c);
}
- printstatus();
+ drawbars();
unset_fullscreen:
m = c->mon ? c->mon : xytomon(c->geom.x, c->geom.y);
@@ -1828,7 +2573,7 @@ monocle(Monitor *m)
wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
continue;
- resize(c, m->w, 0);
+ resize(c, m->w, 0, !smartborders);
n++;
}
if (n)
@@ -1838,6 +2583,49 @@ monocle(Monitor *m)
}
void
+movestack(const Arg *arg)
+{
+ Client *c, *sel = focustop(selmon);
+
+ if (wl_list_length(&clients) <= 1) {
+ return;
+ }
+
+ if (arg->i == 0) {
+ /* Put the selected client on top */
+ wl_list_remove(&sel->link);
+ wl_list_insert(&clients, &sel->link);
+ arrange(selmon);
+ return;
+ } else if (arg->i == INT_MAX) {
+ /* Get the last element */
+ wl_list_for_each_reverse(c, &clients, link) {
+ if (!VISIBLEON(c, selmon) || c->isfloating || c->isfullscreen)
+ continue;
+ break;
+ }
+ } else if (arg->i > 0) {
+ wl_list_for_each(c, &sel->link, link) {
+ if (VISIBLEON(c, selmon) || &c->link == &clients) {
+ break; /* found it */
+ }
+ }
+ } else {
+ wl_list_for_each_reverse(c, &sel->link, link) {
+ if (VISIBLEON(c, selmon) || &c->link == &clients) {
+ break; /* found it */
+ }
+ }
+ /* backup one client */
+ c = wl_container_of(c->link.prev, c, link);
+ }
+
+ wl_list_remove(&sel->link);
+ wl_list_insert(&c->link, &sel->link);
+ arrange(selmon);
+}
+
+void
motionabsolute(struct wl_listener *listener, void *data)
{
/* This event is forwarded by the cursor when a pointer emits an _absolute_
@@ -1919,11 +2707,11 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double d
if (cursor_mode == CurMove) {
/* 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,
- .width = grabc->geom.width, .height = grabc->geom.height}, 1);
+ .width = grabc->geom.width, .height = grabc->geom.height}, 1, 1);
return;
} else if (cursor_mode == CurResize) {
resize(grabc, (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);
+ .width = (int)round(cursor->x) - grabc->geom.x, .height = (int)round(cursor->y) - grabc->geom.y}, 1, 1);
return;
}
@@ -2088,38 +2876,9 @@ void
printstatus(void)
{
Monitor *m = NULL;
- Client *c;
- uint32_t occ, urg, sel;
-
- wl_list_for_each(m, &mons, link) {
- occ = urg = 0;
- wl_list_for_each(c, &clients, link) {
- if (c->mon != m)
- continue;
- occ |= c->tags;
- if (c->isurgent)
- urg |= c->tags;
- }
- if ((c = focustop(m))) {
- printf("%s title %s\n", m->wlr_output->name, client_get_title(c));
- printf("%s appid %s\n", m->wlr_output->name, client_get_appid(c));
- printf("%s fullscreen %d\n", m->wlr_output->name, c->isfullscreen);
- printf("%s floating %d\n", m->wlr_output->name, c->isfloating);
- sel = c->tags;
- } else {
- printf("%s title \n", m->wlr_output->name);
- printf("%s appid \n", m->wlr_output->name);
- printf("%s fullscreen \n", m->wlr_output->name);
- printf("%s floating \n", m->wlr_output->name);
- sel = 0;
- }
- printf("%s selmon %u\n", m->wlr_output->name, m == selmon);
- printf("%s tags %"PRIu32" %"PRIu32" %"PRIu32" %"PRIu32"\n",
- m->wlr_output->name, occ, m->tagset[m->seltags], sel, urg);
- printf("%s layout %s\n", m->wlr_output->name, m->ltsymbol);
- }
- fflush(stdout);
+ wl_list_for_each(m, &mons, link)
+ dwl_ipc_output_printstatus(m);
}
void
@@ -2202,7 +2961,7 @@ requestmonstate(struct wl_listener *listener, void *data)
}
void
-resize(Client *c, struct wlr_box geo, int interact)
+resize(Client *c, struct wlr_box geo, int interact, int draw_borders)
{
struct wlr_box *bbox;
struct wlr_box clip;
@@ -2214,6 +2973,7 @@ resize(Client *c, struct wlr_box geo, int interact)
client_set_bounds(c, geo.width, geo.height);
c->geom = geo;
+ c->bw = draw_borders ? borderpx : 0;
applybounds(c, bbox);
/* Update scene-graph, including borders */
@@ -2235,7 +2995,7 @@ resize(Client *c, struct wlr_box geo, int interact)
}
void
-run(char *startup_cmd)
+run(char *startup_cmd, uid_t uid)
{
/* Add a Unix socket to the Wayland display. */
const char *socket = wl_display_add_socket_auto(dpy);
@@ -2248,34 +3008,25 @@ run(char *startup_cmd)
if (!wlr_backend_start(backend))
die("startup: backend_start");
+ /* In case the option is passed, drop priviledges to desired uid */
+ if (uid > 0)
+ setuid(uid);
+
+
/* Now that the socket exists and the backend is started, run the startup command */
+ autostartexec();
if (startup_cmd) {
- int piperw[2];
- if (pipe(piperw) < 0)
- die("startup: pipe:");
if ((child_pid = fork()) < 0)
die("startup: fork:");
if (child_pid == 0) {
+ close(STDIN_FILENO);
setsid();
- dup2(piperw[0], STDIN_FILENO);
- close(piperw[0]);
- close(piperw[1]);
execl("/bin/sh", "/bin/sh", "-c", startup_cmd, NULL);
die("startup: execl:");
}
- dup2(piperw[1], STDOUT_FILENO);
- close(piperw[1]);
- close(piperw[0]);
}
- /* Mark stdout as non-blocking to avoid the startup script
- * causing dwl to freeze when a user neither closes stdin
- * nor consumes standard input in his startup script */
-
- if (fd_set_nonblock(STDOUT_FILENO) < 0)
- close(STDOUT_FILENO);
-
- printstatus();
+ drawbars();
/* At this point the outputs are initialized, choose initial selmon based on
* cursor position, and set default cursor image */
@@ -2340,8 +3091,10 @@ setfloating(Client *c, int floating)
wlr_scene_node_reparent(&c->scene->node, layers[c->isfullscreen ||
(p && p->isfullscreen) ? LyrFS
: c->isfloating ? LyrFloat : LyrTile]);
+ if (c->isfloating && !c->bw)
+ resize(c, c->mon->m, 0, 1);
arrange(c->mon);
- printstatus();
+ drawbars();
}
void
@@ -2357,14 +3110,36 @@ setfullscreen(Client *c, int fullscreen)
if (fullscreen) {
c->prev = c->geom;
- resize(c, c->mon->m, 0);
+ resize(c, c->mon->m, 0, 0);
} else {
/* restore previous size instead of arrange for floating windows since
* client positions are set by the user and cannot be recalculated */
- resize(c, c->prev, 0);
+ resize(c, c->prev, 0, 1);
}
arrange(c->mon);
- printstatus();
+ drawbars();
+}
+
+void
+setgaps(const Arg *arg) {
+ if ((arg->i == 0) || (selmon->gappx + arg->i < 0))
+ selmon->gappx = gappx;
+ else if (selmon->gappx + arg->i < 0)
+ selmon->gappx = 0;
+ else
+ selmon->gappx += arg->i;
+ arrange(selmon);
+}
+
+void
+setsticky(Client *c, int sticky)
+{
+ if(sticky && !c->issticky) {
+ c->issticky = 1;
+ } else if(!sticky && c->issticky) {
+ c->issticky = 0;
+ arrange(c->mon);
+ }
}
void
@@ -2377,8 +3152,14 @@ setlayout(const Arg *arg)
if (arg && arg->v)
selmon->lt[selmon->sellt] = (Layout *)arg->v;
strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, LENGTH(selmon->ltsymbol));
+ if (!selmon->lt[selmon->sellt]->arrange) {
+ /* floating layout, draw borders around all clients */
+ Client *c;
+ wl_list_for_each(c, &clients, link)
+ resize(c, c->mon->m, 0, 1);
+ }
arrange(selmon);
- printstatus();
+ drawbar(selmon);
}
/* arg > 1.0 will set mfact absolutely */
@@ -2411,7 +3192,7 @@ setmon(Client *c, Monitor *m, uint32_t newtags)
arrange(oldmon);
if (m) {
/* Make sure window actually overlaps with the monitor */
- resize(c, c->geom, 0);
+ resize(c, c->geom, 0, 1);
c->tags = newtags ? newtags : m->tagset[m->seltags]; /* assign tags of target monitor */
setfullscreen(c, c->isfullscreen); /* This will call arrange(c->mon) */
setfloating(c, c->isfloating);
@@ -2451,6 +3232,7 @@ setup(void)
for (i = 0; i < (int)LENGTH(sig); i++)
sigaction(sig[i], &sa, NULL);
+
wlr_log_init(log_level, NULL);
/* The Wayland display is managed by libwayland. It handles accepting
@@ -2645,6 +3427,13 @@ setup(void)
wl_signal_add(&output_mgr->events.apply, &output_mgr_apply);
wl_signal_add(&output_mgr->events.test, &output_mgr_test);
+ wl_global_create(dpy, &zdwl_ipc_manager_v2_interface, 2, NULL, dwl_ipc_manager_bind);
+
+ drwl_init();
+
+ status_event_source = wl_event_loop_add_fd(wl_display_get_event_loop(dpy),
+ STDIN_FILENO, WL_EVENT_READABLE, statusin, NULL);
+
/* Make sure XWayland clients don't connect to the parent X server,
* e.g when running in the x11 backend or the wayland backend and the
* compositor has Xwayland support */
@@ -2669,6 +3458,7 @@ void
spawn(const Arg *arg)
{
if (fork() == 0) {
+ close(STDIN_FILENO);
dup2(STDERR_FILENO, STDOUT_FILENO);
setsid();
execvp(((char **)arg->v)[0], (char **)arg->v);
@@ -2676,6 +3466,16 @@ spawn(const Arg *arg)
}
}
+void spawnscratch(const Arg *arg)
+{
+ if (fork() == 0) {
+ dup2(STDERR_FILENO, STDOUT_FILENO);
+ setsid();
+ execvp(((char **)arg->v)[1], ((char **)arg->v)+1);
+ die("dwl: execvp %s failed:", ((char **)arg->v)[1]);
+ }
+}
+
void
startdrag(struct wl_listener *listener, void *data)
{
@@ -2687,6 +3487,30 @@ startdrag(struct wl_listener *listener, void *data)
LISTEN_STATIC(&drag->icon->events.destroy, destroydragicon);
}
+int
+statusin(int fd, unsigned int mask, void *data)
+{
+ char status[1024];
+ ssize_t n;
+
+ if (mask & WL_EVENT_ERROR)
+ die("status in event error");
+ if (mask & WL_EVENT_HANGUP)
+ wl_event_source_remove(status_event_source);
+
+ n = read(fd, status, sizeof(status) - 1);
+ if (n < 0 && errno != EWOULDBLOCK)
+ die("read:");
+
+ status[n] = '\0';
+ status[strcspn(status, "\n")] = '\0';
+
+ strncpy(stext, status, sizeof(stext));
+ drawbars();
+
+ return 0;
+}
+
void
tag(const Arg *arg)
{
@@ -2697,7 +3521,7 @@ tag(const Arg *arg)
sel->tags = arg->ui & TAGMASK;
focusclient(focustop(selmon), 1);
arrange(selmon);
- printstatus();
+ drawbars();
}
void
@@ -2711,8 +3535,8 @@ tagmon(const Arg *arg)
void
tile(Monitor *m)
{
- unsigned int mw, my, ty;
- int i, n = 0;
+ unsigned int mw, my, ty, draw_borders = 1;
+ int i, n = 0, gap = 0;
Client *c;
wl_list_for_each(c, &clients, link)
@@ -2721,27 +3545,48 @@ tile(Monitor *m)
if (n == 0)
return;
+ if (n > 1)
+ gap = m->gappx;
+
+ if (n == 1 && smartborders)
+ draw_borders = 0;
+
if (n > m->nmaster)
mw = m->nmaster ? (int)roundf(m->w.width * m->mfact) : 0;
else
- mw = m->w.width;
- i = my = ty = 0;
+ mw = m->w.width - gap;
+ i = 0; my = ty = gap;
wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
continue;
if (i < m->nmaster) {
- resize(c, (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;
+ resize(c, (struct wlr_box){.x = m->w.x + gap, .y = m->w.y + my,
+ .width = mw - gap, .height = (m->w.height - my - gap) / (MIN(n, m->nmaster) - i)}, 0, draw_borders);
+ my += c->geom.height + gap;
} else {
- resize(c, (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;
+ resize(c, (struct wlr_box){.x = m->w.x + mw + gap, .y = m->w.y + ty,
+ .width = m->w.width - mw - 2 * gap, .height = (m->w.height - ty) / (n - i) - gap}, 0, draw_borders);
+ ty += c->geom.height + gap;
}
i++;
}
}
+//void
+//togglebar(const Arg *arg) {
+// DwlIpcOutput *ipc_output;
+// wl_list_for_each(ipc_output, &selmon->dwl_ipc_outputs, link)
+// zdwl_ipc_output_v2_send_toggle_visibility(ipc_output->resource);
+//}
+
+void
+togglebar(const Arg *arg)
+{
+ wlr_scene_node_set_enabled(&selmon->scene_buffer->node,
+ !selmon->scene_buffer->node.enabled);
+ arrangelayers(selmon);
+}
+
void
togglefloating(const Arg *arg)
{
@@ -2759,6 +3604,47 @@ togglefullscreen(const Arg *arg)
setfullscreen(sel, !sel->isfullscreen);
}
+void togglegaps(const Arg *arg) {
+ if (selmon->gappx == 0)
+ selmon->gappx = gappx;
+ else
+ selmon->gappx = 0;
+ arrange(selmon);
+}
+
+void
+togglescratch(const Arg *arg)
+{
+ Client *c;
+ unsigned int found = 0;
+
+ /* search for first window that matches the scratchkey */
+ wl_list_for_each(c, &clients, link)
+ if (c->scratchkey == ((char**)arg->v)[0][0]) {
+ found = 1;
+ break;
+ }
+
+ if (found) {
+ c->tags = VISIBLEON(c, selmon) ? 0 : selmon->tagset[selmon->seltags];
+
+ focusclient(c->tags == 0 ? focustop(selmon) : c, 1);
+ arrange(selmon);
+ } else{
+ spawnscratch(arg);
+ }
+}
+
+void
+togglesticky(const Arg *arg)
+{
+ Client *c = focustop(selmon);
+ if(!c)
+ return;
+
+ setsticky(c, !c->issticky);
+}
+
void
toggletag(const Arg *arg)
{
@@ -2770,7 +3656,7 @@ toggletag(const Arg *arg)
sel->tags = newtags;
focusclient(focustop(selmon), 1);
arrange(selmon);
- printstatus();
+ drawbars();
}
void
@@ -2783,7 +3669,7 @@ toggleview(const Arg *arg)
selmon->tagset[selmon->seltags] = newtagset;
focusclient(focustop(selmon), 1);
arrange(selmon);
- printstatus();
+ drawbars();
}
void
@@ -2819,19 +3705,36 @@ unmapnotify(struct wl_listener *listener, void *data)
grabc = NULL;
}
+ if (c->swallowedby)
+ swallow(c->swallowedby, c);
+
if (client_is_unmanaged(c)) {
if (c == exclusive_focus) {
exclusive_focus = NULL;
focusclient(focustop(selmon), 1);
}
} else {
- wl_list_remove(&c->link);
+ if (!c->swallowing)
+ wl_list_remove(&c->link);
setmon(c, NULL, 0);
- wl_list_remove(&c->flink);
+ if (!c->swallowing)
+ wl_list_remove(&c->flink);
+ }
+
+ if (c->swallowedby) {
+ c->swallowedby->prev = c->geom;
+ setfullscreen(c->swallowedby, c->isfullscreen);
+ c->swallowedby->swallowing = NULL;
+ c->swallowedby = NULL;
+ }
+
+ if (c->swallowing) {
+ c->swallowing->swallowedby = NULL;
+ c->swallowing = NULL;
}
wlr_scene_node_destroy(&c->scene->node);
- printstatus();
+ drawbars();
motionnotify(0, NULL, 0, 0, 0, 0);
}
@@ -2904,7 +3807,7 @@ updatemons(struct wl_listener *listener, void *data)
arrange(m);
/* make sure fullscreen clients have the right size */
if ((c = focustop(m)) && c->isfullscreen)
- resize(c, m->m, 0);
+ resize(c, m->m, 0, 0);
/* Try to re-set the gamma LUT when updating monitors,
* it's only really needed when enabling a disabled output, but meh. */
@@ -2931,6 +3834,13 @@ updatemons(struct wl_listener *listener, void *data)
}
}
+ if (stext[0] == '\0')
+ strncpy(stext, "dwl-"VERSION, sizeof(stext));
+ wl_list_for_each(m, &mons, link) {
+ updatebar(m);
+ drawbar(m);
+ }
+
/* FIXME: figure out why the cursor image is at 0,0 after turning all
* the monitors on.
* Move the cursor image where it used to be. It does not generate a
@@ -2942,11 +3852,44 @@ updatemons(struct wl_listener *listener, void *data)
}
void
+updatebar(Monitor *m)
+{
+ size_t i;
+ int rw, rh;
+ char fontattrs[12];
+
+ wlr_output_transformed_resolution(m->wlr_output, &rw, &rh);
+ m->b.width = rw;
+ m->b.real_width = (int)((float)m->b.width / m->wlr_output->scale);
+
+ wlr_scene_node_set_enabled(&m->scene_buffer->node, m->wlr_output->enabled ? showbar : 0);
+
+ for (i = 0; i < LENGTH(m->pool); i++)
+ if (m->pool[i]) {
+ wlr_buffer_drop(&m->pool[i]->base);
+ m->pool[i] = NULL;
+ }
+
+ if (m->b.scale == m->wlr_output->scale && m->drw)
+ return;
+
+ drwl_font_destroy(m->drw->font);
+ snprintf(fontattrs, sizeof(fontattrs), "dpi=%.2f", 96. * m->wlr_output->scale);
+ if (!(drwl_font_create(m->drw, LENGTH(fonts), fonts, fontattrs)))
+ die("Could not load font");
+
+ m->b.scale = m->wlr_output->scale;
+ m->lrpad = m->drw->font->height;
+ m->b.height = m->drw->font->height + 2;
+ m->b.real_height = (int)((float)m->b.height / m->wlr_output->scale);
+}
+
+void
updatetitle(struct wl_listener *listener, void *data)
{
Client *c = wl_container_of(listener, c, set_title);
if (c == focustop(c->mon))
- printstatus();
+ drawbars();
}
void
@@ -2959,10 +3902,10 @@ urgent(struct wl_listener *listener, void *data)
return;
c->isurgent = 1;
- printstatus();
+ drawbars();
if (client_surface(c)->mapped)
- client_set_border_color(c, urgentcolor);
+ client_set_border_color(c, (float[])COLOR(colors[SchemeUrg][ColBorder]));
}
void
@@ -2975,7 +3918,7 @@ view(const Arg *arg)
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
focusclient(focustop(selmon), 1);
arrange(selmon);
- printstatus();
+ drawbars();
}
void
@@ -3003,6 +3946,16 @@ virtualpointer(struct wl_listener *listener, void *data)
wlr_cursor_map_input_to_output(cursor, device, event->suggested_output);
}
+void
+warpcursortoclient(Client *c) {
+ struct wlr_box mg = c->mon->m;
+ struct wlr_box cg = c->geom;
+ if (!VISIBLEON(c, selmon)) return;
+ wlr_cursor_warp_absolute(cursor, NULL,
+ ((double)cg.x + (double)cg.width / 2.0) / (double)mg.width,
+ ((double)cg.y + (double)cg.height / 2.0) / (double)mg.height);
+}
+
Monitor *
xytomon(double x, double y)
{
@@ -3016,6 +3969,7 @@ xytonode(double x, double y, struct wlr_surface **psurface,
{
struct wlr_scene_node *node, *pnode;
struct wlr_surface *surface = NULL;
+ struct wlr_scene_surface *scene_surface = NULL;
Client *c = NULL;
LayerSurface *l = NULL;
int layer;
@@ -3024,9 +3978,12 @@ xytonode(double x, double y, struct wlr_surface **psurface,
if (!(node = wlr_scene_node_at(&layers[layer]->node, x, y, nx, ny)))
continue;
- if (node->type == WLR_SCENE_NODE_BUFFER)
- surface = wlr_scene_surface_try_from_buffer(
- wlr_scene_buffer_from_node(node))->surface;
+ if (node->type == WLR_SCENE_NODE_BUFFER) {
+ scene_surface = wlr_scene_surface_try_from_buffer(
+ wlr_scene_buffer_from_node(node));
+ if (!scene_surface) continue;
+ surface = scene_surface->surface;
+ }
/* Walk the tree to find a node that knows the client */
for (pnode = node; pnode && !c; pnode = &pnode->parent->node)
c = pnode->data;
@@ -3113,7 +4070,7 @@ configurex11(struct wl_listener *listener, void *data)
if ((c->isfloating && c != grabc) || !c->mon->lt[c->mon->sellt]->arrange) {
resize(c, (struct wlr_box){.x = event->x - c->bw,
.y = event->y - c->bw, .width = event->width + c->bw * 2,
- .height = event->height + c->bw * 2}, 0);
+ .height = event->height + c->bw * 2}, 0, 1);
} else {
arrange(c->mon);
}
@@ -3159,10 +4116,10 @@ sethints(struct wl_listener *listener, void *data)
return;
c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints);
- printstatus();
+ drawbars();
if (c->isurgent && surface && surface->mapped)
- client_set_border_color(c, urgentcolor);
+ client_set_border_color(c, (float[])COLOR(colors[SchemeUrg][ColBorder]));
}
void
@@ -3186,10 +4143,13 @@ int
main(int argc, char *argv[])
{
char *startup_cmd = NULL;
+ uid_t uid = 0;
int c;
- while ((c = getopt(argc, argv, "s:hdv")) != -1) {
- if (c == 's')
+ while ((c = getopt(argc, argv, "u:s:hdv")) != -1) {
+ if (c == 'u')
+ uid = atoi(optarg);
+ else if (c == 's')
startup_cmd = optarg;
else if (c == 'd')
log_level = WLR_DEBUG;
@@ -3205,10 +4165,10 @@ main(int argc, char *argv[])
if (!getenv("XDG_RUNTIME_DIR"))
die("XDG_RUNTIME_DIR must be set");
setup();
- run(startup_cmd);
+ run(startup_cmd, uid);
cleanup();
return EXIT_SUCCESS;
usage:
- die("Usage: %s [-v] [-d] [-s startup command]", argv[0]);
+ die("Usage: %s [-v] [-u uid] [-d] [-s startup command]", argv[0]);
}