Previous Next Table of Contents

7. X ÇÁ·Î±×·¡¹Ö ±âÃÊ : À̺¥Æ®Ã³¸®

Áö±Ý±îÁö´Â ±× ÀÚü·Î´Â ½ÇÁúÀûÀÎ ÇÁ·Î±×·¥À» ¸¸µé±â¿¡´Â ºÒ°¡´ÉÇÑ °¡Àå ±âº»ÀûÀÎ °³³äµé¸¸À» ÀÍÇô¿ÔÁö¸¸, ÀÌÁ¦ºÎÅÍ´Â Á» ´Þ¶óÁú °ÍÀÔ´Ï´Ù. ¿©·¯ºÐÀº ÀÌÁ¦ º»°ÝÀûÀÎ ÇÁ·Î±×·¡¹Ö¿¡ µé¾î°¡½Ç Áغñ°¡ µÇ¾ú½À´Ï´Ù.

¿À´Ã ¹è¿ï ³»¿ëÀº "GUI ÇÁ·Î±×·¡¹Ö"¿¡¼­ °¡Àå ÇÙ½ÉÀûÀÎ °³³äÀÎ "À̺¥Æ® event"¿¡ ´ëÇÑ °ÍÀÔ´Ï´Ù. ÀÌ¹Ì À©µµ±× ÇÁ·Î±×·¡¹Ö °°Àº °ÍÀ» Çغ» ÀûÀÌ ÀÖ´Â ºÐµéÀº, ±×¸®°í ƯÈ÷ ¿¾³¯ µµ±× ½ÃÀýºÎÅÍ C ·Î ÇÁ·Î±×·¡¹ÖÀ» Çغ¸½Å ºÐµéÀº Áö±ÝºÎÅÍ ¸»¾¸µå¸®´Â ¸î °¡Áö ¾ê±â¿¡ ´ëÇÏ¿© ±Ý¹æ ÀÌÇØÇÏ½Ç ¼ö ÀÖÀ» °Ì´Ï´Ù. ÀüÇô ¸ð¸£½Ã´Â Ãʺ¸ºÐÀÇ °æ¿ì¿¡´Â ÀÏ´Ü ¸ðµç °ÍÀ» ÀÌÇØÇÒ ¼ö´Â ¾øÀ¸¹Ç·Î ´ÜÁö À©µµ¿ì ÇÁ·Î±×·¡¹ÖÀº ¸ðµÎµé "À̺¥Æ®" ó¸® ¹æ½ÄÀÇ µ¶Æ¯ÇÑ ÇÁ·Î±×·¡¹Ö ½ºÅ¸ÀÏÀ» °®´Â´Ù´Â ¹®±¸ Çϳª¸¸ ±â¾ïÇØ Áֽñ⠹ٶø´Ï´Ù.

7.1 À̺¥Æ® ó¸® ¹æ½Ä°ú ¼øÂ÷ÀûÀΠó¸® ¹æ½Ä Â÷ÀÌÁ¡

¿ì¼± ¼øÂ÷ÀûÀΠó¸® ¹æ½Ä¿¡ ´ëÇؼ­ ¾Ë¾Æº¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.

C ¸¦ º¸Åë ÀýÂ÷¾ð¾î¶ó°í ºÎ¸¨´Ï´Ù. ¸ðµç ÀÏ¿¡´Â ¼ø¼­°¡ ÀÖ´Ù! °¡Àå Àΰ£ÀûÀÎ »ç°í ¹æ½ÄÀ» ¸ðµ¨·Î ÇÏ°í ÀÖ°í °á±¹ ¾î¶² ¾ð¾îµç °£¿¡ Àΰ£ÀÇ ³í¸®´Â Ç×»ó ¿øÀÎ --< °á°úÀÇ ¼ø¼­¸¦ °¡Áö°í »ý°¢ÇÏ´Â ¹æ½ÄÀÇ º¯È­, öÇÐÀÇ º¯È­¾øÀÌ´Â ¾ÕÀ¸·Îµµ Ç×»ó ³²¾ÆÀÖÀ» °ÍÀÔ´Ï´Ù. ¿©·¯ºÐÀÌ Áö±Ý ÇÏ°í ÀÖ´Â ¸ðµç ÀÏÀÌ ´Ù ÀýÂ÷¸¦ °®½À´Ï´Ù. ±×¸®°í ±×°ÍÀº Ç×»ó ¸ðµç ÇÁ·Î±×·¡¹ÖÀÇ ±âº»ÀÌ¸ç ³ªÁß¿¡ À̺¥Æ® ó¸® ¹æ½ÄÀ̶ó ÇÒ Áö¶óµµ ½ºÄÉÀÏÀ» ÀÛ°Ô º¸¸é °á±¹¿¡´Â Àڱ׸¶ÇÑ ¼øÂ÷ ó¸® ¹æ½ÄµéÀÇ °áÇÕÀ̶ó°í »ý°¢ÇÒ ¼öµµ ÀÖ½À´Ï´Ù.

º¸Åë ¼Ð ½ºÅ©¸³Æ®¿Í °°ÀÌ ´Ü ÇÑ ¹øÀÇ ÀÔ·ÂÀ» ¹Þ°í ´Ü ÇÑ ¹øÀÇ Ã³¸®·Î ³¡³ª´Â ÇÁ·Î±×·¥µéÀÌ ÀüÇüÀûÀÎ ¿¹ÀÔ´Ï´Ù.

±×¿¡ ¹ÝÇؼ­ À̺¥Æ® ó¸® ¹æ½ÄÀº "¼ö¸¹Àº ¹öÆ°, ¾ðÁ¦ Ŭ¸¯ÇÒ Áö ¸ð¸£´Â º¯´öÀåÀÌ ¸¶¿ì½º"¶ó´Â °ÍÀ» Ư¡À¸·Î ÇÕ´Ï´Ù. À©µµ¿ì ½Ã½ºÅÛÀÌ µÇ¸é¼­ºÎÅÍ ÇÁ·Î±×·¡¸ÓµéÀº Á¤¸»·Î ¸¹Àº °í¹ÎÀ» Çϱ⠽ÃÀÛÇßÁö¿ä. µµ´ëü ¼ø¼­¶ó´Â °ÍÀ» ¹ß°ßÇϱⰡ Èûµé´Ù´Â °ÍÀÌ ¹®Á¦ÀÔ´Ï´Ù. ¾î¶² ¹öÆ°À» ´©¸¥ ´ÙÀ½ ¾î¶² ¹öÆ°À» ´©¸¦ °ÍÀÎÁö´Â ¿¹ÃøÇÒ ¼ö°¡ ¾ø ½À´Ï´Ù. ¼øÁøÇÑ »ç¿ëÀÚ´Â ¾Æ¹«·¸°Ô ¸¶À½³»Å°´Â ´ë·Î ¹öÆ°À» ´­·¯´ð´Ï´Ù. µµ´ëü ¸¶¿ì½º°¡ ¾îµð·Î ¿òÁ÷ÀÏ Áöµµ ¿¹°ßÇÒ ¼ö°¡ ¾ø½À´Ï´Ù.

