summaryrefslogtreecommitdiff
path: root/framebuffer/fb_frontend_vnc.c
blob: f7ee891517c9254431f4c322784cd084c5b5392f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/*
 * Copyright 2008 Vincent Sanders <vince@simtec.co.uk>
 *
 * This file is part of NetSurf, http://www.netsurf-browser.org/
 *
 * NetSurf is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * NetSurf is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <string.h>

#include <rfb/rfb.h>
#include <rfb/keysym.h>

#include "css/css.h"
#include "desktop/options.h"
#include "desktop/gui.h"
#include "desktop/options.h"
#include "utils/messages.h"
#include "desktop/history_core.h"

#include "framebuffer/fb_gui.h"
#include "framebuffer/fb_plotters.h"
#include "framebuffer/fb_frontend.h"
#include "framebuffer/fb_cursor.h"
#include "framebuffer/fb_rootwindow.h"
#include "framebuffer/fb_options.h"

#include "utils/log.h"

static rfbScreenInfoPtr vnc_screen;
static struct gui_window *cur_window;

static void fb_vnc_doptr(int buttonMask,int x,int y,rfbClientPtr cl)
{
        struct gui_window *g = cur_window;
        if (buttonMask == 0) {
                fb_rootwindow_move(framebuffer, g, x, y, false);
        } else {

                /* left button */
                /*                if (buttonMask && 0x1) {
                                  fb_rootwindow_click(g, BROWSER_MOUSE_PRESS_1,
                                  fb_cursor_x(framebuffer),
                                  fb_cursor_y(framebuffer));
                                  }*/
                if (buttonMask && 0x1) {
                        fb_rootwindow_click(g, BROWSER_MOUSE_CLICK_1,
                                            fb_cursor_x(framebuffer),
                                            fb_cursor_y(framebuffer));
                }

                /* right button */
                /*if (buttonMask && 0x4) {
                  fb_rootwindow_click(g, BROWSER_MOUSE_PRESS_2,
                  fb_cursor_x(framebuffer),
                  fb_cursor_y(framebuffer));
                  }*/
                if (buttonMask && 0x4) {
                        fb_rootwindow_click(g, BROWSER_MOUSE_CLICK_2,
                                            fb_cursor_x(framebuffer),
                                            fb_cursor_y(framebuffer));
                }

                if (buttonMask && 0x8) {
                        /* wheelup */
                        fb_window_scroll(g, 0, -100);
                }

                if (buttonMask && 0x10) {
                        /* wheeldown */
                        fb_window_scroll(g, 0, 100);
                }



                /*
                  case SDL_MOUSEBUTTONUP:
                  switch (event.button.button) {

                  case SDL_BUTTON_LEFT:
                  fb_rootwindow_click(g, BROWSER_MOUSE_CLICK_1,
                  fb_cursor_x(framebuffer),
                  fb_cursor_y(framebuffer));
                  break;

                  case SDL_BUTTON_RIGHT:
                  fb_rootwindow_click(g, BROWSER_MOUSE_CLICK_2,
                  fb_cursor_x(framebuffer),
                  fb_cursor_y(framebuffer));
                  break;

                  default:
                  printf("Mouse button %d pressed at (%d,%d)\n",
                  event.button.button, event.button.x, event.button.y);

                  }
                  break;
                */
        }
}

static void fb_vnc_dokey(rfbBool down,rfbKeySym key,rfbClientPtr cl)
{
        struct gui_window *g = cur_window;

        LOG(("Processing keycode %d",key));
        if(down) {
                switch (key) {

                case XK_Page_Down:
                        fb_window_scroll(g, 0, g->height);
                        break;

                case XK_Page_Up:
                        fb_window_scroll(g, 0, -g->height);
                        break;

                case XK_Down:
                        fb_window_scroll(g, 0, 100);
                        break;

                case XK_Up:
                        fb_window_scroll(g, 0, -100);
                        break;

                case XK_Escape:
                        browser_window_destroy(g->bw);
                        break;

                case XK_Left:
                        if (history_back_available(g->bw->history))
                                history_back(g->bw, g->bw->history);
                        break;

                case XK_Right:
                        if (history_forward_available(g->bw->history))
                                history_forward(g->bw, g->bw->history);
                        break;

                default:
                        fb_rootwindow_input(g, key);
                        break;
                }
        }
}

framebuffer_t *fb_os_init(int argc, char** argv)
{
        framebuffer_t *newfb;
        int fb_width;
        int fb_height;
        int fb_depth;

        if ((option_window_width != 0) && (option_window_height != 0)) {
                fb_width = option_window_width;
                fb_height = option_window_height;
        } else {
                fb_width = 800;
                fb_height = 600;
        }

        fb_depth = option_fb_depth;
        if ((fb_depth != 32) && (fb_depth != 16) && (fb_depth != 8))
                fb_depth = 16; /* sanity checked depth in bpp */

        newfb = calloc(1, sizeof(framebuffer_t));
        if (newfb == NULL)
                return NULL;

        newfb->width = fb_width;
        newfb->height = fb_height;
        newfb->bpp = fb_depth;

        vnc_screen = rfbGetScreen(&argc, argv,
                                  newfb->width, newfb->height,
                                  8, 3, (fb_depth / 8));

        vnc_screen->frameBuffer = malloc(newfb->width * newfb->height * (fb_depth / 8));

        switch (fb_depth) {
        case 8:
                break;

        case 16:
                vnc_screen->serverFormat.trueColour=TRUE;
                vnc_screen->serverFormat.redShift = 11;
                vnc_screen->serverFormat.greenShift = 5;
                vnc_screen->serverFormat.blueShift = 0;
                vnc_screen->serverFormat.redMax = 31;
                vnc_screen->serverFormat.greenMax = 63;
                vnc_screen->serverFormat.blueMax = 31;
                break;

        case 32:
                vnc_screen->serverFormat.trueColour=TRUE;
                vnc_screen->serverFormat.redShift = 16;
                vnc_screen->serverFormat.greenShift = 8;
                vnc_screen->serverFormat.blueShift = 0;
                break;
        }

        vnc_screen->alwaysShared = TRUE;
        vnc_screen->ptrAddEvent = fb_vnc_doptr;
        vnc_screen->kbdAddEvent = fb_vnc_dokey;

        rfbInitServer(vnc_screen);

        newfb->ptr = vnc_screen->frameBuffer;
        newfb->linelen = newfb->width * (fb_depth / 8);

        //rfbUndrawCursor(vnc_screen);

        return newfb;
}

void fb_os_quit(framebuffer_t *fb)
{
}

void fb_os_input(struct gui_window *g, bool active)
{
        //SDL_Event event;
        cur_window = g;

        if (active)
                rfbProcessEvents(vnc_screen, 10000);
        else
                rfbProcessEvents(vnc_screen, 100000);
        /*
          switch (event.type) {
          case SDL_KEYDOWN:

          switch (event.key.keysym.sym) {

          case SDLK_PAGEDOWN:
          fb_window_scroll(g, 0, g->height);
          break;

          case SDLK_PAGEUP:
          fb_window_scroll(g, 0, -g->height);
          break;

          case SDLK_DOWN:
          fb_window_scroll(g, 0, 100);
          break;

          case SDLK_UP:
          fb_window_scroll(g, 0, -100);
          break;

          case SDLK_ESCAPE:
          browser_window_destroy(g->bw);
          break;

          case SDLK_LEFT:
          if (history_back_available(g->bw->history))
          history_back(g->bw, g->bw->history);
          break;

          case SDLK_RIGHT:
          if (history_forward_available(g->bw->history))
          history_forward(g->bw, g->bw->history);
          break;

          default:
          printf("The %s key was pressed!\n",
          SDL_GetKeyName(event.key.keysym.sym));
          fb_rootwindow_input(g, event.key.keysym.sym);
          break;
          }
          break;

          case SDL_MOUSEMOTION:
          fb_rootwindow_move(framebuffer, g, event.motion.x, event.motion.y, false);
          break;

          case SDL_MOUSEBUTTONDOWN:
          switch (event.button.button) {

          case SDL_BUTTON_LEFT:
          fb_rootwindow_click(g, BROWSER_MOUSE_PRESS_1,
          fb_cursor_x(framebuffer),
          fb_cursor_y(framebuffer));
          break;

          case SDL_BUTTON_RIGHT:
          fb_rootwindow_click(g, BROWSER_MOUSE_PRESS_2,
          fb_cursor_x(framebuffer),
          fb_cursor_y(framebuffer));
          break;

          case SDL_BUTTON_WHEELUP:
          fb_window_scroll(g, 0, -100);
          break;

          case SDL_BUTTON_WHEELDOWN:
          fb_window_scroll(g, 0, 100);
          break;

          case SDL_BUTTON_MIDDLE:
          default:
          printf("Mouse button %d pressed at (%d,%d)\n",
          event.button.button, event.button.x, event.button.y);

          }
          break;

          case SDL_MOUSEBUTTONUP:
          switch (event.button.button) {

          case SDL_BUTTON_LEFT:
          fb_rootwindow_click(g, BROWSER_MOUSE_CLICK_1,
          fb_cursor_x(framebuffer),
          fb_cursor_y(framebuffer));
          break;

          case SDL_BUTTON_RIGHT:
          fb_rootwindow_click(g, BROWSER_MOUSE_CLICK_2,
          fb_cursor_x(framebuffer),
          fb_cursor_y(framebuffer));
          break;

          default:
          printf("Mouse button %d pressed at (%d,%d)\n",
          event.button.button, event.button.x, event.button.y);

          }
          break;

          case SDL_QUIT:
          browser_window_destroy(g->bw);
          }
        */
}

void
fb_os_option_override(void)
{
}

/* called by generic code to inform os code of screen update */
void
fb_os_redraw(struct bbox_s *box)
{
        rfbMarkRectAsModified(vnc_screen, box->x0, box->y0, box->x1, box->y1);
}

/*
 * Local Variables:
 * c-basic-offset:8
 * End:
 */