handle gpu resets

Fixes: https://codeberg.org/dwl/dwl/issues/601
This commit is contained in:
Leonardo Hernández Hernández 2024-05-03 11:03:18 -06:00
parent 57b5e41063
commit a8403d7b4d
No known key found for this signature in database
GPG Key ID: E538897EE11B9624

26
dwl.c
View File

@ -289,6 +289,7 @@ static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg); static void focusstack(const Arg *arg);
static Client *focustop(Monitor *m); static Client *focustop(Monitor *m);
static void fullscreennotify(struct wl_listener *listener, void *data); static void fullscreennotify(struct wl_listener *listener, void *data);
static void gpureset(struct wl_listener *listener, void *data);
static void handlesig(int signo); static void handlesig(int signo);
static void incnmaster(const Arg *arg); static void incnmaster(const Arg *arg);
static void inputdevice(struct wl_listener *listener, void *data); static void inputdevice(struct wl_listener *listener, void *data);
@ -1454,6 +1455,30 @@ fullscreennotify(struct wl_listener *listener, void *data)
setfullscreen(c, client_wants_fullscreen(c)); setfullscreen(c, client_wants_fullscreen(c));
} }
void
gpureset(struct wl_listener *listener, void *data)
{
struct wlr_renderer *old_drw = drw;
struct wlr_allocator *old_alloc = alloc;
struct Monitor *m;
if (!(drw = wlr_renderer_autocreate(backend)))
die("couldn't recreate renderer");
if (!(alloc = wlr_allocator_autocreate(backend, drw)))
die("couldn't recreate allocator");
LISTEN_STATIC(&drw->events.lost, gpureset);
wlr_compositor_set_renderer(compositor, drw);
wl_list_for_each(m, &mons, link) {
wlr_output_init_render(m->wlr_output, alloc, drw);
}
wlr_allocator_destroy(old_alloc);
wlr_renderer_destroy(old_drw);
}
void void
handlesig(int signo) handlesig(int signo)
{ {
@ -2394,6 +2419,7 @@ setup(void)
* supports for shared memory, this configures that for clients. */ * supports for shared memory, this configures that for clients. */
if (!(drw = wlr_renderer_autocreate(backend))) if (!(drw = wlr_renderer_autocreate(backend)))
die("couldn't create renderer"); die("couldn't create renderer");
LISTEN_STATIC(&drw->events.lost, gpureset);
/* Create shm, drm and linux_dmabuf interfaces by ourselves. /* Create shm, drm and linux_dmabuf interfaces by ourselves.
* The simplest way is call: * The simplest way is call: