summaryrefslogtreecommitdiff
path: root/app/xvctl
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu@cvs.openbsd.org>2006-11-26 10:59:23 +0000
committerMatthieu Herrb <matthieu@cvs.openbsd.org>2006-11-26 10:59:23 +0000
commit3928433848e2d6a9356f3d438a14b32a4f87f660 (patch)
tree833c3f73530d52192182ff6e208a3d038643ea8b /app/xvctl
parentddd650147fb204ab295c398966127129da577908 (diff)
Importing from XF4
Diffstat (limited to 'app/xvctl')
-rw-r--r--app/xvctl/Makefile15
-rw-r--r--app/xvctl/xvctl.187
-rw-r--r--app/xvctl/xvctl.c270
3 files changed, 372 insertions, 0 deletions
diff --git a/app/xvctl/Makefile b/app/xvctl/Makefile
new file mode 100644
index 000000000..675d17d6d
--- /dev/null
+++ b/app/xvctl/Makefile
@@ -0,0 +1,15 @@
+# $OpenBSD: Makefile,v 1.1 2006/11/26 10:59:22 matthieu Exp $
+
+.include <bsd.own.mk>
+X11BASE?= /usr/X11R6
+
+PROG=xvctl
+MAN=xvctl.1
+
+CPPFLAGS+= -I${X11BASE}/include
+LDADD+=-L${X11BASE}/lib -lXv -lXext -lX11
+
+MANDIR= ${X11BASE}/man/cat
+
+.include <bsd.prog.mk>
+.include <bsd.xorg.mk>
diff --git a/app/xvctl/xvctl.1 b/app/xvctl/xvctl.1
new file mode 100644
index 000000000..4c97e5f2c
--- /dev/null
+++ b/app/xvctl/xvctl.1
@@ -0,0 +1,87 @@
+.\" $OpenBSD: xvctl.1,v 1.1 2006/11/26 10:59:22 matthieu Exp $
+.\"
+.\" Copyright (c) 2001 Marc Espie
+.\"
+.\" All rights reserved.
+.\"
+.\" 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.
+.\"
+.Dd November 9, 2001
+.Dt XVCTL 1
+.Os
+.Sh NAME
+.Nm xvctl
+.Nd get or set xv extension values
+.Sh SYNOPSIS
+.Nm xvctl
+.Op Fl n
+.Op Fl d Ar display
+.Op Fl s Ar screen
+.Op Fl A Ar adaptor
+.Ar name ...
+.Nm xvctl
+.Op Fl n
+.Op Fl d Ar display
+.Op Fl s Ar screen
+.Op Fl A Ar adaptor
+.Fl w
+.Ar name=value ...
+.Nm xvctl
+.Op Fl n
+.Op Fl d Ar display
+.Op Fl s Ar screen
+.Op Fl A Ar adaptor
+.Fl a
+.Sh DESCRIPTION
+The
+.Nm
+utility retrieves the Xvideo extension attributes and
+allows the user to set them.
+.Pp
+For instance, this can be used to change the contrast or brightness of an
+external video program.
+
+The options are as follows:
+.Bl -tag -width xxx
+.It Fl d Ar display
+affect the display named
+.Ar display ,
+instead of the default display.
+.It Fl s Ar screen
+affect screen #
+.Ar screen .
+By default, the first screen with video adaptors will be chosen.
+.It Fl A Ar adaptor
+affect adaptor #
+.Ar adaptor .
+By default, the first display adaptor will be chosen.
+.It Fl a
+list all the currently available gettable attributes.
+.It Fl n
+suppress printing of the field name, only output the field value.
+Useful for setting shell variables.
+.It Fl w
+required to set a variable. The name should be followed
+by an equal sign and the new value.
+.El
+.Sh SEE ALSO
+.Xr xvinfo 1 ,
+.Xr Xv 3x
diff --git a/app/xvctl/xvctl.c b/app/xvctl/xvctl.c
new file mode 100644
index 000000000..0298d0e36
--- /dev/null
+++ b/app/xvctl/xvctl.c
@@ -0,0 +1,270 @@
+/* $OpenBSD: xvctl.c,v 1.1 2006/11/26 10:59:22 matthieu Exp $ */
+/*
+ * Copyright (c) 2001 Marc Espie.
+ *
+ * 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 OPENBSD PROJECT 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 OPENBSD
+ * PROJECT 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.
+ */
+#include <X11/X.h>
+#include <X11/Xlib.h>
+#include <X11/extensions/Xvlib.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <err.h>
+#include <string.h>
+#include <ctype.h>
+
+void
+usage()
+{
+ fprintf(stderr, "usage:\t%s\n\t%s\n\t%s\n",
+ "xvctl [-n] [-d display] [-s screen] [-a adaptor] variable ...",
+ "xvctl [-n] [-d display] [-s screen] [-a adaptor] -w variable=value ...",
+ "xvctl [-n] [-d display] [-s screen] [-a adaptor] -a");
+ exit(1);
+}
+
+char *
+reformat(char *name)
+{
+ static char result[BUFSIZ];
+ char *s;
+ char *t;
+
+ if (strlcpy(result, name, sizeof result) >= sizeof result)
+ warnx("Name %s was truncated", name);
+ s = result;
+ if (strncmp(result, "XV_", 3) == 0)
+ s+=3;
+ for (t = s; *t; t++)
+ *t = tolower(*t);
+ return s;
+}
+
+XvAttribute *
+findname(XvAttribute table[], int nattr, const char *name)
+{
+ int i;
+
+ if (strncasecmp(name, "XV_", 3) == 0)
+ name +=3;
+ for (i = 0; i < nattr; i++) {
+ if (strcasecmp(table[i].name+3, name) == 0)
+ return table+i;
+ }
+ warnx("No such attribute %s", name);
+ return NULL;
+}
+
+void
+printattribute(Display *dpy, XvPortID id, int nflag, XvAttribute *a)
+{
+ Atom atom;
+ int v;
+
+ atom = XInternAtom(dpy, a->name, True);
+ if (atom != None)
+ if (Success == XvGetPortAttribute(dpy, id, atom, &v)) {
+ if (!nflag)
+ printf("%s = ", reformat(a->name));
+ printf("%d\n", v);
+ }
+}
+
+void
+showall(Display *dpy, XvPortID id, int nflag, XvAttribute table[], int nattr)
+{
+ int i;
+
+ for (i = 0; i < nattr; i++)
+ if (table[i].flags & XvGettable)
+ printattribute(dpy, id, nflag, table+i);
+}
+
+void
+setvar(Display *dpy, XvPortID id, int nflag, XvAttribute table[], int nattr,
+ const char *name, int v)
+{
+ XvAttribute *at;
+ Atom atom;
+
+ at = findname(table, nattr, name);
+ if (!at)
+ return;
+ if (!(at->flags & XvSettable)) {
+ warnx("Can't set %s", name);
+ return;
+ }
+ if ((at->max_value != -1 && v > at->max_value) || v < at->min_value) {
+ warnx("Value %d for %s out of range (%d-%d)", v, name,
+ at->min_value, at->max_value);
+ return;
+ }
+ atom = XInternAtom(dpy, at->name, True);
+ if (atom != None)
+ if (Success == XvSetPortAttribute(dpy, id, atom, v)) {
+ if (!nflag)
+ printattribute(dpy, id, nflag, at);
+ }
+}
+
+void
+showvar(Display *dpy, XvPortID id, int nflag, XvAttribute table[], int nattr,
+ const char *name)
+{
+ XvAttribute *at;
+
+ at = findname(table, nattr, name);
+ if (!at)
+ return;
+ if (!(at->flags & XvGettable)) {
+ warnx("Can't get %s", name);
+ return;
+ }
+ printattribute(dpy, id, nflag, at);
+}
+
+void
+parse(Display *dpy, XvPortID id, int nflag, int wflag, XvAttribute table[],
+ int nattr, const char *s)
+{
+ char buf[BUFSIZ];
+ char *cp;
+
+ if (strlcpy(buf, s, sizeof buf) >= sizeof(buf))
+ warnx("Buffer too small for %s", s);
+ cp = strchr(buf, '=');
+ if (cp != NULL) {
+ long v;
+ char *end;
+ char *tail;
+
+ if (!wflag)
+ errx(2, "Can't set variables without -w");
+ tail = cp;
+ while (tail > buf && isspace(tail[-1]))
+ tail--;
+ *tail = 0;
+ do {
+ cp++;
+ } while (isspace(*cp));
+ v = strtol(cp, &end, 0);
+ if (*end != 0) {
+ warnx("Bogus value: %s", cp);
+ return;
+ }
+ setvar(dpy, id, nflag, table, nattr, buf, v);
+ } else
+ showvar(dpy, id, nflag, table, nattr, buf);
+}
+
+char *
+displayname(char *display)
+{
+ return display ? display : XDisplayName(display);
+}
+
+int
+main(int argc, char *argv[])
+{
+ int ch;
+ int aflag = 0;
+ int nflag = 0;
+ int wflag = 0;
+ char *display = NULL;
+ int screen = -1;
+ int nscreens;
+ int nattr;
+ unsigned int nadaptors;
+ XvAdaptorInfo *ainfo;
+ XvAttribute *table;
+ int adaptor = 0;
+ Display *dpy;
+ unsigned int ver, rev, eventB, reqB, errorB;
+
+ while ((ch = getopt(argc, argv, "ad:ns:A:w")) != -1) {
+ switch(ch) {
+ case 'a':
+ aflag = 1;
+ break;
+ case 'd':
+ display = optarg;
+ break;
+ case 's':
+ screen = atoi(optarg);
+ break;
+ case 'A':
+ adaptor = atoi(optarg);
+ break;
+ case 'n':
+ nflag = 1;
+ break;
+ case 'w':
+ wflag = 1;
+ break;
+ default:
+ usage();
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ dpy = XOpenDisplay(display);
+ if (!dpy)
+ errx(1, "Unable to open display %s", displayname(display));
+ if (Success != XvQueryExtension(dpy, &ver, &rev, &reqB, &eventB,
+ &errorB))
+ errx(1, "No X-Video extension on %s", displayname(display));
+
+ if (!nflag)
+ printf("X-Video extension version %i.%i on %s\n", ver, rev,
+ displayname(display));
+
+ nscreens = ScreenCount(dpy);
+ if (screen == -1) {
+ for (screen = 0; screen < nscreens; screen++) {
+ XvQueryAdaptors(dpy, RootWindow(dpy, screen),
+ &nadaptors, &ainfo);
+ if (nadaptors)
+ break;
+ }
+ }
+ if (screen >= nscreens)
+ errx(1, "Not a screen with adaptors");
+
+ if (adaptor > nadaptors)
+ errx(1, "No such adaptor");
+
+ table = XvQueryPortAttributes(dpy, ainfo[adaptor].base_id, &nattr);
+
+
+ if (argc == 0) {
+ if (!aflag)
+ usage();
+ showall(dpy, ainfo[adaptor].base_id, nflag, table, nattr);
+ }
+ for (; *argv != NULL; ++argv)
+ parse(dpy, ainfo[adaptor].base_id, nflag, wflag, table,
+ nattr, *argv);
+ XFree(table);
+ exit(0);
+}