ÀÏÀÌ ÀÌ·¯Çϱ⠶§¹®¿¡ X À©µµ¿ì ÇÁ·Î±×·¡¹Ö ¹æ½ÄÀº ¾ÆÁÖ ÆÇÀÌÇÏ°Ô ´Ù¸¥ ¾î¶² ÀÏÁ¤ ÇÑ ÆÐÅÏÀ» °®½À´Ï´Ù. »ç½Ç ³ªÁß¿¡ º¸½Ã¸é ¾Æ½Ã°ÚÁö¸¸ À̺¥Æ® 󸮹æ½ÄÀ̶ó´Â °Íµµ ¾ÆÁÖ ½±½À´Ï´Ù. ±×¸®°í ´ëÇü ÇÁ·Î±×·¥À» ¸¸µé ¶§ ÁÁÁö¿ä. ±×¸®°í À̺¥Æ® 󸮹æ½ÄÀº ±× ¹«¾ùº¸´Ùµµ C++ °ú °°Àº ¿ÀºêÁ§Æ® ¿À¸®¿£Æ¼µðµå ÇÁ·Î±×·¡¹Ö ¾ð¾î¿Í Á¦ÀÏ Àß ¸Â½À´Ï´Ù. ÇÏÁö¸¸ X À©µµ¿ì´Â ¾ÆÁ÷ C ÇÁ·Î±×·¡¹Ö ¾ð¾î·Î µÇ¾î ÀÖ½À´Ï´Ù. ÇÏÁö¸¸ C++ ·Î Â¥µµ »ó°ü¾ø°í ¾î¶»°Ô º¸¸é C++ ·Î Â¥´Â °ÍÀÌ ´õ¿í ¾Ë¸Â´ÂÁöµµ ¸ð¸¨´Ï´Ù. ½ÇÁ¦ X ÇÁ·Î±×·¡¹ÖÀ» ÇÏ´Ùº¸¸é OOP ºñ½ÁÇÑ ½ºÅ¸ÀÏÀ» ¸¹ÀÌ »ç¿ëÇϴϱî¿ä.

À̺¥Æ® ó¸® ¹æ½ÄÀÇ ÇÁ·Î±×·¡¹ÖÀº º¸Åë ÀÌ·± ½ÄÀ¸·Î »ý°¢ÇÕ´Ï´Ù.

¹öÆ°À» ¸î °³ ¸¸µç´Ù. °¢ ¹öÆ°ÀÌ ´­·ÁÁö¸é ¼öÇàµÉ µ¶Æ¯ÇÑ ÇÔ¼öµéÀ» ÁöÁ¤ÇØÁØ´Ù. ±×¸®°í ³ª¼­ ¿ì¸®´Â ¹öÆ°ÀÌ ´­·ÁÁö±â¸¸À» ±â´Ù¸°´Ù. ±×¸®°í ¹öÆ°ÀÌ ´­·ÁÁú ¶§¸¶´Ù ¿¹¸¦ µé¾î 1 ¹ø ¹öÆ°Àº ¿øÀ», 2 ¹ø ¹öÆ°Àº »ç°¢ÇüÀ», ±×¸®°í 3 ¹ø ¹öÆ°Àº Á÷¼±À» ±×¸®µµ·Ï ÇÑ´Ù. Áï ¾î¶² °´Ã¼¸¦ ¸ÕÀú ¸¸µé°í ³ª¼­ ±×°Í¿¡´Ù°¡ ƯÁ¤ ±â´ÉÀ» ºÎ¿©ÇÏ´Â ¹æ½ÄÀÔ´Ï´Ù. ÀÌ·± ÇÁ·Î±×·¡¹Ö ¹æ½ÄÀ̱⠶§¹®¿¡ ºñÁÖ¾ó C ´Ï ºñÁÖ¾ó º£À̽ÄÀÌ´Ï ÇÏ´Â °ÍÀÌ °¡´ÉÇÑ °ÍÀÔ´Ï´Ù. ±â¾ïÇϽʽÿä. ¸ÕÀú ¾î¶² ¹öÆ°À» ¸¸µì´Ï´Ù. ±×¸®°í ±× ¹öÆ°¿¡´Ù°¡ ¿øÇÏ´Â ±â´ÉÀ» Çϳª¾¿ ºÎ¿©ÇÕ´Ï´Ù. ´­·ÁÁö¸é ½ÇÇàÀ» ÇÕ´Ï´Ù. ¿¹¸¦ µé¾î "Exit" ¹öÆ°À» ¸¸µé¸é ¿ì¸®´Â ÇÁ·Î±×·¥À» Á¾·áÇÏ¸é µË´Ï´Ù.

7.2 º¹ÀâÇÑ ÀÏÀº X ¼­¹ö°¡ ó¸®ÇÕ´Ï´Ù. ¿ì¸®´Â ´ÜÁö...

ÀÚ½ÅÀÌ ÇÁ·Î±×·¡¹ÖÇÏ´Â Ç÷§Æ÷¿ÈÀ» ¹Ï´Â ÀÏÀº ÂüÀ¸·Î Áß¿äÇÕ´Ï´Ù. À©µµ±×95 ÇÁ·Î±×·¡¸ÓµéÀº À©µµ±×95¸¦ ¹Ï°í, X ÇÁ·Î±×·¡¸ÓµéÀº X À©µµ¿ì¸¦ ¹Ï½À´Ï´Ù. ÀüÀÚ´Â M$°¡ ¼¼°è ½ÃÀå¿¡¼­ À̱ä´Ù´Â °ÍÀ» ¹Ï°í ÈÄÀÚÀº X À©µµ¿ì ±× ÀÚüÀÇ ´É·Â°ú °¡´É¼ºÀ» ¹Ï½À´Ï´Ù. À©µµ±×95 ÀÚü¸¦ ¹ÏÁö´Â ¾Ê°ÚÁö¿ä? :)

X À©µµ¿ì°¡ ¶ßÁö ¸¶ÀÚ Á¤½Å¾øÀÌ µ¹¾Æ´Ù´Ï´Â ¸¶¿ì½º, ¶Ç´Â ¾ðÁ¦ ŸÀÌÇ뵃 Áö ¸ð¸£´Â Å°º¸µå, ÀÌ ¸ðµç °Í¿¡ ´ëÇؼ­ ¿©·¯ºÐÀº °ÆÁ¤ÇÒ ÇÊ¿ä°¡ ¾ø½À´Ï´Ù. ¸¶¿ì½º°¡ ¾îµð·Î ¿ò Á÷ÀÌ°í ÀÖ´ÂÁö ±×¸®°í Å°º¸µå ÀÔ·ÂÀ» ¹ÞÀ¸¸é ¾î¶»°Ô ÇÒ °ÍÀÎÁö¿¡ ´ëÇؼ­´Â X ¼­¹ö°¡ ´ã´çÇÕ´Ï´Ù. ±×´Â ¸¶Ä¡ ¿©·¯ºÐ¿¡°Ô Ä«µå Æи¦ µ¹¸®´Â µô·¯¿Íµµ °°½À´Ï´Ù. ¿©·¯ºÐÀÌ ¸¸µç ÇÁ·Î±×·¥Àº ÇÔ²² ½ÇÇàµÇ°í ÀÖ´Â ±× ¸¹Àº âµé°ú °øÁ¸ÇÕ´Ï´Ù. µµ´ëü ¾î´À â¿¡¼­ ¸¶¿ì½º Ŭ¸¯ÀÌ ¹ú¾îÁ³´ÂÁö¿¡ ´ëÇؼ­ °ÆÁ¤ÇÒ ÇÊ¿ä¾ø½À´Ï´Ù. ¿©·¯ºÐÀÇ Ã¢¿¡¼­ Ŭ¸¯ÀÌ ÀÌ·ç¾îÁö¸é X ¼­¹ö°¡ ¾Ë¾Æ¼­ ¿©·¯ºÐÀÇ ÇÁ·Î±×·¥¿¡°Ô "À̺¥Æ®"¸¦ º¸³À´Ï´Ù.

½ÉÁö¾î ³ª´Â Å°º¸µå ÀÔ·ÂÀº ÇÊ¿ä¾ø´Ù. ´ÜÁö ¸¶¿ì½º¸¸À¸·Î ÀÛµ¿ÇÏ´Â ÇÁ·Î±×·¥À̹ǷΠ"Å°º¸µå ÀÔ·ÂÀ̶ó´Â À̺¥Æ®"´Â Å뺸ÇÏÁö ¸»¾Æ´Þ¶ó! °í ¿äûÇϸé X ¼­¹ö´Â ¾Ë¾Æ¼­ Å°º¸µå ÀÔ·ÂÀº ¿©·¯ºÐ¿¡°Ô ÁÖÁö ¾Ê½À´Ï´Ù.

¿©·¯ºÐÀº while ¹®Àå Çϳª¸¦ °¡Áö°í ¹«ÇÑ·çÇÁ¸¦ µ¹¸é¼­ ¸¸¾à À̺¥Æ®°¡ »ý±ä´Ù¸é ±×°ÍÀÌ ¸¶¿ì½º Ŭ¸¯ÀÎÁö ¾Æ´Ï¸é Å°º¸µå ÀÔ·ÂÀÎÁö, ¸¶¿ì½º Ŭ¸¯ÀÌ¸é ¸î ¹ø° ¸¶¿ì½º ¹öÆ°ÀÎÁö ¸î °³¸¦ µ¿½Ã¿¡ ´­·¶´ÂÁö µîÀ» È®ÀÎÇÏ°í ¾Ë¸Â´Â ÇൿÀ» ÃëÇØÁÖ¸é µË´Ï´Ù. °³³ä»ó ÇÁ·Î±×·¡¹ÖÀº ½±½À´Ï´Ù. ¿©·¯ºÐ ÇÁ·Î±×·¥ÀÇ ¼º°øÀº ¿À·ÎÁö ¿©·¯ºÐÀÇ Ã¢Á¶·Â¿¡ ´Þ¸° °ÍÀÌÁö »ç½Ç À©µµ±×95ÀÎÁö X À©µµ¿ìÀÎÁö´Â »ó°ü¾ø½À´Ï´Ù. ½ÉÁö¾î ²À X À©µµ¿ì ÇÁ·Î±×·¡¹ÖÀ» C ¾ð¾î·Î Ç϶õ ¹ýµµ ¾ø½À´Ï´Ù. Tcl/Tk ¿Í °°Àº ¸ÚÁø ½ºÅ©¸³Æà ¾ð¾îµéµµ ¸¹°í ±× °­·ÂÇÔÀ» ÀÔÁõ¹Þ°í ÀÖ½À´Ï´Ù. ´ÜÁö C ÇÁ·Î±×·¡¹Ö ¾ð¾î·Î X À©µµ¿ì ÇÁ·Î±×·¡¹ÖÀ» ÇÑ´Ù´Â °ÍÀº ¿©·¯ºÐ¿¡°Ô ¾ÆÁÖ ÅºÅºÇÑ ±âÃʸ¦ ¸¶·ÃÇØÁÖ°í ´Ù¸¥ ¾î¶² ÇÁ·Î±×·¡¹Öµµ ½±°Ô ÇÒ ¼ö ÀÖ´Â ÀڽۨÀ» Áشٴ °ÍÀ» ¸»¾¸µå¸®°í ½Í½À´Ï´Ù.

7.3 ÀϹÝÀûÀÎ ÄÚµå ÇüŸ¦ º¸°í ´«¿¡ ÀÍÈü½Ã´Ù.

ÀÌ ¼Ò½º´Â ¿Ïº®ÇÑ ¼Ò½º°¡ ¾Æ´Ï¶ó ±×³É °³³äÀûÀÎ ¼Ò½ºÀÏ »ÓÀÔ´Ï´Ù.

 Display display;

 XEvent xe;                             /* À̺¥Æ® ó¸® ±¸Á¶Ã¼ */
 Window window1;


 /* X ¼­¹ö¶û Á¢¼ÓÀ» ÇÕ´Ï´Ù. XOpenDisplay ÇÔ¼ö »ç¿ë */

 /* °£´ÜÇÑ Ã¢ Çϳª¸¦ ¸¸µé¾îµÓ´Ï´Ù. */

 /* ¿øÇÏ´Â À̺¥Æ®¸¸À» ¼­¹ö¿¡°Ô µî·ÏÇÕ´Ï´Ù */
 XSelectInput( display, window1, StructureNotifyMask | ExposureMask 
                                | ButtonPressMask );

 XMapWindow( display, window1 );

 /* ¿©±â¼­ºÎÅÍ º»°ÝÀûÀÎ ÇÁ·Î±×·¥ÀÇ ·ÎÁ÷ÀÌ Àü°³µË´Ï´Ù */

 while(1)       /* WHILE ¹®ÀÇ ½ÃÀÛ */
 {
        /* À̺¥Æ®°¡ »ý±â±â¸¦ ±â´Ù¸®°í ÀÖ½À´Ï´Ù */
        XNextEvent( display, &xe );

        /* À̺¥Æ®°¡ »ý±â¸é ´ÙÀ½ ÁÙÀ» ½ÇÇàÇÕ´Ï´Ù. À̺¥Æ®°¡ ¾î¶² Á¾·ùÀÇ À̺¥
           Æ®ÀÎÁö¸¦ ½Äº°Çس»°í ±×¿¡ ¾Ë¸Â´Â ÇൿÀ» ÇÕ´Ï´Ù                   */

        switch ( xe.type )      {

            case Expose:
                 printf("Expose À̺¥Æ® ¹ß»ý\n");
                 break;

            case ButtonPress:
                 printf("¹öÆ°ÀÌ ´­·ÁÁ³½À´Ï´Ù.\n");
                 break;

            case ConfigureNotify:
                 printf("âÀÇ »óÅ°¡ ¹Ù²î¾ú½À´Ï´Ù.\n");
                 break

            case ClientMessage:
                 printf("´Ù¸¥ Ŭ¶óÀ̾ðÆ®°¡ ¸Þ¼¼Áö¸¦ º¸³»¿Ô½À´Ï´Ù\n");
                 break;

            default:
                 printf("¹ß»ýÇÑ À̺¥Æ®¸¦ ¹«½ÃÇÕ´Ï´Ù\n");
                 break;
        }
 }              /* WHILE ¹®ÀÇ ³¡ */

À§¿¡¼­ º¸¿©µå¸° ÆÐÅÏÀ» ¸Ó¸® ¼Ó¿¡ Ç×»ó ÀÖ¾î¾ß ÇÕ´Ï´Ù. ¹ö½º¸¦ Ÿ°í °¡¸é¼­µµ ±×¸®°í È­Àå½Ç¿¡¼­ º¼ ÀÏÀ» º¼ ¶§µµ À½¾ÇÀ» µè°í À־ ¿©ÀÚ Ä£±¸¸¦ ¸¸³ª¼­ µÎ ´«À» ¹Ù¶óº¸°í ÀÖÀ¸¸é¼­µµ... Àá°á¿¡µµ...

¹«¾ùÀ̵ç ÀüÇüÀûÀÎ ÆÐÅÏÀ̶ó´Â °ÍÀÌ ÀÖ½À´Ï´Ù. ±×·¯ÇÑ ÆÐÅÏÀ» ´«Ä¡Ã¤½Ã´Â °ÍÀÌ °¡Àå Áß¿äÇÕ´Ï´Ù. ±×·³ ÀÌÁ¦ Â÷±ÙÂ÷±Ù ¾Ë¾Æ°¡º¸µµ·Ï ÇսôÙ.

7.4 ÆÐÅÏ ºÐ¼®

Á¦ÀÏ ¸ÕÀú ´«¿¡ ¶ç´Â °ÍÀº ¹Ù·Î XEvent ¶ó´Â »õ·Î¿î ÀÚ·áÇüÀÔ´Ï´Ù. C ÇÁ·Î±×·¥ÀÌµç ¹¹µç °£¿¡ ÇÁ·Î±×·¡¹ÖÀÇ ±âº» ¿ä¼Ò´Â "ÀÚ·áÇü°ú ¾Ë°í¸®Áò"ÀÔ´Ï´Ù. ÈÄÀÚ´Â ¿©·¯ºÐÀÇ ¸òÀ̶ó Ä¡°í ÀÏ´Ü ÀڱⰡ »ç¿ëÇÏ´Â ÀÚ·áÇü¿¡ ´ëÇؼ­ Àͼ÷ÇØÁ® ÀÖÁö ¾Ê°Å³ª ´ëÃæ ¾Ë°í ³Ñ¾î°¡°Ô µÈ´Ù¸é ÇÁ·Î±×·¡¹ÖÀÇ ¹Ý¿¡ Àͼ÷ÇÏÁö ¾Ê°í ¹ÝÀ» ´ëÃæ ÇØ°áÇÑ °Í°ú µ¿ÀÏ ÇÕ´Ï´Ù. ÀÚ·áÇü¿¡ ´ëÇؼ­ Áï½Ã ¾Ë¾Æº¸µµ·Ï ÇսôÙ.

/*
 * this union is defined so Xlib can always use the same sized
 * event structure internally, to avoid memory fragmentation.
 */
typedef union _XEvent {
        int type;               /* must not be changed; first element */
        XAnyEvent xany;
        XKeyEvent xkey;
        XButtonEvent xbutton;
        XMotionEvent xmotion;
        XCrossingEvent xcrossing;
        XFocusChangeEvent xfocus;
        XExposeEvent xexpose;
        XGraphicsExposeEvent xgraphicsexpose;
        XNoExposeEvent xnoexpose;
        XVisibilityEvent xvisibility;
        XCreateWindowEvent xcreatewindow;
        XDestroyWindowEvent xdestroywindow;
        XUnmapEvent xunmap;
        XMapEvent xmap;
        XMapRequestEvent xmaprequest;
        XReparentEvent xreparent;
        XConfigureEvent xconfigure;
        XGravityEvent xgravity;
        XResizeRequestEvent xresizerequest;
        XConfigureRequestEvent xconfigurerequest;
        XCirculateEvent xcirculate;
        XCirculateRequestEvent xcirculaterequest;
        XPropertyEvent xproperty;
        XSelectionClearEvent xselectionclear;
        XSelectionRequestEvent xselectionrequest;
        XSelectionEvent xselection;
        XColormapEvent xcolormap;
        XClientMessageEvent xclient;
        XMappingEvent xmapping;
        XErrorEvent xerror;
        XKeymapEvent xkeymap;
        long pad[24];
} XEvent;
XEvent ´Â <X11/Xlib.h>¿¡ Á¤ÀǵǾî ÀÖ½À´Ï´Ù. Áö±Ý ´çÀå Xlib.h Çì´õÈ­ÀÏÀ» ÆíÁý±â·Î ¿­¾î¼­ ³»¿ëÀ» È®ÀÎÇϽʽÿä. Çì´õ È­ÀÏÀÇ ³»¿ëÀº ¾ðÁ¨°¡´Â ÇÑ ¹ø ¸ù¶¥ ÀоîºÁ¾ß ÇÒ ¶§°¡ ¿À°ÚÁö¿ä?

º¸½Ã´Ù½ÃÇÇ XEvent ´Â °ø¿ëü( À¯´Ï¾ð union )ÀÔ´Ï´Ù. °ø¿ëü°¡ ¹«¾ùÀÎÁö ¸ð¸£½Å´Ù¸é ÀÏ´Ü X À©µµ¿ì ÇÁ·Î±×·¡¹ÖÀº Á¢¾îµÎ½Ã°í Áö±Ý ´çÀå °¡Àå ½¬¿î C ÇÁ·Î±×·¡¹Ö Ã¥¿¡¼­ °ø¿ëü¿¡ ´ëÇؼ­ °øºÎÇϽñ⠹ٶø´Ï´Ù.

XEvent °ø¿ëüÀÇ ±¸Á¶´Â ÀüüÀûÀ¸·Î ´ÙÀ½°ú °°½À´Ï´Ù.

typedef union _XEvent {
        int type;               /* ²À! ù¹ø° ¸â¹ö¿©¾ß ÇÑ´Ù. */
        ...
        X*Event <º¯¼ö¸í>
        ...
        long pad[24];
} XEvent;

°ø¿ëüÀÇ Å©±â´Â °ø¿ëüÀÇ ¸â¹ö Áß °¡Àå Å« ÀÚ·áÇüÀÇ Å©±â¿Í °°½À´Ï´Ù. ¸¶Áö¸· ¸â¹ö¸¦ º¸¸é XEvent ´Â long Çü ÀÚ·á 24 °³ Á¤µµÀÇ Å©±â¸¦ °®´Â °ÍÀ» ¾Ë ¼ö ÀÖ½À´Ï´Ù. ±×¸®°í ¾Æ¸¶µµ Á¦ÀÏ ÀÛÀº ÀÚ·áÇüÀº int type ÀÌ°ÚÁÒ?

Áß°£¿¡ ¹«¼öÈ÷ ¸¹ÀÌ µé¾î°¡ ÀÖ´Â X*Event ÀÚ·áÇüÀ» ÇÑ ¹ø º¾½Ã´Ù. XAnyEvent, XKeyEvent, XButtonEvent, XMotionEvent, XExposeEvent µîµîÀÇ X ·Î ½ÃÀÛÇÏ°í Event·Î ³¡³ª´Â À̸§ÀÇ ±¸Á¶Ã¼°¡ ÀÖ½À´Ï´Ù. ±× ±¸Á¶Ã¼ ÀÚ·áÇüµé ¶ÇÇÑ ¸ðµÎ Xlib.h ¿¡ Á¤ÀǵǾî ÀÖ½À´Ï´Ù. ÇÑ ¹ø »ìÆ캸ÁÒ.

typedef struct {
        int type;             /* <-- ÁÖ¸ñ! */
        unsigned long serial; /* # of last request processed by server */
        Bool send_event;      /* true if this came from a SendEvent request */
        Display *display;/* Display the event was read from */
        Window window;  /* window on which event was requested in event mask */
} XAnyEvent;

