Changeset 4141 for libcaca/trunk/caca/driver/x11.c
- Timestamp:
- Dec 17, 2009, 2:46:30 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/caca/driver/x11.c
r4140 r4141 25 25 #include <X11/Xutil.h> 26 26 #include <X11/keysym.h> 27 #if defined (HAVE_X11_XKBLIB_H)27 #if defined HAVE_X11_XKBLIB_H 28 28 # include <X11/XKBlib.h> 29 29 #endif … … 53 53 int font_width, font_height; 54 54 int colors[4096]; 55 #if defined X_HAVE_UTF8_STRING 56 XFontSet font_set; 57 #endif 55 58 Font font; 56 59 XFontStruct *font_struct; … … 59 62 Atom wm_protocols; 60 63 Atom wm_delete_window; 61 #if defined (HAVE_X11_XKBLIB_H)64 #if defined HAVE_X11_XKBLIB_H 62 65 Bool autorepeat; 63 66 #endif … … 78 81 Colormap colormap; 79 82 XSetWindowAttributes x11_winattr; 83 #if defined X_HAVE_UTF8_STRING 84 XVaNestedList list; 85 #endif 80 86 int (*old_error_handler)(Display *, XErrorEvent *); 81 87 char const *fonts[] = { NULL, "8x13bold", "fixed", NULL }, **parser; … … 87 93 dp->drv.p = malloc(sizeof(struct driver_private)); 88 94 89 #if defined (HAVE_GETENV)95 #if defined HAVE_GETENV 90 96 geometry = getenv("CACA_GEOMETRY"); 91 97 if(geometry && *geometry) … … 104 110 return -1; 105 111 106 #if defined (HAVE_GETENV)112 #if defined HAVE_GETENV 107 113 fonts[0] = getenv("CACA_FONT"); 108 114 if(fonts[0] && *fonts[0]) … … 118 124 for( ; ; parser++) 119 125 { 126 #if defined X_HAVE_UTF8_STRING 127 char **missing_charset_list; 128 char *def_string; 129 int missing_charset_count; 130 #endif 120 131 uint32_t font_max_char; 121 132 … … 126 137 return -1; 127 138 } 139 140 #if defined X_HAVE_UTF8_STRING 141 dp->drv.p->font_set = XCreateFontSet(dp->drv.p->dpy, *parser, 142 &missing_charset_list, 143 &missing_charset_count, 144 &def_string); 145 if (missing_charset_list) 146 XFreeStringList(missing_charset_list); 147 148 if (!dp->drv.p->font_set || missing_charset_count) 149 { 150 char buf[BUFSIZ]; 151 152 if (dp->drv.p->font_set) 153 XFreeFontSet(dp->drv.p->dpy, dp->drv.p->font_set); 154 snprintf(buf, BUFSIZ - 1, "%s,*", *parser); 155 dp->drv.p->font_set = XCreateFontSet(dp->drv.p->dpy, buf, 156 &missing_charset_list, 157 &missing_charset_count, 158 &def_string); 159 if (missing_charset_list) 160 XFreeStringList(missing_charset_list); 161 } 162 163 if (dp->drv.p->font_set) 164 break; 165 #endif 128 166 129 167 dp->drv.p->font = XLoadFont(dp->drv.p->dpy, *parser); … … 161 199 XSetErrorHandler(old_error_handler); 162 200 163 dp->drv.p->font_width = 0; 164 if(dp->drv.p->font_struct->per_char 165 && !dp->drv.p->font_struct->min_byte1 166 && dp->drv.p->font_struct->min_char_or_byte2 <= 0x21 167 && dp->drv.p->font_struct->max_char_or_byte2 >= 0x7e) 168 { 169 for(i = 0x21; i < 0x7f; i++) 170 { 171 int cw = dp->drv.p->font_struct->per_char[i 172 - dp->drv.p->font_struct->min_char_or_byte2].width; 173 if(cw > dp->drv.p->font_width) 174 dp->drv.p->font_width = cw; 175 } 176 } 177 178 if(!dp->drv.p->font_width) 179 dp->drv.p->font_width = dp->drv.p->font_struct->max_bounds.width; 180 181 dp->drv.p->font_height = dp->drv.p->font_struct->max_bounds.ascent 182 + dp->drv.p->font_struct->max_bounds.descent; 183 dp->drv.p->font_offset = dp->drv.p->font_struct->max_bounds.descent; 201 /* Set font width to the largest character in the set */ 202 #if defined X_HAVE_UTF8_STRING 203 if (dp->drv.p->font_set) 204 { 205 XFontSetExtents *ex = XExtentsOfFontSet(dp->drv.p->font_set); 206 dp->drv.p->font_width = 207 XmbTextEscapement(dp->drv.p->font_set, "CAca", 4) / 4; 208 dp->drv.p->font_height = ex->max_logical_extent.height; 209 dp->drv.p->font_offset = ex->max_logical_extent.height 210 + ex->max_logical_extent.y; 211 } 212 else 213 #endif 214 { 215 dp->drv.p->font_width = 0; 216 if(dp->drv.p->font_struct->per_char 217 && !dp->drv.p->font_struct->min_byte1 218 && dp->drv.p->font_struct->min_char_or_byte2 <= 0x21 219 && dp->drv.p->font_struct->max_char_or_byte2 >= 0x7e) 220 { 221 for(i = 0x21; i < 0x7f; i++) 222 { 223 int cw = dp->drv.p->font_struct->per_char[i 224 - dp->drv.p->font_struct->min_char_or_byte2].width; 225 if(cw > dp->drv.p->font_width) 226 dp->drv.p->font_width = cw; 227 } 228 } 229 230 if(!dp->drv.p->font_width) 231 dp->drv.p->font_width = dp->drv.p->font_struct->max_bounds.width; 232 233 dp->drv.p->font_height = dp->drv.p->font_struct->max_bounds.ascent 234 + dp->drv.p->font_struct->max_bounds.descent; 235 dp->drv.p->font_offset = dp->drv.p->font_struct->max_bounds.descent; 236 } 184 237 185 238 colormap = DefaultColormap(dp->drv.p->dpy, DefaultScreen(dp->drv.p->dpy)); … … 222 275 dp->drv.p->gc = XCreateGC(dp->drv.p->dpy, dp->drv.p->window, 0, NULL); 223 276 XSetForeground(dp->drv.p->dpy, dp->drv.p->gc, dp->drv.p->colors[0x888]); 224 XSetFont(dp->drv.p->dpy, dp->drv.p->gc, dp->drv.p->font); 277 #if defined X_HAVE_UTF8_STRING 278 if (!dp->drv.p->font_set) 279 #endif 280 XSetFont(dp->drv.p->dpy, dp->drv.p->gc, dp->drv.p->font); 225 281 226 282 for(;;) … … 232 288 } 233 289 234 #if defined (HAVE_X11_XKBLIB_H)290 #if defined HAVE_X11_XKBLIB_H 235 291 /* Disable autorepeat */ 236 292 XkbSetDetectableAutoRepeat(dp->drv.p->dpy, True, &dp->drv.p->autorepeat); … … 258 314 dp->drv.p->dirty_cursor_y = -1; 259 315 316 #if defined X_HAVE_UTF8_STRING 317 list = XVaCreateNestedList(0, XNFontSet, dp->drv.p->font_set, NULL); 260 318 dp->drv.p->im = XOpenIM(dp->drv.p->dpy, NULL, NULL, NULL); 261 dp->drv.p->ic = XCreateIC(dp->drv.p->im, XNInputStyle, 262 XIMPreeditNothing | XIMStatusNothing, NULL); 319 dp->drv.p->ic = XCreateIC(dp->drv.p->im, 320 XNInputStyle, XIMPreeditNothing | XIMStatusNothing, 321 XNClientWindow, dp->drv.p->window, 322 XNPreeditAttributes, list, 323 XNStatusAttributes, list, 324 NULL); 325 #endif 263 326 264 327 return 0; … … 268 331 { 269 332 XSync(dp->drv.p->dpy, False); 270 #if defined (HAVE_X11_XKBLIB_H)333 #if defined HAVE_X11_XKBLIB_H 271 334 if(!dp->drv.p->autorepeat) 272 335 XAutoRepeatOn(dp->drv.p->dpy); 273 336 #endif 274 337 XFreePixmap(dp->drv.p->dpy, dp->drv.p->pixmap); 275 XFreeFont(dp->drv.p->dpy, dp->drv.p->font_struct); 338 #if defined X_HAVE_UTF8_STRING 339 if (dp->drv.p->font_set) 340 XFreeFontSet(dp->drv.p->dpy, dp->drv.p->font_set); 341 else 342 #endif 343 XFreeFont(dp->drv.p->dpy, dp->drv.p->font_struct); 276 344 XFreeGC(dp->drv.p->dpy, dp->drv.p->gc); 277 345 XUnmapWindow(dp->drv.p->dpy, dp->drv.p->window); 278 346 XDestroyWindow(dp->drv.p->dpy, dp->drv.p->window); 347 #if defined X_HAVE_UTF8_STRING 279 348 XDestroyIC(dp->drv.p->ic); 280 349 XCloseIM(dp->drv.p->im); 350 #endif 281 351 XCloseDisplay(dp->drv.p->dpy); 282 352 … … 666 736 Pixmap px = dp->drv.p->pixmap; 667 737 GC gc = dp->drv.p->gc; 668 XChar2b ch16;669 738 int fw; 670 739 … … 823 892 824 893 #if defined X_HAVE_UTF8_STRING 825 if(ch >= 0x00000020) 826 #else 827 if(ch >= 0x00000020 && ch <= dp->drv.p->max_char) 828 #endif 829 { 830 ch16.byte1 = (uint8_t)(ch >> 8); 831 ch16.byte2 = (uint8_t)ch; 894 if (dp->drv.p->font_set) 895 { 896 wchar_t wch = ch; 897 XwcDrawString(dpy, px, dp->drv.p->font_set, gc, 898 x + (fw - w) / 2, yoff, &wch, 1); 832 899 } 833 900 else 834 { 835 ch16.byte1 = 0; 836 ch16.byte2 = caca_utf32_to_ascii(ch); 837 } 838 839 XDrawString16(dpy, px, gc, 840 x + (ch16.byte1 ? 0 : (fw - w) / 2), yoff, &ch16, 1); 901 #endif 902 { 903 XChar2b ch16; 904 905 #if !defined X_HAVE_UTF8_STRING 906 if(ch > dp->drv.p->max_char) 907 { 908 ch16.byte1 = 0; 909 ch16.byte2 = caca_utf32_to_ascii(ch); 910 } 911 else 912 #endif 913 { 914 ch16.byte1 = (uint8_t)(ch >> 8); 915 ch16.byte2 = (uint8_t)ch; 916 } 917 918 XDrawString16(dpy, px, gc, 919 x + (ch16.byte1 ? 0 : (fw - w) / 2), yoff, &ch16, 1); 920 } 841 921 } 842 922 … … 847 927 int x11_install(caca_display_t *dp) 848 928 { 849 #if defined (HAVE_GETENV)929 #if defined HAVE_GETENV 850 930 if(!getenv("DISPLAY") || !*(getenv("DISPLAY"))) 851 931 return -1;
Note: See TracChangeset
for help on using the changeset viewer.