aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuanma Barranquero2003-07-13 17:29:24 +0000
committerJuanma Barranquero2003-07-13 17:29:24 +0000
commit993d07214775f197a274619dd4c67e89abc7cca7 (patch)
tree58d3c62f81aafc0e04c5b98af512ef53a13452e0
parent62fe13a42095afe74d1ab6e74478d049a424d716 (diff)
downloademacs-993d07214775f197a274619dd4c67e89abc7cca7.tar.gz
emacs-993d07214775f197a274619dd4c67e89abc7cca7.zip
(x_bitmap_mask, x_create_bitmap_mask): New functions to handle mask of bitmaps.
(x_allocate_bitmap_record, x_destroy_bitmap): Modify to handle the mask property. (xg_set_icon): New function, wrapper for gtk_window_icon_from_file.
-rw-r--r--src/xfns.c144
1 files changed, 144 insertions, 0 deletions
diff --git a/src/xfns.c b/src/xfns.c
index cdea92ec63a..fe9ca5a9382 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -550,6 +550,14 @@ x_bitmap_pixmap (f, id)
550 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].pixmap; 550 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].pixmap;
551} 551}
552 552
553int
554x_bitmap_mask (f, id)
555 FRAME_PTR f;
556 int id;
557{
558 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].mask;
559}
560
553 561
554/* Allocate a new bitmap record. Returns index of new record. */ 562/* Allocate a new bitmap record. Returns index of new record. */
555 563
@@ -693,6 +701,7 @@ x_destroy_bitmap (f, id)
693 { 701 {
694 BLOCK_INPUT; 702 BLOCK_INPUT;
695 XFreePixmap (FRAME_X_DISPLAY (f), dpyinfo->bitmaps[id - 1].pixmap); 703 XFreePixmap (FRAME_X_DISPLAY (f), dpyinfo->bitmaps[id - 1].pixmap);
704 XFreePixmap (FRAME_X_DISPLAY (f), dpyinfo->bitmaps[id - 1].mask);
696 if (dpyinfo->bitmaps[id - 1].file) 705 if (dpyinfo->bitmaps[id - 1].file)
697 { 706 {
698 xfree (dpyinfo->bitmaps[id - 1].file); 707 xfree (dpyinfo->bitmaps[id - 1].file);
@@ -714,6 +723,7 @@ x_destroy_all_bitmaps (dpyinfo)
714 if (dpyinfo->bitmaps[i].refcount > 0) 723 if (dpyinfo->bitmaps[i].refcount > 0)
715 { 724 {
716 XFreePixmap (dpyinfo->display, dpyinfo->bitmaps[i].pixmap); 725 XFreePixmap (dpyinfo->display, dpyinfo->bitmaps[i].pixmap);
726 XFreePixmap (dpyinfo->display, dpyinfo->bitmaps[i].mask);
717 if (dpyinfo->bitmaps[i].file) 727 if (dpyinfo->bitmaps[i].file)
718 xfree (dpyinfo->bitmaps[i].file); 728 xfree (dpyinfo->bitmaps[i].file);
719 } 729 }
@@ -721,6 +731,105 @@ x_destroy_all_bitmaps (dpyinfo)
721} 731}
722 732
723 733
734
735
736/* Useful functions defined in the section
737 `Image type independent image structures' below. */
738
739static unsigned long four_corners_best P_ ((XImage *ximg, unsigned long width,
740 unsigned long height));
741
742static int x_create_x_image_and_pixmap P_ ((struct frame *f, int width, int height,
743 int depth, XImage **ximg,
744 Pixmap *pixmap));
745
746static void x_destroy_x_image P_ ((XImage *ximg));
747
748
749/* Create a mask of a bitmap. Note is this not a perfect mask.
750 It's nicer with some borders in this context */
751
752int
753x_create_bitmap_mask(f, id)
754 struct frame *f;
755 int id;
756{
757 Pixmap pixmap, mask;
758 XImage *ximg, *mask_img;
759 unsigned long width, height;
760 int result;
761 unsigned long bg;
762 unsigned long x, y, xp, xm, yp, ym;
763 GC gc;
764
765 int depth = DefaultDepthOfScreen (FRAME_X_SCREEN (f));
766 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
767
768 if (!(id > 0))
769 return -1;
770
771 pixmap = x_bitmap_pixmap(f, id);
772 width = x_bitmap_width(f, id);
773 height = x_bitmap_height(f, id);
774
775 BLOCK_INPUT;
776 ximg = XGetImage (FRAME_X_DISPLAY (f), pixmap, 0, 0, width, height,
777 ~0, ZPixmap);
778
779 if (!ximg)
780 {
781 UNBLOCK_INPUT;
782 return -1;
783 }
784
785 result = x_create_x_image_and_pixmap (f, width, height, 1, &mask_img, &mask);
786
787 UNBLOCK_INPUT;
788 if (!result)
789 {
790 XDestroyImage(ximg);
791 return -1;
792 }
793
794 bg = four_corners_best (ximg, width, height);
795
796 for (y = 0; y < ximg->height; ++y)
797 {
798 for (x = 0; x < ximg->width; ++x)
799 {
800 xp = x != ximg->width - 1 ? x + 1 : 0;
801 xm = x != 0 ? x - 1 : ximg->width - 1;
802 yp = y != ximg->height - 1 ? y + 1 : 0;
803 ym = y != 0 ? y - 1 : ximg->height - 1;
804 if (XGetPixel (ximg, x, y) == bg
805 && XGetPixel (ximg, x, yp) == bg
806 && XGetPixel (ximg, x, ym) == bg
807 && XGetPixel (ximg, xp, y) == bg
808 && XGetPixel (ximg, xp, yp) == bg
809 && XGetPixel (ximg, xp, ym) == bg
810 && XGetPixel (ximg, xm, y) == bg
811 && XGetPixel (ximg, xm, yp) == bg
812 && XGetPixel (ximg, xm, ym) == bg)
813 XPutPixel (mask_img, x, y, 0);
814 else
815 XPutPixel (mask_img, x, y, 1);
816 }
817 }
818
819 xassert (interrupt_input_blocked);
820 gc = XCreateGC (FRAME_X_DISPLAY (f), mask, 0, NULL);
821 XPutImage (FRAME_X_DISPLAY (f), mask, gc, mask_img, 0, 0, 0, 0,
822 width, height);
823 XFreeGC (FRAME_X_DISPLAY (f), gc);
824
825 dpyinfo->bitmaps[id - 1].mask = mask;
826
827 XDestroyImage (ximg);
828 x_destroy_x_image(mask_img);
829
830 return 0;
831}
832
724static Lisp_Object unwind_create_frame P_ ((Lisp_Object)); 833static Lisp_Object unwind_create_frame P_ ((Lisp_Object));
725static Lisp_Object unwind_create_tip_frame P_ ((Lisp_Object)); 834static Lisp_Object unwind_create_tip_frame P_ ((Lisp_Object));
726static void x_disable_image P_ ((struct frame *, struct image *)); 835static void x_disable_image P_ ((struct frame *, struct image *));
@@ -976,6 +1085,41 @@ x_set_wait_for_wm (f, new_value, old_value)
976 f->output_data.x->wait_for_wm = !NILP (new_value); 1085 f->output_data.x->wait_for_wm = !NILP (new_value);
977} 1086}
978 1087
1088#ifdef USE_GTK
1089
1090/* Wrapper for gtk_window_icon_from_file() */
1091
1092int
1093xg_set_icon(f, file)
1094 struct frame *f;
1095 Lisp_Object file;
1096{
1097 struct gcpro gcpro1, gcpro2, gcpro3;
1098 int fd;
1099 int result = 1;
1100 Lisp_Object found, search_path;
1101 char *filename;
1102
1103 search_path = Fcons (Vdata_directory, Vx_bitmap_file_path);
1104
1105 GCPRO3 (found, search_path, file);
1106 fd = openp (search_path, file, Qnil, &found, Qnil);
1107 if (fd > 0)
1108 {
1109 filename = (char *) SDATA (found);
1110 BLOCK_INPUT;
1111 result =
1112 gtk_window_set_icon_from_file (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
1113 filename,
1114 NULL);
1115 UNBLOCK_INPUT;
1116 }
1117 emacs_close (fd);
1118 UNGCPRO;
1119 return result;
1120}
1121#endif /* USE_GTK */
1122
979 1123
980/* Functions called only from `x_set_frame_param' 1124/* Functions called only from `x_set_frame_param'
981 to set individual parameters. 1125 to set individual parameters.