LECTURE 1 ¥¦¥£¥ó¥É¥¦¤Îɽ¼¨

¡û ¤Ï¤¸¤á¤Ë

GUI ¥×¥í¥°¥é¥ß¥ó¥°¤ò¹Ô¤¦¾ì¹ç¡¢²¿¤è¤ê¤â¤Þ¤º¤Ï¥¦¥£¥ó¥É¥¦¤òɽ¼¨¤Ç¤­¤Ê¤±¤ì¤ÐÏ䷤ˤʤê¤Þ¤»¤ó¡ª¤³¤³¤Ç¾Ò²ð¤¹¤ë¤Î¤Ï¥¦¥£¥ó¥É¥¦¤òɽ¼¨¤¹¤ë¤À¤±¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ç¤¹¡£¤·¤«¤·¡¢Xlib ¥×¥í¥°¥é¥ß¥ó¥°¤Ë¤ª¤±¤ë´ðËÜ»ö¹à¤¬¤¤¤¯¤Ä¤â½Ð¤ÆÍè¤Þ¤¹¤Î¤Ç¡¢¤·¤Ã¤«¤ê¤ÈÍý²ò¤·¤Æ²¼¤µ¤¤¡£

¡û Xlib ¥×¥í¥°¥é¥à¤Î¹½À®

Xlib ¥×¥í¥°¥é¥à¹½À®¤Î´ðËܤϡ¢¼¡¤Î¤è¤¦¤Êή¤ì¤È¤Ê¤ê¤Þ¤¹¡£

  1. XOpenDisplay() ¤ò»È¤Ã¤Æ X ¥µ¡¼¥Ð¤ÈÀܳ¤¹¤ë¡£
  2. XCrateSimpleWindow() ( ¤¢¤ë¤¤¤Ï XCreateWindow() ) ¤ò»È¤Ã¤Æ¡¢É½¼¨¤¹¤ë¥¦¥£¥ó¥É¥¦¤òºîÀ®¤¹¤ë¡£
  3. XSelectInput() ¤ò»È¤Ã¤ÆɬÍפʥ¤¥Ù¥ó¥È¤òÁªÂò¤¹¤ë¡£
  4. XMapWindow() ¤ò»È¤Ã¤Æ¡¢ºîÀ®¤·¤¿¥¦¥£¥ó¥É¥¦¤ò²èÌ̤Ëɽ¼¨¤¹¤ë¡£
  5. XNextEvent() ¤ò»È¤Ã¤Æ X ¥µ¡¼¥Ð¤«¤é¥¤¥Ù¥ó¥È¤òÆɤ߹þ¤ß¡¢¥¤¥Ù¥ó¥È¤Ë±þ¤¸¤¿½èÍý¤ò¹Ô¤¦¡£
  6. »ÈÍѤ·¤¿¥ê¥½¡¼¥¹¤ò²òÊü¤·¤Æ½ªÎ»¤¹¤ë¡£

Xlib ¥×¥í¥°¥é¥à¤Ë¸Â¤é¤º¡¢°ìÈÌŪ¤Ë GUI ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï³°Éô¤«¤éÁ÷¤é¤ì¤Æ¤¯¤ë¥¤¥Ù¥ó¥È¤È¸Æ¤Ð¤ì¤ë¥È¥ê¥¬¡¼¤ò¼õ¤±¤ÆÆ°ºî¤·¤Þ¤¹( ¥¤¥Ù¥ó¥È¶îÆ°Êý¼° )¡£´ðËÜŪ¤Ë¤Ï¼«Ê¬¤«¤éǽưŪ¤ËÆ°ºî¤¹¤ë¤³¤È¤Ï¤¢¤ê¤Þ¤»¤ó¡£¤è¤Ã¤Æ¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤òºîÀ®¤¹¤ë¾å¤ÇºÇ¤â½ÅÍ×¤Ê¤Î¤Ï X ¥µ¡¼¥Ð¤«¤é¥¤¥Ù¥ó¥È¤òÆɤ߹þ¤ß¡¢¥¤¥Ù¥ó¥È¤Ë±þ¤¸¤¿½èÍý¤ò¹Ô¤¦Éôʬ¤È¸À¤¨¤Þ¤¹¡£

¤³¤³¤Ç¾Ò²ð¤¹¤ë¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ç¤Ï¡¢²¿¤«¥­¡¼¤ò²¡¤·¤¿»þ¤ËÄÌÃΤµ¤ì¤ë¥¤¥Ù¥ó¥È¤òÁªÂò¤·¤Æ¤¤¤Æ¡¢¤½¤Î¥¤¥Ù¥ó¥È¤ò¼õ¤±¼è¤Ã¤¿¤é½ªÎ»¤¹¤ë¤È¤¤¤¦¥¤¥Ù¥ó¥È¥ë¡¼¥×¤ò¹½À®¤·¤Æ¤¤¤Þ¤¹¡£

¡û ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à

