티스토리 뷰



고객사의 요청에 따라 자사의 X Module Driver를 껐다 켰다 하는 프로그램을 작성했다.


#include <X11/extensions/XInput.h>
#include <STDIO.H>
#include <STDLIB.H>
#include <STRING.H>

int main()
{
 int      loop, num_devices;
 XDevice     *device;
 char     **extensions;
 Display     *dpy;
 XDeviceInfo    *devices;
 int      digi_id;
 int      onoff; //1 : on 2 : off
 XDeviceEnableControl  xDeviceEnableControl;
 dpy = XOpenDisplay(NULL);
 devices = XListInputDevices(dpy, &num_devices);
 for(loop = 0;loop < num_devices;loop++)
 {
  printf("%d: \"%s\" [", devices[loop].id, devices[loop].name ? devices[loop].name : "<NONAME>");
 
 if(!strcmp(devices[loop].name,"DriverName")) //if same
  digi_id = devices[loop].id;
 
 }
 printf("\n\nMyDriver id : %d\n",digi_id);
 printf("**************************************************\n");
 printf("1. on 2.off\n");
 printf("input>");
 scanf("%d",&onoff);
 device = XOpenDevice(dpy,digi_id);
 if(device)
 {
  if(onoff == 1) //on
   xDeviceEnableControl.enable = 1;
  else if(onoff == 2) //off
   xDeviceEnableControl.enable = 0;
 }
 xDeviceEnableControl.length = sizeof(xDeviceEnableControl);
 xDeviceEnableControl.control = DEVICE_ENABLE;
 XChangeDeviceControl(dpy, device, DEVICE_ENABLE,(XDeviceControl*)&xDeviceEnableControl);
 printf("device %s\n",(onoff==1)?"on":"off");
 device = XCloseDevice(dpy,device);
 return 0;
}



소스코드는 별거 없고 컴파일 시에 Xi와 X11 라이브러리를 포함시켜 줘야 한다. (gcc -lX11 -lXi)

너무 간단해서 따로 설명이 필요 없을 것 같다.. XListInputDevice로 XDeviceInfo의 정보를 얻어와서 장치들을 열거 한 후
제어하기 원하는 장치의 이름을 매핑 시켜 id를 얻어와서 XOpenDevice로 장치를 open하여 제어하는게 전부이다.

간단한 소스코드지만 무에서 유를 창조했다는 것이 기쁠 따름~~!
도움이 된 페이지 : http://www.opensource.apple.com/source/X11apps/X11apps-30/xsetpointer/xsetpointer-1.0.1/xsetpointer.c

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
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
글 보관함