LECTURE 8 ¥¦¥£¥ó¥É¥¦¤Î¥³¥ó¥È¥í¡¼¥ë

¡û ¤Ï¤¸¤á¤Ë

¥¦¥£¥ó¥É¥¦¤ÏÍÍ¡¹¤Ê°À­¾ðÊó(ÇØ·Ê¿§¡¢¥µ¥¤¥º¡¢etc.)¤ò»ý¤Ã¤Æ¤¤¤Þ¤¹¤¬¡¢¤½¤Î¤¦¤Á¡¢É½¼¨°ÌÃÖ¡¢¥µ¥¤¥º¡¢¥Ü¡¼¥À¤ÎÉý¤Î¤³¤È¤ò°ìÈ̤˥¸¥ª¥á¥È¥ê¾ðÊó¤È¤¤¤¤¤Þ¤¹¡£¤³¤ì¤é¤Î¥¸¥ª¥á¥È¥ê¾ðÊó¤ò¥×¥í¥°¥é¥àÃ椫¤éÊѹ¹¤¹¤ë¤³¤È¤Ë¤è¤Ã¤Æ¡¢¥¦¥£¥ó¥É¥¦¤Î¥µ¥¤¥º¤äɽ¼¨°ÌÃÖ¤òưŪ¤ËÊѹ¹¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

¤³¤³¤Ç¤Ï¡¢¥¦¥£¥ó¥É¥¦¤Î¥¸¥ª¥á¥È¥ê¾ðÊó¤òÁàºî¤¹¤ëÊýË¡¤Ë¤Ä¤¤¤ÆÀâÌÀ¤·¤Æ¤¤¤­¤Þ¤¹¡£

¡û ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à(°ÜÆ°¡¢¥µ¥¤¥ºÊѹ¹)

¥¦¥£¥ó¥É¥¦¾å¤Ë°ÜÆ°¥Ü¥¿¥ó( MOVE )¤È¥µ¥¤¥ºÊѹ¹¥Ü¥¿¥ó( RESIZE )¤Î 2 ¤Ä¤Î¥Ü¥¿¥ó¤òɽ¼¨¤·¤Æ¡¢°ÜÆ°¥Ü¥¿¥ó¤ò¥¯¥ê¥Ã¥¯¤¹¤ë¤È¸½ºß¤Îɽ¼¨°ÌÃÖ¤è¤ê¾¯¤·±¦²¼¤Ë¥¦¥£¥ó¥É¥¦¤ò°ÜÆ°¤·¡¢¥µ¥¤¥ºÊѹ¹¥Ü¥¿¥ó¤ò¥¯¥ê¥Ã¥¯¤¹¤ë¤È¥¦¥£¥ó¥É¥¦¤Î³ÈÂç( 2 ÇÜ)/½Ì¾®( 1/2 ÇÜ)¤ò¸ò¸ß¤Ë¹Ô¤¦¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à xctrl.c ¤Ç¤¹¡£¤Ï¤¸¤á¤Ë ¤Î¥Ú¡¼¥¸¤«¤é¡¢Á´¤Æ¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ò¸Ç¤á¤¿ tar ¥Ü¡¼¥ë¤ò¥À¥¦¥ó¥í¡¼¥É¤¹¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£

º£¤Þ¤Ç¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤è¤ê½èÍý¤¬ÈË»¨¤Ë¤Ê¤ë¤¿¤á¡¢¥×¥í¥°¥é¥à¤Î¹½Â¤¤òÊѤ¨¤Æ¤¤¤Þ¤¹¡£¥¤¥Ù¥ó¥È¥ë¡¼¥×¤Ç¤¢¤ë xctrl_event_loop() ¤È³Æ¥Ü¥¿¥ó¤¬²¡¤µ¤ì¤¿»þ¤Î½èÍý( xctrl_proc_moveb()¡¢xctrl_proc_resizeb() )¤ËÃí°Õ¤·¤ÆÆɤó¤Ç¤ß¤Æ¤¯¤À¤µ¤¤¡£

¼Â¹Ô¤¹¤ë¤È²¼¿Þ¤Î¤è¤¦¤Ê¥¦¥£¥ó¥É¥¦¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£¥Ü¥¿¥ó¤ò²¡¤¹¤ÈÁ°½Ò¤ÎÆ°ºî¤ò¤·¤Þ¤¹¡£¤Þ¤¿¡¢Esc ¥Ü¥¿¥ó¤ò²¡¤¹¤È½ªÎ»¤·¤Þ¤¹¡£

008control.jpg

