diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2019-03-01 15:16:21 +0100 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2019-03-01 15:16:21 +0100 |
commit | 568029f176168fe9c0718b37767bc69587e92eca (patch) | |
tree | dcf5788c42d84e07fd5dac751492d30df9003b1d | |
parent | 40f389d427d46159d6ddd249f73fad59b507780e (diff) | |
download | fbida-568029f176168fe9c0718b37767bc69587e92eca.tar.gz |
logind support
-rw-r--r-- | fbcon.c | 19 | ||||
-rw-r--r-- | fbcon.desktop | 1 | ||||
-rw-r--r-- | fbida.spec | 1 | ||||
-rw-r--r-- | fbpdf.c | 2 | ||||
-rw-r--r-- | kbd.c | 136 | ||||
-rw-r--r-- | kbd.h | 5 | ||||
-rw-r--r-- | meson.build | 13 |
7 files changed, 167 insertions, 10 deletions
@@ -26,8 +26,8 @@ #include <cairo.h> #include <libudev.h> #include <libinput.h> -#include <xkbcommon/xkbcommon.h> #include <libtsm.h> +#include <xkbcommon/xkbcommon.h> #include "fbtools.h" #include "drmtools.h" @@ -36,10 +36,10 @@ /* ---------------------------------------------------------------------- */ -static char *seat_name = "seat0"; +static const char *seat_name = "seat0"; /* config */ -static char *font_name = "monospace"; +static const char *font_name = "monospace"; static int font_size = 16; static bool verbose; @@ -362,6 +362,9 @@ static void fbcon_cairo_update(const char *font_name, int font_size) fbcon_cairo_update_one(&state1, font_name, font_size); fbcon_cairo_update_one(&state2, font_name, font_size); cairo_font_extents(state1.context, &extents); + + /* underline quirk */ + extents.height++; } static void fbcon_winsize(struct winsize *win) @@ -506,6 +509,8 @@ static void fbcon_child_exec_shell(struct winsize *win) fprintf(stderr, "failed to exec /bin/sh: %s\n", strerror(errno)); } +/* ---------------------------------------------------------------------- */ + int main(int argc, char *argv[]) { struct udev_enumerate *uenum; @@ -513,12 +518,20 @@ int main(int argc, char *argv[]) struct winsize win; const char *drm_node = NULL; const char *fb_node = NULL; + const char *string; int input; pid_t child; setlocale(LC_ALL,""); fbcon_read_config(); + string = getenv("XDG_SEAT"); + if (string) + seat_name = string; + + if (getenv("XDG_SESSION_ID")) + logind_init(); + /* look for gfx devices */ udev = udev_new(); uenum = udev_enumerate_new(udev); diff --git a/fbcon.desktop b/fbcon.desktop index f8e7e6d..260dbe9 100644 --- a/fbcon.desktop +++ b/fbcon.desktop @@ -3,4 +3,3 @@ Name=text console Exec=/usr/bin/fbcon TryExec=/usr/bin/fbcon Type=Application -DesktopNames=fbcon @@ -40,6 +40,7 @@ BuildRequires: pkgconfig(xkbcommon) # fbcon BuildRequires: pkgconfig(libtsm) +BuildRequires: pkgconfig(libsystemd) %description fbida @@ -246,7 +246,7 @@ int main(int argc, char *argv[]) bool use_libinput; bool quit, newpage, pageflip; char cwd[1024]; - char uri[1024]; + char uri[1048]; char key[32]; uint32_t keycode, keymod; int index = 0; @@ -9,6 +9,13 @@ #include <errno.h> #include <termios.h> +#include <sys/stat.h> + +#include "config.h" +#ifdef HAVE_SYSTEMD +# include <systemd/sd-bus.h> +#endif + #include "kbd.h" /* ---------------------------------------------------------------------- */ @@ -192,6 +199,118 @@ static int file_wait(int fd, int timeout) /* ---------------------------------------------------------------------- */ +#ifdef HAVE_SYSTEMD + +static sd_bus *dbus = NULL; + +void logind_init(void) +{ + sd_bus_error error = SD_BUS_ERROR_NULL; + sd_bus_message *m = NULL; + int r; + + r = sd_bus_open_system(&dbus); + if (r < 0) { + fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-r)); + return; + } + + r = sd_bus_call_method(dbus, + "org.freedesktop.login1", + "/org/freedesktop/login1/session/self", + "org.freedesktop.login1.Session", + "TakeControl", + &error, + &m, + "b", + false); + if (r < 0) { + fprintf(stderr, "TakeControl failed: %s\n", error.message); + sd_bus_error_free(&error); + return; + } +} + +bool use_logind(void) +{ + return dbus != NULL; +} + +int logind_open(const char *path) +{ + sd_bus_error error = SD_BUS_ERROR_NULL; + sd_bus_message *m = NULL; + struct stat st; + unsigned int maj, min; + bool unused; + int handle, fd, r; + + r = stat(path, &st); + if (r < 0) { + fprintf(stderr, "stat %s failed: %s\n", path, strerror(errno)); + return -1; + } + + maj = major(st.st_rdev); + min = minor(st.st_rdev); + r = sd_bus_call_method(dbus, + "org.freedesktop.login1", + "/org/freedesktop/login1/session/self", + "org.freedesktop.login1.Session", + "TakeDevice", + &error, + &m, + "uu", + maj, + min); + if (r < 0) { + fprintf(stderr, "TakeDevice failed: %s\n", error.message); + sd_bus_error_free(&error); + return -1; + } + + r = sd_bus_message_read(m, "hb", &handle, &unused); + if (r < 0) { + fprintf(stderr, "Parse TakeDevice reply failed: %s\n", strerror(-r)); + fd = -1; + } + fd = dup(handle); + sd_bus_message_unref(m); + + return fd; +} + +void logind_close(int fd) +{ + /* FIXME */ +} + +#else + +void logind_init(void) +{ + fprintf(stderr, "warning: compiled without logind support.\n"); +} + +bool use_logind(void) +{ + return false; +} + +int logind_open(const char *path) +{ + errno = ENOSYS; + return -1; +} + +void logind_close(int fd) +{ +} + +#endif + +/* ---------------------------------------------------------------------- */ + int libinput_devcount; int libinput_deverror; @@ -199,6 +318,15 @@ static int open_restricted(const char *path, int flags, void *user_data) { int fd; + if (use_logind()) { + fd = logind_open(path); + if (fd < 0) + libinput_deverror++; + else + libinput_devcount++; + return fd; + } + fd = open(path, flags | O_CLOEXEC); if (fd < 0) { fprintf(stderr, "kbd: open %s: %s\n", path, strerror(errno)); @@ -214,9 +342,15 @@ static int open_restricted(const char *path, int flags, void *user_data) static void close_restricted(int fd, void *user_data) { - libinput_devcount--; + if (use_logind()) { + logind_close(fd); + libinput_devcount--; + return; + } + ioctl(fd, EVIOCGRAB, 0); close(fd); + libinput_devcount--; } const struct libinput_interface libinput_interface = { @@ -19,3 +19,8 @@ int kbd_read(char *buf, uint32_t len, void kbd_suspend(void); void kbd_resume(void); void kbd_fini(void); + +void logind_init(void); +bool use_logind(void); +int logind_open(const char *path); +void logind_close(int fd); diff --git a/meson.build b/meson.build index aa695f2..1505d6d 100644 --- a/meson.build +++ b/meson.build @@ -29,6 +29,7 @@ input_dep = dependency('libinput') xkb_dep = dependency('xkbcommon') glib_dep = dependency('glib-2.0') tsm_dep = dependency('libtsm', required : false) +systemd_dep = dependency('libsystemd', required : false, version : '>=221') # other library deps cc = meson.get_compiler('c') @@ -65,6 +66,9 @@ if webp_dep.found() read_srcs += 'rd/read-webp.c' config.set('HAVE_LIBWEBP', true) endif +if systemd_dep.found() + config.set('HAVE_SYSTEMD', true) +endif # jpeg transformation support jpeg_run = run_command('scripts/jpeg-version.sh') @@ -89,7 +93,7 @@ fbi_srcs = [ 'fbi.c', 'fb-gui.c', 'desktop.c', trans_src, read_srcs ] fbi_deps = [ drm_dep, pixman_dep, cairo_dep, exif_dep, image_deps, - math_dep, udev_dep, input_dep ] + math_dep, udev_dep, input_dep, systemd_dep ] executable('fbi', sources : fbi_srcs, @@ -121,7 +125,7 @@ fbpdf_srcs = [ 'fbpdf.c', 'parseconfig.c', 'fbiconfig.c', 'vt.c', 'kbd.c', 'fbtools.c', 'drmtools.c', 'gfx.c' ] fbpdf_deps = [ drm_dep, gbm_dep, epoxy_dep, pixman_dep, poppler_dep, cairo_dep, - udev_dep, input_dep ] + udev_dep, input_dep, systemd_dep ] executable('fbpdf', sources : fbpdf_srcs, @@ -130,7 +134,8 @@ executable('fbpdf', # build fbcon fbcon_srcs = [ 'fbcon.c', 'drmtools.c', 'fbtools.c', 'gfx.c', 'vt.c', 'kbd.c' ] -fbcon_deps = [ drm_dep, cairo_dep, util_dep, udev_dep, input_dep, xkb_dep, glib_dep, tsm_dep ] +fbcon_deps = [ drm_dep, cairo_dep, util_dep, udev_dep, input_dep, xkb_dep, glib_dep, + tsm_dep, systemd_dep ] if tsm_dep.found() executable('fbcon', @@ -144,7 +149,7 @@ endif # build kbdtest executable('kbdtest', sources : [ 'kbdtest.c', 'kbd.c' ], - dependencies : [ udev_dep, input_dep ] ) + dependencies : [ udev_dep, input_dep, systemd_dep ] ) # build ida mkfallback = find_program('scripts/fallback.pl') |