static void pager_propertynotify(pager_priv *p, XEvent *ev) { Atom at = ev->xproperty.atom; Window win = ev->xproperty.window; task *t; ENTER; if ((win == GDK_ROOT_WINDOW()) || !(t = g_hash_table_lookup(p->htable, &win))) RET(); DBG("window=0x%lx\n", t->win); if (at == a_NET_WM_STATE) { DBG("event=NET_WM_STATE\n"); get_net_wm_state(t->win, &t->nws); } else if (at == a_NET_WM_DESKTOP) { DBG("event=NET_WM_DESKTOP\n"); desk_set_dirty_by_win(p, t); // to clean up desks where this task was t->desktop = get_net_wm_desktop(t->win); } else { RET(); } desk_set_dirty_by_win(p, t); RET(); }
static void do_net_active_window(FbEv *ev, pager_priv *p) { Window *fwin; task *t; ENTER; fwin = get_xaproperty(GDK_ROOT_WINDOW(), a_NET_ACTIVE_WINDOW, XA_WINDOW, 0); DBG("win=%lx\n", fwin ? *fwin : 0); if (fwin) { t = g_hash_table_lookup(p->htable, fwin); if (t != p->focusedtask) { if (p->focusedtask) desk_set_dirty_by_win(p, p->focusedtask); p->focusedtask = t; if (t) desk_set_dirty_by_win(p, t); } XFree(fwin); } else { if (p->focusedtask) { desk_set_dirty_by_win(p, p->focusedtask); p->focusedtask = NULL; } } RET(); }
/* Handler for "active-window" event from root window listener. */ static void pager_net_active_window(FbEv * ev, PagerPlugin * pg) { Window * focused_window = get_xaproperty(GDK_ROOT_WINDOW(), a_NET_ACTIVE_WINDOW, XA_WINDOW, 0); if (focused_window != NULL) { PagerTask * tk = task_lookup(pg, *focused_window); if (tk != pg->focused_task) { /* Focused task changed. Redraw both old and new. */ if (pg->focused_task != NULL) desk_set_dirty_by_win(pg, pg->focused_task); pg->focused_task = tk; if (tk != NULL) desk_set_dirty_by_win(pg, tk); } XFree(focused_window); } else { /* Focused task disappeared. Redraw old. */ if (pg->focused_task != NULL) { desk_set_dirty_by_win(pg, pg->focused_task); pg->focused_task = NULL; } } }
/* Handle PropertyNotify event. * http://tronche.com/gui/x/icccm/ * http://standards.freedesktop.org/wm-spec/wm-spec-1.4.html */ static void pager_property_notify_event(PagerPlugin * pg, XEvent * ev) { /* State may be PropertyNewValue, PropertyDeleted. */ if (((XPropertyEvent*) ev)->state == PropertyNewValue) { Atom at = ev->xproperty.atom; Window win = ev->xproperty.window; if (win != GDK_ROOT_WINDOW()) { /* Look up task structure by X window handle. */ PagerTask * tk = task_lookup(pg, win); if (tk != NULL) { /* Install an error handler that ignores BadWindow. * We frequently get a PropertyNotify event on deleted windows. */ XErrorHandler previous_error_handler = XSetErrorHandler(panel_handle_x_error_swallow_BadWindow_BadDrawable); /* Dispatch on atom. */ if (at == a_WM_STATE) { /* Window changed state. */ tk->ws = get_wm_state(tk->win); desk_set_dirty_by_win(pg, tk); } else if (at == a_NET_WM_STATE) { /* Window changed EWMH state. */ get_net_wm_state(tk->win, &tk->nws); desk_set_dirty_by_win(pg, tk); } else if (at == a_NET_WM_DESKTOP) { /* Window changed desktop. * Mark both old and new desktops for redraw. */ desk_set_dirty_by_win(pg, tk); tk->desktop = get_net_wm_desktop(tk->win); desk_set_dirty_by_win(pg, tk); XSetErrorHandler(previous_error_handler); } } } } }
/* Handle ConfigureNotify event. */ static void pager_configure_notify_event(PagerPlugin * pg, XEvent * ev) { Window win = ev->xconfigure.window; PagerTask * tk = task_lookup(pg, win); if (tk != NULL) { task_get_geometry(tk); desk_set_dirty_by_win(pg, tk); } }
static void do_net_client_list_stacking(FbEv *ev, pager *p) { int i; task *t; ENTER; if (p->wins) XFree(p->wins); p->wins = get_xaproperty (GDK_ROOT_WINDOW(), a_NET_CLIENT_LIST_STACKING, XA_WINDOW, &p->winnum); if (!p->wins || !p->winnum) RET(); /* refresh existing tasks and add new */ for (i = 0; i < p->winnum; i++) { if ((t = g_hash_table_lookup(p->htable, &p->wins[i]))) { t->refcount++; if (t->stacking != i) { t->stacking = i; desk_set_dirty_by_win(p, t); } } else { t = g_new0(task, 1); t->refcount++; t->win = p->wins[i]; t->ws = get_wm_state (t->win); t->desktop = get_net_wm_desktop(t->win); get_net_wm_state(t->win, &t->nws); get_net_wm_window_type(t->win, &t->nwwt); task_get_sizepos(t); if (!FBPANEL_WIN(t->win)) XSelectInput (GDK_DISPLAY(), t->win, PropertyChangeMask | StructureNotifyMask); g_hash_table_insert(p->htable, &t->win, t); DBG("add %x\n", t->win); desk_set_dirty_by_win(p, t); } } /* pass throu hash table and delete stale windows */ g_hash_table_foreach_remove(p->htable, (GHRFunc) task_remove_stale, (gpointer)p); RET(); }
/* tell to remove element with zero refcount */ static gboolean task_remove_stale(Window *win, task *t, pager_priv *p) { if (t->refcount-- == 0) { desk_set_dirty_by_win(p, t); if (p->focusedtask == t) p->focusedtask = NULL; DBG("del %lx\n", t->win); g_free(t); return TRUE; } return FALSE; }
/* static void pager_unmapnotify(pager_priv *p, XEvent *ev) { Window win = ev->xunmap.window; task *t; if (!(t = g_hash_table_lookup(p->htable, &win))) RET(); DBG("pager_unmapnotify: win=0x%x\n", win); RET(); t->ws = WithdrawnState; desk_set_dirty_by_win(p, t); RET(); } */ static void pager_configurenotify(pager_priv *p, XEvent *ev) { Window win = ev->xconfigure.window; task *t; ENTER; if (!(t = g_hash_table_lookup(p->htable, &win))) RET(); DBG("win=0x%lx\n", win); task_get_sizepos(t); desk_set_dirty_by_win(p, t); RET(); }