core: add support for the autoverbose feature
[fbsplash.git] / core / src / fbcon_decor.c
blobe5fa15ae3aeedc90e7984194dcc1b7ccbdf5f537
1 /*
2 * fbcon_decor.c - Functions for handling communication with the kernel
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 <sys/stat.h>
17 #include <unistd.h>
18 #include <fcntl.h>
19 #include <termios.h>
20 #include <sys/ioctl.h>
21 #include <errno.h>
23 #include "common.h"
24 #include "render.h"
25 #include "fbcon_decor.h"
27 #ifdef CONFIG_FBCON_DECOR
28 int fd_fbcondecor = -1;
30 int fbcon_decor_open(bool create)
32 int c;
33 c = open(FBCON_DECOR_DEV, O_RDWR);
35 if (c == -1 && create) {
36 if (!dev_create(FBCON_DECOR_DEV, PATH_SYS "/class/misc/fbcondecor/dev"))
37 c = open(FBCON_DECOR_DEV, O_RDWR);
40 if (c == -1) {
41 c = open(PATH_DEV"/fbsplash", O_RDWR);
42 if (c == -1 && create) {
43 if (!dev_create(PATH_DEV"/fbsplash", PATH_SYS "/class/misc/fbsplash/dev"))
44 c = open(PATH_DEV"/fbsplash", O_RDWR);
48 return c;
51 int fbcon_decor_setstate(unsigned char origin, int vc, unsigned int state)
53 struct fbcon_decor_iowrapper wrapper = {
54 .vc = vc,
55 .origin = origin,
56 .data = &state,
59 if (ioctl(fd_fbcondecor, FBIOCONDECOR_SETSTATE, &wrapper)) {
60 iprint(MSG_ERROR, "FBIOCONDECOR_SETSTATE failed, error code %d.\n", errno);
61 return -1;
63 return 0;
66 int fbcon_decor_getstate(unsigned char origin, int vc)
68 int i;
70 struct fbcon_decor_iowrapper wrapper = {
71 .vc = vc,
72 .origin = FBCON_DECOR_IO_ORIG_USER,
73 .data = &i,
76 ioctl(fd_fbcondecor, FBIOCONDECOR_GETSTATE, &wrapper);
77 return i;
80 int fbcon_decor_setpic(unsigned char origin, int vc, stheme_t *theme)
82 struct fbcon_decor_iowrapper wrapper = {
83 .vc = vc,
84 .origin = origin,
85 .data = &theme->verbose_img,
88 if (!(theme->modes & FBSPL_MODE_VERBOSE))
89 return -1;
91 invalidate_all(theme);
92 render_objs(theme, (u8*)theme->verbose_img.data, FBSPL_MODE_VERBOSE, true);
94 if (ioctl(fd_fbcondecor, FBIOCONDECOR_SETPIC, &wrapper)) {
95 iprint(MSG_ERROR, "FBIOCONDECOR_SETPIC failed, error code %d.\n", errno);
96 iprint(MSG_ERROR, "Hint: are you calling 'setpic' for the current virtual console?\n");
97 return -1;
99 return 0;
102 int fbcon_decor_setcfg(unsigned char origin, int vc, stheme_t *theme)
104 struct vc_decor vc_cfg;
105 struct fbcon_decor_iowrapper wrapper = {
106 .vc = vc,
107 .origin = origin,
108 .data = &vc_cfg,
111 int err = cfg_check_sanity(theme, 'v');
112 if (err)
113 return err;
115 vc_cfg.tx = theme->tx;
116 vc_cfg.ty = theme->ty;
117 vc_cfg.twidth = theme->tw;
118 vc_cfg.theight = theme->th;
119 vc_cfg.bg_color = theme->bg_color;
120 vc_cfg.theme = config.theme;
122 if (ioctl(fd_fbcondecor, FBIOCONDECOR_SETCFG, &wrapper)) {
123 iprint(MSG_ERROR, "FBIOCONDECOR_SETCFG failed, error code %d.\n", errno);
124 return -1;
126 return 0;
129 int fbcon_decor_getcfg(int vc)
131 int err = 0;
132 struct vc_decor vc_cfg;
133 struct fbcon_decor_iowrapper wrapper = {
134 .vc = vc,
135 .origin = FBCON_DECOR_IO_ORIG_USER,
136 .data = &vc_cfg,
139 vc_cfg.theme = malloc(FBCON_DECOR_THEME_LEN);
140 if (!vc_cfg.theme)
141 return -1;
143 if (ioctl(fd_fbcondecor, FBIOCONDECOR_GETCFG, &wrapper)) {
144 iprint(MSG_ERROR, "FBIOCONDECOR_GETCFG failed, error code %d.\n", errno);
145 err = -2;
146 goto out;
149 if (vc_cfg.theme[0] == 0) {
150 strcpy(vc_cfg.theme, "<none>");
153 printf("Fbcon decorations config on console %d:\n", vc);
154 printf("tx: %d\n", vc_cfg.tx);
155 printf("ty: %d\n", vc_cfg.ty);
156 printf("twidth: %d\n", vc_cfg.twidth);
157 printf("theight: %d\n", vc_cfg.theight);
158 printf("bg_color: %d\n", vc_cfg.bg_color);
159 printf("theme: %s\n", vc_cfg.theme);
161 out:
162 free(vc_cfg.theme);
163 return err;
166 #endif /* CONFIG_FBCON_DECOR */