|
¡û ¤Ï¤¸¤á¤Ë
ÅÀÌǤ¹¤ë¥é¥ó¥×¤Î¤è¤¦¤Ê¥Ö¥ê¥ó¥¯(ÅÀÌÇ)ÉÁ²è½èÍý¤ò¹Ô¤¦¾ì¹ç¡¢ÉáÄ̤ޤººÇ½é¤Ë»×¤¤ÉÕ¤¯¤Î¤ÏƱ¤¸ÉÁ²èÂоݤòÊ̤ο§¤ÇºÆÉÁ²è¤¹¤ëÊýË¡¤À¤È»×¤¤¤Þ¤¹¡£¤³¤ÎÊýË¡¤Î¾ì¹ç¡¢ºÆÉÁ²è¤ÎÂоݤ¬¤È¤Æ¤â¿¤«¤Ã¤¿¤ê¡¢ÉÁ²è½èÍý¤¬ÃÙ¤¤¥Þ¥·¥ó¤ò»È¤Ã¤Æ¤¤¤¿¤ê¤¹¤ë¤È¡¢´õ˾Ä̤ê¤ÎÆ°²è¤¬ÆÀ¤é¤ì¤Ê¤¤²ÄǽÀ¤¬¤¢¤ê¤Þ¤¹¡£
¤½¤ÎÂå¤ï¤ê¤Ë Xlib ¤ò»È¤Ã¤¿¥×¥í¥°¥é¥ß¥ó¥°¤Ç¤Ï¡¢¥«¥é¡¼¥Þ¥Ã¥×Æâ¤Î¥«¥é¡¼¥»¥ë¤Î RGB Ãͤò½ñ¤´¹¤¨¤ë¤³¤È¤Ç¡¢¤½¤Î¥«¥é¡¼¥»¥ë¤ò»²¾È¤·¤Æ¤¤¤ëÉÁ²è¿§¤òưŪ¤ËÊѹ¹¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£¤³¤ÎÊýË¡¤ò»È¤¨¤ÐƱ¤¸¿§¤ò»È¤Ã¤Æ¤¤¤ë¿¿ô¤ÎÉÁ²èÂоݤ理òƱ»þ¤ËÊѹ¹¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
¤³¤³¤Ç¤Ï¥«¥é¡¼¥»¥ë¤Î½ñ¤´¹¤¨¤ò¹Ô¤¦ÊýË¡¤Ë¤Ä¤¤¤ÆÀâÌÀ¤·¤Æ¤¤¤¤Þ¤¹¡£
¡û ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à
¥«¥é¡¼¥»¥ë¤Î½ñ¤´¹¤¨¤ò»È¤Ã¤Æ¡¢¥¦¥£¥ó¥É¥¦¤ÎÇØ·Ê¿§¤ò¹õ/À֤Π2 ¿§¤ÇÀÚÂؤ¨¤ë¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à xblink.c ¤Ç¤¹¡£¤Ï¤¸¤á¤Ë ¤Î¥Ú¡¼¥¸¤«¤é¡¢Á´¤Æ¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ò¸Ç¤á¤¿ tar ¥Ü¡¼¥ë¤ò¥À¥¦¥ó¥í¡¼¥É¤¹¤ë¤³¤È¤â¤Ç¤¤Þ¤¹¡£
¤³¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ò¼Â¹Ô¤¹¤ë¤Ë¤Ï¾ò·ï¤¬¤¢¤ê¤Þ¤¹¡£X ¥µ¡¼¥Ð¤¬ PseudoColor ¤â¤·¤¯¤Ï DirectColor ¤Î¥Ó¥¸¥å¥¢¥ë¤Çµ¯Æ°¤·¤Æ¤¤¤ë¤³¤È¤¬É¬¿Ü¾ò·ï¤Ç¤¹¡£
¸½ºß X ¥µ¡¼¥Ð¤¬¤É¤Î¥Ó¥¸¥å¥¢¥ë¤Çµ¯Æ°¤·¤Æ¤¤¤ë¤«¤òÄ´¤Ù¤ë¤Ë¤Ï¡¢kterm ¤Ê¤É¤Î¥³¥ó¥½¡¼¥ë¤«¤é xdpyinfo ¤ò¼Â¹Ô¤·¤Þ¤¹¡£¤³¤Î¥³¥Þ¥ó¥É¤ò¼Â¹Ô¤¹¤ë¤È¡¢X ¥µ¡¼¥Ð¤Ë´Ø¤¹¤ëÍÍ¡¹¤Ê¾ðÊó¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£¤½¤Î½ÐÎϤÎÃ椫¤é default visual id : ¤È½ñ¤«¤ì¤Æ¤¤¤ë¹Ô¤ò¸«ÉÕ¤±¤Æ¡¢visual id ¤¬¤¤¤¯¤Ä¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤«¤òÄ´¤Ù¤Þ¤¹¡£visual id ¤¬Ê¬¤«¤Ã¤¿¤é¡¢¤½¤Î id ¤ËÂбþ¤¹¤ë¥Ó¥¸¥å¥¢¥ë¤Î¾ðÊó¤òõ¤·¤Þ¤¹¡£Âбþ¤¹¤ë¥Ó¥¸¥å¥¢¥ë¾ðÊó¤ÎÃæ¤Ë class ¤È¤¤¤¦µ½Ò¤¬¤¢¤ê¤Þ¤¹¤¬¡¢¤½¤³¤Ë PseudoColor¡¢TrueColor ¤Ê¤É¤Î¥Ó¥¸¥å¥¢¥ë¥¯¥é¥¹¤¬µ½Ò¤µ¤ì¤Æ¤¤¤Þ¤¹¡£
²¼¤Ï xdpyinfo ¤Î½ÐÎÏÎã¤Î°ìÉô¤Ç¤¹¡£
default visual id: 0x22 visual: visual id: 0x22 class: TrueColor depth: 16 planes available colormap entries: 64 per subfield red, green, blue masks: 0xf800, 0x7e0, 0x1f significant bits in color specification: 6 bits
¾å¤ÎÎã¤À¤È¡¢default visual id ¤¬ 0x22 ¤Ç¤¢¤ê¡¢Âбþ¤¹¤ë¥Ó¥¸¥å¥¢¥ë¤Î¥¯¥é¥¹¤Ï TrueColor ¤Ç¤¢¤ë¤³¤È¤¬Ê¬¤«¤ê¤Þ¤¹¡£¤³¤Î¥Ç¥£¥¹¥×¥ì¥¤¤À¤È xblink.c ¤ÎÆâÍƤϼ¹ԤǤ¤Þ¤»¤ó¡£X ¥µ¡¼¥Ð¤ò 8 bit ¥â¡¼¥É¤ÇºÆµ¯Æ°¤¹¤ì¤Ð¤ª¤½¤é¤¯ PseudoColor ¤Çµ¯Æ°¤¹¤ë¤È»×¤¤¤Þ¤¹¤Î¤Ç¡¢¤ä¤Ã¤Æ¤ß¤Æ²¼¤µ¤¤¡£DirectColor ¥â¡¼¥É¤Çµ¯Æ°¤¹¤ëÊýË¡¤Ï»ÄÇ°¤Ê¤¬¤éËͤˤÏʬ¤«¤ê¤Þ¤»¤ó¡£
¤¢¤È¡¢PseudoColor ¤â¤·¤¯¤Ï DirectColor ¤Çµ¯Æ°¤·¤¿¤È¤·¤Æ¤â¡¢É½¸½¤Ç¤¤ë¿§¿ô¤òÁ´¤Æ»ÈÍѤ·¤Æ¤¤¤ë¤è¤¦¤Ê¥¦¥£¥ó¥É¥¦¥Þ¥Í¡¼¥¸¥ã¤ò»È¤Ã¤Æ¤¤¤ë¾ì¹ç¡¢¸å½Ò¤Î XAllocColorCells() ¤Ë¤è¤ë¥«¥é¡¼¥»¥ë¤Î³ÎÊݤ˼ºÇÔ¤¹¤ë²ÄǽÀ¤¬¤¢¤ê¤Þ¤¹¡£¤½¤Î¾ì¹ç¤Ï twm ¤È¤«¤Î¿§¿ô¾¯¤Ê¤½¤¦¤Ê¥¦¥£¥ó¥É¥¦¥Þ¥Í¡¼¥¸¥ã¤Ç¼Â¸³¤·¤Æ¤ß¤Æ²¼¤µ¤¤( DirectColor ¤Ç¤Ï̵¤¤¤È»×¤¤¤Þ¤¹¤¬¡¢PseudoColor ¤À¤È 256 ¿§¤Ê¤Î¤Ç¤¢¤êÆÀ¤ë)¡£
xblink.c ¤ò¥³¥ó¥Ñ¥¤¥ë¤·¤Æ PseudoColor ¤â¤·¤¯¤Ï DirectColor ´Ä¶¤Ç ¼Â¹Ô¤¹¤ë¤È¡¢1 ÉÃËè¤Ë¥¦¥£¥ó¥É¥¦¤ÎÇØ·Ê¿§¤¬ ÀÖ <---> ¹õ ¤ÈÀÚ¤êÂؤï¤ê¤Þ¤¹¡£²¿¤«¥¡¼¤ò²¡¤¹¤È½ªÎ»¤·¤Þ¤¹¡£
¢¬¤È¢¤¬¸ò¸ß¤ËÀÚ¤êÂؤï¤ê¤Þ¤¹¡£
--- xblink.c ---
1 #include <X11/Xlib.h> 2 #include <X11/Xutil.h> 3 #include <stdio.h> 4 #include <time.h> 5 6 7 #define WIN_W 400 /* ¥¦¥£¥ó¥É¥¦¤ÎÉý */ 8 #define WIN_H 300 /* ¥¦¥£¥ó¥É¥¦¤Î¹â¤µ */ 9 #define WIN_X 100 /* ¥¦¥£¥ó¥É¥¦É½¼¨°ÌÃÖ(X) */ 10 #define WIN_Y 100 /* ¥¦¥£¥ó¥É¥¦É½¼¨°ÌÃÖ(Y) */ 11 #define BORDER 2 /* ¥Ü¡¼¥À¤ÎÉý */ 12 13 14 static Display* dpy; /* ¥Ç¥£¥¹¥×¥ì¥¤ */ 15 static Window root; /* ¥ë¡¼¥È¥¦¥£¥ó¥É¥¦ */ 16 static Window win; /* ɽ¼¨¤¹¤ë¥¦¥£¥ó¥É¥¦ */ 17 static int screen; /* ¥¹¥¯¥ê¡¼¥ó */ 18 static int depth; /* ¥¹¥¯¥ê¡¼¥ó¤Î¿¼¤µ */ 19 static XVisualInfo visual_info; /* ¥Ó¥¸¥å¥¢¥ë */ 20 static Colormap cmap; /* ¥«¥é¡¼¥Þ¥Ã¥× */ 21 static unsigned long color_pixel; /* ÀÚÂؤ¨¿§¤Ë»ÈÍѤ¹¤ë¥Ô¥¯¥»¥ëÃÍ */ 22 static XColor color[2]; /* ÀÚÂؤ¨¤Ë»È¤¦¿§( RGB ) */ 23 24 25 static void xblink_init( void ); 26 static int xblink_check_visual( void ); 27 static void xblink_create_window( void ); 28 static int xblink_alloc_color( void ); 29 static void xblink_event_loop( void ); 30 31 32 int 33 main( void ) 34 { 35 xblink_init(); 36 37 /* ¥Ó¥¸¥å¥¢¥ë¤ò¥Á¥§¥Ã¥¯¤¹¤ë */ 38 if ( xblink_check_visual() == -1 ) { 39 return 1; 40 } 41 42 /* Æɤ߽ñ¤Î¾ÍÑ¥«¥é¡¼¥»¥ë¤ò³ä¤êÅö¤Æ¡¢¿§¤òÀßÄꤹ¤ë */ 43 if ( xblink_alloc_color() == -1 ) { 44 return 1; 45 } 46 47 xblink_create_window(); 48 XMapWindow( dpy, win ); 49 xblink_event_loop(); 50 51 return 0; 52 } 53 54 55 static void 56 xblink_init( void ) 57 { 58 dpy = XOpenDisplay( "" ); 59 60 root = DefaultRootWindow( dpy ); 61 screen = DefaultScreen( dpy ); 62 depth = DefaultDepth( dpy, screen ); 63 cmap = DefaultColormap( dpy, screen ); 64 } 65 66 67 /* 68 * PseudoColor ¤â¤·¤¯¤Ï DirectColor ¤Î¥Ó¥¸¥å¥¢¥ë 69 * ¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¤«¤É¤¦¤«¥Á¥§¥Ã¥¯¤¹¤ë¡£ 70 */ 71 static int 72 xblink_check_visual( void ) 73 { 74 /* XAllocColorCells() ¤Î¤¿¤á¤Ë¡¢Æɤ߽ñ¤Î¾ÍѤΥӥ¸¥å¥¢¥ë¤¬ 75 ¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¤«¤É¤¦¤«¥Á¥§¥Ã¥¯ */ 76 if ( ! XMatchVisualInfo( dpy, screen, depth, PseudoColor, &visual_info ) ) { 77 printf( "Writable visual class is not supported.\n" ); 78 return -1; 79 } 80 81 return 0; 82 } 83 84 85 /* 86 * Æɤ߽ñ¤Î¾ÍѤΥ«¥é¡¼¥»¥ë¤ò 1 ¸Ä³ÎÊݤ·¡¢½é´üɽ¼¨¿§¤òÀßÄꤷ¤Æ¤ª¤¯¡£ 87 */ 88 static int 89 xblink_alloc_color( void ) 90 { 91 unsigned long b_pixel[1], p_mask[1]; 92 int i; 93 94 /* ¿§ÀÚÂؤ¨ÍѤˡ¢Æɤ߽ñ¤Î¾ÍѤΥ«¥é¡¼¥»¥ë¤ò 1 ¤Ä³ä¤êÅö¤Æ¤ë */ 95 if ( XAllocColorCells( dpy, cmap, True, p_mask, 0, b_pixel, 1 ) == 0 ) { 96 printf( "XAllocColorCells() failed\n" ); 97 return -1; 98 } 99 100 /* b_pixel[0] ¤Ë¥Ô¥¯¥»¥ëÃͤ¬³ÊǼ¤µ¤ì¤Æ¤¤¤ë¡£xblink.c ¤Ç¤Ï p_mask ¤Ë°ÕÌ£¤Ï̵¤¤ */ 101 color_pixel = b_pixel[0]; 102 103 if ( ! XParseColor( dpy, cmap, "red", &color[0] ) ) { 104 printf( "XParseColor() for red failed\n" ); 105 return -1; 106 } 107 108 if ( ! XParseColor( dpy, cmap, "black", &color[1] ) ) { 109 printf( "XParseColor() for black failed\n" ); 110 return -1; 111 } 112 113 for ( i = 0; i < 2; i ++ ) { 114 color[i].pixel = color_pixel; 115 color[i].flags = DoRed | DoGreen | DoBlue; 116 } 117 118 /* ½é´üɽ¼¨¿§¤òÀÖ¿§¤ËÀßÄê */ 119 XStoreColor( dpy, cmap, &color[0] ); 120 return 0; 121 } 122 123 124 /* 125 * ¥¦¥£¥ó¥É¥¦¤ÎºîÀ® / ¥°¥é¥Õ¥£¥Ã¥¯¥¹¥³¥ó¥Æ¥¥¹¥È¤ÎºîÀ®¤ò¹Ô¤¦¡£ 126 */ 127 static void 128 xblink_create_window( void ) 129 { 130 /* ¥¦¥£¥ó¥É¥¦¤òºîÀ®¤¹¤ë¡£¤³¤Î»þÅÀ¤Ç¤Ï¤Þ¤À²èÌ̤Ëɽ¼¨¤µ¤ì¤Ê¤¤¡£*/ 131 win = XCreateSimpleWindow( dpy, root, 132 WIN_X, WIN_Y, WIN_W, WIN_H, BORDER, 133 color_pixel, color_pixel ); 134 135 XSelectInput( dpy, win, KeyPressMask ); 136 } 137 138 139 static void 140 xblink_event_loop( void ) 141 { 142 /* ¸½ºß¤Îɽ¼¨¿§¤ò¼¨¤¹¥¤¥ó¥Ç¥Ã¥¯¥¹ */ 143 int current_col = 0; 144 145 /* ºÇ¸å¤Ëɽ¼¨¿§¤òÀÚÂؤ¨¤¿»þ¹ï */ 146 time_t previous = time( NULL ); 147 148 time_t now; /* ¸½ºß»þ¹ï */ 149 XEvent evt; /* ¥¤¥Ù¥ó¥È¹½Â¤ÂÎÊÑ¿ô */ 150 151 while( 1 ) { 152 /* 153 * ¤Þ¤ºÉ½¼¨¿§¤ÎÀÚ¤êÂؤ¨½èÍý¤ò¹Ô¤Ã¤Æ¤«¤é¡¢¥¤¥Ù¥ó¥È 154 * ¤Î½èÍý¤ò¹Ô¤¦( ¤É¤Á¤é¤¬Àè¤Ç¤âÎɤ¤¤Î¤À¤¬)¡£ 155 */ 156 157 now = time( NULL ); 158 159 /* Á°²óÀÚÂؤ¨»þ¹ï¤è¤ê 1 É÷вᤷ¤Æ¤¤¤¿¤é¡¢É½¼¨¿§¤òÀÚÂؤ¨¤ë */ 160 if ( now - previous >= 1 ) { 161 if ( current_col == 0 ) { 162 current_col ++; 163 } 164 else { 165 current_col = 0; 166 } 167 168 /* ɽ¼¨¿§¤òÀÚÂؤ¨¤ë */ 169 XStoreColor( dpy, cmap, &color[ current_col ] ); 170 171 /* ÀÚÂؤ¨»þ¹ï¤òÊݸ */ 172 previous = now; 173 } 174 175 while ( XPending( dpy ) ) { 176 XNextEvent( dpy, &evt ); 177 178 switch ( evt.type ) { 179 case KeyPress: 180 /* ¥ê¥½¡¼¥¹¤Î²òÊü */ 181 /* 182 * XFreeColors( 183 * dpy, cmap, &color_pixel, 1, planes ); 184 */ 185 XDestroyWindow( dpy, win ); 186 XCloseDisplay( dpy ); 187 return; 188 } 189 } 190 } 191 } 192 193 194 /* End of xblink.c */
¡û ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ÎÀâÌÀ
¤Ç¤Ï¡¢¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ë¤Ä¤¤¤ÆÀâÌÀ¤·¤Æ¤¤¤¤Þ¤¹¡£
- 14 ¡Á 22 ¹ÔÌÜ
¥Õ¥¡¥¤¥ëÆâ¤Ç»ÈÍѤ¹¤ëÊÑ¿ô¤òÀë¸À¤·¤Æ¤¤¤Þ¤¹¡£color_pixel ¤Ï¡¢¥¦¥£¥ó¥É¥¦¤ÎÇØ·Ê¿§¤È¤·¤Æ»ÈÍÑ ¤¹¤ë¿§¤Î¥Ô¥¯¥»¥ëÃͤò³ÊǼ¤·¤Þ¤¹¡£¤½¤ÎÃͤËÂбþ¤¹¤ë¥«¥é¡¼¥»¥ë¤ÎÃͤò¥×¥í¥°¥é¥àÃæ¤ÇưŪ¤ËÊÑ ¹¹¤¹¤ë¤³¤È¤Ç¡¢¥Ö¥ê¥ó¥¯½èÍý¤ò¼Â¸½¤·¤Þ¤¹¡£
- 32 ¡Á 52 ¹ÔÌÜ
xblink.c ¤Î main ´Ø¿ô¤Ç¤¹¡£¤ª¤ª¤Þ¤«¤Ê½èÍý¤Ï¡¢
- ½é´ü½èÍý ( xblink_init() )
- ¥Ó¥¸¥å¥¢¥ë¤Î¥Á¥§¥Ã¥¯ ( xblink_check_visual() )
- Æɤ߽ñ¤Î¾ÍÑ¥«¥é¡¼¥»¥ë¤Î³ä¤êÅö¤Æ / ¿§ÀßÄê ( xblink_alloc_color() )
- ¥¦¥£¥ó¥É¥¦ºîÀ® ( xblink_create_window() )
- ¥¦¥£¥ó¥É¥¦¤Î¥Þ¥Ã¥× ( XMapWindow() )
- ¥¤¥Ù¥ó¥È¥ë¡¼¥× ( xblink_event_loop() )
¤È¤Ê¤ê¤Þ¤¹¡£
- 67 ¡Á 82 ¹ÔÌÜ ( xblink_check_visual() )
¥«¥é¡¼¥»¥ë¤ÎÃͤò½ñ¤´¹¤¨¤ë¤Ë¤Ï¡¢Æɤ߽ñ¤Î¾ÍѤΥӥ¸¥å¥¢¥ë¥¯¥é¥¹¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ëɬÍ× ¤¬¤¢¤ê¤Þ¤¹¡£XMatchVisualInfo() ¤ò»È¤¦¤È¡¢»ØÄꤷ¤¿¾ò·ï¤Ë¹ç¤¦¥Ó¥¸¥å¥¢¥ë¤Î¤¦¤Á¡¢¤¢¤ë 1 ¤Ä ¤Î¥Ó¥¸¥å¥¢¥ë¤Î¾ðÊó¤òÆÀ¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
Status XMatchVisualInfo( Display* display, int screen, int depth, int class, XVisualInfo* vinfo_return ); depth : ¥¹¥¯¥ê¡¼¥ó¤Î¿¼¤µ¤ò»ØÄê class : ¥¹¥¯¥ê¡¼¥ó¤Î¥¯¥é¥¹(¥Ó¥¸¥å¥¢¥ë¥¯¥é¥¹)¤ò»ØÄê vinfo_return : ¾ò·ï¤Ë¹ç¤Ã¤¿¥Ó¥¸¥å¥¢¥ë¾ðÊ󤬳ÊǼ¤µ¤ì¤ë
»ØÄꤷ¤¿¾ò·ï¤Ë¹ç¤Ã¤¿¥Ó¥¸¥å¥¢¥ë¤Î¤¦¤Á¡¢¤¢¤ë 1 ¤Ä¤Î¥Ó¥¸¥å¥¢¥ë¤Î¾ðÊó¤¬ vinfo_return ¤¬¼¨ ¤¹ÊÑ¿ôÎΰè¤Ë³ÊǼ¤µ¤ì¤Þ¤¹¡£XVisualInfo ¹½Â¤ÂΤϰʲ¼¤Î¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£
typedef struct { Visual* visual; /* ¥·¥¹¥Æ¥à¤Ç»ÈÍѤ¹¤ë Visual ¹½Â¤ÂΤؤΥݥ¤¥ó¥¿ */ VisualID visualid; /* Ä̾ï¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï»ÈÍѤµ¤ì¤Ê¤¤ */ int screen_num; /* ¥¹¥¯¥ê¡¼¥óÈÖ¹æ */ unsigned int depth; /* ¥¹¥¯¥ê¡¼¥ó¤Î¿¼¤µ */ int class; /* StaticGray¡¢ GrayScale¡¢StaticColor¡¢ PseudoColor¡¢TrueColor¡¢DirectColor ¤Î¤¤¤º¤ì¤« */ unsigned long red_mask; /* TrueColor ¤â¤·¤¯¤Ï DirectColor ¤Î¾ì¹ç¡¢ ¥Ô¥¯¥»¥ëÃͤΤɤΥӥåȤ¬ÀÖ¿§¤Î¥«¥é¡¼¥Þ¥Ã¥×¥¤¥ó¥Ç ¥Ã¥¯¥¹¤ËÂбþ¤¹¤ë¤«¤òɽ¤¹¥Þ¥¹¥¯ */ unsigned long green_mask; /* Î理ËÂФ·¤Æ red_mask ¤ÈƱ¤¸Ìò³ä¤ò²Ì¤¿¤¹ */ unsigned long blue_mask; /* ÀÄ¿§¤ËÂФ·¤Æ red_mask ¤ÈƱ¤¸Ìò³ä¤ò²Ì¤¿¤¹ */ int colormap_size; /* ¤³¤Î¥Ó¥¸¥å¥¢¥ë¤Ç͸ú¤Ê¥Ô¥¯¥»¥ëÃͤοô */ int bits_per_rgb; /* ¥«¥é¡¼¥»¥ë¤Î RGB ÃͤΥӥåȿô */ } XVisualInfo;
class ¥á¥ó¥Ð¤Ï StaticGray¡¢GrayScale¡¢StaticColor¡¢PseudoColor¡¢TrueColor¡¢DirectColor ¤Î¤¤¤º¤ì¤«¤ÎÄê¿ô¤ÎÃͤò¼è¤ë¤Î¤Ç¡¢¤³¤ÎÃͤò»²¾È¤¹¤ì¤Ð¥Ó¥¸¥å¥¢¥ë¤Î¥¯¥é¥¹¤¬Ê¬¤«¤ê¤Þ¤¹¡£
red_mask¡¢green_mask¡¢blue_mask ¤Ï¡¢TrueColor ¤â¤·¤¯¤Ï DirectColor ¤Î¾ì¹ç¤Ë»ÈÍѤµ¤ì¤Þ ¤¹¡£¤³¤Î 2 ¤Ä¤Î¥Ó¥¸¥å¥¢¥ë¤Ë¤ª¤¤¤Æ¤Ï¡¢1 ¤Ä¤Î¥Ô¥¯¥»¥ëÃͤò»È¤Ã¤Æ ÀÖ / ÎÐ / ÀĤγƿ§¤ËÂФ· ¤ÆÊÌ¡¹¤Î¥«¥é¡¼¥Þ¥Ã¥×¾å¤Î¥¨¥ó¥È¥ê¤ò»²¾È¤·¡¢¤½¤ÎÁȤ߹礻¤Ë¤è¤Ã¤Æ¿§¤¬·èÄꤵ¤ì¤Þ¤¹¡£¤è¤Ã¤Æ¡¢ ¥Ô¥¯¥»¥ëÃͤΤɤΥӥåȤ¬³Æ¿§¤Î¥«¥é¡¼¥»¥ë¥¤¥ó¥Ç¥Ã¥¯¥¹¤ËÂбþ¤¹¤ë¤«¤ò¤³¤ì¤é¤Î¥Þ¥¹¥¯¤Ç·èÄê ¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£¤½¤ì°Ê³°¤Î¥Ó¥¸¥å¥¢¥ë¤Ë¤ª¤¤¤Æ¤Ï 1 ¤Ä¤Î¥«¥é¡¼¥»¥ë¤¬ 1 ¿§¤òɽ¸½¤¹¤ë¤¿ ¤á¡¢¤³¤ì¤é¤Î¥Þ¥¹¥¯¤ÏÉÔÍפȤʤê¤Þ¤¹¡£
»ØÄꤷ¤¿¾ò·ï¤Ë¹ç¤Ã¤¿¥Ó¥¸¥å¥¢¥ë¤¬¸«ÉÕ¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¡¢XMatchVisualInfo() ¤Ï 0 ¤òÊÖ¤·¤Þ ¤¹¡£¸«ÉÕ¤«¤Ã¤¿¾ì¹ç¤Ï 0 °Ê³°¤ÎÃͤòÊÖ¤·¤Þ¤¹¡£
xblink.c ¤Ç¤Ï¡¢¥Ç¥Õ¥©¥ë¥È¤Î¿¼¤µ¤È PseudoColor ¤ò»ØÄꤷ¤Æ¥Ó¥¸¥å¥¢¥ë¤Î¥µ¥Ý¡¼¥È¤ò¥Á¥§¥Ã ¥¯¤·¡¢¤½¤ì¤¬ÂÌÌܤÀ¤Ã¤¿¤é DirectColor ¤ò»ØÄꤷ¤Æ¥Á¥§¥Ã¥¯¤ò¹Ô¤Ã¤Æ¤¤¤Þ¤¹¡£¤¤¤º¤ì¤Î¥Ó¥¸ ¥å¥¢¥ë¤â¸«ÉÕ¤«¤é¤Ê¤«¤Ã¤¿¤é¡¢¤½¤Î»þÅÀ¤Ç½ªÎ»¤·¤Þ¤¹¡£
--- ÀµÄ¾¸À¤¦¤È¡¢¤³¤³¤Ç¥Ó¥¸¥å¥¢¥ë¤Î¥µ¥Ý¡¼¥È¤ò¥Á¥§¥Ã¥¯¤·¤Æ¤â X ¥µ¡¼¥Ð¤¬¤½¤Î¥Ó¥¸¥å¥¢¥ë ¤Çµ¯Æ°¤·¤Æ¤¤¤Ê¤±¤ì¤Ð¸å½Ò¤Î XAllocColorCells() ¤Ë¼ºÇÔ¤¹¤ë¤¿¤á¡¢xblink.c ¤Ç¤Ï¤¢¤ë°ÕÌ£ ÉÔÍפʽèÍý¤È¸À¤¨¤Þ¤¹¡£¤³¤ì¤Ë´Ø¤·¤Æ¤Ï¸å½Ò¤·¤Þ¤¹¡£---
- 85 ¡Á 121 ¹ÔÌÜ ( xblink_alloc_color() )
¤³¤³¤Ç¤Ï¡¢Æɤ߽ñ¤Î¾ÍѤΥ«¥é¡¼¥»¥ë¤ò³ÎÊݤ·¡¢½é´ü¿§¤ÎÀßÄê¤ò¹Ô¤Ã¤Æ¤¤¤Þ¤¹¡£¥«¥é¡¼¥Þ¥Ã¥× ¾å¤ËÆɤ߽ñ¤Î¾ÍѤΥ«¥é¡¼¥»¥ë¤ò³ÎÊݤ¹¤ë¤Ë¤Ï¡¢XAllocColorCells() ¤ò»È¤¤¤Þ¤¹¡£
Status XAllocColorCells( Display* display, Colormap colormap, Bool contig, unsigned long plane_masks_return[], unsigned int nplanes, unsigned long pixels_return[], unsigned int npixels ); contig : ¥×¥ì¡¼¥ó¤¬Ï¢Â³¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¤«¤É¤¦¤«¤ò»ØÄê plane_masks_return : ¥×¥ì¡¼¥ó¥Þ¥¹¥¯¤ÎÇÛÎó nplanes : ¥×¥ì¡¼¥ó¥Þ¥¹¥¯¤ÎÇÛÎó¤ËÊÖ¤µ¤ì¤ë¥×¥ì¡¼¥ó¥Þ¥¹¥¯¤Î¿ô¤ò»ØÄê pixels_return : ¥Ô¥¯¥»¥ëÃͤÎÇÛÎó¤¬ÊÖ¤µ¤ì¤ë npixels : ¥Ô¥¯¥»¥ë¤Î¿ô¤ò»ØÄê
XAllocColorCells() ¤Î³Æ°ú¿ô¤Ï¡¢Àµ³Î¤Ê°ÕÌ£¤ò¹Í¤¨¤ë¤È·ë¹½Æñ¤·¤¤¤Ç¤¹¡£¤³¤³¤Ç¤ÏÆɤ߽ñ¤Î¾ ÍѤΥ«¥é¡¼¥»¥ë¤ò¤¤¤¯¤Ä¤«³ÎÊݤ¹¤ë¤¿¤á¤À¤±¤ËɬÍפÊÀâÌÀ¤Î¤ß¹Ô¤¤¤Þ¤¹¡£npixels ¤ËɬÍפʥ« ¥é¡¼¥»¥ë¿ô¤ò¡¢nplanes ¤Ë 0 ¤ò»ØÄꤹ¤ë¤È¡¢pixels_return ÇÛÎó¤Ë³ÎÊݤµ¤ì¤¿¥Ô¥¯¥»¥ëÃͤ¬³Ê Ǽ¤µ¤ì¤Þ¤¹¡£»ØÄꤷ¤¿¿ô¤Î¥«¥é¡¼¥»¥ë¤Î³ÎÊݤËÀ®¸ù¤·¤¿¾ì¹ç¤Ï 0 °Ê³°¤ÎÃͤò¡¢¼ºÇÔ¤·¤¿¾ì¹ç¤Ï 0 ¤òÊÖ¤·¤Þ¤¹¡£
¤³¤³¤Ç³ÎÊݤ·¤¿¥«¥é¡¼¥»¥ë¤ÎÃͤòưŪ¤Ë½ñ¤´¹¤¨¤ë¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¤¬¡¢¤½¤Î¤¿¤á¤Ë¤ÏÀÖ/¹õ¤Î RGB Ãͤ¬É¬Íפˤʤê¤Þ¤¹¡£¤³¤³¤Ç¤Ï XParseColor() ¤ò»È¤Ã¤Æ¡¢"red" ¤ª¤è¤Ó "black" ¤Î¿§Ì¾ ¤ËÂбþ¤¹¤ë RGB ÃͤòÌ䤤¹ç¤ï¤»¤Æ color ÇÛÎó¤Ë³ÊǼ¤·¤Æ¤¤¤Þ¤¹¡£¤³¤Î color ÇÛÎó¤Î³ÆÍ×ÁÇ¤Ë ¤Ï¡¢¤¢¤È¤Ç»ÈÍѤ¹¤ë¤¿¤á¤Ë³ÎÊݤ·¤¿¥«¥é¡¼¥»¥ë¤Î¥Ô¥¯¥»¥ëÃÍ¤È DoRed | DoGreen | DoBlue ¤Î ¥Õ¥é¥°¤òÀßÄꤷ¤Æ¤¤¤Þ¤¹¡£
xblink_alloc_color() ¤ÎºÇ¸å¤Î½èÍý¤È¤·¤Æ¡¢³ÎÊݤ·¤¿¥«¥é¡¼¥»¥ë¤Î½é´ü¿§¤Ë "red" ¤Î RGB ÃÍ ¤òÀßÄꤷ¤Æ¤¤¤Þ¤¹¡£Æɤ߽ñ¤Î¾ÍÑ¥«¥é¡¼¥»¥ë¤Ë RGB ÃͤòÀßÄꤹ¤ë¤Ë¤Ï XStoreColor() ¤ò»È¤¤ ¤Þ¤¹¡£
XStoreColor( Display* display, Colormap colormap, XColor* color );
color ¤Ç¼¨¤µ¤ì¤ë XColor ·¿ÊÑ¿ô¤Ë¡¢ÃͤòÀßÄꤷ¤¿¤¤¥«¥é¡¼¥»¥ë¤Î¥Ô¥¯¥»¥ëÃͤÈÀßÄꤷ¤¿¤¤ RGB ÃÍ¡¢¤É¤Î¿§À®Ê¬¤òÀßÄꤷ¤¿¤¤¤«¤òɽ¤¹¥Õ¥é¥°¤òÀßÄꤷ¤Æ¼Â¹Ô¤·¤Þ¤¹¡£
- 124 ¡Á 136 ¹ÔÌÜ ( xblink_create_window() )
¤¤¤Ä¤âÄ̤ê XCreateSimpleWindow() ¤Ë¤è¤ë¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤ò¹Ô¤Ã¤Æ¤¤¤Þ¤¹¤¬¡¢¥¦¥£¥ó¥É¥¦¤Î ÇØ·Ê¿§¤È¥Ü¡¼¥À¿§¤Ë xblink_alloc_color() ¤ÇÆÀ¤¿¥Ô¥¯¥»¥ëÃÍ( color_pixel ¤Ë³ÊǼ ) ¤ò»ØÄê ¤·¤Æ¤¤¤ë¤³¤È¤ËÃí°Õ¤·¤Æ²¼¤µ¤¤¡£
- 139 ¡Á 191 ¹ÔÌÜ ( xblink_event_loop() )
ËèÅÙ¤ª¤Ê¤¸¤ß¤Î¥¤¥Ù¥ó¥È¥ë¡¼¥×¤Ç¤¹¡£Ä̾ï¤Î¥¤¥Ù¥ó¥È½èÍý¤ò¹Ô¤¦Á°¤Ëɽ¼¨¿§¤ÎÀÚÂؤ¨½èÍý¤ò¹Ô¤Ã ¤Æ¤¤¤Þ¤¹¡£
¥ë¡¼¥×Ëè¤Ë time() ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ë¤è¤Ã¤Æ¸½ºß»þ¹ï¤ò¼èÆÀ¤·¤Þ¤¹¡£¼èÆÀ¤·¤¿¸½ºß»þ¹ï¤¬Á°²óÀÚ Âؤ¨»þ¹ï¤«¤é 1 Éðʾå·Ð²á¤·¤Æ¤¤¤ì¤Ð¡¢XStoreColor() ¤ò»È¤Ã¤Æ color_pixel ¤Ë¤è¤Ã¤Æ»²¾È¤µ ¤ì¤ë¥«¥é¡¼¥»¥ë¤ÎÆâÍƤò½ñ¤´¹¤¨¤Þ¤¹¡£¤³¤Î½Ö´Ö¤Ë²èÌ̾å¤Î¥¦¥£¥ó¥É¥¦¤ÎÇØ·Ê¿§¤ÏÀÚ¤êÂؤï¤ê¤Þ ¤¹¡£¹¹¤Ë¡¢ÀÚÂؤ¨¤¿»þÅÀ¤Î»þ¹ï¤òÁ°²óÀÚÂؤ¨»þ¹ï¤ËÊݸ¤·¤Æ¤ª¤¤Þ¤¹¡£
X ¤Î¥¤¥Ù¥ó¥È½èÍý¤Ç¤Ï¡¢LECTURE 4 ¤Ç¼è¤êµó¤²¤¿ XPending() ¤ò»È¤Ã¤Æ¤Þ¤º½èÍý²Äǽ¤Ê¥¤¥Ù¥ó¥È¤Î¿ô¤ò¼èÆÀ¤·¤Æ¤¤¤Þ¤¹¡£¸½ºßÆɤ߹þ¤ß²Äǽ¤Ê¥¤¥Ù¥ó¥È¤¬Ìµ¤¤¾ì ¹ç¤Ï¥¤¥Ù¥ó¥È½èÍý¤òÈô¤Ð¤·¤Æ¼¡¤Î¥ë¡¼¥×¤ËÈô¤Ó¤Þ¤¹¡£
KeyPress ¥¤¥Ù¥ó¥È¤ò½¦¤Ã¤¿¾ì¹ç¤Ï¡¢¥ê¥½¡¼¥¹¤ò²òÊü¤·¤Æ¥×¥í¥°¥é¥à¤ò½ªÎ»¤·¤Æ¤¤¤Þ¤¹¡£¥³¥á¥ó ¥È¥¢¥¦¥È¤µ¤ì¤Æ¤¤¤Þ¤¹¤¬¡¢¿·¤·¤¤¥ê¥½¡¼¥¹²òÊüÍÑ´Ø¿ô XFreeColors() ¤ò»È¤Ã¤Æ¤¤¤Þ¤¹¡£
XFreeColors( Display* display, Colormap colormap, unsigned long pixels[], int npixels, unsigned long planes ); pixels : ¥Ô¥¯¥»¥ëÃͤÎÇÛÎó¤ò»ØÄê npixels : ¥Ô¥¯¥»¥ë¤Î¿ô¤ò»ØÄê planes : ²òÊü¤¹¤ë¥×¥ì¡¼¥ó¤ò»ØÄê
¤³¤Î´Ø¿ô¤Ï¡¢ XAllocColorCells() ¤Ç³ÎÊݤ·¤¿Æɤ߽ñ¤Î¾ÍÑ¥»¥ë¤Ë¸Â¤é¤ºº£¤Þ¤Ç¤Ë¾Ò²ð¤·¤¿ XAllocColor()¡¢XAllocNamedColor() ¤Ë¤è¤Ã¤Æ³ÎÊݤµ¤ì¤¿Æɤ߽Ф·ÀìÍÑ¥»¥ë¤Î²òÊü¤Ë¤â»ÈÍѤ·¤Þ ¤¹¡£¤¿¤À¤·¡¢Æɤ߽ñ¤Î¾ÍÑ¥»¥ë¤Ï³ÎÊݤ·¤¿¥¯¥é¥¤¥¢¥ó¥ÈÀìÍÑ¥»¥ë¤Ç¤¢¤ë¤Î¤ËÂФ·¤Æ¡¢Æɤ߽Ф·Àì ÍÑ¥»¥ë¤Ï¥¯¥é¥¤¥¢¥ó¥È´Ö¶¦Í¤Ç¤¢¤ë¤¿¤á¡¢Á´¤Æ¤Î¥¯¥é¥¤¥¢¥ó¥È¤«¤é²òÊü¤µ¤ì¤ë¤Þ¤Ç¼ÂºÝ¤Ë¤ÏºÆÍø ÍѤϤǤ¤Þ¤»¤ó¡£
¤Ê¤ª¡¢XFreeColors() ¤Ï¥×¥í¥°¥é¥àÃæ¤Ë¥«¥é¡¼¥»¥ë¤ò²òÊü¤·¤¿¤¤¾ì¹ç¤Ë»ÈÍѤ¹¤ë¤³¤È¤È¥Þ¥Ë¥å¥¢ ¥ë¤Ë½ñ¤«¤ì¤Æ¤¤¤Þ¤¹¡£Ä̾ï¤Ï¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤¬½ªÎ»¤·¤¿»þÅÀ¤Ç¡¢¤½¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤¬³ÎÊÝ ¤·¤¿¥«¥é¡¼¥»¥ë¤Ï²òÊü¤µ¤ì¤Þ¤¹(¤À¤«¤é¥³¥á¥ó¥È¥¢¥¦¥È¤·¤Æ¤¤¤ë)¡£
°Ê¾å¤Ç¡¢xblink.c ¤ÎÀâÌÀ¤Ï½ª¤ï¤ê¤Ç¤¹¡£PseudoColor ¤â¤·¤¯¤Ï DirectColor ¤Ç X ¥µ¡¼¥Ð¤¬µ¯Æ°¤·¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¤È¤¤¤¦Â礤ÊÀ©¸Â¤¬¤¢¤ê¤Þ¤¹¤¬¡¢¤¼¤Ò¼Â¸³¤·¤Æ¤ß¤Æ²¼¤µ¤¤!