Linux 版 (精华区)
发信人: xian (我想用心来点亮希望), 信区: Linux
标 题: Linux程式设计入门-gpm
发信站: 紫 丁 香 (Sun May 2 16:29:24 1999), 转信
网络工作室--知识库:编程技术:Unix编程:Linux程式设计入门:
Linux程式设计入门-gpm
Linux程式设计入门-gpm
gpm是Linuxconsole下的滑鼠驱动程式,它主要提供文字模式下的滑鼠事件处
理。Linux下文字界面的滑鼠几乎都是用gpm来处理。
gpm的文件在gpm原始码的doc目录中,详细的说明可叁考该目录中的文件gpm
programmingguide,此处只提供给您KickStart的一些技巧及一些叁考说明。
特别注意到以下的范例,需在console下执行,不可在XWindow的Terminal下
执行。
范例:gpm_mouse.c
gpm原始码中有一个mev.c的程式,主要用来测试滑鼠状态。事实上,mev.c是个
很好的范例,本范例便是取自mev.c,经过简化修改而来。
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<gpm.h>
voidmain(intargc,char**argv)
{
fd_setreadset;
Gpm_Eventevent;
Gpm_Connectconn;
conn.eventMask=~0;
conn.defaultMask=~GPM_HARD;
conn.maxMod=0;
conn.minMod=0;
if(Gpm_Open(&conn,0)==-1){
printf("Cannotopenmouseconnection\n");
exit(1);
}
while(1){
FD_ZERO(&readset);
FD_SET(gpm_fd,&readset);
select(gpm_fd+1,&readset,0,0,0);
if(FD_ISSET(gpm_fd,&readset)){
if(Gpm_GetEvent(&event)>0){
printf("mouse:event0x%02X,at%2i%2i(delta%2i%2i),"
"button%i,modifiers0x%02X\r\n",
event.type,
event.x,event.y,
event.dx,event.dy,
event.buttons,
event.modifiers
);
}
}
}
while(Gpm_Close());
}
编译
gcc-ogpm_mousegpm_mouse.c-lgpm
检验结果
mouse:event0x01,at151(delta-2-1),button0,modifiers0x00
mouse:event0x01,at141(delta-10),button0,modifiers0x00
mouse:event0x01,at131(delta-10),button0,modifiers0x00
资料结构
typedefstructGpm_Connect{
unsignedshorteventMask,defaultMask;
unsignedshortminMod,maxMod;
intpid;
intvc;
}Gpm_Connect;
enumGpm_Etype{
GPM_MOVE=1,
GPM_DRAG=2,/*exactlyoneofthebareonesisactiveatatime
*/
GPM_DOWN=4,
GPM_UP=8,
GPM_SINGLE=16,/*atmostoneinthreeisset*/
GPM_DOUBLE=32,
GPM_TRIPLE=64,/*WARNING:Idependonthevalues*/
GPM_MFLAG=128,/*motionduringclick?*/
GPM_HARD=256,/*ifsetinthedefaultMask,forcean
alreadyusedeventtopassovertoanotherhandler*/
GPM_ENTER=512,/*enterevent,userinRoi's*/
GPM_LEAVE=1024/*leaveevent,usedinRoi's*/
};
typedefstructGpm_Event{
unsignedcharbuttons,modifiers;/*trytobeamultipleof4*/
unsignedshortvc;
shortdx,dy,x,y;
enumGpm_Etypetype;
intclicks;
enumGpm_Marginmargin;
}Gpm_Event;
typedefintGpm_Handler(Gpm_Event*event,void*clientdata);
函数宣告
intGpm_Open(Gpm_Connect*CONN,intFLAGS);
intGpm_Close(void);
intGpm_GetEvent(Gpm_Event*EVENT);
intGpm_Getc(FILE*fp);
#defineGpm_Getchar()Gpm_Getc(stdin)
intGpm_Wgetch();
#defineGpm_Getch()(Gpm_Wgetch(NULL))
intGpm_Repeat(intmillisecs);
intGpm_DrawPointer(intX,intY,intFD);
intGPM_DRAWPOINTER(Gpm_Event*EPTR;)
intGpm_FitValuesM(int*X,int*Y,intMARGIN);
intGpm_FitValues(X,Y);
Gpm_FitEvent(EPTR);
char*Gpm_GetLibVersion(int*where);
char*Gpm_GetServerVersion(int*where);
intGpm_GetSnapshot(Gpm_Event*ePtr);
OKSTATION,Webmaster,BrianLin
admin@studio.openunix.org
--
※ 来源:.紫 丁 香 bbs.hit.edu.cn.[FROM: 202.118.239.115]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.014毫秒