2009-02-11 03:20:02 +03:00
|
|
|
/*
|
|
|
|
* 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 <SDL/SDL.h>
|
|
|
|
|
|
|
|
#include "css/css.h"
|
|
|
|
#include "desktop/gui.h"
|
|
|
|
#include "desktop/options.h"
|
|
|
|
#include "utils/messages.h"
|
2009-02-12 12:51:47 +03:00
|
|
|
#include "desktop/history_core.h"
|
2009-03-11 00:45:54 +03:00
|
|
|
#include "desktop/textinput.h"
|
2009-02-11 03:20:02 +03:00
|
|
|
|
|
|
|
#include "framebuffer/fb_gui.h"
|
2009-03-11 00:45:54 +03:00
|
|
|
#include "framebuffer/fb_tk.h"
|
2009-02-11 03:20:02 +03:00
|
|
|
#include "framebuffer/fb_plotters.h"
|
|
|
|
#include "framebuffer/fb_frontend.h"
|
2009-02-11 23:55:50 +03:00
|
|
|
#include "framebuffer/fb_cursor.h"
|
2009-02-26 21:58:03 +03:00
|
|
|
#include "framebuffer/fb_options.h"
|
2009-02-11 03:20:02 +03:00
|
|
|
|
|
|
|
#include "utils/log.h"
|
|
|
|
|
|
|
|
static SDL_Surface *sdl_screen;
|
|
|
|
|
|
|
|
framebuffer_t *fb_os_init(int argc, char** argv)
|
|
|
|
{
|
|
|
|
framebuffer_t *newfb;
|
2009-02-26 21:58:03 +03:00
|
|
|
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 */
|
2009-02-11 03:20:02 +03:00
|
|
|
|
|
|
|
newfb = calloc(1, sizeof(framebuffer_t));
|
|
|
|
if (newfb == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
|
|
|
|
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
atexit(SDL_Quit);
|
|
|
|
|
2009-02-26 21:58:03 +03:00
|
|
|
newfb->width = fb_width;
|
|
|
|
newfb->height = fb_height;
|
|
|
|
newfb->bpp = fb_depth;
|
2009-02-11 03:20:02 +03:00
|
|
|
|
|
|
|
sdl_screen = SDL_SetVideoMode(newfb->width,
|
2009-03-11 00:45:54 +03:00
|
|
|
newfb->height,
|
|
|
|
newfb->bpp,
|
|
|
|
SDL_SWSURFACE);
|
2009-02-11 03:20:02 +03:00
|
|
|
|
|
|
|
if ( sdl_screen == NULL ) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Unable to set video: %s\n", SDL_GetError());
|
|
|
|
free(newfb);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
newfb->ptr = sdl_screen->pixels;
|
|
|
|
newfb->linelen = sdl_screen->pitch;
|
|
|
|
|
2009-02-11 23:55:50 +03:00
|
|
|
SDL_ShowCursor(SDL_DISABLE);
|
|
|
|
|
2009-02-11 03:20:02 +03:00
|
|
|
return newfb;
|
|
|
|
}
|
|
|
|
|
|
|
|
void fb_os_quit(framebuffer_t *fb)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-03-11 00:45:54 +03:00
|
|
|
void fb_os_input(fbtk_widget_t *root, bool active)
|
2009-02-11 03:20:02 +03:00
|
|
|
{
|
2009-02-18 17:26:38 +03:00
|
|
|
int got_event;
|
2009-02-11 03:20:02 +03:00
|
|
|
SDL_Event event;
|
2009-03-11 00:45:54 +03:00
|
|
|
int nskey;
|
2009-02-11 03:20:02 +03:00
|
|
|
|
2009-02-12 01:36:07 +03:00
|
|
|
if (active)
|
2009-02-18 17:26:38 +03:00
|
|
|
got_event = SDL_PollEvent(&event);
|
2009-02-12 01:36:07 +03:00
|
|
|
else
|
2009-02-18 17:26:38 +03:00
|
|
|
got_event = SDL_WaitEvent(&event);
|
|
|
|
|
|
|
|
/* Do nothing if there was no event */
|
|
|
|
if (got_event == 0)
|
|
|
|
return;
|
2009-02-11 03:20:02 +03:00
|
|
|
|
|
|
|
switch (event.type) {
|
|
|
|
case SDL_KEYDOWN:
|
2009-02-11 23:55:50 +03:00
|
|
|
|
2009-03-11 00:45:54 +03:00
|
|
|
switch (event.key.keysym.sym) {
|
|
|
|
case SDLK_PAGEDOWN:
|
|
|
|
nskey = KEY_PAGE_DOWN;
|
|
|
|
break;
|
2009-02-12 17:16:40 +03:00
|
|
|
|
2009-03-11 00:45:54 +03:00
|
|
|
case SDLK_PAGEUP:
|
|
|
|
nskey = KEY_PAGE_UP;
|
|
|
|
break;
|
2009-02-12 17:16:40 +03:00
|
|
|
|
2009-03-11 00:45:54 +03:00
|
|
|
case SDLK_LEFT:
|
|
|
|
nskey = KEY_LEFT;
|
|
|
|
break;
|
2009-02-11 23:55:50 +03:00
|
|
|
|
2009-03-11 00:45:54 +03:00
|
|
|
case SDLK_RIGHT:
|
|
|
|
nskey = KEY_RIGHT;
|
|
|
|
break;
|
2009-02-12 12:51:47 +03:00
|
|
|
|
2009-03-11 00:45:54 +03:00
|
|
|
case SDLK_DOWN:
|
|
|
|
nskey = KEY_DOWN;
|
|
|
|
break;
|
2009-02-12 12:51:47 +03:00
|
|
|
|
2009-03-11 00:45:54 +03:00
|
|
|
case SDLK_UP:
|
|
|
|
nskey = KEY_UP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
nskey = event.key.keysym.sym;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fbtk_input(root, nskey);
|
|
|
|
|
|
|
|
break;
|
2009-02-11 03:20:02 +03:00
|
|
|
|
2009-02-11 23:55:50 +03:00
|
|
|
case SDL_MOUSEMOTION:
|
2009-03-11 00:45:54 +03:00
|
|
|
fbtk_move_pointer(root, event.motion.x, event.motion.y, false);
|
2009-02-11 23:55:50 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
2009-02-12 17:16:40 +03:00
|
|
|
switch (event.button.button) {
|
|
|
|
|
|
|
|
case SDL_BUTTON_LEFT:
|
2009-03-11 00:45:54 +03:00
|
|
|
fbtk_click(root, BROWSER_MOUSE_PRESS_1);
|
2009-02-12 17:16:40 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_BUTTON_RIGHT:
|
2009-03-11 00:45:54 +03:00
|
|
|
fbtk_click(root, BROWSER_MOUSE_PRESS_2);
|
2009-02-12 17:16:40 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_BUTTON_WHEELUP:
|
2009-03-11 00:45:54 +03:00
|
|
|
fbtk_input(root, KEY_UP);
|
|
|
|
break;
|
2009-02-12 17:16:40 +03:00
|
|
|
|
|
|
|
case SDL_BUTTON_WHEELDOWN:
|
2009-03-11 00:45:54 +03:00
|
|
|
fbtk_input(root, KEY_DOWN);
|
|
|
|
break;
|
2009-02-12 17:16:40 +03:00
|
|
|
|
|
|
|
}
|
2009-02-11 23:55:50 +03:00
|
|
|
break;
|
|
|
|
|
2009-02-13 20:34:18 +03:00
|
|
|
case SDL_MOUSEBUTTONUP:
|
|
|
|
switch (event.button.button) {
|
|
|
|
|
|
|
|
case SDL_BUTTON_LEFT:
|
2009-03-11 00:45:54 +03:00
|
|
|
fbtk_click(root, BROWSER_MOUSE_CLICK_1);
|
2009-02-13 20:34:18 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_BUTTON_RIGHT:
|
2009-03-11 00:45:54 +03:00
|
|
|
fbtk_click(root, BROWSER_MOUSE_CLICK_2);
|
2009-02-13 20:34:18 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-02-11 03:20:02 +03:00
|
|
|
case SDL_QUIT:
|
2009-03-11 00:45:54 +03:00
|
|
|
netsurf_quit = true;
|
|
|
|
break;
|
|
|
|
}
|
2009-02-11 03:20:02 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fb_os_option_override(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-02-11 23:55:50 +03:00
|
|
|
/* called by generic code to inform os code of screen update */
|
2009-02-11 03:20:02 +03:00
|
|
|
void
|
2009-02-11 23:55:50 +03:00
|
|
|
fb_os_redraw(struct bbox_s *box)
|
2009-02-11 03:20:02 +03:00
|
|
|
{
|
2009-02-11 23:55:50 +03:00
|
|
|
SDL_UpdateRect(sdl_screen,
|
|
|
|
box->x0, box->y0,
|
|
|
|
box->x1 - box->x0, box->y1 - box->y0);
|
2009-02-11 03:20:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset:8
|
|
|
|
* End:
|
|
|
|
*/
|
|
|
|
|