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
15 #include <sys/types.h>
21 #include <sys/ioctl.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
;
47 static struct cmd cmds
[] = {
53 { "getstate", getstate
},
59 "fbcondecor_ctl/splashutils-" PACKAGE_VERSION
"\n"
60 "Usage: fbcondecor_ctl [options] -c <cmd>\n\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"
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
)
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");
100 while ((c
= getopt_long(argc
, argv
, "c:t:hvq", options
, NULL
)) != EOF
) {
108 arg_vc
= atoi(optarg
);
113 fbsplash_acc_theme_set(optarg
);
118 for (i
= 0; i
< sizeof(cmds
) / sizeof(struct cmd
); i
++) {
119 if (!strcmp(optarg
, cmds
[i
].name
)) {
120 arg_task
= cmds
[i
].value
;
127 arg_vc
= atoi(optarg
)-1;
132 /* Verbosity level adjustment. */
134 config
.verbosity
= FBSPL_VERB_QUIET
;
138 config
.verbosity
= FBSPL_VERB_HIGH
;
143 if (arg_task
== none
) {
149 /* Only load the theme if it will actually be used. */
152 theme
= fbsplashr_theme_load();
163 err
= fbcon_decor_setstate(FBCON_DECOR_IO_ORIG_USER
, arg_vc
, 1);
167 err
= fbcon_decor_setstate(FBCON_DECOR_IO_ORIG_USER
, arg_vc
, 0);
174 if (ioctl(fd_tty0
, VT_GETSTATE
, &stat
) != -1) {
175 if (arg_vc
!= stat
.v_active
- 1)
179 err
= fbcon_decor_setpic(FBCON_DECOR_IO_ORIG_USER
, arg_vc
, theme
);
184 err
= fbcon_decor_getcfg(arg_vc
);
188 err
= fbcon_decor_setcfg(FBCON_DECOR_IO_ORIG_USER
, arg_vc
, theme
);
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");
201 fbsplashr_theme_free(theme
);
203 close(fd_fbcondecor
);
205 fbsplash_lib_cleanup();
210 #ifndef UNIFIED_BUILD
211 int main(int argc
, char **argv
)
213 return fbcondecor_main(argc
, argv
);
215 #endif /* UNIFIED_BUILD */