typedef struct {
        int type;             /* <-- ÁÖ¸ñ! */
        unsigned long serial; /* # of last request processed by server */
        Bool send_event;      /* true if this came from a SendEvent request */
        Display *display;     /* Display the event was read from */
        Window window;        /* "event" window it is reported relative to */
        Window root;          /* root window that the event occured on */
        Window subwindow;     /* child window */
        Time time;            /* milliseconds */
        int x, y;             /* pointer x, y coordinates in event window */
        int x_root, y_root;   /* coordinates relative to root */
        unsigned int state;   /* key or button mask */
        unsigned int keycode; /* detail */
        Bool same_screen;     /* same screen flag */
} XKeyEvent;

typedef struct {
        int type;             /* <-- ÁÖ¸ñ! */ 
        unsigned long serial; /* # of last request processed by server */
        Bool send_event;      /* true if this came from a SendEvent request */
        Display *display;     /* Display the event was read from */
        Window window;        /* "event" window it is reported relative to */
        Window root;          /* root window that the event occured on */
        Window subwindow;     /* child window */
        Time time;            /* milliseconds */
        int x, y;             /* pointer x, y coordinates in event window */
        int x_root, y_root;   /* coordinates relative to root */
        unsigned int state;   /* key or button mask */
        unsigned int button;  /* detail */
        Bool same_screen;     /* same screen flag */
} XButtonEvent;

typedef struct {
        int type;             /* <-- ÁÖ¸ñ! */
        unsigned long serial; /* # of last request processed by server */
        Bool send_event;      /* true if this came from a SendEvent request */
        Display *display;     /* Display the event was read from */
        Window window;        /* "event" window reported relative to */
        Window root;          /* root window that the event occured on */
        Window subwindow;     /* child window */
        Time time;            /* milliseconds */
        int x, y;             /* pointer x, y coordinates in event window */
        int x_root, y_root;   /* coordinates relative to root */
        unsigned int state;   /* key or button mask */
        char is_hint;         /* detail */
        Bool same_screen;     /* same screen flag */
} XMotionEvent;

typedef struct {
        int type;             /* <-- ÁÖ¸ñ! */
        unsigned long serial; /* # of last request processed by server */
        Bool send_event;      /* true if this came from a SendEvent request */
        Display *display;     /* Display the event was read from */
        Window window;
        int x, y;
        int width, height;
        int count;            /* if non-zero, at least this many more */
} XExposeEvent;

¿©±â¼­´Â ¸î °³ÀÇ ±¸Á¶Ã¼¸¸À» ¿¹·Î µé¾úÀ» »ÓÀÔ´Ï´Ù. ¿·¿¡ ¾à°£ÀÇ ¼³¸íÀÌ µé¾îÀÖÀ¸´Ï ±×°ÍÀ» Âü°íÇÏ½Ã¸é µË´Ï´Ù. ¸ðµÎµé ±¸Á¶Ã¼Àε¥ ±¸Á¶Ã¼ ¸â¹öµéÀ» ¼­·Î ºñ±³ÇØ°¡¸é¼­ º¸½Ê½Ã¿ä. ¿©±â¼­ ¿©·¯ºÐ ½º½º·Î °üÂûÀ» Çس»¸é X ÇÁ·Î±×·¡¹ÖÀº Àç¹ÌÀÖ½À´Ï´Ù.

XAnyEvent ÀÇ ³»¿ëÀº ÇÑ ¹ø ¸Ó¸® ¼Ó¿¡ ³Ö°í ´Ù¸¥ X*Event ±¸Á¶Ã¼ ¸â¹öµéÀ» »ìÆ캸½Ê½Ã¿ä. ±×·¯¸é ¿©Áö¾øÀÌ ¸ðµç ±¸Á¶Ã¼¿¡´Â XAnyEvent ÀÇ ³»¿ëÀÌ ¸ðµÎ µé¾î ÀÖ´Ù´Â °ÍÀ» ¾Ë ¼ö ÀÖ½À´Ï´Ù.

7.5 À̺¥Æ® ÀÚ·áÇü »ç¿ë¹ý

¸ðµç À̺¥Æ® ±¸Á¶Ã¼µéÀ» ´ëÇ¥ÇÏ°í ÀÖ´Â °ø¿ëü XEvent ¸¦ ÇÁ·Î±×·¥¿¡¼­ ÀÏ´Ü »ç¿ëÇÕ´Ï´Ù. X ¼­¹ö°¡ ¿ì¸®µé ÇÁ·Î±×·¥¿¡°Ô ¾î¶² À̺¥Æ®°¡ ¹ß»ýÇß´Ù°í ÇÏ¸é ¹Ù·Î XEvent¸¦ º¸³»ÁÝ´Ï´Ù. ±×·¯¸é ¿ì¸®´Â ¿ì¼±! XEvent ÀÇ °¡Àå ±âÃÊÀûÀÎ ÀÚ·áÇüÀÎ int typeÀÇ ³»¿ëÀ» »ìÆ캾´Ï´Ù. ±× type °ªÀ» °¡Áö°í ÀÌ À̺¥Æ®°¡ °ú¿¬ ¸¶¿ì½º°ú °ü·ÃµÈ °ÍÀÎÁö ¾Æ´Ï¸é Å°º¸µå¿Í °ü·ÃµÈ °ÍÀÎÁö µîÀ» ÆǺ°ÇÕ´Ï´Ù. ÆǺ°ÀÌ µÇ¸é ±×¿¡ ¾Ë¸Â´Â ÀÚ·áÇü Áï XEventÀÇ °ø¿ëü ¸â¹öµéÀ» ÀûÀýÇÏ°Ô »ç¿ëÇÕ´Ï´Ù. ¸¶¿ì½º¿Í °ü·ÃµÇ¸é XEvent ¿¡¼­ ¸¶¿ì½º¿Í °ü·ÃµÈ ¸â¹öÀÎ XButtonEvent, XMotionEvent °°Àº °ÍÀ» ÀÌ¿ëÇÏ¿© À̺¥Æ®¸¦ Çؼ®ÇÕ´Ï´Ù. Å°º¸µå¿¡ °ü·ÃµÇ¾î ÀÖ´Ù¸é À̹ø¿¡´Â ±× ÀÚ·áÇüµé ´ë½Å¿¡ XKeyEvent ¸¦ »ç¿ëÇÕ´Ï´Ù.

°¢ ±¸Á¶Ã¼´Â ¶Ç ´Ù½Ã Àڱ⿡°Ô ¾Ë¸Â´Â ±¸Á¶Ã¼ ¸â¹öµéÀ» °¡Áö°í ÀÖ½À´Ï´Ù. ±×°ÍÀ» º¸°í Çؼ®ÇÏ¸é µË´Ï´Ù. ¸¸¾à ¸¶¿ì½º¿¡ °ü·ÃµÇ¾ú´Ù¸é unsigned int button ¸â¹ö¸¦ º¸°í ¾î¶² ¹öÆ°ÀÎÁö¸¦ Çؼ®ÇÕ´Ï´Ù. ¸¸¾à Å°º¸µå¿¡ °ü·ÃµÇ¾ú´Ù¸é unsigned int keycode ¸¦ º¸°í Çؼ®ÇÕ´Ï´Ù.

±×·¯ÇÑ °úÁ¤À» ¹Ù·Î switch ( xe.type ) ¹®Àå¿¡¼­ ÇÏ°í ÀÖ´Â °ÍÀÔ´Ï´Ù. case ¹®¿¡ ³ªÅ¸³­ Expose, ButtonPress µîÀº ¸ÅÅ©·ÎÀÔ´Ï´Ù. X.h ¿¡ Á¤ÀǵǾî ÀÖ½À´Ï´Ù.

        #define KeyPress                2
        #define KeyRelease              3
        #define ButtonPress             4
        #define ButtonRelease           5
        #define MotionNotify            6
        #define EnterNotify             7
        #define LeaveNotify             8
        #define FocusIn                 9
        #define FocusOut                10
        #define KeymapNotify            11
        #define Expose                  12
        #define GraphicsExpose          13
        #define NoExpose                14
        #define VisibilityNotify        15

