Hi, On Wed, 2010-05-12 at 07:39 +0200, ext Pallavi Kandhare wrote: ..
> 2. On mobile certain aplications are running at a time. (ed. clock, calender etc). How > can i find out and list all these applications. There is nothing very convenient for this but you can do it using the same API as the window manager (hildon-desktop) uses: XQueryTree and reading some window properties with XGetWindowProperty. You could get a some kind of list by taking top-level (== parent is the root window) windows that have _NET_WM_WINDOW_TYPE property set to _NET_WM_WINDOW_TYPE_NORMAL. I'm attaching the source code of a small utility that uses XQueryTree, you could use it as a starting point. -Kimmo
#include <X11/Xlib.h> #include <X11/Xatom.h> #include <stdio.h> #include <stdlib.h> #include <string.h> static Atom class_atom, name_atom, name_atom2, xembed_atom, pid_atom, trans_atom, hildon_stack_atom, utf8_string_atom, current_app_atom, win_type_atom, wm_state_atom, theme_atom, portrait_support, portrait_request, non_comp_atom; static char *get_atom_prop(Display *dpy, Window w, Atom atom) { Atom type; int format, rc; unsigned long items; unsigned long left; Atom *value; char *copy; rc = XGetWindowProperty (dpy, w, atom, 0, 1, False, XA_ATOM, &type, &format, &items, &left, (unsigned char**)&value); if (type != XA_ATOM || format == 0 || rc != Success) { copy = strdup(""); } else { char *s = XGetAtomName(dpy, *value); copy = strdup(s); XFree(s); } return copy; } static Window get_win_prop(Display *dpy, Window w, Atom atom) { Atom type; int format, rc; unsigned long items; unsigned long left; Window *value; rc = XGetWindowProperty (dpy, w, atom, 0, 1, False, XA_WINDOW, &type, &format, &items, &left, (unsigned char**)&value); if (type == None || rc != Success) return 0; else { return *value; } } static unsigned long get_card_prop(Display *dpy, Window w, Atom atom) { Atom type; int format, rc; unsigned long items; unsigned long left; unsigned long *value; rc = XGetWindowProperty (dpy, w, atom, 0, 1, False, XA_CARDINAL, &type, &format, &items, &left, (unsigned char**)&value); if (type == None || rc != Success) return 0; else { return *value; } } static long get_int_prop(Display *dpy, Window w, Atom atom) { Atom type; int format, rc; unsigned long items; unsigned long left; unsigned long *value; rc = XGetWindowProperty (dpy, w, atom, 0, 1, False, XA_INTEGER, &type, &format, &items, &left, (unsigned char**)&value); if (type == None || rc != Success) return -1; else { return *value; } } static long get_xembed_prop(Display *dpy, Window w) { Atom type; int format, rc; unsigned long items; unsigned long left; unsigned long *value; rc = XGetWindowProperty (dpy, w, xembed_atom, 0, 2, False, XA_CARDINAL, &type, &format, &items, &left, (unsigned char**)&value); if (type == None || rc != Success) return -1; else { long ret; ret = value[1] & (1 << 0); XFree(value); return ret; } } static char *get_str_prop(Display *dpy, Window w, Atom atom) { Atom type; int format, rc; unsigned long items; unsigned long left; char *value; rc = XGetWindowProperty (dpy, w, atom, 0, 200, False, XA_STRING, &type, &format, &items, &left, (unsigned char**)&value); if (type == None || rc != Success) return NULL; else { char *s = strdup((const char*)value); XFree(value); return s; } } static char *get_utf8_prop(Display *dpy, Window w, Atom atom) { Atom type; int format, rc; unsigned long items; unsigned long left; char *value; rc = XGetWindowProperty (dpy, w, atom, 0, 200, False, utf8_string_atom, &type, &format, &items, &left, (unsigned char**)&value); if (type == None || rc != Success) return NULL; else { char *s = strdup((const char*)value); XFree(value); return s; } } static const char *get_map_state(int state) { switch (state) { case IsUnmapped: return "IsUnmapped"; case IsUnviewable: return "IsUnviewable"; case IsViewable: return "IsViewable"; default: return ""; } } static void print_children(Display *dpy, Window w, int level) { unsigned int n_children = 0; Window *child_l = NULL; Window root_ret, parent_ret; int i; char *wmclass, *wmname, *wmname2, *wmtype, *wmstate; unsigned long por_sup, por_req; Window trans_for; char buf[100], xembed_buf[50]; XWindowAttributes attrs = { 0 }; long xembed, hildon_stack, non_comp; XQueryTree(dpy, w, &root_ret, &parent_ret, &child_l, &n_children); if (level > 0) for (i = 0; i < level; ++i) printf(" "); else { printf("The root (cur. app. 0x%lx, theme %s) ", get_win_prop(dpy, w, current_app_atom), get_str_prop(dpy, w, theme_atom)); } wmclass = get_str_prop(dpy, w, class_atom); wmname = get_utf8_prop(dpy, w, name_atom); wmname2 = get_str_prop(dpy, w, name_atom2); wmtype = get_atom_prop(dpy, w, win_type_atom); wmstate = get_atom_prop(dpy, w, wm_state_atom); por_sup = get_card_prop(dpy, w, portrait_support); por_req = get_card_prop(dpy, w, portrait_request); trans_for = get_win_prop(dpy, w, trans_atom); hildon_stack = get_int_prop(dpy, w, hildon_stack_atom); non_comp = get_int_prop(dpy, w, non_comp_atom); XGetWindowAttributes(dpy, w, &attrs); if (trans_for) snprintf(buf, 100, "(transient for 0x%lx)", trans_for); else buf[0] = '\0'; xembed = get_xembed_prop(dpy, w); if (xembed != -1) snprintf(xembed_buf, 50, "(XEmbed %ld)", xembed); else xembed_buf[0] = '\0'; if (n_children == 0) { printf("0x%lx %s %s %s HStack:%ld [PID %lu] WM_CLASS:%s WM_NAME:%s " "_NET_WM_NAME:%s %s %s %s %s %s %s %s %s\n", w, wmtype, wmstate, get_map_state(attrs.map_state), hildon_stack, get_card_prop(dpy, w, pid_atom), wmclass ? wmclass : "(none)", wmname2 ? wmname2 : "(none)", wmname ? wmname : "(none)", xembed_buf, buf, attrs.override_redirect ? "override-redirect": "", attrs.all_event_masks & SubstructureRedirectMask ? "Substr.Redirect":"", attrs.all_event_masks & SubstructureNotifyMask ? "Substr.Notify":"", por_sup ? "por.sup":"", por_req ? "por.req":"", non_comp != -1 ? "non-comp.":""); } else { printf("0x%lx %s %s %s HStack:%ld [PID %lu] WM_CLASS:%s WM_NAME:%s " "_NET_WM_NAME:%s %s %s %s %s %s %s %s %s (%u children):\n", w, wmtype, wmstate, get_map_state(attrs.map_state), hildon_stack, get_card_prop(dpy, w, pid_atom), wmclass ? wmclass : "(none)", wmname2 ? wmname2 : "(none)", wmname ? wmname : "(none)", xembed_buf, buf, attrs.override_redirect ? "override-redirect": "", attrs.all_event_masks & SubstructureRedirectMask ? "Substr.Redirect":"", attrs.all_event_masks & SubstructureNotifyMask ? "Substr.Notify":"", por_sup ? "por.sup":"", por_req ? "por.req":"", non_comp != -1 ? "non-comp.":"", n_children); for (i = 0; i < n_children; ++i) { print_children(dpy, child_l[i], level + 1); } XFree(child_l); } free(wmclass); free(wmname); free(wmtype); free(wmstate); } int main() { Display *dpy; Window root; dpy = XOpenDisplay(NULL); if (dpy == NULL) { printf("couldn't open display\n"); return 1; } class_atom = XInternAtom(dpy, "WM_CLASS", False); name_atom = XInternAtom(dpy, "_NET_WM_NAME", False); name_atom2 = XInternAtom(dpy, "WM_NAME", False); xembed_atom = XInternAtom(dpy, "_XEMBED_INFO", False); pid_atom = XInternAtom(dpy, "_NET_WM_PID", False); trans_atom = XInternAtom(dpy, "WM_TRANSIENT_FOR", False); utf8_string_atom = XInternAtom(dpy, "UTF8_STRING", False); current_app_atom = XInternAtom(dpy, "_MB_CURRENT_APP_WINDOW", False); win_type_atom = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False); wm_state_atom = XInternAtom(dpy, "_NET_WM_STATE", False); theme_atom = XInternAtom(dpy, "_MB_THEME", False); hildon_stack_atom = XInternAtom(dpy, "_HILDON_STACKABLE_WINDOW", False); portrait_support = XInternAtom(dpy, "_HILDON_PORTRAIT_MODE_SUPPORT", False); portrait_request = XInternAtom(dpy, "_HILDON_PORTRAIT_MODE_REQUEST", False); non_comp_atom = XInternAtom(dpy, "_HILDON_NON_COMPOSITED_WINDOW", False); root = XDefaultRootWindow(dpy); print_children(dpy, root, 0); return 0; }
_______________________________________________ maemo-developers mailing list maemo-developers@maemo.org https://lists.maemo.org/mailman/listinfo/maemo-developers