comparison src/X_supp.c @ 756:cceac4ba259e

Support drawing at root window for X Window
author Thinker K.F. Li <thinker@codemud.net>
date Thu, 26 Aug 2010 14:54:50 +0800
parents 82836f1290b6
children f43224bf3524
comparison
equal deleted inserted replaced
755:82836f1290b6 756:cceac4ba259e
426 XFlush(display); 426 XFlush(display);
427 } else if(FD_ISSET(fd, &rfds)){ 427 } else if(FD_ISSET(fd, &rfds)){
428 handle_x_event(rt); 428 handle_x_event(rt);
429 } else { 429 } else {
430 for(i=0;i<rt->n_monitor;i++) { 430 for(i=0;i<rt->n_monitor;i++) {
431 if (rt->monitors[i].type == MONITOR_READ) 431 if (rt->monitors[i].type == MONITOR_READ) {
432 if (FD_ISSET(rt->monitors[i].fd, &rfds)) 432 if (FD_ISSET(rt->monitors[i].fd, &rfds))
433 rt->monitors[i].f(rt->monitors[i].fd,rt->monitors[i].arg); 433 rt->monitors[i].f(rt->monitors[i].fd,rt->monitors[i].arg);
434 else if (rt->monitors[i].type == MONITOR_WRITE) 434 } else if (rt->monitors[i].type == MONITOR_WRITE) {
435 if (FD_ISSET(rt->monitors[i].fd, &wfds)) 435 if (FD_ISSET(rt->monitors[i].fd, &wfds))
436 rt->monitors[i].f(rt->monitors[i].fd,rt->monitors[i].arg); 436 rt->monitors[i].f(rt->monitors[i].fd,rt->monitors[i].arg);
437 }
437 } 438 }
438 } 439 }
439 } 440 }
440 } 441 }
441 442
452 Visual *visual; 453 Visual *visual;
453 int screen; 454 int screen;
454 XSetWindowAttributes wattr; 455 XSetWindowAttributes wattr;
455 int depth; 456 int depth;
456 int x, y; 457 int x, y;
458 int draw_root = 0;
459 const char *disp_name;
460 char disp_buf[32];
461 int cp;
457 int r; 462 int r;
458 463
459 display = XOpenDisplay(display_name); 464 /*
465 * Support drawing on the root window.
466 */
467 disp_name = display_name;
468 if(strstr(display_name, ":root") != NULL) {
469 draw_root = 1;
470 cp = strlen(display_name) - 5;
471 if(cp >= 32)
472 cp = 31;
473 memcpy(disp_buf, display_name, cp);
474 disp_buf[cp] = 0;
475 disp_name = disp_buf;
476 }
477
478 display = XOpenDisplay(disp_name);
460 if(display == NULL) 479 if(display == NULL)
461 return ERR; 480 return ERR;
462 481
463 screen = DefaultScreen(display); 482 screen = DefaultScreen(display);
464 root = DefaultRootWindow(display); 483 root = DefaultRootWindow(display);
465 visual = DefaultVisual(display, screen); 484 visual = DefaultVisual(display, screen);
466 depth = DefaultDepth(display, screen); 485 depth = DefaultDepth(display, screen);
467 wattr.override_redirect = False; 486 wattr.override_redirect = False;
468 x = 10; 487 x = 10;
469 y = 10; 488 y = 10;
470 win = XCreateWindow(display, root, 489 if(draw_root)
471 x, y, 490 win = RootWindowOfScreen(ScreenOfDisplay(display, screen));
472 w, h, 491 else {
473 1, depth, InputOutput, visual, 492 win = XCreateWindow(display, root,
474 CWOverrideRedirect, &wattr); 493 x, y,
475 r = XMapWindow(display, win); 494 w, h,
476 if(r == -1) { 495 1, depth, InputOutput, visual,
477 XCloseDisplay(display); 496 CWOverrideRedirect, &wattr);
478 return ERR; 497 r = XMapWindow(display, win);
498 if(r == -1) {
499 XCloseDisplay(display);
500 return ERR;
501 }
479 } 502 }
480 503
481 XSelectInput(display, win, PointerMotionMask | ExposureMask | 504 XSelectInput(display, win, PointerMotionMask | ExposureMask |
482 ButtonPressMask | ButtonReleaseMask | 505 ButtonPressMask | ButtonReleaseMask |
483 KeyPressMask | KeyReleaseMask); 506 KeyPressMask | KeyReleaseMask);