7.6 ⸶´Ù ÀڱⰡ ¿øÇÏ´Â À̺¥Æ®¸¸À» ¿¹¾àÇϱâ

¿¹Á¦ ¼Ò½º¸¦ º¸½Ã¸é ´ÙÀ½°ú °°Àº ºÎºÐÀÌ ÀÖ½À´Ï´Ù.

  XSelectInput( display, window1, StructureNotifyMask | ExposureMask 
                                  | ButtonPressMask );

  XMapWindow( display, window1 );

XSelectInputÀ̶ó´Â ÇÔ¼ö°¡ º¸À̴±º¿ä. »õ·Î¿î ÇÔ¼ö´Ï±î Àá½Ã ´«¿¡ ÀÍÇôµÎ¾î¾ß°ÚÁÒ? man ¸í·ÉÀ» ¶°¿Ã¸®¼Å¾ß ÇÕ´Ï´Ù. man XSelectInput

 NAME
       XSelectInput - À̺¥Æ® ÀÔ·ÂÀ» ¼±ÅÃÇÕ´Ï´Ù.

 SYNTAX
       XSelectInput(display, w, event_mask)
             Display *display;
             Window w;
             long event_mask;

 ARGUMENTS
       display    X ¼­¹ö¿ÍÀÇ Á¢¼Ó ID
       event_mask À̺¥Æ® ¸Å½ºÅ©
       w          À̺¥Æ® ¼±ÅÃÀ» Àû¿ëÇÒ Ã¢ ID

¸Å½ºÅ©(Mask)¶ó°í ÇÏ´Â ±â¹ý ¶ÇÇÑ ¾ÆÁÖ Áß¿äÇÑ C ÇÁ·Î±×·¡¹Ö ½ÇÀü ±â¹ýÀÔ´Ï´Ù. ¸ð¸£½Ã´Â ºÐÀº ´çÀå C ÇÁ·Î±×·¡¹Ö Ã¥À» º¸½Ê½Ã¿ä. Á¦°¡ »ý°¢¿£ ¿øÆÇ Ä¿´Ï°Ç & ¸®Ä¡ÀÇ ¾ÆÁÖ ¾ãÁö¸¸ ±× ¾î¶² C ÇÁ·Î±×·¡¹Ö Çؼ³Ã¥º¸´Ùµµ ¶Ù¾î³­ "C ÇÁ·Î±×·¡¹Ö ·©±ÍÁö" ¶ó´Â Ã¥À» ±ÇÇÕ´Ï´Ù. Ç×»ó °¡Áö°í ´Ù´Ï±â¿¡ Âü ÁÁ½À´Ï´Ù. ¾µµ¥ ¾øÀÌ ½±°Ô ¾²Áöµµ ¾î·Æ°Ô ¾²Áöµµ ¾ÊÀº ¸íÀúÀÌÁö¿ä.

À§¿¡¼­º¸¸é ¿ì¸®´Â °¢ ⸶´Ù XSelectInput À̶ó´Â ÇÔ¼ö¸¦ ÅëÇؼ­ ÀڱⰡ °ü½É°®´Â À̺¥Æ®¸¸À» µî·ÏÇÒ ¼ö ÀÖ´Ù´Â °ÍÀ» ¾Ë ¼ö ÀÖ½À´Ï´Ù. ¿¹¸¦ µé¾î OK ³ª CANCEL ¹öÆ°À» Ç¥½ÃÇϴ âÀÇ ÀÔÀå¿¡¼­ Å°º¸µå ÀÔ·ÂÀ̳ª ¸¶¿ì½ºÀÇ À̵¿ °°Àº °ÍÀº ÀüÇô ÇÊ¿ä¾ø°ÚÁö¿ä? ¹öÆ°ÀÌ ´­·È³ª ¾È´­·È³ª¸¸ È®ÀÎÇÏ¸é µË´Ï´Ù.

 StructureNotifyMask | ExposureMask | ButtonPressMask

ºñÆ®¿¬»ê OR ¶ÇÇÑ ¾ÆÁÖ ¸¹ÀÌ Á¢ÇÏ´Â ±â¼úÀÔ´Ï´Ù.

 #define NoEventMask                     0L
 #define KeyPressMask                    (1L<<0)  
 #define KeyReleaseMask                  (1L<<1)  
 #define ButtonPressMask                 (1L<<2)  
 #define ButtonReleaseMask               (1L<<3)  
 #define EnterWindowMask                 (1L<<4)  
 #define LeaveWindowMask                 (1L<<5)  
 #define PointerMotionMask               (1L<<6)  
 #define PointerMotionHintMask           (1L<<7)  
 #define Button1MotionMask               (1L<<8)  
 #define Button2MotionMask               (1L<<9)  
 #define Button3MotionMask               (1L<<10) 
 #define Button4MotionMask               (1L<<11) 
 #define Button5MotionMask               (1L<<12) 
 #define ButtonMotionMask                (1L<<13) 

¿©·¯ºÐÀº (1L>>2) ¶ó´Â Ç¥Çö¿¡ Àͼ÷ÇØÁö¼Å¾ß ÇÕ´Ï´Ù. ¾ÕÀ¸·Îµµ ÀÚÁÖ ³ª¿À°í ±âº»ÀûÀÎ ½ÇÀü Å×Å©´ÐÀ̴ϱî¿ä.

±×·³ °£´ÜÇÑ ¿¹¸¦ µé¾îº¼±î¿ä?

°£´ÜÇÑ ¿¹

°£´ÜÇÑ ¹öÆ°À» Çϳª ¸¸µé¾î¼­ Ŭ¸¯Çϸé Hello, Linuxers ¶ó´Â ¹®ÀÚ¿­À» Ãâ·ÂÇÑ ÈÄ Á¾·áÇÏ´Â ¿¹¸¦ º¸¿©µå¸®°Ú½À´Ï´Ù.

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>

