core: add support for the autoverbose feature
[fbsplash.git] / core / src / fbcon_decor_ctl.c
blob1092a4fb641fc223a498b0cdbe4c9e6e83a4b95b
1 /*
2 * fbcon_decor_ctl.c -- Fbcon Decor control application
4 * Copyright (C) 2004-2007 Michal Januszewski <spock@gentoo.org>
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License v2. See the file COPYING in the main directory of this archive for
8 * more details.
12 #include <stdio.h>
13 #include <string.h>
14 #include <stdlib.h>
15 #include <sys/types.h>
16 #include <linux/kd.h>
17 #include <linux/vt.h>
18 #include <sys/stat.h>
19 #include <fcntl.h>
20 #include <termios.h>
21 #include <sys/ioctl.h>
22 #include <sys/mman.h>
23 #include <getopt.h>
24 #include <unistd.h>
26 #include "common.h"
27 #include "render.h"
28 #include "fbcon_decor.h"
30 static struct option options[] = {
31 { "vc", required_argument, NULL, 0x100 },
32 { "cmd", required_argument, NULL, 0x101 },
33 { "theme", required_argument, NULL, 0x102 },
34 { "tty", required_argument, NULL, 0x103 },
35 { "help", no_argument, NULL, 'h'},
36 { "verbose", no_argument, NULL, 'v'},
37 { "quiet", no_argument, NULL, 'q'},
40 enum { none, setpic, on, off, setcfg, getcfg, getstate } arg_task;
42 struct cmd {
43 char *name;
44 int value;
47 static struct cmd cmds[] = {
48 { "on", on },
49 { "off", off },
50 { "setcfg", setcfg },
51 { "getcfg", getcfg },
52 { "setpic", setpic },
53 { "getstate", getstate },
56 static void usage()
58 printf(
59 "fbcondecor_ctl/splashutils-" PACKAGE_VERSION "\n"
60 "Usage: fbcondecor_ctl [options] -c <cmd>\n\n"
61 "Commands:\n"
62 " on enable fbcondecor on a virtual console\n"
63 " off disable fbcondecor on a virtual console\n"
64 " getstate get fbcondecor state on a virtual console\n"
65 " setcfg set fbcondecor configuration for a virtual console\n"
66 " getcfg get fbcondecor configuration for a virtual console\n"
67 " setpic set fbcondecor background picture for a virtual console;\n"
68 " note that this command will only have any effect if\n"
69 " it's called for the current console\n"
70 "Options:\n"
71 " -c, --cmd=CMD execute command CMD\n"
72 " -h, --help show this help message\n"
73 " -t, --theme=THEME use theme THEME\n"
74 " --vc=NUM use NUMth virtual console [0..n]\n"
75 " --tty=NUM use NUMth tty [1..n]\n"
76 " -v, --verbose display verbose error messages\n"
77 " -q, --quiet don't display any messages\n"
81 int fbcondecor_main(int argc, char **argv)
83 unsigned int c, i;
84 int err = 0;
85 int arg_vc = -1;
86 stheme_t *theme = NULL;
88 fbsplash_lib_init(fbspl_bootup);
89 fbsplashr_init(false);
91 fd_fbcondecor = fbcon_decor_open(false);
92 if (fd_fbcondecor == -1) {
93 iprint(MSG_ERROR, "Failed to open the fbcon_decor control device.\n");
94 exit(1);
97 arg_task = none;
98 arg_vc = -1;
100 while ((c = getopt_long(argc, argv, "c:t:hvq", options, NULL)) != EOF) {
102 switch (c) {
103 case 'h':
104 usage();
105 return 0;
107 case 0x100:
108 arg_vc = atoi(optarg);
109 break;
111 case 0x102:
112 case 't':
113 fbsplash_acc_theme_set(optarg);
114 break;
116 case 0x101:
117 case 'c':
118 for (i = 0; i < sizeof(cmds) / sizeof(struct cmd); i++) {
119 if (!strcmp(optarg, cmds[i].name)) {
120 arg_task = cmds[i].value;
121 break;
124 break;
126 case 0x103:
127 arg_vc = atoi(optarg)-1;
128 if (arg_vc == -1)
129 arg_vc = 0;
130 break;
132 /* Verbosity level adjustment. */
133 case 'q':
134 config.verbosity = FBSPL_VERB_QUIET;
135 break;
137 case 'v':
138 config.verbosity = FBSPL_VERB_HIGH;
139 break;
143 if (arg_task == none) {
144 usage();
145 return 0;
148 switch (arg_task) {
149 /* Only load the theme if it will actually be used. */
150 case setpic:
151 case setcfg:
152 theme = fbsplashr_theme_load();
153 default:
154 break;
157 if (arg_vc == -1)
158 arg_vc = 0;
160 switch (arg_task) {
162 case on:
163 err = fbcon_decor_setstate(FBCON_DECOR_IO_ORIG_USER, arg_vc, 1);
164 break;
166 case off:
167 err = fbcon_decor_setstate(FBCON_DECOR_IO_ORIG_USER, arg_vc, 0);
168 break;
170 case setpic:
172 struct vt_stat stat;
174 if (ioctl(fd_tty0, VT_GETSTATE, &stat) != -1) {
175 if (arg_vc != stat.v_active - 1)
176 goto setpic_out;
179 err = fbcon_decor_setpic(FBCON_DECOR_IO_ORIG_USER, arg_vc, theme);
180 setpic_out: break;
183 case getcfg:
184 err = fbcon_decor_getcfg(arg_vc);
185 break;
187 case setcfg:
188 err = fbcon_decor_setcfg(FBCON_DECOR_IO_ORIG_USER, arg_vc, theme);
189 break;
191 case getstate:
193 printf("Fbcon decorations state on console %d: %s\n", arg_vc,
194 (fbcon_decor_getstate(FBCON_DECOR_IO_ORIG_USER, arg_vc)) ? "on" : "off");
195 break;
197 default:
198 break;
201 fbsplashr_theme_free(theme);
203 close(fd_fbcondecor);
204 fbsplashr_cleanup();
205 fbsplash_lib_cleanup();
207 return 0;
210 #ifndef UNIFIED_BUILD
211 int main(int argc, char **argv)
213 return fbcondecor_main(argc, argv);
215 #endif /* UNIFIED_BUILD */