Éý 400¡¢¹â¤µ 300¡¢¥¦¥£¥ó¥É¥¦ÏÈ(¥Ü¡¼¥À)¤ÎÉý 2¡¢¥Ü¡¼¥À¤Î¿§¤Ï¹õ¡¢ÇØ·Ê¿§¤ÏÇò¤Î¥¦¥£¥ó¥É¥¦¤ò¡¢¥Ç¥¹¥¯¥È¥Ã¥×º¸¾å¤ò¸¶ÅÀ¤È¤·¤Æ (x¡¢y) = (100¡¢100)¤Î°ÌÃÖ¤Ëɽ¼¨¤¹¤ë¥×¥í¥°¥é¥à xwin.c ¤Ç¤¹¡£¤Ï¤¸¤á¤Ë ¤Î¥Ú¡¼¥¸¤«¤é¡¢Á´¤Æ¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ò¸Ç¤á¤¿ tar ¥Ü¡¼¥ë¤ò¥À¥¦¥ó¥í¡¼¥É¤¹¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£

/usr/X11R6 ¤Ë X ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤¬¥¤¥ó¥¹¥È¡¼¥ë¤µ¤ì¤Æ¤¤¤ë¤È²¾Äꤷ¤¿¾ì¹ç¡¢Îã¤È¤·¤Æ¼¡¤Î¤è¤¦¤Ë¤·¤Æ¥³¥ó¥Ñ¥¤¥ë¤ò¹Ô¤¤¤Þ¤¹¡£

gcc -I/usr/X11R6/include -L/usr/X11R6/lib -o xwin xwin.c -lX11

¥³¥ó¥Ñ¥¤¥ë¤ËÀ®¸ù¤¹¤ë¤È¡¢xwin ¤È¤¤¤¦Ì¾Á°¤Î¼Â¹Ô¥Õ¥¡¥¤¥ë¤¬ºîÀ®¤µ¤ì¤Þ¤¹¡£¤³¤Î xwin ¤ò¼Â¹Ô¤¹¤ë¤È¡¢²èÌ̤˥¦¥£¥ó¥É¥¦¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£¥¦¥£¥ó¥É¥¦¤Ë¥Õ¥©¡¼¥«¥¹¤¬Åö¤¿¤Ã¤Æ¤¤¤ë»þ¤Ë²¿¤«¥­¡¼¤ò²¡¤¹¤È¡¢xwin ¤Ï½ªÎ»¤·¤Þ¤¹¡£

001window.jpg

--- xwin.c ---

    1	#include <X11/Xlib.h>
    2	
    3	#define WIN_W  400  /* ¥¦¥£¥ó¥É¥¦¤ÎÉý   */
    4	#define WIN_H  300  /* ¥¦¥£¥ó¥É¥¦¤Î¹â¤µ */
    5	#define WIN_X  100  /* ¥¦¥£¥ó¥É¥¦É½¼¨°ÌÃÖ(X) */
    6	#define WIN_Y  100  /* ¥¦¥£¥ó¥É¥¦É½¼¨°ÌÃÖ(Y) */
    7	#define BORDER 2    /* ¥Ü¡¼¥À¤ÎÉý      */
    8	
    9	
   10	int 
   11	main( void )
   12	{
   13		Display*       dpy;          /* ¥Ç¥£¥¹¥×¥ì¥¤ ( X ¥µ¡¼¥Ð¤Î¤³¤È) */
   14		Window         root;         /* ¥ë¡¼¥È¥¦¥£¥ó¥É¥¦ ( ¥Ç¥¹¥¯¥È¥Ã¥× ) */
   15		Window         win;          /* ɽ¼¨¤¹¤ë¥¦¥£¥ó¥É¥¦ */
   16		int            screen;       /* ¥¹¥¯¥ê¡¼¥ó */
   17		unsigned long  black, white; /* ¹õ¤ÈÇò¤Î¥Ô¥¯¥»¥ëÃÍ */
   18		XEvent         evt;          /* ¥¤¥Ù¥ó¥È¹½Â¤ÂÎÊÑ¿ô */
   19	
   20	
   21		/* X¥µ¡¼¥Ð¤ÈÀܳ¤¹¤ë */
   22		dpy = XOpenDisplay( "" );
   23	
   24	
   25		/* ¥Ç¥£¥¹¥×¥ì¥¤ÊÑ¿ô¤Î¼èÆÀ */
   26		root   = DefaultRootWindow( dpy );
   27		screen = DefaultScreen( dpy );
   28	
   29	
   30		/* Çò¡¢¹õ¤Î¥Ô¥¯¥»¥ëÃͤò¼èÆÀ */
   31		white  = WhitePixel( dpy, screen );
   32		black  = BlackPixel( dpy, screen );
   33	
   34	
   35		/* ¥¦¥£¥ó¥É¥¦¤òºîÀ®¤¹¤ë¡£¤³¤Î»þÅÀ¤Ç¤Ï¤Þ¤À²èÌ̤Ëɽ¼¨¤µ¤ì¤Ê¤¤¡£*/
   36		win = XCreateSimpleWindow( dpy, root,
   37			   WIN_X, WIN_Y, WIN_W, WIN_H, BORDER, black, white);
   38	
   39	
   40		/* X¥µ¡¼¥Ð¤«¤éÄÌÃΤ·¤Æ¤â¤é¤¦¥¤¥Ù¥ó¥È¤ò»ØÄê
   41		   ¤³¤³¤Ç¤Ï¥­¡¼²¡²¼¥¤¥Ù¥ó¥È¤òÁªÂò¤·¤Æ¤¤¤ë */
   42		XSelectInput( dpy, win, KeyPressMask );
   43	
   44	
   45		/* ¥¦¥£¥ó¥É¥¦¤ò²èÌ̤Ëɽ¼¨¤¹¤ë(¥Þ¥Ã¥×¤¹¤ë)¡£ */
   46		XMapWindow( dpy, win );
   47	
   48	
   49		/* ËͤδĶ­¤Ç¤Ï XCreateSimpleWindow() ¤Ç¤ÎºÂɸ»ØÄê¤À¤±¤Ç¤Ï´õ˾¤ÎºÂɸ
   50		   ¤Ë¥¦¥£¥ó¥É¥¦¤¬É½¼¨¤µ¤ì¤Ê¤¤¤Î¤Ç¡¢ÌÀ¼¨Åª¤Ë´õ˾¤ÎºÂɸ¤Ë¥¦¥£¥ó¥É¥¦¤ò
   51		   °ÜÆ°¤µ¤»¤ë¤¿¤á¤Ë XMoveWindow() ¤ò»È¤¤¤Þ¤·¤¿¡£¤â¤· (WIN_X, WIN_Y)¤Ë
   52		   ¤Á¤ã¤ó¤Èɽ¼¨¤µ¤ì¤Ê¤¤¾ì¹ç¤Ï¤ä¤Ã¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£ */
   53	
   54		/* XMoveWindow( dpy, win, WIN_X, WIN_Y ); */
   55	
   56	
   57		/* X¥µ¡¼¥Ð¤Ø¤Î¥ê¥¯¥¨¥¹¥È¥Ð¥Ã¥Õ¥¡¤ò¥Õ¥é¥Ã¥·¥å¤¹¤ë¡£ */
   58		/* XFlush( dpy ); */
   59	
   60	
   61		/* X¥µ¡¼¥Ð¤«¤é¥¤¥Ù¥ó¥È¤òÆɤߤ³¤ó¤Ç¿ï»þ½èÍý¤·¤Æ¤¤¤¯¥¤¥Ù¥ó¥È¥ë¡¼¥× */
   62		while( 1 ) {
   63			XNextEvent( dpy, &evt );
   64	
   65			switch ( evt.type ) {
   66				case KeyPress:
   67					/* ¥ê¥½¡¼¥¹¤Î²òÊü */
   68					XDestroyWindow( dpy, win );
   69					XCloseDisplay( dpy );
   70					return 0;
   71			}
   72		}
   73	}
   74	
   75	/* End of xwin.c */