--- xctrl.c ---

    1	#include <X11/Xlib.h>
    2	#include <string.h>
    3	
    4	#define WINDOW_W   400      /* ¥¦¥£¥ó¥É¥¦¤ÎÉý */
    5	#define WINDOW_H   300      /* ¥¦¥£¥ó¥É¥¦¤Î¹â¤µ */
    6	#define BORDER     2        /* ¥Ü¡¼¥À¤ÎÉý */
    7	#define MOVEB_W    70       /* °ÜÆ°¥Ü¥¿¥ó¤ÎÉý */
    8	#define MOVEB_H    30       /* °ÜÆ°¥Ü¥¿¥ó¤Î¹â¤µ */
    9	#define RESIZEB_W  MOVEB_W  /* ¥µ¥¤¥ºÊѹ¹¥Ü¥¿¥ó¤ÎÉý */
   10	#define RESIZEB_H  MOVEB_H  /* ¥µ¥¤¥ºÊѹ¹¥Ü¥¿¥ó¤Î¹â¤µ */
   11	
   12	
   13	static Display*       dpy;              /* ¥Ç¥£¥¹¥×¥ì¥¤ */
   14	static int            screen;           /* ¥¹¥¯¥ê¡¼¥ó */
   15	static Window         root;             /* ¥ë¡¼¥È¥¦¥£¥ó¥É¥¦ */
   16	static unsigned long  black, white;     /* ¹õ¡¢Çò¤Î¥Ô¥¯¥»¥ëÃÍ */
   17	static GC             gc;               /* ¥°¥é¥Õ¥£¥Ã¥¯¥¹¥³¥ó¥Æ¥­¥¹¥È */
   18	static Window         win;              /* ɽ¼¨¤¹¤ë¥¦¥£¥ó¥É¥¦ */
   19	static Window         move_b, resize_b; /* ¥Ü¥¿¥óÍÑ¥¦¥£¥ó¥É¥¦ */
   20	static int            x = 100, y = 100; /* win ¤Î°ÌÃÖºÂɸ */
   21	
   22	
   23	static void xctrl_init( void );
   24	static void xctrl_create_window( void );
   25	static void xctrl_event_loop( void );
   26	static void xctrl_proc_moveb( void );
   27	static void xctrl_proc_resizeb( void );
   28	
   29	
   30	int 
   31	main( void )
   32	{
   33		/* ½é´ü½èÍý */
   34		xctrl_init();
   35	
   36		/* ¥¦¥£¥ó¥É¥¦ºîÀ® */
   37		xctrl_create_window();
   38	
   39		/* ËͤδĶ­¤Ç¤Ï XCreateSimpleWindow() ¤ÎºÂɸ»ØÄê¤Ç¤Ï»ØÄêÄ̤ê¤Î°ÌÃÖ
   40		   ¤Ëɽ¼¨¤µ¤ì¤Ê¤¤¤Î¤Ç¡¢¥Þ¥Ã¥×¤·¤¿¸å¤Ë°ìÅÙ°ÜÆ°¤µ¤»¤Æ¤¤¤ë */
   41		XMapWindow( dpy, win );
   42		XMoveWindow( dpy, win, x, y );
   43	
   44		/* win¤ò¿Æ¥¦¥£¥ó¥É¥¦¤È¤¹¤ëÁ´¤Æ¤Î»Ò¥¦¥£¥ó¥É¥¦¤ò¥Þ¥Ã¥×¤¹¤ë */
   45		XMapSubwindows( dpy, win );
   46	
   47		/* ¥¤¥Ù¥ó¥È¥ë¡¼¥× */
   48		xctrl_event_loop();
   49	
   50		return 0;
   51	}
   52	
   53	
   54	static void 
   55	xctrl_init( void )
   56	{
   57		dpy = XOpenDisplay( "" );
   58	
   59		root   = DefaultRootWindow( dpy );
   60		screen = DefaultScreen( dpy );
   61	
   62		white = WhitePixel( dpy, screen );
   63		black = BlackPixel( dpy, screen );
   64	}
   65	
   66	
   67	static void 
   68	xctrl_create_window( void )
   69	{
   70		win = XCreateSimpleWindow( dpy, root, 100, 100, 
   71			   WINDOW_W, WINDOW_H, BORDER, black, white );
   72	
   73		move_b = XCreateSimpleWindow( dpy, win, 10, 10, 
   74			      MOVEB_W, MOVEB_H, BORDER, black, white );
   75	
   76		resize_b = XCreateSimpleWindow( dpy, win, 10 + MOVEB_W + 5, 10, 
   77			RESIZEB_W, RESIZEB_H, BORDER, black, white );
   78	
   79		gc = XCreateGC( dpy, win, 0, NULL );
   80		XSetBackground( dpy, gc, white );
   81		XSetForeground( dpy, gc, black );
   82	
   83		XSelectInput( dpy, win,      ExposureMask    | KeyPressMask );
   84		XSelectInput( dpy, move_b,   ButtonPressMask | ExposureMask );
   85		XSelectInput( dpy, resize_b, ButtonPressMask | ExposureMask );
   86	}
   87	
   88	
   89	static void
   90	xctrl_event_loop( void )
   91	{
   92		XEvent event;
   93	
   94		while( 1 ) {
   95			XNextEvent( dpy, &event );
   96			switch( event.type ) {
   97				case Expose:
   98					if ( event.xexpose.count == 0 ) {
   99						/* ¥Ü¥¿¥ó¤Î¥é¥Ù¥ë¤òÉÁ²è */
  100						XDrawString( dpy, move_b, gc, 
  101						    15, MOVEB_H / 2, "MOVE", 
  102						    strlen( "MOVE" ) );
  103	
  104						XDrawString( dpy, resize_b, gc, 
  105						    15, RESIZEB_H / 2, "RESIZE", 
  106						    strlen( "RESIZE" ) );
  107					}
  108					break;
  109	
  110				case ButtonPress:
  111					/* °ÜÆ°¥Ü¥¿¥ó */
  112					if ( event.xbutton.window == move_b  ) {
  113						xctrl_proc_moveb();
  114					}
  115	
  116					/* ¥µ¥¤¥ºÊѹ¹¥Ü¥¿¥ó */
  117					else if ( event.xbutton.window == resize_b ) {
  118						xctrl_proc_resizeb();
  119					}	    
  120	
  121					break;
  122	
  123				case KeyPress:
  124					XFreeGC( dpy, gc );
  125					XDestroyWindow( dpy, win );
  126					XCloseDisplay( dpy );
  127					return;
  128			}
  129		}
  130	}
  131	
  132	
  133	static void 
  134	xctrl_proc_moveb()
  135	{
  136		/* ¥¦¥£¥ó¥É¥¦¥Þ¥Í¡¼¥¸¥ã¤¬´Ö¤Ë¤¤¤ë¤¿¤á¤«¡¢XGetGeometry() ¤Ç¤ÏÀµ¤·¤¯
  137		   °ÌÃÖ¤ò¼èÆÀ¤Ç¤­¤Ê¤«¤Ã¤¿¤Î¤Ç¸½ºßºÂɸ¤ÏÊ̤ËÊݸ¤·¤Æ¤ª¤¯¤³¤È¤Ë¤·¤Æ¡¢
  138		   ¤½¤ì¤ò°ú¿ô¤È¤·¤Æ¥¦¥£¥ó¥É¥¦¤ò°ÜÆ°¤µ¤»¤Æ¤¤¤Þ¤¹¡£ */
  139	
  140		x += 10;
  141		y += 10;
  142		
  143		XMoveWindow( dpy, win, x, y );
  144	}
  145	
  146	
  147	static void 
  148	xctrl_proc_resizeb( void )
  149	{
  150		static int stat = 0;
  151	
  152		unsigned int w, h;
  153		unsigned int dummy;
  154	
  155	
  156		/* ¸½ºß¤ÎÉý¤È¹â¤µ¤ò¼èÆÀ */
  157		XGetGeometry( dpy, win, (Window*)&dummy, (int*)&dummy, (int*)&dummy, 
  158			      &w, &h, &dummy, &dummy );
  159	
  160		if ( ! stat ) {
  161			/* ³ÈÂç */
  162			w    *= 2;
  163			h    *= 2;
  164			stat  = 1;
  165		}
  166		else {
  167			/* ½Ì¾® */
  168			w    /= 2;
  169			h    /= 2;
  170			stat  = 0;
  171		}
  172	
  173		XResizeWindow( dpy, win, w, h );
  174	}
  175	
  176	/* End of xctrl.c */

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

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

  • 4 ¡Á 10 ¹ÔÌÜ

    ³Æ¼ïÄê¿ôÄêµÁ¤ò¹Ô¤Ã¤Æ¤¤¤Þ¤¹¡£º£¤Þ¤Ç¤Î¥á¥¤¥ó¥¦¥£¥ó¥É¥¦ÍѤÎÄê¿ô¤À¤±¤Ç¤Ê¤¯¡¢°ÜÆ°¥Ü¥¿¥ó¤ä¥µ ¥¤¥ºÊѹ¹¥Ü¥¿¥óÍѤÎÄê¿ô¤Ë¤Ä¤¤¤Æ¤âÄêµÁ¤·¤Æ¤¤¤Þ¤¹¡£

  • 13 ¡Á 20 ¹ÔÌÜ

    ¤¤¤í¤¤¤í¤Ê½èÍý¤ò´Ø¿ô¤È¤·¤ÆÀÚ¤êʬ¤±¤¿¤¿¤á¡¢´Ø¿ô´Ö¤Ç¶¦Í­¤¹¤ëÊÑ¿ô¤ò static ÊÑ¿ô¤È¤·¤ÆÀë¸À ¤·¤Æ¤¤¤Þ¤¹¡£xctrl.c ¤ÏÀâÌÀ¤·¤ä¤¹¤¤¤è¤¦¤Ë 1 ¥Õ¥¡¥¤¥ë¤Ë¤·¤Æ¤¤¤ë¤¿¤á static ÊÑ¿ô¤¬Â¿¤¯¤Ê¤Ã ¤Æ¤¤¤Þ¤¹¤¬¡¢¤Á¤ã¤ó¤Èºî¤ë¤Î¤Ç¤¢¤ì¤Ð ¥á¥¤¥ó¥¦¥£¥ó¥É¥¦ / °ÜÆ°¥Ü¥¿¥ó / ¥µ¥¤¥ºÊѹ¹¥Ü¥¿¥ó ¤½ ¤ì¤¾¤ì¤Ë¤Ä¤¤¤Æ¡¢ÊÌ¥Õ¥¡¥¤¥ë¤ËÀÚ¤êʬ¤±¤ëÊý¤¬Îɤ¤ºî¤êÊý¤À¤È»×¤¤¤Þ¤¹¡£

    18¡¢19 ¹ÔÌܤǡ¢°ÜÆ°¥Ü¥¿¥ó / ¥µ¥¤¥ºÊѹ¹¥Ü¥¿¥ó¤È¤·¤Æ»ÈÍѤ¹¤ë Window ·¿ÊÑ¿ô¤òÀë¸À¤·¤Æ¤¤¤Þ¤¹¡£ ¤³¤ì¤é¤Ï¡¢¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤Î»Ò¥¦¥£¥ó¥É¥¦¤È¤·¤Æ¼Â¸½¤·¤Þ¤¹¡£¿Æ»Ò´Ø·¸¤Ë¤¢¤ë¥¦¥£¥ó¥É¥¦´Ö¤Ë ¤Ï¡¢¼¡¤Î¤è¤¦¤ÊÀ­¼Á¤¬¤¢¤ê¤Þ¤¹¡£

    • ¿Æ¥¦¥£¥ó¥É¥¦¤È»Ò¥¦¥£¥ó¥É¥¦¤Ï°ì½ï¤ËÆ°¤­¤Þ¤¹¤¬¡¢¿Æ¥¦¥£¥ó¥É¥¦¤ò¥ê¥µ¥¤¥º¤·¤Æ¤â»Ò¥¦¥£¥ó¥É ¥¦¤ÎÂ礭¤µ¤ÏÊѤï¤ê¤Þ¤»¤ó¡£¿Æ¥¦¥£¥ó¥É¥¦¤ÎÂ礭¤µ¤Ë¹ç¤ï¤»¤Æ»Ò¥¦¥£¥ó¥É¥¦¤ÎÂ礭¤µ¤òÊѤ¨¤¿ ¤¤¾ì¹ç¤Ë¤Ï¡¢¿Æ¥¦¥£¥ó¥É¥¦¤Î¥ê¥µ¥¤¥º¤ò ConfigureNotify ¥¤¥Ù¥ó¥È¤Ë¤è¤Ã¤Æ¸¡ÃΤ·¤Æ¡¢¼«Ê¬¤Ç »Ò¥¦¥£¥ó¥É¥¦¤ÎÂ礭¤µ¤òÊѤ¨¤Ê¤±¤ì¤Ð¤¤¤±¤Þ¤»¤ó¡£

    • »Ò¥¦¥£¥ó¥É¥¦¤Î¿Æ¥¦¥£¥ó¥É¥¦¤«¤é¤Ï¤ß¤À¤·¤¿Éôʬ¤Ï¡¢¿Æ¥¦¥£¥ó¥É¥¦¤Î¥Ü¡¼¥À¤Ç¥¯¥ê¥Ã¥Ô¥ó¥°¤µ ¤ì¤ë¤¿¤áɽ¼¨¤µ¤ì¤Þ¤»¤ó¡£

    Á°¼Ô¤ÎÀ­¼Á¤Ë¤è¤ê¡¢xctrl.c ¤Ç RESIZE ¥Ü¥¿¥ó¤ò¥¯¥ê¥Ã¥¯¤·¤Æ¥¦¥£¥ó¥É¥¦¤ò³ÈÂç/½Ì¾®¤·¤Æ¤â¡¢ ¥Ü¥¿¥ó¤Î¥µ¥¤¥º¤ÏÊѤï¤ê¤Þ¤»¤ó¡£

  • 23 ¡Á 27 ¹ÔÌÜ

    xctrl.c ¤Ç¤Ï¡¢¤³¤³¤Ç¥×¥í¥È¥¿¥¤¥×Àë¸À¤µ¤ì¤Æ¤¤¤ë´Ø¿ôñ°Ì¤Ë½èÍý¤òÀÚ¤êʬ¤±¤Æ¤¤¤Þ¤¹¡£³Æ´Ø¿ô ¤Ë¤Ä¤¤¤Æ¤Ï¡¢°Ê¹ß¤ÇÀâÌÀ¤·¤Þ¤¹¡£

  • 30 ¡Á51 ¹ÔÌÜ ( main() )

    xctrl.c ¤Î main ´Ø¿ô¤Ç¤¹¡£¤ª¤ª¤Þ¤«¤Ê½èÍý¤Ï¡¢

    • ½é´ü½èÍý ( xctrl_init() )
    • ¥¦¥£¥ó¥É¥¦ºîÀ® ( xctrl_create_window() )
    • ¥¦¥£¥ó¥É¥¦¤Î¥Þ¥Ã¥× ( XMapWindow() )
    • ½é´üɽ¼¨ºÂɸ¤Ø¤Î¥¦¥£¥ó¥É¥¦¤Î°ÜÆ° ( XMoveWindow() )
    • »Ò¥¦¥£¥ó¥É¥¦¤Î¥Þ¥Ã¥× ( XMapSubwindows() )
    • ¥¤¥Ù¥ó¥È¥ë¡¼¥× ( xctrl_event_loop() )

    ¤È¤Ê¤ê¤Þ¤¹¡£XCreateSimpleWindow() ¤ÎºÂɸ»ØÄê¤Ç´õ˾Ä̤ê¤Î°ÌÃ֤˥¦¥£¥ó¥É¥¦¤¬É½¼¨¤µ¤ì¤ë¾ì¹ç ¤Ï¡¢XMoveWindow() ¤ò¼Â¹Ô¤¹¤ëɬÍפϤ¢¤ê¤Þ¤»¤ó¡£

  • 54 ¡Á 64 ¹ÔÌÜ ( xctrl_init() )

    ¤³¤³¤Ç¤Ï¡¢

    • X ¥µ¡¼¥Ð¤È¤ÎÀܳ
    • ¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¡¢¥¹¥¯¥ê¡¼¥ó¾ðÊó¤Î¼èÆÀ
    • Çò¡¢¹õ¿§¤Î¥Ô¥¯¥»¥ëÃͤò¼èÆÀ

    ¤È¤¤¤¦½èÍý¤ò½é´ü½èÍý¤È¤·¤Æ¹Ô¤Ã¤Æ¤¤¤Þ¤¹¡£

  • 67 ¡Á 86 ¹ÔÌÜ ( xctrl_create_window() )

    ¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¡¢°ÜÆ°¥Ü¥¿¥ó¡¢¥µ¥¤¥ºÊѹ¹¥Ü¥¿¥ó¤Î 3 ¤Ä¤Î¥¦¥£¥ó¥É¥¦¤òºîÀ®¤·¡¢¤½¤Î¸åÉÁ²è¤Ë »ÈÍѤ¹¤ë GC ¤òºîÀ®¤·¤Æ¤¤¤Þ¤¹¡£¤³¤Î GC ¤Ï¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ò»È¤Ã¤ÆºîÀ®¤·¤Æ¤¤¤Þ¤¹¤¬¡¢3 ¤Ä ¤Î¥¦¥£¥ó¥É¥¦¤ÏƱ¤¸¿¼¤µ¤Ê¤Î¤Ç¡¢¤³¤³¤ÇºîÀ®¤·¤¿ GC ¤ò»È¤Ã¤Æ¥Ü¥¿¥ó¤Ø¤ÎÉÁ²è¤â¹Ô¤¨¤Þ¤¹¡£

    ¤½¤Î¸å¡¢³Æ¥¦¥£¥ó¥É¥¦¤ËɬÍפʥ¤¥Ù¥ó¥È¤òÁªÂò¤·¤Æ¤¤¤Þ¤¹¡£¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤Ç¤Ï Esc ¥­¡¼¤Î²¡ ²¼¤ò¸¡½Ð¤¹¤ë¤¿¤á¤Ë KeyPressMask ¤ò¡¢¥Ü¥¿¥ó¤Ç¤Ï¥Þ¥¦¥¹¥¯¥ê¥Ã¥¯¤ò¸¡½Ð¤¹¤ë¤¿¤á¤Ë ButtonPressMask ¤ò»ØÄꤷ¤Æ¤¤¤Þ¤¹¡£

  • 89 ¡Á 130 ¹ÔÌÜ ( xctrl_event_loop() )

    ¼ç½èÍý¤ò¹Ô¤¦¥¤¥Ù¥ó¥È¥ë¡¼¥×¤Ç¤¹¡£while ¥ë¡¼¥×Æâ¤Ç¡¢Expose ¥¤¥Ù¥ó¥È¡¢ButtonPress ¥¤¥Ù¥ó¥È¡¢ KeyPress ¥¤¥Ù¥ó¥È¤ò½¦¤Ã¤Æ½èÍý¤ò¿¶¤êʬ¤±¤Æ¤¤¤Þ¤¹¡£

    • Expose ¥¤¥Ù¥ó¥È»þ

      XDrawString() ¤ò»ÈÍѤ·¤Æ¥Ü¥¿¥ó¤Ëɽ¼¨¤µ¤ì¤ë¥é¥Ù¥ë¤òÉÁ²è¤·¤Æ¤¤¤Þ¤¹¡£ButtonPress ¥¤¥Ù¥ó ¥È¤Î¤è¤¦¤Ë¡¢¥¤¥Ù¥ó¥ÈȯÀ¸¸µ¥¦¥£¥ó¥É¥¦¤òȽÄꤷ¤Æ¤¤¤Ê¤¤¤¿¤á¡¢3 ¤Ä¤Î¥¦¥£¥ó¥É¥¦¤Ç Expose ¥¤¥Ù¥ó¥È¤¬È¯À¸¤·¤¿¾ì¹çÁ´¤Æ¤Ç¤³¤Î½èÍý¤¬¹Ô¤ï¤ì¤Þ¤¹¡£¤³¤Î̵Â̤µ¤¬·ù¤Ê¾ì¹ç¤Ï¡¢°ÜÆ°¥Ü¥¿¥ó ¤Î Expose ¥¤¥Ù¥ó¥È»þ¤Ë¤Ï°ÜÆ°¥Ü¥¿¥ó¤Î¥é¥Ù¥ëÉÁ²è¤ò¡¢¥µ¥¤¥ºÊѹ¹¥Ü¥¿¥ó¤Î Expose ¥¤¥Ù¥ó¥È »þ¤Ë¤Ï¥µ¥¤¥ºÊѹ¹¥Ü¥¿¥ó¤Î¥é¥Ù¥ëÉÁ²è¤ò¹Ô¤¦¤è¤¦¤Ë½ñ¤­´¹¤¨¤ë¤È¤¤¤¤¤È»×¤¤¤Þ¤¹¡£

    • ButtonPress ¥¤¥Ù¥ó¥È»þ

      ¤Þ¤º event.xbutton.window ¥á¥ó¥Ð(¥¤¥Ù¥ó¥È¤ÎȯÀ¸¸µ¥¦¥£¥ó¥É¥¦ ID )¤È³Æ¥Ü¥¿¥ó¤Î¥¦¥£¥ó¥É ¥¦ ID ¤òÈæ³Ó¤·¤Æ¡¢°ÜÆ°¥Ü¥¿¥ó¤Î¥¦¥£¥ó¥É¥¦ ID ¤È°ìÃפ·¤¿¾ì¹ç¤Ï xctrl_proc_moveb() ¤ò¡¢ ¥µ¥¤¥ºÊѹ¹¥Ü¥¿¥ó¤Î¥¦¥£¥ó¥É¥¦ ID ¤È°ìÃפ·¤¿¾ì¹ç¤Ï xctrl_proc_resizeb() ¤ò¼Â¹Ô¤·¤Æ¤¤¤Þ ¤¹¡£

    • KeyPress ¥¤¥Ù¥ó¥È»þ

      ¤Þ¤º¡¢XLookupString() ¤ò»È¤Ã¤Æ KeyPressEvent ¤ÇÄÌÃΤµ¤ì¤¿¥­¡¼¥³¡¼¥ÉÈÖ¹æ¤ò ASCII ʸ»ú Î󤪤è¤Ó KeySym ̾¤ËÊÑ´¹¤·¤Æ¤¤¤Þ¤¹¡£¤³¤ì¤Ë¤Ä¤¤¤Æ¤Ï¡¢LECTURE 10 ¤Ç¾Ü¤·¤¯ÀâÌÀ¤·¤Þ¤¹¡£

      ÊÑ´¹¤Ë¤è¤Ã¤ÆÆÀ¤é¤ì¤¿ KeySym ̾¤È Esc ¥­¡¼¤Î KeySym ̾( XK_Escape ) ¤òÈæ³Ó¤·¤Æ¡¢°ìÃפ¹ ¤ë¾ì¹ç¤Ë¤Ï¥ê¥½¡¼¥¹¤ò²òÊü¤·¤Æ¥×¥í¥°¥é¥à¤ò½ªÎ»¤·¤Æ¤¤¤Þ¤¹¡£¥ê¥½¡¼¥¹¤Î²òÊü¤Ë¤ª¤¤¤Æ¡¢¥á¥¤ ¥ó¥¦¥£¥ó¥É¥¦¤ËÂФ·¤Æ¤Î¤ß XDestroyWindow() ¤¬¼Â¹Ô¤µ¤ì¤Æ¤¤¤Þ¤¹¤¬¡¢¤³¤ì¤Ë¤è¤Ã¤Æ¼«Æ°Åª¤Ë ¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎÁ´¤Æ¤Î»Ò¥¦¥£¥ó¥É¥¦¤âÇË´þ¤µ¤ì¤Þ¤¹¡£

  • 133 ¡Á 144 ¹ÔÌÜ ( xctrl_proc_moveb() )

    °ÜÆ°¥Ü¥¿¥ó¤¬¥¯¥ê¥Ã¥¯¤µ¤ì¤¿¾ì¹ç¤Ë¼Â¹Ô¤µ¤ì¤ë½èÍý¤Ç¤¹¡£¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤Î¸½ºß¤Î°ÌÃÖºÂɸ¤Î x ¤È y ¤Ë¤½¤ì¤¾¤ì 10 ¤ò­¤·¤¿¸å¤Ë XMoveWindow() ¤ò»È¤Ã¤Æ¥¦¥£¥ó¥É¥¦¤ò°ÜÆ°¤µ¤»¤Æ¤¤¤Þ¤¹¡£ ¥¦¥£¥ó¥É¥¦¤Î¸½ºß°ÌÃÖ¤ò¼èÆÀ¤¹¤ë¤Ë¤Ï¡¢ËÜÍè¤Ï¸åÄøÀâÌÀ¤¹¤ë XGetGeometry() ¤ò»È¤¤¤Þ¤¹¡£¤·¤« ¤·¡¢XCreateSimpleWindow() ¤ÎºÂɸ»ØÄ꤬¤¦¤Þ¤¯¤¤¤«¤Ê¤¤¤Î¤ÈƱ¤¸Íýͳ¤«¤é¤«ËͤδĶ­¤Ç¤ÏÀµ¤· ¤¤°ÌÃÖºÂɸ¤¬¼èÆÀ¤Ç¤­¤Ê¤«¤Ã¤¿¤¿¤á¡¢¥Õ¥¡¥¤¥ë¥¹¥³¡¼¥×¤ò»ý¤Ä static ÊÑ¿ô¤Ë¸½ºß°ÌÃÖ¤òÊݸ¤¹ ¤ë¤è¤¦¤Ë¤·¤Æ¤¤¤Þ¤¹¡£

  • 147 ¡Á 174 ¹ÔÌÜ ( xctrl_proc_resizeb() )

    ¥µ¥¤¥ºÊѹ¹¥Ü¥¿¥ó¤¬¥¯¥ê¥Ã¥¯¤µ¤ì¤¿¾ì¹ç¤Ë¼Â¹Ô¤µ¤ì¤ë½èÍý¤Ç¤¹¡£¤Þ¤º¡¢¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤Î¸½ºß ¤ÎÉý¤È¹â¤µ¤ò¼èÆÀ¤¹¤ë¤¿¤á¤Ë¡¢XGetGeometry() ¤ò»È¤Ã¤Æ¤¤¤Þ¤¹(¤³¤ì¤Ë¤Ä¤¤¤Æ¤ÏÀµ¾ï¤ËÆ°ºî¤·¤Þ ¤¹)¡£

      Status XGetGeometry( Display*      display, 
                           Drawable      d, 
                           Window*       root, 
                           int*          x, 
                           int*          y, 
                           unsigned int* width, 
                           unsigned int* height, 
                           unsigned int* border, 
                           unsigned int* depth 
                         );
    
      root          : d ¤Î¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤Î ID ¤¬³ÊǼ¤µ¤ì¤ë
      x, y          : d ¤Î¿Æ¥¦¥£¥ó¥É¥¦Æâ¤Ç¤ÎºÂɸ¤¬³ÊǼ¤µ¤ì¤ë
      width, height : d ¤ÎÉý¤È¹â¤µ¤¬³ÊǼ¤µ¤ì¤ë
      border, depth : d ¤Î¥Ü¡¼¥À¤ÎÉý¤È¿¼¤µ¤¬³ÊǼ¤µ¤ì¤ë
    
    

    XGetGeometry() ¤ò»È¤¦¤È¡¢»ØÄꤷ¤¿ Drawable ¤Î¡¢¿Æ¥¦¥£¥ó¥É¥¦Æâ¤Ç¤Î°ÌÃÖ¤ÈÂ礭¤µ¤Ë´Ø¤¹¤ë¾ð Ê󤬼èÆÀ¤Ç¤­¤Þ¤¹¡£Drawable ¤¬¥Ô¥¯¥¹¥Þ¥Ã¥×¤Î¾ì¹ç¤Ï x¡¢y¡¢border ¤Ï¸ºß¤·¤Ê¤¤¤Î¤Ç¤Ä¤Í¤Ë 0 ¤¬³ÊǼ¤µ¤ì¤Þ¤¹¡£XGetGeometry() ¤Ï¡¢À®¸ù»þ¤Ë¤Ï 0 °Ê³°¤ÎÃÍ¡¢¼ºÇÔ»þ¤Ë¤Ï 0 ¤òÊÖ¤·¤Þ¤¹¡£

    ÊÑ¿ô stat ¤Ë¸½ºß¤Î¾õÂÖ( 0 ¤Ê¤é¤ÐÄ̾ï¾õÂÖ¡¢1 ¤Ê¤é¤Ð³ÈÂç¾õÂ֤Ȥ·¤Æ¤¤¤ë)¤¬³ÊǼ¤µ¤ì¤Æ¤¤¤ë¤Î ¤Ç¡¢¤½¤ì¤Ë±þ¤¸¤Æ¿·¤¿¤ÊÉý¤È¹â¤µ¤ò·×»»¤·¡¢XResizeWindow() ¤ò»È¤Ã¤Æ¥¦¥£¥ó¥É¥¦¤Î¥µ¥¤¥º¤òÊÑ ¹¹¤·¤Æ¤¤¤Þ¤¹¡£

      XResizeWindow( Display*     display, 
                     Window       w, 
                     unsigned int width, 
                     unsigned int height 
                   );
    
      width  : Êѹ¹¸å¤Î¥¦¥£¥ó¥É¥¦¤ÎÉý
      height : Êѹ¹¸å¤Î¥¦¥£¥ó¥É¥¦¤Î¹â¤µ
    
    

    ¤Á¤Ê¤ß¤Ë¡¢XResizeWindow() ¤È XMoveWindow() ¤Î½èÍý¤òƱ»þ¤Ë¹Ô¤¦ XMoveResizeWindow() ¤È¤¤ ¤¦´Ø¿ô¤¬¤¢¤ê¤Þ¤¹¡£

      XMoveResizeWindow( Display*     display, 
                         Window       w, 
                         int          x, 
                         int          y, 
                         unsigned int width, 
                         unsigned int height 
                       );
    
    

