aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-10-15 22:17:15 +0000
committerRichard M. Stallman1994-10-15 22:17:15 +0000
commit203c1d73bbf5f8bd9fd6111df77e46c34fb39d53 (patch)
tree429f769ec1ca39c6f0d7afc39ee2f79df56eb936
parent7f2ae036225e2c8814ad1eadf1608c3eac3fddc3 (diff)
downloademacs-203c1d73bbf5f8bd9fd6111df77e46c34fb39d53.tar.gz
emacs-203c1d73bbf5f8bd9fd6111df77e46c34fb39d53.zip
(x_set_icon_type): If icon-type is a string, then use
bitmap from that file. (Fx_create_frame): Set icon_bitmap field to -1. (struct x_bitmap_record): New structure type. (x_bitmaps, x_bitmaps_size, x_bitmaps_last, x_bitmaps_free): New variables. (x_allocate_bitmap_record): New function. (x_reference_bitmap, x_create_bitmap, x_create_bitmap_from_file) (x_destroy_bitmap, x_lookup_pixmap): New functions.
-rw-r--r--src/xfns.c187
1 files changed, 183 insertions, 4 deletions
diff --git a/src/xfns.c b/src/xfns.c
index 6cd3450ec67..11a9c47c06c 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -365,6 +365,177 @@ x_top_window_to_frame (wdesc)
365#endif /* USE_X_TOOLKIT */ 365#endif /* USE_X_TOOLKIT */
366 366
367 367
368
369/* Code to deal with bitmaps. Bitmaps are referenced by their bitmap
370 id, which is just an int that this section returns. Bitmaps are
371 reference counted so they can be shared among frames.
372
373 Bitmap indices are guaranteed to be > 0, so a negative number can
374 be used to indicate no bitmap.
375
376 If you use x_create_bitmap_from_data, then you must keep track of
377 the bitmaps yourself. That is, creating a bitmap from the same
378 data more than once will not be caught. */
379
380
381/* Structure recording X pixmap and reference count.
382 If REFCOUNT is 0 then this record is free to be reused. */
383
384struct x_bitmap_record
385{
386 Pixmap pixmap;
387 char *file;
388 int refcount;
389};
390
391/* Pointer to bitmap records. */
392static struct x_bitmap_record *x_bitmaps;
393
394/* Allocated size of x_bitmaps. */
395static int x_bitmaps_size;
396
397/* Last used bitmap index. */
398static int x_bitmaps_last;
399
400/* Count of free bitmaps before X_BITMAPS_LAST. */
401static int x_bitmaps_free;
402
403/* Allocate a new bitmap record. Returns index of new record. */
404
405static int
406x_allocate_bitmap_record ()
407{
408 if (x_bitmaps == NULL)
409 {
410 x_bitmaps_size = 10;
411 x_bitmaps
412 = (struct x_bitmap_record *) xmalloc (x_bitmaps_size * sizeof (struct x_bitmap_record));
413 x_bitmaps_last = 1;
414 return 1;
415 }
416
417 if (x_bitmaps_last < x_bitmaps_size)
418 return ++x_bitmaps_last;
419
420 if (x_bitmaps_free > 0)
421 {
422 int i;
423 for (i = 0; i < x_bitmaps_size; ++i)
424 {
425 if (x_bitmaps[i].refcount == 0)
426 {
427 --x_bitmaps_free;
428 return i + 1;
429 }
430 }
431 }
432
433 x_bitmaps_size *= 2;
434 x_bitmaps = (struct x_bitmap_record *) xrealloc (x_bitmaps, x_bitmaps_size * sizeof (struct x_bitmap_record));
435 return ++x_bitmaps_last;
436}
437
438/* Add one reference to the reference count of the bitmap with id ID. */
439
440void
441x_reference_bitmap (id)
442 int id;
443{
444 ++x_bitmaps[id - 1].refcount;
445}
446
447/* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */
448
449int
450x_create_bitmap_from_data (f, bits, width, height)
451 struct frame *f;
452 char *bits;
453 unsigned int width, height;
454{
455 Pixmap bitmap;
456 int id;
457
458 bitmap = XCreateBitmapFromData (x_current_display, FRAME_X_WINDOW (f),
459 bits, width, height);
460
461 if (! bitmap)
462 return -1;
463
464 id = x_allocate_bitmap_record ();
465 x_bitmaps[id - 1].pixmap = bitmap;
466 x_bitmaps[id - 1].file = NULL;
467 x_bitmaps[id - 1].refcount = 1;
468
469 return id;
470}
471
472/* Create bitmap from file FILE for frame F. */
473
474int
475x_create_bitmap_from_file (f, file)
476 struct frame *f;
477 char *file;
478{
479 unsigned int width, height;
480 Pixmap bitmap;
481 int xhot, yhot, result, id;
482
483 /* Look for an existing bitmap with the same name. */
484 for (id = 0; id < x_bitmaps_last; ++id)
485 {
486 if (x_bitmaps[id].refcount
487 && x_bitmaps[id].file
488 && !strcmp (x_bitmaps[id].file, file))
489 {
490 ++x_bitmaps[id].refcount;
491 return id + 1;
492 }
493 }
494
495 result = XReadBitmapFile (x_current_display, FRAME_X_WINDOW (f),
496 file, &width, &height, &bitmap, &xhot, &yhot);
497 if (result != BitmapSuccess)
498 return -1;
499
500 id = x_allocate_bitmap_record ();
501 x_bitmaps[id - 1].pixmap = bitmap;
502 x_bitmaps[id - 1].refcount = 1;
503 x_bitmaps[id - 1].file = (char *) xmalloc ((strlen (file) + 1));
504 strcpy (x_bitmaps[id - 1].file, file);
505
506 return id;
507}
508
509/* Remove reference to bitmap with id number ID. */
510
511int
512x_destroy_bitmap (id)
513 int id;
514{
515 if (id > 0)
516 {
517 --x_bitmaps[id - 1].refcount;
518 if (! x_bitmaps[id - 1].refcount)
519 {
520 XFreePixmap (x_current_display, x_bitmaps[id - 1].pixmap);
521 if (x_bitmaps[id - 1].file)
522 {
523 free (x_bitmaps[id - 1].file);
524 x_bitmaps[id - 1].file = NULL;
525 }
526 }
527 }
528}
529
530/* Return pixmap given bitmap id. */
531
532Pixmap
533x_lookup_pixmap (id)
534 int id;
535{
536 return x_bitmaps[id - 1].pixmap;
537}
538
368/* Connect the frame-parameter names for X frames 539/* Connect the frame-parameter names for X frames
369 to the ways of passing the parameter values to the window system. 540 to the ways of passing the parameter values to the window system.
370 541
@@ -473,7 +644,7 @@ x_set_frame_parameters (f, alist)
473 Lisp_Object *values; 644 Lisp_Object *values;
474 int i; 645 int i;
475 int left_no_change = 0, top_no_change = 0; 646 int left_no_change = 0, top_no_change = 0;
476 647
477 i = 0; 648 i = 0;
478 for (tail = alist; CONSP (tail); tail = Fcdr (tail)) 649 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
479 i++; 650 i++;
@@ -1083,14 +1254,21 @@ x_set_icon_type (f, arg, oldval)
1083 Lisp_Object tem; 1254 Lisp_Object tem;
1084 int result; 1255 int result;
1085 1256
1086 if (EQ (oldval, Qnil) == EQ (arg, Qnil)) 1257 if (STRINGP (arg))
1258 {
1259 if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt))
1260 return;
1261 }
1262 else if (!STRINGP (oldval) && EQ (oldval, Qnil) == EQ (arg, Qnil))
1087 return; 1263 return;
1088 1264
1089 BLOCK_INPUT; 1265 BLOCK_INPUT;
1090 if (NILP (arg)) 1266 if (NILP (arg))
1091 result = x_text_icon (f, 0); 1267 result = x_text_icon (f, 0);
1092 else 1268 else if (STRINGP (arg))
1093 result = x_bitmap_icon (f); 1269 result = x_bitmap_icon (f, XSTRING (arg)->data);
1270 else
1271 result = x_bitmap_icon (f, 0);
1094 1272
1095 if (result) 1273 if (result)
1096 { 1274 {
@@ -2362,6 +2540,7 @@ be shared by the new frame.")
2362 f->output_method = output_x_window; 2540 f->output_method = output_x_window;
2363 f->display.x = (struct x_display *) xmalloc (sizeof (struct x_display)); 2541 f->display.x = (struct x_display *) xmalloc (sizeof (struct x_display));
2364 bzero (f->display.x, sizeof (struct x_display)); 2542 bzero (f->display.x, sizeof (struct x_display));
2543 f->display.x->icon_bitmap = -1;
2365 2544
2366 FRAME_X_SCREEN (f) = &the_x_screen; 2545 FRAME_X_SCREEN (f) = &the_x_screen;
2367 FRAME_X_SCREEN (f)->reference_count++; 2546 FRAME_X_SCREEN (f)->reference_count++;