コード例 #1
0
ファイル: fspanel.c プロジェクト: hoverisk/fspanel-black
void
get_task_hinticon (task *tk)
{
	XWMHints *hin;

	tk->icon = None;
	tk->mask = None;

	hin = (XWMHints *) get_prop_data (tk->win, XA_WM_HINTS, XA_WM_HINTS, 0);
	if (hin)
	{
		if ((hin->flags & IconPixmapHint))
		{
			if ((hin->flags & IconMaskHint))
			{
				tk->mask = hin->icon_mask;
			}

			tk->icon = hin->icon_pixmap;
			tk->icon_copied = 1;
			scale_icon (tk);
		}
		XFree (hin);
	}

	if (tk->icon == None)
	{
		tk->icon = generic_icon;
		tk->mask = generic_mask;
	}
}
コード例 #2
0
static inline cairo_surface_t *
scale_icon_if_required (cairo_surface_t *icon)
{
  cairo_surface_t *scaled_icon;
  int width, height;

  width = cairo_image_surface_get_width (icon);
  height = cairo_image_surface_get_height (icon);

  if (width == THUMBNAIL_WIDTH &&
      height == THUMBNAIL_HEIGHT)
    return cairo_surface_reference (icon);

  scaled_icon = scale_icon (icon, width, height);

  return scaled_icon;
}
コード例 #3
0
ファイル: launcher.c プロジェクト: Dok-Sergey/tint2
int resize_launcher(void *obj)
{
	Launcher *launcher = obj;
	GSList *l;
	int count, icon_size;
	int icons_per_column=1, icons_per_row=1, marging=0;

	if (panel_horizontal) {
		icon_size = launcher->area.height;
	} else {
		icon_size = launcher->area.width;
	}
	icon_size = icon_size - (2 * launcher->area.bg->border.width) - (2 * launcher->area.paddingy);
	if (launcher_max_icon_size > 0 && icon_size > launcher_max_icon_size)
		icon_size = launcher_max_icon_size;

	// Resize icons if necessary
	for (l = launcher->list_icons; l ; l = l->next) {
		LauncherIcon *launcherIcon = (LauncherIcon *)l->data;
		if (launcherIcon->icon_size != icon_size || !launcherIcon->icon_original) {
			launcherIcon->icon_size = icon_size;
			launcherIcon->area.width = launcherIcon->icon_size;
			launcherIcon->area.height = launcherIcon->icon_size;

			// Get the path for an icon file with the new size
			char *new_icon_path = get_icon_path(launcher->list_themes, launcherIcon->icon_name, launcherIcon->icon_size);
			if (!new_icon_path) {
				// Draw a blank icon
				free_icon(launcherIcon->icon_original);
				launcherIcon->icon_original = NULL;
				free_icon(launcherIcon->icon_scaled);
				launcherIcon->icon_scaled = NULL;
				continue;
			}
			if (launcherIcon->icon_path && strcmp(new_icon_path, launcherIcon->icon_path) == 0) {
				// If it's the same file just rescale
				free_icon(launcherIcon->icon_scaled);
				launcherIcon->icon_scaled = scale_icon(launcherIcon->icon_original, icon_size);
				free(new_icon_path);
				fprintf(stderr, "launcher.c %d: Using icon %s\n", __LINE__, launcherIcon->icon_path);
			} else {
				// Free the old files
				free_icon(launcherIcon->icon_original);
				free_icon(launcherIcon->icon_scaled);
				launcherIcon->icon_original = launcherIcon->icon_scaled = NULL;
				// Load the new file and scale
#ifdef HAVE_RSVG
				if (g_str_has_suffix(new_icon_path, ".svg")) {
					GError* err = NULL;
					RsvgHandle* svg = rsvg_handle_new_from_file(new_icon_path, &err);

					if (err != NULL) {
						fprintf(stderr, "Could not load svg image!: %s", err->message);
						g_error_free(err);
						launcherIcon->icon_original = NULL;
					} else {
						char suffix[128];
						sprintf(suffix, "tmpicon-%d.png", getpid());
						gchar *name = g_build_filename(g_get_user_config_dir(), "tint2", suffix, NULL);
						GdkPixbuf *pixbuf = rsvg_handle_get_pixbuf(svg);
						gdk_pixbuf_save(pixbuf, name, "png", NULL, NULL);
						launcherIcon->icon_original = imlib_load_image_immediately_without_cache(name);
						g_remove(name);
						g_free(name);
						g_object_unref(G_OBJECT(pixbuf));
						g_object_unref(G_OBJECT(svg));
					}
				} else
#endif
				{
					launcherIcon->icon_original = imlib_load_image_immediately(new_icon_path);
				}
				// On loading error, fallback to default
				if (!launcherIcon->icon_original) {
					free(new_icon_path);
					new_icon_path = get_icon_path(launcher->list_themes, DEFAULT_ICON, launcherIcon->icon_size);
					if (new_icon_path)
						launcherIcon->icon_original = imlib_load_image_immediately(new_icon_path);
				}

				if (!launcherIcon->icon_original) {
					// Loading default icon failed, draw a blank icon
					free(new_icon_path);
				} else {
					// Loaded icon successfully
					launcherIcon->icon_scaled = scale_icon(launcherIcon->icon_original, launcherIcon->icon_size);
					free(launcherIcon->icon_path);
					launcherIcon->icon_path = new_icon_path;
					fprintf(stderr, "launcher.c %d: Using icon %s\n", __LINE__, launcherIcon->icon_path);
				}
			}
		}
	}
	
	count = g_slist_length(launcher->list_icons);

	if (panel_horizontal) {
		if (!count) {
			launcher->area.width = 0;
		} else {
			int height = launcher->area.height - 2*launcher->area.bg->border.width - 2*launcher->area.paddingy;
			// here icons_per_column always higher than 0
			icons_per_column = (height+launcher->area.paddingx) / (icon_size+launcher->area.paddingx);
			marging = height - (icons_per_column-1)*(icon_size+launcher->area.paddingx) - icon_size;
			icons_per_row = count / icons_per_column + (count%icons_per_column != 0);
			launcher->area.width = (2 * launcher->area.bg->border.width) +
								   (2 * launcher->area.paddingxlr) +
								   (icon_size * icons_per_row) +
								   ((icons_per_row-1) * launcher->area.paddingx);
		}
	}
	else {
		if (!count) {
			launcher->area.height = 0;
		} else {
			int width = launcher->area.width - 2*launcher->area.bg->border.width - 2*launcher->area.paddingy;
			// here icons_per_row always higher than 0
			icons_per_row = (width+launcher->area.paddingx) / (icon_size+launcher->area.paddingx);
			marging = width - (icons_per_row-1)*(icon_size+launcher->area.paddingx) - icon_size;
			icons_per_column = count / icons_per_row+ (count%icons_per_row != 0);
			launcher->area.height = (2 * launcher->area.bg->border.width) +
									(2 * launcher->area.paddingxlr) +
									(icon_size * icons_per_column) +
									((icons_per_column-1) * launcher->area.paddingx);
		}
	}

	int i, posx, posy;
	int start = launcher->area.bg->border.width + launcher->area.paddingy + marging/2;
	if (panel_horizontal) {
		posy = start;
		posx = launcher->area.bg->border.width + launcher->area.paddingxlr;
	} else {
		posx = start;
		posy = launcher->area.bg->border.width + launcher->area.paddingxlr;
	}

	for (i=1, l = launcher->list_icons; l ; i++, l = l->next) {
		LauncherIcon *launcherIcon = (LauncherIcon*)l->data;
		
		launcherIcon->y = posy;
		launcherIcon->x = posx;
		launcherIcon->area.posy = ((Area*)launcherIcon->area.parent)->posy + launcherIcon->y;
		launcherIcon->area.posx = ((Area*)launcherIcon->area.parent)->posx + launcherIcon->x;
		launcherIcon->area.width = launcherIcon->icon_size;
		launcherIcon->area.height = launcherIcon->icon_size;
		//printf("launcher %d : %d,%d\n", i, posx, posy);
		if (panel_horizontal) {
			if (i % icons_per_column) {
				posy += icon_size + launcher->area.paddingx;
			} else {
				posy = start;
				posx += (icon_size + launcher->area.paddingx);
			}
		} else {
			if (i % icons_per_row) {
				posx += icon_size + launcher->area.paddingx;
			} else {
				posx = start;
				posy += (icon_size + launcher->area.paddingx);
			}
		}
	}
	return 1;
}
コード例 #4
0
ファイル: fixbundle.c プロジェクト: AntonLanghoff/whitecatlib
static int load_resource(char *datafile, char *name, ICON_DATA *icon)
{
   DATAFILE *data;
   BITMAP *temp, *bitmap = NULL;
   RLE_SPRITE *rle_sprite;
   PALETTE palette;
   int size, type, i;
   int result = 0;
   
   if (datafile[0] != '\0') {
      data = load_datafile_object(datafile, name);
      if (!data) {
         fprintf(stderr, "Error loading object '%s' from %s\n", name, datafile);
	 return -1;
      }
      switch (data->type) {
      
         case DAT_BITMAP:
	    temp = (BITMAP *)data->dat;
	    bitmap = create_bitmap_ex(temp->vtable->color_depth, temp->w, temp->h);
	    blit(temp, bitmap, 0, 0, 0, 0, temp->w, temp->h);
	    break;
	    
	 case DAT_RLE_SPRITE:
	    rle_sprite = (RLE_SPRITE *)data->dat;
	    bitmap = create_bitmap_ex(rle_sprite->color_depth, rle_sprite->w, rle_sprite->h);
	    clear_to_color(bitmap, bitmap->vtable->mask_color);
	    draw_rle_sprite(bitmap, rle_sprite, 0, 0);
	    break;
	    
	 case DAT_PALETTE:
	    select_palette((RGB *)data->dat);
	    unload_datafile_object(data);
	    return 0;
	 
	 default:
	    fprintf(stderr, "'%s' is not a BITMAP, RLE_SPRITE or PALETTE object in datafile '%s'\n", name, datafile);
	    unload_datafile_object(data);
	    return -1;
      }
      unload_datafile_object(data);
   }
   else {
      bitmap = load_bitmap(name, palette);
      select_palette(palette);
      if (!bitmap) {
         fprintf(stderr, "Unable to load '%s'\n", name);
	 return -1;
      }
   }
   
   if (!icon) {
      size = MAX(bitmap->w, bitmap->h);
      if (size <= 16)
         type = ICON_SMALL;
      else if (size <= 32)
         type = ICON_LARGE;
      else if (size <= 48)
         type = ICON_HUGE;
      else
         type = ICON_THUMBNAIL;
      icon = &icon_data[type];
      if (flags & icon->defined) {
         for (i = 0; i < 3; i++) {
	    type = (type + 1) % 4;
	    icon = &icon_data[type];
	    if (!(flags & icon->defined))
	       break;
	 }
	 if (flags & icon->defined) {
	    fprintf(stderr, "Too many icon resources!");
	    result = -1;
	    goto exit_error;
	 }
      }
   }
   else {
      if (icon->scaled) {
         fprintf(stderr, "Multiple icon resources of the same size");
	 result = -1;
	 goto exit_error;
      }
   }
   icon->original = create_bitmap_ex(bitmap->vtable->color_depth, bitmap->w, bitmap->h);
   blit(bitmap, icon->original, 0, 0, 0, 0, bitmap->w, bitmap->h);
   result = scale_icon(icon);
   flags |= icon->defined;
   
exit_error:
   destroy_bitmap(bitmap);
   
   return result;
}