Exemplo n.º 1
0
Task *task_get_task (Window win)
{
	GPtrArray* task_group = task_get_tasks(win);
	if (task_group)
		return g_ptr_array_index(task_group, 0);
	else
		return 0;
}
Exemplo n.º 2
0
int get_title(Task *tsk)
{
	Panel *panel = tsk->area.panel;
	char *title, *name;

	if (!panel->g_task.text &&
		!panel->g_task.tooltip_enabled &&
		taskbar_sort_method != TASKBAR_SORT_TITLE)
		return 0;

	name = server_get_property (tsk->win, server.atom._NET_WM_VISIBLE_NAME, server.atom.UTF8_STRING, 0);
	if (!name || !strlen(name)) {
		name = server_get_property (tsk->win, server.atom._NET_WM_NAME, server.atom.UTF8_STRING, 0);
		if (!name || !strlen(name)) {
			name = server_get_property (tsk->win, server.atom.WM_NAME, XA_STRING, 0);
			if (!name || !strlen(name)) {
				name = calloc(10, 1);
				strcpy(name, "Untitled");
			}
		}
	}

	// add space before title
	title = calloc(strlen(name)+2, 1);
	if (panel->g_task.icon) strcpy(title, " ");
	else title[0] = 0;
	strcat(title, name);
	if (name) XFree (name);

	if (tsk->title) {
		// check unecessary title change
		if (strcmp(tsk->title, title) == 0) {
			free(title);
			return 0;
		}
		else
			free(tsk->title);
	}

	tsk->title = title;
	GPtrArray* task_group = task_get_tasks(tsk->win);
	if (task_group) {
		for (size_t i = 0; i<task_group->len; ++i) {
			Task* tsk2 = g_ptr_array_index(task_group, i);
			tsk2->title = tsk->title;
			set_task_redraw(tsk2);
		}
	}
	return 1;
}
Exemplo n.º 3
0
int window_is_hidden (Window win)
{
	Window window;
	Atom *at;
	int count, i;

	at = server_get_property (win, server.atom._NET_WM_STATE, XA_ATOM, &count);
	for (i = 0; i < count; i++) {
		if (at[i] == server.atom._NET_WM_STATE_SKIP_TASKBAR) {
			XFree(at);
			return 1;
		}
		// do not add transient_for windows if the transient window is already in the taskbar
		window=win;
		while ( XGetTransientForHint(server.dsp, window, &window) ) {
			if ( task_get_tasks(window) ) {
				XFree(at);
				return 1;
			}
		}
	}
	XFree(at);

	at = server_get_property (win, server.atom._NET_WM_WINDOW_TYPE, XA_ATOM, &count);
	for (i = 0; i < count; i++) {
		if (at[i] == server.atom._NET_WM_WINDOW_TYPE_DOCK || at[i] == server.atom._NET_WM_WINDOW_TYPE_DESKTOP || at[i] == server.atom._NET_WM_WINDOW_TYPE_TOOLBAR || at[i] == server.atom._NET_WM_WINDOW_TYPE_MENU || at[i] == server.atom._NET_WM_WINDOW_TYPE_SPLASH) {
			XFree(at);
			return 1;
		}
	}
	XFree(at);

	for (i=0 ; i < nb_panel ; i++) {
		if (panel1[i].main_win == win) {
			return 1;
		}
	}

	// specification
	// Windows with neither _NET_WM_WINDOW_TYPE nor WM_TRANSIENT_FOR set
	// MUST be taken as top-level window.
	return 0;
}
Exemplo n.º 4
0
void active_task()
{
	if (task_active) {
		set_task_state(task_active, window_is_iconified(task_active->win) ? TASK_ICONIFIED : TASK_NORMAL);
		task_active = 0;
	}

	Window w1 = window_get_active();
	//printf("Change active task %ld\n", w1);

	if (w1) {
		if (!task_get_tasks(w1)) {
			Window w2;
			while (XGetTransientForHint(server.dsp, w1, &w2))
				w1 = w2;
		}
		set_task_state((task_active = task_get_task(w1)), TASK_ACTIVE);
	}
}
Exemplo n.º 5
0
void set_task_state(Task *tsk, int state)
{
	if (tsk == 0 || state < 0 || state >= TASK_STATE_COUNT)
		return;

	if (tsk->current_state != state || hide_task_diff_monitor) {
		GPtrArray* task_group = task_get_tasks(tsk->win);
		if (task_group) {
			for (size_t i=0; i<task_group->len; ++i) {
				Task* tsk1 = g_ptr_array_index(task_group, i);
				tsk1->current_state = state;
				tsk1->area.background = panel1[0].g_task.background[state];
				tsk1->area.pixmap = tsk1->state_pix[state];
				if (tsk1->state_pix[state] == 0)
					tsk1->area.redraw = 1;
				if (state == TASK_ACTIVE && g_slist_find(urgent_list, tsk1))
					del_urgent(tsk1);
				// Show only the active task
				int hide = 0;
				if (hide_inactive_tasks) {
					if (state != TASK_ACTIVE) {
						hide = 1;
					}
				}
				if (window_get_monitor(tsk->win) != ((Panel*)tsk->area.panel)->monitor &&
					(hide_task_diff_monitor || nb_panel > 1)) {
					hide = 1;
				}
				if (1 - hide != tsk1->area.visible) {
					tsk1->area.visible = 1 - hide;
					set_task_redraw(tsk1);
					Panel *p = (Panel*)tsk->area.panel;
					tsk->area.resize = 1;
					p->taskbar->area.resize = 1;
					p->area.resize = 1;
				}
			}
			panel_refresh = 1;
		}
	}
}
Exemplo n.º 6
0
void get_icon (Task *tsk)
{
	Panel *panel = tsk->area.panel;
	if (!panel->g_task.icon) return;
	size_t i;
	Imlib_Image img = NULL;
	XWMHints *hints = 0;
	gulong *data = 0;

	int k;
	for (k=0; k<TASK_STATE_COUNT; ++k) {
		if (tsk->icon[k]) {
			imlib_context_set_image(tsk->icon[k]);
			imlib_free_image();
			tsk->icon[k] = 0;
		}
	}

	data = server_get_property (tsk->win, server.atom._NET_WM_ICON, XA_CARDINAL, (int*)&i);
	if (data) {
		// get ARGB icon
		int w, h;
		gulong *tmp_data;

		tmp_data = get_best_icon (data, get_icon_count (data, i), i, &w, &h, panel->g_task.icon_size1);
#ifdef __x86_64__
		DATA32 icon_data[w * h];
		size_t length = w * h;
		for (i = 0; i < length; ++i)
			icon_data[i] =  tmp_data[i];
		img = imlib_create_image_using_copied_data (w, h, icon_data);
#else
		img = imlib_create_image_using_data (w, h, (DATA32*)tmp_data);
#endif
	}
	else {
		// get Pixmap icon
		hints = XGetWMHints(server.dsp, tsk->win);
		if (hints) {
			if (hints->flags & IconPixmapHint && hints->icon_pixmap != 0) {
				// get width, height and depth for the pixmap
				Window root;
				int  icon_x, icon_y;
				uint32_t border_width, bpp;
				uint32_t w, h;

				//printf("  get pixmap\n");
				XGetGeometry(server.dsp, hints->icon_pixmap, &root, &icon_x, &icon_y, &w, &h, &border_width, &bpp);
				imlib_context_set_drawable(hints->icon_pixmap);
				img = imlib_create_image_from_drawable(hints->icon_mask, 0, 0, w, h, 0);
			}
		}
	}
	if (img == NULL) {
		imlib_context_set_image(default_icon);
		img = imlib_clone_image();
	}

	// transform icons
	imlib_context_set_image(img);
	imlib_image_set_has_alpha(1);
	int w, h;
	w = imlib_image_get_width();
	h = imlib_image_get_height();
	Imlib_Image orig_image = imlib_create_cropped_scaled_image(0, 0, w, h, panel->g_task.icon_size1, panel->g_task.icon_size1);
	imlib_free_image();

	imlib_context_set_image(orig_image);
	tsk->icon_width = imlib_image_get_width();
	tsk->icon_height = imlib_image_get_height();
	for (k=0; k<TASK_STATE_COUNT; ++k) {
		imlib_context_set_image(orig_image);
		tsk->icon[k] = imlib_clone_image();
		imlib_context_set_image(tsk->icon[k]);
		DATA32 *data32;
		if (panel->g_task.alpha[k] != 100 || panel->g_task.saturation[k] != 0 || panel->g_task.brightness[k] != 0) {
			data32 = imlib_image_get_data();
			adjust_asb(data32, tsk->icon_width, tsk->icon_height, panel->g_task.alpha[k], (float)panel->g_task.saturation[k]/100, (float)panel->g_task.brightness[k]/100);
			imlib_image_put_back_data(data32);
		}
	}
	imlib_context_set_image(orig_image);
	imlib_free_image();

	if (hints)
		XFree(hints);
	if (data)
		XFree (data);

	GPtrArray* task_group = task_get_tasks(tsk->win);
	if (task_group) {
		for (i=0; i<task_group->len; ++i) {
			Task* tsk2 = g_ptr_array_index(task_group, i);
			tsk2->icon_width = tsk->icon_width;
			tsk2->icon_height = tsk->icon_height;
			int k;
			for (k=0; k<TASK_STATE_COUNT; ++k)
				tsk2->icon[k] = tsk->icon[k];
			set_task_redraw(tsk2);
		}
	}
}