°Ê¾å¤Ç xctrl.c ¤ÎÀâÌÀ¤Ï½ª¤ê¤Ç¤¹¡£¤Ê¤ª¡¢xctrl.c ¤Ç¤Ï»È¤ï¤Ê¤«¤Ã¤¿¥¦¥£¥ó¥É¥¦¤Î¥Ü¡¼¥ÀÉý¤òÊѹ¹¤¹¤ë´Ø¿ô¡¢¤ª¤è¤Ó¥¦¥£¥ó¥É¥¦¤ò°ìÈÖ¾å / ²¼¤Ëɽ¼¨¤·¤Ê¤ª¤¹´Ø¿ô¤ò°Ê²¼¤Ë¾Ò²ð¤·¤Æ¤ª¤­¤Þ¤¹¡£

¡û ¥¦¥£¥ó¥É¥¦¤Î¥Ü¡¼¥ÀÉý¤òÊѹ¹¤¹¤ë

¥¦¥£¥ó¥É¥¦¤Î¥Ü¡¼¥ÀÉý¤òÊѹ¹¤¹¤ë¤Ë¤Ï XSetWindowBorderWidth() ¤ò»È¤¤¤Þ¤¹¡£

XSetWindowBorderWidth( Display* display, Window w, unsigned int width );

width : ¿·¤·¤¤¥Ü¡¼¥ÀÉý

¡û ¥¦¥£¥ó¥É¥¦¤ò°ìÈÖ¾å/²¼¤Ëɽ¼¨¤¹¤ë

¥¸¥ª¥á¥È¥êÁàºî¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¤¬¡¢¥¦¥£¥ó¥É¥¦¤ò°ìÈÖ¾å¤Ëɽ¼¨¤¹¤ë¤Ë¤Ï XRaiseWindow() ¤ò»È¤¤¤Þ¤¹¡£¤½¤ÎµÕ¤Ë°ìÈÖ²¼¤Ëɽ¼¨¤¹¤ë¤Ë¤Ï XLowerWindow() ¤ò»È¤¤¤Þ¤¹¡£

XRaiseWindow( Display* display, Window w );
XLowerWindow( Display* display, Window w );