int main( int argc, char* argv[] )
{
    Display *dpy;
    Window  w;
    Font    f;
    GC      gc;
    XEvent  xe;

    dpy = XOpenDisplay( NULL);
    w   = XCreateSimpleWindow( dpy, RootWindow( dpy, 0 ), 50, 50,
                                    100, 50, 5, BlackPixel( dpy, 0 ),
                                    WhitePixel( dpy, 0 ) );
    gc = XCreateGC( dpy, w, 0L, ( XGCValues * ) NULL );
    f  = XLoadFont( dpy, "fixed" );
    XSetFont( dpy, gc, f );
    XSetLineAttributes( dpy, gc, 5, LineSolid, 
                         CapRound, JoinRound );

    XSelectInput( dpy, w, ExposureMask | ButtonPressMask | EnterWindowMask 
                           | LeaveWindowMask );

    XMapWindow( dpy, w );

    XFlush( dpy );

    while ( True )
    {
            XNextEvent( dpy, &xe );

            switch ( xe.type )      {
            case Expose:
                printf("Expose À̺¥Æ®°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù.\n");
                XSetForeground( dpy, gc, BlackPixel( dpy, 0 ) )
                XDrawString( dpy, w, gc, 40, 30, "O K", 3 );
                break;
            case ButtonPress:
                printf("¹öÆ°À» ´©¸£¼Ì½À´Ï´Ù!\n");
                exit(1);
                break;
            case EnterNotify:
                printf("¸¶¿ì½º°¡ â ¾ÈÀ¸·Î µé¾î¿Ô½À´Ï´Ù.\n");
                XSetForeground( dpy, gc, BlackPixel( dpy, 0 ) );
                XDrawRectangle( dpy, w, gc, 10, 10, 80, 30 );
                break;
            case LeaveNotify:
                printf("¸¶¿ì½º°¡ â ¹ÛÀ¸·Î ³ª°¬½À´Ï´Ù.\n");
                XSetForeground( dpy, gc, WhitePixel( dpy, 0 ) );
                XDrawRectangle( dpy, w, gc, 10, 10, 80, 30 );
                break;
            default:
                printf("¸ð¸£´Â À̺¥Æ®ÀÔ´Ï´Ù. ¹«½ÃÇÕ´Ï´Ù.\n");
                break;
            }
    }
        return 0;
}

À§ ¿¹Á¦¸¦ event.example.c ¶ó´Â À̸§À¸·Î ÀúÀåÇÏ°í ´ÙÀ½°ú °°ÀÌ ÇØÁÝ´Ï´Ù.

 gcc -o event.example event.example.c -lX11 -L/usr/X11/lib

½ÇÇàÀº ÇÑÅÒ Ã¢°ú °°ÀÌ ÇѱÛÀÌ Ãâ·ÂµÉ ¼ö ÀÖ´Â °÷¿¡¼­ ½ÇÇàÇØÁֽʽÿä.

 ./event.example

¿¹Á¦¿¡ ´ëÇÑ ¼³¸í

XSelectInput ÇÔ¼ö°¡ ³ª¿À±â Àü±îÁö ³ª¿À´Â ¸ðµç °ÍµéÀº ÀÌ¹Ì ¿ì¸®°¡ Àß ¾Ë°í ÀÖ´Â ³»¿ëÀÔ´Ï´Ù. ¼­¹ö¿Í Á¢¼ÓÀ» ÇÏ°í âÀ» Çϳª ¸¸µì´Ï´Ù. ÆùÆ® Ãâ·Â°ú »ç°¢Çü ±×¸®±â¸¦ ÇÒ °ÍÀ̹ǷΠGC ¸¦ ¸¸µé¾îµÎ´Â °Íµµ ÀØÁö ¾Ê½À´Ï´Ù. ½Ã½ºÅÛÀÇ ±âº»ÀÎ fixed ÆùÆ®¸¦ ·ÎµùÇÏ°í GC ¼¼Æõµ ±×·°Àú·° ÇصӴϴÙ.

  1. âÀ» MAPÇϱâ Àü¿¡ ¿ì¼± ¿øÇÏ´Â À̺¥Æ®¸¦ °ñ¶óµÐ´Ù. XSelectInput ÇÔ¼ö¸¦ ÅëÇؼ­ ¿ì¸®´Â ¿øÇϴ â¿¡´Ù°¡ ¿ì¸®°¡ °ü½ÉÀ» °®´Â À̺¥Æ® ¸¸À» µî·ÏÇصдÙ. ±×·¯¸é ³ª¸ÓÁö À̺¥Æ®µéÀº ±×³É ¹«½ÃµÇ¹ö¸®°í ¸¸´Ù. ¿©±â¼­ ¿ì¸®°¡ ¿øÇÏ´Â °ÍÀº ÀÏ´Ü ¾ÆÁÖ¾ÆÁÖ Áß¿äÇÑ À̺¥Æ®ÀÇ ÇϳªÀÎ Expose À̺¥Æ®, ¸¶¿ì½º ¹öÆ°ÀÌ Å¬¸¯µÇ¾ú´Â°¡¸¦ ¾Ë¾Æº¸´Â À̺¥Æ® ±×¸®°í â ¼ÓÀ¸·Î ¸¶¿ì½º Æ÷ÀÎÅÍ°¡ µé¾î°¬´Â°¡, ³ª¿Ô´Â°¡¸¦ ¾Ë·ÁÁÖ´Â À̺¥Æ®¸¦ ¼³Á¤ÇÏ¿´½À´Ï´Ù.
      ExposureMask | ButtonPressMask | EnterWindowMask | LeaveWindowMask
    
  2. Expose À̺¥Æ®ÀÇ Á߿伺 Expose´Â ¿µ¾îÀÇ ¶æ ±×´ë·Î "¹ÛÀ¸·Î µå·¯³ª´Ù"¶ó´Â ÀǹÌÀÔ´Ï´Ù. À©µµ¿ì ½Ã½ºÅÛ¿¡¼­ °í·ÁÇØÁà¾ß ÇÒ °Í Áß Çϳª´Â ÇÑ È­¸éÀ» µ¿½Ã¿¡ ¸¹Àº âµéÀÌ °øÀ¯ÇÏ°í ÀÖ´Ù´Â »ç½ÇÀÔ´Ï´Ù. âµéÀÌ À̸®Àú¸® ¼­·Î¸¦ °¡¸®±âµµ ÇÏ°í ´Ù½Ã ³ªÅ¸³ª±âµµ ÇÏ¸ç ¾ÆÀÌÄÜÀ¸·Î µÇ¾ú´Ù°¡ ´Ù½Ã ¿ø»óÅ·Πµ¹¾Æ¿À±âµµ ÇÕ´Ï´Ù. Å©±â°¡ ´Ã±âµµ ÇÏÁö¿ä. ƯÈ÷³ª ´Ù¸¥ â¿¡ °¡·È´Ù°¡ ´Ù½Ã ³ªÅ¸³ª°Ô µÉ ¶§´Â ³²µé¿¡ ÀÇÇؼ­ °¡·ÁÁ³´ø ºÎºÐµéÀ» ´Ù½Ã ±×·ÁÁà¾ß ÇÕ´Ï´Ù. ±×·±µ¥ ¿©·¯ºÐÀÌ Xt/¸ðƼÇÁ °°Àº ¼öÁØ¿¡¼­´Â ´À³¢Áö ¸ø ÇϼÌÀ»Áö ¸ð¸£°ÚÁö¸¸ Xlib Àº Àú¼öÁØÀ̹ǷΠ¿©·¯ºÐ ½º½º·Î°¡ ³²µé¿¡ ÀÇÇØ °¡·ÁÁ³´Ù°¡ ´Ù½Ã ³ªÅ¸³¯ ¶§ Áö¿öÁ³´ø ºÎºÐÀ» º¹±¸ÇØÁÖ¾î¾ß ÇÕ´Ï´Ù. ½ÇÁ¦·Î ¸ðƼÇÁ °°Àº °ÍµéÀº ÀÌ¹Ì Xlib ÀÇ ÇÔ¼ö¸¦ ½á¼­ ¿©·¯ºÐ ¸ô·¡ ´Ù½Ã ±×·ÁÁÖ´Â ÀÛ¾÷À» ´ë½Å ÇØÁÖ°í ÀÖÀ» »ÓÀÔ´Ï´Ù. Expose À̺¥Æ®´Â ¿©·¯ºÐÀÇ Ã¢ÀÌ ¸Ç óÀ½ XMapWindow ÇÔ¼ö¿¡ ÀÇÇؼ­ »Ð! ÇÏ°í ³ªÅ¸³¯ ¶§ óÀ½À¸·Î ¹ß»ýÇÕ´Ï´Ù. ´ëºÎºÐÀÇ ÇÁ·Î±×·¥µéÀº âÀÌ ¸Ç óÀ½ »Ð! ÇÏ°í ³ªÅ¸³¯ ¶§ ÀÚ±â ÀÚ½ÅÀ» ¿©·¯ ¸ð·Î Ä¡ÀåÇÕ´Ï´Ù. ¶ÇÇÑ ³²µé¿¡ ÀÇÇØ °¡·ÁÁ³´Ù°¡ ´Ù½Ã »Ð! ÇÏ°í ¿©·¯ºÐ¿¡°Ô ³ªÅ¸³¾ ¶§´Â ÀûÀýÇÏ°Ô Áö¿öÁø ºÎºÐÀ» º¹±¸ÇØÁÖ¾î¾ß ÇÕ´Ï´Ù. ¿©±â¼­´Â ¾ÆÁÖ °£´ÜÇÑ ¹æ½ÄÀ¸·Î ó¸®Çß½À´Ï´Ù. Expose À̺¥Æ®°¡ ¹ß»ýÇÒ ¶§¸¶´Ù ´Ù½Ã O K ¶ó´Â ±Û¾¾¸¦ ½áÁÖ´Â °ÍÀÌÁö¿ä.
  3. while ( True ) ¹®ÀåÀ» ÅëÇؼ­ À̺¥Æ® ó¸® ¹«ÇÑ ·çÇÁ¸¦ µ½´Ï´Ù. XNextEvent ÇÔ¼ö¸¦ »ç¿ëÇÏ¸é ¿©·¯ºÐÀÌ ¿øÇÏ´Â À̺¥Æ® Áß Çϳª°¡ »ý±æ ¶§±îÁö ±â´Ù¸³´Ï´Ù. À̺¥Æ®°¡ ¾È»ý±â¸é °¡¸¸È÷ ÀÖ½À´Ï´Ù. ±×·¯´Ù°¡ »ý±â¸é ÆĶó¹ÌÅÍ·Î ÁÖ¾îÁø XEvent °ø¿ëü¿¡´Ù°¡ À̺¥Æ® Á¤º¸¸¦ Àû¾î¼­ º¸³»ÁÝ´Ï´Ù.

  switch ( xe.type )

