2 * Copyright (c) 2010, GraÅžvydas Ignotas
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the organization nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <X11/Xutil.h>
34 #include <sys/types.h>
38 #include <sys/ioctl.h>
42 #define PFX "op_runfbapp: "
44 static struct termios g_kbd_termios_saved;
47 static Cursor transparent_cursor(Display *display, Window win)
54 memset(&dummy, 0, sizeof(dummy));
55 pix = XCreateBitmapFromData(display, win, &d, 1, 1);
56 cursor = XCreatePixmapCursor(display, pix, pix,
57 &dummy, &dummy, 0, 0);
58 XFreePixmap(display, pix);
62 static void *x11_handler(void *arg)
64 unsigned int display_width, display_height;
65 XSetWindowAttributes attributes;
71 display = XOpenDisplay(NULL);
74 fprintf(stderr, PFX "(not hiding X): Can't open display: %s\n",
79 screen = DefaultScreen(display);
81 display_width = DisplayWidth(display, screen);
82 display_height = DisplayHeight(display, screen);
84 win = XCreateSimpleWindow(display,
85 RootWindow(display, screen),
86 0, 0, display_width, display_height, 0,
87 BlackPixel(display, screen),
88 BlackPixel(display, screen));
90 attributes.override_redirect = True;
91 attributes.cursor = transparent_cursor(display, win);
92 XChangeWindowAttributes(display, win, CWOverrideRedirect | CWCursor, &attributes);
94 XSelectInput(display, win, ExposureMask);
95 XMapWindow(display, win);
96 XGrabKeyboard(display, win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
100 XNextEvent(display, &report);
102 if (report.type == Expose)
103 while (XCheckTypedEvent(display, Expose, &report))
110 static void hidecon_start(void)
112 struct termios kbd_termios;
115 g_kbdfd = open("/dev/tty", O_RDWR);
117 perror(PFX "open /dev/tty");
121 if (ioctl(g_kbdfd, KDGETMODE, &mode) == -1) {
122 perror(PFX "(not hiding FB): KDGETMODE");
126 if (tcgetattr(g_kbdfd, &kbd_termios) == -1) {
127 perror(PFX "tcgetattr");
131 g_kbd_termios_saved = kbd_termios;
132 kbd_termios.c_lflag &= ~(ICANON | ECHO); // | ISIG);
133 kbd_termios.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON);
134 kbd_termios.c_cc[VMIN] = 0;
135 kbd_termios.c_cc[VTIME] = 0;
137 if (tcsetattr(g_kbdfd, TCSAFLUSH, &kbd_termios) == -1) {
138 perror(PFX "tcsetattr");
142 if (ioctl(g_kbdfd, KDSETMODE, KD_GRAPHICS) == -1) {
143 perror(PFX "KDSETMODE KD_GRAPHICS");
144 tcsetattr(g_kbdfd, TCSAFLUSH, &g_kbd_termios_saved);
155 static void hidecon_end(void)
160 if (ioctl(g_kbdfd, KDSETMODE, KD_TEXT) == -1)
161 perror(PFX "KDSETMODE KD_TEXT");
163 if (tcsetattr(g_kbdfd, TCSAFLUSH, &g_kbd_termios_saved) == -1)
164 perror(PFX "tcsetattr");
170 int main(int argc, char *argv[])
178 for (i = 1; i < argc; i++)
179 len += strlen(argv[i]) + 1;
184 fprintf(stderr, PFX "OOM\n");
188 /* rebuild command line for program we launch */
189 for (p = cmd, i = 1; i < argc; i++) {
197 ret = pthread_create(&tid, NULL, x11_handler, NULL);
199 fprintf(stderr, PFX "pthread_create: %d\n", ret);
208 perror(PFX "system");
213 /* XXX: maybe stop the X thread nicely? */