diff --git a/hw/xfree86/common/seatd-libseat.h b/hw/xfree86/common/seatd-libseat.h index ad9b15be27..87ddfe787a 100644 --- a/hw/xfree86/common/seatd-libseat.h +++ b/hw/xfree86/common/seatd-libseat.h @@ -31,6 +31,18 @@ #include extern int seatd_libseat_init(Bool KeepTty_state); extern void seatd_libseat_fini(void); + +/** + * @brief seatd_libseat_open_graphics returns opened fd via rpc call through seatd + * @param path node path + * @warning this function returns <0 in case of error (for example -2) + * @return file descriptior or <0 + * + * @warning _X_EXPORT is only for internal consuption (currently for modesetting only, because its `open_hw` function calls open directly) + * + * @note XXX: maybe in future Xlibre public api could gain function for opening device nodes by path? + **/ +_X_EXPORT extern int seatd_libseat_open_graphics(const char *path); extern void seatd_libseat_open_device(InputInfoPtr p,int *fd,Bool *paus); extern void seatd_libseat_close_device(InputInfoPtr p); diff --git a/hw/xfree86/drivers/video/modesetting/driver.c b/hw/xfree86/drivers/video/modesetting/driver.c index 98e0f74b9d..da9a897e44 100644 --- a/hw/xfree86/drivers/video/modesetting/driver.c +++ b/hw/xfree86/drivers/video/modesetting/driver.c @@ -70,6 +70,11 @@ #ifdef XSERVER_LIBPCIACCESS #include #endif + +#ifdef SEATD_LIBSEAT +#include "seatd-libseat.h" +#endif + #include "driver.h" static void AdjustFrame(ScrnInfoPtr pScrn, int x, int y); @@ -240,17 +245,32 @@ open_hw(const char *dev) if ((fd = get_passed_fd()) != -1) return fd; - if (dev) + if (dev){ fd = open(dev, O_RDWR | O_CLOEXEC, 0); - else { + #ifdef SEATD_LIBSEAT + /* try to open dev node via libseat */ + if (fd == -1) { + fd = seatd_libseat_open_graphics(dev); + } + #endif + } else { dev = getenv("KMSDEVICE"); if ((NULL == dev) || ((fd = open(dev, O_RDWR | O_CLOEXEC, 0)) == -1)) { dev = "/dev/dri/card0"; fd = open(dev, O_RDWR | O_CLOEXEC, 0); + #ifdef SEATD_LIBSEAT + if (fd == -1){ + fd = seatd_libseat_open_graphics(dev); + } + #endif } } - if (fd == -1) + if (fd == -1) { xf86DrvMsg(-1, X_ERROR, "open %s: %s\n", dev, strerror(errno)); + } else if (fd < -1) { + xf86DrvMsg(-1, X_ERROR, "open %s: failed to open, tried seatd_libseat_open_graphics and opening node directly",dev); + fd = -1; + } return fd; }