Added debug functions that only work when the environment variable DWL_DEBUG is equal to 1
This commit is contained in:
parent
fd6c385b7f
commit
1c3001a2dc
|
@ -1,5 +1,5 @@
|
|||
[Desktop Entry]
|
||||
Name=dwl
|
||||
Comment=dwm for Wayland
|
||||
Exec=dwl
|
||||
Exec=session.pl
|
||||
Type=Application
|
|
@ -333,8 +333,10 @@ client_set_size(Client *c, uint32_t width, uint32_t height)
|
|||
{
|
||||
#ifdef XWAYLAND
|
||||
if (client_is_x11(c)) {
|
||||
debug_time(0.5);
|
||||
wlr_xwayland_surface_configure(c->surface.xwayland,
|
||||
c->geom.x, c->geom.y, width, height);
|
||||
debug_time(0.5);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -55,6 +55,7 @@ static const char *const autostart[] = {
|
|||
AS_SHCMD("org.flameshot.Flameshot"),
|
||||
AS_SHCMD("gammastep"),
|
||||
AS_SHCMD("swayidle -w before-sleep swaylock"),
|
||||
AS_SHCMD("konversation"),
|
||||
NULL /* end of list */
|
||||
};
|
||||
|
||||
|
@ -195,7 +196,7 @@ static const Key keys[] = {
|
|||
{ MODKEY, XKB_KEY_d, incnmaster, {.i = -1} },
|
||||
{ MODKEY, XKB_KEY_h, setmfact, {.f = -0.05} },
|
||||
{ MODKEY, XKB_KEY_l, setmfact, {.f = +0.05} },
|
||||
{ MODKEY, XKB_KEY_Return, zoom, {0} },
|
||||
{ MODKEY, XKB_KEY_e, zoom, {0} },
|
||||
{ MODKEY, XKB_KEY_Tab, view, {0} },
|
||||
{ MODKEY, XKB_KEY_c, killclient, {0} },
|
||||
{ MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[0]} },
|
||||
|
@ -233,7 +234,7 @@ static const Key keys[] = {
|
|||
|
||||
#define WEB_BROWSER "firefox"
|
||||
#define TERMINAL "terminator"
|
||||
#define FILE_MANAGER "thunar"
|
||||
#define FILE_MANAGER "pcmanfm-qt"
|
||||
#define TASK_MANAGER "qps"
|
||||
#define CALCULATOR "kcalc"
|
||||
/* mode modifier key function argument */
|
||||
|
|
114
src/dwl.c
114
src/dwl.c
|
@ -7,7 +7,11 @@
|
|||
#define WLR_USE_UNSTABLE
|
||||
#define XWAYLAND
|
||||
#define VERSION "0.5.1"
|
||||
|
||||
|
||||
|
||||
#include <getopt.h>
|
||||
#include <stdarg.h>
|
||||
#include <limits.h>
|
||||
#include <libinput.h>
|
||||
#include <linux/input-event-codes.h>
|
||||
|
@ -73,6 +77,17 @@
|
|||
#include "dwl-ipc-unstable-v2-protocol.h"
|
||||
#include "util.h"
|
||||
|
||||
/* debug */
|
||||
static FILE *debug_file = NULL;
|
||||
static bool debugEnabled = false;
|
||||
static float debug_started = 0.0f;
|
||||
static void debug_init();
|
||||
static float debug_get_current_time();
|
||||
static void _debug_printf(int line, const char *func, float time, const char *msg, ...);
|
||||
#define debug_printf(msg, args...) _debug_printf(__LINE__, __func__, debug_get_current_time(), msg, ##args);
|
||||
static void debug_time(float time); /* Starts a timer, and if that time has elapsed since it was last called. Raise SIGABRT */
|
||||
static float debug_last_time = 0.0f;
|
||||
|
||||
/* macros */
|
||||
#define MAX(A, B) ((A) > (B) ? (A) : (B))
|
||||
#define MIN(A, B) ((A) < (B) ? (A) : (B))
|
||||
|
@ -494,11 +509,73 @@ struct Pertag {
|
|||
const Layout *ltidxs[TAGCOUNT + 1][2]; /* matrix of tags and layouts indexes */
|
||||
};
|
||||
|
||||
/* debug implementations */
|
||||
float
|
||||
debug_get_current_time() {
|
||||
if(debugEnabled == true) {
|
||||
struct timespec tp;
|
||||
if(clock_gettime(CLOCK_MONOTONIC, &tp) != 0) {
|
||||
return(0);
|
||||
}
|
||||
return((((float)tp.tv_nsec/1000000000.0f)+tp.tv_sec)-debug_started);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
debug_time(float time) {
|
||||
if(debugEnabled == true) {
|
||||
if(debug_last_time == 0.0f) {
|
||||
debug_last_time = debug_get_current_time();
|
||||
} else {
|
||||
if(debug_get_current_time() > debug_last_time+time) {
|
||||
raise(SIGABRT);
|
||||
} else {
|
||||
debug_last_time = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void _debug_printf(int line, const char *func, float time, const char *msg, ...) {
|
||||
if(debugEnabled == true) {
|
||||
va_list args;
|
||||
va_start(args, msg);
|
||||
fprintf(debug_file, "[%.3fs] %s:%d : ", time, func, line);
|
||||
fprintf(debug_file, msg, args);
|
||||
fprintf(debug_file, "\n");
|
||||
va_end(args);
|
||||
fflush(debug_file);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
debug_init() {
|
||||
/* Check if the correct environment variable is set */
|
||||
if(getenv("DWL_DEBUG") != NULL) {
|
||||
if(strcmp(getenv("DWL_DEBUG"), "1") == 0) {
|
||||
debugEnabled = true;
|
||||
}
|
||||
/* Initialize the variables */
|
||||
if(debugEnabled == true) {
|
||||
struct timespec tp;
|
||||
clock_gettime(CLOCK_MONOTONIC, &tp);
|
||||
debug_started = ((float)tp.tv_nsec/1000000000)+tp.tv_sec;
|
||||
debug_file = fopen("debug.log", "w");
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* function implementations */
|
||||
|
||||
void
|
||||
applybounds(Client *c, struct wlr_box *bbox)
|
||||
{
|
||||
//debug_printf("Applying bounds.");
|
||||
/* set minimum possible */
|
||||
c->geom.width = MAX(1, c->geom.width);
|
||||
c->geom.height = MAX(1, c->geom.height);
|
||||
|
@ -511,10 +588,12 @@ applybounds(Client *c, struct wlr_box *bbox)
|
|||
c->geom.x = bbox->x;
|
||||
if (c->geom.y + c->geom.height + 2 * c->bw <= bbox->y)
|
||||
c->geom.y = bbox->y;
|
||||
//debug_printf("Done applying bounds.");
|
||||
}
|
||||
|
||||
void
|
||||
autostartexec(void) {
|
||||
debug_printf("Autostarting programs...");
|
||||
const char *const *p;
|
||||
size_t i = 0;
|
||||
|
||||
|
@ -524,14 +603,18 @@ autostartexec(void) {
|
|||
|
||||
autostart_pids = calloc(autostart_len, sizeof(pid_t));
|
||||
for (p = autostart; *p; i++, p++) {
|
||||
if(*p != NULL)
|
||||
debug_printf("Starting: %s", *p);
|
||||
|
||||
if ((autostart_pids[i] = fork()) == 0) {
|
||||
setsid();
|
||||
execvp(*p, (char *const *)p);
|
||||
die("dwl: execvp %s:", *p);
|
||||
}
|
||||
setsid();
|
||||
execvp(*p, (char *const *)p);
|
||||
die("dwl: execvp %s:", *p);
|
||||
}
|
||||
/* skip arguments */
|
||||
while (*++p);
|
||||
}
|
||||
debug_printf("Done autostarting programs.");
|
||||
}
|
||||
|
||||
|
||||
|
@ -549,7 +632,7 @@ applyrules(Client *c)
|
|||
appid = broken;
|
||||
if (!(title = client_get_title(c)))
|
||||
title = broken;
|
||||
|
||||
debug_printf("Applying Rules for %s", appid);
|
||||
for (r = rules; r < END(rules); r++) {
|
||||
if ((!r->title || strstr(title, r->title))
|
||||
&& (!r->id || strstr(appid, r->id))) {
|
||||
|
@ -572,6 +655,7 @@ applyrules(Client *c)
|
|||
}
|
||||
wlr_scene_node_reparent(&c->scene->node, layers[c->isfloating ? LyrFloat : LyrTile]);
|
||||
setmon(c, mon, newtags);
|
||||
debug_printf("Done applying rules for %s", appid);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -2568,12 +2652,14 @@ requestmonstate(struct wl_listener *listener, void *data)
|
|||
void
|
||||
resize(Client *c, struct wlr_box geo, int interact)
|
||||
{
|
||||
debug_printf("resize()");
|
||||
debug_printf("1");
|
||||
struct wlr_box *bbox = interact ? &sgeom : &c->mon->w;
|
||||
struct wlr_box clip;
|
||||
client_set_bounds(c, geo.width, geo.height);
|
||||
c->geom = geo;
|
||||
applybounds(c, bbox);
|
||||
|
||||
debug_printf("2");
|
||||
/* Update scene-graph, including borders */
|
||||
wlr_scene_node_set_position(&c->scene->node, c->geom.x, c->geom.y);
|
||||
wlr_scene_node_set_position(&c->scene_surface->node, c->bw, c->bw);
|
||||
|
@ -2584,12 +2670,13 @@ resize(Client *c, struct wlr_box geo, int interact)
|
|||
wlr_scene_node_set_position(&c->border[1]->node, 0, c->geom.height - c->bw);
|
||||
wlr_scene_node_set_position(&c->border[2]->node, 0, c->bw);
|
||||
wlr_scene_node_set_position(&c->border[3]->node, c->geom.width - c->bw, c->bw);
|
||||
|
||||
debug_printf("3");
|
||||
/* this is a no-op if size hasn't changed */
|
||||
c->resize = client_set_size(c, c->geom.width - 2 * c->bw,
|
||||
c->geom.height - 2 * c->bw);
|
||||
client_get_clip(c, &clip);
|
||||
wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip);
|
||||
debug_printf("resize() done.");
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -3508,6 +3595,7 @@ entermode(const Arg *arg)
|
|||
void
|
||||
activatex11(struct wl_listener *listener, void *data)
|
||||
{
|
||||
debug_printf("Activating x11");
|
||||
Client *c = wl_container_of(listener, c, activate);
|
||||
|
||||
/* Only "managed" windows can be activated */
|
||||
|
@ -3518,6 +3606,7 @@ activatex11(struct wl_listener *listener, void *data)
|
|||
void
|
||||
associatex11(struct wl_listener *listener, void *data)
|
||||
{
|
||||
debug_printf("associatex11()");
|
||||
Client *c = wl_container_of(listener, c, associate);
|
||||
|
||||
LISTEN(&client_surface(c)->events.map, &c->map, mapnotify);
|
||||
|
@ -3527,13 +3616,16 @@ associatex11(struct wl_listener *listener, void *data)
|
|||
void
|
||||
configurex11(struct wl_listener *listener, void *data)
|
||||
{
|
||||
debug_printf("configurex11()");
|
||||
Client *c = wl_container_of(listener, c, configure);
|
||||
struct wlr_xwayland_surface_configure_event *event = data;
|
||||
if (!c->mon)
|
||||
return;
|
||||
if (c->isfloating || c->type == X11Unmanaged)
|
||||
if (c->isfloating || c->type == X11Unmanaged) {
|
||||
debug_printf("Resizing X11 Window");
|
||||
resize(c, (struct wlr_box){.x = event->x, .y = event->y,
|
||||
.width = event->width, .height = event->height}, 0);
|
||||
}
|
||||
else
|
||||
arrange(c->mon);
|
||||
}
|
||||
|
@ -3541,6 +3633,7 @@ configurex11(struct wl_listener *listener, void *data)
|
|||
void
|
||||
createnotifyx11(struct wl_listener *listener, void *data)
|
||||
{
|
||||
debug_printf("createnotifyx11()");
|
||||
struct wlr_xwayland_surface *xsurface = data;
|
||||
Client *c;
|
||||
|
||||
|
@ -3569,6 +3662,7 @@ createnotifyx11(struct wl_listener *listener, void *data)
|
|||
void
|
||||
dissociatex11(struct wl_listener *listener, void *data)
|
||||
{
|
||||
debug_printf("dissociatex11()");
|
||||
Client *c = wl_container_of(listener, c, dissociate);
|
||||
wl_list_remove(&c->map.link);
|
||||
wl_list_remove(&c->unmap.link);
|
||||
|
@ -3577,6 +3671,7 @@ dissociatex11(struct wl_listener *listener, void *data)
|
|||
xcb_atom_t
|
||||
getatom(xcb_connection_t *xc, const char *name)
|
||||
{
|
||||
debug_printf("getatom()");
|
||||
xcb_atom_t atom = 0;
|
||||
xcb_intern_atom_reply_t *reply;
|
||||
xcb_intern_atom_cookie_t cookie = xcb_intern_atom(xc, 0, strlen(name), name);
|
||||
|
@ -3590,6 +3685,7 @@ getatom(xcb_connection_t *xc, const char *name)
|
|||
void
|
||||
sethints(struct wl_listener *listener, void *data)
|
||||
{
|
||||
debug_printf("sethints()");
|
||||
Client *c = wl_container_of(listener, c, set_hints);
|
||||
struct wlr_surface *surface = client_surface(c);
|
||||
if (c == focustop(selmon))
|
||||
|
@ -3606,6 +3702,7 @@ sethints(struct wl_listener *listener, void *data)
|
|||
void
|
||||
xwaylandready(struct wl_listener *listener, void *data)
|
||||
{
|
||||
debug_printf("xwaylandready()");
|
||||
struct wlr_xcursor *xcursor;
|
||||
xcb_connection_t *xc = xcb_connect(xwayland->display_name, NULL);
|
||||
int err = xcb_connection_has_error(xc);
|
||||
|
@ -3657,6 +3754,7 @@ main(int argc, char *argv[])
|
|||
/* Wayland requires XDG_RUNTIME_DIR for creating its communications socket */
|
||||
if (!getenv("XDG_RUNTIME_DIR"))
|
||||
die("XDG_RUNTIME_DIR must be set");
|
||||
debug_init();
|
||||
setup();
|
||||
run(startup_cmd);
|
||||
cleanup();
|
||||
|
|
Loading…
Reference in New Issue