¡û ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ÎÀâÌÀ

¤Ç¤Ï¡¢¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ë¤Ä¤¤¤ÆÀâÌÀ¤·¤Æ¤¤¤­¤Þ¤¹¡£

  • 1 ¹ÔÌÜ

    Xlib ¥×¥í¥°¥é¥ß¥ó¥°¤ËɬÍפʥإåÀ¥Õ¥¡¥¤¥ë <X11/Xlib.h> ¤ò¥¤¥ó¥¯¥ë¡¼¥É¤·¤Æ¤¤¤Þ¤¹¡£

  • 3 ¡Á 7 ¹ÔÌÜ

    ¥¦¥£¥ó¥É¥¦¤ÎÉý¤ä¹â¤µ¤Ê¤É¤Î¡¢¥×¥í¥°¥é¥à¤ËɬÍפÊÄê¿ô¤ò¥Þ¥¯¥íÄêµÁ¤·¤Æ¤¤¤Þ¤¹¡£

  • 13 ¡Á 18 ¹ÔÌÜ

    xlib ¥×¥í¥°¥é¥ß¥ó¥°ÀìÍѤÎÊÑ¿ô·¿¤¬¤¤¤¯¤Ä¤«¤Ç¤Æ¤­¤Æ¤¤¤Þ¤¹¡£Display ·¿¤Ï¡¢Àܳ¤·¤¿ X ¥µ¡¼ ¥Ð¤ò¼±Ê̤¹¤ë¤¿¤á¤ÎÊÑ¿ô·¿¤Ç¤¹¡£Window ·¿¤Ï¡¢ ʸ»úÄ̤ê²èÌ̤Ëɽ¼¨¤µ¤ì¤ë¥¦¥£¥ó¥É¥¦¤ò¼±Ê̤¹ ¤ë¤¿¤á¤Î·¿ÊÑ¿ô¤Ç¤¹¡£root ¤È win ¤È¤¤¤¦ 2 ¤Ä¤ÎÊÑ¿ô¤òÄêµÁ¤·¤Æ¤¤¤Þ¤¹¤¬¡¢root ¤È¤Ï¥Ç¥¹¥¯¥È ¥Ã¥×¤½¤Î¤â¤Î¤òɽ¤·¤Æ¤ª¤ê¡¢¤½¤Î¾¤ÎÁ´¤Æ¤Î¥¦¥£¥ó¥É¥¦¤Ï¤³¤Î root ¥¦¥£¥ó¥É¥¦¤Î»Ò¥¦¥£¥ó¥É¥¦ (¤Þ¤¿¤Ï¡¢¤µ¤é¤Ë¤½¤Î»Ò¥¦¥£¥ó¥É¥¦)¤È¤Ê¤ê¤Þ¤¹¡£XEvent ·¿¤Ï¡¢ X ¥µ¡¼¥Ð¤«¤éÄÌÃΤµ¤ì¤ë³Æ¼ï¤Î ¥¤¥Ù¥ó¥È¤òÆɤߤ³¤à¤¿¤á¤ËɬÍפÊÊÑ¿ô·¿¤Ç¤¹¡£

    ¤½¤Î¾¤ÎÊÑ¿ô¤ò´Þ¤á¤Æ¶ñÂÎŪ¤Ë²¿¤Î¤¿¤á¤Ë»È¤¦¤«¤Ë¤Ä¤¤¤Æ¤Ï¡¢¼ÂºÝ¤Ë¤½¤ÎÊÑ¿ô¤ò»ÈÍѤ·¤Æ¤¤¤ë¸Ä ½ê¤ª¤è¤Ó¤½¤ÎÀâÌÀ¤òÆɤó¤Ç¥¤¥á¡¼¥¸¤·¤Æ¤¯¤À¤µ¤¤¡£

  • 22 ¹ÔÌÜ

    Á´¤Æ¤Î xlib ¥×¥í¥°¥é¥ß¥ó¥°¤Ç¤Ï¡¢¤Þ¤º²¿¤è¤ê¤âºÇ½é¤Ë X ¥µ¡¼¥Ð¤ÈÀܳ¤·¤Ê¤¯¤Æ¤Ï¤Ê¤ê¤Þ¤»¤ó¡£ X ¥µ¡¼¥Ð¤ÈÀܳ¤¹¤ë¤Ë¤Ï¡¢XOpenDisplay() ´Ø¿ô¤ò»ÈÍѤ·¤Þ¤¹¡£Àܳ¤ËÀ®¸ù¤·¤¿¾ì¹ç¤Ë¤Ï¡¢X ¥µ ¡¼¥Ð¤Î¾ðÊó¤ò»ý¤Ä Display ¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤¬Ê֤äƤ­¤Þ¤¹¡£Àܳ¤Ë¼ºÇÔ¤·¤¿¾ì¹ç¤Ë¤Ï NULL ¤È¤Ê¤ê¤Þ¤¹¡£

      Display* XOpenDisplay( char* display_name );
    
      display_name : Àܳ¤·¤¿¤¤ X ¥µ¡¼¥Ð̾¡£NULL ¤Î¾ì¹ç¤Ï¡¢DISPLAY ´Ä¶­ÊÑ¿ô¤Ë
                     ÀßÄꤵ¤ì¤Æ¤¤¤ëÃͤ¬»ÈÍѤµ¤ì¤ë¡£
    
    

  • 25 ¡Á 32 ¹ÔÌÜ

    ¥Ç¥£¥¹¥×¥ì¥¤¥Þ¥¯¥í¤È¸Æ¤Ð¤ì¤ë¥Þ¥¯¥í¤ò»È¤Ã¤Æ¡¢Display ¹½Â¤ÂΤ«¤é³Æ¼ï¤Î¥Ç¥£¥¹¥×¥ì¥¤¾ðÊó¤ò ¼èÆÀ¤·¤Æ¤¤¤Þ¤¹¡£¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ç¤Ï¡¢DefaultRootWindow ¤Ç¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤ò¼èÆÀ¤·¡¢ DefaultScreen ¤Ç¥¹¥¯¥ê¡¼¥ó¤ò¼èÆÀ¤·¤Æ¤¤¤Þ¤¹¡£¤¤¤º¤ì¤â Display ¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤ò°ú¿ô ¤È¤·¤Þ¤¹¡£

    ¤½¤Î¸å¡¢WhitePixel¡¢BlackPixel ¤Çɽ¼¨¤Ë»ÈÍѤ¹¤ë¹õ¡¢Çò¿§¤Î¥Ô¥¯¥»¥ëÃͤò¼èÆÀ¤·¤Æ¤¤¤Þ¤¹¡£ ¥Ô¥¯¥»¥ëÃͤȤϡ¢¿§¤ò»ØÄꤹ¤ë¤¿¤á¤Î¥¤¥ó¥Ç¥Ã¥¯¥¹¤Î¤è¤¦¤Ê¤â¤Î¤Ç¤¹¡£RGB ¤Î¤è¤¦¤Ê¿§¾ðÊ󤽤Π¤â¤Î¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£¿§¾ðÊó¤Ï¥«¥é¡¼¥Þ¥Ã¥×¤È¸Æ¤Ð¤ì¤ë¥Æ¡¼¥Ö¥ë¤ËÀßÄꤵ¤ì¤Æ¤ª¤ê¡¢¤½¤ÎÃæ¤Î¤É ¤Î¿§¤ò»ÈÍѤ¹¤ë¤«¤ò»ØÄꤹ¤ë¤¿¤á¤Ë¥Ô¥¯¥»¥ëÃͤò»È¤¤¤Þ¤¹¡£¤³¤Î¥Þ¥¯¥í¤Ï¡¢Display ¹½Â¤ÂΤؤΠ¥Ý¥¤¥ó¥¿¤È¡¢¥¹¥¯¥ê¡¼¥ó¤ò°ú¿ô¤È¤·¤Þ¤¹¡£

    ¤³¤³¤Ç»ÈÍѤ·¤Æ¤¤¤Ê¤¤¥Ç¥£¥¹¥×¥ì¥¤¥Þ¥¯¥í¤Ç¡¢»È¤¤¤½¤¦¤À¤Ê¤È»×¤Ã¤¿¤â¤Î¤ò°Ê²¼¤Ë¼¨¤·¤Þ¤¹¡£ º£¤ÏÍÑÅÓ¤¬¤è¤¯Ê¬¤«¤é¤Ê¤¤¤â¤Î¤â¤¢¤ë¤È»×¤¤¤Þ¤¹¤¬¡¢ÍѸ줬ʬ¤«¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿»þ¤Ë¤¢¤é¤¿¤á¤Æ ¸«¤ë¤È¤É¤¦»È¤¨¤ÐÎɤ¤¤Î¤«Ê¬¤«¤ë¤È»×¤¤¤Þ¤¹¡£¤³¤³¤Ç¤Ï¡¢¤³¤¦¤¤¤¦¥Ç¥£¥¹¥×¥ì¥¤¥Þ¥¯¥í¤¬¤¢¤ë¤È ¤¤¤¦¤³¤È¤ò³Ð¤¨¤Æ¤ª¤±¤ÐÎɤ¤¤Ç¤¹¡£

    ¥Ç¥£¥¹¥×¥ì¥¤¥Þ¥¯¥í̾ ³µÍ×
    ConnectionNumber( dpy ) X¥µ¡¼¥Ð¤òɽ¤¹¥Õ¥¡¥¤¥ëµ­½Ò»Ò
    DisplayWidth( dpy, scr ) ¥Ç¥£¥¹¥×¥ì¥¤¤ÎÉý(¥Ô¥¯¥»¥ëñ°Ì)
    DisplayHeight( dpy, scr ) ¥Ç¥£¥¹¥×¥ì¥¤¤Î¹â¤µ(¥Ô¥¯¥»¥ëñ°Ì)
    DisplayString( dpy ) ¥Ç¥£¥¹¥×¥ì¥¤Ì¾
    DefaultDepth( dpy, scr ) ¥¹¥¯¥ê¡¼¥ó¤Î¥Ç¥Õ¥©¥ë¥È¤Î¿¼¤µ
    DefaultColormap( dpy, scr ) ¥Ç¥Õ¥©¥ë¥È¤Î¥«¥é¡¼¥Þ¥Ã¥×ID
    DefaultVisual( display, scr ) ¥¹¥¯¥ê¡¼¥ó¤Î¥Ç¥Õ¥©¥ë¥È¤Î¥Ó¥¸¥å¥¢¥ë (Visual ¹½Â¤ÂΤؤΥݥ¤¥ó¥¿)

  • 35 ¡Á 37 ¹ÔÌÜ

    ɽ¼¨¤¹¤ë¥¦¥£¥ó¥É¥¦¤òºîÀ®¤·¤Æ¤¤¤Þ¤¹¡£´Êñ¤Ë¥¦¥£¥ó¥É¥¦¤òºî¤ë´Ø¿ô¤È¤·¤Æ¡¢ XCreateSimpleWindow() ¤ò»È¤Ã¤Æ¤¤¤Þ¤¹¡£°ú¿ô¤ËºîÀ®¤¹¤ë¥¦¥£¥ó¥É¥¦¤Î¿Æ¤È¤Ê¤ë¥¦¥£¥ó¥É¥¦¤ò»Ø Äꤷ¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¤¬¡¢¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ç¤Ï¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤ò»ØÄꤷ¤Æ¤¤¤Þ¤¹¡£

    ÊÖ¤êÃͤϡ¢ºîÀ®¤·¤¿¥¦¥£¥ó¥É¥¦¤Î¼±ÊÌ»Ò(¥¦¥£¥ó¥É¥¦ ID)¤Ç¤¹¡£

      Window XCreateSimpleWindow( Display*      display, 
                                  Window        parant,
                                  int           x, y,
                                  unsigned int  width, height,
                                  unsigned int  border_width,
                                  unsigned long border,
                                  unsigned long background
                                );
    
      display       : Display ¹½Â¤ÂΤؤΥݥ¤¥ó¥¿
      parent        : ºîÀ®¤¹¤ë¥¦¥£¥ó¥É¥¦¤Î¿Æ¥¦¥£¥ó¥É¥¦¤ò»ØÄê
      x, y          : ¥¦¥£¥ó¥É¥¦¤Îɽ¼¨°ÌÃÖ
      width, height : ¥¦¥£¥ó¥É¥¦¤ÎÉý¡¢¹â¤µ
      border_width  : ¥¦¥£¥ó¥É¥¦¤Î¶­³¦(¥Ü¡¼¥À)¤ÎÉý
      border        : ¥Ü¡¼¥À¤Îɽ¼¨¿§¤ò¥Ô¥¯¥»¥ëÃͤǻØÄê
      background    : ¥¦¥£¥ó¥É¥¦¤ÎÇØ·Ê¿§¤ò¥Ô¥¯¥»¥ëÃͤǻØÄê
    
    

  • 40 ¡Á 42 ¹ÔÌÜ

    Á°½Ò¤·¤¿¤è¤¦¤Ë¡¢GUI ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï¡¢³°Éô¤«¤é¤Î¥¤¥Ù¥ó¥È¤ò¼õ¤±¼è¤Ã¤Æ ¤½¤ì¤ËÂФ¹¤ë½èÍý¤ò¹Ô¤¦¤È¤¤¤¦Æ°ºî¤ò¤·¤Þ¤¹¡£Windows ¤Ç¤Ï´ðËÜŪ¤ËÁ´¤Æ¤Î¥¤¥Ù¥ó¥È( Windows ¤Ç¤Ï¥á¥Ã¥»¡¼¥¸¤È¸Æ¤Ö) ¤¬Á÷¤é¤ì¤Æ¤­¤Æ¡¢É¬Íפʥ¤¥Ù¥ó¥È¤òÁª¤ó¤Ç½èÍý¤¹¤ë¤È¤¤¤¦¹½Â¤¤Ë¤Ê¤ë¤Î¤Ç¤¹¤¬¡¢ X ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Ç¤Ï ¤³¤Á¤é¤¬É¬Íפʥ¤¥Ù¥ó¥È¤ò X ¥µ¡¼¥Ð¤ËÄÌÃΤ¹¤ë¤³¤È¤Ç¡¢ ɬÍפʥ¤¥Ù¥ó¥È¤Î¤ß¤¬Á÷¤é¤ì¤ÆÍè¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹(°ìÉôÎã³°Í­)¡£

    ɬÍפʥ¤¥Ù¥ó¥È¤òÄÌÃΤ¹¤ë¤Ë¤Ï¡¢XSelectInput() ¤ò»È¤¤¤Þ¤¹¡£

      XSelectInput( Display* display, Window w, long event_mask );
    
      event_mask : ɬÍפʥ¤¥Ù¥ó¥È¤ò¥¤¥Ù¥ó¥È¥Þ¥¹¥¯¤Ç»ØÄꤹ¤ë¡£
    
    

    ¤³¤³¤Ç¤Ï KeyPressMask ¤È¤¤¤¦¥¤¥Ù¥ó¥È¥Þ¥¹¥¯¤ò»È¤Ã¤Æ¡¢¥­¡¼²¡²¼¥¤¥Ù¥ó¥È¤òÁªÂò¤·¤Æ¤¤¤Þ¤¹¡£ ¤½¤Î¾¤Ë¤É¤ó¤Ê¥¤¥Ù¥ó¥È¤¬¤¢¤ë¤«¤Ë¤Ä¤¤¤Æ¤Ï¡¢LECTURE 4¤Ç¥¤ ¥Ù¥ó¥È¤Ë¤Ä¤¤¤Æ¾¯¤·¾Ü¤·¤¯ÀâÌÀ¤·¤Þ¤¹¡£

  • 45 ¡Á 46 ¹ÔÌÜ

    Xlib ¥×¥í¥°¥é¥ß¥ó¥°¤Ç¤Ï¡¢ºîÀ®¤·¤¿¥¦¥£¥ó¥É¥¦¤Ï¥Þ¥Ã¥×¤È¤¤¤¦Áàºî¤ò¤·¤Ê¤±¤ì¤Ð²èÌ̤Ëɽ¼¨¤µ¤ì ¤Þ¤»¤ó¡£¥¦¥£¥ó¥É¥¦¤ò¥Þ¥Ã¥×¤¹¤ë¤¿¤á¤Ë¤Ï XMapWindow() ´Ø¿ô¤ò»ÈÍѤ·¤Þ¤¹¡£

      XMapWindow( Display* dpy, Window win );
    
    

    XCreateSimpleWindow() ¤ÇºîÀ®¤¹¤ë¥¦¥£¥ó¥É¥¦¤Î¿Æ¤È¤Ê¤ë¥¦¥£¥ó¥É¥¦¤ò»ØÄꤷ¤Þ¤·¤¿¤¬¡¢¥¦¥£¥ó ¥É¥¦¤ò²èÌ̤Ëɽ¼¨¤¹¤ëºÝ¤Ë¤Ï¤½¤Î¥¦¥£¥ó¥É¥¦¤Î¿Æ¥¦¥£¥ó¥É¥¦¤òÀè¤Ë¥Þ¥Ã¥×¤·¤Ê¤±¤ì¤Ð¤¤¤±¤Þ¤»¤ó¡£ ¤¿¤À¤·¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤¬¿Æ¤Î¾ì¹ç¤Ï¤½¤Î¸Â¤ê¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó (¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ï¤³¤Î¥±¡¼ ¥¹)¡£

    Ê䭤Ǥ¹¤¬¡¢¥¦¥£¥ó¥É¥¦¤ò²èÌ̤«¤é¾Ãµî¤¹¤ë¤Ë¤Ï¥¢¥ó¥Þ¥Ã¥×¤È¤¤¤¦Áàºî¤ò¹Ô¤¤¤Þ¤¹¡£¤³¤ì¤Ë¤Ï XUnmapWindow() ´Ø¿ô¤ò»È¤¤¤Þ¤¹¡£»ØÄꤷ¤¿¥¦¥£¥ó¥É¥¦¤¬²èÌ̤«¤é¾Ãµî¤µ¤ì¤Þ¤¹¤¬¡¢¥¦¥£¥ó¥É¥¦ ¤Î¥ê¥½¡¼¥¹¼«ÂΤ¬²òÊü¤µ¤ì¤ë¤ï¤±¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£ºÆÅ٥ޥåפ¹¤ì¤Ðɽ¼¨¤µ¤ì¤Þ¤¹¡£

    ¹¹¤Ë¡¢¥¦¥£¥ó¥É¥¦¤¬´ö¤Ä¤â½Å¤Ê¤Ã¤Æ¤¤¤ë¤è¤¦¤Ê¾ì¹ç¤Ë»ØÄꤷ¤¿¥¦¥£¥ó¥É¥¦¤ò°ìÈÖ¾å¤Ë¥Þ¥Ã¥×¤¹¤ë ¤Ë¤Ï XMapRaised() ¤ò»È¤¤¤Þ¤¹¡£¤Þ¤¿¡¢¤¢¤ë¥¦¥£¥ó¥É¥¦¤Î»Ò¥¦¥£¥ó¥É¥¦¤òÁ´¤Æ¥Þ¥Ã¥×¤¹¤ë¤Ë¤Ï XMapSubwindows() ¤ò»È¤¤¤Þ¤¹¡£

      XUnmapWindow( Display* display, Window w );
      XMapRaised( Display* display, Window w );
      XMapSubwindows( Display* display, Window w );
    
    

  • 49 ¡Á 54 ¹ÔÌÜ

    ËÜÍè¤Ï XCreateSimpleWindow() ¤Ë»ØÄꤷ¤¿ºÂɸ¤ËºîÀ®¤·¤¿¥¦¥£¥ó¥É¥¦¤¬É½¼¨¤µ¤ì¤ë¤Ù¤­¤Ç¤¹¤¬¡¢ »ÈÍѤ·¤Æ¤¤¤ë¥¦¥£¥ó¥É¥¦¥Þ¥Í¡¼¥¸¥ã¤Î¥Ý¥ê¥·¡¼¤Ê¤É¤Ç¤³¤Î°ÌÃÖ»ØÄ꤬ͭ¸ú¤Ë¤Ê¤é¤Ê¤¤¾ì¹ç¤¬¤¢¤ê ¤Þ¤¹¡£¤½¤Î¤è¤¦¤Ê¾ì¹ç¤Ë¤Ï¡¢XMoveWindow() ¤ò»È¤Ã¤Æ¥¦¥£¥ó¥É¥¦¤ò´õ˾¤ÎºÂɸ¤Ë°ÜÆ°¤µ¤»¤ë¤³¤È ¤¬¤Ç¤­¤Þ¤¹¡£

      XMoveWindow( Display* display, Window w, int x, int y );
    
      x, y : win ¤ò°ÜÆ°¤µ¤»¤¿¤¤ºÂɸ
    
    

  • 57 ¡Á 58 ¹ÔÌÜ

    Xlib ´Ø¿ô¤Ï¡¢X ¥µ¡¼¥Ð¤Ø¤ÎÍ×µá¤ò¥ê¥¯¥¨¥¹¥È¥Ð¥Ã¥Õ¥¡¤È¸Æ¤Ð¤ì¤ë¥Ð¥Ã¥Õ¥¡¤Ë¤¿¤á¤Æ¤ª¤¤¤Æ¡¢¤¢ ¤È¤Ç¼ÂºÝ¤ËÁ÷¿®¤¹¤ë¤È¤¤¤¦Æ°ºî¤ò¤·¤Æ¤¤¤Þ¤¹¡£¥¤¥Ù¥ó¥È´ØÏ¢¤Î Xlib ´Ø¿ô¤ò¼Â¹Ô¤¹¤ë¤È¥ê¥¯¥¨¥¹ ¥È¥Ð¥Ã¥Õ¥¡¤¬¼«Æ°Åª¤Ë¥Õ¥é¥Ã¥·¥å¤µ¤ì¤ë¤Î¤Ç¤¹¤¬¡¢¤½¤¦¤Ç¤Ê¤¤¾ì¹ç¤Ï¡¢ÌÀ¼¨Åª¤Ë¥ê¥¯¥¨¥¹¥È¥Ð¥Ã ¥Õ¥¡¤ò¥Õ¥é¥Ã¥·¥å¤·¤Ê¤±¤ì¤Ð¤¤¤±¤Þ¤»¤ó¡£¤³¤Î¤è¤¦¤Ê¾ì¹ç¤Ï XFlush() ¤ò»È¤¤¤Þ¤¹¡£

      XFlush( Display* display );
    
    

    ¤È¤³¤í¤Ç xwin.c ¤Ç¤Ï¥¤¥Ù¥ó¥È½èÍý¤ò¹Ô¤Ã¤Æ¤¤¤ë¤Î¤Ç XFlush() ¤ÏɬÍ×̵¤¤¤Î¤Ç¤¹¤¬¡¢Á°¥Ð¡¼¥¸ ¥ç¥ó¤Ç¤Ï¥¤¥Ù¥ó¥È½èÍý¤ò¹Ô¤Ã¤Æ¤ª¤é¤ºÉ¬ÍפÀ¤Ã¤¿¤¿¤á¡¢»Ä¤·¤Æ¤ª¤¤¤Æ¤Ä¤¤¤Ç¤ËÀâÌÀ¤·¤Æ¤¤¤Þ¤¹ (^_^)¡£

  • 61 ¡Á 72 ¹ÔÌÜ

    X ¥µ¡¼¥Ð¤«¤é¥¤¥Ù¥ó¥È¤òÆɤߤ³¤ó¤Ç½èÍý¤ò¹Ô¤¦¥á¥¤¥ó¥ë¡¼¥×¤Ç¤¹(¥¤¥Ù¥ó¥È¥ë¡¼¥×)¡£¤³¤³¤Ç¤Ï while ¥ë¡¼¥×¤ò»È¤Ã¤Æ¡¢¥¤¥Ù¥ó¥È¤ÎÆɤ߹þ¤ß¡¢¥¤¥Ù¥ó¥È¼ïÊ̤òȽÊ̤·¤Æ¥­¡¼²¡²¼¥¤¥Ù¥ó¥È¤Ç¤¢ ¤ì¤Ð¥ê¥½¡¼¥¹¤ò²òÊü¤·¤Æ½ªÎ»¡¢¤È¤¤¤¦½èÍý¤ò¥­¡¼¤¬²¡¤µ¤ì¤ë¤Þ¤Ç³¤±¤Æ¤¤¤Þ¤¹¡£

    X ¥µ¡¼¥Ð¤«¤é¥¤¥Ù¥ó¥È¤òÆɤߤ³¤à¤Ë¤Ï¡¢XNextEvent() ¤ò»È¤¤¤Þ¤¹¡£

      XNextEvent( Display* display, XEvent* event_return );
    
      event_return : Æɤߤ³¤ó¤À¥¤¥Ù¥ó¥È¾ðÊó¤ò³ÊǼ¤¹¤ë XEvent ¹½Â¤ÂΤؤΥݥ¤¥ó¥¿
    
    

    ¼Â¹Ô¤¹¤ë¤È¡¢X ¥µ¡¼¥Ð¤«¤éÆɤߤ³¤ó¤À¥¤¥Ù¥ó¥È¾ðÊó¤¬ XEvent ¹½Â¤ÂΤ˳ÊǼ¤µ¤ì¤Þ¤¹¡£XEvent ¹½Â¤ÂΤˤĤ¤¤Æ¤Ï¡¢Ê̤ΠLECTURE ¤Ç¾¯¤·¾Ü¤·¤¯ÀâÌÀ¤·¤Þ¤¹¡£

    XEvent ¹½Â¤ÂΤΠtype ¥á¥ó¥Ð¤Ë¡¢¥¤¥Ù¥ó¥È¤Î¼ïÎब³ÊǼ¤µ¤ì¤Þ¤¹¡£¥­¡¼²¡²¼¥¤¥Ù¥ó¥È¤Î¾ì¹ç¡¢ KeyPress ¤¬ÀßÄꤵ¤ì¤Þ¤¹¡£¤³¤ì¤ò¼õ¤±¼è¤Ã¤¿»þÅÀ¤Ç¡¢67 ¡Á 70 ¹ÔÌܤǥ꥽¡¼¥¹¤ò²òÊü¤·¤Æ¥× ¥í¥°¥é¥à¤ò½ªÎ»¤·¤Æ¤¤¤Þ¤¹¡£XDestroyWindow() ¤È XCloseDisplay() ¤Ï¤½¤ì¤¾¤ìºîÀ®¤·¤¿¥¦¥£ ¥ó¥É¥¦¤ÎÇË´þ¡¢X ¥µ¡¼¥Ð¤È¤ÎÀܳ¤ÎÀÚÃǤò¹Ô¤¦¤¿¤á¤Î´Ø¿ô¤Ç¤¹¡£XDestroyWindow() ¤Ç¤Ï¡¢»Ø Äꤷ¤¿¥¦¥£¥ó¥É¥¦¤È¤½¤ÎÁ´¤Æ¤Î»Ò¥¦¥£¥ó¥É¥¦¤¬ÇË´þ¤µ¤ì¤Þ¤¹¡£

      XDestroyWindow( Display* display, Window w );
      XCloseDisplay( Display* display );
    
    

°Ê¾å¤Ç xwin.c ¤Î²òÀâ¤Ï½ª¤ï¤ê¤Ç¤¹¡£¤³¤³¤ÇÀâÌÀ¤·¤¿ xwin.c ¤Ï Xlib ¥×¥í¥°¥é¥ß¥ó¥°¤Î´ðËÜ·Á¤Ç¤¹¡£º£¸å¤Ï¤³¤³¤ÇÀâÌÀ¤·¤¿ xwin.c ¤ò¥Ù¡¼¥¹¤È¤·¤Æ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤òºîÀ®¤·¤Æ¤¤¤­¤Þ¤¹¤Î¤Ç¡¢¤½¤Î¹½Â¤¤Ë¤Ä¤¤¤Æ¤Ï¤·¤Ã¤«¤êÍý²ò¤·¤Æ¤ª¤¤¤Æ¤¯¤À¤µ¤¤¡£