ÀÚ, À̺¥Æ®¶ó´Â °ÍÀº Á¾·ù°¡ ¸¹±â ¶§¹®¿¡ ±×°ÍÀÌ ¸¶¿ì½º¿Í °ü·ÃµÈ °ÍÀÎÁö Å°º¸µå¿Í °ü·ÃµÈ °ÍÀÎÁö¸¦ ¾Ë¾Æ¾ß ÇÒ ÇÊ¿ä°¡ ÀÖ½À´Ï´Ù. ±×°Í¿¡ ¸Â°Ô ÀûÀýÇÏ°Ô Ã³¸®ÇØ¾ß Çϴϱî¿ä.

  case Expose:

     Expose À̺¥Æ® ¹ß»ý½Ã¿¡´Â ÀûÀýÇÏ°Ô ÀÚ±â ÀÚ½ÅÀ» ±×·ÁÁְųª º¹±¸
     ÇØÁÖ¾î¾ß ÇÕ´Ï´Ù. XDrawString ÇÔ¼ö·Î "O K"¶ó°í ½áÁÝ´Ï´Ù.
     ¸ÕÀú XSetForeground ÇÔ¼ö·Î Àü°æ»öÀ» °ËÁ¤À¸·Î ÇØÁÝ´Ï´Ù.

  case ButtonPress:

     ¹öÆ°ÀÌ ´­¸®¸é( ¾î¶² ¹öÆ°ÀÌµç »ó°üÇÏÁö ¾Ê°í ) exit(1) Á¾·áÇÕ´Ï´Ù.

  case EnterNotify:

     ¸¶¿ì½º°¡ â ¾ÈÀ¸·Î µé¾î°¡¸é XDrawRectangle ÇÔ¼ö·Î »ç°¢ÇüÀ» Å×
     µÎ¸®¿¡ ±×·ÁÁÝ´Ï´Ù. ¿©·¯ºÐÀÇ ¸¶¿ì½º°¡ µé¾î¿Ô´Ù´Â °ÍÀ» È®½ÇÇÏ°Ô
     º¸¿©ÁÖ±â À§Çؼ­ÀÔ´Ï´Ù.

  case LeaveNotify:

     ¸¶¿ì½º°¡ ³ª°¡¸é ³ª°¬´Ù´Â °ÍÀ» º¸¿©ÁÖ±â À§ÇØ Àü°æ»öÀ» ÇϾá»öÀ¸
     ·Î Áï, ¹è°æ»ö°ú °°°Ô Çؼ­ »ç°¢ÇüÀ» ±×·ÁÁÝ´Ï´Ù. ±×·¯¸é Áö¿öÁö´Â
     È¿°ú°¡ ³ª°ÚÁö¿ä?

  default:

     ¾Ë ¼ö ¾ø´Â À̺¥Æ®´Â ¹«½ÃÇÕ´Ï´Ù.

À§¿¡¼­ ¿¹·Î µç °ÍÀº ¿©·¯ºÐÀÌ ¾ÆÁÖ ½±°Ô Á¢ÇÒ ¼ö ÀÖ´Â ¹öÆ° Çϳª¸¦ ¾ÆÁÖ Àú¼öÁØ¿¡¼­ ÇØ°áÇÑ °ÍÀÔ´Ï´Ù. º¸Åë ¹öÆ°À» Ŭ¸¯Çϱâ À§ÇÏ¿© ¸¶¿ì½º¸¦ °¡Á®´Ù ´ë¸é ¹öÆ° ÀüüÀÇ »ö»óÀÌ º¯ÇÑ´ÙµçÁö ÇÏ´Â °ÍÀ» º¼ ¼ö ÀÖ½À´Ï´Ù. ¹Ù·Î À̺¥Æ®¿¡ ¸Â°Ô Àڱ⠸ð¾çÀ» ±×¸®¸é µÇ´Â °ÍÀÔ´Ï´Ù. ¿ø¸®´Â ¾ÆÁÖ °£´ÜÇÏÁö¿ä?

¹öÆ° Çϳª¸¦ ¸¸µé¾î º¸¾Ò½À´Ï´Ù. ±âÁ¸ÀÇ ¶óÀ̺귯¸®¸¸ ¾²´Â °ÍÀÌ ¾Æ´Ï¶ó ¿©·¯ºÐÀÌ Àú¼öÁØÀ¸·Î ¾ÆÁÖ Àç¹ÌÀÖ´Â ÇൿÀ» ÇÏ´Â ¹öÆ°À» ¸¸µé ¼öµµ ÀÖ½À´Ï´Ù. ´Ù¸¥ »ç¶÷Àº Èä³»³¾ ¼ö ¾ø´Â Àç¹ÌÀÖ´Â ÀÏÀ» ÇÏ´Â °Í, ÀÌ°ÍÀº Àú¼öÁØ ÇÔ¼ö Xlib À» ¹è¿ìÁö ¾Ê°í ´Â ÀÌ·ê ¼ö ¾ø´Â ÀÏÀÔ´Ï´Ù.


Previous Next Table of Contents