mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-08-04 14:46:03 +00:00
Function to probe for Wayland compositor name
Maybe needed to workaround #8236
This commit is contained in:
parent
5335d183c1
commit
7346aca56d
2 changed files with 35 additions and 0 deletions
33
glfw/wl_init.c
vendored
33
glfw/wl_init.c
vendored
|
|
@ -668,6 +668,35 @@ GLFWAPI pid_t glfwWaylandCompositorPID(void) {
|
|||
return get_socket_peer_pid(fd);
|
||||
}
|
||||
|
||||
const char*
|
||||
_glfwWaylandCompositorName(void) {
|
||||
static bool probed = false;
|
||||
if (!probed) {
|
||||
probed = true;
|
||||
static const size_t sz = 1024;
|
||||
_glfw.wl.compositor_name = malloc(sz);
|
||||
if (!_glfw.wl.compositor_name) return "";
|
||||
char *ans = _glfw.wl.compositor_name; ans[0] = 0;
|
||||
pid_t cpid = glfwWaylandCompositorPID();
|
||||
if (cpid < 0) return ans;
|
||||
snprintf(ans, sz, "/proc/%d/cmdline", cpid);
|
||||
int fd = open(ans, O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
ans[0] = 0;
|
||||
} else {
|
||||
ssize_t n;
|
||||
while (true) {
|
||||
n = read(fd, ans, sz-1);
|
||||
if (n < 0 && errno == EINTR) continue;
|
||||
close(fd); break;
|
||||
}
|
||||
ans[n < 0 ? 0 : n] = 0;
|
||||
}
|
||||
}
|
||||
return _glfw.wl.compositor_name ? _glfw.wl.compositor_name : "";
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW platform API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -876,6 +905,10 @@ void _glfwPlatformTerminate(void)
|
|||
wl_display_disconnect(_glfw.wl.display);
|
||||
}
|
||||
finalizePollData(&_glfw.wl.eventLoopData);
|
||||
if (_glfw.wl.compositor_name) {
|
||||
free(_glfw.wl.compositor_name);
|
||||
_glfw.wl.compositor_name = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#define GLFW_LOOP_BACKEND wl
|
||||
|
|
|
|||
2
glfw/wl_platform.h
vendored
2
glfw/wl_platform.h
vendored
|
|
@ -389,6 +389,7 @@ typedef struct _GLFWlibraryWayland
|
|||
size_t dataOffersCounter;
|
||||
_GLFWWaylandDataOffer dataOffers[8];
|
||||
bool has_preferred_buffer_scale;
|
||||
char *compositor_name;
|
||||
} _GLFWlibraryWayland;
|
||||
|
||||
// Wayland-specific per-monitor data
|
||||
|
|
@ -432,6 +433,7 @@ int _glfwWaylandIntegerWindowScale(_GLFWwindow*);
|
|||
void animateCursorImage(id_type timer_id, void *data);
|
||||
struct wl_cursor* _glfwLoadCursor(GLFWCursorShape, struct wl_cursor_theme*);
|
||||
void destroy_data_offer(_GLFWWaylandDataOffer*);
|
||||
const char* _glfwWaylandCompositorName(void);
|
||||
|
||||
typedef struct wayland_cursor_shape {
|
||||
int which; const char *name;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue