diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..737cfae3 --- /dev/null +++ b/.clang-format @@ -0,0 +1,17 @@ +BasedOnStyle: LLVM +IndentWidth: 8 +UseTab: Always +BreakBeforeBraces: Linux +AllowShortIfStatementsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +IndentCaseLabels: false +ColumnLimit: 100 +ContinuationIndentWidth: 8 +IncludeCategories: + - Regex: '<.*>' + Priority: -1 + SortPriority: -1 + - Regex: '".*' + Priority: 0 + SortPriority: 0 + diff --git a/.github/workflows/meson.yml b/.github/workflows/meson.yml index 7856c3f9..b58d731b 100644 --- a/.github/workflows/meson.yml +++ b/.github/workflows/meson.yml @@ -7,6 +7,15 @@ on: branches: [ main ] jobs: + check-format: + name: Clang-format check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install clang-format + run: sudo apt-get update && sudo apt-get install -y clang-format-20 + - name: Check format + run: clang-format-20 -n --Werror src/*c src/*.h tests/*.c tests/*.h build: name: Ubuntu tests runs-on: ubuntu-latest @@ -23,7 +32,7 @@ jobs: - name: Compile and install libtsm env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - LIBTSM: "https://api.github.com/repos/Aetf/libtsm/releases/latest" + LIBTSM: "https://api.github.com/repos/kmscon/libtsm/releases/latest" run: | tar_url=$(curl -s --request GET --header "Authorization: Bearer $GH_TOKEN" --url $LIBTSM | jq -r .tarball_url) curl --request GET -s -L -o libtsm.tar.gz --header "Authorization: Bearer $GH_TOKEN" --url $tar_url diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index be026b88..00000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: release -on: - push: - # Enable when testing release infrastructure on a branch. - branches: - - release-* - tags: - - 'v[0-9]+.[0-9]+.[0-9]+' -jobs: - create-release: - name: create-release - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 - with: - python-version: '3.x' - - name: Install meson - run: pip install meson ninja - - name: Install dependencies - run: | - sudo apt-get install -y check libudev-dev libxkbcommon-dev libdrm-dev libgbm-dev libegl1-mesa-dev libgles-dev libpango1.0-dev libsystemd-dev - - name: Install libtsm - run: | - curl -L -o libtsm.tar.gz $(curl -s https://api.github.com/repos/Aetf/libtsm/releases/latest \ - | grep "tarball_url" \ - | awk '{ print $2 }' \ - | sed 's/,$//' \ - | sed 's/"//g' ) - mkdir libtsm - tar -xf libtsm.tar.gz -C libtsm --strip 1 - cd libtsm - meson setup build - cd build - meson compile - sudo meson install - - name: Meson setup - run: meson setup builddir/ - - name: Create source distribution - # no unit tests yet - run: meson dist -C builddir/ - - name: Create release note - run: tools/extract_release_note.py NEWS ${{ github.workspace }}-release-note.txt - - name: Upload Artifact - uses: actions/upload-artifact@v3 - with: - name: release-files - path: | - builddir/meson-dist/* - ${{ github.workspace }}-release-note.txt - - name: Release - uses: softprops/action-gh-release@v1 - # only actually create the release when run on tag - if: startsWith(github.ref, 'refs/tags/') - with: - files: builddir/meson-dist/* - body_path: ${{ github.workspace }}-release-note.txt diff --git a/NEWS b/NEWS index 04f76374..78f17250 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,52 @@ = KMSCON Release News = +## CHANGES WITH 9.2.1 + * Bug fixes: + - Remove release github workflow @kdj0c in https://github.com/kmscon/kmscon/pull/155 + - Fix kmscon version @kdj0c in https://github.com/kmscon/kmscon/pull/158 + +## CHANGES WITH 9.2.0 + * New features! + - Add kmscon-launch-gui to start gui from kmscon @kdj0c in https://github.com/Aetf/kmscon/pull/118 + - Add retry count and retry time to login program by @michael-oberpriller in https://github.com/Aetf/kmscon/pull/134 + - Add rotation support by @kdj0c in https://github.com/Aetf/kmscon/pull/147 + - Add mouse support by @kdj0c in https://github.com/Aetf/kmscon/pull/149 + - Double width overflow support by @michael-oberpriller in https://github.com/Aetf/kmscon/pull/135 + + * Bug fixes + - Fix build of conf.c with xkbcommon by @kdj0c in https://github.com/Aetf/kmscon/pull/116 + - Add basic CI for all pull request by @kdj0c in https://github.com/Aetf/kmscon/pull/117 + - github-ci: update package list before installing by @kdj0c in https://github.com/Aetf/kmscon/pull/119 + - Hide hardware cursor on vt switching by @michael-oberpriller in https://github.com/Aetf/kmscon/pull/123 + - Fix github CI, after renaming develop to main by @kdj0c in https://github.com/Aetf/kmscon/pull/127 + - Make sure the main thread gets SIGCHLD by @Vogtinator in https://github.com/Aetf/kmscon/pull/106 + - Revert hup workaround by @kdj0c in https://github.com/Aetf/kmscon/pull/126 + - Readme: add systemd-dev requirement on debian systems by @kdj0c in https://github.com/Aetf/kmscon/pull/128 + - Remove custom SELinux module by @Vogtinator in https://github.com/Aetf/kmscon/pull/130 + - Add a man-page for the kmscon.conf file. by @kdj0c in https://github.com/Aetf/kmscon/pull/131 + - Disable session-control when running with real VTs by @michael-oberpriller in https://github.com/Aetf/kmscon/pull/137 + - Pango: use font cache to check if the font overflows by @kdj0c in https://github.com/Aetf/kmscon/pull/141 + - Pango: align stride to 4 bytes by @kdj0c in https://github.com/Aetf/kmscon/pull/142 + - Update CI as libtsm has switched to meson by @kdj0c in https://github.com/Aetf/kmscon/pull/144 + - Fix character overflow with JetBrainsMono Nerd Font Mono by @kdj0c in https://github.com/Aetf/kmscon/pull/146 + - kmscon-launch-gui: don't use eval by @martinetd in https://github.com/Aetf/kmscon/pull/156 + - Add a default kmscon.conf in /etc by @kdj0c in https://github.com/Aetf/kmscon/pull/154 + - Build video_drm3d as a module by @kdj0c in https://github.com/Aetf/kmscon/pull/153 + - Fix kmscon using 100% CPU when trying to read systemd seats configuration by @kdj0c in https://github.com/Aetf/kmscon/pull/157 + - Set env variable KMS_START_SCRIPT and TERM_SESSION_TYPE by @kdj0c in https://github.com/Aetf/kmscon/pull/160 + - print backends by @kdj0c in https://github.com/Aetf/kmscon/pull/165 + - Remove the pixman renderer by @kdj0c in https://github.com/Aetf/kmscon/pull/163 + - Remove bblit renderer, and make bbulk built-ins by @kdj0c in https://github.com/Aetf/kmscon/pull/166 + - Update Readme.md after moving back to github/kmscon/kmscon by @kdj0c https://github.com/kmscon/kmscon/pull/152 + - Remove render timing by @kdj0c https://github.com/kmscon/kmscon/pull/153 + - Fix typo in README.md by @kdj0c https://github.com/kmscon/kmscon/pull/154 + +## New Contributors +- @martinetd made their first contribution in https://github.com/Aetf/kmscon/pull/156 + +**Full Changelog**: https://github.com/kmscon/kmscon/compare/v9.1.0...v9.2.0 + + CHANGES WITH 9.1.0: * New features! - Add selinux permissions (#109) diff --git a/README.md b/README.md index 4403091a..6e3347cf 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # KMSCON +![Build Status](https://github.com/kmscon/kmscon/actions/workflows/meson.yml/badge.svg?branch=main) + Kmscon is a simple terminal emulator based on linux kernel mode setting (KMS). It is an attempt to replace the in-kernel VT implementation with a userspace console. See kmscon(1) man-page for usage information. @@ -7,7 +9,7 @@ console. See kmscon(1) man-page for usage information. ## Requirements Kmscon requires the following software: - - [libtsm](https://github.com/Aetf/libtsm): terminal emulator state machine + - [libtsm](https://github.com/kmscon/libtsm): terminal emulator state machine - [libudev](https://www.freedesktop.org/software/systemd/man/libudev.html): providing input, video, etc. device hotplug support (>=v172) - [libxkbcommon](https://xkbcommon.org/): providing internationalized keyboard handling - [libdrm](https://gitlab.freedesktop.org/mesa/drm): graphics access to DRM/KMS subsystem @@ -35,7 +37,7 @@ sudo apt install systemd-dev ## Download -Released tarballs can be found at: https://github.com/Aetf/kmscon/releases +Released tarballs can be found at: https://github.com/kmscon/kmscon/releases ## Install @@ -91,7 +93,7 @@ See `man kmscon` for more information. ### Config file The default configuration file is `/etc/kmscon/kmscon.conf`. Any command line option can be put in the config file in -its long form without the leading `--` (double dash). See `man kmscon` for more information. +its long form without the leading `--` (double dash). See `man kmscon` for more information or look at [kmscon.conf](scripts/etc/kmscon.conf) ## License @@ -100,5 +102,4 @@ This software is licensed under the terms of an MIT-like license. Please see ## History -This is a personal fork from https://www.freedesktop.org/wiki/Software/kmscon, which hasn't been updated since 2014. - +This project was maintained in [Aetf's](https://github.com/Aetf/kmscon) fork for 11 years, before coming back here in 2025 diff --git a/docs/man/kmscon.1.xml.in b/docs/man/kmscon.1.xml.in index 435cc2b0..bfca457d 100644 --- a/docs/man/kmscon.1.xml.in +++ b/docs/man/kmscon.1.xml.in @@ -245,6 +245,14 @@ + + + + Send delete character when backspace is pressed. + (default: on) + + + @@ -331,7 +339,7 @@ - Enable mouse/touchpad/trackpoint in kmscon (default: off). + Enable mouse/touchpad/trackpoint in kmscon (default: on). It allows to select, and copy/paste text with a pointing device, and also to scroll with the mouse wheel. It's still experimental, and may not work with specific devices. @@ -467,6 +475,16 @@ (default: <Logo>Minus) + + + + Reboot the system when this keyboard shortcut is pressed. + This option is disabled by default (no default key binding). + Use with caution as the reboot is immediate without confirmation. + Example: --grab-reboot=<Ctrl><Alt>Delete + (default: disabled) + + Video Options: @@ -516,14 +534,6 @@ - - - - Display timing information of the render engines. This should - only be used to debug render engines. (default: off) - - - diff --git a/docs/man/kmscon.conf.1.xml.in b/docs/man/kmscon.conf.1.xml.in index 0a3005d5..40c1f6db 100644 --- a/docs/man/kmscon.conf.1.xml.in +++ b/docs/man/kmscon.conf.1.xml.in @@ -199,6 +199,13 @@ font-name=Ubuntu Mono + + + + Send delete character when backspace is pressed. (default: on) + + + @@ -266,7 +273,7 @@ font-name=Ubuntu Mono - Enable mouse/touchpad/trackpoint in kmscon (default: off). + Enable mouse/touchpad/trackpoint in kmscon (default: on). It allows to select, and copy/paste text with a pointing device, and also to scroll with the mouse wheel. It's still experimental, and may not work with specific devices. @@ -366,6 +373,17 @@ font-name=Ubuntu Mono + + + + Reboot the system when this keyboard shortcut is pressed. + This option is disabled by default. + Use with caution as the reboot is immediate. + Example: grab-reboot=<Ctrl><Alt>Delete + (default: disabled) + + + ### Video Options ### @@ -395,13 +413,6 @@ font-name=Ubuntu Mono - - - - Print renderer timing information. (default: off) - - - diff --git a/meson.build b/meson.build index f31a0b6b..0982cfbf 100644 --- a/meson.build +++ b/meson.build @@ -3,7 +3,7 @@ # SPDX-License-Identifier: MIT project('kmscon', 'c', - version: '9.1.0', + version: '9.2.1', license: 'MIT', # meson 0.58: f-string # meson 0.62: dependency libdl @@ -121,7 +121,6 @@ endforeach config.set('BUILD_ENABLE_DEBUG', get_option('extra_debug')) config.set_quoted('BUILD_MODULE_DIR', prefix / moduledir) config.set_quoted('BUILD_CONFIG_DIR', prefix / sysconfdir) -config.set10('BUILD_BACKSPACE_SENDS_DELETE', get_option('backspace_sends_delete')) # Make all files include "config.h" by default. This shouldn't cause any # problems and we cannot forget to include it anymore. @@ -161,7 +160,6 @@ summary({ 'extra_debug': get_option('extra_debug'), 'tests': get_option('tests'), 'docs': enable_docs, - 'backspace_sends_delete': get_option('backspace_sends_delete'), }, section: 'Miscellaneous') # diff --git a/meson.options b/meson.options index a0501d39..3fe77614 100644 --- a/meson.options +++ b/meson.options @@ -34,7 +34,3 @@ option('session_dummy', type: 'feature', value: 'auto', description: 'dummy session') option('session_terminal', type: 'feature', value: 'auto', description: 'terminal session') - -# terminal options -option('backspace_sends_delete', type: 'boolean', value: false, - description: 'backspace sends ASCII delete (0177) instead of ASCII backspace (010)') diff --git a/scripts/etc/kmscon.conf b/scripts/etc/kmscon.conf index a3d7aae9..c48f3dbd 100644 --- a/scripts/etc/kmscon.conf +++ b/scripts/etc/kmscon.conf @@ -79,6 +79,12 @@ ## value of the $TERM variable #term=kmscon +## Reset environment [on] +#reset-env + +## Send delete when backspace is pressed [on] +#backspace-delete + ## Scrollback buffer size, in lines #sb-size=10000 diff --git a/scripts/kmscon-launch-gui.sh b/scripts/kmscon-launch-gui.sh index 19c2d026..fa6e9419 100644 --- a/scripts/kmscon-launch-gui.sh +++ b/scripts/kmscon-launch-gui.sh @@ -1,33 +1,39 @@ #!/bin/sh if [ "$#" -eq 0 ]; then - echo "Usage: $0 argument" - exit 1 + echo "Usage: $0 argument" + exit 1 fi # Store current tty number -if [ -d /sys/class/tty/tty0 ]; then - kms_tty=$(cat /sys/class/tty/tty0/active) +kms_tty= +active_tty_file=/sys/class/tty/tty0/active +if [ -f "$active_tty_file" ]; then + read -r kms_tty < "$active_tty_file" fi -if [ "${TERM_PROGRAM}" != "tmux" ]; then - printf "\x1B]setBackground\a" -else - printf "\033Ptmux;\033\033]setBackground\a\033\\" -fi +case "${TERM_PROGRAM}" in +tmux) printf '\033Ptmux;\033\033]setBackground\a\033\\' ;; +*) printf '\033]setBackground\a' ;; +esac "$@" # If the current tty has changed, wait until the user switches back. if [ -n "${kms_tty}" ]; then - while [ "$(cat /sys/class/tty/tty0/active)" != "${kms_tty}" ]; do - sleep 1 - done -fi - -if [ "${TERM_PROGRAM}" != "tmux" ]; then - printf "\x1B]setForeground\a" -else - printf "\033Ptmux;\033\033]setForeground\a\033\\" + read -r check_kms_tty < "$active_tty_file" + while [ "${check_kms_tty}" != "${kms_tty}" ]; do + # use inotifywait if available, fallback to plain sleep + if command -v inotifywait > /dev/null; then + inotifywait -qqe modify "$active_tty_file" + else + sleep 1 + fi + read -r check_kms_tty < "$active_tty_file" + done fi +case "${TERM_PROGRAM}" in +tmux) printf '\033Ptmux;\033\033]setForeground\a\033\\' ;; +*) printf '\033]setForeground\a' ;; +esac diff --git a/scripts/systemd/kmscon.service.in b/scripts/systemd/kmscon.service.in index ad5600da..ee4ae460 100644 --- a/scripts/systemd/kmscon.service.in +++ b/scripts/systemd/kmscon.service.in @@ -6,7 +6,7 @@ After=systemd-user-sessions.service After=rc-local.service [Service] -ExecStart=@bindir@/kmscon --login -- /sbin/agetty -o '-p -- \\u' --noclear -- - +ExecStart=@bindir@/kmscon --login -- /sbin/agetty -o '-p -- \\u' --noclear -- - $$TERM [Install] WantedBy=multi-user.target diff --git a/scripts/systemd/kmsconvt@.service.in b/scripts/systemd/kmsconvt@.service.in index a496e261..b1e9c3ec 100644 --- a/scripts/systemd/kmsconvt@.service.in +++ b/scripts/systemd/kmsconvt@.service.in @@ -38,7 +38,7 @@ IgnoreOnIsolate=yes ConditionPathExists=/dev/tty0 [Service] -ExecStart=@bindir@/kmscon --vt=%I --seats=seat0 --no-switchvt --login -- /sbin/agetty -o '-p -- \\u' --noclear -- - +ExecStart=@bindir@/kmscon --vt=%I --seats=seat0 --no-switchvt --login -- /sbin/agetty -o '-p -- \\u' --noclear -- - $$TERM UtmpIdentifier=%I TTYPath=/dev/%I TTYReset=yes diff --git a/src/conf.c b/src/conf.c index 890e599a..8ee46a66 100644 --- a/src/conf.c +++ b/src/conf.c @@ -54,8 +54,7 @@ struct conf_ctx { void *mem; }; -int conf_ctx_new(struct conf_ctx **out, const struct conf_option *opts, - size_t onum, void *mem) +int conf_ctx_new(struct conf_ctx **out, const struct conf_option *opts, size_t onum, void *mem) { struct conf_ctx *ctx; size_t size; @@ -70,7 +69,7 @@ int conf_ctx_new(struct conf_ctx **out, const struct conf_option *opts, return -ENOMEM; } memset(ctx, 0, size); - ctx->opts = (void*)((char*)ctx + sizeof(*ctx)); + ctx->opts = (void *)((char *)ctx + sizeof(*ctx)); ctx->onum = onum; ctx->mem = mem; memcpy(ctx->opts, opts, onum * sizeof(*opts)); @@ -186,15 +185,13 @@ int conf_ctx_parse_argv(struct conf_ctx *ctx, int argc, char **argv) short_options = malloc(sizeof(char) * (ctx->onum + 1) * 2); if (!short_options) { - log_error("out of memory to parse cmd-line arguments (%d): %m", - errno); + log_error("out of memory to parse cmd-line arguments (%d): %m", errno); return -ENOMEM; } long_options = malloc(sizeof(struct option) * ctx->onum * 2); if (!long_options) { - log_error("out of memory to parse cmd-line arguments (%d): %m", - errno); + log_error("out of memory to parse cmd-line arguments (%d): %m", errno); free(short_options); return -ENOMEM; } @@ -212,8 +209,7 @@ int conf_ctx_parse_argv(struct conf_ctx *ctx, int argc, char **argv) if (ctx->opts[i].long_name) { /* skip the "no-" prefix */ opt->name = &ctx->opts[i].long_name[3]; - opt->has_arg = !!(ctx->opts[i].type->flags & - CONF_HAS_ARG); + opt->has_arg = !!(ctx->opts[i].type->flags & CONF_HAS_ARG); opt->flag = NULL; opt->val = 100000 + i; ++opt; @@ -232,24 +228,19 @@ int conf_ctx_parse_argv(struct conf_ctx *ctx, int argc, char **argv) opterr = 0; while (1) { - c = getopt_long(argc, argv, short_options, - long_options, NULL); + c = getopt_long(argc, argv, short_options, long_options, NULL); if (c <= 0) { break; } else if (c == ':') { - fprintf(stderr, "Missing argument for: %s\n", - argv[optind - 1]); + fprintf(stderr, "Missing argument for: %s\n", argv[optind - 1]); return -EFAULT; } else if (c == '?') { if (optopt && optopt < 100000) - fprintf(stderr, "Unknown argument: -%c\n", - optopt); + fprintf(stderr, "Unknown argument: -%c\n", optopt); else if (!optopt) - fprintf(stderr, "Unknown argument: %s\n", - argv[optind - 1]); + fprintf(stderr, "Unknown argument: %s\n", argv[optind - 1]); else - fprintf(stderr, "Option takes no arg: %s\n", - argv[optind - 1]); + fprintf(stderr, "Option takes no arg: %s\n", argv[optind - 1]); return -EFAULT; } else if (c < 100000) { for (i = 0; i < ctx->onum; ++i) { @@ -316,16 +307,14 @@ int conf_ctx_parse_argv(struct conf_ctx *ctx, int argc, char **argv) } if (optind < argc) { - fprintf(stderr, "Unparsed remaining args starting with: %s\n", - argv[optind]); + fprintf(stderr, "Unparsed remaining args starting with: %s\n", argv[optind]); return -EFAULT; } return 0; } -static int parse_kv_pair(struct conf_option *opts, size_t len, - const char *key, const char *value) +static int parse_kv_pair(struct conf_option *opts, size_t len, const char *key, const char *value) { unsigned int i; int ret; @@ -356,12 +345,10 @@ static int parse_kv_pair(struct conf_option *opts, size_t len, } if (opt->type->flags & CONF_HAS_ARG && !value) { - log_error("config option '%s' requires an argument", - key); + log_error("config option '%s' requires an argument", key); return -EFAULT; } else if (!(opt->type->flags & CONF_HAS_ARG) && value) { - log_error("config option '%s' does not take arguments", - key); + log_error("config option '%s' does not take arguments", key); return -EFAULT; } @@ -398,8 +385,7 @@ static void strip_spaces(char **buf) *tail-- = 0; } -static int parse_line(struct conf_option *opts, size_t olen, - char **buf, size_t *size) +static int parse_line(struct conf_option *opts, size_t olen, char **buf, size_t *size) { char *key; char *value = NULL; @@ -415,9 +401,7 @@ static int parse_line(struct conf_option *opts, size_t olen, key = line; while (len) { c = *line; - if (c == '\n' || - c == '#' || - c == '=') + if (c == '\n' || c == '#' || c == '=') break; ++line; --len; @@ -443,8 +427,7 @@ static int parse_line(struct conf_option *opts, size_t olen, value = line; while (len) { c = *line; - if (c == '\n' || - c == '#') + if (c == '\n' || c == '#') break; ++line; --len; @@ -474,7 +457,7 @@ static int parse_line(struct conf_option *opts, size_t olen, done: strip_spaces(&key); - + klen = strlen(key); if (klen > 0) { if (value) @@ -496,8 +479,7 @@ static int parse_line(struct conf_option *opts, size_t olen, return 0; } -static int parse_buffer(struct conf_option *opts, size_t len, - char *buf, size_t size) +static int parse_buffer(struct conf_option *opts, size_t len, char *buf, size_t size) { int ret = 0; struct conf_option *o; @@ -526,8 +508,7 @@ static int parse_buffer(struct conf_option *opts, size_t len, /* This reads the file at \path in memory and parses it as if it was given as * command line options. */ -static int conf_parse_file(struct conf_option *opts, size_t len, - const char *path) +static int conf_parse_file(struct conf_option *opts, size_t len, const char *path) { int fd, ret; size_t size, pos; @@ -559,7 +540,8 @@ static int conf_parse_file(struct conf_option *opts, size_t len, if (size - pos < CONF_BUFSIZE) { tmp = realloc(buf, size + CONF_BUFSIZE + 1); if (!tmp) { - log_error("cannot allocate enough memory to parse config file %s (%d): %m", + log_error("cannot allocate enough memory to parse config file %s " + "(%d): %m", path, errno); ret = -ENOMEM; goto out_free; @@ -570,8 +552,7 @@ static int conf_parse_file(struct conf_option *opts, size_t len, ret = read(fd, &buf[pos], CONF_BUFSIZE); if (ret < 0) { - log_error("cannot read from config file %s (%d): %m", - path, errno); + log_error("cannot read from config file %s (%d): %m", path, errno); ret = -EFAULT; goto out_free; } @@ -631,10 +612,10 @@ int conf_ctx_parse_file(struct conf_ctx *ctx, const char *format, ...) static void conf_free_value(struct conf_option *opt) { - if (*(void**)opt->mem) { - if (*(void**)opt->mem != opt->def) - free(*(void**)opt->mem); - *(void**)opt->mem = NULL; + if (*(void **)opt->mem) { + if (*(void **)opt->mem != opt->def) + free(*(void **)opt->mem); + *(void **)opt->mem = NULL; } } @@ -642,24 +623,23 @@ static void conf_free_value(struct conf_option *opt) static void conf_default_bool(struct conf_option *opt) { - *(bool*)opt->mem = (bool)opt->def; + *(bool *)opt->mem = (bool)opt->def; } static void conf_free_bool(struct conf_option *opt) { - *(bool*)opt->mem = false; + *(bool *)opt->mem = false; } static int conf_parse_bool(struct conf_option *opt, bool on, const char *arg) { - *(bool*)opt->mem = on; + *(bool *)opt->mem = on; return 0; } -static int conf_copy_bool(struct conf_option *opt, - const struct conf_option *src) +static int conf_copy_bool(struct conf_option *opt, const struct conf_option *src) { - *(bool*)opt->mem = *(bool*)src->mem; + *(bool *)opt->mem = *(bool *)src->mem; return 0; } @@ -675,24 +655,23 @@ const struct conf_type conf_bool = { static int conf_parse_int(struct conf_option *opt, bool on, const char *arg) { - *(int*)opt->mem = atoi(arg); + *(int *)opt->mem = atoi(arg); return 0; } static void conf_free_int(struct conf_option *opt) { - *(int*)opt->mem = 0; + *(int *)opt->mem = 0; } static void conf_default_int(struct conf_option *opt) { - *(int*)opt->mem = (int)(unsigned long)opt->def; + *(int *)opt->mem = (int)(unsigned long)opt->def; } -static int conf_copy_int(struct conf_option *opt, - const struct conf_option *src) +static int conf_copy_int(struct conf_option *opt, const struct conf_option *src) { - *(int*)opt->mem = *(int*)src->mem; + *(int *)opt->mem = *(int *)src->mem; return 0; } @@ -708,24 +687,23 @@ const struct conf_type conf_int = { static void conf_default_uint(struct conf_option *opt) { - *(unsigned int*)opt->mem = (unsigned int)(unsigned long)opt->def; + *(unsigned int *)opt->mem = (unsigned int)(unsigned long)opt->def; } static void conf_free_uint(struct conf_option *opt) { - *(unsigned int*)opt->mem = 0; + *(unsigned int *)opt->mem = 0; } static int conf_parse_uint(struct conf_option *opt, bool on, const char *arg) { - *(unsigned int*)opt->mem = atoi(arg); + *(unsigned int *)opt->mem = atoi(arg); return 0; } -static int conf_copy_uint(struct conf_option *opt, - const struct conf_option *src) +static int conf_copy_uint(struct conf_option *opt, const struct conf_option *src) { - *(unsigned int*)opt->mem = *(unsigned int*)src->mem; + *(unsigned int *)opt->mem = *(unsigned int *)src->mem; return 0; } @@ -742,7 +720,7 @@ const struct conf_type conf_uint = { static void conf_default_string(struct conf_option *opt) { opt->type->free(opt); - *(void**)opt->mem = opt->def; + *(void **)opt->mem = opt->def; } static int conf_parse_string(struct conf_option *opt, bool on, const char *arg) @@ -752,25 +730,24 @@ static int conf_parse_string(struct conf_option *opt, bool on, const char *arg) return -ENOMEM; opt->type->free(opt); - *(void**)opt->mem = val; + *(void **)opt->mem = val; return 0; } -static int conf_copy_string(struct conf_option *opt, - const struct conf_option *src) +static int conf_copy_string(struct conf_option *opt, const struct conf_option *src) { char *val; - if (!*(void**)src->mem) { + if (!*(void **)src->mem) { val = NULL; } else { - val = strdup(*(void**)src->mem); + val = strdup(*(void **)src->mem); if (!val) return -ENOMEM; } opt->type->free(opt); - *(void**)opt->mem = val; + *(void **)opt->mem = val; return 0; } @@ -787,11 +764,10 @@ const struct conf_type conf_string = { static void conf_default_string_list(struct conf_option *opt) { opt->type->free(opt); - *(void**)opt->mem = opt->def; + *(void **)opt->mem = opt->def; } -static int conf_parse_string_list(struct conf_option *opt, bool on, - const char *arg) +static int conf_parse_string_list(struct conf_option *opt, bool on, const char *arg) { int ret; char **list; @@ -801,26 +777,25 @@ static int conf_parse_string_list(struct conf_option *opt, bool on, return ret; opt->type->free(opt); - *(char***)opt->mem = list; + *(char ***)opt->mem = list; return 0; } -static int conf_copy_string_list(struct conf_option *opt, - const struct conf_option *src) +static int conf_copy_string_list(struct conf_option *opt, const struct conf_option *src) { int ret; char **t; - if (!(void***)src->mem) { + if (!(void ***)src->mem) { t = NULL; } else { - ret = shl_dup_array(&t, *(char***)src->mem); + ret = shl_dup_array(&t, *(char ***)src->mem); if (ret) return ret; } opt->type->free(opt); - *(char***)opt->mem = t; + *(char ***)opt->mem = t; return 0; } @@ -837,7 +812,7 @@ const struct conf_type conf_string_list = { static void conf_default_grab(struct conf_option *opt) { opt->type->free(opt); - *(void**)opt->mem = opt->def; + *(void **)opt->mem = opt->def; } static void conf_free_grab(struct conf_option *opt) @@ -845,8 +820,8 @@ static void conf_free_grab(struct conf_option *opt) struct conf_grab *grab; unsigned int i; - grab = *(void**)opt->mem; - *(void**)opt->mem = NULL; + grab = *(void **)opt->mem; + *(void **)opt->mem = NULL; if (!grab || grab == opt->def) return; @@ -860,8 +835,7 @@ static void conf_free_grab(struct conf_option *opt) free(grab); } -static int parse_single_grab(char *arg, unsigned int *mods, - uint32_t *keysym, bool allow_mods) +static int parse_single_grab(char *arg, unsigned int *mods, uint32_t *keysym, bool allow_mods) { char *tmp, *start, *end; char buf[128]; @@ -890,8 +864,7 @@ static int parse_single_grab(char *arg, unsigned int *mods, *mods |= SHL_SHIFT_MASK; } else if (!strcasecmp(start, "lock")) { *mods |= SHL_LOCK_MASK; - } else if (!strcasecmp(start, "control") || - !strcasecmp(start, "ctrl")) { + } else if (!strcasecmp(start, "control") || !strcasecmp(start, "ctrl")) { *mods |= SHL_CONTROL_MASK; } else if (!strcasecmp(start, "alt")) { *mods |= SHL_ALT_MASK; @@ -925,8 +898,7 @@ static int parse_single_grab(char *arg, unsigned int *mods, *keysym = xkb_keysym_from_name(start, 0); if (!*keysym) { - *keysym = xkb_keysym_from_name(start, - XKB_KEYSYM_CASE_INSENSITIVE); + *keysym = xkb_keysym_from_name(start, XKB_KEYSYM_CASE_INSENSITIVE); if (!*keysym) { log_error("invalid key '%s'", start); return -EFAULT; @@ -1001,12 +973,10 @@ static int conf_parse_grab(struct conf_option *opt, bool on, const char *arg) k = 0; for (j = 0; j < key_num; ++j) { - ret = parse_single_grab(keys[j], &grab->mods[l], - &grab->keysyms[l][k], + ret = parse_single_grab(keys[j], &grab->mods[l], &grab->keysyms[l][k], j == 0); if (ret < 0) { - log_error("cannot parse grab '%s' in '%s'", - list[i], arg); + log_error("cannot parse grab '%s' in '%s'", list[i], arg); free(keys); goto err_all; } @@ -1023,7 +993,7 @@ static int conf_parse_grab(struct conf_option *opt, bool on, const char *arg) free(list); opt->type->free(opt); - *(void**)opt->mem = grab; + *(void **)opt->mem = grab; return 0; err_all: @@ -1039,18 +1009,17 @@ static int conf_parse_grab(struct conf_option *opt, bool on, const char *arg) return ret; } -static int conf_copy_grab(struct conf_option *opt, - const struct conf_option *src) +static int conf_copy_grab(struct conf_option *opt, const struct conf_option *src) { struct conf_grab *grab, *s; int ret; unsigned int i; - s = *(void**)src->mem; + s = *(void **)src->mem; if (!s) { opt->type->free(opt); - *(void**)opt->mem = NULL; + *(void **)opt->mem = NULL; return 0; } @@ -1073,8 +1042,7 @@ static int conf_copy_grab(struct conf_option *opt, ret = -ENOMEM; goto err_grab; } - memcpy(grab->num_syms, s->num_syms, - sizeof(*grab->num_syms) * grab->num); + memcpy(grab->num_syms, s->num_syms, sizeof(*grab->num_syms) * grab->num); grab->keysyms = malloc(sizeof(*grab->keysyms) * grab->num); if (!grab->keysyms) { @@ -1085,18 +1053,16 @@ static int conf_copy_grab(struct conf_option *opt, } for (i = 0; i < grab->num; ++i) { - grab->keysyms[i] = malloc(sizeof(*s->keysyms[i]) * - s->num_syms[i]); + grab->keysyms[i] = malloc(sizeof(*s->keysyms[i]) * s->num_syms[i]); if (!grab->keysyms[i]) { ret = -ENOMEM; goto err_all; } - memcpy(grab->keysyms[i], s->keysyms[i], - sizeof(*s->keysyms[i]) * s->num_syms[i]); + memcpy(grab->keysyms[i], s->keysyms[i], sizeof(*s->keysyms[i]) * s->num_syms[i]); } opt->type->free(opt); - *(void**)opt->mem = grab; + *(void **)opt->mem = grab; return 0; err_all: diff --git a/src/conf.h b/src/conf.h index 0f24ce49..c1a40d04 100644 --- a/src/conf.h +++ b/src/conf.h @@ -44,14 +44,14 @@ struct conf_ctx; /* Conf Types */ -#define CONF_HAS_ARG 0x0001 +#define CONF_HAS_ARG 0x0001 struct conf_type { unsigned int flags; - void (*set_default) (struct conf_option *opt); - void (*free) (struct conf_option *opt); - int (*parse) (struct conf_option *opt, bool on, const char *arg); - int (*copy) (struct conf_option *opt, const struct conf_option *src); + void (*set_default)(struct conf_option *opt); + void (*free)(struct conf_option *opt); + int (*parse)(struct conf_option *opt, bool on, const char *arg); + int (*copy)(struct conf_option *opt, const struct conf_option *src); }; /* @@ -107,21 +107,19 @@ struct conf_grab { uint32_t **keysyms; }; -static inline bool conf_grab_matches(const struct conf_grab *grab, - unsigned int ev_mods, - unsigned int ev_num_syms, - const uint32_t *ev_syms) +static inline bool conf_grab_matches(const struct conf_grab *grab, unsigned int ev_mods, + unsigned int ev_num_syms, const uint32_t *ev_syms) { - return shl_grab_has_match(ev_mods, ev_num_syms, ev_syms, - grab->num, grab->mods, grab->num_syms, - grab->keysyms); + return shl_grab_has_match(ev_mods, ev_num_syms, ev_syms, grab->num, grab->mods, + grab->num_syms, grab->keysyms); } -#define CONF_SINGLE_GRAB(_mods, _sym) { \ - .num = 1, \ - .mods = (unsigned int[]) { (_mods) }, \ - .num_syms = (unsigned int[]) { 1 }, \ - .keysyms = (uint32_t*[]) { (uint32_t[]) { (_sym) } }, \ +#define CONF_SINGLE_GRAB(_mods, _sym) \ + { \ + .num = 1, \ + .mods = (unsigned int[]){(_mods)}, \ + .num_syms = (unsigned int[]){1}, \ + .keysyms = (uint32_t *[]){(uint32_t[]){(_sym)}}, \ } /* @@ -134,8 +132,7 @@ static inline bool conf_grab_matches(const struct conf_grab *grab, struct conf_ctx; -int conf_ctx_new(struct conf_ctx **out, const struct conf_option *opts, - size_t onum, void *mem); +int conf_ctx_new(struct conf_ctx **out, const struct conf_option *opts, size_t onum, void *mem); void conf_ctx_free(struct conf_ctx *ctx); void conf_ctx_reset(struct conf_ctx *ctx); void *conf_ctx_get_mem(struct conf_ctx *ctx); @@ -151,52 +148,54 @@ int conf_ctx_parse_file(struct conf_ctx *ctx, const char *format, ...); * this structure. */ -#define CONF_LOCKED 0x0001 +#define CONF_LOCKED 0x0001 struct conf_option { unsigned int flags; char short_name; const char *long_name; const struct conf_type *type; - int (*aftercheck) (struct conf_option *opt, int argc, - char **argv, int idx); - int (*copy) (struct conf_option *opt, const struct conf_option *src); - int (*file) (struct conf_option *opt, bool on, const char *arg); + int (*aftercheck)(struct conf_option *opt, int argc, char **argv, int idx); + int (*copy)(struct conf_option *opt, const struct conf_option *src); + int (*file)(struct conf_option *opt, bool on, const char *arg); void *mem; void *def; }; -#define CONF_OPTION(_flags, _short, _long, _type, _aftercheck, _copy, _file, _mem, _def) \ - { _flags, _short, "no-" _long, _type, _aftercheck, _copy, _file, _mem, _def } +#define CONF_OPTION(_flags, _short, _long, _type, _aftercheck, _copy, _file, _mem, _def) \ + {_flags, _short, "no-" _long, _type, _aftercheck, _copy, _file, _mem, _def} -#define CONF_OPTION_BOOL_FULL(_short, _long, _aftercheck, _copy, _file, _mem, _def) \ - CONF_OPTION(0, _short, _long, &conf_bool, _aftercheck, _copy, _file, _mem, (void*)(long)_def) -#define CONF_OPTION_BOOL(_short, _long, _mem, _def) \ +#define CONF_OPTION_BOOL_FULL(_short, _long, _aftercheck, _copy, _file, _mem, _def) \ + CONF_OPTION(0, _short, _long, &conf_bool, _aftercheck, _copy, _file, _mem, \ + (void *)(long)_def) +#define CONF_OPTION_BOOL(_short, _long, _mem, _def) \ CONF_OPTION_BOOL_FULL(_short, _long, NULL, NULL, NULL, _mem, _def) -#define CONF_OPTION_INT_FULL(_short, _long, _aftercheck, _copy, _file, _mem, _def) \ - CONF_OPTION(0, _short, _long, &conf_int, _aftercheck, _copy, _file, _mem, (void*)(long)_def) -#define CONF_OPTION_INT(_short, _long, _mem, _def) \ +#define CONF_OPTION_INT_FULL(_short, _long, _aftercheck, _copy, _file, _mem, _def) \ + CONF_OPTION(0, _short, _long, &conf_int, _aftercheck, _copy, _file, _mem, \ + (void *)(long)_def) +#define CONF_OPTION_INT(_short, _long, _mem, _def) \ CONF_OPTION_INT_FULL(_short, _long, NULL, NULL, NULL, _mem, _def) -#define CONF_OPTION_UINT_FULL(_short, _long, _aftercheck, _copy, _file, _mem, _def) \ - CONF_OPTION(0, _short, _long, &conf_uint, _aftercheck, _copy, _file, _mem, (void*)(unsigned long)_def) -#define CONF_OPTION_UINT(_short, _long, _mem, _def) \ +#define CONF_OPTION_UINT_FULL(_short, _long, _aftercheck, _copy, _file, _mem, _def) \ + CONF_OPTION(0, _short, _long, &conf_uint, _aftercheck, _copy, _file, _mem, \ + (void *)(unsigned long)_def) +#define CONF_OPTION_UINT(_short, _long, _mem, _def) \ CONF_OPTION_UINT_FULL(_short, _long, NULL, NULL, NULL, _mem, _def) -#define CONF_OPTION_STRING_FULL(_short, _long, _aftercheck, _copy, _file, _mem, _def) \ +#define CONF_OPTION_STRING_FULL(_short, _long, _aftercheck, _copy, _file, _mem, _def) \ CONF_OPTION(0, _short, _long, &conf_string, _aftercheck, _copy, _file, _mem, _def) -#define CONF_OPTION_STRING(_short, _long, _mem, _def) \ +#define CONF_OPTION_STRING(_short, _long, _mem, _def) \ CONF_OPTION_STRING_FULL(_short, _long, NULL, NULL, NULL, _mem, _def) -#define CONF_OPTION_STRING_LIST_FULL(_short, _long, _aftercheck, _copy, _file, _mem, _def) \ +#define CONF_OPTION_STRING_LIST_FULL(_short, _long, _aftercheck, _copy, _file, _mem, _def) \ CONF_OPTION(0, _short, _long, &conf_string_list, _aftercheck, _copy, _file, _mem, _def) -#define CONF_OPTION_STRING_LIST(_short, _long, _mem, _def) \ +#define CONF_OPTION_STRING_LIST(_short, _long, _mem, _def) \ CONF_OPTION_STRING_LIST_FULL(_short, _long, NULL, NULL, NULL, _mem, _def) -#define CONF_OPTION_GRAB_FULL(_short, _long, _aftercheck, _copy, _file, _mem, _def) \ +#define CONF_OPTION_GRAB_FULL(_short, _long, _aftercheck, _copy, _file, _mem, _def) \ CONF_OPTION(0, _short, _long, &conf_grab, _aftercheck, _copy, _file, _mem, _def) -#define CONF_OPTION_GRAB(_short, _long, _mem, _def) \ +#define CONF_OPTION_GRAB(_short, _long, _mem, _def) \ CONF_OPTION_GRAB_FULL(_short, _long, NULL, NULL, NULL, _mem, _def) #endif /* CONF_CONF_H */ diff --git a/src/eloop.c b/src/eloop.c index b3f4a910..337f210d 100644 --- a/src/eloop.c +++ b/src/eloop.c @@ -329,8 +329,7 @@ struct ev_signal_shared { * can use signalfd only. */ -static void sig_child(struct ev_eloop *loop, struct signalfd_siginfo *info, - void *data) +static void sig_child(struct ev_eloop *loop, struct signalfd_siginfo *info, void *data) { pid_t pid; int status; @@ -346,14 +345,12 @@ static void sig_child(struct ev_eloop *loop, struct signalfd_siginfo *info, break; } else if (WIFEXITED(status)) { if (WEXITSTATUS(status) != 0) - llog_debug(loop, "child %d exited with status %d", - pid, WEXITSTATUS(status)); + llog_debug(loop, "child %d exited with status %d", pid, + WEXITSTATUS(status)); else - llog_debug(loop, "child %d exited successfully", - pid); + llog_debug(loop, "child %d exited successfully", pid); } else if (WIFSIGNALED(status)) { - llog_debug(loop, "child %d exited by signal %d", pid, - WTERMSIG(status)); + llog_debug(loop, "child %d exited by signal %d", pid, WTERMSIG(status)); } d.pid = pid; @@ -391,8 +388,7 @@ static void shared_signal_cb(struct ev_fd *fd, int mask, void *data) * * Returns: 0 on success, otherwise negative error code */ -static int signal_new(struct ev_signal_shared **out, struct ev_eloop *loop, - int signum) +static int signal_new(struct ev_signal_shared **out, struct ev_eloop *loop, int signum) { sigset_t mask; int ret, fd; @@ -421,8 +417,7 @@ static int signal_new(struct ev_signal_shared **out, struct ev_eloop *loop, goto err_hook; } - ret = ev_eloop_new_fd(loop, &sig->fd, fd, EV_READABLE, - shared_signal_cb, sig); + ret = ev_eloop_new_fd(loop, &sig->fd, fd, EV_READABLE, shared_signal_cb, sig); if (ret) goto err_sig; @@ -507,8 +502,7 @@ static void eloop_event(struct ev_fd *fd, int mask, void *data) llog_warn(eloop, "HUP/ERR on eloop source"); } -static int write_eventfd(llog_submit_t llog, void *llog_data, int fd, - uint64_t val) +static int write_eventfd(llog_submit_t llog, void *llog_data, int fd, uint64_t val) { int ret; @@ -516,25 +510,22 @@ static int write_eventfd(llog_submit_t llog, void *llog_data, int fd, return llog_dEINVAL(llog, llog_data); if (val == 0xffffffffffffffffULL) { - llog_dwarning(llog, llog_data, - "increasing counter with invalid value %" PRIu64, + llog_dwarning(llog, llog_data, "increasing counter with invalid value %" PRIu64, val); - return -EINVAL;; + return -EINVAL; + ; } ret = write(fd, &val, sizeof(val)); if (ret < 0) { if (errno == EAGAIN) - llog_dwarning(llog, llog_data, - "eventfd overflow while writing %" PRIu64, + llog_dwarning(llog, llog_data, "eventfd overflow while writing %" PRIu64, val); else - llog_dwarning(llog, llog_data, - "eventfd write error (%d): %m", errno); + llog_dwarning(llog, llog_data, "eventfd write error (%d): %m", errno); return -EFAULT; } else if (ret != sizeof(val)) { - llog_dwarning(llog, llog_data, - "wrote %d bytes instead of 8 to eventdfd", ret); + llog_dwarning(llog, llog_data, "wrote %d bytes instead of 8 to eventdfd", ret); return -EFAULT; } @@ -557,22 +548,19 @@ static void eloop_idle_event(struct ev_eloop *loop, unsigned int mask) ret = read(loop->idle_fd, &val, sizeof(val)); if (ret < 0) { if (errno != EAGAIN) { - llog_warning(loop, "reading eventfd failed (%d): %m", - errno); + llog_warning(loop, "reading eventfd failed (%d): %m", errno); goto err_out; } } else if (ret == 0) { llog_warning(loop, "EOF on eventfd"); goto err_out; } else if (ret != sizeof(val)) { - llog_warning(loop, "read %d bytes instead of 8 on eventfd", - ret); + llog_warning(loop, "read %d bytes instead of 8 on eventfd", ret); goto err_out; } else if (val > 0) { shl_hook_call(loop->idlers, loop, NULL); if (shl_hook_num(loop->idlers) > 0) - write_eventfd(loop->llog, loop->llog_data, - loop->idle_fd, 1); + write_eventfd(loop->llog, loop->llog_data, loop->idle_fd, 1); } return; @@ -580,8 +568,8 @@ static void eloop_idle_event(struct ev_eloop *loop, unsigned int mask) err_out: ret = epoll_ctl(loop->efd, EPOLL_CTL_DEL, loop->idle_fd, NULL); if (ret) - llog_warning(loop, "cannot remove fd %d from epollset (%d): %m", - loop->idle_fd, errno); + llog_warning(loop, "cannot remove fd %d from epollset (%d): %m", loop->idle_fd, + errno); } /** @@ -616,8 +604,7 @@ int ev_eloop_new(struct ev_eloop **out, ev_log_t log, void *log_data) shl_dlist_init(&loop->sig_list); loop->cur_fds_size = 32; - loop->cur_fds = malloc(sizeof(struct epoll_event) * - loop->cur_fds_size); + loop->cur_fds = malloc(sizeof(struct epoll_event) * loop->cur_fds_size); if (!loop->cur_fds) { ret = llog_ENOMEM(loop); goto err_free; @@ -646,8 +633,8 @@ int ev_eloop_new(struct ev_eloop **out, ev_log_t log, void *log_data) goto err_posts; } - ret = ev_fd_new(&loop->fd, loop->efd, EV_READABLE, eloop_event, loop, - loop->llog, loop->llog_data); + ret = ev_fd_new(&loop->fd, loop->efd, EV_READABLE, eloop_event, loop, loop->llog, + loop->llog_data); if (ret) goto err_close; @@ -664,8 +651,7 @@ int ev_eloop_new(struct ev_eloop **out, ev_log_t log, void *log_data) ret = epoll_ctl(loop->efd, EPOLL_CTL_ADD, loop->idle_fd, &ep); if (ret) { - llog_warning(loop, "cannot add fd %d to epoll set (%d): %m", - loop->idle_fd, errno); + llog_warning(loop, "cannot add fd %d to epoll set (%d): %m", loop->idle_fd, errno); ret = -EFAULT; goto err_idle_fd; } @@ -738,16 +724,14 @@ void ev_eloop_unref(struct ev_eloop *loop) ev_eloop_unregister_signal_cb(loop, SIGCHLD, sig_child, loop); while (loop->sig_list.next != &loop->sig_list) { - sig = shl_dlist_entry(loop->sig_list.next, - struct ev_signal_shared, - list); + sig = shl_dlist_entry(loop->sig_list.next, struct ev_signal_shared, list); signal_free(sig); } ret = epoll_ctl(loop->efd, EPOLL_CTL_DEL, loop->idle_fd, NULL); if (ret) - llog_warning(loop, "cannot remove fd %d from epollset (%d): %m", - loop->idle_fd, errno); + llog_warning(loop, "cannot remove fd %d from epollset (%d): %m", loop->idle_fd, + errno); close(loop->idle_fd); ev_fd_unref(loop->fd); @@ -840,10 +824,7 @@ int ev_eloop_dispatch(struct ev_eloop *loop, int timeout) shl_hook_call(loop->pres, loop, NULL); - count = epoll_wait(loop->efd, - loop->cur_fds, - loop->cur_fds_size, - timeout); + count = epoll_wait(loop->efd, loop->cur_fds, loop->cur_fds_size, timeout); if (count < 0) { if (errno == EINTR) { ret = 0; @@ -875,11 +856,10 @@ int ev_eloop_dispatch(struct ev_eloop *loop, int timeout) } if (count == loop->cur_fds_size) { - ep = realloc(loop->cur_fds, sizeof(struct epoll_event) * - loop->cur_fds_size * 2); + ep = realloc(loop->cur_fds, sizeof(struct epoll_event) * loop->cur_fds_size * 2); if (!ep) { llog_warning(loop, "cannot reallocate dispatch cache to size %zu", - loop->cur_fds_size * 2); + loop->cur_fds_size * 2); } else { loop->cur_fds = ep; loop->cur_fds_size *= 2; @@ -1113,8 +1093,8 @@ void ev_eloop_rm_eloop(struct ev_eloop *rm) * Returns: 0 on success, otherwise negative error code */ SHL_EXPORT -int ev_fd_new(struct ev_fd **out, int rfd, int mask, ev_fd_cb cb, void *data, - ev_log_t log, void *log_data) +int ev_fd_new(struct ev_fd **out, int rfd, int mask, ev_fd_cb cb, void *data, ev_log_t log, + void *log_data) { struct ev_fd *fd; @@ -1195,8 +1175,7 @@ static int fd_epoll_add(struct ev_fd *fd) ret = epoll_ctl(fd->loop->efd, EPOLL_CTL_ADD, fd->fd, &ep); if (ret) { - llog_warning(fd, "cannot add fd %d to epoll set (%d): %m", - fd->fd, errno); + llog_warning(fd, "cannot add fd %d to epoll set (%d): %m", fd->fd, errno); return -EFAULT; } @@ -1212,8 +1191,7 @@ static void fd_epoll_remove(struct ev_fd *fd) ret = epoll_ctl(fd->loop->efd, EPOLL_CTL_DEL, fd->fd, NULL); if (ret && errno != EBADF) - llog_warning(fd, "cannot remove fd %d from epoll set (%d): %m", - fd->fd, errno); + llog_warning(fd, "cannot remove fd %d from epoll set (%d): %m", fd->fd, errno); } static int fd_epoll_update(struct ev_fd *fd) @@ -1233,10 +1211,9 @@ static int fd_epoll_update(struct ev_fd *fd) ep.events |= EPOLLET; ep.data.ptr = fd; - ret = epoll_ctl(fd->loop->efd, EPOLL_CTL_MOD, fd->fd, &ep); + ret = epoll_ctl(fd->loop->efd, EPOLL_CTL_MOD, fd->fd, &ep); if (ret) { - llog_warning(fd, "cannot update epoll fd %d (%d): %m", - fd->fd, errno); + llog_warning(fd, "cannot update epoll fd %d (%d): %m", fd->fd, errno); return -EFAULT; } @@ -1388,8 +1365,8 @@ int ev_fd_update(struct ev_fd *fd, int mask) * Returns: 0 on success, otherwise negative error code */ SHL_EXPORT -int ev_eloop_new_fd(struct ev_eloop *loop, struct ev_fd **out, int rfd, - int mask, ev_fd_cb cb, void *data) +int ev_eloop_new_fd(struct ev_eloop *loop, struct ev_fd **out, int rfd, int mask, ev_fd_cb cb, + void *data) { struct ev_fd *fd; int ret; @@ -1514,8 +1491,7 @@ static int timer_drain(struct ev_timer *timer, uint64_t *out) if (errno == EAGAIN) { return 0; } else { - llog_warning(timer, "cannot read timerfd (%d): %m", - errno); + llog_warning(timer, "cannot read timerfd (%d): %m", errno); return errno; } } else if (len == 0) { @@ -1578,8 +1554,8 @@ static const struct itimerspec ev_timer_zero; * Returns: 0 on success, negative error on failure */ SHL_EXPORT -int ev_timer_new(struct ev_timer **out, const struct itimerspec *spec, - ev_timer_cb cb, void *data, ev_log_t log, void *log_data) +int ev_timer_new(struct ev_timer **out, const struct itimerspec *spec, ev_timer_cb cb, void *data, + ev_log_t log, void *log_data) { struct ev_timer *timer; int ret; @@ -1615,8 +1591,8 @@ int ev_timer_new(struct ev_timer **out, const struct itimerspec *spec, goto err_close; } - ret = ev_fd_new(&timer->efd, timer->fd, EV_READABLE, timer_cb, timer, - timer->llog, timer->llog_data); + ret = ev_fd_new(&timer->efd, timer->fd, EV_READABLE, timer_cb, timer, timer->llog, + timer->llog_data); if (ret) goto err_close; @@ -1817,9 +1793,8 @@ int ev_timer_drain(struct ev_timer *timer, uint64_t *expirations) * Returns: 0 on success, negative error code on failure. */ SHL_EXPORT -int ev_eloop_new_timer(struct ev_eloop *loop, struct ev_timer **out, - const struct itimerspec *spec, ev_timer_cb cb, - void *data) +int ev_eloop_new_timer(struct ev_eloop *loop, struct ev_timer **out, const struct itimerspec *spec, + ev_timer_cb cb, void *data) { struct ev_timer *timer; int ret; @@ -1959,8 +1934,8 @@ static void counter_event(struct ev_fd *fd, int mask, void *data) * Returns: 0 on success, negative error code on failure. */ SHL_EXPORT -int ev_counter_new(struct ev_counter **out, ev_counter_cb cb, void *data, - ev_log_t log, void *log_data) +int ev_counter_new(struct ev_counter **out, ev_counter_cb cb, void *data, ev_log_t log, + void *log_data) { struct ev_counter *cnt; int ret; @@ -1985,8 +1960,8 @@ int ev_counter_new(struct ev_counter **out, ev_counter_cb cb, void *data, goto err_free; } - ret = ev_fd_new(&cnt->efd, cnt->fd, EV_READABLE, counter_event, cnt, - cnt->llog, cnt->llog_data); + ret = ev_fd_new(&cnt->efd, cnt->fd, EV_READABLE, counter_event, cnt, cnt->llog, + cnt->llog_data); if (ret) goto err_close; @@ -2111,8 +2086,7 @@ bool ev_counter_is_bound(struct ev_counter *cnt) * object. */ SHL_EXPORT -void ev_counter_set_cb_data(struct ev_counter *cnt, ev_counter_cb cb, - void *data) +void ev_counter_set_cb_data(struct ev_counter *cnt, ev_counter_cb cb, void *data) { if (!cnt) return; @@ -2151,8 +2125,8 @@ int ev_counter_inc(struct ev_counter *cnt, uint64_t val) * Returns: 0 on success, negative error code on failure. */ SHL_EXPORT -int ev_eloop_new_counter(struct ev_eloop *eloop, struct ev_counter **out, - ev_counter_cb cb, void *data) +int ev_eloop_new_counter(struct ev_eloop *eloop, struct ev_counter **out, ev_counter_cb cb, + void *data) { int ret; struct ev_counter *cnt; @@ -2245,8 +2219,8 @@ void ev_eloop_rm_counter(struct ev_counter *cnt) * Returns: 0 on success, negative error code on failure. */ SHL_EXPORT -int ev_eloop_register_signal_cb(struct ev_eloop *loop, int signum, - ev_signal_shared_cb cb, void *data) +int ev_eloop_register_signal_cb(struct ev_eloop *loop, int signum, ev_signal_shared_cb cb, + void *data) { struct ev_signal_shared *sig = NULL; int ret; @@ -2257,7 +2231,8 @@ int ev_eloop_register_signal_cb(struct ev_eloop *loop, int signum, if (signum < 0 || !cb) return llog_EINVAL(loop); - shl_dlist_for_each(iter, &loop->sig_list) { + shl_dlist_for_each(iter, &loop->sig_list) + { sig = shl_dlist_entry(iter, struct ev_signal_shared, list); if (sig->signum == signum) break; @@ -2292,8 +2267,8 @@ int ev_eloop_register_signal_cb(struct ev_eloop *loop, int signum, * removed. It doesn't matter which callback is removed as both are identical. */ SHL_EXPORT -void ev_eloop_unregister_signal_cb(struct ev_eloop *loop, int signum, - ev_signal_shared_cb cb, void *data) +void ev_eloop_unregister_signal_cb(struct ev_eloop *loop, int signum, ev_signal_shared_cb cb, + void *data) { struct ev_signal_shared *sig; struct shl_dlist *iter; @@ -2301,7 +2276,8 @@ void ev_eloop_unregister_signal_cb(struct ev_eloop *loop, int signum, if (!loop) return; - shl_dlist_for_each(iter, &loop->sig_list) { + shl_dlist_for_each(iter, &loop->sig_list) + { sig = shl_dlist_entry(iter, struct ev_signal_shared, list); if (sig->signum == signum) { shl_hook_rm_cast(sig->hook, cb, data); @@ -2323,8 +2299,7 @@ void ev_eloop_unregister_signal_cb(struct ev_eloop *loop, int signum, */ SHL_EXPORT -int ev_eloop_register_child_cb(struct ev_eloop *loop, ev_child_cb cb, - void *data) +int ev_eloop_register_child_cb(struct ev_eloop *loop, ev_child_cb cb, void *data) { int ret; bool empty; @@ -2338,8 +2313,7 @@ int ev_eloop_register_child_cb(struct ev_eloop *loop, ev_child_cb cb, return ret; if (empty) { - ret = ev_eloop_register_signal_cb(loop, SIGCHLD, sig_child, - loop); + ret = ev_eloop_register_signal_cb(loop, SIGCHLD, sig_child, loop); if (ret) { shl_hook_rm_cast(loop->chlds, cb, data); return ret; @@ -2350,8 +2324,7 @@ int ev_eloop_register_child_cb(struct ev_eloop *loop, ev_child_cb cb, } SHL_EXPORT -void ev_eloop_unregister_child_cb(struct ev_eloop *loop, ev_child_cb cb, - void *data) +void ev_eloop_unregister_child_cb(struct ev_eloop *loop, ev_child_cb cb, void *data) { if (!loop || !shl_hook_num(loop->chlds)) return; @@ -2382,8 +2355,7 @@ void ev_eloop_unregister_child_cb(struct ev_eloop *loop, ev_child_cb cb, * Returns: 0 on success, negative error code on failure. */ SHL_EXPORT -int ev_eloop_register_idle_cb(struct ev_eloop *eloop, ev_idle_cb cb, - void *data, unsigned int flags) +int ev_eloop_register_idle_cb(struct ev_eloop *eloop, ev_idle_cb cb, void *data, unsigned int flags) { int ret; bool os = flags & EV_ONESHOT; @@ -2422,8 +2394,8 @@ int ev_eloop_register_idle_cb(struct ev_eloop *eloop, ev_idle_cb cb, * they are identical. */ SHL_EXPORT -void ev_eloop_unregister_idle_cb(struct ev_eloop *eloop, ev_idle_cb cb, - void *data, unsigned int flags) +void ev_eloop_unregister_idle_cb(struct ev_eloop *eloop, ev_idle_cb cb, void *data, + unsigned int flags) { if (!eloop || (flags & ~EV_IDLE_ALL)) return; @@ -2455,8 +2427,7 @@ void ev_eloop_unregister_idle_cb(struct ev_eloop *eloop, ev_idle_cb cb, * Returns: 0 on success, negative error code on failure. */ SHL_EXPORT -int ev_eloop_register_pre_cb(struct ev_eloop *eloop, ev_idle_cb cb, - void *data) +int ev_eloop_register_pre_cb(struct ev_eloop *eloop, ev_idle_cb cb, void *data) { if (!eloop) return -EINVAL; @@ -2476,8 +2447,7 @@ int ev_eloop_register_pre_cb(struct ev_eloop *eloop, ev_idle_cb cb, * they are identical. */ SHL_EXPORT -void ev_eloop_unregister_pre_cb(struct ev_eloop *eloop, ev_idle_cb cb, - void *data) +void ev_eloop_unregister_pre_cb(struct ev_eloop *eloop, ev_idle_cb cb, void *data) { if (!eloop) return; @@ -2506,8 +2476,7 @@ void ev_eloop_unregister_pre_cb(struct ev_eloop *eloop, ev_idle_cb cb, * Returns: 0 on success, negative error code on failure. */ SHL_EXPORT -int ev_eloop_register_post_cb(struct ev_eloop *eloop, ev_idle_cb cb, - void *data) +int ev_eloop_register_post_cb(struct ev_eloop *eloop, ev_idle_cb cb, void *data) { if (!eloop) return -EINVAL; @@ -2527,8 +2496,7 @@ int ev_eloop_register_post_cb(struct ev_eloop *eloop, ev_idle_cb cb, * they are identical. */ SHL_EXPORT -void ev_eloop_unregister_post_cb(struct ev_eloop *eloop, ev_idle_cb cb, - void *data) +void ev_eloop_unregister_post_cb(struct ev_eloop *eloop, ev_idle_cb cb, void *data) { if (!eloop) return; diff --git a/src/eloop.h b/src/eloop.h index 92cb91f5..c0e0c14c 100644 --- a/src/eloop.h +++ b/src/eloop.h @@ -61,14 +61,8 @@ struct ev_counter; * This is the type of a logging callback function. You can always pass NULL * instead of such a function to disable logging. */ -typedef void (*ev_log_t) (void *data, - const char *file, - int line, - const char *func, - const char *subs, - unsigned int sev, - const char *format, - va_list args); +typedef void (*ev_log_t)(void *data, const char *file, int line, const char *func, const char *subs, + unsigned int sev, const char *format, va_list args); /** * ev_fd_cb: @@ -78,7 +72,7 @@ typedef void (*ev_log_t) (void *data, * * This is the callback-type for file-descriptor event sources. */ -typedef void (*ev_fd_cb) (struct ev_fd *fd, int mask, void *data); +typedef void (*ev_fd_cb)(struct ev_fd *fd, int mask, void *data); /** * ev_timer_cb: @@ -89,8 +83,7 @@ typedef void (*ev_fd_cb) (struct ev_fd *fd, int mask, void *data); * This is the callback-type for timer event sources. If the process was too * busy to be woken up as fast as possible, then @num may be bigger than 1. */ -typedef void (*ev_timer_cb) - (struct ev_timer *timer, uint64_t num, void *data); +typedef void (*ev_timer_cb)(struct ev_timer *timer, uint64_t num, void *data); /** * ev_counter_cb: @@ -102,8 +95,7 @@ typedef void (*ev_timer_cb) * may be bigger if the timer was increased multiple times or by bigger values. * The counter is reset to 0 before this callback is called. */ -typedef void (*ev_counter_cb) - (struct ev_counter *cnt, uint64_t num, void *data); +typedef void (*ev_counter_cb)(struct ev_counter *cnt, uint64_t num, void *data); /** * ev_signal_shared_cb: @@ -113,8 +105,8 @@ typedef void (*ev_counter_cb) * * This is the callback-type for shared signal events. */ -typedef void (*ev_signal_shared_cb) - (struct ev_eloop *eloop, struct signalfd_siginfo *info, void *data); +typedef void (*ev_signal_shared_cb)(struct ev_eloop *eloop, struct signalfd_siginfo *info, + void *data); /** * ev_child_data: @@ -137,8 +129,7 @@ struct ev_child_data { * * This is the callback-type for child-reaper events. */ -typedef void (*ev_child_cb) - (struct ev_eloop *eloop, struct ev_child_data *chld, void *data); +typedef void (*ev_child_cb)(struct ev_eloop *eloop, struct ev_child_data *chld, void *data); /** * ev_idle_cb: @@ -148,7 +139,7 @@ typedef void (*ev_child_cb) * * This is the callback-type for idle-source events. */ -typedef void (*ev_idle_cb) (struct ev_eloop *eloop, void *unused, void *data); +typedef void (*ev_idle_cb)(struct ev_eloop *eloop, void *unused, void *data); /** * ev_eloop_flags: @@ -190,8 +181,8 @@ void ev_eloop_rm_eloop(struct ev_eloop *rm); /* fd sources */ -int ev_fd_new(struct ev_fd **out, int fd, int mask, ev_fd_cb cb, void *data, - ev_log_t log, void *log_data); +int ev_fd_new(struct ev_fd **out, int fd, int mask, ev_fd_cb cb, void *data, ev_log_t log, + void *log_data); void ev_fd_ref(struct ev_fd *fd); void ev_fd_unref(struct ev_fd *fd); @@ -202,15 +193,15 @@ bool ev_fd_is_bound(struct ev_fd *fd); void ev_fd_set_cb_data(struct ev_fd *fd, ev_fd_cb cb, void *data); int ev_fd_update(struct ev_fd *fd, int mask); -int ev_eloop_new_fd(struct ev_eloop *loop, struct ev_fd **out, int rfd, - int mask, ev_fd_cb cb, void *data); +int ev_eloop_new_fd(struct ev_eloop *loop, struct ev_fd **out, int rfd, int mask, ev_fd_cb cb, + void *data); int ev_eloop_add_fd(struct ev_eloop *loop, struct ev_fd *fd); void ev_eloop_rm_fd(struct ev_fd *fd); /* timer sources */ -int ev_timer_new(struct ev_timer **out, const struct itimerspec *spec, - ev_timer_cb cb, void *data, ev_log_t log, void *log_data); +int ev_timer_new(struct ev_timer **out, const struct itimerspec *spec, ev_timer_cb cb, void *data, + ev_log_t log, void *log_data); void ev_timer_ref(struct ev_timer *timer); void ev_timer_unref(struct ev_timer *timer); @@ -222,16 +213,15 @@ void ev_timer_set_cb_data(struct ev_timer *timer, ev_timer_cb cb, void *data); int ev_timer_update(struct ev_timer *timer, const struct itimerspec *spec); int ev_timer_drain(struct ev_timer *timer, uint64_t *expirations); -int ev_eloop_new_timer(struct ev_eloop *loop, struct ev_timer **out, - const struct itimerspec *spec, ev_timer_cb cb, - void *data); +int ev_eloop_new_timer(struct ev_eloop *loop, struct ev_timer **out, const struct itimerspec *spec, + ev_timer_cb cb, void *data); int ev_eloop_add_timer(struct ev_eloop *loop, struct ev_timer *timer); void ev_eloop_rm_timer(struct ev_timer *timer); /* counter sources */ -int ev_counter_new(struct ev_counter **out, ev_counter_cb, void *data, - ev_log_t log, void *log_data); +int ev_counter_new(struct ev_counter **out, ev_counter_cb, void *data, ev_log_t log, + void *log_data); void ev_counter_ref(struct ev_counter *cnt); void ev_counter_unref(struct ev_counter *cnt); @@ -239,55 +229,48 @@ int ev_counter_enable(struct ev_counter *cnt); void ev_counter_disable(struct ev_counter *cnt); bool ev_counter_is_enabled(struct ev_counter *cnt); bool ev_counter_is_bound(struct ev_counter *cnt); -void ev_counter_set_cb_data(struct ev_counter *cnt, ev_counter_cb cb, - void *data); +void ev_counter_set_cb_data(struct ev_counter *cnt, ev_counter_cb cb, void *data); int ev_counter_inc(struct ev_counter *cnt, uint64_t val); -int ev_eloop_new_counter(struct ev_eloop *eloop, struct ev_counter **out, - ev_counter_cb cb, void *data); +int ev_eloop_new_counter(struct ev_eloop *eloop, struct ev_counter **out, ev_counter_cb cb, + void *data); int ev_eloop_add_counter(struct ev_eloop *eloop, struct ev_counter *cnt); void ev_eloop_rm_counter(struct ev_counter *cnt); /* signal sources */ -int ev_eloop_register_signal_cb(struct ev_eloop *loop, int signum, - ev_signal_shared_cb cb, void *data); -void ev_eloop_unregister_signal_cb(struct ev_eloop *loop, int signum, - ev_signal_shared_cb cb, void *data); +int ev_eloop_register_signal_cb(struct ev_eloop *loop, int signum, ev_signal_shared_cb cb, + void *data); +void ev_eloop_unregister_signal_cb(struct ev_eloop *loop, int signum, ev_signal_shared_cb cb, + void *data); /* child reaper sources */ -int ev_eloop_register_child_cb(struct ev_eloop *loop, ev_child_cb cb, - void *data); -void ev_eloop_unregister_child_cb(struct ev_eloop *loop, ev_child_cb cb, - void *data); +int ev_eloop_register_child_cb(struct ev_eloop *loop, ev_child_cb cb, void *data); +void ev_eloop_unregister_child_cb(struct ev_eloop *loop, ev_child_cb cb, void *data); /* idle sources */ enum ev_idle_flags { - EV_NORMAL = 0x00, - EV_ONESHOT = 0x01, - EV_SINGLE = 0x02, - EV_IDLE_ALL = EV_ONESHOT | EV_SINGLE, + EV_NORMAL = 0x00, + EV_ONESHOT = 0x01, + EV_SINGLE = 0x02, + EV_IDLE_ALL = EV_ONESHOT | EV_SINGLE, }; -int ev_eloop_register_idle_cb(struct ev_eloop *eloop, ev_idle_cb cb, - void *data, unsigned int flags); -void ev_eloop_unregister_idle_cb(struct ev_eloop *eloop, ev_idle_cb cb, - void *data, unsigned int flags); +int ev_eloop_register_idle_cb(struct ev_eloop *eloop, ev_idle_cb cb, void *data, + unsigned int flags); +void ev_eloop_unregister_idle_cb(struct ev_eloop *eloop, ev_idle_cb cb, void *data, + unsigned int flags); /* pre dispatch callbacks */ -int ev_eloop_register_pre_cb(struct ev_eloop *eloop, ev_idle_cb cb, - void *data); -void ev_eloop_unregister_pre_cb(struct ev_eloop *eloop, ev_idle_cb cb, - void *data); +int ev_eloop_register_pre_cb(struct ev_eloop *eloop, ev_idle_cb cb, void *data); +void ev_eloop_unregister_pre_cb(struct ev_eloop *eloop, ev_idle_cb cb, void *data); /* post dispatch callbacks */ -int ev_eloop_register_post_cb(struct ev_eloop *eloop, ev_idle_cb cb, - void *data); -void ev_eloop_unregister_post_cb(struct ev_eloop *eloop, ev_idle_cb cb, - void *data); +int ev_eloop_register_post_cb(struct ev_eloop *eloop, ev_idle_cb cb, void *data); +void ev_eloop_unregister_post_cb(struct ev_eloop *eloop, ev_idle_cb cb, void *data); #endif /* EV_ELOOP_H */ diff --git a/src/font.c b/src/font.c index cb7de85f..977f0ff9 100644 --- a/src/font.c +++ b/src/font.c @@ -57,10 +57,10 @@ #include #include #include "font.h" -#include "shl_module.h" #include "shl_dlist.h" #include "shl_log.h" #include "shl_misc.h" +#include "shl_module.h" #include "shl_register.h" #define LOG_SUBSYSTEM "font" @@ -89,8 +89,7 @@ void kmscon_font_attr_normalize(struct kmscon_font_attr *attr) return; if (!*attr->name) - memcpy(attr->name, KMSCON_FONT_DEFAULT_NAME, - sizeof(KMSCON_FONT_DEFAULT_NAME)); + memcpy(attr->name, KMSCON_FONT_DEFAULT_NAME, sizeof(KMSCON_FONT_DEFAULT_NAME)); if (!attr->ppi) attr->ppi = KMSCON_FONT_DEFAULT_PPI; @@ -116,8 +115,7 @@ void kmscon_font_attr_normalize(struct kmscon_font_attr *attr) * Returns: true if they match, otherwise false */ SHL_EXPORT -bool kmscon_font_attr_match(const struct kmscon_font_attr *a1, - const struct kmscon_font_attr *a2) +bool kmscon_font_attr_match(const struct kmscon_font_attr *a1, const struct kmscon_font_attr *a2) { if (!a1 || !a2) return false; @@ -169,11 +167,9 @@ int kmscon_font_register(const struct kmscon_font_ops *ops) log_debug("register font backend %s", ops->name); - ret = shl_register_add_cb(&font_reg, ops->name, (void*)ops, - kmscon_font_destroy); + ret = shl_register_add_cb(&font_reg, ops->name, (void *)ops, kmscon_font_destroy); if (ret) { - log_error("cannot register font backend %s: %d", ops->name, - ret); + log_error("cannot register font backend %s: %d", ops->name, ret); return ret; } @@ -195,8 +191,8 @@ void kmscon_font_unregister(const char *name) shl_register_remove(&font_reg, name); } -static int new_font(struct kmscon_font *font, - const struct kmscon_font_attr *attr, const char *backend) +static int new_font(struct kmscon_font *font, const struct kmscon_font_attr *attr, + const char *backend) { struct shl_register_record *record; const char *name = backend ? backend : ""; @@ -306,8 +302,7 @@ static int new_font(struct kmscon_font *font, * * Returns: 0 on success, error code on failure */ -int kmscon_font_find(struct kmscon_font **out, - const struct kmscon_font_attr *attr, +int kmscon_font_find(struct kmscon_font **out, const struct kmscon_font_attr *attr, const char *backend) { struct kmscon_font *font; @@ -316,9 +311,8 @@ int kmscon_font_find(struct kmscon_font **out, if (!out || !attr) return -EINVAL; - log_debug("searching for: be: %s nm: %s ppi: %u pt: %u b: %d i: %d he: %u wt: %u", - backend, attr->name, attr->ppi, attr->points, - attr->bold, attr->italic, attr->height, + log_debug("searching for: be: %s nm: %s ppi: %u pt: %u b: %d i: %d he: %u wt: %u", backend, + attr->name, attr->ppi, attr->points, attr->bold, attr->italic, attr->height, attr->width); font = malloc(sizeof(*font)); @@ -335,10 +329,9 @@ int kmscon_font_find(struct kmscon_font **out, goto err_free; } - log_debug("using: be: %s nm: %s ppi: %u pt: %u b: %d i: %d he: %u wt: %u", - font->ops->name, font->attr.name, font->attr.ppi, - font->attr.points, font->attr.bold, font->attr.italic, - font->attr.height, font->attr.width); + log_debug("using: be: %s nm: %s ppi: %u pt: %u b: %d i: %d he: %u wt: %u", font->ops->name, + font->attr.name, font->attr.ppi, font->attr.points, font->attr.bold, + font->attr.italic, font->attr.height, font->attr.width); *out = font; return 0; @@ -397,8 +390,7 @@ void kmscon_font_unref(struct kmscon_font *font) * Returns: 0 on success, negative error code on failure */ SHL_EXPORT -int kmscon_font_render(struct kmscon_font *font, - uint64_t id, const uint32_t *ch, size_t len, +int kmscon_font_render(struct kmscon_font *font, uint64_t id, const uint32_t *ch, size_t len, const struct kmscon_glyph **out) { if (!font || !out || !ch || !len) @@ -419,8 +411,7 @@ int kmscon_font_render(struct kmscon_font *font, * Returns: 0 on success, negative error code on failure */ SHL_EXPORT -int kmscon_font_render_empty(struct kmscon_font *font, - const struct kmscon_glyph **out) +int kmscon_font_render_empty(struct kmscon_font *font, const struct kmscon_glyph **out) { if (!font || !out) return -EINVAL; @@ -441,8 +432,7 @@ int kmscon_font_render_empty(struct kmscon_font *font, * Returns: 0 on success ,engative error code on failure */ SHL_EXPORT -int kmscon_font_render_inval(struct kmscon_font *font, - const struct kmscon_glyph **out) +int kmscon_font_render_inval(struct kmscon_font *font, const struct kmscon_glyph **out) { if (!font || !out) return -EINVAL; @@ -460,9 +450,7 @@ int kmscon_font_render_inval(struct kmscon_font *font, * * Returns: true when overflow needed, false when no overflow needed or on error */ -bool kmscon_font_get_overflow(struct kmscon_font *font, - uint64_t id, const uint32_t *ch, - size_t len) +bool kmscon_font_get_overflow(struct kmscon_font *font, uint64_t id, const uint32_t *ch, size_t len) { if (!font || !font->ops->get_overflow) return false; diff --git a/src/font.h b/src/font.h index 4c181c62..f72981cb 100644 --- a/src/font.h +++ b/src/font.h @@ -58,8 +58,7 @@ struct kmscon_font_attr { }; void kmscon_font_attr_normalize(struct kmscon_font_attr *attr); -bool kmscon_font_attr_match(const struct kmscon_font_attr *a1, - const struct kmscon_font_attr *a2); +bool kmscon_font_attr_match(const struct kmscon_font_attr *a1, const struct kmscon_font_attr *a2); struct kmscon_glyph { struct uterm_video_buffer buf; @@ -78,39 +77,28 @@ struct kmscon_font { struct kmscon_font_ops { const char *name; struct shl_module *owner; - int (*init) (struct kmscon_font *out, - const struct kmscon_font_attr *attr); - void (*destroy) (struct kmscon_font *font); - int (*render) (struct kmscon_font *font, - uint64_t id, const uint32_t *ch, size_t len, - const struct kmscon_glyph **out); - int (*render_empty) (struct kmscon_font *font, - const struct kmscon_glyph **out); - int (*render_inval) (struct kmscon_font *font, - const struct kmscon_glyph **out); - bool (*get_overflow) (struct kmscon_font *font, - uint64_t id, const uint32_t *ch, - size_t len); + int (*init)(struct kmscon_font *out, const struct kmscon_font_attr *attr); + void (*destroy)(struct kmscon_font *font); + int (*render)(struct kmscon_font *font, uint64_t id, const uint32_t *ch, size_t len, + const struct kmscon_glyph **out); + int (*render_empty)(struct kmscon_font *font, const struct kmscon_glyph **out); + int (*render_inval)(struct kmscon_font *font, const struct kmscon_glyph **out); + bool (*get_overflow)(struct kmscon_font *font, uint64_t id, const uint32_t *ch, size_t len); }; int kmscon_font_register(const struct kmscon_font_ops *ops); void kmscon_font_unregister(const char *name); -int kmscon_font_find(struct kmscon_font **out, - const struct kmscon_font_attr *attr, +int kmscon_font_find(struct kmscon_font **out, const struct kmscon_font_attr *attr, const char *backend); void kmscon_font_ref(struct kmscon_font *font); void kmscon_font_unref(struct kmscon_font *font); -int kmscon_font_render(struct kmscon_font *font, - uint64_t id, const uint32_t *ch, size_t len, +int kmscon_font_render(struct kmscon_font *font, uint64_t id, const uint32_t *ch, size_t len, const struct kmscon_glyph **out); -int kmscon_font_render_empty(struct kmscon_font *font, - const struct kmscon_glyph **out); -int kmscon_font_render_inval(struct kmscon_font *font, - const struct kmscon_glyph **out); -bool kmscon_font_get_overflow(struct kmscon_font *font, - uint64_t id, const uint32_t *ch, +int kmscon_font_render_empty(struct kmscon_font *font, const struct kmscon_glyph **out); +int kmscon_font_render_inval(struct kmscon_font *font, const struct kmscon_glyph **out); +bool kmscon_font_get_overflow(struct kmscon_font *font, uint64_t id, const uint32_t *ch, size_t len); /* modularized backends */ diff --git a/src/font_8x16.c b/src/font_8x16.c index 65f85f0a..422427bc 100644 --- a/src/font_8x16.c +++ b/src/font_8x16.c @@ -56,8 +56,7 @@ /* forward declaration; see end of file for real array */ static const struct kmscon_glyph kmscon_font_8x16_glyphs[256]; -static int kmscon_font_8x16_init(struct kmscon_font *out, - const struct kmscon_font_attr *attr) +static int kmscon_font_8x16_init(struct kmscon_font *out, const struct kmscon_font_attr *attr) { static const char name[] = "static-8x16"; @@ -80,9 +79,8 @@ static void kmscon_font_8x16_destroy(struct kmscon_font *font) log_debug("unloading static 8x16 font"); } -static int kmscon_font_8x16_render(struct kmscon_font *font, - uint64_t id, const uint32_t *ch, size_t len, - const struct kmscon_glyph **out) +static int kmscon_font_8x16_render(struct kmscon_font *font, uint64_t id, const uint32_t *ch, + size_t len, const struct kmscon_glyph **out) { if (len > 1 || *ch >= 256) return -ERANGE; @@ -91,15 +89,13 @@ static int kmscon_font_8x16_render(struct kmscon_font *font, return 0; } -static int kmscon_font_8x16_render_empty(struct kmscon_font *font, - const struct kmscon_glyph **out) +static int kmscon_font_8x16_render_empty(struct kmscon_font *font, const struct kmscon_glyph **out) { *out = &kmscon_font_8x16_glyphs[0]; return 0; } -static int kmscon_font_8x16_render_inval(struct kmscon_font *font, - const struct kmscon_glyph **out) +static int kmscon_font_8x16_render_inval(struct kmscon_font *font, const struct kmscon_glyph **out) { *out = &kmscon_font_8x16_glyphs['?']; return 0; diff --git a/src/font_pango.c b/src/font_pango.c index e90423ad..b729b2ca 100644 --- a/src/font_pango.c +++ b/src/font_pango.c @@ -109,8 +109,8 @@ static void manager__unref() } } -static int get_glyph(struct face *face, struct kmscon_glyph **out, - uint64_t id, const uint32_t *ch, size_t len, const struct kmscon_font_attr *attr) +static int get_glyph(struct face *face, struct kmscon_glyph **out, uint64_t id, const uint32_t *ch, + size_t len, const struct kmscon_font_attr *attr) { struct kmscon_glyph *glyph; PangoLayout *layout; @@ -131,7 +131,7 @@ static int get_glyph(struct face *face, struct kmscon_glyph **out, return -ERANGE; pthread_mutex_lock(&face->glyph_lock); - res = shl_hashtable_find(face->glyphs, (void**)&glyph, id); + res = shl_hashtable_find(face->glyphs, (void **)&glyph, id); pthread_mutex_unlock(&face->glyph_lock); if (res) { *out = glyph; @@ -164,20 +164,16 @@ static int get_glyph(struct face *face, struct kmscon_glyph **out, /* underline if requested */ if (attr->underline) { - pango_attr_list_change(attrlist, - pango_attr_underline_new(PANGO_UNDERLINE_SINGLE)); + pango_attr_list_change(attrlist, pango_attr_underline_new(PANGO_UNDERLINE_SINGLE)); } else { - pango_attr_list_change(attrlist, - pango_attr_underline_new(PANGO_UNDERLINE_NONE)); + pango_attr_list_change(attrlist, pango_attr_underline_new(PANGO_UNDERLINE_NONE)); } /* italic if requested */ if (attr->italic) { - pango_attr_list_change(attrlist, - pango_attr_style_new(PANGO_STYLE_ITALIC)); + pango_attr_list_change(attrlist, pango_attr_style_new(PANGO_STYLE_ITALIC)); } else { - pango_attr_list_change(attrlist, - pango_attr_style_new(PANGO_STYLE_NORMAL)); + pango_attr_list_change(attrlist, pango_attr_style_new(PANGO_STYLE_NORMAL)); } val = tsm_ucs4_to_utf8_alloc(ch, len, &ulen); @@ -199,7 +195,8 @@ static int get_glyph(struct face *face, struct kmscon_glyph **out, pango_layout_line_get_extents(line, &logical_rec, &rec); pango_extents_to_pixels(&rec, &logical_rec); - glyph->width = (logical_rec.x + logical_rec.width > rec.x + face->real_attr.width) ? 2 : cwidth; + glyph->width = + (logical_rec.x + logical_rec.width > rec.x + face->real_attr.width) ? 2 : cwidth; glyph->buf.width = face->real_attr.width * glyph->width; glyph->buf.height = face->real_attr.height; glyph->buf.stride = glyph->buf.width; @@ -269,7 +266,8 @@ static int manager_get_face(struct face **out, struct kmscon_font_attr *attr) manager_lock(); - shl_dlist_for_each(iter, &manager__list) { + shl_dlist_for_each(iter, &manager__list) + { face = shl_dlist_entry(iter, struct face, list); if (kmscon_font_attr_match(&face->attr, attr)) { ++face->ref; @@ -299,8 +297,7 @@ static int manager_get_face(struct face **out, struct kmscon_font_attr *attr) goto err_free; } - ret = shl_hashtable_new(&face->glyphs, shl_direct_hash, - shl_direct_equal, free_glyph); + ret = shl_hashtable_new(&face->glyphs, shl_direct_hash, shl_direct_equal, free_glyph); if (ret) { log_error("cannot allocate hashtable"); goto err_lock; @@ -311,12 +308,11 @@ static int manager_get_face(struct face **out, struct kmscon_font_attr *attr) pango_context_set_language(face->ctx, pango_language_get_default()); desc = pango_font_description_from_string(attr->name); - pango_font_description_set_absolute_size(desc, - PANGO_SCALE * face->attr.height); + pango_font_description_set_absolute_size(desc, PANGO_SCALE * face->attr.height); pango_font_description_set_weight(desc, - attr->bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL); + attr->bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL); pango_font_description_set_style(desc, - attr->italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL); + attr->italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL); pango_font_description_set_variant(desc, PANGO_VARIANT_NORMAL); pango_font_description_set_stretch(desc, PANGO_STRETCH_NORMAL); pango_font_description_set_gravity(desc, PANGO_GRAVITY_SOUTH); @@ -349,7 +345,8 @@ static int manager_get_face(struct face **out, struct kmscon_font_attr *attr) /* The real metrics probably differ from the requested metrics so try * again to find a suitable cached font. */ - shl_dlist_for_each(iter, &manager__list) { + shl_dlist_for_each(iter, &manager__list) + { f = shl_dlist_entry(iter, struct face, list); if (kmscon_font_attr_match(&f->real_attr, &face->real_attr)) { ++f->ref; @@ -405,8 +402,7 @@ static void block_sigchild(void) pthread_sigmask(SIG_BLOCK, &mask, NULL); } -static int kmscon_font_pango_init(struct kmscon_font *out, - const struct kmscon_font_attr *attr) +static int kmscon_font_pango_init(struct kmscon_font *out, const struct kmscon_font_attr *attr) { struct face *face = NULL; int ret; @@ -437,9 +433,8 @@ static void kmscon_font_pango_destroy(struct kmscon_font *font) manager_put_face(face); } -static int kmscon_font_pango_render(struct kmscon_font *font, uint64_t id, - const uint32_t *ch, size_t len, - const struct kmscon_glyph **out) +static int kmscon_font_pango_render(struct kmscon_font *font, uint64_t id, const uint32_t *ch, + size_t len, const struct kmscon_glyph **out) { struct kmscon_glyph *glyph; int ret; @@ -452,25 +447,20 @@ static int kmscon_font_pango_render(struct kmscon_font *font, uint64_t id, return 0; } -static int kmscon_font_pango_render_empty(struct kmscon_font *font, - const struct kmscon_glyph **out) +static int kmscon_font_pango_render_empty(struct kmscon_font *font, const struct kmscon_glyph **out) { static const uint32_t empty_char = ' '; return kmscon_font_pango_render(font, empty_char, &empty_char, 1, out); } -static int kmscon_font_pango_render_inval(struct kmscon_font *font, - const struct kmscon_glyph **out) +static int kmscon_font_pango_render_inval(struct kmscon_font *font, const struct kmscon_glyph **out) { static const uint32_t question_mark = '?'; - return kmscon_font_pango_render(font, question_mark, &question_mark, 1, - out); + return kmscon_font_pango_render(font, question_mark, &question_mark, 1, out); } -static bool kmscon_font_pango_get_overflow(struct kmscon_font *font, - uint64_t id, - const uint32_t *ch, - size_t len) +static bool kmscon_font_pango_get_overflow(struct kmscon_font *font, uint64_t id, + const uint32_t *ch, size_t len) { struct face *face = font->data; unsigned int cwidth; diff --git a/src/font_rotate.c b/src/font_rotate.c index 7fe2daa2..e39053c8 100644 --- a/src/font_rotate.c +++ b/src/font_rotate.c @@ -26,18 +26,17 @@ #include "font_rotate.h" #include "shl_misc.h" - SHL_EXPORT -int kmscon_rotate_create_tables(struct shl_hashtable **normal, struct shl_hashtable **bold, shl_free_cb free_glyph) +SHL_EXPORT +int kmscon_rotate_create_tables(struct shl_hashtable **normal, struct shl_hashtable **bold, + shl_free_cb free_glyph) { int ret; - ret = shl_hashtable_new(normal, shl_direct_hash, - shl_direct_equal, free_glyph); + ret = shl_hashtable_new(normal, shl_direct_hash, shl_direct_equal, free_glyph); if (ret) return ret; - ret = shl_hashtable_new(bold, shl_direct_hash, - shl_direct_equal, free_glyph); + ret = shl_hashtable_new(bold, shl_direct_hash, shl_direct_equal, free_glyph); if (ret) shl_hashtable_free(*normal); return ret; @@ -51,7 +50,8 @@ void kmscon_rotate_free_tables(struct shl_hashtable *normal, struct shl_hashtabl } SHL_EXPORT -int kmscon_rotate_glyph(struct uterm_video_buffer *vb, const struct kmscon_glyph *glyph, enum Orientation orientation, uint8_t align) +int kmscon_rotate_glyph(struct uterm_video_buffer *vb, const struct kmscon_glyph *glyph, + enum Orientation orientation, uint8_t align) { int width; int height; @@ -68,7 +68,7 @@ int kmscon_rotate_glyph(struct uterm_video_buffer *vb, const struct kmscon_glyph height = buf->width; } - stride = align * ((width + (align - 1)) / align); + stride = align * ((width + (align - 1)) / align); vb->data = malloc(stride * height); if (!vb->data) @@ -93,7 +93,7 @@ int kmscon_rotate_glyph(struct uterm_video_buffer *vb, const struct kmscon_glyph } src += buf->stride; } - break; + break; case OR_UPSIDE_DOWN: src += (buf->height - 1) * buf->stride; for (i = 0; i < buf->height; i++) { @@ -106,7 +106,7 @@ int kmscon_rotate_glyph(struct uterm_video_buffer *vb, const struct kmscon_glyph case OR_LEFT: for (i = 0; i < buf->height; i++) { for (j = 0; j < buf->width; j++) { - dst[(height -j -1) * stride + i] = src[j]; + dst[(height - j - 1) * stride + i] = src[j]; } src += buf->stride; } @@ -117,4 +117,3 @@ int kmscon_rotate_glyph(struct uterm_video_buffer *vb, const struct kmscon_glyph vb->format = buf->format; return 0; } - diff --git a/src/font_rotate.h b/src/font_rotate.h index aa687ab0..b49f76e3 100644 --- a/src/font_rotate.h +++ b/src/font_rotate.h @@ -26,6 +26,8 @@ #include "shl_hashtable.h" #include "text.h" -int kmscon_rotate_create_tables(struct shl_hashtable **normal, struct shl_hashtable **bold, shl_free_cb free_glyph); +int kmscon_rotate_create_tables(struct shl_hashtable **normal, struct shl_hashtable **bold, + shl_free_cb free_glyph); void kmscon_rotate_free_tables(struct shl_hashtable *normal, struct shl_hashtable *bold); -int kmscon_rotate_glyph(struct uterm_video_buffer *vb, const struct kmscon_glyph *glyph, enum Orientation orientation, uint8_t align); +int kmscon_rotate_glyph(struct uterm_video_buffer *vb, const struct kmscon_glyph *glyph, + enum Orientation orientation, uint8_t align); diff --git a/src/font_unifont.c b/src/font_unifont.c index db30d3fd..230ac160 100644 --- a/src/font_unifont.c +++ b/src/font_unifont.c @@ -39,15 +39,15 @@ */ #include +#include #include #include #include -#include #include "font.h" +#include "font_unifont_data.bin.h" #include "shl_hashtable.h" #include "shl_log.h" #include "uterm_video.h" -#include "font_unifont_data.bin.h" #define LOG_SUBSYSTEM "font_unifont" @@ -115,14 +115,13 @@ static int find_glyph(uint32_t ch, const struct kmscon_glyph **out) pthread_mutex_lock(&cache_mutex); if (!cache) { - ret = shl_hashtable_new(&cache, shl_direct_hash, - shl_direct_equal, free_glyph); + ret = shl_hashtable_new(&cache, shl_direct_hash, shl_direct_equal, free_glyph); if (ret) { log_error("cannot create unifont hashtable: %d", ret); goto out_unlock; } } else { - res = shl_hashtable_find(cache, (void**)out, ch); + res = shl_hashtable_find(cache, (void **)out, ch); if (res) { ret = 0; goto out_unlock; @@ -134,8 +133,8 @@ static int find_glyph(uint32_t ch, const struct kmscon_glyph **out) goto out_unlock; } - start = (const struct unifont_data*)_binary_font_unifont_data_start; - end = (const struct unifont_data*)_binary_font_unifont_data_end; + start = (const struct unifont_data *)_binary_font_unifont_data_start; + end = (const struct unifont_data *)_binary_font_unifont_data_end; d = &start[ch]; if (d >= end) { @@ -203,8 +202,7 @@ static int find_glyph(uint32_t ch, const struct kmscon_glyph **out) return ret; } -static int kmscon_font_unifont_init(struct kmscon_font *out, - const struct kmscon_font_attr *attr) +static int kmscon_font_unifont_init(struct kmscon_font *out, const struct kmscon_font_attr *attr) { static const char name[] = "static-unifont"; @@ -215,7 +213,6 @@ static int kmscon_font_unifont_init(struct kmscon_font *out, return -EFAULT; } - memset(&out->attr, 0, sizeof(out->attr)); memcpy(out->attr.name, name, sizeof(name)); out->attr.bold = false; @@ -235,9 +232,8 @@ static void kmscon_font_unifont_destroy(struct kmscon_font *font) cache_unref(); } -static int kmscon_font_unifont_render(struct kmscon_font *font, uint64_t id, - const uint32_t *ch, size_t len, - const struct kmscon_glyph **out) +static int kmscon_font_unifont_render(struct kmscon_font *font, uint64_t id, const uint32_t *ch, + size_t len, const struct kmscon_glyph **out) { if (len > 1) return -ERANGE; diff --git a/src/genunifont.c b/src/genunifont.c index ca464eab..d9bc895f 100644 --- a/src/genunifont.c +++ b/src/genunifont.c @@ -68,8 +68,7 @@ static void print_unifont_glyph(FILE *out, const struct unifont_glyph *g) case 64: break; default: - fprintf(stderr, "genunifont: invalid data size %d for %x", - g->len, g->codepoint); + fprintf(stderr, "genunifont: invalid data size %d for %x", g->len, g->codepoint); return; } @@ -79,7 +78,7 @@ static void print_unifont_glyph(FILE *out, const struct unifont_glyph *g) val |= hex_val(g->data[i + 1]); fprintf(out, "%c", val); } - for ( ; i < 64; i += 2) + for (; i < 64; i += 2) fprintf(out, "%c", 0); } @@ -112,10 +111,7 @@ static int build_unifont_glyph(struct unifont_glyph *g, const char *buf) static int parse_single_file(FILE *out, FILE *in) { static const struct unifont_glyph replacement = { - .codepoint = 0, - .len = 32, - .data = "0000007E665A5A7A76767E76767E0000" - }; + .codepoint = 0, .len = 32, .data = "0000007E665A5A7A76767E76767E0000"}; char buf[MAX_DATA_SIZE]; struct unifont_glyph *g, **iter, *list, *last; int ret, num; @@ -185,8 +181,7 @@ static int parse_single_file(FILE *out, FILE *in) iter = &(*iter)->next; if (*iter && (*iter)->codepoint == g->codepoint) { - fprintf(stderr, "glyph %d used twice\n", - g->codepoint); + fprintf(stderr, "glyph %d used twice\n", g->codepoint); free(g); return -EFAULT; } @@ -231,22 +226,19 @@ int main(int argc, char **argv) out = fopen(argv[1], "wb"); if (!out) { - fprintf(stderr, "genunifont: cannot open output %s: %m\n", - argv[1]); + fprintf(stderr, "genunifont: cannot open output %s: %m\n", argv[1]); ret = EXIT_FAILURE; goto err_out; } in = fopen(argv[2], "rb"); if (!in) { - fprintf(stderr, "genunifont: cannot open %s: %m\n", - argv[2]); + fprintf(stderr, "genunifont: cannot open %s: %m\n", argv[2]); ret = EXIT_FAILURE; } else { ret = parse_single_file(out, in); if (ret) { - fprintf(stderr, "genunifont: parsing input %s failed", - argv[2]); + fprintf(stderr, "genunifont: parsing input %s failed", argv[2]); ret = EXIT_FAILURE; } else { ret = EXIT_SUCCESS; @@ -254,7 +246,6 @@ int main(int argc, char **argv) fclose(in); } - fclose(out); err_out: return ret; diff --git a/src/kmscon_conf.c b/src/kmscon_conf.c index 2be56f8c..028335a2 100644 --- a/src/kmscon_conf.c +++ b/src/kmscon_conf.c @@ -94,6 +94,9 @@ static void print_help() "\t --reset-env [on]\n" "\t Reset environment before running child\n" "\t process\n" + "\t --backspace-delete [on]\n" + "\t Send delete character when backspace is\n" + "\t pressed\n" "\t --sb-size [1000]\n" "\t Size of the scrollback-buffer in lines\n" "\n" @@ -110,8 +113,8 @@ static void print_help() "\t Initial delay for key-repeat in ms\n" "\t --xkb-repeat-rate [50]\n" "\t Delay between two key repeats in ms\n" - "\t --mouse [off]\n" - "\t Enable experimental mouse support\n" + "\t --mouse [on]\n" + "\t Enable mouse support\n" "\n" "Grabs / Keyboard-Shortcuts:\n" "\t --grab-scroll-up [Up]\n" @@ -140,6 +143,8 @@ static void print_help() "\t Rotate output clock-wise\n" "\t --grab-rotate-ccw [Minus]\n" "\t Rotate output counter-clock-wise\n" + "\t --grab-reboot []\n" + "\t Reboot the system (disabled by default)\n" "\n" "Video Options:\n" "\t --drm [on] Use DRM if available\n" @@ -147,7 +152,6 @@ static void print_help() "\t available\n" "\t --gpus={all,aux,primary} [all] GPU selection mode\n" "\t --render-engine [-] Console renderer\n" - "\t --render-timing [off] Print renderer timing information\n" "\t --use-original-mode [on] Use original KMS video mode\n" "\t --mode x [0x0] Set the desired mode for the\n" "\t output. If the specified mode is\n" @@ -221,8 +225,7 @@ static void print_help() */ } -#define KMSCON_CONF_FROM_FIELD(_mem, _name) \ - shl_offsetof((_mem), struct kmscon_conf_t, _name) +#define KMSCON_CONF_FROM_FIELD(_mem, _name) shl_offsetof((_mem), struct kmscon_conf_t, _name) /* * VT Type @@ -266,12 +269,11 @@ static int conf_parse_vt(struct conf_option *opt, bool on, const char *arg) } opt->type->free(opt); - *(void**)opt->mem = str; + *(void **)opt->mem = str; return 0; } -static int conf_copy_vt(struct conf_option *opt, - const struct conf_option *src) +static int conf_copy_vt(struct conf_option *opt, const struct conf_option *src) { return conf_string.copy(opt, src); } @@ -293,7 +295,7 @@ static const struct conf_type conf_vt = { * special handling that the command-line does. */ -static char *def_argv[] = { "/bin/login", "-p", NULL }; +static char *def_argv[] = {"/bin/login", "-p", NULL}; static void conf_default_login(struct conf_option *opt) { @@ -323,8 +325,7 @@ static int conf_parse_login(struct conf_option *opt, bool on, const char *arg) return 0; } -static int conf_copy_login(struct conf_option *opt, - const struct conf_option *src) +static int conf_copy_login(struct conf_option *opt, const struct conf_option *src) { struct kmscon_conf_t *conf = KMSCON_CONF_FROM_FIELD(opt->mem, login); struct kmscon_conf_t *s = KMSCON_CONF_FROM_FIELD(src->mem, login); @@ -353,8 +354,7 @@ static const struct conf_type conf_login = { .copy = conf_copy_login, }; -static int aftercheck_login(struct conf_option *opt, int argc, char **argv, - int idx) +static int aftercheck_login(struct conf_option *opt, int argc, char **argv, int idx) { struct kmscon_conf_t *conf = KMSCON_CONF_FROM_FIELD(opt->mem, login); int ret = 0; @@ -374,8 +374,7 @@ static int aftercheck_login(struct conf_option *opt, int argc, char **argv, conf->argv = t; ret = argc - idx; } else if (!conf->argv) { - ret = shl_dup_array_size(&t, def_argv, - sizeof(def_argv) / sizeof(*def_argv)); + ret = shl_dup_array_size(&t, def_argv, sizeof(def_argv) / sizeof(*def_argv)); if (ret) return ret; @@ -450,8 +449,7 @@ static int conf_parse_gpus(struct conf_option *opt, bool on, const char *arg) return 0; } -static int conf_copy_gpus(struct conf_option *opt, - const struct conf_option *src) +static int conf_copy_gpus(struct conf_option *opt, const struct conf_option *src) { return conf_uint.copy(opt, src); } @@ -482,13 +480,13 @@ static int conf_parse_color(struct conf_option *opt, bool on, const char *arg) ret = shl_split_string(arg, &list, &list_num, ',', true); if (ret) { - log_error("cannot split '%s' config-option argument", - opt->long_name + 3); + log_error("cannot split '%s' config-option argument", opt->long_name + 3); return ret; } if (list_num != 3) { log_error("%u values given for '%s' config-option argument, " - "3 expected", list_num, opt->long_name + 3); + "3 expected", + list_num, opt->long_name + 3); ret = -EFAULT; goto out_free; } @@ -504,7 +502,7 @@ static int conf_parse_color(struct conf_option *opt, bool on, const char *arg) ret = -EFAULT; goto out_free; } - ((uint8_t*)opt->mem)[i] = val; + ((uint8_t *)opt->mem)[i] = val; } out_free: @@ -512,8 +510,7 @@ static int conf_parse_color(struct conf_option *opt, bool on, const char *arg) return ret; } -static int conf_copy_color(struct conf_option *opt, - const struct conf_option *src) +static int conf_copy_color(struct conf_option *opt, const struct conf_option *src) { memcpy(opt->mem, src->mem, 3); return 0; @@ -532,8 +529,9 @@ static const struct conf_type conf_color = { .copy = conf_copy_color, }; -#define CONF_OPTION_COLOR(_long, _mem_palette, _offset) \ - CONF_OPTION(0, 0, _long, &conf_color, NULL, NULL, NULL, &(_mem_palette)[_offset], &def_palette[_offset]) +#define CONF_OPTION_COLOR(_long, _mem_palette, _offset) \ + CONF_OPTION(0, 0, _long, &conf_color, NULL, NULL, NULL, &(_mem_palette)[_offset], \ + &def_palette[_offset]) /* * Custom Afterchecks @@ -542,8 +540,7 @@ static const struct conf_type conf_color = { * Some of them also need copy-helpers because they copy more than one value. */ -static int aftercheck_debug(struct conf_option *opt, int argc, char **argv, - int idx) +static int aftercheck_debug(struct conf_option *opt, int argc, char **argv, int idx) { struct kmscon_conf_t *conf = KMSCON_CONF_FROM_FIELD(opt->mem, debug); @@ -554,8 +551,7 @@ static int aftercheck_debug(struct conf_option *opt, int argc, char **argv, return 0; } -static int aftercheck_help(struct conf_option *opt, int argc, char **argv, - int idx) +static int aftercheck_help(struct conf_option *opt, int argc, char **argv, int idx) { struct kmscon_conf_t *conf = KMSCON_CONF_FROM_FIELD(opt->mem, help); @@ -568,8 +564,7 @@ static int aftercheck_help(struct conf_option *opt, int argc, char **argv, return 0; } -static int aftercheck_drm(struct conf_option *opt, int argc, char **argv, - int idx) +static int aftercheck_drm(struct conf_option *opt, int argc, char **argv, int idx) { #ifndef BUILD_ENABLE_VIDEO_DRM2D #ifndef BUILD_ENABLE_VIDEO_DRM3D @@ -589,8 +584,7 @@ static int aftercheck_drm(struct conf_option *opt, int argc, char **argv, return 0; } -static int aftercheck_vt(struct conf_option *opt, int argc, char **argv, - int idx) +static int aftercheck_vt(struct conf_option *opt, int argc, char **argv, int idx) { struct kmscon_conf_t *conf = KMSCON_CONF_FROM_FIELD(opt->mem, vt); @@ -598,7 +592,8 @@ static int aftercheck_vt(struct conf_option *opt, int argc, char **argv, return 0; if (!kmscon_conf_is_single_seat(conf)) { - log_error("you cannot use global --vt if --seats contains not exactly one seat, ignoring --vt"); + log_error("you cannot use global --vt if --seats contains not exactly one seat, " + "ignoring --vt"); free(conf->vt); conf->vt = NULL; return -EFAULT; @@ -607,8 +602,7 @@ static int aftercheck_vt(struct conf_option *opt, int argc, char **argv, return 0; } -static int aftercheck_listen(struct conf_option *opt, int argc, char **argv, - int idx) +static int aftercheck_listen(struct conf_option *opt, int argc, char **argv, int idx) { struct kmscon_conf_t *conf = KMSCON_CONF_FROM_FIELD(opt->mem, listen); @@ -624,67 +618,59 @@ static int aftercheck_listen(struct conf_option *opt, int argc, char **argv, * speeds up config-parser considerably. */ -static char *def_seats[] = { "current", NULL }; +static char *def_seats[] = {"current", NULL}; -static struct conf_grab def_grab_scroll_up = - CONF_SINGLE_GRAB(SHL_SHIFT_MASK, XKB_KEY_Up); +static struct conf_grab def_grab_scroll_up = CONF_SINGLE_GRAB(SHL_SHIFT_MASK, XKB_KEY_Up); -static struct conf_grab def_grab_scroll_down = - CONF_SINGLE_GRAB(SHL_SHIFT_MASK, XKB_KEY_Down); +static struct conf_grab def_grab_scroll_down = CONF_SINGLE_GRAB(SHL_SHIFT_MASK, XKB_KEY_Down); -static struct conf_grab def_grab_page_up = - CONF_SINGLE_GRAB(SHL_SHIFT_MASK, XKB_KEY_Prior); +static struct conf_grab def_grab_page_up = CONF_SINGLE_GRAB(SHL_SHIFT_MASK, XKB_KEY_Prior); -static struct conf_grab def_grab_page_down = - CONF_SINGLE_GRAB(SHL_SHIFT_MASK, XKB_KEY_Next); +static struct conf_grab def_grab_page_down = CONF_SINGLE_GRAB(SHL_SHIFT_MASK, XKB_KEY_Next); -static struct conf_grab def_grab_zoom_in = - CONF_SINGLE_GRAB(SHL_CONTROL_MASK, XKB_KEY_plus); +static struct conf_grab def_grab_zoom_in = CONF_SINGLE_GRAB(SHL_CONTROL_MASK, XKB_KEY_plus); -static struct conf_grab def_grab_zoom_out = - CONF_SINGLE_GRAB(SHL_CONTROL_MASK, XKB_KEY_minus); +static struct conf_grab def_grab_zoom_out = CONF_SINGLE_GRAB(SHL_CONTROL_MASK, XKB_KEY_minus); static struct conf_grab def_grab_session_next = - CONF_SINGLE_GRAB(SHL_CONTROL_MASK | SHL_LOGO_MASK, XKB_KEY_Right); + CONF_SINGLE_GRAB(SHL_CONTROL_MASK | SHL_LOGO_MASK, XKB_KEY_Right); static struct conf_grab def_grab_session_prev = - CONF_SINGLE_GRAB(SHL_CONTROL_MASK | SHL_LOGO_MASK, XKB_KEY_Left); + CONF_SINGLE_GRAB(SHL_CONTROL_MASK | SHL_LOGO_MASK, XKB_KEY_Left); static struct conf_grab def_grab_session_dummy = - CONF_SINGLE_GRAB(SHL_CONTROL_MASK | SHL_LOGO_MASK, XKB_KEY_Escape); + CONF_SINGLE_GRAB(SHL_CONTROL_MASK | SHL_LOGO_MASK, XKB_KEY_Escape); static struct conf_grab def_grab_session_close = - CONF_SINGLE_GRAB(SHL_CONTROL_MASK | SHL_LOGO_MASK, XKB_KEY_BackSpace); + CONF_SINGLE_GRAB(SHL_CONTROL_MASK | SHL_LOGO_MASK, XKB_KEY_BackSpace); static struct conf_grab def_grab_terminal_new = - CONF_SINGLE_GRAB(SHL_CONTROL_MASK | SHL_LOGO_MASK, XKB_KEY_Return); + CONF_SINGLE_GRAB(SHL_CONTROL_MASK | SHL_LOGO_MASK, XKB_KEY_Return); -static struct conf_grab def_grab_rotate_cw = - CONF_SINGLE_GRAB(SHL_LOGO_MASK, XKB_KEY_plus); +static struct conf_grab def_grab_rotate_cw = CONF_SINGLE_GRAB(SHL_LOGO_MASK, XKB_KEY_plus); -static struct conf_grab def_grab_rotate_ccw = - CONF_SINGLE_GRAB(SHL_LOGO_MASK, XKB_KEY_minus); +static struct conf_grab def_grab_rotate_ccw = CONF_SINGLE_GRAB(SHL_LOGO_MASK, XKB_KEY_minus); static palette_t def_palette = { - [TSM_COLOR_BLACK] = { 0, 0, 0 }, /* black */ - [TSM_COLOR_RED] = { 205, 0, 0 }, /* red */ - [TSM_COLOR_GREEN] = { 0, 205, 0 }, /* green */ - [TSM_COLOR_YELLOW] = { 205, 205, 0 }, /* yellow */ - [TSM_COLOR_BLUE] = { 0, 0, 238 }, /* blue */ - [TSM_COLOR_MAGENTA] = { 205, 0, 205 }, /* magenta */ - [TSM_COLOR_CYAN] = { 0, 205, 205 }, /* cyan */ - [TSM_COLOR_LIGHT_GREY] = { 229, 229, 229 }, /* light grey */ - [TSM_COLOR_DARK_GREY] = { 127, 127, 127 }, /* dark grey */ - [TSM_COLOR_LIGHT_RED] = { 255, 0, 0 }, /* light red */ - [TSM_COLOR_LIGHT_GREEN] = { 0, 255, 0 }, /* light green */ - [TSM_COLOR_LIGHT_YELLOW] = { 255, 255, 0 }, /* light yellow */ - [TSM_COLOR_LIGHT_BLUE] = { 92, 92, 255 }, /* light blue */ - [TSM_COLOR_LIGHT_MAGENTA] = { 255, 0, 255 }, /* light magenta */ - [TSM_COLOR_LIGHT_CYAN] = { 0, 255, 255 }, /* light cyan */ - [TSM_COLOR_WHITE] = { 255, 255, 255 }, /* white */ - - [TSM_COLOR_FOREGROUND] = { 229, 229, 229 }, /* light grey */ - [TSM_COLOR_BACKGROUND] = { 0, 0, 0 }, /* black */ + [TSM_COLOR_BLACK] = {0, 0, 0}, /* black */ + [TSM_COLOR_RED] = {205, 0, 0}, /* red */ + [TSM_COLOR_GREEN] = {0, 205, 0}, /* green */ + [TSM_COLOR_YELLOW] = {205, 205, 0}, /* yellow */ + [TSM_COLOR_BLUE] = {0, 0, 238}, /* blue */ + [TSM_COLOR_MAGENTA] = {205, 0, 205}, /* magenta */ + [TSM_COLOR_CYAN] = {0, 205, 205}, /* cyan */ + [TSM_COLOR_LIGHT_GREY] = {229, 229, 229}, /* light grey */ + [TSM_COLOR_DARK_GREY] = {127, 127, 127}, /* dark grey */ + [TSM_COLOR_LIGHT_RED] = {255, 0, 0}, /* light red */ + [TSM_COLOR_LIGHT_GREEN] = {0, 255, 0}, /* light green */ + [TSM_COLOR_LIGHT_YELLOW] = {255, 255, 0}, /* light yellow */ + [TSM_COLOR_LIGHT_BLUE] = {92, 92, 255}, /* light blue */ + [TSM_COLOR_LIGHT_MAGENTA] = {255, 0, 255}, /* light magenta */ + [TSM_COLOR_LIGHT_CYAN] = {0, 255, 255}, /* light cyan */ + [TSM_COLOR_WHITE] = {255, 255, 255}, /* white */ + + [TSM_COLOR_FOREGROUND] = {229, 229, 229}, /* light grey */ + [TSM_COLOR_BACKGROUND] = {0, 0, 0}, /* black */ }; int kmscon_conf_new(struct conf_ctx **out) @@ -705,10 +691,12 @@ int kmscon_conf_new(struct conf_ctx **out) /* Global Options */ CONF_OPTION_BOOL_FULL('h', "help", aftercheck_help, NULL, NULL, &conf->help, false), CONF_OPTION_BOOL('v', "verbose", &conf->verbose, false), - CONF_OPTION_BOOL_FULL(0, "debug", aftercheck_debug, NULL, NULL, &conf->debug, false), + CONF_OPTION_BOOL_FULL(0, "debug", aftercheck_debug, NULL, NULL, &conf->debug, + false), CONF_OPTION_BOOL(0, "silent", &conf->silent, false), CONF_OPTION_STRING('c', "configdir", &conf->configdir, BUILD_CONFIG_DIR), - CONF_OPTION_BOOL_FULL(0, "listen", aftercheck_listen, NULL, NULL, &conf->listen, false), + CONF_OPTION_BOOL_FULL(0, "listen", aftercheck_listen, NULL, NULL, &conf->listen, + false), /* Seat Options */ CONF_OPTION(0, 0, "vt", &conf_vt, aftercheck_vt, NULL, NULL, &conf->vt, NULL), @@ -721,9 +709,11 @@ int kmscon_conf_new(struct conf_ctx **out) CONF_OPTION_BOOL(0, "terminal-session", &conf->terminal_session, true), /* Terminal Options */ - CONF_OPTION(0, 'l', "login", &conf_login, aftercheck_login, NULL, file_login, &conf->login, false), + CONF_OPTION(0, 'l', "login", &conf_login, aftercheck_login, NULL, file_login, + &conf->login, false), CONF_OPTION_STRING('t', "term", &conf->term, "xterm-256color"), CONF_OPTION_BOOL(0, "reset-env", &conf->reset_env, true), + CONF_OPTION_BOOL(0, "backspace-delete", &conf->backspace_delete, true), CONF_OPTION_UINT(0, "sb-size", &conf->sb_size, 1000), /* Input Options */ @@ -735,27 +725,36 @@ int kmscon_conf_new(struct conf_ctx **out) CONF_OPTION_STRING(0, "xkb-compose-file", &conf->xkb_compose_file, ""), CONF_OPTION_UINT(0, "xkb-repeat-delay", &conf->xkb_repeat_delay, 250), CONF_OPTION_UINT(0, "xkb-repeat-rate", &conf->xkb_repeat_rate, 50), - CONF_OPTION_BOOL(0, "mouse", &conf->mouse, false), + CONF_OPTION_BOOL(0, "mouse", &conf->mouse, true), /* Grabs / Keyboard-Shortcuts */ CONF_OPTION_GRAB(0, "grab-scroll-up", &conf->grab_scroll_up, &def_grab_scroll_up), - CONF_OPTION_GRAB(0, "grab-scroll-down", &conf->grab_scroll_down, &def_grab_scroll_down), + CONF_OPTION_GRAB(0, "grab-scroll-down", &conf->grab_scroll_down, + &def_grab_scroll_down), CONF_OPTION_GRAB(0, "grab-page-up", &conf->grab_page_up, &def_grab_page_up), CONF_OPTION_GRAB(0, "grab-page-down", &conf->grab_page_down, &def_grab_page_down), CONF_OPTION_GRAB(0, "grab-zoom-in", &conf->grab_zoom_in, &def_grab_zoom_in), CONF_OPTION_GRAB(0, "grab-zoom-out", &conf->grab_zoom_out, &def_grab_zoom_out), - CONF_OPTION_GRAB(0, "grab-session-next", &conf->grab_session_next, &def_grab_session_next), - CONF_OPTION_GRAB(0, "grab-session-prev", &conf->grab_session_prev, &def_grab_session_prev), - CONF_OPTION_GRAB(0, "grab-session-dummy", &conf->grab_session_dummy, &def_grab_session_dummy), - CONF_OPTION_GRAB(0, "grab-session-close", &conf->grab_session_close, &def_grab_session_close), - CONF_OPTION_GRAB(0, "grab-terminal-new", &conf->grab_terminal_new, &def_grab_terminal_new), + CONF_OPTION_GRAB(0, "grab-session-next", &conf->grab_session_next, + &def_grab_session_next), + CONF_OPTION_GRAB(0, "grab-session-prev", &conf->grab_session_prev, + &def_grab_session_prev), + CONF_OPTION_GRAB(0, "grab-session-dummy", &conf->grab_session_dummy, + &def_grab_session_dummy), + CONF_OPTION_GRAB(0, "grab-session-close", &conf->grab_session_close, + &def_grab_session_close), + CONF_OPTION_GRAB(0, "grab-terminal-new", &conf->grab_terminal_new, + &def_grab_terminal_new), CONF_OPTION_GRAB(0, "grab-rotate-cw", &conf->grab_rotate_cw, &def_grab_rotate_cw), - CONF_OPTION_GRAB(0, "grab-rotate-ccw", &conf->grab_rotate_ccw, &def_grab_rotate_ccw), + CONF_OPTION_GRAB(0, "grab-rotate-ccw", &conf->grab_rotate_ccw, + &def_grab_rotate_ccw), + CONF_OPTION_GRAB(0, "grab-reboot", &conf->grab_reboot, NULL), /* Video Options */ CONF_OPTION_BOOL_FULL(0, "drm", aftercheck_drm, NULL, NULL, &conf->drm, true), CONF_OPTION_BOOL(0, "hwaccel", &conf->hwaccel, false), - CONF_OPTION(0, 0, "gpus", &conf_gpus, NULL, NULL, NULL, &conf->gpus, KMSCON_GPU_ALL), + CONF_OPTION(0, 0, "gpus", &conf_gpus, NULL, NULL, NULL, &conf->gpus, + KMSCON_GPU_ALL), CONF_OPTION_STRING(0, "render-engine", &conf->render_engine, NULL), CONF_OPTION_BOOL(0, "use-original-mode", &conf->use_original_mode, true), CONF_OPTION_STRING(0, "mode", &conf->mode, NULL), @@ -779,18 +778,20 @@ int kmscon_conf_new(struct conf_ctx **out) CONF_OPTION_COLOR("palette-light-grey", conf->custom_palette, TSM_COLOR_LIGHT_GREY), CONF_OPTION_COLOR("palette-dark-grey", conf->custom_palette, TSM_COLOR_DARK_GREY), CONF_OPTION_COLOR("palette-light-red", conf->custom_palette, TSM_COLOR_LIGHT_RED), - CONF_OPTION_COLOR("palette-light-green", conf->custom_palette, TSM_COLOR_LIGHT_GREEN), - CONF_OPTION_COLOR("palette-light-yellow", conf->custom_palette, TSM_COLOR_LIGHT_YELLOW), + CONF_OPTION_COLOR("palette-light-green", conf->custom_palette, + TSM_COLOR_LIGHT_GREEN), + CONF_OPTION_COLOR("palette-light-yellow", conf->custom_palette, + TSM_COLOR_LIGHT_YELLOW), CONF_OPTION_COLOR("palette-light-blue", conf->custom_palette, TSM_COLOR_LIGHT_BLUE), - CONF_OPTION_COLOR("palette-light-magenta", conf->custom_palette, TSM_COLOR_LIGHT_MAGENTA), + CONF_OPTION_COLOR("palette-light-magenta", conf->custom_palette, + TSM_COLOR_LIGHT_MAGENTA), CONF_OPTION_COLOR("palette-light-cyan", conf->custom_palette, TSM_COLOR_LIGHT_CYAN), CONF_OPTION_COLOR("palette-white", conf->custom_palette, TSM_COLOR_WHITE), CONF_OPTION_COLOR("palette-foreground", conf->custom_palette, TSM_COLOR_FOREGROUND), CONF_OPTION_COLOR("palette-background", conf->custom_palette, TSM_COLOR_BACKGROUND), }; - ret = conf_ctx_new(&ctx, options, sizeof(options) / sizeof(*options), - conf); + ret = conf_ctx_new(&ctx, options, sizeof(options) / sizeof(*options), conf); if (ret) { free(conf); return ret; @@ -832,8 +833,7 @@ int kmscon_conf_load_main(struct conf_ctx *ctx, int argc, char **argv) if (!conf->debug && !conf->verbose && conf->silent) log_set_config(&LOG_CONFIG_WARNING(0, 0, 0, 0)); else - log_set_config(&LOG_CONFIG_INFO(conf->debug, - conf->verbose)); + log_set_config(&LOG_CONFIG_INFO(conf->debug, conf->verbose)); ret = conf_ctx_parse_file(ctx, "%s/kmscon.conf", conf->configdir); if (ret) @@ -847,14 +847,14 @@ int kmscon_conf_load_main(struct conf_ctx *ctx, int argc, char **argv) if (!conf->debug && !conf->verbose && conf->silent) log_set_config(&LOG_CONFIG_WARNING(0, 0, 0, 0)); else - log_set_config(&LOG_CONFIG_INFO(conf->debug, - conf->verbose)); + log_set_config(&LOG_CONFIG_INFO(conf->debug, conf->verbose)); /* You can't set a mode, and use_original_mode at the same time * specified mode takes priority. */ if (conf->use_original_mode && conf->mode != NULL) { - log_error("Cannot use --mode if --use-original-mode is enabled. Try --no-use-original-mode.\n"); + log_error("Cannot use --mode if --use-original-mode is enabled. Try " + "--no-use-original-mode.\n"); conf->use_original_mode = false; } log_print_init("kmscon"); @@ -862,8 +862,7 @@ int kmscon_conf_load_main(struct conf_ctx *ctx, int argc, char **argv) return 0; } -int kmscon_conf_load_seat(struct conf_ctx *ctx, const struct conf_ctx *main, - const char *seat) +int kmscon_conf_load_seat(struct conf_ctx *ctx, const struct conf_ctx *main, const char *seat) { int ret; struct kmscon_conf_t *conf; @@ -880,8 +879,7 @@ int kmscon_conf_load_seat(struct conf_ctx *ctx, const struct conf_ctx *main, if (ret) return ret; - ret = conf_ctx_parse_file(ctx, "%s/%s.seat.conf", conf->configdir, - seat); + ret = conf_ctx_parse_file(ctx, "%s/%s.seat.conf", conf->configdir, seat); if (ret) return ret; diff --git a/src/kmscon_conf.h b/src/kmscon_conf.h index 1964d22a..c76f2b7c 100644 --- a/src/kmscon_conf.h +++ b/src/kmscon_conf.h @@ -31,10 +31,10 @@ #ifndef KMSCON_MAIN_H #define KMSCON_MAIN_H +#include #include #include #include -#include #include "conf.h" #include "shl_dlist.h" @@ -91,6 +91,8 @@ struct kmscon_conf_t { char *term; /* reset environment */ bool reset_env; + /* Send delete when backspace is pressed */ + bool backspace_delete; /* terminal scroll-back buffer size */ unsigned int sb_size; @@ -141,6 +143,8 @@ struct kmscon_conf_t { struct conf_grab *grab_rotate_cw; /* rotate output counter-clock-wise grab */ struct conf_grab *grab_rotate_ccw; + /* reboot system grab */ + struct conf_grab *grab_reboot; /* Video Options */ /* use DRM if available */ @@ -178,8 +182,7 @@ struct kmscon_conf_t { int kmscon_conf_new(struct conf_ctx **out); void kmscon_conf_free(struct conf_ctx *ctx); int kmscon_conf_load_main(struct conf_ctx *ctx, int argc, char **argv); -int kmscon_conf_load_seat(struct conf_ctx *ctx, const struct conf_ctx *main, - const char *seat); +int kmscon_conf_load_seat(struct conf_ctx *ctx, const struct conf_ctx *main, const char *seat); static inline bool kmscon_conf_is_current_seat(struct kmscon_conf_t *conf) { diff --git a/src/kmscon_dummy.c b/src/kmscon_dummy.c index 9d9b5b0f..3107d76a 100644 --- a/src/kmscon_dummy.c +++ b/src/kmscon_dummy.c @@ -34,6 +34,7 @@ #include "kmscon_seat.h" #include "shl_dlist.h" #include "shl_log.h" +#include "uterm_video.h" #define LOG_SUBSYSTEM "dummy" @@ -50,19 +51,17 @@ struct kmscon_dummy { static void dummy_redraw(struct kmscon_dummy *dummy, struct display *d) { - struct uterm_mode *mode; unsigned int w, h; - mode = uterm_display_get_current(d->disp); - w = uterm_mode_get_width(mode); - h = uterm_mode_get_height(mode); + w = uterm_display_get_width(d->disp); + h = uterm_display_get_height(d->disp); uterm_display_fill(d->disp, 0, 0, 0, 0, 0, w, h); uterm_display_swap(d->disp, false); } -static int dummy_session_event(struct kmscon_session *session, - struct kmscon_session_event *ev, void *data) +static int dummy_session_event(struct kmscon_session *session, struct kmscon_session_event *ev, + void *data) { struct kmscon_dummy *dummy = data; struct display *d; @@ -82,7 +81,8 @@ static int dummy_session_event(struct kmscon_session *session, dummy_redraw(dummy, d); break; case KMSCON_SESSION_DISPLAY_GONE: - shl_dlist_for_each(iter, &dummy->displays) { + shl_dlist_for_each(iter, &dummy->displays) + { d = shl_dlist_entry(iter, struct display, list); if (d->disp != ev->disp) continue; @@ -93,7 +93,8 @@ static int dummy_session_event(struct kmscon_session *session, } break; case KMSCON_SESSION_DISPLAY_REFRESH: - shl_dlist_for_each(iter, &dummy->displays) { + shl_dlist_for_each(iter, &dummy->displays) + { d = shl_dlist_entry(iter, struct display, list); if (d->disp != ev->disp) continue; @@ -105,7 +106,8 @@ static int dummy_session_event(struct kmscon_session *session, break; case KMSCON_SESSION_ACTIVATE: dummy->active = true; - shl_dlist_for_each(iter, &dummy->displays) { + shl_dlist_for_each(iter, &dummy->displays) + { d = shl_dlist_entry(iter, struct display, list); dummy_redraw(dummy, d); } @@ -115,8 +117,7 @@ static int dummy_session_event(struct kmscon_session *session, break; case KMSCON_SESSION_UNREGISTER: while (!shl_dlist_empty(&dummy->displays)) { - d = shl_dlist_entry(dummy->displays.prev, - struct display, list); + d = shl_dlist_entry(dummy->displays.prev, struct display, list); shl_dlist_unlink(&d->list); free(d); } @@ -128,8 +129,7 @@ static int dummy_session_event(struct kmscon_session *session, return 0; } -int kmscon_dummy_register(struct kmscon_session **out, - struct kmscon_seat *seat) +int kmscon_dummy_register(struct kmscon_session **out, struct kmscon_seat *seat) { struct kmscon_dummy *dummy; int ret; @@ -143,8 +143,7 @@ int kmscon_dummy_register(struct kmscon_session **out, memset(dummy, 0, sizeof(*dummy)); shl_dlist_init(&dummy->displays); - ret = kmscon_seat_register_session(seat, &dummy->session, - dummy_session_event, dummy); + ret = kmscon_seat_register_session(seat, &dummy->session, dummy_session_event, dummy); if (ret) { log_error("cannot register session for dummy: %d", ret); goto err_free; diff --git a/src/kmscon_dummy.h b/src/kmscon_dummy.h index 9ffbe8d0..b4f3aa24 100644 --- a/src/kmscon_dummy.h +++ b/src/kmscon_dummy.h @@ -36,13 +36,11 @@ #ifdef BUILD_ENABLE_SESSION_DUMMY -int kmscon_dummy_register(struct kmscon_session **out, - struct kmscon_seat *seat); +int kmscon_dummy_register(struct kmscon_session **out, struct kmscon_seat *seat); #else /* !BUILD_ENABLE_SESSION_DUMMY */ -static inline int kmscon_dummy_register(struct kmscon_session **out, - struct kmscon_seat *seat) +static inline int kmscon_dummy_register(struct kmscon_session **out, struct kmscon_seat *seat) { return -EOPNOTSUPP; } diff --git a/src/kmscon_main.c b/src/kmscon_main.c index 7bb74c21..ecdccbc8 100644 --- a/src/kmscon_main.c +++ b/src/kmscon_main.c @@ -34,11 +34,11 @@ #include "conf.h" #include "eloop.h" #include "kmscon_conf.h" -#include "shl_module.h" #include "kmscon_seat.h" #include "shl_dlist.h" #include "shl_log.h" #include "shl_misc.h" +#include "shl_module.h" #include "text.h" #include "uterm_input.h" #include "uterm_monitor.h" @@ -85,8 +85,7 @@ const char be_drm3d[] = "drm3d"; const char be_drm2d[] = "drm2d"; const char be_fbdev[] = "fbdev"; -static int app_seat_event(struct kmscon_seat *s, unsigned int event, - void *data) +static int app_seat_event(struct kmscon_seat *s, unsigned int event, void *data) { struct app_seat *seat = data; struct kmscon_app *app = seat->app; @@ -97,13 +96,15 @@ static int app_seat_event(struct kmscon_seat *s, unsigned int event, case KMSCON_SEAT_FOREGROUND: seat->awake = true; - shl_dlist_for_each(iter, &seat->videos) { + shl_dlist_for_each(iter, &seat->videos) + { vid = shl_dlist_entry(iter, struct app_video, list); uterm_video_wake_up(vid->video); } break; case KMSCON_SEAT_BACKGROUND: - shl_dlist_for_each(iter, &seat->videos) { + shl_dlist_for_each(iter, &seat->videos) + { vid = shl_dlist_entry(iter, struct app_video, list); uterm_video_sleep(vid->video); } @@ -112,8 +113,7 @@ static int app_seat_event(struct kmscon_seat *s, unsigned int event, break; case KMSCON_SEAT_SLEEP: if (app->vt_exit_count > 0) { - log_debug("deactivating VT on exit, %d to go", - app->vt_exit_count - 1); + log_debug("deactivating VT on exit, %d to go", app->vt_exit_count - 1); if (!--app->vt_exit_count) ev_eloop_exit(app->eloop); } @@ -129,8 +129,7 @@ static int app_seat_event(struct kmscon_seat *s, unsigned int event, if (!app->conf->listen) { --app->running_seats; if (!app->running_seats) { - log_debug("seat HUP on %s in default-mode; exiting...", - seat->name); + log_debug("seat HUP on %s in default-mode; exiting...", seat->name); ev_eloop_exit(app->eloop); } else { log_debug("seat HUP on %s in default-mode; %u more running seats", @@ -146,8 +145,7 @@ static int app_seat_event(struct kmscon_seat *s, unsigned int event, * seat here and ignore it. * You can destroy and recreate the seat to make kmscon * pick it up again in listen-mode. */ - log_warning("seat HUP on %s in listen-mode; dropping seat...", - seat->name); + log_warning("seat HUP on %s in listen-mode; dropping seat...", seat->name); } break; @@ -156,8 +154,7 @@ static int app_seat_event(struct kmscon_seat *s, unsigned int event, return 0; } -static int app_seat_new(struct kmscon_app *app, const char *sname, - struct uterm_monitor_seat *useat) +static int app_seat_new(struct kmscon_app *app, const char *sname, struct uterm_monitor_seat *useat) { struct app_seat *seat; int ret; @@ -187,8 +184,7 @@ static int app_seat_new(struct kmscon_app *app, const char *sname, } if (!found) { - log_info("ignoring new seat %s as not specified in seat-list", - sname); + log_info("ignoring new seat %s as not specified in seat-list", sname); return -ERANGE; } @@ -215,15 +211,13 @@ static int app_seat_new(struct kmscon_app *app, const char *sname, if (!app->conf->listen) types |= UTERM_VT_REAL; - ret = kmscon_seat_new(&seat->seat, app->conf_ctx, app->eloop, app->vtm, - types, sname, app_seat_event, seat); + ret = kmscon_seat_new(&seat->seat, app->conf_ctx, app->eloop, app->vtm, types, sname, + app_seat_event, seat); if (ret) { if (ret == -ERANGE) - log_debug("ignoring seat %s as it already has a seat manager", - sname); + log_debug("ignoring seat %s as it already has a seat manager", sname); else - log_error("cannot create seat object on seat %s: %d", - sname, ret); + log_error("cannot create seat object on seat %s: %d", sname, ret); goto err_name; } seat->conf_ctx = kmscon_seat_get_conf(seat->seat); @@ -255,8 +249,7 @@ static void app_seat_free(struct app_seat *seat) free(seat); } -static void app_seat_video_event(struct uterm_video *video, - struct uterm_video_hotplug *ev, +static void app_seat_video_event(struct uterm_video *video, struct uterm_video_hotplug *ev, void *data) { struct app_video *vid = data; @@ -271,24 +264,20 @@ static void app_seat_video_event(struct uterm_video *video, break; case UTERM_REFRESH: if (!vid->seat->app->exiting) - kmscon_seat_refresh_display(vid->seat->seat, - ev->display); + kmscon_seat_refresh_display(vid->seat->seat, ev->display); break; } } -static bool app_seat_gpu_is_ignored(struct app_seat *seat, - unsigned int type, - bool drm_backed, - bool primary, - bool aux, - const char *node) +static bool app_seat_gpu_is_ignored(struct app_seat *seat, unsigned int type, bool drm_backed, + bool primary, bool aux, const char *node) { switch (type) { case UTERM_MONITOR_FBDEV: if (seat->conf->drm) { if (drm_backed) { - log_info("ignoring video device %s on seat %s as it is a DRM-fbdev device", + log_info("ignoring video device %s on seat %s as it is a DRM-fbdev " + "device", node, seat->name); return true; } @@ -296,25 +285,25 @@ static bool app_seat_gpu_is_ignored(struct app_seat *seat, break; case UTERM_MONITOR_DRM: if (!seat->conf->drm) { - log_info("ignoring video device %s on seat %s as it is a DRM device", - node, seat->name); + log_info("ignoring video device %s on seat %s as it is a DRM device", node, + seat->name); return true; } break; default: - log_info("ignoring unknown video device %s on seat %s", - node, seat->name); + log_info("ignoring unknown video device %s on seat %s", node, seat->name); return true; } if (seat->conf->gpus == KMSCON_GPU_PRIMARY && !primary) { - log_info("ignoring video device %s on seat %s as it is no primary GPU", - node, seat->name); + log_info("ignoring video device %s on seat %s as it is no primary GPU", node, + seat->name); return true; } if (seat->conf->gpus == KMSCON_GPU_AUX && !primary && !aux) { - log_info("ignoring video device %s on seat %s as it is neither a primary nor auxiliary GPU", + log_info("ignoring video device %s on seat %s as it is neither a primary nor " + "auxiliary GPU", node, seat->name); return true; } @@ -322,11 +311,8 @@ static bool app_seat_gpu_is_ignored(struct app_seat *seat, return false; } -static int app_seat_add_video(struct app_seat *seat, - unsigned int type, - unsigned int flags, - const char *node, - struct uterm_monitor_dev *udev) +static int app_seat_add_video(struct app_seat *seat, unsigned int type, unsigned int flags, + const char *node, struct uterm_monitor_dev *udev) { int ret; const char *backend; @@ -335,19 +321,16 @@ static int app_seat_add_video(struct app_seat *seat, if (seat->app->exiting) return -EBUSY; - if (app_seat_gpu_is_ignored(seat, type, - flags & UTERM_MONITOR_DRM_BACKED, - flags & UTERM_MONITOR_PRIMARY, - flags & UTERM_MONITOR_AUX, - node)) + if (app_seat_gpu_is_ignored(seat, type, flags & UTERM_MONITOR_DRM_BACKED, + flags & UTERM_MONITOR_PRIMARY, flags & UTERM_MONITOR_AUX, node)) return -ERANGE; log_debug("new video device %s on seat %s", node, seat->name); vid = malloc(sizeof(*vid)); if (!vid) { - log_error("cannot allocate memory for video device %s on seat %s", - node, seat->name); + log_error("cannot allocate memory for video device %s on seat %s", node, + seat->name); return -ENOMEM; } memset(vid, 0, sizeof(*vid)); @@ -356,8 +339,7 @@ static int app_seat_add_video(struct app_seat *seat, vid->node = strdup(node); if (!vid->node) { - log_error("cannot copy video device name %s on seat %s", - node, seat->name); + log_error("cannot copy video device name %s on seat %s", node, seat->name); ret = -ENOMEM; goto err_free; } @@ -374,21 +356,24 @@ static int app_seat_add_video(struct app_seat *seat, unsigned int desired_width = 0; unsigned int desired_height = 0; if (seat->conf->mode != NULL) { - int items_parsed = sscanf(seat->conf->mode, "%ux%u", &desired_width, &desired_height); + int items_parsed = + sscanf(seat->conf->mode, "%ux%u", &desired_width, &desired_height); if (items_parsed != 2) { - log_warning("The argument to --mode is not in the format x. Ignoring"); + log_warning("The argument to --mode is not in the format x. " + "Ignoring"); desired_width = 0; desired_height = 0; } } - ret = uterm_video_new(&vid->video, seat->app->eloop, node, backend, - desired_width, desired_height); + ret = uterm_video_new(&vid->video, seat->app->eloop, node, backend, desired_width, + desired_height, seat->conf->use_original_mode); if (ret) { if (backend == be_drm3d) { log_info("cannot create drm3d device %s on seat %s (%d); trying drm2d mode", vid->node, seat->name, ret); - ret = uterm_video_new(&vid->video, seat->app->eloop, - node, be_drm2d, desired_width, desired_height); + ret = uterm_video_new(&vid->video, seat->app->eloop, node, be_drm2d, + desired_width, desired_height, + seat->conf->use_original_mode); if (ret) goto err_node; } else { @@ -398,8 +383,8 @@ static int app_seat_add_video(struct app_seat *seat, ret = uterm_video_register_cb(vid->video, app_seat_video_event, vid); if (ret) { - log_error("cannot register video callback for device %s on seat %s: %d", - vid->node, seat->name, ret); + log_error("cannot register video callback for device %s on seat %s: %d", vid->node, + seat->name, ret); goto err_video; } @@ -440,9 +425,7 @@ static void app_seat_remove_video(struct app_seat *seat, struct app_video *vid) free(vid); } -static void app_monitor_event(struct uterm_monitor *mon, - struct uterm_monitor_event *ev, - void *data) +static void app_monitor_event(struct uterm_monitor *mon, struct uterm_monitor_event *ev, void *data) { struct kmscon_app *app = data; struct app_seat *seat; @@ -467,15 +450,13 @@ static void app_monitor_event(struct uterm_monitor *mon, switch (ev->dev_type) { case UTERM_MONITOR_DRM: case UTERM_MONITOR_FBDEV: - ret = app_seat_add_video(seat, ev->dev_type, - ev->dev_flags, - ev->dev_node, ev->dev); + ret = app_seat_add_video(seat, ev->dev_type, ev->dev_flags, ev->dev_node, + ev->dev); if (ret) return; break; case UTERM_MONITOR_INPUT: - log_debug("new input device %s on seat %s", - ev->dev_node, seat->name); + log_debug("new input device %s on seat %s", ev->dev_node, seat->name); kmscon_seat_add_input(seat->seat, ev->dev_node, seat->conf->mouse); break; } @@ -492,8 +473,7 @@ static void app_monitor_event(struct uterm_monitor *mon, app_seat_remove_video(seat, ev->dev_data); break; case UTERM_MONITOR_INPUT: - log_debug("free input device %s on seat %s", - ev->dev_node, seat->name); + log_debug("free input device %s on seat %s", ev->dev_node, seat->name); kmscon_seat_remove_input(seat->seat, ev->dev_node); break; } @@ -510,8 +490,8 @@ static void app_monitor_event(struct uterm_monitor *mon, if (!vid) return; - log_debug("video hotplug event on device %s on seat %s", - vid->node, seat->name); + log_debug("video hotplug event on device %s on seat %s", vid->node, + seat->name); uterm_video_poll(vid->video); break; } @@ -519,9 +499,7 @@ static void app_monitor_event(struct uterm_monitor *mon, } } -static void app_sig_generic(struct ev_eloop *eloop, - struct signalfd_siginfo *info, - void *data) +static void app_sig_generic(struct ev_eloop *eloop, struct signalfd_siginfo *info, void *data) { struct kmscon_app *app = data; @@ -529,22 +507,15 @@ static void app_sig_generic(struct ev_eloop *eloop, ev_eloop_exit(app->eloop); } -static void app_sig_ignore(struct ev_eloop *eloop, - struct signalfd_siginfo *info, - void *data) -{ -} +static void app_sig_ignore(struct ev_eloop *eloop, struct signalfd_siginfo *info, void *data) {} static void destroy_app(struct kmscon_app *app) { uterm_monitor_unref(app->mon); uterm_vt_master_unref(app->vtm); - ev_eloop_unregister_signal_cb(app->eloop, SIGPIPE, app_sig_ignore, - app); - ev_eloop_unregister_signal_cb(app->eloop, SIGINT, app_sig_generic, - app); - ev_eloop_unregister_signal_cb(app->eloop, SIGTERM, app_sig_generic, - app); + ev_eloop_unregister_signal_cb(app->eloop, SIGPIPE, app_sig_ignore, app); + ev_eloop_unregister_signal_cb(app->eloop, SIGINT, app_sig_generic, app); + ev_eloop_unregister_signal_cb(app->eloop, SIGTERM, app_sig_generic, app); ev_eloop_unref(app->eloop); } @@ -560,22 +531,19 @@ static int setup_app(struct kmscon_app *app) goto err_app; } - ret = ev_eloop_register_signal_cb(app->eloop, SIGTERM, - app_sig_generic, app); + ret = ev_eloop_register_signal_cb(app->eloop, SIGTERM, app_sig_generic, app); if (ret) { log_error("cannot register SIGTERM signal handler: %d", ret); goto err_app; } - ret = ev_eloop_register_signal_cb(app->eloop, SIGINT, - app_sig_generic, app); + ret = ev_eloop_register_signal_cb(app->eloop, SIGINT, app_sig_generic, app); if (ret) { log_error("cannot register SIGINT signal handler: %d", ret); goto err_app; } - ret = ev_eloop_register_signal_cb(app->eloop, SIGPIPE, - app_sig_ignore, app); + ret = ev_eloop_register_signal_cb(app->eloop, SIGPIPE, app_sig_ignore, app); if (ret) { log_error("cannot register SIGPIPE signal handler: %d", ret); goto err_app; @@ -641,7 +609,7 @@ int main(int argc, char **argv) goto err_unload; if (!app.conf->listen && !app.running_seats) { - log_notice("no running seats; exiting"); + log_notice("no running seats; exiting\n"); } else { log_debug("%u running seats after startup", app.running_seats); ev_eloop_run(app.eloop, -1); @@ -676,8 +644,7 @@ int main(int argc, char **argv) kmscon_conf_free(conf_ctx); err_out: if (ret) - log_err("cannot initialize kmscon, errno %d: %s", - ret, strerror(-ret)); + log_err("cannot initialize kmscon, errno %d: %s", ret, strerror(-ret)); log_info("exiting"); return -ret; } diff --git a/src/kmscon_mod_gltex.c b/src/kmscon_mod_gltex.c index 841786a5..55f1f829 100644 --- a/src/kmscon_mod_gltex.c +++ b/src/kmscon_mod_gltex.c @@ -30,9 +30,9 @@ #include #include -#include "text.h" -#include "shl_module_interface.h" #include "shl_log.h" +#include "shl_module_interface.h" +#include "text.h" #define LOG_SUBSYSTEM "mod_gltex" diff --git a/src/kmscon_mod_pango.c b/src/kmscon_mod_pango.c index bb42f0c3..7d156138 100644 --- a/src/kmscon_mod_pango.c +++ b/src/kmscon_mod_pango.c @@ -31,8 +31,8 @@ #include #include #include "font.h" -#include "shl_module_interface.h" #include "shl_log.h" +#include "shl_module_interface.h" #define LOG_SUBSYSTEM "mod_pango" diff --git a/src/kmscon_mod_unifont.c b/src/kmscon_mod_unifont.c index a2625527..77485925 100644 --- a/src/kmscon_mod_unifont.c +++ b/src/kmscon_mod_unifont.c @@ -31,8 +31,8 @@ #include #include #include "font.h" -#include "shl_module_interface.h" #include "shl_log.h" +#include "shl_module_interface.h" #define LOG_SUBSYSTEM "mod_unifont" diff --git a/src/kmscon_seat.c b/src/kmscon_seat.c index ade4433c..19b4e5db 100644 --- a/src/kmscon_seat.c +++ b/src/kmscon_seat.c @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include "conf.h" #include "eloop.h" #include "kmscon_conf.h" @@ -100,8 +102,7 @@ struct kmscon_seat { void *data; }; -static int session_call(struct kmscon_session *sess, unsigned int event, - struct uterm_display *disp) +static int session_call(struct kmscon_session *sess, unsigned int event, struct uterm_display *disp) { struct kmscon_session_event ev; @@ -126,20 +127,17 @@ static int session_call_deactivate(struct kmscon_session *sess) return session_call(sess, KMSCON_SESSION_DEACTIVATE, NULL); } -static void session_call_display_new(struct kmscon_session *sess, - struct uterm_display *disp) +static void session_call_display_new(struct kmscon_session *sess, struct uterm_display *disp) { session_call(sess, KMSCON_SESSION_DISPLAY_NEW, disp); } -static void session_call_display_gone(struct kmscon_session *sess, - struct uterm_display *disp) +static void session_call_display_gone(struct kmscon_session *sess, struct uterm_display *disp) { session_call(sess, KMSCON_SESSION_DISPLAY_GONE, disp); } -static void session_call_display_refresh(struct kmscon_session *sess, - struct uterm_display *disp) +static void session_call_display_refresh(struct kmscon_session *sess, struct uterm_display *disp) { session_call(sess, KMSCON_SESSION_DISPLAY_REFRESH, disp); } @@ -159,14 +157,9 @@ static void activate_display(struct kmscon_display *d) * but we should also allow the user to specify different modes in the * configuration files. */ if (uterm_display_get_state(d->disp) == UTERM_DISPLAY_INACTIVE) { - if (seat->conf->use_original_mode) - ret = uterm_display_activate(d->disp, - uterm_display_get_original(d->disp)); - else - ret = uterm_display_activate(d->disp, NULL); - + ret = uterm_display_activate(d->disp); if (ret == -EAGAIN) - ret = uterm_display_activate(d->disp, NULL); + ret = uterm_display_activate(d->disp); if (ret) return; @@ -174,10 +167,10 @@ static void activate_display(struct kmscon_display *d) ret = uterm_display_set_dpms(d->disp, UTERM_DPMS_ON); if (ret) - log_warning("cannot set DPMS state to on for display: %d", - ret); + log_warning("cannot set DPMS state to on for display: %d", ret); - shl_dlist_for_each_safe(iter, tmp, &seat->sessions) { + shl_dlist_for_each_safe(iter, tmp, &seat->sessions) + { s = shl_dlist_entry(iter, struct kmscon_session, list); session_call_display_new(s, d->disp); } @@ -198,15 +191,15 @@ static int seat_go_foreground(struct kmscon_seat *seat, bool force) if (seat->cb) { ret = seat->cb(seat, KMSCON_SEAT_FOREGROUND, seat->data); if (ret) { - log_warning("cannot put seat %s into foreground: %d", - seat->name, ret); + log_warning("cannot put seat %s into foreground: %d", seat->name, ret); return ret; } } seat->foreground = true; - shl_dlist_for_each(iter, &seat->displays) { + shl_dlist_for_each(iter, &seat->displays) + { d = shl_dlist_entry(iter, struct kmscon_display, list); activate_display(d); } @@ -226,8 +219,7 @@ static int seat_go_background(struct kmscon_seat *seat, bool force) if (seat->cb) { ret = seat->cb(seat, KMSCON_SEAT_BACKGROUND, seat->data); if (ret) { - log_warning("cannot put seat %s into background: %d", - seat->name, ret); + log_warning("cannot put seat %s into background: %d", seat->name, ret); return ret; } } @@ -255,8 +247,7 @@ static int seat_go_asleep(struct kmscon_seat *seat, bool force) if (seat->cb) { ret = seat->cb(seat, KMSCON_SEAT_SLEEP, seat->data); if (ret) { - log_warning("cannot put seat %s asleep: %d", - seat->name, ret); + log_warning("cannot put seat %s asleep: %d", seat->name, ret); if (!force) return ret; } @@ -278,8 +269,7 @@ static int seat_go_awake(struct kmscon_seat *seat) if (seat->cb) { ret = seat->cb(seat, KMSCON_SEAT_WAKE_UP, seat->data); if (ret) { - log_warning("cannot wake up seat %s: %d", seat->name, - ret); + log_warning("cannot wake up seat %s: %d", seat->name, ret); return ret; } } @@ -301,8 +291,7 @@ static int seat_run(struct kmscon_seat *seat) return 0; if (!seat->scheduled_sess) { - log_debug("no session scheduled to run (num %zu)", - seat->session_count); + log_debug("no session scheduled to run (num %zu)", seat->session_count); return -ENOENT; } session = seat->scheduled_sess; @@ -310,15 +299,15 @@ static int seat_run(struct kmscon_seat *seat) if (session->foreground && !seat->foreground) { ret = seat_go_foreground(seat, false); if (ret) { - log_warning("cannot put seat %s into foreground for session %p", - seat->name, session); + log_warning("cannot put seat %s into foreground for session %p", seat->name, + session); return ret; } } else if (!session->foreground && seat->foreground) { ret = seat_go_background(seat, false); if (ret) { - log_warning("cannot put seat %s into background for session %p", - seat->name, session); + log_warning("cannot put seat %s into background for session %p", seat->name, + session); return ret; } } @@ -355,11 +344,9 @@ static int seat_pause(struct kmscon_seat *seat, bool force) ret = session_call_deactivate(seat->current_sess); if (ret) { if (ret == -EINPROGRESS) - log_debug("pending deactivation for session %p", - seat->current_sess); + log_debug("pending deactivation for session %p", seat->current_sess); else - log_warning("cannot deactivate session %p: %d", - seat->current_sess, ret); + log_warning("cannot deactivate session %p: %d", seat->current_sess, ret); if (!force) return ret; } @@ -387,7 +374,8 @@ static void seat_reschedule(struct kmscon_seat *seat) else start = &seat->sessions; - shl_dlist_for_each_but_one(iter, start, &seat->sessions) { + shl_dlist_for_each_but_one(iter, start, &seat->sessions) + { sess = shl_dlist_entry(iter, struct kmscon_session, list); if (sess == seat->dummy_sess || !sess->enabled) continue; @@ -403,8 +391,7 @@ static void seat_reschedule(struct kmscon_seat *seat) static bool seat_has_schedule(struct kmscon_seat *seat) { - return seat->scheduled_sess && - seat->scheduled_sess != seat->current_sess; + return seat->scheduled_sess && seat->scheduled_sess != seat->current_sess; } static int seat_switch(struct kmscon_seat *seat) @@ -432,11 +419,11 @@ static void seat_next(struct kmscon_seat *seat) return; next = NULL; - if (!seat->current_sess && seat->dummy_sess && - seat->dummy_sess->enabled) + if (!seat->current_sess && seat->dummy_sess && seat->dummy_sess->enabled) next = seat->dummy_sess; - shl_dlist_for_each_but_one(iter, cur, &seat->sessions) { + shl_dlist_for_each_but_one(iter, cur, &seat->sessions) + { s = shl_dlist_entry(iter, struct kmscon_session, list); if (!s->enabled || seat->dummy_sess == s) continue; @@ -465,11 +452,11 @@ static void seat_prev(struct kmscon_seat *seat) return; prev = NULL; - if (!seat->current_sess && seat->dummy_sess && - seat->dummy_sess->enabled) + if (!seat->current_sess && seat->dummy_sess && seat->dummy_sess->enabled) prev = seat->dummy_sess; - shl_dlist_for_each_reverse_but_one(iter, cur, &seat->sessions) { + shl_dlist_for_each_reverse_but_one(iter, cur, &seat->sessions) + { s = shl_dlist_entry(iter, struct kmscon_session, list); if (!s->enabled || seat->dummy_sess == s) continue; @@ -485,8 +472,7 @@ static void seat_prev(struct kmscon_seat *seat) seat_switch(seat); } -static int seat_add_display(struct kmscon_seat *seat, - struct uterm_display *disp) +static int seat_add_display(struct kmscon_seat *seat, struct uterm_display *disp) { struct kmscon_display *d; @@ -505,8 +491,7 @@ static int seat_add_display(struct kmscon_seat *seat, return 0; } -static void seat_remove_display(struct kmscon_seat *seat, - struct kmscon_display *d) +static void seat_remove_display(struct kmscon_seat *seat, struct kmscon_display *d) { struct shl_dlist *iter, *tmp; struct kmscon_session *s; @@ -516,7 +501,8 @@ static void seat_remove_display(struct kmscon_seat *seat, shl_dlist_unlink(&d->list); if (d->activated) { - shl_dlist_for_each_safe(iter, tmp, &seat->sessions) { + shl_dlist_for_each_safe(iter, tmp, &seat->sessions) + { s = shl_dlist_entry(iter, struct kmscon_session, list); session_call_display_gone(s, d->disp); } @@ -526,8 +512,7 @@ static void seat_remove_display(struct kmscon_seat *seat, free(d); } -static void seat_refresh_display(struct kmscon_seat *seat, - struct kmscon_display *d) +static void seat_refresh_display(struct kmscon_seat *seat, struct kmscon_display *d) { struct shl_dlist *iter; struct kmscon_session *s; @@ -535,15 +520,15 @@ static void seat_refresh_display(struct kmscon_seat *seat, log_debug("refresh display %p from seat %s", d->disp, seat->name); if (d->activated) { - shl_dlist_for_each(iter, &seat->sessions) { + shl_dlist_for_each(iter, &seat->sessions) + { s = shl_dlist_entry(iter, struct kmscon_session, list); session_call_display_refresh(s, d->disp); } } } -static int seat_vt_event(struct uterm_vt *vt, struct uterm_vt_event *ev, - void *data) +static int seat_vt_event(struct uterm_vt *vt, struct uterm_vt_event *ev, void *data) { struct kmscon_seat *seat = data; int ret; @@ -576,8 +561,18 @@ static int seat_vt_event(struct uterm_vt *vt, struct uterm_vt_event *ev, return 0; } -static void seat_input_event(struct uterm_input *input, - struct uterm_input_key_event *ev, +static void seat_trigger_reboot(struct kmscon_seat *seat) +{ + log_warning("reboot triggered by keyboard shortcut on seat %s", seat->name); + + sync(); /* Synchronize disk buffers */ + + if (reboot(RB_AUTOBOOT) < 0) { + log_error("failed to reboot system: %m"); + } +} + +static void seat_input_event(struct uterm_input *input, struct uterm_input_key_event *ev, void *data) { struct kmscon_seat *seat = data; @@ -587,24 +582,22 @@ static void seat_input_event(struct uterm_input *input, if (ev->handled || !seat->awake) return; - if (conf_grab_matches(seat->conf->grab_session_next, - ev->mods, ev->num_syms, ev->keysyms)) { + if (conf_grab_matches(seat->conf->grab_session_next, ev->mods, ev->num_syms, ev->keysyms)) { ev->handled = true; if (!seat->conf->session_control) return; seat_next(seat); return; } - if (conf_grab_matches(seat->conf->grab_session_prev, - ev->mods, ev->num_syms, ev->keysyms)) { + if (conf_grab_matches(seat->conf->grab_session_prev, ev->mods, ev->num_syms, ev->keysyms)) { ev->handled = true; if (!seat->conf->session_control) return; seat_prev(seat); return; } - if (conf_grab_matches(seat->conf->grab_session_dummy, - ev->mods, ev->num_syms, ev->keysyms)) { + if (conf_grab_matches(seat->conf->grab_session_dummy, ev->mods, ev->num_syms, + ev->keysyms)) { ev->handled = true; if (!seat->conf->session_control) return; @@ -612,8 +605,8 @@ static void seat_input_event(struct uterm_input *input, seat_switch(seat); return; } - if (conf_grab_matches(seat->conf->grab_session_close, - ev->mods, ev->num_syms, ev->keysyms)) { + if (conf_grab_matches(seat->conf->grab_session_close, ev->mods, ev->num_syms, + ev->keysyms)) { ev->handled = true; if (!seat->conf->session_control) return; @@ -638,13 +631,11 @@ static void seat_input_event(struct uterm_input *input, kmscon_session_unregister(s); return; } - if (conf_grab_matches(seat->conf->grab_terminal_new, - ev->mods, ev->num_syms, ev->keysyms)) { + if (conf_grab_matches(seat->conf->grab_terminal_new, ev->mods, ev->num_syms, ev->keysyms)) { ev->handled = true; if (!seat->conf->session_control) return; - ret = kmscon_terminal_register(&s, seat, - uterm_vt_get_num(seat->vt)); + ret = kmscon_terminal_register(&s, seat, uterm_vt_get_num(seat->vt)); if (ret == -EOPNOTSUPP) { log_notice("terminal support not compiled in"); } else if (ret) { @@ -656,6 +647,12 @@ static void seat_input_event(struct uterm_input *input, } return; } + if (seat->conf->grab_reboot && + conf_grab_matches(seat->conf->grab_reboot, ev->mods, ev->num_syms, ev->keysyms)) { + ev->handled = true; + seat_trigger_reboot(seat); + return; + } } /* @@ -678,14 +675,9 @@ static const char *find_locale(void) return locale; } -int kmscon_seat_new(struct kmscon_seat **out, - struct conf_ctx *main_conf, - struct ev_eloop *eloop, - struct uterm_vt_master *vtm, - unsigned int vt_types, - const char *seatname, - kmscon_seat_cb_t cb, - void *data) +int kmscon_seat_new(struct kmscon_seat **out, struct conf_ctx *main_conf, struct ev_eloop *eloop, + struct uterm_vt_master *vtm, unsigned int vt_types, const char *seatname, + kmscon_seat_cb_t cb, void *data) { struct kmscon_seat *seat; int ret; @@ -723,8 +715,7 @@ int kmscon_seat_new(struct kmscon_seat **out, ret = kmscon_conf_load_seat(seat->conf_ctx, main_conf, seat->name); if (ret) { - log_error("cannot parse seat configuration on seat %s: %d", - seat->name, ret); + log_error("cannot parse seat configuration on seat %s: %d", seat->name, ret); goto err_conf; } @@ -737,30 +728,23 @@ int kmscon_seat_new(struct kmscon_seat **out, if (seat->conf->xkb_keymap && *seat->conf->xkb_keymap) { ret = shl_read_file(seat->conf->xkb_keymap, &keymap, NULL); if (ret) - log_error("cannot read keymap file %s: %d", - seat->conf->xkb_keymap, ret); + log_error("cannot read keymap file %s: %d", seat->conf->xkb_keymap, ret); } compose_file = NULL; compose_file_len = 0; if (seat->conf->xkb_compose_file && *seat->conf->xkb_compose_file) { - ret = shl_read_file(seat->conf->xkb_compose_file, - &compose_file, &compose_file_len); + ret = shl_read_file(seat->conf->xkb_compose_file, &compose_file, &compose_file_len); if (ret) - log_error("cannot read compose file %s: %d", - seat->conf->xkb_compose_file, ret); + log_error("cannot read compose file %s: %d", seat->conf->xkb_compose_file, + ret); } - ret = uterm_input_new(&seat->input, seat->eloop, - seat->conf->xkb_model, - seat->conf->xkb_layout, - seat->conf->xkb_variant, - seat->conf->xkb_options, - locale, keymap, compose_file, - compose_file_len, - seat->conf->xkb_repeat_delay, - seat->conf->xkb_repeat_rate, - log_llog, NULL); + ret = uterm_input_new(&seat->input, seat->eloop, seat->conf->xkb_model, + seat->conf->xkb_layout, seat->conf->xkb_variant, + seat->conf->xkb_options, locale, keymap, compose_file, + compose_file_len, seat->conf->xkb_repeat_delay, + seat->conf->xkb_repeat_rate, log_llog, NULL); free(keymap); if (ret) @@ -770,15 +754,14 @@ int kmscon_seat_new(struct kmscon_seat **out, if (ret) goto err_input; - ret = uterm_vt_allocate(seat->vtm, &seat->vt, - vt_types, seat->name, - seat->input, seat->conf->vt, seat_vt_event, - seat); + ret = uterm_vt_allocate(seat->vtm, &seat->vt, vt_types, seat->name, seat->input, + seat->conf->vt, seat_vt_event, seat); if (ret) goto err_input_cb; if (seat->conf->session_control && uterm_vt_get_type(seat->vt) == UTERM_VT_REAL) { - log_warning("session control cannot be configured on real VT, disabling session control"); + log_warning("session control cannot be configured on real VT, disabling session " + "control"); seat->conf->session_control = false; } @@ -811,25 +794,20 @@ void kmscon_seat_free(struct kmscon_seat *seat) ret = seat_pause(seat, true); if (ret) - log_warning("destroying seat %s while session %p is active", - seat->name, seat->current_sess); + log_warning("destroying seat %s while session %p is active", seat->name, + seat->current_sess); ret = seat_go_asleep(seat, true); if (ret) - log_warning("destroying seat %s while still awake: %d", - seat->name, ret); + log_warning("destroying seat %s while still awake: %d", seat->name, ret); while (!shl_dlist_empty(&seat->sessions)) { - s = shl_dlist_entry(seat->sessions.next, - struct kmscon_session, - list); + s = shl_dlist_entry(seat->sessions.next, struct kmscon_session, list); kmscon_session_unregister(s); } while (!shl_dlist_empty(&seat->displays)) { - d = shl_dlist_entry(seat->displays.next, - struct kmscon_display, - list); + d = shl_dlist_entry(seat->displays.next, struct kmscon_display, list); seat_remove_display(seat, d); } @@ -862,8 +840,7 @@ void kmscon_seat_startup(struct kmscon_seat *seat) } if (seat->conf->terminal_session) { - ret = kmscon_terminal_register(&s, seat, - uterm_vt_get_num(seat->vt)); + ret = kmscon_terminal_register(&s, seat, uterm_vt_get_num(seat->vt)); if (ret == -EOPNOTSUPP) log_notice("terminal support not compiled in"); else if (ret) @@ -872,13 +849,11 @@ void kmscon_seat_startup(struct kmscon_seat *seat) kmscon_session_enable(s); } - if (seat->conf->switchvt || - uterm_vt_get_type(seat->vt) == UTERM_VT_FAKE) + if (seat->conf->switchvt || uterm_vt_get_type(seat->vt) == UTERM_VT_FAKE) uterm_vt_activate(seat->vt); } -int kmscon_seat_add_display(struct kmscon_seat *seat, - struct uterm_display *disp) +int kmscon_seat_add_display(struct kmscon_seat *seat, struct uterm_display *disp) { if (!seat || !disp) return -EINVAL; @@ -886,8 +861,7 @@ int kmscon_seat_add_display(struct kmscon_seat *seat, return seat_add_display(seat, disp); } -void kmscon_seat_remove_display(struct kmscon_seat *seat, - struct uterm_display *disp) +void kmscon_seat_remove_display(struct kmscon_seat *seat, struct uterm_display *disp) { struct shl_dlist *iter; struct kmscon_display *d; @@ -895,7 +869,8 @@ void kmscon_seat_remove_display(struct kmscon_seat *seat, if (!seat || !disp) return; - shl_dlist_for_each(iter, &seat->displays) { + shl_dlist_for_each(iter, &seat->displays) + { d = shl_dlist_entry(iter, struct kmscon_display, list); if (d->disp != disp) continue; @@ -905,8 +880,7 @@ void kmscon_seat_remove_display(struct kmscon_seat *seat, } } -void kmscon_seat_refresh_display(struct kmscon_seat *seat, - struct uterm_display *disp) +void kmscon_seat_refresh_display(struct kmscon_seat *seat, struct uterm_display *disp) { struct shl_dlist *iter; struct kmscon_display *d; @@ -914,7 +888,8 @@ void kmscon_seat_refresh_display(struct kmscon_seat *seat, if (!seat || !disp) return; - shl_dlist_for_each(iter, &seat->displays) { + shl_dlist_for_each(iter, &seat->displays) + { d = shl_dlist_entry(iter, struct kmscon_display, list); if (d->disp != disp) continue; @@ -982,10 +957,10 @@ void kmscon_seat_schedule(struct kmscon_seat *seat, unsigned int id) return; next = seat->dummy_sess; - shl_dlist_for_each(iter, &seat->sessions) { + shl_dlist_for_each(iter, &seat->sessions) + { s = shl_dlist_entry(iter, struct kmscon_session, list); - if (!s->enabled || seat->dummy_sess == s || - seat->current_sess == s) + if (!s->enabled || seat->dummy_sess == s || seat->current_sess == s) continue; next = s; @@ -998,10 +973,8 @@ void kmscon_seat_schedule(struct kmscon_seat *seat, unsigned int id) seat_switch(seat); } -int kmscon_seat_register_session(struct kmscon_seat *seat, - struct kmscon_session **out, - kmscon_session_cb_t cb, - void *data) +int kmscon_seat_register_session(struct kmscon_seat *seat, struct kmscon_session **out, + kmscon_session_cb_t cb, void *data) { struct kmscon_session *sess; struct shl_dlist *iter; @@ -1010,8 +983,7 @@ int kmscon_seat_register_session(struct kmscon_seat *seat, if (!seat || !out) return -EINVAL; - if (seat->conf->session_max && - seat->session_count >= seat->conf->session_max) { + if (seat->conf->session_max && seat->session_count >= seat->conf->session_max) { log_warning("maximum number of sessions reached (%d), dropping new session", seat->conf->session_max); return -EOVERFLOW; @@ -1019,8 +991,7 @@ int kmscon_seat_register_session(struct kmscon_seat *seat, sess = malloc(sizeof(*sess)); if (!sess) { - log_error("cannot allocate memory for new session on seat %s", - seat->name); + log_error("cannot allocate memory for new session on seat %s", seat->name); return -ENOMEM; } @@ -1042,7 +1013,8 @@ int kmscon_seat_register_session(struct kmscon_seat *seat, ++seat->session_count; *out = sess; - shl_dlist_for_each(iter, &seat->displays) { + shl_dlist_for_each(iter, &seat->displays) + { d = shl_dlist_entry(iter, struct kmscon_display, list); session_call_display_new(sess, d->disp); } @@ -1088,7 +1060,8 @@ void kmscon_session_unregister(struct kmscon_session *sess) ret = seat_pause(seat, true); if (ret) { forced = true; - log_warning("unregistering active session %p; skipping automatic session-switch", + log_warning("unregistering active session %p; skipping automatic " + "session-switch", sess); } } @@ -1194,8 +1167,7 @@ void kmscon_session_enable(struct kmscon_session *sess) log_debug("enable session %p", sess); sess->enabled = true; if (sess->seat && - (!sess->seat->current_sess || - sess->seat->current_sess == sess->seat->dummy_sess)) { + (!sess->seat->current_sess || sess->seat->current_sess == sess->seat->dummy_sess)) { sess->seat->scheduled_sess = sess; if (seat_has_schedule(sess->seat)) seat_switch(sess->seat); @@ -1230,8 +1202,7 @@ void kmscon_session_notify_deactivated(struct kmscon_session *sess) return; sched = seat->async_schedule; - log_debug("session %p notified core about deactivation (schedule: %u)", - sess, sched); + log_debug("session %p notified core about deactivation (schedule: %u)", sess, sched); session_deactivate(sess); seat_reschedule(seat); diff --git a/src/kmscon_seat.h b/src/kmscon_seat.h index a179caf4..1efb6a63 100644 --- a/src/kmscon_seat.h +++ b/src/kmscon_seat.h @@ -51,9 +51,7 @@ enum kmscon_seat_event { KMSCON_SEAT_HUP, }; -typedef int (*kmscon_seat_cb_t) (struct kmscon_seat *seat, - unsigned int event, - void *data); +typedef int (*kmscon_seat_cb_t)(struct kmscon_seat *seat, unsigned int event, void *data); enum kmscon_session_event_type { KMSCON_SESSION_DISPLAY_NEW, @@ -69,27 +67,18 @@ struct kmscon_session_event { struct uterm_display *disp; }; -typedef int (*kmscon_session_cb_t) (struct kmscon_session *session, - struct kmscon_session_event *event, - void *data); - -int kmscon_seat_new(struct kmscon_seat **out, - struct conf_ctx *main_conf, - struct ev_eloop *eloop, - struct uterm_vt_master *vtm, - unsigned int vt_types, - const char *seatname, - kmscon_seat_cb_t cb, - void *data); +typedef int (*kmscon_session_cb_t)(struct kmscon_session *session, + struct kmscon_session_event *event, void *data); + +int kmscon_seat_new(struct kmscon_seat **out, struct conf_ctx *main_conf, struct ev_eloop *eloop, + struct uterm_vt_master *vtm, unsigned int vt_types, const char *seatname, + kmscon_seat_cb_t cb, void *data); void kmscon_seat_free(struct kmscon_seat *seat); void kmscon_seat_startup(struct kmscon_seat *seat); -int kmscon_seat_add_display(struct kmscon_seat *seat, - struct uterm_display *disp); -void kmscon_seat_remove_display(struct kmscon_seat *seat, - struct uterm_display *disp); -void kmscon_seat_refresh_display(struct kmscon_seat *seat, - struct uterm_display *disp); +int kmscon_seat_add_display(struct kmscon_seat *seat, struct uterm_display *disp); +void kmscon_seat_remove_display(struct kmscon_seat *seat, struct uterm_display *disp); +void kmscon_seat_refresh_display(struct kmscon_seat *seat, struct uterm_display *disp); int kmscon_seat_add_input(struct kmscon_seat *seat, const char *node, bool mouse); void kmscon_seat_remove_input(struct kmscon_seat *seat, const char *node); @@ -100,10 +89,8 @@ struct conf_ctx *kmscon_seat_get_conf(struct kmscon_seat *seat); void kmscon_seat_schedule(struct kmscon_seat *seat, unsigned int id); -int kmscon_seat_register_session(struct kmscon_seat *seat, - struct kmscon_session **out, - kmscon_session_cb_t cb, - void *data); +int kmscon_seat_register_session(struct kmscon_seat *seat, struct kmscon_session **out, + kmscon_session_cb_t cb, void *data); void kmscon_session_ref(struct kmscon_session *sess); void kmscon_session_unref(struct kmscon_session *sess); diff --git a/src/kmscon_terminal.c b/src/kmscon_terminal.c index f2ae227c..8d634c0b 100644 --- a/src/kmscon_terminal.c +++ b/src/kmscon_terminal.c @@ -101,16 +101,14 @@ struct kmscon_terminal { static void do_clear_margins(struct screen *scr) { unsigned int w, h, sw, sh; - struct uterm_mode *mode; struct tsm_screen_attr attr; int dh, dw; - mode = uterm_display_get_current(scr->disp); - if (!mode) - return; + sw = uterm_display_get_width(scr->disp); + sh = uterm_display_get_height(scr->disp); - sw = uterm_mode_get_width(mode); - sh = uterm_mode_get_height(mode); + if (!sw || !sh) + return; tsm_vte_get_def_attr(scr->term->vte, &attr); @@ -126,26 +124,22 @@ static void do_clear_margins(struct screen *scr) if (dw) { if (scr->txt->orientation == OR_NORMAL || scr->txt->orientation == OR_LEFT) - uterm_display_fill(scr->disp, attr.br, attr.bg, attr.bb, - w, 0,dw, sh); + uterm_display_fill(scr->disp, attr.br, attr.bg, attr.bb, w, 0, dw, sh); else - uterm_display_fill(scr->disp, attr.br, attr.bg, attr.bb, - 0, 0,dw, sh); + uterm_display_fill(scr->disp, attr.br, attr.bg, attr.bb, 0, 0, dw, sh); } if (dh) { if (scr->txt->orientation == OR_NORMAL || scr->txt->orientation == OR_RIGHT) - uterm_display_fill(scr->disp, attr.br, attr.bg, attr.bb, - 0, h, sw, dh); + uterm_display_fill(scr->disp, attr.br, attr.bg, attr.bb, 0, h, sw, dh); else - uterm_display_fill(scr->disp, attr.br, attr.bg, attr.bb, - 0, 0, sw, dh); + uterm_display_fill(scr->disp, attr.br, attr.bg, attr.bb, 0, 0, sw, dh); } } static int font_set(struct kmscon_terminal *term); - -static void coord_to_cell(struct kmscon_terminal *term, int32_t x, int32_t y, unsigned int *posx, unsigned int *posy) +static void coord_to_cell(struct kmscon_terminal *term, int32_t x, int32_t y, unsigned int *posx, + unsigned int *posy) { int fw = term->font->attr.width; int fh = term->font->attr.height; @@ -192,7 +186,7 @@ static void do_redraw_screen(struct screen *scr) if (ret == -EAGAIN) { uterm_display_deactivate(scr->disp); - ret = uterm_display_activate(scr->disp, NULL); + ret = uterm_display_activate(scr->disp); if (!ret) ret = font_set(scr->term); if (!ret) @@ -226,7 +220,8 @@ static void redraw_all(struct kmscon_terminal *term) if (!term->awake) return; - shl_dlist_for_each(iter, &term->screens) { + shl_dlist_for_each(iter, &term->screens) + { scr = shl_dlist_entry(iter, struct screen, list); redraw_screen(scr); } @@ -237,7 +232,8 @@ static bool has_kms_display(struct kmscon_terminal *term) struct shl_dlist *iter; struct screen *scr; - shl_dlist_for_each(iter, &term->screens) { + shl_dlist_for_each(iter, &term->screens) + { scr = shl_dlist_entry(iter, struct screen, list); if (uterm_display_is_drm(scr->disp)) return true; @@ -254,7 +250,6 @@ static void update_pointer_max_all(struct kmscon_terminal *term) { struct shl_dlist *iter; struct screen *scr; - struct uterm_mode *mode; unsigned int max_x = INT_MAX; unsigned int max_y = INT_MAX; unsigned int sw, sh; @@ -262,19 +257,16 @@ static void update_pointer_max_all(struct kmscon_terminal *term) if (!term->awake) return; - shl_dlist_for_each(iter, &term->screens) { + shl_dlist_for_each(iter, &term->screens) + { scr = shl_dlist_entry(iter, struct screen, list); - mode = uterm_display_get_current(scr->disp); - if (!mode) - continue; - if (scr->txt->orientation == OR_NORMAL || scr->txt->orientation == OR_UPSIDE_DOWN) { - sw = uterm_mode_get_width(mode); - sh = uterm_mode_get_height(mode); + sw = uterm_display_get_width(scr->disp); + sh = uterm_display_get_height(scr->disp); } else { - sw = uterm_mode_get_height(mode); - sh = uterm_mode_get_width(mode); + sw = uterm_display_get_height(scr->disp); + sh = uterm_display_get_width(scr->disp); } if (!sw || !sh) continue; @@ -296,7 +288,8 @@ static void redraw_all_test(struct kmscon_terminal *term) if (!term->awake) return; - shl_dlist_for_each(iter, &term->screens) { + shl_dlist_for_each(iter, &term->screens) + { scr = shl_dlist_entry(iter, struct screen, list); if (uterm_display_is_swapping(scr->disp)) scr->swapping = true; @@ -304,8 +297,7 @@ static void redraw_all_test(struct kmscon_terminal *term) } } -static void display_event(struct uterm_display *disp, - struct uterm_display_event *ev, void *data) +static void display_event(struct uterm_display *disp, struct uterm_display_event *ev, void *data) { struct screen *scr = data; @@ -317,16 +309,14 @@ static void display_event(struct uterm_display *disp, do_redraw_screen(scr); } -static void osc_event(struct tsm_vte *vte, const char *osc_string, - size_t osc_len, void *data) +static void osc_event(struct tsm_vte *vte, const char *osc_string, size_t osc_len, void *data) { struct kmscon_terminal *term = data; if (strcmp(osc_string, "setBackground") == 0) { log_info("Got OSC setBackground"); kmscon_session_set_background(term->session); - } - else if (strcmp(osc_string, "setForeground") == 0) { + } else if (strcmp(osc_string, "setForeground") == 0) { log_info("Got OSC setForeground"); kmscon_session_set_foreground(term->session); } @@ -354,8 +344,7 @@ static void mouse_event(struct tsm_vte *vte, enum tsm_mouse_track_mode track_mod * though the size might have changed. force = true and notify = false doesn't * make any sense, though. */ -static void terminal_resize(struct kmscon_terminal *term, - unsigned int cols, unsigned int rows, +static void terminal_resize(struct kmscon_terminal *term, unsigned int cols, unsigned int rows, bool force, bool notify) { bool resize = false; @@ -389,14 +378,12 @@ static int font_set(struct kmscon_terminal *term) struct screen *ent; term->font_attr.bold = false; - ret = kmscon_font_find(&font, &term->font_attr, - term->conf->font_engine); + ret = kmscon_font_find(&font, &term->font_attr, term->conf->font_engine); if (ret) return ret; term->font_attr.bold = true; - ret = kmscon_font_find(&bold_font, &term->font_attr, - term->conf->font_engine); + ret = kmscon_font_find(&bold_font, &term->font_attr, term->conf->font_engine); if (ret) { log_warning("cannot create bold font: %d", ret); bold_font = font; @@ -410,18 +397,16 @@ static int font_set(struct kmscon_terminal *term) term->min_cols = 0; term->min_rows = 0; - shl_dlist_for_each(iter, &term->screens) { + shl_dlist_for_each(iter, &term->screens) + { ent = shl_dlist_entry(iter, struct screen, list); ret = kmscon_text_set(ent->txt, font, bold_font, ent->disp); if (ret) - log_warning("cannot change text-renderer font: %d", - ret); + log_warning("cannot change text-renderer font: %d", ret); - terminal_resize(term, - kmscon_text_get_cols(ent->txt), - kmscon_text_get_rows(ent->txt), - false, false); + terminal_resize(term, kmscon_text_get_cols(ent->txt), + kmscon_text_get_rows(ent->txt), false, false); } terminal_resize(term, 0, 0, true, true); @@ -440,15 +425,14 @@ static void rotate_cw_all(struct kmscon_terminal *term) struct shl_dlist *iter; struct screen *scr; - shl_dlist_for_each(iter, &term->screens) { + shl_dlist_for_each(iter, &term->screens) + { scr = shl_dlist_entry(iter, struct screen, list); rotate_cw_screen(scr); term->min_cols = 0; term->min_rows = 0; - terminal_resize(term, - kmscon_text_get_cols(scr->txt), - kmscon_text_get_rows(scr->txt), - true, true); + terminal_resize(term, kmscon_text_get_cols(scr->txt), + kmscon_text_get_rows(scr->txt), true, true); } } @@ -467,15 +451,14 @@ static void rotate_ccw_all(struct kmscon_terminal *term) struct shl_dlist *iter; struct screen *scr; - shl_dlist_for_each(iter, &term->screens) { + shl_dlist_for_each(iter, &term->screens) + { scr = shl_dlist_entry(iter, struct screen, list); rotate_ccw_screen(scr); term->min_cols = 0; term->min_rows = 0; - terminal_resize(term, - kmscon_text_get_cols(scr->txt), - kmscon_text_get_rows(scr->txt), - true, true); + terminal_resize(term, kmscon_text_get_cols(scr->txt), + kmscon_text_get_rows(scr->txt), true, true); } } @@ -487,7 +470,8 @@ static int add_display(struct kmscon_terminal *term, struct uterm_display *disp) const char *be; bool opengl; - shl_dlist_for_each(iter, &term->screens) { + shl_dlist_for_each(iter, &term->screens) + { scr = shl_dlist_entry(iter, struct screen, list); if (scr->disp == disp) return 0; @@ -522,23 +506,19 @@ static int add_display(struct kmscon_terminal *term, struct uterm_display *disp) goto err_cb; } - ret = kmscon_text_set(scr->txt, term->font, term->bold_font, - scr->disp); + ret = kmscon_text_set(scr->txt, term->font, term->bold_font, scr->disp); if (ret) { log_error("cannot set text-renderer parameters"); goto err_text; } - terminal_resize(term, - kmscon_text_get_cols(scr->txt), - kmscon_text_get_rows(scr->txt), - false, true); + terminal_resize(term, kmscon_text_get_cols(scr->txt), kmscon_text_get_rows(scr->txt), false, + true); shl_dlist_link(&term->screens, &scr->list); - log_notice("Using video backend [%s] with text renderer [%s] and font engine [%s]", - uterm_display_backend_name(disp), scr->txt->ops->name, - term->font->ops->name); + log_notice("Using video backend [%s] with text renderer [%s] and font engine [%s]\n", + uterm_display_backend_name(disp), scr->txt->ops->name, term->font->ops->name); log_debug("added display %p to terminal %p", disp, term); redraw_screen(scr); @@ -572,12 +552,11 @@ static void free_screen(struct screen *scr, bool update) term->min_cols = 0; term->min_rows = 0; - shl_dlist_for_each(iter, &term->screens) { + shl_dlist_for_each(iter, &term->screens) + { ent = shl_dlist_entry(iter, struct screen, list); - terminal_resize(term, - kmscon_text_get_cols(ent->txt), - kmscon_text_get_rows(ent->txt), - false, false); + terminal_resize(term, kmscon_text_get_cols(ent->txt), + kmscon_text_get_rows(ent->txt), false, false); } terminal_resize(term, 0, 0, true, true); @@ -588,7 +567,8 @@ static void rm_display(struct kmscon_terminal *term, struct uterm_display *disp) struct shl_dlist *iter; struct screen *scr; - shl_dlist_for_each(iter, &term->screens) { + shl_dlist_for_each(iter, &term->screens) + { scr = shl_dlist_entry(iter, struct screen, list); if (scr->disp == disp) break; @@ -601,45 +581,39 @@ static void rm_display(struct kmscon_terminal *term, struct uterm_display *disp) free_screen(scr, true); } -static void input_event(struct uterm_input *input, - struct uterm_input_key_event *ev, - void *data) +static void input_event(struct uterm_input *input, struct uterm_input_key_event *ev, void *data) { struct kmscon_terminal *term = data; - if (!term->opened || !term->awake || ev->handled || !kmscon_session_get_foreground(term->session)) + if (!term->opened || !term->awake || ev->handled || + !kmscon_session_get_foreground(term->session)) return; - if (conf_grab_matches(term->conf->grab_scroll_up, - ev->mods, ev->num_syms, ev->keysyms)) { + if (conf_grab_matches(term->conf->grab_scroll_up, ev->mods, ev->num_syms, ev->keysyms)) { tsm_screen_sb_up(term->console, 1); redraw_all(term); ev->handled = true; return; } - if (conf_grab_matches(term->conf->grab_scroll_down, - ev->mods, ev->num_syms, ev->keysyms)) { + if (conf_grab_matches(term->conf->grab_scroll_down, ev->mods, ev->num_syms, ev->keysyms)) { tsm_screen_sb_down(term->console, 1); redraw_all(term); ev->handled = true; return; } - if (conf_grab_matches(term->conf->grab_page_up, - ev->mods, ev->num_syms, ev->keysyms)) { + if (conf_grab_matches(term->conf->grab_page_up, ev->mods, ev->num_syms, ev->keysyms)) { tsm_screen_sb_page_up(term->console, 1); redraw_all(term); ev->handled = true; return; } - if (conf_grab_matches(term->conf->grab_page_down, - ev->mods, ev->num_syms, ev->keysyms)) { + if (conf_grab_matches(term->conf->grab_page_down, ev->mods, ev->num_syms, ev->keysyms)) { tsm_screen_sb_page_down(term->console, 1); redraw_all(term); ev->handled = true; return; } - if (conf_grab_matches(term->conf->grab_zoom_in, - ev->mods, ev->num_syms, ev->keysyms)) { + if (conf_grab_matches(term->conf->grab_zoom_in, ev->mods, ev->num_syms, ev->keysyms)) { ev->handled = true; if (term->font_attr.points + 1 < term->font_attr.points) return; @@ -649,8 +623,7 @@ static void input_event(struct uterm_input *input, --term->font_attr.points; return; } - if (conf_grab_matches(term->conf->grab_zoom_out, - ev->mods, ev->num_syms, ev->keysyms)) { + if (conf_grab_matches(term->conf->grab_zoom_out, ev->mods, ev->num_syms, ev->keysyms)) { ev->handled = true; if (term->font_attr.points <= 1) return; @@ -660,14 +633,12 @@ static void input_event(struct uterm_input *input, ++term->font_attr.points; return; } - if (conf_grab_matches(term->conf->grab_rotate_cw, - ev->mods, ev->num_syms, ev->keysyms)) { + if (conf_grab_matches(term->conf->grab_rotate_cw, ev->mods, ev->num_syms, ev->keysyms)) { rotate_cw_all(term); ev->handled = true; return; } - if (conf_grab_matches(term->conf->grab_rotate_ccw, - ev->mods, ev->num_syms, ev->keysyms)) { + if (conf_grab_matches(term->conf->grab_rotate_ccw, ev->mods, ev->num_syms, ev->keysyms)) { rotate_ccw_all(term); ev->handled = true; return; @@ -679,8 +650,8 @@ static void input_event(struct uterm_input *input, if (ev->num_syms > 1) return; - if (tsm_vte_handle_keyboard(term->vte, ev->keysyms[0], ev->ascii, - ev->mods, ev->codepoints[0])) { + if (tsm_vte_handle_keyboard(term->vte, ev->keysyms[0], ev->ascii, ev->mods, + ev->codepoints[0])) { tsm_screen_sb_reset(term->console); redraw_all(term); ev->handled = true; @@ -708,9 +679,13 @@ static void copy_selection(struct kmscon_terminal *term) term->pointer.copy_len = tsm_screen_selection_copy(term->console, &term->pointer.copy); } -static void forward_pointer_event(struct kmscon_terminal *term, struct uterm_input_pointer_event *ev) +static void forward_pointer_event(struct kmscon_terminal *term, + struct uterm_input_pointer_event *ev) { unsigned int event; + unsigned int button; + + button = ev->button; switch (ev->event) { case UTERM_MOVED: @@ -722,25 +697,36 @@ static void forward_pointer_event(struct kmscon_terminal *term, struct uterm_inp else event = TSM_MOUSE_EVENT_RELEASED; break; + case UTERM_WHEEL: + /* Convert wheel events to button 4 (scroll up) or 5 (scroll down) */ + event = TSM_MOUSE_EVENT_PRESSED; + if (ev->wheel > 0) + button = 4; /* Scroll up */ + else + button = 5; /* Scroll down */ + break; default: return; } - tsm_vte_handle_mouse(term->vte, term->pointer.posx, term->pointer.posy, - term->pointer.x, term->pointer.y, ev->button, event, 0); + tsm_vte_handle_mouse(term->vte, term->pointer.posx, term->pointer.posy, term->pointer.x, + term->pointer.y, button, event, 0); } -static void handle_pointer_button(struct kmscon_terminal *term, struct uterm_input_pointer_event *ev) +static void handle_pointer_button(struct kmscon_terminal *term, + struct uterm_input_pointer_event *ev) { - switch(ev->button) { + switch (ev->button) { case 0: if (ev->pressed) { if (ev->double_click) { - tsm_screen_selection_word(term->console, term->pointer.posx, term->pointer.posy); + tsm_screen_selection_word(term->console, term->pointer.posx, + term->pointer.posy); copy_selection(term); term->pointer.select = false; } else { term->pointer.select = true; - start_selection(term->console, term->pointer.posx, term->pointer.posy); + start_selection(term->console, term->pointer.posx, + term->pointer.posy); } } else { if (term->pointer.select) @@ -760,8 +746,7 @@ static void handle_pointer_button(struct kmscon_terminal *term, struct uterm_inp } } -static void pointer_event(struct uterm_input *input, - struct uterm_input_pointer_event *ev, +static void pointer_event(struct uterm_input *input, struct uterm_input_pointer_event *ev, void *data) { struct kmscon_terminal *term = data; @@ -770,7 +755,8 @@ static void pointer_event(struct uterm_input *input, term->pointer.x = ev->pointer_x; term->pointer.y = ev->pointer_y; - coord_to_cell(term, term->pointer.x, term->pointer.y, &term->pointer.posx, &term->pointer.posy); + coord_to_cell(term, term->pointer.x, term->pointer.y, &term->pointer.posx, + &term->pointer.posy); term->pointer.visible = true; } @@ -785,7 +771,7 @@ static void pointer_event(struct uterm_input *input, break; case UTERM_MOVED: if (term->pointer.select) - update_selection(term->console,term->pointer.posx, term->pointer.posy); + update_selection(term->console, term->pointer.posx, term->pointer.posy); break; case UTERM_BUTTON: handle_pointer_button(term, ev); @@ -794,7 +780,7 @@ static void pointer_event(struct uterm_input *input, if (ev->wheel > 0) tsm_screen_sb_up(term->console, 3); else - tsm_screen_sb_down(term->console, 3); + tsm_screen_sb_down(term->console, 3); break; case UTERM_SYNC: redraw_all(term); @@ -866,8 +852,8 @@ static void terminal_destroy(struct kmscon_terminal *term) free(term); } -static int session_event(struct kmscon_session *session, - struct kmscon_session_event *ev, void *data) +static int session_event(struct kmscon_session *session, struct kmscon_session_event *ev, + void *data) { struct kmscon_terminal *term = data; @@ -898,8 +884,7 @@ static int session_event(struct kmscon_session *session, return 0; } -static void pty_input(struct kmscon_pty *pty, const char *u8, size_t len, - void *data) +static void pty_input(struct kmscon_pty *pty, const char *u8, size_t len, void *data) { struct kmscon_terminal *term = data; @@ -919,16 +904,15 @@ static void pty_event(struct ev_fd *fd, int mask, void *data) kmscon_pty_dispatch(term->pty); } -static void write_event(struct tsm_vte *vte, const char *u8, size_t len, - void *data) +static void write_event(struct tsm_vte *vte, const char *u8, size_t len, void *data) { struct kmscon_terminal *term = data; kmscon_pty_write(term->pty, u8, len); } -int kmscon_terminal_register(struct kmscon_session **out, - struct kmscon_seat *seat, unsigned int vtnr) +int kmscon_terminal_register(struct kmscon_session **out, struct kmscon_seat *seat, + unsigned int vtnr) { struct kmscon_terminal *term; int ret; @@ -949,8 +933,7 @@ int kmscon_terminal_register(struct kmscon_session **out, term->conf_ctx = kmscon_seat_get_conf(seat); term->conf = conf_ctx_get_mem(term->conf_ctx); - strncpy(term->font_attr.name, term->conf->font_name, - KMSCON_FONT_MAX_NAME - 1); + strncpy(term->font_attr.name, term->conf->font_name, KMSCON_FONT_MAX_NAME - 1); term->font_attr.ppi = term->conf->font_ppi; term->font_attr.points = term->conf->font_size; @@ -959,13 +942,11 @@ int kmscon_terminal_register(struct kmscon_session **out, goto err_free; tsm_screen_set_max_sb(term->console, term->conf->sb_size); - ret = tsm_vte_new(&term->vte, term->console, write_event, term, - log_llog, NULL); + ret = tsm_vte_new(&term->vte, term->console, write_event, term, log_llog, NULL); if (ret) goto err_con; - tsm_vte_set_backspace_sends_delete(term->vte, - BUILD_BACKSPACE_SENDS_DELETE); + tsm_vte_set_backspace_sends_delete(term->vte, term->conf->backspace_delete); tsm_vte_set_osc_cb(term->vte, osc_event, (void *)term); tsm_vte_set_mouse_cb(term->vte, mouse_event, (void *)term); @@ -986,33 +967,14 @@ int kmscon_terminal_register(struct kmscon_session **out, if (ret) goto err_font; - kmscon_pty_set_env_reset(term->pty, term->conf->reset_env); - - ret = kmscon_pty_set_term(term->pty, term->conf->term); + ret = kmscon_pty_set_conf(term->pty, term->conf->term, "kmscon", term->conf->argv, + kmscon_seat_get_name(seat), term->conf->reset_env, + term->conf->backspace_delete); if (ret) goto err_pty; - ret = kmscon_pty_set_colorterm(term->pty, "kmscon"); - if (ret) - goto err_pty; - - ret = kmscon_pty_set_argv(term->pty, term->conf->argv); - if (ret) - goto err_pty; - - ret = kmscon_pty_set_seat(term->pty, kmscon_seat_get_name(seat)); - if (ret) - goto err_pty; - - if (vtnr > 0) { - ret = kmscon_pty_set_vtnr(term->pty, vtnr); - if (ret) - goto err_pty; - } - - ret = ev_eloop_new_fd(term->eloop, &term->ptyfd, - kmscon_pty_get_fd(term->pty), - EV_READABLE, pty_event, term); + ret = ev_eloop_new_fd(term->eloop, &term->ptyfd, kmscon_pty_get_fd(term->pty), EV_READABLE, + pty_event, term); if (ret) goto err_pty; @@ -1026,8 +988,7 @@ int kmscon_terminal_register(struct kmscon_session **out, goto err_input; } - ret = kmscon_seat_register_session(seat, &term->session, session_event, - term); + ret = kmscon_seat_register_session(seat, &term->session, session_event, term); if (ret) { log_error("cannot register session for terminal: %d", ret); goto err_pointer; diff --git a/src/kmscon_terminal.h b/src/kmscon_terminal.h index 9c6a3731..cd74bab3 100644 --- a/src/kmscon_terminal.h +++ b/src/kmscon_terminal.h @@ -39,14 +39,12 @@ #ifdef BUILD_ENABLE_SESSION_TERMINAL -int kmscon_terminal_register(struct kmscon_session **out, - struct kmscon_seat *seat, +int kmscon_terminal_register(struct kmscon_session **out, struct kmscon_seat *seat, unsigned int vtnr); #else /* !BUILD_ENABLE_SESSION_TERMINAL */ -static inline int kmscon_terminal_register(struct kmscon_session **out, - struct kmscon_seat *seat, +static inline int kmscon_terminal_register(struct kmscon_session **out, struct kmscon_seat *seat, unsigned int vtnr) { return -EOPNOTSUPP; diff --git a/src/pty.c b/src/pty.c index 3039db3f..96cf9b08 100644 --- a/src/pty.c +++ b/src/pty.c @@ -69,13 +69,13 @@ struct kmscon_pty { char *seat; char *vtnr; bool env_reset; + bool backspace_delete; time_t last_spawn_time; int retry_count; }; -int kmscon_pty_new(struct kmscon_pty **out, kmscon_pty_input_cb input_cb, - void *data) +int kmscon_pty_new(struct kmscon_pty **out, kmscon_pty_input_cb input_cb, void *data) { struct kmscon_pty *pty; int ret; @@ -139,94 +139,34 @@ void kmscon_pty_unref(struct kmscon_pty *pty) free(pty); } -int kmscon_pty_set_term(struct kmscon_pty *pty, const char *term) +int kmscon_pty_set_conf(struct kmscon_pty *pty, const char *term, const char *colorterm, + char **argv, const char *seat, bool do_reset, bool backspace) { - char *t; - - if (!pty || !term) - return -EINVAL; - - t = strdup(term); - if (!t) - return -ENOMEM; - free(pty->term); - pty->term = t; - - return 0; -} - -int kmscon_pty_set_colorterm(struct kmscon_pty *pty, const char *colorterm) -{ - char *t; - - if (!pty || !colorterm) - return -EINVAL; - - t = strdup(colorterm); - if (!t) - return -ENOMEM; - free(pty->colorterm); - pty->colorterm = t; - - return 0; -} - -int kmscon_pty_set_argv(struct kmscon_pty *pty, char **argv) -{ - char **t; - int ret; - - if (!pty || !argv || !*argv || !**argv) - return -EINVAL; - - ret = shl_dup_array(&t, argv); - if (ret) - return ret; - - free(pty->argv); - pty->argv = t; - return 0; -} - -int kmscon_pty_set_seat(struct kmscon_pty *pty, const char *seat) -{ - char *t; - - if (!pty || !seat) - return -EINVAL; - - t = strdup(seat); - if (!t) - return -ENOMEM; - free(pty->seat); - pty->seat = t; - - return 0; -} - -int kmscon_pty_set_vtnr(struct kmscon_pty *pty, unsigned int vtnr) -{ - char *t; - int ret; - if (!pty) return -EINVAL; - ret = asprintf(&t, "%u", vtnr); - if (ret < 0) - return -ENOMEM; - free(pty->vtnr); - pty->vtnr = t; - - return 0; -} + pty->env_reset = do_reset; + pty->backspace_delete = backspace; -void kmscon_pty_set_env_reset(struct kmscon_pty *pty, bool do_reset) -{ - if (!pty) - return; + if (term) { + pty->term = strdup(term); + if (!pty->term) + return -ENOMEM; + } + if (colorterm) { + pty->colorterm = strdup(colorterm); + if (!pty->colorterm) + return -ENOMEM; + } + if (seat) { + pty->seat = strdup(seat); + if (!pty->seat) + return -ENOMEM; + } - pty->env_reset = do_reset; + if (argv && *argv && **argv) + return shl_dup_array(&pty->argv, argv); + return 0; } int kmscon_pty_get_fd(struct kmscon_pty *pty) @@ -250,27 +190,28 @@ static bool pty_is_open(struct kmscon_pty *pty) return pty->fd >= 0; } -static void __attribute__((noreturn)) -exec_child(const char *term, const char *colorterm, char **argv, - const char *seat, const char *vtnr, bool env_reset, bool drm) +static void __attribute__((noreturn)) exec_child(const char *term, const char *colorterm, + char **argv, const char *seat, const char *vtnr, + bool env_reset, bool drm) { char **env; char **def_argv; + char **argv_parsed; + int ret; if (env_reset) { - env = malloc(sizeof(char*)); + env = malloc(sizeof(char *)); if (!env) { - log_error("cannot allocate memory for environment (%d): %m", - errno); + log_error("cannot allocate memory for environment (%d): %m", errno); exit(EXIT_FAILURE); } - memset(env, 0, sizeof(char*)); + memset(env, 0, sizeof(char *)); environ = env; - def_argv = (char*[]){ "/bin/login", "-p", NULL }; + def_argv = (char *[]){"/bin/login", "-p", NULL}; } else { - def_argv = (char*[]){ "/bin/login", NULL }; + def_argv = (char *[]){"/bin/login", NULL}; } if (!term) @@ -292,15 +233,18 @@ exec_child(const char *term, const char *colorterm, char **argv, } else { setenv("TERM_SESSION_TYPE", "fb", 1); } + ret = shl_replace_array_with_env(&argv_parsed, argv); + if (ret) + argv_parsed = argv; - execve(argv[0], argv, environ); + execve(argv_parsed[0], argv_parsed, environ); log_err("failed to exec child %s: %m", argv[0]); exit(EXIT_FAILURE); } -static void setup_child(int master, struct winsize *ws) +static void setup_child(int master, bool backspace_delete, struct winsize *ws) { int ret; sigset_t sigset; @@ -356,7 +300,7 @@ static void setup_child(int master, struct winsize *ws) goto err_out; } - if (BUILD_BACKSPACE_SENDS_DELETE) { + if (backspace_delete) { /* erase character should be delete */ attr.c_cc[VERASE] = 0177; } else { @@ -377,8 +321,8 @@ static void setup_child(int master, struct winsize *ws) } if (dup2(slave, STDIN_FILENO) != STDIN_FILENO || - dup2(slave, STDOUT_FILENO) != STDOUT_FILENO || - dup2(slave, STDERR_FILENO) != STDERR_FILENO) { + dup2(slave, STDOUT_FILENO) != STDOUT_FILENO || + dup2(slave, STDERR_FILENO) != STDERR_FILENO) { log_err("cannot duplicate slave: %m"); goto err_out; } @@ -400,8 +344,8 @@ static void setup_child(int master, struct winsize *ws) * a little bit more control of the process, and as a bonus avoid linking to * the libutil library in glibc. */ -static int pty_spawn(struct kmscon_pty *pty, int master, - unsigned short width, unsigned short height, bool drm) +static int pty_spawn(struct kmscon_pty *pty, int master, unsigned short width, + unsigned short height, bool drm) { pid_t pid; struct winsize ws; @@ -416,9 +360,9 @@ static int pty_spawn(struct kmscon_pty *pty, int master, log_err("cannot fork: %m"); return -errno; case 0: - setup_child(master, &ws); - exec_child(pty->term, pty->colorterm, pty->argv, pty->seat, - pty->vtnr, pty->env_reset, drm); + setup_child(master, pty->backspace_delete, &ws); + exec_child(pty->term, pty->colorterm, pty->argv, pty->seat, pty->vtnr, + pty->env_reset, drm); exit(EXIT_FAILURE); default: log_debug("forking child %d", pid); @@ -444,8 +388,7 @@ static int send_buf(struct kmscon_pty *pty) } if (ret < 0 && errno != EWOULDBLOCK) { - log_warn("cannot write to child process (%d): %m", - errno); + log_warn("cannot write to child process (%d): %m", errno); return ret; } @@ -472,12 +415,10 @@ static int read_buf(struct kmscon_pty *pty) if (pty->input_cb) pty->input_cb(pty, pty->io_buf, len, pty->data); } else if (len == 0) { - log_debug("HUP during read on pty of child %d", - pty->child); + log_debug("HUP during read on pty of child %d", pty->child); break; } else if (errno != EWOULDBLOCK) { - log_debug("cannot read from pty of child %d (%d): %m", - pty->child, errno); + log_debug("cannot read from pty of child %d (%d): %m", pty->child, errno); break; } } while (len > 0 && --num); @@ -526,8 +467,7 @@ static void pty_input(struct ev_fd *fd, int mask, void *data) read_buf(pty); } -static void sig_child(struct ev_eloop *eloop, struct ev_child_data *chld, - void *data) +static void sig_child(struct ev_eloop *eloop, struct ev_child_data *chld, void *data) { struct kmscon_pty *pty = data; time_t current_time; @@ -535,8 +475,7 @@ static void sig_child(struct ev_eloop *eloop, struct ev_child_data *chld, if (chld->pid != pty->child) return; - log_info("child exited: pid: %u status: %d", - chld->pid, chld->status); + log_info("child exited: pid: %u status: %d", chld->pid, chld->status); if (pty->retry_count == MAX_RETRY_COUNT) { log_err("reached max retry attempts for login process"); @@ -555,8 +494,7 @@ static void sig_child(struct ev_eloop *eloop, struct ev_child_data *chld, pty->input_cb(pty, NULL, 0, pty->data); } -int kmscon_pty_open(struct kmscon_pty *pty, unsigned short width, - unsigned short height, bool drm) +int kmscon_pty_open(struct kmscon_pty *pty, unsigned short width, unsigned short height, bool drm) { int ret; int master; @@ -573,8 +511,7 @@ int kmscon_pty_open(struct kmscon_pty *pty, unsigned short width, return -errno; } - ret = ev_eloop_new_fd(pty->eloop, &pty->efd, master, - EV_ET | EV_READABLE, pty_input, pty); + ret = ev_eloop_new_fd(pty->eloop, &pty->efd, master, EV_ET | EV_READABLE, pty_input, pty); if (ret) goto err_master; @@ -659,8 +596,7 @@ void kmscon_pty_signal(struct kmscon_pty *pty, int signum) log_debug("send signal %d to child", signum); } -void kmscon_pty_resize(struct kmscon_pty *pty, - unsigned short width, unsigned short height) +void kmscon_pty_resize(struct kmscon_pty *pty, unsigned short width, unsigned short height) { int ret; struct winsize ws; diff --git a/src/pty.h b/src/pty.h index 413125ce..0eac4c8f 100644 --- a/src/pty.h +++ b/src/pty.h @@ -47,30 +47,22 @@ struct kmscon_pty; -typedef void (*kmscon_pty_input_cb) - (struct kmscon_pty *pty, const char *u8, size_t len, void *data); +typedef void (*kmscon_pty_input_cb)(struct kmscon_pty *pty, const char *u8, size_t len, void *data); -int kmscon_pty_new(struct kmscon_pty **out, kmscon_pty_input_cb input_cb, - void *data); +int kmscon_pty_new(struct kmscon_pty **out, kmscon_pty_input_cb input_cb, void *data); void kmscon_pty_ref(struct kmscon_pty *pty); void kmscon_pty_unref(struct kmscon_pty *pty); -int kmscon_pty_set_term(struct kmscon_pty *pty, const char *term); -int kmscon_pty_set_colorterm(struct kmscon_pty *pty, const char *colorterm); -int kmscon_pty_set_argv(struct kmscon_pty *pty, char **argv); -int kmscon_pty_set_seat(struct kmscon_pty *pty, const char *seat); -int kmscon_pty_set_vtnr(struct kmscon_pty *pty, unsigned int vtnr); -void kmscon_pty_set_env_reset(struct kmscon_pty *pty, bool do_reset); +int kmscon_pty_set_conf(struct kmscon_pty *pty, const char *term, const char *colorterm, + char **argv, const char *seat, bool do_reset, bool backspace); int kmscon_pty_get_fd(struct kmscon_pty *pty); void kmscon_pty_dispatch(struct kmscon_pty *pty); -int kmscon_pty_open(struct kmscon_pty *pty, unsigned short width, - unsigned short height, bool drm); +int kmscon_pty_open(struct kmscon_pty *pty, unsigned short width, unsigned short height, bool drm); void kmscon_pty_close(struct kmscon_pty *pty); int kmscon_pty_write(struct kmscon_pty *pty, const char *u8, size_t len); void kmscon_pty_signal(struct kmscon_pty *pty, int signum); -void kmscon_pty_resize(struct kmscon_pty *pty, - unsigned short width, unsigned short height); +void kmscon_pty_resize(struct kmscon_pty *pty, unsigned short width, unsigned short height); #endif /* KMSCON_PTY_H */ diff --git a/src/shl_array.h b/src/shl_array.h index 9daf4096..2f5445eb 100644 --- a/src/shl_array.h +++ b/src/shl_array.h @@ -44,11 +44,9 @@ struct shl_array { void *data; }; -#define SHL_ARRAY_AT(_arr, _type, _pos) \ - (&((_type*)shl_array_get_array(_arr))[(_pos)]) +#define SHL_ARRAY_AT(_arr, _type, _pos) (&((_type *)shl_array_get_array(_arr))[(_pos)]) -static inline int shl_array_new(struct shl_array **out, size_t element_size, - size_t initial_size) +static inline int shl_array_new(struct shl_array **out, size_t element_size, size_t initial_size) { struct shl_array *arr; @@ -103,8 +101,8 @@ static inline int shl_array_zresize(struct shl_array *arr, size_t size) arr->data = tmp; arr->size = newsize; - memset(((uint8_t*)arr->data) + arr->element_size * arr->length, - 0, arr->element_size * (size - arr->length)); + memset(((uint8_t *)arr->data) + arr->element_size * arr->length, 0, + arr->element_size * (size - arr->length)); } arr->length = size; @@ -129,8 +127,7 @@ static inline int shl_array_push(struct shl_array *arr, const void *data) arr->size = newsize; } - memcpy(((uint8_t*)arr->data) + arr->element_size * arr->length, - data, arr->element_size); + memcpy(((uint8_t *)arr->data) + arr->element_size * arr->length, data, arr->element_size); ++arr->length; return 0; diff --git a/src/shl_dlist.h b/src/shl_dlist.h index 9e30dc5c..83cd233b 100644 --- a/src/shl_dlist.h +++ b/src/shl_dlist.h @@ -38,9 +38,10 @@ /* miscellaneous */ -#define shl_offsetof(pointer, type, member) ({ \ - const typeof(((type*)0)->member) *__ptr = (pointer); \ - (type*)(((char*)__ptr) - offsetof(type, member)); \ +#define shl_offsetof(pointer, type, member) \ + ({ \ + const typeof(((type *)0)->member) *__ptr = (pointer); \ + (type *)(((char *)__ptr) - offsetof(type, member)); \ }) /* double linked list */ @@ -50,7 +51,7 @@ struct shl_dlist { struct shl_dlist *prev; }; -#define SHL_DLIST_INIT(head) { &(head), &(head) } +#define SHL_DLIST_INIT(head) {&(head), &(head)} static inline void shl_dlist_init(struct shl_dlist *list) { @@ -58,9 +59,8 @@ static inline void shl_dlist_init(struct shl_dlist *list) list->prev = list; } -static inline void shl_dlist__link(struct shl_dlist *prev, - struct shl_dlist *next, - struct shl_dlist *n) +static inline void shl_dlist__link(struct shl_dlist *prev, struct shl_dlist *next, + struct shl_dlist *n) { next->prev = n; n->next = next; @@ -68,20 +68,17 @@ static inline void shl_dlist__link(struct shl_dlist *prev, prev->next = n; } -static inline void shl_dlist_link(struct shl_dlist *head, - struct shl_dlist *n) +static inline void shl_dlist_link(struct shl_dlist *head, struct shl_dlist *n) { return shl_dlist__link(head, head->next, n); } -static inline void shl_dlist_link_tail(struct shl_dlist *head, - struct shl_dlist *n) +static inline void shl_dlist_link_tail(struct shl_dlist *head, struct shl_dlist *n) { return shl_dlist__link(head->prev, head, n); } -static inline void shl_dlist__unlink(struct shl_dlist *prev, - struct shl_dlist *next) +static inline void shl_dlist__unlink(struct shl_dlist *prev, struct shl_dlist *next) { next->prev = prev; prev->next = next; @@ -99,45 +96,31 @@ static inline bool shl_dlist_empty(struct shl_dlist *head) return head->next == head; } -#define shl_dlist_entry(ptr, type, member) \ - shl_offsetof((ptr), type, member) +#define shl_dlist_entry(ptr, type, member) shl_offsetof((ptr), type, member) -#define shl_dlist_first(head, type, member) \ - shl_dlist_entry((head)->next, type, member) +#define shl_dlist_first(head, type, member) shl_dlist_entry((head)->next, type, member) -#define shl_dlist_last(head, type, member) \ - shl_dlist_entry((head)->prev, type, member) +#define shl_dlist_last(head, type, member) shl_dlist_entry((head)->prev, type, member) -#define shl_dlist_for_each(iter, head) \ - for (iter = (head)->next; iter != (head); iter = iter->next) +#define shl_dlist_for_each(iter, head) for (iter = (head)->next; iter != (head); iter = iter->next) -#define shl_dlist_for_each_but_one(iter, start, head) \ - for (iter = ((start)->next == (head)) ? \ - (start)->next->next : \ - (start)->next; \ - iter != (start); \ - iter = (iter->next == (head) && (start) != (head)) ? \ - iter->next->next : \ - iter->next) +#define shl_dlist_for_each_but_one(iter, start, head) \ + for (iter = ((start)->next == (head)) ? (start)->next->next : (start)->next; \ + iter != (start); \ + iter = (iter->next == (head) && (start) != (head)) ? iter->next->next : iter->next) -#define shl_dlist_for_each_safe(iter, tmp, head) \ - for (iter = (head)->next, tmp = iter->next; iter != (head); \ - iter = tmp, tmp = iter->next) +#define shl_dlist_for_each_safe(iter, tmp, head) \ + for (iter = (head)->next, tmp = iter->next; iter != (head); iter = tmp, tmp = iter->next) -#define shl_dlist_for_each_reverse(iter, head) \ +#define shl_dlist_for_each_reverse(iter, head) \ for (iter = (head)->prev; iter != (head); iter = iter->prev) -#define shl_dlist_for_each_reverse_but_one(iter, start, head) \ - for (iter = ((start)->prev == (head)) ? \ - (start)->prev->prev : \ - (start)->prev; \ - iter != (start); \ - iter = (iter->prev == (head) && (start) != (head)) ? \ - iter->prev->prev : \ - iter->prev) - -#define shl_dlist_for_each_reverse_safe(iter, tmp, head) \ - for (iter = (head)->prev, tmp = iter->prev; iter != (head); \ - iter = tmp, tmp = iter->prev) +#define shl_dlist_for_each_reverse_but_one(iter, start, head) \ + for (iter = ((start)->prev == (head)) ? (start)->prev->prev : (start)->prev; \ + iter != (start); \ + iter = (iter->prev == (head) && (start) != (head)) ? iter->prev->prev : iter->prev) + +#define shl_dlist_for_each_reverse_safe(iter, tmp, head) \ + for (iter = (head)->prev, tmp = iter->prev; iter != (head); iter = tmp, tmp = iter->prev) #endif /* SHL_DLIST_H */ diff --git a/src/shl_gl.h b/src/shl_gl.h index c1944330..1f7d301f 100644 --- a/src/shl_gl.h +++ b/src/shl_gl.h @@ -36,8 +36,8 @@ #include #include #include -#include #include +#include #include "shl_llog.h" /* @@ -71,9 +71,8 @@ float *gl_m4_stack_tip(struct gl_m4_stack *stack); struct gl_shader; -int gl_shader_new(struct gl_shader **out, const char *vert, int vert_len, - const char *frag, int frag_len, - char **attr, size_t attr_count, llog_submit_t llog, +int gl_shader_new(struct gl_shader **out, const char *vert, int vert_len, const char *frag, + int frag_len, char **attr, size_t attr_count, llog_submit_t llog, void *llog_data); void gl_shader_ref(struct gl_shader *shader); void gl_shader_unref(struct gl_shader *shader); @@ -82,8 +81,8 @@ void gl_shader_use(struct gl_shader *shader); void gl_tex_new(GLuint *tex, size_t num); void gl_tex_free(GLuint *tex, size_t num); -void gl_tex_load(GLuint tex, unsigned int width, unsigned int stride, - unsigned int height, uint8_t *buf); +void gl_tex_load(GLuint tex, unsigned int width, unsigned int stride, unsigned int height, + uint8_t *buf); void gl_clear_error(); bool gl_has_error(struct gl_shader *shader); diff --git a/src/shl_gl_math.c b/src/shl_gl_math.c index a3a3a1d4..d2cdc103 100644 --- a/src/shl_gl_math.c +++ b/src/shl_gl_math.c @@ -113,8 +113,7 @@ void gl_m4_mult_dest(float *dest, const float *n, const float *m) for (col = 0; col < 4; ++col) { dest[row * 4 + col] = 0; for (j = 0; j < 4; ++j) - dest[row * 4 + col] += - n[row * 4 + j] * m[j * 4 + col]; + dest[row * 4 + col] += n[row * 4 + j] * m[j * 4 + col]; } } } @@ -133,7 +132,7 @@ void gl_m4_mult(float *n, const float *m) void gl_m4_translate(float *m, float x, float y, float z) { - float trans[16] = { 1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1 }; + float trans[16] = {1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1}; if (!m) return; @@ -143,7 +142,7 @@ void gl_m4_translate(float *m, float x, float y, float z) void gl_m4_scale(float *m, float x, float y, float z) { - float scale[16] = { x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1 }; + float scale[16] = {x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1}; if (!m) return; diff --git a/src/shl_gl_shader.c b/src/shl_gl_shader.c index 68764e82..4a00e927 100644 --- a/src/shl_gl_shader.c +++ b/src/shl_gl_shader.c @@ -31,9 +31,9 @@ #define GL_GLEXT_PROTOTYPES -#include #include #include +#include #include #include #include @@ -105,8 +105,7 @@ bool gl_has_error(struct gl_shader *shader) return false; } -static int compile_shader(struct gl_shader *shader, GLenum type, - const char *source, int len) +static int compile_shader(struct gl_shader *shader, GLenum type, const char *source, int len) { char msg[512]; GLint status = 1, size; @@ -133,10 +132,8 @@ static int compile_shader(struct gl_shader *shader, GLenum type, return s; } -int gl_shader_new(struct gl_shader **out, const char *vert, int vert_len, - const char *frag, int frag_len, - char **attr, size_t attr_count, llog_submit_t llog, - void *llog_data) +int gl_shader_new(struct gl_shader **out, const char *vert, int vert_len, const char *frag, + int frag_len, char **attr, size_t attr_count, llog_submit_t llog, void *llog_data) { struct gl_shader *shader; int ret, i; @@ -156,15 +153,13 @@ int gl_shader_new(struct gl_shader **out, const char *vert, int vert_len, llog_debug(shader, "new shader"); - shader->vshader = compile_shader(shader, GL_VERTEX_SHADER, vert, - vert_len); + shader->vshader = compile_shader(shader, GL_VERTEX_SHADER, vert, vert_len); if (shader->vshader == GL_NONE) { ret = -EFAULT; goto err_free; } - shader->fshader = compile_shader(shader, GL_FRAGMENT_SHADER, frag, - frag_len); + shader->fshader = compile_shader(shader, GL_FRAGMENT_SHADER, frag, frag_len); if (shader->fshader == GL_NONE) { ret = -EFAULT; goto err_vshader; @@ -251,14 +246,10 @@ void gl_tex_new(GLuint *tex, size_t num) for (i = 0; i < num; ++i) { glBindTexture(GL_TEXTURE_2D, tex[i]); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, - GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, - GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, - GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, - GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } } @@ -267,8 +258,8 @@ void gl_tex_free(GLuint *tex, size_t num) glDeleteTextures(num, tex); } -void gl_tex_load(GLuint tex, unsigned int width, unsigned int stride, - unsigned int height, uint8_t *buf) +void gl_tex_load(GLuint tex, unsigned int width, unsigned int stride, unsigned int height, + uint8_t *buf) { if (!buf || !width || !height || !stride) return; @@ -284,7 +275,7 @@ void gl_tex_load(GLuint tex, unsigned int width, unsigned int stride, glBindTexture(GL_TEXTURE_2D, tex); /* glPixelStorei(GL_UNPACK_ROW_LENGTH, stride); */ - glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, width, height, 0, - GL_BGRA_EXT, GL_UNSIGNED_BYTE, buf); + glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, width, height, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, + buf); /* glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); */ } diff --git a/src/shl_hashtable.h b/src/shl_hashtable.h index 72ee120b..f3a6ca15 100644 --- a/src/shl_hashtable.h +++ b/src/shl_hashtable.h @@ -41,9 +41,9 @@ struct shl_hashtable; -typedef unsigned int (*shl_hash_cb) (uint64_t data); -typedef bool (*shl_equal_cb) (uint64_t data1, uint64_t data2); -typedef void (*shl_free_cb) (void *data); +typedef unsigned int (*shl_hash_cb)(uint64_t data); +typedef bool (*shl_equal_cb)(uint64_t data1, uint64_t data2); +typedef void (*shl_free_cb)(void *data); struct shl_hashentry { uint64_t key; @@ -75,10 +75,8 @@ static size_t shl_rehash(const void *ele, void *priv) return tbl->hash_cb(ent->key); } -static inline int shl_hashtable_new(struct shl_hashtable **out, - shl_hash_cb hash_cb, - shl_equal_cb equal_cb, - shl_free_cb free_value) +static inline int shl_hashtable_new(struct shl_hashtable **out, shl_hash_cb hash_cb, + shl_equal_cb equal_cb, shl_free_cb free_value) { struct shl_hashtable *tbl; @@ -107,9 +105,7 @@ static inline void shl_hashtable_free(struct shl_hashtable *tbl) if (!tbl) return; - for (entry = htable_first(&tbl->tbl, &i); - entry; - entry = htable_next(&tbl->tbl, &i)) { + for (entry = htable_first(&tbl->tbl, &i); entry; entry = htable_next(&tbl->tbl, &i)) { htable_delval(&tbl->tbl, &i); if (tbl->free_value) tbl->free_value(entry->value); @@ -120,8 +116,7 @@ static inline void shl_hashtable_free(struct shl_hashtable *tbl) free(tbl); } -static inline int shl_hashtable_insert(struct shl_hashtable *tbl, uint64_t key, - void *value) +static inline int shl_hashtable_insert(struct shl_hashtable *tbl, uint64_t key, void *value) { struct shl_hashentry *entry; size_t hash; @@ -156,8 +151,7 @@ static inline void shl_hashtable_remove(struct shl_hashtable *tbl, uint64_t key) hash = tbl->hash_cb(key); - for (entry = htable_firstval(&tbl->tbl, &i, hash); - entry; + for (entry = htable_firstval(&tbl->tbl, &i, hash); entry; entry = htable_nextval(&tbl->tbl, &i, hash)) { if (tbl->equal_cb(key, entry->key)) { htable_delval(&tbl->tbl, &i); @@ -166,8 +160,7 @@ static inline void shl_hashtable_remove(struct shl_hashtable *tbl, uint64_t key) } } -static inline bool shl_hashtable_find(struct shl_hashtable *tbl, void **out, - uint64_t key) +static inline bool shl_hashtable_find(struct shl_hashtable *tbl, void **out, uint64_t key) { struct htable_iter i; struct shl_hashentry *entry; @@ -178,8 +171,7 @@ static inline bool shl_hashtable_find(struct shl_hashtable *tbl, void **out, hash = tbl->hash_cb(key); - for (entry = htable_firstval(&tbl->tbl, &i, hash); - entry; + for (entry = htable_firstval(&tbl->tbl, &i, hash); entry; entry = htable_nextval(&tbl->tbl, &i, hash)) { if (tbl->equal_cb(key, entry->key)) { if (out) diff --git a/src/shl_hook.h b/src/shl_hook.h index 66603a06..e1487a58 100644 --- a/src/shl_hook.h +++ b/src/shl_hook.h @@ -41,16 +41,14 @@ struct shl_hook; struct shl_hook_entry; -typedef void (*shl_hook_cb) (void *parent, void *arg, void *data); +typedef void (*shl_hook_cb)(void *parent, void *arg, void *data); -#define shl_hook_add_cast(hook, cb, data, oneshot) \ +#define shl_hook_add_cast(hook, cb, data, oneshot) \ shl_hook_add((hook), (shl_hook_cb)(cb), (data), (oneshot)) -#define shl_hook_add_single_cast(hook, cb, data, oneshot) \ +#define shl_hook_add_single_cast(hook, cb, data, oneshot) \ shl_hook_add_single((hook), (shl_hook_cb)(cb), (data), (oneshot)) -#define shl_hook_rm_cast(hook, cb, data) \ - shl_hook_rm((hook), (shl_hook_cb)(cb), (data)) -#define shl_hook_rm_all_cast(hook, cb, data) \ - shl_hook_rm_all((hook), (shl_hook_cb)(cb), (data)) +#define shl_hook_rm_cast(hook, cb, data) shl_hook_rm((hook), (shl_hook_cb)(cb), (data)) +#define shl_hook_rm_all_cast(hook, cb, data) shl_hook_rm_all((hook), (shl_hook_cb)(cb), (data)) struct shl_hook_entry { struct shl_dlist list; @@ -96,9 +94,7 @@ static inline void shl_hook_free(struct shl_hook *hook) } while (!shl_dlist_empty(&hook->entries)) { - entry = shl_dlist_entry(hook->entries.prev, - struct shl_hook_entry, - list); + entry = shl_dlist_entry(hook->entries.prev, struct shl_hook_entry, list); shl_dlist_unlink(&entry->list); free(entry); } @@ -114,8 +110,7 @@ static inline unsigned int shl_hook_num(struct shl_hook *hook) return hook->num; } -static inline int shl_hook_add(struct shl_hook *hook, shl_hook_cb cb, - void *data, bool oneshot) +static inline int shl_hook_add(struct shl_hook *hook, shl_hook_cb cb, void *data, bool oneshot) { struct shl_hook_entry *entry; @@ -138,8 +133,8 @@ static inline int shl_hook_add(struct shl_hook *hook, shl_hook_cb cb, /* This adds an entry only if it is not already in the list. But notice that if * the entry is already registered twice or with a different \oneshot flag, the * list will _not_ be changed! */ -static inline int shl_hook_add_single(struct shl_hook *hook, shl_hook_cb cb, - void *data, bool oneshot) +static inline int shl_hook_add_single(struct shl_hook *hook, shl_hook_cb cb, void *data, + bool oneshot) { struct shl_hook_entry *entry; struct shl_dlist *iter; @@ -147,7 +142,8 @@ static inline int shl_hook_add_single(struct shl_hook *hook, shl_hook_cb cb, if (!hook || !cb) return -EINVAL; - shl_dlist_for_each(iter, &hook->entries) { + shl_dlist_for_each(iter, &hook->entries) + { entry = shl_dlist_entry(iter, struct shl_hook_entry, list); if (entry->cb == cb && entry->data == data) return 0; @@ -156,8 +152,7 @@ static inline int shl_hook_add_single(struct shl_hook *hook, shl_hook_cb cb, return shl_hook_add(hook, cb, data, oneshot); } -static inline void shl_hook_rm(struct shl_hook *hook, shl_hook_cb cb, - void *data) +static inline void shl_hook_rm(struct shl_hook *hook, shl_hook_cb cb, void *data) { struct shl_dlist *iter; struct shl_hook_entry *entry; @@ -165,7 +160,8 @@ static inline void shl_hook_rm(struct shl_hook *hook, shl_hook_cb cb, if (!hook || !cb) return; - shl_dlist_for_each_reverse(iter, &hook->entries) { + shl_dlist_for_each_reverse(iter, &hook->entries) + { entry = shl_dlist_entry(iter, struct shl_hook_entry, list); if (entry->cb == cb && entry->data == data) { /* if *_call() is running we must not disturb it */ @@ -179,8 +175,7 @@ static inline void shl_hook_rm(struct shl_hook *hook, shl_hook_cb cb, } } -static inline void shl_hook_rm_all(struct shl_hook *hook, shl_hook_cb cb, - void *data) +static inline void shl_hook_rm_all(struct shl_hook *hook, shl_hook_cb cb, void *data) { struct shl_dlist *iter, *tmp; struct shl_hook_entry *entry; @@ -188,7 +183,8 @@ static inline void shl_hook_rm_all(struct shl_hook *hook, shl_hook_cb cb, if (!hook || !cb) return; - shl_dlist_for_each_reverse_safe(iter, tmp, &hook->entries) { + shl_dlist_for_each_reverse_safe(iter, tmp, &hook->entries) + { entry = shl_dlist_entry(iter, struct shl_hook_entry, list); if (entry->cb == cb && entry->data == data) { /* if *_call() is running we must not disturb it */ @@ -201,8 +197,7 @@ static inline void shl_hook_rm_all(struct shl_hook *hook, shl_hook_cb cb, } } -static inline void shl_hook_call(struct shl_hook *hook, void *parent, - void *arg) +static inline void shl_hook_call(struct shl_hook *hook, void *parent, void *arg) { struct shl_hook_entry *entry; bool oneshot; @@ -210,10 +205,8 @@ static inline void shl_hook_call(struct shl_hook *hook, void *parent, if (!hook || hook->cur_entry) return; - for (hook->cur_entry = hook->entries.next; - hook->cur_entry != &hook->entries; ) { - entry = shl_dlist_entry(hook->cur_entry, - struct shl_hook_entry, list); + for (hook->cur_entry = hook->entries.next; hook->cur_entry != &hook->entries;) { + entry = shl_dlist_entry(hook->cur_entry, struct shl_hook_entry, list); hook->cur_entry = entry->list.next; oneshot = entry->oneshot; diff --git a/src/shl_llog.h b/src/shl_llog.h index 2c0e8b93..65a2848f 100644 --- a/src/shl_llog.h +++ b/src/shl_llog.h @@ -70,25 +70,12 @@ enum llog_severity { LLOG_SEV_NUM, }; -typedef void (*llog_submit_t) (void *data, - const char *file, - int line, - const char *func, - const char *subs, - unsigned int sev, - const char *format, - va_list args); - -static inline __attribute__((format(printf, 8, 9))) -void llog_format(llog_submit_t llog, - void *data, - const char *file, - int line, - const char *func, - const char *subs, - unsigned int sev, - const char *format, - ...) +typedef void (*llog_submit_t)(void *data, const char *file, int line, const char *func, + const char *subs, unsigned int sev, const char *format, va_list args); + +static inline __attribute__((format(printf, 8, 9))) void +llog_format(llog_submit_t llog, void *data, const char *file, int line, const char *func, + const char *subs, unsigned int sev, const char *format, ...) { va_list list; @@ -105,24 +92,13 @@ static const char *LLOG_SUBSYSTEM __attribute__((__unused__)); #define LLOG_DEFAULT __FILE__, __LINE__, __func__, LLOG_SUBSYSTEM -#define llog_printf(obj, sev, format, ...) \ - llog_format((obj)->llog, \ - (obj)->llog_data, \ - LLOG_DEFAULT, \ - (sev), \ - (format), \ - ##__VA_ARGS__) -#define llog_dprintf(obj, data, sev, format, ...) \ - llog_format((obj), \ - (data), \ - LLOG_DEFAULT, \ - (sev), \ - (format), \ - ##__VA_ARGS__) - -static inline __attribute__((format(printf, 4, 5))) -void llog_dummyf(llog_submit_t llog, void *data, unsigned int sev, - const char *format, ...) +#define llog_printf(obj, sev, format, ...) \ + llog_format((obj)->llog, (obj)->llog_data, LLOG_DEFAULT, (sev), (format), ##__VA_ARGS__) +#define llog_dprintf(obj, data, sev, format, ...) \ + llog_format((obj), (data), LLOG_DEFAULT, (sev), (format), ##__VA_ARGS__) + +static inline __attribute__((format(printf, 4, 5))) void +llog_dummyf(llog_submit_t llog, void *data, unsigned int sev, const char *format, ...) { } @@ -135,44 +111,37 @@ void llog_dummyf(llog_submit_t llog, void *data, unsigned int sev, */ #ifdef BUILD_ENABLE_DEBUG - #define llog_ddebug(obj, data, format, ...) \ - llog_dprintf((obj), (data), LLOG_DEBUG, (format), ##__VA_ARGS__) - #define llog_debug(obj, format, ...) \ - llog_ddebug((obj)->llog, (obj)->llog_data, (format), ##__VA_ARGS__) +#define llog_ddebug(obj, data, format, ...) \ + llog_dprintf((obj), (data), LLOG_DEBUG, (format), ##__VA_ARGS__) +#define llog_debug(obj, format, ...) \ + llog_ddebug((obj)->llog, (obj)->llog_data, (format), ##__VA_ARGS__) #else - #define llog_ddebug(obj, data, format, ...) \ - llog_dummyf((obj), (data), LLOG_DEBUG, (format), ##__VA_ARGS__) - #define llog_debug(obj, format, ...) \ - llog_ddebug((obj)->llog, (obj)->llog_data, (format), ##__VA_ARGS__) +#define llog_ddebug(obj, data, format, ...) \ + llog_dummyf((obj), (data), LLOG_DEBUG, (format), ##__VA_ARGS__) +#define llog_debug(obj, format, ...) \ + llog_ddebug((obj)->llog, (obj)->llog_data, (format), ##__VA_ARGS__) #endif -#define llog_info(obj, format, ...) \ - llog_printf((obj), LLOG_INFO, (format), ##__VA_ARGS__) -#define llog_dinfo(obj, data, format, ...) \ +#define llog_info(obj, format, ...) llog_printf((obj), LLOG_INFO, (format), ##__VA_ARGS__) +#define llog_dinfo(obj, data, format, ...) \ llog_dprintf((obj), (data), LLOG_INFO, (format), ##__VA_ARGS__) -#define llog_notice(obj, format, ...) \ - llog_printf((obj), LLOG_NOTICE, (format), ##__VA_ARGS__) -#define llog_dnotice(obj, data, format, ...) \ +#define llog_notice(obj, format, ...) llog_printf((obj), LLOG_NOTICE, (format), ##__VA_ARGS__) +#define llog_dnotice(obj, data, format, ...) \ llog_dprintf((obj), (data), LLOG_NOTICE, (format), ##__VA_ARGS__) -#define llog_warning(obj, format, ...) \ - llog_printf((obj), LLOG_WARNING, (format), ##__VA_ARGS__) -#define llog_dwarning(obj, data, format, ...) \ +#define llog_warning(obj, format, ...) llog_printf((obj), LLOG_WARNING, (format), ##__VA_ARGS__) +#define llog_dwarning(obj, data, format, ...) \ llog_dprintf((obj), (data), LLOG_WARNING, (format), ##__VA_ARGS__) -#define llog_error(obj, format, ...) \ - llog_printf((obj), LLOG_ERROR, (format), ##__VA_ARGS__) -#define llog_derror(obj, data, format, ...) \ +#define llog_error(obj, format, ...) llog_printf((obj), LLOG_ERROR, (format), ##__VA_ARGS__) +#define llog_derror(obj, data, format, ...) \ llog_dprintf((obj), (data), LLOG_ERROR, (format), ##__VA_ARGS__) -#define llog_critical(obj, format, ...) \ - llog_printf((obj), LLOG_CRITICAL, (format), ##__VA_ARGS__) -#define llog_dcritical(obj, data, format, ...) \ +#define llog_critical(obj, format, ...) llog_printf((obj), LLOG_CRITICAL, (format), ##__VA_ARGS__) +#define llog_dcritical(obj, data, format, ...) \ llog_dprintf((obj), (data), LLOG_CRITICAL, (format), ##__VA_ARGS__) -#define llog_alert(obj, format, ...) \ - llog_printf((obj), LLOG_ALERT, (format), ##__VA_ARGS__) -#define llog_dalert(obj, data, format, ...) \ +#define llog_alert(obj, format, ...) llog_printf((obj), LLOG_ALERT, (format), ##__VA_ARGS__) +#define llog_dalert(obj, data, format, ...) \ llog_dprintf((obj), (data), LLOG_ALERT, (format), ##__VA_ARGS__) -#define llog_fatal(obj, format, ...) \ - llog_printf((obj), LLOG_FATAL, (format), ##__VA_ARGS__) -#define llog_dfatal(obj, data, format, ...) \ +#define llog_fatal(obj, format, ...) llog_printf((obj), LLOG_FATAL, (format), ##__VA_ARGS__) +#define llog_dfatal(obj, data, format, ...) \ llog_dprintf((obj), (data), LLOG_FATAL, (format), ##__VA_ARGS__) #define llog_dbg llog_debug @@ -192,31 +161,19 @@ void llog_dummyf(llog_submit_t llog, void *data, unsigned int sev, * are used in debug paths and would slow down normal applications. */ -#define llog_dEINVAL(obj, data) \ - (llog_ddebug((obj), (data), "invalid arguments"), -EINVAL) -#define llog_EINVAL(obj) \ - (llog_dEINVAL((obj)->llog, (obj)->llog_data)) -#define llog_vEINVAL(obj) \ - ((void)llog_EINVAL(obj)) -#define llog_vdEINVAL(obj, data) \ - ((void)llog_dEINVAL((obj), (data))) - -#define llog_dEFAULT(obj, data) \ - (llog_ddebug((obj), (data), "operation failed"), -EFAULT) -#define llog_EFAULT(obj) \ - (llog_dEFAULT((obj)->llog, (obj)->llog_data)) -#define llog_vEFAULT(obj) \ - ((void)llog_EFAULT(obj)) -#define llog_vdEFAULT(obj, data) \ - ((void)llog_dEFAULT((obj), (data))) - -#define llog_dENOMEM(obj, data) \ - (llog_ddebug((obj), (data), "memory allocation failed"), -ENOMEM) -#define llog_ENOMEM(obj) \ - (llog_dENOMEM((obj)->llog, (obj)->llog_data)) -#define llog_vENOMEM(obj) \ - ((void)llog_ENOMEM(obj)) -#define llog_vdENOMEM(obj, data) \ - ((void)llog_dENOMEM((obj), (data))) +#define llog_dEINVAL(obj, data) (llog_ddebug((obj), (data), "invalid arguments"), -EINVAL) +#define llog_EINVAL(obj) (llog_dEINVAL((obj)->llog, (obj)->llog_data)) +#define llog_vEINVAL(obj) ((void)llog_EINVAL(obj)) +#define llog_vdEINVAL(obj, data) ((void)llog_dEINVAL((obj), (data))) + +#define llog_dEFAULT(obj, data) (llog_ddebug((obj), (data), "operation failed"), -EFAULT) +#define llog_EFAULT(obj) (llog_dEFAULT((obj)->llog, (obj)->llog_data)) +#define llog_vEFAULT(obj) ((void)llog_EFAULT(obj)) +#define llog_vdEFAULT(obj, data) ((void)llog_dEFAULT((obj), (data))) + +#define llog_dENOMEM(obj, data) (llog_ddebug((obj), (data), "memory allocation failed"), -ENOMEM) +#define llog_ENOMEM(obj) (llog_dENOMEM((obj)->llog, (obj)->llog_data)) +#define llog_vENOMEM(obj) ((void)llog_ENOMEM(obj)) +#define llog_vdENOMEM(obj, data) ((void)llog_dENOMEM((obj), (data))) #endif /* SHL_LLOG_H_INCLUDED */ diff --git a/src/shl_log.c b/src/shl_log.c index 9acae87b..681dde54 100644 --- a/src/shl_log.c +++ b/src/shl_log.c @@ -76,18 +76,16 @@ static void log__time(long long *sec, long long *usec) */ SHL_EXPORT -const struct log_config LOG_CONFIG = { - .sev = { - [LOG_DEBUG] = 2, - [LOG_INFO] = 2, - [LOG_NOTICE] = 2, - [LOG_WARNING] = 2, - [LOG_ERROR] = 2, - [LOG_CRITICAL] = 2, - [LOG_ALERT] = 2, - [LOG_FATAL] = 2, - } -}; +const struct log_config LOG_CONFIG = {.sev = { + [LOG_DEBUG] = 2, + [LOG_INFO] = 2, + [LOG_NOTICE] = 2, + [LOG_WARNING] = 2, + [LOG_ERROR] = 2, + [LOG_CRITICAL] = 2, + [LOG_ALERT] = 2, + [LOG_FATAL] = 2, + }}; const char *LOG_SUBSYSTEM = NULL; @@ -116,18 +114,16 @@ const char *LOG_SUBSYSTEM = NULL; * are affected and the config parameter specifies what action is performed. */ -static struct log_config log__gconfig = { - .sev = { - [LOG_DEBUG] = 0, - [LOG_INFO] = 0, - [LOG_NOTICE] = 1, - [LOG_WARNING] = 1, - [LOG_ERROR] = 1, - [LOG_CRITICAL] = 1, - [LOG_ALERT] = 1, - [LOG_FATAL] = 1, - } -}; +static struct log_config log__gconfig = {.sev = { + [LOG_DEBUG] = 0, + [LOG_INFO] = 0, + [LOG_NOTICE] = 1, + [LOG_WARNING] = 1, + [LOG_ERROR] = 1, + [LOG_CRITICAL] = 1, + [LOG_ALERT] = 1, + [LOG_FATAL] = 1, + }}; struct log_dynconf { struct log_dynconf *next; @@ -148,8 +144,7 @@ void log_set_config(const struct log_config *config) log_unlock(); } -int log_add_filter(const struct log_filter *filter, - const struct log_config *config) +int log_add_filter(const struct log_filter *filter, const struct log_config *config) { struct log_dynconf *dconf; int ret; @@ -187,13 +182,14 @@ void log_rm_filter(int handle) if (log__dconfig->handle == handle) { dconf = log__dconfig; log__dconfig = dconf->next; - } else for (i = log__dconfig; i->next; i = i->next) { - dconf = i->next; - if (dconf->handle == handle) { - i->next = dconf->next; - break; + } else + for (i = log__dconfig; i->next; i = i->next) { + dconf = i->next; + if (dconf->handle == handle) { + i->next = dconf->next; + break; + } } - } } log_unlock(); @@ -212,11 +208,8 @@ void log_clean_filters() log_unlock(); } -static bool log__matches(const struct log_filter *filter, - const char *file, - int line, - const char *func, - const char *subs) +static bool log__matches(const struct log_filter *filter, const char *file, int line, + const char *func, const char *subs) { if (*filter->file) { if (!file || strncmp(filter->file, file, LOG_STRMAX)) @@ -235,12 +228,8 @@ static bool log__matches(const struct log_filter *filter, return true; } -static bool log__omit(const char *file, - int line, - const char *func, - const struct log_config *config, - const char *subs, - enum log_severity sev) +static bool log__omit(const char *file, int line, const char *func, const struct log_config *config, + const char *subs, enum log_severity sev) { int val; struct log_dynconf *dconf; @@ -281,23 +270,13 @@ static bool log__omit(const char *file, * Also set default log-subsystem to "log" for all logging inside this API. */ -static void log__submit(const char *file, - int line, - const char *func, - const struct log_config *config, - const char *subs, - unsigned int sev, - const char *format, - va_list args); - -static void log__format(const char *file, - int line, - const char *func, - const struct log_config *config, - const char *subs, - unsigned int sev, - const char *format, - ...); +static void log__submit(const char *file, int line, const char *func, + const struct log_config *config, const char *subs, unsigned int sev, + const char *format, va_list args); + +static void log__format(const char *file, int line, const char *func, + const struct log_config *config, const char *subs, unsigned int sev, + const char *format, ...); #define LOG_SUBSYSTEM "log" @@ -320,8 +299,7 @@ int log_set_file(const char *file) if (file) { f = fopen(file, "a"); if (!f) { - log_err("cannot change log-file to %s (%d): %m", - file, errno); + log_err("cannot change log-file to %s (%d): %m", file, errno); return -EFAULT; } } else { @@ -333,8 +311,7 @@ int log_set_file(const char *file) log_lock(); if (log__file != f) { - log__format(LOG_DEFAULT, LOG_NOTICE, - "set log-file to %s", file); + log__format(LOG_DEFAULT, LOG_NOTICE, "set log-file to %s", file); old = log__file; log__file = f; f = NULL; @@ -364,24 +341,14 @@ int log_set_file(const char *file) */ static const char *log__sev2str[] = { - [LOG_DEBUG] = "DEBUG", - [LOG_INFO] = "INFO", - [LOG_NOTICE] = "NOTICE", - [LOG_WARNING] = "WARNING", - [LOG_ERROR] = "ERROR", - [LOG_CRITICAL] = "CRITICAL", - [LOG_ALERT] = "ALERT", - [LOG_FATAL] = "FATAL", + [LOG_DEBUG] = "DEBUG", [LOG_INFO] = "INFO", [LOG_NOTICE] = "NOTICE", + [LOG_WARNING] = "WARNING", [LOG_ERROR] = "ERROR", [LOG_CRITICAL] = "CRITICAL", + [LOG_ALERT] = "ALERT", [LOG_FATAL] = "FATAL", }; -static void log__submit(const char *file, - int line, - const char *func, - const struct log_config *config, - const char *subs, - unsigned int sev, - const char *format, - va_list args) +static void log__submit(const char *file, int line, const char *func, + const struct log_config *config, const char *subs, unsigned int sev, + const char *format, va_list args) { const char *prefix = NULL; FILE *out; @@ -404,11 +371,9 @@ static void log__submit(const char *file, if (prefix) { if (subs) - fprintf(out, "[%.4lld.%.6lld] %s: %s: ", - sec, usec, prefix, subs); + fprintf(out, "[%.4lld.%.6lld] %s: %s: ", sec, usec, prefix, subs); else - fprintf(out, "[%.4lld.%.6lld] %s: ", - sec, usec, prefix); + fprintf(out, "[%.4lld.%.6lld] %s: ", sec, usec, prefix); } else { if (subs) fprintf(out, "[%.4lld.%.6lld] %s: ", sec, usec, subs); @@ -432,14 +397,9 @@ static void log__submit(const char *file, fprintf(out, " (%s() in %s:%d)\n", func, file, line); } -static void log__format(const char *file, - int line, - const char *func, - const struct log_config *config, - const char *subs, - unsigned int sev, - const char *format, - ...) +static void log__format(const char *file, int line, const char *func, + const struct log_config *config, const char *subs, unsigned int sev, + const char *format, ...) { va_list list; @@ -449,14 +409,8 @@ static void log__format(const char *file, } SHL_EXPORT -void log_submit(const char *file, - int line, - const char *func, - const struct log_config *config, - const char *subs, - unsigned int sev, - const char *format, - va_list args) +void log_submit(const char *file, int line, const char *func, const struct log_config *config, + const char *subs, unsigned int sev, const char *format, va_list args) { int saved_errno = errno; @@ -468,14 +422,8 @@ void log_submit(const char *file, } SHL_EXPORT -void log_format(const char *file, - int line, - const char *func, - const struct log_config *config, - const char *subs, - unsigned int sev, - const char *format, - ...) +void log_format(const char *file, int line, const char *func, const struct log_config *config, + const char *subs, unsigned int sev, const char *format, ...) { va_list list; int saved_errno = errno; @@ -490,14 +438,8 @@ void log_format(const char *file, } SHL_EXPORT -void log_llog(void *data, - const char *file, - int line, - const char *func, - const char *subs, - unsigned int sev, - const char *format, - va_list args) +void log_llog(void *data, const char *file, int line, const char *func, const char *subs, + unsigned int sev, const char *format, va_list args) { log_submit(file, line, func, NULL, subs, sev, format, args); } @@ -506,7 +448,6 @@ void log_print_init(const char *appname) { if (!appname) appname = ""; - log_format(LOG_DEFAULT_CONF, NULL, LOG_NOTICE, - "%s Revision %s %s %s", appname, + log_format(LOG_DEFAULT_CONF, NULL, LOG_NOTICE, "%s Revision %s %s %s\n", appname, shl_git_head, __DATE__, __TIME__); } diff --git a/src/shl_log.h b/src/shl_log.h index fe623979..7840569c 100644 --- a/src/shl_log.h +++ b/src/shl_log.h @@ -119,28 +119,27 @@ struct log_config { int sev[LOG_SEV_NUM]; }; -#define LOG_CONFIG_ALL(debug, info, notice, warning, error, critical, alert, fatal) \ - (struct log_config){ .sev = { \ - [LOG_DEBUG] = (debug), \ - [LOG_INFO] = (info), \ - [LOG_NOTICE] = (notice), \ - [LOG_WARNING] = (warning), \ - [LOG_ERROR] = (error), \ - [LOG_CRITICAL] = (critical), \ - [LOG_ALERT] = (alert), \ - [LOG_FATAL] = (fatal), \ - } } +#define LOG_CONFIG_ALL(debug, info, notice, warning, error, critical, alert, fatal) \ + (struct log_config) \ + { \ + .sev = { [LOG_DEBUG] = (debug), \ + [LOG_INFO] = (info), \ + [LOG_NOTICE] = (notice), \ + [LOG_WARNING] = (warning), \ + [LOG_ERROR] = (error), \ + [LOG_CRITICAL] = (critical), \ + [LOG_ALERT] = (alert), \ + [LOG_FATAL] = (fatal), \ + } \ + } -#define LOG_CONFIG_DEBUG(debug) \ - LOG_CONFIG_ALL((debug), 2, 2, 2, 2, 2, 2, 2) -#define LOG_CONFIG_INFO(debug, info) \ - LOG_CONFIG_ALL((debug), (info), 2, 2, 2, 2, 2, 2) -#define LOG_CONFIG_WARNING(debug, info, notice, warning) \ +#define LOG_CONFIG_DEBUG(debug) LOG_CONFIG_ALL((debug), 2, 2, 2, 2, 2, 2, 2) +#define LOG_CONFIG_INFO(debug, info) LOG_CONFIG_ALL((debug), (info), 2, 2, 2, 2, 2, 2) +#define LOG_CONFIG_WARNING(debug, info, notice, warning) \ LOG_CONFIG_ALL((debug), (info), (notice), (warning), 2, 2, 2, 2) void log_set_config(const struct log_config *config); -int log_add_filter(const struct log_filter *filter, - const struct log_config *config); +int log_add_filter(const struct log_filter *filter, const struct log_config *config); void log_rm_filter(int handle); void log_clean_filter(); @@ -176,41 +175,26 @@ void log_clean_filter(); * some log-message at application start. This is a handy-helper to do this. */ -__attribute__((format(printf, 7, 0))) -void log_submit(const char *file, - int line, - const char *func, - const struct log_config *config, - const char *subs, - unsigned int sev, - const char *format, - va_list args); +__attribute__((format(printf, 7, 0))) void log_submit(const char *file, int line, const char *func, + const struct log_config *config, + const char *subs, unsigned int sev, + const char *format, va_list args); -__attribute__((format(printf, 7, 8))) -void log_format(const char *file, - int line, - const char *func, - const struct log_config *config, - const char *subs, - unsigned int sev, - const char *format, - ...); +__attribute__((format(printf, 7, 8))) void log_format(const char *file, int line, const char *func, + const struct log_config *config, + const char *subs, unsigned int sev, + const char *format, ...); -__attribute__((format(printf, 7, 0))) -void log_llog(void *data, - const char *file, - int line, - const char *func, - const char *subs, - unsigned int sev, - const char *format, - va_list args); +__attribute__((format(printf, 7, 0))) void log_llog(void *data, const char *file, int line, + const char *func, const char *subs, + unsigned int sev, const char *format, + va_list args); int log_set_file(const char *file); void log_print_init(const char *appname); -static inline __attribute__((format(printf, 2, 3))) -void log_dummyf(unsigned int sev, const char *format, ...) +static inline __attribute__((format(printf, 2, 3))) void log_dummyf(unsigned int sev, + const char *format, ...) { } @@ -256,8 +240,7 @@ extern const char *LOG_SUBSYSTEM; #define LOG_DEFAULT_CONF LOG_DEFAULT_BASE, &LOG_CONFIG #define LOG_DEFAULT LOG_DEFAULT_CONF, LOG_SUBSYSTEM -#define log_printf(sev, format, ...) \ - log_format(LOG_DEFAULT, (sev), (format), ##__VA_ARGS__) +#define log_printf(sev, format, ...) log_format(LOG_DEFAULT, (sev), (format), ##__VA_ARGS__) /* * Helpers @@ -268,27 +251,18 @@ extern const char *LOG_SUBSYSTEM; */ #ifdef BUILD_ENABLE_DEBUG - #define log_debug(format, ...) \ - log_printf(LOG_DEBUG, (format), ##__VA_ARGS__) +#define log_debug(format, ...) log_printf(LOG_DEBUG, (format), ##__VA_ARGS__) #else - #define log_debug(format, ...) \ - log_dummyf(LOG_DEBUG, (format), ##__VA_ARGS__) +#define log_debug(format, ...) log_dummyf(LOG_DEBUG, (format), ##__VA_ARGS__) #endif -#define log_info(format, ...) \ - log_printf(LOG_INFO, (format), ##__VA_ARGS__) -#define log_notice(format, ...) \ - log_printf(LOG_NOTICE, (format), ##__VA_ARGS__) -#define log_warning(format, ...) \ - log_printf(LOG_WARNING, (format), ##__VA_ARGS__) -#define log_error(format, ...) \ - log_printf(LOG_ERROR, (format), ##__VA_ARGS__) -#define log_critical(format, ...) \ - log_printf(LOG_CRITICAL, (format), ##__VA_ARGS__) -#define log_alert(format, ...) \ - log_printf(LOG_ALERT, (format), ##__VA_ARGS__) -#define log_fatal(format, ...) \ - log_printf(LOG_FATAL, (format), ##__VA_ARGS__) +#define log_info(format, ...) log_printf(LOG_INFO, (format), ##__VA_ARGS__) +#define log_notice(format, ...) log_printf(LOG_NOTICE, (format), ##__VA_ARGS__) +#define log_warning(format, ...) log_printf(LOG_WARNING, (format), ##__VA_ARGS__) +#define log_error(format, ...) log_printf(LOG_ERROR, (format), ##__VA_ARGS__) +#define log_critical(format, ...) log_printf(LOG_CRITICAL, (format), ##__VA_ARGS__) +#define log_alert(format, ...) log_printf(LOG_ALERT, (format), ##__VA_ARGS__) +#define log_fatal(format, ...) log_printf(LOG_FATAL, (format), ##__VA_ARGS__) #define log_dbg log_debug #define log_warn log_warning diff --git a/src/shl_misc.h b/src/shl_misc.h index b994bd3b..d7e96431 100644 --- a/src/shl_misc.h +++ b/src/shl_misc.h @@ -143,8 +143,7 @@ static inline unsigned long shl_next_pow2(unsigned long num) * array. You can set it to NULL to not retrieve this value. * \sep is the separator character which must be a valid ASCII character, * otherwise this will not be UTF8 safe. */ -static inline int shl_split_string(const char *arg, char ***out, - unsigned int *out_num, char sep, +static inline int shl_split_string(const char *arg, char ***out, unsigned int *out_num, char sep, bool keep_empty) { unsigned int i; @@ -175,13 +174,13 @@ static inline int shl_split_string(const char *arg, char ***out, size += len + 1; } - list = malloc(sizeof(char*) * (num + 1) + size); + list = malloc(sizeof(char *) * (num + 1) + size); if (!list) return -ENOMEM; - off = (void*)(((char*)list) + (sizeof(char*) * (num + 1))); + off = (void *)(((char *)list) + (sizeof(char *) * (num + 1))); i = 0; - for (pos = 0; pos < num; ) { + for (pos = 0; pos < num;) { list[pos] = off; while (arg[i] && arg[i] != sep) *off++ = arg[i++]; @@ -203,8 +202,7 @@ static inline int shl_split_string(const char *arg, char ***out, /* This parses \arg and splits the string into a new allocated array. The array * is stored in \out and is NULL terminated. \out_num is the number of entries * in the array. You can set it to NULL to not retrieve this value. */ -static inline int shl_split_command_string(const char *arg, char ***out, - unsigned int *out_num) +static inline int shl_split_command_string(const char *arg, char ***out, unsigned int *out_num) { unsigned int i; unsigned int num, len, size, pos; @@ -295,11 +293,11 @@ static inline int shl_split_command_string(const char *arg, char ***out, size += len + 1; } - list = malloc(sizeof(char*) * (num + 1) + size); + list = malloc(sizeof(char *) * (num + 1) + size); if (!list) return -ENOMEM; - off = (void*)(((char*)list) + (sizeof(char*) * (num + 1))); + off = (void *)(((char *)list) + (sizeof(char *) * (num + 1))); len = 0; pos = 0; in_word = false; @@ -413,6 +411,66 @@ static inline int shl_split_command_string(const char *arg, char ***out, return 0; } +static inline char *shl_replace_var(char *in) +{ + if (!in) + return NULL; + if (*in != '$') + return in; + in++; + /* if start with $$, remove 1 $ for escaping */ + if (*in == '$') + return in; + return getenv(in); +} + +static inline int shl_replace_array_with_env(char ***out, char **argv) +{ + char **t, *off; + char **nargv; + unsigned int size, i, j, len; + + if (!out || !argv) + return -EINVAL; + + for (len = 0; argv[len]; ++len) + /* empty */; + + nargv = malloc(sizeof(*nargv) * (len + 1)); + if (!nargv) + return -EINVAL; + + size = 0; + for (i = 0; i < len; ++i) { + ++size; + nargv[i] = shl_replace_var(argv[i]); + size += strlen(nargv[i]); + } + nargv[len] = NULL; + ++i; + + size += i * sizeof(char *); + + t = malloc(size); + if (!t) { + free(nargv); + return -ENOMEM; + } + *out = t; + + off = (char *)t + i * sizeof(char *); + for (i = 0; i < len; ++i) { + *t++ = off; + for (j = 0; nargv[i][j]; ++j) + *off++ = nargv[i][j]; + *off++ = 0; + } + *t = NULL; + + free(nargv); + return 0; +} + static inline int shl_dup_array_size(char ***out, char **argv, size_t len) { char **t, *off; @@ -429,14 +487,14 @@ static inline int shl_dup_array_size(char ***out, char **argv, size_t len) } ++i; - size += i * sizeof(char*); + size += i * sizeof(char *); t = malloc(size); if (!t) return -ENOMEM; *out = t; - off = (char*)t + i * sizeof(char*); + off = (char *)t + i * sizeof(char *); while (len--) { *t++ = off; for (i = 0; *argv && argv[0][i]; ++i) @@ -457,7 +515,7 @@ static inline int shl_dup_array(char ***out, char **argv) return -EINVAL; for (i = 0; argv[i]; ++i) - /* empty */ ; + /* empty */; return shl_dup_array_size(out, argv, i); } @@ -546,39 +604,33 @@ static inline int shl_read_file(const char *path, char **out, size_t *size) * We currently copy them into each library API we use so we need to keep * them in sync. Currently, they're used in uterm-input and tsm-vte. */ enum shl_xkb_mods { - SHL_SHIFT_MASK = (1 << 0), - SHL_LOCK_MASK = (1 << 1), - SHL_CONTROL_MASK = (1 << 2), - SHL_ALT_MASK = (1 << 3), - SHL_LOGO_MASK = (1 << 4), + SHL_SHIFT_MASK = (1 << 0), + SHL_LOCK_MASK = (1 << 1), + SHL_CONTROL_MASK = (1 << 2), + SHL_ALT_MASK = (1 << 3), + SHL_LOGO_MASK = (1 << 4), }; static inline unsigned int shl_get_xkb_mods(struct xkb_state *state) { unsigned int mods = 0; - if (xkb_state_mod_name_is_active(state, XKB_MOD_NAME_SHIFT, - XKB_STATE_MODS_EFFECTIVE) > 0) + if (xkb_state_mod_name_is_active(state, XKB_MOD_NAME_SHIFT, XKB_STATE_MODS_EFFECTIVE) > 0) mods |= SHL_SHIFT_MASK; - if (xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CAPS, - XKB_STATE_MODS_EFFECTIVE) > 0) + if (xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CAPS, XKB_STATE_MODS_EFFECTIVE) > 0) mods |= SHL_LOCK_MASK; - if (xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CTRL, - XKB_STATE_MODS_EFFECTIVE) > 0) + if (xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CTRL, XKB_STATE_MODS_EFFECTIVE) > 0) mods |= SHL_CONTROL_MASK; - if (xkb_state_mod_name_is_active(state, XKB_MOD_NAME_ALT, - XKB_STATE_MODS_EFFECTIVE) > 0) + if (xkb_state_mod_name_is_active(state, XKB_MOD_NAME_ALT, XKB_STATE_MODS_EFFECTIVE) > 0) mods |= SHL_ALT_MASK; - if (xkb_state_mod_name_is_active(state, XKB_MOD_NAME_LOGO, - XKB_STATE_MODS_EFFECTIVE) > 0) + if (xkb_state_mod_name_is_active(state, XKB_MOD_NAME_LOGO, XKB_STATE_MODS_EFFECTIVE) > 0) mods |= SHL_LOGO_MASK; return mods; } static inline uint32_t shl_get_ascii(struct xkb_state *state, uint32_t keycode, - const uint32_t *keysyms, - unsigned int num_keysyms) + const uint32_t *keysyms, unsigned int num_keysyms) { struct xkb_keymap *keymap; xkb_layout_index_t num_layouts; @@ -595,8 +647,7 @@ static inline uint32_t shl_get_ascii(struct xkb_state *state, uint32_t keycode, for (layout = 0; layout < num_layouts; layout++) { level = xkb_state_key_get_level(state, keycode, layout); - num_syms = xkb_keymap_key_get_syms_by_level(keymap, keycode, - layout, level, &syms); + num_syms = xkb_keymap_key_get_syms_by_level(keymap, keycode, layout, level, &syms); if (num_syms != 1) continue; @@ -607,12 +658,9 @@ static inline uint32_t shl_get_ascii(struct xkb_state *state, uint32_t keycode, return XKB_KEY_NoSymbol; } -static inline bool shl_grab_matches(unsigned int ev_mods, - unsigned int ev_num_syms, - const uint32_t *ev_syms, - unsigned int grab_mods, - unsigned int grab_num_syms, - const uint32_t *grab_syms) +static inline bool shl_grab_matches(unsigned int ev_mods, unsigned int ev_num_syms, + const uint32_t *ev_syms, unsigned int grab_mods, + unsigned int grab_num_syms, const uint32_t *grab_syms) { if (!SHL_HAS_BITS(ev_mods, grab_mods)) return false; @@ -627,19 +675,15 @@ static inline bool shl_grab_matches(unsigned int ev_mods, return true; } -static inline bool shl_grab_has_match(unsigned int ev_mods, - unsigned int ev_num_syms, - const uint32_t *ev_syms, - unsigned int grab_num, +static inline bool shl_grab_has_match(unsigned int ev_mods, unsigned int ev_num_syms, + const uint32_t *ev_syms, unsigned int grab_num, const unsigned int *grab_mods, - const unsigned int *grab_num_syms, - uint32_t **grab_syms) + const unsigned int *grab_num_syms, uint32_t **grab_syms) { unsigned int i; for (i = 0; i < grab_num; ++i) { - if (shl_grab_matches(ev_mods, ev_num_syms, ev_syms, - grab_mods[i], grab_num_syms[i], + if (shl_grab_matches(ev_mods, ev_num_syms, ev_syms, grab_mods[i], grab_num_syms[i], grab_syms[i])) return true; } diff --git a/src/shl_module.c b/src/shl_module.c index aee17b1b..b8c6d19a 100644 --- a/src/shl_module.c +++ b/src/shl_module.c @@ -30,12 +30,12 @@ #include #include #include -#include "shl_module.h" -#include "shl_module_interface.h" #include "shl_dlist.h" #include "shl_githead.h" #include "shl_log.h" #include "shl_misc.h" +#include "shl_module.h" +#include "shl_module_interface.h" #define LOG_SUBSYSTEM "module" @@ -54,8 +54,7 @@ int shl_module_open(struct shl_module **out, const char *file) handle = dlopen(file, RTLD_NOW); if (!handle) { - log_error("cannot open module %s (%d): %s", - file, errno, dlerror()); + log_error("cannot open module %s (%d): %s", file, errno, dlerror()); return -EFAULT; } @@ -67,15 +66,14 @@ int shl_module_open(struct shl_module **out, const char *file) } if (strcmp(module->info.githead, shl_git_head)) { - log_error("incompatible module %s (%s != %s)", - file, module->info.githead, shl_git_head); + log_error("incompatible module %s (%s != %s)", file, module->info.githead, + shl_git_head); ret = -EFAULT; goto err_unload; } if (module->ref != 0) { - log_error("module %s already loaded (%ld)", - file, module->ref); + log_error("module %s already loaded (%ld)", file, module->ref); ret = -EFAULT; goto err_unload; } @@ -94,17 +92,13 @@ int shl_module_open(struct shl_module **out, const char *file) log_debug(" Date: %s %s", module->info.date, module->info.time); log_debug(" GIT: %s", module->info.githead); - log_debug(" Hooks: %p %p %p %p", - module->info.init, - module->info.load, - module->info.unload, + log_debug(" Hooks: %p %p %p %p", module->info.init, module->info.load, module->info.unload, module->info.exit); if (module->info.init) { ret = module->info.init(); if (ret) { - log_error("loading module %s failed: %d", - module->file, ret); + log_error("loading module %s failed: %d", module->file, ret); goto err_file; } } @@ -195,21 +189,19 @@ void kmscon_load_modules(void) ent = opendir(BUILD_MODULE_DIR); if (!ent) { if (errno == ENOTDIR || errno == ENOENT) - log_debug("module directory %s not available", - BUILD_MODULE_DIR); + log_debug("module directory %s not available", BUILD_MODULE_DIR); else - log_error("cannot open module directory %s (%d): %m", - BUILD_MODULE_DIR, errno); + log_error("cannot open module directory %s (%d): %m", BUILD_MODULE_DIR, + errno); return; } while (true) { - errno = 0; - de = readdir(ent); + errno = 0; + de = readdir(ent); if (!de && errno != 0) { - int errsv = errno; - log_error("cannot read directory %s: %d", - BUILD_MODULE_DIR, errsv); + int errsv = errno; + log_error("cannot read directory %s: %d", BUILD_MODULE_DIR, errsv); break; } else if (!de) { break; @@ -218,11 +210,9 @@ void kmscon_load_modules(void) if (de->d_type == DT_DIR) continue; - if (de->d_type != DT_REG && - de->d_type != DT_LNK && - de->d_type != DT_UNKNOWN) { - log_warning("non-module file %s in module dir %s", - de->d_name, BUILD_MODULE_DIR); + if (de->d_type != DT_REG && de->d_type != DT_LNK && de->d_type != DT_UNKNOWN) { + log_warning("non-module file %s in module dir %s", de->d_name, + BUILD_MODULE_DIR); continue; } @@ -260,8 +250,7 @@ void kmscon_unload_modules(void) log_debug("unloading modules"); while (!shl_dlist_empty(&module_list)) { - module = shl_dlist_entry(module_list.prev, struct shl_module, - list); + module = shl_dlist_entry(module_list.prev, struct shl_module, list); shl_dlist_unlink(&module->list); shl_module_unload(module); shl_module_unref(module); diff --git a/src/shl_module_interface.h b/src/shl_module_interface.h index a83913e5..f2decf5a 100644 --- a/src/shl_module_interface.h +++ b/src/shl_module_interface.h @@ -32,19 +32,19 @@ #include #include -#include "shl_module.h" #include "shl_dlist.h" #include "shl_githead.h" #include "shl_misc.h" +#include "shl_module.h" struct shl_module_info { const char *githead; const char *date; const char *time; - int (*init) (void); - int (*load) (void); - void (*unload) (void); - void (*exit) (void); + int (*init)(void); + int (*load)(void); + void (*unload)(void); + void (*exit)(void); }; struct shl_module { @@ -56,17 +56,18 @@ struct shl_module { char *file; }; -#define SHL_MODULE(_init, _load, _unload, _exit) \ - struct shl_module module = { \ - .info = { \ - .githead = shl_git_head, \ - .date = __DATE__, \ - .time = __TIME__, \ - .init = _init, \ - .load = _load, \ - .unload = _unload, \ - .exit = _exit, \ - }, \ +#define SHL_MODULE(_init, _load, _unload, _exit) \ + struct shl_module module = { \ + .info = \ + { \ + .githead = shl_git_head, \ + .date = __DATE__, \ + .time = __TIME__, \ + .init = _init, \ + .load = _load, \ + .unload = _unload, \ + .exit = _exit, \ + }, \ }; SHL_EXPORT diff --git a/src/shl_register.h b/src/shl_register.h index d00edff0..484b50dc 100644 --- a/src/shl_register.h +++ b/src/shl_register.h @@ -45,7 +45,7 @@ #include #include "shl_dlist.h" -typedef void (*shl_register_destroy_cb) (void *data); +typedef void (*shl_register_destroy_cb)(void *data); struct shl_register_record { struct shl_dlist list; @@ -62,9 +62,10 @@ struct shl_register { struct shl_dlist records; }; -#define SHL_REGISTER_INIT(name) { \ - .mutex = PTHREAD_MUTEX_INITIALIZER, \ - .records = SHL_DLIST_INIT((name).records), \ +#define SHL_REGISTER_INIT(name) \ + { \ + .mutex = PTHREAD_MUTEX_INITIALIZER, \ + .records = SHL_DLIST_INIT((name).records), \ } static inline void shl_register_record_ref(struct shl_register_record *record) @@ -141,9 +142,9 @@ static inline void shl_register_free(struct shl_register *reg) if (!reg) return; - shl_dlist_for_each(iter, ®->records) { - record = shl_dlist_entry(iter, struct shl_register_record, - list); + shl_dlist_for_each(iter, ®->records) + { + record = shl_dlist_entry(iter, struct shl_register_record, list); shl_dlist_unlink(&record->list); shl_register_record_unref(record); } @@ -152,8 +153,7 @@ static inline void shl_register_free(struct shl_register *reg) free(reg); } -static inline int shl_register_add_cb(struct shl_register *reg, - const char *name, void *data, +static inline int shl_register_add_cb(struct shl_register *reg, const char *name, void *data, shl_register_destroy_cb destroy) { struct shl_dlist *iter; @@ -167,9 +167,9 @@ static inline int shl_register_add_cb(struct shl_register *reg, if (ret) return -EFAULT; - shl_dlist_for_each(iter, ®->records) { - record = shl_dlist_entry(iter, struct shl_register_record, - list); + shl_dlist_for_each(iter, ®->records) + { + record = shl_dlist_entry(iter, struct shl_register_record, list); if (!strcmp(record->name, name)) { ret = -EALREADY; goto out_unlock; @@ -211,14 +211,12 @@ static inline int shl_register_add_cb(struct shl_register *reg, return ret; } -static inline int shl_register_add(struct shl_register *reg, const char *name, - void *data) +static inline int shl_register_add(struct shl_register *reg, const char *name, void *data) { return shl_register_add_cb(reg, name, data, NULL); } -static inline void shl_register_remove(struct shl_register *reg, - const char *name) +static inline void shl_register_remove(struct shl_register *reg, const char *name) { struct shl_dlist *iter; struct shl_register_record *record; @@ -231,9 +229,9 @@ static inline void shl_register_remove(struct shl_register *reg, if (ret) return; - shl_dlist_for_each(iter, ®->records) { - record = shl_dlist_entry(iter, struct shl_register_record, - list); + shl_dlist_for_each(iter, ®->records) + { + record = shl_dlist_entry(iter, struct shl_register_record, list); if (strcmp(record->name, name)) continue; @@ -245,9 +243,8 @@ static inline void shl_register_remove(struct shl_register *reg, pthread_mutex_unlock(®->mutex); } -static inline struct shl_register_record *shl_register_find( - struct shl_register *reg, - const char *name) +static inline struct shl_register_record *shl_register_find(struct shl_register *reg, + const char *name) { struct shl_dlist *iter; struct shl_register_record *record, *res; @@ -261,9 +258,9 @@ static inline struct shl_register_record *shl_register_find( return NULL; res = NULL; - shl_dlist_for_each(iter, ®->records) { - record = shl_dlist_entry(iter, struct shl_register_record, - list); + shl_dlist_for_each(iter, ®->records) + { + record = shl_dlist_entry(iter, struct shl_register_record, list); if (!strcmp(record->name, name)) { res = record; shl_register_record_ref(res); @@ -275,8 +272,7 @@ static inline struct shl_register_record *shl_register_find( return res; } -static inline struct shl_register_record *shl_register_first( - struct shl_register *reg) +static inline struct shl_register_record *shl_register_first(struct shl_register *reg) { int ret; void *res; @@ -291,8 +287,7 @@ static inline struct shl_register_record *shl_register_first( if (shl_dlist_empty(®->records)) { res = NULL; } else { - res = shl_dlist_entry(reg->records.next, - struct shl_register_record, list); + res = shl_dlist_entry(reg->records.next, struct shl_register_record, list); shl_register_record_ref(res); } @@ -300,8 +295,7 @@ static inline struct shl_register_record *shl_register_first( return res; } -static inline struct shl_register_record *shl_register_last( - struct shl_register *reg) +static inline struct shl_register_record *shl_register_last(struct shl_register *reg) { int ret; void *res; @@ -316,8 +310,7 @@ static inline struct shl_register_record *shl_register_last( if (shl_dlist_empty(®->records)) { res = NULL; } else { - res = shl_dlist_entry(reg->records.prev, - struct shl_register_record, list); + res = shl_dlist_entry(reg->records.prev, struct shl_register_record, list); shl_register_record_ref(res); } diff --git a/src/shl_ring.h b/src/shl_ring.h index bd346f64..a8f8105f 100644 --- a/src/shl_ring.h +++ b/src/shl_ring.h @@ -89,8 +89,7 @@ static inline bool shl_ring_is_empty(struct shl_ring *ring) return ring->first == NULL; } -static inline int shl_ring_write(struct shl_ring *ring, const char *val, - size_t len) +static inline int shl_ring_write(struct shl_ring *ring, const char *val, size_t len) { struct shl_ring_entry *ent; size_t space, cp; @@ -131,8 +130,7 @@ static inline int shl_ring_write(struct shl_ring *ring, const char *val, return 0; } -static inline const char *shl_ring_peek(struct shl_ring *ring, size_t *len, - size_t offset) +static inline const char *shl_ring_peek(struct shl_ring *ring, size_t *len, size_t offset) { struct shl_ring_entry *iter; diff --git a/src/text.c b/src/text.c index 29cb079d..5d6f95c5 100644 --- a/src/text.c +++ b/src/text.c @@ -76,11 +76,9 @@ int kmscon_text_register(const struct kmscon_text_ops *ops) log_debug("register text backend %s", ops->name); - ret = shl_register_add_cb(&text_reg, ops->name, (void*)ops, - kmscon_text_destroy); + ret = shl_register_add_cb(&text_reg, ops->name, (void *)ops, kmscon_text_destroy); if (ret) { - log_error("cannot register text backend %s: %d", ops->name, - ret); + log_error("cannot register text backend %s: %d", ops->name, ret); return ret; } @@ -167,16 +165,13 @@ int kmscon_text_new(struct kmscon_text **out, const char *backend, const char *r if (strncmp(rotate, "normal", 6) == 0) { text->orientation = OR_NORMAL; log_debug("using: orientation: normal"); - } - else if (strncmp(rotate, "right", 5) == 0) { + } else if (strncmp(rotate, "right", 5) == 0) { text->orientation = OR_RIGHT; log_debug("using: orientation: right"); - } - else if (strncmp(rotate, "upside-down", 8) == 0) { + } else if (strncmp(rotate, "upside-down", 8) == 0) { text->orientation = OR_UPSIDE_DOWN; log_debug("using: orientation: upside-down"); - } - else if (strncmp(rotate, "left", 4) == 0) { + } else if (strncmp(rotate, "left", 4) == 0) { text->orientation = OR_LEFT; log_debug("using: orientation: left"); } @@ -253,10 +248,8 @@ void kmscon_text_unref(struct kmscon_text *text) * * Returns: 0 on success, negative error code on failure. */ -int kmscon_text_set(struct kmscon_text *txt, - struct kmscon_font *font, - struct kmscon_font *bold_font, - struct uterm_display *disp) +int kmscon_text_set(struct kmscon_text *txt, struct kmscon_font *font, + struct kmscon_font *bold_font, struct uterm_display *disp) { int ret; @@ -445,10 +438,8 @@ int kmscon_text_prepare(struct kmscon_text *txt) * * Returns: 0 on success or negative error code if this glyph couldn't be drawn. */ -int kmscon_text_draw(struct kmscon_text *txt, - uint64_t id, const uint32_t *ch, size_t len, - unsigned int width, - unsigned int posx, unsigned int posy, +int kmscon_text_draw(struct kmscon_text *txt, uint64_t id, const uint32_t *ch, size_t len, + unsigned int width, unsigned int posx, unsigned int posy, const struct tsm_screen_attr *attr) { bool previous_overflow; @@ -480,9 +471,8 @@ int kmscon_text_draw(struct kmscon_text *txt, * * Returns: 0 on success or negative error code if it couldn't be drawn. */ -int kmscon_text_draw_pointer(struct kmscon_text *txt, - unsigned int x, unsigned int y, - const struct tsm_screen_attr *attr) +int kmscon_text_draw_pointer(struct kmscon_text *txt, unsigned int x, unsigned int y, + const struct tsm_screen_attr *attr) { if (!txt || !txt->rendering || !txt->ops->draw_pointer) return -EINVAL; @@ -533,12 +523,9 @@ void kmscon_text_abort(struct kmscon_text *txt) txt->rendering = false; } -int kmscon_text_draw_cb(struct tsm_screen *con, - uint64_t id, const uint32_t *ch, size_t len, - unsigned int width, - unsigned int posx, unsigned int posy, - const struct tsm_screen_attr *attr, - tsm_age_t age, void *data) +int kmscon_text_draw_cb(struct tsm_screen *con, uint64_t id, const uint32_t *ch, size_t len, + unsigned int width, unsigned int posx, unsigned int posy, + const struct tsm_screen_attr *attr, tsm_age_t age, void *data) { return kmscon_text_draw(data, id, ch, len, width, posx, posy, attr); } \ No newline at end of file diff --git a/src/text.h b/src/text.h index da8a4926..74063253 100644 --- a/src/text.h +++ b/src/text.h @@ -45,7 +45,7 @@ enum Orientation { OR_NORMAL = 0, // 0 Degree OR_RIGHT, // 90 Degree - OR_UPSIDE_DOWN, // 180 Degree + OR_UPSIDE_DOWN, // 180 Degree OR_LEFT, // 270 Degree }; @@ -71,23 +71,19 @@ struct kmscon_text { struct kmscon_text_ops { const char *name; struct shl_module *owner; - int (*init) (struct kmscon_text *txt); - void (*destroy) (struct kmscon_text *txt); - int (*set) (struct kmscon_text *txt); - void (*unset) (struct kmscon_text *txt); - int (*rotate) (struct kmscon_text *txt, enum Orientation orientation); - int (*prepare) (struct kmscon_text *txt); - int (*draw) (struct kmscon_text *txt, - uint64_t id, const uint32_t *ch, size_t len, - unsigned int width, - unsigned int posx, unsigned int posy, - const struct tsm_screen_attr *attr); - int (*draw_pointer) (struct kmscon_text *txt, - unsigned int x, - unsigned int y, - const struct tsm_screen_attr *attr); - int (*render) (struct kmscon_text *txt); - void (*abort) (struct kmscon_text *txt); + int (*init)(struct kmscon_text *txt); + void (*destroy)(struct kmscon_text *txt); + int (*set)(struct kmscon_text *txt); + void (*unset)(struct kmscon_text *txt); + int (*rotate)(struct kmscon_text *txt, enum Orientation orientation); + int (*prepare)(struct kmscon_text *txt); + int (*draw)(struct kmscon_text *txt, uint64_t id, const uint32_t *ch, size_t len, + unsigned int width, unsigned int posx, unsigned int posy, + const struct tsm_screen_attr *attr); + int (*draw_pointer)(struct kmscon_text *txt, unsigned int x, unsigned int y, + const struct tsm_screen_attr *attr); + int (*render)(struct kmscon_text *txt); + void (*abort)(struct kmscon_text *txt); }; #define FONT_WIDTH(txt) ((txt)->font->attr.width) @@ -100,10 +96,8 @@ int kmscon_text_new(struct kmscon_text **out, const char *backend, const char *r void kmscon_text_ref(struct kmscon_text *txt); void kmscon_text_unref(struct kmscon_text *txt); -int kmscon_text_set(struct kmscon_text *txt, - struct kmscon_font *font, - struct kmscon_font *bold_font, - struct uterm_display *disp); +int kmscon_text_set(struct kmscon_text *txt, struct kmscon_font *font, + struct kmscon_font *bold_font, struct uterm_display *disp); void kmscon_text_unset(struct kmscon_text *txt); unsigned int kmscon_text_get_cols(struct kmscon_text *txt); unsigned int kmscon_text_get_rows(struct kmscon_text *txt); @@ -112,23 +106,17 @@ enum Orientation kmscon_text_get_orientation(struct kmscon_text *txt); int kmscon_text_rotate(struct kmscon_text *txt, enum Orientation orientation); int kmscon_text_prepare(struct kmscon_text *txt); -int kmscon_text_draw(struct kmscon_text *txt, - uint64_t id, const uint32_t *ch, size_t len, - unsigned int width, - unsigned int posx, unsigned int posy, +int kmscon_text_draw(struct kmscon_text *txt, uint64_t id, const uint32_t *ch, size_t len, + unsigned int width, unsigned int posx, unsigned int posy, const struct tsm_screen_attr *attr); -int kmscon_text_draw_pointer(struct kmscon_text *txt, - unsigned int x, unsigned int y, +int kmscon_text_draw_pointer(struct kmscon_text *txt, unsigned int x, unsigned int y, const struct tsm_screen_attr *attr); int kmscon_text_render(struct kmscon_text *txt); void kmscon_text_abort(struct kmscon_text *txt); -int kmscon_text_draw_cb(struct tsm_screen *con, - uint64_t id, const uint32_t *ch, size_t len, - unsigned int width, - unsigned int posx, unsigned int posy, - const struct tsm_screen_attr *attr, - tsm_age_t age, void *data); +int kmscon_text_draw_cb(struct tsm_screen *con, uint64_t id, const uint32_t *ch, size_t len, + unsigned int width, unsigned int posx, unsigned int posy, + const struct tsm_screen_attr *attr, tsm_age_t age, void *data); /* modularized backends */ diff --git a/src/text_bbulk.c b/src/text_bbulk.c index ae2cdca4..1e762443 100644 --- a/src/text_bbulk.c +++ b/src/text_bbulk.c @@ -86,15 +86,14 @@ static int bbulk_set(struct kmscon_text *txt) struct bbulk *bb = txt->data; unsigned int sw, sh, i, j; struct uterm_video_blend_req *req; - struct uterm_mode *mode; memset(bb, 0, sizeof(*bb)); - mode = uterm_display_get_current(txt->disp); - if (!mode) + sw = uterm_display_get_width(txt->disp); + sh = uterm_display_get_height(txt->disp); + + if (!sw || !sh) return -EINVAL; - sw = uterm_mode_get_width(mode); - sh = uterm_mode_get_height(mode); if (txt->orientation == OR_NORMAL || txt->orientation == OR_UPSIDE_DOWN) { txt->cols = sw / FONT_WIDTH(txt); @@ -132,7 +131,6 @@ static int bbulk_set(struct kmscon_text *txt) req->y = sh - (j + 1) * FONT_WIDTH(txt); break; } - } } if (kmscon_rotate_create_tables(&bb->glyphs, &bb->bold_glyphs, free_glyph)) @@ -160,8 +158,8 @@ static int bbulk_rotate(struct kmscon_text *txt, enum Orientation orientation) return bbulk_set(txt); } -static int find_glyph(struct kmscon_text *txt, struct uterm_video_buffer **out, - uint64_t id, const uint32_t *ch, size_t len, const struct tsm_screen_attr *attr) +static int find_glyph(struct kmscon_text *txt, struct uterm_video_buffer **out, uint64_t id, + const uint32_t *ch, size_t len, const struct tsm_screen_attr *attr) { struct bbulk *bb = txt->data; struct uterm_video_buffer *bb_glyph; @@ -189,7 +187,7 @@ static int find_glyph(struct kmscon_text *txt, struct uterm_video_buffer **out, else font->attr.italic = false; - res = shl_hashtable_find(gtable, (void**)&bb_glyph, id); + res = shl_hashtable_find(gtable, (void **)&bb_glyph, id); if (res) { *out = bb_glyph; return 0; @@ -211,7 +209,7 @@ static int find_glyph(struct kmscon_text *txt, struct uterm_video_buffer **out, goto err_free; } - ret = kmscon_rotate_glyph( bb_glyph, glyph, txt->orientation, 1); + ret = kmscon_rotate_glyph(bb_glyph, glyph, txt->orientation, 1); if (ret) goto err_free; @@ -229,10 +227,8 @@ static int find_glyph(struct kmscon_text *txt, struct uterm_video_buffer **out, return ret; } -static int bbulk_draw(struct kmscon_text *txt, - uint64_t id, const uint32_t *ch, size_t len, - unsigned int width, - unsigned int posx, unsigned int posy, +static int bbulk_draw(struct kmscon_text *txt, uint64_t id, const uint32_t *ch, size_t len, + unsigned int width, unsigned int posx, unsigned int posy, const struct tsm_screen_attr *attr) { struct bbulk *bb = txt->data; @@ -281,25 +277,20 @@ static int bbulk_draw(struct kmscon_text *txt, return 0; } -static int bblit_draw_pointer(struct kmscon_text *txt, - unsigned int pointer_x, unsigned int pointer_y, - const struct tsm_screen_attr *attr) +static int bblit_draw_pointer(struct kmscon_text *txt, unsigned int pointer_x, + unsigned int pointer_y, const struct tsm_screen_attr *attr) { struct bbulk *bb = txt->data; struct uterm_video_blend_req *req; struct uterm_video_buffer *bb_glyph; - struct uterm_mode *mode; uint32_t ch = 'I'; uint64_t id = ch; unsigned int sw, sh; unsigned int m_x, m_y, x, y; int ret; - mode = uterm_display_get_current(txt->disp); - if (!mode) - return -EINVAL; - sw = uterm_mode_get_width(mode); - sh = uterm_mode_get_height(mode); + sw = uterm_display_get_width(txt->disp); + sh = uterm_display_get_height(txt->disp); if (txt->orientation == OR_NORMAL || txt->orientation == OR_UPSIDE_DOWN) { m_x = SHL_DIV_ROUND_UP(FONT_WIDTH(txt), 2); @@ -367,8 +358,7 @@ static int bbulk_render(struct kmscon_text *txt) struct bbulk *bb = txt->data; int ret; - ret = uterm_display_fake_blendv(txt->disp, bb->reqs, - bb->req_len); + ret = uterm_display_fake_blendv(txt->disp, bb->reqs, bb->req_len); return ret; } diff --git a/src/text_gltex.c b/src/text_gltex.c index 4997514e..49c455b4 100644 --- a/src/text_gltex.c +++ b/src/text_gltex.c @@ -38,9 +38,9 @@ #define GL_GLEXT_PROTOTYPES -#include #include #include +#include #include #include #include @@ -51,15 +51,15 @@ #include "shl_log.h" #include "shl_misc.h" #include "text.h" -#include "uterm_video.h" #include "text_gltex_atlas.frag.bin.h" #include "text_gltex_atlas.vert.bin.h" +#include "uterm_video.h" #define LOG_SUBSYSTEM "text_gltex" /* thanks khronos for breaking backwards compatibility.. */ #if !defined(GL_UNPACK_ROW_LENGTH) && defined(GL_UNPACK_ROW_LENGTH_EXT) -# define GL_UNPACK_ROW_LENGTH GL_UNPACK_ROW_LENGTH_EXT +#define GL_UNPACK_ROW_LENGTH GL_UNPACK_ROW_LENGTH_EXT #endif struct atlas { @@ -150,23 +150,19 @@ static int gltex_set(struct kmscon_text *txt) struct gltex *gt = txt->data; int ret, vlen, flen; const char *vert, *frag; - static char *attr[] = { "position", "texture_position", - "fgcolor", "bgcolor" }; + static char *attr[] = {"position", "texture_position", "fgcolor", "bgcolor"}; GLint s; const char *ext; - struct uterm_mode *mode; bool opengl; memset(gt, 0, sizeof(*gt)); shl_dlist_init(>->atlases); - ret = shl_hashtable_new(>->glyphs, shl_direct_hash, - shl_direct_equal, free_glyph); + ret = shl_hashtable_new(>->glyphs, shl_direct_hash, shl_direct_equal, free_glyph); if (ret) return ret; - ret = shl_hashtable_new(>->bold_glyphs, shl_direct_hash, - shl_direct_equal, free_glyph); + ret = shl_hashtable_new(>->bold_glyphs, shl_direct_hash, shl_direct_equal, free_glyph); if (ret) goto err_htable; @@ -183,8 +179,7 @@ static int gltex_set(struct kmscon_text *txt) flen = _binary_text_gltex_atlas_frag_size; gl_clear_error(); - ret = gl_shader_new(>->shader, vert, vlen, frag, flen, attr, 4, - log_llog, NULL); + ret = gl_shader_new(>->shader, vert, vlen, frag, flen, attr, 4, log_llog, NULL); if (ret) goto err_bold_htable; @@ -192,19 +187,16 @@ static int gltex_set(struct kmscon_text *txt) gt->uni_sin = gl_shader_get_uniform(gt->shader, "sin"); gt->uni_proj = gl_shader_get_uniform(gt->shader, "projection"); gt->uni_atlas = gl_shader_get_uniform(gt->shader, "atlas"); - gt->uni_advance_htex = gl_shader_get_uniform(gt->shader, - "advance_htex"); - gt->uni_advance_vtex = gl_shader_get_uniform(gt->shader, - "advance_vtex"); + gt->uni_advance_htex = gl_shader_get_uniform(gt->shader, "advance_htex"); + gt->uni_advance_vtex = gl_shader_get_uniform(gt->shader, "advance_vtex"); if (gl_has_error(gt->shader)) { log_warning("cannot create shader"); goto err_shader; } - mode = uterm_display_get_current(txt->disp); - gt->sw = uterm_mode_get_width(mode); - gt->sh = uterm_mode_get_height(mode); + gt->sw = uterm_display_get_width(txt->disp); + gt->sh = uterm_display_get_height(txt->disp); if (txt->orientation == OR_NORMAL || txt->orientation == OR_UPSIDE_DOWN) { txt->cols = gt->sw / FONT_WIDTH(txt); @@ -223,11 +215,12 @@ static int gltex_set(struct kmscon_text *txt) gl_clear_error(); - ext = (const char*)glGetString(GL_EXTENSIONS); - if (ext && strstr((const char*)ext, "GL_EXT_unpack_subimage")) { + ext = (const char *)glGetString(GL_EXTENSIONS); + if (ext && strstr((const char *)ext, "GL_EXT_unpack_subimage")) { gt->supports_rowlen = true; } else { - log_warning("your GL implementation does not support GL_EXT_unpack_subimage, glyph-rendering may be slower than usual"); + log_warning("your GL implementation does not support GL_EXT_unpack_subimage, " + "glyph-rendering may be slower than usual"); } return 0; @@ -291,8 +284,7 @@ static struct atlas *get_atlas(struct kmscon_text *txt, unsigned int num) /* check whether the last added atlas has still room for one glyph */ if (!shl_dlist_empty(>->atlases)) { - atlas = shl_dlist_entry(gt->atlases.next, struct atlas, - list); + atlas = shl_dlist_entry(gt->atlases.next, struct atlas, list); if (atlas->fill + num <= atlas->count) return atlas; } @@ -327,8 +319,8 @@ static struct atlas *get_atlas(struct kmscon_text *txt, unsigned int num) gl_clear_error(); glBindTexture(GL_TEXTURE_2D, atlas->tex); - glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, - 0, GL_ALPHA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, + NULL); err = glGetError(); if (err != GL_NO_ERROR) { @@ -337,8 +329,7 @@ static struct atlas *get_atlas(struct kmscon_text *txt, unsigned int num) goto try_next; } gl_clear_error(); - log_warning("OpenGL textures too small for a single glyph (%d)", - err); + log_warning("OpenGL textures too small for a single glyph (%d)", err); goto err_tex; } @@ -384,8 +375,8 @@ static struct atlas *get_atlas(struct kmscon_text *txt, unsigned int num) return NULL; } -static int find_glyph(struct kmscon_text *txt, struct glyph **out, - uint64_t id, const uint32_t *ch, size_t len, const struct tsm_screen_attr *attr) +static int find_glyph(struct kmscon_text *txt, struct glyph **out, uint64_t id, const uint32_t *ch, + size_t len, const struct tsm_screen_attr *attr) { struct gltex *gt = txt->data; struct atlas *atlas; @@ -415,7 +406,7 @@ static int find_glyph(struct kmscon_text *txt, struct glyph **out, else font->attr.italic = false; - res = shl_hashtable_find(gtable, (void**)&glyph, id); + res = shl_hashtable_find(gtable, (void **)&glyph, id); if (res) { *out = glyph; return 0; @@ -456,12 +447,9 @@ static int find_glyph(struct kmscon_text *txt, struct glyph **out, glPixelStorei(GL_UNPACK_ALIGNMENT, 1); if (!gt->supports_rowlen) { if (GLYPH_STRIDE(glyph) == GLYPH_WIDTH(glyph)) { - glTexSubImage2D(GL_TEXTURE_2D, 0, - FONT_WIDTH(txt) * atlas->fill, 0, - GLYPH_WIDTH(glyph), - GLYPH_HEIGHT(glyph), - GL_ALPHA, GL_UNSIGNED_BYTE, - GLYPH_DATA(glyph)); + glTexSubImage2D(GL_TEXTURE_2D, 0, FONT_WIDTH(txt) * atlas->fill, 0, + GLYPH_WIDTH(glyph), GLYPH_HEIGHT(glyph), GL_ALPHA, + GL_UNSIGNED_BYTE, GLYPH_DATA(glyph)); } else { packed_data = malloc(GLYPH_WIDTH(glyph) * GLYPH_HEIGHT(glyph)); if (!packed_data) { @@ -478,21 +466,15 @@ static int find_glyph(struct kmscon_text *txt, struct glyph **out, src += GLYPH_STRIDE(glyph); } - glTexSubImage2D(GL_TEXTURE_2D, 0, - FONT_WIDTH(txt) * atlas->fill, 0, - GLYPH_WIDTH(glyph), - GLYPH_HEIGHT(glyph), - GL_ALPHA, GL_UNSIGNED_BYTE, - packed_data); + glTexSubImage2D(GL_TEXTURE_2D, 0, FONT_WIDTH(txt) * atlas->fill, 0, + GLYPH_WIDTH(glyph), GLYPH_HEIGHT(glyph), GL_ALPHA, + GL_UNSIGNED_BYTE, packed_data); free(packed_data); } } else { glPixelStorei(GL_UNPACK_ROW_LENGTH, GLYPH_STRIDE(glyph)); - glTexSubImage2D(GL_TEXTURE_2D, 0, - FONT_WIDTH(txt) * atlas->fill, 0, - GLYPH_WIDTH(glyph), - GLYPH_HEIGHT(glyph), - GL_ALPHA, GL_UNSIGNED_BYTE, + glTexSubImage2D(GL_TEXTURE_2D, 0, FONT_WIDTH(txt) * atlas->fill, 0, + GLYPH_WIDTH(glyph), GLYPH_HEIGHT(glyph), GL_ALPHA, GL_UNSIGNED_BYTE, GLYPH_DATA(glyph)); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); } @@ -509,7 +491,8 @@ static int find_glyph(struct kmscon_text *txt, struct glyph **out, err = glGetError(); if (err != GL_NO_ERROR) { gl_clear_error(); - log_warning("cannot load glyph data into OpenGL texture (%d: %s); disable the GL-renderer if this does not work reliably", + log_warning("cannot load glyph data into OpenGL texture (%d: %s); disable the " + "GL-renderer if this does not work reliably", err, gl_err_to_str(err)); ret = -EFAULT; goto err_free; @@ -552,11 +535,11 @@ static int gltex_rotate(struct kmscon_text *txt, enum Orientation orientation) gt->advance_x = 2.0 / gt->sw * FONT_WIDTH(txt); gt->advance_y = 2.0 / gt->sh * FONT_HEIGHT(txt); } else { - float aspect = (float) gt->sw / (float) gt->sh; + float aspect = (float)gt->sw / (float)gt->sh; txt->cols = gt->sh / FONT_WIDTH(txt); txt->rows = gt->sw / FONT_HEIGHT(txt); gt->advance_x = 2.0 / gt->sw * FONT_WIDTH(txt) * aspect; - gt->advance_y = 2.0 / gt->sh * FONT_HEIGHT(txt) * (1./aspect); + gt->advance_y = 2.0 / gt->sh * FONT_HEIGHT(txt) * (1. / aspect); } gltex_unset(txt); gltex_set(txt); @@ -574,7 +557,8 @@ static int gltex_prepare(struct kmscon_text *txt) if (ret) return ret; - shl_dlist_for_each(iter, >->atlases) { + shl_dlist_for_each(iter, >->atlases) + { atlas = shl_dlist_entry(iter, struct atlas, list); atlas->cache_num = 0; @@ -584,19 +568,17 @@ static int gltex_prepare(struct kmscon_text *txt) gt->advance_x = 2.0 / gt->sw * FONT_WIDTH(txt); gt->advance_y = 2.0 / gt->sh * FONT_HEIGHT(txt); } else { - float aspect = (float) gt->sw / (float) gt->sh; + float aspect = (float)gt->sw / (float)gt->sh; gt->advance_x = 2.0 / gt->sw * FONT_WIDTH(txt) * aspect; - gt->advance_y = 2.0 / gt->sh * FONT_HEIGHT(txt) * (1./aspect); + gt->advance_y = 2.0 / gt->sh * FONT_HEIGHT(txt) * (1. / aspect); } gltex_set_rotate(gt, txt->orientation); return 0; } -static int gltex_draw(struct kmscon_text *txt, - uint64_t id, const uint32_t *ch, size_t len, - unsigned int width, - unsigned int posx, unsigned int posy, +static int gltex_draw(struct kmscon_text *txt, uint64_t id, const uint32_t *ch, size_t len, + unsigned int width, unsigned int posx, unsigned int posy, const struct tsm_screen_attr *attr) { struct gltex *gt = txt->data; @@ -677,8 +659,7 @@ static int gltex_draw(struct kmscon_text *txt, return 0; } -static int gltex_draw_pointer(struct kmscon_text *txt, - unsigned int x, unsigned int y, +static int gltex_draw_pointer(struct kmscon_text *txt, unsigned int x, unsigned int y, const struct tsm_screen_attr *attr) { struct gltex *gt = txt->data; @@ -699,7 +680,7 @@ static int gltex_draw_pointer(struct kmscon_text *txt, if (atlas->cache_num >= atlas->cache_size) return -ERANGE; - if(txt->orientation == OR_NORMAL || txt->orientation == OR_UPSIDE_DOWN) { + if (txt->orientation == OR_NORMAL || txt->orientation == OR_UPSIDE_DOWN) { sw = gt->sw; sh = gt->sh; } else { @@ -790,7 +771,8 @@ static int gltex_render(struct kmscon_text *txt) glActiveTexture(GL_TEXTURE0); glUniform1i(gt->uni_atlas, 0); - shl_dlist_for_each(iter, >->atlases) { + shl_dlist_for_each(iter, >->atlases) + { atlas = shl_dlist_entry(iter, struct atlas, list); if (!atlas->cache_num) continue; diff --git a/src/uterm_drm2d_internal.h b/src/uterm_drm2d_internal.h index e3c8aa91..98fc0388 100644 --- a/src/uterm_drm2d_internal.h +++ b/src/uterm_drm2d_internal.h @@ -35,7 +35,7 @@ #include "uterm_video.h" struct uterm_drm2d_rb { - uint32_t fb; + uint32_t id; uint32_t handle; uint32_t stride; uint64_t size; @@ -53,11 +53,9 @@ struct uterm_drm2d_video { }; int uterm_drm2d_display_fake_blendv(struct uterm_display *disp, - const struct uterm_video_blend_req *req, - size_t num); -int uterm_drm2d_display_fill(struct uterm_display *disp, - uint8_t r, uint8_t g, uint8_t b, - unsigned int x, unsigned int y, - unsigned int width, unsigned int height); + const struct uterm_video_blend_req *req, size_t num); +int uterm_drm2d_display_fill(struct uterm_display *disp, uint8_t r, uint8_t g, uint8_t b, + unsigned int x, unsigned int y, unsigned int width, + unsigned int height); #endif /* UTERM_DRM2D_INTERNAL_H */ diff --git a/src/uterm_drm2d_render.c b/src/uterm_drm2d_render.c index fbb9019a..02a26d45 100644 --- a/src/uterm_drm2d_render.c +++ b/src/uterm_drm2d_render.c @@ -39,16 +39,15 @@ #include #include "eloop.h" #include "shl_log.h" -#include "uterm_drm_shared_internal.h" #include "uterm_drm2d_internal.h" +#include "uterm_drm_shared_internal.h" #include "uterm_video.h" #include "uterm_video_internal.h" #define LOG_SUBSYSTEM "uterm_drm2d_render" int uterm_drm2d_display_fake_blendv(struct uterm_display *disp, - const struct uterm_video_blend_req *req, - size_t num) + const struct uterm_video_blend_req *req, size_t num) { unsigned int tmp; uint8_t *dst, *src; @@ -62,8 +61,8 @@ int uterm_drm2d_display_fake_blendv(struct uterm_display *disp, return -EINVAL; rb = &d2d->rb[d2d->current_rb ^ 1]; - sw = uterm_drm_mode_get_width(disp->current_mode); - sh = uterm_drm_mode_get_height(disp->current_mode); + sw = disp->width; + sh = disp->height; for (j = 0; j < num; ++j, ++req) { if (!req->buf) @@ -110,24 +109,21 @@ int uterm_drm2d_display_fake_blendv(struct uterm_display *disp, b = req->fb; out = (r << 16) | (g << 8) | b; } else { - r = req->fr * src[i] + - req->br * (255 - src[i]); + r = req->fr * src[i] + req->br * (255 - src[i]); r += 0x80; r = (r + (r >> 8)) >> 8; - g = req->fg * src[i] + - req->bg * (255 - src[i]); + g = req->fg * src[i] + req->bg * (255 - src[i]); g += 0x80; g = (g + (g >> 8)) >> 8; - b = req->fb * src[i] + - req->bb * (255 - src[i]); + b = req->fb * src[i] + req->bb * (255 - src[i]); b += 0x80; b = (b + (b >> 8)) >> 8; out = (r << 16) | (g << 8) | b; } - ((uint32_t*)dst)[i] = out; + ((uint32_t *)dst)[i] = out; } dst += rb->stride; src += req->buf->stride; @@ -137,10 +133,9 @@ int uterm_drm2d_display_fake_blendv(struct uterm_display *disp, return 0; } -int uterm_drm2d_display_fill(struct uterm_display *disp, - uint8_t r, uint8_t g, uint8_t b, - unsigned int x, unsigned int y, - unsigned int width, unsigned int height) +int uterm_drm2d_display_fill(struct uterm_display *disp, uint8_t r, uint8_t g, uint8_t b, + unsigned int x, unsigned int y, unsigned int width, + unsigned int height) { unsigned int tmp, i; uint8_t *dst; @@ -149,8 +144,8 @@ int uterm_drm2d_display_fill(struct uterm_display *disp, struct uterm_drm2d_display *d2d = uterm_drm_display_get_data(disp); rb = &d2d->rb[d2d->current_rb ^ 1]; - sw = uterm_drm_mode_get_width(disp->current_mode); - sh = uterm_drm_mode_get_height(disp->current_mode); + sw = disp->width; + sh = disp->height; tmp = x + width; if (tmp < x || x >= sw) @@ -168,7 +163,7 @@ int uterm_drm2d_display_fill(struct uterm_display *disp, while (height--) { for (i = 0; i < width; ++i) - ((uint32_t*)dst)[i] = (r << 16) | (g << 8) | b; + ((uint32_t *)dst)[i] = (r << 16) | (g << 8) | b; dst += rb->stride; } diff --git a/src/uterm_drm2d_video.c b/src/uterm_drm2d_video.c index 0284b008..af3d90a1 100644 --- a/src/uterm_drm2d_video.c +++ b/src/uterm_drm2d_video.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -40,8 +41,8 @@ #include "eloop.h" #include "shl_log.h" #include "shl_misc.h" -#include "uterm_drm_shared_internal.h" #include "uterm_drm2d_internal.h" +#include "uterm_drm_shared_internal.h" #include "uterm_video.h" #include "uterm_video_internal.h" @@ -72,51 +73,47 @@ static void display_destroy(struct uterm_display *disp) uterm_drm_display_destroy(disp); } +static int drm_addfb2(int fd, uint32_t width, uint32_t height, struct uterm_drm2d_rb *rb) +{ + uint32_t handles[4] = {rb->handle, 0, 0, 0}; + uint32_t pitches[4] = {rb->stride, 0, 0, 0}; + uint32_t offsets[4] = {0, 0, 0, 0}; + + return drmModeAddFB2(fd, width, height, DRM_FORMAT_XRGB8888, handles, pitches, offsets, + &rb->id, 0); +} + static int init_rb(struct uterm_display *disp, struct uterm_drm2d_rb *rb) { int ret, r; struct uterm_video *video = disp->video; struct uterm_drm_video *vdrm = video->data; - struct drm_mode_create_dumb req; - struct drm_mode_destroy_dumb dreq; - struct drm_mode_map_dumb mreq; - - memset(&req, 0, sizeof(req)); - req.width = uterm_drm_mode_get_width(disp->current_mode); - req.height = uterm_drm_mode_get_height(disp->current_mode); - req.bpp = 32; - req.flags = 0; - - ret = drmIoctl(vdrm->fd, DRM_IOCTL_MODE_CREATE_DUMB, &req); - if (ret < 0) { + uint32_t width, height; + uint64_t mmap_offset; + + width = disp->width; + height = disp->height; + + if (drmModeCreateDumbBuffer(vdrm->fd, width, height, 32, 0, &rb->handle, &rb->stride, + &rb->size)) { log_err("cannot create dumb drm buffer"); return -EFAULT; } - rb->handle = req.handle; - rb->stride = req.pitch; - rb->size = req.size; - - ret = drmModeAddFB(vdrm->fd, req.width, req.height, - 24, 32, rb->stride, rb->handle, &rb->fb); + ret = drm_addfb2(vdrm->fd, width, height, rb); if (ret) { log_err("cannot add drm-fb"); ret = -EFAULT; goto err_buf; } - memset(&mreq, 0, sizeof(mreq)); - mreq.handle = rb->handle; - - ret = drmIoctl(vdrm->fd, DRM_IOCTL_MODE_MAP_DUMB, &mreq); + ret = drmModeMapDumbBuffer(vdrm->fd, rb->handle, &mmap_offset); if (ret) { - log_err("cannot map dumb buffer"); - ret = -EFAULT; + log_err("Cannot map dumb buffer"); goto err_fb; } - rb->map = mmap(0, rb->size, PROT_READ | PROT_WRITE, MAP_SHARED, - vdrm->fd, mreq.offset); + rb->map = mmap(0, rb->size, PROT_READ | PROT_WRITE, MAP_SHARED, vdrm->fd, mmap_offset); if (rb->map == MAP_FAILED) { log_err("cannot mmap dumb buffer"); ret = -EFAULT; @@ -127,14 +124,11 @@ static int init_rb(struct uterm_display *disp, struct uterm_drm2d_rb *rb) return 0; err_fb: - drmModeRmFB(vdrm->fd, rb->fb); + drmModeRmFB(vdrm->fd, rb->id); err_buf: - memset(&dreq, 0, sizeof(dreq)); - dreq.handle = rb->handle; - r = drmIoctl(vdrm->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &dreq); + r = drmModeDestroyDumbBuffer(vdrm->fd, rb->handle); if (r) - log_warning("cannot destroy dumb buffer (%d/%d): %m", - ret, errno); + log_warning("cannot destroy dumb buffer (%d/%d): %m", ret, errno); return ret; } @@ -142,21 +136,16 @@ static int init_rb(struct uterm_display *disp, struct uterm_drm2d_rb *rb) static void destroy_rb(struct uterm_display *disp, struct uterm_drm2d_rb *rb) { struct uterm_drm_video *vdrm = disp->video->data; - struct drm_mode_destroy_dumb dreq; int ret; munmap(rb->map, rb->size); - drmModeRmFB(vdrm->fd, rb->fb); - memset(&dreq, 0, sizeof(dreq)); - dreq.handle = rb->handle; - ret = drmIoctl(vdrm->fd, DRM_IOCTL_MODE_DESTROY_DUMB, - &dreq); + drmModeRmFB(vdrm->fd, rb->id); + ret = drmModeDestroyDumbBuffer(vdrm->fd, rb->handle); if (ret) - log_warning("cannot destroy dumb buffer (%d/%d): %m", - ret, errno); + log_warning("cannot destroy dumb buffer (%d/%d): %m", ret, errno); } -static int display_activate(struct uterm_display *disp, struct uterm_mode *mode) +static int display_activate(struct uterm_display *disp) { struct uterm_video *video = disp->video; struct uterm_drm_video *vdrm = video->data; @@ -165,19 +154,21 @@ static int display_activate(struct uterm_display *disp, struct uterm_mode *mode) int ret; drmModeModeInfo *minfo; - if (!mode) - return -EINVAL; + if (video->use_original) + ddrm->current_mode = ddrm->original_mode; + else + ddrm->current_mode = ddrm->desired_mode; + minfo = &ddrm->current_mode->info; + disp->width = minfo->hdisplay; + disp->height = minfo->vdisplay; - minfo = uterm_drm_mode_get_info(mode);; - log_info("activating display %p to %ux%u", disp, - minfo->hdisplay, minfo->vdisplay); + log_info("activating display %p to %ux%u", disp, minfo->hdisplay, minfo->vdisplay); ret = uterm_drm_display_activate(disp, vdrm->fd); if (ret) return ret; d2d->current_rb = 0; - disp->current_mode = mode; ret = init_rb(disp, &d2d->rb[0]); if (ret) @@ -187,12 +178,12 @@ static int display_activate(struct uterm_display *disp, struct uterm_mode *mode) if (ret) goto err_rb; - ret = drmModeSetCrtc(vdrm->fd, ddrm->crtc_id, - d2d->rb[0].fb, 0, 0, &ddrm->conn_id, 1, + ret = drmModeSetCrtc(vdrm->fd, ddrm->crtc_id, d2d->rb[0].id, 0, 0, &ddrm->conn_id, 1, minfo); - if (ret && mode == disp->desired_mode && mode != disp->default_mode) { - mode = disp->desired_mode = disp->default_mode; + if (ret && ddrm->current_mode == ddrm->desired_mode && + ddrm->current_mode != ddrm->default_mode) { + ddrm->current_mode = ddrm->desired_mode = ddrm->default_mode; ret = -EAGAIN; goto err_fb; } else if (ret) { @@ -209,7 +200,8 @@ static int display_activate(struct uterm_display *disp, struct uterm_mode *mode) err_rb: destroy_rb(disp, &d2d->rb[0]); err_saved: - disp->current_mode = NULL; + disp->width = 0; + disp->height = 0; uterm_drm_display_deactivate(disp, vdrm->fd); return ret; } @@ -226,7 +218,8 @@ static void display_deactivate(struct uterm_display *disp) destroy_rb(disp, &d2d->rb[1]); destroy_rb(disp, &d2d->rb[0]); - disp->current_mode = NULL; + disp->width = 0; + disp->height = 0; } static int display_use(struct uterm_display *disp, bool *opengl) @@ -239,36 +232,13 @@ static int display_use(struct uterm_display *disp, bool *opengl) return d2d->current_rb ^ 1; } -static int display_get_buffers(struct uterm_display *disp, - struct uterm_video_buffer *buffer, - unsigned int formats) -{ - struct uterm_drm2d_display *d2d = uterm_drm_display_get_data(disp); - struct uterm_drm2d_rb *rb; - int i; - - if (!(formats & UTERM_FORMAT_XRGB32)) - return -EOPNOTSUPP; - - for (i = 0; i < 2; ++i) { - rb = &d2d->rb[i]; - buffer[i].width = uterm_drm_mode_get_width(disp->current_mode); - buffer[i].height = uterm_drm_mode_get_height(disp->current_mode); - buffer[i].stride = rb->stride; - buffer[i].format = UTERM_FORMAT_XRGB32; - buffer[i].data = rb->map; - } - - return 0; -} - static int display_swap(struct uterm_display *disp, bool immediate) { int ret, rb; struct uterm_drm2d_display *d2d = uterm_drm_display_get_data(disp); rb = d2d->current_rb ^ 1; - ret = uterm_drm_display_swap(disp, d2d->rb[rb].fb, immediate); + ret = uterm_drm_display_swap(disp, d2d->rb[rb].id, immediate); if (ret) return ret; @@ -283,8 +253,8 @@ static const struct display_ops drm2d_display_ops = { .deactivate = display_deactivate, .set_dpms = uterm_drm_display_set_dpms, .use = display_use, - .get_buffers = display_get_buffers, .swap = display_swap, + .is_swapping = uterm_drm_is_swapping, .fake_blendv = uterm_drm2d_display_fake_blendv, .fill = uterm_drm2d_display_fill, }; @@ -299,7 +269,8 @@ static void show_displays(struct uterm_video *video) if (!video_is_awake(video)) return; - shl_dlist_for_each(i, &video->displays) { + shl_dlist_for_each(i, &video->displays) + { iter = shl_dlist_entry(i, struct uterm_display, list); if (!display_is_online(iter)) @@ -326,16 +297,14 @@ static int video_init(struct uterm_video *video, const char *node) uint64_t has_dumb; struct uterm_drm_video *vdrm; - ret = uterm_drm_video_init(video, node, &drm2d_display_ops, - NULL, NULL); + ret = uterm_drm_video_init(video, node, &drm2d_display_ops, NULL, NULL); if (ret) return ret; vdrm = video->data; log_debug("initialize 2D layer on %p", video); - if (drmGetCap(vdrm->fd, DRM_CAP_DUMB_BUFFER, &has_dumb) < 0 || - !has_dumb) { + if (drmGetCap(vdrm->fd, DRM_CAP_DUMB_BUFFER, &has_dumb) < 0 || !has_dumb) { log_err("driver does not support dumb buffers"); uterm_drm_video_destroy(video); return -EOPNOTSUPP; @@ -378,11 +347,12 @@ static int video_wake_up(struct uterm_video *video) struct uterm_video_module drm2d_module = { .name = "drm2d", .owner = NULL, - .ops = { - .init = video_init, - .destroy = video_destroy, - .segfault = NULL, /* TODO: reset all saved CRTCs on segfault */ - .poll = video_poll, - .sleep = video_sleep, - .wake_up = video_wake_up,}, + .ops = + { + .init = video_init, + .destroy = video_destroy, + .poll = video_poll, + .sleep = video_sleep, + .wake_up = video_wake_up, + }, }; diff --git a/src/uterm_drm3d_internal.h b/src/uterm_drm3d_internal.h index 6ddd80e5..854cf733 100644 --- a/src/uterm_drm3d_internal.h +++ b/src/uterm_drm3d_internal.h @@ -33,11 +33,11 @@ #include #include +#include +#include #include #include #include -#include -#include #include #include #include @@ -49,13 +49,13 @@ /* thanks khronos for breaking backwards compatibility.. */ #if !defined(GL_UNPACK_ROW_LENGTH) && defined(GL_UNPACK_ROW_LENGTH_EXT) -# define GL_UNPACK_ROW_LENGTH GL_UNPACK_ROW_LENGTH_EXT +#define GL_UNPACK_ROW_LENGTH GL_UNPACK_ROW_LENGTH_EXT #endif struct uterm_drm3d_rb { struct uterm_display *disp; struct gbm_bo *bo; - uint32_t fb; + uint32_t id; }; struct uterm_drm3d_display { @@ -88,11 +88,9 @@ struct uterm_drm3d_video { int uterm_drm3d_display_use(struct uterm_display *disp, bool *opengl); void uterm_drm3d_deinit_shaders(struct uterm_video *video); int uterm_drm3d_display_fake_blendv(struct uterm_display *disp, - const struct uterm_video_blend_req *req, - size_t num); -int uterm_drm3d_display_fill(struct uterm_display *disp, - uint8_t r, uint8_t g, uint8_t b, - unsigned int x, unsigned int y, - unsigned int width, unsigned int height); + const struct uterm_video_blend_req *req, size_t num); +int uterm_drm3d_display_fill(struct uterm_display *disp, uint8_t r, uint8_t g, uint8_t b, + unsigned int x, unsigned int y, unsigned int width, + unsigned int height); #endif /* UTERM_DRM3D_INTERNAL_H */ diff --git a/src/uterm_drm3d_render.c b/src/uterm_drm3d_render.c index bfaf1d08..728905ce 100644 --- a/src/uterm_drm3d_render.c +++ b/src/uterm_drm3d_render.c @@ -32,11 +32,11 @@ #include #include +#include +#include #include #include #include -#include -#include #include #include #include @@ -47,14 +47,14 @@ #include "eloop.h" #include "shl_gl.h" #include "shl_log.h" -#include "uterm_drm_shared_internal.h" +#include "uterm_drm3d_blend.frag.bin.h" +#include "uterm_drm3d_blend.vert.bin.h" +#include "uterm_drm3d_fill.frag.bin.h" +#include "uterm_drm3d_fill.vert.bin.h" #include "uterm_drm3d_internal.h" +#include "uterm_drm_shared_internal.h" #include "uterm_video.h" #include "uterm_video_internal.h" -#include "uterm_drm3d_blend.vert.bin.h" -#include "uterm_drm3d_blend.frag.bin.h" -#include "uterm_drm3d_fill.vert.bin.h" -#include "uterm_drm3d_fill.frag.bin.h" #define LOG_SUBSYSTEM "uterm_drm3d_render" @@ -62,8 +62,8 @@ static int init_shaders(struct uterm_video *video) { struct uterm_drm3d_video *v3d = uterm_drm_video_get_data(video); int ret; - char *fill_attr[] = { "position", "color" }; - char *blend_attr[] = { "position", "texture_position" }; + char *fill_attr[] = {"position", "color"}; + char *blend_attr[] = {"position", "texture_position"}; int blend_vlen, blend_flen, fill_vlen, fill_flen; const char *blend_vert, *blend_frag; const char *fill_vert, *fill_frag; @@ -84,29 +84,22 @@ static int init_shaders(struct uterm_video *video) fill_frag = _binary_uterm_drm3d_fill_frag_start; fill_flen = _binary_uterm_drm3d_fill_frag_size; - ret = gl_shader_new(&v3d->fill_shader, fill_vert, fill_vlen, - fill_frag, fill_flen, fill_attr, 2, log_llog, - NULL); + ret = gl_shader_new(&v3d->fill_shader, fill_vert, fill_vlen, fill_frag, fill_flen, + fill_attr, 2, log_llog, NULL); if (ret) return ret; - v3d->uni_fill_proj = gl_shader_get_uniform(v3d->fill_shader, - "projection"); + v3d->uni_fill_proj = gl_shader_get_uniform(v3d->fill_shader, "projection"); - ret = gl_shader_new(&v3d->blend_shader, blend_vert, blend_vlen, - blend_frag, blend_flen, blend_attr, 2, log_llog, - NULL); + ret = gl_shader_new(&v3d->blend_shader, blend_vert, blend_vlen, blend_frag, blend_flen, + blend_attr, 2, log_llog, NULL); if (ret) return ret; - v3d->uni_blend_proj = gl_shader_get_uniform(v3d->blend_shader, - "projection"); - v3d->uni_blend_tex = gl_shader_get_uniform(v3d->blend_shader, - "texture"); - v3d->uni_blend_fgcol = gl_shader_get_uniform(v3d->blend_shader, - "fgcolor"); - v3d->uni_blend_bgcol = gl_shader_get_uniform(v3d->blend_shader, - "bgcolor"); + v3d->uni_blend_proj = gl_shader_get_uniform(v3d->blend_shader, "projection"); + v3d->uni_blend_tex = gl_shader_get_uniform(v3d->blend_shader, "texture"); + v3d->uni_blend_fgcol = gl_shader_get_uniform(v3d->blend_shader, "fgcolor"); + v3d->uni_blend_bgcol = gl_shader_get_uniform(v3d->blend_shader, "bgcolor"); gl_tex_new(&v3d->tex, 1); v3d->sinit = 2; @@ -127,10 +120,8 @@ void uterm_drm3d_deinit_shaders(struct uterm_video *video) gl_shader_unref(v3d->fill_shader); } -static int display_blend(struct uterm_display *disp, - const struct uterm_video_buffer *buf, - unsigned int x, unsigned int y, - uint8_t fr, uint8_t fg, uint8_t fb, +static int display_blend(struct uterm_display *disp, const struct uterm_video_buffer *buf, + unsigned int x, unsigned int y, uint8_t fr, uint8_t fg, uint8_t fb, uint8_t br, uint8_t bg, uint8_t bb) { struct uterm_drm3d_video *v3d; @@ -151,8 +142,8 @@ static int display_blend(struct uterm_display *disp, if (ret) return ret; - sw = uterm_drm_mode_get_width(disp->current_mode); - sh = uterm_drm_mode_get_height(disp->current_mode); + sw = disp->width; + sh = disp->height; vertices[0] = -1.0; vertices[1] = -1.0; @@ -222,12 +213,12 @@ static int display_blend(struct uterm_display *disp, if (v3d->supports_rowlen) { glPixelStorei(GL_UNPACK_ROW_LENGTH, buf->stride); - glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, - GL_ALPHA, GL_UNSIGNED_BYTE, buf->data); + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, + GL_UNSIGNED_BYTE, buf->data); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); } else if (buf->stride == width) { - glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, - GL_ALPHA, GL_UNSIGNED_BYTE, buf->data); + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, + GL_UNSIGNED_BYTE, buf->data); } else { packed = malloc(width * height); if (!packed) @@ -241,8 +232,8 @@ static int display_blend(struct uterm_display *disp, src += buf->stride; } - glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, - GL_ALPHA, GL_UNSIGNED_BYTE, packed); + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, + GL_UNSIGNED_BYTE, packed); free(packed); } @@ -267,8 +258,7 @@ static int display_blend(struct uterm_display *disp, } int uterm_drm3d_display_fake_blendv(struct uterm_display *disp, - const struct uterm_video_blend_req *req, - size_t num) + const struct uterm_video_blend_req *req, size_t num) { int ret; unsigned int i; @@ -280,8 +270,7 @@ int uterm_drm3d_display_fake_blendv(struct uterm_display *disp, if (!req->buf) continue; - ret = display_blend(disp, req->buf, req->x, req->y, - req->fr, req->fg, req->fb, + ret = display_blend(disp, req->buf, req->x, req->y, req->fr, req->fg, req->fb, req->br, req->bg, req->bb); if (ret) return ret; @@ -290,10 +279,9 @@ int uterm_drm3d_display_fake_blendv(struct uterm_display *disp, return 0; } -int uterm_drm3d_display_fill(struct uterm_display *disp, - uint8_t r, uint8_t g, uint8_t b, - unsigned int x, unsigned int y, - unsigned int width, unsigned int height) +int uterm_drm3d_display_fill(struct uterm_display *disp, uint8_t r, uint8_t g, uint8_t b, + unsigned int x, unsigned int y, unsigned int width, + unsigned int height) { struct uterm_drm3d_video *v3d; unsigned int sw, sh, tmp, i; @@ -309,8 +297,8 @@ int uterm_drm3d_display_fill(struct uterm_display *disp, if (ret) return ret; - sw = uterm_drm_mode_get_width(disp->current_mode); - sh = uterm_drm_mode_get_height(disp->current_mode); + sw = disp->width; + sh = disp->height; for (i = 0; i < 6; ++i) { colors[i * 4 + 0] = r / 255.0; @@ -349,7 +337,7 @@ int uterm_drm3d_display_fill(struct uterm_display *disp, * and positive y-axis up, while other parts uses a coordinate system * with the origin at _upper-left_ corner and positive y-axis down. */ - y = sh - y; // invert y-axis + y = sh - y; // invert y-axis y -= height; // move origin to lower left corner glViewport(x, y, width, height); diff --git a/src/uterm_drm3d_video.c b/src/uterm_drm3d_video.c index ec397b51..d66ec46c 100644 --- a/src/uterm_drm3d_video.c +++ b/src/uterm_drm3d_video.c @@ -32,11 +32,12 @@ #include #include +#include +#include +#include #include #include #include -#include -#include #include #include #include @@ -47,8 +48,8 @@ #include "eloop.h" #include "shl_log.h" #include "shl_misc.h" -#include "uterm_drm_shared_internal.h" #include "uterm_drm3d_internal.h" +#include "uterm_drm_shared_internal.h" #include "uterm_video.h" #include "uterm_video_internal.h" @@ -88,42 +89,39 @@ static void bo_destroy_event(struct gbm_bo *bo, void *data) return; vdrm = rb->disp->video->data; - drmModeRmFB(vdrm->fd, rb->fb); + drmModeRmFB(vdrm->fd, rb->id); free(rb); } -static struct uterm_drm3d_rb *bo_to_rb(struct uterm_display *disp, - struct gbm_bo *bo) +static int drm_addfb2(int fd, struct uterm_drm3d_rb *rb) +{ + uint32_t handles[4] = {gbm_bo_get_handle(rb->bo).u32, 0, 0, 0}; + uint32_t pitches[4] = {gbm_bo_get_stride(rb->bo), 0, 0, 0}; + uint32_t offsets[4] = {0, 0, 0, 0}; + + return drmModeAddFB2(fd, gbm_bo_get_width(rb->bo), gbm_bo_get_height(rb->bo), + DRM_FORMAT_XRGB8888, handles, pitches, offsets, &rb->id, 0); +} + +static struct uterm_drm3d_rb *bo_to_rb(struct uterm_display *disp, struct gbm_bo *bo) { struct uterm_drm3d_rb *rb = gbm_bo_get_user_data(bo); struct uterm_video *video = disp->video; struct uterm_drm_video *vdrm = video->data; int ret; - unsigned int stride, handle, width, height;; if (rb) return rb; rb = malloc(sizeof(*rb)); if (!rb) { - log_error("cannot allocate memory for render buffer (%d): %m", - errno); + log_error("cannot allocate memory for render buffer (%d): %m", errno); return NULL; } rb->disp = disp; rb->bo = bo; -#ifdef BUILD_HAVE_GBM_BO_GET_PITCH - stride = gbm_bo_get_pitch(rb->bo); -#else - stride = gbm_bo_get_stride(rb->bo); -#endif - handle = gbm_bo_get_handle(rb->bo).u32; - width = gbm_bo_get_width(rb->bo); - height = gbm_bo_get_height(rb->bo); - - ret = drmModeAddFB(vdrm->fd, width, height, 24, 32, stride, - handle, &rb->fb); + ret = drm_addfb2(vdrm->fd, rb); if (ret) { log_err("cannot add drm-fb (%d): %m", errno); free(rb); @@ -134,8 +132,7 @@ static struct uterm_drm3d_rb *bo_to_rb(struct uterm_display *disp, return rb; } -static int display_activate(struct uterm_display *disp, - struct uterm_mode *mode) +static int display_activate(struct uterm_display *disp) { struct uterm_video *video = disp->video; struct uterm_drm_video *vdrm; @@ -146,14 +143,19 @@ static int display_activate(struct uterm_display *disp, struct gbm_bo *bo; drmModeModeInfo *minfo; - if (!mode) - return -EINVAL; - vdrm = video->data; v3d = uterm_drm_video_get_data(video); - minfo = uterm_drm_mode_get_info(mode); - log_info("activating display %p to %ux%u", disp, - minfo->hdisplay, minfo->vdisplay); + + if (video->use_original) + ddrm->current_mode = ddrm->original_mode; + else + ddrm->current_mode = ddrm->desired_mode; + + minfo = &ddrm->current_mode->info; + disp->width = minfo->hdisplay; + disp->height = minfo->vdisplay; + + log_info("activating display %p to %ux%u", disp, minfo->hdisplay, minfo->vdisplay); ret = uterm_drm_display_activate(disp, vdrm->fd); if (ret) @@ -161,29 +163,25 @@ static int display_activate(struct uterm_display *disp, d3d->current = NULL; d3d->next = NULL; - disp->current_mode = mode; - d3d->gbm = gbm_surface_create(v3d->gbm, minfo->hdisplay, - minfo->vdisplay, GBM_FORMAT_XRGB8888, - GBM_BO_USE_SCANOUT | - GBM_BO_USE_RENDERING); + d3d->gbm = + gbm_surface_create(v3d->gbm, minfo->hdisplay, minfo->vdisplay, GBM_FORMAT_XRGB8888, + GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); if (!d3d->gbm) { log_error("cannot create gbm surface (%d): %m", errno); ret = -EFAULT; goto err_saved; } - d3d->surface = eglCreateWindowSurface(v3d->disp, v3d->conf, - (EGLNativeWindowType)d3d->gbm, - NULL); + d3d->surface = + eglCreateWindowSurface(v3d->disp, v3d->conf, (EGLNativeWindowType)d3d->gbm, NULL); if (d3d->surface == EGL_NO_SURFACE) { log_error("cannot create EGL window surface"); ret = -EFAULT; goto err_gbm; } - if (!eglMakeCurrent(v3d->disp, d3d->surface, d3d->surface, - v3d->ctx)) { + if (!eglMakeCurrent(v3d->disp, d3d->surface, d3d->surface, v3d->ctx)) { log_error("cannot activate EGL context"); ret = -EFAULT; goto err_surface; @@ -211,10 +209,11 @@ static int display_activate(struct uterm_display *disp, goto err_bo; } - ret = drmModeSetCrtc(vdrm->fd, ddrm->crtc_id, d3d->current->fb, - 0, 0, &ddrm->conn_id, 1, minfo); - if (ret && mode == disp->desired_mode && mode != disp->default_mode) { - mode = disp->desired_mode = disp->default_mode; + ret = drmModeSetCrtc(vdrm->fd, ddrm->crtc_id, d3d->current->id, 0, 0, &ddrm->conn_id, 1, + minfo); + if (ret && ddrm->current_mode == ddrm->desired_mode && + ddrm->current_mode != ddrm->default_mode) { + ddrm->current_mode = ddrm->desired_mode = ddrm->default_mode; ret = -EAGAIN; goto err_bo; } else if (ret) { @@ -229,14 +228,15 @@ static int display_activate(struct uterm_display *disp, err_bo: gbm_surface_release_buffer(d3d->gbm, bo); err_noctx: - eglMakeCurrent(v3d->disp, EGL_NO_SURFACE, EGL_NO_SURFACE, - v3d->ctx); + eglMakeCurrent(v3d->disp, EGL_NO_SURFACE, EGL_NO_SURFACE, v3d->ctx); err_surface: eglDestroySurface(v3d->disp, d3d->surface); err_gbm: gbm_surface_destroy(d3d->gbm); err_saved: - disp->current_mode = NULL; + disp->width = 0; + disp->height = 0; + ddrm->current_mode = NULL; uterm_drm_display_deactivate(disp, vdrm->fd); return ret; } @@ -254,23 +254,21 @@ static void display_deactivate(struct uterm_display *disp) v3d = uterm_drm_video_get_data(video); uterm_drm_display_deactivate(disp, vdrm->fd); - eglMakeCurrent(v3d->disp, EGL_NO_SURFACE, EGL_NO_SURFACE, - v3d->ctx); + eglMakeCurrent(v3d->disp, EGL_NO_SURFACE, EGL_NO_SURFACE, v3d->ctx); eglDestroySurface(v3d->disp, d3d->surface); if (d3d->current) { - gbm_surface_release_buffer(d3d->gbm, - d3d->current->bo); + gbm_surface_release_buffer(d3d->gbm, d3d->current->bo); d3d->current = NULL; } if (d3d->next) { - gbm_surface_release_buffer(d3d->gbm, - d3d->next->bo); + gbm_surface_release_buffer(d3d->gbm, d3d->next->bo); d3d->next = NULL; } gbm_surface_destroy(d3d->gbm); - disp->current_mode = NULL; + disp->width = 0; + disp->height = 0; } int uterm_drm3d_display_use(struct uterm_display *disp, bool *opengl) @@ -279,8 +277,7 @@ int uterm_drm3d_display_use(struct uterm_display *disp, bool *opengl) struct uterm_drm3d_video *v3d; v3d = uterm_drm_video_get_data(disp->video); - if (!eglMakeCurrent(v3d->disp, d3d->surface, - d3d->surface, v3d->ctx)) { + if (!eglMakeCurrent(v3d->disp, d3d->surface, d3d->surface, v3d->ctx)) { log_error("cannot activate EGL context"); return -EFAULT; } @@ -322,7 +319,7 @@ static int display_swap(struct uterm_display *disp, bool immediate) return -EFAULT; } - ret = uterm_drm_display_swap(disp, rb->fb, immediate); + ret = uterm_drm_display_swap(disp, rb->id, immediate); if (ret) { gbm_surface_release_buffer(d3d->gbm, bo); return ret; @@ -351,8 +348,8 @@ static const struct display_ops drm_display_ops = { .deactivate = display_deactivate, .set_dpms = uterm_drm_display_set_dpms, .use = uterm_drm3d_display_use, - .get_buffers = NULL, .swap = display_swap, + .is_swapping = uterm_drm_is_swapping, .fake_blendv = uterm_drm3d_display_fake_blendv, .fill = uterm_drm3d_display_fill, }; @@ -366,7 +363,8 @@ static void show_displays(struct uterm_video *video) if (!video_is_awake(video)) return; - shl_dlist_for_each(i, &video->displays) { + shl_dlist_for_each(i, &video->displays) + { iter = shl_dlist_entry(i, struct uterm_display, list); if (!display_is_online(iter)) @@ -390,8 +388,7 @@ static void page_flip_handler(struct uterm_display *disp) if (d3d->next) { if (d3d->current) - gbm_surface_release_buffer(d3d->gbm, - d3d->current->bo); + gbm_surface_release_buffer(d3d->gbm, d3d->current->bo); d3d->current = d3d->next; d3d->next = NULL; } @@ -400,18 +397,21 @@ static void page_flip_handler(struct uterm_display *disp) static int video_init(struct uterm_video *video, const char *node) { static const EGLint conf_att[] = { - EGL_SURFACE_TYPE, EGL_WINDOW_BIT, - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, - EGL_RED_SIZE, 1, - EGL_GREEN_SIZE, 1, - EGL_BLUE_SIZE, 1, - EGL_ALPHA_SIZE, 0, + EGL_SURFACE_TYPE, + EGL_WINDOW_BIT, + EGL_RENDERABLE_TYPE, + EGL_OPENGL_ES2_BIT, + EGL_RED_SIZE, + 1, + EGL_GREEN_SIZE, + 1, + EGL_BLUE_SIZE, + 1, + EGL_ALPHA_SIZE, + 0, EGL_NONE, }; - static const EGLint ctx_att[] = { - EGL_CONTEXT_CLIENT_VERSION, 2, - EGL_NONE - }; + static const EGLint ctx_att[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE}; const char *ext; int ret; EGLint major, minor, n = 0; @@ -429,8 +429,7 @@ static int video_init(struct uterm_video *video, const char *node) return -ENOMEM; memset(v3d, 0, sizeof(*v3d)); - ret = uterm_drm_video_init(video, node, &drm_display_ops, - page_flip_handler, v3d); + ret = uterm_drm_video_init(video, node, &drm_display_ops, page_flip_handler, v3d); if (ret) goto err_free; vdrm = video->data; @@ -439,13 +438,12 @@ static int video_init(struct uterm_video *video, const char *node) v3d->gbm = gbm_create_device(vdrm->fd); if (!v3d->gbm) { - log_err("cannot create gbm device for %s (permission denied)", - node); + log_err("cannot create gbm device for %s (permission denied)", node); ret = -EFAULT; goto err_video; } - v3d->disp = eglGetDisplay((EGLNativeDisplayType) v3d->gbm); + v3d->disp = eglGetDisplay((EGLNativeDisplayType)v3d->gbm); if (v3d->disp == EGL_NO_DISPLAY) { log_err("cannot retrieve egl display for %s", node); ret = -EFAULT; @@ -511,7 +509,8 @@ static int video_init(struct uterm_video *video, const char *node) if (gbmFmt == GBM_FORMAT_XRGB8888 || gbmFmt == GBM_FORMAT_ARGB8888) { if (!eglGetConfigAttrib(v3d->disp, cfgs[i], EGL_CONFIG_ID, &cfgId)) { err = eglGetError(); - log_warning("cfgs[%d] matched, but failed to get ID (error %x).", i, err); + log_warning("cfgs[%d] matched, but failed to get ID (error %x).", i, + err); } else { log_debug("config with ID %x matched", cfgId); } @@ -527,26 +526,25 @@ static int video_init(struct uterm_video *video, const char *node) goto err_cfgs; } - v3d->ctx = eglCreateContext(v3d->disp, v3d->conf, EGL_NO_CONTEXT, - ctx_att); + v3d->ctx = eglCreateContext(v3d->disp, v3d->conf, EGL_NO_CONTEXT, ctx_att); if (v3d->ctx == EGL_NO_CONTEXT) { log_error("cannot create egl context"); ret = -EFAULT; goto err_cfgs; } - if (!eglMakeCurrent(v3d->disp, EGL_NO_SURFACE, EGL_NO_SURFACE, - v3d->ctx)) { + if (!eglMakeCurrent(v3d->disp, EGL_NO_SURFACE, EGL_NO_SURFACE, v3d->ctx)) { log_error("cannot activate surfaceless EGL context"); ret = -EFAULT; goto err_ctx; } - ext = (const char*)glGetString(GL_EXTENSIONS); - if (ext && strstr((const char*)ext, "GL_EXT_unpack_subimage")) + ext = (const char *)glGetString(GL_EXTENSIONS); + if (ext && strstr((const char *)ext, "GL_EXT_unpack_subimage")) v3d->supports_rowlen = true; else - log_warning("your GL implementation does not support GL_EXT_unpack_subimage, rendering may be slower than usual"); + log_warning("your GL implementation does not support GL_EXT_unpack_subimage, " + "rendering may be slower than usual"); return 0; @@ -571,13 +569,11 @@ static void video_destroy(struct uterm_video *video) log_info("free drm video device %p", video); - if (!eglMakeCurrent(v3d->disp, EGL_NO_SURFACE, EGL_NO_SURFACE, - v3d->ctx)) + if (!eglMakeCurrent(v3d->disp, EGL_NO_SURFACE, EGL_NO_SURFACE, v3d->ctx)) log_error("cannot activate GL context during destruction"); uterm_drm3d_deinit_shaders(video); - eglMakeCurrent(v3d->disp, EGL_NO_SURFACE, EGL_NO_SURFACE, - EGL_NO_CONTEXT); + eglMakeCurrent(v3d->disp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroyContext(v3d->disp, v3d->ctx); eglTerminate(v3d->disp); gbm_device_destroy(v3d->gbm); @@ -614,13 +610,12 @@ SHL_EXPORT struct uterm_video_module drm3d_module = { .name = "drm3d", .owner = NULL, - .ops = { - .init = video_init, - .destroy = video_destroy, - .segfault = NULL, /* TODO: reset all saved CRTCs on segfault */ - .poll = video_poll, - .sleep = video_sleep, - .wake_up = video_wake_up, - }, + .ops = + { + .init = video_init, + .destroy = video_destroy, + .poll = video_poll, + .sleep = video_sleep, + .wake_up = video_wake_up, + }, }; - diff --git a/src/uterm_drm_shared.c b/src/uterm_drm_shared.c index 36c00f0b..b14a7624 100644 --- a/src/uterm_drm_shared.c +++ b/src/uterm_drm_shared.c @@ -36,7 +36,9 @@ #include #include #include +#include "shl_dlist.h" #include "shl_log.h" +#include "shl_misc.h" #include "shl_timer.h" #include "uterm_drm_shared_internal.h" #include "uterm_video.h" @@ -44,60 +46,18 @@ #define LOG_SUBSYSTEM "drm_shared" -int uterm_drm_mode_init(struct uterm_mode *mode) +static struct uterm_mode *mode_new(drmModeModeInfo *info) { - struct uterm_drm_mode *m; + struct uterm_mode *new; - m = malloc(sizeof(*m)); - if (!m) - return -ENOMEM; - memset(m, 0, sizeof(*m)); - mode->data = m; - - return 0; -} - -void uterm_drm_mode_destroy(struct uterm_mode *mode) -{ - free(mode->data); -} + new = malloc(sizeof(*new)); + if (!new) + return NULL; + new->info = *info; -const char *uterm_drm_mode_get_name(const struct uterm_mode *mode) -{ - struct uterm_drm_mode *m = mode->data; - - return m->info.name; + return new; } -unsigned int uterm_drm_mode_get_width(const struct uterm_mode *mode) -{ - struct uterm_drm_mode *m = mode->data; - - return m->info.hdisplay; -} - -unsigned int uterm_drm_mode_get_height(const struct uterm_mode *mode) -{ - struct uterm_drm_mode *m = mode->data; - - return m->info.vdisplay; -} - -void uterm_drm_mode_set(struct uterm_mode *mode, drmModeModeInfo *info) -{ - struct uterm_drm_mode *m = mode->data; - - m->info = *info; -} - -const struct mode_ops uterm_drm_mode_ops = { - .init = uterm_drm_mode_init, - .destroy = uterm_drm_mode_destroy, - .get_name = uterm_drm_mode_get_name, - .get_width = uterm_drm_mode_get_width, - .get_height = uterm_drm_mode_get_height, -}; - int uterm_drm_set_dpms(int fd, uint32_t conn_id, int state) { int i, ret, set; @@ -136,8 +96,7 @@ int uterm_drm_set_dpms(int fd, uint32_t conn_id, int state) } if (!strcmp(prop->name, "DPMS")) { - ret = drmModeConnectorSetProperty(fd, conn_id, - prop->prop_id, set); + ret = drmModeConnectorSetProperty(fd, conn_id, prop->prop_id, set); if (ret) { log_info("cannot set DPMS"); ret = -EFAULT; @@ -204,6 +163,7 @@ int uterm_drm_display_init(struct uterm_display *disp, void *data) if (!d) return -ENOMEM; memset(d, 0, sizeof(*d)); + shl_dlist_init(&d->modes); disp->data = d; d->data = data; @@ -212,6 +172,14 @@ int uterm_drm_display_init(struct uterm_display *disp, void *data) void uterm_drm_display_destroy(struct uterm_display *disp) { + struct uterm_mode *mode; + struct uterm_drm_display *ddrm = disp->data; + + while (!shl_dlist_empty(&ddrm->modes)) { + mode = shl_dlist_entry(ddrm->modes.prev, struct uterm_mode, list); + shl_dlist_unlink(&mode->list); + free(mode); + } free(disp->data); } @@ -271,11 +239,8 @@ void uterm_drm_display_deactivate(struct uterm_display *disp, int fd) if (ddrm->saved_crtc) { if (disp->video->flags & VIDEO_AWAKE) { - drmModeSetCrtc(fd, ddrm->saved_crtc->crtc_id, - ddrm->saved_crtc->buffer_id, - ddrm->saved_crtc->x, - ddrm->saved_crtc->y, - &ddrm->conn_id, 1, + drmModeSetCrtc(fd, ddrm->saved_crtc->crtc_id, ddrm->saved_crtc->buffer_id, + ddrm->saved_crtc->x, ddrm->saved_crtc->y, &ddrm->conn_id, 1, &ddrm->saved_crtc->mode); } drmModeFreeCrtc(ddrm->saved_crtc); @@ -292,8 +257,7 @@ int uterm_drm_display_set_dpms(struct uterm_display *disp, int state) struct uterm_drm_display *ddrm = disp->data; struct uterm_drm_video *vdrm = disp->video->data; - log_info("setting DPMS of display %p to %s", disp, - uterm_dpms_to_name(state)); + log_info("setting DPMS of display %p to %s", disp, uterm_dpms_to_name(state)); ret = uterm_drm_set_dpms(vdrm->fd, ddrm->conn_id, state); if (ret < 0) @@ -323,16 +287,14 @@ int uterm_drm_display_wait_pflip(struct uterm_display *disp) if (ret < 0) return ret; if (ret == 0 || !timeout) { - log_warning("timeout waiting for page-flip on display %p", - disp); + log_warning("timeout waiting for page-flip on display %p", disp); return -ETIMEDOUT; } return 0; } -int uterm_drm_display_swap(struct uterm_display *disp, uint32_t fb, - bool immediate) +int uterm_drm_display_swap(struct uterm_display *disp, uint32_t fb, bool immediate) { struct uterm_drm_display *ddrm = disp->data; struct uterm_video *video = disp->video; @@ -348,9 +310,8 @@ int uterm_drm_display_swap(struct uterm_display *disp, uint32_t fb, if (ret) return ret; - mode = uterm_drm_mode_get_info(disp->current_mode); - ret = drmModeSetCrtc(vdrm->fd, ddrm->crtc_id, fb, 0, 0, - &ddrm->conn_id, 1, mode); + mode = &ddrm->current_mode->info; + ret = drmModeSetCrtc(vdrm->fd, ddrm->crtc_id, fb, 0, 0, &ddrm->conn_id, 1, mode); if (ret) { log_error("cannot set DRM-CRTC (%d): %m", errno); return -EFAULT; @@ -359,16 +320,15 @@ int uterm_drm_display_swap(struct uterm_display *disp, uint32_t fb, if ((disp->flags & DISPLAY_VSYNC)) return -EBUSY; - ret = drmModePageFlip(vdrm->fd, ddrm->crtc_id, fb, - DRM_MODE_PAGE_FLIP_EVENT, disp); + ret = drmModePageFlip(vdrm->fd, ddrm->crtc_id, fb, DRM_MODE_PAGE_FLIP_EVENT, disp); if (ret) { - if (disp->desired_mode != disp->default_mode) { - disp->desired_mode = disp->default_mode; - log_debug("Unable to page-flip desired mode! Switching to default mode."); + if (ddrm->desired_mode != ddrm->default_mode) { + ddrm->desired_mode = ddrm->default_mode; + log_debug("Unable to page-flip desired mode! Switching to default " + "mode."); return -EAGAIN; } - log_error("cannot page-flip on DRM-CRTC (%d): %m", - errno); + log_error("cannot page-flip on DRM-CRTC (%d): %m", errno); return -EFAULT; } @@ -379,6 +339,11 @@ int uterm_drm_display_swap(struct uterm_display *disp, uint32_t fb, return 0; } +bool uterm_drm_is_swapping(struct uterm_display *disp) +{ + return (disp->flags & DISPLAY_VSYNC) != 0; +} + static void uterm_drm_display_pflip(struct uterm_display *disp) { struct uterm_drm_video *vdrm = disp->video->data; @@ -390,8 +355,8 @@ static void uterm_drm_display_pflip(struct uterm_display *disp) DISPLAY_CB(disp, UTERM_PAGE_FLIP); } -static void display_event(int fd, unsigned int frame, unsigned int sec, - unsigned int usec, void *data) +static void display_event(int fd, unsigned int frame, unsigned int sec, unsigned int usec, + void *data) { struct uterm_display *disp = data; @@ -429,7 +394,8 @@ static void do_pflips(struct ev_eloop *eloop, void *unused, void *data) struct uterm_display *disp; struct shl_dlist *iter; - shl_dlist_for_each(iter, &video->displays) { + shl_dlist_for_each(iter, &video->displays) + { disp = shl_dlist_entry(iter, struct uterm_display, list); if ((disp->flags & DISPLAY_PFLIP)) uterm_drm_display_pflip(disp); @@ -459,7 +425,8 @@ static void io_event(struct ev_fd *fd, int mask, void *data) if (ret) return; - shl_dlist_for_each(iter, &video->displays) { + shl_dlist_for_each(iter, &video->displays) + { disp = shl_dlist_entry(iter, struct uterm_display, list); if ((disp->flags & DISPLAY_PFLIP)) uterm_drm_display_pflip(disp); @@ -477,7 +444,8 @@ static void vt_timeout(struct ev_timer *timer, uint64_t exp, void *data) r = uterm_drm_video_wake_up(video); if (!r) { ev_timer_update(vdrm->vt_timer, NULL); - shl_dlist_for_each(iter, &video->displays) { + shl_dlist_for_each(iter, &video->displays) + { disp = shl_dlist_entry(iter, struct uterm_display, list); VIDEO_CB(video, disp, UTERM_REFRESH); } @@ -497,8 +465,8 @@ void uterm_drm_video_arm_vt_timer(struct uterm_video *video) } int uterm_drm_video_init(struct uterm_video *video, const char *node, - const struct display_ops *display_ops, - uterm_drm_page_flip_t pflip, void *data) + const struct display_ops *display_ops, uterm_drm_page_flip_t pflip, + void *data) { struct uterm_drm_video *vdrm; int ret; @@ -523,8 +491,7 @@ int uterm_drm_video_init(struct uterm_video *video, const char *node, /* TODO: fix the race-condition with DRM-Master-on-open */ drmDropMaster(vdrm->fd); - ret = ev_eloop_new_fd(video->eloop, &vdrm->efd, vdrm->fd, EV_READABLE, - io_event, video); + ret = ev_eloop_new_fd(video->eloop, &vdrm->efd, vdrm->fd, EV_READABLE, io_event, video); if (ret) goto err_close; @@ -532,8 +499,7 @@ int uterm_drm_video_init(struct uterm_video *video, const char *node, if (ret) goto err_fd; - ret = ev_eloop_new_timer(video->eloop, &vdrm->vt_timer, NULL, - vt_timeout, video); + ret = ev_eloop_new_timer(video->eloop, &vdrm->vt_timer, NULL, vt_timeout, video); if (ret) goto err_timer; @@ -563,8 +529,7 @@ void uterm_drm_video_destroy(struct uterm_video *video) free(video->data); } -int uterm_drm_video_find_crtc(struct uterm_video *video, drmModeRes *res, - drmModeEncoder *enc) +int uterm_drm_video_find_crtc(struct uterm_video *video, drmModeRes *res, drmModeEncoder *enc) { int i, crtc; struct uterm_display *iter; @@ -574,10 +539,9 @@ int uterm_drm_video_find_crtc(struct uterm_video *video, drmModeRes *res, for (i = 0; i < res->count_crtcs; ++i) { if (enc->possible_crtcs & (1 << i)) { crtc = res->crtcs[i]; - shl_dlist_for_each(it, &video->displays) { - iter = shl_dlist_entry(it, - struct uterm_display, - list); + shl_dlist_for_each(it, &video->displays) + { + iter = shl_dlist_entry(it, struct uterm_display, list); ddrm = iter->data; if (ddrm->crtc_id == crtc) break; @@ -601,8 +565,7 @@ static drmModeCrtc *get_current_crtc(int fd, uint32_t encoder_id) return NULL; } -static void bind_display(struct uterm_video *video, drmModeRes *res, - drmModeConnector *conn) +static void bind_display(struct uterm_video *video, drmModeRes *res, drmModeConnector *conn) { struct uterm_drm_video *vdrm = video->data; struct uterm_display *disp; @@ -619,50 +582,40 @@ static void bind_display(struct uterm_video *video, drmModeRes *res, current_crtc = get_current_crtc(vdrm->fd, conn->encoder_id); for (i = 0; i < conn->count_modes; ++i) { - ret = mode_new(&mode, &uterm_drm_mode_ops); - if (ret) + mode = mode_new(&conn->modes[i]); + if (!mode) continue; - uterm_drm_mode_set(mode, &conn->modes[i]); + shl_dlist_link_tail(&ddrm->modes, &mode->list); - ret = uterm_mode_bind(mode, disp); - if (ret) { - uterm_mode_unref(mode); - continue; - } - - /* TODO: more sophisticated default-mode selection */ - if (!disp->default_mode) - disp->default_mode = mode; + /* Use the mode marked as preferred, or the first if none is marked */ + if (!ddrm->default_mode || mode->info.type & DRM_MODE_TYPE_PREFERRED) + ddrm->default_mode = mode; /* Save the original KMS mode for later use */ - if (current_crtc && memcmp(&conn->modes[i], ¤t_crtc->mode, sizeof(conn->modes[i])) == 0) - disp->original_mode = mode; - - if (video->desired_width != 0 && - video->desired_height != 0 && - mode->ops->get_width(mode) == video->desired_width && - mode->ops->get_height(mode) == video->desired_height) - disp->desired_mode = mode; - - uterm_mode_unref(mode); + if (current_crtc && + memcmp(&conn->modes[i], ¤t_crtc->mode, sizeof(conn->modes[i])) == 0) + ddrm->original_mode = mode; + + if (video->desired_width != 0 && video->desired_height != 0 && + mode->info.hdisplay == video->desired_width && + mode->info.vdisplay == video->desired_height) + ddrm->desired_mode = mode; } if (current_crtc) drmModeFreeCrtc(current_crtc); - if (!disp->desired_mode) { - disp->desired_mode = disp->default_mode; + if (!ddrm->desired_mode) { + ddrm->desired_mode = ddrm->default_mode; } - log_debug("Default mode %dx%d", - disp->default_mode->ops->get_width(disp->default_mode), - disp->default_mode->ops->get_height(disp->default_mode)); + log_debug("Default mode %dx%d", ddrm->default_mode->info.hdisplay, + ddrm->default_mode->info.vdisplay); - log_debug("Desired mode %dx%d", - disp->desired_mode->ops->get_width(disp->desired_mode), - disp->desired_mode->ops->get_height(disp->desired_mode)); + log_debug("Desired mode %dx%d", ddrm->desired_mode->info.hdisplay, + ddrm->desired_mode->info.vdisplay); - if (shl_dlist_empty(&disp->modes)) { + if (shl_dlist_empty(&ddrm->modes)) { log_warn("no valid mode for display found"); ret = -EFAULT; goto err_unref; @@ -672,8 +625,7 @@ static void bind_display(struct uterm_video *video, drmModeRes *res, disp->flags |= DISPLAY_AVAILABLE; disp->dpms = uterm_drm_get_dpms(vdrm->fd, conn); - log_info("display %p DPMS is %s", disp, - uterm_dpms_to_name(disp->dpms)); + log_info("display %p DPMS is %s", disp, uterm_dpms_to_name(disp->dpms)); ret = uterm_display_bind(disp, video); if (ret) @@ -687,8 +639,7 @@ static void bind_display(struct uterm_video *video, drmModeRes *res, return; } -int uterm_drm_video_hotplug(struct uterm_video *video, - bool read_dpms, bool modeset) +int uterm_drm_video_hotplug(struct uterm_video *video, bool read_dpms, bool modeset) { struct uterm_drm_video *vdrm = video->data; drmModeRes *res; @@ -709,7 +660,8 @@ int uterm_drm_video_hotplug(struct uterm_video *video, return -EACCES; } - shl_dlist_for_each(iter, &video->displays) { + shl_dlist_for_each(iter, &video->displays) + { disp = shl_dlist_entry(iter, struct uterm_display, list); disp->flags &= ~DISPLAY_AVAILABLE; } @@ -723,9 +675,9 @@ int uterm_drm_video_hotplug(struct uterm_video *video, continue; } - shl_dlist_for_each(iter, &video->displays) { - disp = shl_dlist_entry(iter, struct uterm_display, - list); + shl_dlist_for_each(iter, &video->displays) + { + disp = shl_dlist_entry(iter, struct uterm_display, list); ddrm = disp->data; if (ddrm->conn_id != res->connectors[i]) @@ -733,7 +685,8 @@ int uterm_drm_video_hotplug(struct uterm_video *video, disp->flags |= DISPLAY_AVAILABLE; - // Clean up kms hardware cursor from display sessions that don't properly clean themselves up` + // Clean up kms hardware cursor from display sessions that don't properly + // clean themselves up` if (drmModeSetCursor(vdrm->fd, ddrm->crtc_id, 0, 0, 0)) log_warn("cannot hide hardware cursor"); @@ -743,8 +696,7 @@ int uterm_drm_video_hotplug(struct uterm_video *video, if (read_dpms) { dpms = uterm_drm_get_dpms(vdrm->fd, conn); if (dpms != disp->dpms) { - log_debug("DPMS state for display %p changed", - disp); + log_debug("DPMS state for display %p changed", disp); uterm_drm_display_set_dpms(disp, disp->dpms); } } @@ -766,7 +718,8 @@ int uterm_drm_video_hotplug(struct uterm_video *video, drmModeFreeResources(res); - shl_dlist_for_each_safe(iter, tmp, &video->displays) { + shl_dlist_for_each_safe(iter, tmp, &video->displays) + { disp = shl_dlist_entry(iter, struct uterm_display, list); if (!(disp->flags & DISPLAY_AVAILABLE)) uterm_display_unbind(disp); @@ -815,8 +768,7 @@ int uterm_drm_video_poll(struct uterm_video *video) /* Waits for events on DRM fd for \mtimeout milliseconds and returns 0 if the * timeout expired, -ERR on errors and 1 if a page-flip event has been read. * \mtimeout is adjusted to the remaining time. */ -int uterm_drm_video_wait_pflip(struct uterm_video *video, - unsigned int *mtimeout) +int uterm_drm_video_wait_pflip(struct uterm_video *video, unsigned int *mtimeout) { struct uterm_drm_video *vdrm = video->data; struct pollfd pfd; @@ -846,8 +798,8 @@ int uterm_drm_video_wait_pflip(struct uterm_video *video, if (ret) return ret; - ret = ev_eloop_register_idle_cb(video->eloop, do_pflips, - video, EV_ONESHOT | EV_SINGLE); + ret = ev_eloop_register_idle_cb(video->eloop, do_pflips, video, + EV_ONESHOT | EV_SINGLE); if (ret) return ret; diff --git a/src/uterm_drm_shared_internal.h b/src/uterm_drm_shared_internal.h index 56a56ffb..07cb1a43 100644 --- a/src/uterm_drm_shared_internal.h +++ b/src/uterm_drm_shared_internal.h @@ -38,26 +38,11 @@ /* drm mode */ -struct uterm_drm_mode { +struct uterm_mode { + struct shl_dlist list; drmModeModeInfo info; }; -int uterm_drm_mode_init(struct uterm_mode *mode); -void uterm_drm_mode_destroy(struct uterm_mode *mode); -const char *uterm_drm_mode_get_name(const struct uterm_mode *mode); -unsigned int uterm_drm_mode_get_width(const struct uterm_mode *mode); -unsigned int uterm_drm_mode_get_height(const struct uterm_mode *mode); -void uterm_drm_mode_set(struct uterm_mode *mode, drmModeModeInfo *info); - -static inline drmModeModeInfo *uterm_drm_mode_get_info(struct uterm_mode *m) -{ - struct uterm_drm_mode *mode = m->data; - - return &mode->info; -} - -extern const struct mode_ops uterm_drm_mode_ops; - /* drm dpms */ int uterm_drm_set_dpms(int fd, uint32_t conn_id, int state); @@ -69,6 +54,12 @@ struct uterm_drm_display { uint32_t conn_id; int crtc_id; drmModeCrtc *saved_crtc; + + struct shl_dlist modes; + struct uterm_mode *default_mode; + struct uterm_mode *desired_mode; + struct uterm_mode *current_mode; + struct uterm_mode *original_mode; void *data; }; @@ -78,8 +69,8 @@ int uterm_drm_display_activate(struct uterm_display *disp, int fd); void uterm_drm_display_deactivate(struct uterm_display *disp, int fd); int uterm_drm_display_set_dpms(struct uterm_display *disp, int state); int uterm_drm_display_wait_pflip(struct uterm_display *disp); -int uterm_drm_display_swap(struct uterm_display *disp, uint32_t fb, - bool immediate); +int uterm_drm_display_swap(struct uterm_display *disp, uint32_t fb, bool immediate); +bool uterm_drm_is_swapping(struct uterm_display *disp); static inline void *uterm_drm_display_get_data(struct uterm_display *disp) { @@ -90,7 +81,7 @@ static inline void *uterm_drm_display_get_data(struct uterm_display *disp) /* drm video */ -typedef void (*uterm_drm_page_flip_t) (struct uterm_display *disp); +typedef void (*uterm_drm_page_flip_t)(struct uterm_display *disp); struct uterm_drm_video { int fd; @@ -103,18 +94,15 @@ struct uterm_drm_video { }; int uterm_drm_video_init(struct uterm_video *video, const char *node, - const struct display_ops *display_ops, - uterm_drm_page_flip_t pflip, void *data); + const struct display_ops *display_ops, uterm_drm_page_flip_t pflip, + void *data); void uterm_drm_video_destroy(struct uterm_video *video); -int uterm_drm_video_find_crtc(struct uterm_video *video, drmModeRes *res, - drmModeEncoder *enc); -int uterm_drm_video_hotplug(struct uterm_video *video, bool read_dpms, - bool modeset); +int uterm_drm_video_find_crtc(struct uterm_video *video, drmModeRes *res, drmModeEncoder *enc); +int uterm_drm_video_hotplug(struct uterm_video *video, bool read_dpms, bool modeset); int uterm_drm_video_wake_up(struct uterm_video *video); void uterm_drm_video_sleep(struct uterm_video *video); int uterm_drm_video_poll(struct uterm_video *video); -int uterm_drm_video_wait_pflip(struct uterm_video *video, - unsigned int *mtimeout); +int uterm_drm_video_wait_pflip(struct uterm_video *video, unsigned int *mtimeout); void uterm_drm_video_arm_vt_timer(struct uterm_video *video); static inline void *uterm_drm_video_get_data(struct uterm_video *video) diff --git a/src/uterm_fbdev_internal.h b/src/uterm_fbdev_internal.h index 6b79e546..1770cf8d 100644 --- a/src/uterm_fbdev_internal.h +++ b/src/uterm_fbdev_internal.h @@ -67,6 +67,10 @@ struct fbdev_display { int_fast32_t dither_r; int_fast32_t dither_g; int_fast32_t dither_b; + + bool vblank_scheduled; + struct itimerspec vblank_spec; + struct ev_timer *vblank_timer; }; struct fbdev_video { @@ -75,11 +79,9 @@ struct fbdev_video { }; int uterm_fbdev_display_fake_blendv(struct uterm_display *disp, - const struct uterm_video_blend_req *req, - size_t num); -int uterm_fbdev_display_fill(struct uterm_display *disp, - uint8_t r, uint8_t g, uint8_t b, - unsigned int x, unsigned int y, - unsigned int width, unsigned int height); + const struct uterm_video_blend_req *req, size_t num); +int uterm_fbdev_display_fill(struct uterm_display *disp, uint8_t r, uint8_t g, uint8_t b, + unsigned int x, unsigned int y, unsigned int width, + unsigned int height); #endif /* UTERM_FBDEV_INTERNAL_H */ diff --git a/src/uterm_fbdev_render.c b/src/uterm_fbdev_render.c index 8bb02136..f98f9411 100644 --- a/src/uterm_fbdev_render.c +++ b/src/uterm_fbdev_render.c @@ -48,8 +48,7 @@ static int clamp_value(int val, int low, int up) return val; } -static uint_fast32_t xrgb32_to_device(struct uterm_display *disp, - uint32_t pixel) +static uint_fast32_t xrgb32_to_device(struct uterm_display *disp, uint32_t pixel) { uint8_t r, g, b, nr, ng, nb; int i; @@ -57,8 +56,8 @@ static uint_fast32_t xrgb32_to_device(struct uterm_display *disp, struct fbdev_display *fbdev = disp->data; r = (pixel >> 16) & 0xff; - g = (pixel >> 8) & 0xff; - b = (pixel >> 0) & 0xff; + g = (pixel >> 8) & 0xff; + b = (pixel >> 0) & 0xff; if (disp->flags & DISPLAY_DITHERING) { /* This is some very basic dithering which simply does small @@ -88,11 +87,11 @@ static uint_fast32_t xrgb32_to_device(struct uterm_display *disp, fbdev->dither_g = ng - fbdev->dither_g; fbdev->dither_b = nb - fbdev->dither_b; - res = r << fbdev->off_r; + res = r << fbdev->off_r; res |= g << fbdev->off_g; res |= b << fbdev->off_b; } else { - res = (r >> (8 - fbdev->len_r)) << fbdev->off_r; + res = (r >> (8 - fbdev->len_r)) << fbdev->off_r; res |= (g >> (8 - fbdev->len_g)) << fbdev->off_g; res |= (b >> (8 - fbdev->len_b)) << fbdev->off_b; } @@ -102,22 +101,21 @@ static uint_fast32_t xrgb32_to_device(struct uterm_display *disp, static void write_24bit(uint8_t *dst, uint_fast32_t value) { - #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - dst[0] = value; - dst[1] = value >> 8; - dst[2] = value >> 16; - #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - dst[0] = value >> 16; - dst[1] = value >> 8; - dst[2] = value; - #else - #error "Unknown endianness" - #endif +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + dst[0] = value; + dst[1] = value >> 8; + dst[2] = value >> 16; +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + dst[0] = value >> 16; + dst[1] = value >> 8; + dst[2] = value; +#else +#error "Unknown endianness" +#endif } int uterm_fbdev_display_fake_blendv(struct uterm_display *disp, - const struct uterm_video_blend_req *req, - size_t num) + const struct uterm_video_blend_req *req, size_t num) { unsigned int tmp; uint8_t *dst, *src; @@ -175,18 +173,15 @@ int uterm_fbdev_display_fake_blendv(struct uterm_display *disp, g = req->fg; b = req->fb; } else { - r = req->fr * src[i] + - req->br * (255 - src[i]); + r = req->fr * src[i] + req->br * (255 - src[i]); r /= 256; - g = req->fg * src[i] + - req->bg * (255 - src[i]); + g = req->fg * src[i] + req->bg * (255 - src[i]); g /= 256; - b = req->fb * src[i] + - req->bb * (255 - src[i]); + b = req->fb * src[i] + req->bb * (255 - src[i]); b /= 256; } val = (r << 16) | (g << 8) | b; - ((uint32_t*)dst)[i] = val; + ((uint32_t *)dst)[i] = val; } dst += fbdev->stride; src += req->buf->stride; @@ -203,19 +198,15 @@ int uterm_fbdev_display_fake_blendv(struct uterm_display *disp, g = req->fg; b = req->fb; } else { - r = req->fr * src[i] + - req->br * (255 - src[i]); + r = req->fr * src[i] + req->br * (255 - src[i]); r /= 256; - g = req->fg * src[i] + - req->bg * (255 - src[i]); + g = req->fg * src[i] + req->bg * (255 - src[i]); g /= 256; - b = req->fb * src[i] + - req->bb * (255 - src[i]); + b = req->fb * src[i] + req->bb * (255 - src[i]); b /= 256; } val = (r << 16) | (g << 8) | b; - ((uint16_t*)dst)[i] = - xrgb32_to_device(disp, val); + ((uint16_t *)dst)[i] = xrgb32_to_device(disp, val); } dst += fbdev->stride; src += req->buf->stride; @@ -232,14 +223,11 @@ int uterm_fbdev_display_fake_blendv(struct uterm_display *disp, g = req->fg; b = req->fb; } else { - r = req->fr * src[i] + - req->br * (255 - src[i]); + r = req->fr * src[i] + req->br * (255 - src[i]); r /= 256; - g = req->fg * src[i] + - req->bg * (255 - src[i]); + g = req->fg * src[i] + req->bg * (255 - src[i]); g /= 256; - b = req->fb * src[i] + - req->bb * (255 - src[i]); + b = req->fb * src[i] + req->bb * (255 - src[i]); b /= 256; } val = (r << 16) | (g << 8) | b; @@ -261,19 +249,15 @@ int uterm_fbdev_display_fake_blendv(struct uterm_display *disp, g = req->fg; b = req->fb; } else { - r = req->fr * src[i] + - req->br * (255 - src[i]); + r = req->fr * src[i] + req->br * (255 - src[i]); r /= 256; - g = req->fg * src[i] + - req->bg * (255 - src[i]); + g = req->fg * src[i] + req->bg * (255 - src[i]); g /= 256; - b = req->fb * src[i] + - req->bb * (255 - src[i]); + b = req->fb * src[i] + req->bb * (255 - src[i]); b /= 256; } val = (r << 16) | (g << 8) | b; - ((uint32_t*)dst)[i] = - xrgb32_to_device(disp, val); + ((uint32_t *)dst)[i] = xrgb32_to_device(disp, val); } dst += fbdev->stride; src += req->buf->stride; @@ -286,10 +270,9 @@ int uterm_fbdev_display_fake_blendv(struct uterm_display *disp, return 0; } -int uterm_fbdev_display_fill(struct uterm_display *disp, - uint8_t r, uint8_t g, uint8_t b, - unsigned int x, unsigned int y, - unsigned int width, unsigned int height) +int uterm_fbdev_display_fill(struct uterm_display *disp, uint8_t r, uint8_t g, uint8_t b, + unsigned int x, unsigned int y, unsigned int width, + unsigned int height) { unsigned int tmp, i; uint8_t *dst; @@ -313,25 +296,25 @@ int uterm_fbdev_display_fill(struct uterm_display *disp, dst = &fbdev->map[fbdev->yres * fbdev->stride]; dst = &dst[y * fbdev->stride + x * fbdev->Bpp]; - full_val = ((r & 0xff) >> (8 - fbdev->len_r)) << fbdev->off_r; + full_val = ((r & 0xff) >> (8 - fbdev->len_r)) << fbdev->off_r; full_val |= ((g & 0xff) >> (8 - fbdev->len_g)) << fbdev->off_g; full_val |= ((b & 0xff) >> (8 - fbdev->len_b)) << fbdev->off_b; if (fbdev->Bpp == 2) { if (disp->flags & DISPLAY_DITHERING) { - rgb32 = (r & 0xff) << 16; - rgb32 |= (g & 0xff) << 8; - rgb32 |= (b & 0xff) << 0; + rgb32 = (r & 0xff) << 16; + rgb32 |= (g & 0xff) << 8; + rgb32 |= (b & 0xff) << 0; while (height--) { for (i = 0; i < width; ++i) - ((uint16_t*)dst)[i] = xrgb32_to_device(disp, rgb32); + ((uint16_t *)dst)[i] = xrgb32_to_device(disp, rgb32); dst += fbdev->stride; } } else { full_val &= 0xffff; while (height--) { for (i = 0; i < width; ++i) - ((uint16_t*)dst)[i] = full_val; + ((uint16_t *)dst)[i] = full_val; dst += fbdev->stride; } } @@ -345,7 +328,7 @@ int uterm_fbdev_display_fill(struct uterm_display *disp, } else if (fbdev->Bpp == 4) { while (height--) { for (i = 0; i < width; ++i) - ((uint32_t*)dst)[i] = full_val; + ((uint32_t *)dst)[i] = full_val; dst += fbdev->stride; } } else { diff --git a/src/uterm_fbdev_video.c b/src/uterm_fbdev_video.c index de2c6b63..11f61053 100644 --- a/src/uterm_fbdev_video.c +++ b/src/uterm_fbdev_video.c @@ -44,54 +44,44 @@ #define LOG_SUBSYSTEM "video_fbdev" -static int mode_init(struct uterm_mode *mode) +static int display_schedule_vblank_timer(struct fbdev_display *fbdev) { - struct fbdev_mode *fbdev; - - fbdev = malloc(sizeof(*fbdev)); - if (!fbdev) - return -ENOMEM; - memset(fbdev, 0, sizeof(*fbdev)); - mode->data = fbdev; + int ret; - return 0; -} + if (fbdev->vblank_scheduled) + return 0; -static void mode_destroy(struct uterm_mode *mode) -{ - free(mode->data); -} + ret = ev_timer_update(fbdev->vblank_timer, &fbdev->vblank_spec); + if (ret) + return ret; -static const char *mode_get_name(const struct uterm_mode *mode) -{ - return ""; + fbdev->vblank_scheduled = true; + return 0; } -static unsigned int mode_get_width(const struct uterm_mode *mode) +static void display_set_vblank_timer(struct fbdev_display *fbdev, unsigned int msecs) { - struct fbdev_mode *fbdev = mode->data; + if (msecs >= 1000) + msecs = 999; + else if (msecs == 0) + msecs = 15; - return fbdev->width; + fbdev->vblank_spec.it_value.tv_nsec = msecs * 1000 * 1000; } -static unsigned int mode_get_height(const struct uterm_mode *mode) +static void display_vblank_timer_event(struct ev_timer *timer, uint64_t expirations, void *data) { - struct fbdev_mode *fbdev = mode->data; + struct uterm_display *disp = data; + struct fbdev_display *fbdev = disp->data; - return fbdev->height; + fbdev->vblank_scheduled = false; + DISPLAY_CB(disp, UTERM_PAGE_FLIP); } -static const struct mode_ops fbdev_mode_ops = { - .init = mode_init, - .destroy = mode_destroy, - .get_name = mode_get_name, - .get_width = mode_get_width, - .get_height = mode_get_height, -}; - static int display_init(struct uterm_display *disp) { struct fbdev_display *fbdev; + int ret; fbdev = malloc(sizeof(*fbdev)); if (!fbdev) @@ -100,11 +90,24 @@ static int display_init(struct uterm_display *disp) disp->data = fbdev; disp->dpms = UTERM_DPMS_UNKNOWN; + fbdev->vblank_spec.it_value.tv_nsec = 15 * 1000 * 1000; + ret = ev_timer_new(&fbdev->vblank_timer, NULL, display_vblank_timer_event, disp, NULL, + NULL); + if (ret) + goto err_free; + return 0; + +err_free: + free(fbdev); + return ret; } static void display_destroy(struct uterm_display *disp) { + struct fbdev_display *fbdev = disp->data; + ev_eloop_rm_timer(fbdev->vblank_timer); + ev_timer_unref(fbdev->vblank_timer); free(disp->data); } @@ -128,14 +131,10 @@ static int refresh_info(struct uterm_display *disp) return 0; } -static int display_activate_force(struct uterm_display *disp, - struct uterm_mode *mode, - bool force) +static int display_activate_force(struct uterm_display *disp, bool force) { - static const char depths[] = { 32, 24, 16, 0 }; + static const char depths[] = {32, 24, 16, 0}; struct fbdev_display *dfb = disp->data; - struct uterm_mode *m; - struct fbdev_mode *mfb; struct fb_var_screeninfo *vinfo; struct fb_fix_screeninfo *finfo; int ret, i; @@ -146,13 +145,6 @@ static int display_activate_force(struct uterm_display *disp, if (!force && (disp->flags & DISPLAY_ONLINE)) return 0; - /* TODO: We do not support explicit modesetting in fbdev, so we require - * @mode to be NULL. You can still switch modes via "fbset" on the - * console and then restart the app. It will automatically adapt to the - * new mode. The only values changed here are bpp and color mode. */ - if (mode) - return -EINVAL; - dfb->fd = open(dfb->node, O_RDWR | O_CLOEXEC | O_NONBLOCK); if (dfb->fd < 0) { log_err("cannot open %s (%d): %m", dfb->node, errno); @@ -212,21 +204,19 @@ static int display_activate_force(struct uterm_display *disp, * modes like pseudocolor or direct-color do not provide this. As I have * never seen a device that does not support TRUECOLOR, I think we can * ignore them here. */ - if (finfo->visual != FB_VISUAL_TRUECOLOR || - vinfo->bits_per_pixel != 32) { + if (finfo->visual != FB_VISUAL_TRUECOLOR || vinfo->bits_per_pixel != 32) { for (i = 0; depths[i]; ++i) { /* Try to set a new mode and if it's successful... */ struct fb_var_screeninfo vinfo_new = *vinfo; vinfo_new.bits_per_pixel = depths[i]; vinfo_new.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE; - ret = ioctl(dfb->fd, FBIOPUT_VSCREENINFO, - &vinfo_new); + ret = ioctl(dfb->fd, FBIOPUT_VSCREENINFO, &vinfo_new); if (ret < 0) continue; /* ... keep it. */ - *vinfo = vinfo_new; + *vinfo = vinfo_new; ret = refresh_info(disp); if (ret) @@ -237,42 +227,35 @@ static int display_activate_force(struct uterm_display *disp, } } - if (vinfo->bits_per_pixel != 32 && - vinfo->bits_per_pixel != 24 && + if (vinfo->bits_per_pixel != 32 && vinfo->bits_per_pixel != 24 && vinfo->bits_per_pixel != 16) { - log_error("device %s does not support 16/32 bpp but: %u", - dfb->node, vinfo->bits_per_pixel); + log_error("device %s does not support 16/32 bpp but: %u", dfb->node, + vinfo->bits_per_pixel); ret = -EFAULT; goto err_close; } if (vinfo->xres_virtual < vinfo->xres || - (disp->flags & DISPLAY_DBUF && - vinfo->yres_virtual < vinfo->yres * 2) || + (disp->flags & DISPLAY_DBUF && vinfo->yres_virtual < vinfo->yres * 2) || vinfo->yres_virtual < vinfo->yres) { - log_warning("device %s has weird virtual buffer sizes (%d %d %d %d)", - dfb->node, vinfo->xres, vinfo->xres_virtual, - vinfo->yres, vinfo->yres_virtual); + log_warning("device %s has weird virtual buffer sizes (%d %d %d %d)", dfb->node, + vinfo->xres, vinfo->xres_virtual, vinfo->yres, vinfo->yres_virtual); } if (finfo->visual != FB_VISUAL_TRUECOLOR) { - log_error("device %s does not support true-color", - dfb->node); + log_error("device %s does not support true-color", dfb->node); ret = -EFAULT; goto err_close; } - if (vinfo->red.length > 8 || - vinfo->green.length > 8 || - vinfo->blue.length > 8) { - log_error("device %s uses unusual color-ranges", - dfb->node); + if (vinfo->red.length > 8 || vinfo->green.length > 8 || vinfo->blue.length > 8) { + log_error("device %s uses unusual color-ranges", dfb->node); ret = -EFAULT; goto err_close; } - log_info("activating display %s to %ux%u %u bpp", dfb->node, - vinfo->xres, vinfo->yres, vinfo->bits_per_pixel); + log_info("activating display %s to %ux%u %u bpp", dfb->node, vinfo->xres, vinfo->yres, + vinfo->bits_per_pixel); /* calculate monitor rate, default is 60 Hz */ quot = (vinfo->upper_margin + vinfo->lower_margin + vinfo->yres); @@ -295,9 +278,8 @@ static int display_activate_force(struct uterm_display *disp, } val = 1000000 / dfb->rate; - display_set_vblank_timer(disp, val); - log_debug("vblank timer: %u ms, monitor refresh rate: %u Hz", val, - dfb->rate / 1000); + display_set_vblank_timer(dfb, val); + log_debug("vblank timer: %u ms, monitor refresh rate: %u Hz", val, dfb->rate / 1000); len = finfo->line_length * vinfo->yres; if (disp->flags & DISPLAY_DBUF) @@ -305,8 +287,7 @@ static int display_activate_force(struct uterm_display *disp, dfb->map = mmap(0, len, PROT_READ | PROT_WRITE, MAP_SHARED, dfb->fd, 0); if (dfb->map == MAP_FAILED) { - log_error("cannot mmap device %s (%d): %m", dfb->node, - errno); + log_error("cannot mmap device %s (%d): %m", dfb->node, errno); ret = -EFAULT; goto err_close; } @@ -329,54 +310,32 @@ static int display_activate_force(struct uterm_display *disp, dfb->dither_b = 0; dfb->xrgb32 = false; dfb->rgb16 = false; - if (dfb->len_r == 8 && dfb->len_g == 8 && dfb->len_b == 8 && - dfb->off_r == 16 && dfb->off_g == 8 && dfb->off_b == 0 && - dfb->Bpp == 4) + if (dfb->len_r == 8 && dfb->len_g == 8 && dfb->len_b == 8 && dfb->off_r == 16 && + dfb->off_g == 8 && dfb->off_b == 0 && dfb->Bpp == 4) dfb->xrgb32 = true; - else if (dfb->len_r == 5 && dfb->len_g == 6 && dfb->len_b == 5 && - dfb->off_r == 11 && dfb->off_g == 5 && dfb->off_b == 0 && - dfb->Bpp == 2) + else if (dfb->len_r == 5 && dfb->len_g == 6 && dfb->len_b == 5 && dfb->off_r == 11 && + dfb->off_g == 5 && dfb->off_b == 0 && dfb->Bpp == 2) dfb->rgb16 = true; - else if (dfb->len_r == 8 && dfb->len_g == 8 && dfb->len_b == 8 && - dfb->off_r == 16 && dfb->off_g == 8 && dfb->off_b == 0 && - dfb->Bpp == 3) + else if (dfb->len_r == 8 && dfb->len_g == 8 && dfb->len_b == 8 && dfb->off_r == 16 && + dfb->off_g == 8 && dfb->off_b == 0 && dfb->Bpp == 3) dfb->rgb24 = true; /* TODO: make dithering configurable */ disp->flags |= DISPLAY_DITHERING; - - if (disp->current_mode) { - m = disp->current_mode; - } else { - ret = mode_new(&m, &fbdev_mode_ops); - if (ret) - goto err_map; - ret = uterm_mode_bind(m, disp); - if (ret) { - uterm_mode_unref(m); - goto err_map; - } - disp->current_mode = m; - uterm_mode_unref(m); - } - - mfb = m->data; - mfb->width = dfb->xres; - mfb->height = dfb->yres; + disp->width = dfb->xres; + disp->height = dfb->yres; disp->flags |= DISPLAY_ONLINE; return 0; -err_map: - munmap(dfb->map, dfb->len); err_close: close(dfb->fd); return ret; } -static int display_activate(struct uterm_display *disp, struct uterm_mode *mode) +static int display_activate(struct uterm_display *disp) { - return display_activate_force(disp, mode, false); + return display_activate_force(disp, false); } static void display_deactivate_force(struct uterm_display *disp, bool force) @@ -392,8 +351,8 @@ static void display_deactivate_force(struct uterm_display *disp, bool force) dfb->map = NULL; } if (!force) { - uterm_mode_unbind(disp->current_mode); - disp->current_mode = NULL; + disp->width = 0; + disp->height = 0; disp->flags &= ~DISPLAY_ONLINE; } } @@ -425,13 +384,11 @@ static int display_set_dpms(struct uterm_display *disp, int state) return -EINVAL; } - log_info("setting DPMS of device %p to %s", dfb->node, - uterm_dpms_to_name(state)); + log_info("setting DPMS of device %p to %s", dfb->node, uterm_dpms_to_name(state)); ret = ioctl(dfb->fd, FBIOBLANK, set); if (ret) { - log_error("cannot set DPMS on %s (%d): %m", dfb->node, - errno); + log_error("cannot set DPMS on %s (%d): %m", dfb->node, errno); return -EFAULT; } @@ -452,37 +409,6 @@ static int display_use(struct uterm_display *disp, bool *opengl) return dfb->bufid ^ 1; } -static int display_get_buffers(struct uterm_display *disp, - struct uterm_video_buffer *buffer, - unsigned int formats) -{ - struct fbdev_display *dfb = disp->data; - unsigned int f = 0, i; - - if (dfb->xrgb32) - f = UTERM_FORMAT_XRGB32; - else if (dfb->rgb16) - f = UTERM_FORMAT_RGB16; - else if (dfb->rgb24) - f = UTERM_FORMAT_RGB24; - - if (!(formats & f)) - return -EOPNOTSUPP; - - for (i = 0; i < 2; ++i) { - buffer[i].width = dfb->xres; - buffer[i].height = dfb->yres; - buffer[i].stride = dfb->stride; - buffer[i].format = f; - if (!(disp->flags & DISPLAY_DBUF) || !i) - buffer[i].data = dfb->map; - else - buffer[i].data = &dfb->map[dfb->yres * dfb->stride]; - } - - return 0; -} - static int display_swap(struct uterm_display *disp, bool immediate) { struct fbdev_display *dfb = disp->data; @@ -492,7 +418,7 @@ static int display_swap(struct uterm_display *disp, bool immediate) if (!(disp->flags & DISPLAY_DBUF)) { if (immediate) return 0; - return display_schedule_vblank_timer(disp); + return display_schedule_vblank_timer(dfb); } vinfo = &dfb->vinfo; @@ -508,13 +434,19 @@ static int display_swap(struct uterm_display *disp, bool immediate) ret = ioctl(dfb->fd, FBIOPUT_VSCREENINFO, vinfo); if (ret) { - log_warning("cannot swap buffers on %s (%d): %m", - dfb->node, errno); + log_warning("cannot swap buffers on %s (%d): %m", dfb->node, errno); return -EFAULT; } dfb->bufid ^= 1; - return display_schedule_vblank_timer(disp); + return display_schedule_vblank_timer(dfb); +} + +static bool display_is_swapping(struct uterm_display *disp) +{ + struct fbdev_display *fbdev = disp->data; + + return fbdev->vblank_scheduled; } static const struct display_ops fbdev_display_ops = { @@ -524,8 +456,8 @@ static const struct display_ops fbdev_display_ops = { .deactivate = display_deactivate, .set_dpms = display_set_dpms, .use = display_use, - .get_buffers = display_get_buffers, .swap = display_swap, + .is_swapping = display_is_swapping, .fake_blendv = uterm_fbdev_display_fake_blendv, .fill = uterm_fbdev_display_fill, }; @@ -549,10 +481,18 @@ static void intro_idle_event(struct ev_eloop *eloop, void *unused, void *data) dfb = disp->data; dfb->node = vfb->node; + + ret = ev_eloop_add_timer(video->eloop, dfb->vblank_timer); + if (ret) { + log_error("cannot add fbdev timer: %d", ret); + return; + } + ret = uterm_display_bind(disp, video); if (ret) { log_error("cannot bind fbdev display: %d", ret); uterm_display_unref(disp); + ev_eloop_rm_timer(dfb->vblank_timer); return; } @@ -578,8 +518,7 @@ static int video_init(struct uterm_video *video, const char *node) goto err_free; } - ret = ev_eloop_register_idle_cb(video->eloop, intro_idle_event, video, - EV_NORMAL); + ret = ev_eloop_register_idle_cb(video->eloop, intro_idle_event, video, EV_NORMAL); if (ret) { log_error("cannot register idle event: %d", ret); goto err_node; @@ -602,8 +541,7 @@ static void video_destroy(struct uterm_video *video) log_info("free device on %s", vfb->node); if (vfb->pending_intro) - ev_eloop_unregister_idle_cb(video->eloop, intro_idle_event, - video, EV_NORMAL); + ev_eloop_unregister_idle_cb(video->eloop, intro_idle_event, video, EV_NORMAL); free(vfb->node); free(vfb); @@ -614,7 +552,8 @@ static void video_sleep(struct uterm_video *video) struct uterm_display *iter; struct shl_dlist *i; - shl_dlist_for_each(i, &video->displays) { + shl_dlist_for_each(i, &video->displays) + { iter = shl_dlist_entry(i, struct uterm_display, list); if (!display_is_online(iter)) @@ -631,13 +570,14 @@ static int video_wake_up(struct uterm_video *video) int ret; video->flags |= VIDEO_AWAKE; - shl_dlist_for_each(i, &video->displays) { + shl_dlist_for_each(i, &video->displays) + { iter = shl_dlist_entry(i, struct uterm_display, list); if (!display_is_online(iter)) continue; - ret = display_activate_force(iter, NULL, true); + ret = display_activate_force(iter, true); if (ret) return ret; @@ -648,15 +588,12 @@ static int video_wake_up(struct uterm_video *video) return 0; } -struct uterm_video_module fbdev_module = { - .name = "fbdev", - .owner = NULL, - .ops = { - .init = video_init, - .destroy = video_destroy, - .segfault = NULL, /* TODO */ - .poll = NULL, - .sleep = video_sleep, - .wake_up = video_wake_up, - } -}; +struct uterm_video_module fbdev_module = {.name = "fbdev", + .owner = NULL, + .ops = { + .init = video_init, + .destroy = video_destroy, + .poll = NULL, + .sleep = video_sleep, + .wake_up = video_wake_up, + }}; diff --git a/src/uterm_input.c b/src/uterm_input.c index cec0798e..a9740a07 100644 --- a/src/uterm_input.c +++ b/src/uterm_input.c @@ -51,10 +51,7 @@ static void input_free_dev(struct uterm_input_dev *dev); -static void notify_event(struct uterm_input_dev *dev, - uint16_t type, - uint16_t code, - int32_t value) +static void notify_event(struct uterm_input_dev *dev, uint16_t type, uint16_t code, int32_t value) { switch (type) { case EV_KEY: @@ -93,20 +90,17 @@ static void input_data_dev(struct ev_fd *fd, int mask, void *data) if (len < 0) { if (errno == EWOULDBLOCK) break; - llog_warn(dev->input, "reading from %s failed (%d): %m", - dev->node, errno); + llog_warn(dev->input, "reading from %s failed (%d): %m", dev->node, errno); input_free_dev(dev); } else if (len == 0) { llog_debug(dev->input, "EOF on %s", dev->node); input_free_dev(dev); } else if (len % sizeof(*ev)) { - llog_warn(dev->input, "invalid input_event on %s", - dev->node); + llog_warn(dev->input, "invalid input_event on %s", dev->node); } else { n = len / sizeof(*ev); for (i = 0; i < n; i++) - notify_event(dev, ev[i].type, ev[i].code, - ev[i].value); + notify_event(dev, ev[i].type, ev[i].code, ev[i].value); } } } @@ -120,15 +114,14 @@ static int input_wake_up_dev(struct uterm_input_dev *dev) dev->rfd = open(dev->node, O_CLOEXEC | O_NONBLOCK | O_RDWR); if (dev->rfd < 0) { - llog_warn(dev->input, "cannot open device %s (%d): %m", - dev->node, errno); + llog_warn(dev->input, "cannot open device %s (%d): %m", dev->node, errno); return -EFAULT; } if (dev->capabilities & UTERM_DEVICE_HAS_KEYS) uxkb_dev_wake_up(dev); - ret = ev_eloop_new_fd(dev->input->eloop, &dev->fd, dev->rfd, - EV_READABLE, input_data_dev, dev); + ret = ev_eloop_new_fd(dev->input->eloop, &dev->fd, dev->rfd, EV_READABLE, input_data_dev, + dev); if (ret) { close(dev->rfd); dev->rfd = -1; @@ -218,9 +211,8 @@ static int input_init_abs(struct uterm_input_dev *dev) dev->pointer.min_y = info.minimum; dev->pointer.max_y = info.maximum; - llog_debug(dev->input, "ABSX min %d max %d ABSY min %d max %d\n", - dev->pointer.min_x, dev->pointer.max_x, - dev->pointer.min_y, dev->pointer.max_y); + llog_debug(dev->input, "ABSX min %d max %d ABSY min %d max %d\n", dev->pointer.min_x, + dev->pointer.max_x, dev->pointer.min_y, dev->pointer.max_y); return 0; err_closefd: @@ -228,9 +220,7 @@ static int input_init_abs(struct uterm_input_dev *dev) return ret; } -static void input_new_dev(struct uterm_input *input, - const char *node, - unsigned int capabilities) +static void input_new_dev(struct uterm_input *input, const char *node, unsigned int capabilities) { struct uterm_input_dev *dev; int ret; @@ -260,7 +250,7 @@ static void input_new_dev(struct uterm_input *input, if (dev->capabilities & UTERM_DEVICE_HAS_TOUCH) dev->pointer.kind = POINTER_TOUCHPAD; else - dev->pointer.kind = POINTER_VMOUSE; + dev->pointer.kind = POINTER_VMOUSE; } if (dev->capabilities & UTERM_DEVICE_HAS_REL) dev->pointer.kind = POINTER_MOUSE; @@ -306,20 +296,11 @@ static void hide_pointer_timer(struct ev_timer *timer, uint64_t num, void *data) } SHL_EXPORT -int uterm_input_new(struct uterm_input **out, - struct ev_eloop *eloop, - const char *model, - const char *layout, - const char *variant, - const char *options, - const char *locale, - const char *keymap, - const char *compose_file, - size_t compose_file_len, - unsigned int repeat_delay, - unsigned int repeat_rate, - uterm_input_log_t log, - void *log_data) +int uterm_input_new(struct uterm_input **out, struct ev_eloop *eloop, const char *model, + const char *layout, const char *variant, const char *options, + const char *locale, const char *keymap, const char *compose_file, + size_t compose_file_len, unsigned int repeat_delay, unsigned int repeat_rate, + uterm_input_log_t log, void *log_data) { struct uterm_input *input; int ret; @@ -356,8 +337,8 @@ int uterm_input_new(struct uterm_input **out, if (ret) goto err_hook; - ret = ev_eloop_new_timer(input->eloop, &input->hide_pointer, NULL, - hide_pointer_timer, input); + ret = ev_eloop_new_timer(input->eloop, &input->hide_pointer, NULL, hide_pointer_timer, + input); if (ret) goto err_hook_pointer; @@ -365,16 +346,16 @@ int uterm_input_new(struct uterm_input **out, * variable if options is an empty string. * So if all variables are empty, use NULL instead. */ - if (model && *model == 0 && layout && *layout == 0 && - variant && *variant == 0 && options && *options == 0) { + if (model && *model == 0 && layout && *layout == 0 && variant && *variant == 0 && options && + *options == 0) { model = NULL; layout = NULL; variant = NULL; options = NULL; } - ret = uxkb_desc_init(input, model, layout, variant, options, locale, - keymap, compose_file, compose_file_len); + ret = uxkb_desc_init(input, model, layout, variant, options, locale, keymap, compose_file, + compose_file_len); if (ret) goto err_hide_timer; @@ -417,9 +398,7 @@ void uterm_input_unref(struct uterm_input *input) llog_debug(input, "free object %p", input); while (input->devices.next != &input->devices) { - dev = shl_dlist_entry(input->devices.next, - struct uterm_input_dev, - list); + dev = shl_dlist_entry(input->devices.next, struct uterm_input_dev, list); input_free_dev(dev); } @@ -434,15 +413,14 @@ void uterm_input_unref(struct uterm_input *input) * We go over the possible capabilities and return a mask of enum * uterm_input_device_capability's. */ -static unsigned int probe_device_capabilities(struct uterm_input *input, - const char *node) +static unsigned int probe_device_capabilities(struct uterm_input *input, const char *node) { int i, fd, ret; unsigned int capabilities = 0; - unsigned long evbits[NLONGS(EV_CNT)] = { 0 }; - unsigned long keybits[NLONGS(KEY_CNT)] = { 0 }; - unsigned long relbits[NLONGS(REL_CNT)] = { 0 }; - unsigned long absbits[NLONGS(ABS_CNT)] = { 0 }; + unsigned long evbits[NLONGS(EV_CNT)] = {0}; + unsigned long keybits[NLONGS(KEY_CNT)] = {0}; + unsigned long relbits[NLONGS(REL_CNT)] = {0}; + unsigned long absbits[NLONGS(ABS_CNT)] = {0}; fd = open(node, O_NONBLOCK | O_CLOEXEC | O_RDONLY); if (fd < 0) @@ -476,25 +454,21 @@ static unsigned int probe_device_capabilities(struct uterm_input *input, capabilities |= UTERM_DEVICE_HAS_TOUCH; } - if (input_bit_is_set(evbits, EV_SYN) && - input_bit_is_set(evbits, EV_REL)) { + if (input_bit_is_set(evbits, EV_SYN) && input_bit_is_set(evbits, EV_REL)) { ret = ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relbits)), relbits); if (ret < 0) goto err_ioctl; - if (input_bit_is_set(relbits, REL_X) && - input_bit_is_set(relbits, REL_Y)) + if (input_bit_is_set(relbits, REL_X) && input_bit_is_set(relbits, REL_Y)) capabilities |= UTERM_DEVICE_HAS_REL; if (input_bit_is_set(relbits, REL_WHEEL)) capabilities |= UTERM_DEVICE_HAS_WHEEL; } - if (input_bit_is_set(evbits, EV_SYN) && - input_bit_is_set(evbits, EV_ABS)) { + if (input_bit_is_set(evbits, EV_SYN) && input_bit_is_set(evbits, EV_ABS)) { ret = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits); if (ret < 0) goto err_ioctl; - if (input_bit_is_set(absbits, ABS_X) && - input_bit_is_set(absbits, ABS_Y)) + if (input_bit_is_set(absbits, ABS_X) && input_bit_is_set(absbits, ABS_Y)) capabilities |= UTERM_DEVICE_HAS_ABS; } @@ -505,8 +479,7 @@ static unsigned int probe_device_capabilities(struct uterm_input *input, return capabilities; err_ioctl: - llog_warn(input, "cannot probe capabilities of device %s (%d): %m", - node, errno); + llog_warn(input, "cannot probe capabilities of device %s (%d): %m", node, errno); close(fd); return 0; } @@ -547,10 +520,9 @@ void uterm_input_remove_dev(struct uterm_input *input, const char *node) if (!input || !node) return; - shl_dlist_for_each(iter, &input->devices) { - dev = shl_dlist_entry(iter, - struct uterm_input_dev, - list); + shl_dlist_for_each(iter, &input->devices) + { + dev = shl_dlist_entry(iter, struct uterm_input_dev, list); if (!strcmp(dev->node, node)) { input_free_dev(dev); break; @@ -559,9 +531,7 @@ void uterm_input_remove_dev(struct uterm_input *input, const char *node) } SHL_EXPORT -int uterm_input_register_key_cb(struct uterm_input *input, - uterm_input_key_cb cb, - void *data) +int uterm_input_register_key_cb(struct uterm_input *input, uterm_input_key_cb cb, void *data) { if (!input || !cb) return -EINVAL; @@ -570,9 +540,7 @@ int uterm_input_register_key_cb(struct uterm_input *input, } SHL_EXPORT -void uterm_input_unregister_key_cb(struct uterm_input *input, - uterm_input_key_cb cb, - void *data) +void uterm_input_unregister_key_cb(struct uterm_input *input, uterm_input_key_cb cb, void *data) { if (!input || !cb) return; @@ -581,8 +549,7 @@ void uterm_input_unregister_key_cb(struct uterm_input *input, } SHL_EXPORT -int uterm_input_register_pointer_cb(struct uterm_input *input, - uterm_input_pointer_cb cb, +int uterm_input_register_pointer_cb(struct uterm_input *input, uterm_input_pointer_cb cb, void *data) { if (!input || !cb) @@ -592,8 +559,7 @@ int uterm_input_register_pointer_cb(struct uterm_input *input, } SHL_EXPORT -void uterm_input_unregister_pointer_cb(struct uterm_input *input, - uterm_input_pointer_cb cb, +void uterm_input_unregister_pointer_cb(struct uterm_input *input, uterm_input_pointer_cb cb, void *data) { if (!input || !cb) @@ -617,10 +583,9 @@ void uterm_input_sleep(struct uterm_input *input) llog_debug(input, "going to sleep"); - shl_dlist_for_each(iter, &input->devices) { - dev = shl_dlist_entry(iter, - struct uterm_input_dev, - list); + shl_dlist_for_each(iter, &input->devices) + { + dev = shl_dlist_entry(iter, struct uterm_input_dev, list); input_sleep_dev(dev); } } @@ -641,10 +606,9 @@ void uterm_input_wake_up(struct uterm_input *input) llog_debug(input, "wakeing up"); - shl_dlist_for_each_safe(iter, tmp, &input->devices) { - dev = shl_dlist_entry(iter, - struct uterm_input_dev, - list); + shl_dlist_for_each_safe(iter, tmp, &input->devices) + { + dev = shl_dlist_entry(iter, struct uterm_input_dev, list); ret = input_wake_up_dev(dev); if (ret) input_free_dev(dev); @@ -661,9 +625,7 @@ bool uterm_input_is_awake(struct uterm_input *input) } SHL_EXPORT -void uterm_input_set_pointer_max(struct uterm_input *input, - unsigned int max_x, - unsigned int max_y) +void uterm_input_set_pointer_max(struct uterm_input *input, unsigned int max_x, unsigned int max_y) { if (!input) return; diff --git a/src/uterm_input.h b/src/uterm_input.h index 55a05d9f..6b942170 100644 --- a/src/uterm_input.h +++ b/src/uterm_input.h @@ -40,36 +40,31 @@ struct uterm_input; -typedef void (*uterm_input_log_t) (void *data, - const char *file, - int line, - const char *func, - const char *subs, - unsigned int sev, - const char *format, - va_list args); +typedef void (*uterm_input_log_t)(void *data, const char *file, int line, const char *func, + const char *subs, unsigned int sev, const char *format, + va_list args); /* keep in sync with shl_xkb_mods */ enum uterm_input_modifier { - UTERM_SHIFT_MASK = (1 << 0), - UTERM_LOCK_MASK = (1 << 1), - UTERM_CONTROL_MASK = (1 << 2), - UTERM_ALT_MASK = (1 << 3), - UTERM_LOGO_MASK = (1 << 4), + UTERM_SHIFT_MASK = (1 << 0), + UTERM_LOCK_MASK = (1 << 1), + UTERM_CONTROL_MASK = (1 << 2), + UTERM_ALT_MASK = (1 << 3), + UTERM_LOGO_MASK = (1 << 4), }; /* keep in sync with TSM_VTE_INVALID */ #define UTERM_INPUT_INVALID 0xffffffff struct uterm_input_key_event { - bool handled; /* user-controlled, default is false */ - uint16_t keycode; /* linux keycode - KEY_* - linux/input.h */ - uint32_t ascii; /* ascii keysym for @keycode */ - unsigned int mods; /* active modifiers - uterm_modifier mask */ - - unsigned int num_syms; /* number of keysyms */ - uint32_t *keysyms; /* XKB-common keysym-array - XKB_KEY_* */ - uint32_t *codepoints; /* ucs4 unicode value or UTERM_INPUT_INVALID */ + bool handled; /* user-controlled, default is false */ + uint16_t keycode; /* linux keycode - KEY_* - linux/input.h */ + uint32_t ascii; /* ascii keysym for @keycode */ + unsigned int mods; /* active modifiers - uterm_modifier mask */ + + unsigned int num_syms; /* number of keysyms */ + uint32_t *keysyms; /* XKB-common keysym-array - XKB_KEY_* */ + uint32_t *codepoints; /* ucs4 unicode value or UTERM_INPUT_INVALID */ }; enum uterm_input_pointer_type { @@ -92,19 +87,16 @@ struct uterm_input_pointer_event { #define UTERM_INPUT_HAS_MODS(_ev, _mods) (((_ev)->mods & (_mods)) == (_mods)) -typedef void (*uterm_input_key_cb) (struct uterm_input *input, - struct uterm_input_key_event *ev, - void *data); +typedef void (*uterm_input_key_cb)(struct uterm_input *input, struct uterm_input_key_event *ev, + void *data); -typedef void (*uterm_input_pointer_cb) (struct uterm_input *input, - struct uterm_input_pointer_event *ev, - void *data); +typedef void (*uterm_input_pointer_cb)(struct uterm_input *input, + struct uterm_input_pointer_event *ev, void *data); -int uterm_input_new(struct uterm_input **out, struct ev_eloop *eloop, - const char *model, const char *layout, const char *variant, - const char *options, const char *locale, const char *keymap, - const char *compose_file, size_t compose_file_len, - unsigned int repeat_delay, unsigned int repeat_rate, +int uterm_input_new(struct uterm_input **out, struct ev_eloop *eloop, const char *model, + const char *layout, const char *variant, const char *options, + const char *locale, const char *keymap, const char *compose_file, + size_t compose_file_len, unsigned int repeat_delay, unsigned int repeat_rate, uterm_input_log_t log, void *log_data); void uterm_input_ref(struct uterm_input *input); void uterm_input_unref(struct uterm_input *input); @@ -112,21 +104,17 @@ void uterm_input_unref(struct uterm_input *input); void uterm_input_add_dev(struct uterm_input *input, const char *node, bool mouse); void uterm_input_remove_dev(struct uterm_input *input, const char *node); -int uterm_input_register_key_cb(struct uterm_input *input, uterm_input_key_cb cb, - void *data); -void uterm_input_unregister_key_cb(struct uterm_input *input, uterm_input_key_cb cb, - void *data); +int uterm_input_register_key_cb(struct uterm_input *input, uterm_input_key_cb cb, void *data); +void uterm_input_unregister_key_cb(struct uterm_input *input, uterm_input_key_cb cb, void *data); int uterm_input_register_pointer_cb(struct uterm_input *input, uterm_input_pointer_cb cb, - void *data); + void *data); void uterm_input_unregister_pointer_cb(struct uterm_input *input, uterm_input_pointer_cb cb, - void *data); + void *data); void uterm_input_sleep(struct uterm_input *input); void uterm_input_wake_up(struct uterm_input *input); bool uterm_input_is_awake(struct uterm_input *input); -void uterm_input_set_pointer_max(struct uterm_input *input, - unsigned int max_x, - unsigned int max_y); +void uterm_input_set_pointer_max(struct uterm_input *input, unsigned int max_x, unsigned int max_y); #endif /* UTERM_UTERM_INPUT_H */ diff --git a/src/uterm_input_internal.h b/src/uterm_input_internal.h index 2a99a283..fa8a5c9d 100644 --- a/src/uterm_input_internal.h +++ b/src/uterm_input_internal.h @@ -126,31 +126,20 @@ static inline bool input_bit_is_set(const unsigned long *array, int bit) return !!(array[bit / LONG_BIT] & (1UL << (bit % LONG_BIT))); } -int uxkb_desc_init(struct uterm_input *input, - const char *model, - const char *layout, - const char *variant, - const char *options, - const char *locale, - const char *keymap, - const char *compose_file, - size_t compose_file_len); +int uxkb_desc_init(struct uterm_input *input, const char *model, const char *layout, + const char *variant, const char *options, const char *locale, const char *keymap, + const char *compose_file, size_t compose_file_len); void uxkb_desc_destroy(struct uterm_input *input); int uxkb_dev_init(struct uterm_input_dev *dev); void uxkb_dev_destroy(struct uterm_input_dev *dev); -int uxkb_dev_process(struct uterm_input_dev *dev, - uint16_t key_state, - uint16_t code); +int uxkb_dev_process(struct uterm_input_dev *dev, uint16_t key_state, uint16_t code); void uxkb_dev_sleep(struct uterm_input_dev *dev); void uxkb_dev_wake_up(struct uterm_input_dev *dev); -void pointer_dev_rel(struct uterm_input_dev *dev, - uint16_t code, int32_t value); -void pointer_dev_abs(struct uterm_input_dev *dev, - uint16_t code, int32_t value); -void pointer_dev_button(struct uterm_input_dev *dev, - uint16_t code, int32_t value); +void pointer_dev_rel(struct uterm_input_dev *dev, uint16_t code, int32_t value); +void pointer_dev_abs(struct uterm_input_dev *dev, uint16_t code, int32_t value); +void pointer_dev_button(struct uterm_input_dev *dev, uint16_t code, int32_t value); void pointer_dev_sync(struct uterm_input_dev *dev); #endif /* UTERM_INPUT_INTERNAL_H */ diff --git a/src/uterm_input_pointer.c b/src/uterm_input_pointer.c index 851c381d..cdbe83d1 100644 --- a/src/uterm_input_pointer.c +++ b/src/uterm_input_pointer.c @@ -1,13 +1,12 @@ -#include #include #include +#include #include "eloop.h" #include "shl_hook.h" #include "shl_llog.h" #include "uterm_input.h" #include "uterm_input_internal.h" - static void pointer_update_inactivity_timer(struct uterm_input_dev *dev) { struct itimerspec spec; @@ -40,7 +39,8 @@ static void pointer_dev_send_wheel(struct uterm_input_dev *dev, int32_t value) shl_hook_call(dev->input->pointer_hook, dev->input, &pev); } -static void pointer_dev_send_button(struct uterm_input_dev *dev, uint8_t button, bool pressed, bool dbl_click) +static void pointer_dev_send_button(struct uterm_input_dev *dev, uint8_t button, bool pressed, + bool dbl_click) { struct uterm_input_pointer_event pev = {0}; @@ -63,8 +63,7 @@ void pointer_dev_sync(struct uterm_input_dev *dev) dev->pointer.touchpaddown = false; } -void pointer_dev_rel(struct uterm_input_dev *dev, - uint16_t code, int32_t value) +void pointer_dev_rel(struct uterm_input_dev *dev, uint16_t code, int32_t value) { switch (code) { case REL_X: @@ -91,8 +90,7 @@ void pointer_dev_rel(struct uterm_input_dev *dev, } } -void pointer_dev_abs(struct uterm_input_dev *dev, - uint16_t code, int32_t value) +void pointer_dev_abs(struct uterm_input_dev *dev, uint16_t code, int32_t value) { switch (code) { case ABS_X: @@ -110,7 +108,9 @@ void pointer_dev_abs(struct uterm_input_dev *dev, dev->pointer.off_x = dev->input->pointer_max_x - value; } } else if (dev->pointer.kind == POINTER_VMOUSE) { - dev->pointer.x = ((value - dev->pointer.min_x) * dev->input->pointer_max_x) / (dev->pointer.max_x - dev->pointer.min_x); + dev->pointer.x = + ((value - dev->pointer.min_x) * dev->input->pointer_max_x) / + (dev->pointer.max_x - dev->pointer.min_x); } else { return; } @@ -130,7 +130,9 @@ void pointer_dev_abs(struct uterm_input_dev *dev, dev->pointer.off_y = dev->input->pointer_max_y - value; } } else if (dev->pointer.kind == POINTER_VMOUSE) { - dev->pointer.y = ((value - dev->pointer.min_y) * dev->input->pointer_max_y) / (dev->pointer.max_y - dev->pointer.min_y); + dev->pointer.y = + ((value - dev->pointer.min_y) * dev->input->pointer_max_y) / + (dev->pointer.max_y - dev->pointer.min_y); } else { return; } @@ -141,8 +143,7 @@ void pointer_dev_abs(struct uterm_input_dev *dev, pointer_dev_send_move(dev); } -void pointer_dev_button(struct uterm_input_dev *dev, - uint16_t code, int32_t value) +void pointer_dev_button(struct uterm_input_dev *dev, uint16_t code, int32_t value) { struct timespec tp; uint64_t elapsed; @@ -153,7 +154,8 @@ void pointer_dev_button(struct uterm_input_dev *dev, case BTN_LEFT: if (pressed) { clock_gettime(CLOCK_MONOTONIC, &tp); - elapsed = (tp.tv_sec - dev->pointer.last_click.tv_sec) * 1000 + (tp.tv_nsec - dev->pointer.last_click.tv_nsec) / 1000000; + elapsed = (tp.tv_sec - dev->pointer.last_click.tv_sec) * 1000 + + (tp.tv_nsec - dev->pointer.last_click.tv_nsec) / 1000000; dbl_click = (elapsed < 500); dev->pointer.last_click = tp; } @@ -174,4 +176,3 @@ void pointer_dev_button(struct uterm_input_dev *dev, break; } } - diff --git a/src/uterm_input_uxkb.c b/src/uterm_input_uxkb.c index 926b6725..d0773799 100644 --- a/src/uterm_input_uxkb.c +++ b/src/uterm_input_uxkb.c @@ -31,19 +31,19 @@ #include #include #include -#include #include +#include #include "shl_hook.h" #include "shl_llog.h" #include "shl_misc.h" #include "uterm_input.h" -#include "uterm_input_internal.h" #include "uterm_input_fallback.xkb.bin.h" +#include "uterm_input_internal.h" #define LLOG_SUBSYSTEM "uterm_uxkb" -static void uxkb_log(struct xkb_context *context, enum xkb_log_level level, - const char *format, va_list args) +static void uxkb_log(struct xkb_context *context, enum xkb_log_level level, const char *format, + va_list args) { struct uterm_input *input; unsigned int sev; @@ -72,22 +72,12 @@ static void uxkb_log(struct xkb_context *context, enum xkb_log_level level, break; } - input->llog(input->llog_data, - LLOG_DEFAULT, - sev, - format, - args); + input->llog(input->llog_data, LLOG_DEFAULT, sev, format, args); } -int uxkb_desc_init(struct uterm_input *input, - const char *model, - const char *layout, - const char *variant, - const char *options, - const char *locale, - const char *keymap, - const char *compose_file, - size_t compose_file_len) +int uxkb_desc_init(struct uterm_input *input, const char *model, const char *layout, + const char *variant, const char *options, const char *locale, const char *keymap, + const char *compose_file, size_t compose_file_len) { int ret; struct xkb_rule_names rmlvo = { @@ -115,11 +105,10 @@ int uxkb_desc_init(struct uterm_input *input, /* If a complete keymap file was given, first try that. */ if (keymap && *keymap) { - input->keymap = xkb_keymap_new_from_string(input->ctx, - keymap, XKB_KEYMAP_FORMAT_TEXT_V1, 0); + input->keymap = xkb_keymap_new_from_string(input->ctx, keymap, + XKB_KEYMAP_FORMAT_TEXT_V1, 0); if (input->keymap) { - llog_debug(input, - "new keyboard description from memory"); + llog_debug(input, "new keyboard description from memory"); } else { llog_warn(input, "cannot parse keymap, reverting to rmlvo"); } @@ -130,26 +119,25 @@ int uxkb_desc_init(struct uterm_input *input, } if (!input->keymap) { - llog_warn(input, "failed to create keymap (%s, %s, %s, %s), " + llog_warn(input, + "failed to create keymap (%s, %s, %s, %s), " "reverting to default system keymap", - model, layout, variant, options); + model, layout, variant, options); rmlvo.model = ""; rmlvo.layout = ""; rmlvo.variant = ""; rmlvo.options = ""; - input->keymap = xkb_keymap_new_from_names(input->ctx, - &rmlvo, 0); + input->keymap = xkb_keymap_new_from_names(input->ctx, &rmlvo, 0); if (!input->keymap) { llog_warn(input, "failed to create XKB default keymap, " - "reverting to built-in fallback"); + "reverting to built-in fallback"); - input->keymap = xkb_keymap_new_from_string(input->ctx, - fallback, XKB_KEYMAP_FORMAT_TEXT_V1, 0); + input->keymap = xkb_keymap_new_from_string(input->ctx, fallback, + XKB_KEYMAP_FORMAT_TEXT_V1, 0); if (!input->keymap) { - llog_error(input, - "cannot create fallback keymap"); + llog_error(input, "cannot create fallback keymap"); ret = -EFAULT; goto err_ctx; } @@ -157,36 +145,28 @@ int uxkb_desc_init(struct uterm_input *input, llog_debug(input, "new fallback keyboard description"); } else { - llog_debug(input, "new keyboard description (%s, %s, %s, %s)", - model, layout, variant, options); + llog_debug(input, "new keyboard description (%s, %s, %s, %s)", model, layout, + variant, options); } if (compose_file && *compose_file) { input->compose_table = xkb_compose_table_new_from_buffer( - input->ctx, - compose_file, - compose_file_len, - locale, - XKB_COMPOSE_FORMAT_TEXT_V1, - 0); + input->ctx, compose_file, compose_file_len, locale, + XKB_COMPOSE_FORMAT_TEXT_V1, 0); if (input->compose_table) { - llog_debug(input, - "new compose table from memory"); + llog_debug(input, "new compose table from memory"); } else { llog_warn(input, "cannot parse compose table, " - "reverting to default"); + "reverting to default"); } } if (!input->compose_table) { - input->compose_table = xkb_compose_table_new_from_locale( - input->ctx, - locale, - 0); + input->compose_table = xkb_compose_table_new_from_locale(input->ctx, locale, 0); if (!input->compose_table) { llog_warn(input, "failed to create XKB default compose " - "table, disabling compose support"); + "table, disabling compose support"); } } @@ -216,8 +196,7 @@ int uxkb_dev_init(struct uterm_input_dev *dev) { int ret; - ret = ev_eloop_new_timer(dev->input->eloop, &dev->repeat_timer, NULL, - timer_event, dev); + ret = ev_eloop_new_timer(dev->input->eloop, &dev->repeat_timer, NULL, timer_event, dev); if (ret) return ret; @@ -229,12 +208,10 @@ int uxkb_dev_init(struct uterm_input_dev *dev) } if (dev->input->compose_table) { - dev->compose_state = xkb_compose_state_new( - dev->input->compose_table, - 0); + dev->compose_state = xkb_compose_state_new(dev->input->compose_table, 0); if (!dev->compose_state) llog_warn(dev->input, "cannot create compose state, " - "disabling compose support"); + "disabling compose support"); } return 0; @@ -264,9 +241,9 @@ static void uxkb_dev_update_keyboard_leds(struct uterm_input_dev *dev) int evdev_led; const char *xkb_led; } leds[] = { - { LED_NUML, XKB_LED_NAME_NUM }, - { LED_CAPSL, XKB_LED_NAME_CAPS }, - { LED_SCROLLL, XKB_LED_NAME_SCROLL }, + {LED_NUML, XKB_LED_NAME_NUM}, + {LED_CAPSL, XKB_LED_NAME_CAPS}, + {LED_SCROLLL, XKB_LED_NAME_SCROLL}, }; struct input_event events[sizeof(leds) / sizeof(*leds)]; int i, ret; @@ -279,15 +256,13 @@ static void uxkb_dev_update_keyboard_leds(struct uterm_input_dev *dev) for (i = 0; i < sizeof(leds) / sizeof(*leds); i++) { events[i].type = EV_LED; events[i].code = leds[i].evdev_led; - if (xkb_state_led_name_is_active(dev->state, - leds[i].xkb_led) > 0) + if (xkb_state_led_name_is_active(dev->state, leds[i].xkb_led) > 0) events[i].value = 1; } ret = write(dev->rfd, events, sizeof(events)); if (ret != sizeof(events)) - llog_warning(dev->input, "cannot update LED state (%d): %m", - errno); + llog_warning(dev->input, "cannot update LED state (%d): %m", errno); } static inline int uxkb_dev_resize_event(struct uterm_input_dev *dev, size_t s) @@ -295,38 +270,30 @@ static inline int uxkb_dev_resize_event(struct uterm_input_dev *dev, size_t s) uint32_t *tmp; if (s > dev->num_syms) { - tmp = realloc(dev->event.keysyms, - sizeof(uint32_t) * s); + tmp = realloc(dev->event.keysyms, sizeof(uint32_t) * s); if (!tmp) { - llog_warning(dev->input, - "cannot reallocate keysym buffer"); + llog_warning(dev->input, "cannot reallocate keysym buffer"); return -ENOKEY; } dev->event.keysyms = tmp; - tmp = realloc(dev->event.codepoints, - sizeof(uint32_t) * s); + tmp = realloc(dev->event.codepoints, sizeof(uint32_t) * s); if (!tmp) { - llog_warning(dev->input, - "cannot reallocate codepoints buffer"); + llog_warning(dev->input, "cannot reallocate codepoints buffer"); return -ENOKEY; } dev->event.codepoints = tmp; - tmp = realloc(dev->repeat_event.keysyms, - sizeof(uint32_t) * s); + tmp = realloc(dev->repeat_event.keysyms, sizeof(uint32_t) * s); if (!tmp) { - llog_warning(dev->input, - "cannot reallocate keysym buffer"); + llog_warning(dev->input, "cannot reallocate keysym buffer"); return -ENOKEY; } dev->repeat_event.keysyms = tmp; - tmp = realloc(dev->repeat_event.codepoints, - sizeof(uint32_t) * s); + tmp = realloc(dev->repeat_event.codepoints, sizeof(uint32_t) * s); if (!tmp) { - llog_warning(dev->input, - "cannot reallocate codepoints buffer"); + llog_warning(dev->input, "cannot reallocate codepoints buffer"); return -ENOKEY; } dev->repeat_event.codepoints = tmp; @@ -337,11 +304,8 @@ static inline int uxkb_dev_resize_event(struct uterm_input_dev *dev, size_t s) return 0; } -static int uxkb_dev_fill_event(struct uterm_input_dev *dev, - struct uterm_input_key_event *ev, - xkb_keycode_t code, - int num_syms, - const xkb_keysym_t *syms) +static int uxkb_dev_fill_event(struct uterm_input_dev *dev, struct uterm_input_key_event *ev, + xkb_keycode_t code, int num_syms, const xkb_keysym_t *syms) { int ret, i; @@ -380,8 +344,7 @@ static void uxkb_dev_repeat(struct uterm_input_dev *dev, unsigned int state) return; } - if (state == KEY_PRESSED && - xkb_keymap_key_repeats(keymap, dev->event.keycode)) { + if (state == KEY_PRESSED && xkb_keymap_key_repeats(keymap, dev->event.keycode)) { dev->repeat_event.keycode = dev->event.keycode; dev->repeat_event.ascii = dev->event.ascii; dev->repeat_event.mods = dev->event.mods; @@ -389,19 +352,15 @@ static void uxkb_dev_repeat(struct uterm_input_dev *dev, unsigned int state) for (i = 0; i < dev->event.num_syms; ++i) { dev->repeat_event.keysyms[i] = dev->event.keysyms[i]; - dev->repeat_event.codepoints[i] = - dev->event.codepoints[i]; + dev->repeat_event.codepoints[i] = dev->event.codepoints[i]; } - } else if (dev->repeating && - !xkb_keymap_key_repeats(keymap, dev->event.keycode)) { - num_keysyms = xkb_state_key_get_syms(dev->state, - dev->repeat_event.keycode, - &keysyms); + } else if (dev->repeating && !xkb_keymap_key_repeats(keymap, dev->event.keycode)) { + num_keysyms = + xkb_state_key_get_syms(dev->state, dev->repeat_event.keycode, &keysyms); if (num_keysyms <= 0) return; - ret = uxkb_dev_fill_event(dev, &dev->repeat_event, - dev->repeat_event.keycode, + ret = uxkb_dev_fill_event(dev, &dev->repeat_event, dev->repeat_event.keycode, num_keysyms, keysyms); if (ret) return; @@ -419,8 +378,7 @@ static void uxkb_dev_repeat(struct uterm_input_dev *dev, unsigned int state) ev_timer_update(dev->repeat_timer, &spec); } -int uxkb_dev_process(struct uterm_input_dev *dev, - uint16_t key_state, uint16_t code) +int uxkb_dev_process(struct uterm_input_dev *dev, uint16_t key_state, uint16_t code) { struct xkb_state *state; struct xkb_compose_state *compose_state; @@ -517,12 +475,10 @@ int uxkb_dev_process(struct uterm_input_dev *dev, if (num_keysyms <= 0) return -ENOKEY; - if (compose_status == XKB_COMPOSE_COMPOSING || - compose_status == XKB_COMPOSE_CANCELLED) + if (compose_status == XKB_COMPOSE_COMPOSING || compose_status == XKB_COMPOSE_CANCELLED) return -ENOKEY; - ret = uxkb_dev_fill_event(dev, &dev->event, keycode, num_keysyms, - keysyms); + ret = uxkb_dev_fill_event(dev, &dev->event, keycode, num_keysyms, keysyms); if (ret) return -ENOKEY; @@ -556,11 +512,9 @@ void uxkb_dev_sleep(struct uterm_input_dev *dev) */ memset(dev->key_state_bits, 0, sizeof(dev->key_state_bits)); errno = 0; - ioctl(dev->rfd, EVIOCGKEY(sizeof(dev->key_state_bits)), - dev->key_state_bits); + ioctl(dev->rfd, EVIOCGKEY(sizeof(dev->key_state_bits)), dev->key_state_bits); if (errno) - llog_warn(dev->input, "failed to save keyboard state (%d): %m", - errno); + llog_warn(dev->input, "failed to save keyboard state (%d): %m", errno); } void uxkb_dev_wake_up(struct uterm_input_dev *dev) @@ -575,9 +529,7 @@ void uxkb_dev_wake_up(struct uterm_input_dev *dev) errno = 0; ioctl(dev->rfd, EVIOCGKEY(sizeof(cur_bits)), cur_bits); if (errno) { - llog_warn(dev->input, - "failed to get current keyboard state (%d): %m", - errno); + llog_warn(dev->input, "failed to get current keyboard state (%d): %m", errno); return; } diff --git a/src/uterm_mod_drm3d.c b/src/uterm_mod_drm3d.c index 3fabfe42..6b38f299 100644 --- a/src/uterm_mod_drm3d.c +++ b/src/uterm_mod_drm3d.c @@ -30,8 +30,8 @@ #include #include -#include "shl_module_interface.h" #include "shl_log.h" +#include "shl_module_interface.h" #include "uterm_video_internal.h" extern struct uterm_video_module drm3d_module; diff --git a/src/uterm_monitor.c b/src/uterm_monitor.c index f705d920..cf526459 100644 --- a/src/uterm_monitor.c +++ b/src/uterm_monitor.c @@ -107,9 +107,9 @@ static void monitor_refresh_seats(struct uterm_monitor *mon) } /* Remove all seats that are no longer present */ - shl_dlist_for_each_safe(iter, tmp, &mon->seats) { - seat = shl_dlist_entry(iter, struct uterm_monitor_seat, - list); + shl_dlist_for_each_safe(iter, tmp, &mon->seats) + { + seat = shl_dlist_entry(iter, struct uterm_monitor_seat, list); for (i = 0; i < num; ++i) { if (!strcmp(seats[i], seat->name)) break; @@ -134,9 +134,7 @@ static void monitor_refresh_seats(struct uterm_monitor *mon) free(seats); } -static void monitor_sd_event(struct ev_fd *fd, - int mask, - void *data) +static void monitor_sd_event(struct ev_fd *fd, int mask, void *data) { struct uterm_monitor *mon = data; @@ -174,8 +172,7 @@ static int monitor_sd_init(struct uterm_monitor *mon) goto err_sd; } - ret = ev_eloop_new_fd(mon->eloop, &mon->sd_mon_fd, sfd, EV_READABLE, - monitor_sd_event, mon); + ret = ev_eloop_new_fd(mon->eloop, &mon->sd_mon_fd, sfd, EV_READABLE, monitor_sd_event, mon); if (ret) goto err_sd; @@ -195,10 +192,8 @@ static void monitor_sd_deinit(struct uterm_monitor *mon) uterm_sd_free(mon->sd); } -static void seat_new_dev(struct uterm_monitor_seat *seat, - unsigned int type, - unsigned int flags, - const char *node) +static void seat_new_dev(struct uterm_monitor_seat *seat, unsigned int type, unsigned int flags, + const char *node) { struct uterm_monitor_dev *dev; struct uterm_monitor_event ev; @@ -261,7 +256,7 @@ static void seat_free_dev(struct uterm_monitor_dev *dev) } static struct uterm_monitor_dev *monitor_find_dev(struct uterm_monitor *mon, - struct udev_device *dev) + struct udev_device *dev) { const char *node; struct shl_dlist *iter, *iter2; @@ -272,13 +267,12 @@ static struct uterm_monitor_dev *monitor_find_dev(struct uterm_monitor *mon, if (!node) return NULL; - shl_dlist_for_each(iter, &mon->seats) { - seat = shl_dlist_entry(iter, struct uterm_monitor_seat, - list); - shl_dlist_for_each(iter2, &seat->devices) { - sdev = shl_dlist_entry(iter2, - struct uterm_monitor_dev, - list); + shl_dlist_for_each(iter, &mon->seats) + { + seat = shl_dlist_entry(iter, struct uterm_monitor_seat, list); + shl_dlist_for_each(iter2, &seat->devices) + { + sdev = shl_dlist_entry(iter2, struct uterm_monitor_dev, list); if (!strcmp(node, sdev->node)) return sdev; } @@ -327,9 +321,7 @@ static void monitor_free_seat(struct uterm_monitor_seat *seat) log_debug("free seat %s", seat->name); while (seat->devices.next != &seat->devices) { - dev = shl_dlist_entry(seat->devices.next, - struct uterm_monitor_dev, - list); + dev = shl_dlist_entry(seat->devices.next, struct uterm_monitor_dev, list); seat_free_dev(dev); } @@ -416,14 +408,15 @@ static unsigned int get_fbdev_flags(struct uterm_monitor *mon, const char *node) fd = open(node, O_RDWR | O_CLOEXEC); if (fd < 0) { - log_warning("cannot open fbdev node %s for drm-device verification (%d): %m", - node, errno); + log_warning("cannot open fbdev node %s for drm-device verification (%d): %m", node, + errno); return flags; } ret = ioctl(fd, FBIOGET_FSCREENINFO, &finfo); if (ret) { - log_warning("cannot retrieve finfo from fbdev node %s for drm-device verification (%d): %m", + log_warning("cannot retrieve finfo from fbdev node %s for drm-device verification " + "(%d): %m", node, errno); goto out_close; } @@ -435,8 +428,7 @@ static unsigned int get_fbdev_flags(struct uterm_monitor *mon, const char *node) * checking whether the parent udev device node does also provide a DRM * device. */ len = strlen(finfo.id); - if ((len < 5 || strcmp(&finfo.id[len - 5], "drmfb")) && - strcmp(finfo.id, "nouveaufb") && + if ((len < 5 || strcmp(&finfo.id[len - 5], "drmfb")) && strcmp(finfo.id, "nouveaufb") && strcmp(finfo.id, "psbfb")) flags &= ~UTERM_MONITOR_DRM_BACKED; @@ -450,8 +442,7 @@ static unsigned int get_fbdev_flags(struct uterm_monitor *mon, const char *node) return flags; } -static bool is_drm_primary(struct uterm_monitor *mon, struct udev_device *dev, - const char *node) +static bool is_drm_primary(struct uterm_monitor *mon, struct udev_device *dev, const char *node) { struct udev_device *pci; const char *id; @@ -476,15 +467,15 @@ static bool is_drm_primary(struct uterm_monitor *mon, struct udev_device *dev, */ struct uterm_drm_version { - int version_major; /**< Major version */ - int version_minor; /**< Minor version */ - int version_patchlevel; /**< Patch level */ - size_t name_len; /**< Length of name buffer */ - char *name; /**< Name of driver */ - size_t date_len; /**< Length of date buffer */ - char *date; /**< User-space buffer to hold date */ - size_t desc_len; /**< Length of desc buffer */ - char *desc; /**< User-space buffer to hold desc */ + int version_major; /**< Major version */ + int version_minor; /**< Minor version */ + int version_patchlevel; /**< Patch level */ + size_t name_len; /**< Length of name buffer */ + char *name; /**< Name of driver */ + size_t date_len; /**< Length of date buffer */ + char *date; /**< User-space buffer to hold date */ + size_t desc_len; /**< Length of desc buffer */ + char *desc; /**< User-space buffer to hold desc */ }; #define UTERM_DRM_IOCTL_VERSION _IOWR('d', 0x00, struct uterm_drm_version) @@ -524,8 +515,7 @@ static bool is_drm_usb(struct uterm_monitor *mon, const char *node, int fd) name = get_drm_name(fd); if (!name) { - log_warning("cannot get driver name for DRM device %s (%d): %m", - node, errno); + log_warning("cannot get driver name for DRM device %s (%d): %m", node, errno); return false; } @@ -539,16 +529,16 @@ static bool is_drm_usb(struct uterm_monitor *mon, const char *node, int fd) return res; } -static unsigned int get_drm_flags(struct uterm_monitor *mon, - struct udev_device *dev, const char *node) +static unsigned int get_drm_flags(struct uterm_monitor *mon, struct udev_device *dev, + const char *node) { int fd; unsigned int flags = 0; fd = open(node, O_RDWR | O_CLOEXEC); if (fd < 0) { - log_warning("cannot open DRM device %s for primary-detection (%d): %m", - node, errno); + log_warning("cannot open DRM device %s for primary-detection (%d): %m", node, + errno); return flags; } @@ -561,8 +551,7 @@ static unsigned int get_drm_flags(struct uterm_monitor *mon, return flags; } -static void monitor_udev_add(struct uterm_monitor *mon, - struct udev_device *dev) +static void monitor_udev_add(struct uterm_monitor *mon, struct udev_device *dev) { const char *sname, *subs, *node, *name, *sysname; struct shl_dlist *iter; @@ -624,8 +613,7 @@ static void monitor_udev_add(struct uterm_monitor *mon, log_debug("adding unsupported input dev %s", name); return; } - p = udev_device_get_parent_with_subsystem_devtype(dev, - "input", NULL); + p = udev_device_get_parent_with_subsystem_devtype(dev, "input", NULL); if (!p) { log_debug("adding device without parent %s", name); return; @@ -638,8 +626,7 @@ static void monitor_udev_add(struct uterm_monitor *mon, type = UTERM_MONITOR_INPUT; flags = 0; } else { - log_debug("adding device with unknown subsystem %s (%s)", - subs, name); + log_debug("adding device with unknown subsystem %s (%s)", subs, name); return; } @@ -647,24 +634,22 @@ static void monitor_udev_add(struct uterm_monitor *mon, sname = "seat0"; /* find correct seat */ - shl_dlist_for_each(iter, &mon->seats) { - seat = shl_dlist_entry(iter, struct uterm_monitor_seat, - list); + shl_dlist_for_each(iter, &mon->seats) + { + seat = shl_dlist_entry(iter, struct uterm_monitor_seat, list); if (!strcmp(sname, seat->name)) break; } if (iter == &mon->seats) { - log_debug("adding device for unknown seat %s (%s)", - sname, name); + log_debug("adding device for unknown seat %s (%s)", sname, name); return; } seat_new_dev(seat, type, flags, node); } -static void monitor_udev_remove(struct uterm_monitor *mon, - struct udev_device *dev) +static void monitor_udev_remove(struct uterm_monitor *mon, struct udev_device *dev) { struct uterm_monitor_dev *sdev; @@ -677,8 +662,7 @@ static void monitor_udev_remove(struct uterm_monitor *mon, seat_free_dev(sdev); } -static void monitor_udev_change(struct uterm_monitor *mon, - struct udev_device *dev) +static void monitor_udev_change(struct uterm_monitor *mon, struct udev_device *dev) { const char *sname, *val; struct uterm_monitor_dev *sdev; @@ -708,8 +692,7 @@ static void monitor_udev_change(struct uterm_monitor *mon, ev.dev_type = sdev->type; ev.dev_node = sdev->node; ev.dev_data = sdev->data; - sdev->seat->mon->cb(sdev->seat->mon, &ev, - sdev->seat->mon->data); + sdev->seat->mon->cb(sdev->seat->mon, &ev, sdev->seat->mon->data); } } else { /* Unknown device; maybe it switched into a known seat? Try @@ -718,9 +701,7 @@ static void monitor_udev_change(struct uterm_monitor *mon, } } -static void monitor_udev_event(struct ev_fd *fd, - int mask, - void *data) +static void monitor_udev_event(struct ev_fd *fd, int mask, void *data) { struct uterm_monitor *mon = data; struct udev_device *dev; @@ -762,10 +743,8 @@ static void monitor_udev_event(struct ev_fd *fd, } SHL_EXPORT -int uterm_monitor_new(struct uterm_monitor **out, - struct ev_eloop *eloop, - uterm_monitor_cb cb, - void *data) +int uterm_monitor_new(struct uterm_monitor **out, struct ev_eloop *eloop, uterm_monitor_cb cb, + void *data) { struct uterm_monitor *mon; int ret, ufd, set; @@ -801,8 +780,7 @@ int uterm_monitor_new(struct uterm_monitor **out, goto err_udev; } - ret = udev_monitor_filter_add_match_subsystem_devtype(mon->umon, - "drm", "drm_minor"); + ret = udev_monitor_filter_add_match_subsystem_devtype(mon->umon, "drm", "drm_minor"); if (ret) { errno = -ret; log_err("cannot add udev filter (%d): %m", ret); @@ -810,8 +788,7 @@ int uterm_monitor_new(struct uterm_monitor **out, goto err_umon; } - ret = udev_monitor_filter_add_match_subsystem_devtype(mon->umon, - "graphics", NULL); + ret = udev_monitor_filter_add_match_subsystem_devtype(mon->umon, "graphics", NULL); if (ret) { errno = -ret; log_err("cannot add udev filter (%d): %m", ret); @@ -819,8 +796,7 @@ int uterm_monitor_new(struct uterm_monitor **out, goto err_umon; } - ret = udev_monitor_filter_add_match_subsystem_devtype(mon->umon, - "input", NULL); + ret = udev_monitor_filter_add_match_subsystem_devtype(mon->umon, "input", NULL); if (ret) { errno = -ret; log_err("cannot add udev filter (%d): %m", ret); @@ -858,8 +834,7 @@ int uterm_monitor_new(struct uterm_monitor **out, goto err_umon; } - ret = ev_eloop_new_fd(mon->eloop, &mon->umon_fd, ufd, EV_READABLE, - monitor_udev_event, mon); + ret = ev_eloop_new_fd(mon->eloop, &mon->umon_fd, ufd, EV_READABLE, monitor_udev_event, mon); if (ret) goto err_umon; @@ -896,9 +871,7 @@ void uterm_monitor_unref(struct uterm_monitor *mon) return; while (mon->seats.next != &mon->seats) { - seat = shl_dlist_entry(mon->seats.next, - struct uterm_monitor_seat, - list); + seat = shl_dlist_entry(mon->seats.next, struct uterm_monitor_seat, list); monitor_free_seat(seat); } @@ -957,7 +930,8 @@ void uterm_monitor_scan(struct uterm_monitor *mon) goto out_enum; } - udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) { + udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) + { path = udev_list_entry_get_name(entry); if (!path) { log_debug("udev device without syspath"); diff --git a/src/uterm_monitor.h b/src/uterm_monitor.h index caf70c3a..d201afac 100644 --- a/src/uterm_monitor.h +++ b/src/uterm_monitor.h @@ -56,9 +56,9 @@ enum uterm_monitor_dev_type { }; enum uterm_monitor_dev_flag { - UTERM_MONITOR_DRM_BACKED = 0x01, - UTERM_MONITOR_PRIMARY = 0x02, - UTERM_MONITOR_AUX = 0x04, + UTERM_MONITOR_DRM_BACKED = 0x01, + UTERM_MONITOR_PRIMARY = 0x02, + UTERM_MONITOR_AUX = 0x04, }; struct uterm_monitor_event { @@ -75,12 +75,11 @@ struct uterm_monitor_event { void *dev_data; }; -typedef void (*uterm_monitor_cb) (struct uterm_monitor *mon, - struct uterm_monitor_event *event, - void *data); +typedef void (*uterm_monitor_cb)(struct uterm_monitor *mon, struct uterm_monitor_event *event, + void *data); -int uterm_monitor_new(struct uterm_monitor **out, struct ev_eloop *eloop, - uterm_monitor_cb cb, void *data); +int uterm_monitor_new(struct uterm_monitor **out, struct ev_eloop *eloop, uterm_monitor_cb cb, + void *data); void uterm_monitor_ref(struct uterm_monitor *mon); void uterm_monitor_unref(struct uterm_monitor *mon); void uterm_monitor_scan(struct uterm_monitor *mon); diff --git a/src/uterm_systemd.c b/src/uterm_systemd.c index c316bedd..25c99046 100644 --- a/src/uterm_systemd.c +++ b/src/uterm_systemd.c @@ -56,8 +56,8 @@ int uterm_sd_new(struct uterm_sd **out) ret = sd_booted(); if (ret < 0) { - log_warning("cannot determine whether system booted with systemd (%d): %s", - ret, strerror(-ret)); + log_warning("cannot determine whether system booted with systemd (%d): %s", ret, + strerror(-ret)); return -EOPNOTSUPP; } else if (!ret) { log_info("system not booted with systemd, disabling multi-seat support"); @@ -73,8 +73,7 @@ int uterm_sd_new(struct uterm_sd **out) ret = sd_login_monitor_new("seat", &sd->mon); if (ret) { - log_err("cannot create systemd login monitor (%d): %s", - ret, strerror(-ret)); + log_err("cannot create systemd login monitor (%d): %s", ret, strerror(-ret)); ret = -EFAULT; goto err_free; } @@ -122,8 +121,7 @@ int uterm_sd_get_seats(struct uterm_sd *sd, char ***seats) ret = sd_get_seats(&s); if (ret < 0) { - log_warning("cannot read seat information from systemd: %d", - ret); + log_warning("cannot read seat information from systemd: %d", ret); return -EFAULT; } diff --git a/src/uterm_systemd_internal.h b/src/uterm_systemd_internal.h index c3a1fd44..356298ce 100644 --- a/src/uterm_systemd_internal.h +++ b/src/uterm_systemd_internal.h @@ -52,18 +52,14 @@ static inline int uterm_sd_new(struct uterm_sd **out) return -EOPNOTSUPP; } -static inline void uterm_sd_free(struct uterm_sd *sd) -{ -} +static inline void uterm_sd_free(struct uterm_sd *sd) {} static inline int uterm_sd_get_fd(struct uterm_sd *sd) { return -1; } -static inline void uterm_sd_flush(struct uterm_sd *sd) -{ -} +static inline void uterm_sd_flush(struct uterm_sd *sd) {} static inline int uterm_sd_get_seats(struct uterm_sd *sd, char ***seats) { diff --git a/src/uterm_video.c b/src/uterm_video.c index 68ca9743..34c11077 100644 --- a/src/uterm_video.c +++ b/src/uterm_video.c @@ -35,11 +35,11 @@ #include #include #include "eloop.h" -#include "shl_module.h" #include "shl_dlist.h" #include "shl_hook.h" #include "shl_log.h" #include "shl_misc.h" +#include "shl_module.h" #include "shl_register.h" #include "uterm_video.h" #include "uterm_video_internal.h" @@ -48,7 +48,6 @@ static struct shl_register video_reg = SHL_REGISTER_INIT(video_reg); - static inline void uterm_video_destroy(void *data) { const struct uterm_video_module *ops = data; @@ -73,149 +72,6 @@ const char *uterm_dpms_to_name(int dpms) } } -SHL_EXPORT -int mode_new(struct uterm_mode **out, const struct mode_ops *ops) -{ - struct uterm_mode *mode; - int ret; - - if (!out || !ops) - return -EINVAL; - - mode = malloc(sizeof(*mode)); - if (!mode) - return -ENOMEM; - memset(mode, 0, sizeof(*mode)); - mode->ref = 1; - mode->ops = ops; - - ret = VIDEO_CALL(mode->ops->init, 0, mode); - if (ret) - goto err_free; - - *out = mode; - return 0; - -err_free: - free(mode); - return ret; -} - -SHL_EXPORT -void uterm_mode_ref(struct uterm_mode *mode) -{ - if (!mode || !mode->ref) - return; - - ++mode->ref; -} - -SHL_EXPORT -void uterm_mode_unref(struct uterm_mode *mode) -{ - if (!mode || !mode->ref || --mode->ref) - return; - - VIDEO_CALL(mode->ops->destroy, 0, mode); - free(mode); -} - -SHL_EXPORT -int uterm_mode_bind(struct uterm_mode *mode, struct uterm_display *disp) -{ - if (!mode || !disp || mode->disp) - return -EINVAL; - - mode->disp = disp; - shl_dlist_link_tail(&disp->modes, &mode->list); - uterm_mode_ref(mode); - - return 0; -} - -SHL_EXPORT -void uterm_mode_unbind(struct uterm_mode *mode) -{ - if (!mode) - return; - - mode->disp = NULL; - shl_dlist_unlink(&mode->list); - uterm_mode_unref(mode); -} - -SHL_EXPORT -struct uterm_mode *uterm_mode_next(struct uterm_mode *mode) -{ - if (!mode || mode->list.next == &mode->disp->modes) - return NULL; - - return shl_dlist_entry(mode->list.next, struct uterm_mode, list); -} - -SHL_EXPORT -const char *uterm_mode_get_name(const struct uterm_mode *mode) -{ - if (!mode) - return NULL; - - return VIDEO_CALL(mode->ops->get_name, NULL, mode); -} - -SHL_EXPORT -unsigned int uterm_mode_get_width(const struct uterm_mode *mode) -{ - if (!mode) - return 0; - - return VIDEO_CALL(mode->ops->get_width, 0, mode); -} - -SHL_EXPORT -unsigned int uterm_mode_get_height(const struct uterm_mode *mode) -{ - if (!mode) - return 0; - - return VIDEO_CALL(mode->ops->get_height, 0, mode); -} - -int display_schedule_vblank_timer(struct uterm_display *disp) -{ - int ret; - - if (disp->vblank_scheduled) - return 0; - - ret = ev_timer_update(disp->vblank_timer, &disp->vblank_spec); - if (ret) - return ret; - - disp->vblank_scheduled = true; - return 0; -} - -void display_set_vblank_timer(struct uterm_display *disp, - unsigned int msecs) -{ - if (msecs >= 1000) - msecs = 999; - else if (msecs == 0) - msecs = 15; - - disp->vblank_spec.it_value.tv_nsec = msecs * 1000 * 1000; -} - -static void display_vblank_timer_event(struct ev_timer *timer, - uint64_t expirations, - void *data) -{ - struct uterm_display *disp = data; - - disp->vblank_scheduled = false; - DISPLAY_CB(disp, UTERM_PAGE_FLIP); -} - int display_new(struct uterm_display **out, const struct display_ops *ops) { struct uterm_display *disp; @@ -230,30 +86,19 @@ int display_new(struct uterm_display **out, const struct display_ops *ops) memset(disp, 0, sizeof(*disp)); disp->ref = 1; disp->ops = ops; - shl_dlist_init(&disp->modes); - log_info("new display %p", disp); ret = shl_hook_new(&disp->hook); if (ret) goto err_free; - disp->vblank_spec.it_value.tv_nsec = 15 * 1000 * 1000; - - ret = ev_timer_new(&disp->vblank_timer, NULL, - display_vblank_timer_event, disp, NULL, NULL); - if (ret) - goto err_hook; - ret = VIDEO_CALL(disp->ops->init, 0, disp); if (ret) - goto err_timer; + goto err_hook; *out = disp; return 0; -err_timer: - ev_timer_unref(disp->vblank_timer); err_hook: shl_hook_free(disp->hook); err_free: @@ -273,21 +118,12 @@ void uterm_display_ref(struct uterm_display *disp) SHL_EXPORT void uterm_display_unref(struct uterm_display *disp) { - struct uterm_mode *mode; - if (!disp || !disp->ref || --disp->ref) return; log_info("free display %p", disp); - while (!shl_dlist_empty(&disp->modes)) { - mode = shl_dlist_entry(disp->modes.prev, struct uterm_mode, - list); - uterm_mode_unbind(mode); - } - VIDEO_CALL(disp->ops->destroy, 0, disp); - ev_timer_unref(disp->vblank_timer); shl_hook_free(disp->hook); free(disp); } @@ -295,15 +131,9 @@ void uterm_display_unref(struct uterm_display *disp) SHL_EXPORT int uterm_display_bind(struct uterm_display *disp, struct uterm_video *video) { - int ret; - if (!disp || !video || disp->video) return -EINVAL; - ret = ev_eloop_add_timer(video->eloop, disp->vblank_timer); - if (ret) - return ret; - shl_dlist_link_tail(&video->displays, &disp->list); disp->video = video; uterm_display_ref(disp); @@ -322,7 +152,6 @@ void uterm_display_unbind(struct uterm_display *disp) uterm_display_deactivate(disp); disp->video = NULL; shl_dlist_unlink(&disp->list); - ev_eloop_rm_timer(disp->vblank_timer); uterm_display_unref(disp); } @@ -350,8 +179,7 @@ struct uterm_display *uterm_display_next(struct uterm_display *disp) } SHL_EXPORT -int uterm_display_register_cb(struct uterm_display *disp, uterm_display_cb cb, - void *data) +int uterm_display_register_cb(struct uterm_display *disp, uterm_display_cb cb, void *data) { if (!disp) return -EINVAL; @@ -360,8 +188,7 @@ int uterm_display_register_cb(struct uterm_display *disp, uterm_display_cb cb, } SHL_EXPORT -void uterm_display_unregister_cb(struct uterm_display *disp, - uterm_display_cb cb, void *data) +void uterm_display_unregister_cb(struct uterm_display *disp, uterm_display_cb cb, void *data) { if (!disp) return; @@ -370,39 +197,21 @@ void uterm_display_unregister_cb(struct uterm_display *disp, } SHL_EXPORT -struct uterm_mode *uterm_display_get_modes(struct uterm_display *disp) -{ - if (!disp || shl_dlist_empty(&disp->modes)) - return NULL; - - return shl_dlist_entry(disp->modes.next, struct uterm_mode, list); -} - -SHL_EXPORT -struct uterm_mode *uterm_display_get_current(struct uterm_display *disp) -{ - if (!disp) - return NULL; - - return disp->current_mode; -} - -SHL_EXPORT -struct uterm_mode *uterm_display_get_default(struct uterm_display *disp) +unsigned int uterm_display_get_width(struct uterm_display *disp) { if (!disp) - return NULL; + return 0; - return disp->default_mode; + return disp->width; } SHL_EXPORT -struct uterm_mode *uterm_display_get_original(struct uterm_display *disp) +unsigned int uterm_display_get_height(struct uterm_display *disp) { if (!disp) - return NULL; + return 0; - return disp->original_mode; + return disp->height; } SHL_EXPORT @@ -426,16 +235,12 @@ int uterm_display_get_state(struct uterm_display *disp) } SHL_EXPORT -int uterm_display_activate(struct uterm_display *disp, struct uterm_mode *mode) +int uterm_display_activate(struct uterm_display *disp) { - if (!disp || !disp->video || display_is_online(disp) || - !video_is_awake(disp->video)) + if (!disp || !disp->video || display_is_online(disp) || !video_is_awake(disp->video)) return -EINVAL; - if (!mode) - mode = disp->desired_mode; - - return VIDEO_CALL(disp->ops->activate, 0, disp, mode); + return VIDEO_CALL(disp->ops->activate, 0, disp); } SHL_EXPORT @@ -474,18 +279,6 @@ int uterm_display_use(struct uterm_display *disp, bool *opengl) return VIDEO_CALL(disp->ops->use, -EOPNOTSUPP, disp, opengl); } -SHL_EXPORT -int uterm_display_get_buffers(struct uterm_display *disp, - struct uterm_video_buffer *buffer, - unsigned int formats) -{ - if (!disp || !display_is_online(disp) || !buffer) - return -EINVAL; - - return VIDEO_CALL(disp->ops->get_buffers, -EOPNOTSUPP, disp, buffer, - formats); -} - SHL_EXPORT int uterm_display_swap(struct uterm_display *disp, bool immediate) { @@ -501,51 +294,21 @@ bool uterm_display_is_swapping(struct uterm_display *disp) if (!disp) return false; - return disp->vblank_scheduled || (disp->flags & DISPLAY_VSYNC); -} - -SHL_EXPORT -int uterm_display_fill(struct uterm_display *disp, - uint8_t r, uint8_t g, uint8_t b, - unsigned int x, unsigned int y, - unsigned int width, unsigned int height) -{ - if (!disp || !display_is_online(disp) || !video_is_awake(disp->video)) - return -EINVAL; - - return VIDEO_CALL(disp->ops->fill, -EOPNOTSUPP, disp, r, g, b, x, y, - width, height); + return VIDEO_CALL(disp->ops->is_swapping, 0, disp); } SHL_EXPORT -int uterm_display_fake_blend(struct uterm_display *disp, - const struct uterm_video_buffer *buf, - unsigned int x, unsigned int y, - uint8_t fr, uint8_t fg, uint8_t fb, - uint8_t br, uint8_t bg, uint8_t bb) +int uterm_display_fill(struct uterm_display *disp, uint8_t r, uint8_t g, uint8_t b, unsigned int x, + unsigned int y, unsigned int width, unsigned int height) { - struct uterm_video_blend_req req; - if (!disp || !display_is_online(disp) || !video_is_awake(disp->video)) return -EINVAL; - memset(&req, 0, sizeof(req)); - req.buf = buf; - req.x = x; - req.y = y; - req.fr = fr; - req.fg = fg; - req.fb = fb; - req.br = br; - req.bg = bg; - req.bb = bb; - - return VIDEO_CALL(disp->ops->fake_blendv, -EOPNOTSUPP, disp, &req, 1); + return VIDEO_CALL(disp->ops->fill, -EOPNOTSUPP, disp, r, g, b, x, y, width, height); } SHL_EXPORT -int uterm_display_fake_blendv(struct uterm_display *disp, - const struct uterm_video_blend_req *req, +int uterm_display_fake_blendv(struct uterm_display *disp, const struct uterm_video_blend_req *req, size_t num) { if (!disp || !display_is_online(disp) || !video_is_awake(disp->video)) @@ -555,9 +318,9 @@ int uterm_display_fake_blendv(struct uterm_display *disp, } SHL_EXPORT -int uterm_video_new(struct uterm_video **out, struct ev_eloop *eloop, - const char *node, const char *backend, - unsigned int desired_width, unsigned int desired_height) +int uterm_video_new(struct uterm_video **out, struct ev_eloop *eloop, const char *node, + const char *backend, unsigned int desired_width, unsigned int desired_height, + bool use_original) { struct shl_register_record *record; const char *name = backend ? backend : ""; @@ -635,8 +398,7 @@ void uterm_video_unref(struct uterm_video *video) log_info("free device %p", video); while (!shl_dlist_empty(&video->displays)) { - disp = shl_dlist_entry(video->displays.prev, - struct uterm_display, list); + disp = shl_dlist_entry(video->displays.prev, struct uterm_display, list); uterm_display_unbind(disp); } @@ -646,28 +408,17 @@ void uterm_video_unref(struct uterm_video *video) free(video); } -SHL_EXPORT -void uterm_video_segfault(struct uterm_video *video) -{ - if (!video) - return; - - VIDEO_CALL(video->mod->ops.segfault, 0, video); -} - SHL_EXPORT struct uterm_display *uterm_video_get_displays(struct uterm_video *video) { if (!video || shl_dlist_empty(&video->displays)) return NULL; - return shl_dlist_entry(video->displays.next, struct uterm_display, - list); + return shl_dlist_entry(video->displays.next, struct uterm_display, list); } SHL_EXPORT -int uterm_video_register_cb(struct uterm_video *video, uterm_video_cb cb, - void *data) +int uterm_video_register_cb(struct uterm_video *video, uterm_video_cb cb, void *data) { if (!video || !cb) return -EINVAL; @@ -676,8 +427,7 @@ int uterm_video_register_cb(struct uterm_video *video, uterm_video_cb cb, } SHL_EXPORT -void uterm_video_unregister_cb(struct uterm_video *video, uterm_video_cb cb, - void *data) +void uterm_video_unregister_cb(struct uterm_video *video, uterm_video_cb cb, void *data) { if (!video || !cb) return; @@ -704,11 +454,9 @@ int uterm_video_register(const struct uterm_video_module *ops) log_debug("register video backend %s", ops->name); - ret = shl_register_add_cb(&video_reg, ops->name, (void*)ops, - uterm_video_destroy); + ret = shl_register_add_cb(&video_reg, ops->name, (void *)ops, uterm_video_destroy); if (ret) { - log_error("cannot register video backend %s: %d", ops->name, - ret); + log_error("cannot register video backend %s: %d", ops->name, ret); return ret; } diff --git a/src/uterm_video.h b/src/uterm_video.h index ec451048..d2a51a37 100644 --- a/src/uterm_video.h +++ b/src/uterm_video.h @@ -97,10 +97,10 @@ struct uterm_display_event { }; enum uterm_video_format { - UTERM_FORMAT_GREY = 0x01, - UTERM_FORMAT_XRGB32 = 0x02, - UTERM_FORMAT_RGB16 = 0x04, - UTERM_FORMAT_RGB24 = 0x08, + UTERM_FORMAT_GREY = 0x01, + UTERM_FORMAT_XRGB32 = 0x02, + UTERM_FORMAT_RGB16 = 0x04, + UTERM_FORMAT_RGB24 = 0x08, }; struct uterm_video_buffer { @@ -123,27 +123,15 @@ struct uterm_video_blend_req { uint8_t bb; }; -typedef void (*uterm_video_cb) (struct uterm_video *video, - struct uterm_video_hotplug *arg, - void *data); -typedef void (*uterm_display_cb) (struct uterm_display *disp, - struct uterm_display_event *arg, - void *data); +typedef void (*uterm_video_cb)(struct uterm_video *video, struct uterm_video_hotplug *arg, + void *data); +typedef void (*uterm_display_cb)(struct uterm_display *disp, struct uterm_display_event *arg, + void *data); /* misc */ const char *uterm_dpms_to_name(int dpms); -/* display modes interface */ - -void uterm_mode_ref(struct uterm_mode *mode); -void uterm_mode_unref(struct uterm_mode *mode); -struct uterm_mode *uterm_mode_next(struct uterm_mode *mode); - -const char *uterm_mode_get_name(const struct uterm_mode *mode); -unsigned int uterm_mode_get_width(const struct uterm_mode *mode); -unsigned int uterm_mode_get_height(const struct uterm_mode *mode); - /* display interface */ void uterm_display_ref(struct uterm_display *disp); @@ -152,56 +140,42 @@ bool uterm_display_is_drm(struct uterm_display *disp); const char *uterm_display_backend_name(struct uterm_display *disp); struct uterm_display *uterm_display_next(struct uterm_display *disp); -int uterm_display_register_cb(struct uterm_display *disp, uterm_display_cb cb, - void *data); -void uterm_display_unregister_cb(struct uterm_display *disp, - uterm_display_cb cb, void *data); +int uterm_display_register_cb(struct uterm_display *disp, uterm_display_cb cb, void *data); +void uterm_display_unregister_cb(struct uterm_display *disp, uterm_display_cb cb, void *data); struct uterm_mode *uterm_display_get_modes(struct uterm_display *disp); struct uterm_mode *uterm_display_get_current(struct uterm_display *disp); struct uterm_mode *uterm_display_get_default(struct uterm_display *disp); struct uterm_mode *uterm_display_get_original(struct uterm_display *disp); +unsigned int uterm_display_get_width(struct uterm_display *disp); +unsigned int uterm_display_get_height(struct uterm_display *disp); int uterm_display_get_state(struct uterm_display *disp); -int uterm_display_activate(struct uterm_display *disp, struct uterm_mode *mode); +int uterm_display_activate(struct uterm_display *disp); void uterm_display_deactivate(struct uterm_display *disp); int uterm_display_set_dpms(struct uterm_display *disp, int state); int uterm_display_get_dpms(const struct uterm_display *disp); int uterm_display_use(struct uterm_display *disp, bool *opengl); -int uterm_display_get_buffers(struct uterm_display *disp, - struct uterm_video_buffer *buffer, - unsigned int formats); int uterm_display_swap(struct uterm_display *disp, bool immediate); bool uterm_display_is_swapping(struct uterm_display *disp); -int uterm_display_fill(struct uterm_display *disp, - uint8_t r, uint8_t g, uint8_t b, - unsigned int x, unsigned int y, - unsigned int width, unsigned int height); -int uterm_display_fake_blend(struct uterm_display *disp, - const struct uterm_video_buffer *buf, - unsigned int x, unsigned int y, - uint8_t fr, uint8_t fg, uint8_t fb, - uint8_t br, uint8_t bg, uint8_t bb); -int uterm_display_fake_blendv(struct uterm_display *disp, - const struct uterm_video_blend_req *req, +int uterm_display_fill(struct uterm_display *disp, uint8_t r, uint8_t g, uint8_t b, unsigned int x, + unsigned int y, unsigned int width, unsigned int height); +int uterm_display_fake_blendv(struct uterm_display *disp, const struct uterm_video_blend_req *req, size_t num); /* video interface */ -int uterm_video_new(struct uterm_video **out, struct ev_eloop *eloop, - const char *node, const char *backend, - unsigned int desired_width, unsigned int desired_height); +int uterm_video_new(struct uterm_video **out, struct ev_eloop *eloop, const char *node, + const char *backend, unsigned int desired_width, unsigned int desired_height, + bool use_original); void uterm_video_ref(struct uterm_video *video); void uterm_video_unref(struct uterm_video *video); -void uterm_video_segfault(struct uterm_video *video); struct uterm_display *uterm_video_get_displays(struct uterm_video *video); -int uterm_video_register_cb(struct uterm_video *video, uterm_video_cb cb, - void *data); -void uterm_video_unregister_cb(struct uterm_video *video, uterm_video_cb cb, - void *data); +int uterm_video_register_cb(struct uterm_video *video, uterm_video_cb cb, void *data); +void uterm_video_unregister_cb(struct uterm_video *video, uterm_video_cb cb, void *data); int uterm_video_register(const struct uterm_video_module *ops); void uterm_video_unregister(const char *name); @@ -213,7 +187,8 @@ void uterm_video_poll(struct uterm_video *video); #ifdef BUILD_ENABLE_VIDEO_DRM2D extern struct uterm_video_module drm2d_module; -static inline void uterm_register_drm2d(void) { +static inline void uterm_register_drm2d(void) +{ uterm_video_register(&drm2d_module); } @@ -224,7 +199,8 @@ static inline void uterm_register_drm2d(void) {} #ifdef BUILD_ENABLE_VIDEO_FBDEV extern struct uterm_video_module fbdev_module; -static inline void uterm_register_fbdev(void) { +static inline void uterm_register_fbdev(void) +{ uterm_video_register(&fbdev_module); } #else diff --git a/src/uterm_video_internal.h b/src/uterm_video_internal.h index 020b7bbd..abf186e7 100644 --- a/src/uterm_video_internal.h +++ b/src/uterm_video_internal.h @@ -39,40 +39,27 @@ /* backend-operations */ -struct mode_ops { - int (*init) (struct uterm_mode *mode); - void (*destroy) (struct uterm_mode *mode); - const char *(*get_name) (const struct uterm_mode *mode); - unsigned int (*get_width) (const struct uterm_mode *mode); - unsigned int (*get_height) (const struct uterm_mode *mode); -}; - struct display_ops { - int (*init) (struct uterm_display *display); - void (*destroy) (struct uterm_display *display); - int (*activate) (struct uterm_display *disp, struct uterm_mode *mode); - void (*deactivate) (struct uterm_display *disp); - int (*set_dpms) (struct uterm_display *disp, int state); - int (*use) (struct uterm_display *disp, bool *opengl); - int (*get_buffers) (struct uterm_display *disp, - struct uterm_video_buffer *buffer, - unsigned int formats); - int (*swap) (struct uterm_display *disp, bool immediate); - int (*fake_blendv) (struct uterm_display *disp, - const struct uterm_video_blend_req *req, - size_t num); - int (*fill) (struct uterm_display *disp, - uint8_t r, uint8_t g, uint8_t b, unsigned int x, - unsigned int y, unsigned int width, unsigned int height); + int (*init)(struct uterm_display *display); + void (*destroy)(struct uterm_display *display); + int (*activate)(struct uterm_display *disp); + void (*deactivate)(struct uterm_display *disp); + int (*set_dpms)(struct uterm_display *disp, int state); + int (*use)(struct uterm_display *disp, bool *opengl); + int (*swap)(struct uterm_display *disp, bool immediate); + bool (*is_swapping)(struct uterm_display *disp); + int (*fake_blendv)(struct uterm_display *disp, const struct uterm_video_blend_req *req, + size_t num); + int (*fill)(struct uterm_display *disp, uint8_t r, uint8_t g, uint8_t b, unsigned int x, + unsigned int y, unsigned int width, unsigned int height); }; struct video_ops { - int (*init) (struct uterm_video *video, const char *node); - void (*destroy) (struct uterm_video *video); - void (*segfault) (struct uterm_video *video); - int (*poll) (struct uterm_video *video); - void (*sleep) (struct uterm_video *video); - int (*wake_up) (struct uterm_video *video); + int (*init)(struct uterm_video *video, const char *node); + void (*destroy)(struct uterm_video *video); + int (*poll)(struct uterm_video *video); + void (*sleep)(struct uterm_video *video); + int (*wake_up)(struct uterm_video *video); }; struct uterm_video_module { @@ -83,64 +70,41 @@ struct uterm_video_module { #define VIDEO_CALL(func, els, ...) (func ? func(__VA_ARGS__) : els) -/* uterm_mode */ - -struct uterm_mode { - struct shl_dlist list; - unsigned long ref; - struct uterm_display *disp; - - const struct mode_ops *ops; - void *data; -}; - -int mode_new(struct uterm_mode **out, const struct mode_ops *ops); -int uterm_mode_bind(struct uterm_mode *mode, struct uterm_display *disp); -void uterm_mode_unbind(struct uterm_mode *mode); - /* uterm_display */ -#define DISPLAY_ONLINE 0x01 -#define DISPLAY_VSYNC 0x02 -#define DISPLAY_AVAILABLE 0x04 -#define DISPLAY_OPEN 0x08 -#define DISPLAY_DBUF 0x10 -#define DISPLAY_DITHERING 0x20 -#define DISPLAY_PFLIP 0x40 +#define DISPLAY_ONLINE 0x01 +#define DISPLAY_VSYNC 0x02 +#define DISPLAY_AVAILABLE 0x04 +#define DISPLAY_OPEN 0x08 +#define DISPLAY_DBUF 0x10 +#define DISPLAY_DITHERING 0x20 +#define DISPLAY_PFLIP 0x40 struct uterm_display { struct shl_dlist list; unsigned long ref; unsigned int flags; + unsigned int width; + unsigned int height; + struct uterm_video *video; struct shl_hook *hook; - struct shl_dlist modes; - struct uterm_mode *default_mode; - struct uterm_mode *desired_mode; - struct uterm_mode *current_mode; - struct uterm_mode *original_mode; int dpms; - bool vblank_scheduled; - struct itimerspec vblank_spec; - struct ev_timer *vblank_timer; - const struct display_ops *ops; void *data; }; int display_new(struct uterm_display **out, const struct display_ops *ops); -void display_set_vblank_timer(struct uterm_display *disp, - unsigned int msecs); -int display_schedule_vblank_timer(struct uterm_display *disp); int uterm_display_bind(struct uterm_display *disp, struct uterm_video *video); void uterm_display_unbind(struct uterm_display *disp); -#define DISPLAY_CB(disp, act) shl_hook_call((disp)->hook, (disp), \ - &(struct uterm_display_event){ \ - .action = (act), \ - }) +#define DISPLAY_CB(disp, act) \ + shl_hook_call((disp)->hook, (disp), \ + &(struct uterm_display_event){ \ + .action = (act), \ + }) static inline bool display_is_online(const struct uterm_display *disp) { @@ -149,8 +113,8 @@ static inline bool display_is_online(const struct uterm_display *disp) /* uterm_video */ -#define VIDEO_AWAKE 0x01 -#define VIDEO_HOTPLUG 0x02 +#define VIDEO_AWAKE 0x01 +#define VIDEO_HOTPLUG 0x02 struct uterm_video { unsigned long ref; @@ -160,6 +124,7 @@ struct uterm_video { struct shl_dlist displays; struct shl_hook *hook; + bool use_original; unsigned int desired_width; unsigned int desired_height; @@ -177,9 +142,10 @@ static inline bool video_need_hotplug(const struct uterm_video *video) return video->flags & VIDEO_HOTPLUG; } -#define VIDEO_CB(vid, disp, act) shl_hook_call((vid)->hook, (vid), \ - &(struct uterm_video_hotplug){ \ - .display = (disp), \ - .action = (act), \ - }) +#define VIDEO_CB(vid, disp, act) \ + shl_hook_call((vid)->hook, (vid), \ + &(struct uterm_video_hotplug){ \ + .display = (disp), \ + .action = (act), \ + }) #endif /* UTERM_VIDEO_INTERNAL_H */ diff --git a/src/uterm_vt.c b/src/uterm_vt.c index 1760a429..24903c61 100644 --- a/src/uterm_vt.c +++ b/src/uterm_vt.c @@ -85,8 +85,7 @@ struct uterm_vt_master { struct shl_dlist vts; }; -static int vt_call(struct uterm_vt *vt, unsigned int event, int target, - bool force) +static int vt_call(struct uterm_vt *vt, unsigned int event, int target, bool force) { int ret; struct uterm_vt_event ev; @@ -106,8 +105,7 @@ static int vt_call(struct uterm_vt *vt, unsigned int event, int target, ret = vt->cb(vt, &ev, vt->data); if (ret) - log_warning("vt event handler returned %d instead of 0 on activation", - ret); + log_warning("vt event handler returned %d instead of 0 on activation", ret); break; case UTERM_VT_DEACTIVATE: if (!vt->active) @@ -118,7 +116,8 @@ static int vt_call(struct uterm_vt *vt, unsigned int event, int target, ret = vt->cb(vt, &ev, vt->data); if (ret) { if (force) - log_warning("vt event handler returned %d instead of 0 on forced deactivation", + log_warning("vt event handler returned %d instead of 0 on forced " + "deactivation", ret); else return ret; @@ -198,11 +197,9 @@ static void real_sig_enter(struct uterm_vt *vt, struct signalfd_siginfo *info) if (vt->real_delayed) { vt->real_delayed = false; - ev_eloop_unregister_idle_cb(vt->vtm->eloop, real_delayed, vt, - EV_NORMAL); + ev_eloop_unregister_idle_cb(vt->vtm->eloop, real_delayed, vt, EV_NORMAL); } else if (vt->active) { - log_warning("activating VT %d even though it's already active", - vt->real_num); + log_warning("activating VT %d even though it's already active", vt->real_num); } else { uterm_input_wake_up(vt->input); } @@ -239,12 +236,10 @@ static void real_sig_leave(struct uterm_vt *vt, struct signalfd_siginfo *info) if (vt->real_delayed) { vt->real_delayed = false; - ev_eloop_unregister_idle_cb(vt->vtm->eloop, real_delayed, vt, - EV_NORMAL); + ev_eloop_unregister_idle_cb(vt->vtm->eloop, real_delayed, vt, EV_NORMAL); uterm_input_sleep(vt->input); } else if (!active) { - log_warning("deactivating VT %d even though it's not active", - vt->real_num); + log_warning("deactivating VT %d even though it's not active", vt->real_num); } else { uterm_input_sleep(vt->input); } @@ -282,7 +277,7 @@ static int open_tty(const char *dev, int *tty_fd, int *tty_num) if (!dev || !tty_fd || !tty_num) return -EINVAL; - log_notice("using tty %s", dev); + log_notice("using tty %s\n", dev); fd = open(dev, O_RDWR | O_NOCTTY | O_CLOEXEC); if (fd < 0) { @@ -351,8 +346,8 @@ static int real_open(struct uterm_vt *vt, const char *vt_name) if (ret) return ret; - ret = ev_eloop_new_fd(vt->vtm->eloop, &vt->real_efd, vt->real_fd, - EV_READABLE, real_vt_input, vt); + ret = ev_eloop_new_fd(vt->vtm->eloop, &vt->real_efd, vt->real_fd, EV_READABLE, + real_vt_input, vt); if (ret) goto err_fd; @@ -409,8 +404,7 @@ static int real_open(struct uterm_vt *vt, const char *vt_name) log_warning("cannot set VT KBMODE to K_OFF (%d): %m", errno); if (vts.v_active == vt->real_num) { - ret = ev_eloop_register_idle_cb(vt->vtm->eloop, real_delayed, - vt, EV_NORMAL); + ret = ev_eloop_register_idle_cb(vt->vtm->eloop, real_delayed, vt, EV_NORMAL); if (ret) { log_error("cannot register idle cb for VT switch"); goto err_kbdmode; @@ -424,20 +418,17 @@ static int real_open(struct uterm_vt *vt, const char *vt_name) err_kbdmode: err = ioctl(vt->real_fd, KDSKBMODE, vt->real_kbmode); if (err) - log_error("cannot reset VT KBMODE to %d (%d): %m", - vt->real_kbmode, errno); + log_error("cannot reset VT KBMODE to %d (%d): %m", vt->real_kbmode, errno); err_setmode: memset(&mode, 0, sizeof(mode)); mode.mode = VT_AUTO; err = ioctl(vt->real_fd, VT_SETMODE, &mode); if (err) - log_warning("cannot reset VT %d to VT_AUTO mode (%d): %m", - vt->real_num, errno); + log_warning("cannot reset VT %d to VT_AUTO mode (%d): %m", vt->real_num, errno); err_text: err = ioctl(vt->real_fd, KDSETMODE, KD_TEXT); if (err) - log_warning("cannot reset VT %d to text-mode (%d): %m", - vt->real_num, errno); + log_warning("cannot reset VT %d to text-mode (%d): %m", vt->real_num, errno); err_eloop: ev_eloop_rm_fd(vt->real_efd); vt->real_efd = NULL; @@ -455,8 +446,7 @@ static void real_close(struct uterm_vt *vt) if (vt->real_delayed) { vt->real_delayed = false; - ev_eloop_unregister_idle_cb(vt->vtm->eloop, real_delayed, vt, - EV_NORMAL); + ev_eloop_unregister_idle_cb(vt->vtm->eloop, real_delayed, vt, EV_NORMAL); uterm_input_sleep(vt->input); } else if (vt->active) { uterm_input_sleep(vt->input); @@ -465,20 +455,17 @@ static void real_close(struct uterm_vt *vt) ret = ioctl(vt->real_fd, KDSKBMODE, vt->real_kbmode); if (ret && !vt->hup) - log_error("cannot reset VT KBMODE to %d (%d): %m", - vt->real_kbmode, errno); + log_error("cannot reset VT KBMODE to %d (%d): %m", vt->real_kbmode, errno); memset(&mode, 0, sizeof(mode)); mode.mode = VT_AUTO; ret = ioctl(vt->real_fd, VT_SETMODE, &mode); if (ret && !vt->hup) - log_warning("cannot reset VT %d to VT_AUTO mode (%d): %m", - vt->real_num, errno); + log_warning("cannot reset VT %d to VT_AUTO mode (%d): %m", vt->real_num, errno); ret = ioctl(vt->real_fd, KDSETMODE, KD_TEXT); if (ret && !vt->hup) - log_warning("cannot reset VT %d to text-mode (%d): %m", - vt->real_num, errno); + log_warning("cannot reset VT %d to text-mode (%d): %m", vt->real_num, errno); ev_eloop_rm_fd(vt->real_efd); vt->real_efd = NULL; @@ -510,8 +497,7 @@ static int real_activate(struct uterm_vt *vt) return 0; if (vt->active) - log_warning("activating VT %d even though it's already active", - vt->real_num); + log_warning("activating VT %d even though it's already active", vt->real_num); vt->real_target = -1; ret = ioctl(vt->real_fd, VT_ACTIVATE, vt->real_num); @@ -556,20 +542,18 @@ static int real_deactivate(struct uterm_vt *vt) return 0; if (!vt->active) - log_warning("deactivating VT %d even though it's not active", - vt->real_num); + log_warning("deactivating VT %d even though it's not active", vt->real_num); vt->real_target = vt->real_saved_num; vt->real_target_time = time(NULL); ret = ioctl(vt->real_fd, VT_ACTIVATE, vt->real_saved_num); if (ret) { - log_warn("cannot leave VT %d to VT %d (%d): %m", vt->real_num, - vt->real_saved_num, errno); + log_warn("cannot leave VT %d to VT %d (%d): %m", vt->real_num, vt->real_saved_num, + errno); return -EFAULT; } - log_debug("leaving VT %d on demand to VT %d", vt->real_num, - vt->real_saved_num); + log_debug("leaving VT %d on demand to VT %d", vt->real_num, vt->real_saved_num); return -EINPROGRESS; } @@ -609,15 +593,13 @@ static void real_input(struct uterm_vt *vt, struct uterm_input_key_event *ev) if (!id || id == vt->real_num) return; - log_debug("deactivating VT %d to %d due to user input", vt->real_num, - id); + log_debug("deactivating VT %d to %d due to user input", vt->real_num, id); vt->real_target = id; vt->real_target_time = time(NULL); ret = ioctl(vt->real_fd, VT_ACTIVATE, id); if (ret) { - log_warn("cannot leave VT %d to %d (%d): %m", vt->real_num, - id, errno); + log_warn("cannot leave VT %d to %d (%d): %m", vt->real_num, id, errno); return; } } @@ -646,16 +628,13 @@ static void real_retry(struct uterm_vt *vt) } if (!vt->active) - log_warning("leaving VT %d even though it's not active", - vt->real_num); + log_warning("leaving VT %d even though it's not active", vt->real_num); - log_debug("deactivating VT %d to %d (retry)", vt->real_num, - vt->real_target); + log_debug("deactivating VT %d to %d (retry)", vt->real_num, vt->real_target); ret = ioctl(vt->real_fd, VT_ACTIVATE, vt->real_target); if (ret) { - log_warn("cannot leave VT %d to %d (%d): %m", vt->real_num, - vt->real_target, errno); + log_warn("cannot leave VT %d to %d (%d): %m", vt->real_num, vt->real_target, errno); return; } } @@ -748,9 +727,7 @@ static void fake_close(struct uterm_vt *vt) * handling. */ -static void vt_input(struct uterm_input *input, - struct uterm_input_key_event *ev, - void *data) +static void vt_input(struct uterm_input *input, struct uterm_input_key_event *ev, void *data) { struct uterm_vt *vt = data; @@ -760,8 +737,7 @@ static void vt_input(struct uterm_input *input, fake_input(vt, ev); } -static void vt_sigusr1(struct ev_eloop *eloop, struct signalfd_siginfo *info, - void *data) +static void vt_sigusr1(struct ev_eloop *eloop, struct signalfd_siginfo *info, void *data) { struct uterm_vt *vt = data; @@ -769,8 +745,7 @@ static void vt_sigusr1(struct ev_eloop *eloop, struct signalfd_siginfo *info, real_sig_enter(vt, info); } -static void vt_sigusr2(struct ev_eloop *eloop, struct signalfd_siginfo *info, - void *data) +static void vt_sigusr2(struct ev_eloop *eloop, struct signalfd_siginfo *info, void *data) { struct uterm_vt *vt = data; @@ -801,8 +776,7 @@ static int seat_find_vt(const char *seat, char **out) /* First check whether our controlling terminal is a real VT. If * it is, use it but verify very hard that it really is. */ ret = fstat(STDERR_FILENO, &st); - if (!ret && major(st.st_rdev) == TTY_MAJOR && - minor(st.st_rdev) > 0) { + if (!ret && major(st.st_rdev) == TTY_MAJOR && minor(st.st_rdev) > 0) { ret = asprintf(&vt, "/dev/tty%d", minor(st.st_rdev)); if (ret < 0) return -ENOMEM; @@ -820,11 +794,9 @@ static int seat_find_vt(const char *seat, char **out) fd = open(def_vt, O_NONBLOCK | O_NOCTTY | O_CLOEXEC); if (fd < 0) { err1 = errno; - fd = open("/dev/tty1", - O_NONBLOCK | O_NOCTTY | O_CLOEXEC); + fd = open("/dev/tty1", O_NONBLOCK | O_NOCTTY | O_CLOEXEC); if (fd < 0) { - log_error("cannot find parent tty (%d, %d): %m", - err1, errno); + log_error("cannot find parent tty (%d, %d): %m", err1, errno); return -EFAULT; } } @@ -850,14 +822,9 @@ static int seat_find_vt(const char *seat, char **out) } SHL_EXPORT -int uterm_vt_allocate(struct uterm_vt_master *vtm, - struct uterm_vt **out, - unsigned int allowed_types, - const char *seat, - struct uterm_input *input, - const char *vt_name, - uterm_vt_cb cb, - void *data) +int uterm_vt_allocate(struct uterm_vt_master *vtm, struct uterm_vt **out, + unsigned int allowed_types, const char *seat, struct uterm_input *input, + const char *vt_name, uterm_vt_cb cb, void *data) { struct uterm_vt *vt; int ret; @@ -1046,8 +1013,7 @@ unsigned int uterm_vt_get_num(struct uterm_vt *vt) } SHL_EXPORT -int uterm_vt_master_new(struct uterm_vt_master **out, - struct ev_eloop *eloop) +int uterm_vt_master_new(struct uterm_vt_master **out, struct ev_eloop *eloop) { struct uterm_vt_master *vtm; @@ -1087,9 +1053,7 @@ void uterm_vt_master_unref(struct uterm_vt_master *vtm) return; while (vtm->vts.next != &vtm->vts) { - vt = shl_dlist_entry(vtm->vts.next, - struct uterm_vt, - list); + vt = shl_dlist_entry(vtm->vts.next, struct uterm_vt, list); uterm_vt_deallocate(vt); } @@ -1111,7 +1075,8 @@ int uterm_vt_master_activate_all(struct uterm_vt_master *vtm) if (!vtm) return -EINVAL; - shl_dlist_for_each(iter, &vtm->vts) { + shl_dlist_for_each(iter, &vtm->vts) + { vt = shl_dlist_entry(iter, struct uterm_vt, list); ret = uterm_vt_activate(vt); if (ret == -EINPROGRESS) @@ -1140,7 +1105,8 @@ int uterm_vt_master_deactivate_all(struct uterm_vt_master *vtm) if (!vtm) return -EINVAL; - shl_dlist_for_each(iter, &vtm->vts) { + shl_dlist_for_each(iter, &vtm->vts) + { vt = shl_dlist_entry(iter, struct uterm_vt, list); ret = uterm_vt_deactivate(vt); if (ret == -EINPROGRESS) diff --git a/src/uterm_vt.h b/src/uterm_vt.h index 9418bb73..c73fd1dc 100644 --- a/src/uterm_vt.h +++ b/src/uterm_vt.h @@ -62,21 +62,18 @@ enum uterm_vt_type { UTERM_VT_FAKE = 0x02, }; -typedef int (*uterm_vt_cb) (struct uterm_vt *vt, struct uterm_vt_event *ev, - void *data); +typedef int (*uterm_vt_cb)(struct uterm_vt *vt, struct uterm_vt_event *ev, void *data); -int uterm_vt_master_new(struct uterm_vt_master **out, - struct ev_eloop *eloop); +int uterm_vt_master_new(struct uterm_vt_master **out, struct ev_eloop *eloop); void uterm_vt_master_ref(struct uterm_vt_master *vtm); void uterm_vt_master_unref(struct uterm_vt_master *vtm); int uterm_vt_master_activate_all(struct uterm_vt_master *vtm); int uterm_vt_master_deactivate_all(struct uterm_vt_master *vtm); -int uterm_vt_allocate(struct uterm_vt_master *vt, struct uterm_vt **out, - unsigned int allowed_types, - const char *seat, struct uterm_input *input, - const char *vt_name, uterm_vt_cb cb, void *data); +int uterm_vt_allocate(struct uterm_vt_master *vt, struct uterm_vt **out, unsigned int allowed_types, + const char *seat, struct uterm_input *input, const char *vt_name, + uterm_vt_cb cb, void *data); void uterm_vt_deallocate(struct uterm_vt *vt); void uterm_vt_ref(struct uterm_vt *vt); void uterm_vt_unref(struct uterm_vt *vt); diff --git a/tests/test_common.h b/tests/test_common.h index 34338fc6..33e43946 100644 --- a/tests/test_common.h +++ b/tests/test_common.h @@ -45,22 +45,22 @@ #include /* lower address-space is protected from user-allocation, so this is invalid */ -#define TEST_INVALID_PTR ((void*)0x10) +#define TEST_INVALID_PTR ((void *)0x10) #define UNUSED(x) (void)(x) -#define TEST_DEFINE_CASE(_name) \ - static TCase *test_create_case_##_name(void) \ - { \ - TCase *tc; \ - \ - tc = tcase_create(#_name); \ +#define TEST_DEFINE_CASE(_name) \ + static TCase *test_create_case_##_name(void) \ + { \ + TCase *tc; \ + \ + tc = tcase_create(#_name); #define TEST(_name) tcase_add_test(tc, _name); -#define TEST_END_CASE \ - return tc; \ - } \ +#define TEST_END_CASE \ + return tc; \ + } #define TEST_END NULL @@ -75,7 +75,7 @@ static inline Suite *test_create_suite(const char *name, ...) s = suite_create(name); va_start(list, name); - while ((fn = va_arg(list, TCase *(*)(void)))) + while ((fn = va_arg(list, TCase * (*)(void)))) suite_add_tcase(s, fn()); va_end(list); @@ -97,26 +97,20 @@ static inline int test_run_suite(Suite *s) return ret; } -#define TEST_DEFINE(_suite) \ - int main(int argc, char **argv) \ - { \ - return test_run_suite(_suite); \ +#define TEST_DEFINE(_suite) \ + int main(int argc, char **argv) \ + { \ + return test_run_suite(_suite); \ } #ifndef ck_assert_mem_eq #include -#define ck_assert_mem_eq(_x, _y, _len) \ - ck_assert(memcmp((_x), (_y), (_len)) == 0) -#define ck_assert_mem_ne(_x, _y, _len) \ - ck_assert(memcmp((_x), (_y), (_len)) != 0) -#define ck_assert_mem_lt(_x, _y, _len) \ - ck_assert(memcmp((_x), (_y), (_len)) < 0) -#define ck_assert_mem_le(_x, _y, _len) \ - ck_assert(memcmp((_x), (_y), (_len)) <= 0) -#define ck_assert_mem_gt(_x, _y, _len) \ - ck_assert(memcmp((_x), (_y), (_len)) > 0) -#define ck_assert_mem_ge(_x, _y, _len) \ - ck_assert(memcmp((_x), (_y), (_len)) >= 0) +#define ck_assert_mem_eq(_x, _y, _len) ck_assert(memcmp((_x), (_y), (_len)) == 0) +#define ck_assert_mem_ne(_x, _y, _len) ck_assert(memcmp((_x), (_y), (_len)) != 0) +#define ck_assert_mem_lt(_x, _y, _len) ck_assert(memcmp((_x), (_y), (_len)) < 0) +#define ck_assert_mem_le(_x, _y, _len) ck_assert(memcmp((_x), (_y), (_len)) <= 0) +#define ck_assert_mem_gt(_x, _y, _len) ck_assert(memcmp((_x), (_y), (_len)) > 0) +#define ck_assert_mem_ge(_x, _y, _len) ck_assert(memcmp((_x), (_y), (_len)) >= 0) #endif #endif /* TEST_COMMON_H */ diff --git a/tests/test_include.h b/tests/test_include.h index afbaefba..a3aa5fa1 100644 --- a/tests/test_include.h +++ b/tests/test_include.h @@ -33,10 +33,10 @@ #include "eloop.h" #include "shl_log.h" -#define TEST_HELP \ - "\t-h, --help [off] Print this help and exit\n" \ - "\t-v, --verbose [off] Print verbose messages\n" \ - "\t --debug [off] Enable debug mode\n" \ +#define TEST_HELP \ + "\t-h, --help [off] Print this help and exit\n" \ + "\t-v, --verbose [off] Print verbose messages\n" \ + "\t --debug [off] Enable debug mode\n" \ "\t --silent [off] Suppress notices and warnings\n" static struct { @@ -49,8 +49,7 @@ static struct { static struct conf_ctx *test_ctx; -static int aftercheck_debug(struct conf_option *opt, int argc, char **argv, - int idx) +static int aftercheck_debug(struct conf_option *opt, int argc, char **argv, int idx) { /* --debug implies --verbose */ if (test_conf.debug) @@ -59,8 +58,7 @@ static int aftercheck_debug(struct conf_option *opt, int argc, char **argv, return 0; } -static int aftercheck_help(struct conf_option *opt, int argc, char **argv, - int idx) +static int aftercheck_help(struct conf_option *opt, int argc, char **argv, int idx) { /* exit after printing --help information */ if (test_conf.help) { @@ -71,14 +69,14 @@ static int aftercheck_help(struct conf_option *opt, int argc, char **argv, return 0; } -#define TEST_OPTIONS \ - CONF_OPTION_BOOL_FULL('h', "help", aftercheck_help, NULL, NULL, &test_conf.help, false), \ - CONF_OPTION_BOOL('v', "verbose", &test_conf.verbose, false), \ - CONF_OPTION_BOOL_FULL(0, "debug", aftercheck_debug, NULL, NULL, &test_conf.debug, false), \ - CONF_OPTION_BOOL(0, "silent", &test_conf.silent, false) +#define TEST_OPTIONS \ + CONF_OPTION_BOOL_FULL('h', "help", aftercheck_help, NULL, NULL, &test_conf.help, false), \ + CONF_OPTION_BOOL('v', "verbose", &test_conf.verbose, false), \ + CONF_OPTION_BOOL_FULL(0, "debug", aftercheck_debug, NULL, NULL, &test_conf.debug, \ + false), \ + CONF_OPTION_BOOL(0, "silent", &test_conf.silent, false) -static void sig_generic(struct ev_eloop *p, struct signalfd_siginfo *info, - void *data) +static void sig_generic(struct ev_eloop *p, struct signalfd_siginfo *info, void *data) { struct ev_eloop *eloop = data; @@ -86,8 +84,8 @@ static void sig_generic(struct ev_eloop *p, struct signalfd_siginfo *info, log_info("terminating due to caught signal %d", info->ssi_signo); } -static int test_prepare(struct conf_option *opts, size_t len, - int argc, char **argv, struct ev_eloop **out) +static int test_prepare(struct conf_option *opts, size_t len, int argc, char **argv, + struct ev_eloop **out) { int ret; struct ev_eloop *eloop; @@ -108,8 +106,7 @@ static int test_prepare(struct conf_option *opts, size_t len, if (!test_conf.debug && !test_conf.verbose && test_conf.silent) log_set_config(&LOG_CONFIG_WARNING(0, 0, 0, 0)); else - log_set_config(&LOG_CONFIG_INFO(test_conf.debug, - test_conf.verbose)); + log_set_config(&LOG_CONFIG_INFO(test_conf.debug, test_conf.verbose)); log_print_init(argv[0]); @@ -123,8 +120,7 @@ static int test_prepare(struct conf_option *opts, size_t len, ret = ev_eloop_register_signal_cb(eloop, SIGINT, sig_generic, eloop); if (ret) { - ev_eloop_unregister_signal_cb(eloop, SIGTERM, - sig_generic, eloop); + ev_eloop_unregister_signal_cb(eloop, SIGTERM, sig_generic, eloop); goto err_unref; } @@ -144,8 +140,7 @@ static void test_fail(int ret) log_err("init failed, errno %d: %s", ret, strerror(-ret)); } -static void test_exit(struct conf_option *opts, size_t len, - struct ev_eloop *eloop) +static void test_exit(struct conf_option *opts, size_t len, struct ev_eloop *eloop) { ev_eloop_unregister_signal_cb(eloop, SIGINT, sig_generic, eloop); ev_eloop_unregister_signal_cb(eloop, SIGTERM, sig_generic, eloop); diff --git a/tests/test_input.c b/tests/test_input.c index ae1f1069..c06304bc 100644 --- a/tests/test_input.c +++ b/tests/test_input.c @@ -39,9 +39,9 @@ static void print_help(); #include #include "eloop.h" #include "shl_log.h" +#include "test_include.h" #include "uterm_input.h" #include "uterm_monitor.h" -#include "test_include.h" static struct ev_eloop *eloop; static struct uterm_input *input; @@ -57,9 +57,7 @@ struct { } input_conf; /* Pressing Ctrl-\ should toggle the capturing. */ -static void sig_quit(struct ev_eloop *p, - struct signalfd_siginfo *info, - void *data) +static void sig_quit(struct ev_eloop *p, struct signalfd_siginfo *info, void *data) { if (!input) return; @@ -88,9 +86,7 @@ static void print_modifiers(unsigned int mods) printf("\n"); } -static void input_arrived(struct uterm_input *input, - struct uterm_input_key_event *ev, - void *data) +static void input_arrived(struct uterm_input *input, struct uterm_input_key_event *ev, void *data) { char s[32]; @@ -106,9 +102,7 @@ static void input_arrived(struct uterm_input *input, print_modifiers(ev->mods); } -static void monitor_event(struct uterm_monitor *mon, - struct uterm_monitor_event *ev, - void *data) +static void monitor_event(struct uterm_monitor *mon, struct uterm_monitor_event *ev, void *data) { int ret; char *keymap, *compose_file; @@ -120,32 +114,26 @@ static void monitor_event(struct uterm_monitor *mon, keymap = NULL; if (input_conf.xkb_keymap && *input_conf.xkb_keymap) { - ret = shl_read_file(input_conf.xkb_keymap, &keymap, - NULL); + ret = shl_read_file(input_conf.xkb_keymap, &keymap, NULL); if (ret) - log_error("cannot read keymap file %s: %d", - input_conf.xkb_keymap, ret); + log_error("cannot read keymap file %s: %d", input_conf.xkb_keymap, + ret); } compose_file = NULL; compose_file_len = 0; - if (input_conf.xkb_compose_file && - *input_conf.xkb_compose_file) { - ret = shl_read_file(input_conf.xkb_compose_file, - &compose_file, &compose_file_len); + if (input_conf.xkb_compose_file && *input_conf.xkb_compose_file) { + ret = shl_read_file(input_conf.xkb_compose_file, &compose_file, + &compose_file_len); if (ret) log_error("cannot read compose file %s: %d", input_conf.xkb_compose_file, ret); } - ret = uterm_input_new(&input, eloop, - input_conf.xkb_model, - input_conf.xkb_layout, - input_conf.xkb_variant, - input_conf.xkb_options, - input_conf.locale, - keymap, compose_file, compose_file_len, - 0, 0, log_llog, NULL); + ret = uterm_input_new(&input, eloop, input_conf.xkb_model, input_conf.xkb_layout, + input_conf.xkb_variant, input_conf.xkb_options, + input_conf.locale, keymap, compose_file, compose_file_len, 0, + 0, log_llog, NULL); if (ret) return; ret = uterm_input_register_key_cb(input, input_arrived, NULL); @@ -185,9 +173,7 @@ static void print_help() "You can prefix boolean options with \"no-\" to negate it. If an argument is\n" "given multiple times, only the last argument matters if not otherwise stated.\n" "\n" - "General Options:\n" - TEST_HELP - "\n" + "General Options:\n" TEST_HELP "\n" "Input Device Options:\n" "\t --xkb-model [-] Set XkbModel for input devices\n" "\t --xkb-layout [-] Set XkbLayout for input devices\n" diff --git a/tests/test_key.c b/tests/test_key.c index f5e2446b..ab348731 100644 --- a/tests/test_key.c +++ b/tests/test_key.c @@ -37,17 +37,16 @@ int main() bool reset = false; fprintf(stderr, "Quit with 'q' (maybe followed by 'enter'/'return')\r\n"); - fprintf(stderr, "Maybe your terminal may be unusable after this, use 'reset' to fix it\r\n"); + fprintf(stderr, + "Maybe your terminal may be unusable after this, use 'reset' to fix it\r\n"); if (tcgetattr(0, &omode) < 0) { - fprintf(stderr, "cannot retrieve terminal attributes (%d): %m\r\n", - errno); + fprintf(stderr, "cannot retrieve terminal attributes (%d): %m\r\n", errno); } else { memcpy(&nmode, &omode, sizeof(nmode)); cfmakeraw(&nmode); if (tcsetattr(0, TCSANOW, &nmode) < 0) - fprintf(stderr, "cannot set terminal attributes (%d): %m\r\n", - errno); + fprintf(stderr, "cannot set terminal attributes (%d): %m\r\n", errno); else reset = true; } @@ -55,24 +54,21 @@ int main() while (1) { res = fread(&buf, 1, 1, stdin); if (res != 1) { - fprintf(stderr, "error on stdin: %d %d: %m\r\n", - res, errno); + fprintf(stderr, "error on stdin: %d %d: %m\r\n", res, errno); break; } if (buf == '\n') fprintf(stderr, "key: \r\n"); else - fprintf(stderr, "key: %x %u %o '%c'\r\n", - (int)buf, buf, buf, buf); + fprintf(stderr, "key: %x %u %o '%c'\r\n", (int)buf, buf, buf, buf); if (buf == 'q') break; } if (reset && tcsetattr(0, TCSANOW, &omode) < 0) - fprintf(stderr, "cannot reset terminal attributes (%d): %m\r\n", - errno); + fprintf(stderr, "cannot reset terminal attributes (%d): %m\r\n", errno); return 0; } diff --git a/tests/test_output.c b/tests/test_output.c index a9d6c7ff..0d3912b6 100644 --- a/tests/test_output.c +++ b/tests/test_output.c @@ -48,8 +48,8 @@ static void print_help(); #include "eloop.h" #include "shl_log.h" -#include "uterm_video.h" #include "test_include.h" +#include "uterm_video.h" /* eloop object */ static struct ev_eloop *eloop; @@ -66,13 +66,12 @@ static int blit_outputs(struct uterm_video *video) { struct uterm_display *iter; int j, ret; - struct uterm_mode *mode; j = 0; iter = uterm_video_get_displays(video); - for ( ; iter; iter = uterm_display_next(iter)) { + for (; iter; iter = uterm_display_next(iter)) { log_notice("Activating display %d %p...", j, iter); - ret = uterm_display_activate(iter, NULL); + ret = uterm_display_activate(iter); if (ret) log_err("Cannot activate display %d: %d", j, ret); else @@ -86,14 +85,13 @@ static int blit_outputs(struct uterm_video *video) } iter = uterm_video_get_displays(video); - for ( ; iter; iter = uterm_display_next(iter)) { + for (; iter; iter = uterm_display_next(iter)) { if (uterm_display_get_state(iter) != UTERM_DISPLAY_ACTIVE) continue; - mode = uterm_display_get_current(iter); ret = uterm_display_fill(iter, 0xff, 0xff, 0xff, 0, 0, - uterm_mode_get_width(mode), - uterm_mode_get_height(mode)); + uterm_display_get_width(iter), + uterm_display_get_height(iter)); if (ret) { log_err("cannot fill framebuffer"); continue; @@ -118,26 +116,15 @@ static int blit_outputs(struct uterm_video *video) static int list_outputs(struct uterm_video *video) { struct uterm_display *iter; - struct uterm_mode *cur, *mode; int i; log_notice("List of Outputs:"); i = 0; iter = uterm_video_get_displays(video); - for ( ; iter; iter = uterm_display_next(iter)) { - cur = uterm_display_get_current(iter); - + for (; iter; iter = uterm_display_next(iter)) { log_notice("Output %d:", i++); log_notice(" active: %d", uterm_display_get_state(iter)); - log_notice(" has current: %s", cur ? "yes" : "no"); - - mode = uterm_display_get_modes(iter); - for ( ; mode; mode = uterm_mode_next(mode)) { - log_notice(" Mode '%s':", uterm_mode_get_name(mode)); - log_notice(" x: %u", uterm_mode_get_width(mode)); - log_notice(" y: %u", uterm_mode_get_height(mode)); - } } log_notice("End of Output list"); @@ -166,12 +153,11 @@ static void print_help() "You can prefix boolean options with \"no-\" to negate it. If an argument is\n" "given multiple times, only the last argument matters if not otherwise stated.\n" "\n" - "General Options:\n" - TEST_HELP - "\n" + "General Options:\n" TEST_HELP "\n" "Video Options:\n" "\t --fbdev [off] Use fbdev instead of DRM\n" - "\t --test [off] Try displaying content instead of listing devices\n" + "\t --test [off] Try displaying content instead of listing " + "devices\n" "\t --dev [/dev/dri/card0 | /dev/fb0] Use the given device\n", "test_input"); /* @@ -188,7 +174,7 @@ struct conf_option options[] = { TEST_OPTIONS, CONF_OPTION_BOOL(0, "fbdev", &output_conf.fbdev, false), CONF_OPTION_BOOL(0, "test", &output_conf.test, false), - CONF_OPTION_STRING(0, "dev", &output_conf.dev, NULL), + CONF_OPTION_STRING(0, "dev", &output_conf.dev, NULL), CONF_OPTION_UINT(0, "desired-width", &output_conf.desired_width, 0), CONF_OPTION_UINT(0, "desired-height", &output_conf.desired_height, 0), }; @@ -219,16 +205,14 @@ int main(int argc, char **argv) log_notice("Creating video object using %s...", node); - ret = uterm_video_new(&video, eloop, node, mode, - output_conf.desired_width, - output_conf.desired_height); + ret = uterm_video_new(&video, eloop, node, mode, output_conf.desired_width, + output_conf.desired_height, false); if (ret) { if (!output_conf.fbdev) { log_notice("cannot create drm device; trying drm2d mode"); - ret = uterm_video_new(&video, eloop, node, - "drm2d", - output_conf.desired_width, - output_conf.desired_height); + ret = uterm_video_new(&video, eloop, node, "drm2d", + output_conf.desired_width, output_conf.desired_height, + false); if (ret) goto err_exit; } else { diff --git a/tests/test_shl.c b/tests/test_shl.c index b287e917..5541b432 100644 --- a/tests/test_shl.c +++ b/tests/test_shl.c @@ -23,21 +23,21 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "test_common.h" #include "shl_misc.h" +#include "test_common.h" -#define check_assert_string_list_eq(X, Y) \ - do { \ - unsigned int i; \ - const char **x, **y; \ - \ - x = (X); \ - y = (Y); \ - \ - for (i = 0; x[i] && y[i]; ++i) \ - ck_assert_str_eq(x[i], y[i]); \ - ck_assert_ptr_eq(x[i], NULL); \ - ck_assert_ptr_eq(y[i], NULL); \ +#define check_assert_string_list_eq(X, Y) \ + do { \ + unsigned int i; \ + const char **x, **y; \ + \ + x = (X); \ + y = (Y); \ + \ + for (i = 0; x[i] && y[i]; ++i) \ + ck_assert_str_eq(x[i], y[i]); \ + ck_assert_ptr_eq(x[i], NULL); \ + ck_assert_ptr_eq(y[i], NULL); \ } while (0) START_TEST(test_split_command_string) @@ -47,9 +47,7 @@ START_TEST(test_split_command_string) char **list; const char *invalid_command_strings[] = { - "\"", "'", "\\", - "\"/bin/true", "'/bin/true", "/bin/true\\", - "ls -h \"*.c'", + "\"", "'", "\\", "\"/bin/true", "'/bin/true", "/bin/true\\", "ls -h \"*.c'", }; n = sizeof(invalid_command_strings) / sizeof(invalid_command_strings[0]); @@ -57,29 +55,30 @@ START_TEST(test_split_command_string) list = TEST_INVALID_PTR; n_list = -10; - ret = shl_split_command_string(invalid_command_strings[i], - &list, &n_list); + ret = shl_split_command_string(invalid_command_strings[i], &list, &n_list); ck_assert_int_eq(ret, -EINVAL); ck_assert_ptr_eq(list, TEST_INVALID_PTR); ck_assert_uint_eq(n_list, (unsigned int)-10); } - const char *expected_command_list[] = { - "'/bin/command with space", - "\t\\argument=\"quoted\"", - "plain\3argument", - " an\tother='ere", - "\"ends with \\", - "\\\"more\\bquotes\\", - NULL - }; - n_expected = sizeof(expected_command_list) / - sizeof(expected_command_list[0]) - 1; + const char *expected_command_list[] = {"'/bin/command with space", + "\t\\argument=\"quoted\"", + "plain\3argument", + " an\tother='ere", + "\"ends with \\", + "\\\"more\\bquotes\\", + NULL}; + n_expected = sizeof(expected_command_list) / sizeof(expected_command_list[0]) - 1; const char *valid_command_strings[] = { - "\\'/bin/command\\ with\\ space \\\t\\\\argument=\\\"quoted\\\" plain\3argument \\ an\\\tother=\\'ere \\\"ends\\ with\\ \\\\ \\\\\\\"more\\\\bquotes\\\\", - "\"'/bin/command with space\" \"\t\\argument=\\\"quoted\\\"\" \"plain\3argument\" \" an\tother='ere\" \"\\\"ends with \\\\\" \"\\\\\\\"more\\bquotes\\\\\"", - "\"'\"'/bin/command with space' '\t\\argument=\"quoted\"' 'plain\3argument' ' an\tother='\"'\"'ere' '\"ends with \\' '\\\"more\\bquotes\\'", - " \\'/bin/command\\ with\\ space\t\t\\\t\\\\argument=\\\"quoted\\\"\t plain\3argument \t\\ an\\\tother=\\'ere \\\"ends\\ with\\ \\\\ \t \\\\\\\"more\\\\\\bquotes\\\\ \t \t", + "\\'/bin/command\\ with\\ space \\\t\\\\argument=\\\"quoted\\\" plain\3argument \\ " + "an\\\tother=\\'ere \\\"ends\\ with\\ \\\\ \\\\\\\"more\\\\bquotes\\\\", + "\"'/bin/command with space\" \"\t\\argument=\\\"quoted\\\"\" \"plain\3argument\" " + "\" an\tother='ere\" \"\\\"ends with \\\\\" \"\\\\\\\"more\\bquotes\\\\\"", + "\"'\"'/bin/command with space' '\t\\argument=\"quoted\"' 'plain\3argument' ' " + "an\tother='\"'\"'ere' '\"ends with \\' '\\\"more\\bquotes\\'", + " \\'/bin/command\\ with\\ space\t\t\\\t\\\\argument=\\\"quoted\\\"\t " + "plain\3argument \t\\ an\\\tother=\\'ere \\\"ends\\ with\\ \\\\ \t " + "\\\\\\\"more\\\\\\bquotes\\\\ \t \t", }; n = sizeof(valid_command_strings) / sizeof(valid_command_strings[0]); @@ -87,11 +86,10 @@ START_TEST(test_split_command_string) list = TEST_INVALID_PTR; n_list = -10; - ret = shl_split_command_string(valid_command_strings[i], &list, - &n_list); + ret = shl_split_command_string(valid_command_strings[i], &list, &n_list); ck_assert_int_eq(ret, 0); ck_assert_ptr_ne(list, TEST_INVALID_PTR); - check_assert_string_list_eq((const char**)list, expected_command_list); + check_assert_string_list_eq((const char **)list, expected_command_list); ck_assert_uint_eq(n_list, n_expected); } @@ -106,8 +104,7 @@ START_TEST(test_split_command_string) list = TEST_INVALID_PTR; n_list = -10; - ret = shl_split_command_string(empty_command_strings[i], &list, - &n_list); + ret = shl_split_command_string(empty_command_strings[i], &list, &n_list); ck_assert_int_eq(ret, 0); ck_assert_ptr_ne(list, TEST_INVALID_PTR); ck_assert_ptr_eq(list[0], NULL); @@ -118,29 +115,26 @@ START_TEST(test_split_command_string) list = TEST_INVALID_PTR; n_list = -10; - ret = shl_split_command_string(valid_command_strings[0], &list, - &n_list); + ret = shl_split_command_string(valid_command_strings[0], &list, &n_list); ck_assert_int_eq(ret, 0); ck_assert_ptr_ne(list, TEST_INVALID_PTR); - check_assert_string_list_eq((const char**)list, expected_command_list); + check_assert_string_list_eq((const char **)list, expected_command_list); ck_assert_uint_eq(n_list, n_expected); } { list = TEST_INVALID_PTR; - ret = shl_split_command_string(valid_command_strings[0], &list, - NULL); + ret = shl_split_command_string(valid_command_strings[0], &list, NULL); ck_assert_int_eq(ret, 0); ck_assert_ptr_ne(list, TEST_INVALID_PTR); - check_assert_string_list_eq((const char**)list, expected_command_list); + check_assert_string_list_eq((const char **)list, expected_command_list); } { n_list = -10; - ret = shl_split_command_string(valid_command_strings[0], NULL, - &n_list); + ret = shl_split_command_string(valid_command_strings[0], NULL, &n_list); ck_assert_int_eq(ret, -EINVAL); ck_assert_uint_eq(n_list, (unsigned int)-10); } @@ -166,12 +160,7 @@ START_TEST(test_split_command_string) END_TEST TEST_DEFINE_CASE(misc) - TEST(test_split_command_string) +TEST(test_split_command_string) TEST_END_CASE -TEST_DEFINE( - TEST_SUITE(shl, - TEST_CASE(misc), - TEST_END - ) -) +TEST_DEFINE(TEST_SUITE(shl, TEST_CASE(misc), TEST_END)) diff --git a/tests/test_vt.c b/tests/test_vt.c index 2d3fbd92..4be24872 100644 --- a/tests/test_vt.c +++ b/tests/test_vt.c @@ -44,9 +44,9 @@ static void print_help(); #include #include "eloop.h" #include "shl_log.h" +#include "test_include.h" #include "uterm_input.h" #include "uterm_vt.h" -#include "test_include.h" static void print_help() { @@ -69,9 +69,7 @@ static void print_help() "You can prefix boolean options with \"no-\" to negate it. If an argument is\n" "given multiple times, only the last argument matters if not otherwise stated.\n" "\n" - "General Options:\n" - TEST_HELP - "\n" + "General Options:\n" TEST_HELP "\n" "VT Options:\n" "\t --vt [-] Path to VT to use\n" "\t-s, --switchvt [off] Switch automatically to the new VT\n", @@ -113,13 +111,12 @@ int main(int argc, char **argv) if (ret) goto err_exit; - ret = uterm_input_new(&input, eloop, "", "", "", "", "C", "", "", 0, 0, - 0, log_llog, NULL); + ret = uterm_input_new(&input, eloop, "", "", "", "", "C", "", "", 0, 0, 0, log_llog, NULL); if (ret) goto err_vtm; - ret = uterm_vt_allocate(vtm, &vt, UTERM_VT_FAKE | UTERM_VT_REAL, - "seat0", input, vtpath, NULL, NULL); + ret = uterm_vt_allocate(vtm, &vt, UTERM_VT_FAKE | UTERM_VT_REAL, "seat0", input, vtpath, + NULL, NULL); if (ret) goto err_input; diff --git a/tools/extract_release_note.py b/tools/extract_release_note.py deleted file mode 100755 index 3a06eafe..00000000 --- a/tools/extract_release_note.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-FileCopyrightText: 2022 Aetf -# -# SPDX-License-Identifier: MIT -import re -import inspect - -PTN_RELEASE_NOTE = re.compile(r'^CHANGES WITH.+$([\s\S]+?)^CHANGES WITH.+$', re.MULTILINE) - - -def extract(src: str) -> str: - """Find section between the first and the next 'CHANGES WITH xx:' lines, - and strip common prefix whitespace - """ - m = PTN_RELEASE_NOTE.search(src) - if m is not None: - return inspect.cleandoc(m.group(1)) + '\n' - else: - return '' - - -def main(): - import argparse - import sys - - parser = argparse.ArgumentParser() - parser.add_argument( - 'src', - type=argparse.FileType('r'), - nargs='?', - help='input NEWS', - default=sys.stdin, - ) - parser.add_argument( - 'dest', - type=argparse.FileType('w'), - nargs='?', - help='output', - default=sys.stdout, - ) - args = parser.parse_args() - - args.dest.write(extract(args.src.read())) - - -if __name__ == '__main__': - main()