Example #1
0
/**
 * This function adds images into image list. It is kinda special as it does not
 * use yank buffer as an input. It should be used at special occasions only,
 * like for loading image_group from image_pile.
 *
 * \param group image list into which images will be added
 * \param index position to which images will be added
 * \param data array containing list of image pointers
 * \param size number of pointers in array
 * \return OK on success
 */
extern RCode group_insert(ImageGroup* group, gint index, Image* data[], guint size) {
	unsigned int source_index = 0;
	unsigned int target_index = 0;
	ImageGroupRecord* buffer = NULL;

	ASSERT(NULL != group);
	ASSERT(NULL != group->list);

	/* check position into which images are being inserted
	 * we do not fail if index = list length ( which is one record after the
	 * last one to be able to add at the end of array */
	if ( index < 0 || group->list->len < index ) {
		ERROR_SET(ERROR.OUT_OF_RANGE);
		ERROR_NOTE("Index %d out of range [0, %d]", index, group->list->len);
		return FAIL;
	}

	// allocate internal buffer for insertions
	TRACE_MESSAGE(IGRP, TL_DEBUG, "Allocate insert buffer (size=%d)", size);
	buffer = (ImageGroupRecord*) g_try_malloc0(size*sizeof(ImageGroupRecord));
	if ( NULL == buffer ) {
		ERROR_SET(ERROR.MEMORY_FAILURE);
		return FAIL;
	}

	// prepare data in buffer for insertion
	TRACE_MESSAGE(IGRP, TL_DEBUG, "Preparing values into insert buffer (count=%d)",size);
	for ( source_index = 0, target_index = 0; source_index < size; source_index++ ) {
		TagList *tags = image_get_groups(data[source_index]);

		if ( FALSE == taglist_contains(tags, group->tag) ) {
			buffer[target_index].image = data[source_index];
			buffer[target_index].select = FALSE;

			image_ref(buffer[target_index].image);
			taglist_insert(tags, group->tag);
			target_index++;
		}
	}

	// compute position into which to insert and insert the data
	TRACE_MESSAGE(IGRP, TL_INFO, "Inserting records into group (name='%s', index=%d, count=%d, filtered=%d)",
		group->name, index, target_index, (size - target_index)
	);
	group->list = g_array_insert_vals(group->list, index, (gpointer)buffer, target_index);

	// deallocate insert buffer
	g_free( (gpointer)buffer );

	return OK;
}
Example #2
0
static int
property_handle_net_wm_icon(void *data,
                            xcb_connection_t *connection,
                            uint8_t state,
                            xcb_window_t window,
                            xcb_atom_t name,
                            xcb_get_property_reply_t *reply)
{
    client_t *c = client_getbywin(window);

    if(c)
    {
        image_t *icon;
        image_unref(&c->icon);
        icon = ewmh_window_icon_from_reply(reply);
        c->icon = icon ? image_ref(&icon) : NULL;

        /* execute hook */
        hooks_property(c, "icon");
    }

    return 0;
}