· KLDP.org · KLDP.net · KLDP Wiki · KLDP BBS ·
SetHHK InXUsing Hotplug

Hotplug¸¦ ÀÌ¿ëÇØ¼­ HappyHacking Keyboard Ű¸Ê ÁöÁ¤Çϱâ

ÀÌ ±ÛÀº ¸®´ª½ºÀÇ Hotplug ±â´ÉÀ» ÀÌ¿ëÇØ¼­ X Window¿¡¼­ »ç¿ëÀÚ°¡ ÁöÁ¤ÇÑ Å°¸Ê, Xmodmap ¼³Á¤ÆÄÀÏ,ÇØÇÇÇØÅ· Űº¸µåÀÇ Å°¸ÊÀ» Àû¿ë½ÃŰ´Â ¹æ¹ýÀ» ¼³¸íÇÕ´Ï´Ù. Á¦°¡ »ç¿ëÇÏ´Â µ¥ºñ¾È ½Ãµå Debian Sid¸¦ ±âÁØÀ¸·Î ¼³¸íÇÕ´Ï´Ù.

Àú´Â Thinkpad T42 ³ëÆ®ºÏ¿¡ HHK¸¦ »ç¿ëÇϰí ÀÖ½À´Ï´Ù. HHKÀÇ ¿ø·¡ Ű¸Ê¿¡ Àͼ÷ÇØÁöÁú ¾Ê¾Æ¼­ ºÎµæÀÌ tilde(~)Ű¿Í Esc۸¦ ¾Æ¿¹ ŰĸÀ» ¹Ù²ã³¢¿ì°í, Caps_Lock ÀÚ¸®¿¡ ÀÖ´Â HHKÀÇ Control۸¦ EscapeŰ·Î ¹èÁ¤Çؼ­ »ç¿ëÇϰí ÀÖ½À´Ï´Ù. AltŰ¿Í ±× ¿·ÀÇ »ç°¢Çü۵µ ¹Ù²ã¼­ ´Ù¸¥ Űº¸µåµéó·³ Control, Alt ¼ø¼­·Î ¹èÁ¤Çؼ­ »ç¿ëÇϰí ÀÖ½À´Ï´Ù. HHK¸¦ ºÙÀÏ ¶§¸¶´Ù º¯°æµÈ ۸ÊÀ» ¼³Á¤ÇϱⰡ ¹ø°Å·Î¿ö¼­ Hotplug¸¦ ÀÌ¿ëÇØ¼­ ÀÚµ¿À¸·Î Àνĵǵµ·Ï ¼³Á¤ÇغýÀ´Ï´Ù.

(¾Æ·¡¿¡ ¼³¸íÇÏ´Â ¹æ¹ýÀÌ hotplug¸¦ Á¦´ë·Î »ç¿ëÇÏ´Â °ÍÀÎÁö Àß ¸ð¸£°Ú³×¿ä. º¸ÃæÇØ¾ß µÉ ºÎºÐÀº ÁöÀûÇØÁÖ¼¼¿ä.)

Hotplug¿¡ ´ëÇÑ ±¸Ã¼ÀûÀÎ ¼³¸íÀº LinuxHotplug ÆäÀÌÁö¸¦ Âü°íÇϼ¼¿ä.


2. ¸ÕÀú,

  • ½Ã½ºÅÛÀÌ hotplug±â´ÉÀ» »ç¿ëÇϰí ÀÖ¾î¾ß ÇÕ´Ï´Ù.
  • pythonÀÌ ¼³Ä¡µÇ¾î ÀÖ¾î¾ß ÇÕ´Ï´Ù.
  • ¹°·Ð HHK´Â ÁغñÇØ¾ß °ÚÁÒ.

Hotplug°¡ »ç¿ëÇÏ´Â µð·ºÅ丮µéÀº,
  • /etc/hotplug
  • /etc/hotplug.d

3. ½ºÅ©¸³Æ®¸¦ ÀÛ¼ºÇÕ´Ï´Ù.

/etc/hotplug_device.d µð·ºÅ丮¸¦ ¸¸µì´Ï´Ù.
shell > mkdir /etc/hotplug_device.d

