コード例 #1
0
ファイル: tinto.c プロジェクト: roomcays/tinto-panel
void event_property_notify(XEvent* e) {
    int i;
    Task* tsk;
    Window win = e->xproperty.window;
    Atom at = e->xproperty.atom;

    if (xsettings_client) xsettings_client_process_event(xsettings_client, e);
    if (win == server.root_win) {
        if (!server.got_root_win) {
            XSelectInput(server.dsp, server.root_win,
                         PropertyChangeMask | StructureNotifyMask);
            server.got_root_win = 1;
        }

        // Change name of desktops
        else if (at == server.atom._NET_DESKTOP_NAMES) {
            if (!taskbarname_enabled) return;
            GSList* l, *list = server_get_name_of_desktop();
            gchar* name;
            Taskbar* tskbar;
            for (i = 0; i < nb_panel; i++) {
                l = list;
                for (uint8_t j = 0; j < panel1[i].desktop_count; j++) {
                    if (l) {
                        name = g_strdup(l->data);
                        l = l->next;
                    } else
                        name = g_strdup_printf("%d", j + 1);
                    tskbar = &panel1[i].taskbar[j];
                    if (strcmp(name, tskbar->bar_name.name) != 0) {
                        g_free(tskbar->bar_name.name);
                        tskbar->bar_name.name = name;
                        tskbar->bar_name.area.resize = 1;
                    } else
                        g_free(name);
                }
            }
            for (l = list; l; l = l->next) g_free(l->data);
            g_slist_free(list);
            panel_refresh = 1;
        }
        // Change number of desktops
        else if (at == server.atom._NET_NUMBER_OF_DESKTOPS) {
            if (!taskbar_enabled) return;
            server.nb_desktop = server_get_number_of_desktop();
            if (server.nb_desktop <= server.desktop) {
                server.desktop = server.nb_desktop - 1;
            }
            cleanup_taskbar();
            init_taskbar();
            for (i = 0; i < nb_panel; i++) {
                init_taskbar_panel(&panel1[i]);
                set_panel_items_order(&panel1[i]);
                visible_taskbar(&panel1[i]);
                panel1[i].area.resize = 1;
            }
            task_refresh_tasklist();
            active_task();
            panel_refresh = 1;
        }
        // Change desktop
        else if (at == server.atom._NET_CURRENT_DESKTOP) {
            if (!taskbar_enabled) return;
            int old_desktop = server.desktop;
            server.desktop = server_get_current_desktop();
            for (i = 0; i < nb_panel; i++) {
                Panel* panel = &panel1[i];
                set_taskbar_state(&panel->taskbar[old_desktop], TASKBAR_NORMAL);
                set_taskbar_state(&panel->taskbar[server.desktop], TASKBAR_ACTIVE);
                // check ALLDESKTOP task => resize taskbar
                Taskbar* tskbar;
                Task* tsk;
                GSList* l;
                if (server.nb_desktop > old_desktop) {
                    tskbar = &panel->taskbar[old_desktop];
                    l = tskbar->area.list;
                    if (taskbarname_enabled) l = l->next;
                    for (; l; l = l->next) {
                        tsk = l->data;
                        if (tsk->desktop == ALLDESKTOP) {
                            tsk->area.on_screen = 0;
                            tskbar->area.resize = 1;
                            panel_refresh = 1;
                        }
                    }
                }
                tskbar = &panel->taskbar[server.desktop];
                l = tskbar->area.list;
                if (taskbarname_enabled) l = l->next;
                for (; l; l = l->next) {
                    tsk = l->data;
                    if (tsk->desktop == ALLDESKTOP) {
                        tsk->area.on_screen = 1;
                        tskbar->area.resize = 1;
                    }
                }
            }
        }
        // Window list
        else if (at == server.atom._NET_CLIENT_LIST) {
            task_refresh_tasklist();
            panel_refresh = 1;
        }
        // Change active
        else if (at == server.atom._NET_ACTIVE_WINDOW) {
            active_task();
            panel_refresh = 1;
        } else if (at == server.atom._XROOTPMAP_ID ||
                   at == server.atom._XROOTMAP_ID) {
            // change Wallpaper
            for (i = 0; i < nb_panel; i++) {
                set_panel_background(&panel1[i]);
            }
            panel_refresh = 1;
        }
    } else {
        tsk = task_get_task(win);
        if (!tsk) {
            if (at != server.atom._NET_WM_STATE)
                return;
            else {
                // xfce4 sends _NET_WM_STATE after minimized to tray, so we need to
                // check if window is mapped
                // if it is mapped and not set as skip_taskbar, we must add it to our
                // task list
                XWindowAttributes wa;
                XGetWindowAttributes(server.dsp, win, &wa);
                if (wa.map_state == IsViewable && !window_is_skip_taskbar(win)) {
                    if ((tsk = add_task(win)))
                        panel_refresh = 1;
                    else
                        return;
                } else
                    return;
            }
        }

        // Window title changed
        if (at == server.atom._NET_WM_VISIBLE_NAME ||
                at == server.atom._NET_WM_NAME || at == server.atom.WM_NAME) {
            if (get_title(tsk)) {
                if (g_tooltip.mapped && (g_tooltip.area == (Area*)tsk)) {
                    tooltip_copy_text((Area*)tsk);
                    tooltip_update();
                }
                panel_refresh = 1;
            }
        }
        // Demand attention
        else if (at == server.atom._NET_WM_STATE) {
            if (window_is_urgent(win)) {
                add_urgent(tsk);
            }
            if (window_is_skip_taskbar(win)) {
                remove_task(tsk);
                panel_refresh = 1;
            }
        } else if (at == server.atom.WM_STATE) {
            // Iconic state
            int state = (task_active && tsk->win == task_active->win ? TASK_ACTIVE
                         : TASK_NORMAL);
            if (window_is_iconified(win)) state = TASK_ICONIFIED;
            set_task_state(tsk, state);
            panel_refresh = 1;
        }
        // Window icon changed
        else if (at == server.atom._NET_WM_ICON) {
            get_icon(tsk);
            panel_refresh = 1;
        }
        // Window desktop changed
        else if (at == server.atom._NET_WM_DESKTOP) {
            uint32_t desktop = window_get_desktop(win);
            // bug in windowmaker : send unecessary 'desktop changed' when focus
            // changed
            if (desktop != tsk->desktop) {
                remove_task(tsk);
                tsk = add_task(win);
                active_task();
                panel_refresh = 1;
            }
        } else if (at == server.atom.WM_HINTS) {
            XWMHints* wmhints = XGetWMHints(server.dsp, win);
            if (wmhints && wmhints->flags & XUrgencyHint) {
                add_urgent(tsk);
            }
            XFree(wmhints);
        }

        if (!server.got_root_win)
            server.root_win = RootWindow(server.dsp, server.screen);
    }
}
コード例 #2
0
ファイル: task.c プロジェクト: chigoncalves/tinto
Task *add_task (Window win)
{
	if (!win) return 0;
	if (window_is_hidden(win)) return 0;

	int monitor;
	if (nb_panel > 1) {
		monitor = window_get_monitor (win);
		if (monitor >= nb_panel) monitor = 0;
	}
	else monitor = 0;

	Task new_tsk;
	new_tsk.win = win;
	new_tsk.desktop = window_get_desktop (win);
	new_tsk.area.panel = &panel1[monitor];
	new_tsk.current_state = window_is_iconified(win) ? TASK_ICONIFIED : TASK_NORMAL;

  window_get_coordinates (win, &new_tsk.geometry);

	// allocate only one title and one icon
	// even with task_on_all_desktop and with task_on_all_panel
	new_tsk.title = 0;
	int k;
	for (k=0; k<TASK_STATE_COUNT; ++k) {
		new_tsk.icon[k] = 0;
		new_tsk.state_pix[k] = 0;
	}
	get_title(&new_tsk);
	get_icon(&new_tsk);

	//printf("task %s : desktop %d, monitor %d\n", new_tsk->title, desktop, monitor);
	XSelectInput (server.dsp, new_tsk.win, PropertyChangeMask|StructureNotifyMask);

	GPtrArray* task_group = g_ptr_array_new();
	Taskbar *tskbar;
	Task *new_tsk2=0;

	for (uint32_t j=0, desktop_count = panel1[monitor].nb_desktop; j < desktop_count ; j++) {
		if (new_tsk.desktop != ALLDESKTOP && new_tsk.desktop != j) continue;

		tskbar = &panel1[monitor].taskbar[j];
		new_tsk2 = calloc(1, sizeof(Task));
		memcpy(&new_tsk2->area, &panel1[monitor].g_task.area, sizeof(Area));
		new_tsk2->area.parent = tskbar;
		new_tsk2->win = new_tsk.win;
		new_tsk2->desktop = new_tsk.desktop;
		/* new_tsk2->win_x = new_tsk.win_x; */
		/* new_tsk2->win_y = new_tsk.win_y; */
		/* new_tsk2->win_w = new_tsk.win_w; */
		/* new_tsk2->win_h = new_tsk.win_h; */
    new_tsk2->geometry = new_tsk.geometry;
		new_tsk2->current_state = -1;  // to update the current state later in set_task_state...
		if (new_tsk2->desktop == ALLDESKTOP && server.desktop != (int)j) {
			// hide ALLDESKTOP task on non-current desktop
			new_tsk2->area.visible = 0;
		}
		new_tsk2->title = new_tsk.title;
		if (panel1[monitor].g_task.tooltip_enabled)
			new_tsk2->area._get_tooltip_text = task_get_tooltip;
		for (k=0; k<TASK_STATE_COUNT; ++k) {
			new_tsk2->icon[k] = new_tsk.icon[k];
			new_tsk2->state_pix[k] = 0;
		}
		new_tsk2->icon_width = new_tsk.icon_width;
		new_tsk2->icon_height = new_tsk.icon_height;
		tskbar->area.children = g_slist_append(tskbar->area.children, new_tsk2);
		tskbar->area.resize = 1;
		g_ptr_array_add(task_group, new_tsk2);
		//printf("add_task panel %d, desktop %d, task %s\n", i, j, new_tsk2->title);
	}
	Window* key = calloc(1, sizeof(Window));
	*key = new_tsk.win;
	g_hash_table_insert(win_to_task_table, key, task_group);
	set_task_state(new_tsk2, new_tsk.current_state);

	sort_taskbar_for_win(win);

	if (panel_mode == MULTI_DESKTOP) {
		Panel *panel = new_tsk2->area.panel;
		panel->area.resize = 1;
	}

	if (window_is_urgent(win)) {
		add_urgent(new_tsk2);
	}

	return new_tsk2;
}