Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 548 lines (469 sloc) 14.899 kb
c23b974 add vnc driver
michux authored
1 /* $Id$
2 * $URL$
3 *
4 * Libvncserver driver
5 *
6 * Copyright (C) 2009 Michael Vogt <michu@neophob.com>
7 * Modified from sample code by:
8 * Copyright (C) 2005 Michael Reinelt <michael@reinelt.co.at>
9 * Copyright (C) 2005, 2006, 2007, 2008, 2009 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
10 *
11 * This file is part of LCD4Linux.
12 *
13 * LCD4Linux is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
16 * any later version.
17 *
18 * LCD4Linux is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 */
28
29 /*
30 *
31 * exported fuctions:
32 *
33 * struct DRIVER drv_vnc
34 *
35 */
36
37 #include "config.h"
38
39 #include <stdlib.h>
40 #include <stdio.h>
41 #include <unistd.h>
42 #include <string.h>
43 #include <errno.h>
44
ec8146e more vnc driver stuff...
michux authored
45 #include <rfb/rfb.h>
c23b974 add vnc driver
michux authored
46
611fcee update keypad function for vnc driver
michux authored
47 /* struct timeval */
48 #include <sys/time.h>
49
c23b974 add vnc driver
michux authored
50 #include "debug.h"
51 #include "cfg.h"
52 #include "qprintf.h"
53 #include "udelay.h"
54 #include "plugin.h"
55 #include "widget.h"
56 #include "widget_text.h"
57 #include "widget_icon.h"
58 #include "widget_bar.h"
4ce7480 vnc driver: add beta keypad support
michux authored
59 #include "widget_keypad.h"
c23b974 add vnc driver
michux authored
60 #include "drv.h"
61 #include "drv_generic_graphic.h"
4ce7480 vnc driver: add beta keypad support
michux authored
62 #include "drv_generic_keypad.h"
c23b974 add vnc driver
michux authored
63
4852531 add fps limiter
michux authored
64 //todo: key widget text
c23b974 add vnc driver
michux authored
65
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
66 #define NO_MOUSE_BUTTON_PRESSED 0
67 #define LEFT_MOUSE_BUTTON_PRESSED 1
4852531 add fps limiter
michux authored
68 #define SLEEP_STEPS 1000
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
69
c23b974 add vnc driver
michux authored
70 static char Name[] = "VNC";
71
4ce7480 vnc driver: add beta keypad support
michux authored
72 static int xres = 320; /* screen settings */
c23b974 add vnc driver
michux authored
73 static int yres = 200;
74 static int BPP = 4;
4ce7480 vnc driver: add beta keypad support
michux authored
75 static int max_clients = 2; /* max connected clients */
fec42ab some more keypad stuff for vnc driver...
michux authored
76 static int osd_showtime = 2000; /* time to display the osd in ms */
4ce7480 vnc driver: add beta keypad support
michux authored
77 static int buttons = 2; /* number of keypad buttons */
fec42ab some more keypad stuff for vnc driver...
michux authored
78 static int buttonsize = 50; /* size of keypad buttons */
eed0c5c vnc driver: keypad works now
michux authored
79 static int keypadxofs = 0;
80 static int keypadyofs = 0;
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
81 static int keypadgap = 0;
3c865ce add server port as config option, rename options
michux authored
82 static int port = 5900;
3428f32 drv_vnc: http port as option
michux authored
83 static int httpPort = 5800;
6200a30 add keypadframe color as parameter, some minor fixups
michux authored
84 static unsigned char framer = 0;
85 static unsigned char frameg = 0;
86 static unsigned char frameb = 0;
4ce7480 vnc driver: add beta keypad support
michux authored
87
fec42ab some more keypad stuff for vnc driver...
michux authored
88 static rfbScreenInfoPtr server; /* vnc device */
611fcee update keypad function for vnc driver
michux authored
89 static struct timeval osd_timestamp;
fec42ab some more keypad stuff for vnc driver...
michux authored
90 static int show_keypad_osd = 0; /* is the osd active? */
4ce7480 vnc driver: add beta keypad support
michux authored
91 static int clientCount = 0; /* currently connected clients */
fec42ab some more keypad stuff for vnc driver...
michux authored
92 static int mouse_x = 0;
93 static int mouse_y = 0;
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
94 static int mouse_stat_old = 0;
95 static int process_event = 0;
4852531 add fps limiter
michux authored
96 static long frames = 0;
a4601a3 add UNSECURE password option to drv_vnc - SSH would be the better choice...
michux authored
97 static char *password;
27bba2d drv_vnc: run as http daemon
michux authored
98 static char *javaClassFiles;
4852531 add fps limiter
michux authored
99 static struct timeval startDriver;
100 static int maxfps = -1;
c23b974 add vnc driver
michux authored
101
611fcee update keypad function for vnc driver
michux authored
102 /* draws a simple rect, used to display keypad */
6200a30 add keypadframe color as parameter, some minor fixups
michux authored
103 int draw_rect(int x, int y, int size, unsigned char col, char *buffer)
611fcee update keypad function for vnc driver
michux authored
104 {
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
105 int ofs, ofs2, i, ret;
eed0c5c vnc driver: keypad works now
michux authored
106 unsigned char colr, colg;
107 colr = colg = col;
108 ret = 0;
fec42ab some more keypad stuff for vnc driver...
michux authored
109
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
110 /* check if mouse is in current rect */
fec42ab some more keypad stuff for vnc driver...
michux authored
111 if (mouse_x > x && mouse_x < (x + size))
3c865ce add server port as config option, rename options
michux authored
112 if (mouse_y > y && mouse_y < (y + size)) {
6200a30 add keypadframe color as parameter, some minor fixups
michux authored
113 colr = framer;
114 colg = frameg;
115 col = frameb;
eed0c5c vnc driver: keypad works now
michux authored
116 ret = 1;
117 }
611fcee update keypad function for vnc driver
michux authored
118
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
119 ofs2 = size * xres * BPP;
611fcee update keypad function for vnc driver
michux authored
120 for (i = x; i < x + size; i++) {
121 ofs = (i + xres * y) * BPP;
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
122 buffer[ofs + ofs2] = colr;
fec42ab some more keypad stuff for vnc driver...
michux authored
123 buffer[ofs++] = colr;
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
124 buffer[ofs + ofs2] = colg;
eed0c5c vnc driver: keypad works now
michux authored
125 buffer[ofs++] = colg;
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
126 buffer[ofs + ofs2] = col;
611fcee update keypad function for vnc driver
michux authored
127 buffer[ofs++] = col;
128 }
129
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
130 ofs2 = size * BPP;
611fcee update keypad function for vnc driver
michux authored
131 for (i = y; i <= y + size; i++) {
132 ofs = (i * xres + x) * BPP;
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
133 buffer[ofs + ofs2] = colr;
fec42ab some more keypad stuff for vnc driver...
michux authored
134 buffer[ofs++] = colr;
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
135 buffer[ofs + ofs2] = colg;
eed0c5c vnc driver: keypad works now
michux authored
136 buffer[ofs++] = colg;
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
137 buffer[ofs + ofs2] = col;
611fcee update keypad function for vnc driver
michux authored
138 buffer[ofs++] = col;
139 }
eed0c5c vnc driver: keypad works now
michux authored
140 return ret;
611fcee update keypad function for vnc driver
michux authored
141 }
ec8146e more vnc driver stuff...
michux authored
142
fec42ab some more keypad stuff for vnc driver...
michux authored
143 void display_keypad()
144 {
145 int i, rectx, recty;
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
146 int active;
fec42ab some more keypad stuff for vnc driver...
michux authored
147 for (i = 0; i < buttons; i++) {
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
148 rectx = keypadxofs + (i * (buttonsize + keypadgap));
eed0c5c vnc driver: keypad works now
michux authored
149 recty = keypadyofs /*+ (i*(buttonsize+gap)) */ ;
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
150 active = draw_rect(rectx, recty, buttonsize, 0, server->frameBuffer);
eed0c5c vnc driver: keypad works now
michux authored
151
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
152 /* if the lmb button is pressed and we didnt processed the event yet - do it now */
153 if (active == 1 && process_event == 1) {
3c865ce add server port as config option, rename options
michux authored
154 drv_generic_keypad_press(i + 1);
eed0c5c vnc driver: keypad works now
michux authored
155 //debug("mouse in keypad nr %d", i);
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
156 process_event = 0;
eed0c5c vnc driver: keypad works now
michux authored
157 }
fec42ab some more keypad stuff for vnc driver...
michux authored
158 }
159 }
160
4ce7480 vnc driver: add beta keypad support
michux authored
161 /* called if a vnc client disconnects */
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
162 static void clientgone( __attribute__ ((unused)) rfbClientPtr cl)
ec8146e more vnc driver stuff...
michux authored
163 {
164 if (clientCount > 0)
165 clientCount--;
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
166 debug("%d clients connected", clientCount);
ec8146e more vnc driver stuff...
michux authored
167 }
168
4ce7480 vnc driver: add beta keypad support
michux authored
169 /* called if a vnc client connect */
170 static enum rfbNewClientAction hook_newclient(rfbClientPtr cl)
ec8146e more vnc driver stuff...
michux authored
171 {
89efe11 add max client option
michux authored
172 if (clientCount < max_clients) {
173 clientCount++;
174 cl->clientGoneHook = clientgone;
baa22cf add sample cfg for vnc driver, indent
michux authored
175 debug("%d clients connected", clientCount);
89efe11 add max client option
michux authored
176 return RFB_CLIENT_ACCEPT;
177 } else {
baa22cf add sample cfg for vnc driver, indent
michux authored
178 info("client refused due max. client connections (%d)", clientCount);
89efe11 add max client option
michux authored
179 return RFB_CLIENT_REFUSE;
180 }
ec8146e more vnc driver stuff...
michux authored
181 }
182
e3d860b minor fixup
michux authored
183 /* handle mouse action */
4ce7480 vnc driver: add beta keypad support
michux authored
184 static void hook_mouseaction(int buttonMask, int x, int y, rfbClientPtr cl)
ec8146e more vnc driver stuff...
michux authored
185 {
186 if (x >= 0 && y >= 0 && x < xres && y < yres) {
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
187 process_event = 0;
188
189 /* process ONLY if mouse button is released. */
190 if (buttonMask == NO_MOUSE_BUTTON_PRESSED && mouse_stat_old == LEFT_MOUSE_BUTTON_PRESSED) {
fec42ab some more keypad stuff for vnc driver...
michux authored
191 gettimeofday(&osd_timestamp, NULL);
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
192 process_event = 1;
eed0c5c vnc driver: keypad works now
michux authored
193 mouse_x = x;
194 mouse_y = y;
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
195 }
196 //debug("btnMask: %d, old state: %d, processevent: %d", buttonMask, mouse_stat_old, process_event);
611fcee update keypad function for vnc driver
michux authored
197
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
198 /* show osd display if mouse is pressed */
199 if (buttonMask == 1) {
200 gettimeofday(&osd_timestamp, NULL);
6200a30 add keypadframe color as parameter, some minor fixups
michux authored
201 mouse_x = x;
202 mouse_y = y;
611fcee update keypad function for vnc driver
michux authored
203 if (show_keypad_osd == 0) {
204 /* no osd until yet, activate osd keypad ... */
205 show_keypad_osd = 1;
206 }
ec8146e more vnc driver stuff...
michux authored
207 }
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
208
ec8146e more vnc driver stuff...
michux authored
209 }
210
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
211 mouse_stat_old = buttonMask;
ec8146e more vnc driver stuff...
michux authored
212 rfbDefaultPtrAddEvent(buttonMask, x, y, cl);
213 }
214
4ce7480 vnc driver: add beta keypad support
michux authored
215 static int drv_vnc_keypad(const int num)
216 {
217 int val = WIDGET_KEY_PRESSED;
218
219 switch (num) {
220 case 1:
221 val += WIDGET_KEY_UP;
222 break;
223 case 2:
224 val += WIDGET_KEY_DOWN;
225 break;
226 case 3:
227 val += WIDGET_KEY_LEFT;
228 break;
229 case 4:
230 val += WIDGET_KEY_RIGHT;
231 break;
232 case 5:
233 val += WIDGET_KEY_CONFIRM;
234 break;
235 case 6:
236 val += WIDGET_KEY_CANCEL;
237 break;
238 default:
239 error("%s: unknown keypad value %d", Name, num);
240 }
c23b974 add vnc driver
michux authored
241
4ce7480 vnc driver: add beta keypad support
michux authored
242 return val;
243 }
244
245 /* init the driver, read config */
c23b974 add vnc driver
michux authored
246 static int drv_vnc_open(const char *Section)
247 {
6200a30 add keypadframe color as parameter, some minor fixups
michux authored
248 int keypadcol;
3c865ce add server port as config option, rename options
michux authored
249 if (cfg_number(Section, "Xres", 320, 32, 2048, &xres) < 1) {
250 info("[DRV_VNC] no '%s.Xres' entry from %s using default %d", Section, cfg_source(), xres);
ec8146e more vnc driver stuff...
michux authored
251 }
3c865ce add server port as config option, rename options
michux authored
252 if (cfg_number(Section, "Yres", 200, 32, 2048, &yres) < 1) {
253 info("[DRV_VNC] no '%s.Yres' entry from %s using default %d", Section, cfg_source(), yres);
c23b974 add vnc driver
michux authored
254 }
3c865ce add server port as config option, rename options
michux authored
255 if (cfg_number(Section, "Bpp", 4, 1, 4, &BPP) < 1) {
256 info("[DRV_VNC] no '%s.Bpp' entry from %s using default %d", Section, cfg_source(), BPP);
c23b974 add vnc driver
michux authored
257 }
3c865ce add server port as config option, rename options
michux authored
258 if (cfg_number(Section, "Maxclients", 2, 1, 64, &max_clients) < 1) {
259 info("[DRV_VNC] no '%s.Maxclients' entry from %s using default %d", Section, cfg_source(), max_clients);
89efe11 add max client option
michux authored
260 }
3c865ce add server port as config option, rename options
michux authored
261 if (cfg_number(Section, "Osd_showtime", 2000, 500, 60000, &osd_showtime) < 1) {
262 info("[DRV_VNC] no '%s.Osd_showtime' entry from %s using default %d", Section, cfg_source(), osd_showtime);
611fcee update keypad function for vnc driver
michux authored
263 }
3c865ce add server port as config option, rename options
michux authored
264 if (cfg_number(Section, "Buttons", 2, 0, 6, &buttons) < 1) {
265 info("[DRV_VNC] no '%s.Buttons' entry from %s using default %d", Section, cfg_source(), buttons);
fec42ab some more keypad stuff for vnc driver...
michux authored
266 }
3c865ce add server port as config option, rename options
michux authored
267 if (cfg_number(Section, "Buttonsize", 50, 8, 256, &buttonsize) < 1) {
268 info("[DRV_VNC] no '%s.Buttonsize' entry from %s using default %d", Section, cfg_source(), buttonsize);
fec42ab some more keypad stuff for vnc driver...
michux authored
269 }
3c865ce add server port as config option, rename options
michux authored
270 if (cfg_number(Section, "Keypadxofs", 0, 0, 4096, &keypadxofs) < 1) {
271 info("[DRV_VNC] no '%s.Keypadxofs' entry from %s using default %d", Section, cfg_source(), keypadxofs);
eed0c5c vnc driver: keypad works now
michux authored
272 }
3c865ce add server port as config option, rename options
michux authored
273 if (cfg_number(Section, "Keypadyofs", 0, 0, 4096, &keypadyofs) < 1) {
274 info("[DRV_VNC] no '%s.Keypadyofs' entry from %s using default %d", Section, cfg_source(), keypadyofs);
275 }
7ca8109 update keypad handling, add more options, remove compiler waarnings
michux authored
276 if (cfg_number(Section, "Keypadgap", 10, 0, 2048, &keypadgap) < 1) {
277 info("[DRV_VNC] no '%s.Keypadgap' entry from %s using default %d", Section, cfg_source(), keypadgap);
278 }
6200a30 add keypadframe color as parameter, some minor fixups
michux authored
279 if (cfg_number(Section, "Keypadcol", 255, 0, 0xffffff, &keypadcol) < 1) {
280 info("[DRV_VNC] no '%s.Keypadcol' entry from %s using default red", Section, cfg_source());
281 framer = 255;
282 } else {
283 framer = keypadcol & 0xff;
284 frameg = (keypadcol & 0xff00) >> 8;
285 frameb = (keypadcol & 0xff0000) >> 16;
286 }
3c865ce add server port as config option, rename options
michux authored
287 if (cfg_number(Section, "Port", 5900, 1, 65535, &port) < 1) {
288 info("[DRV_VNC] no '%s.Port' entry from %s using default %d", Section, cfg_source(), port);
eed0c5c vnc driver: keypad works now
michux authored
289 }
3428f32 drv_vnc: http port as option
michux authored
290 if (cfg_number(Section, "HttpPort", 5800, 1, 65535, &httpPort) < 1) {
291 info("[DRV_VNC] no '%s.HttpPort' entry from %s using default %d", Section, cfg_source(), httpPort);
292 }
4852531 add fps limiter
michux authored
293 if (cfg_number(Section, "Maxfps", -1, -1, 512, &maxfps) < 1) {
294 info("[DRV_VNC] no '%s.Maxfps' entry from %s using default %d", Section, cfg_source(), maxfps);
295 }
a4601a3 add UNSECURE password option to drv_vnc - SSH would be the better choice...
michux authored
296 password = cfg_get(Section, "Password", NULL);
297 if (password != NULL) {
298 info("[DRV_VNC] password enabled");
299 }
27bba2d drv_vnc: run as http daemon
michux authored
300 javaClassFiles = cfg_get(Section, "HttpDir", NULL);
301 if (javaClassFiles != NULL) {
302 info("[DRV_VNC] HTTP server enabled");
303 }
c23b974 add vnc driver
michux authored
304 return 0;
305 }
306
4ce7480 vnc driver: add beta keypad support
michux authored
307 /* shutdown driver, release allocated stuff */
c23b974 add vnc driver
michux authored
308 static int drv_vnc_close(void)
309 {
310 rfbShutdownServer(server, TRUE);
311 free(server->frameBuffer);
312 return 0;
313 }
314
611fcee update keypad function for vnc driver
michux authored
315
4ce7480 vnc driver: add beta keypad support
michux authored
316 /* actual blitting method */
ec8146e more vnc driver stuff...
michux authored
317 static void drv_vnc_blit_it(const int row, const int col, const int height, const int width, unsigned char *buffer)
c23b974 add vnc driver
michux authored
318 {
4852531 add fps limiter
michux authored
319 static int sleep = 0;
c23b974 add vnc driver
michux authored
320 int r, c, ofs;
321 RGBA p;
ec8146e more vnc driver stuff...
michux authored
322
c23b974 add vnc driver
michux authored
323 for (r = row; r < row + height; r++) {
324 for (c = col; c < col + width; c++) {
325 p = drv_generic_graphic_rgb(r, c);
326 ofs = (r * xres + c) * BPP;
327 buffer[ofs++] = p.R;
328 buffer[ofs++] = p.G;
329 buffer[ofs++] = p.B;
ec8146e more vnc driver stuff...
michux authored
330 buffer[ofs] = 255;
c23b974 add vnc driver
michux authored
331 }
332 }
611fcee update keypad function for vnc driver
michux authored
333
334 /* display osd keypad */
335 if (show_keypad_osd == 1) {
336 display_keypad();
337
338 /* check if the osd should be disabled after the waittime */
339 struct timeval now;
340 gettimeofday(&now, NULL);
341 int timedelta = (now.tv_sec - osd_timestamp.tv_sec) * 1000 + (now.tv_usec - osd_timestamp.tv_usec) / 1000;
342
343 if (timedelta > osd_showtime) {
344 show_keypad_osd = 0;
345 }
346 }
4852531 add fps limiter
michux authored
347 frames++;
348 if ((frames % 10) == 0 && maxfps > 0) {
349 struct timeval blittime;
350 gettimeofday(&blittime, NULL);
351 int time_since_start =
352 (blittime.tv_sec - startDriver.tv_sec) * 1000 + (blittime.tv_usec - startDriver.tv_usec) / 1000;
6322058 timer fix for vnc driver
michux authored
353
354 /* if time changed since start of lcd4linux */
355 if (time_since_start < 0) {
356 gettimeofday(&startDriver, NULL);
357 time_since_start =
358 (blittime.tv_sec - startDriver.tv_sec) * 1000 + (blittime.tv_usec - startDriver.tv_usec) / 1000;
359 if (time_since_start == 0)
360 time_since_start = 1;
361 }
362 //info("time :%d, frames: %d, sleep: %d", time_since_start, frames, sleep);
363
4852531 add fps limiter
michux authored
364 int fps = (int) (1000 * frames / time_since_start);
365
366 if (fps > maxfps) {
367 sleep += SLEEP_STEPS;
368 }
369
7228a0e fix fps delay error
michux authored
370 if (fps < maxfps && sleep >= SLEEP_STEPS) {
4852531 add fps limiter
michux authored
371 sleep -= SLEEP_STEPS;
372 }
373 }
374 usleep(sleep);
375
c23b974 add vnc driver
michux authored
376 }
377
4852531 add fps limiter
michux authored
378
c23b974 add vnc driver
michux authored
379 static void drv_vnc_blit(const int row, const int col, const int height, const int width)
380 {
ec8146e more vnc driver stuff...
michux authored
381
89efe11 add max client option
michux authored
382 if (rfbIsActive(server)) {
ec8146e more vnc driver stuff...
michux authored
383 drv_vnc_blit_it(row, col, height, width, (unsigned char *) server->frameBuffer);
89efe11 add max client option
michux authored
384
9ad3a78 I just wanted to commit the 1000st change to lcd4linux ;)
michux authored
385 if (clientCount > 0) {
e3d860b minor fixup
michux authored
386 rfbMarkRectAsModified(server, 0, 0, xres, yres);
9ad3a78 I just wanted to commit the 1000st change to lcd4linux ;)
michux authored
387 }
eed0c5c vnc driver: keypad works now
michux authored
388 rfbProcessEvents(server, server->deferUpdateTime * 500);
c23b974 add vnc driver
michux authored
389 }
390 }
391
392 /* start graphic display */
393 static int drv_vnc_start(const char *section)
394 {
395 char *s;
396
397 s = cfg_get(section, "Font", "6x8");
398 if (s == NULL || *s == '\0') {
399 error("%s: no '%s.Font' entry from %s", Name, section, cfg_source());
400 return -1;
401 }
402
403 XRES = -1;
404 YRES = -1;
405 if (sscanf(s, "%dx%d", &XRES, &YRES) != 2 || XRES < 1 || YRES < 1) {
406 error("%s: bad Font '%s' from %s", Name, s, cfg_source());
407 return -1;
408 }
409
410 /* Fixme: provider other fonts someday... */
411 if (XRES != 6 && YRES != 8) {
412 error("%s: bad Font '%s' from %s (only 6x8 at the moment)", Name, s, cfg_source());
413 return -1;
414 }
415
416 /* open communication with the display */
417 if (drv_vnc_open(section) < 0) {
418 return -1;
419 }
420
421 /* you surely want to allocate a framebuffer or something... */
ec8146e more vnc driver stuff...
michux authored
422 server = rfbGetScreen(0, NULL, xres, yres, 8, 3, BPP);
c23b974 add vnc driver
michux authored
423 server->desktopName = "LCD4Linux VNC Driver";
ec8146e more vnc driver stuff...
michux authored
424 server->frameBuffer = (char *) malloc(xres * yres * BPP);
425 server->alwaysShared = (1 == 1);
3c865ce add server port as config option, rename options
michux authored
426 server->port = port;
4ce7480 vnc driver: add beta keypad support
michux authored
427 server->ptrAddEvent = hook_mouseaction;
428 server->newClientHook = hook_newclient;
ec8146e more vnc driver stuff...
michux authored
429
a4601a3 add UNSECURE password option to drv_vnc - SSH would be the better choice...
michux authored
430 if (password != NULL) {
431 char **passwds = malloc(sizeof(char **) * 2);
432 passwds[0] = password;
433 passwds[1] = 0;
434 server->authPasswdData = (void *) passwds;
435 server->passwordCheck = rfbCheckPasswordByList;
436 }
27bba2d drv_vnc: run as http daemon
michux authored
437 if (javaClassFiles != NULL) {
438 server->httpDir = javaClassFiles;
439 server->httpEnableProxyConnect = TRUE;
3428f32 drv_vnc: http port as option
michux authored
440 server->httpPort = httpPort;
27bba2d drv_vnc: run as http daemon
michux authored
441 }
c23b974 add vnc driver
michux authored
442 /* Initialize the server */
443 rfbInitServer(server);
ec8146e more vnc driver stuff...
michux authored
444
c23b974 add vnc driver
michux authored
445 /* set width/height */
446 DROWS = yres;
447 DCOLS = xres;
448
4852531 add fps limiter
michux authored
449 /* set timestamp */
450 gettimeofday(&startDriver, NULL);
451
c23b974 add vnc driver
michux authored
452 return 0;
453 }
454
455 /****************************************/
456 /*** widget callbacks ***/
457 /****************************************/
458
459
460 /* using drv_generic_text_draw(W) */
461 /* using drv_generic_text_icon_draw(W) */
462 /* using drv_generic_text_bar_draw(W) */
463 /* using drv_generic_gpio_draw(W) */
464
465
466 /****************************************/
467 /*** exported functions ***/
468 /****************************************/
469
470
471 /* list models */
472 int drv_vnc_list(void)
473 {
474 printf("vnc server");
475 return 0;
476 }
477
478
479 /* initialize driver & display */
480 int drv_vnc_init(const char *section, const int quiet)
481 {
482 int ret;
483
484 /* real worker functions */
485 drv_generic_graphic_real_blit = drv_vnc_blit;
4ce7480 vnc driver: add beta keypad support
michux authored
486 drv_generic_keypad_real_press = drv_vnc_keypad;
c23b974 add vnc driver
michux authored
487
488 /* start display */
489 if ((ret = drv_vnc_start(section)) != 0)
490 return ret;
491
492 /* initialize generic graphic driver */
493 if ((ret = drv_generic_graphic_init(section, Name)) != 0)
494 return ret;
495
4ce7480 vnc driver: add beta keypad support
michux authored
496 /* initialize generic key pad driver */
497 if ((ret = drv_generic_keypad_init(section, Name)) != 0)
498 return ret;
499
c23b974 add vnc driver
michux authored
500 if (!quiet) {
501 char buffer[40];
502 qprintf(buffer, sizeof(buffer), "%s %dx%d", Name, DCOLS, DROWS);
503 if (drv_generic_graphic_greet(buffer, NULL)) {
504 sleep(3);
505 drv_generic_graphic_clear();
506 }
507 }
508
509 return 0;
510 }
511
512
513 /* close driver & display */
514 int drv_vnc_quit(const int quiet)
515 {
516 info("%s: shutting down.", Name);
517
518 /* clear display */
519 drv_generic_graphic_clear();
520
521 /* say goodbye... */
522 if (!quiet) {
523 drv_generic_graphic_greet("goodbye!", NULL);
524 }
525
526 drv_generic_graphic_quit();
4ce7480 vnc driver: add beta keypad support
michux authored
527 drv_generic_keypad_quit();
a4601a3 add UNSECURE password option to drv_vnc - SSH would be the better choice...
michux authored
528 if (password != NULL) {
529 free(password);
530 }
27bba2d drv_vnc: run as http daemon
michux authored
531 if (javaClassFiles != NULL) {
532 free(javaClassFiles);
533 }
c23b974 add vnc driver
michux authored
534
535 debug("closing connection");
536 drv_vnc_close();
537
538 return (0);
539 }
540
541
542 DRIVER drv_vnc = {
543 .name = Name,
544 .list = drv_vnc_list,
545 .init = drv_vnc_init,
546 .quit = drv_vnc_quit,
547 };
Something went wrong with that request. Please try again.