⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kegui.c

📁 EGui是一个开源的图形系统软件,类似于QT/Embedded、GTK-FB、MicroWindow。目标是嵌入式平台整合解 决方案。基于Linux Framebuffer 设备驱动上实现。有完
💻 C
字号:
/******************************************************** * EGui code,LGPL * Function : Egui input event handling and windows management  * Author: asmcos@hotmail.com * Data : 2005-08-24 * $Id: kegui.c,v 1.11 2006/03/23 02:03:23 hjs Exp $ ********************************************************/#include "kegui.h"#include "event.c"extern struct fb_info *registered_fb[FB_MAX];struct fb_info * efb_info;short cursor_x,cursor_y;static int focus_pid = 0;LIST_HEAD(focus_window);/* window id */unsigned char	idmap[MAXID];   /* windows id use list,save window's pid*/short   max_width,max_height;EGui_FBinfo fbinfo;static spinlock_t eguilock = SPIN_LOCK_UNLOCKED;MODULE_AUTHOR("Asmcos");MODULE_DESCRIPTION("Egui kernel driver for input event and windows manage ");MODULE_LICENSE("GPL");#define EGUI_MAJOR   240#define EGUI_NAME    "egui"/*  * window list operate start *//* create a new window * add the new window into list */int add_newqueue ( EGui_Window *window){  window_list * list;  /* alloc a node for the new window */  window->window_list = kmalloc (sizeof(window_list),GFP_KERNEL);  if ( window->window_list == NULL)    {      printk ("malloc window_list error!\n");      return -1;    }  list = window->window_list;  /* set list */  list->window = window;	  list->width_in   = kmalloc (max_width,GFP_KERNEL);  list->height_in  = kmalloc (max_height,GFP_KERNEL);  if (list->width_in == NULL && list->height_in == NULL)    {      printk ("EGui kmalloc width,height error!\n");      return -1;    }  /* initialize wait queue ,copy a new wait to event_wait*/  init_waitqueue_head(&list->event_wait);  /* set all erea as empty */  memset(list->width_in,0,max_width);  memset(list->height_in,0,max_height);  /* set erea that is inside as 1 */  memset(list->width_in  + window->x,1,window->width);  memset(list->height_in + window->y,1,window->height);  list->pid = window->pid;  list->id  = window->id;  list_add ((struct list_head *)(window->window_list),&focus_window);  return 0;}/* return : * 0 focus is changed. it needs changing map * 1 unchanged.  */int change_list (window_list * list){  /* root window don't change */  if (list->id == 0xFF)    return 1;  if (focus_window.next != (struct list_head *)list)    {      list_del ((struct list_head *)list);      list_add ((struct list_head *)list,&focus_window);      return 0;    }  return 1;}/* return : * 0: None of window is found * 1: A window is found.  */window_list * find_list_by_xy (short x,short y){  window_list *list;  list = (window_list *)focus_window.next;  /* No any window */  if ((focus_window.next == &focus_window) || (list->window == NULL) )    return NULL;   /* is point (x,y) within the window */  while ((list->width_in[x] + list->height_in[y]) != 2)    {      list = (window_list *)list->next;      if (list == (window_list *)&focus_window)	return NULL;          }  return list;}window_list * find_list_by_pid (int pid){  window_list *list;  list = (window_list *)focus_window.next;  /* There isnt any window */  if ((focus_window.next == &focus_window) || (list->window == NULL) )    return NULL;   /* search the window which id is pid */  while (list->pid != pid)    {      list = (window_list *)list->next;      if (list == (window_list *)&focus_window)	return NULL;          }  return list;}intnew_window ( void __user * argp){  short i;  EGui_Window *newwindow = (EGui_Window * )argp;  /* root window */  if (newwindow->window_type == EGUI_WINDOW_ROOT)    {      if (idmap [0] == 0xFF)	{	  printk ("EGui: had exist ROOT window\n");	  return -1;	}      idmap [0] = 0xFF;      newwindow->id = 0xFF;      add_newqueue (newwindow);      return 0;    }  /* other window */  for ( i = 1; i< MAXID; i++)    {      if ( idmap[i] == 0)	{	  newwindow->id  = i;  	  focus_pid      = newwindow->pid;     	  idmap [i]      = i;	  add_newqueue (newwindow);	  break;	}    }  return 0;}intclose_window ( void __user * argp){   EGui_Window * closewindow = (EGui_Window * )argp;  window_list * list;  idmap[ closewindow->id ] = 0 ;  list = closewindow->window_list;  list_del ((struct list_head *)closewindow->window_list);  kfree (list->width_in);  kfree (list->height_in);  kfree (closewindow->window_list);  return 0;}/* window handler end */static integui_open(struct inode *inode, struct file *file){  printk ("Open ok\n");    return 0;}static ssize_tegui_write(struct file *fp, const char *bp, size_t count, loff_t *ppos){  printk("DO NOT WRITE!\n");    return 0;}static ssize_tegui_read(struct file *fp, char *bp, size_t count, loff_t *ppos){  printk("EGui read function ....(..) \n");    return 0;}static integui_release(struct inode *inode, struct file *file){  window_list * list;  printk ("EGui release ....\n");    list = find_list_by_pid (current->pid);  /* some windows is closed,but maybe list is exist */  if (list != NULL)    {      if (list->id == 0xFF)	{			/* root window */	  idmap [0] = 0;	}      else	{	  idmap[ list->id ] = 0 ;	}      list_del ((struct list_head *)list);      kfree (list->width_in);      kfree (list->height_in);      kfree (list);    }  return 0;}static integui_ioctl(struct inode *inode, struct file *file,	   unsigned int cmd, unsigned long arg){  void __user * argp = (void __user * )arg;   switch (cmd)    {    case EGUI_GET_FBINFO:      return copy_to_user (argp,&fbinfo,sizeof(EGui_FBinfo))?-1:0;          case EGUI_NEWWINDOW:      return new_window (argp);          case EGUI_CLOSEWINDOW:      return close_window (argp);    case EGUI_EVENT:      return get_event (argp);    case EGUI_REPORT_EVENT:      return report_event (argp);    case EGUI_REPORT_MOVE:      return report_move (argp);          default:      return -1;        }  return 0;}static void egui_input_event(struct input_handle *handle, 			     unsigned int type, unsigned int code, int value){  unsigned long flags;  spin_lock_irqsave(&eguilock, flags);  egui_event (type,code,value);  spin_unlock_irqrestore(&eguilock, flags);}static struct input_handle *egui_input_connect(struct input_handler *handler, 		    struct input_dev *dev, struct input_device_id *id){  struct input_handle *handle;  if (!(handle = kmalloc(sizeof(struct input_handle), GFP_KERNEL)))    return NULL;  memset(handle, 0, sizeof(struct input_handle));  handle->dev     = dev;  handle->handler = handler;  handle->name    = "egui input";  input_open_device(handle);  return handle;}static void egui_input_disconnect(struct input_handle *handle){  input_close_device(handle);  kfree(handle);}/************************* * input end * **************************//************************* * egui windows start * **************************/int get_fbinfo (void){  int i;  struct fb_var_screeninfo *fb_var;  for (i=0;i<FB_MAX;i++)    {      efb_info = registered_fb[i];      if (efb_info)	{	  printk ("Framebuffer mode: %dx%d-%dbpp device:  /dev/fb%d.\n",efb_info->var.xres,		  efb_info->var.yres,efb_info->var.bits_per_pixel,i);	 	  fb_var = &efb_info->var;	  	  fbinfo.screen_width    = fb_var->xres;  	  fbinfo.screen_height   = fb_var->yres;	  fbinfo.bpp             = fb_var->bits_per_pixel;           	  fbinfo.Egui_phyaddress = (unsigned char *)((efb_info->fix.smem_start) & 0x3FF);	  fbinfo.smem_len        = (unsigned char *) efb_info->fix.smem_len;	  fbinfo.dev             = i;	  fbinfo.p_bpp           = fbinfo.bpp / 8;	  fbinfo.p_width         = fbinfo.screen_width * fbinfo.p_bpp;      	  fbinfo.p_height        = fbinfo.screen_height;	  	 	  fbinfo.red_length         = fb_var->red.length;	  fbinfo.green_length       = fb_var->green.length;	  fbinfo.blue_length        = fb_var->blue.length;	  fbinfo.red_offset         = fb_var->red.offset;	  fbinfo.green_offset       = fb_var->green.offset;	  fbinfo.blue_offset        = fb_var->blue.offset;		  return 0;	}    }    return -1;}voidbase_init (void){  int i;    for (i=0;i<MAXID;i++)    {      idmap [i] = 0;    }    max_width  = fbinfo.screen_width;  max_height = fbinfo.screen_height;  /* when initial ,set cursor to middle position*/  cursor_x   = max_width / 2;  cursor_y   = max_height / 2;  return;}/************************* * egui windows end * **************************/static struct file_operations egui_fops =  {    owner:		THIS_MODULE,    write:		egui_write,    read:		egui_read,    ioctl:		egui_ioctl,    open:		egui_open,    release:	        egui_release,         };static struct input_device_id egui_input_ids[] = {  { .driver_info = 1 },	/* Matches all devices */  { },			/* Terminating zero entry */};MODULE_DEVICE_TABLE(input, egui_input_ids);static struct input_handler egui_input_handler = {  .event      =	egui_input_event,  .connect    =	egui_input_connect,  .disconnect =	egui_input_disconnect,  .name       =	"egui_input",  .id_table   =	egui_input_ids,};int __init egui_init (void){  int retval;  /* 1.get information */  get_fbinfo ();  /* 2.set idmap */  base_init ();    retval = register_chrdev(EGUI_MAJOR, EGUI_NAME, &egui_fops);  if(retval < 0)    {      printk("Could not register Egui device\n");      return 0;    }  /* 3. initial event queue */  event_init();  /* 4. register input,    * system maybe invoke egui_input_event   */  input_register_handler(&egui_input_handler);  printk ("Egui runing...\n");  return 0;}void __exitegui_exit (void){	  unregister_chrdev(EGUI_MAJOR, EGUI_NAME);  input_unregister_handler(&egui_input_handler);  printk ("Egui exit\n");  return ;}module_init(egui_init);module_exit(egui_exit);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -