aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fbcon.c73
-rw-r--r--fbi.c8
-rw-r--r--fbpdf.c5
-rw-r--r--kbd.c23
-rw-r--r--kbd.h7
-rw-r--r--meson.build2
6 files changed, 67 insertions, 51 deletions
diff --git a/fbcon.c b/fbcon.c
index 78c47c4..b231984 100644
--- a/fbcon.c
+++ b/fbcon.c
@@ -30,6 +30,7 @@
#include "fbtools.h"
#include "drmtools.h"
#include "vt.h"
+#include "kbd.h"
#include "tmt.h"
/* ---------------------------------------------------------------------- */
@@ -123,31 +124,6 @@ static void console_switch_resume(void)
/* ---------------------------------------------------------------------- */
-static int open_restricted(const char *path, int flags, void *user_data)
-{
- int fd;
-
- fd = open(path, flags | O_CLOEXEC);
- if (fd < 0) {
- fprintf(stderr, "open %s: %s\n", path, strerror(errno));
- return fd;
- }
-
- ioctl(fd, EVIOCGRAB, 1);
- return fd;
-}
-
-static void close_restricted(int fd, void *user_data)
-{
- ioctl(fd, EVIOCGRAB, 0);
- close(fd);
-}
-
-static const struct libinput_interface interface = {
- .open_restricted = open_restricted,
- .close_restricted = close_restricted,
-};
-
const char *ansiseq[KEY_MAX] = {
[ KEY_UP ] = "\x1b[A",
[ KEY_DOWN ] = "\x1b[B",
@@ -330,6 +306,38 @@ static void tmt_callback(tmt_msg_t m, TMT *vt, const void *a, void *p)
}
}
+static void child_exec_shell(struct winsize *win)
+{
+ char lines[10], columns[10];
+
+ /* reset terminal */
+ fprintf(stderr, "\x1b[0m");
+
+ /* check for errors */
+ if (libinput_deverror != 0) {
+ fprintf(stderr, "ERROR: failed to open input devices (%d ok, %d failed)\n",
+ libinput_devcount, libinput_deverror);
+ return;
+ }
+
+#if 1
+ fprintf(stderr, "# \n");
+ fprintf(stderr, "# This is fbcon @%s, using %s-%d.\n",
+ seat_name, font_name, font_size);
+ fprintf(stderr, "# \n");
+#endif
+
+ /* prepare environment, run shell */
+ snprintf(lines, sizeof(lines), "%d", win->ws_row);
+ snprintf(columns, sizeof(columns), "%d", win->ws_col);
+ setenv("TERM", "ansi", true);
+ setenv("LINES", lines, true);
+ setenv("COLUMNS", columns, true);
+
+ execl("/bin/sh", "-sh", NULL);
+ fprintf(stderr, "failed to exec /bin/sh: %s\n", strerror(errno));
+}
+
int main(int argc, char *argv[])
{
struct udev_enumerate *uenum;
@@ -414,7 +422,7 @@ int main(int argc, char *argv[])
}
/* init libinput */
- kbd = libinput_udev_create_context(&interface, NULL, udev);
+ kbd = libinput_udev_create_context(&libinput_interface, NULL, udev);
libinput_udev_assign_seat(kbd, seat_name);
input = libinput_get_fd(kbd);
@@ -440,17 +448,10 @@ int main(int argc, char *argv[])
vt = tmt_open(win.ws_row, win.ws_col, tmt_callback, NULL, NULL);
child = forkpty(&pty, NULL, NULL, &win);
if (0 == child) {
- /* child */
- char lines[10], columns[10];
- snprintf(lines, sizeof(lines), "%d", win.ws_row);
- snprintf(columns, sizeof(columns), "%d", win.ws_col);
- setenv("TERM", "ansi", true);
- setenv("LINES", lines, true);
- setenv("COLUMNS", columns, true);
- execl("/bin/sh", "-sh", NULL);
- fprintf(stderr, "failed to exec /bin/sh: %s\n", strerror(errno));
+ child_exec_shell(&win);
+ /* only reached on errors ... */
sleep(3);
- exit(0);
+ exit(1);
}
/* parent */
diff --git a/fbi.c b/fbi.c
index 677ba25..37c2fcd 100644
--- a/fbi.c
+++ b/fbi.c
@@ -1357,8 +1357,14 @@ int main(int argc, char *argv[])
shadow_init(gfx);
extents = shadow_font_init(fontname);
- /* svga main loop */
kbd_init(use_libinput, gfx->devnum);
+ if (use_libinput && libinput_deverror != 0) {
+ fprintf(stderr, "ERROR: failed to open input devices (%d ok, %d failed)\n",
+ libinput_devcount, libinput_deverror);
+ cleanup_and_exit(0);
+ }
+
+ /* svga main loop */
desc = NULL;
info = NULL;
for (;;) {
diff --git a/fbpdf.c b/fbpdf.c
index dfde24d..58b4741 100644
--- a/fbpdf.c
+++ b/fbpdf.c
@@ -350,6 +350,11 @@ int main(int argc, char *argv[])
}
kbd_init(use_libinput, gfx->devnum);
+ if (use_libinput && libinput_deverror != 0) {
+ fprintf(stderr, "ERROR: failed to open input devices (%d ok, %d failed)\n",
+ libinput_devcount, libinput_deverror);
+ cleanup_and_exit(0);
+ }
index = 0;
newpage = true;
diff --git a/kbd.c b/kbd.c
index 1d74132..1b9ba69 100644
--- a/kbd.c
+++ b/kbd.c
@@ -9,9 +9,6 @@
#include <errno.h>
#include <termios.h>
-#include <libudev.h>
-#include <libinput.h>
-
#include "kbd.h"
/* ---------------------------------------------------------------------- */
@@ -195,7 +192,8 @@ static int file_wait(int fd, int timeout)
/* ---------------------------------------------------------------------- */
-static int devcount;
+int libinput_devcount;
+int libinput_deverror;
static int open_restricted(const char *path, int flags, void *user_data)
{
@@ -203,23 +201,25 @@ static int open_restricted(const char *path, int flags, void *user_data)
fd = open(path, flags | O_CLOEXEC);
if (fd < 0) {
- fprintf(stderr, "open %s: %s\n", path, strerror(errno));
+ fprintf(stderr, "kbd: open %s: %s\n", path, strerror(errno));
+ libinput_deverror++;
return fd;
}
- fprintf(stderr, "using %s\n", path);
+ fprintf(stderr, "kbd: using %s\n", path);
ioctl(fd, EVIOCGRAB, 1);
- devcount++;
+ libinput_devcount++;
return fd;
}
static void close_restricted(int fd, void *user_data)
{
+ libinput_devcount--;
ioctl(fd, EVIOCGRAB, 0);
close(fd);
}
-static const struct libinput_interface interface = {
+const struct libinput_interface libinput_interface = {
.open_restricted = open_restricted,
.close_restricted = close_restricted,
};
@@ -239,13 +239,10 @@ void kbd_init(int use_libinput, dev_t gfx)
seat = udev_device_get_property_value(ugfx, "ID_SEAT");
if (!seat)
seat = "seat0";
- ctx = libinput_udev_create_context(&interface, NULL, udev);
+ ctx = libinput_udev_create_context(&libinput_interface, NULL, udev);
libinput_udev_assign_seat(ctx, seat);
- if (devcount == 0) {
- fprintf(stderr, "WARNING: no input devices available\n");
- }
fprintf(stderr, "kbd: using libinput (%d devices, %s)\n",
- devcount, seat);
+ libinput_devcount, seat);
} else {
fprintf(stderr, "kbd: using stdin from terminal\n");
tty_raw();
diff --git a/kbd.h b/kbd.h
index 10aa12d..ad391f8 100644
--- a/kbd.h
+++ b/kbd.h
@@ -2,9 +2,16 @@
#include <inttypes.h>
#include <linux/input.h>
+#include <libudev.h>
+#include <libinput.h>
+
#define KEY_MOD_SHIFT (1 << 0)
#define KEY_MOD_CTRL (1 << 1)
+extern int libinput_devcount;
+extern int libinput_deverror;
+extern const struct libinput_interface libinput_interface;
+
void kbd_init(int use_libinput, dev_t gfx);
int kbd_wait(int timeout);
int kbd_read(char *buf, uint32_t len,
diff --git a/meson.build b/meson.build
index 4e4b620..c8967e3 100644
--- a/meson.build
+++ b/meson.build
@@ -127,7 +127,7 @@ executable('fbpdf',
install : true)
# build fbcon
-fbcon_srcs = [ 'fbcon.c', 'drmtools.c', 'fbtools.c', 'vt.c', 'tmt.c' ]
+fbcon_srcs = [ 'fbcon.c', 'drmtools.c', 'fbtools.c', 'vt.c', 'kbd.c', 'tmt.c' ]
fbcon_deps = [ drm_dep, cairo_dep, util_dep, udev_dep, input_dep, xkb_dep ]
executable('fbcon',