PageRenderTime 262ms CodeModel.GetById 100ms app.highlight 9ms RepoModel.GetById 112ms app.codeStats 0ms

/src/backend/native/ftk_backend_fb.c

http://ftk.googlecode.com/
C | 119 lines | 103 code | 15 blank | 1 comment | 25 complexity | 85fe372134434e4ffb20713df4e86500 MD5 | raw file
  1#include "ftk_log.h"
  2#include "ftk_globals.h"
  3#include "ftk_display_fb.h"
  4#include "ftk_source_input.h"
  5#include "ftk_wnd_manager.h"
  6#include "ftk_source_tslib.h"
  7#include "ftk_source_ps2mouse.h"
  8
  9static Ret ftk_init_input(void)
 10{
 11	char filename[260] = {0};
 12	const char* tsdev = NULL;
 13	FtkSource* source = NULL;
 14	struct dirent* iter = NULL;
 15	const char* extra_input = NULL;
 16	DIR* dir = opendir("/dev/input");
 17	
 18	return_val_if_fail(dir != NULL, RET_FAIL);
 19
 20	tsdev = getenv("FTK_TSLIB_FILE") ? getenv("FTK_TSLIB_FILE") : FTK_TSLIB_FILE;
 21	while((iter = readdir(dir)) != NULL)
 22	{
 23		if(iter->d_name[0] == '.') continue;
 24		if(!(iter->d_type & DT_CHR)) continue;
 25
 26		ftk_snprintf(filename, sizeof(filename), "/dev/input/%s", iter->d_name);
 27#ifdef USE_TSLIB
 28		if(strcmp(filename, tsdev) == 0)
 29		{
 30			/*skip tsdev now, open it later.*/
 31			continue;
 32		}
 33		else
 34#endif
 35		if(strcmp(filename, "/dev/input/mice") == 0)
 36		{
 37			int max_x = ftk_display_width(ftk_default_display());
 38			int max_y = ftk_display_height(ftk_default_display());
 39
 40			source = ftk_source_ps2mouse_create(filename, 
 41				(FtkOnEvent)ftk_wnd_manager_queue_event_auto_rotate, ftk_default_wnd_manager(), max_x, max_y);
 42		}
 43		else
 44		{
 45			source = ftk_source_input_create(filename, 
 46				(FtkOnEvent)ftk_wnd_manager_queue_event_auto_rotate, ftk_default_wnd_manager());
 47		}
 48		if(source != NULL)
 49		{
 50			ftk_sources_manager_add(ftk_default_sources_manager(), source);
 51		}
 52	}
 53	closedir(dir);
 54
 55#ifdef USE_TSLIB
 56	source = ftk_source_tslib_create(tsdev, 
 57				(FtkOnEvent)ftk_wnd_manager_queue_event_auto_rotate, ftk_default_wnd_manager());
 58	if(source != NULL)
 59	{
 60		ftk_sources_manager_add(ftk_default_sources_manager(), source);
 61	}
 62	ftk_logd("%s: tsdev %s source=%p\n", __func__, tsdev, source);
 63#endif
 64
 65	extra_input = getenv("FTK_EXTRA_INPUT");
 66	if(extra_input != NULL)
 67	{
 68		source = ftk_source_input_create(filename, 
 69				(FtkOnEvent)ftk_wnd_manager_queue_event_auto_rotate, ftk_default_wnd_manager());
 70		if(source != NULL)
 71		{
 72			ftk_sources_manager_add(ftk_default_sources_manager(), source);
 73
 74			ftk_logd("add %s input device\n", extra_input);
 75		}
 76	}
 77
 78	return RET_OK;
 79}
 80
 81static const char* fb_dev[] =
 82{
 83	FTK_FB_NAME,
 84	"/dev/fb0",
 85	"/dev/graphic/fb0",
 86	NULL
 87};
 88
 89Ret ftk_backend_init(int argc, char* argv[])
 90{
 91	ftk_set_display(ftk_display_fb_create(getenv("FTK_FB_NAME") ? getenv("FTK_FB_NAME") : FTK_FB_NAME));
 92	
 93	if(ftk_default_display() == NULL)
 94	{
 95		size_t i = 0;
 96		for(i = 0; fb_dev[i] != NULL; i++)
 97		{
 98			ftk_set_display(ftk_display_fb_create(fb_dev[i]));
 99			if(ftk_default_display() != NULL)
100			{
101				break;
102			}
103			else
104			{
105				ftk_loge("open %s failed.\n", fb_dev[i]);
106			}
107		}
108	}
109
110	if(ftk_default_display() == NULL)
111	{
112		ftk_loge("open display failed %s.\n", FTK_FB_NAME);
113		exit(0);
114	}
115	ftk_init_input();
116
117	return RET_OK;
118}
119