´ÙÀ½ ½ºÅ©¸³Æ®¸¦ ÀÛ¼ºÇÕ´Ï´Ù.

/etc/hotplug.d/usb/usbhid.hotplug
#!/usr/bin/env python import os, glob, sys, sre DIR_HOTPLUG_DEVICE = "/etc/hotplug_device.d" if not os.path.isdir(DIR_HOTPLUG_DEVICE) : sys.exit(1) sys.path.append(DIR_HOTPLUG_DEVICE) for i in glob.glob("%s/*_usb.py" % DIR_HOTPLUG_DEVICE) : __device_filename = sre.compile(".py$").sub("", os.path.basename(i)) __module = __import__(__device_filename, globals(), locals(), [__device_filename,]) DEVICE = getattr(__module, "device") DEVICE().do()

/etc/hotplug_device.d/BASIC_USB.py
import os, sys, pickle class device : LOG_HOTPLUG_DEVICE = "/var/run/hotplug_device.pkl" ACTION = "" DEVPATH_REMOVE = "" DEVPATH = "" PRODUCT = "" MANUFACTURER = "" def __init__ (self) : self.get_info() def get_info (self) : self.ACTION = os.getenv("ACTION") self.DEVPATH = "/sys%s" % os.getenv("DEVPATH") self.DEVPATH_REMOVE = os.sep.join(self.DEVPATH.split(os.sep)[:-2]) if not os.path.isdir(self.DEVPATH) : raise RuntimeError, "devpath, %s does not exists" % self.DEVPATH # get PRODUCT name and get MANUFACTURER name __file_product = "%s/product" % os.sep.join(self.DEVPATH.split(os.sep)[:-1]) __file_manufacture = "%s/manufacturer" % os.sep.join(self.DEVPATH.split(os.sep)[:-1]) if os.path.isfile(__file_product) : self.PRODUCT = "".join(open(__file_product, "r").readlines()).strip() if os.path.isfile(__file_manufacture) : self.MANUFACTURER = "".join(open(__file_manufacture, "r").readlines()).strip() def check_add (self) : pass def check_remove (self) : pass def do (self) : data = self.get_data() if self.ACTION == "add" : if self.check_add() : self.add() data[self.DEVPATH_REMOVE] = \ (self.PRODUCT, self.MANUFACTURER, self.ACTION,) self.store_data(data) return True elif self.ACTION == "remove" : if self.check_remove() : self.remove() del(data[self.DEVPATH]) self.store_data() return True return False def add (self) : self.store_data() def remove (self) : pass def store_data (self, data) : """ store information for removing this devices. """ __fd_pk = open(self.LOG_HOTPLUG_DEVICE, "w") pickle.dump(data, __fd_pk) __fd_pk.close() def get_data (self) : if not os.path.isfile(self.LOG_HOTPLUG_DEVICE) : __data = dict() else : __fd_pk = open(self.LOG_HOTPLUG_DEVICE, "r") try : __data = pickle.load(__fd_pk) except : __data = dict() return __data def run_external_command (self, cmd) : pi, po, pe = os.popen3(cmd) return (pi, po, pe,)

/etc/hotplug_device.d/HHK_usb.py
import os, sys, pickle import __BASIC_USB__ XMODMAP = "/usr/bin/X11/xmodmap" MAPFILE_BASIC = "/usr/local/etc/xmodmap/basic" MAPFILE_HHK = "/usr/local/etc/xmodmap/HHK" MAPFILE_TP = "/usr/local/etc/xmodmap/TP" class device (__BASIC_USB__.device) : KEY_PRODUCT = "PFU-65 USB Keyboard" KEY_MANUFACTURER = "Chicony" def check_add (self) : # if this attached device is keyboard and is HHK. if not self.PRODUCT == self.KEY_PRODUCT or \ not self.MANUFACTURER == self.KEY_MANUFACTURER : return False return True def check_remove (self) : if not os.path.isfile(self.LOG_HOTPLUG_DEVICE) : return False __data = self.get_data() return self.DEVPATH in __data def add (self) : self.xmodmap(MAPFILE_BASIC) self.xmodmap(MAPFILE_HHK) def remove (self) : self.xmodmap(MAPFILE_BASIC) self.xmodmap(MAPFILE_TP) def xmodmap (self, mapfile) : self.run_external_command("/bin/su spike -c '%s -display :0.0 %s'" % (XMODMAP, mapfile))

