Changeset 811 for libcaca/trunk/caca/driver_x11.c
 Timestamp:
 Apr 18, 2006, 5:11:25 PM (14 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

libcaca/trunk/caca/driver_x11.c
r810 r811 60 60 }; 61 61 62 static int x11_init_graphics(caca_ t *kk)62 static int x11_init_graphics(caca_display_t *dp) 63 63 { 64 64 Colormap colormap; … … 70 70 int i; 71 71 72 kk>drv.p = malloc(sizeof(struct driver_private));72 dp>drv.p = malloc(sizeof(struct driver_private)); 73 73 74 74 #if defined(HAVE_GETENV) … … 79 79 80 80 if(width && height) 81 _cucul_set_size( kk>c, width, height);82 83 kk>drv.p>dpy = XOpenDisplay(NULL);84 if( kk>drv.p>dpy == NULL)81 _cucul_set_size(dp>cv, width, height); 82 83 dp>drv.p>dpy = XOpenDisplay(NULL); 84 if(dp>drv.p>dpy == NULL) 85 85 return 1; 86 86 … … 102 102 { 103 103 XSetErrorHandler(old_error_handler); 104 XCloseDisplay( kk>drv.p>dpy);104 XCloseDisplay(dp>drv.p>dpy); 105 105 return 1; 106 106 } 107 107 108 kk>drv.p>font = XLoadFont(kk>drv.p>dpy, *parser);109 if(! kk>drv.p>font)108 dp>drv.p>font = XLoadFont(dp>drv.p>dpy, *parser); 109 if(!dp>drv.p>font) 110 110 continue; 111 111 112 kk>drv.p>font_struct = XQueryFont(kk>drv.p>dpy, kk>drv.p>font);113 if(! kk>drv.p>font_struct)114 { 115 XUnloadFont( kk>drv.p>dpy, kk>drv.p>font);112 dp>drv.p>font_struct = XQueryFont(dp>drv.p>dpy, dp>drv.p>font); 113 if(!dp>drv.p>font_struct) 114 { 115 XUnloadFont(dp>drv.p>dpy, dp>drv.p>font); 116 116 continue; 117 117 } … … 123 123 XSetErrorHandler(old_error_handler); 124 124 125 kk>drv.p>font_width = kk>drv.p>font_struct>max_bounds.width;126 kk>drv.p>font_height = kk>drv.p>font_struct>max_bounds.ascent127 + kk>drv.p>font_struct>max_bounds.descent;128 kk>drv.p>font_offset = kk>drv.p>font_struct>max_bounds.descent;129 130 colormap = DefaultColormap( kk>drv.p>dpy, DefaultScreen(kk>drv.p>dpy));125 dp>drv.p>font_width = dp>drv.p>font_struct>max_bounds.width; 126 dp>drv.p>font_height = dp>drv.p>font_struct>max_bounds.ascent 127 + dp>drv.p>font_struct>max_bounds.descent; 128 dp>drv.p>font_offset = dp>drv.p>font_struct>max_bounds.descent; 129 130 colormap = DefaultColormap(dp>drv.p>dpy, DefaultScreen(dp>drv.p>dpy)); 131 131 for(i = 0x000; i < 0x1000; i++) 132 132 { … … 135 135 color.green = ((i & 0x0f0) >> 4) * 0x1111; 136 136 color.blue = (i & 0x00f) * 0x1111; 137 XAllocColor( kk>drv.p>dpy, colormap, &color);138 kk>drv.p>colors[i] = color.pixel;137 XAllocColor(dp>drv.p>dpy, colormap, &color); 138 dp>drv.p>colors[i] = color.pixel; 139 139 } 140 140 141 141 x11_winattr.backing_store = Always; 142 x11_winattr.background_pixel = kk>drv.p>colors[0x000];142 x11_winattr.background_pixel = dp>drv.p>colors[0x000]; 143 143 x11_winattr.event_mask = ExposureMask  StructureNotifyMask; 144 144 145 kk>drv.p>window =146 XCreateWindow( kk>drv.p>dpy, DefaultRootWindow(kk>drv.p>dpy), 0, 0,147 kk>c>width * kk>drv.p>font_width,148 kk>c>height * kk>drv.p>font_height,145 dp>drv.p>window = 146 XCreateWindow(dp>drv.p>dpy, DefaultRootWindow(dp>drv.p>dpy), 0, 0, 147 dp>cv>width * dp>drv.p>font_width, 148 dp>cv>height * dp>drv.p>font_height, 149 149 0, 0, InputOutput, 0, 150 150 CWBackingStore  CWBackPixel  CWEventMask, 151 151 &x11_winattr); 152 152 153 kk>drv.p>wm_protocols =154 XInternAtom( kk>drv.p>dpy, "WM_PROTOCOLS", True);155 kk>drv.p>wm_delete_window =156 XInternAtom( kk>drv.p>dpy, "WM_DELETE_WINDOW", True);157 158 if( kk>drv.p>wm_protocols != None && kk>drv.p>wm_delete_window != None)159 XSetWMProtocols( kk>drv.p>dpy, kk>drv.p>window,160 & kk>drv.p>wm_delete_window, 1);161 162 XStoreName( kk>drv.p>dpy, kk>drv.p>window, "caca for X");163 164 XSelectInput( kk>drv.p>dpy, kk>drv.p>window, StructureNotifyMask);165 XMapWindow( kk>drv.p>dpy, kk>drv.p>window);166 167 kk>drv.p>gc = XCreateGC(kk>drv.p>dpy, kk>drv.p>window, 0, NULL);168 XSetForeground( kk>drv.p>dpy, kk>drv.p>gc, kk>drv.p>colors[0x888]);169 XSetFont( kk>drv.p>dpy, kk>drv.p>gc, kk>drv.p>font);153 dp>drv.p>wm_protocols = 154 XInternAtom(dp>drv.p>dpy, "WM_PROTOCOLS", True); 155 dp>drv.p>wm_delete_window = 156 XInternAtom(dp>drv.p>dpy, "WM_DELETE_WINDOW", True); 157 158 if(dp>drv.p>wm_protocols != None && dp>drv.p>wm_delete_window != None) 159 XSetWMProtocols(dp>drv.p>dpy, dp>drv.p>window, 160 &dp>drv.p>wm_delete_window, 1); 161 162 XStoreName(dp>drv.p>dpy, dp>drv.p>window, "caca for X"); 163 164 XSelectInput(dp>drv.p>dpy, dp>drv.p>window, StructureNotifyMask); 165 XMapWindow(dp>drv.p>dpy, dp>drv.p>window); 166 167 dp>drv.p>gc = XCreateGC(dp>drv.p>dpy, dp>drv.p>window, 0, NULL); 168 XSetForeground(dp>drv.p>dpy, dp>drv.p>gc, dp>drv.p>colors[0x888]); 169 XSetFont(dp>drv.p>dpy, dp>drv.p>gc, dp>drv.p>font); 170 170 171 171 for(;;) 172 172 { 173 173 XEvent xevent; 174 XNextEvent( kk>drv.p>dpy, &xevent);174 XNextEvent(dp>drv.p>dpy, &xevent); 175 175 if (xevent.type == MapNotify) 176 176 break; … … 179 179 #if defined(HAVE_X11_XKBLIB_H) 180 180 /* Disable autorepeat */ 181 XkbSetDetectableAutoRepeat( kk>drv.p>dpy, True, &kk>drv.p>autorepeat);182 if(! kk>drv.p>autorepeat)183 XAutoRepeatOff( kk>drv.p>dpy);181 XkbSetDetectableAutoRepeat(dp>drv.p>dpy, True, &dp>drv.p>autorepeat); 182 if(!dp>drv.p>autorepeat) 183 XAutoRepeatOff(dp>drv.p>dpy); 184 184 #endif 185 185 186 kk>drv.p>event_mask = KeyPressMask  KeyReleaseMask  ButtonPressMask186 dp>drv.p>event_mask = KeyPressMask  KeyReleaseMask  ButtonPressMask 187 187  ButtonReleaseMask  PointerMotionMask  StructureNotifyMask 188 188  ExposureMask; 189 189 190 XSelectInput( kk>drv.p>dpy, kk>drv.p>window, kk>drv.p>event_mask);191 192 XSync( kk>drv.p>dpy, False);193 194 kk>drv.p>pixmap = XCreatePixmap(kk>drv.p>dpy, kk>drv.p>window,195 kk>c>width * kk>drv.p>font_width,196 kk>c>height * kk>drv.p>font_height,197 DefaultDepth( kk>drv.p>dpy,198 DefaultScreen( kk>drv.p>dpy)));199 kk>drv.p>pointer = None;190 XSelectInput(dp>drv.p>dpy, dp>drv.p>window, dp>drv.p>event_mask); 191 192 XSync(dp>drv.p>dpy, False); 193 194 dp>drv.p>pixmap = XCreatePixmap(dp>drv.p>dpy, dp>drv.p>window, 195 dp>cv>width * dp>drv.p>font_width, 196 dp>cv>height * dp>drv.p>font_height, 197 DefaultDepth(dp>drv.p>dpy, 198 DefaultScreen(dp>drv.p>dpy))); 199 dp>drv.p>pointer = None; 200 200 201 201 return 0; 202 202 } 203 203 204 static int x11_end_graphics(caca_ t *kk)205 { 206 XSync( kk>drv.p>dpy, False);204 static int x11_end_graphics(caca_display_t *dp) 205 { 206 XSync(dp>drv.p>dpy, False); 207 207 #if defined(HAVE_X11_XKBLIB_H) 208 if(! kk>drv.p>autorepeat)209 XAutoRepeatOn( kk>drv.p>dpy);208 if(!dp>drv.p>autorepeat) 209 XAutoRepeatOn(dp>drv.p>dpy); 210 210 #endif 211 XFreePixmap( kk>drv.p>dpy, kk>drv.p>pixmap);212 XFreeFont( kk>drv.p>dpy, kk>drv.p>font_struct);213 XFreeGC( kk>drv.p>dpy, kk>drv.p>gc);214 XUnmapWindow( kk>drv.p>dpy, kk>drv.p>window);215 XDestroyWindow( kk>drv.p>dpy, kk>drv.p>window);216 XCloseDisplay( kk>drv.p>dpy);217 218 free( kk>drv.p);211 XFreePixmap(dp>drv.p>dpy, dp>drv.p>pixmap); 212 XFreeFont(dp>drv.p>dpy, dp>drv.p>font_struct); 213 XFreeGC(dp>drv.p>dpy, dp>drv.p>gc); 214 XUnmapWindow(dp>drv.p>dpy, dp>drv.p>window); 215 XDestroyWindow(dp>drv.p>dpy, dp>drv.p>window); 216 XCloseDisplay(dp>drv.p>dpy); 217 218 free(dp>drv.p); 219 219 220 220 return 0; 221 221 } 222 222 223 static int x11_set_window_title(caca_ t *kk, char const *title)224 { 225 XStoreName( kk>drv.p>dpy, kk>drv.p>window, title);223 static int x11_set_window_title(caca_display_t *dp, char const *title) 224 { 225 XStoreName(dp>drv.p>dpy, dp>drv.p>window, title); 226 226 return 0; 227 227 } 228 228 229 static unsigned int x11_get_window_width(caca_ t *kk)230 { 231 return kk>c>width * kk>drv.p>font_width;232 } 233 234 static unsigned int x11_get_window_height(caca_ t *kk)235 { 236 return kk>c>height * kk>drv.p>font_height;237 } 238 239 static void x11_display(caca_ t *kk)229 static unsigned int x11_get_window_width(caca_display_t *dp) 230 { 231 return dp>cv>width * dp>drv.p>font_width; 232 } 233 234 static unsigned int x11_get_window_height(caca_display_t *dp) 235 { 236 return dp>cv>height * dp>drv.p>font_height; 237 } 238 239 static void x11_display(caca_display_t *dp) 240 240 { 241 241 unsigned int x, y, len; … … 243 243 /* First draw the background colours. Splitting the process in two 244 244 * loops like this is actually slightly faster. */ 245 for(y = 0; y < kk>c>height; y++)246 { 247 for(x = 0; x < kk>c>width; x += len)248 { 249 uint32_t *attr = kk>c>attr + x + y * kk>c>width;245 for(y = 0; y < dp>cv>height; y++) 246 { 247 for(x = 0; x < dp>cv>width; x += len) 248 { 249 uint32_t *attr = dp>cv>attr + x + y * dp>cv>width; 250 250 uint16_t bg = _cucul_argb32_to_rgb12bg(*attr); 251 251 252 252 len = 1; 253 while(x + len < kk>c>width253 while(x + len < dp>cv>width 254 254 && _cucul_argb32_to_rgb12bg(attr[len]) == bg) 255 255 len++; 256 256 257 XSetForeground( kk>drv.p>dpy, kk>drv.p>gc,258 kk>drv.p>colors[bg]);259 XFillRectangle( kk>drv.p>dpy, kk>drv.p>pixmap, kk>drv.p>gc,260 x * kk>drv.p>font_width, y * kk>drv.p>font_height,261 len * kk>drv.p>font_width, kk>drv.p>font_height);257 XSetForeground(dp>drv.p>dpy, dp>drv.p>gc, 258 dp>drv.p>colors[bg]); 259 XFillRectangle(dp>drv.p>dpy, dp>drv.p>pixmap, dp>drv.p>gc, 260 x * dp>drv.p>font_width, y * dp>drv.p>font_height, 261 len * dp>drv.p>font_width, dp>drv.p>font_height); 262 262 } 263 263 } 264 264 265 265 /* Then print the foreground characters */ 266 for(y = 0; y < kk>c>height; y++)267 { 268 unsigned int yoff = (y + 1) * kk>drv.p>font_height269  kk>drv.p>font_offset;270 uint32_t *chars = kk>c>chars + y * kk>c>width;271 272 for(x = 0; x < kk>c>width; x++, chars++)273 { 274 uint32_t *attr = kk>c>attr + x + y * kk>c>width;266 for(y = 0; y < dp>cv>height; y++) 267 { 268 unsigned int yoff = (y + 1) * dp>drv.p>font_height 269  dp>drv.p>font_offset; 270 uint32_t *chars = dp>cv>chars + y * dp>cv>width; 271 272 for(x = 0; x < dp>cv>width; x++, chars++) 273 { 274 uint32_t *attr = dp>cv>attr + x + y * dp>cv>width; 275 275 276 276 /* Skip spaces */ … … 278 278 continue; 279 279 280 XSetForeground( kk>drv.p>dpy, kk>drv.p>gc,281 kk>drv.p>colors[_cucul_argb32_to_rgb12fg(*attr)]);280 XSetForeground(dp>drv.p>dpy, dp>drv.p>gc, 281 dp>drv.p>colors[_cucul_argb32_to_rgb12fg(*attr)]); 282 282 283 283 /* Plain ASCII, no problem. */ 284 284 if(*chars > 0x00000020 && *chars < 0x00000080) 285 285 { 286 char c = (uint8_t)*chars;287 XDrawString( kk>drv.p>dpy, kk>drv.p>pixmap, kk>drv.p>gc,288 x * kk>drv.p>font_width, yoff, &c, 1);286 char ch = (uint8_t)*chars; 287 XDrawString(dp>drv.p>dpy, dp>drv.p>pixmap, dp>drv.p>gc, 288 x * dp>drv.p>font_width, yoff, &ch, 1); 289 289 continue; 290 290 } … … 296 296 { 297 297 case 0x00002580: /* ▀ */ 298 XFillRectangle( kk>drv.p>dpy, kk>drv.p>pixmap,299 kk>drv.p>gc,300 x * kk>drv.p>font_width,301 y * kk>drv.p>font_height,302 kk>drv.p>font_width,303 kk>drv.p>font_height / 2);298 XFillRectangle(dp>drv.p>dpy, dp>drv.p>pixmap, 299 dp>drv.p>gc, 300 x * dp>drv.p>font_width, 301 y * dp>drv.p>font_height, 302 dp>drv.p>font_width, 303 dp>drv.p>font_height / 2); 304 304 break; 305 305 case 0x00002584: /* ▄ */ 306 XFillRectangle( kk>drv.p>dpy, kk>drv.p>pixmap,307 kk>drv.p>gc,308 x * kk>drv.p>font_width,309 (y + 1) * kk>drv.p>font_height310  kk>drv.p>font_height / 2,311 kk>drv.p>font_width,312 kk>drv.p>font_height / 2);306 XFillRectangle(dp>drv.p>dpy, dp>drv.p>pixmap, 307 dp>drv.p>gc, 308 x * dp>drv.p>font_width, 309 (y + 1) * dp>drv.p>font_height 310  dp>drv.p>font_height / 2, 311 dp>drv.p>font_width, 312 dp>drv.p>font_height / 2); 313 313 break; 314 314 case 0x00002588: /* █ */ 315 XFillRectangle( kk>drv.p>dpy, kk>drv.p>pixmap,316 kk>drv.p>gc,317 x * kk>drv.p>font_width,318 y * kk>drv.p>font_height,319 kk>drv.p>font_width,320 kk>drv.p>font_height);315 XFillRectangle(dp>drv.p>dpy, dp>drv.p>pixmap, 316 dp>drv.p>gc, 317 x * dp>drv.p>font_width, 318 y * dp>drv.p>font_height, 319 dp>drv.p>font_width, 320 dp>drv.p>font_height); 321 321 break; 322 322 case 0x0000258c: /* ▌ */ 323 XFillRectangle( kk>drv.p>dpy, kk>drv.p>pixmap,324 kk>drv.p>gc,325 x * kk>drv.p>font_width,326 y * kk>drv.p>font_height,327 kk>drv.p>font_width / 2,328 kk>drv.p>font_height);323 XFillRectangle(dp>drv.p>dpy, dp>drv.p>pixmap, 324 dp>drv.p>gc, 325 x * dp>drv.p>font_width, 326 y * dp>drv.p>font_height, 327 dp>drv.p>font_width / 2, 328 dp>drv.p>font_height); 329 329 break; 330 330 case 0x00002590: /* ▐ */ 331 XFillRectangle( kk>drv.p>dpy, kk>drv.p>pixmap,332 kk>drv.p>gc,333 (x + 1) * kk>drv.p>font_width334  kk>drv.p>font_width / 2,335 y * kk>drv.p>font_height,336 kk>drv.p>font_width / 2,337 kk>drv.p>font_height);331 XFillRectangle(dp>drv.p>dpy, dp>drv.p>pixmap, 332 dp>drv.p>gc, 333 (x + 1) * dp>drv.p>font_width 334  dp>drv.p>font_width / 2, 335 y * dp>drv.p>font_height, 336 dp>drv.p>font_width / 2, 337 dp>drv.p>font_height); 338 338 break; 339 339 case 0x00002593: /* ▓ */ … … 343 343 /* FIXME: this sucks utterly */ 344 344 int i, j, k = *chars  0x00002591; 345 for(j = kk>drv.p>font_height; j; )346 for(i = kk>drv.p>font_width; i; )345 for(j = dp>drv.p>font_height; j; ) 346 for(i = dp>drv.p>font_width; i; ) 347 347 { 348 348 if(((i + 2 * (j & 1)) & 3) > k) 349 349 continue; 350 350 351 XDrawPoint( kk>drv.p>dpy, kk>drv.p>pixmap,352 kk>drv.p>gc,353 x * kk>drv.p>font_width + i,354 y * kk>drv.p>font_height + j);351 XDrawPoint(dp>drv.p>dpy, dp>drv.p>pixmap, 352 dp>drv.p>gc, 353 x * dp>drv.p>font_width + i, 354 y * dp>drv.p>font_height + j); 355 355 } 356 356 break; … … 358 358 default: 359 359 { 360 char c ;361 c = '?';362 XDrawString( kk>drv.p>dpy, kk>drv.p>pixmap,363 kk>drv.p>gc,364 x * kk>drv.p>font_width, yoff, &c, 1);360 char ch; 361 ch = '?'; 362 XDrawString(dp>drv.p>dpy, dp>drv.p>pixmap, 363 dp>drv.p>gc, 364 x * dp>drv.p>font_width, yoff, &ch, 1); 365 365 break; 366 366 } … … 369 369 } 370 370 371 XCopyArea( kk>drv.p>dpy, kk>drv.p>pixmap, kk>drv.p>window,372 kk>drv.p>gc, 0, 0,373 kk>c>width * kk>drv.p>font_width,374 kk>c>height * kk>drv.p>font_height,371 XCopyArea(dp>drv.p>dpy, dp>drv.p>pixmap, dp>drv.p>window, 372 dp>drv.p>gc, 0, 0, 373 dp>cv>width * dp>drv.p>font_width, 374 dp>cv>height * dp>drv.p>font_height, 375 375 0, 0); 376 XFlush( kk>drv.p>dpy);377 } 378 379 static void x11_handle_resize(caca_ t *kk)376 XFlush(dp>drv.p>dpy); 377 } 378 379 static void x11_handle_resize(caca_display_t *dp) 380 380 { 381 381 Pixmap new_pixmap; 382 382 383 new_pixmap = XCreatePixmap( kk>drv.p>dpy, kk>drv.p>window,384 kk>resize.w * kk>drv.p>font_width,385 kk>resize.h * kk>drv.p>font_height,386 DefaultDepth( kk>drv.p>dpy,387 DefaultScreen( kk>drv.p>dpy)));388 XCopyArea( kk>drv.p>dpy, kk>drv.p>pixmap, new_pixmap,389 kk>drv.p>gc, 0, 0,390 kk>resize.w * kk>drv.p>font_width,391 kk>resize.h * kk>drv.p>font_height, 0, 0);392 XFreePixmap( kk>drv.p>dpy, kk>drv.p>pixmap);393 kk>drv.p>pixmap = new_pixmap;394 } 395 396 static int x11_get_event(caca_ t *kk, caca_event_t *ev)383 new_pixmap = XCreatePixmap(dp>drv.p>dpy, dp>drv.p>window, 384 dp>resize.w * dp>drv.p>font_width, 385 dp>resize.h * dp>drv.p>font_height, 386 DefaultDepth(dp>drv.p>dpy, 387 DefaultScreen(dp>drv.p>dpy))); 388 XCopyArea(dp>drv.p>dpy, dp>drv.p>pixmap, new_pixmap, 389 dp>drv.p>gc, 0, 0, 390 dp>resize.w * dp>drv.p>font_width, 391 dp>resize.h * dp>drv.p>font_height, 0, 0); 392 XFreePixmap(dp>drv.p>dpy, dp>drv.p>pixmap); 393 dp>drv.p>pixmap = new_pixmap; 394 } 395 396 static int x11_get_event(caca_display_t *dp, caca_event_t *ev) 397 397 { 398 398 XEvent xevent; 399 399 char key; 400 400 401 while(XCheckWindowEvent( kk>drv.p>dpy, kk>drv.p>window,402 kk>drv.p>event_mask, &xevent) == True)401 while(XCheckWindowEvent(dp>drv.p>dpy, dp>drv.p>window, 402 dp>drv.p>event_mask, &xevent) == True) 403 403 { 404 404 KeySym keysym; … … 407 407 if(xevent.type == Expose) 408 408 { 409 XCopyArea( kk>drv.p>dpy, kk>drv.p>pixmap,410 kk>drv.p>window, kk>drv.p>gc, 0, 0,411 kk>c>width * kk>drv.p>font_width,412 kk>c>height * kk>drv.p>font_height, 0, 0);409 XCopyArea(dp>drv.p>dpy, dp>drv.p>pixmap, 410 dp>drv.p>window, dp>drv.p>gc, 0, 0, 411 dp>cv>width * dp>drv.p>font_width, 412 dp>cv>height * dp>drv.p>font_height, 0, 0); 413 413 continue; 414 414 } … … 419 419 unsigned int w, h; 420 420 421 w = (xevent.xconfigure.width + kk>drv.p>font_width / 3)422 / kk>drv.p>font_width;423 h = (xevent.xconfigure.height + kk>drv.p>font_height / 3)424 / kk>drv.p>font_height;425 426 if(!w  !h  (w == kk>c>width && h == kk>c>height))421 w = (xevent.xconfigure.width + dp>drv.p>font_width / 3) 422 / dp>drv.p>font_width; 423 h = (xevent.xconfigure.height + dp>drv.p>font_height / 3) 424 / dp>drv.p>font_height; 425 426 if(!w  !h  (w == dp>cv>width && h == dp>cv>height)) 427 427 continue; 428 428 429 kk>resize.w = w;430 kk>resize.h = h;431 kk>resize.resized = 1;429 dp>resize.w = w; 430 dp>resize.h = h; 431 dp>resize.resized = 1; 432 432 433 433 continue; … … 437 437 if(xevent.type == MotionNotify) 438 438 { 439 unsigned int newx = xevent.xmotion.x / kk>drv.p>font_width;440 unsigned int newy = xevent.xmotion.y / kk>drv.p>font_height;441 442 if(newx >= kk>c>width)443 newx = kk>c>width  1;444 if(newy >= kk>c>height)445 newy = kk>c>height  1;446 447 if( kk>mouse.x == newx && kk>mouse.y == newy)439 unsigned int newx = xevent.xmotion.x / dp>drv.p>font_width; 440 unsigned int newy = xevent.xmotion.y / dp>drv.p>font_height; 441 442 if(newx >= dp>cv>width) 443 newx = dp>cv>width  1; 444 if(newy >= dp>cv>height) 445 newy = dp>cv>height  1; 446 447 if(dp>mouse.x == newx && dp>mouse.y == newy) 448 448 continue; 449 449 450 kk>mouse.x = newx;451 kk>mouse.y = newy;450 dp>mouse.x = newx; 451 dp>mouse.y = newy; 452 452 453 453 ev>type = CACA_EVENT_MOUSE_MOTION; 454 ev>data.mouse.x = kk>mouse.x;455 ev>data.mouse.y = kk>mouse.y;454 ev>data.mouse.x = dp>mouse.x; 455 ev>data.mouse.y = dp>mouse.y; 456 456 return 1; 457 457 } … … 489 489 } 490 490 491 keysym = XKeycodeToKeysym( kk>drv.p>dpy, xevent.xkey.keycode, 0);491 keysym = XKeycodeToKeysym(dp>drv.p>dpy, xevent.xkey.keycode, 0); 492 492 switch(keysym) 493 493 { … … 520 520 } 521 521 522 while(XCheckTypedEvent( kk>drv.p>dpy, ClientMessage, &xevent))523 { 524 if(xevent.xclient.message_type != kk>drv.p>wm_protocols)522 while(XCheckTypedEvent(dp>drv.p>dpy, ClientMessage, &xevent)) 523 { 524 if(xevent.xclient.message_type != dp>drv.p>wm_protocols) 525 525 continue; 526 526 527 if((Atom)xevent.xclient.data.l[0] == kk>drv.p>wm_delete_window)527 if((Atom)xevent.xclient.data.l[0] == dp>drv.p>wm_delete_window) 528 528 { 529 529 ev>type = CACA_EVENT_QUIT; … … 536 536 } 537 537 538 static void x11_set_mouse(caca_ t *kk, int flags)538 static void x11_set_mouse(caca_display_t *dp, int flags) 539 539 { 540 540 Cursor no_ptr; … … 546 546 if(flags) 547 547 { 548 XDefineCursor( kk>drv.p>dpy,kk>drv.p>window, 0);548 XDefineCursor(dp>drv.p>dpy,dp>drv.p>window, 0); 549 549 return; 550 550 } 551 551 552 colormap = DefaultColormap( kk>drv.p>dpy, DefaultScreen(kk>drv.p>dpy));553 if(!XAllocNamedColor( kk>drv.p>dpy, colormap, "black", &black, &dummy))552 colormap = DefaultColormap(dp>drv.p>dpy, DefaultScreen(dp>drv.p>dpy)); 553 if(!XAllocNamedColor(dp>drv.p>dpy, colormap, "black", &black, &dummy)) 554 554 { 555 555 return; 556 556 } 557 bm_no = XCreateBitmapFromData( kk>drv.p>dpy, kk>drv.p>window,557 bm_no = XCreateBitmapFromData(dp>drv.p>dpy, dp>drv.p>window, 558 558 empty, 8, 8); 559 no_ptr = XCreatePixmapCursor( kk>drv.p>dpy, bm_no, bm_no,559 no_ptr = XCreatePixmapCursor(dp>drv.p>dpy, bm_no, bm_no, 560 560 &black, &black, 0, 0); 561 XDefineCursor( kk>drv.p>dpy, kk>drv.p>window, no_ptr);562 XFreeCursor( kk>drv.p>dpy, no_ptr);561 XDefineCursor(dp>drv.p>dpy, dp>drv.p>window, no_ptr); 562 XFreeCursor(dp>drv.p>dpy, no_ptr); 563 563 if(bm_no != None) 564 XFreePixmap( kk>drv.p>dpy, bm_no);565 XFreeColors( kk>drv.p>dpy, colormap, &black.pixel, 1, 0);566 567 XSync( kk>drv.p>dpy, False);564 XFreePixmap(dp>drv.p>dpy, bm_no); 565 XFreeColors(dp>drv.p>dpy, colormap, &black.pixel, 1, 0); 566 567 XSync(dp>drv.p>dpy, False); 568 568 } 569 569 … … 582 582 */ 583 583 584 int x11_install(caca_ t *kk)584 int x11_install(caca_display_t *dp) 585 585 { 586 586 #if defined(HAVE_GETENV) … … 589 589 #endif 590 590 591 kk>drv.driver = CACA_DRIVER_X11;592 593 kk>drv.init_graphics = x11_init_graphics;594 kk>drv.end_graphics = x11_end_graphics;595 kk>drv.set_window_title = x11_set_window_title;596 kk>drv.get_window_width = x11_get_window_width;597 kk>drv.get_window_height = x11_get_window_height;598 kk>drv.display = x11_display;599 kk>drv.handle_resize = x11_handle_resize;600 kk>drv.get_event = x11_get_event;601 kk>drv.set_mouse = x11_set_mouse;591 dp>drv.driver = CACA_DRIVER_X11; 592 593 dp>drv.init_graphics = x11_init_graphics; 594 dp>drv.end_graphics = x11_end_graphics; 595 dp>drv.set_window_title = x11_set_window_title; 596 dp>drv.get_window_width = x11_get_window_width; 597 dp>drv.get_window_height = x11_get_window_height; 598 dp>drv.display = x11_display; 599 dp>drv.handle_resize = x11_handle_resize; 600 dp>drv.get_event = x11_get_event; 601 dp>drv.set_mouse = x11_set_mouse; 602 602 603 603 return 0;
Note: See TracChangeset
for help on using the changeset viewer.