Add support for wlr_virtual_keyboard_v1 protocol

This commit is contained in:
DanyLE
2025-03-11 00:01:47 +01:00
parent 4a7219f03c
commit 9e53955336
4 changed files with 267 additions and 66 deletions

102
diyac.c
View File

@@ -4,6 +4,10 @@
#include <unistd.h>
#include <getopt.h>
#include <wlr/util/log.h>
#include <wait.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
#include "output.h"
#include "xdg.h"
#include "cursor.h"
@@ -11,30 +15,77 @@
#include "layer.h"
#include "session.h"
#define PROC_MON_TO 100
void help()
{
printf("Usage: diyac [-x] [startup command]\n");
printf("Options:\n");
printf(" -x exit with the session\n");
}
/**
* session process monitor
*/
static int session_monitor(void *data)
{
struct diyac_server *server = data;
int status;
pid_t pid;
if (server->session_pid > 0)
{
pid = waitpid(server->session_pid, &status, WNOHANG);
if (pid == -1)
{
wlr_log(WLR_ERROR, "session waitpid error: %s", strerror(errno));
// try to kill it
(void)kill(server->session_pid, SIGKILL);
}
else if (pid == 0)
{
wl_event_source_timer_update(server->proc_mon, PROC_MON_TO);
return 0;
}
server->session_pid = -1;
}
wl_display_terminate(server->wl_display);
return 0;
}
int main(int argc, char *argv[])
{
wlr_log_init(WLR_INFO, NULL);
char *startup_cmd = NULL;
int exit_with_session = 0;
int c;
while ((c = getopt(argc, argv, "s:h")) != -1)
while ((c = getopt(argc, argv, "xh")) != -1)
{
switch (c)
{
case 's':
startup_cmd = optarg;
case 'x':
exit_with_session = 1;
break;
default:
printf("Usage: %s [-s startup command]\n", argv[0]);
printf("Usage: %s [-s] startup command]\n", argv[0]);
return 0;
}
}
if (exit_with_session && optind == argc)
{
help();
return 1;
}
if (optind < argc)
{
printf("Usage: %s [-s startup command]\n", argv[0]);
return 0;
if(optind != argc - 1)
{
help();
return 1;
}
// the last argument is the startup command
startup_cmd = argv[optind];
}
struct diyac_server server = {0};
/* The Wayland display is managed by libwayland. It handles accepting
* clients from the Unix socket, manging Wayland globals, and so on. */
@@ -147,7 +198,7 @@ int main(int argc, char *argv[])
* pointer, touch, and drawing tablet device. We also rig up a listener to
* let us know when new input devices are available on the backend.
*/
wl_list_init(&server.seat.keyboards);
wl_list_init(&server.seat.inputs);
/* foreign toplevel manager for create shell panel for application control */
server.foreign_toplevel_manager = wlr_foreign_toplevel_manager_v1_create(server.wl_display);
diyac_init_seat(&server);
@@ -172,9 +223,11 @@ int main(int argc, char *argv[])
/* Set the WAYLAND_DISPLAY environment variable to our socket and run the
* startup command if requested. */
setenv("WAYLAND_DISPLAY", socket, true);
server.session_pid = -1;
if (startup_cmd)
{
if (fork() == 0)
server.session_pid = fork();
if (server.session_pid == 0)
{
execl("/bin/sh", "/bin/sh", "-c", startup_cmd, (void *)NULL);
}
@@ -185,14 +238,41 @@ int main(int argc, char *argv[])
* frame events at the refresh rate, and so on. */
wlr_log(WLR_INFO, "Running Wayland compositor on WAYLAND_DISPLAY=%s",
socket);
wl_display_run(server.wl_display);
server.proc_mon = NULL;
if( startup_cmd && exit_with_session)
{
if (server.session_pid == -1)
{
wlr_log(WLR_ERROR, "Cannot run startup command: %s. Exit", strerror(errno));
}
else
{
server.proc_mon = wl_event_loop_add_timer(server.wl_event_loop, session_monitor, &server);
wl_event_source_timer_update(server.proc_mon, PROC_MON_TO);
wl_display_run(server.wl_display);
}
}
else
{
wl_display_run(server.wl_display);
}
/* Once wl_display_run returns, we destroy all clients then shut down the
* server. */
if(server.proc_mon)
{
wl_event_source_remove(server.proc_mon);
}
wl_display_destroy_clients(server.wl_display);
wlr_scene_node_destroy(&server.scene->tree.node);
// wlr_scene_node_destroy(&server.scene->tree.node);
wlr_xcursor_manager_destroy(server.seat.cursor_mgr);
wlr_output_layout_destroy(server.output_layout);
wl_display_destroy(server.wl_display);
return 0;
}
/**
* @brief TODO
* reload configuration (keymap, etc.) when sighub is received
*
*/