Mercurial > MadButterfly
comparison src/X_supp.c @ 822:586e50f82c1f
Unify coding style tag for emacs and vim.
author | Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com> |
---|---|
date | Tue, 14 Sep 2010 01:08:39 +0800 |
parents | f43224bf3524 |
children | c18058fb48ee |
comparison
equal
deleted
inserted
replaced
821:bfdc82bbd6e4 | 822:586e50f82c1f |
---|---|
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- | |
2 // vim: sw=4:ts=8:sts=4 | |
1 #include <stdio.h> | 3 #include <stdio.h> |
2 #include <stdlib.h> | 4 #include <stdlib.h> |
3 #include <string.h> | 5 #include <string.h> |
4 #include <X11/Xlib.h> | 6 #include <X11/Xlib.h> |
5 #include <X11/Xutil.h> | 7 #include <X11/Xutil.h> |
70 | 72 |
71 #ifdef XSHM | 73 #ifdef XSHM |
72 static void | 74 static void |
73 XSHM_update(X_MB_runtime_t *xmb_rt) { | 75 XSHM_update(X_MB_runtime_t *xmb_rt) { |
74 GC gc; | 76 GC gc; |
75 | 77 |
76 gc = DefaultGC(xmb_rt->display, DefaultScreen(xmb_rt->display)); | 78 gc = DefaultGC(xmb_rt->display, DefaultScreen(xmb_rt->display)); |
77 if(xmb_rt->ximage) { /* support XSHM */ | 79 if(xmb_rt->ximage) { /* support XSHM */ |
78 XShmPutImage(xmb_rt->display, | 80 XShmPutImage(xmb_rt->display, |
79 xmb_rt->win, | 81 xmb_rt->win, |
80 gc, | 82 gc, |
164 but |= MOUSE_BUT1; | 166 but |= MOUSE_BUT1; |
165 if(state & Button2Mask) | 167 if(state & Button2Mask) |
166 but |= MOUSE_BUT2; | 168 but |= MOUSE_BUT2; |
167 if(state & Button3Mask) | 169 if(state & Button3Mask) |
168 but |= MOUSE_BUT3; | 170 but |= MOUSE_BUT3; |
169 | 171 |
170 return but; | 172 return but; |
171 } | 173 } |
172 | 174 |
173 static unsigned int get_button(unsigned int button) { | 175 static unsigned int get_button(unsigned int button) { |
174 switch(button) { | 176 switch(button) { |
200 mouse_event.event.type = etype; | 202 mouse_event.event.type = etype; |
201 mouse_event.x = x; | 203 mouse_event.x = x; |
202 mouse_event.y = y; | 204 mouse_event.y = y; |
203 mouse_event.but_state = state; | 205 mouse_event.but_state = state; |
204 mouse_event.button = button; | 206 mouse_event.button = button; |
205 | 207 |
206 if(IS_MBO_SHAPES(obj)) | 208 if(IS_MBO_SHAPES(obj)) |
207 subject = sh_get_mouse_event_subject((shape_t *)obj); | 209 subject = sh_get_mouse_event_subject((shape_t *)obj); |
208 else | 210 else |
209 subject = coord_get_mouse_event((coord_t *)obj); | 211 subject = coord_get_mouse_event((coord_t *)obj); |
210 | 212 |
211 subject_notify(subject, (event_t *)&mouse_event); | 213 subject_notify(subject, (event_t *)&mouse_event); |
212 } | 214 } |
213 | 215 |
214 /*! \brief Dispatch all X events in the queue. | 216 /*! \brief Dispatch all X events in the queue. |
215 */ | 217 */ |
282 break; | 284 break; |
283 XNextEvent(display, &evt); | 285 XNextEvent(display, &evt); |
284 } | 286 } |
285 if(r == -1) | 287 if(r == -1) |
286 break; | 288 break; |
287 | 289 |
288 mevt = (XMotionEvent *)&evt; | 290 mevt = (XMotionEvent *)&evt; |
289 x = mevt->x; | 291 x = mevt->x; |
290 y = mevt->y; | 292 y = mevt->y; |
291 state = get_button_state(mevt->state); | 293 state = get_button_state(mevt->state); |
292 | 294 |
398 if (rt->monitors[i].type == MONITOR_READ) | 400 if (rt->monitors[i].type == MONITOR_READ) |
399 FD_SET(rt->monitors[i].fd, &rfds); | 401 FD_SET(rt->monitors[i].fd, &rfds); |
400 else if (rt->monitors[i].type == MONITOR_WRITE) | 402 else if (rt->monitors[i].type == MONITOR_WRITE) |
401 FD_SET(rt->monitors[i].fd, &wfds); | 403 FD_SET(rt->monitors[i].fd, &wfds); |
402 } | 404 } |
403 | 405 |
404 get_now(&now); | 406 get_now(&now); |
405 r = mb_tman_next_timeout(tman, &now, &tmo); | 407 r = mb_tman_next_timeout(tman, &now, &tmo); |
406 | 408 |
407 if(r == 0) { | 409 if(r == 0) { |
408 tv.tv_sec = MB_TIMEVAL_SEC(&tmo); | 410 tv.tv_sec = MB_TIMEVAL_SEC(&tmo); |
472 cp = 31; | 474 cp = 31; |
473 memcpy(disp_buf, display_name, cp); | 475 memcpy(disp_buf, display_name, cp); |
474 disp_buf[cp] = 0; | 476 disp_buf[cp] = 0; |
475 disp_name = disp_buf; | 477 disp_name = disp_buf; |
476 } | 478 } |
477 | 479 |
478 display = XOpenDisplay(disp_name); | 480 display = XOpenDisplay(disp_name); |
479 if(display == NULL) | 481 if(display == NULL) |
480 return ERR; | 482 return ERR; |
481 | 483 |
482 screen = DefaultScreen(display); | 484 screen = DefaultScreen(display); |
517 static void | 519 static void |
518 xshm_destroy(X_MB_runtime_t *xmb_rt) { | 520 xshm_destroy(X_MB_runtime_t *xmb_rt) { |
519 XShmSegmentInfo *shminfo; | 521 XShmSegmentInfo *shminfo; |
520 | 522 |
521 shminfo = &xmb_rt->shminfo; | 523 shminfo = &xmb_rt->shminfo; |
522 | 524 |
523 if(xmb_rt->shminfo.shmaddr) { | 525 if(xmb_rt->shminfo.shmaddr) { |
524 XShmDetach(xmb_rt->display, shminfo); | 526 XShmDetach(xmb_rt->display, shminfo); |
525 } | 527 } |
526 | 528 |
527 if(xmb_rt->ximage) { | 529 if(xmb_rt->ximage) { |
528 XDestroyImage(xmb_rt->ximage); | 530 XDestroyImage(xmb_rt->ximage); |
529 xmb_rt->ximage = NULL; | 531 xmb_rt->ximage = NULL; |
530 } | 532 } |
531 | 533 |
532 if(shminfo->shmaddr) { | 534 if(shminfo->shmaddr) { |
533 shmdt(shminfo->shmaddr); | 535 shmdt(shminfo->shmaddr); |
534 shminfo->shmaddr = NULL; | 536 shminfo->shmaddr = NULL; |
535 } | 537 } |
536 | 538 |
537 if(shminfo->shmid) { | 539 if(shminfo->shmid) { |
538 shmctl(shminfo->shmid, IPC_RMID, 0); | 540 shmctl(shminfo->shmid, IPC_RMID, 0); |
539 shminfo->shmid = 0; | 541 shminfo->shmid = 0; |
540 } | 542 } |
541 } | 543 } |
553 int surf_fmt; | 555 int surf_fmt; |
554 | 556 |
555 display = xmb_rt->display; | 557 display = xmb_rt->display; |
556 visual = xmb_rt->visual; | 558 visual = xmb_rt->visual; |
557 shminfo = &xmb_rt->shminfo; | 559 shminfo = &xmb_rt->shminfo; |
558 | 560 |
559 support_shm = XShmQueryExtension(display); | 561 support_shm = XShmQueryExtension(display); |
560 if(!support_shm) | 562 if(!support_shm) |
561 return; | 563 return; |
562 | 564 |
563 screen = DefaultScreen(display); | 565 screen = DefaultScreen(display); |
564 depth = DefaultDepth(display, screen); | 566 depth = DefaultDepth(display, screen); |
565 | 567 |
566 if(depth != 24 && depth != 32) | 568 if(depth != 24 && depth != 32) |
567 return; | 569 return; |
568 | 570 |
569 xmb_rt->ximage = XShmCreateImage(display, visual, depth, | 571 xmb_rt->ximage = XShmCreateImage(display, visual, depth, |
570 ZPixmap, NULL, shminfo, | 572 ZPixmap, NULL, shminfo, |
571 xmb_rt->w, xmb_rt->h); | 573 xmb_rt->w, xmb_rt->h); |
572 ximage = xmb_rt->ximage; | 574 ximage = xmb_rt->ximage; |
573 | 575 |
574 mem_sz = ximage->bytes_per_line * ximage->height; | 576 mem_sz = ximage->bytes_per_line * ximage->height; |
575 shminfo->shmid = shmget(IPC_PRIVATE, mem_sz, IPC_CREAT | 0777); | 577 shminfo->shmid = shmget(IPC_PRIVATE, mem_sz, IPC_CREAT | 0777); |
576 if(shminfo->shmid == -1) { | 578 if(shminfo->shmid == -1) { |
577 xshm_destroy(xmb_rt); | 579 xshm_destroy(xmb_rt); |
578 return; | 580 return; |
579 } | 581 } |
580 | 582 |
581 shminfo->shmaddr = shmat(shminfo->shmid, 0, 0); | 583 shminfo->shmaddr = shmat(shminfo->shmid, 0, 0); |
582 ximage->data = shminfo->shmaddr; | 584 ximage->data = shminfo->shmaddr; |
583 | 585 |
584 shminfo->readOnly = 0; | 586 shminfo->readOnly = 0; |
585 | 587 |
586 XShmAttach(display, shminfo); | 588 XShmAttach(display, shminfo); |
587 | 589 |
588 switch(depth) { | 590 switch(depth) { |
615 */ | 617 */ |
616 static int | 618 static int |
617 X_MB_init_with_win(X_MB_runtime_t *xmb_rt) { | 619 X_MB_init_with_win(X_MB_runtime_t *xmb_rt) { |
618 mb_img_ldr_t *img_ldr; | 620 mb_img_ldr_t *img_ldr; |
619 int w, h; | 621 int w, h; |
620 | 622 |
621 w = xmb_rt->w; | 623 w = xmb_rt->w; |
622 h = xmb_rt->h; | 624 h = xmb_rt->h; |
623 | 625 |
624 #ifdef XSHM | 626 #ifdef XSHM |
625 xshm_init(xmb_rt); | 627 xshm_init(xmb_rt); |
628 xmb_rt->surface = | 630 xmb_rt->surface = |
629 mbe_image_surface_create(MB_IFMT_ARGB32, w, h); | 631 mbe_image_surface_create(MB_IFMT_ARGB32, w, h); |
630 | 632 |
631 xmb_rt->surface_ptn = | 633 xmb_rt->surface_ptn = |
632 mbe_pattern_create_for_surface(xmb_rt->surface); | 634 mbe_pattern_create_for_surface(xmb_rt->surface); |
633 | 635 |
634 if(xmb_rt->backend_surface == NULL) /* xshm_init() may create one */ | 636 if(xmb_rt->backend_surface == NULL) /* xshm_init() may create one */ |
635 xmb_rt->backend_surface = | 637 xmb_rt->backend_surface = |
636 mbe_xlib_surface_create(xmb_rt->display, | 638 mbe_xlib_surface_create(xmb_rt->display, |
637 xmb_rt->win, | 639 xmb_rt->win, |
638 xmb_rt->visual, | 640 xmb_rt->visual, |
643 | 645 |
644 mbe_set_source(xmb_rt->backend_cr, xmb_rt->surface_ptn); | 646 mbe_set_source(xmb_rt->backend_cr, xmb_rt->surface_ptn); |
645 | 647 |
646 xmb_rt->rdman = (redraw_man_t *)malloc(sizeof(redraw_man_t)); | 648 xmb_rt->rdman = (redraw_man_t *)malloc(sizeof(redraw_man_t)); |
647 redraw_man_init(xmb_rt->rdman, xmb_rt->cr, xmb_rt->backend_cr); | 649 redraw_man_init(xmb_rt->rdman, xmb_rt->cr, xmb_rt->backend_cr); |
648 // FIXME: This is a wired loopback reference. This is inly required when we need | 650 // FIXME: This is a wired loopback reference. This is inly required when we need |
649 // to get the xmb_rt->tman for the animation. We should relocate the tman | 651 // to get the xmb_rt->tman for the animation. We should relocate the tman |
650 // to the redraw_man_t instead. | 652 // to the redraw_man_t instead. |
651 xmb_rt->rdman->rt = xmb_rt; | 653 xmb_rt->rdman->rt = xmb_rt; |
652 | 654 |
653 xmb_rt->tman = mb_tman_new(); | 655 xmb_rt->tman = mb_tman_new(); |
654 | 656 |
655 img_ldr = simple_mb_img_ldr_new(""); | 657 img_ldr = simple_mb_img_ldr_new(""); |
656 xmb_rt->img_ldr = img_ldr; | 658 xmb_rt->img_ldr = img_ldr; |
657 rdman_set_img_ldr(xmb_rt->rdman, img_ldr); | 659 rdman_set_img_ldr(xmb_rt->rdman, img_ldr); |
658 memset(xmb_rt->monitors,0,sizeof(xmb_rt->monitors)); | 660 memset(xmb_rt->monitors,0,sizeof(xmb_rt->monitors)); |
659 | 661 |
660 #ifndef ONLY_MOUSE_MOVE_RAW | 662 #ifndef ONLY_MOUSE_MOVE_RAW |
661 xmb_rt->last = NULL; | 663 xmb_rt->last = NULL; |
662 #endif | 664 #endif |
663 | 665 |
664 X_kb_init(&xmb_rt->kbinfo, xmb_rt->display, xmb_rt->rdman); | 666 X_kb_init(&xmb_rt->kbinfo, xmb_rt->display, xmb_rt->rdman); |
672 * Users should specify width and height of the opening window. | 674 * Users should specify width and height of the opening window. |
673 */ | 675 */ |
674 static int X_MB_init(const char *display_name, | 676 static int X_MB_init(const char *display_name, |
675 int w, int h, X_MB_runtime_t *xmb_rt) { | 677 int w, int h, X_MB_runtime_t *xmb_rt) { |
676 int r; | 678 int r; |
677 | 679 |
678 memset(xmb_rt, 0, sizeof(X_MB_runtime_t)); | 680 memset(xmb_rt, 0, sizeof(X_MB_runtime_t)); |
679 | 681 |
680 xmb_rt->w = w; | 682 xmb_rt->w = w; |
681 xmb_rt->h = h; | 683 xmb_rt->h = h; |
682 r = X_init_connection(display_name, w, h, &xmb_rt->display, | 684 r = X_init_connection(display_name, w, h, &xmb_rt->display, |
683 &xmb_rt->visual, &xmb_rt->win); | 685 &xmb_rt->visual, &xmb_rt->win); |
684 if(r != OK) | 686 if(r != OK) |
685 return ERR; | 687 return ERR; |
686 | 688 |
687 r = X_MB_init_with_win(xmb_rt); | 689 r = X_MB_init_with_win(xmb_rt); |
688 | 690 |
689 return r; | 691 return r; |
690 } | 692 } |
691 | 693 |
692 static void X_MB_destroy(X_MB_runtime_t *xmb_rt) { | 694 static void X_MB_destroy(X_MB_runtime_t *xmb_rt) { |
693 if(xmb_rt->rdman) { | 695 if(xmb_rt->rdman) { |
827 }; | 829 }; |
828 /*! \defgroup x_supp_nodejs_sup Export functions for supporting nodejs plugin. | 830 /*! \defgroup x_supp_nodejs_sup Export functions for supporting nodejs plugin. |
829 * | 831 * |
830 * These functions are for internal using. | 832 * These functions are for internal using. |
831 * @{ | 833 * @{ |
832 */ | 834 */ |
833 /*! \brief Exported for nodejs plugin to call handle_x_event. | 835 /*! \brief Exported for nodejs plugin to call handle_x_event. |
834 */ | 836 */ |
835 void _X_MB_handle_x_event_for_nodejs(void *rt) { | 837 void _X_MB_handle_x_event_for_nodejs(void *rt) { |
836 handle_x_event((X_MB_runtime_t *)rt); | 838 handle_x_event((X_MB_runtime_t *)rt); |
837 } | 839 } |