À§¿¡¼­
MAPFILE_BASIC = "/usr/local/etc/xmodmap/basic" MAPFILE_HHK = "/usr/local/etc/xmodmap/HHK" MAPFILE_TP = "/usr/local/etc/xmodmap/TP"
¶ó°í Á¤ÀǵǾî ÀÖ´Â ºÎºÐ¿¡¼­ MAPFILE_HHKÀº HHKÀÇ xmodmapÀ», MAPFILE_TP´Â HHK¸¦ »ç¿ëÇÏÁö ¾ÊÀ» °æ¿ì »ç¿ëÇÒ xmodmap ÆÄÀÏÀ», MAPFILE_BASICÀº µÎ°¡Áö ¸ðµÎ ÇÊ¿ä·Î ÇÏ´Â ºÎºÐÀ» ³Öµµ·Ï ÇÕ´Ï´Ù. À§ ½ºÅ©¸³Æ®¿¡ ³ª¿ÍÀÖ´Â ´ë·Î, MAPFILE_BASICÀÌ ¸ÕÀú ÀоîµéÀ̱⠶§¹®¿¡ MAPFILE_BASIC¿¡´Â MAPFILE_HHK, MAPFILE_TP°¡ ¸ðµÎ ¹Ì¸® ÀоîµéÀÌ´Â °øÅëÀûÀÎ ¼³Á¤À» ÁöÁ¤ÇÏ¸é µË´Ï´Ù.

±×¸®°í /etc/hotplug_device.d/HHK_usb.pyÀÇ ¸¶Áö¸· ºÎºÐ
def xmodmap (self, mapfile) : self.run_external_command("/bin/su spike -c '%s -display :0.0 %s'" % (XMODMAP, mapfile))
¿¡¼­ spike¸¦ X Window¸¦ »ç¿ëÇÏ´Â »ç¿ëÀÚ id·Î ¹Ù²ãÁÖ¸é µË´Ï´Ù. (»ç¿ëÀÚ¸¦ ÁöÁ¤ÇÏÁö ¾Ê°í xmodmapÀ» ÁöÁ¤ÇÒ ¼ö ÀÖ´Â ¹æ¹ýÀÌ ÀÖÀ¸¸é ¾Ë·ÁÁÖ¼¼¿ä.)

¸¶Áö¸·À¸·Î
shell > chmod 700 /etc/hotplug.d/usb/usbhid.hotplug

4. Å×½ºÆ®,

À§ÀÇ ½ºÅ©¸³Æ®¸¦ ¸ðµÎ Á¦ À§Ä¡¿¡ °®´Ù³õ°í, ÀÌÁ¦ ½ÃÇèÀ» ÇØº¾´Ï´Ù. HHK¸¦ usb¿¡ ºÙÀÌ°í »©°í¸¦ ¹Ýº¹Çϸ鼭 ¿øÇϴ Ű¸ÊÀÌ Á¦´ë·Î ÁöÁ¤µÇ´ÂÁö Å×½ºÆ®Çغ¾´Ï´Ù. ½ºÅ©¸³Æ®¸¦ µð¹ö±ëÇϱⰡ ¸¶¶àÄ¡ ¾Ê±ä ÇÏÁö¸¸, ¹®Á¦°¡ µÉ ¸¸ÇÑ ºÎºÐÀ» Á¶±Ý¾¿ ¼öÁ¤Çذ¡¸é¼­ Å×½ºÆ®Çغ¾´Ï´Ù.


ID
Password
Join
Your mode of life will be changed for the better because of new developments.


sponsored by andamiro
sponsored by cdnetworks
sponsored by HP

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2010-02-03 17:35:04
Processing time 0.0078 sec