Index: head/usr.bin/Makefile =================================================================== --- head/usr.bin/Makefile (revision 366369) +++ head/usr.bin/Makefile (revision 366370) @@ -1,299 +1,300 @@ # From: @(#)Makefile 8.3 (Berkeley) 1/7/94 # $FreeBSD$ .include SUBDIR= alias \ apply \ asa \ awk \ + backlight \ banner \ basename \ brandelf \ bsdcat \ bsdiff \ bzip2 \ bzip2recover \ cap_mkdb \ chat \ chpass \ cksum \ cmp \ col \ colrm \ column \ comm \ compress \ cpuset \ csplit \ ctlstat \ cut \ diff \ dirname \ du \ elfctl \ elfdump \ enigma \ env \ etdump \ expand \ false \ fetch \ find \ fmt \ fold \ fstat \ fsync \ gcore \ gencat \ getaddrinfo \ getconf \ getent \ getopt \ grep \ gzip \ head \ hexdump \ id \ ident \ ipcrm \ ipcs \ join \ jot \ keylogin \ keylogout \ killall \ ktrace \ ktrdump \ lam \ lastcomm \ ldd \ leave \ less \ lessecho \ lesskey \ limits \ locale \ localedef \ lock \ lockf \ logger \ login \ logins \ logname \ look \ lorder \ lsvfs \ lzmainfo \ m4 \ mandoc \ mesg \ minigzip \ ministat \ mkdep \ mkfifo \ mkimg \ mktemp \ mkuzip \ mt \ ncal \ netstat \ newgrp \ nfsstat \ nice \ nl \ nohup \ opieinfo \ opiekey \ opiepasswd \ pagesize \ passwd \ paste \ patch \ pathchk \ perror \ posixshmcontrol \ pr \ printenv \ printf \ proccontrol \ procstat \ protect \ rctl \ renice \ resizewin \ rev \ revoke \ rpcinfo \ rs \ rup \ ruptime \ rusers \ rwall \ rwho \ script \ sdiff \ sed \ seq \ shar \ showmount \ sockstat \ soelim \ sort \ split \ stat \ stdbuf \ strings \ su \ systat \ tabs \ tail \ tar \ tcopy \ tee \ time \ timeout \ tip \ top \ touch \ tput \ tr \ true \ truncate \ tset \ tsort \ tty \ uname \ unexpand \ uniq \ unzip \ units \ unvis \ uudecode \ uuencode \ vis \ vmstat \ w \ wall \ wc \ what \ whereis \ which \ whois \ write \ xargs \ xinstall \ xo \ xz \ xzdec \ yes \ zstd # NB: keep these sorted by MK_* knobs SUBDIR.${MK_AT}+= at SUBDIR.${MK_ATM}+= atm SUBDIR.${MK_BLUETOOTH}+= bluetooth SUBDIR.${MK_BSD_CPIO}+= cpio SUBDIR.${MK_CALENDAR}+= calendar SUBDIR.${MK_CLANG}+= clang SUBDIR.${MK_DIALOG}+= dpv SUBDIR.${MK_EE}+= ee SUBDIR.${MK_FILE}+= file SUBDIR.${MK_FINGER}+= finger SUBDIR.${MK_FTP}+= ftp SUBDIR.${MK_GAMES}+= caesar SUBDIR.${MK_GAMES}+= factor SUBDIR.${MK_GAMES}+= fortune SUBDIR.${MK_GAMES}+= grdc SUBDIR.${MK_GAMES}+= morse SUBDIR.${MK_GAMES}+= number SUBDIR.${MK_GAMES}+= pom SUBDIR.${MK_GAMES}+= primes SUBDIR.${MK_GAMES}+= random .if ${COMPILER_FEATURES:Mc++11} SUBDIR+= dtc .endif .if ${MK_GH_BC} == "yes" SUBDIR+= gh-bc .else SUBDIR.${MK_OPENSSL}+= bc SUBDIR.${MK_OPENSSL}+= dc .endif SUBDIR.${MK_HESIOD}+= hesinfo SUBDIR.${MK_ICONV}+= iconv SUBDIR.${MK_ICONV}+= mkcsmapper SUBDIR.${MK_ICONV}+= mkesdb SUBDIR.${MK_ISCSI}+= iscsictl SUBDIR.${MK_KDUMP}+= kdump SUBDIR.${MK_KDUMP}+= truss SUBDIR.${MK_KERBEROS_SUPPORT}+= compile_et SUBDIR.${MK_LDNS_UTILS}+= drill SUBDIR.${MK_LDNS_UTILS}+= host SUBDIR.${MK_LIB32}+= ldd32 SUBDIR.${MK_LOCATE}+= locate # XXX msgs? SUBDIR.${MK_MAIL}+= biff SUBDIR.${MK_MAIL}+= from SUBDIR.${MK_MAIL}+= mail SUBDIR.${MK_MAIL}+= msgs SUBDIR.${MK_MAKE}+= bmake SUBDIR.${MK_MAN_UTILS}+= man SUBDIR.${MK_NETCAT}+= nc SUBDIR.${MK_NIS}+= ypcat SUBDIR.${MK_NIS}+= ypmatch SUBDIR.${MK_NIS}+= ypwhich SUBDIR.${MK_OPENSSH}+= ssh-copy-id SUBDIR.${MK_OPENSSL}+= chkey SUBDIR.${MK_OPENSSL}+= newkey SUBDIR.${MK_QUOTAS}+= quota SUBDIR.${MK_SENDMAIL}+= vacation SUBDIR.${MK_TALK}+= talk SUBDIR.${MK_TELNET}+= telnet SUBDIR.${MK_TESTS_SUPPORT}.${MK_CXX}+= kyua SUBDIR.${MK_TESTS}+= tests SUBDIR.${MK_TEXTPROC}+= ul SUBDIR.${MK_TFTP}+= tftp SUBDIR.${MK_TOOLCHAIN}+= addr2line SUBDIR.${MK_TOOLCHAIN}+= ar SUBDIR.${MK_TOOLCHAIN}+= c89 SUBDIR.${MK_TOOLCHAIN}+= c99 SUBDIR.${MK_TOOLCHAIN}+= ctags SUBDIR.${MK_TOOLCHAIN}+= cxxfilt SUBDIR.${MK_TOOLCHAIN}+= objcopy SUBDIR.${MK_TOOLCHAIN}+= file2c SUBDIR.${MK_TOOLCHAIN}+= gprof SUBDIR.${MK_TOOLCHAIN}+= indent SUBDIR.${MK_TOOLCHAIN}+= lex SUBDIR.${MK_TOOLCHAIN}+= mkstr SUBDIR.${MK_TOOLCHAIN}+= nm SUBDIR.${MK_TOOLCHAIN}+= readelf SUBDIR.${MK_TOOLCHAIN}+= rpcgen SUBDIR.${MK_TOOLCHAIN}+= unifdef SUBDIR.${MK_TOOLCHAIN}+= size SUBDIR.${MK_TOOLCHAIN}+= xstr SUBDIR.${MK_TOOLCHAIN}+= yacc SUBDIR.${MK_VI}+= vi SUBDIR.${MK_VT}+= vtfontcvt SUBDIR.${MK_USB}+= usbhidaction SUBDIR.${MK_USB}+= usbhidctl SUBDIR.${MK_UTMPX}+= last .if ${MK_CXX} != "no" SUBDIR.${MK_UTMPX}+= users .endif SUBDIR.${MK_UTMPX}+= who SUBDIR.${MK_SVN}+= svn SUBDIR.${MK_SVNLITE}+= svn SUBDIR.${MK_OFED}+= ofed # These are normally only handled for build-tools. .if make(clean*) SUBDIR+= mkcsmapper_static SUBDIR+= mkesdb_static .endif .include SUBDIR_PARALLEL= .include Index: head/usr.bin/backlight/Makefile =================================================================== --- head/usr.bin/backlight/Makefile (nonexistent) +++ head/usr.bin/backlight/Makefile (revision 366370) @@ -0,0 +1,6 @@ +# $FreeBSD$ + +PROG= backlight +MAN= backlight.8 + +.include Property changes on: head/usr.bin/backlight/Makefile ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/usr.bin/backlight/backlight.8 =================================================================== --- head/usr.bin/backlight/backlight.8 (nonexistent) +++ head/usr.bin/backlight/backlight.8 (revision 366370) @@ -0,0 +1,95 @@ +.\" Copyright (c) 2020 Emmanuel Vadot +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd October 02, 2020 +.Dt BACKLIGHT 8 +.Os +.Sh NAME +.Nm backlight +.Nd configure backlight hardware +.Sh SYNOPSIS +.Nm +.Op Fl f Ar device +.Op Fl q +.Op Fl i +.Op Ar value +.Nm +.Op Fl f Ar device +incr | + +.Op Ar value +.Nm +.Op Fl f Ar device +decr | - +.Op Ar value +.Sh DESCRIPTION +The +.Nm +utility can be used to configure brightness levels for registered backlights +.Pp +The options are as follows: +.Bl -tag -width "-f device" +.It Fl f Ar device +Device to operate on. +If not specified, +.Pa /dev/backlight/backlight0 +is used. +If an unqualified name is provided, +.Pa /dev/backlight +is automatically prepended. +.It Fl q +When querying the brightness level only print the value. +.It Fl i +Query information about the backlight (name, type). +.It Ar value +Set the brightness level to this value, must be between 0 and 100. +.It Ar incr | + +.Op Ar value +Decrement the backlight level. +If no value is specified a default of 10 percent is used. +.It Ar decr | - +.Op Ar value +Increment the backlight level. +If no value is specified a default of 10 percent is used. +.El +.Sh EXAMPLES +.Bl -bullet +.It +Show the current brightness level +.Bd -literal +backlight -f /dev/backlight/backlight0 +.Ed +.El +.Sh SEE ALSO +.Xr backlight 9 +.Sh HISTORY +The +.Nm +utility appeared in +.Fx 13.0 . +.Sh AUTHORS +.An -nosplit +The +.Nm +utility and this manual page were written by +.An Emmanuel Vadot Aq Mt manu@FreeBSD.org . Property changes on: head/usr.bin/backlight/backlight.8 ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/usr.bin/backlight/backlight.c =================================================================== --- head/usr.bin/backlight/backlight.c (nonexistent) +++ head/usr.bin/backlight/backlight.c (revision 366370) @@ -0,0 +1,220 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2020 Emmanuel Vadot + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define BACKLIGHT_QUERY 0x0001 +#define BACKLIGHT_SET_BRIGHTNESS 0x0002 +#define BACKLIGHT_INCR 0x0004 +#define BACKLIGHT_DECR 0x0008 +#define BACKLIGHT_INFO 0x0010 + +static char device_name[PATH_MAX] = "/dev/backlight/backlight0"; + +static void +set_device_name(const char *name) +{ + + if (name[0] == '/') + strlcpy(device_name, name, sizeof(device_name)); + else + snprintf(device_name, sizeof(device_name), "/dev/backlight/%s", name); +} + +static void +usage(void) +{ + fprintf(stderr, "Usage:\n"); + fprintf(stderr, "\tbacklight [-f dev]\n"); + fprintf(stderr, "\tbacklight [-f dev] -i\n"); + fprintf(stderr, "\tbacklight [-f dev] \n"); + fprintf(stderr, "\tbacklight [-f dev] incr|+ \n"); + fprintf(stderr, "\tbacklight [-f dev] decr|- \n"); + exit(1); +} + +static const char * +backlight_type_to_string(enum backlight_info_type type) +{ + switch (type) { + case BACKLIGHT_TYPE_PANEL: + return ("Panel"); + case BACKLIGHT_TYPE_KEYBOARD: + return ("Keyboard"); + } + + return ("Unknown"); +} + +int +main(int argc, char *argv[]) +{ + struct backlight_props props; + struct backlight_info info; + int fd; + int action, ch; + cap_rights_t right_ioctl; + const unsigned long backlight_ioctls[] = { + BACKLIGHTGETSTATUS, + BACKLIGHTUPDATESTATUS, + BACKLIGHTGETINFO}; + long percent = 0; + const char *percent_error; + uint32_t i; + bool setname; + bool quiet = false; + + action = BACKLIGHT_QUERY; + setname = false; + fd = -1; + + while ((ch = getopt(argc, argv, "f:qhi")) != -1) { + switch (ch) { + case 'q': + quiet = true; + break; + case 'f': + setname = true; + set_device_name(optarg); + break; + case 'i': + action = BACKLIGHT_INFO; + break; + case 'h': + usage(); + break; + } + } + + argc -= optind; + argv += optind; + if (argc != 0) { + if (strcmp("incr", argv[0]) == 0 || + strcmp("+", argv[0]) == 0) { + action = BACKLIGHT_INCR; + argc -= 1; + argv += 1; + } + else if (strcmp("decr", argv[0]) == 0 || + strcmp("-", argv[0]) == 0) { + action = BACKLIGHT_DECR; + argc -= 1; + argv += 1; + } else + action = BACKLIGHT_SET_BRIGHTNESS; + + if (argc == 1) { + percent = strtonum(argv[0], 0, 100, &percent_error); + if (percent_error) + errx(1, "Cannot parse brightness level %s: %s", + argv[0], + percent_error); + } + } + + if ((fd = open(device_name, O_RDWR)) == -1) + errx(1, "cannot open %s: %s", + device_name, strerror(errno)); + + if (caph_limit_stdio() < 0) + errx(1, "can't limit stdio rights"); + caph_cache_catpages(); + cap_rights_init(&right_ioctl, CAP_IOCTL); + if (caph_rights_limit(fd, &right_ioctl) < 0) + errx(1, "cap_right_limit() failed"); + if (caph_ioctls_limit(fd, backlight_ioctls, nitems(backlight_ioctls)) < 0) + errx(1, "caph_ioctls_limit() failed"); + if (caph_enter() < 0) + errx(1, "failed to enter capability mode"); + + switch (action) { + case BACKLIGHT_QUERY: + if (ioctl(fd, BACKLIGHTGETSTATUS, &props) == -1) + errx(1, "Cannot query the backlight device"); + if (quiet) + printf("%u\n", props.brightness); + else { + printf("brightness: %d\n", props.brightness); + if (props.nlevels != 0) { + printf("levels:"); + for (i = 0; i < props.nlevels; i++) + printf(" %d", props.levels[i]); + printf("\n"); + } + } + break; + case BACKLIGHT_SET_BRIGHTNESS: + props.brightness = percent; + if (ioctl(fd, BACKLIGHTUPDATESTATUS, &props) == -1) + errx(1, "Cannot update the backlight device"); + break; + case BACKLIGHT_INCR: + case BACKLIGHT_DECR: + if (ioctl(fd, BACKLIGHTGETSTATUS, &props) == -1) + errx(1, "Cannot query the backlight device"); + percent = percent == 0 ? 10 : percent; + percent = action == BACKLIGHT_INCR ? percent : -percent; + props.brightness += percent; + if ((int)props.brightness < 0) + props.brightness = 0; + if (props.brightness > 100) + props.brightness = 100; + if (ioctl(fd, BACKLIGHTUPDATESTATUS, &props) == -1) + errx(1, "Cannot update the backlight device"); + break; + case BACKLIGHT_INFO: + if (ioctl(fd, BACKLIGHTGETINFO, &info) == -1) + errx(1, "Cannot query the backlight device"); + if (quiet == false) { + printf("Backlight name: %s\n", info.name); + printf("Backlight hardware type: %s\n", backlight_type_to_string(info.type)); + } else { + printf("%s\n", info.name); + printf("%s\n", backlight_type_to_string(info.type)); + } + break; + } + + close(fd); + return (0); +} Property changes on: head/usr.bin/backlight/backlight.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property